function browse()
 {
     CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
     $statusTypes = array();
     $dao = new CRM_Event_DAO_ParticipantStatusType();
     $dao->orderBy('weight');
     $dao->find();
     $visibilities = CRM_Core_PseudoConstant::visibility();
     // these statuses are reserved, but disabled by default - so should be disablable after being enabled
     $disablable = array('On waitlist', 'Awaiting approval', 'Pending from waitlist', 'Pending from approval', 'Rejected');
     while ($dao->fetch()) {
         CRM_Core_DAO::storeValues($dao, $statusTypes[$dao->id]);
         $action = array_sum(array_keys($this->links()));
         if ($dao->is_reserved) {
             $action -= CRM_Core_Action::DELETE;
             if (!in_array($dao->name, $disablable)) {
                 $action -= CRM_Core_Action::DISABLE;
             }
         }
         $action -= $dao->is_active ? CRM_Core_Action::ENABLE : CRM_Core_Action::DISABLE;
         $statusTypes[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id), ts('more'), FALSE, 'participantStatusType.manage.action', 'ParticipantStatusType', $dao->id);
         $statusTypes[$dao->id]['visibility'] = $visibilities[$dao->visibility_id];
     }
     $this->assign('rows', $statusTypes);
 }
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_ParticipantStatusType');
     $this->add('text', 'name', ts('Name'), NULL, TRUE);
     $this->add('text', 'label', ts('Label'), $attributes['label'], TRUE);
     $classes = array('Positive' => ts('Positive'), 'Pending' => ts('Pending'), 'Waiting' => ts('Waiting'), 'Negative' => ts('Negative'));
     $this->add('select', 'class', ts('Class'), $classes, TRUE);
     $this->add('checkbox', 'is_active', ts('Active?'));
     $this->add('checkbox', 'is_counted', ts('Counted?'));
     $this->add('text', 'weight', ts('Weight'), $attributes['weight'], TRUE);
     $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility(), TRUE);
 }
Пример #3
0
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_ParticipantStatusType');
     $this->add('text', 'name', ts('Name'), $attributes['name'], true);
     $this->add('text', 'label', ts('Label'), $attributes['label'], true);
     $classes = array();
     foreach (array('Positive', 'Pending', 'Waiting', 'Negative') as $class) {
         $classes[$class] = CRM_Event_DAO_ParticipantStatusType::tsEnum('class', $class);
     }
     $this->add('select', 'class', ts('Class'), $classes, true);
     $this->add('checkbox', 'is_active', ts('Active?'));
     $this->add('checkbox', 'is_counted', ts('Counted?'));
     $this->add('text', 'weight', ts('Weight'), $attributes['weight'], true);
     require_once 'CRM/Core/PseudoConstant.php';
     $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility(), true);
 }
Пример #4
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     // lets trim all the whitespace
     $this->applyFilter('__ALL__', 'trim');
     // add a hidden field to remember the price set id
     // this get around the browser tab issue
     $this->add('hidden', 'sid', $this->_sid);
     $this->add('hidden', 'fid', $this->_fid);
     // label
     $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'label'), TRUE);
     // html_type
     $javascript = 'onchange="option_html_type(this.form)";';
     $htmlTypes = CRM_Price_BAO_PriceField::htmlTypes();
     // Text box for Participant Count for a field
     // Financial Type
     $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
     foreach ($financialType as $finTypeId => $type) {
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('add contributions of type ' . $type)) {
             unset($financialType[$finTypeId]);
         }
     }
     if (count($financialType)) {
         $this->assign('financialType', $financialType);
     }
     $enabledComponents = CRM_Core_Component::getEnabledComponents();
     $eventComponentId = $memberComponentId = NULL;
     if (array_key_exists('CiviEvent', $enabledComponents)) {
         $eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
     }
     if (array_key_exists('CiviMember', $enabledComponents)) {
         $memberComponentId = CRM_Core_Component::getComponentID('CiviMember');
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceFieldValue');
     $this->add('select', 'financial_type_id', ts('Financial Type'), array(' ' => ts('- select -')) + $financialType);
     $this->assign('useForMember', FALSE);
     if (in_array($eventComponentId, $this->_extendComponentId)) {
         $this->add('text', 'count', ts('Participant Count'), $attributes['count']);
         $this->addRule('count', ts('Participant Count should be a positive number'), 'positiveInteger');
         $this->add('text', 'max_value', ts('Max Participants'), $attributes['max_value']);
         $this->addRule('max_value', ts('Please enter a valid Max Participants.'), 'positiveInteger');
         $this->assign('useForEvent', TRUE);
     } else {
         if (in_array($memberComponentId, $this->_extendComponentId)) {
             $this->_useForMember = 1;
             $this->assign('useForMember', $this->_useForMember);
         }
         $this->assign('useForEvent', FALSE);
     }
     $sel = $this->add('select', 'html_type', ts('Input Field Type'), $htmlTypes, TRUE, $javascript);
     // price (for text inputs)
     $this->add('text', 'price', ts('Price'));
     $this->registerRule('price', 'callback', 'money', 'CRM_Utils_Rule');
     $this->addRule('price', ts('must be a monetary value'), 'money');
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $this->freeze('html_type');
     }
     // form fields of Custom Option rows
     $_showHide = new CRM_Core_ShowHideBlocks('', '');
     for ($i = 1; $i <= self::NUM_OPTION; $i++) {
         //the show hide blocks
         $showBlocks = 'optionField_' . $i;
         if ($i > 2) {
             $_showHide->addHide($showBlocks);
             if ($i == self::NUM_OPTION) {
                 $_showHide->addHide('additionalOption');
             }
         } else {
             $_showHide->addShow($showBlocks);
         }
         // label
         $attributes['label']['size'] = 25;
         $this->add('text', 'option_label[' . $i . ']', ts('Label'), $attributes['label']);
         // amount
         $this->add('text', 'option_amount[' . $i . ']', ts('Amount'), $attributes['amount']);
         $this->addRule('option_amount[' . $i . ']', ts('Please enter a valid amount for this field.'), 'money');
         //Financial Type
         $this->add('select', 'option_financial_type_id[' . $i . ']', ts('Financial Type'), array('' => ts('- select -')) + $financialType);
         if (in_array($eventComponentId, $this->_extendComponentId)) {
             // count
             $this->add('text', 'option_count[' . $i . ']', ts('Participant Count'), $attributes['count']);
             $this->addRule('option_count[' . $i . ']', ts('Please enter a valid Participants Count.'), 'positiveInteger');
             // max_value
             $this->add('text', 'option_max_value[' . $i . ']', ts('Max Participants'), $attributes['max_value']);
             $this->addRule('option_max_value[' . $i . ']', ts('Please enter a valid Max Participants.'), 'positiveInteger');
             // description
             //$this->add('textArea', 'option_description['.$i.']', ts('Description'), array('rows' => 1, 'cols' => 40 ));
         } elseif (in_array($memberComponentId, $this->_extendComponentId)) {
             $membershipTypes = CRM_Member_PseudoConstant::membershipType();
             $js = array('onchange' => "calculateRowValues( {$i} );");
             $this->add('select', 'membership_type_id[' . $i . ']', ts('Membership Type'), array('' => ' ') + $membershipTypes, FALSE, $js);
             $this->add('text', 'membership_num_terms[' . $i . ']', ts('Number of Terms'), CRM_Utils_Array::value('membership_num_terms', $attributes));
         }
         // weight
         $this->add('text', 'option_weight[' . $i . ']', ts('Order'), $attributes['weight']);
         // is active ?
         $this->add('checkbox', 'option_status[' . $i . ']', ts('Active?'));
         $defaultOption[$i] = $this->createElement('radio', NULL, NULL, NULL, $i);
         //for checkbox handling of default option
         $this->add('checkbox', "default_checkbox_option[{$i}]", NULL);
     }
     //default option selection
     $this->addGroup($defaultOption, 'default_option');
     $_showHide->addToTemplate();
     // is_display_amounts
     $this->add('checkbox', 'is_display_amounts', ts('Display Amount?'));
     // weight
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'weight'), TRUE);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     // checkbox / radio options per line
     $this->add('text', 'options_per_line', ts('Options Per Line'));
     $this->addRule('options_per_line', ts('must be a numeric value'), 'numeric');
     // help post, mask, attributes, javascript ?
     $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'help_post'));
     // active_on
     $date_options = array('format' => 'dmY His', 'minYear' => date('Y') - 1, 'maxYear' => date('Y') + 5, 'addEmptyOption' => TRUE);
     $this->addDateTime('active_on', ts('Active On'), FALSE, array('formatType' => 'activityDateTime'));
     // expire_on
     $this->addDateTime('expire_on', ts('Expire On'), FALSE, array('formatType' => 'activityDateTime'));
     // is required ?
     $this->add('checkbox', 'is_required', ts('Required?'));
     // is active ?
     $this->add('checkbox', 'is_active', ts('Active?'));
     // add buttons
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // is public?
     $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility());
     // add a form rule to check default value
     $this->addFormRule(array('CRM_Price_Form_Field', 'formRule'), $this);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid);
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='{$url}'"));
     }
 }
