예제 #1
0
 /**
  * @return string
  */
 function run()
 {
     $errorMessage = '';
     // ensure that all CiviCRM tables are InnoDB, else abort
     // this is not a very fast operation, so we do it randomly 10% of the times
     // but we do it for most / all tables
     // http://bugs.mysql.com/bug.php?id=43664
     if (rand(1, 10) == 3 && CRM_Core_DAO::isDBMyISAM(150)) {
         $errorMessage = ts('Your database is configured to use the MyISAM database engine. CiviCRM requires InnoDB. You will need to convert any MyISAM tables in your database to InnoDB. Using MyISAM tables will result in data integrity issues.');
         CRM_Core_Session::setStatus($errorMessage, ts('Warning'), "alert");
     }
     if (!CRM_Utils_System::isDBVersionValid($errorMessage)) {
         CRM_Core_Session::setStatus($errorMessage, ts('Warning'), "alert", array('expires' => 0));
     }
     $groups = array('Customize Data and Screens' => ts('Customize Data and Screens'), 'Communications' => ts('Communications'), 'Localization' => ts('Localization'), 'Users and Permissions' => ts('Users and Permissions'), 'System Settings' => ts('System Settings'));
     $config = CRM_Core_Config::singleton();
     if (in_array('CiviContribute', $config->enableComponents)) {
         $groups['CiviContribute'] = ts('CiviContribute');
     }
     if (in_array('CiviMember', $config->enableComponents)) {
         $groups['CiviMember'] = ts('CiviMember');
     }
     if (in_array('CiviEvent', $config->enableComponents)) {
         $groups['CiviEvent'] = ts('CiviEvent');
     }
     if (in_array('CiviMail', $config->enableComponents)) {
         $groups['CiviMail'] = ts('CiviMail');
     }
     if (in_array('CiviCase', $config->enableComponents)) {
         $groups['CiviCase'] = ts('CiviCase');
     }
     if (in_array('CiviReport', $config->enableComponents)) {
         $groups['CiviReport'] = ts('CiviReport');
     }
     if (in_array('CiviCampaign', $config->enableComponents)) {
         $groups['CiviCampaign'] = ts('CiviCampaign');
     }
     $values = CRM_Core_Menu::getAdminLinks();
     $this->_showHide = new CRM_Core_ShowHideBlocks();
     foreach ($groups as $group => $title) {
         $groupId = str_replace(' ', '_', $group);
         $this->_showHide->addShow("id_{$groupId}_show");
         $this->_showHide->addHide("id_{$groupId}");
         $v = CRM_Core_ShowHideBlocks::links($this, $groupId, '', '', FALSE);
         if (isset($values[$group])) {
             $adminPanel[$groupId] = $values[$group];
             $adminPanel[$groupId]['show'] = $v['show'];
             $adminPanel[$groupId]['hide'] = $v['hide'];
             $adminPanel[$groupId]['title'] = $title;
         } else {
             $adminPanel[$groupId] = array();
             $adminPanel[$groupId]['show'] = '';
             $adminPanel[$groupId]['hide'] = '';
             $adminPanel[$groupId]['title'] = $title;
         }
     }
     $this->assign('adminPanel', $adminPanel);
     $this->_showHide->addToTemplate();
     return parent::run();
 }
예제 #2
0
 /**
  * Fix what blocks to show/hide based on the default values set
  *
  * @param array   $defaults the array of default values
  * @param boolean $force    should we set show hide based on input defaults
  *
  * @return void
  */
 function setShowHide(&$defaults)
 {
     require_once 'CRM/Core/ShowHideBlocks.php';
     $this->_showHide = new CRM_Core_ShowHideBlocks(array('registration' => 1), '');
     if (empty($defaults)) {
         $this->_showHide->addShow('registration_screen_show');
         $this->_showHide->addShow('confirm_show');
         $this->_showHide->addShow('mail_show');
         $this->_showHide->addShow('thankyou_show');
         $this->_showHide->addHide('registration');
         $this->_showHide->addHide('registration_screen');
         $this->_showHide->addHide('confirm');
         $this->_showHide->addHide('mail');
         $this->_showHide->addHide('thankyou');
         $this->_showHide->addHide('additional_profile_pre');
         $this->_showHide->addHide('additional_profile_post');
         $this->_showHide->addHide('id-approval-text');
     } else {
         $this->_showHide->addShow('confirm');
         $this->_showHide->addShow('mail');
         $this->_showHide->addShow('thankyou');
         $this->_showHide->addHide('registration_screen_show');
         $this->_showHide->addHide('confirm_show');
         $this->_showHide->addHide('mail_show');
         $this->_showHide->addHide('thankyou_show');
         if (!$defaults['is_multiple_registrations']) {
             $this->_showHide->addHide('additional_profile_pre');
             $this->_showHide->addHide('additional_profile_post');
         }
         if (!CRM_Utils_Array::value('requires_approval', $defaults)) {
             $this->_showHide->addHide('id-approval-text');
         }
     }
     $this->_showHide->addToTemplate();
 }
예제 #3
0
 /**
  * Load icon vars used in hide and show links.
  */
 public static function setIcons()
 {
     if (!isset(self::$_showIcon)) {
         $config = CRM_Core_Config::singleton();
         self::$_showIcon = '<img src="' . $config->resourceBase . 'i/TreePlus.gif" class="action-icon" alt="' . ts('show field or section') . '"/>';
         self::$_hideIcon = '<img src="' . $config->resourceBase . 'i/TreeMinus.gif" class="action-icon" alt="' . ts('hide field or section') . '"/>';
     }
 }
예제 #4
0
 /**
  * build the form elements for an IM object
  *
  * @param CRM_Core_Form $form       reference to the form object
  * @param array         $location   the location object to store all the form elements in
  * @param int           $locationId the locationId we are dealing with
  * @param int           $count      the number of blocks to create
  *
  * @return void
  * @access public
  * @static
  */
 function buildIMBlock(&$form, &$location, $locationId, $count)
 {
     for ($i = 1; $i <= $count; $i++) {
         $label = $i == 1 ? ts('Instant Messenger (preferred)') : ts('Instant Messenger');
         CRM_Core_ShowHideBlocks::linksForArray($form, $i, $count, "location[{$locationId}][im]", ts('another IM'), ts('hide this IM'));
         $location[$locationId]['im'][$i]['service_id'] = $form->addElement('select', "location[{$locationId}][im][{$i}][provider_id]", $label, array('' => ts('- select service -')) + CRM_Core_PseudoConstant::IMProvider());
         $location[$locationId]['im'][$i]['name'] = $form->addElement('text', "location[{$locationId}][im][{$i}][name]", null, CRM_Core_DAO::getAttribute('CRM_Core_DAO_IM', 'name'));
     }
 }
