Ejemplo n.º 1
0
 /** 
  * Heart of the viewing process. The runner gets all the meta data for 
  * the contact and calls the appropriate type of page to view. 
  * 
  * @return void 
  * @access public 
  * 
  */
 function preProcess()
 {
     // Make sure case types have been configured for the component
     require_once 'CRM/Core/OptionGroup.php';
     $caseType = CRM_Core_OptionGroup::values('case_type');
     if (empty($caseType)) {
         $this->assign('notConfigured', 1);
         return;
     }
     $session =& CRM_Core_Session::singleton();
     $allCases = CRM_Utils_Request::retrieve('all', 'Positive', $session);
     CRM_Utils_System::setTitle(ts('CiviCase Dashboard'));
     $userID = $session->get('userID');
     if (!$allCases) {
         $this->assign('myCases', true);
     } else {
         $this->assign('myCases', false);
     }
     $this->assign('newClient', false);
     if (CRM_Core_Permission::check('add contacts')) {
         $this->assign('newClient', true);
     }
     require_once 'CRM/Case/BAO/Case.php';
     $summary = CRM_Case_BAO_Case::getCasesSummary($allCases, $userID);
     $upcoming = CRM_Case_BAO_Case::getCases($allCases, $userID, 'upcoming');
     $recent = CRM_Case_BAO_Case::getCases($allCases, $userID, 'recent');
     $this->assign('casesSummary', $summary);
     if (!empty($upcoming)) {
         $this->assign('upcomingCases', $upcoming);
     }
     if (!empty($recent)) {
         $this->assign('recentCases', $recent);
     }
 }
Ejemplo n.º 2
0
 /**
  * List activities as dashlet
  *
  * @return void
  *
  * @access public
  */
 function run()
 {
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'dashlet');
     $this->assign('context', $context);
     //check for civicase access.
     if (!CRM_Case_BAO_Case::accessCiviCase()) {
         CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
     }
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     $upcoming = CRM_Case_BAO_Case::getCases(FALSE, $userID, 'upcoming', $context);
     if (!empty($upcoming)) {
         $this->assign('upcomingCases', $upcoming);
     }
     return parent::run();
 }
Ejemplo n.º 3
0
 /**
  * List activities as dashlet
  *
  * @return none
  *
  * @access public
  */
 function run()
 {
     require_once 'CRM/Case/BAO/Case.php';
     //check for civicase access.
     if (!CRM_Case_BAO_Case::accessCiviCase()) {
         CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
     }
     require_once 'CRM/Core/OptionGroup.php';
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     $upcoming = CRM_Case_BAO_Case::getCases(true, $userID, 'upcoming');
     if (!empty($upcoming)) {
         $this->assign('AllCases', $upcoming);
     }
     return parent::run();
 }
Ejemplo n.º 4
0
 /**
  * Heart of the viewing process.
  *
  * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
  */
 public function preProcess()
 {
     //check for civicase access.
     if (!CRM_Case_BAO_Case::accessCiviCase()) {
         CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
     }
     //validate case configuration.
     $configured = CRM_Case_BAO_Case::isCaseConfigured();
     $this->assign('notConfigured', !$configured['configured']);
     $this->assign('allowToAddNewCase', $configured['allowToAddNewCase']);
     if (!$configured['configured']) {
         return;
     }
     $session = CRM_Core_Session::singleton();
     $allCases = CRM_Utils_Request::retrieve('all', 'Positive', $session);
     CRM_Utils_System::setTitle(ts('CiviCase Dashboard'));
     $userID = $session->get('userID');
     //validate access for all cases.
     if ($allCases && !CRM_Core_Permission::check('access all cases and activities')) {
         $allCases = FALSE;
         CRM_Core_Session::setStatus(ts('You are not authorized to access all cases and activities.'), ts('Sorry'), 'error');
     }
     if (!$allCases) {
         $this->assign('myCases', TRUE);
     } else {
         $this->assign('myCases', FALSE);
     }
     $this->assign('newClient', FALSE);
     if (CRM_Core_Permission::check('add contacts') && CRM_Core_Permission::check('access all cases and activities')) {
         $this->assign('newClient', TRUE);
     }
     $summary = CRM_Case_BAO_Case::getCasesSummary($allCases, $userID);
     $upcoming = CRM_Case_BAO_Case::getCases($allCases, $userID, 'upcoming');
     $recent = CRM_Case_BAO_Case::getCases($allCases, $userID, 'recent');
     foreach ($upcoming as $key => $value) {
         if (strtotime($value['case_scheduled_activity_date']) < time()) {
             $upcoming[$key]['activity_status'] = 'status-overdue';
         }
     }
     $this->assign('casesSummary', $summary);
     if (!empty($upcoming)) {
         $this->assign('upcomingCases', $upcoming);
     }
     if (!empty($recent)) {
         $this->assign('recentCases', $recent);
     }
 }