Пример #5
0
 /**
  * Return option-values of a particular group
  *
  * @param array $groupParams
  *   Array containing group fields whose option-values is to retrieved.
  * @param array $links
  *   Has links like edit, delete, disable ..etc.
  * @param string $orderBy
  *   For orderBy clause.
  *
  * @return array
  *   Array of option-values
  *
  */
 public static function getRows($groupParams, $links, $orderBy = 'weight')
 {
     $optionValue = array();
     $optionGroupID = NULL;
     if (!isset($groupParams['id']) || !$groupParams['id']) {
         if ($groupParams['name']) {
             $config = CRM_Core_Config::singleton();
             $optionGroup = CRM_Core_BAO_OptionGroup::retrieve($groupParams, $dnc);
             $optionGroupID = $optionGroup->id;
         }
     } else {
         $optionGroupID = $groupParams['id'];
     }
     $groupName = CRM_Utils_Array::value('name', $groupParams);
     if (!$groupName && $optionGroupID) {
         $groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $optionGroupID, 'name', 'id');
     }
     $dao = new CRM_Core_DAO_OptionValue();
     if ($optionGroupID) {
         $dao->option_group_id = $optionGroupID;
         if (in_array($groupName, CRM_Core_OptionGroup::$_domainIDGroups)) {
             $dao->domain_id = CRM_Core_Config::domainID();
         }
         $dao->orderBy($orderBy);
         $dao->find();
     }
     if ($groupName == 'case_type') {
         $caseTypeIds = CRM_Case_BAO_Case::getUsedCaseType();
     } elseif ($groupName == 'case_status') {
         $caseStatusIds = CRM_Case_BAO_Case::getUsedCaseStatuses();
     }
     $componentNames = CRM_Core_Component::getNames();
     $visibilityLabels = CRM_Core_PseudoConstant::visibility();
     while ($dao->fetch()) {
         $optionValue[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $optionValue[$dao->id]);
         // form all action links
         $action = array_sum(array_keys($links));
         // update enable/disable links depending on if it is is_reserved or is_active
         if ($dao->is_reserved) {
             $action = CRM_Core_Action::UPDATE;
         } else {
             if ($dao->is_active) {
                 $action -= CRM_Core_Action::ENABLE;
             } else {
                 $action -= CRM_Core_Action::DISABLE;
             }
             if ($groupName == 'case_type' && in_array($dao->value, $caseTypeIds) || $groupName == 'case_status' && in_array($dao->value, $caseStatusIds)) {
                 $action -= CRM_Core_Action::DELETE;
             }
         }
         $optionValue[$dao->id]['label'] = htmlspecialchars($optionValue[$dao->id]['label']);
         $optionValue[$dao->id]['order'] = $optionValue[$dao->id]['weight'];
         $optionValue[$dao->id]['action'] = CRM_Core_Action::formLink($links, $action, array('id' => $dao->id, 'gid' => $optionGroupID, 'value' => $dao->value), ts('more'), FALSE, 'optionValue.row.actions', 'optionValue', $dao->id);
         if (!empty($optionValue[$dao->id]['component_id'])) {
             $optionValue[$dao->id]['component_name'] = $componentNames[$optionValue[$dao->id]['component_id']];
         } else {
             $optionValue[$dao->id]['component_name'] = 'Contact';
         }
         if (!empty($optionValue[$dao->id]['visibility_id'])) {
             $optionValue[$dao->id]['visibility_label'] = $visibilityLabels[$optionValue[$dao->id]['visibility_id']];
         }
     }
     return $optionValue;
 }
 /**
  * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
  *
  * Get all Visibility levels.
  *
  * The static array visibility is returned
  *
  * @access public
  * @static
  *
  * @return array - array reference of all Visibility levels.
  *
  */
 public static function &visibility($column = 'label')
 {
     if (!isset(self::$visibility)) {
         self::$visibility = array();
     }
     if (!isset(self::$visibility[$column])) {
         self::$visibility[$column] = CRM_Core_OptionGroup::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
     }
     return self::$visibility[$column];
 }