예제 #5
0
 /**
  * build the form elements for an email object
  *
  * @param CRM_Core_Form $form       reference to the form object
  * @param array         $location   the location object to store all the form elements in
  * @param int           $locationId the locationId we are dealing with
  * @param int           $count      the number of blocks to create
  *
  * @return void
  * @access public
  * @static
  */
 function buildEmailBlock(&$form, &$location, $locationId, $count)
 {
     for ($i = 1; $i <= $count; $i++) {
         $label = $i == 1 ? ts('Email (preferred)') : ts('Email');
         CRM_Core_ShowHideBlocks::linksForArray($form, $i, $count, "location[{$locationId}][email]", ts('another email'), ts('hide this email'));
         $location[$locationId]['email'][$i]['email'] = $form->addElement('text', "location[{$locationId}][email][{$i}][email]", $label, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email'));
         $form->addRule("location[{$locationId}][email][{$i}][email]", ts('Email is not valid.'), 'email');
     }
 }
예제 #6
0
 function run()
 {
     // ensure that all CiviCRM tables are InnoDB, else abort
     if (CRM_Core_DAO::isDBMyISAM()) {
         $errorMessage = 'Your database is configured to use the MyISAM database engine. CiviCRM  requires InnoDB. You will need to convert any MyISAM tables in your database to InnoDB. Using MyISAM tables will result in data integrity issues. This will be a fatal error in CiviCRM v2.1.';
         require_once 'CRM/Core/Session.php';
         CRM_Core_Session::setStatus($errorMessage);
     }
     if (!CRM_Utils_System::isDBVersionValid($errorMessage)) {
         CRM_Core_Session::setStatus($errorMessage);
     }
     $groups = array('Customize' => ts('Customize'), 'Configure' => ts('Configure'), 'Manage' => ts('Manage'), 'Option Lists' => ts('Option Lists'));
     $config = CRM_Core_Config::singleton();
     if (in_array("CiviContribute", $config->enableComponents)) {
         $groups['CiviContribute'] = ts('CiviContribute');
     }
     if (in_array("CiviMember", $config->enableComponents)) {
         $groups['CiviMember'] = ts('CiviMember');
     }
     if (in_array("CiviEvent", $config->enableComponents)) {
         $groups['CiviEvent'] = ts('CiviEvent');
     }
     if (in_array("CiviMail", $config->enableComponents)) {
         $groups['CiviMail'] = ts('CiviMail');
     }
     if (in_array("CiviCase", $config->enableComponents)) {
         $groups['CiviCase'] = ts('CiviCase');
     }
     if (in_array("CiviReport", $config->enableComponents)) {
         $groups['CiviReport'] = ts('CiviReport');
     }
     if (in_array("CiviCampaign", $config->enableComponents)) {
         $groups['CiviCampaign'] = ts('CiviCampaign');
     }
     require_once 'CRM/Core/Menu.php';
     $values =& CRM_Core_Menu::getAdminLinks();
     require_once 'CRM/Core/ShowHideBlocks.php';
     $this->_showHide = new CRM_Core_ShowHideBlocks();
     foreach ($groups as $group => $title) {
         $this->_showHide->addShow("id_{$group}_show");
         $this->_showHide->addHide("id_{$group}");
         $v = CRM_Core_ShowHideBlocks::links($this, $group, '', '', false);
         $adminPanel[$group] = $values[$group];
         $adminPanel[$group]['show'] = $v['show'];
         $adminPanel[$group]['hide'] = $v['hide'];
         $adminPanel[$group]['title'] = $title;
     }
     require_once 'CRM/Utils/VersionCheck.php';
     $versionCheck =& CRM_Utils_VersionCheck::singleton();
     $this->assign('newVersion', $versionCheck->newerVersion());
     $this->assign('localVersion', $versionCheck->localVersion);
     $this->assign('adminPanel', $adminPanel);
     $this->_showHide->addToTemplate();
     return parent::run();
 }
예제 #7
0
 /**
  * build the form elements for a phone object
  *
  * @param CRM_Core_Form $form       reference to the form object
  * @param array         $location   the location object to store all the form elements in
  * @param int           $locationId the locationId we are dealing with
  * @param int           $count      the number of blocks to create
  *
  * @return void
  * @access public
  * @static
  */
 function buildPhoneBlock(&$form, &$location, $locationId, $count)
 {
     for ($i = 1; $i <= $count; $i++) {
         $label = $i == 1 ? ts('Phone (preferred)') : ts('Phone');
         CRM_Core_ShowHideBlocks::linksForArray($form, $i, $count, "location[{$locationId}][phone]", ts('another phone'), ts('hide this phone'));
         $location[$locationId]['phone'][$i]['phone_type'] = $form->addElement('select', "location[{$locationId}][phone][{$i}][phone_type]", null, CRM_Core_SelectValues::phoneType());
         $location[$locationId]['phone'][$i]['phone'] = $form->addElement('text', "location[{$locationId}][phone][{$i}][phone]", $label, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'));
         // TODO: set this up as a group, we need a valid phone_type_id if we have a  phone number
         //             $form->addRule( "location[$locationId][phone][$i][phone]", ts('Phone number is not valid.'), 'phone' );
     }
 }
예제 #8
0
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     $defaults = array();
     // check if there is a widget already created
     if ($this->_widget) {
         CRM_Core_DAO::storeValues($this->_widget, $defaults);
     } else {
         foreach ($this->_fields as $name => $val) {
             $defaults[$name] = $val[3];
         }
         foreach ($this->_colorFields as $name => $val) {
             $defaults[$name] = $val[3];
         }
         $defaults['about'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'intro_text');
     }
     $showHide = new CRM_Core_ShowHideBlocks();
     $showHide->addHide('id-colors');
     $showHide->addToTemplate();
     return $defaults;
 }
예제 #9
0
 /**
  * Fix what blocks to show/hide based on the default values set
  *
  * @param array $defaults
  *   The array of default values.
  *
  * @return void
  */
 public function setShowHide($defaults)
 {
     $this->_showHide = new CRM_Core_ShowHideBlocks(array('registration' => 1), '');
     if (empty($defaults)) {
         $this->_showHide->addHide('registration');
         $this->_showHide->addHide('id-approval-text');
     } else {
         if (empty($defaults['requires_approval'])) {
             $this->_showHide->addHide('id-approval-text');
         }
     }
     $this->assign('defaultsEmpty', empty($defaults));
     $this->_showHide->addToTemplate();
 }
예제 #10
0
 /**
  * Run page.
  *
  * @return string
  */
 public function run()
 {
     Civi::resources()->addStyleFile('civicrm', 'css/admin.css');
     $this->assign('registerSite', htmlspecialchars('https://civicrm.org/register-your-site?src=iam&sid=' . CRM_Utils_System::getSiteID()));
     $groups = array('Customize Data and Screens' => ts('Customize Data and Screens'), 'Communications' => ts('Communications'), 'Localization' => ts('Localization'), 'Users and Permissions' => ts('Users and Permissions'), 'System Settings' => ts('System Settings'));
     $config = CRM_Core_Config::singleton();
     if (in_array('CiviContribute', $config->enableComponents)) {
         $groups['CiviContribute'] = ts('CiviContribute');
     }
     if (in_array('CiviMember', $config->enableComponents)) {
         $groups['CiviMember'] = ts('CiviMember');
     }
     if (in_array('CiviEvent', $config->enableComponents)) {
         $groups['CiviEvent'] = ts('CiviEvent');
     }
     if (in_array('CiviMail', $config->enableComponents)) {
         $groups['CiviMail'] = ts('CiviMail');
     }
     if (in_array('CiviCase', $config->enableComponents)) {
         $groups['CiviCase'] = ts('CiviCase');
     }
     if (in_array('CiviReport', $config->enableComponents)) {
         $groups['CiviReport'] = ts('CiviReport');
     }
     if (in_array('CiviCampaign', $config->enableComponents)) {
         $groups['CiviCampaign'] = ts('CiviCampaign');
     }
     $values = CRM_Core_Menu::getAdminLinks();
     $this->_showHide = new CRM_Core_ShowHideBlocks();
     foreach ($groups as $group => $title) {
         $groupId = str_replace(' ', '_', $group);
         $this->_showHide->addShow("id_{$groupId}_show");
         $this->_showHide->addHide("id_{$groupId}");
         $v = CRM_Core_ShowHideBlocks::links($this, $groupId, '', '', FALSE);
         if (isset($values[$group])) {
             $adminPanel[$groupId] = $values[$group];
             $adminPanel[$groupId]['show'] = $v['show'];
             $adminPanel[$groupId]['hide'] = $v['hide'];
             $adminPanel[$groupId]['title'] = $title;
         } else {
             $adminPanel[$groupId] = array();
             $adminPanel[$groupId]['show'] = '';
             $adminPanel[$groupId]['hide'] = '';
             $adminPanel[$groupId]['title'] = $title;
         }
     }
     $this->assign('adminPanel', $adminPanel);
     $this->_showHide->addToTemplate();
     return parent::run();
 }
예제 #11
0
 /**
  * @return string
  */
 public function run()
 {
     $groups = array('Customize Data and Screens' => ts('Customize Data and Screens'), 'Communications' => ts('Communications'), 'Localization' => ts('Localization'), 'Users and Permissions' => ts('Users and Permissions'), 'System Settings' => ts('System Settings'));
     $config = CRM_Core_Config::singleton();
     if (in_array('CiviContribute', $config->enableComponents)) {
         $groups['CiviContribute'] = ts('CiviContribute');
     }
     if (in_array('CiviMember', $config->enableComponents)) {
         $groups['CiviMember'] = ts('CiviMember');
     }
     if (in_array('CiviEvent', $config->enableComponents)) {
         $groups['CiviEvent'] = ts('CiviEvent');
     }
     if (in_array('CiviMail', $config->enableComponents)) {
         $groups['CiviMail'] = ts('CiviMail');
     }
     if (in_array('CiviCase', $config->enableComponents)) {
         $groups['CiviCase'] = ts('CiviCase');
     }
     if (in_array('CiviReport', $config->enableComponents)) {
         $groups['CiviReport'] = ts('CiviReport');
     }
     if (in_array('CiviCampaign', $config->enableComponents)) {
         $groups['CiviCampaign'] = ts('CiviCampaign');
     }
     $values = CRM_Core_Menu::getAdminLinks();
     $this->_showHide = new CRM_Core_ShowHideBlocks();
     foreach ($groups as $group => $title) {
         $groupId = str_replace(' ', '_', $group);
         $this->_showHide->addShow("id_{$groupId}_show");
         $this->_showHide->addHide("id_{$groupId}");
         $v = CRM_Core_ShowHideBlocks::links($this, $groupId, '', '', FALSE);
         if (isset($values[$group])) {
             $adminPanel[$groupId] = $values[$group];
             $adminPanel[$groupId]['show'] = $v['show'];
             $adminPanel[$groupId]['hide'] = $v['hide'];
             $adminPanel[$groupId]['title'] = $title;
         } else {
             $adminPanel[$groupId] = array();
             $adminPanel[$groupId]['show'] = '';
             $adminPanel[$groupId]['hide'] = '';
             $adminPanel[$groupId]['title'] = $title;
         }
     }
     $this->assign('adminPanel', $adminPanel);
     $this->_showHide->addToTemplate();
     return parent::run();
 }
 /**
  * Generate the custom Data Fields based
  * on the is_searchable
  *
  *
  * @param $form
  *
  * @return void
  */
 public static function custom(&$form)
 {
     $form->add('hidden', 'hidden_custom', 1);
     $extends = array('Relationship');
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
     $form->assign('groupTree', $groupDetails);
     foreach ($groupDetails as $key => $group) {
         $_groupTitle[$key] = $group['name'];
         CRM_Core_ShowHideBlocks::links($form, $group['name'], '', '');
         $groupId = $group['id'];
         foreach ($group['fields'] as $field) {
             $fieldId = $field['id'];
             $elementName = 'custom_' . $fieldId;
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE);
         }
     }
 }
