Пример #1
0
 /**
  * This function sets the default values for the form. MobileProvider that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 public function setDefaultValues()
 {
     $defaults = array();
     $defaults =& parent::setDefaultValues();
     //finding default weight to be put
     if (!isset($defaults['weight']) || !$defaults['weight']) {
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipType');
     }
     //setting default relationshipType
     if (isset($defaults['relationship_type_id'])) {
         //$defaults['relationship_type_id'] = $defaults['relationship_type_id'].'_a_b';
         $defaults['relationship_type_id'] = $defaults['relationship_type_id'] . '_' . $defaults['relationship_direction'];
     }
     $config =& CRM_Core_Config::singleton();
     //setting default fixed_period_start_day & fixed_period_rollover_day
     $periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
     foreach ($periods as $per) {
         if (isset($defaults[$per])) {
             $dat = $defaults[$per];
             $dat = $dat < 999 ? '0' . $dat : $dat;
             $defaults[$per] = array();
             $defaults[$per][$config->dateformatMonthVar] = substr($dat, 0, 2);
             $defaults[$per]['d'] = substr($dat, 2, 3);
         }
     }
     return $defaults;
 }
 /**
  * This function sets the default values for the form. MobileProvider that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 public function setDefaultValues()
 {
     $defaults = array();
     $defaults = parent::setDefaultValues();
     //finding default weight to be put
     if (!isset($defaults['weight']) || !$defaults['weight']) {
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipType');
     }
     //setting default relationshipType
     if (isset($defaults['relationship_type_id'])) {
         //$defaults['relationship_type_id'] = $defaults['relationship_type_id'].'_a_b';
         // Set values for relation type select box
         $relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['relationship_type_id']);
         $relDirections = explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['relationship_direction']);
         $defaults['relationship_type_id'] = array();
         foreach ($relTypeIds as $key => $value) {
             $defaults['relationship_type_id'][] = $value . '_' . $relDirections[$key];
         }
     }
     $config = CRM_Core_Config::singleton();
     //setting default fixed_period_start_day & fixed_period_rollover_day
     $periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
     foreach ($periods as $per) {
         if (isset($defaults[$per])) {
             $dat = $defaults[$per];
             $dat = $dat < 999 ? '0' . $dat : $dat;
             $defaults[$per] = array();
             $defaults[$per]['M'] = substr($dat, 0, 2);
             $defaults[$per]['d'] = substr($dat, 2, 3);
         }
     }
     return $defaults;
 }
Пример #3
0
 public function createEntry($id, $key)
 {
     $e = self::$_extensions;
     $ids = array();
     $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::OPTION_GROUP_NAME, 'id', 'name');
     $params = array('option_group_id' => $groupId, 'weight' => CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $groupId)), 'label' => $e['per_id'][$id]['label'], 'name' => $e['per_id'][$id]['label'], 'value' => $key, 'grouping' => $e['per_id'][$id]['type'], 'is_active' => 1);
     $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
 }
 /**
  * Set default values for the form. MobileProvider that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     //finding default weight to be put
     if (empty($defaults['weight'])) {
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipStatus');
     }
     return $defaults;
 }
 /**
  * This function sets the default values for the form. MobileProvider that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 public function setDefaultValues()
 {
     $defaults = array();
     $defaults =& parent::setDefaultValues();
     //finding default weight to be put
     if (!CRM_Utils_Array::value('weight', $defaults)) {
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipStatus');
     }
     return $defaults;
 }
Пример #6
0
 public function install()
 {
     if (array_key_exists($this->ext->key, $this->customSearches)) {
         CRM_Core_Error::fatal('This custom search is already registered.');
     }
     $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $this->groupId));
     $params = array('option_group_id' => $this->groupId, 'weight' => $weight, 'description' => $this->ext->label . ' (' . $this->ext->key . ')', 'name' => $this->ext->key, 'value' => max($this->customSearches) + 1, 'label' => $this->ext->key, 'is_active' => 1);
     $ids = array();
     $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
 }
 /**
  * Set default values.
  *
  * @return array
  */
 public function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     if (empty($defaults['weight'])) {
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Event_DAO_ParticipantStatusType');
     }
     $this->_isReserved = CRM_Utils_Array::value('is_reserved', $defaults);
     if ($this->_isReserved) {
         $this->freeze(array('name', 'class', 'is_active'));
     }
     return $defaults;
 }
Пример #8
0
 /**
  * @param CRM_Extension_Info $info
  *
  * @return bool
  * @throws Exception
  */
 public function onPreInstall(CRM_Extension_Info $info)
 {
     $customSearchesByName = $this->getCustomSearchesByName();
     if (array_key_exists($info->key, $customSearchesByName)) {
         CRM_Core_Error::fatal('This custom search is already registered.');
     }
     $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $this->groupId));
     $params = array('option_group_id' => $this->groupId, 'weight' => $weight, 'description' => $info->label . ' (' . $info->key . ')', 'name' => $info->key, 'value' => max($customSearchesByName) + 1, 'label' => $info->key, 'is_active' => 1);
     $ids = array();
     $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
     return $optionValue ? TRUE : FALSE;
 }
Пример #9
0
 function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     if (!CRM_Utils_Array::value('weight', $defaults)) {
         require_once 'CRM/Utils/Weight.php';
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Event_DAO_ParticipantStatusType');
     }
     $this->_isReserved = $defaults['is_reserved'];
     if ($this->_isReserved) {
         $this->freeze(array('name', 'class', 'is_active'));
     }
     return $defaults;
 }
 function setDefaultValues()
 {
     $defaults = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     if ($this->_id) {
         $params = array('id' => $this->_id);
         $defaults = array();
         CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_OptionValue', $params, $defaults);
     } else {
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $this->_opID));
     }
     return $defaults;
 }
Пример #11
0
 public function install()
 {
     if (array_key_exists($this->ext->key, $this->customReports)) {
         CRM_Core_Error::fatal('This report is already registered.');
     }
     if ($this->ext->typeInfo['component'] === 'Contact') {
         $compId = 'null';
     } else {
         $comp = CRM_Core_Component::get($this->ext->typeInfo['component']);
         $compId = $comp->componentID;
     }
     if (empty($compId)) {
         CRM_Core_Error::fatal("Component for which you're trying to install the extension (" . $this->ext->typeInfo['component'] . ") is currently disabled.");
     }
     $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $this->groupId));
     $ids = array();
     $params = array('label' => $this->ext->label . ' (' . $this->ext->key . ')', 'value' => $this->ext->typeInfo['reportUrl'], 'name' => $this->ext->key, 'weight' => $weight, 'description' => $this->ext->label . ' (' . $this->ext->key . ')', 'component_id' => $compId, 'option_group_id' => $this->groupId, 'is_active' => 1);
     $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
 }