Пример #7
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->setPageTitle(ts('%1 Option', array(1 => $this->_gLabel)));
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $isReserved = FALSE;
     if ($this->_id) {
         $isReserved = (bool) CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'is_reserved');
     }
     $this->add('text', 'label', ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'), TRUE);
     if ($this->_gName != 'activity_type') {
         $this->add('text', 'value', ts('Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'), TRUE);
     }
     if (!in_array($this->_gName, array('email_greeting', 'postal_greeting', 'addressee')) && !$isReserved) {
         $this->addRule('label', ts('This Label already exists in the database for this option group. Please select a different Value.'), 'optionExists', array('CRM_Core_DAO_OptionValue', $this->_id, $this->_gid, 'label'));
     }
     if ($this->_gName == 'case_status') {
         $classes = array('Opened' => ts('Opened'), 'Closed' => ts('Closed'));
         $grouping = $this->add('select', 'grouping', ts('Status Class'), $classes);
         if ($isReserved) {
             $grouping->freeze();
         }
     }
     // CRM-11516
     if ($this->_gName == 'payment_instrument') {
         $accountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' ");
         $financialAccount = CRM_Contribute_PseudoConstant::financialAccount(NULL, key($accountType));
         $this->add('select', 'financial_account_id', ts('Financial Account'), array('' => ts('- select -')) + $financialAccount, TRUE);
     }
     $required = FALSE;
     if ($this->_gName == 'custom_search') {
         $required = TRUE;
     } elseif ($this->_gName == 'redaction_rule' || $this->_gName == 'engagement_index') {
         if ($this->_gName == 'redaction_rule') {
             $this->add('checkbox', 'filter', ts('Regular Expression?'));
         }
     }
     if ($this->_gName == 'participant_listing') {
         $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'description'));
     } else {
         // Hard-coding attributes here since description is still stored as varchar and not text in the schema. dgg
         $this->add('wysiwyg', 'description', ts('Description'), array('rows' => 4, 'cols' => 80), $required);
     }
     if ($this->_gName == 'event_badge') {
         $this->add('text', 'name', ts('Class Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'name'));
     }
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'weight'), TRUE);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     // If CiviCase enabled AND "Add" mode OR "edit" mode for non-reserved activities, only allow user to pick Core or CiviCase component.
     // FIXME: Each component should define whether adding new activity types is allowed.
     $config = CRM_Core_Config::singleton();
     if ($this->_gName == 'activity_type' && in_array("CiviCase", $config->enableComponents) && ($this->_action & CRM_Core_Action::ADD || !$isReserved)) {
         $caseID = CRM_Core_Component::getComponentID('CiviCase');
         $components = array('' => ts('Contacts AND Cases'), $caseID => ts('Cases Only'));
         $this->add('select', 'component_id', ts('Component'), $components, FALSE);
     }
     $enabled = $this->add('checkbox', 'is_active', ts('Enabled?'));
     if ($isReserved) {
         $enabled->freeze();
     }
     //fix for CRM-3552, CRM-4575
     $showIsDefaultGroups = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address', 'case_status', 'encounter_medium', 'case_type', 'payment_instrument', 'communication_style', 'soft_credit_type', 'website_type');
     if (in_array($this->_gName, $showIsDefaultGroups)) {
         $this->assign('showDefault', TRUE);
         $this->add('checkbox', 'is_default', ts('Default Option?'));
     }
     //get contact type for which user want to create a new greeting/addressee type, CRM-4575
     if (in_array($this->_gName, array('email_greeting', 'postal_greeting', 'addressee')) && !$isReserved) {
         $values = array(1 => ts('Individual'), 2 => ts('Household'), 3 => ts('Organization'), 4 => ts('Multiple Contact Merge'));
         $this->add('select', 'contactOptions', ts('Contact Type'), array('' => '-select-') + $values, TRUE);
         $this->assign('showContactFilter', TRUE);
     }
     if ($this->_gName == 'participant_status') {
         // For Participant Status options, expose the 'filter' field to track which statuses are "Counted", and the Visibility field
         $element = $this->add('checkbox', 'filter', ts('Counted?'));
         $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility());
     }
     if ($this->_gName == 'participant_role') {
         // For Participant Role options, expose the 'filter' field to track which statuses are "Counted"
         $this->add('checkbox', 'filter', ts('Counted?'));
     }
     $this->addFormRule(array('CRM_Admin_Form_Options', 'formRule'), $this);
 }