예제 #13
0
 /**
  * Fix what blocks to show/hide based on the default values set
  *
  * @param    array    array of Group Titles
  * @param    array    array of Group Collapse Display 
  *
  * @return   
  *
  * @access   protected
  */
 function setShowHide(&$groupTitle, &$groupCollapseDisplay)
 {
     if (empty($groupTitle)) {
         return;
     }
     $this->_showHide =& new CRM_Core_ShowHideBlocks('', '');
     foreach ($groupTitle as $key => $title) {
         $showBlocks = $title . '[show]';
         $hideBlocks = $title;
         if ($groupCollapseDisplay[$key]) {
             $this->_showHide->addShow($showBlocks);
             $this->_showHide->addHide($hideBlocks);
         } else {
             $this->_showHide->addShow($hideBlocks);
             $this->_showHide->addHide($showBlocks);
         }
     }
     $this->_showHide->addToTemplate();
 }
예제 #14
0
 /**
  * Fix what blocks to show/hide based on the default values set
  *
  * @param array   $defaults the array of default values
  * @param boolean $force    should we set show hide based on input defaults
  *
  * @return void
  */
 function setShowHide($defaults)
 {
     $this->_showHide = new CRM_Core_ShowHideBlocks(array('registration' => 1), '');
     if (empty($defaults)) {
         $this->_showHide->addHide('registration');
         $this->_showHide->addHide('additional_profile_pre');
         $this->_showHide->addHide('additional_profile_post');
         $this->_showHide->addHide('id-approval-text');
     } else {
         if (!CRM_Utils_Array::value('is_multiple_registrations', $defaults)) {
             $this->_showHide->addHide('additional_profile_pre');
             $this->_showHide->addHide('additional_profile_post');
         }
         if (!CRM_Utils_Array::value('requires_approval', $defaults)) {
             $this->_showHide->addHide('id-approval-text');
         }
     }
     $this->assign('defaultsEmpty', empty($defaults));
     $this->_showHide->addToTemplate();
 }
예제 #15
0
 /**
  * This function provides the HTML form elements that are specific to the Individual Contact Type
  * 
  * @access public
  * @return None 
  */
 function buildQuickForm(&$form)
 {
     $form->applyFilter('__ALL__', 'trim');
     // prefix
     $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => ts('- prefix -')) + CRM_Core_PseudoConstant::individualPrefix());
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Individual');
     // first_name
     $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']);
     //middle_name
     $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']);
     // last_name
     $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']);
     // suffix
     $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => ts('- suffix -')) + CRM_Core_PseudoConstant::individualSuffix());
     // nick_name
     $form->addElement('text', 'nick_name', ts('Nick Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name'));
     // greeting type
     $form->addElement('select', 'greeting_type', ts('Greeting'), CRM_Core_SelectValues::greeting());
     // job title
     $form->addElement('text', 'job_title', ts('Job title'), $attributes['job_title']);
     // radio button for gender
     $genderOptions = array();
     $gender = CRM_Core_PseudoConstant::gender();
     foreach ($gender as $key => $var) {
         $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
     }
     $form->addGroup($genderOptions, 'gender_id', ts('Gender'));
     $form->addElement('checkbox', 'is_deceased', null, ts('Contact is deceased'));
     $form->addElement('date', 'birth_date', ts('Date of birth'), CRM_Core_SelectValues::date('birth'));
     $form->addRule('birth_date', ts('Select a valid date.'), 'qfDate');
     $form->addElement('text', 'home_URL', ts('Website'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'home_URL'));
     $form->addRule('home_URL', ts('Enter a valid Website.'), 'url');
     $config =& CRM_Core_Config::singleton();
     CRM_Core_ShowHideBlocks::links($this, 'demographics', '', '');
 }
예제 #16
0
파일: Criteria.php 프로젝트: kidaa30/yes
 /**
  * Generate the custom Data Fields based
  * on the is_searchable
  *
  *
  * @param $form
  *
  * @return void
  */
 public static function custom(&$form)
 {
     $form->add('hidden', 'hidden_custom', 1);
     $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), CRM_Contact_BAO_ContactType::subTypes());
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
     $form->assign('groupTree', $groupDetails);
     foreach ($groupDetails as $key => $group) {
         $_groupTitle[$key] = $group['name'];
         CRM_Core_ShowHideBlocks::links($form, $group['name'], '', '');
         $groupId = $group['id'];
         foreach ($group['fields'] as $field) {
             $fieldId = $field['id'];
             $elementName = 'custom_' . $fieldId;
             if ($field['data_type'] == 'Date' && $field['is_search_range']) {
                 CRM_Core_Form_Date::buildDateRange($form, $elementName, 1, '_from', '_to', ts('From:'), FALSE);
             } else {
                 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE);
             }
         }
     }
     //TODO: validate for only one state if prox_distance isset
 }
예제 #17
0
 /**
  * Generic function to build all the form elements for a specific group tree.
  *
  * @param CRM_Core_Form $form
  *   The form object.
  * @param array $groupTree
  *   The group tree object.
  * @param bool $inactiveNeeded
  *   Return inactive custom groups.
  * @param string $prefix
  *   Prefix for custom grouptree assigned to template.
  */
 public static function buildQuickForm(&$form, &$groupTree, $inactiveNeeded = FALSE, $prefix = '')
 {
     $form->assign_by_ref("{$prefix}groupTree", $groupTree);
     foreach ($groupTree as $id => $group) {
         CRM_Core_ShowHideBlocks::links($form, $group['title'], '', '');
         foreach ($group['fields'] as $field) {
             $required = CRM_Utils_Array::value('is_required', $field);
             //fix for CRM-1620
             if ($field['data_type'] == 'File') {
                 if (!empty($field['element_value']['data'])) {
                     $required = 0;
                 }
             }
             $fieldId = $field['id'];
             $elementName = $field['element_name'];
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, $required);
         }
     }
 }
