Exemplo n.º 1
0
 /**
  * Add activity assignment.
  *
  * @param array  $params       (reference ) an assoc array of name/value pairs
  * @param array  $ids          (reference ) the array that holds all the db ids
  *
  * @return object activity type of object that is added
  * @access public
  *
  */
 public static function create(&$params)
 {
     $assignment = new CRM_Activity_BAO_ActivityContact();
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     $assignment->copyValues($params);
     $assignment->record_type_id = $assigneeID;
     return $assignment->save();
 }
 /**
  * Trigger a rule for this event
  *
  * @param $op
  * @param $objectName
  * @param $objectId
  * @param $objectRef
  */
 public function triggerEvent($op, $objectName, $objectId, $objectRef)
 {
     $eventData = $this->getEventDataFromPost($op, $objectName, $objectId, $objectRef);
     //trigger for activity event for every source_contact_id, target_contact_id and assignee_contact_id
     $activityContact = new CRM_Activity_BAO_ActivityContact();
     $activityContact->activity_id = $objectId;
     $activityContact->find();
     while ($activityContact->fetch()) {
         $data = array();
         CRM_Core_DAO::storeValues($activityContact, $data);
         $eventData->setEntityData('ActivityContact', $data);
         CRM_Civirules_Engine::triggerRule($this, clone $eventData);
     }
 }
Exemplo n.º 3
0
 /**
  * the initializer code, called before the processing
  *
  * @return void
  * @access public
  */
 function init()
 {
     $activityContact = CRM_Activity_BAO_ActivityContact::import();
     $activityTarget['target_contact_id'] = $activityContact['contact_id'];
     $fields = array_merge(CRM_Activity_BAO_Activity::importableFields(), $activityTarget);
     $fields = array_merge($fields, array('source_contact_id' => array('title' => ts('Source Contact'), 'headerPattern' => '/Source.Contact?/i'), 'activity_label' => array('title' => ts('Activity Type Label'), 'headerPattern' => '/(activity.)?type label?/i')));
     foreach ($fields as $name => $field) {
         $field['type'] = CRM_Utils_Array::value('type', $field, CRM_Utils_Type::T_INT);
         $field['dataPattern'] = CRM_Utils_Array::value('dataPattern', $field, '//');
         $field['headerPattern'] = CRM_Utils_Array::value('headerPattern', $field, '//');
         $this->addField($name, $field['title'], $field['type'], $field['headerPattern'], $field['dataPattern']);
     }
     $this->_newActivity = array();
     $this->setActiveFields($this->_mapperKeys);
     // FIXME: we should do this in one place together with Form/MapField.php
     $this->_contactIdIndex = -1;
     $this->_activityTypeIndex = -1;
     $this->_activityLabelIndex = -1;
     $this->_activityDateIndex = -1;
     $index = 0;
     foreach ($this->_mapperKeys as $key) {
         switch ($key) {
             case 'target_contact_id':
             case 'external_identifier':
                 $this->_contactIdIndex = $index;
                 break;
             case 'activity_label':
                 $this->_activityLabelIndex = $index;
                 break;
             case 'activity_type_id':
                 $this->_activityTypeIndex = $index;
                 break;
             case 'activity_date_time':
                 $this->_activityDateIndex = $index;
                 break;
         }
         $index++;
     }
 }
