Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class assigns the current case to another client | |
38 | * | |
39 | */ | |
40 | class CRM_Case_Form_EditClient extends CRM_Core_Form { | |
41 | ||
42 | /** | |
100fef9d | 43 | * Build all the data structures needed to build the form |
6a488035 TO |
44 | * |
45 | * @return void | |
6a488035 TO |
46 | */ |
47 | public function preProcess() { | |
66adc860 CW |
48 | $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); |
49 | CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); | |
50 | $context = CRM_Utils_Request::retrieve('context', 'String', $this); | |
6a488035 TO |
51 | |
52 | //get current client name. | |
66adc860 | 53 | $this->assign('currentClientName', CRM_Contact_BAO_Contact::displayName($cid)); |
6a488035 TO |
54 | |
55 | //set the context. | |
66adc860 | 56 | $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$cid}&selectedChild=case"); |
6a488035 TO |
57 | if ($context == 'search') { |
58 | $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); | |
59 | //validate the qfKey | |
60 | $urlParams = 'force=1'; | |
61 | if (CRM_Utils_Rule::qfKey($qfKey)) { | |
62 | $urlParams .= "&qfKey=$qfKey"; | |
63 | } | |
64 | $url = CRM_Utils_System::url('civicrm/case/search', $urlParams); | |
65 | } | |
66 | elseif ($context == 'dashboard') { | |
67 | $url = CRM_Utils_System::url('civicrm/case', 'reset=1'); | |
68 | } | |
69 | elseif (in_array($context, array( | |
70 | 'dashlet', 'dashletFullscreen'))) { | |
71 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
72 | } | |
73 | $session = CRM_Core_Session::singleton(); | |
74 | $session->pushUserContext($url); | |
75 | } | |
76 | ||
77 | /** | |
c490a46a | 78 | * Build the form object |
6a488035 | 79 | * |
355ba699 | 80 | * @return void |
6a488035 TO |
81 | */ |
82 | public function buildQuickForm() { | |
66adc860 CW |
83 | $this->addEntityRef('reassign_contact_id', ts('Select Contact'), array('create' => TRUE), TRUE); |
84 | $this->addButtons(array( | |
66adc860 CW |
85 | array( |
86 | 'type' => 'done', | |
87 | 'name' => ts('Reassign Case'), | |
88 | ), | |
cc1bf3ed CW |
89 | array( |
90 | 'type' => 'cancel', | |
91 | 'name' => ts('Cancel'), | |
92 | ), | |
66adc860 CW |
93 | )); |
94 | ||
95 | // This form may change the url structure so should not submit via ajax | |
96 | $this->preventAjaxSubmit(); | |
97 | } | |
6a488035 | 98 | |
6a488035 | 99 | |
00be9182 | 100 | public function addRules() { |
66adc860 CW |
101 | $this->addFormRule(array(get_class($this), 'formRule'), $this); |
102 | } | |
103 | ||
4c6ce474 EM |
104 | /** |
105 | * @param $vals | |
106 | * @param $rule | |
c490a46a | 107 | * @param CRM_Core_Form $form |
4c6ce474 EM |
108 | * |
109 | * @return array | |
110 | */ | |
00be9182 | 111 | public static function formRule($vals, $rule, $form) { |
66adc860 CW |
112 | $errors = array(); |
113 | if (empty($vals['reassign_contact_id']) || $vals['reassign_contact_id'] == $form->get('cid')) { | |
114 | $errors['reassign_contact_id'] = ts("Please select a different contact."); | |
115 | } | |
116 | return $errors; | |
6a488035 TO |
117 | } |
118 | ||
119 | /** | |
120 | * Process the form | |
121 | * | |
122 | * @return void | |
6a488035 TO |
123 | */ |
124 | public function postProcess() { | |
125 | $params = $this->controller->exportValues($this->_name); | |
126 | ||
127 | //assign case to another client. | |
66adc860 | 128 | $mainCaseId = CRM_Case_BAO_Case::mergeCases($params['reassign_contact_id'], $this->get('id'), $this->get('cid'), NULL, TRUE); |
6a488035 TO |
129 | |
130 | // user context | |
131 | $url = CRM_Utils_System::url('civicrm/contact/view/case', | |
66adc860 | 132 | "reset=1&action=view&cid={$params['reassign_contact_id']}&id={$mainCaseId[0]}&show=1" |
6a488035 | 133 | ); |
66adc860 | 134 | CRM_Core_Session::singleton()->pushUserContext($url); |
6a488035 TO |
135 | } |
136 | } |