Ejemplo n.º 5
0
 /** 
  * Heart of the viewing process. The runner gets all the meta data for 
  * the contact and calls the appropriate type of page to view. 
  * 
  * @return void 
  * @access public 
  * 
  */
 function preProcess()
 {
     //check for civicase access.
     if (!CRM_Case_BAO_Case::accessCiviCase()) {
         CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
     }
     //validate case configuration.
     require_once 'CRM/Case/BAO/Case.php';
     $configured = CRM_Case_BAO_Case::isCaseConfigured();
     $this->assign('notConfigured', !$configured['configured']);
     $this->assign('allowToAddNewCase', $configured['allowToAddNewCase']);
     if (!$configured['configured']) {
         return;
     }
     $session =& CRM_Core_Session::singleton();
     $allCases = CRM_Utils_Request::retrieve('all', 'Positive', $session);
     CRM_Utils_System::setTitle(ts('CiviCase Dashboard'));
     $userID = $session->get('userID');
     //validate access for all cases.
     if ($allCases && !CRM_Core_Permission::check('access all cases and activities')) {
         $allCases = false;
         CRM_Core_Session::setStatus(ts('You are not authorized to access all cases and activities.'));
     }
     if (!$allCases) {
         $this->assign('myCases', true);
     } else {
         $this->assign('myCases', false);
     }
     $this->assign('newClient', false);
     if (CRM_Core_Permission::check('add contacts') && CRM_Core_Permission::check('access all cases and activities')) {
         $this->assign('newClient', true);
     }
     require_once 'CRM/Case/BAO/Case.php';
     $summary = CRM_Case_BAO_Case::getCasesSummary($allCases, $userID);
     $upcoming = CRM_Case_BAO_Case::getCases($allCases, $userID, 'upcoming');
     $recent = CRM_Case_BAO_Case::getCases($allCases, $userID, 'recent');
     $this->assign('casesSummary', $summary);
     if (!empty($upcoming)) {
         $this->assign('upcomingCases', $upcoming);
     }
     if (!empty($recent)) {
         $this->assign('recentCases', $recent);
     }
 }
