Esempio n. 1
0
 /**
  * Validate contact permission for
  * given operation on activity record.
  *
  * @param int $activityId      activity record id.
  * @param string $operation       user operation.
  * @param int $actTypeId       activity type id.
  * @param int $contactId       contact id/if not pass consider logged in
  * @param boolean $checkComponent  do we need to check component enabled.
  *
  * @return boolean $allow  true/false
  * @static
  */
 static function checkPermission($activityId, $operation, $actTypeId = NULL, $contactId = NULL, $checkComponent = TRUE)
 {
     $allow = FALSE;
     if (!$actTypeId && $activityId) {
         $actTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityId, 'activity_type_id');
     }
     if (!$activityId || !$operation || !$actTypeId) {
         return $allow;
     }
     //do check for civicase component enabled.
     if ($checkComponent) {
         static $componentEnabled;
         if (!isset($componentEnabled)) {
             $config = CRM_Core_Config::singleton();
             $componentEnabled = FALSE;
             if (in_array('CiviCase', $config->enableComponents)) {
                 $componentEnabled = TRUE;
             }
         }
         if (!$componentEnabled) {
             return $allow;
         }
     }
     //do check for cases.
     $caseActOperations = array('File On Case', 'Link Cases', 'Move To Case', 'Copy To Case');
     if (in_array($operation, $caseActOperations)) {
         static $unclosedCases;
         if (!is_array($unclosedCases)) {
             $unclosedCases = self::getUnclosedCases();
         }
         if ($operation == 'File On Case') {
             $allow = empty($unclosedCases) ? FALSE : TRUE;
         } else {
             $allow = count($unclosedCases) > 1 ? TRUE : FALSE;
         }
     }
     $actionOperations = array('view', 'edit', 'delete');
     if (in_array($operation, $actionOperations)) {
         //do cache when user has non/supper permission.
         static $allowOperations;
         if (!is_array($allowOperations) || !array_key_exists($operation, $allowOperations)) {
             if (!$contactId) {
                 $session = CRM_Core_Session::singleton();
                 $contactId = $session->get('userID');
             }
             //check for permissions.
             $permissions = array('view' => array('access my cases and activities', 'access all cases and activities'), 'edit' => array('access my cases and activities', 'access all cases and activities'), 'delete' => array('delete activities'));
             //check for core permission.
             $hasPermissions = array();
             $checkPermissions = CRM_Utils_Array::value($operation, $permissions);
             if (is_array($checkPermissions)) {
                 foreach ($checkPermissions as $per) {
                     if (CRM_Core_Permission::check($per)) {
                         $hasPermissions[$operation][] = $per;
                     }
                 }
             }
             //has permissions.
             if (!empty($hasPermissions)) {
                 //need to check activity object specific.
                 if (in_array($operation, array('view', 'edit'))) {
                     //do we have supper permission.
                     if (in_array('access all cases and activities', $hasPermissions[$operation])) {
                         $allowOperations[$operation] = $allow = TRUE;
                     } else {
                         //user has only access to my cases and activity.
                         //here object specific permmions come in picture.
                         //edit - contact must be source or assignee
                         //view - contact must be source/assignee/target
                         $isTarget = $isAssignee = $isSource = FALSE;
                         $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);
                         $target = new CRM_Activity_DAO_ActivityContact();
                         $target->record_type_id = $targetID;
                         $target->activity_id = $activityId;
                         $target->contact_id = $contactId;
                         if ($target->find(TRUE)) {
                             $isTarget = TRUE;
                         }
                         $assignee = new CRM_Activity_DAO_ActivityContact();
                         $assignee->activity_id = $activityId;
                         $assignee->record_type_id = $assigneeID;
                         $assignee->contact_id = $contactId;
                         if ($assignee->find(TRUE)) {
                             $isAssignee = TRUE;
                         }
                         $source = new CRM_Activity_DAO_ActivityContact();
                         $source->activity_id = $activityId;
                         $source->record_type_id = $sourceID;
                         $source->contact_id = $contactId;
                         if ($source->find(TRUE)) {
                             $isSource = TRUE;
                         }
                         if ($operation == 'edit') {
                             if ($isAssignee || $isSource) {
                                 $allow = TRUE;
                             }
                         }
                         if ($operation == 'view') {
                             if ($isTarget || $isAssignee || $isSource) {
                                 $allow = TRUE;
                             }
                         }
                     }
                 } elseif (is_array($hasPermissions[$operation])) {
                     $allowOperations[$operation] = $allow = TRUE;
                 }
             } else {
                 //contact do not have permission.
                 $allowOperations[$operation] = FALSE;
             }
         } else {
             //use cache.
             //here contact might have supper/non permission.
             $allow = $allowOperations[$operation];
         }
     }
     //do further only when operation is granted.
     if ($allow) {
         $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name');
         //get the activity type name.
         $actTypeName = CRM_Utils_Array::value($actTypeId, $activityTypes);
         //do not allow multiple copy / edit action.
         $singletonNames = array('Open Case', 'Reassigned Case', 'Merge Case', 'Link Cases', 'Assign Case Role', 'Email', 'Inbound Email');
         //do not allow to delete these activities, CRM-4543
         $doNotDeleteNames = array('Open Case', 'Change Case Type', 'Change Case Status', 'Change Case Start Date');
         //allow edit operation.
         $allowEditNames = array('Open Case');
         // do not allow File on Case
         $doNotFileNames = array('Open Case', 'Change Case Type', 'Change Case Status', 'Change Case Start Date', 'Reassigned Case', 'Merge Case', 'Link Cases', 'Assign Case Role');
         if (in_array($actTypeName, $singletonNames)) {
             $allow = FALSE;
             if ($operation == 'File On Case') {
                 $allow = in_array($actTypeName, $doNotFileNames) ? FALSE : TRUE;
             }
             if (in_array($operation, $actionOperations)) {
                 $allow = TRUE;
                 if ($operation == 'edit') {
                     $allow = in_array($actTypeName, $allowEditNames) ? TRUE : FALSE;
                 } elseif ($operation == 'delete') {
                     $allow = in_array($actTypeName, $doNotDeleteNames) ? FALSE : TRUE;
                 }
             }
         }
         if ($allow && $operation == 'delete' && in_array($actTypeName, $doNotDeleteNames)) {
             $allow = FALSE;
         }
         if ($allow && $operation == 'File On Case' && in_array($actTypeName, $doNotFileNames)) {
             $allow = FALSE;
         }
         //check settings file for masking actions
         //on the basis the activity types
         //hide Edit link if activity type is NOT editable
         //(special case activities).CRM-5871
         if ($allow && in_array($operation, $actionOperations)) {
             static $actionFilter = array();
             if (!array_key_exists($operation, $actionFilter)) {
                 $xmlProcessor = new CRM_Case_XMLProcessor_Process();
                 $actionFilter[$operation] = $xmlProcessor->get('Settings', 'ActivityTypes', FALSE, $operation);
             }
             if (array_key_exists($operation, $actionFilter[$operation]) && in_array($actTypeId, $actionFilter[$operation][$operation])) {
                 $allow = FALSE;
             }
         }
     }
     return $allow;
 }