Пример #8
0
 /**
  * Function to actually build the form
  *
  * @param null
  * 
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     // lets trim all the whitespace
     $this->applyFilter('__ALL__', 'trim');
     // label
     $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_Field', 'label'), true);
     // html_type
     $javascript = 'onchange="option_html_type(this.form)";';
     require_once 'CRM/Price/BAO/Field.php';
     $htmlTypes = CRM_Price_BAO_Field::htmlTypes();
     $sel = $this->add('select', 'html_type', ts('Input Field Type'), $htmlTypes, true, $javascript);
     // Text box for Participant Count for a field
     require_once 'CRM/Core/Component.php';
     $eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Price_DAO_FieldValue');
     if (in_array($eventComponentId, $this->_extendComponentId)) {
         $this->add('text', 'count', ts('Participant Count'), $attributes['count']);
         $this->addRule('count', ts('Participant Count should be a positive number'), 'positiveInteger');
         $this->add('text', 'max_value', ts('Max Participants'), $attributes['max_value']);
         $this->addRule('max_value', ts('Please enter a valid Max Participants.'), 'positiveInteger');
         $this->add('textArea', 'description', ts('Description'), $attributes['description']);
         $this->assign('useForEvent', true);
     } else {
         $this->assign('useForEvent', false);
     }
     // price (for text inputs)
     $this->add('text', 'price', ts('Price'));
     $this->registerRule('price', 'callback', 'money', 'CRM_Utils_Rule');
     $this->addRule('price', ts('must be a monetary value'), 'money');
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $this->freeze('html_type');
     }
     // form fields of Custom Option rows
     $_showHide = new CRM_Core_ShowHideBlocks('', '');
     for ($i = 1; $i <= self::NUM_OPTION; $i++) {
         //the show hide blocks
         $showBlocks = 'optionField_' . $i;
         if ($i > 2) {
             $_showHide->addHide($showBlocks);
             if ($i == self::NUM_OPTION) {
                 $_showHide->addHide('additionalOption');
             }
         } else {
             $_showHide->addShow($showBlocks);
         }
         // label
         $attributes['label']['size'] = 25;
         $this->add('text', 'option_label[' . $i . ']', ts('Label'), $attributes['label']);
         // amount
         $this->add('text', 'option_amount[' . $i . ']', ts('Amount'), $attributes['amount']);
         $this->addRule('option_amount[' . $i . ']', ts('Please enter a valid amount for this field.'), 'money');
         if (in_array($eventComponentId, $this->_extendComponentId)) {
             // count
             $this->add('text', 'option_count[' . $i . ']', ts('Participant Count'), $attributes['count']);
             $this->addRule('option_count[' . $i . ']', ts('Please enter a valid Participants Count.'), 'positiveInteger');
             // max_value
             $this->add('text', 'option_max_value[' . $i . ']', ts('Max Participants'), $attributes['max_value']);
             $this->addRule('option_max_value[' . $i . ']', ts('Please enter a valid Max Participants.'), 'positiveInteger');
             // description
             $this->add('textArea', 'option_description[' . $i . ']', ts('Description'), array('rows' => 1, 'cols' => 40));
         }
         // weight
         $this->add('text', 'option_weight[' . $i . ']', ts('Order'), $attributes['weight']);
         // is active ?
         $this->add('checkbox', 'option_status[' . $i . ']', ts('Active?'));
         $defaultOption[$i] = $this->createElement('radio', null, null, null, $i);
         //for checkbox handling of default option
         $this->add('checkbox', "default_checkbox_option[{$i}]", null);
     }
     //default option selection
     $this->addGroup($defaultOption, 'default_option');
     $_showHide->addToTemplate();
     // is_display_amounts
     $this->add('checkbox', 'is_display_amounts', ts('Display Amount?'));
     // weight
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_Field', 'weight'), true);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     // checkbox / radio options per line
     $this->add('text', 'options_per_line', ts('Options Per Line'));
     $this->addRule('options_per_line', ts('must be a numeric value'), 'numeric');
     // help post, mask, attributes, javascript ?
     $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_Field', 'help_post'));
     // active_on
     $date_options = array('minYear' => date('Y'), 'maxYear' => date('Y') + 5, 'addEmptyOption' => true);
     $this->add('date', 'active_on', ts('Active On'), $date_options);
     // expire_on
     $this->add('date', 'expire_on', ts('Expire On'), $date_options);
     // is required ?
     $this->add('checkbox', 'is_required', ts('Required?'));
     // is active ?
     $this->add('checkbox', 'is_active', ts('Active?'));
     // add buttons
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // is public?
     require_once 'CRM/Core/PseudoConstant.php';
     $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility());
     // add a form rule to check default value
     $this->addFormRule(array('CRM_Price_Form_Field', 'formRule'), $this);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid);
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='{$url}'"));
     }
 }
Пример #9
0
    /**
     * Get price set details.
     *
     * An array containing price set details (including price fields) is returned
     *
     * @param int $setID
     *   Price Set ID.
     * @param bool $required
     *   Appears to have no effect based on reading the code.
     * @param bool $validOnly
     *   Should only fields where today's date falls within the valid range be returned?
     *
     * @return array
     *   Array consisting of field details
     */
    public static function getSetDetail($setID, $required = TRUE, $validOnly = FALSE)
    {
        // create a new tree
        $setTree = array();
        $priceFields = array('id', 'name', 'label', 'html_type', 'is_enter_qty', 'help_pre', 'help_post', 'weight', 'is_display_amounts', 'options_per_line', 'is_active', 'active_on', 'expire_on', 'javascript', 'visibility_id', 'is_required');
        if ($required == TRUE) {
            $priceFields[] = 'is_required';
        }
        // create select
        $select = 'SELECT ' . implode(',', $priceFields);
        $from = ' FROM civicrm_price_field';
        $params = array();
        $params[1] = array($setID, 'Integer');
        $where = '
WHERE price_set_id = %1
AND is_active = 1
';
        $dateSelect = '';
        if ($validOnly) {
            $currentTime = date('YmdHis');
            $dateSelect = "\nAND ( active_on IS NULL OR active_on <= {$currentTime} )\nAND ( expire_on IS NULL OR expire_on >= {$currentTime} )\n";
        }
        $orderBy = ' ORDER BY weight';
        $sql = $select . $from . $where . $dateSelect . $orderBy;
        $dao = CRM_Core_DAO::executeQuery($sql, $params);
        $visibility = CRM_Core_PseudoConstant::visibility('name');
        while ($dao->fetch()) {
            $fieldID = $dao->id;
            $setTree[$setID]['fields'][$fieldID] = array();
            $setTree[$setID]['fields'][$fieldID]['id'] = $fieldID;
            foreach ($priceFields as $field) {
                if ($field == 'id' || is_null($dao->{$field})) {
                    continue;
                }
                if ($field == 'visibility_id') {
                    $setTree[$setID]['fields'][$fieldID]['visibility'] = $visibility[$dao->{$field}];
                }
                $setTree[$setID]['fields'][$fieldID][$field] = $dao->{$field};
            }
            $setTree[$setID]['fields'][$fieldID]['options'] = CRM_Price_BAO_PriceField::getOptions($fieldID, FALSE);
        }
        // also get the pre and post help from this price set
        $sql = "\nSELECT extends, financial_type_id, help_pre, help_post, is_quick_config\nFROM   civicrm_price_set\nWHERE  id = %1";
        $dao = CRM_Core_DAO::executeQuery($sql, $params);
        if ($dao->fetch()) {
            $setTree[$setID]['extends'] = $dao->extends;
            $setTree[$setID]['financial_type_id'] = $dao->financial_type_id;
            $setTree[$setID]['help_pre'] = $dao->help_pre;
            $setTree[$setID]['help_post'] = $dao->help_post;
            $setTree[$setID]['is_quick_config'] = $dao->is_quick_config;
        }
        return $setTree;
    }
