header("Location: index.php?app=menu&inc=feature_sms_survey&op=list&sid=" . $sid); exit; break; case 'stop': $content = '<h2>' . _('SMS Survey') . '</h2><p />'; if ($error_content) { $content .= '<p>' . $error_content . '</p>'; } $content .= '<h3>' . _('Stop survey') . '</h3><p />'; $sid = $_REQUEST['sid']; $data = sms_survey_getdatabyid($sid); $keyword = $data['keyword']; $title = $data['title']; $c_members = count(sms_survey_getmembers($sid)); $c_members = "<a href='index.php?app=menu&inc=feature_sms_survey&route=members&op=members&sid=" . $sid . "'>" . $c_members . "</a>"; $c_questions = count(sms_survey_getquestions($sid)); $c_questions = "<a href='index.php?app=menu&inc=feature_sms_survey&route=questions&op=questions&sid=" . $sid . "'>" . $c_questions . "</a>"; $c_status = $data['status'] ? "<font color='green'>" . _('enabled') . "</font>" : "<font color='red'>" . _('disabled') . "</font>"; if ($data['status']) { $c_status = $data['running'] == 2 ? "<font color='blue'>" . _('completed') . "</font>" : "<font color='green'>" . _('enabled') . "</font>"; } $c_started = $data['started'] ? "<font color='green'>" . _('yes') . "</font>" : "<font color='red'>" . _('no') . "</font>"; if (!$data['started']) { $c_started = $data['running'] == 2 ? "<font color='red'>" . _('restart') . "</font>" : "<font color='red'>" . _('no') . "</font>"; } $content .= "\n\t\t\t<table cellpadding='1' cellspacing='2' border='0'>\n\t\t\t<tr><td>" . _('Keyword') . "</td><td>:</td><td>" . $keyword . "</td></tr>\n\t\t\t<tr><td>" . _('Title') . "</td><td>:</td><td>" . $title . "</td></tr>\n\t\t\t<tr><td>" . _('Members') . "</td><td>:</td><td>" . $c_members . "</td></tr>\n\t\t\t<tr><td>" . _('Questions') . "</td><td>:</td><td>" . $c_questions . "</td></tr>\n\t\t\t<tr><td>" . _('Status') . "</td><td>:</td><td>" . $c_status . "</td></tr>\n\t\t\t<tr><td>" . _('Started') . "</td><td>:</td><td>" . $c_started . "</td></tr>\n\t\t\t</table>\n\t\t\t<p>" . _('Are you sure you want to stop this survey ?') . "</p>\n\t\t\t<form method='post' action='index.php?app=menu&inc=feature_sms_survey&op=stop_submit'>\n\t\t\t<input type='hidden' name='sid' value='{$sid}'>\n\t\t\t<p><input class='button' type='submit' value='" . _('Yes') . "'></p>\n\t\t\t</form>\n\t\t\t<form method='post'action='index.php?app=menu&inc=feature_sms_survey&op=list'>\n\t\t\t<p><input class='button' type='submit' value='" . _('Cancel') . "'></p>\n\t\t\t</form>\n\t\t"; echo $content; break; case 'stop_submit': $sid = $_REQUEST['sid']; $data = sms_survey_getdatabyid($sid);
function sms_survey_handle($c_uid, $sms_datetime, $sms_sender, $sms_receiver, $survey_keyword, $survey_param = '') { global $core_config; $ok = false; // get survey data by keyword $data = sms_survey_getdatabykeyword($survey_keyword); if ($data['status'] == 1) { // survey enabled, accept incoming answers $session = $data['session']; $sid = $data['id']; $m = sms_survey_getmemberbymobile($sid, $sms_sender); // link_id is used to link each questions and answers if ($link_id = sms_survey_getlinkid($session, $sid, $m['id'])) { // get last question data from log $l = sms_survey_getoutlogs($link_id); $outlogs = $l[count($l) - 1]; $qn = $outlogs['question_number']; $next_qn = $qn + 1; // save answer in log $log = ""; $log['incoming'] = 1; $log['question_number'] = $qn; $log['link_id'] = $link_id; $log['in_datetime'] = $sms_datetime; $log['in_sender'] = $sms_sender; $log['in_receiver'] = $sms_receiver; $log['answer'] = $survey_param; $log['session'] = $session; if (sms_survey_savelog($log)) { // get next question $q = sms_survey_getquestions($sid); // stop when ran out questions if ($qn < count($q)) { $c_message = $q[$qn]['question']; // yes, not $next_qn, array questions start from 0 $c_username = uid2username($c_uid); $c_keyword = $survey_keyword; $c_sms_msg = $c_keyword . " " . $c_message; $c_sms_to = $sms_sender; logger_print("playsmsd send start next qn:" . $next_qn . " sid:" . $c_sid . " username:"******" to:" . $c_sms_to . " msg:" . $c_sms_msg, 3, "sms_survey"); // if member's mobile, question and username owned the survey exists if ($c_sms_to && $c_sms_msg && $c_username) { $type = 'text'; $unicode = '0'; // send next question to member list($ok, $to, $smslog_id) = sendsms_pv($c_username, $c_sms_to, $c_sms_msg, $type, $unicode); $ok = $ok[0] ? "true" : "false"; logger_print("playsmsd send finish sid:" . $c_sid . " smslog_id:" . $smslog_id[0] . " ok:" . $ok, 3, "sms_survey"); // save the log $log = ""; $log['survey_id'] = $sid; $log['question_id'] = $q[$qn]['id']; $log['member_id'] = $m['id']; $log['link_id'] = $link_id; $log['smslog_id'] = $smslog_id[0]; $log['name'] = $m['name']; $log['mobile'] = $m['mobile']; $log['question'] = $q[$qn]['question']; $log['question_number'] = $next_qn; $log['creation_datetime'] = $core_config['datetime']['now']; $log['session'] = $session; sms_survey_savelog($log); } } // set handled $ok = true; } } } else { // returns true even if its not handled since survey is disabled // returning false will make this SMS as unhandled SMS $ok = true; } return $ok; }
$buttons = ""; } if ($op == 'questions_edit') { $qid = $_REQUEST['qid']; $q = sms_survey_getquestionbyid($qid); $edit_question = "\n\t\t\t\t<p> </p>\n\t\t\t\t<form method='post' action='index.php?app=menu&inc=feature_sms_survey&route=questions&op=questions_edit_submit'>\n\t\t\t\t<input type='hidden' name='sid' value='{$sid}'>\n\t\t\t\t<input type='hidden' name='qid' value='{$qid}'>\n\t\t\t\t<table cellpadding='1' cellspacing='2' border='0'>\n\t\t\t\t<tr><td>" . _('Question') . "</td><td>:</td><td><input type='text' name='question' value='" . $q['question'] . "' maxlength='140' size='100'></td></tr>\n\t\t\t\t</table>\n\t\t\t\t<p><input class='button' type='submit' value='" . _('Submit') . "'></p>\n\t\t\t\t</form>\n\t\t\t\t<p> </p>\n\t\t\t"; $buttons = ""; } if ($op == 'questions_del') { $qid = $_REQUEST['qid']; $q = sms_survey_getquestionbyid($qid); $edit_question = "\n\t\t\t\t<p> </p>\n\t\t\t\t<form method='post' action='index.php?app=menu&inc=feature_sms_survey&route=questions&op=questions_del_submit'>\n\t\t\t\t<input type='hidden' name='sid' value='{$sid}'>\n\t\t\t\t<input type='hidden' name='qid' value='{$qid}'>\n\t\t\t\t<table cellpadding='1' cellspacing='2' border='0'>\n\t\t\t\t<tr><td>" . _('Question') . "</td><td>:</td><td>" . $q['question'] . "</td></tr>\n\t\t\t\t</table>\n\t\t\t\t<p><input class='button' type='submit' value='" . _('Submit') . "'></p>\n\t\t\t\t</form>\n\t\t\t\t<p> </p>\n\t\t\t"; $buttons = ""; } $content .= "\n\t\t\t<table cellpadding='1' cellspacing='2' border='0'>\n\t\t\t<tr><td>" . _('User') . "</td><td>:</td><td>" . $c_user . "</td></tr>\n\t\t\t<tr><td>" . _('Keyword') . "</td><td>:</td><td>" . $keyword . "</td></tr>\n\t\t\t<tr><td>" . _('Title') . "</td><td>:</td><td>" . $title . "</td></tr>\n\t\t\t<tr><td>" . _('Members') . "</td><td>:</td><td>" . $c_members . "</td></tr>\n\t\t\t<tr><td>" . _('Questions') . "</td><td>:</td><td>" . $c_questions . "</td></tr>\n\t\t\t<tr><td>" . _('Status') . "</td><td>:</td><td>" . $c_status . "</td></tr>\n\t\t\t<tr><td>" . _('Started') . "</td><td>:</td><td>" . $c_started . "</td></tr>\n\t\t\t</table>\n\t\t\t<!-- add question -->\n\t\t\t" . $add_question . "\n\t\t\t" . $edit_question . "\n\t\t\t" . $del_question . "\n\t\t\t<!-- buttons -->\n\t\t\t" . $buttons . "\n\t\t\t<table width='100%' cellpadding='1' cellspacing='2' border='0' class='sortable'>\n\t\t\t<tr>\n\t\t\t\t<td class='box_title' width='4'>*</td>\n\t\t\t\t<td class='box_title' width='90%'>" . _('Question') . "</td>\n\t\t\t\t<td class='box_title' width='10%'>" . _('Action') . "</td>\n\t\t\t</tr>\n\t\t"; $questions = sms_survey_getquestions($sid); for ($i = 0; $i < count($questions); $i++) { $c_qid = $questions[$i]['id']; $c_question = htmlspecialchars($questions[$i]['question']); if (!$data['status']) { $c_action = "<a href='index.php?app=menu&inc=feature_sms_survey&route=questions&op=questions_edit&sid=" . $sid . "&qid=" . $c_qid . "'>" . $icon_edit . "</a> "; $c_action .= "<a href='index.php?app=menu&inc=feature_sms_survey&route=questions&op=questions_del&sid=" . $sid . "&qid=" . $c_qid . "'>" . $icon_delete . "</a> "; } $td_class = ($i + 1) % 2 ? "box_text_odd" : "box_text_even"; $content .= "\n\t\t\t\t<tr class='" . $td_class . "'>\n\t\t\t\t\t<td align='center'>" . ($i + 1) . ".</td>\n\t\t\t\t\t<td align='center'>" . $c_question . "</td>\n\t\t\t\t\t<td align='center'>" . $c_action . "</td>\n\t\t\t\t</tr>\n\t\t\t"; } $content .= "\n\t\t\t</table>\n\t\t\t<!-- buttons -->\n\t\t\t" . $buttons; echo $content; break; case 'questions_add_submit': $sid = $_REQUEST['sid'];