Ejemplo n.º 6
0
 /**
  * Heart of the viewing process. The runner gets all the meta data for
  * the contact and calls the appropriate type of page to view.
  *
  * @return void
  * @access public
  *
  */
 function preProcess()
 {
     // js for changing activity status
     CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Case/Form/ActivityChangeStatus.js');
     //check for civicase access.
     if (!CRM_Case_BAO_Case::accessCiviCase()) {
         CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
     }
     //validate case configuration.
     $configured = CRM_Case_BAO_Case::isCaseConfigured();
     $this->assign('notConfigured', !$configured['configured']);
     $this->assign('allowToAddNewCase', $configured['allowToAddNewCase']);
     if (!$configured['configured']) {
         return;
     }
     $session = CRM_Core_Session::singleton();
     $allCases = CRM_Utils_Request::retrieve('all', 'Positive', $session);
     CRM_Utils_System::setTitle(ts('CiviCase Dashboard'));
     $userID = $session->get('userID');
     //validate access for all cases.
     if ($allCases && !CRM_Core_Permission::check('access all cases and activities')) {
         $allCases = FALSE;
         CRM_Core_Session::setStatus(ts('You are not authorized to access all cases and activities.'), ts('Sorry'), 'error');
     }
     if (!$allCases) {
         $this->assign('myCases', TRUE);
     } else {
         $this->assign('myCases', FALSE);
     }
     $this->assign('newClient', FALSE);
     if (CRM_Core_Permission::check('add contacts') && CRM_Core_Permission::check('access all cases and activities')) {
         $this->assign('newClient', TRUE);
     }
     $summary = CRM_Case_BAO_Case::getCasesSummary($allCases, $userID);
     $upcoming = CRM_Case_BAO_Case::getCases($allCases, $userID, 'upcoming');
     $recent = CRM_Case_BAO_Case::getCases($allCases, $userID, 'recent');
     $this->assign('casesSummary', $summary);
     if (!empty($upcoming)) {
         $this->assign('upcomingCases', $upcoming);
     }
     if (!empty($recent)) {
         $this->assign('recentCases', $recent);
     }
 }
Ejemplo n.º 7
0
 function preProcess()
 {
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse');
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     //validate case configuration.
     require_once 'CRM/Case/BAO/Case.php';
     $configured = CRM_Case_BAO_Case::isCaseConfigured($this->_contactId);
     $this->assign('notConfigured', !$configured['configured']);
     $this->assign('allowToAddNewCase', $configured['allowToAddNewCase']);
     $this->assign('redirectToCaseAdmin', $configured['redirectToCaseAdmin']);
     if (!$configured['configured'] || $configured['redirectToCaseAdmin']) {
         return;
     }
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     if ($this->_contactId) {
         $this->assign('contactId', $this->_contactId);
         // check logged in user permission
         require_once 'CRM/Contact/Page/View.php';
         if ($this->_id && $this->_action & CRM_Core_Action::VIEW) {
             //user might have special permissions to view this case, CRM-5666
             if (!CRM_Core_Permission::check('access all cases and activities')) {
                 $session = CRM_Core_Session::singleton();
                 $userCases = CRM_Case_BAO_Case::getCases(false, $session->get('userID'));
                 if (!array_key_exists($this->_id, $userCases)) {
                     CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
                 }
             }
         } else {
             CRM_Contact_Page_View::checkUserPermission($this);
         }
         // set page title
         CRM_Contact_Page_View::setTitle($this->_contactId);
     } else {
         if ($this->_action & CRM_Core_Action::VIEW) {
             CRM_Core_Error::fatal('Contact Id is required for view action.');
         }
     }
     $activityTypes = CRM_Case_PseudoConstant::activityType();
     $this->assign('openCaseId', $activityTypes['Open Case']['id']);
     $this->assign('changeCaseTypeId', $activityTypes['Change Case Type']['id']);
     $this->assign('changeCaseStatusId', $activityTypes['Change Case Status']['id']);
     $this->assign('changeCaseStartDateId', $activityTypes['Change Case Start Date']['id']);
 }
