/**
  * Process the form submission.
  *
  *
  * @param array $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;
     }
     // 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, $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'];
         }
     }
     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];
                         }
                     }
                 }
             }
         }
         $extraParams = array('case_id' => $vval['case_id'], 'client_id' => $this->_currentlyViewedContactId);
         $result = CRM_Activity_BAO_Activity::sendToAssignee($activity, $mailToContacts, $extraParams);
         if (empty($result)) {
             $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.") . '<br /><br />';
             }
         }
         $title = ts("%1 Saved", array(1 => $this->_activityTypeName));
         CRM_Core_Session::setStatus($followupStatus . $mailStatus, $title, 'success');
     }
 }
Exemple #2
0
 /** 
  * Function to process the form 
  * 
  * @access public 
  * @return None 
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         require_once 'CRM/Grant/BAO/Grant.php';
         CRM_Grant_BAO_Grant::del($this->_id);
         return;
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $ids['grant'] = $this->_id;
     }
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     if (!$params['grant_report_received']) {
         $params['grant_report_received'] = "null";
     }
     // set the contact, when contact is selected
     if (CRM_Utils_Array::value('contact_select_id', $params)) {
         $this->_contactID = $params['contact_select_id'][1];
     }
     $params['contact_id'] = $this->_contactID;
     $dates = array('application_received_date', 'decision_date', 'money_transfer_date', 'grant_due_date');
     foreach ($dates as $d) {
         $params[$d] = CRM_Utils_Date::processDate($params[$d], null, true);
     }
     $ids['note'] = array();
     if ($this->_noteId) {
         $ids['note']['id'] = $this->_noteId;
     }
     // process custom data
     $customFields = CRM_Core_BAO_CustomField::getFields('Grant');
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Grant');
     // add attachments as needed
     CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_grant', $this->_id);
     require_once 'CRM/Grant/BAO/Grant.php';
     $grant = CRM_Grant_BAO_Grant::create($params, $ids);
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($this->_context == 'standalone') {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/grant/add', 'reset=1&action=add&context=standalone'));
         } else {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactID}&selectedChild=grant"));
         }
     } else {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/grant', "reset=1&action=add&context=grant&cid={$this->_contactID}"));
         }
     }
 }
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active', 'is_notify');
     foreach ($checkBoxes as $key) {
         if (!isset($params[$key])) {
             $params[$key] = 0;
         }
     }
     $session = CRM_Core_Session::singleton();
     $contactID = isset($this->_contactID) ? $this->_contactID : $session->get('userID');
     if (!$contactID) {
         $contactID = $this->get('contactID');
     }
     $params['title'] = $params['pcp_title'];
     $params['intro_text'] = $params['pcp_intro_text'];
     $params['contact_id'] = $contactID;
     $params['page_id'] = $this->get('component_page_id') ? $this->get('component_page_id') : $this->_contriPageId;
     $params['page_type'] = $this->_component;
     // since we are allowing html input from the user
     // we also need to purify it, so lets clean it up
     $htmlFields = array('intro_text', 'page_text', 'title');
     foreach ($htmlFields as $field) {
         if (!empty($params[$field])) {
             $params[$field] = CRM_Utils_String::purifyHTML($params[$field]);
         }
     }
     $entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($params['page_type']);
     $pcpBlock = new CRM_PCP_DAO_PCPBlock();
     $pcpBlock->entity_table = $entity_table;
     $pcpBlock->entity_id = $params['page_id'];
     $pcpBlock->find(TRUE);
     $params['pcp_block_id'] = $pcpBlock->id;
     $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
     $approval_needed = $pcpBlock->is_approval_needed;
     $approvalMessage = NULL;
     if ($this->get('action') & CRM_Core_Action::ADD) {
         $params['status_id'] = $approval_needed ? 1 : 2;
         $approvalMessage = $approval_needed ? ts('but requires administrator review before you can begin promoting your campaign. You will receive an email confirmation shortly which includes a link to return to this page.') : ts('and is ready to use.');
     }
     $params['id'] = $this->_pageId;
     $pcp = CRM_PCP_BAO_PCP::add($params, FALSE);
     //create page in wordpress
     create_wp_campaign($pcp->title, $pcp->contact_id, $pcp->id);
     CRM_Core_Error::debug_log_message("Calling create_wp_campaign.... Params title: {$pcp->title}, contact_id: {$pcp->contact_id}, pcp_id: {$pcp->id} ");
     // add attachments as needed
     CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_pcp', $pcp->id);
     $pageStatus = isset($this->_pageId) ? ts('updated') : ts('created');
     $statusId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcp->id, 'status_id');
     //send notification of PCP create/update.
     $pcpParams = array('entity_table' => $entity_table, 'entity_id' => $pcp->page_id);
     $notifyParams = array();
     $notifyStatus = "";
     CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $pcpParams, $notifyParams, array('notify_email'));
     if ($emails = $pcpBlock->notify_email) {
         $this->assign('pcpTitle', $pcp->title);
         if ($this->_pageId) {
             $this->assign('mode', 'Update');
         } else {
             $this->assign('mode', 'Add');
         }
         $pcpStatus = CRM_Core_OptionGroup::getLabel('pcp_status', $statusId);
         $this->assign('pcpStatus', $pcpStatus);
         $this->assign('pcpId', $pcp->id);
         $supporterUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$pcp->contact_id}", TRUE, NULL, FALSE, FALSE);
         $this->assign('supporterUrl', $supporterUrl);
         $supporterName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $pcp->contact_id, 'display_name');
         $this->assign('supporterName', $supporterName);
         if ($this->_component == 'contribute') {
             $pageUrl = CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpBlock->entity_id}", TRUE, NULL, FALSE, TRUE);
             $contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $pcpBlock->entity_id, 'title');
         } elseif ($this->_component == 'event') {
             $pageUrl = CRM_Utils_System::url('civicrm/event', "reset=1&id={$pcpBlock->entity_id}", TRUE, NULL, FALSE, TRUE);
             $contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $pcpBlock->entity_id, 'title');
         }
         $this->assign('contribPageUrl', $pageUrl);
         $this->assign('contribPageTitle', $contribPageTitle);
         $managePCPUrl = CRM_Utils_System::url('civicrm/admin/pcp', "reset=1", TRUE, NULL, FALSE, FALSE);
         $this->assign('managePCPUrl', $managePCPUrl);
         //get the default domain email address.
         list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
         if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') {
             $fixUrl = CRM_Utils_System::url('civicrm/admin/domain', 'action=update&reset=1');
             CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl)));
         }
         //if more than one email present for PCP notification ,
         //first email take it as To and other as CC and First email
         //address should be sent in users email receipt for
         //support purpose.
         $emailArray = explode(',', $emails);
         $to = $emailArray[0];
         unset($emailArray[0]);
         $cc = implode(',', $emailArray);
         list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'pcp_notify', 'contactId' => $contactID, 'from' => "{$domainEmailName} <{$domainEmailAddress}>", 'toEmail' => $to, 'cc' => $cc));
         if ($sent) {
             $notifyStatus = ts('A notification email has been sent to the site administrator.');
         }
     }
     CRM_Core_BAO_File::processAttachment($params, 'civicrm_pcp', $pcp->id);
     // send email notification to supporter, if initial setup / add mode.
     if (!$this->_pageId) {
         CRM_PCP_BAO_PCP::sendStatusUpdate($pcp->id, $statusId, TRUE, $this->_component);
         if ($approvalMessage && CRM_Utils_Array::value('status_id', $params) == 1) {
             $notifyStatus .= ts(' You will receive a second email as soon as the review process is complete.');
         }
     }
     //check if pcp created by anonymous user
     $anonymousPCP = 0;
     if (!$session->get('userID')) {
         $anonymousPCP = 1;
     }
     CRM_Core_Session::setStatus(ts("Your Personal Campaign Page has been %1 %2 %3", array(1 => $pageStatus, 2 => $approvalMessage, 3 => $notifyStatus)), '', 'info');
     if (!$this->_pageId) {
         $session->pushUserContext(CRM_Utils_System::url('civicrm/pcp/info', "reset=1&id={$pcp->id}&ap={$anonymousPCP}"));
     } elseif ($this->_context == 'dashboard') {
         $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/pcp', 'reset=1'));
     }
 }
Exemple #4
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 static function beginPostProcess(&$form, &$params)
 {
     if ($form->_context == 'caseActivity') {
         return;
     }
     // set the contact, when contact is selected
     if (isset($params['contact_select_id']) && CRM_Utils_Array::value(1, $params['contact_select_id'])) {
         $params['contact_id'] = $params['contact_select_id'][1];
         $form->_currentlyViewedContactId = $params['contact_id'];
     } elseif ($form->_allowMultiClient && $form->_context != 'case') {
         $clients = explode(',', $params['contact'][1]);
         $form->_currentlyViewedContactId = $clients[0];
     }
     // for open case start date should be set to current date
     $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
     $caseStatus = CRM_Case_PseudoConstant::caseStatus('name');
     // for resolved case the end date should set to now
     if ($params['status_id'] == array_search('Closed', $caseStatus)) {
         $params['end_date'] = $params['now'];
     }
     // rename activity_location param to the correct column name for activity DAO
     $params['location'] = CRM_Utils_Array::value('activity_location', $params);
     // Add attachments
     CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $form->_activityId);
 }
 /**
  * Process the form after the input has been submitted and validated.
  *
  * @param CRM_Core_Form $form
  */
 public static function postProcess(&$form)
 {
     if (count($form->_contactIds) > self::MAX_EMAILS_KILL_SWITCH) {
         CRM_Core_Error::fatal(ts('Please do not use this task to send a lot of emails (greater than %1). We recommend using CiviMail instead.', array(1 => self::MAX_EMAILS_KILL_SWITCH)));
     }
     // check and ensure that
     $formValues = $form->controller->exportValues($form->getName());
     $fromEmail = $formValues['fromEmailAddress'];
     $from = CRM_Utils_Array::value($fromEmail, $form->_emails);
     $subject = $formValues['subject'];
     // CRM-13378: Append CC and BCC information at the end of Activity Details and format cc and bcc fields
     $elements = array('cc_id', 'bcc_id');
     $additionalDetails = NULL;
     $ccValues = $bccValues = array();
     foreach ($elements as $element) {
         if (!empty($formValues[$element])) {
             $allEmails = explode(',', $formValues[$element]);
             foreach ($allEmails as $value) {
                 list($contactId, $email) = explode('::', $value);
                 $contactURL = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$contactId}", TRUE);
                 switch ($element) {
                     case 'cc_id':
                         $ccValues['email'][] = '"' . $form->_contactDetails[$contactId]['sort_name'] . '" <' . $email . '>';
                         $ccValues['details'][] = "<a href='{$contactURL}'>" . $form->_contactDetails[$contactId]['display_name'] . "</a>";
                         break;
                     case 'bcc_id':
                         $bccValues['email'][] = '"' . $form->_contactDetails[$contactId]['sort_name'] . '" <' . $email . '>';
                         $bccValues['details'][] = "<a href='{$contactURL}'>" . $form->_contactDetails[$contactId]['display_name'] . "</a>";
                         break;
                 }
             }
         }
     }
     $cc = $bcc = '';
     if (!empty($ccValues)) {
         $cc = implode(',', $ccValues['email']);
         $additionalDetails .= "\ncc : " . implode(", ", $ccValues['details']);
     }
     if (!empty($bccValues)) {
         $bcc = implode(',', $bccValues['email']);
         $additionalDetails .= "\nbcc : " . implode(", ", $bccValues['details']);
     }
     // CRM-5916: prepend case id hash to CiviCase-originating emails’ subjects
     if (isset($form->_caseId) && is_numeric($form->_caseId)) {
         $hash = substr(sha1(CIVICRM_SITE_KEY . $form->_caseId), 0, 7);
         $subject = "[case #{$hash}] {$subject}";
     }
     // process message template
     if (!empty($formValues['saveTemplate']) || !empty($formValues['updateTemplate'])) {
         $messageTemplate = array('msg_text' => $formValues['text_message'], 'msg_html' => $formValues['html_message'], 'msg_subject' => $formValues['subject'], 'is_active' => TRUE);
         if (!empty($formValues['saveTemplate'])) {
             $messageTemplate['msg_title'] = $formValues['saveTemplateName'];
             CRM_Core_BAO_MessageTemplate::add($messageTemplate);
         }
         if (!empty($formValues['template']) && !empty($formValues['updateTemplate'])) {
             $messageTemplate['id'] = $formValues['template'];
             unset($messageTemplate['msg_title']);
             CRM_Core_BAO_MessageTemplate::add($messageTemplate);
         }
     }
     $attachments = array();
     CRM_Core_BAO_File::formatAttachment($formValues, $attachments, NULL, NULL);
     // format contact details array to handle multiple emails from same contact
     $formattedContactDetails = array();
     $tempEmails = array();
     foreach ($form->_contactIds as $key => $contactId) {
         // if we dont have details on this contactID, we should ignore
         // potentially this is due to the contact not wanting to receive email
         if (!isset($form->_contactDetails[$contactId])) {
             continue;
         }
         $email = $form->_toContactEmails[$key];
         // prevent duplicate emails if same email address is selected CRM-4067
         // we should allow same emails for different contacts
         $emailKey = "{$contactId}::{$email}";
         if (!in_array($emailKey, $tempEmails)) {
             $tempEmails[] = $emailKey;
             $details = $form->_contactDetails[$contactId];
             $details['email'] = $email;
             unset($details['email_id']);
             $formattedContactDetails[] = $details;
         }
     }
     // send the mail
     list($sent, $activityId) = CRM_Activity_BAO_Activity::sendEmail($formattedContactDetails, $subject, $formValues['text_message'], $formValues['html_message'], NULL, NULL, $from, $attachments, $cc, $bcc, array_keys($form->_toContactDetails), $additionalDetails);
     $followupStatus = '';
     if ($sent) {
         $followupActivity = NULL;
         if (!empty($formValues['followup_activity_type_id'])) {
             $params['followup_activity_type_id'] = $formValues['followup_activity_type_id'];
             $params['followup_activity_subject'] = $formValues['followup_activity_subject'];
             $params['followup_date'] = $formValues['followup_date'];
             $params['followup_date_time'] = $formValues['followup_date_time'];
             $params['target_contact_id'] = $form->_contactIds;
             $params['followup_assignee_contact_id'] = explode(',', $formValues['followup_assignee_contact_id']);
             $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activityId, $params);
             $followupStatus = ts('A followup activity has been scheduled.');
             if (Civi::settings()->get('activity_assignee_notification')) {
                 if ($followupActivity) {
                     $mailToFollowupContacts = array();
                     $assignee = array($followupActivity->id);
                     $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($assignee, TRUE, FALSE);
                     foreach ($assigneeContacts as $values) {
                         $mailToFollowupContacts[$values['email']] = $values;
                     }
                     $sentFollowup = CRM_Activity_BAO_Activity::sendToAssignee($followupActivity, $mailToFollowupContacts);
                     if ($sentFollowup) {
                         $followupStatus .= '<br />' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s).");
                     }
                 }
             }
         }
         $count_success = count($form->_toContactDetails);
         CRM_Core_Session::setStatus(ts('One message was sent successfully. ', array('plural' => '%count messages were sent successfully. ', 'count' => $count_success)) . $followupStatus, ts('Message Sent', array('plural' => 'Messages Sent', 'count' => $count_success)), 'success');
     }
     // Display the name and number of contacts for those email is not sent.
     // php 5.4 throws out a notice since the values of these below arrays are arrays.
     // the behavior is not documented in the php manual, but it does the right thing
     // suppressing the notices to get things in good shape going forward
     $emailsNotSent = @array_diff_assoc($form->_allContactDetails, $form->_contactDetails);
     if ($emailsNotSent) {
         $not_sent = array();
         foreach ($emailsNotSent as $contactId => $values) {
             $displayName = $values['display_name'];
             $email = $values['email'];
             $contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$contactId}");
             $not_sent[] = "<a href='{$contactViewUrl}' title='{$email}'>{$displayName}</a>" . ($values['on_hold'] ? '(' . ts('on hold') . ')' : '');
         }
         $status = '(' . ts('because no email address on file or communication preferences specify DO NOT EMAIL or Contact is deceased or Primary email address is On Hold') . ')<ul><li>' . implode('</li><li>', $not_sent) . '</li></ul>';
         CRM_Core_Session::setStatus($status, ts('One Message Not Sent', array('count' => count($emailsNotSent), 'plural' => '%count Messages Not Sent')), 'info');
     }
     if (isset($form->_caseId)) {
         // if case-id is found in the url, create case activity record
         $cases = explode(',', $form->_caseId);
         foreach ($cases as $key => $val) {
             if (is_numeric($val)) {
                 $caseParams = array('activity_id' => $activityId, 'case_id' => $val);
                 CRM_Case_BAO_Case::processCaseActivity($caseParams);
             }
         }
     }
 }