/**
 *  Add a OptionValue. OptionValues are used to classify CRM entities (including Contacts, Groups and Actions).
 *
 * Allowed @params array keys are:
 *
 * {@example OptionValueCreate.php}
 *
 * @return array of newly created option_value property values.
 * {@getfields OptionValue_create}
 * @access public
 */
function civicrm_api3_option_value_create($params)
{
    $weight = 0;
    if (!array_key_exists('label', $params) && array_key_exists('name', $params)) {
        // no idea why that's a "mandatory" field
        $params['label'] = $params['name'];
    }
    if (!CRM_Utils_Array::value('value', $params) && array_key_exists('option_group_id', $params)) {
        require_once 'CRM/Utils/Weight.php';
        $fieldValues = array('option_group_id' => $params['option_group_id']);
        // use the next available value
        /* CONVERT(value, DECIMAL) is used to convert varchar
           field 'value' to decimal->integer                    */
        $params['value'] = (int) CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues, 'CONVERT(value, DECIMAL)');
        $weight = $params['value'];
    }
    if (!array_key_exists('weight', $params) && array_key_exists('value', $params)) {
        // no idea why that's a "mandatory" field
        $params['weight'] = $params['value'];
    } elseif (array_key_exists('weight', $params) && $params['weight'] == 'next') {
        // weight is numeric, so it's safe-ish to treat symbol 'next' as magical value
        $params['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $params['option_group_id']));
    }
    if (array_key_exists('component', $params)) {
        if (empty($params['component'])) {
            $params['component_id'] = '';
        } else {
            $params['component_id'] = array_search($params['component'], CRM_Core_PseudoConstant::component());
        }
        unset($params['component']);
    }
    if (CRM_Utils_Array::value('id', $params)) {
        $ids = array('optionValue' => $params['id']);
    }
    $optionValueBAO = CRM_Core_BAO_OptionValue::add($params, $ids);
    civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1));
    $values = array();
    _civicrm_api3_object_to_array($optionValueBAO, $values[$optionValueBAO->id]);
    return civicrm_api3_create_success($values, $params);
}
Пример #13
0
 /**
  * This function sets the default values for the form. MobileProvider that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 public function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     // get the member org display name
     if ($this->_id && CRM_Utils_Array::value('member_of_contact_id', $defaults)) {
         $this->assign('member_org_id', $defaults['member_of_contact_id']);
     }
     //finding default weight to be put
     if (!isset($defaults['weight']) || !$defaults['weight']) {
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipType');
     }
     //setting default relationshipType
     if (isset($defaults['relationship_type_id'])) {
         //$defaults['relationship_type_id'] = $defaults['relationship_type_id'].'_a_b';
         // Set values for relation type select box
         $relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['relationship_type_id']);
         $relDirections = explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['relationship_direction']);
         $defaults['relationship_type_id'] = array();
         foreach ($relTypeIds as $key => $value) {
             $defaults['relationship_type_id'][] = $value . '_' . $relDirections[$key];
         }
     }
     //setting default fixed_period_start_day & fixed_period_rollover_day
     $periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
     foreach ($periods as $per) {
         if (isset($defaults[$per])) {
             $date = $defaults[$per];
             $defaults[$per] = array();
             if ($date > 31) {
                 $date = $date < 999 ? '0' . $date : $date;
                 $defaults[$per]['M'] = substr($date, 0, 2);
                 $defaults[$per]['d'] = substr($date, 2, 3);
             } else {
                 //special case when only day is rollover and duration is month
                 $defaults['month_fixed_period_rollover_day']['d'] = $date;
             }
         }
     }
     return $defaults;
 }
Пример #14
0
 /**
  * Get the default PDF Page Format values.
  *
  * @return array
  *   Name/value pairs containing the default PDF Page Format values.
  */
 public static function &getDefaultValues()
 {
     $params = array('is_active' => 1, 'is_default' => 1);
     $defaults = array();
     if (!self::retrieve($params, $defaults)) {
         foreach (self::$optionValueFields as $name => $field) {
             $defaults[$name] = $field['default'];
         }
         $filter = array('option_group_id' => self::_getGid());
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $filter);
         // also set the id to avoid NOTICES, CRM-8454
         $defaults['id'] = NULL;
     }
     return $defaults;
 }
