function sms_autosend_hook_playsmsd() { global $core_config; $timenow = mktime(); $db_query = "SELECT uid,time_id," . _DB_PREF_ . "_featureAutosend.autosend_id, autosend_message,autosend_number,autosend_time\n\t\t\t\t\t\t\tFROM " . _DB_PREF_ . "_featureAutosend\n\t\t\t\t\t\t\tINNER JOIN " . _DB_PREF_ . "_featureAutosend_time\n\t\t\t\t\t\t\tON " . _DB_PREF_ . "_featureAutosend.autosend_id = " . _DB_PREF_ . "_featureAutosend_time.autosend_id\n\t\t\t\t\t\t\tWHERE UNIX_TIMESTAMP(" . _DB_PREF_ . "_featureAutosend_time.autosend_time) <= '{$timenow}'\n\t\t\t\t\t\t\tAND " . _DB_PREF_ . "_featureAutosend_time.sent='0'\n\t\t\t\t\t\t\tAND autosend_time != ''\n\t\t\t\t\t\t\tAND " . _DB_PREF_ . "_featureAutosend.autosend_enable='1'"; $db_result = dba_query($db_query); while ($db_row = dba_fetch_array($db_result)) { $message = $db_row['autosend_message']; $c_uid = $db_row['uid']; $username = uid2username($c_uid); $sms_to = $db_row['autosend_number']; // we are sending to this number $autosend_id = $db_row['autosend_id']; $time_id = $db_row['time_id']; $unicode = 0; if (function_exists('mb_detect_encoding')) { $encoding = mb_detect_encoding($message, 'auto'); if ($encoding != 'ASCII') { $unicode = 1; } } list($ok, $to, $smslog_id) = sendsms_pv($username, $sms_to, $message, 'text', $unicode); if ($ok[0]) { $db_query = "UPDATE " . _DB_PREF_ . "_featureAutosend_time SET sent='1' WHERE time_id = '{$time_id}'"; $db_result = @dba_affected_rows($db_query); } } }
function simplebilling_hook_billing_finalize($smslog_id) { $db_query = "UPDATE " . _DB_PREF_ . "_tblBilling SET status='1' WHERE smslog_id='{$smslog_id}'"; $db_result = dba_affected_rows($db_query); logger_print("saving smslog_id:" . $smslog_id, 3, "simplebilling finalize"); return true; }
function simplerate_hook_rate_setusercredit($uid, $remaining = 0) { $ok = false; logger_print("saving uid:" . $uid . " remaining:" . $remaining, 3, "simplerate setusercredit"); $db_query = "UPDATE " . _DB_PREF_ . "_tblUser SET c_timestamp=NOW(),credit='{$remaining}' WHERE uid='{$uid}'"; if ($db_result = @dba_affected_rows($db_query)) { logger_print("saved uid:" . $uid . " remaining:" . $remaining, 3, "simplerate setusercredit"); $ok = true; } return $ok; }
function simplebilling_hook_billing_finalize($smslog_id) { $ok = false; logger_print("saving smslog_id:" . $smslog_id, 2, "simplebilling finalize"); $db_query = "UPDATE " . _DB_PREF_ . "_tblBilling SET status='1' WHERE smslog_id='{$smslog_id}'"; if ($db_result = dba_affected_rows($db_query)) { logger_print("saved smslog_id:" . $smslog_id, 2, "simplebilling finalize"); $ok = true; } return $ok; }
function queuelog_delete_all($queue) { global $user_config; $ret = FALSE; if ($user_config['status'] != 2) { $user_query = "AND uid='" . $user_config['uid'] . "'"; } $db_query = "DELETE FROM " . _DB_PREF_ . "_tblSMSOutgoing_queue WHERE (flag='0' OR flag='3') " . $user_query; if ($db_result = dba_affected_rows($db_query)) { $ret = TRUE; } return $ret; }
function logger_get_error_string($id, $nodel = false) { $ret_string = ""; $db_query = "SELECT error_string FROM " . _DB_PREF_ . "_tblErrorString WHERE id='{$id}'"; $db_result = dba_query($db_query); if ($db_row = dba_fetch_array($db_result)) { $ret_string = $db_row['error_string']; if (!$nodel) { $db_query = "DELETE FROM " . _DB_PREF_ . "_tblErrorString WHERE id='{$id}'"; $db_result = @dba_affected_rows($db_query); } } return $ret_string; }
function setsmsdeliverystatus($smslog_id, $uid, $p_status) { global $core_config; // $p_status = 0 --> pending // $p_status = 1 --> sent // $p_status = 2 --> failed // $p_status = 3 --> delivered // logger_print("smslog_id:".$smslog_id." uid:".$uid." p_status:".$p_status, 2, "setsmsdeliverystatus"); $ok = false; $db_query = "UPDATE " . _DB_PREF_ . "_tblSMSOutgoing SET c_timestamp='" . mktime() . "',p_update='" . core_get_datetime() . "',p_status='{$p_status}' WHERE smslog_id='{$smslog_id}' AND uid='{$uid}'"; if ($aff_id = @dba_affected_rows($db_query)) { // logger_print("saved smslog_id:".$smslog_id, 2, "setsmsdeliverystatus"); $ok = true; if ($p_status > 0) { for ($c = 0; $c < count($core_config['featurelist']); $c++) { core_hook($core_config['featurelist'][$c], 'setsmsdeliverystatus', array($smslog_id, $uid, $p_status)); } } } return $ok; }
if ($gateway_module == $template_param[name]) { $status_active = "(<font color=green><b>Active</b></font>)"; } else { $status_active = "(<font color=red><b>Inactive</b></font>) (<a href=\"menu_admin.php?inc=gwmod_template&op=manage_activate\">click here to activate</a>)"; } switch ($op) { case "manage": if ($err) { $content = "<p><font color=red>{$err}</font><p>"; } $content .= "\n\t\t <h2>Manage Gateway Module</h2>\n\t\t <p>\n\t\t <form action=menu_admin.php?inc=gwmod_template&op=manage_save method=post>\n\t\t <p>Gateway Name: <b>" . $template_param[name] . "</b> {$status_active}\n\t\t <p>Template Path: <input type=text size=40 maxlength=250 name=up_path value=\"" . $template_param[path] . "\"> (No trailing slash \"/\")\n\t\t <p>Note :<br>\n\t\t - When you put <b>/usr/local</b> above, the real path is <b>/usr/local/cache/smsd</b>\n\t\t <!-- <p><input type=checkbox name=up_trn {$checked}> Send SMS message without footer banner ({$username}) -->\n\t\t <p><input type=submit class=button value=Save>\n\t\t </form>\n\t\t"; echo $content; break; case "manage_save": $up_path = $_POST[up_path]; $error_string = "No changes made!"; if ($up_path) { $db_query = "\n\t\t\t\tUPDATE playsms_gwmodTemplate_config \n\t\t\t\tSET cfg_path='{$up_path}'\n\t\t\t "; if (@dba_affected_rows($db_query)) { $error_string = "Gateway module configurations has been saved"; } } header("Location: menu_admin.php?inc=gwmod_template&op=manage&err=" . urlencode($error_string)); break; case "manage_activate": $db_query = "UPDATE playsms_tblConfig_main SET cfg_gateway_module='template'"; $db_result = dba_query($db_query); $error_string = "Gateway has been activated"; header("Location: menu_admin.php?inc=gwmod_template&op=manage&err=" . urlencode($error_string)); break; }
$content .= "</table>\n\t\t\t\t<p><input type=submit class=button value=" . _('Add') . ">\n\t\t\t\t</form>\n\t\t\t"; echo $content; break; case "sms_autosend_add_yes": $add_autosend_message = $_POST['add_autosend_message']; $add_autosend_number = $_POST['add_autosend_number']; $add_autosend_time = $_POST['add_autosend_time']; if ($add_autosend_message && $add_autosend_number && $add_autosend_time) { $db_query = "\n\t\t\t\t\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_featureAutosend (uid,autosend_message, autosend_number)\n\t\t\t\t\t\t\t\t\tVALUES ('{$uid}','{$add_autosend_message}','{$add_autosend_number}')\n\t\t\t\t\t\t\t\t\t"; if ($new_uid = @dba_insert_id($db_query)) { foreach ($add_autosend_time as $value) { $db_query = "\n\t\t\t\t\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_featureAutosend_time (autosend_id, autosend_time)\n\t\t\t\t\t\t\t\t\tVALUES ('{$new_uid}','{$value}')\n\t\t\t\t\t\t\t\t\t"; if ($value) { $insert = dba_insert_id($db_query); } } if ($insert) { $error_string = _('SMS autosend has been added'); } else { $db_query = "DELETE FROM " . _DB_PREF_ . "_featureAutosend WHERE autosend_id = '" . $db_row['autosend_id'] . "'"; $delete = @dba_affected_rows($db_query); } } else { $error_string = _('Fail to add SMS autosend'); } } else { $error_string = _('You must fill all fields'); } header("Location: index.php?app=menu&inc=feature_sms_autosend&op=sms_autosend_add&err=" . urlencode($error_string)); break; }
function credit_hook_rate_setusercredit($uid, $balance = 0) { $ok = false; $balance = (double) $balance; if ($balance > 0) { _log("saving uid:" . $uid . " balance:" . $balance, 2, "credit_hook_rate_setusercredit"); $db_query = "UPDATE " . _DB_PREF_ . "_tblUser SET c_timestamp='" . mktime() . "',credit='{$balance}' WHERE uid='{$uid}'"; if ($db_result = @dba_affected_rows($db_query)) { _log("saved uid:" . $uid . " balance:" . $balance, 2, "credit_hook_rate_setusercredit"); $ok = true; } } return $ok; }
function sendsmsd($single_queue = '', $sendsmsd_limit = 0, $sendsmsd_offset = 0) { global $core_config; if ($single_queue) { $queue_sql = "AND queue_code='" . $single_queue . "'"; // logger_print("single queue queue_code:".$single_queue, 2, "sendsmsd"); } $sendsmsd_limit = (int) $sendsmsd_limit; if ($sendsmsd_limit > 0) { $sql_limit = "LIMIT " . $sendsmsd_limit; } $sendsmsd_offset = (int) $sendsmsd_offset; if ($sendsmsd_offset > 0) { $sql_offset = "OFFSET " . $sendsmsd_offset; } $db_query = "SELECT * FROM " . _DB_PREF_ . "_tblSMSOutgoing_queue WHERE flag='0' " . $queue_sql . " " . $sql_limit . " " . $sql_offset; // logger_print("q: ".$db_query, 3, "sendsmsd"); $db_result = dba_query($db_query); while ($db_row = dba_fetch_array($db_result)) { $c_queue_id = $db_row['id']; $c_queue_code = $db_row['queue_code']; $c_sender_id = addslashes(trim($db_row['sender_id'])); $c_footer = addslashes(trim($db_row['footer'])); $c_message = addslashes(trim($db_row['message'])); $c_uid = $db_row['uid']; $c_gpid = $db_row['gpid']; $c_sms_type = $db_row['sms_type']; $c_unicode = $db_row['unicode']; $c_sms_count = $db_row['sms_count']; $c_schedule = $db_row['datetime_scheduled']; $c_smsc = $db_row['smsc']; $c_current = core_get_datetime(); // logger_print("delivery datetime qeueue:".$c_queue_code." scheduled:".$c_schedule." current:".$c_current, 3, "sendsmsd"); if (strtotime($c_current) >= strtotime($c_schedule)) { logger_print("start processing queue_code:" . $c_queue_code . " sms_count:" . $c_sms_count . " uid:" . $c_uid . " gpid:" . $c_gpid . " sender_id:" . $c_sender_id, 2, "sendsmsd"); $counter = 0; $db_query2 = "SELECT * FROM " . _DB_PREF_ . "_tblSMSOutgoing_queue_dst WHERE queue_id='{$c_queue_id}' AND flag='0'"; $db_result2 = dba_query($db_query2); while ($db_row2 = dba_fetch_array($db_result2)) { $counter++; // queue_dst ID is SMS Log ID $c_smslog_id = $db_row2['id']; $c_dst = $db_row2['dst']; $c_flag = 2; $c_ok = false; logger_print("sending queue_code:" . $c_queue_code . " smslog_id:" . $c_smslog_id . " to:" . $c_dst . " sms_count:" . $c_sms_count . " counter:" . $counter, 2, "sendsmsd"); $ret = sendsms_process($c_smslog_id, $c_sender_id, $c_footer, $c_dst, $c_message, $c_uid, $c_gpid, $c_sms_type, $c_unicode, $c_queue_code, $c_smsc); $c_dst = $ret['to']; if ($ret['status']) { $c_ok = true; $c_flag = 1; } logger_print("result queue_code:" . $c_queue_code . " to:" . $c_dst . " flag:" . $c_flag . " smslog_id:" . $c_smslog_id, 2, "sendsmsd"); $db_query3 = "UPDATE " . _DB_PREF_ . "_tblSMSOutgoing_queue_dst SET flag='{$c_flag}' WHERE id='{$c_smslog_id}'"; $db_result3 = dba_query($db_query3); $ok[] = $c_ok; $to[] = $c_dst; $smslog_id[] = $c_smslog_id; $queue[] = $c_queue_code; $counts[] = $c_sms_count; } $db_query = "SELECT count(*) AS count FROM " . _DB_PREF_ . "_tblSMSOutgoing_queue_dst WHERE queue_id='{$c_queue_id}' AND NOT flag ='0'"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); // destinations processed $dst_processed = (int) ($db_row['count'] ? $db_row['count'] : 0); // number of SMS processed $sms_processed = $dst_processed * $c_sms_count; // check whether SMS processed is >= stated SMS count in queue // if YES then processing queue is finished if ($sms_processed >= $c_sms_count) { $dt = core_get_datetime(); $db_query5 = "UPDATE " . _DB_PREF_ . "_tblSMSOutgoing_queue SET flag='1', datetime_update='" . $dt . "' WHERE id='{$c_queue_id}'"; if ($db_result5 = dba_affected_rows($db_query5)) { logger_print("finish processing queue_code:" . $c_queue_code . " uid:" . $c_uid . " sender_id:" . $c_sender_id . " sms_count:" . $c_sms_count, 2, "sendsmsd"); } else { logger_print("fail to finalize process queue_code:" . $c_queue_code . " uid:" . $c_uid . " sender_id:" . $c_sender_id . " sms_processed:" . $sms_processed, 2, "sendsmsd"); } } else { logger_print("partially processing queue_code:" . $c_queue_code . " uid:" . $c_uid . " sender_id:" . $c_sender_id . " sms_count:" . $c_sms_count . " sms_processed:" . $sms_processed . " counter:" . $counter, 2, "sendsmsd"); } } } return array($ok, $to, $smslog_id, $queue, $counts); }
function inboxgroup_catchalldel($rid, $uid) { $ret = false; $db_query = "SELECT id FROM " . _DB_PREF_ . "_featureInboxgroup_catchall WHERE rid='{$rid}' AND uid='{$uid}'"; $db_result = dba_query($db_query); if ($db_row = dba_fetch_array($db_result)) { $db_query = "DELETE FROM " . _DB_PREF_ . "_featureInboxgroup_catchall WHERE rid='{$rid}' AND uid='{$uid}'"; $ret = dba_affected_rows($db_query); } return $ret; }
function credit_hook_rate_setusercredit($uid, $balance = 0) { $balance = (double) $balance; $user = user_getdatabyuid($uid); if ($user['uid']) { if ($user['credit'] != $balance) { _log("saving uid:" . $uid . " balance:" . $balance, 2, "credit_hook_rate_setusercredit"); $db_query = "UPDATE " . _DB_PREF_ . "_tblUser SET c_timestamp='" . mktime() . "',credit='{$balance}' WHERE flag_deleted='0' AND uid='{$uid}'"; if ($db_result = @dba_affected_rows($db_query)) { _log("saved uid:" . $uid . " balance:" . $balance, 2, "credit_hook_rate_setusercredit"); return TRUE; } else { _log("unable to save uid:" . $uid . " balance:" . $balance, 2, "credit_hook_rate_setusercredit"); return FALSE; } } else { _log("no changes uid:" . $uid . " balance:" . $balance, 2, "credit_hook_rate_setusercredit"); return TRUE; } } else { _log("user does not exists uid:" . $uid . " balance:" . $balance, 2, "credit_hook_rate_setusercredit"); return FALSE; } }
function sms_survey_questionsdel($sid, $id) { $ret = false; $db_query = "SELECT id FROM " . _DB_PREF_ . "_featureSurvey_questions WHERE sid='{$sid}' AND id='{$id}'"; $db_result = dba_query($db_query); if ($db_row = dba_fetch_array($db_result)) { $db_query1 = "DELETE FROM " . _DB_PREF_ . "_featureSurvey_questions WHERE sid='{$sid}' AND id='" . $db_row['id'] . "'"; $ret = dba_affected_rows($db_query1); } return $ret; }
function setsmsdeliverystatus($smslog_id, $uid, $p_status) { global $core_config, $datetime_now; // $p_status = 0 --> pending // $p_status = 1 --> sent // $p_status = 2 --> failed // $p_status = 3 --> delivered $ok = false; $db_query = "UPDATE " . _DB_PREF_ . "_tblSMSOutgoing SET c_timestamp='" . mktime() . "',p_update='{$datetime_now}',p_status='{$p_status}' WHERE smslog_id='{$smslog_id}' AND uid='{$uid}'"; if ($aff_id = @dba_affected_rows($db_query)) { $ok = true; if ($p_status > 0) { for ($c = 0; $c < count($core_config['toolslist']); $c++) { x_hook($core_config['toolslist'][$c], 'setsmsdeliverystatus', array($smslog_id, $uid, $p_status)); } for ($c = 0; $c < count($core_config['featurelist']); $c++) { x_hook($core_config['featurelist'][$c], 'setsmsdeliverystatus', array($smslog_id, $uid, $p_status)); } x_hook($gateway_module, 'setsmsdeliverystatus', array($smslog_id, $uid, $p_status)); } } return $ok; }
/** * Process login * */ function auth_login() { global $core_config; $username = trim($_REQUEST['username']); $password = trim($_REQUEST['password']); if ($username && $password) { if ($ticket = validatelogin($username, $password)) { $db_query = "UPDATE " . _DB_PREF_ . "_tblUser SET c_timestamp='" . mktime() . "',ticket='{$ticket}' WHERE username='******'"; if (@dba_affected_rows($db_query)) { setcookie("vc1", "{$ticket}"); setcookie("vc2", "{$username}"); if ($core_config['multilogin']) { $multilogin_id = md5($username . $password); setcookie("vc3", "{$multilogin_id}"); } logger_print("u:" . $username . " t:" . $ticket . " ip:" . $_SERVER['REMOTE_ADDR'], 3, "login"); } else { $error_string = _('Unable to update login session'); } } else { $error_string = _('Invalid username or password'); } } if (isset($error_string)) { $errid = logger_set_error_string($error_string); header("Location: " . $core_config['http_path']['base'] . "/?errid=" . $errid); } else { header("Location: " . $core_config['http_path']['base']); } exit; }
if ($replace == "ok") { $db_query = "SELECT * FROM " . _DB_PREF_ . "_toolsSimplephonebook WHERE gpid='{$gpid}'"; $db_result = dba_query($db_query); $j = 0; while ($db_row = dba_fetch_array($db_result)) { $j++; $pid[$j] = $db_row['pid']; $pdesc[$j] = $db_row['p_desc']; } for ($i = 0; $i < $num; $i++) { $m = 0; for ($k = 1; $k <= $j; $k++) { if ($Name[$i] == $pdesc[$k]) { if ($Number[$i]) { $db_query1 = "UPDATE " . _DB_PREF_ . "_toolsSimplephonebook SET c_timestamp='" . mktime() . "',p_num='" . $Number[$i] . "',p_email='" . $Email[$i] . "' WHERE pid='" . $pid[$k] . "' AND gpid='{$gpid}'"; $db_result1 = dba_affected_rows($db_query1); if ($db_result1 > 0) { // FIXME } else { // FIXME } } $m++; } } if ($m <= 0) { if ($Name[$i] && $Number[$i]) { $db_query2 = "\n\t\t\t INSERT INTO " . _DB_PREF_ . "_toolsSimplephonebook (uid,p_desc,p_num,p_email,gpid)\n\t\t\t VALUES ('{$uid}','" . $Name[$i] . "','" . $Number[$i] . "','" . $Email[$i] . "','{$gpid}')\n\t\t\t"; $db_result2 = dba_insert_id($db_query2); if ($db_result2 > 0) { // FIXME
header("Location: index.php?app=menu&inc=feature_sms_collect&op=sms_collect_list"); exit; break; case "sms_collect_del": $collect_id = $_REQUEST['collect_id']; $db_query = "SELECT collect_keyword FROM " . _DB_PREF_ . "_featureCollect WHERE collect_id='{$collect_id}'"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); $collect_keyword = $db_row['collect_keyword']; if ($collect_keyword) { $db_query = "DELETE FROM " . _DB_PREF_ . "_featureCollect WHERE collect_keyword='{$collect_keyword}'"; if (@dba_affected_rows($db_query)) { $db_query = "DELETE FROM " . _DB_PREF_ . "_featureCollect_msg WHERE collect_id='{$collect_id}'"; $del_msg = dba_affected_rows($db_query); $db_query = "DELETE FROM " . _DB_PREF_ . "_featureCollect_member WHERE collect_id='{$collect_id}'"; $del_member = dba_affected_rows($db_query); $_SESSION['error_string'] = _('SMS collect with all its messages and members has been deleted') . " (" . _('keyword') . ": " . $collect_keyword . ")"; } } header("Location: index.php?app=menu&inc=feature_sms_collect&op=sms_collect_list"); exit; break; case "sms_collect_add": if ($err = $_SESSION['error_string']) { $content = "<div class=error_string>{$err}</div>"; } $content .= "\n\t\t\t<h2>" . _('Manage collect') . "</h2>\n\t\t\t<h3>" . _('Add SMS collect') . "</h3>\n\t\t\t<form action=index.php?app=menu&inc=feature_sms_collect&op=sms_collect_add_yes method=post>\n\t\t\t<table width=100%>\n\t\t\t<tr>\n\t\t\t\t<td width=270>" . _('SMS collect keyword') . "</td><td><input type=text size=8 maxlength=10 name=add_collect_keyword value=\"{$add_collect_keyword}\"></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>" . _('SMS collect reply') . "</td><td><input type=text size=30 maxlength=200 name=add_collect_msg value=\"{$add_collect_msg}\"></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>" . _('Forward to email') . "</td><td><input type=text size=30 maxlength=250 name=add_collect_fwd_email value=\"{$add_collect_fwd_email}\"></td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<p><input type=submit class=button value=\"" . _('Save') . "\">\n\t\t\t</form>\n\t\t\t" . _b('index.php?app=menu&inc=feature_sms_collect&op=sms_collect_list'); echo $content; break; case "sms_collect_add_yes": $add_collect_keyword = strtoupper($_REQUEST['add_collect_keyword']);
function smstools_hook_getsmsinbox() { global $plugin_config; $plugin_config['smstools']['backup'] = $plugin_config['smstools']['default_queue'] . '/backup'; if (!is_dir($plugin_config['smstools']['backup'] . '/incoming')) { mkdir($plugin_config['smstools']['backup'] . '/incoming', 0777, TRUE); } $handle = @opendir($plugin_config['smstools']['default_queue'] . '/incoming'); while ($sms_in_file = @readdir($handle)) { $smsc = ''; $sms_receiver = ''; $sms_sender = ''; $sms_datetime = ''; $found_sender = FALSE; $found_datetime = FALSE; $fn = $plugin_config['smstools']['default_queue'] . '/incoming/' . $sms_in_file; $fn_backup = $plugin_config['smstools']['backup'] . '/incoming/' . $sms_in_file; $lines = @file($fn); $start = 0; for ($c = 0; $c < count($lines); $c++) { $c_line = $lines[$c]; if (preg_match('/^From: /', $c_line)) { $sms_sender = '+' . trim(str_replace('From: ', '', trim($c_line))); $found_sender = TRUE; } else { if (preg_match('/^Received: /', $c_line)) { $sms_datetime = '20' . trim(str_replace('Received: ', '', trim($c_line))); $found_datetime = TRUE; } else { if (preg_match('/^Modem: /', $c_line)) { if ($smsc = trim(str_replace('Modem: ', '', trim($c_line)))) { $c_plugin_config = gateway_apply_smsc_config($smsc, $plugin_config); $sms_receiver = $c_plugin_config['smstools']['sms_receiver']; } } else { if ($c_line == "\n") { $start = $c + 1; break; } } } } } // proceed only when the file contains some hint that it is an incoming SMS if ($found_sender && $found_datetime && $start) { // inspired by keke's suggestion (smstools3 dev). // copy to backup folder instead of delete it directly from original spool dir. // playSMS does the backup since probably not many smstools3 users configure // an eventhandler to backup incoming sms if (!rename($fn, $plugin_config['smstools']['backup'] . '/incoming/' . $sms_in_file)) { if (file_exists($fn)) { @unlink($fn); } } // continue process only when incoming sms file can be deleted if (!file_exists($fn) && $start) { if ($sms_sender && $sms_datetime) { $message = ''; for ($lc = $start; $lc < count($lines); $lc++) { $message .= trim($lines[$lc]) . "\n"; } if (strlen($message) > 0) { $message = substr($message, 0, -1); } $is_dlr = false; $msg = explode("\n", $message); if (trim($msg[0]) == 'SMS STATUS REPORT') { $label = explode(':', $msg[1]); if (trim($label[0]) == 'Message_id') { $message_id = trim($label[1]); } unset($label); $label = explode(':', $msg[3]); if (trim($label[0]) == 'Status') { $status_var = explode(',', trim($label[1])); $status = (int) $status_var[0]; } if ($message_id && $status_var[1]) { _log('DLR received message_id:' . $message_id . ' status:' . $status . ' info1:[' . $status_var[1] . '] info2:[' . $status_var[2] . '] smsc:[' . $smsc . ']', 2, 'smstools_hook_getsmsinbox'); $db_query = "SELECT id,uid,smslog_id FROM " . _DB_PREF_ . "_gatewaySmstools_dlr WHERE message_id='" . $message_id . "' AND status='1' ORDER BY id DESC LIMIT 1"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); $id = $db_row['id']; $uid = $db_row['uid']; $smslog_id = $db_row['smslog_id']; if ($uid && $smslog_id && $status === 0) { $db_query = "UPDATE " . _DB_PREF_ . "_gatewaySmstools_dlr SET status='2' WHERE id='" . $id . "'"; if ($db_result = dba_affected_rows($db_query)) { $p_status = 3; dlr($smslog_id, $uid, $p_status); _log('DLR smslog_id:' . $smslog_id . ' p_status:' . $p_status . ' smsc:[' . $smsc . ']', 2, 'smstools_hook_getsmsinbox'); } } $is_dlr = true; } } // collected: $sms_datetime, $sms_sender, $message, $sms_receiver // if not a DLR then route it to incoming handler if (!$is_dlr) { _log('sender:' . $sms_sender . ' receiver:' . $sms_receiver . ' dt:' . $sms_datetime . ' msg:[' . $message . '] smsc:[' . $smsc . ']', 3, 'smstools_hook_getsmsinbox'); $sms_sender = addslashes($sms_sender); $message = addslashes($message); recvsms($sms_datetime, $sms_sender, $message, $sms_receiver, $smsc); } } } } } }
function dba_remove($db_table, $condition = '', $operand = 'AND') { $ret = false; if (is_array($condition)) { foreach ($condition as $key => $val) { $q_condition .= $operand . " " . $key . "='" . $val . "' "; } if ($q_condition) { $q_condition = "WHERE " . substr($q_condition, 3); } $db_query = "DELETE FROM " . $db_table . " " . $q_condition; if ($c_rows = dba_affected_rows($db_query)) { $ret = $c_rows; } } return $ret; }
function sendsmsd($single_queue = '', $chunk = 0) { global $core_config; if ($single_queue) { $queue_sql = "AND queue_code='" . $single_queue . "'"; // _log("single queue queue_code:".$single_queue, 2, "sendsmsd"); } $db_query = "SELECT * FROM " . _DB_PREF_ . "_tblSMSOutgoing_queue WHERE flag='3' " . $queue_sql; // _log("q: ".$db_query, 3, "sendsmsd"); $db_result = dba_query($db_query); while ($db_row = dba_fetch_array($db_result)) { $c_queue_id = $db_row['id']; $c_queue_code = $db_row['queue_code']; $c_sender_id = addslashes(trim($db_row['sender_id'])); $c_footer = addslashes(trim(htmlspecialchars_decode($db_row['footer']))); $c_message = addslashes(trim(htmlspecialchars_decode($db_row['message']))); $c_uid = $db_row['uid']; $c_gpid = $db_row['gpid']; $c_sms_type = $db_row['sms_type']; $c_unicode = $db_row['unicode']; // queue size $c_queue_count = $db_row['queue_count']; // total number of SMS per queue $c_sms_count = $db_row['sms_count']; // SMS count per destination $c_sms_size = ceil($c_sms_count / $c_queue_count); $c_schedule = $db_row['datetime_scheduled']; $c_smsc = $db_row['smsc']; $c_current = core_get_datetime(); $continue = FALSE; // check delivery datetime // _log("delivery datetime qeueue:" . $c_queue_code . " scheduled:" . core_display_datetime($c_schedule) . " current:" . core_display_datetime($c_current), 3, "sendsmsd"); if (strtotime($c_current) >= strtotime($c_schedule)) { $continue = TRUE; // next, check throttle limit (number of sent SMS per hour) if (sendsms_throttle_isoverlimit(0)) { $continue = FALSE; } } // process queue if ($continue) { _log("start processing queue_code:" . $c_queue_code . " chunk:" . $chunk . " queue_count:" . $c_queue_count . " sms_count:" . $c_sms_count . " scheduled:" . core_display_datetime($c_schedule) . " uid:" . $c_uid . " gpid:" . $c_gpid . " sender_id:" . $c_sender_id, 2, "sendsmsd"); $counter = 0; $db_query2 = "SELECT * FROM " . _DB_PREF_ . "_tblSMSOutgoing_queue_dst WHERE queue_id='{$c_queue_id}' AND chunk='" . $chunk . "' AND flag='0'"; $db_result2 = dba_query($db_query2); while ($db_row2 = dba_fetch_array($db_result2)) { // make sure the queue is still there // if the queue_code with flag=3 is not exists then break, stop sendqueue if (!dba_isexists(_DB_PREF_ . "_tblSMSOutgoing_queue", array('flag' => 3, 'queue_code' => $c_queue_code), 'AND')) { break; } $counter++; // queue_dst ID is SMS Log ID $c_smslog_id = $db_row2['id']; $c_dst = $db_row2['dst']; $c_flag = 2; $c_ok = false; _log("sending queue_code:" . $c_queue_code . " smslog_id:" . $c_smslog_id . " to:" . $c_dst . " sms_count:" . $c_sms_count . " counter:" . $counter, 2, "sendsmsd"); $ret = sendsms_process($c_smslog_id, $c_sender_id, $c_footer, $c_dst, $c_message, $c_uid, $c_gpid, $c_sms_type, $c_unicode, $c_queue_code, $c_smsc); $c_dst = $ret['to']; if ($ret['status']) { $c_ok = true; $c_flag = 1; // add to throttle counter sendsms_throttle_count(0, $c_sms_size); } _log("result queue_code:" . $c_queue_code . " to:" . $c_dst . " flag:" . $c_flag . " smslog_id:" . $c_smslog_id, 2, "sendsmsd"); $db_query3 = "UPDATE " . _DB_PREF_ . "_tblSMSOutgoing_queue_dst SET flag='{$c_flag}' WHERE id='{$c_smslog_id}'"; $db_result3 = dba_query($db_query3); $ok[] = $c_ok; $to[] = $c_dst; $smslog_id[] = $c_smslog_id; $queue[] = $c_queue_code; $counts[] = $c_sms_count; // check throttle limit (number of sent SMS per hour) if (sendsms_throttle_isoverlimit(0)) { break; } } $db_query = "SELECT count(*) AS count FROM " . _DB_PREF_ . "_tblSMSOutgoing_queue_dst WHERE queue_id='{$c_queue_id}' AND NOT flag ='0'"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); // destinations processed $dst_processed = (int) ($db_row['count'] ? $db_row['count'] : 0); // number of SMS processed $sms_processed = $dst_processed * $c_sms_size; // check whether SMS processed is >= stated SMS count in queue // if YES then processing queue is finished if ($sms_processed >= $c_sms_count) { $dt = core_get_datetime(); $db_query5 = "UPDATE " . _DB_PREF_ . "_tblSMSOutgoing_queue SET flag='1', datetime_update='" . $dt . "' WHERE id='{$c_queue_id}'"; if ($db_result5 = dba_affected_rows($db_query5)) { _log("finish processing queue_code:" . $c_queue_code . " uid:" . $c_uid . " sender_id:" . $c_sender_id . " queue_count:" . $c_queue_count . " sms_count:" . $c_sms_count, 2, "sendsmsd"); } else { _log("fail to finalize process queue_code:" . $c_queue_code . " uid:" . $c_uid . " sender_id:" . $c_sender_id . " queue_count:" . $c_queue_count . " sms_count:" . $c_sms_count . " sms_processed:" . $sms_processed, 2, "sendsmsd"); } } else { _log("partially processing queue_code:" . $c_queue_code . " uid:" . $c_uid . " sender_id:" . $c_sender_id . " queue_count:" . $c_queue_count . " sms_count:" . $c_sms_count . " sms_processed:" . $sms_processed . " counter:" . $counter, 2, "sendsmsd"); } } } return array($ok, $to, $smslog_id, $queue, $counts); }
function sendsmsd($single_queue = '') { global $core_config; if ($single_queue) { $queue_sql = "AND queue_code='" . $single_queue . "'"; logger_print("single queue queue_code:" . $single_queue, 3, "sendsmsd"); } $db_query = "SELECT * FROM " . _DB_PREF_ . "_tblSMSOutgoing_queue WHERE flag='0' " . $queue_sql; $db_result = dba_query($db_query); while ($db_row = dba_fetch_array($db_result)) { $c_queue_id = $db_row['id']; $c_queue_code = $db_row['queue_code']; $c_sender_id = $db_row['sender_id']; $c_footer = $db_row['footer']; $c_message = $db_row['message']; $c_uid = $db_row['uid']; $c_gpid = 0; $c_sms_type = $db_row['sms_type']; $c_unicode = $db_row['unicode']; logger_print("start processing queue_code:" . $c_queue_code . " uid:" . $c_uid . " sender_id:" . $c_sender_id, 3, "sendsmsd"); $db_query2 = "SELECT * FROM " . _DB_PREF_ . "_tblSMSOutgoing_queue_dst WHERE queue_id='{$c_queue_id}' AND flag='0'"; $db_result2 = dba_query($db_query2); while ($db_row2 = dba_fetch_array($db_result2)) { $c_id = $db_row2['id']; $c_dst = $db_row2['dst']; $c_flag = 2; logger_print("sending queue_code:" . $c_queue_code . " to:" . $c_dst, 3, "sendsmsd"); $ret = sendsms($c_sender_id, $c_footer, $c_dst, $c_message, $c_uid, $c_gpid, $c_sms_type, $c_unicode); if ($ret['status']) { $c_flag = 1; } logger_print("result queue_code:" . $c_queue_code . " to:" . $c_dst . " flag:" . $c_flag, 3, "sendsmsd"); $db_query3 = "UPDATE " . _DB_PREF_ . "_tblSMSOutgoing_queue_dst SET flag='{$c_flag}' WHERE id='{$c_id}'"; $db_result3 = dba_query($db_query3); } $db_query5 = "UPDATE " . _DB_PREF_ . "_tblSMSOutgoing_queue SET flag='1', datetime_update='" . $core_config['datetime']['now'] . "' WHERE id='{$c_queue_id}'"; if ($db_result5 = dba_affected_rows($db_query5)) { logger_print("finish processing queue_code:" . $c_queue_code . " uid:" . $c_uid . " sender_id:" . $c_sender_id, 3, "sendsmsd"); } else { logger_print("fail to finalize process queue_code:" . $c_queue_code . " uid:" . $c_uid . " sender_id:" . $c_sender_id, 3, "sendsmsd"); } } }
$content .= "\n\t</tbody></table>\n\t<table width=100% cellpadding=0 cellspacing=0 border=0>\n\t<tr>\n\t <td width=100% colspan=2 align=right>\n\t\t<input type=hidden name=item_count value=\"{$item_count}\">\n\t\t<input type=submit value=\"" . _('Delete selection') . "\" class=button />\n\t </td>\n\t</tr>\n\t</table>\t\n\t</form>\n\t<p>{$nav_pages}</p>\n\t"; if ($err) { echo "<div class=error_string>{$err}</div><br><br>"; } echo $content; break; case "all_outgoing_del": if ($slid) { $db_query = "UPDATE " . _DB_PREF_ . "_tblSMSOutgoing SET c_timestamp='" . mktime() . "',flag_deleted='1' WHERE smslog_id='{$slid}'"; $db_result = dba_affected_rows($db_query); if ($db_result > 0) { $err = _('Selected outgoing SMS has been deleted'); } else { $err = _('Fail to delete SMS'); } } header("Location: index.php?app=menu&inc=all_outgoing&op=all_outgoing&err=" . urlencode($err)); break; case "act_del": $item_count = $_POST['item_count']; for ($i = 1; $i <= $item_count; $i++) { $chkid = $_POST['chkid' . $i]; $slid = $_POST['slid' . $i]; if ($chkid == "on" && $slid) { $db_query = "UPDATE " . _DB_PREF_ . "_tblSMSOutgoing SET c_timestamp='" . mktime() . "',flag_deleted='1' WHERE smslog_id='{$slid}'"; $db_result = dba_affected_rows($db_query); } } header("Location: index.php?app=menu&inc=all_outgoing&op=all_outgoing&err=" . urlencode(_('Selected outgoing SMS has been deleted'))); break; }
} for ($i = 1; $i <= 7; $i++) { $content .= "\n\t <tr>\n\t\t<td width=190>" . _('SMS autoreply scenario parameter') . " {$i}</td><td>:</td><td><input type=text size=20 maxlength=20 name=edit_autoreply_scenario_param{$i} value=\"" . ${"edit_autoreply_scenario_param" . $i} . "\">\n</td>\n\t </tr>"; } $edit_autoreply_scenario_result = $db_row['autoreply_scenario_result']; $content .= "\n\t <tr>\n\t\t<td>" . _('SMS autoreply scenario replies with') . "</td><td>:</td><td><input type=text size=60 name=edit_autoreply_scenario_result value=\"{$edit_autoreply_scenario_result}\"></td>\n\t </tr>\t \t\n\t </table>\n\t <p><input type=submit class=button value=\"" . _('Save') . "\">\n\t <p><input type=button class=button value=" . _('Back') . " onClick=javascript:linkto('index.php?app=menu&inc=feature_sms_autoreply&op=sms_autoreply_manage&autoreply_id={$autoreply_id}')>\n\t </form>\n\t"; echo $content; break; case "sms_autoreply_scenario_edit_yes": $autoreply_scenario_id = $_POST['autoreply_scenario_id']; $autoreply_id = $_POST['autoreply_id']; $edit_autoreply_scenario_result = $_POST['edit_autoreply_scenario_result']; for ($i = 1; $i <= 7; $i++) { ${"edit_autoreply_scenario_param" . $i} = strtoupper($_POST['edit_autoreply_scenario_param' . $i]); } if ($edit_autoreply_scenario_result) { for ($i = 1; $i <= 7; $i++) { $autoreply_scenario_param_list .= "autoreply_scenario_param" . $i . "='" . ${"edit_autoreply_scenario_param" . $i} . "',"; } $db_query = "\n\t\tUPDATE " . _DB_PREF_ . "_featureAutoreply_scenario \n\t\tSET c_timestamp='" . mktime() . "'," . $autoreply_scenario_param_list . "autoreply_scenario_result='{$edit_autoreply_scenario_result}' \n\t\tWHERE autoreply_id='{$autoreply_id}' AND autoreply_scenario_id='{$autoreply_scenario_id}'\n\t "; if ($db_result = @dba_affected_rows($db_query)) { $error_string = _('SMS autoreply scenario has been edited'); } else { $error_string = _('Fail to edit SMS autoreply scenario'); } } else { $error_string = _('You must fill all fields'); } header("Location: index.php?app=menu&inc=feature_sms_autoreply&op=sms_autoreply_scenario_edit&autoreply_id={$autoreply_id}&autoreply_scenario_id={$autoreply_scenario_id}&err=" . urlencode($error_string)); break; }