Exemple #1
0
 /**
  * @param $token
  * @param $mailing
  * @param bool $escapeSmarty
  *
  * @return string
  */
 public static function getMailingTokenReplacement($token, &$mailing, $escapeSmarty = FALSE)
 {
     $value = '';
     switch ($token) {
         // CRM-7663
         case 'id':
             $value = $mailing ? $mailing->id : 'undefined';
             break;
         case 'name':
             $value = $mailing ? $mailing->name : 'Mailing Name';
             break;
         case 'group':
             $groups = $mailing ? $mailing->getGroupNames() : array('Mailing Groups');
             $value = implode(', ', $groups);
             break;
         case 'subject':
             $value = $mailing->subject;
             break;
         case 'viewUrl':
             $mailingKey = $mailing->id;
             if ($hash = CRM_Mailing_BAO_Mailing::getMailingHash($mailingKey)) {
                 $mailingKey = $hash;
             }
             $value = CRM_Utils_System::url('civicrm/mailing/view', "reset=1&id={$mailingKey}", TRUE, NULL, FALSE, TRUE);
             break;
         case 'editUrl':
         case 'scheduleUrl':
             // Note: editUrl and scheduleUrl used to be different, but now there's
             // one screen which can adapt based on permissions (in workflow mode).
             $value = CRM_Utils_System::url('civicrm/mailing/send', "reset=1&mid={$mailing->id}&continue=true", TRUE, NULL, FALSE, TRUE);
             break;
         case 'html':
             $page = new CRM_Mailing_Page_View();
             $value = $page->run($mailing->id, NULL, FALSE, TRUE);
             break;
         case 'approvalStatus':
             $value = CRM_Core_PseudoConstant::getLabel('CRM_Mailing_DAO_Mailing', 'approval_status_id', $mailing->approval_status_id);
             break;
         case 'approvalNote':
             $value = $mailing->approval_note;
             break;
         case 'approveUrl':
             $value = CRM_Utils_System::url('civicrm/mailing/approve', "reset=1&mid={$mailing->id}", TRUE, NULL, FALSE, TRUE);
             break;
         case 'creator':
             $value = CRM_Contact_BAO_Contact::displayName($mailing->created_id);
             break;
         case 'creatorEmail':
             $value = CRM_Contact_BAO_Contact::getPrimaryEmail($mailing->created_id);
             break;
         default:
             $value = "{mailing.{$token}}";
             break;
     }
     if ($escapeSmarty) {
         $value = self::tokenEscapeSmarty($value);
     }
     return $value;
 }