Esempio n. 2
0
 function printCaseReport()
 {
     $caseID = CRM_Utils_Request::retrieve('caseID', 'Positive', CRM_Core_DAO::$_nullObject);
     $clientID = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject);
     $activitySetName = CRM_Utils_Request::retrieve('asn', 'String', CRM_Core_DAO::$_nullObject);
     $isRedact = CRM_Utils_Request::retrieve('redact', 'Boolean', CRM_Core_DAO::$_nullObject);
     $includeActivities = CRM_Utils_Request::retrieve('all', 'Positive', CRM_Core_DAO::$_nullObject);
     $params = $otherRelationships = $globalGroupInfo = array();
     $report = new CRM_Case_XMLProcessor_Report($isRedact);
     if ($includeActivities) {
         $params['include_activities'] = 1;
     }
     if ($isRedact) {
         $params['is_redact'] = 1;
         $report->_redactionStringRules = array();
     }
     $template = CRM_Core_Smarty::singleton();
     //get case related relationships (Case Role)
     $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($clientID, $caseID);
     $caseType = CRM_Case_BAO_Case::getCaseType($caseID, 'name');
     $xmlProcessor = new CRM_Case_XMLProcessor_Process();
     $caseRoles = $xmlProcessor->get($caseType, 'CaseRoles');
     foreach ($caseRelationships as $key => &$value) {
         if (!empty($caseRoles[$value['relation_type']])) {
             unset($caseRoles[$value['relation_type']]);
         }
         if ($isRedact) {
             if (!array_key_exists($value['name'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['name'] => 'name_' . rand(10000, 100000)));
             }
             $value['name'] = self::redact($value['name'], TRUE, $report->_redactionStringRules);
             if (!empty($value['email']) && !array_key_exists($value['email'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['email'] => 'email_' . rand(10000, 100000)));
             }
             $value['email'] = self::redact($value['email'], TRUE, $report->_redactionStringRules);
             if (!empty($value['phone']) && !array_key_exists($value['phone'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['phone'] => 'phone_' . rand(10000, 100000)));
             }
             $value['phone'] = self::redact($value['phone'], TRUE, $report->_redactionStringRules);
         }
     }
     $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID);
     if ($isRedact) {
         if (!array_key_exists($caseRoles['client']['sort_name'], $report->_redactionStringRules)) {
             $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['sort_name'] => 'name_' . rand(10000, 100000)));
         }
         if (!array_key_exists($caseRoles['client']['display_name'], $report->_redactionStringRules)) {
             $report->_redactionStringRules[$caseRoles['client']['display_name']] = $report->_redactionStringRules[$caseRoles['client']['sort_name']];
         }
         $caseRoles['client']['sort_name'] = self::redact($caseRoles['client']['sort_name'], TRUE, $report->_redactionStringRules);
         if (!empty($caseRoles['client']['email']) && !array_key_exists($caseRoles['client']['email'], $report->_redactionStringRules)) {
             $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['email'] => 'email_' . rand(10000, 100000)));
         }
         $caseRoles['client']['email'] = self::redact($caseRoles['client']['email'], TRUE, $report->_redactionStringRules);
         if (!empty($caseRoles['client']['phone']) && !array_key_exists($caseRoles['client']['phone'], $report->_redactionStringRules)) {
             $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['phone'] => 'phone_' . rand(10000, 100000)));
         }
         $caseRoles['client']['phone'] = self::redact($caseRoles['client']['phone'], TRUE, $report->_redactionStringRules);
     }
     // Retrieve ALL client relationships
     $relClient = CRM_Contact_BAO_Relationship::getRelationship($clientID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, NULL, NULL, FALSE);
     foreach ($relClient as $r) {
         if ($isRedact) {
             if (!array_key_exists($r['name'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['name'] => 'name_' . rand(10000, 100000)));
             }
             if (!array_key_exists($r['display_name'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules[$r['display_name']] = $report->_redactionStringRules[$r['name']];
             }
             $r['name'] = self::redact($r['name'], TRUE, $report->_redactionStringRules);
             if (!empty($r['phone']) && !array_key_exists($r['phone'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['phone'] => 'phone_' . rand(10000, 100000)));
             }
             $r['phone'] = self::redact($r['phone'], TRUE, $report->_redactionStringRules);
             if (!empty($r['email']) && !array_key_exists($r['email'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['email'] => 'email_' . rand(10000, 100000)));
             }
             $r['email'] = self::redact($r['email'], TRUE, $report->_redactionStringRules);
         }
         if (!array_key_exists($r['id'], $caseRelationships)) {
             $otherRelationships[] = $r;
         }
     }
     // Now global contact list that appears on all cases.
     $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo);
     foreach ($relGlobal as &$r) {
         if ($isRedact) {
             if (!array_key_exists($r['sort_name'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['sort_name'] => 'name_' . rand(10000, 100000)));
             }
             if (!array_key_exists($r['display_name'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules[$r['display_name']] = $report->_redactionStringRules[$r['sort_name']];
             }
             $r['sort_name'] = self::redact($r['sort_name'], TRUE, $report->_redactionStringRules);
             if (!empty($r['phone']) && !array_key_exists($r['phone'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['phone'] => 'phone_' . rand(10000, 100000)));
             }
             $r['phone'] = self::redact($r['phone'], TRUE, $report->_redactionStringRules);
             if (!empty($r['email']) && !array_key_exists($r['email'], $report->_redactionStringRules)) {
                 $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['email'] => 'email_' . rand(10000, 100000)));
             }
             $r['email'] = self::redact($r['email'], TRUE, $report->_redactionStringRules);
         }
     }
     $template->assign('caseRelationships', $caseRelationships);
     $template->assign('caseRoles', $caseRoles);
     $template->assign('otherRelationships', $otherRelationships);
     $template->assign('globalRelationships', $relGlobal);
     $template->assign('globalGroupInfo', $globalGroupInfo);
     $contents = self::getCaseReport($clientID, $caseID, $activitySetName, $params, $report);
     $printReport = CRM_Case_Audit_Audit::run($contents, $clientID, $caseID, TRUE);
     echo $printReport;
     CRM_Utils_System::civiExit();
 }
