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