Пример #10
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  * Finally it calls the parent's run method.
  *
  * @return void
  */
 public function run()
 {
     //get the event id.
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $config = CRM_Core_Config::singleton();
     // ensure that the user has permission to see this page
     if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id, 'view event info')) {
         CRM_Utils_System::setUFMessage(ts('You do not have permission to view this event'));
         return CRM_Utils_System::permissionDenied();
     }
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'register');
     $this->assign('context', $context);
     // Sometimes we want to suppress the Event Full msg
     $noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, FALSE, 'false');
     // set breadcrumb to append to 2nd layer pages
     $breadCrumbPath = CRM_Utils_System::url('civicrm/event/info', "id={$this->_id}&reset=1");
     //retrieve event information
     $params = array('id' => $this->_id);
     CRM_Event_BAO_Event::retrieve($params, $values['event']);
     if (!$values['event']['is_active']) {
         // form is inactive, die a fatal death
         CRM_Utils_System::setUFMessage(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
         return CRM_Utils_System::permissionDenied();
     }
     if (!empty($values['event']['is_template'])) {
         // form is an Event Template
         CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
     }
     // Add Event Type to $values in case folks want to display it
     $values['event']['event_type'] = CRM_Utils_Array::value($values['event']['event_type_id'], CRM_Event_PseudoConstant::eventType());
     $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
     // show event fees.
     if ($this->_id && !empty($values['event']['is_monetary'])) {
         //CRM-6907
         $config = CRM_Core_Config::singleton();
         $config->defaultCurrency = CRM_Utils_Array::value('currency', $values['event'], $config->defaultCurrency);
         //CRM-10434
         $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
         if ($discountId) {
             $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
         } else {
             $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_id);
         }
         // get price set options, - CRM-5209
         if ($priceSetId) {
             $setDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, TRUE);
             $priceSetFields = $setDetails[$priceSetId]['fields'];
             if (is_array($priceSetFields)) {
                 $fieldCnt = 1;
                 $visibility = CRM_Core_PseudoConstant::visibility('name');
                 // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
                 $adminFieldVisible = FALSE;
                 if (CRM_Core_Permission::check('administer CiviCRM')) {
                     $adminFieldVisible = TRUE;
                 }
                 foreach ($priceSetFields as $fid => $fieldValues) {
                     if (!is_array($fieldValues['options']) || empty($fieldValues['options']) || CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility) && $adminFieldVisible == FALSE) {
                         continue;
                     }
                     if (count($fieldValues['options']) > 1) {
                         $values['feeBlock']['value'][$fieldCnt] = '';
                         $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label';
                         $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
                         $fieldCnt++;
                         $labelClass = 'price_set_option-label';
                     } else {
                         $labelClass = 'price_set_field-label';
                     }
                     // show tax rate with amount
                     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
                     $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
                     $displayOpt = CRM_Utils_Array::value('tax_display_settings', $invoiceSettings);
                     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
                     foreach ($fieldValues['options'] as $optionId => $optionVal) {
                         $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
                         if ($invoicing && isset($optionVal['tax_amount'])) {
                             $values['feeBlock']['value'][$fieldCnt] = CRM_Price_BAO_PriceField::getTaxLabel($optionVal, 'amount', $displayOpt, $taxTerm);
                             $values['feeBlock']['tax_amount'][$fieldCnt] = $optionVal['tax_amount'];
                         } else {
                             $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
                         }
                         $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
                         $fieldCnt++;
                     }
                 }
             }
             // Tell tpl we have price set fee data and whether it's a quick_config price set
             $this->assign('isPriceSet', 1);
             $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']);
         }
     }
     $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
     $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
     // fix phone type labels
     if (!empty($values['location']['phone'])) {
         $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
         foreach ($values['location']['phone'] as &$val) {
             if (!empty($val['phone_type_id'])) {
                 $val['phone_type_display'] = $phoneTypes[$val['phone_type_id']];
             }
         }
     }
     //retrieve custom field information
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_id, 0, $values['event']['event_type_id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
     $this->assign('action', CRM_Core_Action::VIEW);
     //To show the event location on maps directly on event info page
     $locations = CRM_Event_BAO_Event::getMapInfo($this->_id);
     if (!empty($locations) && !empty($values['event']['is_map'])) {
         $this->assign('locations', $locations);
         $this->assign('mapProvider', $config->mapProvider);
         $this->assign('mapKey', $config->mapAPIKey);
         $sumLat = $sumLng = 0;
         $maxLat = $maxLng = -400;
         $minLat = $minLng = 400;
         foreach ($locations as $location) {
             $sumLat += $location['lat'];
             $sumLng += $location['lng'];
             if ($location['lat'] > $maxLat) {
                 $maxLat = $location['lat'];
             }
             if ($location['lat'] < $minLat) {
                 $minLat = $location['lat'];
             }
             if ($location['lng'] > $maxLng) {
                 $maxLng = $location['lng'];
             }
             if ($location['lng'] < $minLng) {
                 $minLng = $location['lng'];
             }
         }
         $center = array('lat' => (double) $sumLat / count($locations), 'lng' => (double) $sumLng / count($locations));
         $span = array('lat' => (double) ($maxLat - $minLat), 'lng' => (double) ($maxLng - $minLng));
         $this->assign_by_ref('center', $center);
         $this->assign_by_ref('span', $span);
         if ($action == CRM_Core_Action::PREVIEW) {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE);
         } else {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1", TRUE, NULL, TRUE, TRUE);
         }
         $this->assign('skipLocationType', TRUE);
         $this->assign('mapURL', $mapURL);
     }
     if (CRM_Core_Permission::check('view event participants') && CRM_Core_Permission::check('view all contacts')) {
         $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label');
         $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label');
         $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
         $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
         $this->assign('findParticipants', $findParticipants);
     }
     $participantListingID = CRM_Utils_Array::value('participant_listing_id', $values['event']);
     if ($participantListingID) {
         $participantListingURL = CRM_Utils_System::url('civicrm/event/participant', "reset=1&id={$this->_id}", TRUE, NULL, TRUE, TRUE);
         $this->assign('participantListingURL', $participantListingURL);
     }
     $hasWaitingList = CRM_Utils_Array::value('has_waitlist', $values['event']);
     $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id, FALSE, $hasWaitingList);
     $allowRegistration = FALSE;
     if (!empty($values['event']['is_online_registration'])) {
         if (CRM_Event_BAO_Event::validRegistrationRequest($values['event'], $this->_id)) {
             // we always generate urls for the front end in joomla
             $action_query = $action === CRM_Core_Action::PREVIEW ? "&action={$action}" : '';
             $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1{$action_query}", TRUE, NULL, TRUE, TRUE);
             if (!$eventFullMessage || $hasWaitingList) {
                 $registerText = ts('Register Now');
                 if (!empty($values['event']['registration_link_text'])) {
                     $registerText = $values['event']['registration_link_text'];
                 }
                 // check if we're in shopping cart mode for events
                 $enable_cart = Civi::settings()->get('enable_cart');
                 if ($enable_cart) {
                     $link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($this->_id);
                     $registerText = $link['label'];
                     $url = CRM_Utils_System::url($link['path'], $link['query'] . $action_query, TRUE, NULL, TRUE, TRUE);
                 }
                 //Fixed for CRM-4855
                 $allowRegistration = CRM_Event_BAO_Event::showHideRegistrationLink($values);
                 $this->assign('registerText', $registerText);
                 $this->assign('registerURL', $url);
                 $this->assign('eventCartEnabled', $enable_cart);
             }
         } elseif (CRM_Core_Permission::check('register for events')) {
             $this->assign('registerClosed', TRUE);
         }
     }
     $this->assign('allowRegistration', $allowRegistration);
     $session = CRM_Core_Session::singleton();
     $params = array('contact_id' => $session->get('userID'), 'event_id' => CRM_Utils_Array::value('id', $values['event']), 'role_id' => CRM_Utils_Array::value('default_role_id', $values['event']));
     if ($eventFullMessage && $noFullMsg == 'false' || CRM_Event_BAO_Event::checkRegistration($params)) {
         $statusMessage = $eventFullMessage;
         if (CRM_Event_BAO_Event::checkRegistration($params)) {
             if ($noFullMsg == 'false') {
                 if ($values['event']['allow_same_participant_emails']) {
                     $statusMessage = ts('It looks like you are already registered for this event.  You may proceed if you want to create an additional registration.');
                 } else {
                     $registerUrl = CRM_Utils_System::url('civicrm/event/register', "reset=1&id={$values['event']['id']}&cid=0");
                     $statusMessage = ts("It looks like you are already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.") . ' ' . ts('You can also <a href="%1">register another participant</a>.', array(1 => $registerUrl));
                 }
             }
         } elseif ($hasWaitingList) {
             $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event']);
             if (!$statusMessage) {
                 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
             }
         }
         CRM_Core_Session::setStatus($statusMessage);
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', FALSE);
     // set page title = event title
     CRM_Utils_System::setTitle($values['event']['title']);
     $this->assign('event', $values['event']);
     if (isset($values['feeBlock'])) {
         $this->assign('feeBlock', $values['feeBlock']);
     }
     $this->assign('location', $values['location']);
     if (CRM_Core_Permission::check('access CiviEvent')) {
         $enableCart = Civi::settings()->get('enable_cart');
         $this->assign('manageEventLinks', CRM_Event_Page_ManageEvent::tabs($enableCart));
     }
     return parent::run();
 }
