Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * This class generates form components | |
20 | * for previewing Civicrm Profile Group | |
21 | * | |
22 | */ | |
23 | class CRM_UF_Form_Preview extends CRM_UF_Form_AbstractPreview { | |
24 | ||
25 | /** | |
100fef9d | 26 | * Pre processing work done here. |
6a488035 TO |
27 | * |
28 | * gets session variables for group or field id | |
29 | * | |
30 | * @param | |
31 | * | |
32 | * @return void | |
6a488035 | 33 | */ |
00be9182 | 34 | public function preProcess() { |
6a488035 TO |
35 | $flag = FALSE; |
36 | $gid = $this->get('id'); | |
37 | $this->set('gid', $gid); | |
38 | $field = CRM_Utils_Request::retrieve('field', 'Boolean', $this, TRUE, 0); | |
39 | ||
40 | if ($field) { | |
41 | $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, NULL, NULL, NULL, TRUE); | |
42 | $fieldDAO = new CRM_Core_DAO_UFField(); | |
43 | $fieldDAO->id = $this->get('fieldId'); | |
44 | $fieldDAO->find(TRUE); | |
45 | ||
46 | if ($fieldDAO->is_active == 0) { | |
47 | CRM_Core_Error::statusBounce(ts('This field is inactive so it will not be displayed on profile form.')); | |
48 | } | |
49 | elseif ($fieldDAO->is_view == 1) { | |
50 | CRM_Core_Error::statusBounce(ts('This field is view only so it will not be displayed on profile form.')); | |
51 | } | |
52 | $name = $fieldDAO->field_name; | |
53 | ||
54 | if ($fieldDAO->field_name == 'phone_and_ext') { | |
55 | $name = 'phone'; | |
56 | } | |
57 | ||
58 | // preview for field | |
be2fb01f | 59 | $specialFields = [ |
6a488035 TO |
60 | 'address_name', |
61 | 'street_address', | |
62 | 'supplemental_address_1', | |
63 | 'supplemental_address_2', | |
207f62c6 | 64 | 'supplemental_address_3', |
6a488035 TO |
65 | 'city', |
66 | 'postal_code', | |
67 | 'postal_code_suffix', | |
68 | 'geo_code_1', | |
69 | 'geo_code_2', | |
70 | 'state_province', | |
71 | 'country', | |
72 | 'county', | |
73 | 'phone', | |
74 | 'email', | |
21dfd5f5 | 75 | 'im', |
be2fb01f | 76 | ]; |
6a488035 TO |
77 | |
78 | if ($fieldDAO->location_type_id) { | |
79 | $name .= '-' . $fieldDAO->location_type_id; | |
80 | } | |
81 | elseif (in_array($name, $specialFields)) { | |
82 | $name .= '-Primary'; | |
83 | } | |
84 | ||
85 | if (isset($fieldDAO->phone_type_id)) { | |
86 | $name .= '-' . $fieldDAO->phone_type_id; | |
87 | } | |
88 | ||
89 | $fieldArray[$name] = $fields[$name]; | |
90 | ||
91 | if ($fieldDAO->field_name == 'phone_and_ext') { | |
fe7f4414 | 92 | $phoneExtField = str_replace('phone', 'phone_ext', $name); |
6a488035 TO |
93 | $fieldArray[$phoneExtField] = $fields[$phoneExtField]; |
94 | } | |
95 | ||
96 | $fields = $fieldArray; | |
97 | if (!is_array($fields[$name])) { | |
98 | $flag = TRUE; | |
99 | } | |
100 | $this->setProfile($fields, TRUE, $flag); | |
101 | } | |
102 | else { | |
103 | $fields = CRM_Core_BAO_UFGroup::getFields($gid); | |
104 | $this->setProfile($fields); | |
105 | } | |
106 | } | |
107 | ||
108 | /** | |
fe482240 | 109 | * Build the form object. |
6a488035 TO |
110 | * |
111 | * @return void | |
6a488035 TO |
112 | */ |
113 | public function buildQuickForm() { | |
114 | parent::buildQuickForm(); | |
115 | ||
be2fb01f CW |
116 | $this->addButtons([ |
117 | [ | |
c5c263ca AH |
118 | 'type' => 'cancel', |
119 | 'name' => ts('Done with Preview'), | |
120 | 'isDefault' => TRUE, | |
be2fb01f CW |
121 | ], |
122 | ]); | |
6a488035 TO |
123 | } |
124 | ||
125 | } |