Exemple #6
0
 public function postProcess()
 {
     $params = $ids = array();
     $uploadParams = array('header_id', 'footer_id', 'subject', 'from_name', 'from_email', 'override_verp');
     $fileType = array('textFile', 'htmlFile');
     $formValues = $this->controller->exportValues($this->_name);
     foreach ($uploadParams as $key) {
         if (CRM_Utils_Array::value($key, $formValues) || in_array($key, array('header_id', 'footer_id'))) {
             $params[$key] = $formValues[$key];
             $this->set($key, $formValues[$key]);
         }
     }
     if (!$formValues['upload_type']) {
         foreach ($fileType as $key) {
             $contents = null;
             if (isset($formValues[$key]) && !empty($formValues[$key])) {
                 $contents = file_get_contents($formValues[$key]['name']);
                 $this->set($key, $formValues[$key]['name']);
             }
             if ($contents) {
                 $params['body_' . substr($key, 0, 4)] = $contents;
             } else {
                 $params['body_' . substr($key, 0, 4)] = 'NULL';
             }
         }
     } else {
         $text_message = $formValues['text_message'];
         $params['body_text'] = $text_message;
         $this->set('textFile', $params['body_text']);
         $this->set('text_message', $params['body_text']);
         $html_message = $formValues['html_message'];
         // dojo editor does some html conversion when tokens are
         // inserted as links. Hence token replacement fails.
         // this is hack to revert html conversion for { to %7B and
         // } to %7D by dojo editor
         $html_message = str_replace('%7B', '{', str_replace('%7D', '}', $html_message));
         $params['body_html'] = $html_message;
         $this->set('htmlFile', $params['body_html']);
         $this->set('html_message', $params['body_html']);
     }
     $params['name'] = $this->get('name');
     $session =& CRM_Core_Session::singleton();
     $params['contact_id'] = $session->get('userID');
     $composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName');
     $msgTemplate = null;
     //mail template is composed
     if ($formValues['upload_type']) {
         foreach ($composeFields as $key) {
             if (CRM_Utils_Array::value($key, $formValues)) {
                 $composeParams[$key] = $formValues[$key];
                 $this->set($key, $formValues[$key]);
             }
         }
         if (CRM_Utils_Array::value('updateTemplate', $composeParams)) {
             $templateParams = array('msg_text' => $text_message, 'msg_html' => $html_message, 'msg_subject' => $params['subject'], 'is_active' => true);
             $templateParams['id'] = $formValues['template'];
             $msgTemplate = CRM_Core_BAO_MessageTemplates::add($templateParams);
         }
         if (CRM_Utils_Array::value('saveTemplate', $composeParams)) {
             $templateParams = array('msg_text' => $text_message, 'msg_html' => $html_message, 'msg_subject' => $params['subject'], 'is_active' => true);
             $templateParams['msg_title'] = $composeParams['saveTemplateName'];
             $msgTemplate = CRM_Core_BAO_MessageTemplates::add($templateParams);
         }
         if (isset($msgTemplate->id)) {
             $params['msg_template_id'] = $msgTemplate->id;
         } else {
             $params['msg_template_id'] = CRM_Utils_Array::value('template', $formValues);
         }
         $this->set('template', $params['msg_template_id']);
     }
     CRM_Core_BAO_File::formatAttachment($formValues, $params, 'civicrm_mailing', $this->_mailingID);
     $ids['mailing_id'] = $this->_mailingID;
     //handle mailing from name & address.
     $formEmailAddress = CRM_Utils_Array::value($formValues['from_email_address'], CRM_Core_PseudoConstant::fromEmailAddress("from_email_address"));
     //get the from email address
     require_once 'CRM/Utils/Mail.php';
     $params['from_email'] = CRM_Utils_Mail::pluckEmailFromHeader($formEmailAddress);
     //get the from Name
     $params['from_name'] = CRM_Utils_Array::value(1, explode('"', $formEmailAddress));
     /* Build the mailing object */
     require_once 'CRM/Mailing/BAO/Mailing.php';
     CRM_Mailing_BAO_Mailing::create($params, $ids);
     if ($this->_submitValues['_qf_Upload_upload'] == 'Save & Continue Later') {
         //when user perform mailing from search context
         //redirect it to search result CRM-3711.
         $ssID = $this->get('ssID');
         $context = $this->get('context');
         if ($ssID && $context == 'search') {
             if ($this->_action == CRM_Core_Action::BASIC) {
                 $fragment = 'search';
             } else {
                 if ($this->_action == CRM_Core_Action::PROFILE) {
                     $fragment = 'search/builder';
                 } else {
                     if ($this->_action == CRM_Core_Action::ADVANCED) {
                         $fragment = 'search/advanced';
                     } else {
                         $fragment = 'search/custom';
                     }
                 }
             }
             $session =& CRM_Core_Session::singleton();
             $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             $status = ts("Your mailing has been saved. You can continue later by clicking the 'Continue' action to resume working on it.<br /> From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
             CRM_Core_Session::setStatus($status);
             //replace user context to search.
             $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, "force=1&reset=1&ssID={$ssID}");
             CRM_Utils_System::redirect($url);
         } else {
             $status = ts("Your mailing has been saved. Click the 'Continue' action to resume working on it.");
             CRM_Core_Session::setStatus($status);
             $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             CRM_Utils_System::redirect($url);
         }
     }
 }