Esempio n. 3
0
 function addVacancies($cid)
 {
     //sample data for HRRecruitment table
     $grpParams['name'] = 'vacancy_status';
     $optionValues = $vacancyPermissionContactIds = array();
     $caseStatuses = CRM_Core_OptionGroup::values('case_status', FALSE, FALSE, FALSE, " AND grouping = 'Vacancy'");
     $vacancyStatuses = CRM_Core_OptionGroup::values('vacancy_status');
     //Filterout Rejected and Cancelled status while creating vacancy
     foreach (array('Cancelled', 'Rejected') as $status) {
         $key = array_search($status, $vacancyStatuses);
         unset($vacancyStatuses[$key]);
     }
     $totalcount = 6;
     $setNewVacancy = FALSE;
     $templatePosition = array();
     $randomVacancies = $this->randomVacancy();
     for ($i = 1; $i <= $totalcount; $i++) {
         $jobCount = mt_rand(0, 2);
         $position = $randomVacancies[$jobCount]['position'];
         $vacanciesValues = array('salary' => $randomVacancies[$jobCount]['salary'], 'position' => $position, 'description' => $this->randomItem('vacancydescription'), 'benefits' => $randomVacancies[$jobCount]['benefits'], 'requirements' => $randomVacancies[$jobCount]['requirements'], 'location' => $this->randomItem('location'), 'is_template' => mt_rand(0, 1), 'status_id' => array_rand($vacancyStatuses, 1), 'start_date' => $this->randomDate('20130701', '20140101', 'YmdHis'), 'end_date' => $this->randomDate('20140102', '20151231', 'YmdHis'), 'created_id' => $cid, 'created_date' => $this->randomDate());
         if ($vacanciesValues['is_template'] == 1) {
             unset($vacanciesValues['status_id']);
             if (array_key_exists($position, $templatePosition)) {
                 //always create distict template
                 continue;
             }
             $templatePosition[$position] = NULL;
         } else {
             $setNewVacancy = TRUE;
         }
         //ensure that atleast there is one vacancy not all template
         if (!$setNewVacancy && $i == $totalcount) {
             $totalcount++;
         }
         $hrVacancies[] = $this->insertVacancyData('CRM_HRRecruitment_DAO_HRVacancy', $vacanciesValues);
     }
     //There are 6 sample Vacancies created, next is to create Entities - VacancyStage, VacancyPermission, Cases
     foreach ($hrVacancies as $key => $hrVacanciesObj) {
         $selectedCaseStatuses = array();
         $lastSelectedCaseStatus = NULL;
         $randCaseStatus = $caseStatuses;
         //Igonre Apply and Hired statuses while removing random status
         $ignoreCaseStatus = array(array_search('Apply', $randCaseStatus), array_search('Hired', $randCaseStatus));
         for ($i = 1; $i <= mt_rand(1, 6); $i++) {
             $randomValue = array_rand($randCaseStatus, 1);
             if (in_array($randomValue, $ignoreCaseStatus)) {
                 continue;
             }
             unset($randCaseStatus[$randomValue]);
         }
         $count = 1;
         foreach ($randCaseStatus as $caseStatus => $dontCare) {
             $vacancyStagesValues = array('case_status_id' => $caseStatus, 'vacancy_id' => $hrVacanciesObj->id, 'weight' => $count);
             $count++;
             $this->insertVacancyData('CRM_HRRecruitment_DAO_HRVacancyStage', $vacancyStagesValues);
         }
         //sample data for HRPermission table
         $vacancyPermissionContactIds[$hrVacanciesObj->id][] = $hrVacanciesObj->created_id;
         for ($i = 1; $i <= mt_rand(1, 4); $i++) {
             $vacancyPermissionValues = array('contact_id' => $this->randomContact(), 'vacancy_id' => $hrVacanciesObj->id, 'permission' => $this->randomItem('permission'));
             if ($vacancyPermissionValues['permission'] == 'manage Applicants' || $vacancyPermissionValues['permission'] == 'administer Vacancy') {
                 $vacancyPermissionContactIds[$hrVacanciesObj->id][] = $vacancyPermissionValues['contact_id'];
             }
             $this->insertVacancyData('CRM_HRRecruitment_DAO_HRVacancyPermission', $vacancyPermissionValues);
         }
         foreach (array('application_profile', 'evaluation_profile') as $profileName) {
             $ufgID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileName, 'id', 'name');
             $vacancyUFJoinValues = array('module' => 'Vacancy', 'entity_id' => $hrVacanciesObj->id, 'entity_table' => 'civicrm_hrvacancy', 'uf_group_id' => $ufgID, 'module_data' => $profileName);
             $this->insertVacancyData('CRM_Core_DAO_UFJoin', $vacancyUFJoinValues);
             $caseTypes = CRM_Case_PseudoConstant::caseType('name', 1, 'AND filter = 1');
             if (!$hrVacanciesObj->is_template) {
                 for ($i = 1; $i <= mt_rand(1, 4); $i++) {
                     $applicantID = $this->randomContact();
                     $caseParams['case_type_id'] = CRM_Utils_Array::key('Application', $caseTypes);
                     $caseParams['start_date'] = $this->randomDate($hrVacanciesObj->start_date, $hrVacanciesObj->end_date);
                     $caseParams['status_id'] = array_rand($randCaseStatus, 1);
                     $caseObj = CRM_Case_BAO_Case::create($caseParams);
                     $contactParams = array('case_id' => $caseObj->id, 'contact_id' => $applicantID);
                     CRM_Case_BAO_Case::addCaseToContact($contactParams);
                     $xmlProcessor = new CRM_Case_XMLProcessor_Process();
                     $xmlProcessorParams = array('clientID' => $applicantID, 'creatorID' => $cid, 'standardTimeline' => 1, 'activityTypeName' => 'Open Case', 'caseID' => $caseObj->id, 'activity_date_time' => $caseParams['start_date']);
                     $xmlProcessor->run('Application', $xmlProcessorParams);
                     $aTypes = $xmlProcessor->get('Application', 'ActivityTypes');
                     $aTypes = array_rand(array_flip($aTypes), mt_rand(2, 5));
                     foreach ($aTypes as $aType) {
                         if (in_array($aType, array('Open Case', 'Assign Case Role', 'Link Cases'))) {
                             continue;
                         }
                         $index = array_rand($vacancyPermissionContactIds[$hrVacanciesObj->id], 1);
                         $aParam = array('source_contact_id' => $vacancyPermissionContactIds[$hrVacanciesObj->id][$index], 'activity_date_time' => $this->randomDate($hrVacanciesObj->start_date, $hrVacanciesObj->end_date, 'YmdHis'), 'activity_type_id' => $aType, 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'));
                         if ($aType == 'Change Case Status') {
                             $aParam['last_status'] = $caseStatuses[$caseObj->status_id];
                             $caseObj->status_id = array_rand($caseStatuses, 1);
                             $caseObj->save();
                             $aParam['new_status'] = $caseStatuses[$caseObj->status_id];
                         }
                         $this->addActivityParamByType($aType, $aParam);
                         $result = civicrm_api3('Activity', 'create', $aParam);
                         $caseActivityParams = array('case_id' => $caseObj->id, 'activity_id' => $result['id']);
                         CRM_Case_BAO_Case::processCaseActivity($caseActivityParams);
                     }
                     $cgID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', 'application_case', 'id', 'name');
                     $result = civicrm_api3('CustomField', 'get', array('custom_group_id' => $cgID, 'name' => 'vacancy_id'));
                     civicrm_api3('custom_value', 'create', array("custom_{$result['id']}" => $hrVacanciesObj->id, 'entity_id' => $caseObj->id));
                 }
             }
         }
     }
 }