예제 #18
0
 /**
  * global validation rules for the form
  *
  * @param array  $fields   (referance) posted values of the form
  *
  * @return array    if errors then list of errors to be posted back to the form,
  *                  true otherwise
  * @static
  * @access public
  */
 static function formRule($fields, $files, $form)
 {
     // all option fields are of type "money"
     $errors = array();
     /** Check the option values entered
      *  Appropriate values are required for the selected datatype
      *  Incomplete row checking is also required.
      */
     if (($form->_action & CRM_Core_Action::ADD || $form->_action & CRM_Core_Action::UPDATE) && $fields['html_type'] == 'Text' && $fields['price'] == NULL) {
         $errors['price'] = ts('Price is a required field');
     }
     //avoid the same price field label in Within PriceSet
     $priceFieldLabel = new CRM_Price_DAO_Field();
     $priceFieldLabel->label = $fields['label'];
     $priceFieldLabel->price_set_id = $form->_sid;
     $dupeLabel = false;
     if ($priceFieldLabel->find(true) && $form->_fid != $priceFieldLabel->id) {
         $dupeLabel = true;
     }
     if ($dupeLabel) {
         $errors['label'] = ts('Name already exists in Database.');
     }
     if (is_numeric(CRM_Utils_Array::value('count', $fields)) && CRM_Utils_Array::value('count', $fields) == 0 && CRM_Utils_Array::value('html_type', $fields) == 'Text') {
         $errors['count'] = ts('Participant Count must be greater than zero.');
     }
     if ($form->_action & CRM_Core_Action::ADD) {
         if ($fields['html_type'] != 'Text') {
             $countemptyrows = 0;
             $_flagOption = $_rowError = 0;
             $_showHide = new CRM_Core_ShowHideBlocks('', '');
             for ($index = 1; $index <= self::NUM_OPTION; $index++) {
                 $noLabel = $noAmount = $noWeight = 1;
                 if (!empty($fields['option_label'][$index])) {
                     $noLabel = 0;
                     $duplicateIndex = CRM_Utils_Array::key($fields['option_label'][$index], $fields['option_label']);
                     if (!($duplicateIndex === false) && !($duplicateIndex == $index)) {
                         $errors["option_label[{$index}]"] = ts('Duplicate label value');
                         $_flagOption = 1;
                     }
                 }
                 // allow for 0 value.
                 if (!empty($fields['option_amount'][$index]) || strlen($fields['option_amount'][$index]) > 0) {
                     $noAmount = 0;
                 }
                 if (!empty($fields['option_weight'][$index])) {
                     $noWeight = 0;
                     $duplicateIndex = CRM_Utils_Array::key($fields['option_weight'][$index], $fields['option_weight']);
                     if (!($duplicateIndex === false) && !($duplicateIndex == $index)) {
                         $errors["option_weight[{$index}]"] = ts('Duplicate weight value');
                         $_flagOption = 1;
                     }
                 }
                 if ($noLabel && !$noAmount) {
                     $errors["option_label[{$index}]"] = ts('Label cannot be empty.');
                     $_flagOption = 1;
                 }
                 if (!$noLabel && $noAmount) {
                     $errors["option_amount[{$index}]"] = ts('Amount cannot be empty.');
                     $_flagOption = 1;
                 }
                 if ($noLabel && $noAmount) {
                     $countemptyrows++;
                     $_emptyRow = 1;
                 } else {
                     if (!empty($fields['option_max_value'][$index]) && !empty($fields['option_count'][$index]) && $fields['option_count'][$index] > $fields['option_max_value'][$index]) {
                         $errors["option_max_value[{$index}]"] = ts('Participant count can not be greater than max participants.');
                         $_flagOption = 1;
                     }
                 }
                 $showBlocks = 'optionField_' . $index;
                 if ($_flagOption) {
                     $_showHide->addShow($showBlocks);
                     $_rowError = 1;
                 }
                 if (!empty($_emptyRow)) {
                     $_showHide->addHide($showBlocks);
                 } else {
                     $_showHide->addShow($showBlocks);
                 }
                 if ($index == self::NUM_OPTION) {
                     $hideBlock = 'additionalOption';
                     $_showHide->addHide($hideBlock);
                 }
                 $_flagOption = $_emptyRow = 0;
             }
             $_showHide->addToTemplate();
             if ($countemptyrows == 11) {
                 $errors["option_label[1]"] = $errors["option_amount[1]"] = ts('Label and value cannot be empty.');
                 $_flagOption = 1;
             }
         } else {
             if (!empty($fields['max_value']) && !empty($fields['count']) && $fields['count'] > $fields['max_value']) {
                 $errors["max_value"] = ts('Participant count can not be greater than max participants.');
             }
         }
         // do not process if no option rows were submitted
         if (empty($fields['option_amount']) && empty($fields['option_label'])) {
             return true;
         }
         if (empty($fields['option_name'])) {
             $fields['option_amount'] = array();
         }
         if (empty($fields['option_label'])) {
             $fields['option_label'] = array();
         }
     }
     return empty($errors) ? true : $errors;
 }
예제 #19
0
 /**
  * generic function to build all the form elements for a specific group tree
  *
  * @param CRM_Core_Form $form      the form object
  * @param array         $groupTree the group tree object
  * @param string        $showName  
  * @param string        $hideName
  *
  * @return void
  * @access public
  * @static
  */
 function buildQuickForm(&$form, &$groupTree, $showName = 'showBlocks', $hideName = 'hideBlocks')
 {
     //this is fix for calendar for date field
     foreach ($groupTree as $key1 => $group) {
         foreach ($group['fields'] as $key2 => $field) {
             if ($field['data_type'] == 'Date' && $field['date_parts']) {
                 $datePart = explode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $field['date_parts']);
                 if (count($datePart) < 3) {
                     $groupTree[$key1]['fields'][$key2]['skip_calendar'] = true;
                 }
             }
         }
     }
     $form->assign_by_ref('groupTree', $groupTree);
     $sBlocks = array();
     $hBlocks = array();
     // this is fix for date field
     $form->assign('currentYear', date('Y'));
     require_once 'CRM/Core/ShowHideBlocks.php';
     foreach ($groupTree as $group) {
         CRM_Core_ShowHideBlocks::links($form, $group['title'], '', '');
         $groupId = $group['id'];
         foreach ($group['fields'] as $field) {
             $fieldId = $field['id'];
             $elementName = 'custom_' . $fieldId;
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, $inactiveNeeded, $group['is_required']);
         }
         if ($group['collapse_display']) {
             $sBlocks[] = "'" . $group['title'] . "[show]'";
             $hBlocks[] = "'" . $group['title'] . "'";
         } else {
             $hBlocks[] = "'" . $group['title'] . "[show]'";
             $sBlocks[] = "'" . $group['title'] . "'";
         }
     }
     $showBlocks = implode(",", $sBlocks);
     $hideBlocks = implode(",", $hBlocks);
     $form->assign($showName, $showBlocks);
     $form->assign($hideName, $hideBlocks);
 }
예제 #20
0
 /**
  * Global validation rules for the form.
  *
  * @param array $fields
  *   Posted values of the form.
  *
  * @param $files
  * @param CRM_Core_Form $form
  *
  * @return array
  *   if errors then list of errors to be posted back to the form,
  *                  true otherwise
  */
 public static function formRule($fields, $files, $form)
 {
     // all option fields are of type "money"
     $errors = array();
     /** Check the option values entered
      *  Appropriate values are required for the selected datatype
      *  Incomplete row checking is also required.
      */
     if (($form->_action & CRM_Core_Action::ADD || $form->_action & CRM_Core_Action::UPDATE) && $fields['html_type'] == 'Text' && $fields['price'] == NULL) {
         $errors['price'] = ts('Price is a required field');
     }
     if (($form->_action & CRM_Core_Action::ADD || $form->_action & CRM_Core_Action::UPDATE) && $fields['html_type'] == 'Text' && $fields['financial_type_id'] == '') {
         $errors['financial_type_id'] = ts('Financial Type is a required field');
     }
     //avoid the same price field label in Within PriceSet
     $priceFieldLabel = new CRM_Price_DAO_PriceField();
     $priceFieldLabel->label = $fields['label'];
     $priceFieldLabel->price_set_id = $form->_sid;
     $dupeLabel = FALSE;
     if ($priceFieldLabel->find(TRUE) && $form->_fid != $priceFieldLabel->id) {
         $dupeLabel = TRUE;
     }
     if ($dupeLabel) {
         $errors['label'] = ts('Name already exists in Database.');
     }
     if (is_numeric(CRM_Utils_Array::value('count', $fields)) && CRM_Utils_Array::value('count', $fields) == 0 && CRM_Utils_Array::value('html_type', $fields) == 'Text') {
         $errors['count'] = ts('Participant Count must be greater than zero.');
     }
     if ($form->_action & CRM_Core_Action::ADD) {
         if ($fields['html_type'] != 'Text') {
             $countemptyrows = 0;
             $_flagOption = $_rowError = 0;
             $_showHide = new CRM_Core_ShowHideBlocks('', '');
             for ($index = 1; $index <= self::NUM_OPTION; $index++) {
                 $noLabel = $noAmount = $noWeight = 1;
                 if (!empty($fields['option_label'][$index])) {
                     $noLabel = 0;
                     $duplicateIndex = CRM_Utils_Array::key($fields['option_label'][$index], $fields['option_label']);
                     if (!($duplicateIndex === FALSE) && !($duplicateIndex == $index)) {
                         $errors["option_label[{$index}]"] = ts('Duplicate label value');
                         $_flagOption = 1;
                     }
                 }
                 if ($form->_useForMember) {
                     if (!empty($fields['membership_type_id'][$index])) {
                         $memTypesIDS[] = $fields['membership_type_id'][$index];
                     }
                 }
                 // allow for 0 value.
                 if (!empty($fields['option_amount'][$index]) || strlen($fields['option_amount'][$index]) > 0) {
                     $noAmount = 0;
                 }
                 if (!empty($fields['option_weight'][$index])) {
                     $noWeight = 0;
                     $duplicateIndex = CRM_Utils_Array::key($fields['option_weight'][$index], $fields['option_weight']);
                     if (!($duplicateIndex === FALSE) && !($duplicateIndex == $index)) {
                         $errors["option_weight[{$index}]"] = ts('Duplicate weight value');
                         $_flagOption = 1;
                     }
                 }
                 if (!$noLabel && !$noAmount && !empty($fields['option_financial_type_id']) && $fields['option_financial_type_id'][$index] == '' && $fields['html_type'] != 'Text') {
                     $errors["option_financial_type_id[{$index}]"] = ts('Financial Type is a Required field.');
                 }
                 if ($noLabel && !$noAmount) {
                     $errors["option_label[{$index}]"] = ts('Label cannot be empty.');
                     $_flagOption = 1;
                 }
                 if (!$noLabel && $noAmount) {
                     $errors["option_amount[{$index}]"] = ts('Amount cannot be empty.');
                     $_flagOption = 1;
                 }
                 if ($noLabel && $noAmount) {
                     $countemptyrows++;
                     $_emptyRow = 1;
                 } elseif (!empty($fields['option_max_value'][$index]) && !empty($fields['option_count'][$index]) && $fields['option_count'][$index] > $fields['option_max_value'][$index]) {
                     $errors["option_max_value[{$index}]"] = ts('Participant count can not be greater than max participants.');
                     $_flagOption = 1;
                 }
                 $showBlocks = 'optionField_' . $index;
                 if ($_flagOption) {
                     $_showHide->addShow($showBlocks);
                     $_rowError = 1;
                 }
                 if (!empty($_emptyRow)) {
                     $_showHide->addHide($showBlocks);
                 } else {
                     $_showHide->addShow($showBlocks);
                 }
                 if ($index == self::NUM_OPTION) {
                     $hideBlock = 'additionalOption';
                     $_showHide->addHide($hideBlock);
                 }
                 $_flagOption = $_emptyRow = 0;
             }
             if (!empty($memTypesIDS)) {
                 // check for checkboxes allowing user to select multiple memberships from same membership organization
                 if ($fields['html_type'] == 'CheckBox') {
                     $foundDuplicate = FALSE;
                     $orgIds = array();
                     foreach ($memTypesIDS as $key => $val) {
                         $org = CRM_Member_BAO_MembershipType::getMembershipTypeOrganization($val);
                         if (in_array($org[$val], $orgIds)) {
                             $foundDuplicate = TRUE;
                             break;
                         }
                         $orgIds[$val] = $org[$val];
                     }
                     if ($foundDuplicate) {
                         $errors['_qf_default'] = ts('You have selected multiple memberships for the same organization or entity. Please review your selections and choose only one membership per entity.');
                     }
                 }
                 // CRM-10390 - Only one price field in a set can include auto-renew membership options
                 $foundAutorenew = FALSE;
                 foreach ($memTypesIDS as $key => $val) {
                     // see if any price field option values in this price field are for memberships with autorenew
                     $memTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($val);
                     if (!empty($memTypeDetails['auto_renew'])) {
                         $foundAutorenew = TRUE;
                         break;
                     }
                 }
                 if ($foundAutorenew) {
                     // if so, check for other fields in this price set which also have auto-renew membership options
                     $otherFieldAutorenew = CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($form->_sid);
                     if ($otherFieldAutorenew) {
                         $errors['_qf_default'] = ts('You can include auto-renew membership choices for only one price field in a price set. Another field in this set already contains one or more auto-renew membership options.');
                     }
                 }
             }
             $_showHide->addToTemplate();
             if ($countemptyrows == 15) {
                 $errors['option_label[1]'] = $errors['option_amount[1]'] = ts('Label and value cannot be empty.');
                 $_flagOption = 1;
             }
         } elseif (!empty($fields['max_value']) && !empty($fields['count']) && $fields['count'] > $fields['max_value']) {
             $errors['max_value'] = ts('Participant count can not be greater than max participants.');
         }
         // do not process if no option rows were submitted
         if (empty($fields['option_amount']) && empty($fields['option_label'])) {
             return TRUE;
         }
         if (empty($fields['option_name'])) {
             $fields['option_amount'] = array();
         }
         if (empty($fields['option_label'])) {
             $fields['option_label'] = array();
         }
     }
     return empty($errors) ? TRUE : $errors;
 }
