/** * Process the form after the input has been submitted and validated. */ public function postProcess() { $formparams = $this->exportValues(); $caseId = $formparams['unclosed_case_id']; $filedActivities = 0; foreach ($this->_activityHolderIds as $key => $id) { $targetContactValues = $defaults = array(); $params = array('id' => $id); CRM_Activity_BAO_Activity::retrieve($params, $defaults); if (CRM_Case_BAO_Case::checkPermission($id, 'File On Case', $defaults['activity_type_id'])) { if (!CRM_Utils_Array::crmIsEmptyArray($defaults['target_contact'])) { $targetContactValues = array_combine(array_unique($defaults['target_contact']), explode(';', trim($defaults['target_contact_value']))); $targetContactValues = implode(',', array_keys($targetContactValues)); } $params = array('caseID' => $caseId, 'activityID' => $id, 'newSubject' => empty($defaults['subject']) ? '' : $defaults['subject'], 'targetContactIds' => $targetContactValues, 'mode' => 'file'); $error_msg = CRM_Activity_Page_AJAX::_convertToCaseActivity($params); if (empty($error_msg['error_msg'])) { $filedActivities++; } else { CRM_Core_Session::setStatus($error_msg['error_msg'], ts("Error"), "error"); } } else { CRM_Core_Session::setStatus(ts('Not permitted to file activity %1 %2.', array(1 => empty($defaults['subject']) ? '' : $defaults['subject'], 2 => $defaults['activity_date_time'])), ts("Error"), "error"); } } CRM_Core_Session::setStatus($filedActivities, ts("Filed Activities"), "success"); CRM_Core_Session::setStatus("", ts('Total Selected Activities: %1', array(1 => count($this->_activityHolderIds))), "info"); }
/** * 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); }
/** * Does user has sufficient permission for view/edit activity record. * * @param int $activityId * Activity record id. * @param int $action * Edit/view. * * @return bool */ public static function checkPermission($activityId, $action) { $allow = FALSE; if (!$activityId || !in_array($action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW))) { return $allow; } $activity = new CRM_Activity_DAO_Activity(); $activity->id = $activityId; if (!$activity->find(TRUE)) { return $allow; } // Component related permissions. $compPermissions = array('CiviCase' => array('administer CiviCase', 'access my cases and activities', 'access all cases and activities'), 'CiviMail' => array('access CiviMail'), 'CiviEvent' => array('access CiviEvent'), 'CiviGrant' => array('access CiviGrant'), 'CiviPledge' => array('access CiviPledge'), 'CiviMember' => array('access CiviMember'), 'CiviReport' => array('access CiviReport'), 'CiviContribute' => array('access CiviContribute'), 'CiviCampaign' => array('administer CiviCampaign')); // Return early when it is case activity. $isCaseActivity = CRM_Case_BAO_Case::isCaseActivity($activityId); // Check for civicase related permission. if ($isCaseActivity) { $allow = FALSE; foreach ($compPermissions['CiviCase'] as $per) { if (CRM_Core_Permission::check($per)) { $allow = TRUE; break; } } // Check for case specific permissions. if ($allow) { $oper = 'view'; if ($action == CRM_Core_Action::UPDATE) { $oper = 'edit'; } $allow = CRM_Case_BAO_Case::checkPermission($activityId, $oper, $activity->activity_type_id); } return $allow; } // First check the component permission. $sql = "\n SELECT component_id\n FROM civicrm_option_value val\nINNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.name = %1 )\n WHERE val.value = %2"; $params = array(1 => array('activity_type', 'String'), 2 => array($activity->activity_type_id, 'Integer')); $componentId = CRM_Core_DAO::singleValueQuery($sql, $params); if ($componentId) { $componentName = CRM_Core_Component::getComponentName($componentId); $compPermission = CRM_Utils_Array::value($componentName, $compPermissions); // Here we are interesting in any single permission. if (is_array($compPermission)) { foreach ($compPermission as $per) { if (CRM_Core_Permission::check($per)) { $allow = TRUE; break; } } } } // Check for this permission related to contact. $permission = CRM_Core_Permission::VIEW; if ($action == CRM_Core_Action::UPDATE) { $permission = CRM_Core_Permission::EDIT; } $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); // Check for source contact. if (!$componentId || $allow) { $sourceContactId = self::getActivityContact($activity->id, $sourceID); // Account for possibility of activity not having a source contact (as it may have been deleted). if ($sourceContactId) { $allow = CRM_Contact_BAO_Contact_Permission::allow($sourceContactId, $permission); } } // Check for target and assignee contacts. if ($allow) { // First check for supper permission. $supPermission = 'view all contacts'; if ($action == CRM_Core_Action::UPDATE) { $supPermission = 'edit all contacts'; } $allow = CRM_Core_Permission::check($supPermission); // User might have sufficient permission, through acls. if (!$allow) { $allow = TRUE; // Get the target contacts. $targetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $targetID); foreach ($targetContacts as $cnt => $contactId) { if (!CRM_Contact_BAO_Contact_Permission::allow($contactId, $permission)) { $allow = FALSE; break; } } // Get the assignee contacts. if ($allow) { $assigneeContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $assigneeID); foreach ($assigneeContacts as $cnt => $contactId) { if (!CRM_Contact_BAO_Contact_Permission::allow($contactId, $permission)) { $allow = FALSE; break; } } } } } return $allow; }
/** * Build the form object. * * @return void */ public function preProcess() { $caseIds = CRM_Utils_Request::retrieve('caseid', 'String', $this); $this->_caseId = explode(',', $caseIds); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); if (!$this->_context) { $this->_context = 'caseActivity'; } $this->_crmDir = 'Case'; $this->assign('context', $this->_context); $result = parent::preProcess(); $scheduleStatusId = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled', 'name'); $this->assign('scheduleStatusId', $scheduleStatusId); if (!$this->_caseId && $this->_activityId) { $this->_caseId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $this->_activityId, 'case_id', 'activity_id'); } if ($this->_caseId) { $this->assign('caseId', $this->_caseId); $this->assign('countId', count($this->_caseId)); $this->assign('caseID', CRM_Utils_Array::first($this->_caseId)); } if (!$this->_caseId || !$this->_activityId && !$this->_activityTypeId) { CRM_Core_Error::fatal('required params missing.'); } //check for case activity access. if (!CRM_Case_BAO_Case::accessCiviCase()) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } //validate case id. if ($this->_caseId && !CRM_Core_Permission::check('access all cases and activities')) { $session = CRM_Core_Session::singleton(); $allCases = CRM_Case_BAO_Case::getCases(TRUE, $session->get('userID'), 'any'); if (!array_key_exists($this->_caseId, $allCases)) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } } //validate case activity id. if ($this->_activityId && $this->_action & CRM_Core_Action::UPDATE) { $valid = CRM_Case_BAO_Case::checkPermission($this->_activityId, 'edit', $this->_activityTypeId); if (!$valid) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } } foreach ($this->_caseId as $casePos => $caseId) { $this->_caseType[$casePos] = CRM_Case_BAO_Case::getCaseType($caseId, 'name'); } $this->assign('caseType', $this->_caseType); $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); $this->assign('multiClient', $isMultiClient); foreach ($this->_caseId as $casePos => $caseId) { $clients[] = CRM_Case_BAO_Case::getContactNames($caseId); } $this->assign('client_names', $clients); $caseIds = implode(',', $this->_caseId); // set context for pushUserContext and for statusBounce if ($this->_context == 'fulltext') { if ($this->_action == CRM_Core_Action::UPDATE || $this->_action == CRM_Core_Action::DELETE) { $url = CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1&context={$this->_context}"); } else { $url = CRM_Utils_System::url('civicrm/contact/search/custom', 'force=1'); } } else { $url = CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1"); } if (!$this->_activityId) { $caseTypes = CRM_Case_PseudoConstant::caseType(); if (empty($caseTypes) && $this->_activityTypeName == 'Change Case Type' && !$this->_caseId) { $url = CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); CRM_Core_Error::statusBounce(ts("You do not have any active Case Types")); } // check if activity count is within the limit $xmlProcessor = new CRM_Case_XMLProcessor_Process(); foreach ($this->_caseId as $casePos => $caseId) { $caseType = $this->_caseType[$casePos]; $activityInst = $xmlProcessor->getMaxInstance($caseType); // If not bounce back and also provide activity edit link if (isset($activityInst[$this->_activityTypeName])) { $activityCount = CRM_Case_BAO_Case::getCaseActivityCount($caseId, $this->_activityTypeId); if ($activityCount >= $activityInst[$this->_activityTypeName]) { if ($activityInst[$this->_activityTypeName] == 1) { $atArray = array('activity_type_id' => $this->_activityTypeId); $activities = CRM_Case_BAO_Case::getCaseActivity($caseId, $atArray, $this->_currentUserId); $activities = array_keys($activities); $activities = $activities[0]; $editUrl = CRM_Utils_System::url('civicrm/case/activity', "reset=1&cid={$this->_currentlyViewedContactId}&caseid={$caseId}&action=update&id={$activities}"); } CRM_Core_Error::statusBounce(ts("You can not add another '%1' activity to this case. %2", array(1 => $this->_activityTypeName, 2 => ts("Do you want to <a %1>edit the existing activity</a>?", array(1 => "href='{$editUrl}'")))), $url); } } } } $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); }
/** * This method returns the action links that are given for each search row. * currently the action links added for each row are * * - View * * @param string $activityType type of activity * * @return array * @access public * */ function actionLinks($activityTypeId, $sourceRecordId = null, $accessMailingReport = false, $activityId = null, $key = null, $compContext = null) { $activityTypes = CRM_Core_PseudoConstant::activityType(false); $activityTypeIds = array_flip(CRM_Core_PseudoConstant::activityType(true, true, false, 'name')); $extraParams = $key ? "&key={$key}" : null; if ($compContext) { $extraParams .= "&compContext={$compContext}"; } //show edit link only for meeting/phone and other activities $showUpdate = false; $showDelete = false; if ($activityTypeId == $activityTypeIds['Event Registration']) { // event registration $url = 'civicrm/contact/view/participant'; $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}"; } elseif ($activityTypeId == $activityTypeIds['Contribution']) { //contribution $url = 'civicrm/contact/view/contribution'; $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}"; } elseif (in_array($activityTypeId, array($activityTypeIds['Membership Signup'], $activityTypeIds['Membership Renewal']))) { // membership $url = 'civicrm/contact/view/membership'; $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}"; } elseif ($activityTypeId == CRM_Utils_Array::value('Pledge Acknowledgment', $activityTypeIds) || $activityTypeId == CRM_Utils_Array::value('Pledge Reminder', $activityTypeIds)) { //pledge acknowledgment $url = 'civicrm/contact/view/activity'; $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; } elseif ($activityTypeId == $activityTypeIds['Email'] || $activityTypeId == $activityTypeIds['Bulk Email']) { $url = 'civicrm/activity/view'; $delUrl = 'civicrm/activity'; $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; // allow delete of regular outbound emails (CRM-) if ($activityTypeId == $activityTypeIds['Email']) { $showDelete = true; } } elseif ($activityTypeId == $activityTypeIds['Inbound Email']) { $url = 'civicrm/contact/view/activity'; $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; } elseif ($activityTypeId == CRM_Utils_Array::value('Open Case', $activityTypeIds) || $activityTypeId == CRM_Utils_Array::value('Change Case Type', $activityTypeIds) || $activityTypeId == CRM_Utils_Array::value('Change Case Status', $activityTypeIds) || $activityTypeId == CRM_Utils_Array::value('Change Case Start Date', $activityTypeIds)) { $showUpdate = $showDelete = false; $url = 'civicrm/contact/view/activity'; $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; } else { $showUpdate = $showDelete = true; $url = 'civicrm/contact/view/activity'; $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; } $qsDelete = "atype={$activityTypeId}&action=delete&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; if ($this->_context == 'case') { $qsView .= "&caseid=%%caseid%%"; $qsDelete .= "&caseid=%%caseid%%"; if ($showUpdate) { $qsUpdate .= "&caseid=%%caseid%%"; } } self::$_actionLinks = array(CRM_Core_Action::VIEW => array('name' => ts('View'), 'url' => $url, 'qs' => $qsView, 'title' => ts('View Activity'))); if ($showUpdate) { self::$_actionLinks = self::$_actionLinks + array(CRM_Core_Action::UPDATE => array('name' => ts('Edit'), 'url' => $url, 'qs' => $qsUpdate, 'title' => ts('Update Activity'))); } require_once 'CRM/Case/BAO/Case.php'; if (CRM_Case_BAO_Case::checkPermission($activityId, 'File On Case', $activityTypeId)) { self::$_actionLinks = self::$_actionLinks + array(CRM_Core_Action::ADD => array('name' => ts('File On Case'), 'url' => CRM_Utils_System::currentPath(), 'extra' => 'onClick="Javascript:fileOnCase( \'file\', \'%%id%%\' ); return false;"', 'title' => ts('File On Case'))); } if ($showDelete) { if (!isset($delUrl) || !$delUrl) { $delUrl = $url; } self::$_actionLinks = self::$_actionLinks + array(CRM_Core_Action::DELETE => array('name' => ts('Delete'), 'url' => $delUrl, 'qs' => $qsDelete, 'title' => ts('Delete Activity'))); } if ($this->_context == 'case') { $qsDetach = "atype={$activityTypeId}&action=detach&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%&caseid=%%caseid%%{$extraParams}"; self::$_actionLinks = self::$_actionLinks + array(CRM_Core_Action::DETACH => array('name' => ts('Detach'), 'url' => $url, 'qs' => $qsDetach, 'title' => ts('Detach Activity'))); } if ($accessMailingReport) { self::$_actionLinks = self::$_actionLinks + array(CRM_Core_Action::BROWSE => array('name' => ts('Mailing Report'), 'url' => 'civicrm/mailing/report', 'qs' => "mid={$sourceRecordId}&reset=1&cid=%%cid%%&context=activitySelector", 'title' => ts('View Mailing Report'))); } return self::$_actionLinks; }
public function buildQuickForm() { if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) { //enable form element (ActivityLinks sets this true) $this->assign('suppressForm', FALSE); $button = ts('Delete'); if ($this->_action & CRM_Core_Action::RENEW) { $button = ts('Restore'); } $this->addButtons(array(array('type' => 'next', 'name' => $button, 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if (!$this->_single && !empty($this->_contactIds)) { $withArray = array(); foreach ($this->_contactIds as $contactId) { $withDisplayName = self::_getDisplayNameById($contactId); $withArray[] = "\"{$withDisplayName}\" "; } $this->assign('with', implode(', ', $withArray)); } if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } //build other activity links CRM_Activity_Form_ActivityLinks::commonBuildQuickForm($this); //enable form element (ActivityLinks sets this true) $this->assign('suppressForm', FALSE); $element =& $this->add('select', 'activity_type_id', ts('Activity Type'), $this->_fields['followup_activity_type_id']['attributes'], FALSE, array('onchange' => "CRM.buildCustomData( 'Activity', this.value );", 'class' => 'crm-select2')); //freeze for update mode. if ($this->_action & CRM_Core_Action::UPDATE) { $element->freeze(); } foreach ($this->_fields as $field => $values) { if (!empty($this->_fields[$field])) { $attribute = CRM_Utils_Array::value('attributes', $values); $required = !empty($values['required']); if ($values['type'] == 'wysiwyg') { $this->addWysiwyg($field, $values['label'], $attribute, $required); } elseif ($values['type'] == 'select' && empty($attribute)) { $this->addSelect($field, array(), $required); } elseif ($field != 'source_contact_id') { $this->add($values['type'], $field, $values['label'], $attribute, $required); } } } //CRM-7362 --add campaigns. CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values)); //add engagement level CRM-7775 $buildEngagementLevel = FALSE; if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) { $buildEngagementLevel = TRUE; $this->addSelect('engagement_level'); $this->addRule('engagement_level', ts('Please enter the engagement index as a number (integers only).'), 'positiveInteger'); } $this->assign('buildEngagementLevel', $buildEngagementLevel); // check for survey activity $this->_isSurveyActivity = FALSE; if ($this->_activityId && CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) { $this->_isSurveyActivity = CRM_Campaign_BAO_Survey::isSurveyActivity($this->_activityId); if ($this->_isSurveyActivity) { $surveyId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'source_record_id'); $responseOptions = CRM_Campaign_BAO_Survey::getResponsesOptions($surveyId); if ($responseOptions) { $this->add('select', 'result', ts('Result'), array('' => ts('- select -')) + array_combine($responseOptions, $responseOptions)); } $surveyTitle = NULL; if ($surveyId) { $surveyTitle = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $surveyId, 'title'); } $this->assign('surveyTitle', $surveyTitle); } } $this->assign('surveyActivity', $this->_isSurveyActivity); // this option should be available only during add mode if ($this->_action != CRM_Core_Action::UPDATE) { $this->add('advcheckbox', 'is_multi_activity', ts('Create a separate activity for each contact.')); } $this->addRule('duration', ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger'); $this->addDateTime('activity_date_time', ts('Date'), TRUE, array('formatType' => 'activityDateTime')); //add followup date $this->addDateTime('followup_date', ts('in'), FALSE, array('formatType' => 'activityDateTime')); //tokeninput url $tokenUrl = CRM_Utils_System::url("civicrm/ajax/checkemail", "noemail=1", FALSE, NULL, FALSE); $this->assign('tokenUrl', $tokenUrl); $sourceContactField = $this->addEntityRef('source_contact_id', $this->_fields['source_contact_id']['label'], array(), TRUE); // Only admins and case-workers can change the activity source if (!CRM_Core_Permission::check('administer CiviCRM') && $this->_context != 'caseActivity') { $sourceContactField->freeze(); } CRM_Contact_Form_NewContact::buildQuickForm($this); $this->add('text', 'assignee_contact_id', ts('assignee')); $this->add('text', 'followup_assignee_contact_id', ts('assignee')); //need to assign custom data type and subtype to the template $this->assign('customDataType', 'Activity'); $this->assign('customDataSubType', $this->_activityTypeId); $this->assign('entityID', $this->_activityId); $tags = CRM_Core_BAO_Tag::getTags('civicrm_activity'); if (!empty($tags)) { $this->add('select', 'tag', ts('Tags'), $tags, FALSE, array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2 huge')); } // we need to hide activity tagset for special activities $specialActivities = array('Open Case'); if (!in_array($this->_activityTypeName, $specialActivities)) { // build tag widget $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity'); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_activity', $this->_activityId, TRUE, TRUE); } // if we're viewing, we're assigning different buttons than for adding/editing if ($this->_action & CRM_Core_Action::VIEW) { if (isset($this->_groupTree)) { CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $this->_groupTree); } $buttons = array(); // do check for permissions if (CRM_Case_BAO_Case::checkPermission($this->_activityId, 'File On Case', $this->_activityTypeId)) { $buttons[] = array('type' => 'cancel', 'name' => ts('File on case'), 'subName' => 'file_on_case', 'js' => array('onClick' => "javascript:fileOnCase( \"file\", {$this->_activityId} ); return false;")); } // form should be frozen for view mode $this->freeze(); $buttons[] = array('type' => 'cancel', 'name' => ts('Done')); $this->addButtons($buttons); } else { $message = array('completed' => ts('Are you sure? This is a COMPLETED activity with the DATE in the FUTURE. Click Cancel to change the date / status. Otherwise, click OK to save.'), 'scheduled' => ts('Are you sure? This is a SCHEDULED activity with the DATE in the PAST. Click Cancel to change the date / status. Otherwise, click OK to save.')); $js = array('onclick' => "return activityStatus(" . json_encode($message) . ");"); $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => $js, 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); } if ($this->_activityTypeFile) { $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}"; $className::buildQuickForm($this); $this->addFormRule(array($className, 'formRule'), $this); } $this->addFormRule(array('CRM_Activity_Form_Activity', 'formRule'), $this); if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) { $this->assign('activityAssigneeNotification', TRUE); } else { $this->assign('activityAssigneeNotification', FALSE); } }
/** * This method returns the action links that are given for each search row. * currently the action links added for each row are * * - View * * @param int $activityTypeId * @param int $sourceRecordId * @param bool $accessMailingReport * @param int $activityId * @param null $key * @param null $compContext * * @return array */ public static function actionLinks($activityTypeId, $sourceRecordId = NULL, $accessMailingReport = FALSE, $activityId = NULL, $key = NULL, $compContext = NULL) { static $activityActTypes = NULL; //CRM-14277 added addtitional param to handle activity search $extraParams = "&searchContext=activity"; $extraParams .= $key ? "&key={$key}" : NULL; if ($compContext) { $extraParams .= "&compContext={$compContext}"; } $showView = TRUE; $showUpdate = $showDelete = FALSE; $qsUpdate = NULL; if (!$activityActTypes) { $activeActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name', TRUE); } $activityTypeName = CRM_Utils_Array::value($activityTypeId, $activeActTypes); // CRM-7607 // Lets allow to have normal operation for only activity types. // When activity type is disabled or no more exists give only delete. switch ($activityTypeName) { case 'Event Registration': case 'Change Registration': $url = 'civicrm/contact/view/participant'; $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}"; break; case 'Contribution': $url = 'civicrm/contact/view/contribution'; $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}"; break; case 'Payment': case 'Refund': $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $sourceRecordId, 'participant_id', 'contribution_id'); if (!empty($participantId)) { $url = 'civicrm/contact/view/participant'; $qsView = "action=view&reset=1&id={$participantId}&cid=%%cid%%&context=%%cxt%%{$extraParams}"; } break; case 'Membership Signup': case 'Membership Renewal': case 'Change Membership Status': case 'Change Membership Type': $url = 'civicrm/contact/view/membership'; $qsView = "action=view&reset=1&id={$sourceRecordId}&cid=%%cid%%&context=%%cxt%%{$extraParams}"; break; case 'Pledge Reminder': case 'Pledge Acknowledgment': $url = 'civicrm/contact/view/activity'; $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; break; case 'Email': case 'Bulk Email': $url = 'civicrm/activity/view'; $delUrl = 'civicrm/activity'; $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; if ($activityTypeName == 'Email') { $showDelete = TRUE; } break; case 'Inbound Email': $url = 'civicrm/contact/view/activity'; $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; break; case 'Open Case': case 'Change Case Type': case 'Change Case Status': case 'Change Case Start Date': $showUpdate = $showDelete = FALSE; $url = 'civicrm/activity'; $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; break; default: $url = 'civicrm/activity'; $showView = $showDelete = $showUpdate = TRUE; $qsView = "atype={$activityTypeId}&action=view&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; $qsUpdate = "atype={$activityTypeId}&action=update&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; // When type is not available lets hide view and update. if (empty($activityTypeName)) { $showView = $showUpdate = FALSE; } break; } $qsDelete = "atype={$activityTypeId}&action=delete&reset=1&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}"; $actionLinks = array(); if ($showView) { $actionLinks += array(CRM_Core_Action::VIEW => array('name' => ts('View'), 'url' => $url, 'qs' => $qsView, 'title' => ts('View Activity'))); } if ($showUpdate) { $updateUrl = 'civicrm/activity/add'; if ($activityTypeName == 'Email') { $updateUrl = 'civicrm/activity/email/add'; } elseif ($activityTypeName == 'Print PDF Letter') { $updateUrl = 'civicrm/activity/pdf/add'; } if (CRM_Activity_BAO_Activity::checkPermission($activityId, CRM_Core_Action::UPDATE)) { $actionLinks += array(CRM_Core_Action::UPDATE => array('name' => ts('Edit'), 'url' => $updateUrl, 'qs' => $qsUpdate, 'title' => ts('Update Activity'))); } } if ($activityTypeName && CRM_Case_BAO_Case::checkPermission($activityId, 'File On Case', $activityTypeId)) { $actionLinks += array(CRM_Core_Action::ADD => array('name' => ts('File on Case'), 'url' => '#', 'extra' => 'onclick="javascript:fileOnCase( \'file\', \'%%id%%\', null, this ); return false;"', 'title' => ts('File on Case'))); } if ($showDelete) { if (!isset($delUrl) || !$delUrl) { $delUrl = $url; } $actionLinks += array(CRM_Core_Action::DELETE => array('name' => ts('Delete'), 'url' => $delUrl, 'qs' => $qsDelete, 'title' => ts('Delete Activity'))); } if ($accessMailingReport) { $actionLinks += array(CRM_Core_Action::BROWSE => array('name' => ts('Mailing Report'), 'url' => 'civicrm/mailing/report', 'qs' => "mid={$sourceRecordId}&reset=1&cid=%%cid%%&context=activitySelector", 'title' => ts('View Mailing Report'))); } return $actionLinks; }
public function buildQuickForm() { if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) { //enable form element (ActivityLinks sets this true) $this->assign('suppressForm', false); $button = ts('Delete'); if ($this->_action & CRM_Core_Action::RENEW) { $button = ts('Restore'); } $this->addButtons(array(array('type' => 'next', 'name' => $button, 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if (!$this->_single && !empty($this->_contactIds)) { $withArray = array(); require_once 'CRM/Contact/BAO/Contact.php'; foreach ($this->_contactIds as $contactId) { $withDisplayName = self::_getDisplayNameById($contactId); $withArray[] = "\"{$withDisplayName}\" "; } $this->assign('with', implode(', ', $withArray)); } if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } //build other activity links require_once 'CRM/Activity/Form/ActivityLinks.php'; CRM_Activity_Form_ActivityLinks::buildQuickForm(); //enable form element (ActivityLinks sets this true) $this->assign('suppressForm', false); $element =& $this->add('select', 'activity_type_id', ts('Activity Type'), $this->_fields['followup_activity_type_id']['attributes'], false, array('onchange' => "buildCustomData( 'Activity', this.value );")); //freeze for update mode. if ($this->_action & CRM_Core_Action::UPDATE) { $element->freeze(); } foreach ($this->_fields as $field => $values) { if (CRM_Utils_Array::value($field, $this->_fields)) { $attribute = null; if (CRM_Utils_Array::value('attributes', $values)) { $attribute = $values['attributes']; } $required = false; if (CRM_Utils_Array::value('required', $values)) { $required = true; } if ($values['type'] == 'wysiwyg') { $this->addWysiwyg($field, $values['label'], $attribute, $required); } else { $this->add($values['type'], $field, $values['label'], $attribute, $required); } } } $this->addRule('duration', ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger'); $this->addRule('interval', ts('Please enter the follow-up interval as a number (integers only).'), 'positiveInteger'); $this->addDateTime('activity_date_time', ts('Date'), true, array('formatType' => 'activityDateTime')); //autocomplete url $dataUrl = CRM_Utils_System::url("civicrm/ajax/rest", "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=activity&reset=1", false, null, false); $this->assign('dataUrl', $dataUrl); //tokeninput url $tokenUrl = CRM_Utils_System::url("civicrm/ajax/checkemail", "noemail=1", false, null, false); $this->assign('tokenUrl', $tokenUrl); $admin = CRM_Core_Permission::check('administer CiviCRM'); //allow to edit sourcecontactfield field if context is civicase. if ($this->_context == 'caseActivity') { $admin = true; } $this->assign('admin', $admin); $sourceContactField =& $this->add($this->_fields['source_contact_id']['type'], 'source_contact_id', $this->_fields['source_contact_id']['label'], null, $admin); $hiddenSourceContactField =& $this->add('hidden', 'source_contact_qid', '', array('id' => 'source_contact_qid')); $targetContactField =& $this->add('text', 'target_contact_id', ts('target')); $assigneeContactField =& $this->add('text', 'assignee_contact_id', ts('assignee')); if ($sourceContactField->getValue()) { $this->assign('source_contact', $sourceContactField->getValue()); } else { if ($this->_currentUserId) { // we're setting currently LOGGED IN user as source for this activity $this->assign('source_contact_value', self::_getDisplayNameById($this->_currentUserId)); } } //need to assign custom data type and subtype to the template $this->assign('customDataType', 'Activity'); $this->assign('customDataSubType', $this->_activityTypeId); $this->assign('entityID', $this->_activityId); if ($this->_targetContactId) { $defaultTargetContactName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_targetContactId, 'sort_name'); $this->assign('target_contact_value', $defaultTargetContactName); } require_once 'CRM/Core/BAO/Tag.php'; $tags = CRM_Core_BAO_Tag::getTags('civicrm_activity'); if (!empty($tags)) { $this->add('select', 'tag', ts('Tags'), $tags, false, array('id' => 'tags', 'multiple' => 'multiple', 'title' => ts('- select -'))); } // build tag widget require_once 'CRM/Core/Form/Tag.php'; $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity'); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_activity', $this->_activityId, false, true); // check for survey activity $this->_isSurveyActivity = false; if ($this->_activityId) { require_once 'CRM/Campaign/BAO/Survey.php'; $this->_isSurveyActivity = CRM_Campaign_BAO_Survey::isSurveyActivity($this->_activityId); if ($this->_isSurveyActivity) { $surveyId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'source_record_id'); $responseOptions = CRM_Campaign_BAO_Survey::getResponsesOptions($surveyId); if ($responseOptions) { $this->add('select', 'result', ts('Result'), array('' => ts('- select -')) + array_combine($responseOptions, $responseOptions)); } $surveyTitle = null; if ($surveyId) { $surveyTitle = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $surveyId, 'title'); } $this->assign('surveyTitle', $surveyTitle); } } $this->assign('surveyActivity', $this->_isSurveyActivity); // if we're viewing, we're assigning different buttons than for adding/editing if ($this->_action & CRM_Core_Action::VIEW) { if (isset($this->_groupTree)) { CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $this->_groupTree); } $buttons = array(); // do check for permissions require_once 'CRM/Case/BAO/Case.php'; if (CRM_Case_BAO_Case::checkPermission($this->_activityId, 'File On Case', $this->_activityTypeId)) { $buttons[] = array('type' => 'cancel', 'name' => ts('File on case'), 'subName' => 'file_on_case', 'js' => array('onClick' => "Javascript:fileOnCase( \"file\", {$this->_activityId} ); return false;")); } // form should be frozen for view mode $this->freeze(); $buttons[] = array('type' => 'cancel', 'name' => ts('Done')); $this->addButtons($buttons); } else { $message = array('completed' => ts('Are you sure? This is a COMPLETED activity with the DATE in the FUTURE. Click Cancel to change the date / status. Otherwise, click OK to save.'), 'scheduled' => ts('Are you sure? This is a SCHEDULED activity with the DATE in the PAST. Click Cancel to change the date / status. Otherwise, click OK to save.')); $js = array('onclick' => "return activityStatus(" . json_encode($message) . ");"); $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => $js, 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); } if ($this->_activityTypeFile) { eval("CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}::buildQuickForm( \$this );"); } if ($this->_activityTypeFile) { eval('$this->addFormRule' . "(array('CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}', 'formrule'), \$this);"); } $this->addFormRule(array('CRM_Activity_Form_Activity', 'formRule'), $this); }
/** * Does user has sufficient permission for view/edit activity record. * * @param int $activityId activity record id. * @param int $action edit/view * * @return boolean $allow true/false * @access public */ public function checkPermission($activityId, $action) { $allow = false; if (!$activityId || !in_array($action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW))) { return $allow; } $activity = new CRM_Activity_DAO_Activity(); $activity->id = $activityId; if (!$activity->find(true)) { return $allow; } //component related permissions. $compPermissions = array('CiviCase' => array('administer CiviCase', 'access my cases and activities', 'access all cases and activities'), 'CiviMail' => array('access CiviMail'), 'CiviEvent' => array('access CiviEvent'), 'CiviGrant' => array('access CiviGrant'), 'CiviPledge' => array('access CiviPledge'), 'CiviMember' => array('access CiviMember'), 'CiviReport' => array('access CiviReport'), 'CiviContribute' => array('access CiviContribute'), 'CiviCampaign' => array('administer CiviCampaign')); //return early when it is case activity. require_once 'CRM/Case/BAO/Case.php'; $isCaseActivity = CRM_Case_BAO_Case::isCaseActivity($activityId); //check for civicase related permission. if ($isCaseActivity) { $allow = false; foreach ($compPermissions['CiviCase'] as $per) { if (CRM_Core_Permission::check($per)) { $allow = true; break; } } //check for case specific permissions. if ($allow) { $oper = 'view'; if ($action == CRM_Core_Action::UPDATE) { $oper = 'edit'; } $allow = CRM_Case_BAO_Case::checkPermission($activityId, $oper, $activity->activity_type_id); } return $allow; } require_once 'CRM/Core/Permission.php'; require_once 'CRM/Contact/BAO/Contact/Permission.php'; //first check the component permission. $sql = "\n SELECT component_id\n FROM civicrm_option_value val\nINNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.name = %1 )\n WHERE val.value = %2"; $params = array(1 => array('activity_type', 'String'), 2 => array($activity->activity_type_id, 'Integer')); $componentId = CRM_Core_DAO::singleValueQuery($sql, $params); if ($componentId) { require_once 'CRM/Core/Component.php'; $componentName = CRM_Core_Component::getComponentName($componentId); $compPermission = CRM_Utils_Array::value($componentName, $compPermissions); //here we are interesting in any single permission. if (is_array($compPermission)) { foreach ($compPermission as $per) { if (CRM_Core_Permission::check($per)) { $allow = true; break; } } } } //check for this permission related to contact. $permission = CRM_Core_Permission::VIEW; if ($action == CRM_Core_Action::UPDATE) { $permission = CRM_Core_Permission::EDIT; } //check for source contact. if (!$componentId || $allow) { $allow = CRM_Contact_BAO_Contact_Permission::allow($activity->source_contact_id, $permission); } //check for target and assignee contacts. if ($allow) { //first check for supper permission. $supPermission = 'view all contacts'; if ($action == CRM_Core_Action::UPDATE) { $supPermission = 'edit all contacts'; } $allow = CRM_Core_Permission::check($supPermission); //user might have sufficient permission, through acls. if (!$allow) { $allow = true; //get the target contacts. $targetContacts = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activity->id); foreach ($targetContacts as $cnt => $contactId) { if (!CRM_Contact_BAO_Contact_Permission::allow($contactId, $permission)) { $allow = false; break; } } //get the assignee contacts. if ($allow) { $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($activity->id); foreach ($assigneeContacts as $cnt => $contactId) { if (!CRM_Contact_BAO_Contact_Permission::allow($contactId, $permission)) { $allow = false; break; } } } } } return $allow; }