Пример #11
0
 /**
  * Get all Visibility levels.
  *
  * The static array visibility is returned
  *
  * @access public
  * @static
  *
  * @return array - array reference of all Visibility levels.
  *
  */
 public static function &visibility($column = 'label')
 {
     if (!self::$visibility) {
         require_once 'CRM/Core/OptionGroup.php';
         self::$visibility = CRM_Core_OptionGroup::values('visibility', false, false, false, null, $column);
     }
     return self::$visibility;
 }
Пример #12
0
 /**
  * Get all Visibility levels.
  *
  * The static array visibility is returned
  *
  * @access public
  * @static
  *
  * @return array - array reference of all Visibility levels.
  *
  */
 public static function &visibility()
 {
     if (!self::$visibility) {
         require_once 'CRM/Core/OptionGroup.php';
         self::$visibility = CRM_Core_OptionGroup::values('visibility');
     }
     return self::$visibility;
 }
Пример #13
0
 /**
  * Function to return option-values of a particular group
  *
  * @param  array     $groupParams   Array containing group fields whose option-values is to retrieved.
  * @param  string    $orderBy       for orderBy clause
  * @param  array     $links         has links like edit, delete, disable ..etc
  *
  * @return array of option-values     
  * 
  * @access public
  * @static
  */
 static function getRows($groupParams, $links, $orderBy = 'weight')
 {
     $optionValue = array();
     if (!isset($groupParams['id']) || !$groupParams['id']) {
         if ($groupParams['name']) {
             $config =& CRM_Core_Config::singleton();
             $optionGroup = CRM_Core_BAO_OptionGroup::retrieve($groupParams, $dnc);
             $optionGroupID = $optionGroup->id;
         }
     } else {
         $optionGroupID = $groupParams['id'];
     }
     $dao =& new CRM_Core_DAO_OptionValue();
     if ($optionGroupID) {
         $dao->option_group_id = $optionGroupID;
         $dao->orderBy($orderBy);
         $dao->find();
     }
     require_once 'CRM/Core/Component.php';
     $componentNames = CRM_Core_Component::getNames();
     $visibilityLabels = CRM_Core_PseudoConstant::visibility();
     while ($dao->fetch()) {
         $optionValue[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $optionValue[$dao->id]);
         // form all action links
         $action = array_sum(array_keys($links));
         // update enable/disable links depending on if it is is_reserved or is_active
         if ($dao->is_reserved) {
             $action = CRM_Core_Action::UPDATE;
         } else {
             if ($dao->is_active) {
                 $action -= CRM_Core_Action::ENABLE;
             } else {
                 $action -= CRM_Core_Action::DISABLE;
             }
         }
         $optionValue[$dao->id]['label'] = htmlspecialchars($optionValue[$dao->id]['label']);
         $optionValue[$dao->id]['order'] = $optionValue[$dao->id]['weight'];
         $optionValue[$dao->id]['action'] = CRM_Core_Action::formLink($links, $action, array('id' => $dao->id, 'gid' => $optionGroupID, 'value' => $dao->value));
         if (CRM_Utils_Array::value('component_id', $optionValue[$dao->id])) {
             $optionValue[$dao->id]['component_name'] = $componentNames[$optionValue[$dao->id]['component_id']];
         } else {
             $optionValue[$dao->id]['component_name'] = 'Contact';
         }
         if (CRM_Utils_Array::value('visibility_id', $optionValue[$dao->id])) {
             $optionValue[$dao->id]['visibility_label'] = $visibilityLabels[$optionValue[$dao->id]['visibility_id']];
         }
     }
     return $optionValue;
 }
