/**
  * @param $self
  */
 public static function commonBuildQuickForm($self)
 {
     $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $self);
     if (!$contactId) {
         $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST);
     }
     $urlParams = "action=add&reset=1&cid={$contactId}&selectedChild=activity&atype=";
     $activityTypes = $urls = array();
     $emailTypeId = CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name');
     $letterTypeId = CRM_Core_OptionGroup::getValue('activity_type', 'Print PDF Letter', 'name');
     $SMSId = CRM_Core_OptionGroup::getValue('activity_type', 'Text Message (SMS)', 'label');
     if (CRM_Utils_Mail::validOutBoundMail() && $contactId) {
         list($name, $email, $doNotEmail, $onHold, $isDeseased) = CRM_Contact_BAO_Contact::getContactDetails($contactId);
         if (!$doNotEmail && $email && !$isDeseased) {
             $activityTypes = array($emailTypeId => ts('Send an Email'));
         }
     }
     if ($contactId && CRM_SMS_BAO_Provider::activeProviderCount()) {
         // Check for existence of a mobile phone and ! do not SMS privacy setting
         $mobileTypeID = CRM_Core_OptionGroup::getValue('phone_type', 'Mobile', 'name');
         list($name, $phone, $doNotSMS) = CRM_Contact_BAO_Contact_Location::getPhoneDetails($contactId, $mobileTypeID);
         if (!$doNotSMS && $phone) {
             $sendSMS = array($SMSId => ts('Send SMS'));
             $activityTypes += $sendSMS;
         }
     }
     // this returns activity types sorted by weight
     $otherTypes = CRM_Core_PseudoConstant::activityType(FALSE);
     $activityTypes += $otherTypes;
     foreach (array_keys($activityTypes) as $typeId) {
         if ($typeId == $emailTypeId) {
             $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/email/add', "{$urlParams}{$typeId}", FALSE, NULL, FALSE);
         } elseif ($typeId == $SMSId) {
             $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/sms/add', "{$urlParams}{$typeId}", FALSE, NULL, FALSE);
         } elseif ($typeId == $letterTypeId) {
             $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/pdf/add', "{$urlParams}{$typeId}", FALSE, NULL, FALSE);
         } else {
             $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/add', "{$urlParams}{$typeId}", FALSE, NULL, FALSE);
         }
     }
     $self->assign('activityTypes', $activityTypes);
     $self->assign('urls', $urls);
     $self->assign('suppressForm', TRUE);
 }
示例#2
0
文件: SMS.php 项目: ksecor/civicrm
 /**
  * Build the form
  *
  * @access public
  * @return void
  */
 public function buildQuickForm()
 {
     if (!$this->_single) {
         $toArray = array();
         foreach ($this->_contactIds as $contactId) {
             list($toDisplayName, $toSMS) = CRM_Contact_BAO_Contact_Location::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_Location::getPhoneDetails($userID, 'Mobile');
     if (!$fromSMS) {
         CRM_Core_Error::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'));
     }
 }
示例#3
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
  */
 static function sendMessage($from, $toID, &$message, $smsNumber, $activityID)
 {
     list($toDisplayName, $toSMS) = CRM_Contact_BAO_Contact_Location::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;
 }