Пример #15
0
 function upgrade($rev)
 {
     // fix CRM-5270: if civicrm_report_instance.description is localised,
     // recreate it based on the first locale’s description_xx_YY contents
     // and drop all the description_xx_YY columns
     if (!CRM_Core_DAO::checkFieldExists('civicrm_report_instance', 'description')) {
         require_once 'CRM/Core/DAO/Domain.php';
         $domain = new CRM_Core_DAO_Domain();
         $domain->find(true);
         $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
         CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_report_instance ADD description VARCHAR(255)");
         CRM_Core_DAO::executeQuery("UPDATE civicrm_report_instance SET description = description_{$locales[0]}");
         CRM_Core_DAO::executeQuery("DROP TRIGGER civicrm_report_instance_before_insert");
         foreach ($locales as $locale) {
             CRM_Core_DAO::executeQuery("DROP VIEW civicrm_report_instance_{$locale}");
             CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_report_instance DROP description_{$locale}");
         }
     }
     //We execute some part of php after sql and then again sql
     //So using conditions for skipping some part of sql CRM-4575
     $upgrade =& new CRM_Upgrade_Form();
     //Run the SQL file (1)
     $upgrade->processSQL($rev);
     //replace  with ; in report instance
     $sql = "UPDATE civicrm_report_instance \n                       SET form_values = REPLACE(form_values,'#',';') ";
     CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
     //delete unnecessary activities
     $bulkEmailID = CRM_Core_OptionGroup::getValue('activity_type', 'Bulk Email', 'name');
     if ($bulkEmailID) {
         $mailingActivityIds = array();
         $query = " \n            SELECT max( ca.id ) as aid, \n                   ca.source_record_id sid\n            FROM civicrm_activity ca\n            WHERE ca.activity_type_id = %1 \n            GROUP BY ca.source_record_id";
         $params = array(1 => array($bulkEmailID, 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($query, $params);
         while ($dao->fetch()) {
             $updateQuery = "\n                UPDATE civicrm_activity_target cat, civicrm_activity ca \n                    SET cat.activity_id = {$dao->aid}  \n                WHERE ca.source_record_id IS NOT NULL   AND\n                      ca.activity_type_id = %1          AND \n                      ca.id <> {$dao->aid}              AND \n                      ca.source_record_id = {$dao->sid} AND \n                      ca.id = cat.activity_id";
             $updateParams = array(1 => array($bulkEmailID, 'Integer'));
             CRM_Core_DAO::executeQuery($updateQuery, $updateParams);
             $deleteQuery = " \n                DELETE ca.* \n                FROM civicrm_activity ca \n                WHERE ca.source_record_id IS NOT NULL  AND \n                      ca.activity_type_id = %1         AND \n                      ca.id <> {$dao->aid}             AND \n                      ca.source_record_id = {$dao->sid}";
             $deleteParams = array(1 => array($bulkEmailID, 'Integer'));
             CRM_Core_DAO::executeQuery($deleteQuery, $deleteParams);
         }
     }
     //CRM-4453
     //lets insert column in civicrm_aprticipant table
     $query = "\n        ALTER TABLE `civicrm_participant` \n            ADD `fee_currency` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT '3 character string, value derived from config setting.' AFTER `discount_id`";
     CRM_Core_DAO::executeQuery($query);
     //get currency from contribution table if exists/default
     //insert currency when fee_amount != NULL or event is paid.
     $query = "\n        SELECT  civicrm_participant.id \n        FROM    civicrm_participant\n            LEFT JOIN  civicrm_event \n                   ON ( civicrm_participant.event_id = civicrm_event.id )\n        WHERE  civicrm_participant.fee_amount IS NOT NULL OR \n               civicrm_event.is_monetary = 1";
     $participant = CRM_Core_DAO::executeQuery($query);
     while ($participant->fetch()) {
         $query = "\n            SELECT civicrm_contribution.currency \n            FROM   civicrm_contribution, \n                   civicrm_participant_payment\n            WHERE  civicrm_contribution.id = civicrm_participant_payment.contribution_id AND  \n                   civicrm_participant_payment.participant_id = {$participant->id}";
         $currencyID = CRM_Core_DAO::singleValueQuery($query);
         if (!$currencyID) {
             $config =& CRM_Core_Config::singleton();
             $currencyID = $config->defaultCurrency;
         }
         //finally update participant record.
         CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Participant', $participant->id, 'fee_currency', $currencyID);
     }
     //CRM-4575
     //check whether {contact.name} is set in mailing labels
     require_once 'CRM/Core/BAO/Preferences.php';
     $mailingFormat = CRM_Core_BAO_Preferences::value('mailing_format');
     $addNewAddressee = true;
     if (strpos($mailingFormat, '{contact.contact_name}') === false) {
         $addNewAddressee = false;
     } else {
         //else compare individual name format with default individual addressee.
         $individualNameFormat = CRM_Core_BAO_Preferences::value('individual_name_format');
         $defaultAddressee = CRM_Core_OptionGroup::values('addressee', false, false, false, " AND v.filter = 1 AND v.is_default =  1", 'label');
         if (array_search($individualNameFormat, $defaultAddressee) !== false) {
             $addNewAddressee = false;
         }
     }
     require_once 'CRM/Utils/System.php';
     $docURL = CRM_Utils_System::docURL2('Update Greetings and Address Data for Contacts', false, null, null, 'color: white; text-decoration: underline;');
     if ($addNewAddressee) {
         //otherwise insert new token in addressee and set as a default
         $addresseeGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'addressee', 'id', 'name');
         $optionValueParams = array('label' => $individualNameFormat, 'is_active' => 1, 'contactOptions' => 1, 'filter' => 1, 'is_default' => 1, 'reset_default_for' => array('filter' => "0, 1"));
         $action = CRM_Core_Action::ADD;
         $addresseeGroupParams = array('name' => 'addressee');
         $fieldValues = array('option_group_id' => $addresseeGroupId);
         $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
         $optionValueParams['weight'] = $weight;
         $addresseeToken = CRM_Core_OptionValue::addOptionValue($optionValueParams, $addresseeGroupParams, $action, $optionId = null);
         $afterUpgradeMessage = ts("During this upgrade, Postal Addressee values have been stored for each contact record using the system default format - %2.You will need to run the included command-line script to update your Individual contact records to use the \"Individual Name Format\" previously specified for your site %1", array(1 => $docURL, 2 => array_pop($defaultAddressee)));
     } else {
         $afterUpgradeMessage = ts("Email Greeting, Postal Greeting and Postal Addressee values have been stored for all contact records based on the system default formats. If you want to use a different format for any of these contact fields - you can run the provided command line script to update contacts to a different format %1 ", array(1 => $docURL));
     }
     //replace contact.contact_name with contact.addressee in civicrm_preference.mailing_format
     $updateQuery = "\n        UPDATE civicrm_preferences \n               SET `mailing_format` = \n                    replace(`mailing_format`, '{contact.contact_name}','{contact.addressee}')";
     CRM_Core_DAO::executeQuery($updateQuery);
     //drop column individual_name_format
     $alterQuery = "\n        ALTER TABLE `civicrm_preferences`\n              DROP `individual_name_format`";
     CRM_Core_DAO::executeQuery($alterQuery);
     //set status message for default greetings
     $template =& CRM_Core_Smarty::singleton();
     $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
 }
Пример #16
0
 /**
  * Process the form when submitted
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     require_once 'CRM/Core/BAO/Domain.php';
     $params = array();
     $params = $this->exportValues();
     $params['entity_id'] = $this->_id;
     $params['entity_table'] = CRM_Core_BAO_Domain::getTableName();
     $domain = CRM_Core_BAO_Domain::edit($params, $this->_id);
     require_once 'CRM/Core/BAO/LocationType.php';
     $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
     $location = array();
     $params['address'][1]['location_type_id'] = $defaultLocationType->id;
     $params['phone'][1]['location_type_id'] = $defaultLocationType->id;
     $params['email'][1]['location_type_id'] = $defaultLocationType->id;
     $location = CRM_Core_BAO_Location::create($params, true, 'domain');
     $params['loc_block_id'] = $location['id'];
     require_once 'CRM/Core/BAO/Domain.php';
     CRM_Core_BAO_Domain::edit($params, $this->_id);
     //set domain from email address, CRM-3552
     $emailName = '"' . $params['email_name'] . '"<' . $params['email_address'] . '>';
     $emailParams = array('label' => $emailName, 'description' => $params['description'], 'is_active' => 1, 'is_default' => 1);
     $groupParams = array('name' => 'from_email_address');
     //get the option value wt.
     if ($this->_fromEmailId) {
         $action = $this->_action;
         $emailParams['weight'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_fromEmailId, 'weight');
     } else {
         //add from email address.
         $action = CRM_Core_Action::ADD;
         require_once 'CRM/Utils/Weight.php';
         $grpId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'from_email_address', 'id', 'name');
         $fieldValues = array('option_group_id' => $grpId);
         $emailParams['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
     }
     require_once 'CRM/Core/OptionValue.php';
     //reset default within domain.
     $emailParams['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
     CRM_Core_OptionValue::addOptionValue($emailParams, $groupParams, $action, $this->_fromEmailId);
     CRM_Core_Session::setStatus(ts('Domain information for \'%1\' has been saved.', array(1 => $domain->name)));
     $session =& CRM_Core_Session::singleton();
     $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
 }
Пример #17
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @param null
  *
  * @return array    array of default values
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = $this->_values;
     if ($this->_id) {
         $this->assign('id', $this->_id);
         $this->_gid = $defaults['custom_group_id'];
         //get the value for state or country
         if ($defaults['data_type'] == 'StateProvince' && ($stateId = CRM_Utils_Array::value('default_value', $defaults))) {
             $defaults['default_value'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_StateProvince', $stateId);
         } elseif ($defaults['data_type'] == 'Country' && ($countryId = CRM_Utils_Array::value('default_value', $defaults))) {
             $defaults['default_value'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Country', $countryId);
         }
         if ($defaults['data_type'] == 'ContactReference' && CRM_Utils_Array::value('filter', $defaults)) {
             $contactRefFilter = 'Advance';
             if (strpos($defaults['filter'], 'action=lookup') !== FALSE && strpos($defaults['filter'], 'group=') !== FALSE) {
                 $filterParts = explode('&', $defaults['filter']);
                 if (count($filterParts) == 2) {
                     $contactRefFilter = 'Group';
                     foreach ($filterParts as $part) {
                         if (strpos($part, 'group=') === FALSE) {
                             continue;
                         }
                         $groups = substr($part, strpos($part, '=') + 1);
                         foreach (explode(',', $groups) as $grp) {
                             if (CRM_Utils_Rule::positiveInteger($grp)) {
                                 $defaults['group_id'][] = $grp;
                             }
                         }
                     }
                 }
             }
             $defaults['filter_selected'] = $contactRefFilter;
         }
         if (CRM_Utils_Array::value('data_type', $defaults)) {
             $defaultDataType = array_search($defaults['data_type'], self::$_dataTypeKeys);
             $defaultHTMLType = array_search($defaults['html_type'], self::$_dataToHTML[$defaultDataType]);
             $defaults['data_type'] = array('0' => $defaultDataType, '1' => $defaultHTMLType);
             $this->_defaultDataType = $defaults['data_type'];
         }
         $defaults['option_type'] = 2;
         $this->assign('changeFieldType', CRM_Custom_Form_ChangeFieldType::fieldTypeTransitions($this->_values['data_type'], $this->_values['html_type']));
     } else {
         $defaults['is_active'] = 1;
         $defaults['option_type'] = 1;
     }
     // set defaults for weight.
     for ($i = 1; $i <= self::NUM_OPTION; $i++) {
         $defaults['option_status[' . $i . ']'] = 1;
         $defaults['option_weight[' . $i . ']'] = $i;
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $fieldValues = array('custom_group_id' => $this->_gid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_CustomField', $fieldValues);
         $defaults['text_length'] = 255;
         $defaults['note_columns'] = 60;
         $defaults['note_rows'] = 4;
         $defaults['is_view'] = 0;
     }
     if (CRM_Utils_Array::value('html_type', $defaults)) {
         $dontShowLink = substr($defaults['html_type'], -14) == 'State/Province' || substr($defaults['html_type'], -7) == 'Country' ? 1 : 0;
     }
     if (isset($dontShowLink)) {
         $this->assign('dontShowLink', $dontShowLink);
     }
     return $defaults;
 }
Пример #18
0
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @return array
  *   array of default values
  */
 public function setDefaultValues()
 {
     $defaults = array();
     // is it an edit operation ?
     if (isset($this->_fid)) {
         $params = array('id' => $this->_fid);
         $this->assign('fid', $this->_fid);
         CRM_Price_BAO_PriceField::retrieve($params, $defaults);
         $this->_sid = $defaults['price_set_id'];
         // if text, retrieve price
         if ($defaults['html_type'] == 'Text') {
             $isActive = $defaults['is_active'];
             $valueParams = array('price_field_id' => $this->_fid);
             CRM_Price_BAO_PriceFieldValue::retrieve($valueParams, $defaults);
             // fix the display of the monetary value, CRM-4038
             $defaults['price'] = CRM_Utils_Money::format($defaults['amount'], NULL, '%a');
             $defaults['is_active'] = $isActive;
         }
         if (!empty($defaults['active_on'])) {
             list($defaults['active_on'], $defaults['active_on_time']) = CRM_Utils_Date::setDateDefaults($defaults['active_on'], 'activityDateTime');
         }
         if (!empty($defaults['expire_on'])) {
             list($defaults['expire_on'], $defaults['expire_on_time']) = CRM_Utils_Date::setDateDefaults($defaults['expire_on'], 'activityDateTime');
         }
     } else {
         $defaults['is_active'] = 1;
         for ($i = 1; $i <= self::NUM_OPTION; $i++) {
             $defaults['option_status[' . $i . ']'] = 1;
             $defaults['option_weight[' . $i . ']'] = $i;
         }
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $fieldValues = array('price_set_id' => $this->_sid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_PriceField', $fieldValues);
         $defaults['options_per_line'] = 1;
         $defaults['is_display_amounts'] = 1;
     }
     $enabledComponents = CRM_Core_Component::getEnabledComponents();
     $eventComponentId = NULL;
     if (array_key_exists('CiviEvent', $enabledComponents)) {
         $eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
     }
     if (isset($this->_sid) && $this->_action == CRM_Core_Action::ADD) {
         $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'financial_type_id');
         $defaults['financial_type_id'] = $financialTypeId;
         for ($i = 1; $i <= self::NUM_OPTION; $i++) {
             $defaults['option_financial_type_id[' . $i . ']'] = $financialTypeId;
         }
     }
     return $defaults;
 }
Пример #19
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @param null
  * 
  * @return array   array of default values
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     $fieldDefaults = array();
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_CustomOption::retrieve($params, $defaults);
         $paramsField = array('id' => $this->_fid);
         CRM_Core_BAO_CustomField::retrieve($paramsField, $fieldDefaults);
         if ($fieldDefaults['html_type'] == 'CheckBox' || $fieldDefaults['html_type'] == 'Multi-Select' || $fieldDefaults['html_type'] == 'AdvMulti-Select') {
             $defaultCheckValues = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($fieldDefaults['default_value'], 1, -1));
             if (in_array($defaults['value'], $defaultCheckValues)) {
                 $defaults['default_value'] = 1;
             }
         } else {
             if (CRM_Utils_Array::value('default_value', $fieldDefaults) == CRM_Utils_Array::value('value', $defaults)) {
                 $defaults['default_value'] = 1;
             }
         }
     } else {
         $defaults['is_active'] = 1;
     }
     require_once 'CRM/Core/DAO.php';
     if ($this->_action & CRM_Core_Action::ADD) {
         $fieldValues = array('option_group_id' => $this->_optionGroupID);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
     }
     return $defaults;
 }
