/** * Implements CiviCRM 'buildForm' hook. * * @param string $formName Name of current form. * @param CRM_Core_Form $form Current form. */ function Paytrail_civicrm_buildForm($formName, &$form) { //Confirm Contribution if ($form instanceof CRM_Contribute_Form_Contribution_Confirm) { $paymentHelper = new PaytrailPaymentHelper(); if (!$paymentHelper->isEmbeddedButtonsEnabled()) { return; } //Get form params to get customer contact info and product info $component = "contribute"; $params = $form->get("params"); $params['item_name'] = $form->_values['title']; $paymentHelper->embeddPaymentButtons($params, $component); } else { if ($form instanceof CRM_Event_Form_Registration_Confirm) { $paymentHelper = new PaytrailPaymentHelper(); if (!$paymentHelper->isEmbeddedButtonsEnabled()) { return; } //Get form params to get customer contact info and product info $component = "event"; $formParamsArray = $form->get("params"); $params = $formParamsArray[0]; $params['item_name'] = $form->_values['event']['title']; $paymentHelper->embeddPaymentButtons($params, $component); } } }
/** * build the form elements for a phone object * * @param CRM_Core_Form $form reference to the form object * @param int $addressBlockCount block number to build * @param boolean $blockEdit is it block edit * * @return void * @access public * @static */ static function buildQuickForm(&$form, $addressBlockCount = NULL, $blockEdit = FALSE) { // passing this via the session is AWFUL. we need to fix this if (!$addressBlockCount) { $blockId = $form->get('Phone_Block_Count') ? $form->get('Phone_Block_Count') : 1; } else { $blockId = $addressBlockCount; } $form->applyFilter('__ALL__', 'trim'); //phone type select $form->addElement('select', "phone[{$blockId}][phone_type_id]", ts('Phone'), CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id')); //main phone number with crm_phone class $form->addElement('text', "phone[{$blockId}][phone]", ts('Phone'), array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'), array('class' => 'crm_phone twelve'))); // phone extension $form->addElement('text', "phone[{$blockId}][phone_ext]", ts('Extension'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone_ext')); if (isset($form->_contactType) || $blockEdit) { //Block type select $form->addElement('select', "phone[{$blockId}][location_type_id]", '', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id')); //is_Primary radio $js = array('id' => 'Phone_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );'); $form->addElement('radio', "phone[{$blockId}][is_primary]", '', '', '1', $js); } // TODO: set this up as a group, we need a valid phone_type_id if we have a phone number // $form->addRule( "location[$locationId][phone][$locationId][phone]", ts('Phone number is not valid.'), 'phone' ); }
/** * build the form elements for an email object * * @param CRM_Core_Form $form reference to the form object * @param array $location the location object to store all the form elements in * @param int $locationId the locationId we are dealing with * @param int $count the number of blocks to create * * @return void * @access public * @static */ static function buildQuickForm(&$form, $addressBlockCount = null) { // passing this via the session is AWFUL. we need to fix this if (!$addressBlockCount) { $blockId = $form->get('Email_Block_Count') ? $form->get('Email_Block_Count') : 1; } else { $blockId = $addressBlockCount; } $form->applyFilter('__ALL__', 'trim'); //Email box $form->addElement('text', "email[{$blockId}][email]", ts('Email'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email')); $form->addRule("email[{$blockId}][email]", ts('Email is not valid.'), 'email'); if (isset($form->_contactType)) { //Block type $form->addElement('select', "email[{$blockId}][location_type_id]", '', CRM_Core_PseudoConstant::locationType()); //On-hold checkbox $form->addElement('advcheckbox', "email[{$blockId}][on_hold]", null); //Bulkmail checkbox $js = array('id' => "Email_" . $blockId . "_IsBulkmail", 'onClick' => 'singleSelect( this.id );'); $form->addElement('advcheckbox', "email[{$blockId}][is_bulkmail]", null, '', $js); //is_Primary radio $js = array('id' => "Email_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );'); $form->addElement('radio', "email[{$blockId}][is_primary]", '', '', '1', $js); if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') { $form->add('textarea', "email[{$blockId}][signature_text]", ts('Signature (Text)'), array('rows' => 2, 'cols' => 40)); $form->addWysiwyg("email[{$blockId}][signature_html]", ts('Signature (HTML)'), array('rows' => 2, 'cols' => 40)); } } }
/** * build the form elements for an Website object * * @param CRM_Core_Form $form reference to the form object * @param array $location the location object to store all the form elements in * @param int $locationId the locationId we are dealing with * @param int $count the number of blocks to create * * @return void * @access public * @static */ static function buildQuickForm(&$form) { $blockId = $form->get('Website_Block_Count') ? $form->get('Website_Block_Count') : 1; $form->applyFilter('__ALL__', 'trim'); //Website type select $form->addElement('select', "website[{$blockId}][website_type_id]", '', CRM_Core_PseudoConstant::websiteType()); //Website box $form->addElement('text', "website[{$blockId}][url]", ts('Website'), array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) this.value='http://'; else return false", 'onblur' => "if ( this.value == 'http://') this.value=''; else return false"))); $form->addRule("website[{$blockId}][url]", ts('Enter a valid web location beginning with \'http://\' or \'https://\'. EXAMPLE: http://www.mysite.org/'), 'url'); }
/** * build the form elements for an Website object * * @param CRM_Core_Form $form reference to the form object * @param int $blockCount block number to build * * @return void * @access public * @static */ static function buildQuickForm(&$form, $blockCount = NULL) { if (!$blockCount) { $blockId = $form->get('Website_Block_Count') ? $form->get('Website_Block_Count') : 1; } else { $blockId = $blockCount; } $form->applyFilter('__ALL__', 'trim'); //Website type select $form->addSelect("website[{$blockId}][website_type_id]", array('entity' => 'website', 'class' => 'eight')); //Website box $form->addElement('text', "website[{$blockId}][url]", ts('Website'), array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) { this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') { this.value='';} else return false"))); $form->addRule("website[{$blockId}][url]", ts('Enter a valid web location beginning with \'http://\' or \'https://\'. EXAMPLE: http://www.mysite.org/'), 'url'); }
/** * Build the form object elements for an Website object. * * @param CRM_Core_Form $form * Reference to the form object. * @param int $blockCount * Block number to build. */ public static function buildQuickForm(&$form, $blockCount = NULL) { if (!$blockCount) { $blockId = $form->get('Website_Block_Count') ? $form->get('Website_Block_Count') : 1; } else { $blockId = $blockCount; } $form->applyFilter('__ALL__', 'trim'); //Website type select $form->addField("website[{$blockId}][website_type_id]", array('entity' => 'website', 'class' => 'eight')); //Website box $form->addField("website[{$blockId}][url]", array('entity' => 'website')); $form->addRule("website[{$blockId}][url]", ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url'); }
/** * build the form elements for an IM object * * @param CRM_Core_Form $form reference to the form object * @param array $location the location object to store all the form elements in * @param int $locationId the locationId we are dealing with * @param int $count the number of blocks to create * * @return void * @access public * @static */ static function buildQuickForm(&$form) { $blockId = $form->get('IM_Block_Count') ? $form->get('IM_Block_Count') : 1; $form->applyFilter('__ALL__', 'trim'); //IM provider select $form->addElement('select', "im[{$blockId}][provider_id]", '', CRM_Core_PseudoConstant::IMProvider()); //Block type select $form->addElement('select', "im[{$blockId}][location_type_id]", '', CRM_Core_PseudoConstant::locationType()); //IM box $form->addElement('text', "im[{$blockId}][name]", ts('Instant Messenger'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_IM', 'name')); //is_Primary radio $js = array('id' => "IM_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );'); $form->addElement('radio', "im[{$blockId}][is_primary]", '', '', '1', $js); }
/** * Build the form object elements for an email object. * * @param CRM_Core_Form $form * Reference to the form object. * @param int $blockCount * Block number to build. * @param bool $blockEdit * Is it block edit. */ public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) { // passing this via the session is AWFUL. we need to fix this if (!$blockCount) { $blockId = $form->get('Email_Block_Count') ? $form->get('Email_Block_Count') : 1; } else { $blockId = $blockCount; } $form->applyFilter('__ALL__', 'trim'); //Email box $form->addField("email[{$blockId}][email]", array('entity' => 'email')); $form->addRule("email[{$blockId}][email]", ts('Email is not valid.'), 'email'); if (isset($form->_contactType) || $blockEdit) { //Block type $form->addField("email[{$blockId}][location_type_id]", array('entity' => 'email', 'placeholder' => NULL, 'class' => 'eight')); //TODO: Refactor on_hold field to select. $multipleBulk = CRM_Core_BAO_Email::isMultipleBulkMail(); //On-hold select if ($multipleBulk) { $holdOptions = array(0 => ts('- select -'), 1 => ts('On Hold Bounce'), 2 => ts('On Hold Opt Out')); $form->addElement('select', "email[{$blockId}][on_hold]", '', $holdOptions); } else { $form->addField("email[{$blockId}][on_hold]", array('entity' => 'email', 'type' => 'advcheckbox')); } //Bulkmail checkbox $form->assign('multipleBulk', $multipleBulk); if ($multipleBulk) { $js = array('id' => "Email_" . $blockId . "_IsBulkmail"); $form->addElement('advcheckbox', "email[{$blockId}][is_bulkmail]", NULL, '', $js); } else { $js = array('id' => "Email_" . $blockId . "_IsBulkmail"); if (!$blockEdit) { $js['onClick'] = 'singleSelect( this.id );'; } $form->addElement('radio', "email[{$blockId}][is_bulkmail]", '', '', '1', $js); } //is_Primary radio $js = array('id' => "Email_" . $blockId . "_IsPrimary"); if (!$blockEdit) { $js['onClick'] = 'singleSelect( this.id );'; } $form->addElement('radio', "email[{$blockId}][is_primary]", '', '', '1', $js); if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') { $form->add('textarea', "email[{$blockId}][signature_text]", ts('Signature (Text)'), array('rows' => 2, 'cols' => 40)); $form->add('wysiwyg', "email[{$blockId}][signature_html]", ts('Signature (HTML)'), array('rows' => 2, 'cols' => 40)); } } }
/** * @param CRM_Core_Form $form * * @return array */ public static function process(&$form) { if ($form->getVar('_surveyId') <= 0) { return NULL; } $tabs = array('main' => array('title' => ts('Main Information'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'questions' => array('title' => ts('Questions'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'results' => array('title' => ts('Results'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE)); $surveyID = $form->getVar('_surveyId'); $class = $form->getVar('_name'); $class = CRM_Utils_String::getClassName($class); $class = strtolower($class); if (array_key_exists($class, $tabs)) { $tabs[$class]['current'] = TRUE; $qfKey = $form->get('qfKey'); if ($qfKey) { $tabs[$class]['qfKey'] = "&qfKey={$qfKey}"; } } if ($surveyID) { $reset = !empty($_GET['reset']) ? 'reset=1&' : ''; foreach ($tabs as $key => $value) { if (!isset($tabs[$key]['qfKey'])) { $tabs[$key]['qfKey'] = NULL; } $tabs[$key]['link'] = CRM_Utils_System::url("civicrm/survey/configure/{$key}", "{$reset}action=update&id={$surveyID}{$tabs[$key]['qfKey']}"); $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE; } } return $tabs; }
/** * build the form elements for an open id object * * @param CRM_Core_Form $form reference to the form object * @param array $location the location object to store all the form elements in * @param int $locationId the locationId we are dealing with * @param int $count the number of blocks to create * * @return void * @access public * @static */ static function buildQuickForm(&$form) { $blockId = $form->get('OpenID_Block_Count') ? $form->get('OpenID_Block_Count') : 1; $form->applyFilter('__ALL__', 'trim'); $form->addElement('text', "openid[{$blockId}][openid]", ts('OpenID'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OpenID', 'openid')); $form->addRule("openid[{$blockId}][openid]", ts('OpenID is not a valid URL.'), 'url'); //Block type $form->addElement('select', "openid[{$blockId}][location_type_id]", '', CRM_Core_PseudoConstant::locationType()); $config = CRM_Core_Config::singleton(); if ($config->userFramework == 'Standalone') { $js = array('id' => "OpenID_" . $blockId . "_IsLogin", 'onClick' => 'singleSelect( this.id );'); $form->addElement('advcheckbox', "openid[{$blockId}][allowed_to_login]", null, '', $js); } //is_Primary radio $js = array('id' => "OpenID_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );'); $form->addElement('radio', "openid[{$blockId}][is_primary]", '', '', '1', $js); }
/** * @param CRM_Core_Form $form * @param bool $useTable */ public static function preProcessCommon(&$form, $useTable = FALSE) { $values = $form->controller->exportValues($form->get('searchFormName')); $form->_task = CRM_Utils_Array::value('task', $values); $mailingTasks = CRM_Mailing_Task::tasks(); $form->assign('taskName', CRM_Utils_Array::value('task', $values)); // ids are mailing event queue ids $ids = array(); if ($values['radio_ts'] == 'ts_sel') { foreach ($values as $name => $value) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } else { $queryParams = $form->get('queryParams'); $sortOrder = NULL; if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); } $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_MAILING); $result = $query->searchQuery(0, 0, $sortOrder); while ($result->fetch()) { $ids[] = $result->mailing_recipients_id; } $form->assign('totalSelectedMailingRecipients', $form->get('rowCount')); } if (!empty($ids)) { $form->_componentClause = ' civicrm_mailing_recipients.id IN ( ' . implode(',', $ids) . ' ) '; } // set the context for redirection for any task actions $session = CRM_Core_Session::singleton(); $fragment = 'search'; if ($form->_action == CRM_Core_Action::ADVANCED) { $fragment .= '/advanced'; } $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams); $session = CRM_Core_Session::singleton(); $session->replaceUserContext($url); }
/** * build the form elements for a phone object * * @param CRM_Core_Form $form reference to the form object * @param array $location the location object to store all the form elements in * @param int $locationId the locationId we are dealing with * @param int $count the number of blocks to create * * @return void * @access public * @static */ static function buildQuickForm(&$form) { $blockId = $form->get('Phone_Block_Count') ? $form->get('Phone_Block_Count') : 1; $form->applyFilter('__ALL__', 'trim'); //phone type select $form->addElement('select', "phone[{$blockId}][phone_type_id]", ts('Phone'), CRM_Core_PseudoConstant::phoneType()); //phone box $form->addElement('text', "phone[{$blockId}][phone]", ts('Phone'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone')); if (isset($form->_contactType)) { //Block type select $form->addElement('select', "phone[{$blockId}][location_type_id]", '', CRM_Core_PseudoConstant::locationType()); //is_Primary radio $js = array('id' => "Phone_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );'); $form->addElement('radio', "phone[{$blockId}][is_primary]", '', '', '1', $js); } // TODO: set this up as a group, we need a valid phone_type_id if we have a phone number // $form->addRule( "location[$locationId][phone][$locationId][phone]", ts('Phone number is not valid.'), 'phone' ); }
/** * Common pre-process function. * * @param CRM_Core_Form $form * @param bool $useTable */ public static function preProcessCommon(&$form, $useTable = FALSE) { $form->_activityHolderIds = array(); $values = $form->controller->exportValues($form->get('searchFormName')); $form->_task = $values['task']; $activityTasks = CRM_Activity_Task::tasks(); $form->assign('taskName', $activityTasks[$form->_task]); $ids = array(); if ($values['radio_ts'] == 'ts_sel') { foreach ($values as $name => $value) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } else { $queryParams = $form->get('queryParams'); $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_ACTIVITY); $query->_distinctComponentClause = '( civicrm_activity.id )'; $query->_groupByComponentClause = " GROUP BY civicrm_activity.id "; // CRM-12675 $activityClause = NULL; $components = CRM_Core_Component::getNames(); $componentClause = array(); foreach ($components as $componentID => $componentName) { if (!CRM_Core_Permission::check("access {$componentName}")) { $componentClause[] = " (activity_type.component_id IS NULL OR activity_type.component_id <> {$componentID}) "; } } if (!empty($componentClause)) { $activityClause = implode(' AND ', $componentClause); } $result = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, $activityClause); while ($result->fetch()) { if (!empty($result->activity_id)) { $ids[] = $result->activity_id; } } } if (!empty($ids)) { $form->_componentClause = ' civicrm_activity.id IN ( ' . implode(',', $ids) . ' ) '; $form->assign('totalSelectedActivities', count($ids)); } $form->_activityHolderIds = $form->_componentIds = $ids; // Set the context for redirection for any task actions. $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $session = CRM_Core_Session::singleton(); $searchFormName = strtolower($form->get('searchFormName')); if ($searchFormName == 'search') { $session->replaceUserContext(CRM_Utils_System::url('civicrm/activity/search', $urlParams)); } else { $session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/{$searchFormName}", $urlParams)); } }
/** * Build the form object elements for an open id object. * * @param CRM_Core_Form $form * Reference to the form object. * @param int $blockCount * Block number to build. * @param bool $blockEdit * Is it block edit. */ public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) { if (!$blockCount) { $blockId = $form->get('OpenID_Block_Count') ? $form->get('OpenID_Block_Count') : 1; } else { $blockId = $blockCount; } $form->applyFilter('__ALL__', 'trim'); $form->addElement('text', "openid[{$blockId}][openid]", ts('OpenID'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OpenID', 'openid')); $form->addRule("openid[{$blockId}][openid]", ts('OpenID is not a valid URL.'), 'url'); //Block type $form->addElement('select', "openid[{$blockId}][location_type_id]", '', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id')); //is_Primary radio $js = array('id' => "OpenID_" . $blockId . "_IsPrimary"); if (!$blockEdit) { $js['onClick'] = 'singleSelect( this.id );'; } $form->addElement('radio', "openid[{$blockId}][is_primary]", '', '', '1', $js); }
/** * build the form elements for an email object * * @param CRM_Core_Form $form reference to the form object * @param array $location the location object to store all the form elements in * @param int $locationId the locationId we are dealing with * @param int $count the number of blocks to create * * @return void * @access public * @static */ static function buildQuickForm(&$form) { $blockId = $form->get('Email_Block_Count') ? $form->get('Email_Block_Count') : 1; $form->applyFilter('__ALL__', 'trim'); //Email box $form->addElement('text', "email[{$blockId}][email]", ts('Email'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email')); $form->addRule("email[{$blockId}][email]", ts('Email is not valid.'), 'email'); if (isset($form->_contactType)) { //Block type $form->addElement('select', "email[{$blockId}][location_type_id]", '', CRM_Core_PseudoConstant::locationType()); //On-hold checkbox $form->addElement('advcheckbox', "email[{$blockId}][on_hold]", null); //Bulkmail checkbox $js = array('id' => "Email_" . $blockId . "_IsBulkmail", 'onClick' => 'singleSelect( this.id );'); $form->addElement('advcheckbox', "email[{$blockId}][is_bulkmail]", null, '', $js); //is_Primary radio $js = array('id' => "Email_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );'); $form->addElement('radio', "email[{$blockId}][is_primary]", '', '', '1', $js); } }
/** * build the form elements for an IM object * * @param CRM_Core_Form $form reference to the form object * @param int $blockCount block number to build * @param boolean $blockEdit is it block edit * * @return void * @access public * @static */ static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) { if (!$blockCount) { $blockId = $form->get('IM_Block_Count') ? $form->get('IM_Block_Count') : 1; } else { $blockId = $blockCount; } $form->applyFilter('__ALL__', 'trim'); //IM provider select $form->addSelect("im[{$blockId}][provider_id]", array('entity' => 'im', 'class' => 'eight', 'placeholder' => NULL)); //Block type select $form->addSelect("im[{$blockId}][location_type_id]", array('entity' => 'im', 'class' => 'eight', 'placeholder' => NULL)); //IM box $form->addElement('text', "im[{$blockId}][name]", ts('Instant Messenger'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_IM', 'name')); //is_Primary radio $js = array('id' => 'IM_' . $blockId . '_IsPrimary'); if (!$blockEdit) { $js['onClick'] = 'singleSelect( this.id );'; } $form->addElement('radio', "im[{$blockId}][is_primary]", '', '', '1', $js); }
/** * @param CRM_Core_Form $form * * @return array */ public static function process(&$form) { if ($form->getVar('_id') <= 0) { return NULL; } $tabs = array('settings' => array('title' => ts('Title'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'amount' => array('title' => ts('Amounts'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'membership' => array('title' => ts('Memberships'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'thankyou' => array('title' => ts('Receipt'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'friend' => array('title' => ts('Tell a Friend'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'custom' => array('title' => ts('Profiles'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'premium' => array('title' => ts('Premiums'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'widget' => array('title' => ts('Widgets'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'pcp' => array('title' => ts('Personal Campaigns'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE)); $contribPageId = $form->getVar('_id'); CRM_Utils_Hook::tabset('civicrm/admin/contribute', $tabs, array('contribution_page_id' => $contribPageId)); $fullName = $form->getVar('_name'); $className = CRM_Utils_String::getClassName($fullName); // Hack for special cases. switch ($className) { case 'Contribute': $attributes = $form->getVar('_attributes'); $class = strtolower(basename(CRM_Utils_Array::value('action', $attributes))); break; case 'MembershipBlock': $class = 'membership'; break; default: $class = strtolower($className); break; } if (array_key_exists($class, $tabs)) { $tabs[$class]['current'] = TRUE; $qfKey = $form->get('qfKey'); if ($qfKey) { $tabs[$class]['qfKey'] = "&qfKey={$qfKey}"; } } if ($contribPageId) { $reset = !empty($_GET['reset']) ? 'reset=1&' : ''; foreach ($tabs as $key => $value) { if (!isset($tabs[$key]['qfKey'])) { $tabs[$key]['qfKey'] = NULL; } $tabs[$key]['link'] = CRM_Utils_System::url("civicrm/admin/contribute/{$key}", "{$reset}action=update&id={$contribPageId}{$tabs[$key]['qfKey']}"); $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE; } //get all section info. $contriPageInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo(array($contribPageId)); foreach ($contriPageInfo[$contribPageId] as $section => $info) { if (!$info) { $tabs[$section]['valid'] = FALSE; } } } return $tabs; }
/** * Build the form object elements for a phone object. * * @param CRM_Core_Form $form * Reference to the form object. * @param int $addressBlockCount * Block number to build. * @param bool $blockEdit * Is it block edit. */ public static function buildQuickForm(&$form, $addressBlockCount = NULL, $blockEdit = FALSE) { // passing this via the session is AWFUL. we need to fix this if (!$addressBlockCount) { $blockId = $form->get('Phone_Block_Count') ? $form->get('Phone_Block_Count') : 1; } else { $blockId = $addressBlockCount; } $form->applyFilter('__ALL__', 'trim'); //phone type select $form->addField("phone[{$blockId}][phone_type_id]", array('entity' => 'phone', 'class' => 'eight', 'placeholder' => NULL)); //main phone number with crm_phone class $form->addField("phone[{$blockId}][phone]", array('entity' => 'phone', 'class' => 'crm_phone twelve')); $form->addField("phone[{$blockId}][phone_ext]", array('entity' => 'phone')); if (isset($form->_contactType) || $blockEdit) { //Block type select $form->addField("phone[{$blockId}][location_type_id]", array('entity' => 'phone', 'class' => 'eight', 'placeholder' => NULL)); //is_Primary radio $js = array('id' => 'Phone_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );'); $form->addElement('radio', "phone[{$blockId}][is_primary]", '', '', '1', $js); } // TODO: set this up as a group, we need a valid phone_type_id if we have a phone number // $form->addRule( "location[$locationId][phone][$locationId][phone]", ts('Phone number is not valid.'), 'phone' ); }
/** * @param CRM_Core_Form $form * @param bool $useTable */ public static function preProcessCommon(&$form, $useTable = FALSE) { $form->_participantIds = array(); $values = $form->controller->exportValues($form->get('searchFormName')); $form->_task = $values['task']; $eventTasks = CRM_Event_Task::tasks(); $form->assign('taskName', $eventTasks[$form->_task]); $ids = array(); if ($values['radio_ts'] == 'ts_sel') { foreach ($values as $name => $value) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } else { $queryParams = $form->get('queryParams'); $sortOrder = NULL; if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); } $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_EVENT); $query->_distinctComponentClause = "civicrm_participant.id"; $query->_groupByComponentClause = " GROUP BY civicrm_participant.id "; $result = $query->searchQuery(0, 0, $sortOrder); while ($result->fetch()) { $ids[] = $result->participant_id; } } if (!empty($ids)) { $form->_componentClause = ' civicrm_participant.id IN ( ' . implode(',', $ids) . ' ) '; $form->assign('totalSelectedParticipants', count($ids)); } $form->_participantIds = $form->_componentIds = $ids; //set the context for redirection for any task actions $session = CRM_Core_Session::singleton(); $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $searchFormName = strtolower($form->get('searchFormName')); if ($searchFormName == 'search') { $session->replaceUserContext(CRM_Utils_System::url('civicrm/event/search', $urlParams)); } else { $session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/{$searchFormName}", $urlParams)); } }
/** * Processes the request. * * @param CRM_Core_Form $page * CRM_Core_Form the current form-page. * @param string $actionName * Current action name, as one Action object can serve multiple actions. * * @return void */ public function perform(&$page, $actionName) { // check whether the page is valid before trying to go to it if ($page->controller->isModal()) { // we check whether *all* pages up to current are valid // if there is an invalid page we go to it, instead of the // requested one $pageName = $page->getAttribute('id'); if (!$page->controller->isValid($pageName)) { $pageName = $page->controller->findInvalid(); } $current =& $page->controller->getPage($pageName); } else { $current =& $page; } // generate the URL for the page 'display' event and redirect to it $action = $current->getAttribute('action'); $url = $action . (FALSE === strpos($action, '?') ? '?' : '&') . $current->getButtonName('display') . '=true' . '&qfKey=' . $page->get('qfKey'); CRM_Utils_System::redirect($url); }
/** * This function for building custom fields * * @param CRM_Core_Form $qf form object (reference) * @param string $elementName name of the custom field * @param $fieldId * @param boolean $inactiveNeeded * @param boolean $useRequired true if required else false * @param string $label label for custom field * * @param null $fieldOptions * @param array $feezeOptions * * @return null * @internal param bool $search true if used for search else false * @access public * @static */ public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = TRUE, $label = NULL, $fieldOptions = NULL, $feezeOptions = array()) { $field = new CRM_Price_DAO_PriceField(); $field->id = $fieldId; if (!$field->find(TRUE)) { /* FIXME: failure! */ return NULL; } $is_pay_later = 0; if (isset($qf->_mode) && empty($qf->_mode)) { $is_pay_later = 1; } elseif (isset($qf->_values)) { $is_pay_later = CRM_Utils_Array::value('is_pay_later', $qf->_values); } $otherAmount = $qf->get('values'); $config = CRM_Core_Config::singleton(); $currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $config->defaultCurrency, 'symbol', 'name'); $qf->assign('currencySymbol', $currencySymbol); // get currency name for price field and option attributes $currencyName = $config->defaultCurrency; if (!isset($label)) { $label = !empty($qf->_membershipBlock) && $field->name == 'contribution_amount' ? ts('Additional Contribution') : $field->label; } if ($field->name == 'contribution_amount') { $qf->_contributionAmount = 1; } if (isset($qf->_online) && $qf->_online) { $useRequired = FALSE; } $customOption = $fieldOptions; if (!is_array($customOption)) { $customOption = CRM_Price_BAO_PriceField::getOptions($field->id, $inactiveNeeded); } //use value field. $valueFieldName = 'amount'; $seperator = '|'; switch ($field->html_type) { case 'Text': $optionKey = key($customOption); $count = CRM_Utils_Array::value('count', $customOption[$optionKey], ''); $max_value = CRM_Utils_Array::value('max_value', $customOption[$optionKey], ''); $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName], $count, $max_value)); $extra = array(); if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) { foreach ($fieldOptions as &$fieldOption) { if ($fieldOption['name'] == 'other_amount') { $fieldOption['label'] = $fieldOption['label'] . ' ' . $currencySymbol; } } $qf->assign('priceset', $elementName); $extra = array('onclick' => 'useAmountOther();'); } if (!empty($qf->_membershipBlock) && !empty($qf->_quickConfig) && $field->name == 'other_amount' && empty($qf->_contributionAmount)) { $useRequired = 0; } elseif (!empty($fieldOptions[$optionKey]['label'])) { //check for label. $label = $fieldOptions[$optionKey]['label']; } $element =& $qf->add('text', $elementName, $label, array_merge($extra, array('price' => json_encode(array($optionKey, $priceVal)), 'size' => '4')), $useRequired && $field->is_required); if ($is_pay_later) { $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4')); } // CRM-6902 if (in_array($optionKey, $feezeOptions)) { $element->freeze(); } //CRM-10117 if (!empty($qf->_quickConfig)) { $message = ts('Please enter a valid amount.'); $type = 'money'; } else { $message = ts('%1 must be an integer (whole number).', array(1 => $label)); $type = 'positiveInteger'; } // integers will have numeric rule applied to them. $qf->addRule($elementName, $message, $type); break; case 'Radio': $choice = array(); if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) { $qf->assign('contriPriceset', $elementName); } foreach ($customOption as $opId => $opt) { if ($field->is_display_amounts) { $opt['label'] = !empty($opt['label']) ? $opt['label'] : ''; $opt['label'] = '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span> <span class="crm-price-amount-label">' . $opt['label'] . '</span>'; } $count = CRM_Utils_Array::value('count', $opt, ''); $max_value = CRM_Utils_Array::value('max_value', $opt, ''); $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value)); $extra = array('price' => json_encode(array($elementName, $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName); if (!empty($qf->_quickConfig) && $field->name == 'contribution_amount') { $extra += array('onclick' => 'clearAmountOther();'); } elseif (!empty($qf->_quickConfig) && $field->name == 'membership_amount') { $extra += array('onclick' => "return showHideAutoRenew({$opt['membership_type_id']});", 'membership-type' => $opt['membership_type_id']); $qf->assign('membershipFieldID', $field->id); } $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra); if ($is_pay_later) { $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4')); } // CRM-6902 if (in_array($opId, $feezeOptions)) { $choice[$opId]->freeze(); } } if (!empty($qf->_membershipBlock) && $field->name == 'contribution_amount') { $choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1', array('onclick' => 'clearAmountOther();')); } if (!$field->is_required) { // add "none" option if (!empty($otherAmount['is_allow_other_amount']) && $field->name == 'contribution_amount') { $none = ts('Other Amount'); } elseif (!empty($qf->_membershipBlock) && empty($qf->_membershipBlock['is_required']) && $field->name == 'membership_amount') { $none = ts('No thank you'); } else { $none = ts('- none -'); } $choice[] = $qf->createElement('radio', NULL, '', $none, '0', array('price' => json_encode(array($elementName, '0')))); } $element =& $qf->addGroup($choice, $elementName, $label); // make contribution field required for quick config when membership block is enabled if (($field->name == 'membership_amount' || $field->name == 'contribution_amount') && !empty($qf->_membershipBlock) && !$field->is_required) { $useRequired = $field->is_required = TRUE; } if ($useRequired && $field->is_required) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'Select': $selectOption = $allowedOptions = $priceVal = array(); foreach ($customOption as $opt) { $count = CRM_Utils_Array::value('count', $opt, ''); $max_value = CRM_Utils_Array::value('max_value', $opt, ''); $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName], $count, $max_value)); if ($field->is_display_amounts) { $opt['label'] .= ' - '; $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]); } $selectOption[$opt['id']] = $opt['label']; if (!in_array($opt['id'], $feezeOptions)) { $allowedOptions[] = $opt['id']; } if ($is_pay_later) { $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4')); } } $element =& $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, $useRequired && $field->is_required, array('price' => json_encode($priceVal))); // CRM-6902 $button = substr($qf->controller->getButtonName(), -4); if (!empty($feezeOptions) && $button != 'skip') { $qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/"); } break; case 'CheckBox': $check = array(); foreach ($customOption as $opId => $opt) { $count = CRM_Utils_Array::value('count', $opt, ''); $max_value = CRM_Utils_Array::value('max_value', $opt, ''); $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value)); if ($field->is_display_amounts) { $opt['label'] .= ' - '; $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]); } $check[$opId] =& $qf->createElement('checkbox', $opt['id'], NULL, $opt['label'], array('price' => json_encode(array($opt['id'], $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName)); if ($is_pay_later) { $txtcheck[$opId] =& $qf->createElement('text', $opId, $opt['label'], array('size' => '4')); $qf->addGroup($txtcheck, 'txt-' . $elementName, $label); } // CRM-6902 if (in_array($opId, $feezeOptions)) { $check[$opId]->freeze(); } } $element =& $qf->addGroup($check, $elementName, $label); if ($useRequired && $field->is_required) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; } if (isset($qf->_online) && $qf->_online) { $element->freeze(); } }
/** * Build form for address input fields. * * @param CRM_Core_Form $form * @param int $addressBlockCount * The index of the address array (if multiple addresses on a page). * @param bool $sharing * False, if we want to skip the address sharing features. * @param bool $inlineEdit * True when edit used in inline edit. */ public static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharing = TRUE, $inlineEdit = FALSE) { // passing this via the session is AWFUL. we need to fix this if (!$addressBlockCount) { $blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1; } else { $blockId = $addressBlockCount; } $config = CRM_Core_Config::singleton(); $countryDefault = $config->defaultContactCountry; $form->applyFilter('__ALL__', 'trim'); $js = array(); if (!$inlineEdit) { $js = array('onChange' => 'checkLocation( this.id );', 'placeholder' => NULL); } //make location type required for inline edit $form->addField("address[{$blockId}][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js, $inlineEdit); if (!$inlineEdit) { $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );'); } $form->addField("address[{$blockId}][is_primary]", array('entity' => 'address', 'label' => ts('Primary location for this contact'), 'text' => ts('Primary location for this contact')) + $js); if (!$inlineEdit) { $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );'); } $form->addField("address[{$blockId}][is_billing]", array('entity' => 'address', 'label' => ts('Primary location for this contact'), 'text' => ts('Primary location for this contact')) + $js); // hidden element to store master address id $form->addField("address[{$blockId}][master_id]", array('entity' => 'address', 'type' => 'hidden')); $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $elements = array('address_name', 'street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'country_id', 'state_province_id', 'county_id', 'geo_code_1', 'geo_code_2', 'street_number', 'street_name', 'street_unit'); foreach ($elements as $name) { //Remove id from name, to allow comparison against enabled addressOtions. $nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name; // Skip fields which are not enabled in the address options. if (empty($addressOptions[$nameWithoutID])) { $continue = TRUE; //Don't skip street parsed fields when parsing is enabled. if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && !empty($addressOptions['street_address_parsing'])) { $continue = FALSE; } if ($continue) { continue; } } if ($name == 'address_name') { $name = 'name'; } $params = array('entity' => 'address'); if ($name == 'postal_code_suffix') { $params['label'] = ts('Suffix'); } $form->addField("address[{$blockId}][{$name}]", $params); } $entityId = NULL; if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) { $entityId = $form->_values['address'][$blockId]['id']; } // CRM-11665 geocode override option $geoCode = FALSE; if (!empty($config->geocodeMethod)) { $geoCode = TRUE; $form->addElement('checkbox', "address[{$blockId}][manual_geo_code]", ts('Override automatic geocoding')); } $form->assign('geoCode', $geoCode); // Process any address custom data - $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId); if (isset($groupTree) && is_array($groupTree)) { // use simplified formatted groupTree $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form); // make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]' foreach ($groupTree as $id => $group) { foreach ($group['fields'] as $fldId => $field) { $groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name']; $groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]"; } } $defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults); // since we change element name for address custom data, we need to format the setdefault values $addressDefaults = array(); foreach ($defaults as $key => $val) { if (empty($val)) { continue; } // inorder to set correct defaults for checkbox custom data, we need to converted flat key to array // this works for all types custom data $keyValues = explode('[', str_replace(']', '', $key)); $addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val; } $form->setDefaults($addressDefaults); // we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var. // And we can't set it to 'address_' because we want to set it in a slightly different format. CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_'); // during contact editing : if no address is filled // required custom data must not produce 'required' form rule error // more handling done in formRule func if (!$inlineEdit) { CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree); } $template = CRM_Core_Smarty::singleton(); $tplGroupTree = $template->get_template_vars('address_groupTree'); $tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree; $form->assign('address_groupTree', $tplGroupTree + array($blockId => $groupTree)); // unset the temp smarty var that got created $form->assign('dnc_groupTree', NULL); } // address custom data processing ends .. if ($sharing) { // shared address $form->addElement('checkbox', "address[{$blockId}][use_shared_address]", NULL, ts('Use another contact\'s address')); // Override the default profile links to add address form $profileLinks = CRM_Core_BAO_UFGroup::getCreateLinks(array('new_individual', 'new_organization', 'new_household'), 'shared_address'); $form->addEntityRef("address[{$blockId}][master_contact_id]", ts('Share With'), array('create' => $profileLinks)); } }
/** * @param CRM_Core_Form $form * * @return array */ public static function setDefaultValues(&$form) { $defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($form->_groupTree, $defaults, FALSE, FALSE, $form->get('action')); return $defaults; }
/** * Add profile field to a form. * * @param CRM_Core_Form $form * @param array $field * Properties. * @param int $mode * Profile mode. * @param int $contactId * @param bool $online * @param string $usedFor * For building up prefixed fieldname for special cases (e.g. onBehalf, Honor). * @param int $rowNumber * @param string $prefix * * @return null */ public static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $usedFor = NULL, $rowNumber = NULL, $prefix = '') { $defaultValues = array(); $fieldName = $field['name']; $title = $field['title']; $attributes = $field['attributes']; $rule = $field['rule']; $view = $field['is_view']; $required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required']; $search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE; $isShared = CRM_Utils_Array::value('is_shared', $field, 0); // do not display view fields in drupal registration form // CRM-4632 if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) { return NULL; } if ($usedFor == 'onbehalf') { $name = "onbehalf[{$fieldName}]"; } elseif ($usedFor == 'honor') { $name = "honor[{$fieldName}]"; } elseif ($contactId && !$online) { $name = "field[{$contactId}][{$fieldName}]"; } elseif ($rowNumber) { $name = "field[{$rowNumber}][{$fieldName}]"; } elseif (!empty($prefix)) { $name = $prefix . "[{$fieldName}]"; } else { $name = $fieldName; } $selectAttributes = array('class' => 'crm-select2', 'placeholder' => TRUE); if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) { $deleteExtra = json_encode(ts('Are you sure you want to delete contact image.')); $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "' . htmlspecialchars("if (confirm({$deleteExtra})) this.href+='&confirmed=1'; else return false;") . '"')); $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')), ts('more'), FALSE, 'contact.profileimage.delete', 'Contact', $form->get('id')); $form->assign('deleteURL', $deleteURL); } $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); if (substr($fieldName, 0, 14) === 'state_province') { $form->addChainSelect($name, array('label' => $title, 'required' => $required)); $config = CRM_Core_Config::singleton(); if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactStateProvince) { $defaultValues[$name] = $config->defaultContactStateProvince; $form->setDefaults($defaultValues); } } elseif (substr($fieldName, 0, 7) === 'country') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required, $selectAttributes); $config = CRM_Core_Config::singleton(); if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) { $defaultValues[$name] = $config->defaultContactCountry; $form->setDefaults($defaultValues); } } elseif (substr($fieldName, 0, 6) === 'county') { if ($addressOptions['county']) { $form->addChainSelect($name, array('label' => $title, 'required' => $required)); } } elseif (substr($fieldName, 0, 9) === 'image_URL') { $form->add('file', $name, $title, $attributes, $required); $form->addUploadElement($name); } elseif (substr($fieldName, 0, 2) === 'im') { $form->add('text', $name, $title, $attributes, $required); if (!$contactId) { if ($usedFor) { if (substr($name, -1) == ']') { $providerName = substr($name, 0, -1) . '-provider_id]'; } $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required); } else { $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required); } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) { $form->freeze($name . '-provider_id'); } } } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') { $form->addDate($name, $title, $required, array('formatType' => 'birth')); } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) { $form->addDate($name, $title, $required, array('formatType' => 'activityDate')); } elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') { list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo(); $sel =& $form->addElement('hierselect', $name, $title); $select = array('' => ts('- select -')); if (count($orgInfo) == 1 && $field['is_required']) { // we only have one org - so we should default to it. Not sure about defaulting to first type // as it could be missed - so adding a select // however, possibly that is more similar to the membership form if (count($types[1]) > 1) { $types[1] = $select + $types[1]; } } else { $orgInfo = $select + $orgInfo; } $sel->setOptions(array($orgInfo, $types)); } elseif (CRM_Utils_Array::value('name', $field) == 'membership_status') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required); } elseif (in_array($fieldName, array('gender_id', 'communication_style_id'))) { $options = array(); $pseudoValues = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $fieldName); foreach ($pseudoValues as $key => $var) { $options[$key] = $form->createElement('radio', NULL, ts($title), $var, $key); } $group = $form->addGroup($options, $name, $title); if ($required) { $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required'); } else { $group->setAttribute('allowClear', TRUE); } } elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') { $form->addSelect($name, array('label' => $title, 'entity' => 'contact', 'field' => $fieldName, 'class' => 'six', 'placeholder' => ''), $required); } elseif ($fieldName === 'contact_sub_type') { $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); if ($usedFor == 'onbehalf') { $profileType = 'Organization'; } elseif ($usedFor == 'honor') { $profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']); } else { $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL; if ($profileType == 'Contact') { $profileType = 'Individual'; } } $setSubtype = FALSE; if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $setSubtype = $profileType; $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array(); if ($setSubtype) { $subtypeList = array(); $subtypeList[$setSubtype] = $subtypes[$setSubtype]; } else { $subtypeList = $subtypes; } $form->add('select', $name, $title, $subtypeList, $required, array('class' => 'crm-select2', 'multiple' => TRUE)); } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) { //add email greeting, postal greeting, addressee, CRM-4575 $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE); if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) { $profileType = 'Individual'; } if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName); $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required); // add custom greeting element $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE); } elseif ($fieldName === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'); foreach ($communicationFields as $key => $var) { if ($key == '') { continue; } $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var); } $form->addGroup($communicationOptions, $name, $title, '<br/>'); } elseif ($fieldName === 'preferred_mail_format') { $form->add('select', $name, $title, CRM_Core_SelectValues::pmf()); } elseif ($fieldName === 'preferred_language') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contact_BAO_Contact::buildOptions('preferred_language')); } elseif ($fieldName == 'external_identifier') { $form->add('text', $name, $title, $attributes, $required); $contID = $contactId; if (!$contID) { $contID = $form->get('id'); } $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier')); } elseif ($fieldName === 'group') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name); } elseif ($fieldName === 'tag') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name); } elseif (substr($fieldName, 0, 4) === 'url-') { $form->add('text', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), $required); $form->addRule($name, ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url'); } elseif (substr($fieldName, -4) == 'note') { $form->add('textarea', $name, $title, $attributes, $required); } elseif (substr($fieldName, 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (substr($fieldName, 0, 14) === 'address_custom') { list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2); $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8)); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'send_receipt') { $form->addElement('checkbox', $name, $title); } elseif ($fieldName == 'soft_credit') { $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Soft Credit To'), array('create' => TRUE)); $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE); } elseif ($fieldName == 'product_name') { list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); $sel =& $form->addElement('hierselect', $name, $title); $products = array('0' => ts('- select -')) + $products; $sel->setOptions(array($products, $options)); } elseif ($fieldName == 'payment_instrument') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } elseif ($fieldName == 'financial_type') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), $required); } elseif ($fieldName == 'contribution_status_id') { $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(); $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); foreach (array('In Progress', 'Overdue', 'Refunded') as $suppress) { unset($contributionStatuses[CRM_Utils_Array::key($suppress, $statusName)]); } $form->add('select', $name, $title, array('' => ts('- select -')) + $contributionStatuses, $required); } elseif ($fieldName == 'soft_credit_type') { $name = "soft_credit_type[{$rowNumber}]"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_OptionGroup::values("soft_credit_type")); //CRM-15350: choose SCT field default value as 'Gift' for membership use //else (for contribution), use configured SCT default value $SCTDefaultValue = CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"); if ($field['field_type'] == 'Membership') { $SCTDefaultValue = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name'); } $form->addElement('hidden', 'sct_default_id', $SCTDefaultValue, array('id' => 'sct_default_id')); } elseif ($fieldName == 'currency') { $form->addCurrency($name, $title, $required); } elseif ($fieldName == 'contribution_page_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"'); } elseif ($fieldName == 'participant_register_date') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'activity_status_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required); } elseif ($fieldName == 'activity_engagement_level') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required); } elseif ($fieldName == 'activity_date_time') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'participant_status') { $cond = NULL; if ($online == TRUE) { $cond = 'visibility_id = 1'; } $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required); } elseif ($fieldName == 'participant_role') { if (!empty($field['is_multiple'])) { $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, ' ', TRUE); } else { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required); } } elseif ($fieldName == 'world_region') { $form->add('select', $name, $title, CRM_Core_PseudoConstant::worldRegion(), $required, $selectAttributes); } elseif ($fieldName == 'signature_html') { $form->add('wysiwyg', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif ($fieldName == 'signature_text') { $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif (substr($fieldName, -11) == 'campaign_id') { if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns)); $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="crm-select2 big"'); } } elseif ($fieldName == 'activity_details') { $form->add('wysiwyg', $fieldName, $title, array('rows' => 4, 'cols' => 60), $required); } elseif ($fieldName == 'activity_duration') { $form->add('text', $name, $title, $attributes, $required); $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger'); } else { if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') { $form->add('advcheckbox', $name, $title, $attributes, $required); } else { $form->add('text', $name, $title, $attributes, $required); } } static $hiddenSubtype = FALSE; if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) { // In registration mode params are submitted via POST and we don't have any clue // about profile-id or the profile-type (which could be a subtype) // To generalize the behavior and simplify the process, // lets always add the hidden //subtype value if there is any, and we won't have to // compute it while processing. if ($usedFor) { $form->addElement('hidden', $usedFor . '[contact_sub_type]', $field['field_type']); } else { $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']); } $hiddenSubtype = TRUE; } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) { $form->freeze($name); } //add the rules if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) { $form->addRule($name, ts('Please enter a valid amount.'), 'money'); } if ($rule) { if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) { $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule); } } }
/** * @param $vals * @param $rule * @param CRM_Core_Form $form * * @return array */ public static function formRule($vals, $rule, $form) { $errors = array(); if (empty($vals['reassign_contact_id']) || $vals['reassign_contact_id'] == $form->get('cid')) { $errors['reassign_contact_id'] = ts("Please select a different contact."); } return $errors; }
/** * Build the form object. * * * @param CRM_Core_Form $form * * @return void */ public static function buildQuickForm(&$form) { $toArray = array(); $providers = CRM_SMS_BAO_Provider::getProviders(NULL, NULL, TRUE, 'is_default desc'); $providerSelect = array(); foreach ($providers as $provider) { $providerSelect[$provider['id']] = $provider['title']; } $suppressedSms = 0; //here we are getting logged in user id as array but we need target contact id. CRM-5988 $cid = $form->get('cid'); if ($cid) { $form->_contactIds = array($cid); } $to = $form->add('text', 'to', ts('To'), array('class' => 'huge'), TRUE); $form->add('text', 'activity_subject', ts('Name The SMS'), array('class' => 'huge'), TRUE); $toSetDefault = TRUE; if (property_exists($form, '_context') && $form->_context == 'standalone') { $toSetDefault = FALSE; } // when form is submitted recompute contactIds $allToSMS = array(); if ($to->getValue()) { $allToPhone = explode(',', $to->getValue()); $form->_contactIds = array(); foreach ($allToPhone as $value) { list($contactId, $phone) = explode('::', $value); if ($contactId) { $form->_contactIds[] = $contactId; $form->_toContactPhone[] = $phone; } } $toSetDefault = TRUE; } //get the group of contacts as per selected by user in case of Find Activities if (!empty($form->_activityHolderIds)) { $extendTargetContacts = 0; $invalidActivity = 0; $validActivities = 0; foreach ($form->_activityHolderIds as $key => $id) { //valid activity check if (CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $id, 'subject', 'id') != self::RECIEVED_SMS_ACTIVITY_SUBJECT) { $invalidActivity++; continue; } $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); //target contacts limit check $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $targetID)); if (count($ids) > 1) { $extendTargetContacts++; continue; } $validActivities++; $form->_contactIds = empty($form->_contactIds) ? $ids : array_unique(array_merge($form->_contactIds, $ids)); } if (!$validActivities) { $errorMess = ""; if ($extendTargetContacts) { $errorMess = ts('One selected activity consists of more than one target contact.', array('count' => $extendTargetContacts, 'plural' => '%count selected activities consist of more than one target contact.')); } if ($invalidActivity) { $errorMess = $errorMess ? ' ' : ''; $errorMess .= ts('The selected activity is invalid.', array('count' => $invalidActivity, 'plural' => '%count selected activities are invalid.')); } CRM_Core_Error::statusBounce(ts("%1: SMS Reply will not be sent.", array(1 => $errorMess))); } } if (is_array($form->_contactIds) && !empty($form->_contactIds) && $toSetDefault) { $returnProperties = array('sort_name' => 1, 'phone' => 1, 'do_not_sms' => 1, 'is_deceased' => 1, 'display_name' => 1); list($form->_contactDetails) = CRM_Utils_Token::getTokenDetails($form->_contactIds, $returnProperties, FALSE, FALSE); // make a copy of all contact details $form->_allContactDetails = $form->_contactDetails; foreach ($form->_contactIds as $key => $contactId) { $value = $form->_contactDetails[$contactId]; //to check if the phone type is "Mobile" $phoneTypes = CRM_Core_OptionGroup::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name'); if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Form_Task_SMS') { //to check for "if the contact id belongs to a specified activity type" $actDetails = CRM_Activity_BAO_Activity::getContactActivity($contactId); if (self::RECIEVED_SMS_ACTIVITY_SUBJECT != CRM_Utils_Array::retrieveValueRecursive($actDetails, 'subject')) { $suppressedSms++; unset($form->_contactDetails[$contactId]); continue; } } if (isset($value['phone_type_id']) && $value['phone_type_id'] != CRM_Utils_Array::value('Mobile', $phoneTypes) || $value['do_not_sms'] || empty($value['phone']) || !empty($value['is_deceased'])) { //if phone is not primary check if non-primary phone is "Mobile" if (!empty($value['phone']) && $value['phone_type_id'] != CRM_Utils_Array::value('Mobile', $phoneTypes) && empty($value['is_deceased'])) { $filter = array('do_not_sms' => 0); $contactPhones = CRM_Core_BAO_Phone::allPhones($contactId, FALSE, 'Mobile', $filter); if (count($contactPhones) > 0) { $mobilePhone = CRM_Utils_Array::retrieveValueRecursive($contactPhones, 'phone'); $form->_contactDetails[$contactId]['phone_id'] = CRM_Utils_Array::retrieveValueRecursive($contactPhones, 'id'); $form->_contactDetails[$contactId]['phone'] = $mobilePhone; $form->_contactDetails[$contactId]['phone_type_id'] = CRM_Utils_Array::value('Mobile', $phoneTypes); } else { $suppressedSms++; unset($form->_contactDetails[$contactId]); continue; } } else { $suppressedSms++; unset($form->_contactDetails[$contactId]); continue; } } if (isset($mobilePhone)) { $phone = $mobilePhone; } elseif (empty($form->_toContactPhone)) { $phone = $value['phone']; } else { $phone = CRM_Utils_Array::value($key, $form->_toContactPhone); } if ($phone) { $toArray[] = array('text' => '"' . $value['sort_name'] . '" (' . $phone . ')', 'id' => "{$contactId}::{$phone}"); } } if (empty($toArray)) { CRM_Core_Error::statusBounce(ts('Selected contact(s) do not have a valid Phone, or communication preferences specify DO NOT SMS, or they are deceased')); } } //activity related variables if (isset($invalidActivity)) { $form->assign('invalidActivity', $invalidActivity); } if (isset($extendTargetContacts)) { $form->assign('extendTargetContacts', $extendTargetContacts); } $form->assign('toContact', json_encode($toArray)); $form->assign('suppressedSms', $suppressedSms); $form->assign('totalSelectedContacts', count($form->_contactIds)); $form->add('select', 'sms_provider_id', ts('From'), $providerSelect, TRUE); CRM_Mailing_BAO_Mailing::commonCompose($form); if ($form->_single) { // also fix the user context stack if ($form->_context) { $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); } else { $url = CRM_Utils_System::url('civicrm/contact/view', "&show=1&action=browse&cid={$form->_contactIds[0]}&selectedChild=activity"); } $session = CRM_Core_Session::singleton(); $session->replaceUserContext($url); $form->addDefaultButtons(ts('Send SMS'), 'upload', 'cancel'); } else { $form->addDefaultButtons(ts('Send SMS'), 'upload'); } $form->addFormRule(array('CRM_Contact_Form_Task_SMSCommon', 'formRule'), $form); }
/** * Build badges parameters before actually creating badges. * * @param array $params * Associated array of submitted values. * @param CRM_Core_Form $form * * @return void */ public static function buildBadges(&$params, &$form) { // get name badge layout info $layoutInfo = CRM_Badge_BAO_Layout::buildLayout($params); // split/get actual field names from token and individual contact image URLs $returnProperties = array(); if (!empty($layoutInfo['data']['token'])) { foreach ($layoutInfo['data']['token'] as $index => $value) { $element = ''; if ($value) { $token = CRM_Utils_Token::getTokens($value); if (key($token) == 'contact') { $element = $token['contact'][0]; } elseif (key($token) == 'event') { $element = $token['event'][0]; //FIX ME - we need to standardize event token names if (substr($element, 0, 6) != 'event_') { $element = 'event_' . $element; } } elseif (key($token) == 'participant') { $element = $token['participant'][0]; } // build returnproperties for query $returnProperties[$element] = 1; } // add actual field name to row element $layoutInfo['data']['rowElements'][$index] = $element; } } // add additional required fields for query execution $additionalFields = array('participant_register_date', 'participant_id', 'event_id', 'contact_id', 'image_URL'); foreach ($additionalFields as $field) { $returnProperties[$field] = 1; } if ($form->_single) { $queryParams = NULL; } else { $queryParams = $form->get('queryParams'); } $query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_EVENT); list($select, $from, $where, $having) = $query->query(); if (empty($where)) { $where = "WHERE {$form->_componentClause}"; } else { $where .= " AND {$form->_componentClause}"; } $sortOrder = NULL; if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); if (!empty($sortOrder)) { $sortOrder = " ORDER BY {$sortOrder}"; } } $queryString = "{$select} {$from} {$where} {$having} {$sortOrder}"; $dao = CRM_Core_DAO::executeQuery($queryString); $rows = array(); while ($dao->fetch()) { $query->convertToPseudoNames($dao); $rows[$dao->participant_id] = array(); foreach ($returnProperties as $key => $dontCare) { $value = isset($dao->{$key}) ? $dao->{$key} : NULL; // Format custom fields if (strstr($key, 'custom_') && isset($value)) { $value = CRM_Core_BAO_CustomField::getDisplayValue($value, substr($key, 7), $query->_options, $dao->contact_id); } $rows[$dao->participant_id][$key] = $value; } } $eventBadgeClass = new CRM_Badge_BAO_Badge(); $eventBadgeClass->createLabels($rows, $layoutInfo); }
/** * Implementation of hook_civicrm_validateForm() * * Used in the initial event registration screen. * * @param string $name * @param array $fields reference * @param array $files * @param CRM_Core_Form $form * @param $errors */ function cividiscount_civicrm_validateForm($name, &$fields, &$files, &$form, &$errors) { if (!in_array($name, array('CRM_Contribute_Form_Contribution_Main', 'CRM_Event_Form_Participant', 'CRM_Event_Form_Registration_Register', 'CRM_Member_Form_Membership', 'CRM_Member_Form_MembershipRenewal'))) { return; } // _discountInfo is assigned in cividiscount_civicrm_buildAmount() or // cividiscount_civicrm_membershipTypeValues() when a discount is used. $discountInfo = $form->get('_discountInfo'); $code = trim(CRM_Utils_Request::retrieve('discountcode', 'String', $form, false, null, 'REQUEST')); if ((!$discountInfo || !$discountInfo['autodiscount']) && trim($code) != '') { if (!$discountInfo) { $errors['discountcode'] = ts('The discount code you entered is invalid.'); return; } $discount = $discountInfo['discount']; if ($discount['count_max'] > 0) { // Initially 1 for person registering. $apcount = 1; $sv = $form->getVar('_submitValues'); if (array_key_exists('additional_participants', $sv)) { $apcount += $sv['additional_participants']; } if ($discount['count_use'] + $apcount > $discount['count_max']) { $errors['discountcode'] = ts('There are not enough uses remaining for this code.'); } } } }
/** * Validate price set submitted params for price option limit. * * User should select at least one price field option. * * @param CRM_Core_Form $form * @param array $params * * @return array */ public static function validatePriceSet(&$form, $params) { $errors = array(); $hasOptMaxValue = FALSE; if (!is_array($params) || empty($params)) { return $errors; } $currentParticipantNum = substr($form->_name, 12); if (!$currentParticipantNum) { $currentParticipantNum = 0; } $priceSetId = $form->get('priceSetId'); $priceSetDetails = $form->get('priceSet'); if (!$priceSetId || !is_array($priceSetDetails) || empty($priceSetDetails)) { return $errors; } $optionsCountDetails = $optionsMaxValueDetails = array(); if (isset($priceSetDetails['optionsMaxValueTotal']) && $priceSetDetails['optionsMaxValueTotal']) { $hasOptMaxValue = TRUE; $optionsMaxValueDetails = $priceSetDetails['optionsMaxValueDetails']['fields']; } if (isset($priceSetDetails['optionsCountTotal']) && $priceSetDetails['optionsCountTotal']) { $hasOptCount = TRUE; $optionsCountDetails = $priceSetDetails['optionsCountDetails']['fields']; } $feeBlock = $form->_feeBlock; if (empty($feeBlock)) { $feeBlock = $priceSetDetails['fields']; } $optionMaxValues = $fieldSelected = array(); foreach ($params as $pNum => $values) { if (!is_array($values) || $values == 'skip') { continue; } foreach ($values as $valKey => $value) { if (strpos($valKey, 'price_') === FALSE) { continue; } $priceFieldId = substr($valKey, 6); $noneOptionValueSelected = FALSE; if (!$feeBlock[$priceFieldId]['is_required'] && $value == 0) { $noneOptionValueSelected = TRUE; } if (!$priceFieldId || !$noneOptionValueSelected && !is_array($value)) { continue; } $fieldSelected[$pNum] = TRUE; if (!$hasOptMaxValue || !is_array($value)) { continue; } foreach ($value as $optId => $optVal) { if (CRM_Utils_Array::value('html_type', $feeBlock[$priceFieldId]) == 'Text') { $currentMaxValue = $optVal; } else { $currentMaxValue = 1; } if (isset($optionsCountDetails[$priceFieldId]) && isset($optionsCountDetails[$priceFieldId]['options'][$optId])) { $currentMaxValue = $optionsCountDetails[$priceFieldId]['options'][$optId] * $optVal; } if (empty($optionMaxValues)) { $optionMaxValues[$priceFieldId][$optId] = $currentMaxValue; } else { $optionMaxValues[$priceFieldId][$optId] = $currentMaxValue + CRM_Utils_Array::value($optId, CRM_Utils_Array::value($priceFieldId, $optionMaxValues), 0); } $soldOutPnum[$optId] = $pNum; } } //validate for price field selection. if (empty($fieldSelected[$pNum])) { $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).'); } } //validate for option max value. foreach ($optionMaxValues as $fieldId => $values) { $options = CRM_Utils_Array::value('options', $feeBlock[$fieldId], array()); foreach ($values as $optId => $total) { $optMax = $optionsMaxValueDetails[$fieldId]['options'][$optId]; $opDbCount = CRM_Utils_Array::value('db_total_count', $options[$optId], 0); $total += $opDbCount; if ($optMax && $total > $optMax) { if ($opDbCount && $opDbCount >= $optMax) { $errors[$soldOutPnum[$optId]]["price_{$fieldId}"] = ts('Sorry, this option is currently sold out.'); } elseif ($optMax - $opDbCount == 1) { $errors[$soldOutPnum[$optId]]["price_{$fieldId}"] = ts('Sorry, currently only a single seat is available for this option.', array(1 => $optMax - $opDbCount)); } else { $errors[$soldOutPnum[$optId]]["price_{$fieldId}"] = ts('Sorry, currently only %1 seats are available for this option.', array(1 => $optMax - $opDbCount)); } } } } return $errors; }
/** * Set default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * * @param CRM_Core_Form $form * @param $defaults * * @return void */ public static function setDefaultValues(&$form, &$defaults) { $contactEditOptions = $form->get('contactEditOptions'); if ($form->_action & CRM_Core_Action::ADD) { if (array_key_exists('TagsAndGroups', $contactEditOptions)) { // set group and tag defaults if any if ($form->_gid) { $defaults['group'][$form->_gid] = 1; } if ($form->_tid) { $defaults['tag'][$form->_tid] = 1; } } } else { if (array_key_exists('TagsAndGroups', $contactEditOptions)) { // set the group and tag ids $groupElementType = 'checkbox'; if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') { $groupElementType = 'select'; } self::setDefaults($form->_contactId, $defaults, self::ALL, NULL, $groupElementType); } } }