Exemplo n.º 4
0
 /**
  * Build the form object.
  *
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildQuickForm(&$form)
 {
     $toArray = array();
     $providers = CRM_SMS_BAO_Provider::getProviders(NULL, NULL, TRUE, 'is_default desc');
     $providerSelect = array();
     foreach ($providers as $provider) {
         $providerSelect[$provider['id']] = $provider['title'];
     }
     $suppressedSms = 0;
     //here we are getting logged in user id as array but we need target contact id. CRM-5988
     $cid = $form->get('cid');
     if ($cid) {
         $form->_contactIds = array($cid);
     }
     $to = $form->add('text', 'to', ts('To'), array('class' => 'huge'), TRUE);
     $form->add('text', 'activity_subject', ts('Name The SMS'), array('class' => 'huge'), TRUE);
     $toSetDefault = TRUE;
     if (property_exists($form, '_context') && $form->_context == 'standalone') {
         $toSetDefault = FALSE;
     }
     // when form is submitted recompute contactIds
     $allToSMS = array();
     if ($to->getValue()) {
         $allToPhone = explode(',', $to->getValue());
         $form->_contactIds = array();
         foreach ($allToPhone as $value) {
             list($contactId, $phone) = explode('::', $value);
             if ($contactId) {
                 $form->_contactIds[] = $contactId;
                 $form->_toContactPhone[] = $phone;
             }
         }
         $toSetDefault = TRUE;
     }
     //get the group of contacts as per selected by user in case of Find Activities
     if (!empty($form->_activityHolderIds)) {
         $extendTargetContacts = 0;
         $invalidActivity = 0;
         $validActivities = 0;
         foreach ($form->_activityHolderIds as $key => $id) {
             //valid activity check
             if (CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $id, 'subject', 'id') != self::RECIEVED_SMS_ACTIVITY_SUBJECT) {
                 $invalidActivity++;
                 continue;
             }
             $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
             $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
             //target contacts limit check
             $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $targetID));
             if (count($ids) > 1) {
                 $extendTargetContacts++;
                 continue;
             }
             $validActivities++;
             $form->_contactIds = empty($form->_contactIds) ? $ids : array_unique(array_merge($form->_contactIds, $ids));
         }
         if (!$validActivities) {
             $errorMess = "";
             if ($extendTargetContacts) {
                 $errorMess = ts('One selected activity consists of more than one target contact.', array('count' => $extendTargetContacts, 'plural' => '%count selected activities consist of more than one target contact.'));
             }
             if ($invalidActivity) {
                 $errorMess = $errorMess ? ' ' : '';
                 $errorMess .= ts('The selected activity is invalid.', array('count' => $invalidActivity, 'plural' => '%count selected activities are invalid.'));
             }
             CRM_Core_Error::statusBounce(ts("%1: SMS Reply will not be sent.", array(1 => $errorMess)));
         }
     }
     if (is_array($form->_contactIds) && !empty($form->_contactIds) && $toSetDefault) {
         $returnProperties = array('sort_name' => 1, 'phone' => 1, 'do_not_sms' => 1, 'is_deceased' => 1, 'display_name' => 1);
         list($form->_contactDetails) = CRM_Utils_Token::getTokenDetails($form->_contactIds, $returnProperties, FALSE, FALSE);
         // make a copy of all contact details
         $form->_allContactDetails = $form->_contactDetails;
         foreach ($form->_contactIds as $key => $contactId) {
             $value = $form->_contactDetails[$contactId];
             //to check if the phone type is "Mobile"
             $phoneTypes = CRM_Core_OptionGroup::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name');
             if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Form_Task_SMS') {
                 //to check for "if the contact id belongs to a specified activity type"
                 $actDetails = CRM_Activity_BAO_Activity::getContactActivity($contactId);
                 if (self::RECIEVED_SMS_ACTIVITY_SUBJECT != CRM_Utils_Array::retrieveValueRecursive($actDetails, 'subject')) {
                     $suppressedSms++;
                     unset($form->_contactDetails[$contactId]);
                     continue;
                 }
             }
             if (isset($value['phone_type_id']) && $value['phone_type_id'] != CRM_Utils_Array::value('Mobile', $phoneTypes) || $value['do_not_sms'] || empty($value['phone']) || !empty($value['is_deceased'])) {
                 //if phone is not primary check if non-primary phone is "Mobile"
                 if (!empty($value['phone']) && $value['phone_type_id'] != CRM_Utils_Array::value('Mobile', $phoneTypes) && empty($value['is_deceased'])) {
                     $filter = array('do_not_sms' => 0);
                     $contactPhones = CRM_Core_BAO_Phone::allPhones($contactId, FALSE, 'Mobile', $filter);
                     if (count($contactPhones) > 0) {
                         $mobilePhone = CRM_Utils_Array::retrieveValueRecursive($contactPhones, 'phone');
                         $form->_contactDetails[$contactId]['phone_id'] = CRM_Utils_Array::retrieveValueRecursive($contactPhones, 'id');
                         $form->_contactDetails[$contactId]['phone'] = $mobilePhone;
                         $form->_contactDetails[$contactId]['phone_type_id'] = CRM_Utils_Array::value('Mobile', $phoneTypes);
                     } else {
                         $suppressedSms++;
                         unset($form->_contactDetails[$contactId]);
                         continue;
                     }
                 } else {
                     $suppressedSms++;
                     unset($form->_contactDetails[$contactId]);
                     continue;
                 }
             }
             if (isset($mobilePhone)) {
                 $phone = $mobilePhone;
             } elseif (empty($form->_toContactPhone)) {
                 $phone = $value['phone'];
             } else {
                 $phone = CRM_Utils_Array::value($key, $form->_toContactPhone);
             }
             if ($phone) {
                 $toArray[] = array('text' => '"' . $value['sort_name'] . '" (' . $phone . ')', 'id' => "{$contactId}::{$phone}");
             }
         }
         if (empty($toArray)) {
             CRM_Core_Error::statusBounce(ts('Selected contact(s) do not have a valid Phone, or communication preferences specify DO NOT SMS, or they are deceased'));
         }
     }
     //activity related variables
     if (isset($invalidActivity)) {
         $form->assign('invalidActivity', $invalidActivity);
     }
     if (isset($extendTargetContacts)) {
         $form->assign('extendTargetContacts', $extendTargetContacts);
     }
     $form->assign('toContact', json_encode($toArray));
     $form->assign('suppressedSms', $suppressedSms);
     $form->assign('totalSelectedContacts', count($form->_contactIds));
     $form->add('select', 'sms_provider_id', ts('From'), $providerSelect, TRUE);
     CRM_Mailing_BAO_Mailing::commonCompose($form);
     if ($form->_single) {
         // also fix the user context stack
         if ($form->_context) {
             $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
         } else {
             $url = CRM_Utils_System::url('civicrm/contact/view', "&show=1&action=browse&cid={$form->_contactIds[0]}&selectedChild=activity");
         }
         $session = CRM_Core_Session::singleton();
         $session->replaceUserContext($url);
         $form->addDefaultButtons(ts('Send SMS'), 'upload', 'cancel');
     } else {
         $form->addDefaultButtons(ts('Send SMS'), 'upload');
     }
     $form->addFormRule(array('CRM_Contact_Form_Task_SMSCommon', 'formRule'), $form);
 }
Exemplo n.º 5
0
 /**
  * Function to get Case Activities
  *
  * @param int $caseID case id
  * @param array $params posted params
  * @param int $contactID contact id
  *
  * @param null $context
  * @param null $userID
  * @param null $type
  *
  * @return returns case activities
  *
  * @static
  */
 static function getCaseActivity($caseID, &$params, $contactID, $context = NULL, $userID = NULL, $type = NULL)
 {
     $values = array();
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     // CRM-5081 - formatting the dates to omit seconds.
     // Note the 00 in the date format string is needed otherwise later on it thinks scheduled ones are overdue.
     $select = "SELECT count(ca.id) as ismultiple, ca.id as id,\n                          ca.activity_type_id as type,\n                          ca.activity_type_id as activity_type_id,\n                          cc.sort_name as reporter,\n                          cc.id as reporter_id,\n                          acc.sort_name AS assignee,\n                          acc.id AS assignee_id,\n                          DATE_FORMAT(IF(ca.activity_date_time < NOW() AND ca.status_id=ov.value,\n                            ca.activity_date_time,\n                            DATE_ADD(NOW(), INTERVAL 1 YEAR)\n                          ), '%Y%m%d%H%i00') as overdue_date,\n                          DATE_FORMAT(ca.activity_date_time, '%Y%m%d%H%i00') as display_date,\n                          ca.status_id as status,\n                          ca.subject as subject,\n                          ca.is_deleted as deleted,\n                          ca.priority_id as priority,\n                          ca.weight as weight,\n                          GROUP_CONCAT(ef.file_id) as attachment_ids ";
     $from = "\n      FROM civicrm_case_activity cca\n                  INNER JOIN civicrm_activity ca ON ca.id = cca.activity_id\n                  INNER JOIN civicrm_activity_contact cac ON cac.activity_id = ca.id AND cac.record_type_id = {$sourceID}\n                  INNER JOIN civicrm_contact cc ON cc.id = cac.contact_id\n                  INNER JOIN civicrm_option_group cog ON cog.name = 'activity_type'\n                  INNER JOIN civicrm_option_value cov ON cov.option_group_id = cog.id\n                         AND cov.value = ca.activity_type_id AND cov.is_active = 1\n                  LEFT JOIN civicrm_entity_file ef on ef.entity_table = 'civicrm_activity'  AND ef.entity_id = ca.id\n                  LEFT OUTER JOIN civicrm_option_group og ON og.name = 'activity_status'\n                  LEFT OUTER JOIN civicrm_option_value ov ON ov.option_group_id=og.id AND ov.name = 'Scheduled'\n                  LEFT JOIN civicrm_activity_contact caa\n                                ON caa.activity_id = ca.id AND caa.record_type_id = {$assigneeID}\n                  LEFT JOIN civicrm_contact acc ON acc.id = caa.contact_id  ";
     $where = 'WHERE cca.case_id= %1
                 AND ca.is_current_revision = 1';
     if (!empty($params['reporter_id'])) {
         $where .= " AND cac.contact_id = " . CRM_Utils_Type::escape($params['reporter_id'], 'Integer');
     }
     if (!empty($params['status_id'])) {
         $where .= " AND ca.status_id = " . CRM_Utils_Type::escape($params['status_id'], 'Integer');
     }
     if (!empty($params['activity_deleted'])) {
         $where .= " AND ca.is_deleted = 1";
     } else {
         $where .= " AND ca.is_deleted = 0";
     }
     if (!empty($params['activity_type_id'])) {
         $where .= " AND ca.activity_type_id = " . CRM_Utils_Type::escape($params['activity_type_id'], 'Integer');
     }
     if (!empty($params['activity_date_low'])) {
         $fromActivityDate = CRM_Utils_Type::escape(CRM_Utils_Date::processDate($params['activity_date_low']), 'Date');
     }
     if (!empty($params['activity_date_high'])) {
         $toActivityDate = CRM_Utils_Type::escape(CRM_Utils_Date::processDate($params['activity_date_high']), 'Date');
         $toActivityDate = $toActivityDate ? $toActivityDate + 235959 : NULL;
     }
     if (!empty($fromActivityDate)) {
         $where .= " AND ca.activity_date_time >= '{$fromActivityDate}'";
     }
     if (!empty($toActivityDate)) {
         $where .= " AND ca.activity_date_time <= '{$toActivityDate}'";
     }
     // hack to handle to allow initial sorting to be done by query
     if (CRM_Utils_Array::value('sortname', $params) == 'undefined') {
         $params['sortname'] = NULL;
     }
     if (CRM_Utils_Array::value('sortorder', $params) == 'undefined') {
         $params['sortorder'] = NULL;
     }
     $sortname = CRM_Utils_Array::value('sortname', $params);
     $sortorder = CRM_Utils_Array::value('sortorder', $params);
     $groupBy = " GROUP BY ca.id ";
     if (!$sortname and !$sortorder) {
         // CRM-5081 - added id to act like creation date
         $orderBy = " ORDER BY overdue_date ASC, display_date DESC, weight DESC";
     } else {
         $sort = "{$sortname} {$sortorder}";
         $sort = CRM_Utils_Type::escape($sort, 'String');
         $orderBy = " ORDER BY {$sort} ";
         if ($sortname != 'display_date') {
             $orderBy .= ', display_date DESC';
         }
     }
     $page = CRM_Utils_Array::value('page', $params);
     $rp = CRM_Utils_Array::value('rp', $params);
     if (!$page) {
         $page = 1;
     }
     if (!$rp) {
         $rp = 10;
     }
     $start = ($page - 1) * $rp;
     $query = $select . $from . $where . $groupBy . $orderBy;
     $params = array(1 => array($caseID, 'Integer'));
     $dao = CRM_Core_DAO::executeQuery($query, $params);
     $params['total'] = $dao->N;
     //FIXME: need to optimize/cache these queries
     $limit = " LIMIT {$start}, {$rp}";
     $query .= $limit;
     //EXIT;
     $dao = CRM_Core_DAO::executeQuery($query, $params);
     $activityTypes = CRM_Case_PseudoConstant::caseActivityType(FALSE, TRUE);
     $activityStatus = CRM_Core_PseudoConstant::activityStatus();
     $activityPriority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id');
     $url = CRM_Utils_System::url("civicrm/case/activity", "reset=1&cid={$contactID}&caseid={$caseID}", FALSE, NULL, FALSE);
     $contextUrl = '';
     if ($context == 'fulltext') {
         $contextUrl = "&context={$context}";
     }
     $editUrl = "{$url}&action=update{$contextUrl}";
     $deleteUrl = "{$url}&action=delete{$contextUrl}";
     $restoreUrl = "{$url}&action=renew{$contextUrl}";
     $viewTitle = ts('View this activity.');
     $statusTitle = ts('Edit status');
     $emailActivityTypeIDs = array('Email' => CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name'), 'Inbound Email' => CRM_Core_OptionGroup::getValue('activity_type', 'Inbound Email', 'name'));
     $emailActivityTypeIDs = array('Email' => CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name'), 'Inbound Email' => CRM_Core_OptionGroup::getValue('activity_type', 'Inbound Email', 'name'));
     $caseDeleted = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseID, 'is_deleted');
     // define statuses which are handled like Completed status (others are assumed to be handled like Scheduled status)
     $compStatusValues = array();
     $compStatusNames = array('Completed', 'Left Message', 'Cancelled', 'Unreachable', 'Not Required');
     foreach ($compStatusNames as $name) {
         $compStatusValues[] = CRM_Core_OptionGroup::getValue('activity_status', $name, 'name');
     }
     $contactViewUrl = CRM_Utils_System::url("civicrm/contact/view", "reset=1&cid=", FALSE, NULL, FALSE);
     $hasViewContact = CRM_Core_Permission::giveMeAllACLs();
     $clientIds = self::retrieveContactIdsByCaseId($caseID);
     if (!$userID) {
         $session = CRM_Core_Session::singleton();
         $userID = $session->get('userID');
     }
     while ($dao->fetch()) {
         $allowView = self::checkPermission($dao->id, 'view', $dao->activity_type_id, $userID);
         $allowEdit = self::checkPermission($dao->id, 'edit', $dao->activity_type_id, $userID);
         $allowDelete = self::checkPermission($dao->id, 'delete', $dao->activity_type_id, $userID);
         //do not have sufficient permission
         //to access given case activity record.
         if (!$allowView && !$allowEdit && !$allowDelete) {
             continue;
         }
         $values[$dao->id]['id'] = $dao->id;
         $values[$dao->id]['type'] = $activityTypes[$dao->type]['label'];
         $reporterName = $dao->reporter;
         if ($hasViewContact) {
             $reporterName = '<a href="' . $contactViewUrl . $dao->reporter_id . '">' . $dao->reporter . '</a>';
         }
         $values[$dao->id]['reporter'] = $reporterName;
         $targetNames = CRM_Activity_BAO_ActivityContact::getNames($dao->id, $targetID);
         $targetContactUrls = $withContacts = array();
         foreach ($targetNames as $targetId => $targetName) {
             if (!in_array($targetId, $clientIds)) {
                 $withContacts[$targetId] = $targetName;
             }
         }
         foreach ($withContacts as $cid => $name) {
             if ($hasViewContact) {
                 $name = '<a href="' . $contactViewUrl . $cid . '">' . $name . '</a>';
             }
             $targetContactUrls[] = $name;
         }
         $values[$dao->id]['with_contacts'] = implode('; ', $targetContactUrls);
         $values[$dao->id]['display_date'] = CRM_Utils_Date::customFormat($dao->display_date);
         $values[$dao->id]['status'] = $activityStatus[$dao->status];
         //check for view activity.
         $subject = empty($dao->subject) ? '(' . ts('no subject') . ')' : $dao->subject;
         if ($allowView) {
             $url = CRM_Utils_System::url('civicrm/case/activity/view', array('cid' => $contactID, 'aid' => $dao->id));
             $subject = '<a class="crm-popup medium-popup" href="' . $url . '" title="' . $viewTitle . '">' . $subject . '</a>';
         }
         $values[$dao->id]['subject'] = $subject;
         // add activity assignee to activity selector. CRM-4485.
         if (isset($dao->assignee)) {
             if ($dao->ismultiple == 1) {
                 if ($dao->reporter_id != $dao->assignee_id) {
                     $values[$dao->id]['reporter'] .= $hasViewContact ? ' / ' . "<a href='{$contactViewUrl}{$dao->assignee_id}'>{$dao->assignee}</a>" : ' / ' . $dao->assignee;
                 }
                 $values[$dao->id]['assignee'] = $dao->assignee;
             } else {
                 $values[$dao->id]['reporter'] .= ' / ' . ts('(multiple)');
             }
         }
         // FIXME: Why are we not using CRM_Core_Action for these links? This is too much manual work and likely to get out-of-sync with core markup.
         $url = "";
         $css = 'class="action-item crm-hover-button"';
         $additionalUrl = "&id={$dao->id}";
         if (!$dao->deleted) {
             //hide edit link of activity type email.CRM-4530.
             if (!in_array($dao->type, $emailActivityTypeIDs)) {
                 //hide Edit link if activity type is NOT editable (special case activities).CRM-5871
                 if ($allowEdit) {
                     $url = '<a ' . $css . ' href="' . $editUrl . $additionalUrl . '">' . ts('Edit') . '</a> ';
                 }
             }
             if ($allowDelete) {
                 $url .= ' <a ' . str_replace('action-item', 'action-item small-popup', $css) . ' href="' . $deleteUrl . $additionalUrl . '">' . ts('Delete') . '</a>';
             }
         } elseif (!$caseDeleted) {
             $url = ' <a ' . $css . ' href="' . $restoreUrl . $additionalUrl . '">' . ts('Restore') . '</a>';
             $values[$dao->id]['status'] = $values[$dao->id]['status'] . '<br /> (deleted)';
         }
         //check for operations.
         if (self::checkPermission($dao->id, 'Move To Case', $dao->activity_type_id)) {
             $url .= ' <a ' . $css . ' href="#" onClick="Javascript:fileOnCase( \'move\',' . $dao->id . ', ' . $caseID . ', this ); return false;">' . ts('Move To Case') . '</a> ';
         }
         if (self::checkPermission($dao->id, 'Copy To Case', $dao->activity_type_id)) {
             $url .= ' <a ' . $css . ' href="#" onClick="Javascript:fileOnCase( \'copy\',' . $dao->id . ',' . $caseID . ', this ); return false;">' . ts('Copy To Case') . '</a> ';
         }
         // if there are file attachments we will return how many and, if only one, add a link to it
         if (!empty($dao->attachment_ids)) {
             $attachmentIDs = explode(',', $dao->attachment_ids);
             $values[$dao->id]['no_attachments'] = count($attachmentIDs);
             if ($values[$dao->id]['no_attachments'] == 1) {
                 // if there is only one it's easy to do a link - otherwise just flag it
                 $attachmentViewUrl = CRM_Utils_System::url("civicrm/file", "reset=1&eid=" . $dao->id . "&id=" . $dao->attachment_ids, FALSE, NULL, FALSE);
                 $url .= " <a href='{$attachmentViewUrl}' ><span class='icon paper-icon'></span></a>";
             }
         }
         $values[$dao->id]['links'] = $url;
         $values[$dao->id]['class'] = "";
         if (!empty($dao->priority)) {
             if ($dao->priority == CRM_Core_OptionGroup::getValue('priority', 'Urgent', 'name')) {
                 $values[$dao->id]['class'] = $values[$dao->id]['class'] . "priority-urgent ";
             } elseif ($dao->priority == CRM_Core_OptionGroup::getValue('priority', 'Low', 'name')) {
                 $values[$dao->id]['class'] = $values[$dao->id]['class'] . "priority-low ";
             }
         }
         if (CRM_Utils_Array::crmInArray($dao->status, $compStatusValues)) {
             $values[$dao->id]['class'] = $values[$dao->id]['class'] . " status-completed";
         } else {
             if (CRM_Utils_Date::overdue($dao->display_date)) {
                 $values[$dao->id]['class'] = $values[$dao->id]['class'] . " status-overdue";
             } else {
                 $values[$dao->id]['class'] = $values[$dao->id]['class'] . " status-scheduled";
             }
         }
         if ($allowEdit) {
             $values[$dao->id]['status'] = '<a class="crm-activity-status crm-activity-status-' . $dao->id . ' ' . $values[$dao->id]['class'] . ' crm-activity-change-status crm-editable-enabled" activity_id=' . $dao->id . ' current_status=' . $dao->status . ' case_id=' . $caseID . ' href="#" title=\'' . $statusTitle . '\'>' . $values[$dao->id]['status'] . '</a>';
         }
     }
     $dao->free();
     return $values;
 }
Exemplo n.º 6
0
 /**
  * Get activity contact.
  *
  * @param int $activityId
  * @param int $recordTypeID
  * @param string $column
  *
  * @return null
  */
 public static function getActivityContact($activityId, $recordTypeID = NULL, $column = 'contact_id')
 {
     $activityContact = new CRM_Activity_BAO_ActivityContact();
     $activityContact->activity_id = $activityId;
     if ($recordTypeID) {
         $activityContact->record_type_id = $recordTypeID;
     }
     if ($activityContact->find(TRUE)) {
         return $activityContact->{$column};
     }
     return NULL;
 }
Exemplo n.º 7
0
 /**
  * Takes an associative array and creates a friend object.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @return void
  */
 public static function create(&$params)
 {
     $transaction = new CRM_Core_Transaction();
     $mailParams = array();
     //create contact corresponding to each friend
     foreach ($params['friend'] as $key => $details) {
         if ($details["first_name"]) {
             $contactParams[$key] = array('first_name' => $details["first_name"], 'last_name' => $details["last_name"], 'contact_source' => ts('Tell a Friend') . ": {$params['title']}", 'email-Primary' => $details["email"]);
             $displayName = $details["first_name"] . " " . $details["last_name"];
             $mailParams['email'][$displayName] = $details["email"];
         }
     }
     $frndParams = array();
     $frndParams['entity_id'] = $params['entity_id'];
     $frndParams['entity_table'] = $params['entity_table'];
     self::getValues($frndParams);
     $activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', 'Tell a Friend', 'value', 'name');
     //create activity
     $activityParams = array('source_contact_id' => $params['source_contact_id'], 'source_record_id' => NULL, 'activity_type_id' => $activityTypeId, 'title' => $params['title'], 'activity_date_time' => date("YmdHis"), 'subject' => ts('Tell a Friend') . ": {$params['title']}", 'details' => $params['suggested_message'], 'status_id' => 2, 'is_test' => $params['is_test'], 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params));
     //activity creation
     $activity = CRM_Activity_BAO_Activity::create($activityParams);
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     //friend contacts creation
     foreach ($contactParams as $key => $value) {
         //create contact only if it does not exits in db
         $value['email'] = $value['email-Primary'];
         $value['check_permission'] = FALSE;
         $contact = CRM_Core_BAO_UFGroup::findContact($value, NULL, 'Individual');
         if (!$contact) {
             $contact = self::add($value);
         }
         // attempt to save activity targets
         $targetParams = array('activity_id' => $activity->id, 'contact_id' => $contact, 'record_type_id' => $targetID);
         // See if it already exists
         $activityContact = new CRM_Activity_DAO_ActivityContact();
         $activityContact->activity_id = $activity->id;
         $activityContact->contact_id = $contact;
         $activityContact->find(TRUE);
         if (empty($activityContact->id)) {
             $resultTarget = CRM_Activity_BAO_ActivityContact::create($targetParams);
         }
     }
     $transaction->commit();
     //process sending of mails
     $mailParams['title'] = CRM_Utils_Array::value('title', $params);
     $mailParams['general_link'] = CRM_Utils_Array::value('general_link', $frndParams);
     $mailParams['message'] = CRM_Utils_Array::value('suggested_message', $params);
     // get domain
     $domainDetails = CRM_Core_BAO_Domain::getNameAndEmail();
     list($username, $mailParams['domain']) = explode('@', $domainDetails[1]);
     $default = array();
     $findProperties = array('id' => $params['entity_id']);
     if ($params['entity_table'] == 'civicrm_contribution_page') {
         $returnProperties = array('receipt_from_email', 'is_email_receipt');
         CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $findProperties, $default, $returnProperties);
         //if is_email_receipt is set then take receipt_from_email
         //as from_email
         if (!empty($default['is_email_receipt']) && !empty($default['receipt_from_email'])) {
             $mailParams['email_from'] = $default['receipt_from_email'];
         }
         $urlPath = 'civicrm/contribute/transact';
         $mailParams['module'] = 'contribute';
     } elseif ($params['entity_table'] == 'civicrm_event') {
         $returnProperties = array('confirm_from_email', 'is_email_confirm');
         CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $findProperties, $default, $returnProperties);
         $mailParams['email_from'] = $domainDetails['1'];
         //if is_email_confirm is set then take confirm_from_email
         //as from_email
         if (!empty($default['is_email_confirm']) && !empty($default['confirm_from_email'])) {
             $mailParams['email_from'] = $default['confirm_from_email'];
         }
         $urlPath = 'civicrm/event/info';
         $mailParams['module'] = 'event';
     } elseif ($params['entity_table'] == 'civicrm_pcp') {
         $mailParams['email_from'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $params['source_contact_id'], 'email', 'contact_id');
         $urlPath = 'civicrm/pcp/info';
         $mailParams['module'] = 'contribute';
     }
     $mailParams['page_url'] = CRM_Utils_System::url($urlPath, "reset=1&id={$params['entity_id']}", TRUE, NULL, FALSE, TRUE);
     //send mail
     self::sendMail($params['source_contact_id'], $mailParams);
 }