Esempio n. 4
0
 public function buildQuickForm()
 {
     $this->_fields['source_contact_id']['label'] = ts('Reported By');
     unset($this->_fields['status_id']['attributes']['required']);
     if ($this->_caseType) {
         $xmlProcessor = new CRM_Case_XMLProcessor_Process();
         $aTypes = array();
         foreach ($this->_caseType as $key => $val) {
             $activityTypes = $xmlProcessor->get($val, 'ActivityTypes', TRUE);
             $aTypes = $aTypes + $activityTypes;
         }
         // remove Open Case activity type since we're inside an existing case
         $openCaseID = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name');
         unset($aTypes[$openCaseID]);
         asort($aTypes);
         $this->_fields['followup_activity_type_id']['attributes'] = array('' => '- select activity type -') + $aTypes;
     }
     $result = parent::buildQuickForm();
     if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::DETACH | CRM_Core_Action::RENEW)) {
         return;
     }
     $this->assign('urlPath', 'civicrm/case/activity');
     $encounterMediums = CRM_Case_PseudoConstant::encounterMedium();
     // Fixme: what's the justification for this? It seems like it is just re-adding an option in case it is the default and disabled.
     // Is that really a big problem?
     if ($this->_activityTypeFile == 'OpenCase') {
         $this->_encounterMedium = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'medium_id');
         if (!array_key_exists($this->_encounterMedium, $encounterMediums)) {
             $encounterMediums[$this->_encounterMedium] = CRM_Core_OptionGroup::getLabel('encounter_medium', $this->_encounterMedium, FALSE);
         }
     }
     $this->add('select', 'medium_id', ts('Medium'), $encounterMediums, TRUE);
     $i = 0;
     foreach ($this->_caseId as $key => $val) {
         $this->_relatedContacts[] = $rgc = CRM_Case_BAO_Case::getRelatedAndGlobalContacts($val);
         $contName = CRM_Case_BAO_Case::getContactNames($val);
         foreach ($contName as $nkey => $nval) {
             array_push($this->_relatedContacts[$i][0], $this->_relatedContacts[$i][0]['managerOf'] = $nval['display_name']);
         }
         $i++;
     }
     //add case client in send a copy selector.CRM-4438.
     foreach ($this->_caseId as $key => $val) {
         $relatedContacts[] = $relCon = CRM_Case_BAO_Case::getContactNames($val);
     }
     if (!empty($relatedContacts)) {
         foreach ($relatedContacts as $relatedContact) {
             $this->_relatedContacts[] = $relatedContact;
         }
     }
     if (!empty($this->_relatedContacts)) {
         $checkBoxes = array();
         foreach ($this->_relatedContacts as $id => $row) {
             $checkBoxes[$id] = $this->addElement('checkbox', $id, NULL, NULL, array('class' => 'select-row'));
         }
         $this->addGroup($checkBoxes, 'contact_check');
         $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows'));
         $this->assign('searchRows', $this->_relatedContacts);
     }
     $this->_relatedContacts = $rgc + $relCon;
     $this->addFormRule(array('CRM_Case_Form_Activity', 'formRule'), $this);
 }