예제 #21
0
파일: Field.php 프로젝트: hguru/224Civi
 /**
  * global validation rules for the form
  *
  * @param array  $fields   (referance) posted values of the form
  *
  * @return array    if errors then list of errors to be posted back to the form,
  *                  true otherwise
  * @static
  * @access public
  */
 static function formRule($fields, $files, $self)
 {
     $default = CRM_Utils_Array::value('default_value', $fields);
     $errors = array();
     //validate field label as well as name.
     $title = $fields['label'];
     $name = CRM_Utils_String::munge($title, '_', 64);
     $gId = $self->_gid;
     // CRM-7564
     $query = 'select count(*) from civicrm_custom_field where ( name like %1 OR label like %2 ) and id != %3 and custom_group_id = %4';
     $fldCnt = CRM_Core_DAO::singleValueQuery($query, array(1 => array($name, 'String'), 2 => array($title, 'String'), 3 => array((int) $self->_id, 'Integer'), 4 => array($gId, 'Integer')));
     if ($fldCnt) {
         $errors['label'] = ts('Custom field \'%1\' already exists in Database.', array(1 => $title));
     }
     //checks the given custom field name doesnot start with digit
     if (!empty($title)) {
         // gives the ascii value
         $asciiValue = ord($title[0]);
         if ($asciiValue >= 48 && $asciiValue <= 57) {
             $errors['label'] = ts("Field's Name should not start with digit");
         }
     }
     // ensure that the label is not 'id'
     if (strtolower($title) == 'id') {
         $errors['label'] = ts("You cannot use 'id' as a field label.");
     }
     if (!isset($fields['data_type'][0]) || !isset($fields['data_type'][1])) {
         $errors['_qf_default'] = ts('Please enter valid - Data and Input Field Type.');
     }
     $dataType = self::$_dataTypeKeys[$fields['data_type'][0]];
     if ($default || $dataType == 'ContactReference') {
         switch ($dataType) {
             case 'Int':
                 if (!CRM_Utils_Rule::integer($default)) {
                     $errors['default_value'] = ts('Please enter a valid integer as default value.');
                 }
                 break;
             case 'Float':
                 if (!CRM_Utils_Rule::numeric($default)) {
                     $errors['default_value'] = ts('Please enter a valid number as default value.');
                 }
                 break;
             case 'Money':
                 if (!CRM_Utils_Rule::money($default)) {
                     $errors['default_value'] = ts('Please enter a valid number value.');
                 }
                 break;
             case 'Link':
                 if (!CRM_Utils_Rule::url($default)) {
                     $errors['default_value'] = ts('Please enter a valid link.');
                 }
                 break;
             case 'Date':
                 if (!CRM_Utils_Rule::date($default)) {
                     $errors['default_value'] = ts('Please enter a valid date as default value using YYYY-MM-DD format. Example: 2004-12-31.');
                 }
                 break;
             case 'Boolean':
                 if ($default != '1' && $default != '0') {
                     $errors['default_value'] = ts('Please enter 1 (for Yes) or 0 (for No) if you want to set a default value.');
                 }
                 break;
             case 'Country':
                 if (!empty($default)) {
                     $query = "SELECT count(*) FROM civicrm_country WHERE name = %1 OR iso_code = %1";
                     $params = array(1 => array($fields['default_value'], 'String'));
                     if (CRM_Core_DAO::singleValueQuery($query, $params) <= 0) {
                         $errors['default_value'] = ts('Invalid default value for country.');
                     }
                 }
                 break;
             case 'StateProvince':
                 if (!empty($default)) {
                     $query = "\nSELECT count(*)\n  FROM civicrm_state_province\n WHERE name = %1\n    OR abbreviation = %1";
                     $params = array(1 => array($fields['default_value'], 'String'));
                     if (CRM_Core_DAO::singleValueQuery($query, $params) <= 0) {
                         $errors['default_value'] = ts('The invalid default value for State/Province data type');
                     }
                 }
                 break;
             case 'ContactReference':
                 if ($fields['filter_selected'] == 'Advance' && CRM_Utils_Array::value('filter', $fields)) {
                     if (strpos($fields['filter'], 'entity=') !== FALSE) {
                         $errors['filter'] = ts("Please do not include entity parameter (entity is always 'contact')");
                     } elseif (strpos($fields['filter'], 'action=') === FALSE) {
                         $errors['filter'] = ts("Please specify 'action' parameter, it should be 'lookup' or 'get'");
                     } elseif (strpos($fields['filter'], 'action=get') === FALSE && strpos($fields['filter'], 'action=lookup') === FALSE) {
                         $errors['filter'] = ts("Only 'get' and 'lookup' actions are supported.");
                     }
                 }
                 $self->setDefaults(array('filter_selected', $fields['filter_selected']));
                 break;
         }
     }
     if (self::$_dataTypeKeys[$fields['data_type'][0]] == 'Date') {
         if (!$fields['date_format']) {
             $errors['date_format'] = ts('Please select a date format.');
         }
     }
     /** Check the option values entered
      *  Appropriate values are required for the selected datatype
      *  Incomplete row checking is also required.
      */
     $_flagOption = $_rowError = 0;
     $_showHide = new CRM_Core_ShowHideBlocks('', '');
     $dataType = self::$_dataTypeKeys[$fields['data_type'][0]];
     if (isset($fields['data_type'][1])) {
         $dataField = $fields['data_type'][1];
     }
     $optionFields = array('Select', 'Multi-Select', 'CheckBox', 'Radio', 'AdvMulti-Select');
     if (isset($fields['option_type']) && $fields['option_type'] == 1) {
         //capture duplicate Custom option values
         if (!empty($fields['option_value'])) {
             $countValue = count($fields['option_value']);
             $uniqueCount = count(array_unique($fields['option_value']));
             if ($countValue > $uniqueCount) {
                 $start = 1;
                 while ($start < self::NUM_OPTION) {
                     $nextIndex = $start + 1;
                     while ($nextIndex <= self::NUM_OPTION) {
                         if ($fields['option_value'][$start] == $fields['option_value'][$nextIndex] && !empty($fields['option_value'][$nextIndex])) {
                             $errors['option_value[' . $start . ']'] = ts('Duplicate Option values');
                             $errors['option_value[' . $nextIndex . ']'] = ts('Duplicate Option values');
                             $_flagOption = 1;
                         }
                         $nextIndex++;
                     }
                     $start++;
                 }
             }
         }
         //capture duplicate Custom Option label
         if (!empty($fields['option_label'])) {
             $countValue = count($fields['option_label']);
             $uniqueCount = count(array_unique($fields['option_label']));
             if ($countValue > $uniqueCount) {
                 $start = 1;
                 while ($start < self::NUM_OPTION) {
                     $nextIndex = $start + 1;
                     while ($nextIndex <= self::NUM_OPTION) {
                         if ($fields['option_label'][$start] == $fields['option_label'][$nextIndex] && !empty($fields['option_label'][$nextIndex])) {
                             $errors['option_label[' . $start . ']'] = ts('Duplicate Option label');
                             $errors['option_label[' . $nextIndex . ']'] = ts('Duplicate Option label');
                             $_flagOption = 1;
                         }
                         $nextIndex++;
                     }
                     $start++;
                 }
             }
         }
         for ($i = 1; $i <= self::NUM_OPTION; $i++) {
             if (!$fields['option_label'][$i]) {
                 if ($fields['option_value'][$i]) {
                     $errors['option_label[' . $i . ']'] = ts('Option label cannot be empty');
                     $_flagOption = 1;
                 } else {
                     $_emptyRow = 1;
                 }
             } else {
                 if (!strlen(trim($fields['option_value'][$i]))) {
                     if (!$fields['option_value'][$i]) {
                         $errors['option_value[' . $i . ']'] = ts('Option value cannot be empty');
                         $_flagOption = 1;
                     }
                 }
             }
             if ($fields['option_value'][$i] && $dataType != 'String') {
                 if ($dataType == 'Int') {
                     if (!CRM_Utils_Rule::integer($fields['option_value'][$i])) {
                         $_flagOption = 1;
                         $errors['option_value[' . $i . ']'] = ts('Please enter a valid integer.');
                     }
                 } elseif ($dataType == 'Money') {
                     if (!CRM_Utils_Rule::money($fields['option_value'][$i])) {
                         $_flagOption = 1;
                         $errors['option_value[' . $i . ']'] = ts('Please enter a valid money value.');
                     }
                 } else {
                     if (!CRM_Utils_Rule::numeric($fields['option_value'][$i])) {
                         $_flagOption = 1;
                         $errors['option_value[' . $i . ']'] = ts('Please enter a valid number.');
                     }
                 }
             }
             $showBlocks = 'optionField_' . $i;
             if ($_flagOption) {
                 $_showHide->addShow($showBlocks);
                 $_rowError = 1;
             }
             if (!empty($_emptyRow)) {
                 $_showHide->addHide($showBlocks);
             } else {
                 $_showHide->addShow($showBlocks);
             }
             if ($i == self::NUM_OPTION) {
                 $hideBlock = 'additionalOption';
                 $_showHide->addHide($hideBlock);
             }
             $_flagOption = $_emptyRow = 0;
         }
     } elseif (isset($dataField) && in_array($dataField, $optionFields) && !in_array($dataType, array('Boolean', 'Country', 'StateProvince'))) {
         if (!$fields['option_group_id']) {
             $errors['option_group_id'] = ts('You must select a Multiple Choice Option set if you chose Reuse an existing set.');
         } else {
             $query = "\nSELECT count(*)\nFROM   civicrm_custom_field\nWHERE  data_type != %1\nAND    option_group_id = %2";
             $params = array(1 => array(self::$_dataTypeKeys[$fields['data_type'][0]], 'String'), 2 => array($fields['option_group_id'], 'Integer'));
             $count = CRM_Core_DAO::singleValueQuery($query, $params);
             if ($count > 0) {
                 $errors['option_group_id'] = ts('The data type of the multiple choice option set you\'ve selected does not match the data type assigned to this field.');
             }
         }
     }
     $assignError = new CRM_Core_Page();
     if ($_rowError) {
         $_showHide->addToTemplate();
         $assignError->assign('optionRowError', $_rowError);
     } else {
         if (isset($fields['data_type'][1])) {
             switch (self::$_dataToHTML[$fields['data_type'][0]][$fields['data_type'][1]]) {
                 case 'Radio':
                     $_fieldError = 1;
                     $assignError->assign('fieldError', $_fieldError);
                     break;
                 case 'Checkbox':
                     $_fieldError = 1;
                     $assignError->assign('fieldError', $_fieldError);
                     break;
                 case 'Select':
                     $_fieldError = 1;
                     $assignError->assign('fieldError', $_fieldError);
                     break;
                 default:
                     $_fieldError = 0;
                     $assignError->assign('fieldError', $_fieldError);
             }
         }
         for ($idx = 1; $idx <= self::NUM_OPTION; $idx++) {
             $showBlocks = 'optionField_' . $idx;
             if (!empty($fields['option_label'][$idx])) {
                 $_showHide->addShow($showBlocks);
             } else {
                 $_showHide->addHide($showBlocks);
             }
         }
         $_showHide->addToTemplate();
     }
     // we can not set require and view at the same time.
     if (CRM_Utils_Array::value('is_required', $fields) && CRM_Utils_Array::value('is_view', $fields)) {
         $errors['is_view'] = ts('Can not set this field Required and View Only at the same time.');
     }
     return empty($errors) ? TRUE : $errors;
 }