Exemplo n.º 8
0
 /**
  * Process activity creation.
  *
  * @param array $params
  *   Associated array of submitted values.
  *
  * @return self|null|object
  */
 protected function processActivity(&$params)
 {
     $activityAssigned = array();
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     // format assignee params
     if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) {
         //skip those assignee contacts which are already assigned
         //while sending a copy.CRM-4509.
         $activityAssigned = array_flip($params['assignee_contact_id']);
         if ($this->_activityId) {
             $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($this->_activityId, $assigneeID);
             $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts);
         }
     }
     // call begin post process. Idea is to let injecting file do
     // any processing before the activity is added/updated.
     $this->beginPostProcess($params);
     $activity = CRM_Activity_BAO_Activity::create($params);
     // add tags if exists
     $tagParams = array();
     if (!empty($params['tag'])) {
         foreach ($params['tag'] as $tag) {
             $tagParams[$tag] = 1;
         }
     }
     // Save static tags.
     CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id);
     // Save free tags.
     if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) {
         CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this);
     }
     // call end post process. Idea is to let injecting file do any
     // processing needed, after the activity has been added/updated.
     $this->endPostProcess($params, $activity);
     // CRM-9590
     if (!empty($params['is_multi_activity'])) {
         $this->_activityIds[] = $activity->id;
     } else {
         $this->_activityId = $activity->id;
     }
     // create follow up activity if needed
     $followupStatus = '';
     $followupActivity = NULL;
     if (!empty($params['followup_activity_type_id'])) {
         $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params);
         $followupStatus = ts('A followup activity has been scheduled.');
     }
     // send copy to assignee contacts.CRM-4509
     $mailStatus = '';
     if (Civi::settings()->get('activity_assignee_notification')) {
         $activityIDs = array($activity->id);
         if ($followupActivity) {
             $activityIDs = array_merge($activityIDs, array($followupActivity->id));
         }
         $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityIDs, TRUE, FALSE);
         if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) {
             $mailToContacts = array();
             // Build an associative array with unique email addresses.
             foreach ($activityAssigned as $id => $dnc) {
                 if (isset($id) && array_key_exists($id, $assigneeContacts)) {
                     $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id];
                 }
             }
             $sent = CRM_Activity_BAO_Activity::sendToAssignee($activity, $mailToContacts);
             if ($sent) {
                 $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s).");
             }
         }
         // Also send email to follow-up activity assignees if set
         if ($followupActivity) {
             $mailToFollowupContacts = array();
             foreach ($assigneeContacts as $values) {
                 if ($values['activity_id'] == $followupActivity->id) {
                     $mailToFollowupContacts[$values['email']] = $values;
                 }
             }
             $sentFollowup = CRM_Activity_BAO_Activity::sendToAssignee($followupActivity, $mailToFollowupContacts);
             if ($sentFollowup) {
                 $mailStatus .= '<br />' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s).");
             }
         }
     }
     // set status message
     $subject = '';
     if (!empty($params['subject'])) {
         $subject = "'" . $params['subject'] . "'";
     }
     CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2 %3', array(1 => $subject, 2 => $followupStatus, 3 => $mailStatus)), ts('Saved'), 'success');
     return $activity;
 }
 /**
  * Handle the different actions, should probably be handles at base class level ...
  * 
  * @param type $match
  * @param type $btx
  */
 public function executeCancellation($match, $btx)
 {
     $config = $this->_plugin_config;
     $contribution_id = $match->getParameter('contribution_id');
     $mandate_id = $match->getParameter('mandate_id');
     $status_cancelled = banking_helper_optionvalue_by_groupname_and_name('contribution_status', 'Cancelled');
     // set the status to 'Cancelled'
     $query = array('version' => 3, 'id' => $contribution_id);
     $query['contribution_status_id'] = $status_cancelled;
     $query['cancel_date'] = date('Ymdhis', strtotime($btx->value_date));
     $query = array_merge($query, $this->getPropagationSet($btx, $match, 'contribution', $config->cancellation_value_propagation));
     // add propagated values
     if (empty($query['cancel_reason'])) {
         // add default values
         $query['cancel_reason'] = $config->cancellation_default_reason;
     }
     if ($config->cancellation_cancel_reason) {
         $query['cancel_reason'] = $match->getParameter('cancel_reason');
     }
     $result = civicrm_api('Contribution', 'create', $query);
     if (isset($result['is_error']) && $result['is_error']) {
         error_log("org.project60.sepa: matcher_sepa: Couldn't modify contribution, error was: " . $result['error_message']);
         CRM_Core_Session::setStatus(ts("Couldn't modify contribution."), ts('Error'), 'error');
     } else {
         // now for the mandate...
         $contribution = civicrm_api('Contribution', 'getsingle', array('version' => 3, 'id' => $contribution_id));
         if (!empty($contribution['is_error'])) {
             error_log("org.project60.sepa: matcher_sepa: Couldn't load contribution, error was: " . $result['error_message']);
             CRM_Core_Session::setStatus(ts("Couldn't modify contribution."), ts('Error'), 'error');
         } else {
             if ('OOFF' == $contribution['contribution_payment_instrument'] && !empty($config->cancellation_update_mandate_status_OOFF)) {
                 // everything seems fine, adjust the mandate's status
                 $query = array('version' => 3, 'id' => $mandate_id);
                 $query['status'] = $config->cancellation_update_mandate_status_OOFF;
                 $query = array_merge($query, $this->getPropagationSet($btx, $match, 'mandate'));
                 // add propagated values
                 $result = civicrm_api('SepaMandate', 'create', $query);
                 if (!empty($result['is_error'])) {
                     error_log("org.project60.sepa: matcher_sepa: Couldn't modify mandate, error was: " . $result['error_message']);
                     CRM_Core_Session::setStatus(ts("Couldn't modify mandate."), ts('Error'), 'error');
                 }
             } elseif ('RCUR' == $contribution['contribution_payment_instrument'] && !empty($config->cancellation_update_mandate_status_RCUR)) {
                 // everything seems fine, adjust the mandate's status
                 $query = array('version' => 3, 'id' => $mandate_id);
                 $query['status'] = $config->cancellation_update_mandate_status_RCUR;
                 $query = array_merge($query, $this->getPropagationSet($btx, $match, 'mandate'));
                 // add propagated values
                 $result = civicrm_api('SepaMandate', 'create', $query);
                 if (!empty($result['is_error'])) {
                     error_log("org.project60.sepa: matcher_sepa: Couldn't modify mandate, error was: " . $result['error_message']);
                     CRM_Core_Session::setStatus(ts("Couldn't modify mandate."), ts('Error'), 'error');
                 }
             }
         }
     }
     // create activity if wanted
     if ($config->cancellation_create_activity) {
         // gather some information to put in the text
         $smarty_vars = array();
         $smarty_vars['contribution'] = $contribution;
         $smarty_vars['cancel_fee'] = $match->getParameter('cancel_fee');
         $smarty_vars['cancel_reason'] = $match->getParameter('cancel_reason');
         // load the mandate
         $mandate = civicrm_api('SepaMandate', 'getsingle', array('id' => $mandate_id, 'version' => 3));
         $smarty_vars['mandate'] = $mandate;
         // load the contact
         $contact = civicrm_api('Contact', 'getsingle', array('id' => $contribution['contact_id'], 'version' => 3));
         $smarty_vars['contact'] = $contact;
         // count the cancelled contributions connected to this mandate
         $cancelled_contribution_count = 0;
         $current_contribution_date = date('Ymdhis', strtotime($contribution['receive_date']));
         if ($mandate['type'] == 'RCUR') {
             $query = "SELECT contribution_status_id\n                  FROM civicrm_contribution\n                  WHERE contribution_recur_id = {$mandate['entity_id']}\n                    AND receive_date <= '{$current_contribution_date}'\n                  ORDER BY receive_date DESC;";
             $status_list = CRM_Core_DAO::executeQuery($query);
             while ($status_list->fetch()) {
                 if ($status_list->contribution_status_id == $status_cancelled) {
                     $cancelled_contribution_count += 1;
                 } else {
                     break;
                 }
             }
         }
         $smarty_vars['cancelled_contribution_count'] = $cancelled_contribution_count;
         // look up contact if not set
         $user_id = CRM_Core_Session::singleton()->get('userID');
         if (empty($config->cancellation_create_activity_assignee_id)) {
             $assignedTo = $user_id;
         } else {
             $assignedTo = (int) $config->cancellation_create_activity_assignee_id;
         }
         // compile the text
         $smarty = CRM_Banking_Helpers_Smarty::singleton();
         $smarty->pushScope($smarty_vars);
         if (empty($config->cancellation_create_activity_text)) {
             $details = $smarty->fetch('CRM/Banking/PluginImpl/Matcher/SepaMandate.activity.tpl');
         } else {
             $details = $smarty->fetch("string:" . $config->cancellation_create_activity_text);
         }
         $smarty->popScope();
         $activity_parameters = array('version' => 3, 'activity_type_id' => $config->cancellation_create_activity_type_id, 'subject' => $config->cancellation_create_activity_subject, 'status_id' => 1, 'activity_date_time' => date('YmdHis'), 'source_contact_id' => $user_id, 'target_contact_id' => $contact['id'], 'details' => $details);
         $activity = CRM_Activity_BAO_Activity::create($activity_parameters);
         $assignment_parameters = array('activity_id' => $activity->id, 'contact_id' => $assignedTo, 'record_type_id' => 1);
         $assignment = CRM_Activity_BAO_ActivityContact::create($assignment_parameters);
     }
     $newStatus = banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'Processed');
     $btx->setStatus($newStatus);
     parent::execute($match, $btx);
     return true;
 }