Пример #20
0
 /**
  * retrieve the default Label Format values
  *
  * @param string $groupName label format group name
  *
  * @return array   Name/value pairs containing the default Label Format values.
  * @static
  * @access public
  */
 static function &getDefaultValues($groupName = 'label_format')
 {
     $params = array('is_active' => 1, 'is_default' => 1);
     $defaults = array();
     if (!self::retrieve($params, $defaults, $groupName)) {
         foreach (self::$optionValueFields as $name => $field) {
             $defaults[$name] = $field['default'];
         }
         $filter = array('option_group_id' => self::_getGid($groupName));
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $filter);
     }
     return $defaults;
 }
Пример #21
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 function setDefaultValues()
 {
     $defaults = array();
     $showHide = new CRM_Core_ShowHideBlocks();
     if ($this->_action == CRM_Core_Action::ADD) {
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFJoin');
     }
     //id fetched for Dojo Pane
     $pId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     if (isset($pId)) {
         $this->_id = $pId;
     }
     if (isset($this->_id)) {
         $defaults['weight'] = CRM_Core_BAO_UFGroup::getWeight($this->_id);
         $params = array('id' => $this->_id);
         CRM_Core_BAO_UFGroup::retrieve($params, $defaults);
         $defaults['group'] = CRM_Utils_Array::value('limit_listings_group_id', $defaults);
         $defaults['add_contact_to_group'] = CRM_Utils_Array::value('add_to_group_id', $defaults);
         //get the uf join records for current uf group
         $ufJoinRecords = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_id);
         foreach ($ufJoinRecords as $key => $value) {
             $checked[$value] = 1;
         }
         $defaults['uf_group_type'] = isset($checked) ? $checked : "";
         //get the uf join records for current uf group other than default modules
         $otherModules = array();
         $otherModules = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_id, TRUE, TRUE);
         if (!empty($otherModules)) {
             $otherModuleString = NULL;
             foreach ($otherModules as $key) {
                 $otherModuleString .= " [ x ] <label>" . $key . "</label>";
             }
             $this->assign('otherModuleString', $otherModuleString);
         }
         $showAdvanced = 0;
         $advFields = array('group', 'post_URL', 'cancel_URL', 'add_captcha', 'is_map', 'is_uf_link', 'is_edit_link', 'is_update_dupe', 'is_cms_user', 'is_proximity_search');
         foreach ($advFields as $key) {
             if (!empty($defaults[$key])) {
                 $showAdvanced = 1;
                 $this->_allPanes['Advanced Settings']['open'] = 'true';
                 break;
             }
         }
     } else {
         $defaults['is_active'] = 1;
         $defaults['is_map'] = 0;
         $defaults['is_update_dupe'] = 0;
         $defaults['is_proximity_search'] = 0;
     }
     // Don't assign showHide elements to template in DELETE mode (fields to be shown and hidden don't exist)
     if (!($this->_action & CRM_Core_Action::DELETE) && !($this->_action & CRM_Core_Action::DISABLE)) {
         $showHide->addToTemplate();
     }
     $this->assign('allPanes', $this->_allPanes);
     return $defaults;
 }
