Exemplo n.º 1
0
 /**
  * Singleton function used to manage this object.
  *
  * @param array $providerParams
  * @param bool $force
  *
  * @return object
  */
 public static function &singleton($providerParams = array(), $force = FALSE)
 {
     $mailingID = CRM_Utils_Array::value('mailing_id', $providerParams);
     $providerID = CRM_Utils_Array::value('provider_id', $providerParams);
     $providerName = CRM_Utils_Array::value('provider', $providerParams);
     if (!$providerID && $mailingID) {
         $providerID = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $mailingID, 'sms_provider_id', 'id');
         $providerParams['provider_id'] = $providerID;
     }
     if ($providerID) {
         $providerName = CRM_SMS_BAO_Provider::getProviderInfo($providerID, 'name');
     }
     if (!$providerName) {
         CRM_Core_Error::fatal('Provider not known or not provided.');
     }
     $providerName = CRM_Utils_Type::escape($providerName, 'String');
     $cacheKey = "{$providerName}_" . (int) $providerID . "_" . (int) $mailingID;
     if (!isset(self::$_singleton[$cacheKey]) || $force) {
         $ext = CRM_Extension_System::singleton()->getMapper();
         if ($ext->isExtensionKey($providerName)) {
             $paymentClass = $ext->keyToClass($providerName);
             require_once "{$paymentClass}.php";
         } else {
             CRM_Core_Error::fatal("Could not locate extension for {$providerName}.");
         }
         self::$_singleton[$cacheKey] = $paymentClass::singleton($providerParams, $force);
     }
     return self::$_singleton[$cacheKey];
 }
Exemplo n.º 2
0
 /**
  * Set variables up before form is built.
  */
 public function preProcess()
 {
     if (!CRM_SMS_BAO_Provider::activeProviderCount()) {
         CRM_Core_Error::fatal(ts('The <a href="%1">SMS Provider</a> has not been configured or is not active.', array(1 => CRM_Utils_System::url('civicrm/admin/sms/provider', 'reset=1'))));
     }
     $session = CRM_Core_Session::singleton();
     $session->replaceUserContext(CRM_Utils_System::url('civicrm/mailing/browse', 'reset=1&sms=1'));
 }