Exemplo n.º 10
0
 /**
  * @param array $params
  *
  * @return array
  */
 public static function _convertToCaseActivity($params)
 {
     if (!$params['activityID'] || !$params['caseID']) {
         return array('error_msg' => 'required params missing.');
     }
     $otherActivity = new CRM_Activity_DAO_Activity();
     $otherActivity->id = $params['activityID'];
     if (!$otherActivity->find(TRUE)) {
         return array('error_msg' => 'activity record is missing.');
     }
     $actDateTime = CRM_Utils_Date::isoToMysql($otherActivity->activity_date_time);
     // Create new activity record.
     $mainActivity = new CRM_Activity_DAO_Activity();
     $mainActVals = array();
     CRM_Core_DAO::storeValues($otherActivity, $mainActVals);
     // Get new activity subject.
     if (!empty($params['newSubject'])) {
         $mainActVals['subject'] = $params['newSubject'];
     }
     $mainActivity->copyValues($mainActVals);
     $mainActivity->id = NULL;
     $mainActivity->activity_date_time = $actDateTime;
     // Make sure this is current revision.
     $mainActivity->is_current_revision = TRUE;
     // Drop all relations.
     $mainActivity->parent_id = $mainActivity->original_id = NULL;
     $mainActivity->save();
     $mainActivityId = $mainActivity->id;
     CRM_Activity_BAO_Activity::logActivityAction($mainActivity);
     $mainActivity->free();
     // Mark previous activity as deleted. If it was a non-case activity
     // then just change the subject.
     if (in_array($params['mode'], array('move', 'file'))) {
         $caseActivity = new CRM_Case_DAO_CaseActivity();
         $caseActivity->case_id = $params['caseID'];
         $caseActivity->activity_id = $otherActivity->id;
         if ($params['mode'] == 'move' || $caseActivity->find(TRUE)) {
             $otherActivity->is_deleted = 1;
         } else {
             $otherActivity->subject = ts('(Filed on case %1)', array(1 => $params['caseID'])) . ' ' . $otherActivity->subject;
         }
         $otherActivity->activity_date_time = $actDateTime;
         $otherActivity->save();
         $caseActivity->free();
     }
     $otherActivity->free();
     $targetContacts = array();
     if (!empty($params['targetContactIds'])) {
         $targetContacts = array_unique(explode(',', $params['targetContactIds']));
     }
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     $sourceContactID = CRM_Activity_BAO_Activity::getSourceContactID($params['activityID']);
     $src_params = array('activity_id' => $mainActivityId, 'contact_id' => $sourceContactID, 'record_type_id' => $sourceID);
     CRM_Activity_BAO_ActivityContact::create($src_params);
     foreach ($targetContacts as $key => $value) {
         $targ_params = array('activity_id' => $mainActivityId, 'contact_id' => $value, 'record_type_id' => $targetID);
         CRM_Activity_BAO_ActivityContact::create($targ_params);
     }
     // typically this will be empty, since assignees on another case may be completely different
     $assigneeContacts = array();
     if (!empty($params['assigneeContactIds'])) {
         $assigneeContacts = array_unique(explode(',', $params['assigneeContactIds']));
     }
     foreach ($assigneeContacts as $key => $value) {
         $assigneeParams = array('activity_id' => $mainActivityId, 'contact_id' => $value, 'record_type_id' => $assigneeID);
         CRM_Activity_BAO_ActivityContact::create($assigneeParams);
     }
     // Attach newly created activity to case.
     $caseActivity = new CRM_Case_DAO_CaseActivity();
     $caseActivity->case_id = $params['caseID'];
     $caseActivity->activity_id = $mainActivityId;
     $caseActivity->save();
     $error_msg = $caseActivity->_lastError;
     $caseActivity->free();
     $params['mainActivityId'] = $mainActivityId;
     CRM_Activity_BAO_Activity::copyExtendedActivityData($params);
     return array('error_msg' => $error_msg, 'newId' => $mainActivity->id);
 }