Пример #22
0
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     // Default weight & value
     $fieldValues = array('option_group_id' => $this->_gid);
     foreach (array('weight', 'value') as $field) {
         if (empty($defaults[$field])) {
             $defaults[$field] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues, $field);
         }
     }
     //setDefault of contact types for email greeting, postal greeting, addressee, CRM-4575
     if (in_array($this->_gName, array('email_greeting', 'postal_greeting', 'addressee'))) {
         $defaults['contactOptions'] = CRM_Utils_Array::value('filter', $defaults) ? $defaults['filter'] : NULL;
     }
     // CRM-11516
     if ($this->_gName == 'payment_instrument' && $this->_id) {
         $defaults['financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($this->_id, 'civicrm_option_value', 'financial_account_id');
     }
     return $defaults;
 }
Пример #23
0
 /**
  * Add/edit option-value of a particular group
  *
  * @param array $params
  *   Array containing exported values from the invoking form.
  * @param array $groupParams
  *   Array containing group fields whose option-values is to retrieved/saved.
  * @param $action
  * @param int $optionValueID Has the id of the optionValue being edited, disabled ..etc.
  *   Has the id of the optionValue being edited, disabled ..etc.
  *
  * @return CRM_Core_DAO_OptionValue
  *
  */
 public static function addOptionValue(&$params, &$groupParams, &$action, &$optionValueID)
 {
     $ids = array();
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     // checking if the group name with the given id or name (in $groupParams) exists
     if (!empty($groupParams)) {
         $config = CRM_Core_Config::singleton();
         $groupParams['is_active'] = 1;
         $optionGroup = CRM_Core_BAO_OptionGroup::retrieve($groupParams, $defaults);
     }
     // if the corresponding group doesn't exist, create one, provided $groupParams has 'name' in it.
     if (!$optionGroup->id) {
         if ($groupParams['name']) {
             $newOptionGroup = CRM_Core_BAO_OptionGroup::add($groupParams, $defaults);
             $params['weight'] = 1;
             $optionGroupID = $newOptionGroup->id;
         }
     } else {
         $optionGroupID = $optionGroup->id;
         $oldWeight = NULL;
         if ($optionValueID) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $optionValueID, 'weight', 'id');
         }
         $fieldValues = array('option_group_id' => $optionGroupID);
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues);
     }
     $params['option_group_id'] = $optionGroupID;
     if ($action & CRM_Core_Action::ADD && empty($params['value'])) {
         $fieldValues = array('option_group_id' => $optionGroupID);
         // use the next available value
         /* CONVERT(value, DECIMAL) is used to convert varchar
            field 'value' to decimal->integer                    */
         $params['value'] = (int) CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues, 'CONVERT(value, DECIMAL)');
     }
     if (!$params['label'] && $params['name']) {
         $params['label'] = $params['name'];
     }
     // set name to label if it's not set - but *only* for ADD action (CRM-3522)
     if ($action & CRM_Core_Action::ADD && empty($params['name']) && $params['label']) {
         $params['name'] = $params['label'];
     }
     if ($action & CRM_Core_Action::UPDATE) {
         $ids['optionValue'] = $optionValueID;
     }
     $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
     return $optionValue;
 }