Ejemplo n.º 8
0
 /**
  * Retrieve related cases for give case.
  *
  * @param int $mainCaseId     id of main case
  * @param int $contactId      id of contact
  * @param boolean $excludeDeleted do not include deleted cases.
  *
  * @return an array of related cases.
  *
  * @access public
  */
 static function getRelatedCases($mainCaseId, $contactId, $excludeDeleted = TRUE)
 {
     //FIXME : do check for permissions.
     $relatedCases = array();
     if (!$mainCaseId || !$contactId) {
         return $relatedCases;
     }
     $linkActType = array_search('Link Cases', CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'));
     if (!$linkActType) {
         return $relatedCases;
     }
     $whereClause = "mainCase.id = %2";
     if ($excludeDeleted) {
         $whereClause .= " AND ( relAct.is_deleted = 0 OR relAct.is_deleted IS NULL )";
     }
     //1. first fetch related case ids.
     $query = "\n    SELECT  relCaseAct.case_id\n      FROM  civicrm_case mainCase\n INNER JOIN  civicrm_case_activity mainCaseAct ON (mainCaseAct.case_id = mainCase.id)\n INNER JOIN  civicrm_activity mainAct          ON (mainCaseAct.activity_id = mainAct.id AND mainAct.activity_type_id = %1)\n INNER JOIN  civicrm_case_activity relCaseAct  ON (relCaseAct.activity_id = mainAct.id AND mainCaseAct.id !=  relCaseAct.id)\n INNER JOIN  civicrm_activity relAct           ON (relCaseAct.activity_id = relAct.id  AND relAct.activity_type_id = %1)\n     WHERE  {$whereClause}";
     $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($linkActType, 'Integer'), 2 => array($mainCaseId, 'Integer')));
     $relatedCaseIds = array();
     while ($dao->fetch()) {
         $relatedCaseIds[$dao->case_id] = $dao->case_id;
     }
     $dao->free();
     // there are no related cases.
     if (empty($relatedCaseIds)) {
         return $relatedCases;
     }
     $whereClause = 'relCase.id IN ( ' . implode(',', $relatedCaseIds) . ' )';
     if ($excludeDeleted) {
         $whereClause .= " AND ( relCase.is_deleted = 0 OR relCase.is_deleted IS NULL )";
     }
     //filter for permissioned cases.
     $filterCases = array();
     $doFilterCases = FALSE;
     if (!CRM_Core_Permission::check('access all cases and activities')) {
         $doFilterCases = TRUE;
         $session = CRM_Core_Session::singleton();
         $filterCases = CRM_Case_BAO_Case::getCases(FALSE, $session->get('userID'));
     }
     //2. fetch the details of related cases.
     $query = "\n    SELECT  relCase.id as id,\n            civicrm_case_type.title as case_type,\n            client.display_name as client_name,\n            client.id as client_id\n      FROM  civicrm_case relCase\n INNER JOIN  civicrm_case_contact relCaseContact ON ( relCase.id = relCaseContact.case_id )\n INNER JOIN  civicrm_contact      client         ON ( client.id = relCaseContact.contact_id )\n LEFT JOIN  civicrm_case_type ON relCase.case_type_id = civicrm_case_type.id\n     WHERE  {$whereClause}";
     $dao = CRM_Core_DAO::executeQuery($query);
     $contactViewUrl = CRM_Utils_System::url("civicrm/contact/view", "reset=1&cid=");
     $hasViewContact = CRM_Core_Permission::giveMeAllACLs();
     while ($dao->fetch()) {
         $caseView = NULL;
         if (!$doFilterCases || array_key_exists($dao->id, $filterCases)) {
             $caseViewStr = "reset=1&id={$dao->id}&cid={$dao->client_id}&action=view&context=case&selectedChild=case";
             $caseViewUrl = CRM_Utils_System::url("civicrm/contact/view/case", $caseViewStr);
             $caseView = "<a class='action-item no-popup crm-hover-button' href='{$caseViewUrl}'>" . ts('View Case') . "</a>";
         }
         $clientView = $dao->client_name;
         if ($hasViewContact) {
             $clientView = "<a href='{$contactViewUrl}{$dao->client_id}'>{$dao->client_name}</a>";
         }
         $relatedCases[$dao->id] = array('case_id' => $dao->id, 'case_type' => $dao->case_type, 'client_name' => $clientView, 'links' => $caseView);
     }
     $dao->free();
     return $relatedCases;
 }