Exemplo n.º 11
0
 /**
  * Process the form after the input has been submitted and validated.
  */
 public function postProcess()
 {
     // Clear any formRule errors from Email form in case they came back here via Cancel button
     $this->controller->resetPage('Email');
     $params = $this->exportValues();
     $this->_contacts = array();
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     // Get assignee contacts.
     if (!empty($params['assigned_to'])) {
         foreach ($this->_activityHolderIds as $key => $id) {
             $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $assigneeID));
             $this->_contacts = array_merge($this->_contacts, $ids);
         }
     }
     // Get target contacts.
     if (!empty($params['with_contact'])) {
         foreach ($this->_activityHolderIds as $key => $id) {
             $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $targetID));
             $this->_contacts = array_merge($this->_contacts, $ids);
         }
     }
     // Get 'Added by' contacts.
     if (!empty($params['created_by'])) {
         parent::setContactIDs();
         if (!empty($this->_contactIds)) {
             $this->_contacts = array_merge($this->_contacts, $this->_contactIds);
         }
     }
     $this->_contacts = array_unique($this->_contacts);
     // Bounce to pick option if no contacts to send to.
     if (empty($this->_contacts)) {
         $urlParams = "_qf_PickOption_display=true&qfKey={$params['qfKey']}";
         $urlRedirect = CRM_Utils_System::url('civicrm/activity/search', $urlParams);
         CRM_Core_Error::statusBounce(ts('It appears you have no contacts with email addresses from the selected recipients.'), $urlRedirect);
     }
     $this->set('contacts', $this->_contacts);
 }
 /**
  * @param CRM_Core_Form $form
  * @param $html_message
  * @param $contactIds
  *
  * @throws CRM_Core_Exception
  */
 public static function createActivities($form, $html_message, $contactIds)
 {
     //Added for CRM-12682: Add activity subject and campaign fields
     $formValues = $form->controller->exportValues($form->getName());
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Print PDF Letter', 'name');
     $activityParams = array('subject' => $formValues['subject'], 'campaign_id' => CRM_Utils_Array::value('campaign_id', $formValues), 'source_contact_id' => $userID, 'activity_type_id' => $activityTypeID, 'activity_date_time' => date('YmdHis'), 'details' => $html_message);
     if (!empty($form->_activityId)) {
         $activityParams += array('id' => $form->_activityId);
     }
     if ($form->_cid) {
         $activity = CRM_Activity_BAO_Activity::create($activityParams);
         if (!empty($form->_caseId)) {
             $caseActivityParams = array('activity_id' => $activity->id, 'case_id' => $form->_caseId);
             CRM_Case_BAO_Case::processCaseActivity($caseActivityParams);
         }
     } else {
         // create  Print PDF activity for each selected contact. CRM-6886
         $activityIds = array();
         foreach ($contactIds as $contactId) {
             $activityID = CRM_Activity_BAO_Activity::create($activityParams);
             $activityIds[$contactId] = $activityID->id;
         }
     }
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     //@todo why are we using $form->_contactIds here & contactIds above - need comment
     foreach ($form->_contactIds as $contactId) {
         $activityTargetParams = array('activity_id' => empty($activity->id) ? $activityIds[$contactId] : $activity->id, 'contact_id' => $contactId, 'record_type_id' => $targetID);
         CRM_Activity_BAO_ActivityContact::create($activityTargetParams);
     }
 }