Пример #24
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @param null
  *
  * @return array    array of default values
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     // is it an edit operation ?
     if (isset($this->_fid)) {
         $params = array('id' => $this->_fid);
         $this->assign('fid', $this->_fid);
         CRM_Price_BAO_Field::retrieve($params, $defaults);
         $this->_sid = $defaults['price_set_id'];
         // if text, retrieve price
         if ($defaults['html_type'] == 'Text') {
             $valueParams = array('price_field_id' => $this->_fid);
             CRM_Price_BAO_FieldValue::retrieve($valueParams, $defaults);
             // fix the display of the monetary value, CRM-4038
             $defaults['price'] = CRM_Utils_Money::format($defaults['amount'], NULL, '%a');
         }
         if (CRM_Utils_Array::value('active_on', $defaults)) {
             list($defaults['active_on'], $defaults['active_on_time']) = CRM_Utils_Date::setDateDefaults($defaults['active_on'], 'activityDateTime');
         }
         if (CRM_Utils_Array::value('expire_on', $defaults)) {
             list($defaults['expire_on'], $defaults['expire_on_time']) = CRM_Utils_Date::setDateDefaults($defaults['expire_on'], 'activityDateTime');
         }
     } else {
         $defaults['is_active'] = 1;
         for ($i = 1; $i <= self::NUM_OPTION; $i++) {
             $defaults['option_status[' . $i . ']'] = 1;
             $defaults['option_weight[' . $i . ']'] = $i;
         }
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $fieldValues = array('price_set_id' => $this->_sid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_Field', $fieldValues);
         $defaults['options_per_line'] = 1;
         $defaults['is_display_amounts'] = 1;
     }
     return $defaults;
 }
Пример #25
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @param null
  * 
  * @return array    array of default values
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     // is it an edit operation ?
     if (isset($this->_fid)) {
         $params = array('id' => $this->_fid);
         $this->assign('id', $this->_fid);
         CRM_Price_BAO_Field::retrieve($params, $defaults);
         $this->_sid = $defaults['price_set_id'];
         // if text, retrieve price
         if ($defaults['html_type'] == 'Text') {
             $valueParams = array('price_field_id' => $this->_fid);
             require_once 'CRM/Price/BAO/FieldValue.php';
             CRM_Price_BAO_FieldValue::retrieve($valueParams, $defaults);
             // fix the display of the monetary value, CRM-4038
             require_once 'CRM/Utils/Money.php';
             $defaults['price'] = CRM_Utils_Money::format($defaults['amount'], null, '%a');
         }
     } else {
         $defaults['is_active'] = 1;
         for ($i = 1; $i <= self::NUM_OPTION; $i++) {
             $defaults['option_status[' . $i . ']'] = 1;
             $defaults['option_weight[' . $i . ']'] = $i;
         }
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         require_once 'CRM/Utils/Weight.php';
         $fieldValues = array('price_set_id' => $this->_sid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_Field', $fieldValues);
         $defaults['options_per_line'] = 1;
         $defaults['is_display_amounts'] = 1;
     }
     return $defaults;
 }