Exemple #7
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 static function postProcess(&$form)
 {
     if (count($form->_contactIds) > self::MAX_EMAILS_KILL_SWITCH) {
         CRM_Core_Error::fatal(ts('Please do not use this task to send a lot of emails (greater than %1). We recommend using CiviMail instead.', array(1 => self::MAX_EMAILS_KILL_SWITCH)));
     }
     // check and ensure that
     $formValues = $form->controller->exportValues($form->getName());
     $fromEmail = $formValues['fromEmailAddress'];
     $from = CRM_Utils_Array::value($fromEmail, $form->_fromEmails);
     $cc = CRM_Utils_Array::value('cc_id', $formValues);
     $bcc = CRM_Utils_Array::value('bcc_id', $formValues);
     $subject = $formValues['subject'];
     // process message template
     require_once 'CRM/Core/BAO/MessageTemplates.php';
     if (CRM_Utils_Array::value('saveTemplate', $formValues) || CRM_Utils_Array::value('updateTemplate', $formValues)) {
         $messageTemplate = array('msg_text' => $formValues['text_message'], 'msg_html' => $formValues['html_message'], 'msg_subject' => $formValues['subject'], 'is_active' => true);
         if ($formValues['saveTemplate']) {
             $messageTemplate['msg_title'] = $formValues['saveTemplateName'];
             CRM_Core_BAO_MessageTemplates::add($messageTemplate);
         }
         if ($formValues['template'] && $formValues['updateTemplate']) {
             $messageTemplate['id'] = $formValues['template'];
             unset($messageTemplate['msg_title']);
             CRM_Core_BAO_MessageTemplates::add($messageTemplate);
         }
     }
     $attachments = array();
     CRM_Core_BAO_File::formatAttachment($formValues, $attachments, null, null);
     // format contact details array to handle multiple emails from same contact
     $formattedContactDetails = array();
     $tempEmails = array();
     foreach ($form->_contactIds as $key => $contactId) {
         $email = $form->_toContactEmails[$key];
         // prevent duplicate emails if same email address is selected CRM-4067
         // we should allow same emails for different contacts
         $emailKey = "{$contactId}::{$email}";
         if (!in_array($emailKey, $tempEmails)) {
             $tempEmails[] = $emailKey;
             $details = $form->_contactDetails[$contactId];
             $details['email'] = $email;
             unset($details['email_id']);
             $formattedContactDetails[] = $details;
         }
     }
     // send the mail
     require_once 'CRM/Activity/BAO/Activity.php';
     list($sent, $activityId) = CRM_Activity_BAO_Activity::sendEmail($formattedContactDetails, $subject, $formValues['text_message'], $formValues['html_message'], null, null, $from, $attachments, $cc, $bcc, array_keys($form->_contactDetails));
     if ($sent) {
         $status = array('', ts('Your message has been sent.'));
     }
     //Display the name and number of contacts for those email is not sent.
     $emailsNotSent = array_diff_assoc($form->_allContactDetails, $form->_contactDetails);
     if (!empty($emailsNotSent)) {
         $statusOnHold = '';
         $statusDisplay = ts('Email not sent to contact(s) (no email address on file or communication preferences specify DO NOT EMAIL or Contact is deceased or Primary email address is On Hold): %1', array(1 => count($emailsNotSent))) . '<br />' . ts('Details') . ': ';
         foreach ($emailsNotSent as $contactId => $values) {
             $displayName = $values['display_name'];
             $email = $values['email'];
             $contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$contactId}");
             $statusDisplay .= "<a href='{$contactViewUrl}'>{$displayName}</a>, ";
             // build separate status for on hold messages
             if ($values['on_hold']) {
                 $statusOnHold .= ts('Email was not sent to %1 because primary email address (%2) is On Hold.', array(1 => "<a href='{$contactViewUrl}'>{$displayName}</a>", 2 => "<strong>{$email}</strong>")) . '<br />';
             }
         }
         $status[] = $statusDisplay;
     }
     if ($form->_caseId) {
         // if case-id is found in the url, create case activity record
         $caseParams = array('activity_id' => $activityId, 'case_id' => $form->_caseId);
         require_once 'CRM/Case/BAO/Case.php';
         CRM_Case_BAO_Case::processCaseActivity($caseParams);
     }
     if (strlen($statusOnHold)) {
         $status[] = $statusOnHold;
     }
     CRM_Core_Session::setStatus($status);
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Grant_BAO_Grant::del($this->_id);
         return;
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $ids['grant_id'] = $this->_id;
     }
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     if (empty($params['grant_report_received'])) {
         $params['grant_report_received'] = "null";
     }
     // set the contact, when contact is selected
     if ($this->_context == 'standalone') {
         $this->_contactID = $params['contact_id'];
     }
     $params['contact_id'] = $this->_contactID;
     $ids['note'] = array();
     if ($this->_noteId) {
         $ids['note']['id'] = $this->_noteId;
     }
     // build custom data getFields array
     $customFieldsGrantType = CRM_Core_BAO_CustomField::getFields('Grant', FALSE, FALSE, CRM_Utils_Array::value('grant_type_id', $params));
     $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsGrantType, CRM_Core_BAO_CustomField::getFields('Grant', FALSE, FALSE, NULL, NULL, TRUE));
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Grant');
     // add attachments as needed
     CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_grant', $this->_id);
     $grant = CRM_Grant_BAO_Grant::create($params, $ids);
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($this->_context == 'standalone') {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/grant/add', 'reset=1&action=add&context=standalone'));
         } else {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactID}&selectedChild=grant"));
         }
     } elseif ($buttonName == $this->getButtonName('upload', 'new')) {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/grant', "reset=1&action=add&context=grant&cid={$this->_contactID}"));
     }
 }
 function updateTemplateOptions()
 {
     // Update the templates and upload options
     $params = $ids = array();
     $uploadParams = array('header_id', 'footer_id', 'subject', 'from_name', 'from_email');
     $fileType = array('textFile', 'htmlFile');
     $formValues = $this->controller->exportValues($this->_name);
     foreach ($uploadParams as $key) {
         if (CRM_Utils_Array::value($key, $formValues) || in_array($key, array('header_id', 'footer_id'))) {
             $params[$key] = $formValues[$key];
             $this->set($key, $formValues[$key]);
         }
     }
     $text_message = $formValues['text_message'];
     $params['body_text'] = $text_message;
     $this->set('textFile', $params['body_text']);
     $this->set('text_message', $params['body_text']);
     $html_message = $formValues['html_message'];
     // dojo editor does some html conversion when tokens are
     // inserted as links. Hence token replacement fails.
     // this is hack to revert html conversion for { to %7B and
     // } to %7D by dojo editor
     $html_message = str_replace('%7B', '{', str_replace('%7D', '}', $html_message));
     $params['body_html'] = $html_message;
     $this->set('htmlFile', $params['body_html']);
     $this->set('html_message', $params['body_html']);
     $params['name'] = $this->get('name');
     $session = CRM_Core_Session::singleton();
     $params['contact_id'] = $session->get('userID');
     $composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName');
     CRM_Core_BAO_File::formatAttachment($formValues, $params, 'civicrm_mailing', $this->get('mailing_id'));
     $ids['mailing_id'] = $this->get('mailing_id');
     //set msg_template_id
     $params['msg_template_id'] = CRM_Utils_Array::value('template', $formValues);
     $this->set('template', $params['msg_template_id']);
     //handle mailing from name & address.
     $fromEmailAddress = CRM_Utils_Array::value($formValues['from_email_address'], CRM_Core_OptionGroup::values('from_email_address'));
     //get the from email address
     $params['from_email'] = CRM_Utils_Mail::pluckEmailFromHeader($fromEmailAddress);
     //get the from Name
     $params['from_name'] = CRM_Utils_Array::value(1, explode('"', $fromEmailAddress));
     //Add Reply-To to headers
     if (CRM_Utils_Array::value('reply_to_address', $formValues)) {
         $replyToEmail = CRM_Core_OptionGroup::values('from_email_address');
         $params['replyto_email'] = CRM_Utils_Array::value($formValues['reply_to_address'], $replyToEmail);
     }
     /* Build the mailing object */
     CRM_Mailing_BAO_Mailing::create($params, $ids);
 }