Exemple #2
0
 /**
  * Build the form object for the approval/rejection mailing.
  */
 public function buildQuickform()
 {
     $title = ts('Approve/Reject Mailing') . " - {$this->_mailing->name}";
     CRM_Utils_System::setTitle($title);
     $this->addElement('textarea', 'approval_note', ts('Approve/Reject Note'));
     $mailApprovalStatus = CRM_Core_OptionGroup::values('mail_approval_status');
     // eliminate the none option
     $noneOptionID = CRM_Core_OptionGroup::getValue('mail_approval_status', 'None', 'name');
     if ($noneOptionID) {
         unset($mailApprovalStatus[$noneOptionID]);
     }
     $this->addRadio('approval_status_id', ts('Approval Status'), $mailApprovalStatus, array(), NULL, TRUE);
     $buttons = array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '                 ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')));
     $this->addButtons($buttons);
     // add the preview elements
     $preview = array();
     $preview['subject'] = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'subject');
     $mailingKey = $this->_mailingID;
     if ($hash = CRM_Mailing_BAO_Mailing::getMailingHash($mailingKey)) {
         $mailingKey = $hash;
     }
     $preview['viewURL'] = CRM_Utils_System::url('civicrm/mailing/view', "reset=1&id={$mailingKey}");
     $preview['type'] = $this->_mailing->body_html ? 'html' : 'text';
     $preview['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_mailing', $this->_mailingID);
     $this->assign_by_ref('preview', $preview);
 }
 /**
  * wrapper for ajax activity selector.
  *
  * @param array $params
  *   Associated array for params record id.
  *
  * @return array
  *   associated array of contact activities
  */
 public static function getContactMailingSelector(&$params)
 {
     // format the params
     $params['offset'] = ($params['page'] - 1) * $params['rp'];
     $params['rowCount'] = $params['rp'];
     $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
     $params['caseId'] = NULL;
     // get contact mailings
     $mailings = CRM_Mailing_BAO_Mailing::getContactMailings($params);
     // add total
     $params['total'] = CRM_Mailing_BAO_Mailing::getContactMailingsCount($params);
     //CRM-12814
     if (!empty($mailings)) {
         $openCounts = CRM_Mailing_Event_BAO_Opened::getMailingContactCount(array_keys($mailings), $params['contact_id']);
         $clickCounts = CRM_Mailing_Event_BAO_TrackableURLOpen::getMailingContactCount(array_keys($mailings), $params['contact_id']);
     }
     // format params and add links
     $contactMailings = array();
     foreach ($mailings as $mailingId => $values) {
         $mailing = array();
         $mailing['subject'] = $values['subject'];
         $mailing['creator_name'] = CRM_Utils_System::href($values['creator_name'], 'civicrm/contact/view', "reset=1&cid={$values['creator_id']}");
         $mailing['recipients'] = CRM_Utils_System::href(ts('(recipients)'), 'civicrm/mailing/report/event', "mid={$values['mailing_id']}&reset=1&cid={$params['contact_id']}&event=queue&context=mailing");
         $mailing['start_date'] = CRM_Utils_Date::customFormat($values['start_date']);
         //CRM-12814
         $mailing['openstats'] = "Opens: " . CRM_Utils_Array::value($values['mailing_id'], $openCounts, 0) . "<br />Clicks: " . CRM_Utils_Array::value($values['mailing_id'], $clickCounts, 0);
         $actionLinks = array(CRM_Core_Action::VIEW => array('name' => ts('View'), 'url' => 'civicrm/mailing/view', 'qs' => "reset=1&id=%%mkey%%", 'title' => ts('View Mailing'), 'class' => 'crm-popup'), CRM_Core_Action::BROWSE => array('name' => ts('Mailing Report'), 'url' => 'civicrm/mailing/report', 'qs' => "mid=%%mid%%&reset=1&cid=%%cid%%&context=mailing", 'title' => ts('View Mailing Report')));
         $mailingKey = $values['mailing_id'];
         if ($hash = CRM_Mailing_BAO_Mailing::getMailingHash($mailingKey)) {
             $mailingKey = $hash;
         }
         $mailing['links'] = CRM_Core_Action::formLink($actionLinks, NULL, array('mid' => $values['mailing_id'], 'cid' => $params['contact_id'], 'mkey' => $mailingKey), ts('more'), FALSE, 'mailing.contact.action', 'Mailing', $values['mailing_id']);
         array_push($contactMailings, $mailing);
     }
     $contactMailingsDT = array();
     $contactMailingsDT['data'] = $contactMailings;
     $contactMailingsDT['recordsTotal'] = $params['total'];
     $contactMailingsDT['recordsFiltered'] = $params['total'];
     return $contactMailingsDT;
 }
 /**
  * Build the form object for the last step of the mailing wizard.
  *
  * @param
  *
  * @return void
  */
 public function buildQuickform()
 {
     $this->addDateTime('start_date', ts('Schedule Mailing'), FALSE, array('formatType' => 'mailing'));
     $this->addElement('checkbox', 'now', ts('Send Immediately'));
     $this->addFormRule(array('CRM_Mailing_Form_Schedule', 'formRule'), $this);
     if ($this->_scheduleFormOnly) {
         $title = ts('Schedule Mailing') . ' - ' . CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'name');
         CRM_Utils_System::setTitle($title);
         $buttons = array(array('type' => 'next', 'name' => ts('Submit Mailing'), 'spacing' => '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')));
     } else {
         //FIXME : currently we are hiding save an continue later when
         //search base mailing, we should handle it when we fix CRM-3876
         if ($this->_searchBasedMailing) {
             $buttons = array(array('type' => 'back', 'name' => ts('Previous')), array('type' => 'next', 'name' => ts('Submit Mailing'), 'spacing' => '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;', 'isDefault' => TRUE));
         } else {
             $buttons = array(array('type' => 'back', 'name' => ts('Previous')), array('type' => 'next', 'name' => ts('Submit Mailing'), 'spacing' => '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;', 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');")), array('type' => 'cancel', 'name' => ts('Continue Later')));
         }
     }
     $this->addButtons($buttons);
     if (CRM_Mailing_Info::workflowEnabled() && $this->_scheduleFormOnly) {
         // add the preview elements
         $preview = array();
         $preview['type'] = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'body_html') ? 'html' : 'text';
         $preview['subject'] = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'subject');
         $mailingKey = $this->_mailingID;
         if ($hash = CRM_Mailing_BAO_Mailing::getMailingHash($mailingKey)) {
             $mailingKey = $hash;
         }
         $preview['viewURL'] = CRM_Utils_System::url('civicrm/mailing/view', "reset=1&id={$mailingKey}");
         $preview['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_mailing', $this->_mailingID);
         $this->assign_by_ref('preview', $preview);
     }
 }