/** * send reminders * @param SugarBean $bean * @param Administration $admin * @param array $recipients * @return boolean */ protected function sendReminders(SugarBean $bean, Administration $admin, $recipients) { if (empty($_SESSION['authenticated_user_language'])) { $current_language = $GLOBALS['sugar_config']['default_language']; } else { $current_language = $_SESSION['authenticated_user_language']; } if (!empty($bean->created_by)) { $user_id = $bean->created_by; } else { if (!empty($bean->assigned_user_id)) { $user_id = $bean->assigned_user_id; } else { $user_id = $GLOBALS['current_user']->id; } } $user = new User(); $user->retrieve($bean->created_by); $OBCharset = $GLOBALS['locale']->getPrecedentPreference('default_email_charset'); ///////////////////SMS/////////////////////////// require_once 'custom/sms/sms.php'; $sms = new sms(); $sms->parent_type = 'Users'; foreach ($recipients as $r) { $sms->parent_id = $r['id']; $sms->pname = $r['name']; $type = $bean->object_name == "Call" ? "Вам назначен звонок " : "Вам назначена Встреча "; $text = $type . $bean->name . " на " . $bean->date_start; $resp = $sms->send_message($r['number'], $text); //TODO if ($resp == "SENT") { return true; } else { return false; } } return true; }
echo "<td valign='top'>Сообщение не отправлено</td></tr>"; echo "<td valign='top'>Нажмите F5</td></tr>"; } } echo "</table>"; } else { echo $summary; } echo "<div style='margin-top:15px;'>Нажмите F5, чтобы закрыть это сообщение.</div>"; } } else { # single recipient $sms->parent_type = $_POST['ptype']; $sms->parent_id = $_POST['pid']; $sms->pname = $_POST["pname"]; $resp = $sms->send_message($_POST["num"], $_POST["sms_msg"]); if ($resp == "SENT") { echo "Сообщение успешно отправленно. Нажмите F5"; //echo "<td valign='top'>Нажмите F5</td></tr>"; } else { echo "Сообщение не отправленно. Нажмите F5"; //echo "<td valign='top'>Нажмите F5</td></tr>"; } } } else { echo "Отправка сообщения не удалась. Представленные данные пусты."; } break; case "resend": $sms->retrieve_settings(); if ($sms->authenticate($sms->params['sms_instance_id']) == 'ERROR') {
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; } }