Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
df371444 | 35 | * This class assigns the current case to another client. |
6a488035 TO |
36 | */ |
37 | class CRM_Case_Form_EditClient extends CRM_Core_Form { | |
38 | ||
39 | /** | |
fe482240 | 40 | * Build all the data structures needed to build the form. |
6a488035 TO |
41 | */ |
42 | public function preProcess() { | |
66adc860 CW |
43 | $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); |
44 | CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); | |
45 | $context = CRM_Utils_Request::retrieve('context', 'String', $this); | |
6a488035 TO |
46 | |
47 | //get current client name. | |
66adc860 | 48 | $this->assign('currentClientName', CRM_Contact_BAO_Contact::displayName($cid)); |
6a488035 TO |
49 | |
50 | //set the context. | |
66adc860 | 51 | $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$cid}&selectedChild=case"); |
6a488035 TO |
52 | if ($context == 'search') { |
53 | $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); | |
54 | //validate the qfKey | |
55 | $urlParams = 'force=1'; | |
56 | if (CRM_Utils_Rule::qfKey($qfKey)) { | |
57 | $urlParams .= "&qfKey=$qfKey"; | |
58 | } | |
59 | $url = CRM_Utils_System::url('civicrm/case/search', $urlParams); | |
60 | } | |
61 | elseif ($context == 'dashboard') { | |
62 | $url = CRM_Utils_System::url('civicrm/case', 'reset=1'); | |
63 | } | |
64 | elseif (in_array($context, array( | |
353ffa53 | 65 | 'dashlet', |
3bdca100 | 66 | 'dashletFullscreen', |
353ffa53 | 67 | ))) { |
6a488035 TO |
68 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); |
69 | } | |
70 | $session = CRM_Core_Session::singleton(); | |
71 | $session->pushUserContext($url); | |
72 | } | |
73 | ||
74 | /** | |
fe482240 | 75 | * Build the form object. |
6a488035 TO |
76 | */ |
77 | public function buildQuickForm() { | |
66adc860 CW |
78 | $this->addEntityRef('reassign_contact_id', ts('Select Contact'), array('create' => TRUE), TRUE); |
79 | $this->addButtons(array( | |
66adc860 CW |
80 | array( |
81 | 'type' => 'done', | |
82 | 'name' => ts('Reassign Case'), | |
83 | ), | |
cc1bf3ed CW |
84 | array( |
85 | 'type' => 'cancel', | |
86 | 'name' => ts('Cancel'), | |
87 | ), | |
66adc860 CW |
88 | )); |
89 | ||
90 | // This form may change the url structure so should not submit via ajax | |
91 | $this->preventAjaxSubmit(); | |
92 | } | |
6a488035 | 93 | |
6a488035 | 94 | |
00be9182 | 95 | public function addRules() { |
66adc860 CW |
96 | $this->addFormRule(array(get_class($this), 'formRule'), $this); |
97 | } | |
98 | ||
4c6ce474 EM |
99 | /** |
100 | * @param $vals | |
101 | * @param $rule | |
c490a46a | 102 | * @param CRM_Core_Form $form |
4c6ce474 EM |
103 | * |
104 | * @return array | |
105 | */ | |
00be9182 | 106 | public static function formRule($vals, $rule, $form) { |
66adc860 CW |
107 | $errors = array(); |
108 | if (empty($vals['reassign_contact_id']) || $vals['reassign_contact_id'] == $form->get('cid')) { | |
109 | $errors['reassign_contact_id'] = ts("Please select a different contact."); | |
110 | } | |
111 | return $errors; | |
6a488035 TO |
112 | } |
113 | ||
114 | /** | |
fe482240 | 115 | * Process the form. |
6a488035 TO |
116 | */ |
117 | public function postProcess() { | |
118 | $params = $this->controller->exportValues($this->_name); | |
119 | ||
120 | //assign case to another client. | |
66adc860 | 121 | $mainCaseId = CRM_Case_BAO_Case::mergeCases($params['reassign_contact_id'], $this->get('id'), $this->get('cid'), NULL, TRUE); |
6a488035 TO |
122 | |
123 | // user context | |
124 | $url = CRM_Utils_System::url('civicrm/contact/view/case', | |
66adc860 | 125 | "reset=1&action=view&cid={$params['reassign_contact_id']}&id={$mainCaseId[0]}&show=1" |
6a488035 | 126 | ); |
66adc860 | 127 | CRM_Core_Session::singleton()->pushUserContext($url); |
6a488035 | 128 | } |
96025800 | 129 | |
6a488035 | 130 | } |