Exemplo n.º 13
0
 static function recentApplicationActivities($limit = 10)
 {
     $recentActivities = array();
     $customTableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', 'application_case', 'table_name', 'name');
     //Retrieve top $limit(as total activity count) recent activities
     $query = CRM_Case_BAO_Case::getCaseActivityQuery($type = 'any', NULL, $condition = "AND c_type.name = 'Application' AND t_act.desired_date <= CURRENT_TIMESTAMP ");
     $query .= "LIMIT 0, {$limit}";
     $query = str_replace('ORDER BY case_activity_date ASC', 'ORDER BY case_activity_date DESC', $query);
     $dao = CRM_Core_DAO::executeQuery($query);
     while ($dao->fetch()) {
         $query = "SELECT vacancy_id FROM {$customTableName} WHERE entity_id = {$dao->case_id}";
         $ctDAO = CRM_Core_DAO::executeQuery($query);
         $ctDAO->fetch();
         $vacancyDAO = new self();
         $vacancyDAO->id = $ctDAO->vacancy_id;
         $vacancyDAO->find(TRUE);
         //Applicant contact link
         $applicant = "<a href='" . CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}") . "'>{$dao->sort_name}</a>";
         //Position link
         $position = "<a href='" . CRM_Utils_System::url('civicrm/case/pipeline', "reset=1&vid={$vacancyDAO->id}") . "'>{$vacancyDAO->position}</a>";
         //Case Activity Source link
         $sourceID = civicrm_api3('OptionValue', 'getvalue', array('option_group_id' => 'activity_contacts', 'name' => 'Activity Source', 'return' => 'value'));
         $sourceContact = CRM_Activity_BAO_ActivityContact::getNames($dao->case_activity_id, $sourceID);
         $sourceContactID = key($sourceContact);
         $source = "<a href='" . CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$sourceContactID}") . "'>{$sourceContact[$sourceContactID]}</a>";
         switch ($dao->case_activity_type_name) {
             case 'Open Case':
                 $recentActivities[] = array('activity' => "{$applicant} applied for {$position}", 'time' => $dao->case_activity_date);
                 break;
             case 'Comment':
                 $recentActivities[] = array('activity' => "{$source} commented on {$position}", 'time' => $dao->case_activity_date);
                 break;
             case 'Phone Call':
             case 'Meeting':
             case 'Follow up':
                 $recentActivities[] = array('activity' => "{$source} had a {$dao->case_activity_type_name} with {$applicant} (vis-a-vis {$position})", 'time' => $dao->case_activity_date);
                 break;
             case 'Email':
                 $recentActivities[] = array('activity' => "{$source} sent email to {$applicant}", 'time' => $dao->case_activity_date);
                 break;
             case 'Change Case Status':
                 $subject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $dao->case_activity_id, 'subject');
                 $subject = str_replace('Assignment status changed', '', $subject);
                 $recentActivities[] = array('activity' => "{$source} changed the status of {$position} {$subject}", 'time' => $dao->case_activity_date);
                 break;
             case 'Evaluation':
                 $subject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $dao->case_activity_id, 'subject');
                 $recentActivities[] = array('activity' => "{$source} evaluated {$applicant} for {$position}", 'time' => $dao->case_activity_date);
                 break;
             default:
                 $subject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $dao->case_activity_id, 'subject');
                 $recentActivities[] = array('activity' => "{$position}: {$dao->case_activity_type_name} for {$applicant}", 'time' => $dao->case_activity_date);
                 break;
         }
     }
     return $recentActivities;
 }
Exemplo n.º 14
0
 /**
  * Process activity creation
  *
  * @param array $params associated array of submitted values
  * @access protected
  */
 protected function processActivity(&$params)
 {
     $activityAssigned = array();
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     // format assignee params
     if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) {
         //skip those assignee contacts which are already assigned
         //while sending a copy.CRM-4509.
         $activityAssigned = array_flip($params['assignee_contact_id']);
         if ($this->_activityId) {
             $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($this->_activityId, $assigneeID);
             $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts);
         }
     }
     // call begin post process. Idea is to let injecting file do
     // any processing before the activity is added/updated.
     $this->beginPostProcess($params);
     $activity = CRM_Activity_BAO_Activity::create($params);
     // add tags if exists
     $tagParams = array();
     if (!empty($params['tag'])) {
         foreach ($params['tag'] as $tag) {
             $tagParams[$tag] = 1;
         }
     }
     //save static tags
     CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id);
     //save free tags
     if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) {
         CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this);
     }
     // call end post process. Idea is to let injecting file do any
     // processing needed, after the activity has been added/updated.
     $this->endPostProcess($params, $activity);
     // CRM-9590
     if (CRM_Utils_Array::value('is_multi_activity', $params)) {
         $this->_activityIds[] = $activity->id;
     } else {
         $this->_activityId = $activity->id;
     }
     // create follow up activity if needed
     $followupStatus = '';
     if (CRM_Utils_Array::value('followup_activity_type_id', $params)) {
         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 sending a copy of activity.
             $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id);
             $ics = new CRM_Activity_BAO_ICalendar($activity);
             $ics->addAttachment($attachments, $mailToContacts);
             // CRM-8400 add param with _currentlyViewedContactId for URL link in mail
             CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL);
             $ics->cleanup();
             $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s).");
         }
     }
     // set status message
     $subject = '';
     if (CRM_Utils_Array::value('subject', $params)) {
         $subject = "'" . $params['subject'] . "'";
     }
     CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2 %3', array(1 => $subject, 2 => $followupStatus, 3 => $mailStatus)), ts('Saved'), 'success');
     return $activity;
 }
