Exemplo n.º 1
0
 /**
  * Build the form
  *
  * @access public
  * @return void
  */
 function buildQuickForm()
 {
     if (!$this->_single) {
         $toArray = array();
         foreach ($this->_contactIds as $contactId) {
             list($toDisplayName, $toSMS) = CRM_Contact_BAO_Contact::getPhoneDetails($contactId, 'Mobile');
             if (!empty($toSMS)) {
                 $toArray[] = "\"{$toDisplayName}\" <{$toSMS}>";
             }
         }
         $this->assign('to', implode(', ', $toArray));
     } else {
         $to =& $this->add('select', 'to', ts('To'), $this->_smsNumbers, true);
         if (count($this->_smsNumbers) <= 1) {
             foreach ($this->_smsNumbers as $number => $dontCare) {
                 $defaults = array('to' => $number);
                 $this->setDefaults($defaults);
             }
             $to->freeze();
         }
     }
     $session =& CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     list($fromDisplayName, $fromSMS) = CRM_Contact_BAO_Contact::getPhoneDetails($userID, 'Mobile');
     if (!$fromSMS) {
         CRM_Utils_System::statusBounce(ts('Your user record does not have a valid SMS number'));
     }
     $from = '"' . $fromDisplayName . '"' . "<{$fromSMS}>";
     $this->assign('from', $from);
     $this->add('textarea', 'message', ts('Message'), CRM_Core_DAO::getAttribute('CRM_SMS_DAO_History', 'message'), true);
     if ($this->_single) {
         // also fix the user context stack
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/activity', '&show=1&action=browse&cid=' . $this->_contactIds[0]));
         $this->addDefaultButtons(ts('Send SMS'), 'next', 'cancel');
     } else {
         $this->addDefaultButtons(ts('Send SMS'));
     }
 }
Exemplo n.º 2
0
 /**
  * send the message to a specific contact
  *
  * @param string $from       the name and sms of the sender
  * @param int    $toID       the contact id of the recipient       
  * @param string $message    the message contents
  * @param string $smsNumber  use this 'number' instead of the default primary sms number
  * @param int    $activityID the activity ID that tracks the message
  *
  * @return array             (total, added, notAdded) count of emails sent
  * @access public
  * @static
  */
 function sendMessage($from, $toID, &$message, $smsNumber, $activityID)
 {
     list($toDisplayName, $toSMS) = CRM_Contact_BAO_Contact::getPhoneDetails($toID, 'Mobile');
     if ($toSMS) {
         $to = trim($toSMS);
     }
     // make sure sms number is non-empty
     if (empty($to)) {
         return false;
     }
     $params = array();
     $params['From'] = $from;
     $params['To'] = $to;
     $params['Body'] = $message;
     $params['id'] = substr(md5(uniqid(rand(), true)), 0, 31);
     $params['Type'] = "SMS_TEXT";
     $aggregator =& CRM_SMS_Protocol::singleton();
     if (!$aggregator->sendMessage($params)) {
         return false;
     }
     // we need to insert an activity history record here
     $params = array('entity_table' => 'civicrm_contact', 'entity_id' => $toID, 'activity_type' => ts('SMS Sent'), 'module' => 'CiviCRM', 'callback' => 'CRM_SMS_BAO_History::details', 'activity_id' => $activityID, 'activity_summary' => ts('To: %1; Message: %2', array(1 => "{$toDisplayName} <{$toSMS}>", 2 => $message)), 'activity_date' => date('YmdHis'));
     if (is_a(crm_create_activity_history($params), CRM_Core_Error)) {
         return false;
     }
     return true;
 }