From a3dbd1bc19fbfdac93b4e83e7861e06869df3f5c Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 13 Jun 2014 17:05:06 -0700 Subject: [PATCH] CRM-14856 - CRM_Profile_Form - Load postURL and add_to_group from DB (instead of POST) Also: * Keep & use a single copy of the UFGroup in $this->_ufGroup. * Retain "gid" as a hidden field (for use in POST-backs). --- CRM/Profile/Form.php | 62 ++++++++++++++++----------------------- CRM/Profile/Form/Edit.php | 35 +++++----------------- 2 files changed, 32 insertions(+), 65 deletions(-) diff --git a/CRM/Profile/Form.php b/CRM/Profile/Form.php index 27d9d21e56..f223130a94 100644 --- a/CRM/Profile/Form.php +++ b/CRM/Profile/Form.php @@ -67,11 +67,9 @@ class CRM_Profile_Form extends CRM_Core_Form { protected $_gid; /** - * The group id that we are editing - * - * @var string + * @var array details of the UFGroup used on this page */ - protected $_ufGroupName = 'unknown'; + protected $_ufGroup = array('name' => 'unknown'); /** * The group id that we are passing in url @@ -101,13 +99,6 @@ class CRM_Profile_Form extends CRM_Core_Form { */ protected $_contact; - /** - * to store group_id of the group which is to be assigned to the contact - * - * @var int - */ - protected $_addToGroupID; - /** * Do we allow updates of the contact * @@ -193,7 +184,6 @@ class CRM_Profile_Form extends CRM_Core_Form { */ function preProcess() { $this->_id = $this->get('id'); - $this->_gid = $this->get('gid'); $this->_profileIds = $this->get('profileIds'); $this->_grid = CRM_Utils_Request::retrieve('grid', 'Integer', $this); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); @@ -228,7 +218,7 @@ class CRM_Profile_Form extends CRM_Core_Form { } $this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate'); - $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')); + $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0)); if ((count($gids) > 1) && !$this->_profileIds && empty($this->_profileIds)) { if (!empty($gids)) { @@ -251,7 +241,12 @@ class CRM_Profile_Form extends CRM_Core_Form { } if (!$this->_gid) { - $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0, 'GET'); + $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0); + $this->set('gid', $this->_gid); + } + + if (!$this->_gid) { + CRM_Core_Error::fatal(ts('The required parameter "gid" is missing or malformed.')); } $this->_activityId = CRM_Utils_Request::retrieve('aid', 'Positive', $this, FALSE, 0, 'GET'); @@ -270,13 +265,17 @@ class CRM_Profile_Form extends CRM_Core_Form { if ($dao->find(TRUE)) { $this->_isUpdateDupe = $dao->is_update_dupe; $this->_isAddCaptcha = $dao->add_captcha; - if (!empty($dao->name)) { - $this->_ufGroupName = $dao->name; - } + $this->_ufGroup = (array) $dao; } $dao->free(); } - $this->assign('ufGroupName', $this->_ufGroupName); + $this->assign('ufGroupName', $this->_ufGroup['name']); + + if (!CRM_Utils_Array::value('is_active', $this->_ufGroup)) { + CRM_Core_Error::fatal(ts('The requested profile (gid=%1) is inactive or does not exist.', array( + 1 => $this->_gid, + ))); + } $gids = empty($this->_profileIds) ? $this->_gid : $this->_profileIds; @@ -584,14 +583,16 @@ class CRM_Profile_Form extends CRM_Core_Form { * @access public */ public function buildQuickForm() { + $this->add('hidden', 'gid', $this->_gid); + switch ($this->_mode) { case self::MODE_CREATE: case self::MODE_EDIT: case self::MODE_REGISTER: - CRM_Utils_Hook::buildProfile($this->_ufGroupName); + CRM_Utils_Hook::buildProfile($this->_ufGroup['name']); break; case self::MODE_SEARCH: - CRM_Utils_Hook::searchProfile($this->_ufGroupName); + CRM_Utils_Hook::searchProfile($this->_ufGroup['name']); break; default: } @@ -752,10 +753,6 @@ class CRM_Profile_Form extends CRM_Core_Form { CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode); - if ($field['add_to_group_id']) { - $addToGroupId = $field['add_to_group_id']; - } - //build array for captcha if ($field['add_captcha']) { $addCaptcha[$field['group_id']] = $field['add_captcha']; @@ -800,13 +797,6 @@ class CRM_Profile_Form extends CRM_Core_Form { } $this->assign("isCaptcha", $this->_isAddCaptcha); - if ($this->_mode != self::MODE_SEARCH) { - if (isset($addToGroupId)) { - $this->add('hidden', "add_to_group", $addToGroupId); - $this->_addToGroupID = $addToGroupId; - } - } - // lets do the defaults, so we can use it for the below state country routines $this->setDefaultsValues(); @@ -891,7 +881,7 @@ class CRM_Profile_Form extends CRM_Core_Form { * @static */ static function formRule($fields, $files, $form) { - CRM_Utils_Hook::validateProfile($form->_ufGroupName); + CRM_Utils_Hook::validateProfile($form->_ufGroup['name']); $errors = array(); // if no values, return @@ -1091,7 +1081,7 @@ class CRM_Profile_Form extends CRM_Core_Form { return; } } - CRM_Utils_Hook::processProfile($this->_ufGroupName); + CRM_Utils_Hook::processProfile($this->_ufGroup['name']); if (CRM_Utils_Array::value('image_URL', $params)) { CRM_Contact_BAO_Contact::processImageParams($params); } @@ -1191,10 +1181,8 @@ class CRM_Profile_Form extends CRM_Core_Form { } } - $addToGroupId = NULL; - if (CRM_Utils_Array::value('add_to_group', $params)) { - $addToGroupId = $params['add_to_group']; - + $addToGroupId = CRM_Utils_Array::value('add_to_group_id', $this->_ufGroup); + if ($addToGroupId) { //run same check whether group is a mailing list $groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $addToGroupId, 'group_type', 'id' diff --git a/CRM/Profile/Form/Edit.php b/CRM/Profile/Form/Edit.php index 2bc5a0865f..1bb06d497b 100644 --- a/CRM/Profile/Form/Edit.php +++ b/CRM/Profile/Form/Edit.php @@ -113,13 +113,6 @@ class CRM_Profile_Form_Edit extends CRM_Profile_Form { parent::preProcess(); - // make sure the gid is set and valid - if (!$this->_gid) { - CRM_Core_Error::fatal(ts('The requested Profile (gid=%1) is disabled, OR there is no Profile with that ID, OR a valid \'gid=\' integer value is missing from the URL. Contact the site administrator if you need assistance.', - array(1 => $this->_gid) - )); - } - // and also the profile is of type 'Profile' $query = " SELECT module @@ -143,11 +136,7 @@ SELECT module * @access public */ public function buildQuickForm() { - // add the hidden field to redirect the postProcess from - $ufGroup = new CRM_Core_DAO_UFGroup(); - - $ufGroup->id = $this->_gid; - if (!$ufGroup->find(TRUE)) { + if (empty($this->_ufGroup['id'])) { CRM_Core_Error::fatal(); } @@ -157,24 +146,20 @@ SELECT module 'Edit ' . $this->_customGroupTitle . ' Record' : $this->_customGroupTitle; } else { - $groupTitle = $ufGroup->title; + $groupTitle = $this->_ufGroup['title']; } CRM_Utils_System::setTitle($groupTitle); $this->assign('recentlyViewed', FALSE); if ($this->_context != 'dialog') { - $this->_postURL = CRM_Utils_Array::value('postURL', $_POST); - $this->_cancelURL = CRM_Utils_Array::value('cancelURL', $_POST); + $this->_postURL = $this->_ufGroup['post_URL']; + $this->_cancelURL = $this->_ufGroup['cancel_URL']; $gidString = $this->_gid; if (!empty($this->_profileIds)) { $gidString = implode(',', $this->_profileIds); } - if (!$this->_postURL) { - $this->_postURL = $ufGroup->post_URL; - } - if (!$this->_postURL) { if ($this->_context == 'Search') { $this->_postURL = CRM_Utils_System::url('civicrm/contact/search'); @@ -193,14 +178,9 @@ SELECT module } if (!$this->_cancelURL) { - if ($ufGroup->cancel_URL) { - $this->_cancelURL = $ufGroup->cancel_URL; - } - else { - $this->_cancelURL = CRM_Utils_System::url('civicrm/profile', - "reset=1&gid={$gidString}" - ); - } + $this->_cancelURL = CRM_Utils_System::url('civicrm/profile', + "reset=1&gid={$gidString}" + ); } if ($this->_multiRecordProfile) { @@ -231,7 +211,6 @@ SELECT module $this->_postURL = str_replace('&', '&', $this->_postURL); $this->_cancelURL = str_replace('&', '&', $this->_cancelURL); - $this->addElement('hidden', 'postURL', $this->_postURL); if ($this->_cancelURL) { $this->addElement('hidden', 'cancelURL', $this->_cancelURL); } -- 2.25.1