Exemplo n.º 15
0
 /**
  * Returns all the rows in the given offset and rowCount.
  *
  * @param string $action
  *   The action being performed.
  * @param int $offset
  *   The row number to start from.
  * @param int $rowCount
  *   The number of rows to return.
  * @param string $sort
  *   The sql string that describes the sort order.
  * @param string $output
  *   What should the result set include (web/email/csv).
  *
  * @return array
  *   rows in the given offset and rowCount
  */
 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_activityClause);
     $rows = array();
     $mailingIDs = CRM_Mailing_BAO_Mailing::mailingACLIDs();
     $accessCiviMail = CRM_Core_Permission::check('access CiviMail');
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     $engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel();
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     //get all activity types
     $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name', TRUE);
     while ($result->fetch()) {
         $row = array();
         // ignore rows where we dont have an activity id
         if (empty($result->activity_id)) {
             continue;
         }
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (isset($result->{$property})) {
                 $row[$property] = $result->{$property};
             }
         }
         $contactId = CRM_Utils_Array::value('contact_id', $row);
         if (!$contactId) {
             $contactId = CRM_Utils_Array::value('source_contact_id', $row);
         }
         $row['target_contact_name'] = CRM_Activity_BAO_ActivityContact::getNames($row['activity_id'], $targetID);
         $row['assignee_contact_name'] = CRM_Activity_BAO_ActivityContact::getNames($row['activity_id'], $assigneeID);
         list($row['source_contact_name'], $row['source_contact_id']) = CRM_Activity_BAO_ActivityContact::getNames($row['activity_id'], $sourceID, TRUE);
         $row['source_contact_name'] = implode(',', array_values($row['source_contact_name']));
         $row['source_contact_id'] = implode(',', $row['source_contact_id']);
         if ($this->_context == 'search') {
             $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->activity_id;
         }
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id);
         $accessMailingReport = FALSE;
         $activityTypeId = $row['activity_type_id'];
         if ($row['activity_is_test']) {
             $row['activity_type'] = $row['activity_type'] . " (test)";
         }
         $bulkActivityTypeID = CRM_Utils_Array::key('Bulk Email', $activityTypes);
         $row['mailingId'] = '';
         if ($accessCiviMail && ($mailingIDs === TRUE || in_array($result->source_record_id, $mailingIDs)) && $bulkActivityTypeID == $activityTypeId) {
             $row['mailingId'] = CRM_Utils_System::url('civicrm/mailing/report', "mid={$result->source_record_id}&reset=1&cid={$contactId}&context=activitySelector");
             $row['recipients'] = ts('(recipients)');
             $row['target_contact_name'] = '';
             $row['assignee_contact_name'] = '';
             $accessMailingReport = TRUE;
         }
         $activityActions = new CRM_Activity_Selector_Activity($result->contact_id, NULL);
         $actionLinks = $activityActions->actionLinks($activityTypeId, CRM_Utils_Array::value('source_record_id', $row), $accessMailingReport, CRM_Utils_Array::value('activity_id', $row), $this->_key, $this->_compContext);
         $row['action'] = CRM_Core_Action::formLink($actionLinks, NULL, array('id' => $result->activity_id, 'cid' => $contactId, 'cxt' => $this->_context), ts('more'), FALSE, 'activity.selector.row', 'Activity', $result->activity_id);
         //carry campaign to selector.
         $row['campaign'] = CRM_Utils_Array::value($result->activity_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->activity_campaign_id;
         if ($engagementLevel = CRM_Utils_Array::value('activity_engagement_level', $row)) {
             $row['activity_engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel);
         }
         //Check if recurring activity
         $repeat = CRM_Core_BAO_RecurringEntity::getPositionAndCount($row['activity_id'], 'civicrm_activity');
         $row['repeat'] = '';
         if ($repeat) {
             $row['repeat'] = ts('Repeating (%1 of %2)', array(1 => $repeat[0], 2 => $repeat[1]));
         }
         $rows[] = $row;
     }
     return $rows;
 }
Exemplo n.º 16
0
 function &getActivity($clientID, $activityDAO, &$activityTypeInfo)
 {
     if (empty($this->_redactionStringRules)) {
         $this->_redactionStringRules = array();
     }
     $activity = array();
     $activity['fields'] = array();
     if ($clientID) {
         $clientID = CRM_Utils_Type::escape($clientID, 'Integer');
         if (!in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) {
             $activity['editURL'] = CRM_Utils_System::url('civicrm/case/activity', "reset=1&cid={$clientID}&caseid={$activityDAO->caseID}&action=update&atype={$activityDAO->activity_type_id}&id={$activityDAO->id}");
         } else {
             $activity['editURL'] = '';
         }
         $client = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'display_name');
         // add Client SortName as well as Display to the strings to be redacted across the case session
         // suffixed with a randomly generated 4-digit number
         if (!array_key_exists($client, $this->_redactionStringRules)) {
             $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($client => 'name_' . rand(10000, 100000)));
             $clientSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $clientID, 'sort_name');
             if (!array_key_exists($clientSortName, $this->_redactionStringRules)) {
                 $this->_redactionStringRules[$clientSortName] = $this->_redactionStringRules[$client];
             }
         }
         $activity['fields'][] = array('label' => 'Client', 'value' => $this->redact($client), 'type' => 'String');
     }
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     if (!empty($activityDAO->targetID)) {
         // Re-lookup the target ID since the DAO only has the first recipient if there are multiple.
         // Maybe not the best solution.
         $targetNames = CRM_Activity_BAO_ActivityContact::getNames($activityDAO->id, $targetID);
         $processTarget = FALSE;
         $label = ts('With Contact(s)');
         if (in_array($activityTypeInfo['name'], array('Email', 'Inbound Email'))) {
             $processTarget = TRUE;
             $label = ts('Recipient');
         }
         if (!$processTarget) {
             foreach ($targetNames as $targetID => $targetName) {
                 if ($targetID != $clientID) {
                     $processTarget = TRUE;
                     break;
                 }
             }
         }
         if ($processTarget) {
             $targetRedacted = array();
             foreach ($targetNames as $targetID => $target) {
                 // add Recipient SortName as well as Display to the strings to be redacted across the case session
                 // suffixed with a randomly generated 4-digit number
                 if (!array_key_exists($target, $this->_redactionStringRules)) {
                     $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($target => 'name_' . rand(10000, 100000)));
                     $targetSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $targetID, 'sort_name');
                     if (!array_key_exists($targetSortName, $this->_redactionStringRules)) {
                         $this->_redactionStringRules[$targetSortName] = $this->_redactionStringRules[$target];
                     }
                 }
                 $targetRedacted[] = $this->redact($target);
             }
             $activity['fields'][] = array('label' => $label, 'value' => implode('; ', $targetRedacted), 'type' => 'String');
         }
     }
     // Activity Type info is a special field
     $activity['fields'][] = array('label' => ts('Activity Type'), 'value' => $activityTypeInfo['label'], 'type' => 'String');
     $activity['fields'][] = array('label' => ts('Subject'), 'value' => htmlspecialchars($this->redact($activityDAO->subject)), 'type' => 'Memo');
     $creator = $this->getCreatedBy($activityDAO->id);
     // add Creator to the strings to be redacted across the case session
     if (!array_key_exists($creator, $this->_redactionStringRules)) {
         $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($creator => 'name_' . rand(10000, 100000)));
     }
     $activity['fields'][] = array('label' => ts('Created By'), 'value' => $this->redact($creator), 'type' => 'String');
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
     $source_contact_id = CRM_Activity_BAO_Activity::getActivityContact($activityDAO->id, $sourceID);
     $reporter = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $source_contact_id, 'display_name');
     // add Reporter SortName as well as Display to the strings to be redacted across the case session
     // suffixed with a randomly generated 4-digit number
     if (!array_key_exists($reporter, $this->_redactionStringRules)) {
         $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($reporter => 'name_' . rand(10000, 100000)));
         $reporterSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $source_contact_id, 'sort_name');
         if (!array_key_exists($reporterSortName, $this->_redactionStringRules)) {
             $this->_redactionStringRules[$reporterSortName] = $this->_redactionStringRules[$reporter];
         }
     }
     $activity['fields'][] = array('label' => ts('Reported By'), 'value' => $this->redact($reporter), 'type' => 'String');
     if (!empty($activityDAO->assigneeID)) {
         //allow multiple assignee contacts.CRM-4503.
         $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activityDAO->id), TRUE);
         foreach ($assignee_contact_names as &$assignee) {
             // add Assignee to the strings to be redacted across the case session
             $this->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($this->_redactionStringRules, array($assignee => 'name_' . rand(10000, 100000)));
             $assignee = $this->redact($assignee);
         }
         $assigneeContacts = implode(', ', $assignee_contact_names);
         $activity['fields'][] = array('label' => ts('Assigned To'), 'value' => $assigneeContacts, 'type' => 'String');
     }
     if ($activityDAO->medium_id) {
         $activity['fields'][] = array('label' => ts('Medium'), 'value' => CRM_Core_OptionGroup::getLabel('encounter_medium', $activityDAO->medium_id, FALSE), 'type' => 'String');
     }
     $activity['fields'][] = array('label' => ts('Location'), 'value' => $activityDAO->location, 'type' => 'String');
     $activity['fields'][] = array('label' => ts('Date and Time'), 'value' => $activityDAO->activity_date_time, 'type' => 'Date');
     $activity['fields'][] = array('label' => ts('Details'), 'value' => $this->redact(CRM_Utils_String::stripAlternatives($activityDAO->details)), 'type' => 'Memo');
     // Skip Duration field if empty (to avoid " minutes" output). Might want to do this for all fields at some point. dgg
     if ($activityDAO->duration) {
         $activity['fields'][] = array('label' => ts('Duration'), 'value' => $activityDAO->duration . ' ' . ts('minutes'), 'type' => 'Int');
     }
     $activity['fields'][] = array('label' => ts('Status'), 'value' => CRM_Core_OptionGroup::getLabel('activity_status', $activityDAO->status_id), 'type' => 'String');
     $activity['fields'][] = array('label' => ts('Priority'), 'value' => CRM_Core_OptionGroup::getLabel('priority', $activityDAO->priority_id), 'type' => 'String');
     //for now empty custom groups
     $activity['customGroups'] = $this->getCustomData($clientID, $activityDAO, $activityTypeInfo);
     return $activity;
 }