Esempio n. 5
0
 public static function getCaseRoles()
 {
     $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer');
     $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
     $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
     $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID);
     $caseTypeName = CRM_Case_BAO_Case::getCaseType($caseID, 'name');
     $xmlProcessor = new CRM_Case_XMLProcessor_Process();
     $caseRoles = $xmlProcessor->get($caseTypeName, 'CaseRoles');
     $hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities');
     $managerRoleId = $xmlProcessor->getCaseManagerRoleId($caseTypeName);
     foreach ($caseRelationships as $key => $value) {
         // This role has been filled
         unset($caseRoles[$value['relation_type']]);
         // mark original case relationships record to use on setting edit links below
         $caseRelationships[$key]['source'] = 'caseRel';
     }
     $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID);
     // move/transform caseRoles array data to caseRelationships
     // for sorting and display
     // CRM-14466 added cid to the non-client array to avoid php notice
     foreach ($caseRoles as $id => $value) {
         if ($id != "client") {
             $rel = array();
             $rel['relation'] = $value;
             $rel['relation_type'] = $id;
             $rel['name'] = '(not assigned)';
             $rel['phone'] = '';
             $rel['email'] = '';
             $rel['source'] = 'caseRoles';
             $caseRelationships[] = $rel;
         } else {
             foreach ($value as $clientRole) {
                 $relClient = array();
                 $relClient['relation'] = 'Client';
                 $relClient['name'] = $clientRole['sort_name'];
                 $relClient['phone'] = $clientRole['phone'];
                 $relClient['email'] = $clientRole['email'];
                 $relClient['cid'] = $clientRole['contact_id'];
                 $relClient['source'] = 'contact';
                 $caseRelationships[] = $relClient;
             }
         }
     }
     // sort clientRelationships array using jquery call params
     foreach ($caseRelationships as $key => $row) {
         $sortArray[$key] = $row[$params['_raw_values']['sort'][0]];
     }
     $sort_type = "SORT_" . strtoupper($params['_raw_values']['order'][0]);
     array_multisort($sortArray, constant($sort_type), $caseRelationships);
     $relationships = array();
     // set user name, email and edit columns links
     foreach ($caseRelationships as $key => &$row) {
         $typeLabel = $row['relation'];
         // Add "<br />(Case Manager)" to label
         if ($row['relation_type'] == $managerRoleId) {
             $row['relation'] .= '<br />' . '(' . ts('Case Manager') . ')';
         }
         // view user links
         if (!empty($row['cid'])) {
             $row['name'] = '<a class="view-contact" title="' . ts('View Contact') . '" href=' . CRM_Utils_System::url('civicrm/contact/view', 'action=view&reset=1&cid=' . $row['cid']) . '>' . $row['name'] . '</a>';
         }
         // email column links/icon
         if ($row['email']) {
             $row['email'] = '<a class="crm-hover-button crm-popup" href="' . CRM_Utils_System::url('civicrm/activity/email/add', 'reset=1&action=add&atype=3&cid=' . $row['cid']) . '&caseid=' . $caseID . '" title="' . ts('Send an Email') . '"><i class="crm-i fa-envelope"></i></a>';
         }
         // edit links
         $row['actions'] = '';
         if ($hasAccessToAllCases) {
             $contactType = empty($row['relation_type']) ? '' : (string) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $row['relation_type'], 'contact_type_b');
             $contactType = $contactType == 'Contact' ? '' : $contactType;
             switch ($row['source']) {
                 case 'caseRel':
                     $row['actions'] = '<a href="#editCaseRoleDialog" title="' . ts('Reassign %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '_' . $row['relationship_direction'] . '" data-cid="' . $row['cid'] . '" data-rel_id="' . $row['rel_id'] . '"data-key="' . CRM_Core_Key::get('civicrm/ajax/relation') . '">' . '<i class="crm-i fa-pencil"></i>' . '</a>' . '<a href="#deleteCaseRoleDialog" title="' . ts('Remove %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '_' . $row['relationship_direction'] . '" data-cid="' . $row['cid'] . '" data-key="' . CRM_Core_Key::get('civicrm/ajax/delcaserole') . '">' . '<span class="icon delete-icon"></span>' . '</a>';
                     break;
                 case 'caseRoles':
                     $row['actions'] = '<a href="#editCaseRoleDialog" title="' . ts('Assign %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '_b_a" data-key="' . CRM_Core_Key::get('civicrm/ajax/relation') . '">' . '<i class="crm-i fa-pencil"></i>' . '</a>';
                     break;
             }
         }
         unset($row['cid']);
         unset($row['relation_type']);
         unset($row['rel_id']);
         unset($row['client_id']);
         unset($row['source']);
         array_push($relationships, $row);
     }
     $params['total'] = count($relationships);
     $caseRelationshipsDT = array();
     $caseRelationshipsDT['data'] = $relationships;
     $caseRelationshipsDT['recordsTotal'] = $params['total'];
     $caseRelationshipsDT['recordsFiltered'] = $params['total'];
     CRM_Utils_JSON::output($caseRelationshipsDT);
 }