Ejemplo n.º 9
0
 /**
  * Get a list of relationships.
  *
  * @param int $contactId
  *   Contact id.
  * @param int $status
  *   1: Past 2: Disabled 3: Current.
  * @param int $numRelationship
  *   No of relationships to display (limit).
  * @param int $count
  *   Get the no of relationships.
  * @param int $relationshipId
  * @param array $links
  *   the list of links to display
  * @param int $permissionMask
  *   the permission mask to be applied for the actions
  * @param bool $permissionedContact
  *   to return only permissioned Contact
  * @param array $params
  *
  * @return array|int
  *   relationship records
  */
 public static function getRelationship($contactId = NULL, $status = 0, $numRelationship = 0, $count = 0, $relationshipId = 0, $links = NULL, $permissionMask = NULL, $permissionedContact = FALSE, $params = array())
 {
     $values = array();
     if (!$contactId && !$relationshipId) {
         return $values;
     }
     list($select1, $from1, $where1) = self::makeURLClause($contactId, $status, $numRelationship, $count, $relationshipId, 'a_b', $params);
     list($select2, $from2, $where2) = self::makeURLClause($contactId, $status, $numRelationship, $count, $relationshipId, 'b_a', $params);
     $order = $limit = '';
     if (!$count) {
         if (empty($params['sort'])) {
             $order = ' ORDER BY civicrm_relationship_type_id, sort_name ';
         } else {
             $order = " ORDER BY {$params['sort']} ";
         }
         $offset = 0;
         if (!empty($params['offset']) && $params['offset'] > 0) {
             $offset = $params['offset'];
         }
         if ($numRelationship) {
             $limit = " LIMIT {$offset}, {$numRelationship}";
         }
     }
     // building the query string
     $queryString = $select1 . $from1 . $where1 . $select2 . $from2 . $where2 . $order . $limit;
     $relationship = new CRM_Contact_DAO_Relationship();
     $relationship->query($queryString);
     $row = array();
     if ($count) {
         $relationshipCount = 0;
         while ($relationship->fetch()) {
             $relationshipCount += $relationship->cnt1 + $relationship->cnt2;
         }
         return $relationshipCount;
     } else {
         $mask = NULL;
         if ($status != self::INACTIVE) {
             if ($links) {
                 $mask = array_sum(array_keys($links));
                 if ($mask & CRM_Core_Action::DISABLE) {
                     $mask -= CRM_Core_Action::DISABLE;
                 }
                 if ($mask & CRM_Core_Action::ENABLE) {
                     $mask -= CRM_Core_Action::ENABLE;
                 }
                 if ($status == self::CURRENT) {
                     $mask |= CRM_Core_Action::DISABLE;
                 } elseif ($status == self::DISABLED) {
                     $mask |= CRM_Core_Action::ENABLE;
                 }
                 $mask = $mask & $permissionMask;
             }
         }
         while ($relationship->fetch()) {
             $rid = $relationship->civicrm_relationship_id;
             $cid = $relationship->civicrm_contact_id;
             if ($permissionedContact && !CRM_Contact_BAO_Contact_Permission::allow($cid)) {
                 continue;
             }
             $values[$rid]['id'] = $rid;
             $values[$rid]['cid'] = $cid;
             $values[$rid]['contact_id_a'] = $relationship->contact_id_a;
             $values[$rid]['contact_id_b'] = $relationship->contact_id_b;
             $values[$rid]['contact_type'] = $relationship->contact_type;
             $values[$rid]['relationship_type_id'] = $relationship->civicrm_relationship_type_id;
             $values[$rid]['relation'] = $relationship->relation;
             $values[$rid]['name'] = $relationship->sort_name;
             $values[$rid]['display_name'] = $relationship->display_name;
             $values[$rid]['job_title'] = $relationship->job_title;
             $values[$rid]['email'] = $relationship->email;
             $values[$rid]['phone'] = $relationship->phone;
             $values[$rid]['employer_id'] = $relationship->employer_id;
             $values[$rid]['organization_name'] = $relationship->organization_name;
             $values[$rid]['country'] = $relationship->country;
             $values[$rid]['city'] = $relationship->city;
             $values[$rid]['state'] = $relationship->state;
             $values[$rid]['start_date'] = $relationship->start_date;
             $values[$rid]['end_date'] = $relationship->end_date;
             $values[$rid]['description'] = $relationship->description;
             $values[$rid]['is_active'] = $relationship->is_active;
             $values[$rid]['is_permission_a_b'] = $relationship->is_permission_a_b;
             $values[$rid]['is_permission_b_a'] = $relationship->is_permission_b_a;
             $values[$rid]['case_id'] = $relationship->case_id;
             if ($status) {
                 $values[$rid]['status'] = $status;
             }
             $values[$rid]['civicrm_relationship_type_id'] = $relationship->civicrm_relationship_type_id;
             if ($relationship->contact_id_a == $contactId) {
                 $values[$rid]['rtype'] = 'a_b';
             } else {
                 $values[$rid]['rtype'] = 'b_a';
             }
             if ($links) {
                 $replace = array('id' => $rid, 'rtype' => $values[$rid]['rtype'], 'cid' => $contactId, 'cbid' => $values[$rid]['cid'], 'caseid' => $values[$rid]['case_id'], 'clientid' => $contactId);
                 if ($status == self::INACTIVE) {
                     // setting links for inactive relationships
                     $mask = array_sum(array_keys($links));
                     if (!$values[$rid]['is_active']) {
                         $mask -= CRM_Core_Action::DISABLE;
                     } else {
                         $mask -= CRM_Core_Action::ENABLE;
                         $mask -= CRM_Core_Action::DISABLE;
                     }
                     $mask = $mask & $permissionMask;
                 }
                 // Give access to manage case link by copying to MAX_ACTION index temporarily, depending on case permission of user.
                 if ($values[$rid]['case_id']) {
                     // Borrowed logic from CRM_Case_Page_Tab
                     $hasCaseAccess = FALSE;
                     if (CRM_Core_Permission::check('access all cases and activities')) {
                         $hasCaseAccess = TRUE;
                     } else {
                         $userCases = CRM_Case_BAO_Case::getCases(FALSE);
                         if (array_key_exists($values[$rid]['case_id'], $userCases)) {
                             $hasCaseAccess = TRUE;
                         }
                     }
                     if ($hasCaseAccess) {
                         // give access by copying to MAX_ACTION temporarily, otherwise leave at NONE which won't display
                         $links[CRM_Core_Action::MAX_ACTION] = $links[CRM_Core_Action::NONE];
                         $links[CRM_Core_Action::MAX_ACTION]['name'] = ts('Manage Case #%1', array(1 => $values[$rid]['case_id']));
                         $links[CRM_Core_Action::MAX_ACTION]['class'] = 'no-popup';
                         // Also make sure we have the right client cid since can get here from multiple relationship tabs.
                         if ($values[$rid]['rtype'] == 'b_a') {
                             $replace['clientid'] = $values[$rid]['cid'];
                         }
                     }
                 }
                 $values[$rid]['action'] = CRM_Core_Action::formLink($links, $mask, $replace, ts('more'), FALSE, 'relationship.selector.row', 'Relationship', $rid);
                 unset($links[CRM_Core_Action::MAX_ACTION]);
             }
         }
         $relationship->free();
         return $values;
     }
 }