Exemplo n.º 17
0
 /**
  * Process the view.
  *
  *
  * @return void
  */
 public function preProcess()
 {
     $contactID = CRM_Utils_Request::retrieve('cid', 'Integer', $this, TRUE);
     $activityID = CRM_Utils_Request::retrieve('aid', 'Integer', $this, TRUE);
     $revs = CRM_Utils_Request::retrieve('revs', 'Boolean', CRM_Core_DAO::$_nullObject);
     $caseID = CRM_Utils_Request::retrieve('caseID', 'Boolean', CRM_Core_DAO::$_nullObject);
     $activitySubject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'subject');
     //check for required permissions, CRM-6264
     if ($activityID && !CRM_Activity_BAO_Activity::checkPermission($activityID, CRM_Core_Action::VIEW)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     $this->assign('contactID', $contactID);
     $this->assign('caseID', $caseID);
     // CRM-9145
     $this->assign('activityID', $activityID);
     $xmlProcessor = new CRM_Case_XMLProcessor_Report();
     $report = $xmlProcessor->getActivityInfo($contactID, $activityID, TRUE);
     $attachmentUrl = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityID);
     if ($attachmentUrl) {
         $report['fields'][] = array('label' => 'Attachment(s)', 'value' => $attachmentUrl, 'type' => 'Link');
     }
     $tags = CRM_Core_BAO_EntityTag::getTag($activityID, 'civicrm_activity');
     if (!empty($tags)) {
         $allTag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
         foreach ($tags as $tid) {
             $tags[$tid] = $allTag[$tid];
         }
         $report['fields'][] = array('label' => 'Tags', 'value' => implode('<br />', $tags), 'type' => 'String');
     }
     $this->assign('report', $report);
     $latestRevisionID = CRM_Activity_BAO_Activity::getLatestActivityId($activityID);
     $viewPriorActivities = array();
     $priorActivities = CRM_Activity_BAO_Activity::getPriorAcitivities($activityID);
     foreach ($priorActivities as $activityId => $activityValues) {
         if (CRM_Case_BAO_Case::checkPermission($activityId, 'view', NULL, $contactID)) {
             $viewPriorActivities[$activityId] = $activityValues;
         }
     }
     if ($revs) {
         CRM_Utils_System::setTitle(ts('Activity Revision History'));
         $this->assign('revs', $revs);
         $this->assign('result', $viewPriorActivities);
         $this->assign('subject', $activitySubject);
         $this->assign('latestRevisionID', $latestRevisionID);
     } else {
         if (count($viewPriorActivities) > 1) {
             $this->assign('activityID', $activityID);
         }
         if ($latestRevisionID != $activityID) {
             $this->assign('latestRevisionID', $latestRevisionID);
         }
     }
     $parentID = CRM_Activity_BAO_Activity::getParentActivity($activityID);
     if ($parentID) {
         $this->assign('parentID', $parentID);
     }
     //viewing activity should get diplayed in recent list.CRM-4670
     $activityTypeID = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'activity_type_id');
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     $activityTargetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activityID, $targetID);
     if (!empty($activityTargetContacts)) {
         $recentContactId = $activityTargetContacts[0];
     } else {
         $recentContactId = $contactID;
     }
     if (!isset($caseID)) {
         $caseID = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $activityID, 'case_id', 'activity_id');
     }
     $url = CRM_Utils_System::url('civicrm/case/activity/view', "reset=1&aid={$activityID}&cid={$recentContactId}&caseID={$caseID}&context=home");
     $recentContactDisplay = CRM_Contact_BAO_Contact::displayName($recentContactId);
     // add the recently created Activity
     $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE);
     $title = "";
     if (isset($activitySubject)) {
         $title = $activitySubject . ' - ';
     }
     $title = $title . $recentContactDisplay . ' (' . $activityTypes[$activityTypeID] . ')';
     $recentOther = array();
     if (CRM_Case_BAO_Case::checkPermission($activityID, 'edit')) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/case/activity', "reset=1&action=update&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home");
     }
     if (CRM_Case_BAO_Case::checkPermission($activityID, 'delete')) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/case/activity', "reset=1&action=delete&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home");
     }
     CRM_Utils_Recent::add($title, $url, $activityID, 'Activity', $recentContactId, $recentContactDisplay, $recentOther);
 }
 static function sendInviteEmail($message_template, $contact_id, $emailParams = array(), $teampcpId, $activityId)
 {
     $mailParams = array();
     $contactParams = array();
     if (isset($emailParams['tplParams'])) {
         $mailParams['tplParams'] = $emailParams['tplParams'];
     }
     //create contact corresponding to each friend
     foreach ($emailParams['friend'] as $key => $details) {
         if ($details["first_name"]) {
             $displayName = $details["first_name"] . " " . $details["last_name"];
             $contactParams[$key] = array('first_name' => $details["first_name"], 'last_name' => $details["last_name"], 'contact_source' => ts('PCP Team Invite'), 'email-Primary' => $details["email"], 'display_name' => $displayName);
             $mailParams['email'][$displayName] = $contactParams[$key];
         }
     }
     if (empty($mailParams)) {
         return NULL;
     }
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     //friend contacts creation
     foreach ($contactParams as $key => $value) {
         //create contact only if it does not exits in db
         $value['email'] = $value['email-Primary'];
         $value['check_permission'] = FALSE;
         $contact = CRM_Core_BAO_UFGroup::findContact($value, NULL, 'Individual');
         if (!$contact) {
             $contact = CRM_Contact_BAO_Contact::createProfileContact($value, CRM_Core_DAO::$_nullArray);
         }
         // attempt to save activity targets
         $targetParams = array('activity_id' => $activityId, 'contact_id' => $contact, 'record_type_id' => $targetID);
         // See if it already exists
         $activityContact = new CRM_Activity_DAO_ActivityContact();
         $activityContact->activity_id = $activityId;
         $activityContact->contact_id = $contact;
         $activityContact->find(TRUE);
         if (empty($activityContact->id)) {
             CRM_Activity_BAO_ActivityContact::create($targetParams);
         }
     }
     $mailParams['valueName'] = $message_template;
     return self::sendMail($contact_id, $mailParams);
 }