3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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
56 protected $_groupElement;
61 * Function to set variables up before form is built
66 public function preProcess() {
68 $this->_id
= $this->get('id');
70 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, 0);
72 $this->assign('gid', $this->_id
);
73 $this->_group
= CRM_Core_PseudoConstant
::group();
75 if ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::DELETE
)) {
76 $title = CRM_Core_BAO_UFGroup
::getTitle($this->_id
);
77 $this->assign('profileTitle', $title);
80 // setting title for html page
81 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
82 CRM_Utils_System
::setTitle(ts('Profile Settings') . " - $title");
84 elseif ($this->_action
& (CRM_Core_Action
::DISABLE | CRM_Core_Action
::DELETE
)) {
85 $ufGroup['module'] = implode(' , ', CRM_Core_BAO_UFGroup
::getUFJoinRecord($this->_id
, TRUE));
87 $status = CRM_Core_BAO_UFGroup
::usedByModule($this->_id
);
88 if ($this->_action
& (CRM_Core_Action
::DISABLE
)) {
90 $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?';
93 $message = 'Are you sure you want to disable this Profile?';
98 $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?';
101 $message = 'Are you sure you want to delete this Profile? This action cannot be undone.';
104 $this->assign('message', $message);
107 CRM_Utils_System
::setTitle(ts('New CiviCRM Profile'));
112 * Function to actually build the form
117 public function buildQuickForm() {
118 if ($this->_action
& (CRM_Core_Action
::DISABLE | CRM_Core_Action
::DELETE
)) {
119 if ($this->_action
& (CRM_Core_Action
::DISABLE
)) {
120 $display = 'Disable Profile';
123 $display = 'Delete Profile';
125 $this->addButtons(array(
129 'spacing' => ' ',
134 'name' => ts('Cancel'),
140 $this->applyFilter('__ALL__', 'trim');
143 $this->add('text', 'title', ts('Profile Name'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_UFGroup', 'title'), TRUE);
147 $uf_group_type = array();
148 $UFGroupType = CRM_Core_SelectValues
::ufGroupTypes();
149 foreach ($UFGroupType as $key => $value) {
150 $uf_group_type[] = $this->createElement('checkbox', $key, NULL, $value);
152 $this->addGroup($uf_group_type, 'uf_group_type', ts('Used For'), ' ');
155 $this->addWysiwyg('help_pre', ts('Pre-form Help'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_UFGroup', 'help_post'));
156 $this->addWysiwyg('help_post', ts('Post-form Help'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_UFGroup', 'help_post'));
159 $this->add('text', 'weight', ts('Order'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_UFJoin', 'weight'), TRUE);
160 $this->addRule('weight', ts('is a numeric field'), 'numeric');
162 // is this group active ?
163 $this->addElement('checkbox', 'is_active', ts('Is this CiviCRM Profile active?'));
165 $paneNames = array('Advanced Settings' => 'buildAdvanceSetting');
167 foreach ($paneNames as $name => $type) {
169 $dataURL = "&reset=1&action=update&id={$this->_id}&snippet=4&formType={$type}";
172 $dataURL = "&reset=1&action=add&snippet=4&formType={$type}";
175 $allPanes[$name] = array(
176 'url' => CRM_Utils_System
::url('civicrm/admin/uf/group/setting',
183 eval('CRM_UF_Form_AdvanceSetting::' . $type . '( $this );');
186 $this->addButtons(array(
189 'name' => ts('Save'),
190 'spacing' => ' ',
195 'name' => ts('Cancel'),
200 // views are implemented as frozen form
201 if ($this->_action
& CRM_Core_Action
::VIEW
) {
203 $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group?reset=1&action=browse'"));
206 $this->addFormRule(array('CRM_UF_Form_Group', 'formRule'), $this);
210 * This function sets the default values for the form. Note that in edit/view mode
211 * the default values are retrieved from the database
217 function setDefaultValues() {
219 $showHide = new CRM_Core_ShowHideBlocks();
221 if ($this->_action
== CRM_Core_Action
::ADD
) {
222 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_UFJoin');
225 //id fetched for Dojo Pane
226 $pId = CRM_Utils_Request
::retrieve('id', 'Positive', $this);
231 if ((isset($this->_id
))) {
233 $defaults['weight'] = CRM_Core_BAO_UFGroup
::getWeight($this->_id
);
235 $params = array('id' => $this->_id
);
236 CRM_Core_BAO_UFGroup
::retrieve($params, $defaults);
237 $defaults['group'] = CRM_Utils_Array
::value('limit_listings_group_id', $defaults);
238 $defaults['add_contact_to_group'] = CRM_Utils_Array
::value('add_to_group_id', $defaults);
239 //get the uf join records for current uf group
240 $ufJoinRecords = CRM_Core_BAO_UFGroup
::getUFJoinRecord($this->_id
);
241 foreach ($ufJoinRecords as $key => $value) {
242 $checked[$value] = 1;
244 $defaults['uf_group_type'] = isset($checked) ?
$checked : "";
246 //get the uf join records for current uf group other than default modules
247 $otherModules = array();
248 $otherModules = CRM_Core_BAO_UFGroup
::getUFJoinRecord($this->_id
, TRUE, TRUE);
249 if (!empty($otherModules)) {
250 $otherModuleString = NULL;
251 foreach ($otherModules as $key) {
252 $otherModuleString .= " [ x ] <label>" . $key . "</label>";
254 $this->assign('otherModuleString', $otherModuleString);
259 'group', 'post_URL', 'cancel_URL',
260 'add_captcha', 'is_map', 'is_uf_link', 'is_edit_link',
261 'is_update_dupe', 'is_cms_user', 'is_proximity_search',
263 foreach ($advFields as $key) {
264 if (!empty($defaults[$key])) {
266 $this->_allPanes
['Advanced Settings']['open'] = 'true';
272 $defaults['is_active'] = 1;
273 $defaults['is_map'] = 0;
274 $defaults['is_update_dupe'] = 0;
275 $defaults['is_proximity_search'] = 0;
276 $defaults['uf_group_type[Profile]'] = 1;
278 // Don't assign showHide elements to template in DELETE mode (fields to be shown and hidden don't exist)
279 if (!($this->_action
& CRM_Core_Action
::DELETE
) && !($this->_action
& CRM_Core_Action
::DISABLE
)) {
280 $showHide->addToTemplate();
282 $this->assign('allPanes', $this->_allPanes
);
289 * @param array $fields the input form values
290 * @param array $files the uploaded files if any
291 * @param array $self current form object.
293 * @return true if no errors, else array of errors
297 static function formRule($fields, $files, $self) {
300 //validate profile title as well as name.
301 $title = $fields['title'];
302 $name = CRM_Utils_String
::munge($title, '_', 56);
303 $name .= $self->_id ?
'_' . $self->_id
: '';
304 $query = 'select count(*) from civicrm_uf_group where ( name like %1 ) and id != %2';
305 $pCnt = CRM_Core_DAO
::singleValueQuery($query, array(1 => array($name, 'String'),
306 2 => array((int)$self->_id
, 'Integer'),
309 $errors['title'] = ts('Profile \'%1\' already exists in Database.', array(1 => $title));
312 return empty($errors) ?
TRUE : $errors;
321 public function postProcess() {
322 if ($this->_action
& CRM_Core_Action
::DELETE
) {
323 $title = CRM_Core_BAO_UFGroup
::getTitle($this->_id
);
324 CRM_Core_BAO_UFGroup
::del($this->_id
);
325 CRM_Core_Session
::setStatus(ts("Your CiviCRM Profile '%1' has been deleted.", array(1 => $title)), ts('Profile Deleted'), 'success');
327 elseif ($this->_action
& CRM_Core_Action
::DISABLE
) {
328 $ufJoinParams = array('uf_group_id' => $this->_id
);
329 CRM_Core_BAO_UFGroup
::delUFJoin($ufJoinParams);
331 CRM_Core_BAO_UFGroup
::setIsActive($this->_id
, 0);
334 // get the submitted form values.
335 $params = $ids = array();
336 $params = $this->controller
->exportValues($this->_name
);
338 if (!array_key_exists('is_active', $params)) {
339 $params['is_active'] = 0;
342 if ($this->_action
& (CRM_Core_Action
::UPDATE
)) {
343 $ids['ufgroup'] = $this->_id
;
345 // lets skip trying to mess around with profile weights and allow the user to do as needed.
347 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
348 $session = CRM_Core_Session
::singleton();
349 $params['created_id'] = $session->get('userID');
350 $params['created_date'] = date('YmdHis');
354 $ufGroup = CRM_Core_BAO_UFGroup
::add($params, $ids);
356 if (CRM_Utils_Array
::value('is_active', $params)) {
357 //make entry in uf join table
358 CRM_Core_BAO_UFGroup
::createUFJoin($params, $ufGroup->id
);
360 elseif ($this->_id
) {
361 // this profile has been set to inactive, delete all corresponding UF Join's
362 $ufJoinParams = array('uf_group_id' => $this->_id
);
363 CRM_Core_BAO_UFGroup
::delUFJoin($ufJoinParams);
366 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
367 $url = CRM_Utils_System
::url('civicrm/admin/uf/group', 'reset=1&action=browse');
368 CRM_Core_Session
::setStatus(ts("Your CiviCRM Profile '%1' has been saved.", array(1 => $ufGroup->title
)), ts('Profile Saved'), 'success');
371 $url = CRM_Utils_System
::url('civicrm/admin/uf/group/field/add', 'reset=1&action=add&gid=' . $ufGroup->id
);
372 CRM_Core_Session
::setStatus(ts('Your CiviCRM Profile \'%1\' has been added. You can add fields to this profile now.',
373 array(1 => $ufGroup->title
)
374 ), ts('Profile Added'), 'success');
376 $session = CRM_Core_Session
::singleton();
377 $session->replaceUserContext($url);
380 // update cms integration with registration / my account
381 CRM_Utils_System
::updateCategories();