예제 #22
0
 /**
  * This function sets the default values for the form.
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     $mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, FALSE, NULL);
     $continue = CRM_Utils_Request::retrieve('continue', 'String', $this, FALSE, NULL);
     // check that the user has permission to access mailing id
     CRM_Mailing_BAO_Mailing::checkPermission($mailingID);
     $defaults = array();
     if ($mailingID) {
         $mailing = new CRM_Mailing_DAO_Mailing();
         $mailing->id = $mailingID;
         $mailing->addSelect('name', 'campaign_id');
         $mailing->find(TRUE);
         $defaults['name'] = $mailing->name;
         if (!$continue) {
             $defaults['name'] = ts('Copy of %1', array(1 => $mailing->name));
         } else {
             // CRM-7590, reuse same mailing ID if we are continuing
             $this->set('mailing_id', $mailingID);
         }
         $defaults['campaign_id'] = $mailing->campaign_id;
         $defaults['dedupe_email'] = $mailing->dedupe_email;
         $dao = new CRM_Mailing_DAO_Group();
         $mailingGroups = array();
         $dao->mailing_id = $mailingID;
         $dao->find();
         while ($dao->fetch()) {
             $mailingGroups[$dao->entity_table][$dao->group_type][] = $dao->entity_id;
         }
         $defaults['includeGroups'] = $mailingGroups['civicrm_group']['Include'];
         $defaults['excludeGroups'] = CRM_Utils_Array::value('Exclude', $mailingGroups['civicrm_group']);
         $defaults['includeMailings'] = CRM_Utils_Array::value('Include', $mailingGroups['civicrm_mailing']);
         $defaults['excludeMailings'] = $mailingGroups['civicrm_mailing']['Exclude'];
     }
     //when the context is search hide the mailing recipients.
     $showHide = new CRM_Core_ShowHideBlocks();
     $showGroupSelector = TRUE;
     if ($this->_searchBasedMailing) {
         $showGroupSelector = FALSE;
         $formElements = array('includeGroups', 'excludeGroups', 'includeMailings', 'excludeMailings');
         $formValues = $this->controller->exportValues($this->_name);
         foreach ($formElements as $element) {
             if (!empty($formValues[$element])) {
                 $showGroupSelector = TRUE;
                 break;
             }
         }
     }
     if ($showGroupSelector) {
         $showHide->addShow("id-additional");
         $showHide->addHide("id-additional-show");
     } else {
         $showHide->addShow("id-additional-show");
         $showHide->addHide("id-additional");
     }
     $showHide->addToTemplate();
     return $defaults;
 }
예제 #23
0
 /**
  * Check for empty order_by configurations and remove them.
  *
  * Also set template to hide them.
  *
  * @param array $formValues
  */
 public function preProcessOrderBy(&$formValues)
 {
     // Object to show/hide form elements
     $_showHide = new CRM_Core_ShowHideBlocks('', '');
     $_showHide->addShow('optionField_1');
     // Cycle through order_by options; skip any empty ones, and hide them as well
     $n = 1;
     if (!empty($formValues['order_bys'])) {
         foreach ($formValues['order_bys'] as $order_by) {
             if ($order_by['column'] && $order_by['column'] != '-') {
                 $_showHide->addShow('optionField_' . $n);
                 $orderBys[$n] = $order_by;
                 $n++;
             }
         }
     }
     for ($i = $n; $i <= 5; $i++) {
         if ($i > 1) {
             $_showHide->addHide('optionField_' . $i);
         }
     }
     // overwrite order_by options with modified values
     if (!empty($orderBys)) {
         $formValues['order_bys'] = $orderBys;
     } else {
         $formValues['order_bys'] = array(1 => array('column' => '-'));
     }
     // assign show/hide data to template
     $_showHide->addToTemplate();
 }
