function fileDisplay() { // Display evidence file $postParams = $_POST; $fileID = CRM_Core_BAO_File::getEntityFile($postParams['entityTable'], $postParams['entityID']); if ($fileID) { foreach ($fileID as $k => $v) { $fileType = $v['mime_type']; $fid = $v['fileID']; $eid = $postParams['entityID']; if ($fileType == 'image/jpeg' || $fileType == 'image/pjpeg' || $fileType == 'image/gif' || $fileType == 'image/x-png' || $fileType == 'image/png') { list($path) = CRM_Core_BAO_File::path($fid, $eid, NULL, NULL); list($imageWidth, $imageHeight) = getimagesize($path); list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight); $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fid}&eid={$eid}", FALSE, NULL, TRUE, TRUE); $file_url = "\n <a href=\"{$url}\" class='crm-image-popup'>\n <img src=\"{$url}\" width={$imageThumbWidth} height={$imageThumbHeight}/>\n </a>"; // for non image files } else { $uri = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fid, 'uri'); $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fid}&eid={$eid}"); $file_url = "<a href=\"{$url}\">{$uri}</a>"; } if (isset($fid)) { $deleteurl = "<div class=file-delete><a class='action-item crm-hover-button' href='javascript:void(0)' id=file_{$fid}>Delete Attached File</a></div>"; echo "<div id='del_{$fid}'>{$file_url}{$deleteurl}</div>"; } } } CRM_Utils_System::civiExit(); }
/** * Fetch the template text/html messages */ public static function template() { $templateId = CRM_Utils_Type::escape($_POST['tid'], 'Integer'); $messageTemplate = new CRM_Core_DAO_MessageTemplate(); $messageTemplate->id = $templateId; $messageTemplate->selectAdd(); $messageTemplate->selectAdd('msg_text, msg_html, msg_subject, pdf_format_id'); $messageTemplate->find(TRUE); $messages = array('subject' => $messageTemplate->msg_subject, 'msg_text' => $messageTemplate->msg_text, 'msg_html' => $messageTemplate->msg_html, 'pdf_format_id' => $messageTemplate->pdf_format_id); $documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $templateId); foreach ((array) $documentInfo as $info) { list($messages['document_body']) = CRM_Utils_PDF_Document::docReader($info['fullPath'], $info['mime_type']); } CRM_Utils_JSON::output($messages); }
/** * run this page (figure out the action needed and perform it). * * @return void */ function run() { require_once 'CRM/Mailing/BAO/Mailing.php'; $session =& CRM_Core_Session::singleton(); $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, false, 'text'); $type = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, false, 'text'); $options = array(); $session->getVars($options, "CRM_Mailing_Controller_Send_{$qfKey}"); //get the options if control come from search context, CRM-3711 if (empty($options)) { $session->getVars($options, "CRM_Contact_Controller_Search_{$qfKey}"); } // FIXME: the below and CRM_Mailing_Form_Test::testMail() // should be refactored $fromEmail = null; $mailing =& new CRM_Mailing_BAO_Mailing(); if (!empty($options)) { $mailing->id = $options['mailing_id']; $fromEmail = $options['from_email']; } $mailing->find(true); CRM_Mailing_BAO_Mailing::tokenReplace($mailing); if (defined('CIVICRM_MAIL_SMARTY')) { require_once 'CRM/Core/Smarty/resources/String.php'; civicrm_smarty_register_string_resource(); } // get and format attachments require_once 'CRM/Core/BAO/File.php'; $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id); //get details of contact with token value including Custom Field Token Values.CRM-3734 $returnProperties = $mailing->getReturnProperties(); $params = array('contact_id' => $session->get('userID')); $details = $mailing->getDetails($params, $returnProperties); $mime =& $mailing->compose(null, null, null, $session->get('userID'), $fromEmail, $fromEmail, true, $details[0][$session->get('userID')], $attachments); // there doesn't seem to be a way to get to Mail_Mime's text and HTML // parts, so we steal a peek at Mail_Mime's private properties, render // them and exit // note that preview does not display any attachments $mime->get(); if ($type == 'html') { header('Content-Type: text/html; charset=utf-8'); print $mime->_htmlbody; } else { header('Content-Type: text/plain; charset=utf-8'); print $mime->_txtbody; } exit; }
/** * View details of a note * * @return void * @access public */ function view() { $note = new CRM_Core_DAO_Note(); $note->id = $this->_id; if ($note->find(TRUE)) { $values = array(); CRM_Core_DAO::storeValues($note, $values); $values['privacy'] = CRM_Core_OptionGroup::optionLabel('note_privacy', $values['privacy']); $this->assign('note', $values); } $comments = CRM_Core_BAO_Note::getNoteTree($values['id'], 1); if (!empty($comments)) { $this->assign('comments', $comments); } // add attachments part $currentAttachmentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_note', $this->_id); $this->assign('currentAttachmentInfo', $currentAttachmentInfo); }
/** * Run this page (figure out the action needed and perform it). * * @return void */ public function run() { $session = CRM_Core_Session::singleton(); $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text'); $type = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text'); $options = array(); $session->getVars($options, "CRM_Mailing_Controller_Send_{$qfKey}"); //get the options if control come from search context, CRM-3711 if (empty($options)) { $session->getVars($options, "CRM_Contact_Controller_Search_{$qfKey}"); } // FIXME: the below and CRM_Mailing_Form_Test::testMail() // should be refactored $fromEmail = NULL; $mailing = new CRM_Mailing_BAO_Mailing(); if (!empty($options)) { $mailing->id = $options['mailing_id']; $fromEmail = CRM_Utils_Array::value('from_email', $options); } $mailing->find(TRUE); CRM_Mailing_BAO_Mailing::tokenReplace($mailing); // get and format attachments $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id); //get details of contact with token value including Custom Field Token Values.CRM-3734 $returnProperties = $mailing->getReturnProperties(); $params = array('contact_id' => $session->get('userID')); $details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens(), get_class($this)); $mime =& $mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, TRUE, $details[0][$session->get('userID')], $attachments); if ($type == 'html') { CRM_Utils_System::setHttpHeader('Content-Type', 'text/html; charset=utf-8'); print $mime->getHTMLBody(); } else { CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain; charset=utf-8'); print $mime->getTXTBody(); } CRM_Utils_System::civiExit(); }
/** * Set default values for the form. * * The default values are retrieved from the database. */ public function setDefaultValues() { $defaults = $this->_values; if (empty($defaults['pdf_format_id'])) { $defaults['pdf_format_id'] = 'null'; } if (empty($defaults['file_type'])) { $defaults['file_type'] = 0; } $this->_workflow_id = CRM_Utils_Array::value('workflow_id', $defaults); $this->assign('workflow_id', $this->_workflow_id); if ($this->_action & CRM_Core_Action::ADD) { $defaults['is_active'] = 1; //set the context for redirection after form submit or cancel $session = CRM_Core_Session::singleton(); $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1')); } // FIXME: we need to fix the Cancel button here as we don’t know whether it’s a workflow template in buildQuickForm() if ($this->_action & CRM_Core_Action::UPDATE) { if ($this->_workflow_id) { $selectedChild = 'workflow'; } else { $selectedChild = 'user'; } $documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $this->_id, TRUE); if (!empty($documentInfo)) { $defaults['file_type'] = 1; $this->_is_document = TRUE; $this->assign('attachment', $documentInfo); } $cancelURL = CRM_Utils_System::url('civicrm/admin/messageTemplates', "selectedChild={$selectedChild}&reset=1"); $cancelURL = str_replace('&', '&', $cancelURL); $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'), 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;")))); } return $defaults; }
/** * Function to process the form * * @access public * @return None */ public function postProcess($params = null) { if ($this->_action & CRM_Core_Action::DELETE) { $deleteParams = array('id' => $this->_activityId); CRM_Activity_BAO_Activity::deleteActivity($deleteParams); CRM_Core_Session::setStatus(ts("Selected Activity has been deleted sucessfully.")); return; } // store the submitted values in an array if (!$params) { $params = $this->controller->exportValues($this->_name); } //set activity type id if (!CRM_Utils_Array::value('activity_type_id', $params)) { $params['activity_type_id'] = $this->_activityTypeId; } if (CRM_Utils_Array::value('hidden_custom', $params) && !isset($params['custom'])) { $customFields = CRM_Core_BAO_CustomField::getFields('Activity', false, false, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', false, false, null, null, true)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } // store the date with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); // assigning formated value to related variable if (CRM_Utils_Array::value('target_contact_id', $params)) { $params['target_contact_id'] = explode(',', $params['target_contact_id']); } else { $params['target_contact_id'] = array(); } if (CRM_Utils_Array::value('assignee_contact_id', $params)) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } // get ids for associated contacts if (!$params['source_contact_id']) { $params['source_contact_id'] = $this->_currentUserId; } else { $params['source_contact_id'] = $this->_submitValues['source_contact_qid']; } if (isset($this->_activityId)) { $params['id'] = $this->_activityId; } // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId); // format target params if (!$this->_single) { $params['target_contact_id'] = $this->_contactIds; } $activityAssigned = array(); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($this->_activityId); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // create follow up activity if needed $followupStatus = ''; if (CRM_Utils_Array::value('followup_activity_type_id', $params)) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); $followupStatus = "A followup activity has been scheduled."; } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; $config =& CRM_Core_Config::singleton(); if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) && $config->activityAssigneeNotification) { $mailToContacts = array(); $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, true, false); //build an associative array with unique email addresses. foreach ($activityAssigned as $id => $dnc) { if (isset($id) && array_key_exists($id, $assigneeContacts)) { $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id]; } } if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { //include attachments while sendig a copy of activity. $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); require_once "CRM/Case/BAO/Case.php"; $result = CRM_Case_BAO_Case::sendActivityCopy(null, $activity->id, $mailToContacts, $attachments, null); $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); } } // set status message if (CRM_Utils_Array::value('subject', $params)) { $params['subject'] = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2. %3', array(1 => $params['subject'], 2 => $followupStatus, 3 => $mailStatus))); return array('activity' => $activity); }
/** * Function to process the form * * @access public * * @param null $params * * @return void */ public function postProcess($params = NULL) { $transaction = new CRM_Core_Transaction(); if ($this->_action & CRM_Core_Action::DELETE) { $statusMsg = NULL; //block deleting activities which affects //case attributes.CRM-4543 $activityCondition = " AND v.name IN ('Open Case', 'Change Case Type', 'Change Case Status', 'Change Case Start Date')"; $caseAttributeActivities = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, $activityCondition); if (!array_key_exists($this->_activityTypeId, $caseAttributeActivities)) { $params = array('id' => $this->_activityId); $activityDelete = CRM_Activity_BAO_Activity::deleteActivity($params, TRUE); if ($activityDelete) { $statusMsg = ts('The selected activity has been moved to the Trash. You can view and / or restore deleted activities by checking "Deleted Activities" from the Case Activities search filter (under Manage Case).<br />'); } } else { $statusMsg = ts("Selected Activity cannot be deleted."); } $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus('', $statusMsg, 'info'); return; } if ($this->_action & CRM_Core_Action::RENEW) { $statusMsg = NULL; $params = array('id' => $this->_activityId); $activityRestore = CRM_Activity_BAO_Activity::restoreActivity($params); if ($activityRestore) { $statusMsg = ts('The selected activity has been restored.<br />'); } CRM_Core_Session::setStatus('', $statusMsg, 'info'); return; } // store the submitted values in an array $params = $this->controller->exportValues($this->_name); //set parent id if its edit mode if ($parentId = CRM_Utils_Array::value('parent_id', $this->_defaults)) { $params['parent_id'] = $parentId; } // required for status msg $recordStatus = 'created'; // store the dates with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); $params['activity_type_id'] = $this->_activityTypeId; // format with contact (target contact) values if (isset($params['target_contact_id'])) { $params['target_contact_id'] = explode(',', $params['target_contact_id']); } else { $params['target_contact_id'] = array(); } // format activity custom data if (!empty($params['hidden_custom'])) { if ($this->_activityId) { // unset custom fields-id from params since we want custom // fields to be saved for new activity. foreach ($params as $key => $value) { $match = array(); if (preg_match('/^(custom_\\d+_)(\\d+)$/', $key, $match)) { $params[$match[1] . '-1'] = $params[$key]; // for autocomplete transfer hidden value instead of label if ($params[$key] && isset($params[$key . '_id'])) { $params[$match[1] . '-1_id'] = $params[$key . '_id']; unset($params[$key . '_id']); } unset($params[$key]); } } } // build custom data getFields array $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } // assigning formatted value if (!empty($params['assignee_contact_id'])) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } if (isset($this->_activityId)) { // activity which hasn't been modified by a user yet if ($this->_defaults['is_auto'] == 1) { $params['is_auto'] = 0; } // always create a revision of an case activity. CRM-4533 $newActParams = $params; // add target contact values in update mode if (empty($params['target_contact_id']) && !empty($this->_defaults['target_contact'])) { $newActParams['target_contact_id'] = $this->_defaults['target_contact']; } // record status for status msg $recordStatus = 'updated'; } if (!isset($newActParams)) { // add more attachments if needed for old activity CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($params); foreach ($this->_caseId as $key => $val) { $params['case_id'] = $val; // activity create/update $activity = CRM_Activity_BAO_Activity::create($params); $vvalue[] = array('case_id' => $val, 'actId' => $activity->id); // call end post process, after the activity has been created/updated. $this->endPostProcess($params, $activity); } } else { // since the params we need to set are very few, and we don't want rest of the // work done by bao create method , lets use dao object to make the changes $params = array('id' => $this->_activityId); $params['is_current_revision'] = 0; $activity = new CRM_Activity_DAO_Activity(); $activity->copyValues($params); $activity->save(); } // create a new version of activity if activity was found to // have been modified/created by user if (isset($newActParams)) { // set proper original_id if (!empty($this->_defaults['original_id'])) { $newActParams['original_id'] = $this->_defaults['original_id']; } else { $newActParams['original_id'] = $activity->id; } //is_current_revision will be set to 1 by default. // add attachments if any CRM_Core_BAO_File::formatAttachment($newActParams, $newActParams, 'civicrm_activity'); // call begin post process, before the activity is created/updated. $this->beginPostProcess($newActParams); foreach ($this->_caseId as $key => $val) { $newActParams['case_id'] = $val; $activity = CRM_Activity_BAO_Activity::create($newActParams); $vvalue[] = array('case_id' => $val, 'actId' => $activity->id); // call end post process, after the activity has been created/updated. $this->endPostProcess($newActParams, $activity); } // copy files attached to old activity if any, to new one, // as long as users have not selected the 'delete attachment' option. if (empty($newActParams['is_delete_attachment'])) { CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $this->_activityId, 'civicrm_activity', $activity->id); } // copy back params to original var $params = $newActParams; } foreach ($vvalue as $vkey => $vval) { if ($vval['actId']) { // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $vval['actId']); //save free tags if (isset($params['taglist']) && !empty($params['taglist'])) { CRM_Core_Form_Tag::postProcess($params['taglist'], $vval['actId'], 'civicrm_activity', $this); } } // update existing case record if needed $caseParams = $params; $caseParams['id'] = $vval['case_id']; if (!empty($caseParams['case_status_id'])) { $caseParams['status_id'] = $caseParams['case_status_id']; } // unset params intended for activities only unset($caseParams['subject'], $caseParams['details'], $caseParams['status_id'], $caseParams['custom']); $case = CRM_Case_BAO_Case::create($caseParams); // create case activity record $caseParams = array('activity_id' => $vval['actId'], 'case_id' => $vval['case_id']); CRM_Case_BAO_Case::processCaseActivity($caseParams); } // Insert civicrm_log record for the activity (e.g. store the // created / edited by contact id and date for the activity) // Note - civicrm_log is already created by CRM_Activity_BAO_Activity::create() // send copy to selected contacts. $mailStatus = ''; $mailToContacts = array(); //CRM-5695 //check for notification settings for assignee contacts $selectedContacts = array('contact_check'); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) { $selectedContacts[] = 'assignee_contact_id'; } foreach ($vvalue as $vkey => $vval) { foreach ($selectedContacts as $dnt => $val) { if (array_key_exists($val, $params) && !CRM_Utils_array::crmIsEmptyArray($params[$val])) { if ($val == 'contact_check') { $mailStatus = ts("A copy of the activity has also been sent to selected contacts(s)."); } else { $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($vval['actId']), TRUE, FALSE); $mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s)."); } //build an associative array with unique email addresses. foreach ($params[$val] as $key => $value) { if ($val == 'contact_check') { $id = $key; } else { $id = $value; } if (isset($id) && array_key_exists($id, $this->_relatedContacts) && isset($this->_relatedContacts[$id]['email'])) { //if email already exists in array then append with ', ' another role only otherwise add it to array. if ($contactDetails = CRM_Utils_Array::value($this->_relatedContacts[$id]['email'], $mailToContacts)) { $caseRole = CRM_Utils_Array::value('role', $this->_relatedContacts[$id]); $mailToContacts[$this->_relatedContacts[$id]['email']]['role'] = $contactDetails['role'] . ', ' . $caseRole; } else { $mailToContacts[$this->_relatedContacts[$id]['email']] = $this->_relatedContacts[$id]; } } } } } if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { //include attachments while sending a copy of activity. $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $vval['actId']); $ics = new CRM_Activity_BAO_ICalendar($activity); $ics->addAttachment($attachments, $mailToContacts); $result = CRM_Case_BAO_Case::sendActivityCopy($this->_currentlyViewedContactId, $vval['actId'], $mailToContacts, $attachments, $vval['case_id']); $ics->cleanup(); if (empty($result)) { $mailStatus = ''; } } else { $mailStatus = ''; } // create follow up activity if needed $followupStatus = ''; if (!empty($params['followup_activity_type_id'])) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($vval['actId'], $params); if ($followupActivity) { $caseParams = array('activity_id' => $followupActivity->id, 'case_id' => $vval['case_id']); CRM_Case_BAO_Case::processCaseActivity($caseParams); $followupStatus = ts("A followup activity has been scheduled."); } } CRM_Core_Session::setStatus('', ts("'%1' activity has been %2. %3 %4", array(1 => $this->_activityTypeName, 2 => $recordStatus, 3 => $followupStatus, 4 => $mailStatus)), 'info'); } }
/** * run this page (figure out the action needed and perform it). * * @return void */ function run($id = NULL, $contact_id = NULL, $print = TRUE) { if (is_numeric($id)) { $this->_mailingID = $id; } else { $print = TRUE; $this->_mailingID = CRM_Utils_Request::retrieve('id', 'Integer', CRM_Core_DAO::$_nullObject, TRUE); } // # CRM-7651 // override contactID from the function level if passed in if (isset($contactID) && is_numeric($contactID)) { $this->_contactID = $contactID; } else { $session = CRM_Core_Session::singleton(); $this->_contactID = $session->get('userID'); } $this->_mailing = new CRM_Mailing_BAO_Mailing(); $this->_mailing->id = $this->_mailingID; if (!$this->_mailing->find(TRUE) || !$this->checkPermission()) { CRM_Utils_System::permissionDenied(); return; } CRM_Mailing_BAO_Mailing::tokenReplace($this->_mailing); // get and format attachments $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $this->_mailing->id); // get contact detail and compose if contact id exists if (isset($this->_contactID)) { //get details of contact with token value including Custom Field Token Values.CRM-3734 $returnProperties = $this->_mailing->getReturnProperties(); $params = array('contact_id' => $this->_contactID); $details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this)); $details = $details[0][$this->_contactID]; } else { $details = array('test'); } $mime =& $this->_mailing->compose(NULL, NULL, NULL, 0, $this->_mailing->from_email, $this->_mailing->from_email, TRUE, $details, $attachments); if (isset($this->_mailing->body_html)) { $header = 'Content-Type: text/html; charset=utf-8'; $content = $mime->getHTMLBody(); } else { $header = 'Content-Type: text/plain; charset=utf-8'; $content = $mime->getTXTBody(); } if ($print) { header($header); print $content; CRM_Utils_System::civiExit(); } else { return $content; } }
/** * Process activity creation. * * @param array $params * Associated array of submitted values. * * @return self|null|object */ protected function processActivity(&$params) { $activityAssigned = array(); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($this->_activityId, $assigneeID); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) { CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this); } // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // CRM-9590 if (!empty($params['is_multi_activity'])) { $this->_activityIds[] = $activity->id; } else { $this->_activityId = $activity->id; } // create follow up activity if needed $followupStatus = ''; $followupActivity = NULL; if (!empty($params['followup_activity_type_id'])) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); $followupStatus = ts('A followup activity has been scheduled.'); } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) { $activityIDs = array($activity->id); if ($followupActivity) { $activityIDs = array_merge($activityIDs, array($followupActivity->id)); } $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityIDs, TRUE, FALSE); if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { $mailToContacts = array(); //build an associative array with unique email addresses. foreach ($activityAssigned as $id => $dnc) { if (isset($id) && array_key_exists($id, $assigneeContacts)) { $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id]; } } if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { //include attachments while sending a copy of activity. $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); $ics = new CRM_Activity_BAO_ICalendar($activity); $ics->addAttachment($attachments, $mailToContacts); // CRM-8400 add param with _currentlyViewedContactId for URL link in mail CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL); $ics->cleanup(); $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); } } // Also send email to follow-up activity assignees if set if ($followupActivity) { $mailToFollowupContacts = array(); foreach ($assigneeContacts as $values) { if ($values['activity_id'] == $followupActivity->id) { $mailToFollowupContacts[$values['email']] = $values; } } if (!CRM_Utils_array::crmIsEmptyArray($mailToFollowupContacts)) { $ics = new CRM_Activity_BAO_ICalendar($followupActivity); $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $followupActivity->id); $ics->addAttachment($attachments, $mailToFollowupContacts); CRM_Case_BAO_Case::sendActivityCopy(NULL, $followupActivity->id, $mailToFollowupContacts, $attachments, NULL); $ics->cleanup(); $mailStatus .= '<br />' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s)."); } } } // set status message $subject = ''; if (!empty($params['subject'])) { $subject = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2 %3', array(1 => $subject, 2 => $followupStatus, 3 => $mailStatus)), ts('Saved'), 'success'); return $activity; }
/** * Run this page (figure out the action needed and perform it). * * @param int $id * @param int $contactID * @param bool $print * @param bool $allowID */ public function run($id = NULL, $contactID = NULL, $print = TRUE, $allowID = FALSE) { if (is_numeric($id)) { $this->_mailingID = $id; } else { $print = TRUE; $this->_mailingID = CRM_Utils_Request::retrieve('id', 'String', CRM_Core_DAO::$_nullObject, TRUE); } // # CRM-7651 // override contactID from the function level if passed in if (isset($contactID) && is_numeric($contactID)) { $this->_contactID = $contactID; } else { $session = CRM_Core_Session::singleton(); $this->_contactID = $session->get('userID'); } // mailing key check if (Civi::settings()->get('hash_mailing_url')) { $this->_mailing = new CRM_Mailing_BAO_Mailing(); if (!is_numeric($this->_mailingID)) { $this->_mailing->hash = $this->_mailingID; } elseif (is_numeric($this->_mailingID)) { $this->_mailing->id = $this->_mailingID; // if mailing is present and associated hash is present // while 'hash' is not been used for mailing view : throw 'permissionDenied' if ($this->_mailing->find() && CRM_Core_DAO::getFieldValue('CRM_Mailing_BAO_Mailing', $this->_mailingID, 'hash', 'id') && !$allowID) { CRM_Utils_System::permissionDenied(); return; } } } else { $this->_mailing = new CRM_Mailing_BAO_Mailing(); $this->_mailing->id = $this->_mailingID; } if (!$this->_mailing->find(TRUE) || !$this->checkPermission()) { CRM_Utils_System::permissionDenied(); return; } CRM_Mailing_BAO_Mailing::tokenReplace($this->_mailing); // get and format attachments $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $this->_mailing->id); // get contact detail and compose if contact id exists $returnProperties = $this->_mailing->getReturnProperties(); if (isset($this->_contactID)) { // get details of contact with token value including Custom Field Token Values.CRM-3734 $params = array('contact_id' => $this->_contactID); $details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, FALSE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this)); $details = $details[0][$this->_contactID]; $contactId = $this->_contactID; } else { // get tokens that are not contact specific resolved $params = array('contact_id' => 0); $details = CRM_Utils_Token::getAnonymousTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this)); $details = CRM_Utils_Array::value(0, $details[0]); $contactId = 0; } $mime =& $this->_mailing->compose(NULL, NULL, NULL, $contactId, $this->_mailing->from_email, $this->_mailing->from_email, TRUE, $details, $attachments); $title = NULL; if (isset($this->_mailing->body_html) && empty($_GET['text'])) { $header = 'text/html; charset=utf-8'; $content = $mime->getHTMLBody(); if (strpos($content, '<head>') === FALSE && strpos($content, '<title>') === FALSE) { $title = '<head><title>' . $this->_mailing->subject . '</title></head>'; } } else { $header = 'text/plain; charset=utf-8'; $content = $mime->getTXTBody(); } CRM_Utils_System::setTitle($this->_mailing->subject); if (CRM_Utils_Array::value('snippet', $_GET) === 'json') { CRM_Core_Page_AJAX::returnJsonResponse($content); } if ($print) { CRM_Utils_System::setHttpHeader('Content-Type', $header); print $title; print $content; CRM_Utils_System::civiExit(); } else { return $content; } }
public function buildQuickForm() { $session = CRM_Core_Session::singleton(); $this->add('text', 'test_email', ts('Send to This Address')); $defaults['test_email'] = $session->get('ufUniqID'); $qfKey = $this->get('qfKey'); $this->add('select', 'test_group', ts('Send to This Group'), array('' => ts('- none -')) + CRM_Core_PseudoConstant::group('Mailing')); $this->setDefaults($defaults); $this->add('submit', 'sendtest', ts('Send a Test Mailing')); $name = ts('Next >>'); require_once 'CRM/Mailing/Info.php'; if (CRM_Mailing_Info::workflowEnabled()) { if (!CRM_Core_Permission::check('schedule mailings') && CRM_Core_Permission::check('create mailings')) { $name = ts('Inform Scheduler'); } } //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' => 'next', 'name' => $name, 'spacing' => ' ', 'isDefault' => true), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel'))); if ($this->_searchBasedMailing && $this->get('ssID')) { $buttons = array(array('type' => 'back', 'name' => ts('<< Previous')), array('type' => 'next', 'name' => $name, 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))); } $this->addButtons($buttons); $mailingID = $this->get('mailing_id'); $textFile = $this->get('textFile'); $htmlFile = $this->get('htmlFile'); $this->addFormRule(array('CRM_Mailing_Form_Test', 'testMail'), $this); $preview = array(); if ($textFile) { $preview['text_link'] = CRM_Utils_System::url('civicrm/mailing/preview', "type=text&qfKey={$qfKey}"); } if ($htmlFile) { $preview['html_link'] = CRM_Utils_System::url('civicrm/mailing/preview', "type=html&qfKey={$qfKey}"); } require_once 'CRM/Core/BAO/File.php'; $preview['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_mailing', $mailingID); $this->assign('preview', $preview); //Token Replacement of Subject in preview mailing $options = array(); $prefix = "CRM_Mailing_Controller_Send_{$qfKey}"; if ($this->_searchBasedMailing) { $prefix = "CRM_Contact_Controller_Search_{$qfKey}"; } $session->getVars($options, $prefix); require_once 'CRM/Mailing/BAO/Mailing.php'; $mailing = new CRM_Mailing_BAO_Mailing(); $mailing->id = $options['mailing_id']; $mailing->find(true); $fromEmail = $mailing->from_email; require_once 'CRM/Core/BAO/File.php'; $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id); $returnProperties = $mailing->getReturnProperties(); $userID = $session->get('userID'); $params = array('contact_id' => $userID); $details = $mailing->getDetails($params, $returnProperties); $allDetails =& $mailing->compose(null, null, null, $userID, $fromEmail, $fromEmail, true, $details[0][$userID], $attachments); $this->assign('subject', $allDetails->_headers['Subject']); }
/** * Send activity as attachment. * * @param object $activity * @param array $mailToContacts * @param array $params * * @return bool */ public static function sendToAssignee($activity, $mailToContacts, $params = array()) { if (!CRM_Utils_Array::crmIsEmptyArray($mailToContacts)) { $clientID = CRM_Utils_Array::value('client_id', $params); $caseID = CRM_Utils_Array::value('case_id', $params); $ics = new CRM_Activity_BAO_ICalendar($activity); $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); $ics->addAttachment($attachments, $mailToContacts); $result = CRM_Case_BAO_Case::sendActivityCopy($clientID, $activity->id, $mailToContacts, $attachments, $caseID); $ics->cleanup(); return $result; } return FALSE; }
/** * Send the mailing. * * @param object $mailer * A Mail object to send the messages. * * @param array $testParams * * @return void */ public function deliver(&$mailer, $testParams = NULL) { $mailing = new CRM_Mailing_BAO_Mailing(); $mailing->id = $this->mailing_id; $mailing->find(TRUE); $mailing->free(); $eq = new CRM_Mailing_Event_BAO_Queue(); $eqTable = CRM_Mailing_Event_BAO_Queue::getTableName(); $emailTable = CRM_Core_BAO_Email::getTableName(); $phoneTable = CRM_Core_DAO_Phone::getTableName(); $contactTable = CRM_Contact_BAO_Contact::getTableName(); $edTable = CRM_Mailing_Event_BAO_Delivered::getTableName(); $ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName(); $query = " SELECT {$eqTable}.id,\n {$emailTable}.email as email,\n {$eqTable}.contact_id,\n {$eqTable}.hash,\n NULL as phone\n FROM {$eqTable}\n INNER JOIN {$emailTable}\n ON {$eqTable}.email_id = {$emailTable}.id\n INNER JOIN {$contactTable}\n ON {$contactTable}.id = {$emailTable}.contact_id\n LEFT JOIN {$edTable}\n ON {$eqTable}.id = {$edTable}.event_queue_id\n LEFT JOIN {$ebTable}\n ON {$eqTable}.id = {$ebTable}.event_queue_id\n WHERE {$eqTable}.job_id = " . $this->id . "\n AND {$edTable}.id IS null\n AND {$ebTable}.id IS null\n AND {$contactTable}.is_opt_out = 0"; if ($mailing->sms_provider_id) { $query = "\n SELECT {$eqTable}.id,\n {$phoneTable}.phone as phone,\n {$eqTable}.contact_id,\n {$eqTable}.hash,\n NULL as email\n FROM {$eqTable}\n INNER JOIN {$phoneTable}\n ON {$eqTable}.phone_id = {$phoneTable}.id\n INNER JOIN {$contactTable}\n ON {$contactTable}.id = {$phoneTable}.contact_id\n LEFT JOIN {$edTable}\n ON {$eqTable}.id = {$edTable}.event_queue_id\n LEFT JOIN {$ebTable}\n ON {$eqTable}.id = {$ebTable}.event_queue_id\n WHERE {$eqTable}.job_id = " . $this->id . "\n AND {$edTable}.id IS null\n AND {$ebTable}.id IS null\n AND ( {$contactTable}.is_opt_out = 0\n OR {$contactTable}.do_not_sms = 0 )"; } $eq->query($query); $config = NULL; if ($config == NULL) { $config = CRM_Core_Config::singleton(); } $job_date = CRM_Utils_Date::isoToMysql($this->scheduled_date); $fields = array(); if (!empty($testParams)) { $mailing->subject = ts('[CiviMail Draft]') . ' ' . $mailing->subject; } CRM_Mailing_BAO_Mailing::tokenReplace($mailing); // get and format attachments $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id); if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) { CRM_Core_Smarty::registerStringResource(); } // CRM-12376 // This handles the edge case scenario where all the mails // have been delivered in prior jobs $isDelivered = TRUE; // make sure that there's no more than $config->mailerBatchLimit mails processed in a run while ($eq->fetch()) { // if ( ( $mailsProcessed % 100 ) == 0 ) { // CRM_Utils_System::xMemory( "$mailsProcessed: " ); // } if ($config->mailerBatchLimit > 0 && self::$mailsProcessed >= $config->mailerBatchLimit) { if (!empty($fields)) { $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments); } $eq->free(); return FALSE; } self::$mailsProcessed++; $fields[] = array('id' => $eq->id, 'hash' => $eq->hash, 'contact_id' => $eq->contact_id, 'email' => $eq->email, 'phone' => $eq->phone); if (count($fields) == self::MAX_CONTACTS_TO_PROCESS) { $isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments); if (!$isDelivered) { $eq->free(); return $isDelivered; } $fields = array(); } } $eq->free(); if (!empty($fields)) { $isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments); } return $isDelivered; }
/** * Preview mailing. * * @param array $params * Array per getfields metadata. * * @return array * @throws \API_Exception */ function civicrm_api3_mailing_preview($params) { civicrm_api3_verify_mandatory($params, 'CRM_Mailing_DAO_Mailing', array('id'), FALSE); $fromEmail = NULL; if (!empty($params['from_email'])) { $fromEmail = $params['from_email']; } $session = CRM_Core_Session::singleton(); $mailing = new CRM_Mailing_BAO_Mailing(); $mailing->id = $params['id']; $mailing->find(TRUE); CRM_Mailing_BAO_Mailing::tokenReplace($mailing); // get and format attachments $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id); $returnProperties = $mailing->getReturnProperties(); $contactID = CRM_Utils_Array::value('contact_id', $params); if (!$contactID) { $contactID = $session->get('userID'); } $mailingParams = array('contact_id' => $contactID); $details = CRM_Utils_Token::getTokenDetails($mailingParams, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens()); $mime =& $mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, TRUE, $details[0][$contactID], $attachments); return civicrm_api3_create_success(array('id' => $params['id'], 'contact_id' => $contactID, 'subject' => $mime->_headers['Subject'], 'body_html' => $mime->getHTMLBody(), 'body_text' => $mime->getTXTBody())); }
/** * run this page (figure out the action needed and perform it). * * @return void */ function run($id = null, $print = true) { if (is_numeric($id)) { $this->_mailingID = $id; } else { $print = true; $this->_mailingID = CRM_Utils_Request::retrieve('id', 'Integer', CRM_Core_DAO::$_nullObject, true); } $session =& CRM_Core_Session::singleton(); $this->_contactID = $session->get('userID'); require_once 'CRM/Mailing/BAO/Mailing.php'; $this->_mailing = new CRM_Mailing_BAO_Mailing(); $this->_mailing->id = $this->_mailingID; require_once 'CRM/Core/Error.php'; if (!$this->_mailing->find(true)) { CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to approve this mailing.')); } CRM_Mailing_BAO_Mailing::tokenReplace($this->_mailing); if (defined('CIVICRM_MAIL_SMARTY')) { require_once 'CRM/Core/Smarty/resources/String.php'; civicrm_smarty_register_string_resource(); } // get and format attachments require_once 'CRM/Core/BAO/File.php'; $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $this->_mailing->id); //get details of contact with token value including Custom Field Token Values.CRM-3734 $returnProperties = $this->_mailing->getReturnProperties(); $params = array('contact_id' => $this->_contactID); $details = $this->_mailing->getDetails($params, $returnProperties); $mime =& $this->_mailing->compose(null, null, null, $this->_contactID, $fromEmail, $fromEmail, true, $details[0][$this->_contactID], $attachments); if (isset($this->_mailing->body_html)) { $header = 'Content-Type: text/html; charset=utf-8'; $content = $mime->getHTMLBody(); } else { $header = 'Content-Type: text/plain; charset=utf-8'; $content = $mime->getTXTBody(); } if ($print) { header($header); print $content; CRM_Utils_System::civiExit(); } else { return $content; } }
/** * send the message to all the contacts and also insert a * contact activity in each contacts record * * @param array $contactDetails the array of contact details to send the email * @param string $subject the subject of the message * @param string $message the message contents * @param string $emailAddress use this 'to' email address instead of the default Primary address * @param int $userID use this userID if set * @param string $from * @param array $attachments the array of attachments if any * @param string $cc cc recepient * @param string $bcc bcc recepient * @param array $contactIds contact ids * @return array ( sent, activityId) if any email is sent and activityId * @access public * @static */ static function sendEmail(&$contactDetails, &$subject, &$text, &$html, $emailAddress, $userID = null, $from = null, $attachments = null, $cc = null, $bcc = null, &$contactIds) { // get the contact details of logged in contact, which we set as from email if ($userID == null) { $session =& CRM_Core_Session::singleton(); $userID = $session->get('userID'); } list($fromDisplayName, $fromEmail, $fromDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID); if (!$fromEmail) { return array(count($contactDetails), 0, count($contactDetails)); } if (!trim($fromDisplayName)) { $fromDisplayName = $fromEmail; } //CRM-4575 //token replacement of addressee/email/postal greetings // get the tokens added in subject and message $messageToken = self::getTokens($text); $subjectToken = self::getTokens($subject); $messageToken = array_merge($messageToken, self::getTokens($html)); require_once 'CRM/Utils/Mail.php'; if (!$from) { $from = "{$fromDisplayName} <{$fromEmail}>"; } //create the meta level record first ( email activity ) $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name'); $activityParams = array('source_contact_id' => $userID, 'activity_type_id' => $activityTypeID, 'activity_date_time' => date('YmdHis'), 'subject' => $subject, 'details' => $text ? $text : $html, 'status_id' => 2); // add the attachments to activity params here if ($attachments) { // first process them $activityParams = array_merge($activityParams, $attachments); } $activity = self::create($activityParams); // get the set of attachments from where they are stored $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); $returnProperties = array(); if (isset($messageToken['contact'])) { foreach ($messageToken['contact'] as $key => $value) { $returnProperties[$value] = 1; } } if (isset($subjectToken['contact'])) { foreach ($subjectToken['contact'] as $key => $value) { if (!isset($returnProperties[$value])) { $returnProperties[$value] = 1; } } } // get token details for contacts, call only if tokens are used $details = array(); if (!empty($returnProperties)) { require_once 'CRM/Mailing/BAO/Mailing.php'; $mailing = new CRM_Mailing_BAO_Mailing(); list($details) = $mailing->getDetails($contactIds, $returnProperties); } // call token hook $tokens = array(); CRM_Utils_Hook::tokens($tokens); $categories = array_keys($tokens); if (defined('CIVICRM_MAIL_SMARTY')) { $smarty =& CRM_Core_Smarty::singleton(); require_once 'CRM/Core/Smarty/resources/String.php'; civicrm_smarty_register_string_resource(); } require_once 'CRM/Utils/Token.php'; $sent = $notSent = array(); foreach ($contactDetails as $values) { $contactId = $values['contact_id']; $emailAddress = $values['email']; if (!empty($details) && is_array($details["{$contactId}"])) { // unset email from details since it always returns primary email address unset($details["{$contactId}"]['email']); unset($details["{$contactId}"]['email_id']); $values = array_merge($values, $details["{$contactId}"]); } $tokenSubject = CRM_Utils_Token::replaceContactTokens($subject, $values, false, $subjectToken); $tokenSubject = CRM_Utils_Token::replaceHookTokens($tokenSubject, $values, $categories, false); //CRM-4539 if ($values['preferred_mail_format'] == 'Text' || $values['preferred_mail_format'] == 'Both') { $tokenText = CRM_Utils_Token::replaceContactTokens($text, $values, false, $messageToken); $tokenText = CRM_Utils_Token::replaceHookTokens($tokenText, $values, $categories, false); } else { $tokenText = null; } if ($values['preferred_mail_format'] == 'HTML' || $values['preferred_mail_format'] == 'Both') { $tokenHtml = CRM_Utils_Token::replaceContactTokens($html, $values, true, $messageToken); $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $values, $categories, true); } else { $tokenHtml = null; } if (defined('CIVICRM_MAIL_SMARTY')) { // also add the contact tokens to the template $smarty->assign_by_ref('contact', $values); $tokenText = $smarty->fetch("string:{$tokenText}"); $tokenHtml = $smarty->fetch("string:{$tokenHtml}"); } $sent = false; if (self::sendMessage($from, $userID, $contactId, $tokenSubject, $tokenText, $tokenHtml, $emailAddress, $activity->id, $attachments, $cc, $bcc)) { $sent = true; } } return array($sent, $activity->id); }
static function fileZip() { $config = CRM_Core_Config::singleton(); $dest = $config->customFileUploadDir; $params = $_GET; $files = array(); $mimeType = 'application/zip'; $ext = 'zip'; $revisionId = (int) $params['entityID']; $entityFiles = CRM_Core_BAO_File::getEntityFile($params['entityTable'], $revisionId); if (empty($entityFiles)) { CRM_Utils_System::civiExit(); } $zipname = 'jobcontract_' . (int) $params['entityID'] . '_files'; $jobContractResult = civicrm_api3('HRJobContract', 'get', array('sequential' => 1, 'jobcontract_revision_id' => $revisionId)); if ($jobContractResult['count']) { $contactResult = civicrm_api3('Contact', 'get', array('sequential' => 1, 'id' => $jobContractResult['values'][0]['contact_id'])); $jobContractDetailsResult = civicrm_api3('HRJobDetails', 'get', array('sequential' => 1, 'jobcontract_revision_id' => $revisionId)); if ($contactResult['count'] && $jobContractDetailsResult['count']) { $zipname = CRM_Utils_String::munge($contactResult['values'][0]['sort_name']) . '-' . CRM_Utils_String::munge($jobContractDetailsResult['values'][0]['position']) . '-r' . $revisionId; } } if (count($entityFiles) > 1) { foreach ($entityFiles as $entityFile) { if (!empty($entityFile['fullPath'])) { $files[] = $entityFile['fullPath']; } } if (empty($files)) { CRM_Utils_System::civiExit(); } $zipname .= '.' . $ext; $zipfullpath = $dest . '/' . $zipname; $zip = new ZipArchive(); $zip->open($zipfullpath, ZipArchive::CREATE); foreach ($files as $file) { $zip->addFile($file, substr($file, strrpos($file, '/') + 1)); } $zip->close(); } else { $firstFile = CRM_Utils_Array::first($entityFiles); $zipfullpath = $firstFile['fullPath']; $mimeType = $firstFile['mime_type']; $parts = explode('.', $zipfullpath); $ext = end($parts); $zipname .= '.' . $ext; } header('Content-Type: ' . $mimeType); header('Content-disposition: attachment; filename=' . $zipname); header('Content-Length: ' . filesize($zipfullpath)); readfile($zipfullpath); CRM_Utils_System::civiExit(); }
/** * Function to process the form * * @access public * * @return None */ public function postProcess($params = NULL) { if ($this->_action & CRM_Core_Action::DELETE) { $deleteParams = array('id' => $this->_activityId); $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($this->_activityId); CRM_Activity_BAO_Activity::deleteActivity($deleteParams, $moveToTrash); // delete tags for the entity $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus(ts("Selected Activity has been deleted successfully.")); return; } // store the submitted values in an array if (!$params) { $params = $this->controller->exportValues($this->_name); } //set activity type id if (!CRM_Utils_Array::value('activity_type_id', $params)) { $params['activity_type_id'] = $this->_activityTypeId; } if (CRM_Utils_Array::value('hidden_custom', $params) && !isset($params['custom'])) { $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } // store the date with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); // assigning formated value to related variable if (CRM_Utils_Array::value('target_contact_id', $params)) { $params['target_contact_id'] = explode(',', $params['target_contact_id']); } else { $params['target_contact_id'] = array(); } if (CRM_Utils_Array::value('assignee_contact_id', $params)) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } // get ids for associated contacts if (!$params['source_contact_id']) { $params['source_contact_id'] = $this->_currentUserId; } else { $params['source_contact_id'] = $this->_submitValues['source_contact_qid']; } if (isset($this->_activityId)) { $params['id'] = $this->_activityId; } // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId); // format target params if (!$this->_single) { $params['target_contact_id'] = $this->_contactIds; } $activityAssigned = array(); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($this->_activityId); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) { CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this); } // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // CRM-9590 $this->_activityId = $activity->id; // create follow up activity if needed $followupStatus = ''; if (CRM_Utils_Array::value('followup_activity_type_id', $params)) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); $followupStatus = ts('A followup activity has been scheduled.'); } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) { $mailToContacts = array(); $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE); //build an associative array with unique email addresses. foreach ($activityAssigned as $id => $dnc) { if (isset($id) && array_key_exists($id, $assigneeContacts)) { $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id]; } } if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { //include attachments while sendig a copy of activity. $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); // CRM-8400 add param with _currentlyViewedContactId for URL link in mail $result = CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL); $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); } } // set status message if (CRM_Utils_Array::value('subject', $params)) { $params['subject'] = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2. %3', array(1 => $params['subject'], 2 => $followupStatus, 3 => $mailStatus))); return array('activity' => $activity); }
public function buildQuickForm() { $session = CRM_Core_Session::singleton(); $this->add('text', 'test_email', ts('Send to This Address')); $defaults['test_email'] = $session->get('ufUniqID'); $qfKey = $this->get('qfKey'); $this->add('select', 'test_group', ts('Send to This Group'), array('' => ts('- none -')) + CRM_Core_PseudoConstant::group('Mailing')); $this->setDefaults($defaults); $this->add('submit', 'sendtest', ts('Send a Test Mailing')); $name = ts('Next'); if (CRM_Mailing_Info::workflowEnabled()) { if (!CRM_Core_Permission::check('schedule mailings') && CRM_Core_Permission::check('create mailings')) { $name = ts('Inform Scheduler'); } } $buttons = array(array('type' => 'back', 'name' => ts('Previous')), array('type' => 'next', 'name' => $name, 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel'))); $this->addButtons($buttons); $mailingID = $this->get('mailing_id'); $textFile = $this->get('textFile'); $htmlFile = $this->get('htmlFile'); $this->addFormRule(array('CRM_Mailing_Form_Test', 'testMail'), $this); $preview = array(); if ($textFile) { $preview['text_link'] = CRM_Utils_System::url('civicrm/mailing/preview', "type=text&qfKey={$qfKey}"); } if ($htmlFile) { $preview['html_link'] = CRM_Utils_System::url('civicrm/mailing/preview', "type=html&qfKey={$qfKey}"); } $preview['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_mailing', $mailingID); $this->assign('preview', $preview); //Token Replacement of Subject in preview mailing $options = array(); $prefix = "CRM_Mailing_Controller_Send_{$qfKey}"; if ($this->_searchBasedMailing) { $prefix = "CRM_Contact_Controller_Search_{$qfKey}"; } $session->getVars($options, $prefix); $mailing = new CRM_Mailing_BAO_Mailing(); $mailing->id = $options['mailing_id']; $mailing->find(TRUE); $fromEmail = $mailing->from_email; $replyToEmail = $mailing->replyto_email; $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id); $returnProperties = $mailing->getReturnProperties(); $userID = $session->get('userID'); $params = array('contact_id' => $userID); $details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens(), get_class($this)); $allDetails =& $mailing->compose(NULL, NULL, NULL, $userID, $fromEmail, $fromEmail, TRUE, $details[0][$userID], $attachments); $this->assign('subject', $allDetails->_headers['Subject']); }
/** * Send the mailing * * @param object $mailer A Mail object to send the messages * @return void * @access public */ public function deliver(&$mailer, $testParams = null) { require_once 'CRM/Mailing/BAO/Mailing.php'; $mailing =& new CRM_Mailing_BAO_Mailing(); $mailing->id = $this->mailing_id; $mailing->find(true); $eq =& new CRM_Mailing_Event_BAO_Queue(); $eqTable = CRM_Mailing_Event_BAO_Queue::getTableName(); $emailTable = CRM_Core_BAO_Email::getTableName(); $contactTable = CRM_Contact_BAO_Contact::getTableName(); $edTable = CRM_Mailing_Event_BAO_Delivered::getTableName(); $ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName(); $query = " SELECT {$eqTable}.id,\n {$emailTable}.email as email,\n {$eqTable}.contact_id,\n {$eqTable}.hash\n FROM {$eqTable}\n INNER JOIN {$emailTable}\n ON {$eqTable}.email_id = {$emailTable}.id\n LEFT JOIN {$edTable}\n ON {$eqTable}.id = {$edTable}.event_queue_id\n LEFT JOIN {$ebTable}\n ON {$eqTable}.id = {$ebTable}.event_queue_id\n WHERE {$eqTable}.job_id = " . $this->id . "\n AND {$edTable}.id IS null\n AND {$ebTable}.id IS null"; $eq->query($query); static $config = null; $mailsProcessed = 0; if ($config == null) { $config =& CRM_Core_Config::singleton(); } $job_date = CRM_Utils_Date::isoToMysql($this->scheduled_date); $fields = array(); if (!empty($testParams)) { $mailing->from_name = ts('CiviCRM Test Mailer (%1)', array(1 => $mailing->from_name)); $mailing->subject = ts('Test Mailing:') . ' ' . $mailing->subject; } CRM_Mailing_BAO_Mailing::tokenReplace($mailing); // get and format attachments require_once 'CRM/Core/BAO/File.php'; $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id); if (defined('CIVICRM_MAIL_SMARTY')) { require_once 'CRM/Core/Smarty/resources/String.php'; civicrm_smarty_register_string_resource(); } // make sure that there's no more than $config->mailerBatchLimit mails processed in a run while ($eq->fetch()) { // if ( ( $mailsProcessed % 100 ) == 0 ) { // CRM_Utils_System::xMemory( "$mailsProcessed: " ); // } if ($config->mailerBatchLimit > 0 && $mailsProcessed >= $config->mailerBatchLimit) { $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments); return false; } $mailsProcessed++; $fields[] = array('id' => $eq->id, 'hash' => $eq->hash, 'contact_id' => $eq->contact_id, 'email' => $eq->email); if (count($fields) == self::MAX_CONTACTS_TO_PROCESS) { $isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments); if (!$isDelivered) { return $isDelivered; } $fields = array(); } } $isDelivered = $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments); return $isDelivered; }
/** * send the message to all the contacts and also insert a * contact activity in each contacts record * * @param array $contactDetails the array of contact details to send the email * @param string $subject the subject of the message * @param string $message the message contents * @param string $emailAddress use this 'to' email address instead of the default Primary address * @param int $userID use this userID if set * @param string $from * @param array $attachments the array of attachments if any * @param string $cc cc recipient * @param string $bcc bcc recipient * @param array $contactIds contact ids * @param string $additionalDetails the additional information of CC and BCC appended to the activity Details * * @return array ( sent, activityId) if any email is sent and activityId * @access public * @static */ static function sendEmail(&$contactDetails, &$subject, &$text, &$html, $emailAddress, $userID = NULL, $from = NULL, $attachments = NULL, $cc = NULL, $bcc = NULL, $contactIds, $additionalDetails = NULL) { // get the contact details of logged in contact, which we set as from email if ($userID == NULL) { $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); } list($fromDisplayName, $fromEmail, $fromDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID); if (!$fromEmail) { return array(count($contactDetails), 0, count($contactDetails)); } if (!trim($fromDisplayName)) { $fromDisplayName = $fromEmail; } // CRM-4575 // token replacement of addressee/email/postal greetings // get the tokens added in subject and message $subjectToken = CRM_Utils_Token::getTokens($subject); $messageToken = CRM_Utils_Token::getTokens($text); $messageToken = array_merge($messageToken, CRM_Utils_Token::getTokens($html)); $allTokens = array_merge($messageToken, $subjectToken); if (!$from) { $from = "{$fromDisplayName} <{$fromEmail}>"; } //create the meta level record first ( email activity ) $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name'); // CRM-6265: save both text and HTML parts in details (if present) if ($html and $text) { $details = "-ALTERNATIVE ITEM 0-\n{$html}{$additionalDetails}\n-ALTERNATIVE ITEM 1-\n{$text}{$additionalDetails}\n-ALTERNATIVE END-\n"; } else { $details = $html ? $html : $text; $details .= $additionalDetails; } $activityParams = array('source_contact_id' => $userID, 'activity_type_id' => $activityTypeID, 'activity_date_time' => date('YmdHis'), 'subject' => $subject, 'details' => $details, 'status_id' => 2); // CRM-5916: strip [case #…] before saving the activity (if present in subject) $activityParams['subject'] = preg_replace('/\\[case #([0-9a-h]{7})\\] /', '', $activityParams['subject']); // add the attachments to activity params here if ($attachments) { // first process them $activityParams = array_merge($activityParams, $attachments); } $activity = self::create($activityParams); // get the set of attachments from where they are stored $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); $returnProperties = array(); if (isset($messageToken['contact'])) { foreach ($messageToken['contact'] as $key => $value) { $returnProperties[$value] = 1; } } if (isset($subjectToken['contact'])) { foreach ($subjectToken['contact'] as $key => $value) { if (!isset($returnProperties[$value])) { $returnProperties[$value] = 1; } } } // get token details for contacts, call only if tokens are used $details = array(); if (!empty($returnProperties) || !empty($tokens) || !empty($allTokens)) { list($details) = CRM_Utils_Token::getTokenDetails($contactIds, $returnProperties, NULL, NULL, FALSE, $allTokens, 'CRM_Activity_BAO_Activity'); } // call token hook $tokens = array(); CRM_Utils_Hook::tokens($tokens); $categories = array_keys($tokens); $escapeSmarty = FALSE; if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) { $smarty = CRM_Core_Smarty::singleton(); $escapeSmarty = TRUE; } $sent = $notSent = array(); foreach ($contactDetails as $values) { $contactId = $values['contact_id']; $emailAddress = $values['email']; if (!empty($details) && is_array($details["{$contactId}"])) { // unset email from details since it always returns primary email address unset($details["{$contactId}"]['email']); unset($details["{$contactId}"]['email_id']); $values = array_merge($values, $details["{$contactId}"]); } $tokenSubject = CRM_Utils_Token::replaceContactTokens($subject, $values, FALSE, $subjectToken, FALSE, $escapeSmarty); $tokenSubject = CRM_Utils_Token::replaceHookTokens($tokenSubject, $values, $categories, FALSE, $escapeSmarty); //CRM-4539 if ($values['preferred_mail_format'] == 'Text' || $values['preferred_mail_format'] == 'Both') { $tokenText = CRM_Utils_Token::replaceContactTokens($text, $values, FALSE, $messageToken, FALSE, $escapeSmarty); $tokenText = CRM_Utils_Token::replaceHookTokens($tokenText, $values, $categories, FALSE, $escapeSmarty); } else { $tokenText = NULL; } if ($values['preferred_mail_format'] == 'HTML' || $values['preferred_mail_format'] == 'Both') { $tokenHtml = CRM_Utils_Token::replaceContactTokens($html, $values, TRUE, $messageToken, FALSE, $escapeSmarty); $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $values, $categories, TRUE, $escapeSmarty); } else { $tokenHtml = NULL; } if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) { // also add the contact tokens to the template $smarty->assign_by_ref('contact', $values); $tokenSubject = $smarty->fetch("string:{$tokenSubject}"); $tokenText = $smarty->fetch("string:{$tokenText}"); $tokenHtml = $smarty->fetch("string:{$tokenHtml}"); } $sent = FALSE; if (self::sendMessage($from, $userID, $contactId, $tokenSubject, $tokenText, $tokenHtml, $emailAddress, $activity->id, $attachments, $cc, $bcc)) { $sent = TRUE; } } return array($sent, $activity->id); }
/** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * Finally it calls the parent's run method. * * @return void */ public function run() { $session = CRM_Core_Session::singleton(); $config = CRM_Core_Config::singleton(); $permissionCheck = FALSE; $statusMessage = ''; if ($config->userFramework != 'Joomla') { $permissionCheck = CRM_Core_Permission::check('administer CiviCRM'); } //get the pcp id. $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE); $prms = array('id' => $this->_id); CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo); $this->_component = $pcpInfo['page_type']; if (empty($pcpInfo)) { $statusMessage = ts('The personal campaign page you requested is currently unavailable.'); CRM_Core_Error::statusBounce($statusMessage, $config->userFrameworkBaseURL); } CRM_Utils_System::setTitle($pcpInfo['title']); $this->assign('pcp', $pcpInfo); $pcpStatus = CRM_Core_OptionGroup::values("pcp_status"); $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name'); // check if PCP is created by anonymous user $anonymousPCP = CRM_Utils_Request::retrieve('ap', 'Boolean', $this); if ($anonymousPCP) { $loginURL = $config->userSystem->getLoginURL(); $anonMessage = ts('Once you\'ve received your new account welcome email, you can <a href=%1>click here</a> to login and promote your campaign page.', array(1 => $loginURL)); CRM_Core_Session::setStatus($anonMessage, ts('Success'), 'success'); } else { $statusMessage = ts('The personal campaign page you requested is currently unavailable. However you can still support the campaign by making a contribution here.'); } $pcpBlock = new CRM_PCP_DAO_PCPBlock(); $pcpBlock->entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($pcpInfo['page_type']); $pcpBlock->entity_id = $pcpInfo['page_id']; $pcpBlock->find(TRUE); // Redirect back to source page in case of error. if ($pcpInfo['page_type'] == 'contribute') { $urlBase = 'civicrm/contribute/transact'; } elseif ($pcpInfo['page_type'] == 'event') { $urlBase = 'civicrm/event/register'; } if ($pcpInfo['status_id'] != $approvedId || !$pcpInfo['is_active']) { if ($pcpInfo['contact_id'] != $session->get('userID') && !$permissionCheck) { CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url($urlBase, "reset=1&id=" . $pcpInfo['page_id'], FALSE, NULL, FALSE, TRUE)); } } else { $getStatus = CRM_PCP_BAO_PCP::getStatus($this->_id, $this->_component); if (!$getStatus) { // PCP not enabled for this contribution page. Forward everyone to source page CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url($urlBase, "reset=1&id=" . $pcpInfo['page_id'], FALSE, NULL, FALSE, TRUE)); } } $default = array(); if ($pcpBlock->target_entity_type == 'contribute') { $urlBase = 'civicrm/contribute/transact'; } elseif ($pcpBlock->target_entity_type == 'event') { $urlBase = 'civicrm/event/register'; } if ($pcpBlock->entity_table == 'civicrm_event') { $page_class = 'CRM_Event_DAO_Event'; $this->assign('pageName', CRM_Event_PseudoConstant::event($pcpInfo['page_id'])); CRM_Core_DAO::commonRetrieveAll($page_class, 'id', $pcpInfo['page_id'], $default, array('start_date', 'end_date', 'registration_start_date', 'registration_end_date')); } elseif ($pcpBlock->entity_table == 'civicrm_contribution_page') { $page_class = 'CRM_Contribute_DAO_ContributionPage'; $this->assign('pageName', CRM_Contribute_PseudoConstant::contributionPage($pcpInfo['page_id'], TRUE)); CRM_Core_DAO::commonRetrieveAll($page_class, 'id', $pcpInfo['page_id'], $default, array('start_date', 'end_date')); } $pageInfo = $default[$pcpInfo['page_id']]; if ($pcpInfo['contact_id'] == $session->get('userID')) { $owner = $pageInfo; $owner['status'] = CRM_Utils_Array::value($pcpInfo['status_id'], $pcpStatus); $this->assign('owner', $owner); $link = CRM_PCP_BAO_PCP::pcpLinks(); $hints = array(CRM_Core_Action::UPDATE => ts('Change the content and appearance of your page'), CRM_Core_Action::DETACH => ts('Send emails inviting your friends to support your campaign!'), CRM_Core_Action::VIEW => ts('Copy this link to share directly with your network!'), CRM_Core_Action::BROWSE => ts('Update your personal contact information'), CRM_Core_Action::DISABLE => ts('De-activate the page (you can re-activate it later)'), CRM_Core_Action::ENABLE => ts('Activate the page (you can de-activate it later)'), CRM_Core_Action::DELETE => ts('Remove the page (this cannot be undone!)')); $replace = array('id' => $this->_id, 'block' => $pcpBlock->id, 'pageComponent' => $this->_component); if (!$pcpBlock->is_tellfriend_enabled || CRM_Utils_Array::value('status_id', $pcpInfo) != $approvedId) { unset($link['all'][CRM_Core_Action::DETACH]); } switch ($pcpInfo['is_active']) { case 1: unset($link['all'][CRM_Core_Action::ENABLE]); break; case 0: unset($link['all'][CRM_Core_Action::DISABLE]); break; } $this->assign('links', $link['all']); $this->assign('hints', $hints); $this->assign('replace', $replace); } $honor = CRM_PCP_BAO_PCP::honorRoll($this->_id); $entityFile = CRM_Core_BAO_File::getEntityFile('civicrm_pcp', $this->_id); if (!empty($entityFile)) { $fileInfo = reset($entityFile); $fileId = $fileInfo['fileID']; $image = '<img src="' . CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$this->_id}") . '" />'; $this->assign('image', $image); } $totalAmount = CRM_PCP_BAO_PCP::thermoMeter($this->_id); $achieved = round($totalAmount / $pcpInfo['goal_amount'] * 100, 2); if ($pcpBlock->is_active == 1) { $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$pcpInfo['page_id']}&component={$pcpInfo['page_type']}", TRUE, NULL, TRUE, TRUE); $this->assign('linkTextUrl', $linkTextUrl); $this->assign('linkText', $pcpBlock->link_text); } $this->assign('honor', $honor); $this->assign('total', $totalAmount ? $totalAmount : '0.0'); $this->assign('achieved', $achieved <= 100 ? $achieved : 100); if ($achieved <= 100) { $this->assign('remaining', 100 - $achieved); } // make sure that we are between contribution page start and end dates OR registration start date and end dates if they are set if ($pcpBlock->entity_table == 'civicrm_event') { $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_start_date', $pageInfo)); $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_end_date', $pageInfo)); } else { $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $pageInfo)); $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $pageInfo)); } $now = time(); $validDate = TRUE; if ($startDate && $startDate >= $now) { $validDate = FALSE; } if ($endDate && $endDate < $now) { $validDate = FALSE; } $this->assign('validDate', $validDate); // form parent page url if ($action == CRM_Core_Action::PREVIEW) { $parentUrl = CRM_Utils_System::url($urlBase, "id={$pcpInfo['page_id']}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE); } else { $parentUrl = CRM_Utils_System::url($urlBase, "id={$pcpInfo['page_id']}&reset=1", TRUE, NULL, TRUE, TRUE); } $this->assign('parentURL', $parentUrl); if ($validDate) { $contributionText = ts('Contribute Now'); if (!empty($pcpInfo['donate_link_text'])) { $contributionText = $pcpInfo['donate_link_text']; } $this->assign('contributionText', $contributionText); // we always generate urls for the front end in joomla if ($action == CRM_Core_Action::PREVIEW) { $url = CRM_Utils_System::url($urlBase, "id=" . $pcpBlock->target_entity_id . "&pcpId={$this->_id}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE); } else { $url = CRM_Utils_System::url($urlBase, "id=" . $pcpBlock->target_entity_id . "&pcpId={$this->_id}&reset=1", TRUE, NULL, TRUE, TRUE); } $this->assign('contributeURL', $url); } // we do not want to display recently viewed items, so turn off $this->assign('displayRecent', FALSE); $single = $permission = FALSE; switch ($action) { case CRM_Core_Action::BROWSE: $subForm = 'PCPAccount'; $form = "CRM_PCP_Form_{$subForm}"; $single = TRUE; break; case CRM_Core_Action::UPDATE: $subForm = 'Campaign'; $form = "CRM_PCP_Form_{$subForm}"; $single = TRUE; break; } $userID = $session->get('userID'); //make sure the user has "administer CiviCRM" permission //OR has created the PCP if (CRM_Core_Permission::check('administer CiviCRM') || $userID && CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'contact_id') == $userID) { $permission = TRUE; } if ($single && $permission) { $controller = new CRM_Core_Controller_Simple($form, $subForm, $action); $controller->set('id', $this->_id); $controller->set('single', TRUE); $controller->process(); return $controller->run(); } $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&id=' . $this->_id)); parent::run(); }
function _civicrm_api3_pcpteams_getMoreInfo(&$params) { foreach ($params as $pcpId => $pcpValues) { $entityFile = CRM_Core_BAO_File::getEntityFile('civicrm_pcp', $pcpId); $imageUrl = ""; $fileId = NULL; if ($entityFile) { $fileInfo = reset($entityFile); $fileId = $fileInfo['fileID']; $imageUrl = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$pcpId}"); } $pcpBlockId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'pcp_block_id', 'id'); if ($pcpBlockId) { $contributionPageId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCPBlock', $pcpBlockId, 'target_entity_id', 'id'); } $donateUrl = CRM_Utils_System::url('civicrm/contribute/transact', 'id=' . $contributionPageId . '&pcpId=' . $pcpId . '&reset=1'); $aContactTypes = CRM_Contact_BAO_Contact::getContactTypes($pcpValues['contact_id']); $isTeamPcp = in_array('Team', $aContactTypes) ? TRUE : FALSE; $params[$pcpId]['page_title'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $pcpValues['page_id'], 'title'); $params[$pcpId]['amount_raised'] = civicrm_api3_pcpteams_getAmountRaised(array('pcp_id' => $pcpId, 'version' => 3)); $params[$pcpId]['image_url'] = $imageUrl ? $imageUrl : CRM_Pcpteams_Constant::C_DEFAULT_PROFILE_PIC; $params[$pcpId]['image_id'] = $fileId; $params[$pcpId]['donate_url'] = $donateUrl; $params[$pcpId]['is_teampage'] = $isTeamPcp; //calculate percentage $percentage = 0; if (isset($pcpValues['goal_amount']) && number_format($pcpValues['goal_amount']) != '0') { $percentage = number_format($params[$pcpId]['amount_raised'] / $params[$pcpId]['goal_amount'] * 100); } if (isset($pcpValues['currency'])) { $params[$pcpId]['currency_symbol'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $pcpValues['currency'], 'symbol', 'name'); } $params[$pcpId]['percentage'] = $percentage; // check the user has pending request $pendingDetails = civicrm_api3_pcpteams_getMyPendingTeam(array('contact_id' => $pcpValues['contact_id'])); $params[$pcpId]['pending_team_pcp_id'] = isset($pendingDetails['values'][0]) ? $pendingDetails['values'][0]['teamPcpId'] : NULL; $params[$pcpId]['pending_team_relationship_id'] = isset($pendingDetails['values'][0]) ? $pendingDetails['values'][0]['relationship_id'] : NULL; } }
/** * Part of the post process which prepare and extract information from the template. * * * @param array $formValues * * @return array * [$categories, $html_message, $messageToken, $returnProperties] */ public static function processMessageTemplate($formValues) { $html_message = CRM_Utils_Array::value('html_message', $formValues); // process message template if (!empty($formValues['saveTemplate']) || !empty($formValues['updateTemplate'])) { $messageTemplate = array('msg_text' => NULL, 'msg_html' => $formValues['html_message'], 'msg_subject' => NULL, 'is_active' => TRUE); $messageTemplate['pdf_format_id'] = 'null'; if (!empty($formValues['bind_format']) && $formValues['format_id']) { $messageTemplate['pdf_format_id'] = $formValues['format_id']; } if (!empty($formValues['saveTemplate']) && $formValues['saveTemplate']) { $messageTemplate['msg_title'] = $formValues['saveTemplateName']; CRM_Core_BAO_MessageTemplate::add($messageTemplate); } if (!empty($formValues['updateTemplate']) && $formValues['template'] && $formValues['updateTemplate']) { $messageTemplate['id'] = $formValues['template']; unset($messageTemplate['msg_title']); CRM_Core_BAO_MessageTemplate::add($messageTemplate); } } elseif (CRM_Utils_Array::value('template', $formValues) > 0) { if (!empty($formValues['bind_format']) && $formValues['format_id']) { $query = "UPDATE civicrm_msg_template SET pdf_format_id = {$formValues['format_id']} WHERE id = {$formValues['template']}"; } else { $query = "UPDATE civicrm_msg_template SET pdf_format_id = NULL WHERE id = {$formValues['template']}"; } CRM_Core_DAO::executeQuery($query); $documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $formValues['template']); foreach ((array) $documentInfo as $info) { list($html_message, $formValues['document_type']) = CRM_Utils_PDF_Document::docReader($info['fullPath'], $info['mime_type']); $formValues['document_file_path'] = $info['fullPath']; } } elseif (!empty($formValues['document_file'])) { list($html_message, $formValues['document_type']) = CRM_Utils_PDF_Document::docReader($formValues['document_file']['name'], $formValues['document_file']['type']); $formValues['document_file_path'] = $formValues['document_file']['name']; } if (!empty($formValues['update_format'])) { $bao = new CRM_Core_BAO_PdfFormat(); $bao->savePdfFormat($formValues, $formValues['format_id']); } $tokens = array(); CRM_Utils_Hook::tokens($tokens); $categories = array_keys($tokens); //time being hack to strip ' ' //from particular letter line, CRM-6798 self::formatMessage($html_message); $messageToken = CRM_Utils_Token::getTokens($html_message); $returnProperties = array(); if (isset($messageToken['contact'])) { foreach ($messageToken['contact'] as $key => $value) { $returnProperties[$value] = 1; } } return array($formValues, $categories, $html_message, $messageToken, $returnProperties); }