Пример #1
0
 /**
  * 
  */
 public static function send($pn_user_id, $ps_message)
 {
     global $AUTH_CURRENT_USER_ID, $g_request;
     if (!function_exists("curl_init")) {
         return false;
     }
     if ($pn_user_id == $AUTH_CURRENT_USER_ID) {
         $t_user = $g_request->user;
         // use request user object
     } else {
         $t_user = new ca_users($pn_user_id);
     }
     if (!$t_user->getPrimaryKey()) {
         return null;
     }
     if (!$t_user->get('sms_number')) {
         return null;
     }
     if (!($vn_sendhub_contact_id = $t_user->getVar('sms_sendhub_contact_id')) || $t_user->getVar('sms_sendhub_phone_number') != $t_user->get('sms_number')) {
         if (!($vn_sendhub_contact_id = WLPlugSMSSendHub::addContact($t_user))) {
             // TODO: check and log errors here
             return null;
         }
     }
     $vs_user = $t_user->getAppConfig()->get('sms_user');
     $vs_api_key = $t_user->getAppConfig()->get('sms_api_key');
     $vs_url = "https://api.sendhub.com/v1/messages/?username={$vs_user}&api_key={$vs_api_key}";
     $o_ch = curl_init();
     $ps_message = stripslashes(rawurldecode($ps_message));
     $ps_message = trim(preg_replace("!\n+!", "\\" . "n", $ps_message));
     curl_setopt($o_ch, CURLOPT_URL, $vs_url);
     curl_setopt($o_ch, CURLOPT_HEADER, false);
     curl_setopt($o_ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
     curl_setopt($o_ch, CURLOPT_POSTFIELDS, '{"contacts":[' . $vn_sendhub_contact_id . '],"text":"' . $ps_message . '"}');
     curl_setopt($o_ch, CURLOPT_RETURNTRANSFER, 1);
     $vs_return = curl_exec($o_ch);
     $va_return = json_decode($vs_return);
     // TODO: check and log errors here
     curl_close($o_ch);
     return true;
 }
<?php

require '../../../setup.php';
require_once __CA_LIB_DIR__ . "/core/Db.php";
require_once __CA_MODELS_DIR__ . "/ca_users.php";
$o_db = new Db();
$q_users = $o_db->query("select user_id from ca_users");
$t_user = new ca_users();
while ($q_users->nextRow()) {
    $t_user->load($q_users->get("user_id"));
    $t_user->setMode(ACCESS_WRITE);
    $t_user->setPreference("user_profile_field_of_research", $t_user->getVar("field_of_research"));
    $t_user->update();
}