3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This class is for UF Group
39 class CRM_UF_Form_Group
extends CRM_Core_Form
{
42 * The form id saved to the session for an update
54 protected $_groupElement;
59 * Set variables up before form is built
63 public function preProcess() {
65 $this->_id
= $this->get('id');
67 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, 0);
69 $this->assign('gid', $this->_id
);
70 $this->_group
= CRM_Core_PseudoConstant
::group();
72 if ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::DELETE
)) {
73 $title = CRM_Core_BAO_UFGroup
::getTitle($this->_id
);
74 $this->assign('profileTitle', $title);
77 // setting title for html page
78 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
79 CRM_Utils_System
::setTitle(ts('Profile Settings') . " - $title");
81 elseif ($this->_action
& (CRM_Core_Action
::DISABLE | CRM_Core_Action
::DELETE
)) {
82 $ufGroup['module'] = implode(' , ', CRM_Core_BAO_UFGroup
::getUFJoinRecord($this->_id
, TRUE));
84 $status = CRM_Core_BAO_UFGroup
::usedByModule($this->_id
);
85 if ($this->_action
& (CRM_Core_Action
::DISABLE
)) {
87 $message = 'This profile is currently used for ' . $ufGroup['module'] . '. If you disable the profile - it will be removed from these forms and/or modules. Do you want to continue?';
90 $message = 'Are you sure you want to disable this Profile?';
95 $message = 'This profile is currently used for ' . $ufGroup['module'] . '. If you delete the profile - it will be removed from these forms and/or modules. This action cannot be undone. Do you want to continue?';
98 $message = 'Are you sure you want to delete this Profile? This action cannot be undone.';
101 $this->assign('message', $message);
104 CRM_Utils_System
::setTitle(ts('New CiviCRM Profile'));
109 * Build the form object
113 public function buildQuickForm() {
114 if ($this->_action
& (CRM_Core_Action
::DISABLE | CRM_Core_Action
::DELETE
)) {
115 if ($this->_action
& (CRM_Core_Action
::DISABLE
)) {
116 $display = 'Disable Profile';
119 $display = 'Delete Profile';
121 $this->addButtons(array(
125 'spacing' => ' ',
130 'name' => ts('Cancel'),
136 $this->applyFilter('__ALL__', 'trim');
139 $this->add('text', 'title', ts('Profile Name'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_UFGroup', 'title'), TRUE);
140 $this->add('textarea', 'description', ts('Description'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_UFGroup', 'description'));
144 $uf_group_type = array();
145 $UFGroupType = CRM_Core_SelectValues
::ufGroupTypes();
146 foreach ($UFGroupType as $key => $value) {
147 $uf_group_type[] = $this->createElement('checkbox', $key, NULL, $value);
149 $this->addGroup($uf_group_type, 'uf_group_type', ts('Used For'), ' ');
152 $this->addWysiwyg('help_pre', ts('Pre-form Help'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_UFGroup', 'help_post'));
153 $this->addWysiwyg('help_post', ts('Post-form Help'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_UFGroup', 'help_post'));
156 $this->add('text', 'weight', ts('Order'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_UFJoin', 'weight'), TRUE);
157 $this->addRule('weight', ts('is a numeric field'), 'numeric');
159 // is this group active ?
160 $this->addElement('checkbox', 'is_active', ts('Is this CiviCRM Profile active?'));
162 $paneNames = array('Advanced Settings' => 'buildAdvanceSetting');
164 foreach ($paneNames as $name => $type) {
166 $dataURL = "&reset=1&action=update&id={$this->_id}&snippet=4&formType={$type}";
169 $dataURL = "&reset=1&action=add&snippet=4&formType={$type}";
172 $allPanes[$name] = array(
173 'url' => CRM_Utils_System
::url('civicrm/admin/uf/group/setting',
180 CRM_UF_Form_AdvanceSetting
::$type($this);
183 $this->addButtons(array(
186 'name' => ts('Save'),
187 'spacing' => ' ',
192 'name' => ts('Cancel'),
197 // views are implemented as frozen form
198 if ($this->_action
& CRM_Core_Action
::VIEW
) {
200 $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group?reset=1&action=browse'"));
203 $this->addFormRule(array('CRM_UF_Form_Group', 'formRule'), $this);
207 * Set default values for the form. Note that in edit/view mode
208 * the default values are retrieved from the database
213 public function setDefaultValues() {
215 $showHide = new CRM_Core_ShowHideBlocks();
217 if ($this->_action
== CRM_Core_Action
::ADD
) {
218 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_UFJoin');
221 //id fetched for Dojo Pane
222 $pId = CRM_Utils_Request
::retrieve('id', 'Positive', $this);
227 if ((isset($this->_id
))) {
229 $defaults['weight'] = CRM_Core_BAO_UFGroup
::getWeight($this->_id
);
231 $params = array('id' => $this->_id
);
232 CRM_Core_BAO_UFGroup
::retrieve($params, $defaults);
233 $defaults['group'] = CRM_Utils_Array
::value('limit_listings_group_id', $defaults);
234 $defaults['add_contact_to_group'] = CRM_Utils_Array
::value('add_to_group_id', $defaults);
235 //get the uf join records for current uf group
236 $ufJoinRecords = CRM_Core_BAO_UFGroup
::getUFJoinRecord($this->_id
);
237 foreach ($ufJoinRecords as $key => $value) {
238 $checked[$value] = 1;
240 $defaults['uf_group_type'] = isset($checked) ?
$checked : "";
242 //get the uf join records for current uf group other than default modules
243 $otherModules = array();
244 $otherModules = CRM_Core_BAO_UFGroup
::getUFJoinRecord($this->_id
, TRUE, TRUE);
245 if (!empty($otherModules)) {
246 $otherModuleString = NULL;
247 foreach ($otherModules as $key) {
248 $otherModuleString .= " [ x ] <label>" . $key . "</label>";
250 $this->assign('otherModuleString', $otherModuleString);
255 'group', 'post_URL', 'cancel_URL',
256 'add_captcha', 'is_map', 'is_uf_link', 'is_edit_link',
257 'is_update_dupe', 'is_cms_user', 'is_proximity_search',
259 foreach ($advFields as $key) {
260 if (!empty($defaults[$key])) {
262 $this->_allPanes
['Advanced Settings']['open'] = 'true';
268 $defaults['is_active'] = 1;
269 $defaults['is_map'] = 0;
270 $defaults['is_update_dupe'] = 0;
271 $defaults['is_proximity_search'] = 0;
273 // Don't assign showHide elements to template in DELETE mode (fields to be shown and hidden don't exist)
274 if (!($this->_action
& CRM_Core_Action
::DELETE
) && !($this->_action
& CRM_Core_Action
::DISABLE
)) {
275 $showHide->addToTemplate();
277 $this->assign('allPanes', $this->_allPanes
);
284 * @param array $fields
285 * The input form values.
286 * @param array $files
287 * The uploaded files if any.
289 * Current form object.
291 * @return true if no errors, else array of errors
294 public static function formRule($fields, $files, $self) {
297 //validate profile title as well as name.
298 $title = $fields['title'];
299 $name = CRM_Utils_String
::munge($title, '_', 56);
300 $name .= $self->_id ?
'_' . $self->_id
: '';
301 $query = 'select count(*) from civicrm_uf_group where ( name like %1 ) and id != %2';
302 $pCnt = CRM_Core_DAO
::singleValueQuery($query, array(1 => array($name, 'String'),
303 2 => array((int)$self->_id
, 'Integer'),
306 $errors['title'] = ts('Profile \'%1\' already exists in Database.', array(1 => $title));
309 return empty($errors) ?
TRUE : $errors;
317 public function postProcess() {
318 if ($this->_action
& CRM_Core_Action
::DELETE
) {
319 $title = CRM_Core_BAO_UFGroup
::getTitle($this->_id
);
320 CRM_Core_BAO_UFGroup
::del($this->_id
);
321 CRM_Core_Session
::setStatus(ts("Your CiviCRM Profile '%1' has been deleted.", array(1 => $title)), ts('Profile Deleted'), 'success');
323 elseif ($this->_action
& CRM_Core_Action
::DISABLE
) {
324 $ufJoinParams = array('uf_group_id' => $this->_id
);
325 CRM_Core_BAO_UFGroup
::delUFJoin($ufJoinParams);
327 CRM_Core_BAO_UFGroup
::setIsActive($this->_id
, 0);
330 // get the submitted form values.
331 $params = $ids = array();
332 $params = $this->controller
->exportValues($this->_name
);
334 if (!array_key_exists('is_active', $params)) {
335 $params['is_active'] = 0;
338 if ($this->_action
& (CRM_Core_Action
::UPDATE
)) {
339 $ids['ufgroup'] = $this->_id
;
341 // lets skip trying to mess around with profile weights and allow the user to do as needed.
343 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
344 $session = CRM_Core_Session
::singleton();
345 $params['created_id'] = $session->get('userID');
346 $params['created_date'] = date('YmdHis');
350 $ufGroup = CRM_Core_BAO_UFGroup
::add($params, $ids);
352 if (!empty($params['is_active'])) {
353 //make entry in uf join table
354 CRM_Core_BAO_UFGroup
::createUFJoin($params, $ufGroup->id
);
356 elseif ($this->_id
) {
357 // this profile has been set to inactive, delete all corresponding UF Join's
358 $ufJoinParams = array('uf_group_id' => $this->_id
);
359 CRM_Core_BAO_UFGroup
::delUFJoin($ufJoinParams);
362 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
363 $url = CRM_Utils_System
::url('civicrm/admin/uf/group', 'reset=1&action=browse');
364 CRM_Core_Session
::setStatus(ts("Your CiviCRM Profile '%1' has been saved.", array(1 => $ufGroup->title
)), ts('Profile Saved'), 'success');
367 // Jump directly to adding a field if popups are disabled
368 $action = CRM_Core_Resources
::singleton()->ajaxPopupsEnabled ?
'' : '/add';
369 $url = CRM_Utils_System
::url("civicrm/admin/uf/group/field$action", 'reset=1&new=1&gid=' . $ufGroup->id
. '&action=' . ($action ?
'add' : 'browse'));
370 CRM_Core_Session
::setStatus(ts('Your CiviCRM Profile \'%1\' has been added. You can add fields to this profile now.',
371 array(1 => $ufGroup->title
)
372 ), ts('Profile Added'), 'success');
374 $session = CRM_Core_Session
::singleton();
375 $session->replaceUserContext($url);
378 // update cms integration with registration / my account
379 CRM_Utils_System
::updateCategories();