/** * Implementations of hook keyword_isavail() * * @param string $keyword * Keyword * @param string $sms_receiver * Receiver number * @return boolean TRUE if keyword is available */ function sms_custom_hook_keyword_isavail($keyword, $sms_receiver) { $found = FALSE; $keyword = trim(strtoupper($keyword)); $sms_receiver = trim($sms_receiver); // check with receiver number empty, a catchall $db_query = "SELECT custom_id FROM " . _DB_PREF_ . "_featureCustom WHERE (custom_keyword='{$keyword}' OR custom_keyword LIKE '{$keyword} %' OR custom_keyword LIKE '% {$keyword}' OR custom_keyword LIKE '% {$keyword} %') AND sms_receiver=''"; if ($db_result = dba_num_rows($db_query)) { $found = TRUE; } // if no cathall if (!$found) { if ($sms_receiver) { $db_query = "SELECT custom_id FROM " . _DB_PREF_ . "_featureCustom WHERE (custom_keyword='{$keyword}' OR custom_keyword LIKE '{$keyword} %' OR custom_keyword LIKE '% {$keyword}' OR custom_keyword LIKE '% {$keyword} %') AND sms_receiver='{$sms_receiver}'"; } else { $db_query = "SELECT custom_id FROM " . _DB_PREF_ . "_featureCustom WHERE (custom_keyword='{$keyword}' OR custom_keyword LIKE '{$keyword} %' OR custom_keyword LIKE '% {$keyword}' OR custom_keyword LIKE '% {$keyword} %')"; } if ($db_result = dba_num_rows($db_query)) { $found = TRUE; } } // found means not available $ret = !$found; return $ret; }
function inboxgroup_hook_checkavailablekeyword($keyword) { $ok = true; $db_query = "SELECT id FROM " . _DB_PREF_ . "_featureInboxgroup WHERE keywords LIKE '%{$keyword}%'"; if ($db_result = dba_num_rows($db_query)) { $ok = false; } return $ok; }
function sms_autoreply_hook_checkavailablekeyword($keyword) { $ok = true; $db_query = "SELECT autoreply_id FROM " . _DB_PREF_ . "_featureAutoreply WHERE autoreply_keyword='{$keyword}'"; if ($db_result = dba_num_rows($db_query)) { $ok = false; } return $ok; }
/** * Implementations of hook keyword_isavail() * * @param $keyword keyword_isavail() * will insert keyword for checking to the hook here * @return TRUE if keyword is available */ function sms_quiz_hook_keyword_isavail($keyword) { $ok = true; $db_query = "SELECT quiz_id FROM " . _DB_PREF_ . "_featureQuiz WHERE quiz_keyword='{$keyword}'"; if ($db_result = dba_num_rows($db_query)) { $ok = false; } return $ok; }
function sms_board_hook_checkavailablekeyword($keyword) { $ok = true; $db_query = "SELECT board_id FROM " . _DB_PREF_ . "_featureBoard WHERE board_keyword='{$keyword}'"; if ($db_result = dba_num_rows($db_query)) { $ok = false; } return $ok; }
function inboxgroup_hook_keyword_isavail($keyword) { $ok = true; $db_query = "SELECT id FROM " . _DB_PREF_ . "_featureInboxgroup WHERE keywords LIKE '%{$keyword}%' AND deleted='0'"; if ($db_result = dba_num_rows($db_query)) { $ok = false; } return $ok; }
function sms_poll_hook_webservices_output($ta, $requests) { global $http_path, $themes_module; $keyword = $requests['keyword']; $db_query = "SELECT poll_id,poll_title FROM " . _DB_PREF_ . "_featurePoll WHERE poll_keyword='{$keyword}'"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); $poll_id = $db_row['poll_id']; $poll_title = $db_row['poll_title']; $db_query = "SELECT result_id FROM " . _DB_PREF_ . "_featurePoll_log WHERE poll_id='{$poll_id}'"; $total_voters = @dba_num_rows($db_query); if ($poll_id) { $mult = $requests['mult']; $bodybgcolor = $requests['bodybgcolor']; if (!isset($mult)) { $mult = "2"; } if (!isset($bodybgcolor)) { $bodybgcolor = "#FEFEFE"; } $content = "\n\t <html>\n\t <head>\n\t <title>{$web_title}</title>\n\t <meta name=\"author\" content=\"http://playsms.org\">\n\t <link rel=\"stylesheet\" type=\"text/css\" href=\"" . $http_path['themes'] . "/" . $themes_module . "/jscss/common.css\">\n\t </head>\n\t <body bgcolor=\"{$bodybgcolor}\" topmargin=\"0\" leftmargin\"0\">\n\t <table cellpadding=1 cellspacing=1 border=0>\n\t <tr><td colspan=2 width=100% class=box_text><font size=-2>{$poll_title}</font></td></tr>\n\t"; $db_query = "SELECT * FROM " . _DB_PREF_ . "_featurePoll_choice WHERE poll_id='{$poll_id}' ORDER BY choice_keyword"; $db_result = dba_query($db_query); while ($db_row = dba_fetch_array($db_result)) { $choice_id = $db_row['choice_id']; $choice_title = $db_row['choice_title']; $choice_keyword = $db_row['choice_keyword']; $db_query1 = "SELECT result_id FROM " . _DB_PREF_ . "_featurePoll_log WHERE poll_id='{$poll_id}' AND choice_id='{$choice_id}'"; $choice_voted = @dba_num_rows($db_query1); if ($total_voters) { $percentage = round($choice_voted / $total_voters * 100); } else { $percentage = "0"; } $content .= "\n\t\t<tr>\n\t\t <td width=90% nowrap class=box_text valign=middle align=left>\n\t\t\t<font size=-2>[' <b>{$choice_keyword}</b> '] {$choice_title}</font>\n\t\t </td>\n\t\t <td width=10% nowrap class=box_text valign=middle align=right>\n\t\t\t<font size=-2>{$percentage}%, {$choice_voted}</font>\n\t\t </td>\n\t\t</tr>\n\t\t<tr>\n\t\t <td width=100% nowrap class=box_text valign=middle align=left colspan=2>\n\t\t\t<img src=\"" . $http_path['themes'] . "/" . $themes_module . "/images/bar.gif\" height=\"12\" width=\"" . $mult * $percentage . "\" alt=\"" . $percentage . "% ({$choice_voted})\"></font><br>\n\t\t </td>\n\t\t</tr>\n\t "; } $content .= "\n\t <tr><td colspan=2><font size=-2><b>Total: {$total_voters}</b></font></td></tr>\n\t </table>\n\t </body>\n\t </html>\n\t"; $ret = $content; } return $ret; }
$content .= "\n\t\t\t</tr></thead>\n\t\t\t<tbody>"; $i = 0; if (!auth_isadmin()) { $query_user_only = "WHERE uid='" . $user_config['uid'] . "'"; } $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureSubscribe " . $query_user_only . " ORDER BY subscribe_id"; $db_result = dba_query($db_query); while ($db_row = dba_fetch_array($db_result)) { if ($owner = user_uid2username($db_row['uid'])) { $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureSubscribe_member WHERE subscribe_id = '" . $db_row['subscribe_id'] . "'"; $members = @dba_num_rows($db_query); if (!$members) { $members = 0; } $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureSubscribe_msg WHERE subscribe_id = '" . $db_row['subscribe_id'] . "'"; $messages = @dba_num_rows($db_query); if (!$messages) { $messages = 0; } $subscribe_status = "<a href=\"" . _u('index.php?app=main&inc=feature_sms_subscribe&op=sms_subscribe_status&subscribe_id=' . $db_row['subscribe_id'] . '&ps=1') . "\"><span class=status_disabled /></a>"; if ($db_row['subscribe_enable']) { $subscribe_status = "<a href=\"" . _u('index.php?app=main&inc=feature_sms_subscribe&op=sms_subscribe_status&subscribe_id=' . $db_row['subscribe_id'] . '&ps=0') . "\"><span class=status_enabled /></a>"; } $action = "<a href=\"" . _u('index.php?app=main&inc=feature_sms_subscribe&op=sms_subscribe_edit&subscribe_id=' . $db_row['subscribe_id']) . "\">" . $icon_config['edit'] . "</a> "; $action .= "<a href=\"javascript: ConfirmURL('" . _('Are you sure you want to delete SMS subscribe ?') . " (" . _('keyword') . ": " . $db_row['subscribe_keyword'] . ")','" . _u('index.php?app=main&inc=feature_sms_subscribe&op=sms_subscribe_del&subscribe_id=' . $db_row['subscribe_id']) . "')\">" . $icon_config['delete'] . "</a>"; if (auth_isadmin()) { $option_owner = "<td>{$owner}</td>"; } $i++; $content .= "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>" . $db_row['subscribe_keyword'] . "</td>\n\t\t\t\t\t\t<td><a href=\"" . _u('index.php?app=main&inc=feature_sms_subscribe&op=mbr_list&subscribe_id=' . $db_row['subscribe_id']) . "\">" . $members . "</a></td>\n\t\t\t\t\t\t<td><a href=\"" . _u('index.php?app=main&inc=feature_sms_subscribe&op=msg_list&subscribe_id=' . $db_row['subscribe_id']) . "\">" . $messages . "</a></td>\n\t\t\t\t\t\t" . $option_owner . "\n\t\t\t\t\t\t<td>{$subscribe_status}</td>\n\t\t\t\t\t\t<td>{$action}</td>\n\t\t\t\t\t</tr>"; }
$db_query1 = "SELECT * FROM playsms_tblUserPhonebook WHERE gpid='$gpid' AND uid='$uid'"; $db_result1 = dba_query($db_query1); while ($db_row1 = dba_fetch_array($db_result1)) { $list_of_phonenumber .= "[<a href=\"javascript:ConfirmURL('Are you sure you want to delete mobiles number `$db_row1[p_num]` owned by `$db_row1[p_desc]` ?','menu.php?inc=phone_del&op=user&pid=$db_row1[pid]')\">x</a>] <font size=-1>Number: <font color=darkgreen>$db_row1[p_num]</font> - Owner: <font color=darkgreen>$db_row1[p_desc]</font> [<a href=\"javascript: PopupSendSms('PV','$db_row1[p_num]')\">send</a>]<br>\n"; } $list_of_phonenumber .= "<br>"; } */ $db_query = "SELECT * FROM playsms_tblUserGroupPhonebook WHERE uid='{$uid}' ORDER BY gp_name"; $db_result = dba_query($db_query); while ($db_row = dba_fetch_array($db_result)) { $gpid = $db_row[gpid]; $fm_name = "fm_phonebook_" . $db_row[gp_code]; $db_query1 = "SELECT gpidpublic FROM playsms_tblUserGroupPhonebook_public WHERE uid='{$uid}' AND gpid='{$gpid}'"; $db_result1 = dba_num_rows($db_query1); if ($db_result1 > 0) { $option_public = "<a href=\"menu.php?inc=phonebook&op=hide_from_public&gpid={$gpid}\">[ hide from public ]</a>"; } else { $option_public = "<a href=\"menu.php?inc=phonebook&op=share_this_group&gpid={$gpid}\">[ share this group ]</a>"; } $option_group_edit = "<a href=\"menu.php?inc=dir_edit&op=edit&gpid={$gpid}\">[ edit ]</a>"; // WWW 041208 $option_group_export = "<a href=\"menu.php?inc=phonebook_exim&op=export&gpid={$gpid}\">[ export ]</a>"; $option_group_import = "<a href=\"menu.php?inc=phonebook_exim&op=import&gpid={$gpid}\">[ import ]</a>"; $list_of_phonenumber .= "\r\n\t\t<form name=\"{$fm_name}\" action=\"menu.php?inc=phonebook\" method=post>\r\n\t\t<p>[<a href=\"javascript:ConfirmURL('Are you sure you want to delete group `{$db_row['gp_name']}` with all its members ?','menu.php?inc=phone_del&op=group&gpid={$gpid}')\">x</a>] Group: {$db_row['gp_name']} - code: {$db_row['gp_code']} <a href=\"javascript: PopupSendSms('BC','{$db_row['gp_code']}')\">[ send ]</a> {$option_public} {$option_group_edit} {$option_group_export} {$option_group_import}\r\n\t\t<table width=100% cellpadding=0 cellspacing=0 border=1>\r\n\t\t<tr>\r\n\t\t <td class=box_title width=4> * </td>\r\n\t\t <td class=box_title width=35%>Owner</td>\r\n\t\t <td class=box_title width=25%>Number</td>\r\n\t\t <td class=box_title width=40%>Email</td>\r\n\t\t <td class=box_title width=4><input type=checkbox onclick=CheckUncheckAll(document." . $fm_name . ")></td>\r\n\t\t</tr>\r\n\t "; $db_query1 = "SELECT * FROM playsms_tblUserPhonebook WHERE gpid='{$gpid}' AND uid='{$uid}' ORDER BY p_desc"; $db_result1 = dba_query($db_query1); $i = 0; while ($db_row1 = dba_fetch_array($db_result1)) { // $list_of_phonenumber .= "[<a href=\"javascript:ConfirmURL('Are you sure you want to delete mobiles number `$db_row1[p_num]` owned by `$db_row1[p_desc]` ?','menu.php?inc=phone_del&op=user&pid=$db_row1[pid]')\">x</a>] <font size=-1>Number: <font color=darkgreen>$db_row1[p_num]</font> - Owner: <font color=darkgreen>$db_row1[p_desc]</font> [<a href=\"javascript: PopupSendSms('PV','$db_row1[p_num]')\">send</a>]<br>\n";
} } else { $items = array('uid' => $uid, 'name' => $name, 'mobile' => sendsms_getvalidnumber($mobile), 'email' => $email, 'tags' => $tags); if ($c_pid = dba_add(_DB_PREF_ . '_featurePhonebook', $items)) { if ($gpid) { $save_to_group = TRUE; } else { _log('contact added pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 3, 'phonebook_add'); } } else { _log('fail to add contact pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email . ' tags:[' . $tags . ']', 3, 'phonebook_add'); } } if ($save_to_group && $gpid) { $db_query = "SELECT id FROM " . _DB_PREF_ . "_featurePhonebook_group_contacts WHERE gpid='" . $gpid . "' AND pid='" . $c_pid . "' LIMIT 1"; if (dba_num_rows($db_query) > 0) { _log('contact already in the group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 3, 'phonebook_add'); } else { $items = array('gpid' => $gpid, 'pid' => $c_pid); if (dba_add(_DB_PREF_ . '_featurePhonebook_group_contacts', $items)) { _log('contact added to group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 3, 'phonebook_add'); } else { _log('contact added but fail to save in group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 3, 'phonebook_add'); } } } // $i++; // _log("no:".$i." gpid:".$gpid." uid:".$uid." name:".$name." mobile:".$mobile." email:".$email, 3, "phonebook import"); } unset($gpid); }
$poll_title = $db_row['poll_title']; if ($poll_title) { $db_query = "DELETE FROM " . _DB_PREF_ . "_featurePoll WHERE poll_title='{$poll_title}'"; if (@dba_affected_rows($db_query)) { $error_string = _('SMS poll with all its messages has been deleted') . " (" . _('title') . ": `{$poll_title}`)"; } } header("Location: index.php?app=menu&inc=feature_sms_poll&op=sms_poll_list&err=" . urlencode($error_string)); break; case "sms_poll_choice_add": $poll_id = $_POST['poll_id']; $add_choice_title = $_POST['add_choice_title']; $add_choice_keyword = strtoupper($_POST['add_choice_keyword']); if ($poll_id && $add_choice_title && $add_choice_keyword) { $db_query = "SELECT choice_id FROM " . _DB_PREF_ . "_featurePoll_choice WHERE poll_id='{$poll_id}' AND choice_keyword='{$add_choice_keyword}'"; $db_result = @dba_num_rows($db_query); if (!$db_result) { $db_query = "\n\t\t INSERT INTO " . _DB_PREF_ . "_featurePoll_choice \n\t\t (poll_id,choice_title,choice_keyword)\n\t\t VALUES ('{$poll_id}','{$add_choice_title}','{$add_choice_keyword}')\n\t\t"; if ($db_result = @dba_insert_id($db_query)) { $error_string = _('Choice has been added') . " (" . _('keyword') . ": `{$add_choice_keyword}`)"; } } else { $error_string = _('Choice already exists') . " (" . _('keyword') . ": `{$add_choice_keyword}`)"; } } else { $error_string = _('You must fill all fields'); } header("Location: index.php?app=menu&inc=feature_sms_poll&op=sms_poll_edit&poll_id={$poll_id}&err=" . urlencode($error_string)); break; case "sms_poll_choice_del": $poll_id = $_REQUEST['poll_id'];
function kannel_gw_set_delivery_status($smslog_id, $uid, $kannel_dlr) { $playsms_dlr = convertKannelDlrToPlaysmsDlr($kannel_dlr); setsmsdeliverystatus($smslog_id, $uid, $playsms_dlr); // log dlr $db_query = "SELECT kannel_dlr_id FROM playsms_gwmodKannel_dlr WHERE smslog_id='{$smslog_id}'"; $db_result = dba_num_rows($db_query); if ($db_result > 0) { $db_query = "UPDATE playsms_gwmodKannel_dlr SET kannel_dlr_type='{$kannel_dlr}' WHERE smslog_id='{$smslog_id}'"; $db_result = dba_query($db_query); } else { $db_query = "INSERT INTO playsms_gwmodKannel_dlr (smslog_id,kannel_dlr_type) VALUES ('{$smslog_id}','{$kannel_dlr}')"; $db_result = dba_query($db_query); } }
$bodybgcolor = $_GET[bodybgcolor]; if (!isset($mult)) { $mult = "2"; } if (!isset($bodybgcolor)) { $bodybgcolor = "#FEFEFE"; } $content = "\n\t\t\t\t<html>\n\t\t\t\t<head>\n\t\t\t\t<title>{$web_title}</title>\n\t\t\t\t<meta name=\"author\" content=\"http://playsms.sourceforge.net\">\n\t\t\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"./inc/jscss/common.css\">\n\t\t\t\t</head>\n\t\t\t\t<body bgcolor=\"{$bodybgcolor}\" topmargin=\"0\" leftmargin\"0\">\n\t\t\t\t<table cellpadding=1 cellspacing=1 border=0>\n\t\t\t\t<tr><td colspan=2 width=100% class=box_text><font size=-2>{$poll_title}</font></td></tr>\n\t\t\t "; $db_query = "SELECT * FROM playsms_featPoll_choice WHERE poll_id='{$poll_id}' ORDER BY choice_code"; $db_result = dba_query($db_query); while ($db_row = dba_fetch_array($db_result)) { $choice_id = $db_row[choice_id]; $choice_title = $db_row[choice_title]; $choice_code = $db_row[choice_code]; $db_query1 = "SELECT result_id FROM playsms_featPoll_result WHERE poll_id='{$poll_id}' AND choice_id='{$choice_id}'"; $choice_voted = @dba_num_rows($db_query1); if ($total_voters) { $percentage = round($choice_voted / $total_voters * 100); } else { $percentage = "0"; } $content .= "\n\t\t\t\t\t <tr>\n\t\t\t\t\t\t<td width=90% nowrap class=box_text valign=middle align=left>\n\t\t\t\t\t\t <font size=-2>[ <b>{$choice_code}</b> ] {$choice_title}</font>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<td width=10% nowrap class=box_text valign=middle align=right>\n\t\t\t\t\t\t <font size=-2>{$percentage}%, {$choice_voted}</font>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t </tr>\n\t\t\t\t\t <tr>\n\t\t\t\t\t\t<td width=100% nowrap class=box_text valign=middle align=left colspan=2>\n\t\t\t\t\t\t <img src=\"./images/bar.gif\" height=\"12\" width=\"" . $mult * $percentage . "\" alt=\"" . $percentage . "% ({$choice_voted})\"></font><br>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t </tr>\n\t\t\t\t\t"; } $content .= "\n\t\t\t\t<tr><td colspan=2><font size=-2><b>Total: {$total_voters}</b></font></td></tr>\n\t\t\t\t</table>\n\t\t\t\t</body>\n\t\t\t\t</html>\n\t\t\t "; echo $content; } break; case "board": default: // Use code, tag deprecated $code = $_GET[code];
function setsmsincomingaction($sms_datetime, $sms_sender, $message) { global $system_from; $ok = false; $keywords = explode(' ', $message); $target_code = strtoupper($keywords[0]); switch ($target_code) { case 'BC': $array_target_group = explode(" ", $message); $target_group = strtoupper(trim($array_target_group[0])); $message = $array_target_group[1]; for ($i = 2; $i < count($array_target_group); $i++) { $message .= " " . $array_target_group[$i]; } if (send2group($sms_sender, $target_group, $message)) { $ok = true; } break; case 'PV': $array_target_user = explode(" ", $message); $target_user = strtoupper(trim($array_target_user[0])); $message = $array_target_user[1]; for ($i = 2; $i < count($array_target_user); $i++) { $message .= " " . $array_target_user[$i]; } if (insertsmstoinbox($sms_datetime, $sms_sender, $target_user, $message)) { $ok = true; } break; default: // try as autoreply $ok = processAutoreply($sms_datetime, $sms_sender, $message); // maybe its for sms poll if (!$ok) { $db_query = "SELECT poll_id FROM playsms_featPoll WHERE poll_code='{$target_code}'"; if ($db_result = dba_num_rows($db_query)) { $ok = savepoll($sms_sender, $target_code, $message); } } // or maybe its for sms command if (!$ok) { $db_query = "SELECT command_id FROM playsms_featCommand WHERE command_code='{$target_code}'"; if ($db_result = dba_num_rows($db_query)) { $ok = execcommand($sms_datetime, $sms_sender, $target_code, $message); } } // or maybe its for sms custom if (!$ok) { $db_query = "SELECT custom_id FROM playsms_featCustom WHERE custom_code='{$target_code}'"; if ($db_result = dba_num_rows($db_query)) { $ok = processcustom($sms_datetime, $sms_sender, $target_code, $message); } } // its for sms board if (!$ok) { $db_query = "SELECT board_id FROM playsms_featBoard WHERE board_code='{$target_code}'"; if ($db_result = dba_num_rows($db_query)) { $ok = insertsmstodb($sms_datetime, $sms_sender, $target_code, $message); } } // if its from the known system messsage sender, // then process it as a system message $syssenders = explode(',', $system_from); foreach ($syssenders as $syssender) { if (0 == strcasecmp($sms_sender, $syssender)) { $saveToInbox = true; $ok = processSystemMessage($sms_sender, "{$target_code} {$message}"); } } break; } if (!$ok) { $saveToInbox = true; // If all else failed, then check the autoreplies again, // this time with a more sophisticated match. // // Note that since this can result in autoreply error messages, // we only do this if its a regular number, not a shortcode or // some special cell provider number // (if we don't check we can get into an infinite loop, us // sending an error message to another autmoated system, which // sends us an error message...) if (strlen($sms_sender) > 4 && ereg('^\\+?[0-9]+$', $sms_sender)) { $ok = processAutoreply($sms_datetime, $sms_sender, $message, false); $saveToInbox = !$ok; } } if ($saveToInbox) { error_log("saving to inbox..."); if (insertsmstoinbox($sms_datetime, $sms_sender, "admin", $message)) { $ok = true; } } return $ok; }
function sms_subscribe_handle($c_uid, $sms_datetime, $sms_sender, $subscribe_keyword, $subscribe_param = '') { global $core_config; $ok = false; $subscribe_param = strtoupper($subscribe_param); $subscribe_keyword = strtoupper($subscribe_keyword); $username = uid2username($c_uid); $sms_to = $sms_sender; // we are replying to this sender $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureSubscribe WHERE subscribe_keyword='{$subscribe_keyword}'"; $db_result = dba_query($db_query); if ($db_row = dba_fetch_array($db_result)) { if (!$db_row['subscribe_enable']) { $message = _('Subscribe service inactive'); //list($ok,$to,$smslog_id) = sendsms_pv($username, $sms_to, $message); //$ok = $ok[0]; $unicode = 0; if (function_exists('mb_detect_encoding')) { $encoding = mb_detect_encoding($message, 'auto'); if ($encoding != 'ASCII') { $unicode = 1; } } $ret = sendsms($core_config['main']['cfg_gateway_number'], '', $sms_to, $message, $c_uid, 0, 'text', $unicode); $ok = $ret['status']; return $ok; } } $c_uid = $db_row['uid']; $subscribe_id = $db_row['subscribe_id']; $num_rows = dba_num_rows($db_query); if ($num_rows) { $msg1 = $db_row['subscribe_msg']; $msg2 = $db_row['unsubscribe_msg']; $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureSubscribe_member WHERE member_number='{$sms_to}' AND subscribe_id='{$subscribe_id}'"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); $num_rows = dba_num_rows($db_query); if ($num_rows == 0) { $member = false; $db_query = "INSERT INTO " . _DB_PREF_ . "_featureSubscribe_member (subscribe_id,member_number,member_since) VALUES ('{$subscribe_id}','{$sms_to}',now())"; switch ($subscribe_param) { case "ON": $message = $msg1; $logged = dba_query($db_query); $ok = true; break; case "IN": $message = $msg1; $logged = dba_query($db_query); $ok = true; break; case "REG": $message = $msg1; $logged = dba_query($db_query); $ok = true; break; case "OFF": $message = _('You are not a member'); $ok = true; break; case "OUT": $message = _('You are not a member'); $ok = true; break; case "UNREG": $message = _('You are not a member'); $ok = true; break; default: $message = _('Unknown SMS format'); $ok = true; break; } } else { $member = true; $db_query = "DELETE FROM " . _DB_PREF_ . "_featureSubscribe_member WHERE member_number='{$sms_to}' AND subscribe_id='{$subscribe_id}'"; switch ($subscribe_param) { case "OFF": $message = $msg2; $deleted = dba_query($db_query); if ($deleted) { $ok = true; } break; case "OUT": $message = $msg2; $deleted = dba_query($db_query); if ($deleted) { $ok = true; } break; case "UNREG": $message = $msg2; $deleted = dba_query($db_query); if ($deleted) { $ok = true; } break; case "ON": $message = _('You already a member'); $ok = true; break; case "IN": $message = _('You already a member'); $ok = true; break; case "REG": $message = _('You already a member'); $ok = true; break; default: $message = _('Unknown sms format'); $ok = true; break; } } list($ok, $to, $smslog_id) = sendsms_pv($username, $sms_to, $message); $ok = $ok[0]; } else { $ok = false; } return $ok; }
function sms_subscribe_handle($list, $sms_datetime, $sms_sender, $subscribe_keyword, $subscribe_param = '', $sms_receiver = '', $smsc = '', $raw_message = '') { global $core_config; $c_uid = $list['uid']; $subscribe_keyword = strtoupper(trim($subscribe_keyword)); $subscribe_param = trim($subscribe_param); $username = user_uid2username($c_uid); _log("username:"******" sender:" . $sms_sender . " keyword:" . $subscribe_keyword . " param:" . $subscribe_param, 3, "sms_subscribe"); $subscribe_accept_param = $list['subscribe_param']; $subscribe_reject_param = $list['unsubscribe_param']; $forward_param = $list['forward_param']; $smsc = gateway_decide_smsc($smsc, $list['smsc']); // for later use $subscribe_param_array = explode(" ", $subscribe_param); $forward_sms = ''; for ($i = 1; $i < sizeof($subscribe_param_array); $i++) { $forward_sms .= $subscribe_param_array[$i] . ' '; } $forward_sms = substr($forward_sms, 0, -1); // check for BC sub-keyword $subscribe_id = $list['subscribe_id']; $c_arr = explode(' ', $subscribe_param); // check for BC/forward param $bc = trim(strtoupper($c_arr[0])); if (($bc == 'BC' || $forward_param && $bc == $forward_param) && $c_uid == user_mobile2uid($sms_sender)) { for ($i = 1; $i < count($c_arr); $i++) { $msg0 .= $c_arr[$i] . ' '; } $message = trim($msg0); $bc_to = ''; $db_query1 = "SELECT member_number FROM " . _DB_PREF_ . "_featureSubscribe_member WHERE subscribe_id = '{$subscribe_id}'"; $db_result1 = dba_query($db_query1); while ($db_row1 = dba_fetch_array($db_result1)) { $bc_to[] = $db_row1['member_number']; } if (is_array($bc_to) && count($bc_to) > 0) { $unicode = core_detect_unicode($message); _log('BC sender:' . $sms_sender . ' keyword:' . $subscribe_keyword . ' count:' . count($bc_to) . ' m:' . $message, 3, "sms_subscribe"); $message = addslashes($message); list($ok, $to, $smslog_id, $queue) = sendsms_helper($username, $bc_to, $message, 'text', $unicode, $smsc, TRUE); return true; } else { return false; } } // check for subscribe/unsubscribe sub-keyword $ok = false; $subscribe_param = trim(strtoupper($subscribe_param)); if ($sms_to = $sms_sender) { $msg1 = addslashes($list['subscribe_msg']); $msg2 = addslashes($list['unsubscribe_msg']); $unknown_format_msg = addslashes($list['unknown_format_msg']); $already_member_msg = addslashes($list['already_member_msg']); $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureSubscribe_member WHERE member_number='{$sms_to}' AND subscribe_id='{$subscribe_id}'"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); $num_rows = dba_num_rows($db_query) ? 1 : 0; if ($num_rows == 0) { $member = false; switch ($subscribe_param) { case "ON": case "IN": case "REG": case $subscribe_accept_param: $message = $msg1; $db_query = "INSERT INTO " . _DB_PREF_ . "_featureSubscribe_member (subscribe_id,member_number,member_since) VALUES ('{$subscribe_id}','{$sms_to}','" . core_get_datetime() . "')"; $logged = dba_query($db_query); _log('REG SUCCESS sender:' . $sms_sender . ' keyword:' . $subscribe_keyword . ' mobile:' . $sms_to . ' m:[' . $message . ']', 2, "sms_subscribe"); $ok = true; break; default: $message = $unknown_format_msg; _log('Unknown format sender:' . $sms_sender . ' keyword:' . $subscribe_keyword . ' mobile:' . $sms_to, 2, "sms_subscribe"); $ok = true; break; } } else { $member = true; switch ($subscribe_param) { case "OFF": case "OUT": case "UNREG": case $subscribe_reject_param: $message = $msg2; $success = 'fail to delete member'; $db_query = "DELETE FROM " . _DB_PREF_ . "_featureSubscribe_member WHERE member_number='{$sms_to}' AND subscribe_id='{$subscribe_id}'"; $deleted = dba_query($db_query); $success = 'FAILED'; if ($deleted) { $success = 'SUCCESS'; $ok = true; } _log('UNREG ' . $success . ' sender:' . $sms_sender . ' keyword:' . $subscribe_keyword . ' mobile:' . $sms_to . ' m:[' . $message . ']', 2, "sms_subscribe"); break; case "ON": case "IN": case "REG": case $subscribe_accept_param: $message = $already_member_msg; _log('REG fail already a member sender:' . $sms_sender . ' keyword:' . $subscribe_keyword . ' mobile:' . $sms_to . ' m:[' . $message . ']', 2, "sms_subscribe"); $ok = true; break; default: $message = $unknown_format_msg; _log('Unknown format sender:' . $sms_sender . ' keyword:' . $subscribe_keyword . ' mobile:' . $sms_to, 2, "sms_subscribe"); $ok = true; break; } } if ($message) { $message = addslashes($message); _log('sending reply u:' . $username . ' to:' . $sms_to . ' m:[' . $message . '] smsc:[' . $smsc . ']', 3, 'sms_subscribe_handle'); sendsms_helper($username, $sms_to, $message, 'text', '', $smsc, TRUE); } } return $ok; }
function sms_collect_handle($c_uid, $sms_datetime, $sms_sender, $collect_keyword, $collect_param = '', $sms_receiver) { global $core_config; global $web_title, $email_service, $email_footer, $gateway_module; $ok = false; $collect_keyword = strtoupper($collect_keyword); $username = uid2username($c_uid); $sms_to = $sms_sender; // we are replying to this sender $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureCollect WHERE collect_keyword='{$collect_keyword}'"; $db_result = dba_query($db_query); if ($db_row = dba_fetch_array($db_result)) { if (!$db_row['collect_enable']) { $message = _('Collect service inactive'); //list($ok,$to,$smslog_id) = sendsms_pv($username, $sms_to, $message); //$ok = $ok[0]; $unicode = 0; if (function_exists('mb_detect_encoding')) { $encoding = mb_detect_encoding($message, 'auto'); if ($encoding != 'ASCII') { $unicode = 1; } } $ret = sendsms($core_config['main']['cfg_gateway_number'], '', $sms_to, $message, $c_uid, 0, 'text', $unicode); $ok = $ret['status']; return $ok; } } $c_uid = $db_row['uid']; $collect_id = $db_row['collect_id']; $num_rows = dba_num_rows($db_query); if ($num_rows) { $msg1 = $db_row['collect_msg']; $db_query = "INSERT INTO " . _DB_PREF_ . "_featureCollect_member (collect_id,collect_msg,member_number,member_since) VALUES ('{$collect_id}','{$collect_param}','{$sms_to}',now())"; $message = $msg1; $logged = dba_query($db_query); $ok = true; $unicode = core_detect_unicode($message); logger_print('to:' . $sms_to . ' m:' . $message, 3, "sms_collect_handle"); list($ok, $to, $smslog_id, $queue) = sendsms($username, $sms_to, $message, 'text', $unicode); $ok = $ok[0]; // Forward to email as well if enable $db_query = "SELECT collect_fwd_email FROM " . _DB_PREF_ . "_featureCollect WHERE collect_keyword='{$collect_keyword}'"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); if ($email = $db_row['collect_fwd_email']) { // get name from c_uid's phonebook $c_username = uid2username($c_uid); $c_name = phonebook_number2name($sms_sender, $c_username); $sms_sender = $c_name ? $c_name . ' <' . $sms_sender . '>' : $sms_sender; $subject = "[SMSGW-" . $collect_keyword . "] " . _('from') . " {$sms_sender}"; $body = _('Forward WebSMS') . " ({$web_title})\n\n"; $body .= _('Date and time') . ": {$sms_datetime}\n"; $body .= _('Sender') . ": {$sms_sender}\n"; $body .= _('Receiver') . ": {$sms_receiver}\n"; $body .= _('Keyword') . ": {$collect_keyword}\n\n"; $body .= _('Message') . ":\n{$collect_param}\n\n"; $body .= $email_footer . "\n\n"; sendmail($email_service, $email, $subject, $body); logger_print("fwd email to:" . $email, "3", "sms_collect_handle"); } //$ok = true; } else { $ok = false; } return $ok; }
} $content .= "\n\t\t\t\t\t\t\t\t<table cellpadding=1 cellspacing=2 border=0 width=100%>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td width=150>Owner</td><td width=5>:</td><td>{$owner}</td>\t\t \n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td width=150>Message</td><td width=5>:</td><td>{$message}</td>\t\t \n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td width=150>Send to</td><td width=5>:</td><td>{$send_to}</td>\t\t \n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td>Repeat send</td><td width=5>:</td><td>{$repeat}</td>\t\t \n\t\t\t\t\t\t\t\t\t</tr>"; $db_result = dba_query($db_query); $i = 1; while ($db_row = dba_fetch_array($db_result)) { $content .= "<tr>\n\t\t\t\t\t\t\t\t\t<td>" . _('Time') . " {$i}</td><td>:</td><td> " . $db_row['autosend_time'] . "</td>\t\t \n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t"; $i++; } echo $content; break; case "sms_autosend_edit": $autosend_id = $_REQUEST['autosend_id']; $db_query = "SELECT uid,time_id," . _DB_PREF_ . "_featureAutosend.autosend_id, autosend_message,autosend_number,autosend_time\n\t\t\t\t\t\t\t\t\tFROM " . _DB_PREF_ . "_featureAutosend\n\t\t\t\t\t\t\t\t\tINNER JOIN " . _DB_PREF_ . "_featureAutosend_time\n\t\t\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\t\t\tWHERE " . _DB_PREF_ . "_featureAutosend.autosend_id = '{$autosend_id}'\n\t\t\t\t\t\t\t\t\t"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); $num_rows = dba_num_rows($db_query); $edit_autosend_message = $db_row['autosend_message']; $edit_autosend_number = $db_row['autosend_number']; $edit_time_id = $db_row['time_id']; $edit_autosend_time = $db_row['autosend_time']; if ($err) { $content = "<div class=error_string>{$err}</div>"; } $content .= "\n\t\t\t\t\t\t\t\t<h2>" . _('Edit SMS autosend') . "</h2>\n\t\t\t\t\t\t <form action=index.php?app=menu&inc=feature_sms_autosend&op=sms_autosend_edit_yes method=post>\n\t\t\t\t\t\t \t<input type=hidden name=edit_autosend_id value={$autosend_id}>\t\n\t\t\t\t\t\t\t<table width=100% cellpadding=1 cellspacing=2 border=0>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td width=150>" . _('Message') . "</td><td width=5>:</td><td><input type=text size=50 maxlength=200 name=edit_autosend_message value=\"{$edit_autosend_message}\"></td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>" . _('Repeat send') . "</td><td>:</td><td><b>{$num_rows}</b> times</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td>" . _('Send to') . "</td><td>:</td><td><input type=text value=\"{$edit_autosend_number}\" name=edit_autosend_number size=30></td>\t\t\n\t\t\t\t\t\t\t\t</tr>"; $j = 1; $a = 0; while ($a < 4) { $db_query = "SELECT time_id, autosend_time FROM " . _DB_PREF_ . "_featureAutosend_time WHERE autosend_id = '{$autosend_id}' order by time_id limit {$a},1"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); $edit_autosend_time = $db_row['autosend_time'];
function sms_poll_check_option_vote($list, $sms_sender, $poll_keyword, $choice_keyword) { $poll_id = $list['poll_id']; $poll_option_vote = $list['poll_option_vote']; $c_sms_sender = substr($sms_sender, 3); // check already vote $db_query = "SELECT in_datetime FROM " . _DB_PREF_ . "_featurePoll_log WHERE poll_sender LIKE '%{$c_sms_sender}' AND poll_id='{$poll_id}' AND status!=0 ORDER BY log_id DESC LIMIT 1"; $db_result = dba_query($db_query); if ($db_row = dba_fetch_array($db_result)) { // yup, voted if ($poll_option_vote == 4) { logger_print('vote s:' . $sms_sender . ' k:' . $poll_keyword . ' c:' . $choice_keyword . ' vote multiple', 2, 'sms_poll'); return TRUE; } $in_datetime = $db_row['in_datetime']; $votes = (int) @dba_num_rows($db_query); } else { // nope, go ahead save it in the log logger_print('vote s:' . $sms_sender . ' k:' . $poll_keyword . ' c:' . $choice_keyword . ' continue', 2, 'sms_poll'); return TRUE; } $continue = TRUE; switch ($poll_option_vote) { case 0: // one time if ($votes) { logger_print('vote s:' . $sms_sender . 'k:' . $poll_keyword . ' c:' . $choice_keyword . ' option_vote:' . $poll_option_vote . ' vote_count:' . $votes . ' already vote one time', 2, 'sms_poll'); $continue = FALSE; } break; case 1: // one time every 24 hours if ($votes) { $d = new DateTime($in_datetime); $day_in = $d->format("Ymd"); $d = new DateTime(core_get_datetime()); $day_current = $d->format("Ymd"); if ($day_in && $day_current && $day_in == $day_current) { logger_print('vote s:' . $sms_sender . 'k:' . $poll_keyword . ' c:' . $choice_keyword . ' option_vote:' . $poll_option_vote . ' vote_count:' . $votes . ' already vote today', 2, 'sms_poll'); $continue = FALSE; } } break; case 2: // one time every week if ($votes) { $d = new DateTime($in_datetime); $week_in = $d->format("YmW"); $d = new DateTime(core_get_datetime()); $week_current = $d->format("YmW"); if ($week_in && $week_current && $week_in == $week_current) { logger_print('vote s:' . $sms_sender . 'k:' . $poll_keyword . ' c:' . $choice_keyword . ' option_vote:' . $poll_option_vote . ' vote_count:' . $votes . ' already vote this week', 2, 'sms_poll'); $continue = FALSE; } } break; case 3: // one time every month if ($votes) { $d = new DateTime($in_datetime); $month_in = $d->format("Ym"); $d = new DateTime(core_get_datetime()); $month_current = $d->format("Ym"); if ($month_in && $month_current && $month_in == $month_current) { logger_print('vote s:' . $sms_sender . 'k:' . $poll_keyword . ' c:' . $choice_keyword . ' option_vote:' . $poll_option_vote . ' vote_count:' . $votes . ' already vote this month', 2, 'sms_poll'); $continue = FALSE; } } break; } return $continue; }