Пример #14
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'label', ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'), true);
     $this->addRule('label', ts('This Label already exists in the database for this option group. Please select a different Value.'), 'optionExists', array('CRM_Core_DAO_OptionValue', $this->_id, $this->_gid, 'label'));
     $required = false;
     if ($this->_gName == 'custom_search') {
         $required = true;
     } elseif ($this->_gName == 'redaction_rule') {
         $this->add('text', 'value', ts('Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'), true);
         $this->add('checkbox', 'filter', ts('Regular Expression?'));
     }
     if ($this->_gName == 'participant_listing') {
         $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'description'));
     } else {
         // Hard-coding attributes here since description is still stored as varchar and not text in the schema. dgg
         $this->addWysiwyg('description', ts('Description'), array('rows' => 4, 'cols' => 80), $required);
     }
     $this->add('text', 'weight', ts('Weight'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'weight'), true);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     $isReserved = false;
     if ($this->_id) {
         $isReserved = (bool) CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'is_reserved');
     }
     // If CiviCase enabled AND "Add" mode OR "edit" mode for non-reserved activities, only allow user to pick Core or CiviCase component.
     // FIXME: Each component should define whether adding new activity types is allowed.
     require_once 'CRM/Core/Config.php';
     $config =& CRM_Core_Config::singleton();
     if ($this->_gName == 'activity_type' && in_array("CiviCase", $config->enableComponents) && ($this->_action & CRM_Core_Action::ADD || !$isReserved)) {
         require_once 'CRM/Core/Component.php';
         $caseID = CRM_Core_Component::getComponentID('CiviCase');
         $components = array('' => ts('Contact'), $caseID => 'CiviCase');
         $this->add('select', 'component_id', ts('Component'), $components, false);
     }
     $enabled = $this->add('checkbox', 'is_active', ts('Enabled?'));
     if ($isReserved) {
         $enabled->freeze();
     }
     //fix for CRM-3552, CRM-4575
     if (in_array($this->_gName, array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address'))) {
         $this->assign('showDefault', true);
         $this->add('checkbox', 'is_default', ts('Default Option?'));
     }
     //get contact type for which user want to create a new greeting/addressee type, CRM-4575
     if (in_array($this->_gName, array('email_greeting', 'postal_greeting', 'addressee')) && !$isReserved) {
         $values = array(1 => ts('Individual'), 2 => ts('Household'));
         if ($this->_gName == 'addressee') {
             $values[] = ts('Organization');
         }
         $this->add('select', 'contactOptions', ts('Contact Type'), array('' => '-select-') + $values, true);
         $this->assign('showContactFilter', true);
     }
     if ($this->_gName == 'participant_status') {
         // For Participant Status options, expose the 'filter' field to track which statuses are "Counted", and the Visibility field
         $element = $this->add('checkbox', 'filter', ts('Counted?'));
         require_once "CRM/Core/PseudoConstant.php";
         $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility());
     }
     if ($this->_gName == 'participant_role') {
         // For Participant Role options, expose the 'filter' field to track which statuses are "Counted"
         $this->add('checkbox', 'filter', ts('Counted?'));
     }
     $this->addFormRule(array('CRM_Admin_Form_Options', 'formRule'), $this);
 }
Пример #15
0
    /**
     * Get price set details
     *
     * An array containing price set details (including price fields) is returned
     *
     * @param int $setId - price set id whose details are needed
     * @return array $setTree - array consisting of field details
     */
    public static function getSetDetail($setID, $required = true)
    {
        // create a new tree
        $setTree = array();
        $select = $from = $where = $orderBy = '';
        $priceFields = array('id', 'name', 'label', 'html_type', 'is_enter_qty', 'help_post', 'is_display_amounts', 'options_per_line', 'is_active', 'visibility_id');
        if ($required == true) {
            $priceFields[] = 'is_required';
        }
        // create select
        $select = 'SELECT ' . implode(',', $priceFields);
        $from = ' FROM civicrm_price_field';
        $params = array();
        $params[1] = array($setID, 'Integer');
        $where = '
WHERE price_set_id = %1
AND is_active = 1
';
        $orderBy = ' ORDER BY weight';
        $sql = $select . $from . $where . $orderBy;
        $dao =& CRM_Core_DAO::executeQuery($sql, $params);
        $visibility = CRM_Core_PseudoConstant::visibility('name');
        while ($dao->fetch()) {
            $fieldID = $dao->id;
            $setTree[$setID]['fields'][$fieldID] = array();
            $setTree[$setID]['fields'][$fieldID]['id'] = $fieldID;
            foreach ($priceFields as $field) {
                if ($field == 'id' || is_null($dao->{$field})) {
                    continue;
                }
                if ($field == 'visibility_id') {
                    $setTree[$setID]['fields'][$fieldID]['visibility'] = $visibility[$dao->{$field}];
                }
                $setTree[$setID]['fields'][$fieldID][$field] = $dao->{$field};
            }
            $setTree[$setID]['fields'][$fieldID]['options'] = CRM_Price_BAO_Field::getOptions($fieldID, false);
        }
        // also get the pre and post help from this price set
        $sql = "\nSELECT help_pre, help_post\nFROM   civicrm_price_set\nWHERE  id = %1";
        $dao =& CRM_Core_DAO::executeQuery($sql, $params);
        if ($dao->fetch()) {
            $setTree[$setID]['help_pre'] = $dao->help_pre;
            $setTree[$setID]['help_post'] = $dao->help_post;
        }
        return $setTree;
    }
