/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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(); }
/** * 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; }
/** * 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; }
/** * global validation rules for the form * */ static function formRule($fields, $files, $form) { $errors = array(); if (CRM_Utils_Array::value('option_label', $fields) && CRM_Utils_Array::value('option_value', $fields) && count(array_filter($fields['option_label'])) == 0 && count(array_filter($fields['option_value'])) == 0) { $errors['option_label[1]'] = ts('Enter atleast one response option.'); return $errors; } else { if (!CRM_Utils_Array::value('option_label', $fields) && !CRM_Utils_Array::value('option_value', $fields)) { return $errors; } } if ($fields['option_type'] == 2 && !CRM_Utils_Array::value('option_group_id', $fields)) { $errors['option_group_id'] = ts("Please select Survey Response set."); return $errors; } $_flagOption = $_rowError = 0; $_showHide = new CRM_Core_ShowHideBlocks('', ''); //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 (CRM_Utils_Array::value($i, $fields['option_interval']) && !CRM_Utils_Rule::integer($fields['option_interval'][$i])) { $_flagOption = 1; $errors['option_interval[' . $i . ']'] = ts('Please enter a valid integer.'); } $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; } $_showHide->addToTemplate(); return empty($errors) ? true : $errors; }
/** * Set default values for the form. * the default values are retrieved from the database * * * @return void */ public function setDefaultValues() { $continue = CRM_Utils_Request::retrieve('continue', 'String', $this, FALSE, NULL); $defaults = array(); $defaults['dedupe_email'] = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'dedupe_email_default', NULL, FALSE); if ($this->_mailingID) { // check that the user has permission to access mailing id CRM_Mailing_BAO_Mailing::checkPermission($this->_mailingID); $mailing = new CRM_Mailing_DAO_Mailing(); $mailing->id = $this->_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', $this->_mailingID); } $defaults['campaign_id'] = $mailing->campaign_id; $defaults['dedupe_email'] = $mailing->dedupe_email; $defaults['location_type_id'] = $mailing->location_type_id; $defaults['email_selection_method'] = $mailing->email_selection_method; $dao = new CRM_Mailing_DAO_MailingGroup(); $mailingGroups = array('civicrm_group' => array(), 'civicrm_mailing' => array()); $dao->mailing_id = $this->_mailingID; $dao->find(); while ($dao->fetch()) { // account for multi-lingual // CRM-11431 $entityTable = 'civicrm_group'; if (substr($dao->entity_table, 0, 15) == 'civicrm_mailing') { $entityTable = 'civicrm_mailing'; } $mailingGroups[$entityTable][$dao->group_type][] = $dao->entity_id; } $defaults['includeGroups'] = CRM_Utils_Array::value('Include', $mailingGroups['civicrm_group']); $defaults['excludeGroups'] = CRM_Utils_Array::value('Exclude', $mailingGroups['civicrm_group']); if (!empty($mailingGroups['civicrm_mailing'])) { $defaults['includeMailings'] = CRM_Utils_Array::value('Include', $mailingGroups['civicrm_mailing']); $defaults['excludeMailings'] = CRM_Utils_Array::value('Exclude', $mailingGroups['civicrm_mailing']); } } //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; }
/** * function to show/hide the block * * @param CRM_Core_ShowHideBlocks $showHide the showHide object * * @access public */ function updateShowHideSubBlocks(&$showHide, $name, $prefix, &$values) { if (empty($values)) { return; } $blockKeys = array_keys($values); foreach ($blockKeys as $blockId) { /* if ( empty( $values[$blockId] ) ) { continue; }*/ $blocks = $values[$blockId]; $blockFlag = false; foreach ($blocks as $block) { if ($block != '') { $blockFlag = true; } } if (!$blockFlag) { continue; } // blockId 1 is always shows if ($blockId == 1) { continue; } $showHide->addShow("{$prefix}[{$name}][{$blockId}]"); $showHide->addHide("{$prefix}[{$name}][{$blockId}][show]"); if ($blockId < CRM_CONTACT_FORM_LOCATION_BLOCKS) { $nextBlockId = $blockId + 1; $showHide->addShow("{$prefix}[{$name}][{$nextBlockId}][show]"); } } }
/** * 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, $force) { $this->_showHide =& new CRM_Core_ShowHideBlocks(array('commPrefs' => 1), ''); if ($this->_contactType == 'Individual') { $this->_showHide->addShow('demographics[show]'); $this->_showHide->addHide('demographics'); } // first do the defaults showing CRM_Contact_Form_Location::setShowHideDefaults($this->_showHide, CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS); if ($this->_action & CRM_CORE_ACTION_ADD) { // notes are only included in the template for New Contact $this->_showHide->addShow('notes[show]'); $this->_showHide->addHide('notes'); } //add group and tags $contactGroup = $contactTag = array(); if ($this->_contactId) { $contactGroup =& CRM_Contact_BAO_GroupContact::getContactGroup($this->_contactId, 'Added'); $contactTag =& CRM_Core_BAO_EntityTag::getTag('civicrm_contact', $this->_contactId); } if (empty($contactGroup) || empty($contactTag)) { $this->_showHide->addShow('group[show]'); $this->_showHide->addHide('group'); } else { $this->_showHide->addShow('group'); $this->_showHide->addHide('group[show]'); } // is there any demographics data? if (CRM_Utils_Array::value('gender_id', $defaults) || CRM_Utils_Array::value('is_deceased', $defaults) || CRM_Utils_Array::value('birth_date', $defaults)) { $this->_showHide->addShow('demographics'); $this->_showHide->addHide('demographics[show]'); } if ($force) { $locationDefaults = CRM_Utils_Array::value('location', $defaults); CRM_Contact_Form_Location::updateShowHide($this->_showHide, $locationDefaults, CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS); } $this->_showHide->addToTemplate(); }
/** * Function to build the form * * @return None * @access public */ 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->addCheckBox('payment_processor', ts('Payment Processor'), array_flip($paymentProcessor), NULL, NULL, NULL, NULL, array(' ', ' ', ' ', '<br/>')); $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); // 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->addElement('textarea', 'pay_later_receipt', ts('Pay Later Instructions'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_receipt'), FALSE); $this->add('text', 'fee_label', ts('Fee Label')); $price = CRM_Price_BAO_Set::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->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_Set', 'title')); $this->add('hidden', "discount_price_set[{$i}]", '', array('id' => "discount_price_set[{$i}]")); // add a rule to ensure that discount name is not more than 24 characters to prevent overflow // in option group name, CRM-7915 // 24 characters will make the option group name less than 64 characters $this->addRule("discount_name[{$i}]", ts('Discount Name cannot be more than 24 characters'), 'maxlength', 24); //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' => 'form-submit')); $this->buildAmountLabel(); parent::buildQuickForm(); }
/** * 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; }
/** * 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(); }
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; }