예제 #24
0
 /**
  * This function provides the HTML form elements that are specific to the Individual Contact Type
  * 
  * @access public
  * @return None 
  */
 public function buildQuickForm(&$form, $action = null)
 {
     $form->applyFilter('__ALL__', 'trim');
     //prefix
     $prefix = CRM_Core_PseudoConstant::individualPrefix();
     if (!empty($prefix)) {
         $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => '') + $prefix);
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
     // first_name
     $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']);
     //middle_name
     $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']);
     // last_name
     $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']);
     // suffix
     $suffix = CRM_Core_PseudoConstant::individualSuffix();
     if ($suffix) {
         $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => '') + $suffix);
     }
     // nick_name
     $form->addElement('text', 'nick_name', ts('Nick Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name'));
     // job title
     // override the size for UI to look better
     $attributes['job_title']['size'] = 30;
     $form->addElement('text', 'job_title', ts('Job title'), $attributes['job_title'], 'size="30"');
     //Current Employer Element
     $employerDataURL = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&org=1', false, null, false);
     $form->assign('employerDataURL', $employerDataURL);
     $form->addElement('text', 'current_employer', ts('Current Employer'), '');
     $form->addElement('hidden', 'current_employer_id', '', array('id' => 'current_employer_id'));
     $form->addElement('text', 'contact_source', ts('Source'));
     $checkSimilar = defined('CIVICRM_CONTACT_AJAX_CHECK_SIMILAR') ? CIVICRM_CONTACT_AJAX_CHECK_SIMILAR : true;
     $form->assign('checkSimilar', $checkSimilar);
     //External Identifier Element
     $form->add('text', 'external_identifier', ts('External Id'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), false);
     $form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
     $config = CRM_Core_Config::singleton();
     CRM_Core_ShowHideBlocks::links($form, 'demographics', '', '');
 }
예제 #25
0
 /**
  * This function provides the HTML form elements that are specific to the Individual Contact Type.
  *
  * @param CRM_Core_Form $form
  *   Form object.
  * @param int $inlineEditMode
  *   ( 1 for contact summary.
  * top bar form and 2 for display name edit )
  */
 public static function buildQuickForm(&$form, $inlineEditMode = NULL)
 {
     $form->applyFilter('__ALL__', 'trim');
     if (!$inlineEditMode || $inlineEditMode == 1) {
         $nameFields = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 2');
         // Fixme: dear god why? these come out in a format that is NOT the name of the fields.
         foreach ($nameFields as &$fix) {
             $fix = str_replace(' ', '_', strtolower($fix));
             if ($fix == 'prefix' || $fix == 'suffix') {
                 // God, why god?
                 $fix .= '_id';
             }
         }
         foreach ($nameFields as $name) {
             $props = array();
             if ($name == 'prefix_id' || $name == 'suffix_id') {
                 $options = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $name);
                 // Skip if we have no options available
                 if (!CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $name)) {
                     //continue;
                 }
                 $props = array('class' => 'eight', 'placeholder' => ' ', 'label' => $name == 'prefix_id' ? ts('Prefix') : ts('Suffix'));
             }
             $form->addField($name, $props);
         }
     }
     if (!$inlineEditMode || $inlineEditMode == 2) {
         // nick_name
         $form->addField('nick_name');
         // job title
         // override the size for UI to look better
         $form->addField('job_title', array('size' => '30'));
         //Current Employer Element
         $props = array('api' => array('params' => array('contact_type' => 'Organization')), 'create' => TRUE);
         $form->addField('employer_id', $props);
         $form->addField('contact_source', array('class' => 'big'));
     }
     if (!$inlineEditMode) {
         $checkSimilar = Civi::settings()->get('contact_ajax_check_similar');
         if ($checkSimilar == NULL) {
             $checkSimilar = 0;
         }
         $form->assign('checkSimilar', $checkSimilar);
         //External Identifier Element
         $form->addField('external_identifier', array('label' => 'External ID'));
         $form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
         CRM_Core_ShowHideBlocks::links($form, 'demographics', '', '');
     }
 }
예제 #26
0
 static function formRule($params)
 {
     $showHide = new CRM_Core_ShowHideBlocks();
     // Make sure role is not -1
     if ($params['entity_id'] == -1) {
         $errors['entity_id'] = ts('Please assign this permission to a Role.');
     }
     $validOperations = array('View', 'Edit');
     $operationMessage = ts("Only 'View' and 'Edit' operations are valid for this type of data");
     // Figure out which type of object we're permissioning on and make sure user has selected a value.
     switch ($params['object_type']) {
         case 1:
             if ($params['group_id'] == -1) {
                 $errors['group_id'] = ts('Please select a Group (or ALL Groups).');
                 $showHide->addShow("id-group-acl");
                 $showHide->addHide("id-profile-acl");
                 $showHide->addHide("id-custom-acl");
                 $showHide->addHide("id-event-acl");
             }
             if (!in_array($params['operation'], $validOperations)) {
                 $errors['operation'] = $operationMessage;
             }
             break;
         case 2:
             if ($params['uf_group_id'] == -1) {
                 $errors['uf_group_id'] = ts('Please select a Profile (or ALL Profiles).');
                 $showHide->addShow("id-profile-acl");
                 $showHide->addHide("id-group-acl");
                 $showHide->addHide("id-custom-acl");
                 $showHide->addHide("id-event-acl");
             }
             break;
         case 3:
             if ($params['custom_group_id'] == -1) {
                 $errors['custom_group_id'] = ts('Please select a set of Custom Data (or ALL Custom Data).');
                 $showHide->addShow("id-custom-acl");
                 $showHide->addHide("id-group-acl");
                 $showHide->addHide("id-profile-acl");
                 $showHide->addHide("id-event-acl");
             }
             if (!in_array($params['operation'], $validOperations)) {
                 $errors['operation'] = $operationMessage;
             }
             break;
         case 4:
             if ($params['event_id'] == -1) {
                 $errors['event_id'] = ts('Please select an Event (or ALL Events).');
                 $showHide->addShow("id-event-acl");
                 $showHide->addHide("id-custom-acl");
                 $showHide->addHide("id-group-acl");
                 $showHide->addHide("id-profile-acl");
             }
             if (!in_array($params['operation'], $validOperations)) {
                 $errors['operation'] = $operationMessage;
             }
             break;
     }
     $showHide->addToTemplate();
     return empty($errors) ? TRUE : $errors;
 }
예제 #27
0
 /**
  * This function sets the default values for the form.
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     $mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, false, null);
     $continue = CRM_Utils_Request::retrieve('continue', 'String', $this, false, null);
     // check that the user has permission to access mailing id
     require_once 'CRM/Mailing/BAO/Mailing.php';
     CRM_Mailing_BAO_Mailing::checkPermission($mailingID);
     $defaults = array();
     if ($mailingID && $continue) {
         $defaults['name'] = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $mailingID, 'name', 'id');
         $this->set('mailing_id', $mailingID);
     } elseif ($mailingID && !$continue) {
         $defaults['name'] = ts('Copy of %1', array(1 => CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $mailingID, 'name', 'id')));
     }
     if ($mailingID) {
         require_once 'CRM/Mailing/DAO/Group.php';
         $dao =& new CRM_Mailing_DAO_Group();
         $mailingGroups = array();
         $dao->mailing_id = $mailingID;
         $dao->find();
         while ($dao->fetch()) {
             $mailingGroups[$dao->entity_table][$dao->group_type][] = $dao->entity_id;
         }
         $defaults['includeGroups'] = $mailingGroups['civicrm_group']['Include'];
         $defaults['excludeGroups'] = CRM_Utils_Array::value('Exclude', $mailingGroups['civicrm_group']);
         $defaults['includeMailings'] = CRM_Utils_Array::value('Include', $mailingGroups['civicrm_mailing']);
         $defaults['excludeMailings'] = $mailingGroups['civicrm_mailing']['Exclude'];
     }
     //when the context is search hide the mailing recipients.
     require_once 'CRM/Core/ShowHideBlocks.php';
     $showHide = new CRM_Core_ShowHideBlocks();
     $showGroupSelector = true;
     if ($this->_searchBasedMailing) {
         $showGroupSelector = false;
         $formElements = array('includeGroups', 'excludeGroups', 'includeMailings', 'excludeMailings');
         $formValues = $this->controller->exportValues($this->_name);
         foreach ($formElements as $element) {
             if (!empty($formValues[$element])) {
                 $showGroupSelector = true;
                 break;
             }
         }
     }
     if ($showGroupSelector) {
         $showHide->addShow("id-additional");
         $showHide->addHide("id-additional-show");
     } else {
         $showHide->addShow("id-additional-show");
         $showHide->addHide("id-additional");
     }
     $showHide->addToTemplate();
     return $defaults;
 }
예제 #28
0
 /**
  * generic function to build all the form elements for a specific group tree
  *
  * @param CRM_Core_Form $form      the form object
  * @param array         $groupTree the group tree object
  * @param string        $showName  
  * @param string        $hideName
  *
  * @return void
  * @access public
  * @static
  */
 static function buildQuickForm(&$form, &$groupTree, $inactiveNeeded = false, $groupCount = 1, $prefix = '')
 {
     require_once 'CRM/Core/BAO/CustomField.php';
     require_once 'CRM/Core/BAO/CustomOption.php';
     $form->assign_by_ref("{$prefix}groupTree", $groupTree);
     $sBlocks = array();
     $hBlocks = array();
     // this is fix for date field
     $form->assign('currentYear', date('Y'));
     require_once 'CRM/Core/ShowHideBlocks.php';
     foreach ($groupTree as $id => $group) {
         CRM_Core_ShowHideBlocks::links($form, $group['title'], '', '');
         $groupId = CRM_Utils_Array::value('id', $group);
         foreach ($group['fields'] as $field) {
             // skip all view fields
             if (CRM_Utils_Array::value('is_view', $field)) {
                 continue;
             }
             $required = CRM_Utils_Array::value('is_required', $field);
             //fix for CRM-1620
             if ($field['data_type'] == 'File') {
                 if (isset($field['customValue']['data'])) {
                     $required = 0;
                 }
             }
             $fieldId = $field['id'];
             $elementName = $field['element_name'];
             require_once "CRM/Core/BAO/CustomField.php";
             CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, $inactiveNeeded, $required);
         }
     }
 }