Exemplo n.º 3
0
 public static function initTasks()
 {
     if (!self::$_tasks) {
         self::$_tasks = array(self::GROUP_CONTACTS => array('title' => ts('Add Contacts to Group'), 'class' => 'CRM_Contact_Form_Task_AddToGroup'), self::REMOVE_CONTACTS => array('title' => ts('Remove Contacts from Group'), 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup'), self::TAG_CONTACTS => array('title' => ts('Tag Contacts (assign tags)'), 'class' => 'CRM_Contact_Form_Task_AddToTag'), self::REMOVE_TAGS => array('title' => ts('Untag Contacts (remove tags)'), 'class' => 'CRM_Contact_Form_Task_RemoveFromTag'), self::EXPORT_CONTACTS => array('title' => ts('Export Contacts'), 'class' => array('CRM_Export_Form_Select', 'CRM_Export_Form_Map'), 'result' => FALSE), self::EMAIL_CONTACTS => array('title' => ts('Send Email to Contacts'), 'class' => 'CRM_Contact_Form_Task_Email', 'result' => TRUE), self::DELETE_CONTACTS => array('title' => ts('Delete Contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), self::RECORD_CONTACTS => array('title' => ts('Record Activity for Contacts'), 'class' => 'CRM_Activity_Form_Activity'), self::SAVE_SEARCH => array('title' => ts('New Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch', 'result' => TRUE), self::SAVE_SEARCH_UPDATE => array('title' => ts('Update Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', 'result' => TRUE), self::PRINT_CONTACTS => array('title' => ts('Print Selected Rows'), 'class' => 'CRM_Contact_Form_Task_Print', 'result' => FALSE), self::LABEL_CONTACTS => array('title' => ts('Mailing Labels'), 'class' => 'CRM_Contact_Form_Task_Label', 'result' => TRUE), self::BATCH_UPDATE => array('title' => ts('Batch Update via Profile'), 'class' => array('CRM_Contact_Form_Task_PickProfile', 'CRM_Contact_Form_Task_Batch'), 'result' => TRUE), self::PRINT_FOR_CONTACTS => array('title' => ts('Print PDF Letter for Contacts'), 'class' => 'CRM_Contact_Form_Task_PDF', 'result' => TRUE), self::EMAIL_UNHOLD => array('title' => ts('Unhold Emails'), 'class' => 'CRM_Contact_Form_Task_Unhold'), self::COMMUNICATION_PREFS => array('title' => ts('Alter Contact Communication Preferences'), 'class' => 'CRM_Contact_Form_Task_AlterPreferences'), self::RESTORE => array('title' => ts('Restore Contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), self::DELETE_PERMANENTLY => array('title' => ts('Delete Permanently'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE));
         //CRM-16329, if SMS provider is configured show sms action.
         $providersCount = CRM_SMS_BAO_Provider::activeProviderCount();
         if ($providersCount) {
             self::$_tasks[self::SMS_CONTACTS] = array('title' => ts('Send SMS to Contacts'), 'class' => 'CRM_Contact_Form_Task_SMS', 'result' => TRUE);
         }
         if (CRM_Contact_BAO_ContactType::isActive('Household')) {
             $label = CRM_Contact_BAO_ContactType::getLabel('Household');
             self::$_tasks[self::HOUSEHOLD_CONTACTS] = array('title' => ts('Add Contacts to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToHousehold');
         }
         if (CRM_Contact_BAO_ContactType::isActive('Organization')) {
             $label = CRM_Contact_BAO_ContactType::getLabel('Organization');
             self::$_tasks[self::ORGANIZATION_CONTACTS] = array('title' => ts('Add Contacts to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToOrganization');
         }
         if (CRM_Core_Permission::check('merge duplicate contacts')) {
             self::$_tasks[self::MERGE_CONTACTS] = array('title' => ts('Merge Contacts'), 'class' => 'CRM_Contact_Form_Task_Merge', 'result' => TRUE);
         }
         //CRM-4418, check for delete
         if (!CRM_Core_Permission::check('delete contacts')) {
             unset(self::$_tasks[self::DELETE_CONTACTS]);
         }
         //show map action only if map provider and geoprovider are set (Google doesn't need geoprovider)
         // should fix this to be more flexible as providers are added ??
         $config = CRM_Core_Config::singleton();
         if ($config->mapProvider && ($config->mapProvider == 'Google' || ($config->mapProvider == 'OpenStreetMaps' || $config->geoProvider == 'Google'))) {
             self::$_tasks[self::MAP_CONTACTS] = array('title' => ts('Map Contacts'), 'class' => 'CRM_Contact_Form_Task_Map', 'result' => FALSE);
         }
         if (CRM_Core_Permission::access('CiviEvent')) {
             self::$_tasks[self::ADD_EVENT] = array('title' => ts('Add Contacts to Event'), 'class' => 'CRM_Event_Form_Participant');
         }
         if (defined('CIVICRM_CIVIMAIL_UI_LEGACY')) {
             if (CRM_Core_Permission::access('CiviMail')) {
                 self::$_tasks[self::CREATE_MAILING] = array('title' => ts('Schedule/Send a Mass Mailing'), 'class' => array('CRM_Mailing_Form_Group', 'CRM_Mailing_Form_Settings', 'CRM_Mailing_Form_Upload', 'CRM_Mailing_Form_Test', 'CRM_Mailing_Form_Schedule'), 'result' => FALSE);
             } elseif (CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) {
                 self::$_tasks[self::CREATE_MAILING] = array('title' => ts('Create a Mass Mailing'), 'class' => array('CRM_Mailing_Form_Group', 'CRM_Mailing_Form_Settings', 'CRM_Mailing_Form_Upload', 'CRM_Mailing_Form_Test'), 'result' => FALSE);
             }
         } else {
             if (CRM_Core_Permission::access('CiviMail') || CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) {
                 self::$_tasks[self::CREATE_MAILING] = array('title' => ts('Schedule/Send a Mass Mailing'), 'class' => 'CRM_Mailing_Form_Task_AdhocMailing', 'result' => FALSE);
             }
         }
         self::$_tasks += CRM_Core_Component::taskList();
         CRM_Utils_Hook::searchTasks('contact', self::$_tasks);
         asort(self::$_tasks);
     }
 }
/**
 * Implementation of hook_civicrm_disable
 */
function clickatell_civicrm_disable()
{
    $optionID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', 'clickatell', 'id', 'name');
    if ($optionID) {
        CRM_Core_BAO_OptionValue::setIsActive($optionID, FALSE);
    }
    $filter = array('name' => 'org.civicrm.sms.clickatell');
    $Providers = CRM_SMS_BAO_Provider::getProviders(False, $filter, False);
    if ($Providers) {
        foreach ($Providers as $key => $value) {
            CRM_SMS_BAO_Provider::setIsActive($value['id'], FALSE);
        }
    }
    return _clickatell_civix_civicrm_disable();
}
Exemplo n.º 5
0
 /**
  * @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);
 }
Exemplo n.º 6
0
 public static function initTasks()
 {
     if (!self::$_tasks) {
         self::$_tasks = array(self::GROUP_CONTACTS => array('title' => ts('Group - add contacts'), 'class' => 'CRM_Contact_Form_Task_AddToGroup'), self::REMOVE_CONTACTS => array('title' => ts('Group - remove contacts'), 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup'), self::TAG_CONTACTS => array('title' => ts('Tag - add to contacts'), 'class' => 'CRM_Contact_Form_Task_AddToTag'), self::REMOVE_TAGS => array('title' => ts('Tag - remove from contacts'), 'class' => 'CRM_Contact_Form_Task_RemoveFromTag'), self::EXPORT_CONTACTS => array('title' => ts('Export contacts'), 'class' => array('CRM_Export_Form_Select', 'CRM_Export_Form_Map'), 'result' => FALSE), self::EMAIL_CONTACTS => array('title' => ts('Email - send now (to 50 or less)'), 'class' => 'CRM_Contact_Form_Task_Email', 'result' => TRUE), self::DELETE_CONTACTS => array('title' => ts('Delete contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), self::RECORD_CONTACTS => array('title' => ts('Add activity'), 'class' => 'CRM_Activity_Form_Activity'), self::SAVE_SEARCH => array('title' => ts('Smart group - create'), 'class' => 'CRM_Contact_Form_Task_SaveSearch', 'result' => TRUE), self::SAVE_SEARCH_UPDATE => array('title' => ts('Smart group - update'), 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', 'result' => TRUE), self::PRINT_CONTACTS => array('title' => ts('Print selected rows'), 'class' => 'CRM_Contact_Form_Task_Print', 'result' => FALSE), self::LABEL_CONTACTS => array('title' => ts('Mailing labels - print'), 'class' => 'CRM_Contact_Form_Task_Label', 'result' => TRUE), self::BATCH_UPDATE => array('title' => ts('Batch update contacts via profile'), 'class' => array('CRM_Contact_Form_Task_PickProfile', 'CRM_Contact_Form_Task_Batch'), 'result' => TRUE), self::PRINT_FOR_CONTACTS => array('title' => ts('PDF letters - print'), 'class' => 'CRM_Contact_Form_Task_PDF', 'result' => TRUE), self::EMAIL_UNHOLD => array('title' => ts('Email - unhold addresses'), 'class' => 'CRM_Contact_Form_Task_Unhold'), self::COMMUNICATION_PREFS => array('title' => ts('Communication preferences - alter'), 'class' => 'CRM_Contact_Form_Task_AlterPreferences'), self::RESTORE => array('title' => ts('Restore contacts from trash'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE), self::DELETE_PERMANENTLY => array('title' => ts('Delete permanently'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => FALSE));
         //CRM-16329, if SMS provider is configured show sms action.
         $providersCount = CRM_SMS_BAO_Provider::activeProviderCount();
         if ($providersCount) {
             self::$_tasks[self::SMS_CONTACTS] = array('title' => ts('SMS - schedule/send'), 'class' => 'CRM_Contact_Form_Task_SMS', 'result' => TRUE);
         }
         if (CRM_Contact_BAO_ContactType::isActive('Household')) {
             $label = CRM_Contact_BAO_ContactType::getLabel('household');
             self::$_tasks[self::HOUSEHOLD_CONTACTS] = array('title' => ts('Add relationship - to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToHousehold');
         }
         if (CRM_Contact_BAO_ContactType::isActive('Organization')) {
             $label = CRM_Contact_BAO_ContactType::getLabel('organization');
             self::$_tasks[self::ORGANIZATION_CONTACTS] = array('title' => ts('Add relationship - to %1', array(1 => $label)), 'class' => 'CRM_Contact_Form_Task_AddToOrganization');
         }
         if (CRM_Core_Permission::check('merge duplicate contacts')) {
             self::$_tasks[self::MERGE_CONTACTS] = array('title' => ts('Merge contacts'), 'class' => 'CRM_Contact_Form_Task_Merge', 'result' => TRUE);
         }
         //CRM-4418, check for delete
         if (!CRM_Core_Permission::check('delete contacts')) {
             unset(self::$_tasks[self::DELETE_CONTACTS]);
         }
         //show map action only if map provider and geoprovider are set (Google doesn't need geoprovider)
         // should fix this to be more flexible as providers are added ??
         $config = CRM_Core_Config::singleton();
         if ($config->mapProvider && ($config->mapProvider == 'Google' || ($config->mapProvider == 'OpenStreetMaps' || $config->geoProvider == 'Google'))) {
             self::$_tasks[self::MAP_CONTACTS] = array('title' => ts('Map contacts'), 'class' => 'CRM_Contact_Form_Task_Map', 'result' => FALSE);
         }
         if (CRM_Core_Permission::access('CiviEvent')) {
             self::$_tasks[self::ADD_EVENT] = array('title' => ts('Register participants for event'), 'class' => 'CRM_Event_Form_Participant');
         }
         if (CRM_Core_Permission::access('CiviMail') || CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) {
             self::$_tasks[self::CREATE_MAILING] = array('title' => ts('Email - schedule/send via CiviMail'), 'class' => 'CRM_Mailing_Form_Task_AdhocMailing', 'result' => FALSE);
         }
         self::$_tasks += CRM_Core_Component::taskList();
         CRM_Utils_Hook::searchTasks('contact', self::$_tasks);
         asort(self::$_tasks);
     }
 }
 /**
  * singleton function used to manage this object
  *
  * @return object
  * @static
  *
  */
 static function &singleton($providerParams = array(), $force = FALSE)
 {
     $mailingID = CRM_Utils_Array::value('mailing_id', $providerParams);
     $providerID = CRM_Utils_Array::value('provider_id', $providerParams);
     // make clickatell default provider for now
     $providerName = CRM_Utils_Array::value('provider', $providerParams, 'clickatell');
     if (!$providerID && $mailingID) {
         $providerID = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $mailingID, 'sms_provider_id', 'id');
         $providerParams['provider_id'] = $providerID;
     }
     if ($providerID) {
         $providerName = CRM_SMS_BAO_Provider::getProviderInfo($providerID, 'name');
     }
     if (!$providerName) {
         CRM_Core_Error::fatal('Provider not known or not provided.');
     }
     $providerName = CRM_Utils_Type::escape($providerName, 'String');
     $providerName = ucfirst($providerName);
     $cacheKey = "{$providerName}_" . (int) $providerID . "_" . (int) $mailingID;
     if (!isset(self::$_singleton[$cacheKey]) || $force) {
         self::$_singleton[$cacheKey] = eval('return ' . "CRM_SMS_Provider_{$providerName}" . '::singleton( $providerParams, $force );');
     }
     return self::$_singleton[$cacheKey];
 }
Exemplo n.º 8
0
 /**
  * Build the form object.
  *
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildQuickForm(&$form)
 {
     $toArray = array();
     $providers = CRM_SMS_BAO_Provider::getProviders(NULL, NULL, TRUE, 'is_default desc');
     $providerSelect = array();
     foreach ($providers as $provider) {
         $providerSelect[$provider['id']] = $provider['title'];
     }
     $suppressedSms = 0;
     //here we are getting logged in user id as array but we need target contact id. CRM-5988
     $cid = $form->get('cid');
     if ($cid) {
         $form->_contactIds = array($cid);
     }
     $to = $form->add('text', 'to', ts('To'), array('class' => 'huge'), TRUE);
     $form->add('text', 'activity_subject', ts('Name The SMS'), array('class' => 'huge'), TRUE);
     $toSetDefault = TRUE;
     if (property_exists($form, '_context') && $form->_context == 'standalone') {
         $toSetDefault = FALSE;
     }
     // when form is submitted recompute contactIds
     $allToSMS = array();
     if ($to->getValue()) {
         $allToPhone = explode(',', $to->getValue());
         $form->_contactIds = array();
         foreach ($allToPhone as $value) {
             list($contactId, $phone) = explode('::', $value);
             if ($contactId) {
                 $form->_contactIds[] = $contactId;
                 $form->_toContactPhone[] = $phone;
             }
         }
         $toSetDefault = TRUE;
     }
     //get the group of contacts as per selected by user in case of Find Activities
     if (!empty($form->_activityHolderIds)) {
         $extendTargetContacts = 0;
         $invalidActivity = 0;
         $validActivities = 0;
         foreach ($form->_activityHolderIds as $key => $id) {
             //valid activity check
             if (CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $id, 'subject', 'id') != self::RECIEVED_SMS_ACTIVITY_SUBJECT) {
                 $invalidActivity++;
                 continue;
             }
             $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
             $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
             //target contacts limit check
             $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $targetID));
             if (count($ids) > 1) {
                 $extendTargetContacts++;
                 continue;
             }
             $validActivities++;
             $form->_contactIds = empty($form->_contactIds) ? $ids : array_unique(array_merge($form->_contactIds, $ids));
         }
         if (!$validActivities) {
             $errorMess = "";
             if ($extendTargetContacts) {
                 $errorMess = ts('One selected activity consists of more than one target contact.', array('count' => $extendTargetContacts, 'plural' => '%count selected activities consist of more than one target contact.'));
             }
             if ($invalidActivity) {
                 $errorMess = $errorMess ? ' ' : '';
                 $errorMess .= ts('The selected activity is invalid.', array('count' => $invalidActivity, 'plural' => '%count selected activities are invalid.'));
             }
             CRM_Core_Error::statusBounce(ts("%1: SMS Reply will not be sent.", array(1 => $errorMess)));
         }
     }
     if (is_array($form->_contactIds) && !empty($form->_contactIds) && $toSetDefault) {
         $returnProperties = array('sort_name' => 1, 'phone' => 1, 'do_not_sms' => 1, 'is_deceased' => 1, 'display_name' => 1);
         list($form->_contactDetails) = CRM_Utils_Token::getTokenDetails($form->_contactIds, $returnProperties, FALSE, FALSE);
         // make a copy of all contact details
         $form->_allContactDetails = $form->_contactDetails;
         foreach ($form->_contactIds as $key => $contactId) {
             $value = $form->_contactDetails[$contactId];
             //to check if the phone type is "Mobile"
             $phoneTypes = CRM_Core_OptionGroup::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name');
             if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Form_Task_SMS') {
                 //to check for "if the contact id belongs to a specified activity type"
                 $actDetails = CRM_Activity_BAO_Activity::getContactActivity($contactId);
                 if (self::RECIEVED_SMS_ACTIVITY_SUBJECT != CRM_Utils_Array::retrieveValueRecursive($actDetails, 'subject')) {
                     $suppressedSms++;
                     unset($form->_contactDetails[$contactId]);
                     continue;
                 }
             }
             if (isset($value['phone_type_id']) && $value['phone_type_id'] != CRM_Utils_Array::value('Mobile', $phoneTypes) || $value['do_not_sms'] || empty($value['phone']) || !empty($value['is_deceased'])) {
                 //if phone is not primary check if non-primary phone is "Mobile"
                 if (!empty($value['phone']) && $value['phone_type_id'] != CRM_Utils_Array::value('Mobile', $phoneTypes) && empty($value['is_deceased'])) {
                     $filter = array('do_not_sms' => 0);
                     $contactPhones = CRM_Core_BAO_Phone::allPhones($contactId, FALSE, 'Mobile', $filter);
                     if (count($contactPhones) > 0) {
                         $mobilePhone = CRM_Utils_Array::retrieveValueRecursive($contactPhones, 'phone');
                         $form->_contactDetails[$contactId]['phone_id'] = CRM_Utils_Array::retrieveValueRecursive($contactPhones, 'id');
                         $form->_contactDetails[$contactId]['phone'] = $mobilePhone;
                         $form->_contactDetails[$contactId]['phone_type_id'] = CRM_Utils_Array::value('Mobile', $phoneTypes);
                     } else {
                         $suppressedSms++;
                         unset($form->_contactDetails[$contactId]);
                         continue;
                     }
                 } else {
                     $suppressedSms++;
                     unset($form->_contactDetails[$contactId]);
                     continue;
                 }
             }
             if (isset($mobilePhone)) {
                 $phone = $mobilePhone;
             } elseif (empty($form->_toContactPhone)) {
                 $phone = $value['phone'];
             } else {
                 $phone = CRM_Utils_Array::value($key, $form->_toContactPhone);
             }
             if ($phone) {
                 $toArray[] = array('text' => '"' . $value['sort_name'] . '" (' . $phone . ')', 'id' => "{$contactId}::{$phone}");
             }
         }
         if (empty($toArray)) {
             CRM_Core_Error::statusBounce(ts('Selected contact(s) do not have a valid Phone, or communication preferences specify DO NOT SMS, or they are deceased'));
         }
     }
     //activity related variables
     if (isset($invalidActivity)) {
         $form->assign('invalidActivity', $invalidActivity);
     }
     if (isset($extendTargetContacts)) {
         $form->assign('extendTargetContacts', $extendTargetContacts);
     }
     $form->assign('toContact', json_encode($toArray));
     $form->assign('suppressedSms', $suppressedSms);
     $form->assign('totalSelectedContacts', count($form->_contactIds));
     $form->add('select', 'sms_provider_id', ts('From'), $providerSelect, TRUE);
     CRM_Mailing_BAO_Mailing::commonCompose($form);
     if ($form->_single) {
         // also fix the user context stack
         if ($form->_context) {
             $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
         } else {
             $url = CRM_Utils_System::url('civicrm/contact/view', "&show=1&action=browse&cid={$form->_contactIds[0]}&selectedChild=activity");
         }
         $session = CRM_Core_Session::singleton();
         $session->replaceUserContext($url);
         $form->addDefaultButtons(ts('Send SMS'), 'upload', 'cancel');
     } else {
         $form->addDefaultButtons(ts('Send SMS'), 'upload');
     }
     $form->addFormRule(array('CRM_Contact_Form_Task_SMSCommon', 'formRule'), $form);
 }
Exemplo n.º 9
0
 /**
  * Browse all Providers.
  *
  * @param array $action
  */
 public function browse($action = NULL)
 {
     $providers = CRM_SMS_BAO_Provider::getProviders();
     $rows = array();
     foreach ($providers as $provider) {
         $action = array_sum(array_keys($this->links()));
         // update enable/disable links.
         if ($provider['is_active']) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         $apiTypes = CRM_Core_OptionGroup::values('sms_api_type', FALSE, FALSE, FALSE, NULL, 'label');
         $provider['api_type'] = $apiTypes[$provider['api_type']];
         $provider['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $provider['id']), ts('more'), FALSE, 'sms.provider.row', 'SMSProvider', $provider['id']);
         $rows[] = $provider;
     }
     $this->assign('rows', $rows);
 }
Exemplo n.º 10
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->_mappingID = $mappingID = NULL;
     $providersCount = CRM_SMS_BAO_Provider::activeProviderCount();
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     //CRM-16777: Don't provide access to administer schedule reminder page, with user that does not have 'administer CiviCRM' permission
     if (empty($this->_context) && !CRM_Core_Permission::check('administer CiviCRM')) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     } else {
         $this->_compId = CRM_Utils_Request::retrieve('compId', 'Integer', $this);
         if (!CRM_Event_BAO_Event::checkPermission($this->_compId, CRM_Core_Permission::EDIT)) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
         }
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         $reminderName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionSchedule', $this->_id, 'title');
         if ($this->_context == 'event') {
             $this->_compId = CRM_Utils_Request::retrieve('compId', 'Integer', $this);
         }
         $this->assign('reminderName', $reminderName);
         return;
     } elseif ($this->_action & CRM_Core_Action::UPDATE) {
         $this->_mappingID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionSchedule', $this->_id, 'mapping_id');
         if ($this->_context == 'event') {
             $this->_compId = CRM_Utils_Request::retrieve('compId', 'Integer', $this);
         }
     } elseif (!empty($this->_context)) {
         if ($this->_context == 'event') {
             $this->_compId = CRM_Utils_Request::retrieve('compId', 'Integer', $this);
             $isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_compId, 'is_template');
             $mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array('id' => $isTemplate ? CRM_Event_ActionMapping::EVENT_TPL_MAPPING_ID : CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID)));
             if ($mapping) {
                 $this->_mappingID = $mapping->getId();
             } else {
                 CRM_Core_Error::fatal('Could not find mapping for event scheduled reminders.');
             }
         }
     }
     if (!empty($_POST) && !empty($_POST['entity']) && empty($this->_context)) {
         $mappingID = $_POST['entity'][0];
     } elseif ($this->_mappingID) {
         $mappingID = $this->_mappingID;
     }
     $this->add('text', 'title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_ActionSchedule', 'title'), TRUE);
     $mappings = CRM_Core_BAO_ActionSchedule::getMappings();
     $selectedMapping = $mappings[$mappingID ? $mappingID : 1];
     $entityRecipientLabels = $selectedMapping->getRecipientTypes() + CRM_Core_BAO_ActionSchedule::getAdditionalRecipients();
     $this->assign('entityMapping', json_encode(CRM_Utils_Array::collectMethod('getEntity', $mappings)));
     $this->assign('recipientMapping', json_encode(array_combine(array_keys($entityRecipientLabels), array_keys($entityRecipientLabels))));
     if (empty($this->_context)) {
         $sel =& $this->add('hierselect', 'entity', ts('Entity'), array('name' => 'entity[0]', 'style' => 'vertical-align: top;'));
         $sel->setOptions(array(CRM_Utils_Array::collectMethod('getLabel', $mappings), CRM_Core_BAO_ActionSchedule::getAllEntityValueLabels(), CRM_Core_BAO_ActionSchedule::getAllEntityStatusLabels()));
         if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) {
             // make second selector a multi-select -
             $sel->_elements[1]->setMultiple(TRUE);
             $sel->_elements[1]->setSize(5);
         }
         if (is_a($sel->_elements[2], 'HTML_QuickForm_select')) {
             // make third selector a multi-select -
             $sel->_elements[2]->setMultiple(TRUE);
             $sel->_elements[2]->setSize(5);
         }
     } else {
         // Dig deeper - this code is sublimely stupid.
         $allEntityStatusLabels = CRM_Core_BAO_ActionSchedule::getAllEntityStatusLabels();
         $options = $allEntityStatusLabels[$this->_mappingID][0];
         $attributes = array('multiple' => 'multiple', 'class' => 'crm-select2 huge', 'placeholder' => $options[0]);
         unset($options[0]);
         $this->add('select', 'entity', ts('Recipient(s)'), $options, TRUE, $attributes);
         $this->assign('context', $this->_context);
     }
     //get the frequency units.
     $this->_freqUnits = CRM_Core_SelectValues::getRecurringFrequencyUnits();
     $numericOptions = CRM_Core_SelectValues::getNumericOptions(0, 30);
     //reminder_interval
     $this->add('select', 'start_action_offset', ts('When'), $numericOptions);
     $isActive = ts('Send email');
     $recordActivity = ts('Record activity for automated email');
     if ($providersCount) {
         $this->assign('sms', $providersCount);
         $isActive = ts('Send email or SMS');
         $recordActivity = ts('Record activity for automated email or SMS');
         $options = CRM_Core_OptionGroup::values('msg_mode');
         $this->add('select', 'mode', ts('Send as'), $options);
         $providers = CRM_SMS_BAO_Provider::getProviders(NULL, NULL, TRUE, 'is_default desc');
         $providerSelect = array();
         foreach ($providers as $provider) {
             $providerSelect[$provider['id']] = $provider['title'];
         }
         $this->add('select', 'sms_provider_id', ts('SMS Provider'), $providerSelect, TRUE);
     }
     foreach ($this->_freqUnits as $val => $label) {
         $freqUnitsDisplay[$val] = ts('%1(s)', array(1 => $label));
     }
     $this->addDate('absolute_date', ts('Start Date'), FALSE, array('formatType' => 'mailing'));
     //reminder_frequency
     $this->add('select', 'start_action_unit', ts('Frequency'), $freqUnitsDisplay, TRUE);
     $condition = array('before' => ts('before'), 'after' => ts('after'));
     //reminder_action
     $this->add('select', 'start_action_condition', ts('Action Condition'), $condition);
     $this->add('select', 'start_action_date', ts('Date Field'), $selectedMapping->getDateFields(), TRUE);
     $this->addElement('checkbox', 'record_activity', $recordActivity);
     $this->addElement('checkbox', 'is_repeat', ts('Repeat'), NULL, array('onchange' => "return showHideByValue('is_repeat',true,'repeatFields','table-row','radio',false);"));
     $this->add('select', 'repetition_frequency_unit', ts('every'), $freqUnitsDisplay);
     $this->add('select', 'repetition_frequency_interval', ts('every'), $numericOptions);
     $this->add('select', 'end_frequency_unit', ts('until'), $freqUnitsDisplay);
     $this->add('select', 'end_frequency_interval', ts('until'), $numericOptions);
     $this->add('select', 'end_action', ts('Repetition Condition'), $condition, TRUE);
     $this->add('select', 'end_date', ts('Date Field'), $selectedMapping->getDateFields(), TRUE);
     $this->add('text', 'from_name', ts('From Name'));
     $this->add('text', 'from_email', ts('From Email'));
     $recipientListingOptions = array();
     if ($mappingID) {
         $mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array('id' => $mappingID)));
     }
     $limitOptions = array('' => '-neither-', 1 => ts('Limit to'), 0 => ts('Also include'));
     $recipientLabels = array('activity' => ts('Recipients'), 'other' => ts('Limit or Add Recipients'));
     $this->assign('recipientLabels', $recipientLabels);
     $this->add('select', 'limit_to', ts('Limit Options'), $limitOptions, FALSE, array('onChange' => "showHideByValue('limit_to','','recipient', 'select','select',true);"));
     $this->add('select', 'recipient', $recipientLabels['other'], $entityRecipientLabels, FALSE, array('onchange' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);"));
     if (!empty($this->_submitValues['recipient_listing'])) {
         if (!empty($this->_context)) {
             $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($this->_mappingID, $this->_submitValues['recipient']);
         } else {
             $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($_POST['entity'][0], $_POST['recipient']);
         }
     } elseif (!empty($this->_values['recipient_listing'])) {
         $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($this->_values['mapping_id'], $this->_values['recipient']);
     }
     $this->add('select', 'recipient_listing', ts('Recipient Roles'), $recipientListingOptions, FALSE, array('multiple' => TRUE, 'class' => 'crm-select2 huge', 'placeholder' => TRUE));
     $this->addEntityRef('recipient_manual_id', ts('Manual Recipients'), array('multiple' => TRUE, 'create' => TRUE));
     $this->add('select', 'group_id', ts('Group'), CRM_Core_PseudoConstant::nestedGroup('Mailing'), FALSE, array('class' => 'crm-select2 huge'));
     // multilingual only options
     $multilingual = CRM_Core_I18n::isMultilingual();
     if ($multilingual) {
         $smarty = CRM_Core_Smarty::singleton();
         $smarty->assign('multilingual', $multilingual);
         $languages = CRM_Core_I18n::languages(TRUE);
         $languageFilter = $languages + array(CRM_Core_I18n::NONE => ts('Contacts with no preferred language'));
         $element = $this->add('select', 'filter_contact_language', ts('Recipients language'), $languageFilter, FALSE, array('multiple' => TRUE, 'class' => 'crm-select2', 'placeholder' => TRUE));
         $communicationLanguage = array('' => ts('System default language'), CRM_Core_I18n::AUTO => ts('Follow recipient preferred language'));
         $communicationLanguage = $communicationLanguage + $languages;
         $this->add('select', 'communication_language', ts('Communication language'), $communicationLanguage);
     }
     CRM_Mailing_BAO_Mailing::commonCompose($this);
     $this->add('text', 'subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_ActionSchedule', 'subject'));
     $this->add('checkbox', 'is_active', $isActive);
     $this->addFormRule(array('CRM_Admin_Form_ScheduleReminders', 'formRule'), $this);
     $this->setPageTitle(ts('Scheduled Reminder'));
 }
 /**
  * Function to build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->_mappingID = $mappingID = NULL;
     $providersCount = CRM_SMS_BAO_Provider::activeProviderCount();
     if ($this->_action & CRM_Core_Action::DELETE) {
         $reminderName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionSchedule', $this->_id, 'title');
         $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
         if ($this->_context == 'event') {
             $this->_eventId = CRM_Utils_Request::retrieve('eventId', 'Integer', $this);
         }
         $this->assign('reminderName', $reminderName);
         return;
     } elseif ($this->_action & CRM_Core_Action::UPDATE) {
         $this->_mappingID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionSchedule', $this->_id, 'mapping_id');
         $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
         if ($this->_context == 'event') {
             $this->_eventId = CRM_Utils_Request::retrieve('eventId', 'Integer', $this);
         }
     }
     if (!empty($_POST) && !empty($_POST['entity'])) {
         $mappingID = $_POST['entity'][0];
     } elseif ($this->_mappingID) {
         $mappingID = $this->_mappingID;
     }
     $this->add('text', 'title', ts('Title'), array('size' => 45, 'maxlength' => 128), TRUE);
     $selectionOptions = CRM_Core_BAO_ActionSchedule::getSelection($mappingID);
     extract($selectionOptions);
     if (empty($sel1)) {
         CRM_Core_Error::fatal('Could not find mapping for scheduled reminders.');
     }
     $this->assign('entityMapping', json_encode($entityMapping));
     $this->assign('recipientMapping', json_encode($recipientMapping));
     $sel =& $this->add('hierselect', 'entity', ts('Entity'), array('name' => 'entity[0]', 'style' => 'vertical-align: top;'), TRUE);
     $sel->setOptions(array($sel1, $sel2, $sel3));
     if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) {
         // make second selector a multi-select -
         $sel->_elements[1]->setMultiple(TRUE);
         $sel->_elements[1]->setSize(5);
     }
     if (is_a($sel->_elements[2], 'HTML_QuickForm_select')) {
         // make third selector a multi-select -
         $sel->_elements[2]->setMultiple(TRUE);
         $sel->_elements[2]->setSize(5);
     }
     //get the frequency units.
     $this->_freqUnits = CRM_Core_SelectValues::getScheduleReminderFrequencyUnits();
     //pass the mapping ID in UPDATE mode
     $mappings = CRM_Core_BAO_ActionSchedule::getMapping($mappingID);
     $numericOptions = CRM_Core_SelectValues::getNumericOptions(0, 30);
     //reminder_interval
     $this->add('select', 'start_action_offset', ts('When'), $numericOptions);
     $title = ts('Email');
     $isActive = ts('Send email');
     $recordActivity = ts('Record activity for automated email');
     if ($providersCount) {
         $this->assign('sms', $providersCount);
         $title = ts('Email or SMS');
         $isActive = ts('Send email or SMS');
         $recordActivity = ts('Record activity for automated email or SMS');
         $options = CRM_Core_OptionGroup::values('msg_mode');
         $this->add('select', 'mode', ts('Send as'), $options);
         $providers = CRM_SMS_BAO_Provider::getProviders(NULL, NULL, TRUE, 'is_default desc');
         $providerSelect = array();
         foreach ($providers as $provider) {
             $providerSelect[$provider['id']] = $provider['title'];
         }
         $this->add('select', 'sms_provider_id', ts('From'), $providerSelect, TRUE);
     }
     $this->assign('title', $title);
     foreach ($this->_freqUnits as $val => $label) {
         $freqUnitsDisplay[$val] = ts('%1(s)', array(1 => $label));
     }
     $this->addDate('absolute_date', ts('Start Date'), FALSE, array('formatType' => 'mailing'));
     //reminder_frequency
     $this->add('select', 'start_action_unit', ts('Frequency'), $freqUnitsDisplay, TRUE);
     $condition = array('before' => ts('before'), 'after' => ts('after'));
     //reminder_action
     $this->add('select', 'start_action_condition', ts('Action Condition'), $condition);
     $this->add('select', 'start_action_date', ts('Date Field'), $sel4, TRUE);
     $this->addElement('checkbox', 'record_activity', $recordActivity);
     $this->addElement('checkbox', 'is_repeat', ts('Repeat'), NULL, array('onchange' => "return showHideByValue('is_repeat',true,'repeatFields','table-row','radio',false);"));
     $this->add('select', 'repetition_frequency_unit', ts('every'), $freqUnitsDisplay);
     $this->add('select', 'repetition_frequency_interval', ts('every'), $numericOptions);
     $this->add('select', 'end_frequency_unit', ts('until'), $freqUnitsDisplay);
     $this->add('select', 'end_frequency_interval', ts('until'), $numericOptions);
     $this->add('select', 'end_action', ts('Repetition Condition'), $condition, TRUE);
     $this->add('select', 'end_date', ts('Date Field'), $sel4, TRUE);
     $this->add('text', 'from_name', ts('From Name'));
     $this->add('text', 'from_email', ts('From Email'));
     $recipient = 'activity_contacts';
     $recipientListingOptions = array();
     if ($mappingID) {
         $recipient = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', $mappingID, 'entity_recipient');
     }
     $limitOptions = array(1 => ts('Limit to'), 0 => ts('Also include'));
     $this->add('select', 'limit_to', ts('Limit Options'), $limitOptions);
     $this->add('select', 'recipient', ts('Recipients'), $sel5[$recipient], FALSE, array('onchange' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);"));
     if (!empty($_POST['is_recipient_listing'])) {
         $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($_POST['entity'][0], $_POST['recipient']);
     } elseif (!empty($this->_values['recipient_listing'])) {
         $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($this->_values['mapping_id'], $this->_values['recipient']);
     }
     $this->add('select', 'recipient_listing', ts('Recipient Roles'), $recipientListingOptions, FALSE, array('multiple' => TRUE, 'class' => 'crm-select2 huge', 'placeholder' => TRUE));
     $this->add('hidden', 'is_recipient_listing', (int) (!empty($recipientListingOptions)));
     $this->addEntityRef('recipient_manual_id', ts('Manual Recipients'), array('multiple' => TRUE, 'create' => TRUE));
     $this->add('select', 'group_id', ts('Group'), CRM_Core_PseudoConstant::nestedGroup(), FALSE, array('class' => 'crm-select2 huge'));
     CRM_Mailing_BAO_Mailing::commonCompose($this);
     $this->add('text', 'subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_ActionSchedule', 'subject'));
     $this->add('checkbox', 'is_active', $isActive);
     $this->addFormRule(array('CRM_Admin_Form_ScheduleReminders', 'formRule'));
     $this->setPageTitle(ts('Scheduled Reminder'));
 }
Exemplo n.º 12
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $session = CRM_Core_Session::singleton();
     $config = CRM_Core_Config::singleton();
     $options = array();
     $tempVar = FALSE;
     $this->assign('max_sms_length', CRM_SMS_Provider::MAX_SMS_CHAR);
     // this seems so hacky, not sure what we are doing here and why. Need to investigate and fix
     $session->getVars($options, "CRM_SMS_Controller_Send_{$this->controller->_key}");
     $providers = CRM_SMS_BAO_Provider::getProviders(array('id', 'title'));
     if (empty($providers)) {
         //redirect user to configure sms provider.
         $url = CRM_Utils_System::url('civicrm/admin/sms/provider', 'action=add&reset=1');
         $status = ts("There is no SMS Provider Configured. You can add here <a href='%1'>Add SMS Provider</a>", array(1 => $url));
         $session->setStatus($status);
     } else {
         $providerSelect[''] = '- select -';
         foreach ($providers as $provider) {
             $providerSelect[$provider['id']] = $provider['title'];
         }
     }
     $this->add('select', 'sms_provider_id', ts('SMS Provider'), $providerSelect, TRUE);
     $attributes = array('onclick' => "showHideUpload();");
     $options = array(ts('Upload Content'), ts('Compose On-screen'));
     $this->addRadio('upload_type', ts('I want to'), $options, $attributes, "&nbsp;&nbsp;");
     CRM_Mailing_BAO_Mailing::commonCompose($this);
     $this->addElement('file', 'textFile', ts('Upload TEXT Message'), 'size=30 maxlength=60');
     $this->setMaxFileSize(1024 * 1024);
     $this->addRule('textFile', ts('File size should be less than 1 MByte'), 'maxfilesize', 1024 * 1024);
     $this->addRule('textFile', ts('File must be in UTF-8 encoding'), 'utf8File');
     $this->addFormRule(array('CRM_SMS_Form_Upload', 'formRule'), $this);
     $buttons = array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'upload', 'name' => ts('Next >>'), 'spacing' => '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')));
     $this->addButtons($buttons);
 }
Exemplo n.º 13
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_SMS_DAO_Provider');
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_SMS_BAO_Provider::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Provider has been deleted.'), ts('Deleted'), 'success');
         return;
     }
     $recData = $values = $this->controller->exportValues($this->_name);
     $recData['is_active'] = CRM_Utils_Array::value('is_active', $recData, 0);
     $recData['is_default'] = CRM_Utils_Array::value('is_default', $recData, 0);
     if ($this->_action & CRM_Core_Action::UPDATE) {
         CRM_SMS_BAO_Provider::updateRecord($recData, $this->_id);
     } elseif ($this->_action & CRM_Core_Action::ADD) {
         CRM_SMS_BAO_Provider::saveRecord($recData);
     }
 }
 /**
  * singleton function used to manage this object
  *
  * @return object
  * @static
  *
  */
 static function &singleton($providerParams = array(), $force = FALSE)
 {
     $providerID = CRM_Utils_Array::value('provider_id', $providerParams);
     $skipAuth = $providerID ? FALSE : TRUE;
     $cacheKey = (int) $providerID;
     if (!isset(self::$_singleton[$cacheKey]) || $force) {
         $provider = array();
         if ($providerID) {
             $provider = CRM_SMS_BAO_Provider::getProviderInfo($providerID);
         }
         self::$_singleton[$cacheKey] = new org_civicrm_sms_twilio($provider, $skipAuth);
     }
     return self::$_singleton[$cacheKey];
 }