Merge remote-tracking branch 'upstream/4.3' into 4.3-4.4-2013-11-11-10-44-51
[civicrm-core.git] / CRM / UF / Form / Preview.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * This class generates form components
38 * for previewing Civicrm Profile Group
39 *
40 */
41 class CRM_UF_Form_Preview extends CRM_UF_Form_AbstractPreview {
42
43 /**
44 * pre processing work done here.
45 *
46 * gets session variables for group or field id
47 *
48 * @param
49 *
50 * @return void
51 *
52 * @access public
53 *
54 */
55 function preProcess() {
56 $flag = FALSE;
57 $gid = $this->get('id');
58 $this->set('gid', $gid);
59 $field = CRM_Utils_Request::retrieve('field', 'Boolean', $this, TRUE, 0);
60
61 if ($field) {
62 $fields = CRM_Core_BAO_UFGroup::getFields($gid, FALSE, NULL, NULL, NULL, TRUE);
63 $fieldDAO = new CRM_Core_DAO_UFField();
64 $fieldDAO->id = $this->get('fieldId');
65 $fieldDAO->find(TRUE);
66
67 if ($fieldDAO->is_active == 0) {
68 CRM_Core_Error::statusBounce(ts('This field is inactive so it will not be displayed on profile form.'));
69 }
70 elseif ($fieldDAO->is_view == 1) {
71 CRM_Core_Error::statusBounce(ts('This field is view only so it will not be displayed on profile form.'));
72 }
73 $name = $fieldDAO->field_name;
74
75 if ($fieldDAO->field_name == 'phone_and_ext') {
76 $name = 'phone';
77 }
78
79 // preview for field
80 $specialFields = array(
81 'address_name',
82 'street_address',
83 'supplemental_address_1',
84 'supplemental_address_2',
85 'city',
86 'postal_code',
87 'postal_code_suffix',
88 'geo_code_1',
89 'geo_code_2',
90 'state_province',
91 'country',
92 'county',
93 'phone',
94 'email',
95 'im'
96 );
97
98 if ($fieldDAO->location_type_id) {
99 $name .= '-' . $fieldDAO->location_type_id;
100 }
101 elseif (in_array($name, $specialFields)) {
102 $name .= '-Primary';
103 }
104
105 if (isset($fieldDAO->phone_type_id)) {
106 $name .= '-' . $fieldDAO->phone_type_id;
107 }
108
109 $fieldArray[$name] = $fields[$name];
110
111 if ($fieldDAO->field_name == 'phone_and_ext') {
112 $phoneExtField = str_replace('phone', 'phone_ext', $name);;
113 $fieldArray[$phoneExtField] = $fields[$phoneExtField];
114 }
115
116 $fields = $fieldArray;
117 if (!is_array($fields[$name])) {
118 $flag = TRUE;
119 }
120 $this->setProfile($fields, TRUE, $flag);
121 }
122 else {
123 $fields = CRM_Core_BAO_UFGroup::getFields($gid);
124 $this->setProfile($fields);
125 }
126 }
127
128 /**
129 * Function to actually build the form
130 *
131 * @return void
132 * @access public
133 */
134 public function buildQuickForm() {
135 parent::buildQuickForm();
136
137 $this->addButtons(array(
138 array(
139 'type' => 'cancel',
140 'name' => ts('Done with Preview'),
141 'isDefault' => TRUE,
142 ),
143 )
144 );
145 }
146
147 }