Esempio n. 6
0
 /**
  * View a particular stage in a tab
  */
 function viewStage()
 {
     // Data needed for contact list
     $contacts = CRM_HRRecruitment_BAO_HRVacancyStage::getCasesAtStage($this->_vid, $this->_statusId);
     $this->assign('contacts', $contacts);
     $this->ajaxResponse['tabCount'] = count($contacts);
     // Data needed for activity buttons/menu
     $xmlProcessor = new CRM_Case_XMLProcessor_Process();
     $activities = $xmlProcessor->get('Application', 'ActivityTypes', TRUE);
     // Special activities we don't want in the action menu
     foreach (array('Open Case', 'Comment', 'Email', 'Evaluation', 'Change Case Status', 'Link Cases', 'Assign Case Role') as $remove) {
         $type = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', $remove);
         if ($type) {
             // Assign to the tpl as camelCase
             $this->assign(str_replace(' ', '', lcfirst($remove . 'Activity')), $type);
             // And remove from the list
             unset($activities[$type]);
         }
     }
     $this->assign('activities', $activities);
     // Data needed for status menu
     $this->assign('statusId', $this->_statusId);
     $caseStatus = array();
     foreach (CRM_HRRecruitment_BAO_HRVacancyStage::caseStage($this->_vid) as $id => $stage) {
         $caseStatus[$stage['weight']] = $stage + array('id' => $id);
     }
     ksort($caseStatus);
     $this->assign('caseStatus', $caseStatus);
 }
Esempio n. 7
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $buttonName = $this->controller->getButtonName();
     // user context
     $url = CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=view&cid={$this->_contactID}&id={$this->_caseID}&show=1");
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext($url);
     if (!empty($params['timeline_id']) && !empty($_POST['_qf_CaseView_next'])) {
         $session = CRM_Core_Session::singleton();
         $this->_uid = $session->get('userID');
         $xmlProcessor = new CRM_Case_XMLProcessor_Process();
         $xmlProcessorParams = array('clientID' => $this->_contactID, 'creatorID' => $this->_uid, 'standardTimeline' => 0, 'activity_date_time' => date('YmdHis'), 'caseID' => $this->_caseID, 'caseType' => $this->_caseType, 'activitySetName' => $params['timeline_id']);
         $xmlProcessor->run($this->_caseType, $xmlProcessorParams);
         $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets');
         CRM_Core_Session::setStatus(ts('Activities from the %1 activity set have been added to this case.', array(1 => $reports[$params['timeline_id']])), ts('Done'), 'success');
     } elseif ($this->_mergeCases && $buttonName == '_qf_CaseView_next_merge_case') {
         $mainCaseId = $params['merge_case_id'];
         $otherCaseId = $this->_caseID;
         //merge two cases.
         CRM_Case_BAO_Case::mergeCases($this->_contactID, $mainCaseId, NULL, $otherCaseId);
         //redirect user to main case view.
         $url = CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=view&cid={$this->_contactID}&id={$mainCaseId}&show=1");
         $session = CRM_Core_Session::singleton();
         $session->pushUserContext($url);
     }
 }
Esempio n. 8
0
<?php

require_once '../civicrm.config.php';
require_once 'CRM/Core/Config.php';
require_once 'CRM/Core/Error.php';
$config = CRM_Core_Config::singleton();
require_once 'CRM/Case/XMLProcessor/Report.php';
$xmlProcessor = new CRM_Case_XMLProcessor_Report();
$report = $xmlProcessor->getActivityInfo(102, 552);
CRM_Core_Error::debug($report);
exit;
$xmlProcessor->run(104, 1, 'Substance Abuse', '15 Day Review');
$params = array('clientID' => 104, 'creatorID' => 108, 'standardTimeline' => 1, 'activityTypeName' => 'Open Case', 'dueDateTime' => time(), 'caseID' => 1);
require_once 'CRM/Case/XMLProcessor/Process.php';
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$result = $xmlProcessor->get('Substance Abuse', 'CaseRoles');
CRM_Core_Error::debug('Case Roles', $result);
$result = $xmlProcessor->get('Substance Abuse', 'ActivityTypes');
CRM_Core_Error::debug('Activity Types', $result);
$result = $xmlProcessor->get('Substance Abuse', 'ActivitySets');
CRM_Core_Error::debug('Activity Sets', $result);
$xmlProcessor->run('Substance Abuse', $params);
exit;
 public function buildQuickForm()
 {
     // modify core Activity fields
     $this->add('text', 'target_contact_id', ts('target'));
     //FIXME : ideally hidden element should work.
     $this->addElement('advcheckbox', "hidden_target_contact");
     $this->_fields['source_contact_id']['label'] = ts('Reported By');
     $this->_fields['status_id']['attributes'] = array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus();
     if ($this->_caseType) {
         $xmlProcessor = new CRM_Case_XMLProcessor_Process();
         $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', TRUE);
         // remove Open Case activity type since we're inside an existing case
         $openCaseID = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name');
         unset($aTypes[$openCaseID]);
         asort($aTypes);
         $this->_fields['followup_activity_type_id']['attributes'] = array('' => '- select activity type -') + $aTypes;
     }
     $result = parent::buildQuickForm();
     if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::DETACH | CRM_Core_Action::RENEW)) {
         return;
     }
     if ($this->_cdType || $this->_addAssigneeContact || $this->_addTargetContact) {
         return $result;
     }
     $this->assign('urlPath', 'civicrm/case/activity');
     $encounterMediums = CRM_Case_PseudoConstant::encounterMedium();
     if ($this->_activityTypeFile == 'OpenCase') {
         $this->_encounterMedium = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'medium_id');
         if (!array_key_exists($this->_encounterMedium, $encounterMediums)) {
             $encounterMediums[$this->_encounterMedium] = CRM_Core_OptionGroup::getLabel('encounter_medium', $this->_encounterMedium, FALSE);
         }
     }
     $this->add('select', 'medium_id', ts('Medium'), $encounterMediums, TRUE);
     $this->_relatedContacts = CRM_Case_BAO_Case::getRelatedAndGlobalContacts($this->_caseId);
     //add case client in send a copy selector.CRM-4438.
     $relatedContacts = CRM_Case_BAO_Case::getContactNames($this->_caseId);
     if (!empty($relatedContacts)) {
         foreach ($relatedContacts as $relatedContact) {
             $this->_relatedContacts[] = $relatedContact;
         }
     }
     if (!empty($this->_relatedContacts)) {
         $checkBoxes = array();
         foreach ($this->_relatedContacts as $id => $row) {
             $checkBoxes[$id] = $this->addElement('checkbox', $id, NULL, '');
         }
         $this->addGroup($checkBoxes, 'contact_check');
         $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "return toggleCheckboxVals('contact_check',this);"));
         $this->assign('searchRows', $this->_relatedContacts);
     }
     $this->addFormRule(array('CRM_Case_Form_Activity', 'formRule'), $this);
 }
