示例#1
1
 /**
  * get recipients of reminding email for specific activity
  * @param string $id
  * @param string $module
  * @return array
  */
 protected function getRecipients($id, $module = "Meetings")
 {
     global $db;
     //        require_once('custom/sms/sms.php');
     //        $sms = new sms();
     require_once "modules/Administration/izeno_smsPhone/sms_enzyme.php";
     $e = new sms_enzyme('Users');
     $sms_field = $e->get_custom_phone_field();
     switch ($module) {
         case "Meetings":
             $field_part = "meeting";
             break;
         case "Calls":
             $field_part = "call";
             break;
         default:
             return array();
     }
     $phones = array();
     // fetch users
     $query = "SELECT user_id FROM {$field_part}s_users WHERE {$field_part}_id = '{$id}' AND accept_status != 'decline' AND deleted = 0\n        ";
     $re = $db->query($query);
     while ($row = $db->fetchByAssoc($re)) {
         $user = new User();
         $user->retrieve($row['user_id']);
         $arr = array('type' => 'Users', 'name' => $user->full_name, 'number' => $user->phone_mobile, 'id' => $user->id);
         $phones[] = $arr;
     }
     return $phones;
 }
示例#2
0
         $msg = $sugartalk_SMS->description;
         $pid = $sugartalk_SMS->id;
         // uses $pid to store the record id
         $ptype = $sugartalk_SMS->parent_type;
         // not really needed but may be later
         $pname = $sugartalk_SMS->name;
         // not really needed but may be later
         $onclick = "resend_sms();";
         $send_to_multi = '0';
     } else {
         $mod_key_sing = $GLOBALS["beanList"][$_GET['ptype']];
         $mod_bean_files = $GLOBALS["beanFiles"][$mod_key_sing];
         # retrieve configured SMS phone field for the active module
         require_once "modules/Administration/sugartalk_smsPhone/sms_enzyme.php";
         $e = new sms_enzyme($_GET['ptype']);
         $sms_field = $e->get_custom_phone_field();
         $msg = "";
         $pid = $_GET['pid'];
         $pids = explode(",", $pid);
         $ptype = $_GET['ptype'];
         $pname = isset($_GET['pname']) ? $_GET['pname'] : "";
         $phone_number = $_GET['num'];
         $onclick = "send_sms();";
         $send_to_multi = $_GET['num'] == 'multi' ? '1' : '0';
     }
     include_once "modules/Administration/sugartalk_smsPhone/sms_editor.php";
     break;
 case "template":
     if (isset($_GET['id'])) {
         $et = new EmailTemplate();
         $et->retrieve($_GET['id']);
示例#3
0
 function sendSMS($save_emails = 1, $testmode = false)
 {
     require_once 'custom/sms/sms.php';
     require_once 'modules/Administration/sugartalk_smsPhone/sms_enzyme.php';
     $sms = new sms();
     $sms->retrieve_settings();
     global $beanList, $beanFiles, $sugar_config;
     global $mod_strings;
     $mod_strings = return_module_language($sugar_config['default_language'], 'EmailMan');
     if (!isset($beanList[$this->related_type])) {
         return false;
     }
     $class = $beanList[$this->related_type];
     if (!class_exists($class)) {
         require_once $beanFiles[$class];
     }
     if (!class_exists('SMS')) {
     }
     $module = new $class();
     // tracy: the module
     $module->retrieve($this->related_id);
     // tracy: person's id
     $mod = array_search($class, $beanList);
     # tracy: use the selected phone field else use the default phone_mobile (esp for Users)
     $phone_number = "";
     if ($mod == "Users") {
         $phone_number = $module->phone_mobile;
     } elseif (!empty($mod)) {
         $e = new sms_enzyme($mod);
         $phone_field = $e->get_custom_phone_field();
         if (!empty($phone_field)) {
             $phone_number = $module->{$phone_field};
         }
     }
     $phone_number = preg_replace('/[^0-9]/', '', $phone_number);
     $this->test = $testmode;
     # tracy: invalid if there's no number
     if (empty($phone_number) or $phone_number == '') {
         $this->set_as_sent($phone_number, true, null, 'SMS', 'invalid email');
         $GLOBALS['log']->debug('Phone number was empty. Emailman id = ' . $this->id);
     }
     # tracy: check if phone number is in the suppression list
     if (isset($this->restricted_phone_numbers) && isset($this->restricted_phone_numbers[$phone_number])) {
         if ($this->restricted_phone_numbers[$phone_number] == 1) {
             $this->set_as_sent($phone_number, true, null, 'SMS', 'blocked');
             $GLOBALS['log']->debug('Phone number is in the suppression list by phone number. Emailman id = ' . $this->id);
             return true;
         }
     }
     //fetch email marketing.
     if (empty($this->current_emailmarketing) or !isset($this->current_emailmarketing)) {
         if (!class_exists('EmailMarketing')) {
         }
         $this->current_emailmarketing = new EmailMarketing();
     }
     if (empty($this->current_emailmarketing->id) or $this->current_emailmarketing->id !== $this->marketing_id) {
         $this->current_emailmarketing->retrieve($this->marketing_id);
         $this->newmessage = true;
     }
     //fetch email template associated with the marketing message.
     if (empty($this->current_emailtemplate) or $this->current_emailtemplate->id != $this->current_emailmarketing->template_id) {
         if (!class_exists('EmailTemplate')) {
         }
         $this->current_emailtemplate = new EmailTemplate();
         $this->current_emailtemplate->retrieve($this->current_emailmarketing->template_id);
     }
     $sms_message = isset($this->current_emailtemplate->body) ? $this->current_emailtemplate->body : '';
     //parse and replace bean variables in sms_message
     $template_data = $this->current_emailtemplate->parse_email_template(array('body' => $sms_message), 'Contacts', $module, $macro_nv);
     // what if user chose other accounts or user? hmm
     //replace sms_message with clean message
     $sms_message = $template_data['body'];
     # tracy: do not send sms if msg is empty
     if ($sms_message == '') {
         $this->set_as_sent($phone_number, true, null, 'SMS', 'send error');
         $GLOBALS['log']->debug('Message was empty. Emailman id = ' . $this->id);
         return false;
     }
     // fetch campaign details..
     if (empty($this->current_campaign)) {
         if (!class_exists('Campaign')) {
         }
         $this->current_campaign = new Campaign();
     }
     //refetch strings in case they have been changed by creation of email templates or other beans.
     $mod_strings = return_module_language($sugar_config['default_language'], 'EmailMan');
     # get the parent info
     $sms->parent_type = $module->object_name == 'Case' ? 'Cases' : array_search($module->object_name, $beanList);
     $sms->parent_id = $module->id;
     if (isset($sms->params) && !empty($sms->params)) {
         $sms->pname = $module->name;
         $res = $sms->send_message($phone_number, $sms_message);
         # tracy: this handles the error response from the api
         if ($sms->response_text == "SENT" || $res == "SENT") {
             $this->set_as_sent($phone_number, true, null, 'SMS', 'targeted');
             $GLOBALS['log']->debug('Message sent to {$phone_number}. Emailman id = ' . $this->id);
             return true;
         } else {
             $this->set_as_sent($phone_number, true, null, 'SMS', 'send error');
             $GLOBALS['log']->fatal('API Error: {$sms->response_text}. Emailman id = ' . $this->id);
             return false;
         }
     } else {
         $this->set_as_sent($phone_number, true, null, 'SMS', 'send error');
         $GLOBALS['log']->fatal('SMS Config Error: There was no provider configured for this service. Emailman id = ' . $this->id);
         return false;
     }
 }