Пример #26
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_UFField::retrieve($params, $defaults);
         // set it to null if so (avoids crappy E_NOTICE errors below
         $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults);
         $specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'county', 'phone', 'email', 'im', 'address_name');
         if (!$defaults['location_type_id'] && in_array($defaults['field_name'], $specialFields)) {
             $defaults['location_type_id'] = 0;
         }
         $defaults['field_name'] = array($defaults['field_type'], $defaults['field_name'], $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults));
         $this->_gid = $defaults['uf_group_id'];
     } else {
         $defaults['is_active'] = 1;
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $fieldValues = array('uf_group_id' => $this->_gid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues);
     }
     // lets trim all the whitespace
     $this->applyFilter('__ALL__', 'trim');
     //hidden field to catch the group id in profile
     $this->add('hidden', 'group_id', $this->_gid);
     //hidden field to catch the field id in profile
     $this->add('hidden', 'field_id', $this->_id);
     $fields = array();
     $fields['Individual'] =& CRM_Contact_BAO_Contact::importableFields('Individual', false, false, true);
     $fields['Household'] =& CRM_Contact_BAO_Contact::importableFields('Household', false, false, true);
     $fields['Organization'] =& CRM_Contact_BAO_Contact::importableFields('Organization', false, false, true);
     // add current employer for individuals
     $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer'));
     // unset unwanted fields
     $unsetFieldArray = array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id');
     foreach ($unsetFieldArray as $value) {
         unset($fields['Individual'][$value]);
         unset($fields['Household'][$value]);
         unset($fields['Organization'][$value]);
     }
     require_once 'CRM/Core/BAO/Preferences.php';
     $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
     if (!$addressOptions['county']) {
         unset($fields['Individual']['county']);
         unset($fields['Household']['county']);
         unset($fields['Organization']['county']);
     }
     //build the common contact fields array CRM-3037.
     foreach ($fields['Individual'] as $key => $value) {
         if (CRM_Utils_Array::value($key, $fields['Household']) && CRM_Utils_Array::value($key, $fields['Organization'])) {
             $fields['Contact'][$key] = $value;
             //as we move common fields to contacts. There fore these fields
             //are unset from resoective array's.
             unset($fields['Individual'][$key]);
             unset($fields['Household'][$key]);
             unset($fields['Organization'][$key]);
         }
     }
     // add current employer for individuals
     $fields['Contact']['id'] = array('name' => 'id', 'title' => ts('Internal Contact ID'));
     unset($fields['Contact']['contact_type']);
     // since we need a hierarchical list to display contact types & subtypes,
     // this is what we going to display in first selector
     $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(false, false);
     unset($contactTypes['']);
     // include Subtypes For Profile
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $name => $val) {
         //custom fields for sub type
         $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name);
         if (array_key_exists($val['parent'], $fields)) {
             $fields[$name] = $fields[$val['parent']] + $subTypeFields;
         } else {
             $fields[$name] = $subTypeFields;
         }
     }
     unset($subTypes);
     if (CRM_Core_Permission::access('Quest')) {
         require_once 'CRM/Quest/BAO/Student.php';
         $fields['Student'] =& CRM_Quest_BAO_Student::exportableFields();
     }
     if (CRM_Core_Permission::access('CiviContribute')) {
         $contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields();
         if (!empty($contribFields)) {
             unset($contribFields['is_test']);
             unset($contribFields['is_pay_later']);
             unset($contribFields['contribution_id']);
             $fields['Contribution'] =& $contribFields;
         }
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         require_once 'CRM/Event/BAO/Query.php';
         $participantFields =& CRM_Event_BAO_Query::getParticipantFields(true);
         if (!empty($participantFields)) {
             unset($participantFields['external_identifier']);
             unset($participantFields['event_id']);
             unset($participantFields['participant_contact_id']);
             unset($participantFields['participant_is_test']);
             unset($participantFields['participant_fee_level']);
             unset($participantFields['participant_id']);
             unset($participantFields['participant_is_pay_later']);
             $fields['Participant'] =& $participantFields;
         }
     }
     if (CRM_Core_Permission::access('CiviMember')) {
         require_once 'CRM/Member/BAO/Membership.php';
         $membershipFields =& CRM_Member_BAO_Membership::getMembershipFields();
         unset($membershipFields['membership_id']);
         unset($membershipFields['join_date']);
         unset($membershipFields['membership_start_date']);
         unset($membershipFields['membership_type_id']);
         unset($membershipFields['membership_end_date']);
         unset($membershipFields['member_is_test']);
         unset($membershipFields['is_override']);
         unset($membershipFields['status_id']);
         unset($membershipFields['member_is_pay_later']);
         $fields['Membership'] =& $membershipFields;
     }
     $noSearchable = array();
     foreach ($fields as $key => $value) {
         foreach ($value as $key1 => $value1) {
             //CRM-2676, replacing the conflict for same custom field name from different custom group.
             require_once 'CRM/Core/BAO/CustomField.php';
             if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) {
                 $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id');
                 $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title');
                 $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName;
             } else {
                 $this->_mapperFields[$key][$key1] = $value1['title'];
             }
             $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1);
             // hide the 'is searchable' field for 'File' custom data
             if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) {
                 if (!in_array($value1['title'], $noSearchable)) {
                     $noSearchable[] = $value1['title'];
                 }
             }
         }
     }
     $this->assign('noSearchable', $noSearchable);
     require_once 'CRM/Core/BAO/LocationType.php';
     $this->_location_types =& CRM_Core_PseudoConstant::locationType();
     $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
     /* FIXME: dirty hack to make the default option show up first.  This
      * avoids a mozilla browser bug with defaults on dynamically constructed
      * selector widgets. */
     if ($defaultLocationType) {
         $defaultLocation = $this->_location_types[$defaultLocationType->id];
         unset($this->_location_types[$defaultLocationType->id]);
         $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types;
     }
     $this->_location_types = array('Primary') + $this->_location_types;
     $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
     $sel1 = array('' => '- select -') + $contactTypes;
     if (CRM_Core_Permission::access('Quest')) {
         $sel1['Student'] = 'Students';
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         $sel1['Participant'] = 'Participants';
     }
     if (!empty($contribFields)) {
         $sel1['Contribution'] = 'Contributions';
     }
     if (!empty($membershipFields)) {
         $sel1['Membership'] = 'Membership';
     }
     foreach ($sel1 as $key => $sel) {
         if ($key) {
             $sel2[$key] = $this->_mapperFields[$key];
         }
     }
     $sel3[''] = null;
     $phoneTypes = CRM_Core_PseudoConstant::phoneType();
     ksort($phoneTypes);
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             foreach ($this->_location_types as $key => $value) {
                 $sel4[$k]['phone'][$key] =& $phoneTypes;
             }
         }
     }
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             if (is_array($this->_mapperFields[$k])) {
                 foreach ($this->_mapperFields[$k] as $key => $value) {
                     if ($hasLocationTypes[$k][$key]) {
                         $sel3[$k][$key] = $this->_location_types;
                     } else {
                         $sel3[$key] = null;
                     }
                 }
             }
         }
     }
     $this->_defaults = array();
     $js = "<script type='text/javascript'>\n";
     $formName = "document.{$this->_name}";
     $alreadyMixProfile = false;
     if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
         $alreadyMixProfile = true;
     }
     $this->assign('alreadyMixProfile', $alreadyMixProfile);
     $attributes = array('onclick' => "showLabel();mixProfile();", 'onblur' => 'showLabel();mixProfile();');
     $sel =& $this->addElement('hierselect', "field_name", ts('Field Name'), $attributes);
     $formValues = array();
     $formValues = $this->exportValues();
     if (empty($formValues)) {
         for ($k = 1; $k < 4; $k++) {
             if (!$defaults['field_name'][$k]) {
                 $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
             }
         }
     } else {
         if (!empty($formValues['field_name'])) {
             foreach ($formValues['field_name'] as $value) {
                 for ($k = 1; $k < 4; $k++) {
                     if (!isset($formValues['field_name'][$k]) || !$formValues['field_name'][$k]) {
                         $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
                     } else {
                         $js .= "{$formName}['field_name[{$k}]'].style.display = '';\n";
                     }
                 }
             }
         } else {
             for ($k = 1; $k < 4; $k++) {
                 if (!isset($defaults['field_name'][$k])) {
                     $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
                 }
             }
         }
     }
     foreach ($sel2 as $k => $v) {
         if (is_array($sel2[$k])) {
             asort($sel2[$k]);
         }
     }
     $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
     $js .= "</script>\n";
     $this->assign('initHideBoxes', $js);
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true, array("onChange" => "showHideSeletorSearch(this.value);"));
     //CRM-4363
     $js = array('onclick' => "mixProfile();");
     // should the field appear in selectors (as a column)?
     $this->add('checkbox', 'in_selector', ts('Results Column?'), null, null, $js);
     $this->add('checkbox', 'is_searchable', ts('Searchable?'), null, null, $js);
     // weight
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'weight'), true);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'help_post'));
     // listings title
     $this->add('text', 'listings_title', ts('Listings Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'listings_title'));
     $this->addRule('listings_title', ts('Please enter a valid title for this field when displayed in user listings.'), 'title');
     $this->add('checkbox', 'is_required', ts('Required?'));
     $this->add('checkbox', 'is_active', ts('Active?'));
     $this->add('checkbox', 'is_view', ts('View Only?'));
     // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) );
     //$this->add( 'checkbox', 'is_match'       , ts( 'Key to Match Contacts?'        ) );
     $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'label'));
     $js = null;
     if ($this->_hasSearchableORInSelector) {
         $js = array('onclick' => "return verify( );");
     }
     // add buttons
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'"));
     }
     $this->setDefaults($defaults);
 }
