<?php
/*
OpenDataBag - Data Web Interface
Copyright (C) 2004 Nawara
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
$send_to=get('to');
$send_body=get('body');
$memo=get('memo');
function sendsms($phone,$message)
{
$valid=0;
ini_set('user_agent','MSIE 4\.0b2;');
//country code
if(substr($phone,0,2)=='48') //Poland
{
$phone=substr($phone,2);
$message=urlencode(substr($message,0,160));
$login='600216716';
$pass='4994BB';
$url='http://partner.wapster.pl/partnerSMSGate.aspx?userid=0&ID=30&smslen=160&send=1&userlimit=-1&statenoc=0&editok=0&toedit=-1&idtoedit=-1&logged=0&onlylog=0&tos='.$phone.'&body='.$message.'&smstype=N&login='.$login.'&pass='.$pass;
$valid=1;
}
if($valid)
{
$dh = @fopen($url,'r');
$result = @fread($dh,8192);
if($result)
return true;
else
{
echo 'Cannot send SMS - no connection to internet service';
return false;
}
}
else
{
echo 'SMS not valid';
return false;
}
}
//~ $send_array=explode(',',$send_to);
//~ for($tmp_ii=0;$tmp_ii<count($send_array);$tmp_ii++)
//~ if(trim($send_array[$tmp_ii]))
if(!sendsms($send_to,$send_body))
{
//echo "Message was not sent <p>";
$email_file=rand(10000000,99999999);
addpath(cfg_data_path.'/config/not_sent');
$fp=fopen(cfg_data_path.'/config/not_sent/'.$email_file.'.txt','wb');
fwrite($fp,$send_to.CRLF.'-------------------'.CRLF.'SMS'.CRLF.'-------------------'.CRLF.$send_body);
fclose($fp);
mylog('SMS ERROR ('.$email_file.') Unknown error');
//echo 'SMS Error: Unknown error';
}
else
{
$group='sms';
$variable_array['sysId']='0';
$variable_array['sysGroupBy']=$group;
$variable_array['sysValidFrom']=date('Ymd');
$variable_array['sysValidTo']=99991231;
$variable_array['sysValid']=1;
$variable_array['sysComment']='SMS sent';
$variable_array['Send From']=USERNAME;
$variable_array['Send Date']=date('Ymd');
$variable_array['Send To']=$send_to;
$variable_array['Send Body']=$send_body;
$variable_array['Memo']=$memo;
//USEREXIT OnSave
$userexit='onsave';
if(file_exists(cfg_data_path.'/config/userexit/exit_'.$userexit.'.txt'))
{
include(cfg_data_path.'/config/userexit/exit_'.$userexit.'.txt');
}
else
{
include(cfg_data_path.'/script/userexit/exit_'.$userexit.'.txt');
}
if($variable_array['MyBag']=='')
$variable_array['MyBag']=$bag;
$variable_array['MyBag']=purename($variable_array['MyBag']);
$id=save($variable_array);
//$search=$group.' sysId='.$id;
if(!$script)
$search='sysId='.$id;
}
?>