Exemple #10
0
 /**
  * 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);
 }
Exemple #11
0
 /**
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     $session = CRM_Core_Session::singleton();
     $params['contact_id'] = $session->get('userID');
     if ($params['parent_id']) {
         $params['entity_table'] = 'civicrm_note';
         $params['entity_id'] = $params['parent_id'];
     } else {
         $params['entity_table'] = $this->_entityTable;
         $params['entity_id'] = $this->_entityId;
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_Note::del($this->_id);
         return;
     }
     $params['id'] = null;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
     }
     // add attachments as needed
     CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_note', $params['id']);
     $ids = array();
     $note = CRM_Core_BAO_Note::add($params, $ids);
     CRM_Core_Session::setStatus(ts('Your Note has been saved.'), ts('Saved'), 'success');
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 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."), ts('Record Deleted'), 'success');
         return;
     }
     // store the submitted values in an array
     if (!$params) {
         $params = $this->controller->exportValues($this->_name);
     }
     //set activity type id
     if (empty($params['activity_type_id'])) {
         $params['activity_type_id'] = $this->_activityTypeId;
     }
     if (!empty($params['hidden_custom']) && !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']);
     // format with contact (target contact) values
     if (isset($params['contact'][1])) {
         $params['target_contact_id'] = explode(',', $params['contact'][1]);
     } else {
         $params['target_contact_id'] = array();
     }
     // assigning formated value to related variable
     if (!empty($params['assignee_contact_id'])) {
         $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']);
     } else {
         $params['assignee_contact_id'] = array();
     }
     // civicrm-10043 - 14/12/13
     if (!empty($params['followup_assignee_contact_id'])) {
         $params['followup_assignee_contact_id'] = explode(',', $params['followup_assignee_contact_id']);
     } else {
         $params['followup_assignee_contact_id'] = array();
     }
     // get ids for associated contacts
     if (!$params['source_contact_id']) {
         $params['source_contact_id'] = $this->_currentUserId;
     }
     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;
     }
     $activity = array();
     if (!empty($params['is_multi_activity']) && !CRM_Utils_Array::crmIsEmptyArray($params['target_contact_id'])) {
         $targetContacts = $params['target_contact_id'];
         foreach ($targetContacts as $targetContactId) {
             $params['target_contact_id'] = array($targetContactId);
             // save activity
             $activity[] = $this->processActivity($params);
         }
     } else {
         // save activity
         $activity = $this->processActivity($params);
     }
     return array('activity' => $activity);
 }
Exemple #13
0
 /**
  * function to add the auction
  *
  * @param array $params reference array contains the values submitted by the form
  *
  * @access public
  * @static
  *
  * @return object
  */
 static function add(&$params)
 {
     require_once 'CRM/Utils/Hook.php';
     if (!empty($params['id'])) {
         CRM_Utils_Hook::pre('edit', 'Auction_Item', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Auction_Item', NULL, $params);
     }
     $auction = new CRM_Auction_DAO_Item();
     $auction->copyValues($params);
     $auction->save();
     // add attachments as needed
     CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_auction_item', $auction->id);
     // add attachments as needed
     CRM_Core_BAO_File::processAttachment($params, 'civicrm_auction_item', $auction->id);
     if (!empty($params['id'])) {
         CRM_Utils_Hook::post('edit', 'Auction_Item', $auction->id, $auction);
     } else {
         CRM_Utils_Hook::post('create', 'Auction_Item', $auction->id, $auction);
     }
     return $result;
 }
 /**
  * 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 postProcess()
 {
     $params = $ids = array();
     $uploadParams = array('header_id', 'footer_id', 'subject', 'from_name', 'from_email');
     $fileType = array('textFile', 'htmlFile');
     $formValues = $this->controller->exportValues($this->_name);
     foreach ($uploadParams as $key) {
         if (!empty($formValues[$key]) || in_array($key, array('header_id', 'footer_id'))) {
             $params[$key] = $formValues[$key];
             $this->set($key, $formValues[$key]);
         }
     }
     if (!$formValues['upload_type']) {
         foreach ($fileType as $key) {
             $contents = NULL;
             if (isset($formValues[$key]) && !empty($formValues[$key])) {
                 $contents = file_get_contents($formValues[$key]['name']);
                 $this->set($key, $formValues[$key]['name']);
             }
             if ($contents) {
                 $params['body_' . substr($key, 0, 4)] = $contents;
             } else {
                 $params['body_' . substr($key, 0, 4)] = 'NULL';
             }
         }
     } else {
         $text_message = $formValues['text_message'];
         $params['body_text'] = $text_message;
         $this->set('textFile', $params['body_text']);
         $this->set('text_message', $params['body_text']);
         $html_message = $formValues['html_message'];
         // dojo editor does some html conversion when tokens are
         // inserted as links. Hence token replacement fails.
         // this is hack to revert html conversion for { to %7B and
         // } to %7D by dojo editor
         $html_message = str_replace('%7B', '{', str_replace('%7D', '}', $html_message));
         $params['body_html'] = $html_message;
         $this->set('htmlFile', $params['body_html']);
         $this->set('html_message', $params['body_html']);
     }
     $params['name'] = $this->get('name');
     $session = CRM_Core_Session::singleton();
     $params['contact_id'] = $session->get('userID');
     $composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName');
     $msgTemplate = NULL;
     //mail template is composed
     if ($formValues['upload_type']) {
         $composeParams = array();
         foreach ($composeFields as $key) {
             if (!empty($formValues[$key])) {
                 $composeParams[$key] = $formValues[$key];
                 $this->set($key, $formValues[$key]);
             }
         }
         if (!empty($composeParams['updateTemplate'])) {
             $templateParams = array('msg_text' => $text_message, 'msg_html' => $html_message, 'msg_subject' => $params['subject'], 'is_active' => TRUE);
             $templateParams['id'] = $formValues['template'];
             $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
         }
         if (!empty($composeParams['saveTemplate'])) {
             $templateParams = array('msg_text' => $text_message, 'msg_html' => $html_message, 'msg_subject' => $params['subject'], 'is_active' => TRUE);
             $templateParams['msg_title'] = $composeParams['saveTemplateName'];
             $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
         }
         if (isset($msgTemplate->id)) {
             $params['msg_template_id'] = $msgTemplate->id;
         } else {
             $params['msg_template_id'] = CRM_Utils_Array::value('template', $formValues);
         }
         $this->set('template', $params['msg_template_id']);
     }
     CRM_Core_BAO_File::formatAttachment($formValues, $params, 'civicrm_mailing', $this->_mailingID);
     $ids['mailing_id'] = $this->_mailingID;
     //handle mailing from name & address.
     $fromEmailAddress = CRM_Utils_Array::value($formValues['from_email_address'], CRM_Core_OptionGroup::values('from_email_address'));
     //get the from email address
     $params['from_email'] = CRM_Utils_Mail::pluckEmailFromHeader($fromEmailAddress);
     //get the from Name
     $params['from_name'] = CRM_Utils_Array::value(1, explode('"', $fromEmailAddress));
     //Add Reply-To to headers
     if (!empty($formValues['reply_to_address'])) {
         $replyToEmail = CRM_Core_OptionGroup::values('from_email_address');
         $params['replyto_email'] = CRM_Utils_Array::value($formValues['reply_to_address'], $replyToEmail);
     }
     /* Build the mailing object */
     CRM_Mailing_BAO_Mailing::create($params, $ids);
     if (isset($this->_submitValues['_qf_Upload_upload_save']) && $this->_submitValues['_qf_Upload_upload_save'] == 'Save & Continue Later') {
         //when user perform mailing from search context
         //redirect it to search result CRM-3711.
         $ssID = $this->get('ssID');
         if ($ssID && $this->_searchBasedMailing) {
             if ($this->_action == CRM_Core_Action::BASIC) {
                 $fragment = 'search';
             } elseif ($this->_action == CRM_Core_Action::PROFILE) {
                 $fragment = 'search/builder';
             } elseif ($this->_action == CRM_Core_Action::ADVANCED) {
                 $fragment = 'search/advanced';
             } else {
                 $fragment = 'search/custom';
             }
             $context = $this->get('context');
             if (!CRM_Contact_Form_Search::isSearchContext($context)) {
                 $context = 'search';
             }
             $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}";
             $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
             if (CRM_Utils_Rule::qfKey($qfKey)) {
                 $urlParams .= "&qfKey={$qfKey}";
             }
             $session = CRM_Core_Session::singleton();
             $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             $status = ts("You can continue later by clicking the 'Continue' action to resume working on it.<br />From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
             CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success');
             // Redirect user to search.
             $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
         } else {
             $status = ts("Click the 'Continue' action to resume working on it.");
             $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
         }
         CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success');
         return $this->controller->setDestination($url);
     }
 }
