/** * 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); }
/** * Function to build the form * * @return void * @access public */ public function buildQuickForm() { $field = 'civicrm_event'; if ($this->_isTemplate) { $field = 'event_template'; } $this->_mappingID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', $field, 'id', 'entity_value'); if (!$this->_mappingID) { CRM_Core_Error::fatal('Could not find mapping for event scheduled reminders.'); } parent::buildQuickForm(); $this->add('text', 'title', ts('Reminder Name'), array('size' => 45, 'maxlength' => 128), TRUE); $selectionOptions = CRM_Core_BAO_ActionSchedule::getSelection($this->_mappingID); extract($selectionOptions); $this->assign('recipientMapping', json_encode($recipientMapping)); // Fixme: hack to adjust the output of CRM_Core_BAO_ActionSchedule::getSelection so it looks nice with the jQuery.select2 plugin // TODO: fix this upstream $options = $sel3[$this->_mappingID][0]; $attributes = array('multiple' => 'multiple', 'class' => 'crm-select2 huge', 'placeholder' => $options[0]); unset($options[0]); $entity = $this->add('select', 'entity', ts('Recipient(s)'), $options, TRUE, $attributes); //get the frequency units. $this->_freqUnits = array('hour' => 'hour') + CRM_Core_OptionGroup::values('recur_frequency_units'); $numericOptions = CRM_Core_SelectValues::getNumericOptions(0, 30); //reminder_interval $this->add('select', 'start_action_offset', ts('When'), $numericOptions); 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', ts('Record activity for automated email')); $this->addElement('checkbox', 'is_repeat', ts('Repeat'), NULL, array('onclick' => "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); $recipient = 'event_contacts'; $limitOptions = array(1 => ts('Limit to'), 0 => ts('Addition to')); $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);")); $recipientListing = $this->add('select', 'recipient_listing', ts('Recipient Listing'), $sel3[$this->_mappingID][0], FALSE, array('class' => 'crm-select2 huge')); $recipientListing->setMultiple(TRUE); //auto-complete url $dataUrl = CRM_Utils_System::url('civicrm/ajax/rest', "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=activity&reset=1", FALSE, NULL, FALSE); $this->assign('dataUrl', $dataUrl); //token input url $tokenUrl = CRM_Utils_System::url('civicrm/ajax/checkemail', 'noemail=1', FALSE, NULL, FALSE); $this->assign('tokenUrl', $tokenUrl); $this->add('text', 'recipient_manual_id', ts('Manual Recipients')); $this->add('select', 'group_id', ts('Group'), CRM_Core_PseudoConstant::staticGroup(), 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', ts('Send email')); $this->addFormRule(array('CRM_Event_Form_ManageEvent_ScheduleReminders', 'formRule')); }
/** * 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 None * @access public */ public function buildQuickForm() { parent::buildQuickForm(); $this->_mappingID = $mappingID = NULL; 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) && CRM_Utils_Array::value('entity', $_POST)) { $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 = array('hour' => 'hour') + CRM_Core_OptionGroup::values('recur_frequency_units'); //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); 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', 'is_repeat', ts('Repeat'), NULL, array('onclick' => "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); $recipient = 'activity_contacts'; $recipientListingOptions = array(); if ($mappingID) { $recipient = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', $mappingID, 'entity_recipient'); } $this->add('select', 'recipient', ts('Recipient(s)'), $sel5[$recipient], FALSE, array('onClick' => "showHideByValue('recipient','manual','recipientManual','table-row','select',false); showHideByValue('recipient','group','recipientGroup','table-row','select',false);")); if (CRM_Utils_Array::value('is_recipient_listing', $_POST)) { $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($_POST['entity'][0], $_POST['recipient']); } elseif (CRM_Utils_Array::value('recipient_listing', $this->_values)) { $recipientListingOptions = CRM_Core_BAO_ActionSchedule::getRecipientListing($this->_values['mapping_id'], $this->_values['recipient']); } $recipientListing = $this->add('select', 'recipient_listing', ts('Recipient Listing'), $recipientListingOptions); $recipientListing->setMultiple(TRUE); $this->add('hidden', 'is_recipient_listing', empty($recipientListingOptions) ? FALSE : TRUE, array('id' => 'is_recipient_listing')); //autocomplete url $dataUrl = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=activity&reset=1', FALSE, NULL, FALSE); $this->assign('dataUrl', $dataUrl); //tokeninput url $tokenUrl = CRM_Utils_System::url('civicrm/ajax/checkemail', 'noemail=1', FALSE, NULL, FALSE); $this->assign('tokenUrl', $tokenUrl); $this->add('text', 'recipient_manual_id', ts('Manual Recipients')); $this->addElement('select', 'group_id', ts('Group'), CRM_Core_PseudoConstant::staticGroup()); 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', ts('Send email')); $this->addFormRule(array('CRM_Admin_Form_ScheduleReminders', 'formRule')); }
/** * Build the form object. * * @return void */ public function buildQuickForm() { $session = CRM_Core_Session::singleton(); $config = CRM_Core_Config::singleton(); $options = array(); $tempVar = FALSE; // this seems so hacky, not sure what we are doing here and why. Need to investigate and fix $session->getVars($options, "CRM_Mailing_Controller_Send_{$this->controller->_key}"); $fromEmailAddress = CRM_Core_OptionGroup::values('from_email_address'); if (empty($fromEmailAddress)) { //redirect user to enter from email address. $url = CRM_Utils_System::url('civicrm/admin/options/from_email_address', 'action=add&reset=1'); $status = ts("There is no valid from email address present. You can add here <a href='%1'>Add From Email Address.</a>", array(1 => $url)); $session->setStatus($status, ts('Notice')); } else { foreach ($fromEmailAddress as $key => $email) { $fromEmailAddress[$key] = htmlspecialchars($fromEmailAddress[$key]); } } $this->add('select', 'from_email_address', ts('From Email Address'), array('' => '- select -') + $fromEmailAddress, TRUE); //Added code to add custom field as Reply-To on form when it is enabled from Mailer settings if ((int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo') && empty($options['override_verp'])) { $this->add('select', 'reply_to_address', ts('Reply-To'), array('' => '- select -') + $fromEmailAddress); } elseif (!empty($options['override_verp'])) { $trackReplies = TRUE; $this->assign('trackReplies', $trackReplies); } $this->add('text', 'subject', ts('Mailing Subject'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'subject'), TRUE); $attributes = array('onclick' => "showHideUpload();"); $options = array(ts('Upload Content'), ts('Compose On-screen')); $this->addRadio('upload_type', ts('I want to'), $options, $attributes, " "); CRM_Mailing_BAO_Mailing::commonCompose($this); $this->addElement('file', 'textFile', ts('Upload TEXT Message'), 'size=30 maxlength=60'); $this->addUploadElement('textFile'); $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->addElement('file', 'htmlFile', ts('Upload HTML Message'), 'size=30 maxlength=60'); $this->addUploadElement('htmlFile'); $this->setMaxFileSize(1024 * 1024); $this->addRule('htmlFile', ts('File size should be less than %1 MByte(s)', array(1 => 1)), 'maxfilesize', 1024 * 1024); $this->addRule('htmlFile', ts('File must be in UTF-8 encoding'), 'utf8File'); //fix upload files when context is search. CRM-3711 $ssID = $this->get('ssID'); if ($this->_searchBasedMailing && $ssID) { $this->set('uploadNames', array('textFile', 'htmlFile')); } CRM_Core_BAO_File::buildAttachment($this, 'civicrm_mailing', $this->_mailingID); $this->add('select', 'header_id', ts('Mailing Header'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Header')); $this->add('select', 'footer_id', ts('Mailing Footer'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Footer')); $this->addFormRule(array('CRM_Mailing_Form_Upload', 'formRule'), $this); $buttons = array(array('type' => 'back', 'name' => ts('Previous')), array('type' => 'upload', 'name' => ts('Next'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'upload', 'name' => ts('Save & Continue Later'), 'subName' => 'save'), array('type' => 'cancel', 'name' => ts('Cancel'))); $this->addButtons($buttons); }
/** * 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')); }
/** * Build the form object. * * @param CRM_Core_Form $form */ public static function buildQuickForm(&$form) { $toArray = $ccArray = $bccArray = array(); $suppressedEmails = 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 = explode(',', $cid); } if (count($form->_contactIds) > 1) { $form->_single = FALSE; } $emailAttributes = array('class' => 'huge'); $to = $form->add('text', 'to', ts('To'), $emailAttributes, TRUE); $cc = $form->add('text', 'cc_id', ts('CC'), $emailAttributes); $bcc = $form->add('text', 'bcc_id', ts('BCC'), $emailAttributes); $setDefaults = TRUE; if (property_exists($form, '_context') && $form->_context == 'standalone') { $setDefaults = FALSE; } $elements = array('to', 'cc', 'bcc'); $form->_allContactIds = $form->_toContactIds = $form->_contactIds; foreach ($elements as $element) { if (${$element}->getValue()) { $allEmails = explode(',', ${$element}->getValue()); if ($element == 'to') { $form->_toContactIds = $form->_contactIds = array(); } foreach ($allEmails as $value) { list($contactId, $email) = explode('::', $value); if ($contactId) { switch ($element) { case 'to': $form->_contactIds[] = $form->_toContactIds[] = $contactId; $form->_toContactEmails[] = $email; break; case 'cc': $form->_ccContactIds[] = $contactId; break; case 'bcc': $form->_bccContactIds[] = $contactId; break; } $form->_allContactIds[] = $contactId; } } $setDefaults = TRUE; } } //get the group of contacts as per selected by user in case of Find Activities if (!empty($form->_activityHolderIds)) { $contact = $form->get('contacts'); $form->_allContactIds = $form->_contactIds = $contact; } // check if we need to setdefaults and check for valid contact emails / communication preferences if (is_array($form->_allContactIds) && $setDefaults) { $returnProperties = array('sort_name' => 1, 'email' => 1, 'do_not_email' => 1, 'is_deceased' => 1, 'on_hold' => 1, 'display_name' => 1, 'preferred_mail_format' => 1); // get the details for all selected contacts ( to, cc and bcc contacts ) list($form->_contactDetails) = CRM_Utils_Token::getTokenDetails($form->_allContactIds, $returnProperties, FALSE, FALSE); // make a copy of all contact details $form->_allContactDetails = $form->_contactDetails; // perform all validations foreach ($form->_allContactIds as $key => $contactId) { $value = $form->_contactDetails[$contactId]; if ($value['do_not_email'] || empty($value['email']) || !empty($value['is_deceased']) || $value['on_hold']) { $suppressedEmails++; // unset contact details for contacts that we won't be sending email. This is prevent extra computation // during token evaluation etc. unset($form->_contactDetails[$contactId]); } else { $email = $value['email']; // build array's which are used to setdefaults if (in_array($contactId, $form->_toContactIds)) { $form->_toContactDetails[$contactId] = $form->_contactDetails[$contactId]; // If a particular address has been specified as the default, use that instead of contact's primary email if (!empty($form->_toEmail) && $form->_toEmail['contact_id'] == $contactId) { $email = $form->_toEmail['email']; } $toArray[] = array('text' => '"' . $value['sort_name'] . '" <' . $email . '>', 'id' => "{$contactId}::{$email}"); } elseif (in_array($contactId, $form->_ccContactIds)) { $ccArray[] = array('text' => '"' . $value['sort_name'] . '" <' . $email . '>', 'id' => "{$contactId}::{$email}"); } elseif (in_array($contactId, $form->_bccContactIds)) { $bccArray[] = array('text' => '"' . $value['sort_name'] . '" <' . $email . '>', 'id' => "{$contactId}::{$email}"); } } } if (empty($toArray)) { CRM_Core_Error::statusBounce(ts('Selected contact(s) do not have a valid email address, or communication preferences specify DO NOT EMAIL, or they are deceased or Primary email address is On Hold.')); } } $form->assign('toContact', json_encode($toArray)); $form->assign('ccContact', json_encode($ccArray)); $form->assign('bccContact', json_encode($bccArray)); $form->assign('suppressedEmails', $suppressedEmails); $form->assign('totalSelectedContacts', count($form->_contactIds)); $form->add('text', 'subject', ts('Subject'), 'size=50 maxlength=254', TRUE); $form->add('select', 'fromEmailAddress', ts('From'), $form->_fromEmails, TRUE, array('class' => 'crm-select2 huge')); CRM_Mailing_BAO_Mailing::commonCompose($form); // add attachments CRM_Core_BAO_File::buildAttachment($form, NULL); if ($form->_single) { // also fix the user context stack if ($form->_caseId) { $ccid = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseContact', $form->_caseId, 'contact_id', 'case_id'); $url = CRM_Utils_System::url('civicrm/contact/view/case', "&reset=1&action=view&cid={$ccid}&id={$form->_caseId}"); } elseif ($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 Email'), 'upload', 'cancel'); } else { $form->addDefaultButtons(ts('Send Email'), 'upload'); } $fields = array('followup_assignee_contact_id' => array('type' => 'entityRef', 'label' => ts('Assigned to'), 'attributes' => array('multiple' => TRUE, 'create' => TRUE, 'api' => array('params' => array('is_deceased' => 0)))), 'followup_activity_type_id' => array('type' => 'select', 'label' => ts('Followup Activity'), 'attributes' => array('' => '- ' . ts('select activity') . ' -') + CRM_Core_PseudoConstant::ActivityType(FALSE), 'extra' => array('class' => 'crm-select2')), 'followup_activity_subject' => array('type' => 'text', 'label' => ts('Subject'), 'attributes' => CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', 'subject'))); //add followup date $form->addDateTime('followup_date', ts('in'), FALSE, array('formatType' => 'activityDateTime')); foreach ($fields as $field => $values) { if (!empty($fields[$field])) { $attribute = CRM_Utils_Array::value('attributes', $values); $required = !empty($values['required']); if ($values['type'] == 'select' && empty($attribute)) { $form->addSelect($field, array('entity' => 'activity'), $required); } elseif ($values['type'] == 'entityRef') { $form->addEntityRef($field, $values['label'], $attribute, $required); } else { $form->add($values['type'], $field, $values['label'], $attribute, $required, CRM_Utils_Array::value('extra', $values)); } } } $form->addFormRule(array('CRM_Contact_Form_Task_EmailCommon', 'formRule'), $form); CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Contact/Form/Task/EmailCommon.js', 0, 'html-header'); }
/** * 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, " "); 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' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))); $this->addButtons($buttons); }
/** * Build the form * * @access public * @return void */ static function buildQuickForm(&$form) { $toArray = $ccArray = $bccArray = array(); $suppressedEmails = 0; $to = $form->add('text', 'to', ts('To'), '', true); $cc = $form->add('text', 'cc_id', ts('CC')); $bcc = $form->add('text', 'bcc_id', ts('BCC')); $elements = array('cc', 'bcc'); foreach ($elements as $element) { if (${$element}->getValue()) { preg_match_all('!"(.*?)"\\s+<\\s*(.*?)\\s*>!', ${$element}->getValue(), $matches); $elementValues = array(); for ($i = 0; $i < count($matches[0]); $i++) { $name = '"' . $matches[1][$i] . '" <' . $matches[2][$i] . '>'; $elementValues[] = array('name' => $name, 'id' => $matches[0][$i]); } $var = "{$element}Contact"; $form->assign($var, json_encode($elementValues)); } } // when form is submitted recompute contactIds $allToEmails = array(); if ($to->getValue()) { $allToEmails = explode(',', $to->getValue()); $form->_contactIds = array(); foreach ($allToEmails as $value) { list($contactId, $email) = explode('::', $value); $form->_contactIds[] = $contactId; $form->_toContactEmails[] = $email; } } if (is_array($form->_contactIds)) { $returnProperties = array('sort_name' => 1, 'email' => 1, 'do_not_email' => 1, 'on_hold' => 1, 'display_name' => 1, 'preferred_mail_format' => 1); require_once 'CRM/Mailing/BAO/Mailing.php'; list($form->_contactDetails) = CRM_Mailing_BAO_Mailing::getDetails($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]; if ($value['do_not_email'] || empty($value['email']) || $value['is_deceased'] || $value['on_hold']) { $suppressedEmails++; // unset contact details for contacts that we won't be sending email. This is prevent extra computation // during token evaluation etc. unset($form->_contactDetails[$contactId]); } else { if (empty($form->_toContactEmails)) { $email = $value['email']; } else { $email = $form->_toContactEmails[$key]; } $toArray[] = array('name' => '"' . $value['sort_name'] . '" <' . $email . '>', 'id' => "{$contactId}::{$email}"); } } if (empty($toArray)) { CRM_Core_Error::statusBounce(ts('Selected contact(s) do not have a valid email address, or communication preferences specify DO NOT EMAIL, or they are deceased or Primary email address is On Hold).')); } } $form->assign('toContact', json_encode($toArray)); $form->assign('suppressedEmails', $suppressedEmails); $form->assign('noEmails', $form->_noEmails); $session =& CRM_Core_Session::singleton(); $userID = $session->get('userID'); list($fromDisplayName, $fromEmail, $fromDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID); if (!$fromEmail) { CRM_Core_Error::statusBounce(ts('Your user record does not have a valid email address')); } if (!trim($fromDisplayName)) { $fromDisplayName = $fromEmail; } $form->assign('totalSelectedContacts', count($form->_contactIds)); $from = "{$fromDisplayName} <{$fromEmail}>"; $form->_fromEmails = array('0' => $from) + CRM_Core_PseudoConstant::fromEmailAddress(); $form->add('text', 'subject', ts('Subject'), 'size=50 maxlength=254', true); $selectEmails = $form->_fromEmails; foreach (array_keys($selectEmails) as $k) { $selectEmails[$k] = htmlspecialchars($selectEmails[$k]); } $form->add('select', 'fromEmailAddress', ts('From'), $selectEmails, true); require_once "CRM/Mailing/BAO/Mailing.php"; CRM_Mailing_BAO_Mailing::commonCompose($form); // add attachments require_once 'CRM/Core/BAO/File.php'; CRM_Core_BAO_File::buildAttachment($form, null); if ($form->_single) { // also fix the user context stack if ($form->_caseId) { $ccid = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseContact', $form->_caseId, 'contact_id', 'case_id'); $url = CRM_Utils_System::url('civicrm/contact/view/case', "&reset=1&action=view&cid={$ccid}&id={$form->_caseId}"); } else { 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->replaceUserContext($url); $form->addDefaultButtons(ts('Send Email'), 'upload', 'cancel'); } else { $form->addDefaultButtons(ts('Send Email'), 'upload'); } $form->addFormRule(array('CRM_Contact_Form_Task_EmailCommon', 'formRule'), $form); }
function buildQuickForm() { $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); // add form elements $this->add('text', 'name', ts('Name Your Mailing'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), TRUE); //get the mailing groups. $groups = CRM_Core_PseudoConstant::group('Mailing'); $this->add('select', 'includeGroups', 'Select Group', array('' => '- select -') + $groups, true); // Add campaign // Start $mailingId = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL); $campaignId = NULL; if ($mailingId) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $mailingId, 'campaign_id'); } CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); // End // Add email subject and and template elements // Start $this->add('text', 'subject', ts('Subject'), 'size=50 maxlength=254', TRUE); CRM_Mailing_BAO_Mailing::commonCompose($this); // End // Advanced options - Tracking options // Start $this->addElement('checkbox', 'override_verp', ts('Track Replies?')); $defaults['override_verp'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'track_civimail_replies', NULL, FALSE); $this->add('checkbox', 'url_tracking', ts('Track Click-throughs?')); $defaults['url_tracking'] = TRUE; $this->add('checkbox', 'open_tracking', ts('Track Opens?')); //$this->add('checkbox', 'open_tracking', ts('Track Opens?'), '', array('value' => '1'), array('checked' => 'checked')); $defaults['open_tracking'] = TRUE; $this->add('checkbox', 'forward_replies', ts('Forward Replies?')); $defaults['forward_replies'] = FALSE; $this->add('checkbox', 'auto_responder', ts('Auto-respond to Replies?')); $defaults['auto_responder'] = FALSE; $this->add('select', 'reply_id', ts('Auto-responder'), CRM_Mailing_PseudoConstant::component('Reply'), TRUE); // End // From email address and reply to options // Start $options = array(); // this seems so hacky, not sure what we are doing here and why. Need to investigate and fix $session->getVars($options, "CRM_Mailing_Controller_Send_{$this->controller->_key}"); $fromEmailAddress = CRM_Core_OptionGroup::values('from_email_address'); if (empty($fromEmailAddress)) { //redirect user to enter from email address. $url = CRM_Utils_System::url('civicrm/admin/options/from_email_address', 'group=from_email_address&action=add&reset=1'); $status = ts("There is no valid from email address present. You can add here <a href='%1'>Add From Email Address.</a>", array(1 => $url)); $session->setStatus($status); } else { foreach ($fromEmailAddress as $key => $email) { $fromEmailAddress[$key] = htmlspecialchars($fromEmailAddress[$key]); } } $this->add('select', 'from_email_address', ts('From Email Address'), array('' => '- select -') + $fromEmailAddress, TRUE); //echo "<pre>";print_r ($config);echo "</pre>"; //Added code to add custom field as Reply-To on form when it is enabled from Mailer settings if (isset($config->replyTo) && !empty($config->replyTo) && !CRM_Utils_Array::value('override_verp', $options)) { $this->add('select', 'reply_to_address', ts('Reply-To'), array('' => '- select -') + $fromEmailAddress); } elseif (CRM_Utils_Array::value('override_verp', $options)) { $trackReplies = TRUE; $this->assign('trackReplies', $trackReplies); } // Mailing Header and footer // Start $this->add('select', 'header_id', ts('Mailing Header'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Header')); $this->add('select', 'footer_id', ts('Mailing Footer'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Footer')); // End #@madav getting default header na footer id to tpl #start $this->assign('headerId', key(CRM_Mailing_PseudoConstant::component('Header'))); $this->assign('footerId', key(CRM_Mailing_PseudoConstant::component('Footer'))); #end // Exclude from groups, Innclude/Exclude mailings // Start $outG =& $this->addElement('advmultiselect', 'excludeGroups', ts('Exclude Group(s)') . ' ', $groups, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $outG->setButtonAttributes('add', array('value' => ts('Add >>'))); $outG->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $mailings = CRM_Mailing_PseudoConstant::completed(); if (!$mailings) { $mailings = array(); } $inM =& $this->addElement('advmultiselect', 'includeMailings', ts('INCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $outM =& $this->addElement('advmultiselect', 'excludeMailings', ts('EXCLUDE Recipients of These Mailing(s)') . ' ', $mailings, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect')); $inM->setButtonAttributes('add', array('value' => ts('Add >>'))); $outM->setButtonAttributes('add', array('value' => ts('Add >>'))); $inM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $outM->setButtonAttributes('remove', array('value' => ts('<< Remove'))); $this->assign('mailingCount', count($mailings)); // End $this->addFormRule(array('CRM_Quickbulkemail_Form_QuickBulkEmail', 'formRule')); // Schedule or send // Start //$this->addDateTime('start_date', ts('Schedule Mailing'), FALSE, array('formatType' => 'mailing')); //$this->addElement('checkbox', 'now', ts('Send Immediately')); // End $buttons = array(array('type' => 'next', 'name' => ts('Schedule & Send >>'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'submit', 'name' => ts('Save & Continue Later'))); $this->addButtons($buttons); // export form elements // $this->assign('elementNames', $this->getRenderableElementNames()); parent::buildQuickForm(); }
/** * Build the form object. * * @var CRM_Core_Form $form * * @return void */ public static function buildQuickForm(&$form) { // This form outputs a file so should never be submitted via ajax $form->preventAjaxSubmit(); //Added for CRM-12682: Add activity subject and campaign fields CRM_Campaign_BAO_Campaign::addCampaign($form); $form->add('text', 'subject', ts('Activity Subject'), array('size' => 45, 'maxlength' => 255), FALSE); $form->add('static', 'pdf_format_header', NULL, ts('Page Format: %1', array(1 => '<span class="pdf-format-header-label"></span>'))); $form->addSelect('format_id', array('label' => ts('Select Format'), 'placeholder' => ts('Default'), 'entity' => 'message_template', 'field' => 'pdf_format_id', 'option_url' => 'civicrm/admin/pdfFormats')); $form->add('select', 'paper_size', ts('Paper Size'), array(0 => ts('- default -')) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE, array('onChange' => "selectPaper( this.value ); showUpdateFormatChkBox();")); $form->add('static', 'paper_dimensions', NULL, ts('Width x Height')); $form->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE, array('onChange' => "updatePaperDimensions(); showUpdateFormatChkBox();")); $form->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_PdfFormat::getUnits(), FALSE, array('onChange' => "selectMetric( this.value );")); $form->add('text', 'margin_left', ts('Left Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE); $form->add('text', 'margin_right', ts('Right Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE); $form->add('text', 'margin_top', ts('Top Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE); $form->add('text', 'margin_bottom', ts('Bottom Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE); $config = CRM_Core_Config::singleton(); /** CRM-15883 Suppressing Stationery path field until we switch from DOMPDF to a library that supports it. if ($config->wkhtmltopdfPath == FALSE) { $form->add( 'text', 'stationery', ts('Stationery (relative path to PDF you wish to use as the background)'), array('size' => 25, 'maxlength' => 900, 'onkeyup' => "showUpdateFormatChkBox();"), FALSE ); } */ $form->add('checkbox', 'bind_format', ts('Always use this Page Format with the selected Template')); $form->add('checkbox', 'update_format', ts('Update Page Format (this will affect all templates that use this format)')); $form->assign('useThisPageFormat', ts('Always use this Page Format with the new template?')); $form->assign('useSelectedPageFormat', ts('Should the new template always use the selected Page Format?')); $form->assign('totalSelectedContacts', count($form->_contactIds)); CRM_Mailing_BAO_Mailing::commonCompose($form); $buttons = array(); if ($form->get('action') != CRM_Core_Action::VIEW) { $buttons[] = array('type' => 'submit', 'name' => $form->_single ? ts('Make PDF') : ts('Make PDFs'), 'isDefault' => TRUE); } $buttons[] = array('type' => 'cancel', 'name' => $form->get('action') == CRM_Core_Action::VIEW ? ts('Done') : ts('Cancel')); $form->addButtons($buttons); $form->addFormRule(array('CRM_Contact_Form_Task_PDFLetterCommon', 'formRule'), $form); }
/** * Function to actually build the form * * @return None * @access public */ public function buildQuickForm() { $session = CRM_Core_Session::singleton(); require_once 'CRM/Core/PseudoConstant.php'; $formEmailAddress = CRM_Core_PseudoConstant::fromEmailAddress('from_email_address'); if (empty($formEmailAddress)) { //redirect user to enter from email address. $url = CRM_Utils_System::url('civicrm/admin/options/from_email_address', 'group=from_email_address&action=add&reset=1'); $status = ts("There is no valid from email address present. You can add here <a href='%1'>Add From Email Address.</a>", array(1 => $url)); $session->setStatus($status); } else { foreach ($formEmailAddress as $key => $email) { $formEmailAddress[$key] = htmlspecialchars($formEmailAddress[$key]); } } $this->add('select', 'from_email_address', ts('From Email Address'), array('' => '- select -') + $formEmailAddress, true); $this->add('text', 'subject', ts('Mailing Subject'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'subject'), true); $attributes = array('onclick' => "showHideUpload();"); $options = array(ts('Upload Content'), ts('Compose On-screen')); $this->addRadio('upload_type', ts('I want to'), $options, $attributes, " "); require_once 'CRM/Mailing/BAO/Mailing.php'; 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->addElement('file', 'htmlFile', ts('Upload HTML Message'), 'size=30 maxlength=60'); $this->setMaxFileSize(1024 * 1024); $this->addRule('htmlFile', ts('File size should be less than %1 MByte(s)', array(1 => 1)), 'maxfilesize', 1024 * 1024); $this->addRule('htmlFile', ts('File must be in UTF-8 encoding'), 'utf8File'); //fix upload files when context is search. CRM-3711 $ssID = $this->get('ssID'); if ($this->_searchBasedMailing && $ssID) { $this->set('uploadNames', array('textFile', 'htmlFile')); } require_once 'CRM/Core/BAO/File.php'; CRM_Core_BAO_File::buildAttachment($this, 'civicrm_mailing', $this->_mailingID); require_once 'CRM/Mailing/PseudoConstant.php'; $this->add('select', 'header_id', ts('Mailing Header'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Header')); $this->add('select', 'footer_id', ts('Mailing Footer'), array('' => ts('- none -')) + CRM_Mailing_PseudoConstant::component('Footer')); $this->addFormRule(array('CRM_Mailing_Form_Upload', 'formRule'), $this); //FIXME : currently we are hiding save an continue later when //search base mailing, we should handle it when we fix CRM-3876 $buttons = array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'upload', 'name' => ts('Next >>'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'upload', 'name' => ts('Save & Continue Later'), 'subName' => 'save'), array('type' => 'cancel', 'name' => ts('Cancel'))); if ($this->_searchBasedMailing && $ssID) { $buttons = array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'upload', 'name' => ts('Next >>'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))); } $this->addButtons($buttons); }
/** * Build the form * * @access public * * @return void */ static function buildQuickForm(&$form) { $toArray = $ccArray = $bccArray = array(); $suppressedEmails = 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'), '', TRUE); $cc = $form->add('text', 'cc_id', ts('CC')); $bcc = $form->add('text', 'bcc_id', ts('BCC')); $elements = array('cc', 'bcc'); foreach ($elements as $element) { if (${$element}->getValue()) { preg_match_all('!"(.*?)"\\s+<\\s*(.*?)\\s*>!', ${$element}->getValue(), $matches); $elementValues = array(); for ($i = 0; $i < count($matches[0]); $i++) { $name = '"' . $matches[1][$i] . '" <' . $matches[2][$i] . '>'; $elementValues[] = array('name' => $name, 'id' => $matches[0][$i]); } $var = "{$element}Contact"; $form->assign($var, json_encode($elementValues)); } } $toSetDefault = TRUE; if (property_exists($form, '_context') && $form->_context == 'standalone') { $toSetDefault = FALSE; } // when form is submitted recompute contactIds $allToEmails = array(); if ($to->getValue()) { $allToEmails = explode(',', $to->getValue()); $form->_contactIds = array(); foreach ($allToEmails as $value) { list($contactId, $email) = explode('::', $value); if ($contactId) { $form->_contactIds[] = $contactId; $form->_toContactEmails[] = $email; } } $toSetDefault = TRUE; } //get the group of contacts as per selected by user in case of Find Activities if (!empty($form->_activityHolderIds)) { $contact = $form->get('contacts'); $form->_contactIds = $contact; } if (is_array($form->_contactIds) && $toSetDefault) { $returnProperties = array('sort_name' => 1, 'email' => 1, 'do_not_email' => 1, 'is_deceased' => 1, 'on_hold' => 1, 'display_name' => 1, 'preferred_mail_format' => 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]; if ($value['do_not_email'] || empty($value['email']) || CRM_Utils_Array::value('is_deceased', $value) || $value['on_hold']) { $suppressedEmails++; // unset contact details for contacts that we won't be sending email. This is prevent extra computation // during token evaluation etc. unset($form->_contactDetails[$contactId]); } else { if (empty($form->_toContactEmails)) { $email = $value['email']; } else { $email = $form->_toContactEmails[$key]; } $toArray[] = array('name' => '"' . $value['sort_name'] . '" <' . $email . '>', 'id' => "{$contactId}::{$email}"); } } if (empty($toArray)) { CRM_Core_Error::statusBounce(ts('Selected contact(s) do not have a valid email address, or communication preferences specify DO NOT EMAIL, or they are deceased or Primary email address is On Hold.')); } } $form->assign('toContact', json_encode($toArray)); $form->assign('suppressedEmails', $suppressedEmails); $form->assign('totalSelectedContacts', count($form->_contactIds)); $form->add('text', 'subject', ts('Subject'), 'size=50 maxlength=254', TRUE); $form->add('select', 'fromEmailAddress', ts('From'), $form->_fromEmails, TRUE); CRM_Mailing_BAO_Mailing::commonCompose($form); // add attachments CRM_Core_BAO_File::buildAttachment($form, NULL); if ($form->_single) { // also fix the user context stack if ($form->_caseId) { $ccid = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseContact', $form->_caseId, 'contact_id', 'case_id'); $url = CRM_Utils_System::url('civicrm/contact/view/case', "&reset=1&action=view&cid={$ccid}&id={$form->_caseId}"); } elseif ($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 Email'), 'upload', 'cancel'); } else { $form->addDefaultButtons(ts('Send Email'), 'upload'); } $form->addFormRule(array('CRM_Contact_Form_Task_EmailCommon', 'formRule'), $form); }