예제 #29
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->addYesNo('is_monetary', ts('Paid Event'), NULL, NULL, array('onclick' => "return showHideByValue('is_monetary','0','event-fees','block','radio',false);"));
     //add currency element.
     $this->addCurrency('currency', ts('Currency'), FALSE);
     $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor();
     $this->assign('paymentProcessor', $paymentProcessor);
     $this->addEntityRef('payment_processor', ts('Payment Processor'), array('entity' => 'PaymentProcessor', 'multiple' => TRUE, 'select' => array('minimumInputLength' => 0)));
     // financial type
     if (!CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() || CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && CRM_Core_Permission::check('administer CiviCRM Financial Types')) {
         $this->addSelect('financial_type_id');
     } else {
         CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD);
         $this->addSelect('financial_type_id', array('context' => 'search', 'options' => $financialTypes));
     }
     // add pay later options
     $this->addElement('checkbox', 'is_pay_later', ts('Enable Pay Later option?'), NULL, array('onclick' => "return showHideByValue('is_pay_later','','payLaterOptions','block','radio',false);"));
     $this->addElement('textarea', 'pay_later_text', ts('Pay Later Label'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_text'), FALSE);
     $this->add('wysiwyg', 'pay_later_receipt', ts('Pay Later Instructions'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_receipt'));
     $this->addElement('checkbox', 'is_billing_required', ts('Billing address required'));
     $this->add('text', 'fee_label', ts('Fee Label'));
     $price = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviEvent');
     if (CRM_Utils_System::isNull($price)) {
         $this->assign('price', FALSE);
     } else {
         $this->assign('price', TRUE);
     }
     $this->add('select', 'price_set_id', ts('Price Set'), array('' => ts('- none -')) + $price, NULL, array('onchange' => "return showHideByValue('price_set_id', '', 'map-field', 'block', 'select', false);"));
     $default = array($this->createElement('radio', NULL, NULL, NULL, 0));
     $this->add('hidden', 'price_field_id', '', array('id' => 'price_field_id'));
     for ($i = 1; $i <= self::NUM_OPTION; $i++) {
         // label
         $this->add('text', "label[{$i}]", ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'));
         $this->add('hidden', "price_field_value[{$i}]", '', array('id' => "price_field_value[{$i}]"));
         // value
         $this->add('text', "value[{$i}]", ts('Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'));
         $this->addRule("value[{$i}]", ts('Please enter a valid money value for this field (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
         // default
         $default[] = $this->createElement('radio', NULL, NULL, NULL, $i);
     }
     $this->addGroup($default, 'default');
     $this->addElement('checkbox', 'is_discount', ts('Discounts by Signup Date?'), NULL, array('onclick' => "warnDiscountDel(); return showHideByValue('is_discount','','discount','block','radio',false);"));
     $discountSection = $this->get('discountSection');
     $this->assign('discountSection', $discountSection);
     // form fields of Discount sets
     $defaultOption = array();
     $_showHide = new CRM_Core_ShowHideBlocks('', '');
     for ($i = 1; $i <= self::NUM_DISCOUNT; $i++) {
         //the show hide blocks
         $showBlocks = 'discount_' . $i;
         if ($i > 2) {
             $_showHide->addHide($showBlocks);
         } else {
             $_showHide->addShow($showBlocks);
         }
         //Increment by 1 of start date of previous end date.
         if (is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i + 1]) && isset($this->_submitValues['discount_end_date']) && isset($this->_submitValues['discount_end_date'][$i]) && $i < self::NUM_DISCOUNT - 1) {
             $end_date = CRM_Utils_Date::processDate($this->_submitValues['discount_end_date'][$i]);
             if (!empty($this->_submitValues['discount_end_date'][$i + 1]) && empty($this->_submitValues['discount_start_date'][$i + 1])) {
                 list($this->_submitValues['discount_start_date'][$i + 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("+1 days {$end_date}")));
             }
         }
         //Decrement by 1 of end date from next start date.
         if ($i > 1 && is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i - 1]) && isset($this->_submitValues['discount_start_date']) && isset($this->_submitValues['discount_start_date'][$i])) {
             $start_date = CRM_Utils_Date::processDate($this->_submitValues['discount_start_date'][$i]);
             if (!empty($this->_submitValues['discount_start_date'][$i]) && empty($this->_submitValues['discount_end_date'][$i - 1])) {
                 list($this->_submitValues['discount_end_date'][$i - 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("-1 days {$start_date}")));
             }
         }
         //discount name
         $this->add('text', 'discount_name[' . $i . ']', ts('Discount Name'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'title'));
         $this->add('hidden', "discount_price_set[{$i}]", '', array('id' => "discount_price_set[{$i}]"));
         //discount start date
         $this->addDate('discount_start_date[' . $i . ']', ts('Discount Start Date'), FALSE, array('formatType' => 'activityDate'));
         //discount end date
         $this->addDate('discount_end_date[' . $i . ']', ts('Discount End Date'), FALSE, array('formatType' => 'activityDate'));
     }
     $_showHide->addToTemplate();
     $this->addElement('submit', $this->getButtonName('submit'), ts('Add Discount Set to Fee Table'), array('class' => 'crm-form-submit cancel'));
     $this->buildAmountLabel();
     parent::buildQuickForm();
 }
예제 #30
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 function setDefaultValues()
 {
     $defaults = array();
     $showHide = new CRM_Core_ShowHideBlocks();
     if ($this->_action == CRM_Core_Action::ADD) {
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFJoin');
     }
     //id fetched for Dojo Pane
     $pId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     if (isset($pId)) {
         $this->_id = $pId;
     }
     if (isset($this->_id)) {
         $defaults['weight'] = CRM_Core_BAO_UFGroup::getWeight($this->_id);
         $params = array('id' => $this->_id);
         CRM_Core_BAO_UFGroup::retrieve($params, $defaults);
         $defaults['group'] = CRM_Utils_Array::value('limit_listings_group_id', $defaults);
         $defaults['add_contact_to_group'] = CRM_Utils_Array::value('add_to_group_id', $defaults);
         //get the uf join records for current uf group
         $ufJoinRecords = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_id);
         foreach ($ufJoinRecords as $key => $value) {
             $checked[$value] = 1;
         }
         $defaults['uf_group_type'] = isset($checked) ? $checked : "";
         //get the uf join records for current uf group other than default modules
         $otherModules = array();
         $otherModules = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_id, TRUE, TRUE);
         if (!empty($otherModules)) {
             $otherModuleString = NULL;
             foreach ($otherModules as $key) {
                 $otherModuleString .= " [ x ] <label>" . $key . "</label>";
             }
             $this->assign('otherModuleString', $otherModuleString);
         }
         $showAdvanced = 0;
         $advFields = array('group', 'post_URL', 'cancel_URL', 'add_captcha', 'is_map', 'is_uf_link', 'is_edit_link', 'is_update_dupe', 'is_cms_user', 'is_proximity_search');
         foreach ($advFields as $key) {
             if (!empty($defaults[$key])) {
                 $showAdvanced = 1;
                 $this->_allPanes['Advanced Settings']['open'] = 'true';
                 break;
             }
         }
     } else {
         $defaults['is_active'] = 1;
         $defaults['is_map'] = 0;
         $defaults['is_update_dupe'] = 0;
         $defaults['is_proximity_search'] = 0;
     }
     // Don't assign showHide elements to template in DELETE mode (fields to be shown and hidden don't exist)
     if (!($this->_action & CRM_Core_Action::DELETE) && !($this->_action & CRM_Core_Action::DISABLE)) {
         $showHide->addToTemplate();
     }
     $this->assign('allPanes', $this->_allPanes);
     return $defaults;
 }