Ejemplo n.º 10
0
 /**
  * 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);
 }
Ejemplo n.º 11
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $this->_showRelatedCases = CRM_Utils_Array::value('relatedCases', $_GET);
     $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
     $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
     $this->assign('multiClient', $isMultiClient);
     //pull the related cases.
     $this->assign('showRelatedCases', FALSE);
     if ($this->_showRelatedCases) {
         $relatedCases = $this->get('relatedCases');
         if (!isset($relatedCases)) {
             $cId = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject);
             $caseId = CRM_Utils_Request::retrieve('id', 'Integer', CRM_Core_DAO::$_nullObject);
             $relatedCases = CRM_Case_BAO_Case::getRelatedCases($caseId, $cId);
         }
         $this->assign('relatedCases', $relatedCases);
         $this->assign('showRelatedCases', TRUE);
         CRM_Utils_System::setTitle(ts('Related Cases'));
         return;
     }
     //check for civicase access.
     if (!CRM_Case_BAO_Case::accessCiviCase()) {
         CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
     }
     $this->_hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities');
     $this->assign('hasAccessToAllCases', $this->_hasAccessToAllCases);
     $this->_contactID = $this->get('cid');
     $this->_caseID = $this->get('id');
     $fulltext = CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject);
     if ($fulltext == 'fulltext') {
         $this->assign('fulltext', $fulltext);
     }
     $this->assign('caseID', $this->_caseID);
     $this->assign('contactID', $this->_contactID);
     //validate case id.
     $this->_userCases = array();
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     if (!$this->_hasAccessToAllCases) {
         $this->_userCases = CRM_Case_BAO_Case::getCases(FALSE, $userID, 'any');
         if (!array_key_exists($this->_caseID, $this->_userCases)) {
             CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
         }
     }
     $this->assign('userID', $userID);
     if (CRM_Case_BAO_Case::caseCount($this->_contactID) >= 2) {
         $this->_mergeCases = TRUE;
     }
     $this->assign('mergeCases', $this->_mergeCases);
     //retrieve details about case
     $params = array('id' => $this->_caseID);
     $returnProperties = array('case_type_id', 'subject', 'status_id', 'start_date');
     CRM_Core_DAO::commonRetrieve('CRM_Case_BAO_Case', $params, $values, $returnProperties);
     $statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE);
     $caseTypeName = CRM_Case_BAO_Case::getCaseType($this->_caseID, 'name');
     $caseType = CRM_Case_BAO_Case::getCaseType($this->_caseID);
     $this->_caseDetails = array('case_type' => $caseType, 'case_status' => CRM_Utils_Array::value($values['case_status_id'], $statuses), 'case_subject' => CRM_Utils_Array::value('subject', $values), 'case_start_date' => $values['case_start_date']);
     $this->_caseType = $caseTypeName;
     $this->assign('caseDetails', $this->_caseDetails);
     $reportUrl = CRM_Utils_System::url('civicrm/case/report', "reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&asn=", FALSE, NULL, FALSE);
     $this->assign('reportUrl', $reportUrl);
     // add to recently viewed
     $url = CRM_Utils_System::url('civicrm/contact/view/case', "action=view&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home");
     $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID);
     $this->assign('displayName', $displayName);
     CRM_Utils_System::setTitle($displayName . ' - ' . $caseType);
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case', "action=delete&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home");
     }
     // Add the recently viewed case
     CRM_Utils_Recent::add($displayName . ' - ' . $caseType, $url, $this->_caseID, 'Case', $this->_contactID, NULL, $recentOther);
     //get the related cases for given case.
     $relatedCases = $this->get('relatedCases');
     if (!isset($relatedCases)) {
         $relatedCases = CRM_Case_BAO_Case::getRelatedCases($this->_caseID, $this->_contactID);
         $relatedCases = empty($relatedCases) ? FALSE : $relatedCases;
         $this->set('relatedCases', $relatedCases);
     }
     $this->assign('hasRelatedCases', (bool) $relatedCases);
     if ($relatedCases) {
         $this->assign('relatedCaseLabel', ts('%1 Related Case', array('count' => count($relatedCases), 'plural' => '%1 Related Cases')));
         $this->assign('relatedCaseUrl', CRM_Utils_System::url('civicrm/contact/view/case', array('id' => $this->_caseID, 'cid' => $this->_contactID, 'relatedCases' => 1, 'action' => 'view')));
     }
     $entitySubType = !empty($values['case_type_id']) ? $values['case_type_id'] : NULL;
     $this->assign('caseTypeID', $entitySubType);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Case', $this, $this->_caseID, NULL, $entitySubType);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
 }
Ejemplo n.º 12
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     $this->_showRelatedCases = CRM_Utils_Array::value('relatedCases', $_GET);
     require_once 'CRM/Case/XMLProcessor/Process.php';
     $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
     $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
     $this->assign('multiClient', $isMultiClient);
     //pull the related cases.
     $this->assign('showRelatedCases', false);
     if ($this->_showRelatedCases) {
         $relatedCases = $this->get('relatedCases');
         if (!isset($relatedCases)) {
             $cId = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject);
             $caseId = CRM_Utils_Request::retrieve('id', 'Integer', CRM_Core_DAO::$_nullObject);
             $relatedCases = CRM_Case_BAO_Case::getRelatedCases($caseId, $cId);
         }
         $this->assign('relatedCases', $relatedCases);
         $this->assign('showRelatedCases', true);
         return;
     }
     //check for civicase access.
     if (!CRM_Case_BAO_Case::accessCiviCase()) {
         CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
     }
     $this->_hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities');
     $this->assign('hasAccessToAllCases', $this->_hasAccessToAllCases);
     $this->_contactID = $this->get('cid');
     $this->_caseID = $this->get('id');
     $fulltext = CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject);
     if ($fulltext == 'fulltext') {
         $this->assign('fulltext', $fulltext);
     }
     $this->assign('caseID', $this->_caseID);
     $this->assign('contactID', $this->_contactID);
     //validate case id.
     $this->_userCases = array();
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     if (!$this->_hasAccessToAllCases) {
         $this->_userCases = CRM_Case_BAO_Case::getCases(false, $userID);
         if (!array_key_exists($this->_caseID, $this->_userCases)) {
             CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
         }
     }
     $this->assign('userID', $userID);
     if (CRM_Case_BAO_Case::caseCount($this->_contactID) >= 2) {
         $this->_mergeCases = true;
     }
     $this->assign('mergeCases', $this->_mergeCases);
     //retrieve details about case
     $params = array('id' => $this->_caseID);
     $returnProperties = array('case_type_id', 'subject', 'status_id', 'start_date');
     CRM_Core_DAO::commonRetrieve('CRM_Case_BAO_Case', $params, $values, $returnProperties);
     $values['case_type_id'] = explode(CRM_Case_BAO_Case::VALUE_SEPERATOR, CRM_Utils_Array::value('case_type_id', $values));
     require_once 'CRM/Case/PseudoConstant.php';
     $statuses = CRM_Case_PseudoConstant::caseStatus('label', false);
     $caseTypeName = CRM_Case_BAO_Case::getCaseType($this->_caseID, 'name');
     $caseType = CRM_Case_BAO_Case::getCaseType($this->_caseID);
     $this->_caseDetails = array('case_type' => $caseType, 'case_status' => $statuses[$values['case_status_id']], 'case_subject' => CRM_Utils_Array::value('subject', $values), 'case_start_date' => $values['case_start_date']);
     $this->_caseType = $caseTypeName;
     $this->assign('caseDetails', $this->_caseDetails);
     $newActivityUrl = CRM_Utils_System::url('civicrm/case/activity', "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=", false, null, false);
     $this->assign('newActivityUrl', $newActivityUrl);
     // Send Email activity requires a different URL format from all other activities
     $newActivityEmailUrl = CRM_Utils_System::url('civicrm/activity/add', "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype=", false, null, false);
     $this->assign('newActivityEmailUrl', $newActivityEmailUrl);
     $reportUrl = CRM_Utils_System::url('civicrm/case/report', "reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&asn=", false, null, false);
     $this->assign('reportUrl', $reportUrl);
     // add to recently viewed
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/case', "action=view&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home");
     $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID);
     $this->assign('displayName', $displayName);
     $title = $displayName . ' - ' . $caseType;
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case', "action=delete&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home");
     }
     // add the recently created case
     CRM_Utils_Recent::add($displayName . ' - ' . $caseType, $url, $this->_caseID, 'Case', $this->_contactID, null, $recentOther);
     //get the related cases for given case.
     $relatedCases = $this->get('relatedCases');
     if (!isset($relatedCases)) {
         $relatedCases = CRM_Case_BAO_Case::getRelatedCases($this->_caseID, $this->_contactID);
         $relatedCases = empty($relatedCases) ? false : $relatedCases;
         $this->set('relatedCases', $relatedCases);
     }
     $this->assign('hasRelatedCases', $relatedCases);
 }