Пример #27
0
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @return array|void  array of default values
  */
 public function setDefaultValues()
 {
     if ($this->_action == CRM_Core_Action::DELETE) {
         return NULL;
     }
     $defaults = array();
     if (isset($this->_oid)) {
         $params = array('id' => $this->_oid);
         CRM_Price_BAO_PriceFieldValue::retrieve($params, $defaults);
         // fix the display of the monetary value, CRM-4038
         $defaults['value'] = CRM_Utils_Money::format(CRM_Utils_Array::value('value', $defaults), NULL, '%a');
     }
     $memberComponentId = CRM_Core_Component::getComponentID('CiviMember');
     $extendComponentId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'extends', 'id');
     if (!isset($defaults['membership_num_terms']) && $memberComponentId == $extendComponentId) {
         $defaults['membership_num_terms'] = 1;
     }
     // set financial type used for price set to set default for new option
     if (!$this->_oid) {
         $defaults['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'financial_type_id', 'id');
     }
     if (!isset($defaults['weight']) || !$defaults['weight']) {
         $fieldValues = array('price_field_id' => $this->_fid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_PriceFieldValue', $fieldValues);
         $defaults['is_active'] = 1;
     }
     return $defaults;
 }
Пример #28
0
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return array
  *   array of default values
  */
 public function setDefaultValues()
 {
     $defaults =& $this->_defaults;
     $this->assign('showMaxMultiple', TRUE);
     if ($this->_action == CRM_Core_Action::ADD) {
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_CustomGroup');
         $defaults['is_multiple'] = $defaults['min_multiple'] = 0;
         $defaults['is_active'] = $defaults['collapse_display'] = 1;
         $defaults['style'] = 'Inline';
     } elseif (empty($defaults['max_multiple']) && !$this->_isGroupEmpty) {
         $this->assign('showMaxMultiple', FALSE);
     }
     if ($this->_action & CRM_Core_Action::UPDATE && !empty($defaults['is_multiple'])) {
         $defaults['collapse_display'] = 0;
     }
     if (isset($defaults['extends'])) {
         $extends = $defaults['extends'];
         unset($defaults['extends']);
         $defaults['extends'][0] = $extends;
         if (!empty($this->_subtypes)) {
             $defaults['extends'][1] = $this->_subtypes;
         } else {
             $defaults['extends'][1] = array(0 => '');
         }
         if ($extends == 'Relationship' && !empty($this->_subtypes)) {
             $relationshipDefaults = array();
             foreach ($defaults['extends'][1] as $donCare => $rel_type_id) {
                 $relationshipDefaults[] = $rel_type_id;
             }
             $defaults['extends'][1] = $relationshipDefaults;
         }
     }
     return $defaults;
 }
Пример #29
0
 /**
  * Get next available value.
  * We will take the highest numeric value (or 0 if no numeric values exist)
  * and add one. The calling function is responsible for any
  * more complex decision making
  *
  * @param array $params
  *
  * @return int
  */
 public static function getDefaultWeight($params)
 {
     return (int) CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $params['option_group_id']));
 }
Пример #30
0
 static function updateCiviACLRole(&$params, $op)
 {
     $optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'acl_role', 'id', 'name');
     $dao = new CRM_Core_DAO_OptionValue();
     $dao->option_group_id = $optionGroupID;
     $dao->description = $params['source'];
     if ($op == 'delete') {
         $dao->delete();
         return;
     }
     $dao->label = $params['title'];
     $dao->is_active = 1;
     $weightParams = array('option_group_id' => $optionGroupID);
     $dao->weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $weightParams);
     $dao->value = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $weightParams, 'value');
     $query = "\nSELECT v.id\n  FROM civicrm_option_value v\n WHERE v.option_group_id = %1\n   AND v.description     = %2\n";
     $queryParams = array(1 => array($optionGroupID, 'Integer'), 2 => array($params['source'], 'String'));
     $dao->id = CRM_Core_DAO::singleValueQuery($query, $queryParams);
     $dao->save();
     $params['acl_role_id'] = $dao->value;
 }