function teltree_handle($c_uid, $sms_datetime, $sms_sender, $sms_receiver, $teltree_keyword, $teltree_param = '', $smsc = '', $raw_message = '') { $ps = explode(" ", $raw_message, 2); $kk = strtoupper($ps[0]); $username = "******"; if ($teltree_keyword == 'DAFTAR') { $pecah = preg_split("/#/", $ps[1], null, PREG_SPLIT_NO_EMPTY); $data = array(); $data['name'] = trim($pecah[0]); $data['username'] = trim($pecah[0]); $data['mobile'] = $sms_sender; $data['email'] = str_replace(' ', '', $data['name']) . "@noreply.org"; $data['parent_uid'] = 1; //----- ini parentnya admin $data['status'] = 4; //---ini artinya ditambahkan ke sub user $ret = user_add($data); $ok = $ret['status'] ? TRUE : FALSE; if ($ok) { echo "okee"; $items = array('uid' => 1, 'name' => $data['name'], 'mobile' => $data['mobile'], 'email' => $data['email'], 'tags' => $tags); if ($c_pid = dba_add(_DB_PREF_ . '_featurePhonebook', $items)) { $save_to_group = TRUE; _log('Success to add contact pid:' . $c_pid . ' m:' . $data['mobile'] . ' n:' . $data['name'] . ' e:' . $data['email'] . ' tags:[' . $data['tags'] . ']', 2, 'teltree'); } else { _log('Fail to add contact pid:' . $c_pid . ' m:' . $data['mobile'] . ' n:' . $data['name'] . ' e:' . $data['email'] . ' tags:[' . $data['tags'] . ']', 2, 'teltree'); } $balasan = "Selamat anda telah terdaftar di Telephone Tree"; $gagal = "Maaf Sistem sedang mengalami gangguan, silahkan coba beberapa saat lagi"; if ($save_to_group) { $unicode = core_detect_unicode($balasan); $balasan = addslashes($balasan); // $username = "******"; //$smsc = "dev"; _log("returns:" . $balasan, 2, "teltree"); sendsms_helper($username, $sms_sender, $balasan, 'text', $unicode, $smsc); } else { $unicode = core_detect_unicode($gagal); $balasan = addslashes($gagal); _log("returns:" . $gagal, 2, "teltree"); sendsms_helper($username, $sms_sender, $balasan, 'text', $unicode, $smsc); _log_print("returns empty", 2, "teltree"); } } else { echo "gagal"; } return $ret; //$ok = true; } elseif ($kk == 'GABUNG') { /*$gpids = dba_search(_DB_PREF_ . '_featurePhonebook_group','code',array( ));*/ $uid = user_mobile2uid($sms_sender); $group_code = strtoupper($ps[1]); $list = dba_search(_DB_PREF_ . '_featurePhonebook', 'id', array('uid' => 1, 'mobile' => $sms_sender)); if ($group_code && $sms_sender) { /*--dummy code--*/ $c_pid = dba_search(_DB_PREF_ . '_featurePhonebook', 'id', array('uid' => 1, 'mobile' => $sms_sender)); $gpids = dba_search(_DB_PREF_ . '_featurePhonebook_group', 'id', array('uid' => 1, 'code' => $group_code)); foreach ($gpids as $gpid) { foreach ($gpid as $key => $val) { $items = array('gpid' => $val, 'pid' => $c_pid[0]['id']); if (dba_isavail(_DB_PREF_ . '_featurePhonebook_group_contacts', $items, 'AND')) { if (dba_add(_DB_PREF_ . '_featurePhonebook_group_contacts', $items)) { $list = dba_search(_DB_PREF_ . '_featurePhonebook_group', 'code', array('uid' => 1)); _log('contact added to group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'phonebook_edit'); if ($iid = $c_pid[0]['id']) { $bal_grup = "selamat anda telah tergabung di grup" . $list[$iid]['code']; $unicode = core_detect_unicode($bal_grup); $bal_grup = addslashes($bal_grup); _log("returns:" . $bal_grup, 2, "telek"); sendsms_helper($username, $sms_sender, $bal_grup, 'text', $unicode, $smsc); _log("returns empty", 2, "sms custom"); } } else { _log('contact edited but fail to save in group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'phonebook_edit'); } } } } } //$ok = true; } elseif ($kk == 'KELUAR') { $uid = user_mobile2uid($sms_sender); $group_code = strtoupper($ps[1]); //_log($sms_sender . ' '. $group_code, 2 , 'test'); if ($group_code && $sms_sender) { // _log($sms_sender . ' '. $group_code, 2 , 'test'); $c_pid = dba_search(_DB_PREF_ . '_featurePhonebook', 'id', array('uid' => 1, 'mobile' => $sms_sender)); $gpids = dba_search(_DB_PREF_ . '_featurePhonebook_group', 'id', array('uid' => 1, 'code' => $group_code)); foreach ($gpids as $gpid) { foreach ($gpid as $key => $val) { $items = array('gpid' => $val, 'pid' => $c_pid[0]['id']); // _log($sms_sender . ' '. $group_code, 2 , 'test'); if (!dba_isavail(_DB_PREF_ . '_featurePhonebook_group_contacts', $items, 'AND')) { if (dba_remove(_DB_PREF_ . '_featurePhonebook_group_contacts', $items)) { if ($iid = $c_pid[0]['id']) { $bal_grup = "anda telah keluar dari grup" . $list[$iid]['code']; $unicode = core_detect_unicode($bal_grup); $bal_grup = addslashes($bal_grup); _log("returns:" . $bal_grup, 2, "telek"); sendsms_helper($username, $sms_sender, $bal_grup, 'text', $unicode, $smsc); _log("returns empty", 2, "sms custom"); } _log('contact removed from group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'teltree_phonebook_edit'); } else { _log('contact fail to remove from group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'teltree_phonebook_edit'); } } else { _log('failed ' . $val . ' ' . $c_pid[0]['id'], 2, 'test'); } } } } } }
/** * Add notification * @param integer $uid User ID * @param string $label Notification label * @param string $subject Notification subject * @param string $body Notification body * @param array $data Additional data, json encoded * @return boolean */ function notif_add($uid, $label, $subject, $body, $data = array()) { $ret = FALSE; $db_table = _DB_PREF_ . '_tblNotif'; $items = array('uid' => $uid, 'last_update' => core_get_datetime(), 'label' => $label, 'subject' => $subject, 'body' => $body, 'flag_unread' => 1, 'data' => json_encode($data)); if ($result = dba_add($db_table, $items)) { logger_print('uid:' . $uid . ' id:' . $result . ' label:' . $label . ' subject:' . $subject, 2, 'notif_add'); $ret = TRUE; } return $ret; }
function dlr($smslog_id, $uid, $p_status) { global $core_config; if ($core_config['isdlrd']) { $c_isdlrd = 1; $ret = dba_add(_DB_PREF_ . '_tblDLR', array('flag_processed' => 1, 'smslog_id' => $smslog_id, 'p_status' => $p_status, 'uid' => $uid)); } else { $c_isdlrd = 0; $ret = dba_add(_DB_PREF_ . '_tblDLR', array('flag_processed' => 2, 'smslog_id' => $smslog_id, 'p_status' => $p_status, 'uid' => $uid)); setsmsdeliverystatus($smslog_id, $uid, $p_status); } logger_print("isdlrd:" . $c_isdlrd . " smslog_id:" . $smslog_id . " p_status:" . $p_status . " uid:" . $uid, 3, "dlr"); return $ret; }
function recvsms($sms_datetime, $sms_sender, $message, $sms_receiver = "", $smsc = '') { global $core_config; if ($core_config['isrecvsmsd']) { $c_isrecvsmsd = 1; // save to db and mark as queued (flag_processed = 1) $ret = dba_add(_DB_PREF_ . '_tblRecvSMS', array('flag_processed' => 1, 'sms_datetime' => core_adjust_datetime($sms_datetime), 'sms_sender' => $sms_sender, 'message' => $message, 'sms_receiver' => $sms_receiver, 'smsc' => $smsc)); } else { $c_isrecvsmsd = 0; // save to db but mark as processed (flag_processed = 2) and then directly call recvsms_process() $ret = dba_add(_DB_PREF_ . '_tblRecvSMS', array('flag_processed' => 2, 'sms_datetime' => core_adjust_datetime($sms_datetime), 'sms_sender' => $sms_sender, 'message' => $message, 'sms_receiver' => $sms_receiver, 'smsc' => $smsc)); recvsms_process(core_display_datetime($sms_datetime), $sms_sender, $message, $sms_receiver, $smsc); } logger_print("isrecvsmsd:" . $c_isrecvsmsd . " dt:" . $sms_datetime . " sender:" . $sms_sender . " m:" . $message . " receiver:" . $sms_receiver . " smsc:" . $smsc, 3, "recvsms"); return $ret; }
/** * Add notification * * @param integer $uid * User ID * @param string $label * Notification label * @param string $subject * Notification subject * @param string $body * Notification body * @param array $data * Additional data, json encoded * @return boolean */ function notif_add($uid, $label, $subject, $body, $data = array()) { $ret = FALSE; if (!is_array($data)) { $data = array($data); } $db_table = _DB_PREF_ . '_tblNotif'; $items = array('uid' => $uid, 'last_update' => core_get_datetime(), 'label' => $label, 'subject' => $subject, 'body' => $body, 'flag_unread' => 1, 'data' => json_encode($data)); if ($result = dba_add($db_table, $items)) { foreach ($data as $key => $val) { $show_data .= $key . ':' . $val . ' '; } _log('uid:' . $uid . ' id:' . $result . ' label:' . $label . ' subject:' . $subject . ' data:[' . trim($show_data) . ']', 2, 'notif_add'); $ret = TRUE; } return $ret; }
/** * Add a mobile number to stoplist * * @param integer $uid * User ID * @param string $mobile * single mobile number * @return boolean TRUE on added */ function stoplist_hook_blacklist_mobile_add($uid, $mobile) { $ret = FALSE; // if account exists $uid = user_uid2username((int) $uid) ? (int) $uid : 1; $items = array('uid' => $uid, 'mobile' => $mobile); if (!blacklist_mobile_isexists(0, $mobile)) { if ($new_id = dba_add(_DB_PREF_ . '_featureStoplist', $items)) { _log('added mobile number to stoplist id:' . $new_id . ' mobile:' . $mobile . ' uid:' . $uid, 2, 'stoplist_hook_blacklist_mobile_add'); $ret = TRUE; } } else { _log('mobile number is already in stoplist mobile:' . $mobile . ' uid:' . $uid, 2, 'stoplist_hook_blacklist_mobile_remove'); $ret = TRUE; } return $ret; }
function registry_update($uid, $registry_group, $registry_family, $items) { $ret = false; $db_table = _DB_PREF_ . '_tblRegistry'; if (is_array($items)) { foreach ($items as $key => $val) { $conditions = array('uid' => $uid, 'registry_group' => $registry_group, 'registry_family' => $registry_family, 'registry_key' => $key); $values = array('c_timestamp' => strtotime(core_get_datetime()), 'registry_value' => $val); if (dba_count($db_table, $conditions)) { $ret[$key] = dba_update($db_table, $values, $conditions); } else { $ret[$key] = dba_add($db_table, array_merge($conditions, $values)); } unset($conditions); unset($values); } } return $ret; }
/** * Add country * @param string $name Country name * @param string $code Country code * @param string $prefix Country prefix * @return boolean */ function country_add($name, $code, $prefix = '') { $ret = FALSE; if (!$name) { return FALSE; } $code = substr(0, 2, core_sanitize_alpha(strtolower(trim($code)))); if (!$code) { return FALSE; } $prefix = trim($prefix) ? core_sanitize_numeric($prefix) : ''; $db_table = _DB_PREF_ . '_tblCountry'; if (dba_isavail($db_table, array('country_name' => $name, 'country_code' => $code))) { $items = array('name' => $name, 'code' => $code, 'prefix' => $prefix); if ($result = dba_add($db_table, $items)) { logger_print('id:' . $result . ' name:' . $name . ' code:' . $code . ' prefix:' . $prefix, 3, 'country_add'); $ret = TRUE; } } return $ret; }
/** * hook_sendsms called by sendsms_process() * * @param string $smsc * SMSC name * @param unknown $sms_sender * Sender ID * @param string $sms_footer * Message footer * @param string $sms_to * Destination number * @param string $sms_msg * Message * @param integer $uid * User ID * @param integer $gpid * Group ID * @param integer $smslog_id * SMS Log ID * @param integer $sms_type * Type of SMS * @param integer $unicode * Unicode flag * @return boolean */ function playnet_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0) { global $plugin_config; $ok = FALSE; _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "playnet_hook_sendsms"); // override plugin gateway configuration by smsc configuration $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config); $sms_sender = stripslashes($sms_sender); if ($plugin_config['playnet']['module_sender']) { $sms_sender = $plugin_config['playnet']['module_sender']; } $sms_footer = stripslashes(htmlspecialchars_decode($sms_footer)); $sms_msg = stripslashes(htmlspecialchars_decode($sms_msg)); if ($sms_footer) { $sms_msg = $sms_msg . $sms_footer; } $unicode = trim($unicode) ? 1 : 0; if (!$unicode) { $unicode = core_detect_unicode($sms_msg); } if ($sms_to && $sms_msg) { $now = core_get_datetime(); $items = array('created' => $now, 'last_update' => $now, 'flag' => 1, 'uid' => $uid, 'smsc' => $smsc, 'smslog_id' => $smslog_id, 'sender_id' => $sms_sender, 'sms_to' => $sms_to, 'message' => $sms_msg, 'sms_type' => $sms_type, 'unicode' => $unicode); if ($id = dba_add(_DB_PREF_ . '_gatewayPlaynet_outgoing', $items)) { $ok = TRUE; } } if ($ok) { $p_status = 0; // pending } else { $p_status = 2; // failed } dlr($smslog_id, $uid, $p_status); return $ok; }
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); } $_SESSION['dialog']['info'][] = _('Contacts have been imported'); header("Location: " . _u('index.php?app=main&inc=feature_phonebook&route=import&op=list')); exit; break;
$db_table = _DB_PREF_ . '_featureSmssysnc'; $conditions = array('uid' => $c_uid, 'message_id' => $message_id); if (dba_isavail($db_table, $conditions, 'AND')) { _log("saving uid:" . $c_uid . " dt:" . $sms_datetime . " ts:" . $r['sent_timestamp'] . " message_id:" . $message_id . " s:" . $sms_sender . " m:" . $message . " r:" . $sms_receiver, 3, "sms_sync sync"); // if keyword does not exists (checkavailablekeyword == TRUE) // then prefix the message with an @username so that it will be routed to $c_uid's inbox $m = explode(' ', $message); $c_m = str_replace('#', '', $m[0]); if (checkavailablekeyword($c_m)) { _log("forwarded to inbox uid:" . $c_uid . " message_id:" . $message_id, 3, "sms_sync sync"); $message = "@" . user_uid2username($c_uid) . " " . $message; } // route it if ($recvsms_id = recvsms($sms_datetime, $sms_sender, $message, $sms_receiver)) { $items = array('uid' => $c_uid, 'message_id' => $message_id, 'recvsms_id' => $recvsms_id); dba_add($db_table, $items); _log("saved uid:" . $c_uid . " message_id:" . $message_id . " recvsms_id:" . $recvsms_id, 3, "sms_sync sync"); $ret = array('payload' => array('success' => "true", 'error' => NULL)); $ok = TRUE; } else { $error_string = "fail to save uid:" . $c_uid . " message_id:" . $message_id; _log($error_string, 3, "sms_sync sync"); } } else { $error_string = "duplicate message uid:" . $c_uid . " message_id:" . $message_id; _log($error_string, 3, "sms_sync sync"); } if (!$ok) { $ret = array('payload' => array('success' => "false", 'error' => $error_string)); } _p(json_encode($ret));
function credit_hook_rate_addusercredit($uid, $amount) { global $plugin_config; $db_table = $plugin_config['credit']['db_table']; $parent_uid = user_getparentbyuid($uid); $username = user_uid2username($uid); $status = user_getfieldbyuid($uid, 'status'); $balance = (double) rate_getusercredit($username); $amount = (double) $amount; if (abs($amount) <= 0) { _log('amount cannot be zero. amount:[' . $amount . ']', 2, 'credit_hook_rate_addusercredit'); return FALSE; } // add to balance $balance = $balance + $amount; // record it $id = dba_add($db_table, array('parent_uid' => $parent_uid, 'uid' => $uid, 'username' => $username, 'status' => $status, 'create_datetime' => core_get_datetime(), 'amount' => $amount, 'balance' => $balance, 'flag_deleted' => 0)); // update user's credit if ($id) { _log('saved id:' . $id . ' parent_uid:' . $parent_uid . ' uid:' . $uid . ' username:'******' amount:' . $amount . ' balance:' . $balance, 3, 'credit_add'); if (rate_setusercredit($uid, $balance)) { _log('updated uid:' . $uid . ' credit:' . $balance, 3, 'credit_add'); return TRUE; } else { _log('fail to update uid:' . $uid . ' credit:' . $balance, 3, 'credit_add'); dba_remove($db_table, array('id' => $id)); return FALSE; } } else { _log('fail to save parent_uid:' . $parent_uid . ' uid:' . $uid . ' username:'******' amount:' . $amount . ' balance:' . $balance, 3, 'credit_add'); return FALSE; } }
} break; case "import_yes": @set_time_limit(0); $num = $_POST['number_of_row']; $session_import = $_POST['session_import']; $data = $_SESSION['tmp'][$session_import]; foreach ($data as $d) { $name = trim($d[0]); $destination = trim($d[1]); $schedule = trim($d[2]); if ($name && $destination && $schedule) { $schedule = core_adjust_datetime($schedule); // add destiantions, replace existing entry with the same name if (dba_isexists(_DB_PREF_ . '_featureSchedule_dst', array('schedule_id' => $schedule_id, 'name' => $name), 'AND')) { // update $items = array('c_timestamp' => mktime(), 'schedule' => $schedule, 'scheduled' => '0000-00-00 00:00:00'); $conditions = array('schedule_id' => $schedule_id, 'name' => $name, 'destination' => $destination); dba_update(_DB_PREF_ . '_featureSchedule_dst', $items, $conditions); } else { // insert $items = array('schedule_id' => $schedule_id, 'schedule' => $schedule, 'scheduled' => '0000-00-00 00:00:00', 'name' => $name, 'destination' => $destination); dba_add(_DB_PREF_ . '_featureSchedule_dst', $items); } } } $_SESSION['dialog']['info'][] = _('Entries in CSV file have been imported'); header("Location: " . _u('index.php?app=main&inc=feature_schedule&route=import&op=list&schedule_id=' . $schedule_id)); exit; break; }
/** * Add new user * * @param array $data * User data * @param boolean $forced * Forced addition * @return array $ret('error_string', 'status', 'uid') */ function user_add($data = array(), $forced = FALSE) { global $core_config, $user_config; $ret['error_string'] = _('Unknown error has occurred'); $ret['status'] = FALSE; $ret['uid'] = 0; $data = trim($data['username']) ? $data : $_REQUEST; if ($forced || auth_isadmin() || $user_config['status'] == 3 || !auth_isvalid() && $core_config['main']['enable_register']) { foreach ($data as $key => $val) { $data[$key] = trim($val); } // set valid status $data['status'] = (int) $data['status']; if (!($data['status'] == 2 || $data['status'] == 3)) { $data['status'] = 4; } // logic for parent_uid, parent uid by default is 0 if ($data['status'] == 4) { $parent_status = user_getfieldbyuid($data['parent_uid'], 'status'); if (!($parent_status == 2 || $parent_status == 3)) { $data['parent_uid'] = 0; } } else { $data['parent_uid'] = 0; } $data['username'] = core_sanitize_username($data['username']); $data['password'] = $data['password'] ? $data['password'] : core_get_random_string(10); $new_password = $data['password']; $data['password'] = md5($new_password); $data['token'] = md5(uniqid($data['username'] . $data['password'], true)); // credit set to 0 by default // $data['credit'] = ( $data['credit'] ? $data['credit'] : $core_config['main']['default_credit'] ); $data['credit'] = 0; // sender set to empty by default // $data['sender'] = ($data['sender'] ? core_sanitize_sender($data['sender']) : ''); $data['sender'] = ''; $dt = core_get_datetime(); $data['register_datetime'] = $dt; $data['lastupdate_datetime'] = $dt; $data['webservices_ip'] = trim($data['webservices_ip']) ? trim($data['webservices_ip']) : '127.0.0.1, 192.168.*.*'; $v = user_add_validate($data); if ($v['status']) { _log('attempt to register status:' . $data['status'] . ' u:' . $data['username'] . ' email:' . $data['email'], 3, 'user_add'); if ($data['username'] && $data['email'] && $data['name']) { if ($new_uid = dba_add(_DB_PREF_ . '_tblUser', $data)) { $ret['status'] = TRUE; $ret['uid'] = $new_uid; } else { $ret['error_string'] = _('Fail to register an account'); } if ($ret['status']) { _log('registered status:' . $data['status'] . ' u:' . $data['username'] . ' uid:' . $ret['uid'] . ' email:' . $data['email'] . ' ip:' . $_SERVER['REMOTE_ADDR'] . ' mobile:' . $data['mobile'] . ' credit:' . $data['credit'], 2, 'user_add'); $subject = _('New account registration'); $body = $core_config['main']['web_title'] . "\n"; $body .= $core_config['http_path']['base'] . "\n\n"; $body .= _('Username') . ": " . $data['username'] . "\n"; $body .= _('Password') . ": " . $new_password . "\n"; $body .= _('Mobile') . ": " . $data['mobile'] . "\n"; $body .= _('Credit') . ": " . $data['credit'] . "\n\n"; $body .= $core_config['main']['email_footer'] . "\n\n"; $ret['error_string'] = _('Account has been added and password has been emailed') . " (" . _('username') . ": " . $data['username'] . ")"; $mail_data = array('mail_from_name' => $core_config['main']['web_title'], 'mail_from' => $core_config['main']['email_service'], 'mail_to' => $data['email'], 'mail_subject' => $subject, 'mail_body' => $body); if (!sendmail($mail_data)) { $ret['error_string'] = _('Account has been added but failed to send email') . " (" . _('username') . ": " . $data['username'] . ")"; } } } else { $ret['error_string'] = _('You must fill all required fields'); } } else { $ret['error_string'] = $v['error_string']; } } else { $ret['error_string'] = _('Account registration is not available'); } return $ret; }
if (!$c_name) { $c_name = mktime(); } $smsc = gateway_get_smscbyname($c_name); if ($smsc['name']) { $_SESSION['error_string'] = _('SMSC already exists'); } else { if ($c_name && $c_gateway) { $dv = $plugin_config[$c_gateway]['_smsc_config_'] ? $plugin_config[$c_gateway]['_smsc_config_'] : array(); $dynamic_variables = array(); foreach ($dv as $key => $val) { $dynamic_variables[$key] = $_REQUEST[$key]; } $items = array('created' => core_get_datetime(), 'name' => $c_name, 'gateway' => $c_gateway, 'data' => json_encode($dynamic_variables)); $db_table = _DB_PREF_ . '_tblGateway'; if ($new_id = dba_add($db_table, $items)) { $_SESSION['error_string'] = _('New SMSC has been added'); } else { $_SESSION['error_string'] = _('Fail to add new SMSC'); } } else { $_SESSION['error_string'] = _('Unknown error'); header('Location: ' . _u('index.php?app=main&inc=core_gateway&op=gateway_list')); exit; } } header('Location: ' . _u('index.php?app=main&inc=core_gateway&op=add_smsc&gateway=' . $c_gateway)); exit; break; case 'edit_smsc': $c_id = $_REQUEST['id'];
function telek_hook_recvsms_intercept($sms_datetime, $sms_sender, $message, $sms_receiver) { //$ret = array(); $ps = explode(" ", $message, 2); $ikut = strtoupper($ps[0]); //$pesan = ''; $hooked = false; if ($ikut == 'DAFTAR') { $pecah = preg_split("/#/", $ps[1], null, PREG_SPLIT_NO_EMPTY); $c_uid = user_mobile2uid($sms_sender); $data = array(); $data['name'] = trim($pecah[0]); $data['username'] = trim($pecah[1]); $data['mobile'] = $sms_sender; $data['email'] = $data['name'] . "@noreply.org"; $data['parent_uid'] = 0; $data['status'] = 4; } if ($nama && $nohp && $pengguna) { logger_print("*******", 3, "telek"); logger_print("sms_sender " . $sms_sender, 3, "telek"); logger_print("message " . $message, 3, "telek"); logger_print("new message " . $nama, 3, "telek"); logger_print("sms target user" . $sms_receiver, 3, "telek"); logger_print("*******", 3, "telek"); if (($uid = user_mobile2uid($sms_sender)) && $nama) { _log("save in inbox u:" . $username . " uid:" . $uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:[" . $nohp . "]", 3, 'telek'); //recvsms_inbox_add($sms_datetime, $sms_sender, $username, $nama, $sms_receiver); //$hooked = true; //$status = ($ok ? 'handled' : 'unhandled'); } } //// $ret['uid'] = user_mobile2uid($sms_sender); //// $ret['status'] = TRUE; // $ret['param']['message'] = $ikut . ' ' . $nama .' '. $nohp . ' ' . $pengguna; // $ret['modified'] = TRUE; // $ret['hooked'] = TRUE; $ret = user_add($data); $ok = $ret['status'] ? TRUE : FALSE; if ($ok) { echo "okee"; $items = array('uid' => 1, 'name' => $data['name'], 'mobile' => $data['mobile'], 'email' => $data['email'], 'tags' => $tags); if ($c_pid = dba_add(_DB_PREF_ . '_featurePhonebook', $items)) { $save_to_group = TRUE; } else { logger_print('fail to add contact pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email . ' tags:[' . $tags . ']', 3, 'phonebook_add'); } } else { echo "gagal"; } return $ret; }
/** * Add new user * * @param array $data * User data * @param boolean $forced * Forced addition * @param boolean $send_email * Send email after successful user addition * @return array $ret['error_string', 'status', 'uid', 'data'] */ function user_add($data = array(), $forced = FALSE, $send_email = TRUE) { global $core_config, $user_config; // default return values $ret['error_string'] = _('Unknown error has occurred'); $ret['status'] = FALSE; $ret['uid'] = 0; $ret['data'] = array(); $data = trim($data['username']) ? $data : $_REQUEST; if ($forced || auth_isadmin() || $user_config['status'] == 3 || !auth_isvalid() && $core_config['main']['enable_register']) { foreach ($data as $key => $val) { $data[$key] = trim($val); } // set valid status $data['status'] = (int) $data['status']; if (!($data['status'] == 2 || $data['status'] == 3)) { $data['status'] = 4; } // ACL exception for admins $data['acl_id'] = (int) $data['acl_id'] ? (int) $data['acl_id'] : $core_config['main']['default_acl']; if ($data['status'] == 2) { $data['acl_id'] = 0; } // default parent_id $data['parent_uid'] = (int) $data['parent_uid'] ? (int) $data['parent_uid'] : $core_config['main']['default_parent']; if ($parent_status = user_getfieldbyuid($data['parent_uid'], 'status')) { // logic for parent_uid, parent uid by default is 0 if ($data['status'] == 4) { if (!($parent_status == 2 || $parent_status == 3)) { $data['parent_uid'] = $core_config['main']['default_parent']; } } else { $data['parent_uid'] = $core_config['main']['default_parent']; } } else { $data['parent_uid'] = $core_config['main']['default_parent']; } $data['username'] = core_sanitize_username($data['username']); $data['password'] = trim($data['password']) ? trim($data['password']) : core_get_random_string(10); $register_password = $data['password']; $data['password'] = md5($register_password); $data['token'] = md5(uniqid($data['username'] . $data['password'], true)); // default credit $supplied_credit = (double) $data['credit']; $data['credit'] = 0; // sender set to empty by default // $data['sender'] = ($data['sender'] ? core_sanitize_sender($data['sender']) : ''); $data['sender'] = ''; $dt = core_get_datetime(); $data['register_datetime'] = $dt; $data['lastupdate_datetime'] = $dt; // fixme anton - these should be configurable on main config $data['footer'] = '@' . $data['username']; $data['enable_webservices'] = 1; // $data['webservices_ip'] = (trim($data['webservices_ip']) ? trim($data['webservices_ip']) : '127.0.0.1, 192.168.*.*'); $data['webservices_ip'] = '*.*.*.*'; $v = user_add_validate($data); if ($v['status']) { _log('attempt to register status:' . $data['status'] . ' u:' . $data['username'] . ' email:' . $data['email'], 3, 'user_add'); if ($data['username'] && $data['email'] && $data['name']) { if ($new_uid = dba_add(_DB_PREF_ . '_tblUser', $data)) { $ret['status'] = TRUE; $ret['uid'] = $new_uid; // set credit upon registration $default_credit = $supplied_credit ? $supplied_credit : (double) $core_config['main']['default_credit']; rate_addusercredit($ret['uid'], $default_credit); } else { $ret['error_string'] = _('Fail to register an account'); } if ($ret['status']) { $data['credit'] = user_getfieldbyuid($new_uid, 'credit'); $data['register_password'] = $register_password; _log('registered status:' . $data['status'] . ' u:' . $data['username'] . ' uid:' . $ret['uid'] . ' email:' . $data['email'] . ' ip:' . $_SERVER['REMOTE_ADDR'] . ' mobile:' . $data['mobile'] . ' credit:' . $data['credit'], 2, 'user_add'); // save $data on returns $ret['data'] = $data; // default is TRUE, always send email from this function if ($send_email) { // injected variables must be global, need to work on this later global $reg_data; $reg_data = $ret['data']; // send email $tpl = array('name' => 'user_add_email', 'vars' => array('Name' => _('Name'), 'Username' => _('Username'), 'Password' => _('Password'), 'Mobile' => _('Mobile'), 'Credit' => _('Credit'), 'Email' => _('Email')), 'injects' => array('core_config', 'reg_data')); $email_body = tpl_apply($tpl); $email_subject = _('New account registration'); $mail_data = array('mail_from_name' => $core_config['main']['web_title'], 'mail_from' => $core_config['main']['email_service'], 'mail_to' => $data['email'], 'mail_subject' => $email_subject, 'mail_body' => $email_body); if (sendmail($mail_data)) { $ret['error_string'] = _('Account has been added and password has been emailed') . " (" . _('username') . ": " . $data['username'] . ")"; } else { $ret['error_string'] = _('Account has been added but failed to send email') . " (" . _('username') . ": " . $data['username'] . ")"; } } } } else { $ret['error_string'] = _('You must fill all required fields'); } } else { $ret['error_string'] = $v['error_string']; } } else { $ret['error_string'] = _('Account registration is not available'); } return $ret; }
function sms_poll_handle($list, $sms_datetime, $sms_sender, $poll_keyword, $poll_param = '', $sms_receiver = '', $smsc = '', $raw_message = '') { $ok = false; $smsc = gateway_decide_smsc($smsc, $list['smsc']); $poll_keyword = strtoupper(trim($poll_keyword)); $poll_param = strtoupper(trim($poll_param)); $choice_keyword = $poll_param; if ($sms_sender && $poll_keyword && $choice_keyword) { $poll_id = $list['poll_id']; // if poll disabled then immediately return, just ignore the vote if (!$list['poll_enable']) { logger_print('vote s:' . $sms_sender . ' k:' . $poll_keyword . ' c:' . $choice_keyword . ' poll disabled', 2, 'sms_poll'); return TRUE; } $db_query = "SELECT choice_id FROM " . _DB_PREF_ . "_featurePoll_choice WHERE choice_keyword='{$choice_keyword}' AND poll_id='{$poll_id}'"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); $choice_id = (int) $db_row['choice_id']; $db_table = _DB_PREF_ . "_featurePoll_log"; $items = array('poll_id' => $poll_id, 'choice_id' => $choice_id, 'poll_sender' => $sms_sender, 'in_datetime' => core_get_datetime(), 'status' => 0); // status 0 = failed/unknown // status 1 = valid // status 2 = out of vote option // status 3 = invalid $log_id = dba_add($db_table, $items); if ($poll_id && $choice_id) { $continue = sms_poll_check_option_vote($list, $sms_sender, $poll_keyword, $choice_keyword); if ($continue) { // send message valid if (dba_update($db_table, array('status' => 1), array('log_id' => $log_id))) { logger_print('vote s:' . $sms_sender . ' k:' . $poll_keyword . ' c:' . $choice_keyword . ' log_id:' . $log_id . ' valid vote', 2, 'sms_poll'); if (($poll_message_valid = trim($list['poll_message_valid'])) && ($c_username = user_uid2username($list['uid']))) { $unicode = core_detect_unicode($poll_message_valid); $poll_message_valid = addslashes($poll_message_valid); list($ok, $to, $smslog_id, $queue_code) = sendsms_helper($c_username, $sms_sender, $poll_message_valid, 'text', $unicode, $smsc); } } } else { // send message out of vote option if (dba_update($db_table, array('status' => 2), array('log_id' => $log_id))) { logger_print('vote s:' . $sms_sender . ' k:' . $poll_keyword . ' c:' . $choice_keyword . ' log_id:' . $log_id . ' out of vote option', 2, 'sms_poll'); if (($poll_message_option = trim($list['poll_message_option'])) && ($c_username = user_uid2username($list['uid']))) { $unicode = core_detect_unicode($poll_message_option); $poll_message_option = addslashes($poll_message_option); list($ok, $to, $smslog_id, $queue_code) = sendsms_helper($c_username, $sms_sender, $poll_message_option, 'text', $unicode, $smsc); } } } $ok = true; } else { // send message invalid if (dba_update($db_table, array('status' => 3), array('log_id' => $log_id))) { logger_print('vote s:' . $sms_sender . ' k:' . $poll_keyword . ' c:' . $choice_keyword . ' log_id:' . $log_id . ' invalid vote', 2, 'sms_poll'); if (($poll_message_invalid = trim($list['poll_message_invalid'])) && ($c_username = user_uid2username($list['uid']))) { $unicode = core_detect_unicode($poll_message_invalid); $poll_message_invalid = addslashes($poll_message_invalid); list($ok, $to, $smslog_id, $queue_code) = sendsms_helper($c_username, $sms_sender, $poll_message_invalid, 'text', $unicode, $smsc); } } } } return $ok; }