Пример #16
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the  
  * type of action and executes that action.
  * Finally it calls the parent's run method.
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     //get the event id.
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, true);
     $config = CRM_Core_Config::singleton();
     require_once 'CRM/Event/BAO/Event.php';
     // ensure that the user has permission to see this page
     if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id)) {
         CRM_Core_Error::fatal(ts('You do not have permission to view this event'));
     }
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, false);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, false, 'register');
     $this->assign('context', $context);
     // Sometimes we want to suppress the Event Full msg
     $noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, false, 'false');
     // set breadcrumb to append to 2nd layer pages
     $breadCrumbPath = CRM_Utils_System::url("civicrm/event/info", "id={$this->_id}&reset=1");
     $additionalBreadCrumb = "<a href=\"{$breadCrumbPath}\">" . ts('Events') . '</a>';
     //retrieve event information
     $params = array('id' => $this->_id);
     CRM_Event_BAO_Event::retrieve($params, $values['event']);
     if (!$values['event']['is_active']) {
         // form is inactive, die a fatal death
         CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
     }
     if (!empty($values['event']['is_template'])) {
         // form is an Event Template
         CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
     }
     $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
     // show event fees.
     require_once 'CRM/Price/BAO/Set.php';
     if ($this->_id && CRM_Utils_Array::value('is_monetary', $values['event'])) {
         // get price set options, - CRM-5209
         if ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $this->_id)) {
             $setDetails = CRM_Price_BAO_Set::getSetDetail($priceSetId);
             $priceSetFields = $setDetails[$priceSetId]['fields'];
             if (is_array($priceSetFields)) {
                 $fieldCnt = 1;
                 require_once 'CRM/Core/PseudoConstant.php';
                 $visibility = CRM_Core_PseudoConstant::visibility('name');
                 foreach ($priceSetFields as $fid => $fieldValues) {
                     if (!is_array($fieldValues['options']) || empty($fieldValues['options']) || CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility)) {
                         continue;
                     }
                     if (count($fieldValues['options']) > 1) {
                         $values['feeBlock']['value'][$fieldCnt] = '';
                         $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label';
                         $fieldCnt++;
                         $labelClass = 'price_set_option-label';
                     } else {
                         $labelClass = 'price_set_field-label';
                     }
                     foreach ($fieldValues['options'] as $optionId => $optionVal) {
                         $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
                         $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
                         $fieldCnt++;
                     }
                 }
             }
             // Tell tpl we have price set fee data
             $this->assign('isPriceSet', 1);
         } else {
             //retrieve event fee block.
             require_once 'CRM/Core/OptionGroup.php';
             require_once 'CRM/Core/BAO/Discount.php';
             $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
             if ($discountId) {
                 CRM_Core_OptionGroup::getAssoc(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'option_group_id'), $values['feeBlock'], false, 'id');
             } else {
                 CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$this->_id}", $values['feeBlock']);
             }
         }
     }
     $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
     require_once 'CRM/Core/BAO/Location.php';
     $values['location'] = CRM_Core_BAO_Location::getValues($params, true);
     //retrieve custom field information
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree("Event", $this, $this->_id, 0, $values['event']['event_type_id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $this->assign('action', CRM_Core_Action::VIEW);
     //To show the event location on maps directly on event info page
     $locations =& CRM_Event_BAO_Event::getMapInfo($this->_id);
     if (!empty($locations) && CRM_Utils_Array::value('is_map', $values['event'])) {
         $this->assign('locations', $locations);
         $this->assign('mapProvider', $config->mapProvider);
         $this->assign('mapKey', $config->mapAPIKey);
         $sumLat = $sumLng = 0;
         $maxLat = $maxLng = -400;
         $minLat = $minLng = +400;
         foreach ($locations as $location) {
             $sumLat += $location['lat'];
             $sumLng += $location['lng'];
             if ($location['lat'] > $maxLat) {
                 $maxLat = $location['lat'];
             }
             if ($location['lat'] < $minLat) {
                 $minLat = $location['lat'];
             }
             if ($location['lng'] > $maxLng) {
                 $maxLng = $location['lng'];
             }
             if ($location['lng'] < $minLng) {
                 $minLng = $location['lng'];
             }
         }
         $center = array('lat' => (double) $sumLat / count($locations), 'lng' => (double) $sumLng / count($locations));
         $span = array('lat' => (double) ($maxLat - $minLat), 'lng' => (double) ($maxLng - $minLng));
         $this->assign_by_ref('center', $center);
         $this->assign_by_ref('span', $span);
         if ($action == CRM_Core_Action::PREVIEW) {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1&action=preview", true, null, true, true);
         } else {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1", true, null, true, true);
         }
         $this->assign('skipLocationType', true);
         $this->assign('mapURL', $mapURL);
     }
     require_once 'CRM/Event/BAO/Participant.php';
     $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id);
     $hasWaitingList = CRM_Utils_Array::value('has_waitlist', $values['event']);
     $allowRegistration = false;
     if (CRM_Utils_Array::value('is_online_registration', $values['event'])) {
         if (CRM_Event_BAO_Event::validRegistrationDate($values['event'], $this->_id)) {
             if (!$eventFullMessage || $hasWaitingList) {
                 $registerText = ts('Register Now');
                 if (CRM_Utils_Array::value('registration_link_text', $values['event'])) {
                     $registerText = $values['event']['registration_link_text'];
                 }
                 //Fixed for CRM-4855
                 $allowRegistration = CRM_Event_BAO_Event::showHideRegistrationLink($values);
                 $this->assign('registerText', $registerText);
             }
             // we always generate urls for the front end in joomla
             if ($action == CRM_Core_Action::PREVIEW) {
                 $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1&action=preview", true, null, true, true);
             } else {
                 $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1", true, null, true, true);
             }
             if (!$eventFullMessage || $hasWaitingList) {
                 $this->assign('registerURL', $url);
             }
         } else {
             if (CRM_Core_Permission::check('register for events')) {
                 $this->assign('registerClosed', true);
             }
         }
     }
     $this->assign('allowRegistration', $allowRegistration);
     if ($eventFullMessage && $noFullMsg == 'false') {
         $statusMessage = $eventFullMessage;
         $session = CRM_Core_Session::singleton();
         $params = array('contact_id' => $session->get('userID'), 'event_id' => CRM_Utils_Array::value('id', $values['event']), 'role_id' => CRM_Utils_Array::value('default_role_id', $values['event']));
         if (CRM_Event_BAO_Event::checkRegistration($params)) {
             $statusMessage = ts("Oops. It looks like you are already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.");
         } else {
             if ($hasWaitingList) {
                 $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event']);
                 if (!$statusMessage) {
                     $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
                 }
             }
         }
         CRM_Core_Session::setStatus($statusMessage);
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', false);
     // set page title = event title
     CRM_Utils_System::setTitle($values['event']['title']);
     $this->assign('event', $values['event']);
     if (isset($values['feeBlock'])) {
         $this->assign('feeBlock', $values['feeBlock']);
     }
     $this->assign('location', $values['location']);
     parent::run();
 }