Exemple #16
0
 /** 
  * Function to process the form 
  * 
  * @access public 
  * @return None 
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues();
     $checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active');
     foreach ($checkBoxes as $key) {
         if (!isset($params[$key])) {
             $params[$key] = 0;
         }
     }
     $session =& CRM_Core_Session::singleton();
     $contactID = isset($this->_contactID) ? $this->_contactID : $session->get('userID');
     if (!$contactID) {
         $contactID = $this->get('contactID');
     }
     $params['contact_id'] = $contactID;
     $params['contribution_page_id'] = $this->get('contribution_page_id') ? $this->get('contribution_page_id') : $this->_contriPageId;
     $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
     $approval_needed = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCPBlock', $params['contribution_page_id'], 'is_approval_needed', 'entity_id');
     $approvalMessage = null;
     if ($this->get('action') & CRM_Core_Action::ADD) {
         $params['status_id'] = $approval_needed ? 1 : 2;
         $approvalMessage = $approval_needed ? ts('but requires administrator review before you can begin your fundraising efforts. You will receive an email confirmation shortly which includes a link to return to your fundraising page.') : ts('and is ready to use.');
     }
     $params['id'] = $this->_pageId;
     require_once 'CRM/Contribute/BAO/PCP.php';
     $pcp = CRM_Contribute_BAO_PCP::add($params, false);
     // add attachments as needed
     CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_pcp', $pcp->id);
     $pageStatus = isset($this->_pageId) ? ts('updated') : ts('created');
     $statusId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCP', $pcp->id, 'status_id');
     //send notification of PCP create/update.
     $pcpParams = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $pcp->contribution_page_id);
     $notifyParams = array();
     $notifyStatus = "";
     CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCPBlock', $pcpParams, $notifyParams, array('notify_email'));
     if ($emails = CRM_Utils_Array::value('notify_email', $notifyParams)) {
         $this->assign('pcpTitle', $pcp->title);
         if ($this->_pageId) {
             $this->assign('mode', 'Update');
         } else {
             $this->assign('mode', 'Add');
         }
         require_once 'CRM/Core/OptionGroup.php';
         $pcpStatus = CRM_Core_OptionGroup::getLabel('pcp_status', $statusId);
         $this->assign('pcpStatus', $pcpStatus);
         $this->assign('pcpId', $pcp->id);
         $supporterUrl = CRM_Utils_System::url("civicrm/contact/view", "reset=1&cid={$pcp->contact_id}", true, null, true, true);
         $this->assign('supporterUrl', $supporterUrl);
         $supporterName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $pcp->contact_id, 'display_name');
         $this->assign('supporterName', $supporterName);
         $contribPageUrl = CRM_Utils_System::url("civicrm/contribute/transact", "reset=1&id={$pcp->contribution_page_id}", true, null, true, true);
         $this->assign('contribPageUrl', $contribPageUrl);
         $contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $pcp->contribution_page_id, 'title');
         $this->assign('contribPageTitle', $contribPageTitle);
         $managePCPUrl = CRM_Utils_System::url("civicrm/admin/pcp", "reset=1", true, null, true, true);
         $this->assign('managePCPUrl', $managePCPUrl);
         //get the default domain email address.
         require_once 'CRM/Core/BAO/Domain.php';
         list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
         if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') {
             CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in Administer CiviCRM &raquo; Configure &raquo; Domain Information. The email address used may need to be a valid mail account with your email service provider.'));
         }
         //if more than one email present for PCP notification ,
         //first email take it as To and other as CC and First email
         //address should be sent in users email receipt for
         //support purpose.
         $emailArray = explode(',', $emails);
         $to = $emailArray[0];
         unset($emailArray[0]);
         $cc = implode(',', $emailArray);
         require_once 'CRM/Core/BAO/MessageTemplates.php';
         list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'pcp_notify', 'contactId' => $contactID, 'from' => "{$domainEmailName} <{$domainEmailAddress}>", 'toEmail' => $to, 'cc' => $cc));
         if ($sent) {
             $notifyStatus = ts('A notification email has been sent to the site administrator.');
         }
     }
     CRM_Core_BAO_File::processAttachment($params, 'civicrm_pcp', $pcp->id);
     // send email notification to supporter, if initial setup / add mode.
     if (!$this->_pageId) {
         CRM_Contribute_BAO_PCP::sendStatusUpdate($pcp->id, $statusId, true);
         if ($approvalMessage && CRM_Utils_Array::value('status_id', $params) == 1) {
             $notifyStatus .= ts(' You will receive a second email as soon as the review process is complete.');
         }
     }
     //check if pcp created by anonymous user
     $anonymousPCP = 0;
     if (!$session->get('userID')) {
         $anonymousPCP = 1;
     }
     CRM_Core_Session::setStatus(ts("Your Personal Campaign Page has been %1 %2 %3", array(1 => $pageStatus, 2 => $approvalMessage, 3 => $notifyStatus)));
     if (!$this->_pageId) {
         $session->pushUserContext(CRM_Utils_System::url('civicrm/contribute/pcp/info', "reset=1&id={$pcp->id}&ap={$anonymousPCP}"));
     }
 }
 /**
  * Process the form submission.
  *
  *
  * @param array $params
  * @return array|null
  */
 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."), ts('Record Deleted'), 'success');
         return NULL;
     }
     // store the submitted values in an array
     if (!$params) {
         $params = $this->controller->exportValues($this->_name);
     }
     // Set activity type id.
     if (empty($params['activity_type_id'])) {
         $params['activity_type_id'] = $this->_activityTypeId;
     }
     if (!empty($params['hidden_custom']) && !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, $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']);
     // format params as arrays
     foreach (array('target', 'assignee', 'followup_assignee') as $name) {
         if (!empty($params["{$name}_contact_id"])) {
             $params["{$name}_contact_id"] = explode(',', $params["{$name}_contact_id"]);
         } else {
             $params["{$name}_contact_id"] = array();
         }
     }
     // get ids for associated contacts
     if (!$params['source_contact_id']) {
         $params['source_contact_id'] = $this->_currentUserId;
     }
     if (isset($this->_activityId)) {
         $params['id'] = $this->_activityId;
     }
     // add attachments as needed
     CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId);
     $activity = array();
     if (!empty($params['is_multi_activity']) && !CRM_Utils_Array::crmIsEmptyArray($params['target_contact_id'])) {
         $targetContacts = $params['target_contact_id'];
         foreach ($targetContacts as $targetContactId) {
             $params['target_contact_id'] = array($targetContactId);
             // save activity
             $activity[] = $this->processActivity($params);
         }
     } else {
         // save activity
         $activity = $this->processActivity($params);
     }
     $activityIds = empty($this->_activityIds) ? array($this->_activityId) : $this->_activityIds;
     foreach ($activityIds as $activityId) {
         // set params for repeat configuration in create mode
         $params['entity_id'] = $activityId;
         $params['entity_table'] = 'civicrm_activity';
         if (!empty($params['entity_id']) && !empty($params['entity_table'])) {
             $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($params['entity_id'], $params['entity_table']);
             if ($checkParentExistsForThisId) {
                 $params['parent_entity_id'] = $checkParentExistsForThisId;
                 $scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, $params['entity_table']);
             } else {
                 $params['parent_entity_id'] = $params['entity_id'];
                 $scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($params['entity_id'], $params['entity_table']);
             }
             if (property_exists($scheduleReminderDetails, 'id')) {
                 $params['schedule_reminder_id'] = $scheduleReminderDetails->id;
             }
         }
         $params['dateColumns'] = array('activity_date_time');
         // Set default repetition start if it was not provided.
         if (empty($params['repetition_start_date'])) {
             $params['repetition_start_date'] = $params['activity_date_time'];
         }
         // unset activity id
         unset($params['id']);
         $linkedEntities = array(array('table' => 'civicrm_activity_contact', 'findCriteria' => array('activity_id' => $activityId), 'linkedColumns' => array('activity_id'), 'isRecurringEntityRecord' => FALSE));
         CRM_Core_Form_RecurringEntity::postProcess($params, 'civicrm_activity', $linkedEntities);
     }
     return array('activity' => $activity);
 }
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     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.");
         }
         require_once 'CRM/Core/BAO/EntityTag.php';
         $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId);
         CRM_Core_BAO_EntityTag::del($tagParams);
         CRM_Core_Session::setStatus($statusMsg);
         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);
         return;
     }
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     if ($params['source_contact_id']) {
         $params['source_contact_id'] = $params['source_contact_qid'];
     }
     //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;
     require_once 'CRM/Case/XMLProcessor/Process.php';
     $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
     $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
     $this->assign('multiClient', $isMultiClient);
     $targetContacts = array($this->_currentlyViewedContactId);
     if (CRM_Utils_Array::value('hidden_target_contact', $params) && CRM_Utils_Array::value('target_contact_id', $params)) {
         $targetContacts = array_unique(explode(',', $params['target_contact_id']));
     }
     $params['target_contact_id'] = $targetContacts;
     // format activity custom data
     if (CRM_Utils_Array::value('hidden_custom', $params)) {
         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');
     }
     if (CRM_Utils_Array::value('assignee_contact_id', $params)) {
         $assineeContacts = explode(',', $params['assignee_contact_id']);
         $assineeContacts = array_unique($assineeContacts);
         unset($params['assignee_contact_id']);
     } else {
         $params['assignee_contact_id'] = $assineeContacts = 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);
         $params['case_id'] = $this->_caseId;
         // activity create/update
         $activity = CRM_Activity_BAO_Activity::create($params);
         // 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 (CRM_Utils_Array::value('original_id', $this->_defaults)) {
             $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);
         $newActParams['case_id'] = $this->_caseId;
         $activity = CRM_Activity_BAO_Activity::create($newActParams);
         // 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 (!CRM_Utils_Array::value('is_delete_attachment', $newActParams)) {
             CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $this->_activityId, 'civicrm_activity', $activity->id);
         }
         // copy back params to original var
         $params = $newActParams;
     }
     if ($activity->id) {
         // add tags if exists
         $tagParams = array();
         if (!empty($params['tag'])) {
             foreach ($params['tag'] as $tag) {
                 $tagParams[$tag] = 1;
             }
         }
         //save static tags
         require_once 'CRM/Core/BAO/EntityTag.php';
         CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id);
         //save free tags
         if (isset($params['taglist']) && !empty($params['taglist'])) {
             require_once 'CRM/Core/Form/Tag.php';
             CRM_Core_Form_Tag::postProcess($params['taglist'], $activity->id, 'civicrm_activity', $this);
         }
     }
     $params['assignee_contact_id'] = $assineeContacts;
     // update existing case record if needed
     $caseParams = $params;
     $caseParams['id'] = $this->_caseId;
     if (CRM_Utils_Array::value('case_type_id', $caseParams)) {
         $caseParams['case_type_id'] = CRM_Case_BAO_Case::VALUE_SEPERATOR . $caseParams['case_type_id'] . CRM_Case_BAO_Case::VALUE_SEPERATOR;
     }
     if (CRM_Utils_Array::value('case_status_id', $caseParams)) {
         $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' => $activity->id, 'case_id' => $this->_caseId);
     CRM_Case_BAO_Case::processCaseActivity($caseParams);
     // create activity assignee records
     $assigneeParams = array('activity_id' => $activity->id);
     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']);
         $activityId = isset($this->_activityId) ? $this->_activityId : $activity->id;
         $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityId);
         $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts);
         foreach ($params['assignee_contact_id'] as $key => $id) {
             $assigneeParams['assignee_contact_id'] = $id;
             CRM_Activity_BAO_Activity::createActivityAssignment($assigneeParams);
         }
         //modify assigne_contact as per newly assigned contact before sending copy. CRM-4509.
         $params['assignee_contact_id'] = $activityAssigned;
     }
     // 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');
     $config =& CRM_Core_Config::singleton();
     if ($config->activityAssigneeNotification) {
         $selectedContacts[] = 'assignee_contact_id';
     }
     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($activity->id, 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 $id => $dnc) {
                 if (isset($id) && array_key_exists($id, $this->_relatedContacts)) {
                     //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 sendig a copy of activity.
         $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id);
         $result = CRM_Case_BAO_Case::sendActivityCopy($this->_currentlyViewedContactId, $activity->id, $mailToContacts, $attachments, $this->_caseId);
         if (empty($result)) {
             $mailStatus = '';
         }
     } else {
         $mailStatus = '';
     }
     // 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);
         if ($followupActivity) {
             $caseParams = array('activity_id' => $followupActivity->id, 'case_id' => $this->_caseId);
             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)));
 }