Esempio n. 10
0
File: AJAX.php Progetto: kidaa30/yes
 public static function getCaseRoles()
 {
     $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer');
     $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
     $sortMapper = array(0 => 'relation', 1 => 'name', 2 => 'phone', 3 => 'email', 4 => 'actions');
     $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
     $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
     $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
     $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : 'relation';
     $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
     $params = $_POST;
     if ($sort && $sortOrder) {
         $sortSQL = $sort . ' ' . $sortOrder;
     }
     $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID);
     $caseTypeName = CRM_Case_BAO_Case::getCaseType($caseID, 'name');
     $xmlProcessor = new CRM_Case_XMLProcessor_Process();
     $caseRoles = $xmlProcessor->get($caseTypeName, 'CaseRoles');
     $hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities');
     $managerRoleId = $xmlProcessor->getCaseManagerRoleId($caseTypeName);
     if (!empty($managerRoleId)) {
         $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')';
     }
     foreach ($caseRelationships as $key => $value) {
         //calculate roles that don't have relationships
         if (!empty($caseRoles[$value['relation_type']])) {
             //keep naming from careRoles array
             $caseRelationships[$key]['relation'] = $caseRoles[$value['relation_type']];
             unset($caseRoles[$value['relation_type']]);
         }
         // mark orginal case relationships record to use on setting edit links below
         $caseRelationships[$key]['source'] = 'caseRel';
     }
     $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID);
     // move/transform caseRoles array data to caseRelationships
     // for sorting and display
     // CRM-14466 added cid to the non-client array to avoid php notice
     foreach ($caseRoles as $id => $value) {
         if ($id != "client") {
             $rel = array();
             $rel['relation'] = $value;
             $rel['relation_type'] = $id;
             $rel['name'] = '(not assigned)';
             $rel['phone'] = '';
             $rel['email'] = '';
             $rel['source'] = 'caseRoles';
             $caseRelationships[] = $rel;
         } else {
             foreach ($value as $clientRole) {
                 $relClient = array();
                 $relClient['relation'] = 'Client';
                 $relClient['name'] = $clientRole['sort_name'];
                 $relClient['phone'] = $clientRole['phone'];
                 $relClient['email'] = $clientRole['email'];
                 $relClient['cid'] = $clientRole['contact_id'];
                 $relClient['source'] = 'contact';
                 $caseRelationships[] = $relClient;
             }
         }
     }
     // sort clientRelationships array using jquery call params
     foreach ($caseRelationships as $key => $row) {
         $sortArray[$key] = $row[$sort];
     }
     $sort_type = "SORT_" . strtoupper($sortOrder);
     array_multisort($sortArray, constant($sort_type), $caseRelationships);
     //limit rows display
     $allCaseRelationships = $caseRelationships;
     $caseRelationships = array_slice($allCaseRelationships, $offset, $rowCount, TRUE);
     // set user name, email and edit columns links
     // idx will count number of current row / needed by edit links
     $idx = 1;
     foreach ($caseRelationships as &$row) {
         // Get rid of the "<br />(Case Manager)" from label
         list($typeLabel) = explode('<', $row['relation']);
         // view user links
         if (!empty($row['cid'])) {
             $row['name'] = '<a class="view-contact" title="' . ts('View Contact') . '" href=' . CRM_Utils_System::url('civicrm/contact/view', 'action=view&reset=1&cid=' . $row['cid']) . '>' . $row['name'] . '</a>';
         }
         // email column links/icon
         if ($row['email']) {
             $row['email'] = '<a class="crm-hover-button crm-popup" href="' . CRM_Utils_System::url('civicrm/activity/email/add', 'reset=1&action=add&atype=3&cid=' . $row['cid']) . '&caseid=' . $caseID . '" title="' . ts('Send an Email') . '"><span class="icon ui-icon-mail-closed"></span></a>';
         }
         // edit links
         $row['actions'] = '';
         if ($hasAccessToAllCases) {
             $contactType = empty($row['relation_type']) ? '' : (string) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $row['relation_type'], 'contact_type_b');
             $contactType = $contactType == 'Contact' ? '' : $contactType;
             switch ($row['source']) {
                 case 'caseRel':
                     $row['actions'] = '<a href="#editCaseRoleDialog" title="' . ts('Reassign %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '" data-rel_id="' . $row['rel_id'] . '"data-key="' . CRM_Core_Key::get('civicrm/ajax/relation') . '">' . '<span class="icon ui-icon-pencil"></span>' . '</a>' . '<a href="#deleteCaseRoleDialog" title="' . ts('Remove %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '" data-key="' . CRM_Core_Key::get('civicrm/ajax/delcaserole') . '">' . '<span class="icon delete-icon"></span>' . '</a>';
                     break;
                 case 'caseRoles':
                     $row['actions'] = '<a href="#editCaseRoleDialog" title="' . ts('Assign %1', array(1 => $typeLabel)) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '" data-key="' . CRM_Core_Key::get('civicrm/ajax/relation') . '">' . '<span class="icon ui-icon-pencil"></span>' . '</a>';
                     break;
             }
         }
         $idx++;
     }
     $iFilteredTotal = $iTotal = $params['total'] = count($allCaseRelationships);
     $selectorElements = array('relation', 'name', 'phone', 'email', 'actions');
     header('Content-Type: application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($caseRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
Esempio n. 11
0
 static function getCaseRoles()
 {
     $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer');
     $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
     $sortMapper = array(0 => 'relation', 1 => 'name', 2 => 'phone', 3 => 'email', 4 => 'actions');
     $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
     $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
     $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
     $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : 'relation';
     $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
     $params = $_POST;
     if ($sort && $sortOrder) {
         $sortSQL = $sort . ' ' . $sortOrder;
     }
     $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID);
     $caseTypeName = CRM_Case_BAO_Case::getCaseType($caseID, 'name');
     $xmlProcessor = new CRM_Case_XMLProcessor_Process();
     $caseRoles = $xmlProcessor->get($caseTypeName, 'CaseRoles');
     $hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities');
     $managerRoleId = $xmlProcessor->getCaseManagerRoleId($caseTypeName);
     if (!empty($managerRoleId)) {
         $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')';
     }
     foreach ($caseRelationships as $key => $value) {
         //calculate roles that don't have relationships
         if (CRM_Utils_Array::value($value['relation_type'], $caseRoles)) {
             //keep naming from careRoles array
             $caseRelationships[$key]['relation'] = $caseRoles[$value['relation_type']];
             unset($caseRoles[$value['relation_type']]);
         }
         // mark orginal case relationships record to use on setting edit links below
         $caseRelationships[$key]['source'] = 'caseRel';
     }
     $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID);
     // move/transform caseRoles array data to caseRelationships
     // for sorting and display
     foreach ($caseRoles as $id => $value) {
         if ($id != "client") {
             $rel = array();
             $rel['relation'] = $value;
             $rel['relation_type'] = $id;
             $rel['name'] = '(not assigned)';
             $rel['phone'] = '';
             $rel['email'] = '';
             $rel['source'] = 'caseRoles';
             $caseRelationships[] = $rel;
         } else {
             foreach ($value as $clientRole) {
                 $relClient = array();
                 $relClient['relation'] = 'Client';
                 $relClient['name'] = $clientRole['sort_name'];
                 $relClient['phone'] = $clientRole['phone'];
                 $relClient['email'] = $clientRole['email'];
                 $relClient['cid'] = $clientRole['contact_id'];
                 $relClient['source'] = 'contact';
                 $caseRelationships[] = $relClient;
             }
         }
     }
     // sort clientRelationships array using jquery call params
     foreach ($caseRelationships as $key => $row) {
         $sortArray[$key] = $row[$sort];
     }
     $sort_type = "SORT_" . strtoupper($sortOrder);
     array_multisort($sortArray, constant($sort_type), $caseRelationships);
     //limit rows display
     $allCaseRelationships = $caseRelationships;
     $caseRelationships = array_slice($allCaseRelationships, $offset, $rowCount, TRUE);
     // set user name, email and edit columns links
     // idx will count number of current row / needed by edit links
     $idx = 1;
     foreach ($caseRelationships as $key => $row) {
         // view user links
         if ($caseRelationships[$key]['cid']) {
             $caseRelationships[$key]['name'] = '<a href=' . CRM_Utils_System::url('civicrm/contact/view', 'action=view&reset=1&cid=' . $caseRelationships[$key]['cid']) . '>' . $caseRelationships[$key]['name'] . '</a>';
         }
         // email column links/icon
         if ($caseRelationships[$key]['email']) {
             $caseRelationships[$key]['email'] = '<a href="' . CRM_Utils_System::url('civicrm/contact/view/activity', 'action=reset=1&action=add&atype=3&cid=' . $caseRelationships[$key]['cid']) . '&caseid=' . $caseID . '" title="compose and send an email"><div class="icon email-icon" title="compose and send an email"></div>
          </a>';
         }
         // edit links
         if ($hasAccessToAllCases) {
             switch ($caseRelationships[$key]['source']) {
                 case 'caseRel':
                     $caseRelationships[$key]['actions'] = '<a href="#" title="edit case role" onclick="createRelationship( ' . $caseRelationships[$key]['relation_type'] . ', ' . $caseRelationships[$key]['cid'] . ', ' . $caseRelationships[$key]['rel_id'] . ', ' . $idx . ', \'' . $caseRelationships[$key]['relation'] . '\' );return false;"><div class="icon edit-icon" ></div></a>&nbsp;&nbsp;<a href="#" class="case-role-delete" case_id="' . $caseID . '" rel_type="' . $caseRelationships[$key]['relation_type'] . '"><div class="icon delete-icon" title="remove contact from case role"></div></a>';
                     break;
                 case 'caseRoles':
                     $caseRelationships[$key]['actions'] = '<a href="#" title="edit case role" onclick="createRelationship(' . $caseRelationships[$key]['relation_type'] . ', null, null, ' . $idx . ',  \'' . $caseRelationships[$key]['relation'] . '\');return false;"><div class="icon edit-icon"></div></a>';
                     break;
             }
         } else {
             $caseRelationships[$key]['actions'] = '';
         }
         $idx++;
     }
     $iFilteredTotal = $iTotal = $params['total'] = count($allCaseRelationships);
     $selectorElements = array('relation', 'name', 'phone', 'email', 'actions');
     echo CRM_Utils_JSON::encodeDataTableSelector($caseRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
Esempio n. 12
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     // user context
     $url = CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=view&cid={$this->_contactID}&id={$this->_caseID}&show=1");
     $session =& CRM_Core_Session::singleton();
     $session->pushUserContext($url);
     if (CRM_Utils_Array::value('timeline_id', $params) && CRM_Utils_Array::value('_qf_CaseView_next', $_POST)) {
         $session =& CRM_Core_Session::singleton();
         $this->_uid = $session->get('userID');
         $xmlProcessor = new CRM_Case_XMLProcessor_Process();
         $xmlProcessorParams = array('clientID' => $this->_contactID, 'creatorID' => $this->_uid, 'standardTimeline' => 0, 'activity_date_time' => date('YmdHis'), 'caseID' => $this->_caseID, 'caseType' => $this->_caseType, 'activitySetName' => $params['timeline_id']);
         $xmlProcessor->run($this->_caseType, $xmlProcessorParams);
         $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets');
         CRM_Core_Session::setStatus(ts('Activities from the %1 activity set have been added to this case.', array(1 => $reports[$params['timeline_id']])));
     }
 }