Example #1
0
 /**
  * @return array
  */
 public function checkOptionGroupValues()
 {
     $messages = array();
     $problemValues = array();
     $optionGroups = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'data_type' => array('IS NOT NULL' => 1), 'options' => array('limit' => 0)));
     if ($optionGroups['count'] > 0) {
         foreach ($optionGroups['values'] as $optionGroup) {
             $values = CRM_Core_BAO_OptionValue::getOptionValuesArray($optionGroup['id']);
             if (count($values) > 0) {
                 foreach ($values as $value) {
                     $validate = CRM_Utils_Type::validate($value['value'], $optionGroup['data_type'], FALSE);
                     if (!$validate) {
                         $problemValues[] = array('group_name' => $optionGroup['title'], 'value_name' => $value['label']);
                     }
                 }
             }
         }
     }
     if (!empty($problemValues)) {
         $strings = '';
         foreach ($problemValues as $problemValue) {
             $strings .= ts('<tr><td> "%1" </td><td> "%2" </td></tr>', array(1 => $problemValue['group_name'], 2 => $problemValue['value_name']));
         }
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('The Following Option Values contain value fields that do not match the Data Type of the Option Group</p>
     <p><table><tbody><th>Option Group</th><th>Option Value</th></tbody><tbody>') . $strings . ts('</tbody></table></p>'), ts('Option Values with problematic Values'), \Psr\Log\LogLevel::NOTICE, 'fa-server');
     }
     return $messages;
 }
 /**
  * Returns all active options ordered by weight for a given field
  *
  * @param  int      $fieldId         field whose options are needed
  * @param  boolean  $inactiveNeeded  do we need inactive options ?
  *
  * @return array $customOption all active options for fieldId
  * @static
  */
 static function getCustomOption($fieldID, $inactiveNeeded = FALSE)
 {
     $options = array();
     if (!$fieldID) {
         return $options;
     }
     $field = CRM_Core_BAO_CustomField::getFieldObject($fieldID);
     // get the option group id
     $optionGroupID = $field->option_group_id;
     if (!$optionGroupID) {
         return $options;
     }
     $optionValues = CRM_Core_BAO_OptionValue::getOptionValuesArray($optionGroupID);
     foreach ($optionValues as $id => $value) {
         if (!$inactiveNeeded && empty($value['is_active'])) {
             continue;
         }
         $options[$id] = array();
         $options[$id]['id'] = $id;
         $options[$id]['label'] = $value['label'];
         $options[$id]['value'] = $value['value'];
     }
     CRM_Utils_Hook::customFieldOptions($fieldID, $options, TRUE);
     return $options;
 }
Example #3
0
 public function onPreEnable(CRM_Extension_Info $info)
 {
     $customSearchesByName = $this->getCustomSearchesByName();
     $cs = $this->getCustomSearchesById();
     $id = $cs[$customSearchesByName[$info->key]];
     $optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 1);
 }
 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);
 }
Example #5
0
 /**
  * Ensure only one option value copes with disabled.
  *
  * (Our expectation is no change - ie. currently we are respecting 'someone's
  * decision to disable it & leaving it in that state.
  */
 public function testEnsureOptionValueExistsDisabled()
 {
     CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('name' => 'Crashed', 'option_group_id' => 'contribution_status', 'is_active' => 0));
     $value = $this->callAPISuccessGetSingle('OptionValue', array('name' => 'Crashed', 'option_group_id' => 'contribution_status'));
     $this->assertEquals(0, $value['is_active']);
     CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('name' => 'Crashed', 'option_group_id' => 'contribution_status'));
     $value = $this->callAPISuccessGetSingle('OptionValue', array('name' => 'Crashed', 'option_group_id' => 'contribution_status'));
     $this->assertEquals(0, $value['is_active']);
 }
/**
 * Deletes an existing OptionValue
 *
 * @param  array  $params
 *
 * {@example OptionValueDelete.php 0}
 *
 * @return array Api result
 * {@getfields OptionValue_create}
 * @access public
 */
function civicrm_api3_option_value_delete($params)
{
    // we will get the option group id before deleting so we can flush pseudoconstants
    $optionGroupID = civicrm_api('option_value', 'getvalue', array('version' => 3, 'id' => $params['id'], 'return' => 'option_group_id'));
    if (CRM_Core_BAO_OptionValue::del((int) $params['id'])) {
        civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $optionGroupID));
        return civicrm_api3_create_success();
    } else {
        civicrm_api3_create_error('Could not delete OptionValue ' . $params['id']);
    }
}
Example #7
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     //get the activity values
     $activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     //check for required permissions, CRM-6264
     if ($activityId && !CRM_Activity_BAO_Activity::checkPermission($activityId, CRM_Core_Action::VIEW)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     $session = CRM_Core_Session::singleton();
     if (!in_array($context, array('home', 'dashlet', 'dashletFullscreen'))) {
         $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity");
     } else {
         $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
     }
     $session->pushUserContext($url);
     $defaults = array();
     $params = array('id' => $activityId);
     CRM_Activity_BAO_Activity::retrieve($params, $defaults);
     //set activity type name and description to template
     list($activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($defaults['activity_type_id']);
     $this->assign('activityTypeName', $activityTypeName);
     $this->assign('activityTypeDescription', $activityTypeDescription);
     if (CRM_Utils_Array::value('mailingId', $defaults)) {
         $this->_mailing_id = CRM_Utils_Array::value('source_record_id', $defaults);
         $mailingReport = CRM_Mailing_BAO_Mailing::report($this->_mailing_id, TRUE);
         CRM_Mailing_BAO_Mailing::getMailingContent($mailingReport, $this);
         $this->assign('mailingReport', $mailingReport);
         $full_open_report = CRM_Mailing_Event_BAO_Opened::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, $cid);
         $this->assign('openreport', $full_open_report);
         $click_thru_report = CRM_Mailing_Event_BAO_TrackableURLOpen::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, NULL, $cid);
         $this->assign('clickreport', $click_thru_report);
     }
     foreach ($defaults as $key => $value) {
         if (substr($key, -3) != '_id') {
             $values[$key] = $value;
         }
     }
     //get the campaign
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $defaults)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     if ($engagementLevel = CRM_Utils_Array::value('engagement_level', $defaults)) {
         $engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel();
         $values['engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel);
     }
     $values['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityId);
     $this->assign('values', $values);
 }
Example #8
0
 function buildQuickForm()
 {
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_hours_type', 'id', 'name');
     $optionGroupIds = CRM_Core_BAO_OptionValue::getOptionValuesArray($optionGroupId);
     foreach ($optionGroupIds as $key => $value) {
         $this->_optionValue[$value['value']] = $value['label'];
         $this->_id[$key] = $value['value'];
     }
     $this->assign('optionGroupIds', $optionGroupIds);
     $this->addElement('select', 'hour_type_select', ts('Select Hour Type'), array('' => ts('- select -')) + $this->_optionValue);
     $this->add('text', 'hour_value', ts('Value'));
     $this->addFormRule(array('CRM_Hrjobcontract_Form_EditHourOption', 'formRule'), $this);
 }
/**
 * Implementation of hook_civicrm_disable
 */
function clickatell_civicrm_disable()
{
    $optionID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', 'clickatell', 'id', 'name');
    if ($optionID) {
        CRM_Core_BAO_OptionValue::setIsActive($optionID, FALSE);
    }
    $filter = array('name' => 'org.civicrm.sms.clickatell');
    $Providers = CRM_SMS_BAO_Provider::getProviders(False, $filter, False);
    if ($Providers) {
        foreach ($Providers as $key => $value) {
            CRM_SMS_BAO_Provider::setIsActive($value['id'], FALSE);
        }
    }
    return _clickatell_civix_civicrm_disable();
}
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     //get the activity values
     $activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     //check for required permissions, CRM-6264
     if ($activityId && !CRM_Activity_BAO_Activity::checkPermission($activityId, CRM_Core_Action::VIEW)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     $session = CRM_Core_Session::singleton();
     if ($context != 'home') {
         $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity");
     } else {
         $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
     }
     $session->pushUserContext($url);
     $params = array('id' => $activityId);
     CRM_Activity_BAO_Activity::retrieve($params, $defaults);
     //set activity type name and description to template
     require_once 'CRM/Core/BAO/OptionValue.php';
     list($activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($defaults['activity_type_id']);
     $this->assign('activityTypeName', $activityTypeName);
     $this->assign('activityTypeDescription', $activityTypeDescription);
     if (CRM_Utils_Array::value('mailingId', $defaults)) {
         $this->_mailing_id = CRM_Utils_Array::value('source_record_id', $defaults);
         require_once 'CRM/Mailing/BAO/Mailing.php';
         $mailingReport =& CRM_Mailing_BAO_Mailing::report($this->_mailing_id, true);
         CRM_Mailing_BAO_Mailing::getMailingContent($mailingReport, $this);
         $this->assign('mailingReport', $mailingReport);
     }
     foreach ($defaults as $key => $value) {
         if (substr($key, -3) != '_id') {
             $values[$key] = $value;
         }
     }
     require_once 'CRM/Core/BAO/File.php';
     $values['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityId);
     $this->assign('values', $values);
 }
 /**
  * Process the form submission.
  *
  * @param array $params
  * @param string $type
  * @param array $linkedEntities
  *
  * @throws \CiviCRM_API3_Exception
  */
 public static function postProcess($params = array(), $type, $linkedEntities = array())
 {
     //Check entity_id not present in params take it from class variable
     if (empty($params['entity_id'])) {
         $params['entity_id'] = self::$_entityId;
     }
     //Process this function only when you get this variable
     if ($params['allowRepeatConfigToSubmit'] == 1) {
         if (!empty($params['entity_table']) && !empty($params['entity_id']) && $type) {
             $params['used_for'] = $type;
             if (empty($params['parent_entity_id'])) {
                 $params['parent_entity_id'] = self::$_parentEntityId;
             }
             if (!empty($params['schedule_reminder_id'])) {
                 $params['id'] = $params['schedule_reminder_id'];
             } else {
                 $params['id'] = self::$_scheduleReminderID;
             }
             //Save post params to the schedule reminder table
             $recurobj = new CRM_Core_BAO_RecurringEntity();
             $dbParams = $recurobj->mapFormValuesToDB($params);
             //Delete repeat configuration and rebuild
             if (!empty($params['id'])) {
                 CRM_Core_BAO_ActionSchedule::del($params['id']);
                 unset($params['id']);
             }
             $actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams);
             //exclude dates
             $excludeDateList = array();
             if (CRM_Utils_Array::value('exclude_date_list', $params) && CRM_Utils_Array::value('parent_entity_id', $params) && $actionScheduleObj->entity_value) {
                 //Since we get comma separated values lets get them in array
                 $excludeDates = explode(",", $params['exclude_date_list']);
                 //Check if there exists any values for this option group
                 $optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $type . '_repeat_exclude_dates_' . $params['parent_entity_id'], 'id', 'name');
                 if ($optionGroupIdExists) {
                     CRM_Core_BAO_OptionGroup::del($optionGroupIdExists);
                 }
                 $optionGroupParams = array('name' => $type . '_repeat_exclude_dates_' . $actionScheduleObj->entity_value, 'title' => $type . ' recursion', 'is_reserved' => 0, 'is_active' => 1);
                 $opGroup = CRM_Core_BAO_OptionGroup::add($optionGroupParams);
                 if ($opGroup->id) {
                     $oldWeight = 0;
                     $fieldValues = array('option_group_id' => $opGroup->id);
                     foreach ($excludeDates as $val) {
                         $optionGroupValue = array('option_group_id' => $opGroup->id, 'label' => CRM_Utils_Date::processDate($val), 'value' => CRM_Utils_Date::processDate($val), 'name' => $opGroup->name, 'description' => 'Used for recurring ' . $type, 'weight' => CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues), 'is_active' => 1);
                         $excludeDateList[] = $optionGroupValue['value'];
                         CRM_Core_BAO_OptionValue::create($optionGroupValue);
                     }
                 }
             }
             //Set type for API
             $apiEntityType = explode("_", $type);
             if (!empty($apiEntityType[1])) {
                 $apiType = $apiEntityType[1];
             }
             //Delete relations if any from recurring entity tables before inserting new relations for this entity id
             if ($params['entity_id']) {
                 //If entity has any pre delete function, consider that first
                 if (CRM_Utils_Array::value('pre_delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
                     $preDeleteResult = call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func'], array($params['entity_id']));
                     if (!empty($preDeleteResult)) {
                         call_user_func(array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'], $preDeleteResult));
                     }
                 }
                 //Ready to execute delete on entities if it has delete function set
                 if (CRM_Utils_Array::value('delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
                     //Check if pre delete function has some ids to be deleted
                     if (!empty(CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted)) {
                         foreach (CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted as $eid) {
                             $result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $eid));
                             if ($result['error']) {
                                 CRM_Core_Error::statusBounce('Error creating recurring list');
                             }
                         }
                     } else {
                         $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table'], FALSE);
                         foreach ($getRelatedEntities as $key => $value) {
                             $result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $value['id']));
                             if ($result['error']) {
                                 CRM_Core_Error::statusBounce('Error creating recurring list');
                             }
                         }
                     }
                 }
                 // find all entities from the recurring set. At this point we 'll get entities which were not deleted
                 // for e.g due to participants being present. We need to delete them from recurring tables anyway.
                 $pRepeatingEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table']);
                 foreach ($pRepeatingEntities as $val) {
                     CRM_Core_BAO_RecurringEntity::delEntity($val['id'], $val['table'], TRUE);
                 }
             }
             $recursion = new CRM_Core_BAO_RecurringEntity();
             $recursion->dateColumns = $params['dateColumns'];
             $recursion->scheduleId = $actionScheduleObj->id;
             if (!empty($excludeDateList)) {
                 $recursion->excludeDates = $excludeDateList;
                 $recursion->excludeDateRangeColumns = $params['excludeDateRangeColumns'];
             }
             if (!empty($params['intervalDateColumns'])) {
                 $recursion->intervalDateColumns = $params['intervalDateColumns'];
             }
             $recursion->entity_id = $params['entity_id'];
             $recursion->entity_table = $params['entity_table'];
             if (!empty($linkedEntities)) {
                 $recursion->linkedEntities = $linkedEntities;
             }
             $recursion->generate();
             $status = ts('Repeat Configuration has been saved');
             CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
         }
     }
 }
Example #12
0
 /**
  * @param string $objectName
  *   Business-entity/xml-tag name.
  * @param CRM_Core_DAO $object
  * @param $mappedFields
  *
  * @return array
  */
 public function exportDAO($objectName, $object, $mappedFields)
 {
     $dbFields =& $object->fields();
     // Filter the list of keys and values so that we only export interesting stuff
     $keyValues = array();
     foreach ($dbFields as $name => $dontCare) {
         // ignore all ids
         if ($name == 'id' || substr($name, -3, 3) == '_id') {
             continue;
         }
         if (isset($object->{$name}) && $object->{$name} !== NULL) {
             // hack for extends_entity_column_value
             if ($name == 'extends_entity_column_value') {
                 if (in_array($object->extends, array('Event', 'Activity', 'Relationship', 'Individual', 'Organization', 'Household', 'Case'))) {
                     if ($object->extends == 'Event') {
                         $key = 'event_type';
                     } elseif ($object->extends == 'Activity') {
                         $key = 'activity_type';
                     } elseif ($object->extends == 'Relationship') {
                         $key = 'relationship_type';
                     } elseif ($object->extends == 'Case') {
                         $key = 'case_type';
                     }
                     $types = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($object->{$name}, 1, -1));
                     $values = array();
                     if (in_array($object->extends, array('Individual', 'Organization', 'Household'))) {
                         $key = 'contact_type';
                         $values = $types;
                     } else {
                         foreach ($types as $type) {
                             if (in_array($key, array('activity_type', 'event_type', 'case_type'))) {
                                 $ogID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $key, 'id', 'name');
                                 $ovParams = array('option_group_id' => $ogID, 'value' => $type);
                                 CRM_Core_BAO_OptionValue::retrieve($ovParams, $oValue);
                                 $values[] = $oValue['name'];
                             } else {
                                 $relTypeName = CRM_Core_DAO::getFieldValue('CRM_Contact_BAO_RelationshipType', $type, 'name_a_b', 'id');
                                 $values[] = $relTypeName;
                             }
                         }
                     }
                     $keyValues['extends_entity_column_value_option_group'] = $key;
                     $value = implode(',', $values);
                     $object->extends_entity_column_value = $value;
                 } else {
                     echo "This extension: {$object->extends} is not yet handled";
                     exit;
                 }
             }
             $value = $object->{$name};
             if ($name == 'field_name') {
                 // hack for profile field_name
                 if (substr($value, 0, 7) == 'custom_') {
                     $cfID = substr($value, 7);
                     list($tableName, $columnName, $groupID) = CRM_Core_BAO_CustomField::getTableColumnGroup($cfID);
                     $value = "custom.{$tableName}.{$columnName}";
                 }
             }
             $keyValues[$name] = $value;
         }
     }
     $keyValues += $this->computeMappedFields($mappedFields, $object);
     return $keyValues;
 }
Example #13
0
 /**
  * This function preserve the civicrm_domain.email_name and civicrm_domain.email_address
  * as a default option value into "from_email_address" option group
  * and drop these columns from civicrm_domain table.
  * @access public
  *
  * @return void
  */
 function upgradeDomainFromEmail()
 {
     $query = "\nSELECT id\n  FROM civicrm_option_group\n WHERE name = 'from_Email_address'";
     $fmaGroup = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     $fmaGroupId = NULL;
     if ($fmaGroup->fetch()) {
         $fmaGroupId = $fmaGroup->id;
     } else {
         //insert 'from_mailing_address' option group.
         $query = "\nINSERT INTO civicrm_option_group ( name, description, is_reserved, is_active )\nVALUES ('from_email_address', 'From Email Address', 0, 1)";
         CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
         //get the group id.
         $query = "\nSELECT id\n  FROM civicrm_option_group\n WHERE name = 'from_email_address'";
         $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
         if ($dao->fetch()) {
             $fmaGroupId = $dao->id;
         }
     }
     if ($fmaGroupId) {
         //get domain from email address and name as default value.
         $domain = CRM_Core_BAO_Domain::getDomain();
         $domain->selectAdd();
         $domain->selectAdd('email_name', 'email_address');
         $domain->find(TRUE);
         $formEmailAddress = '"' . $domain->email_name . '"<' . $domain->email_address . '>';
         //first check given domain email address exist in option
         //value, if yes make it as domain email address by making
         //it as default from email address..
         //get the existing from email address.
         $optionValues = array();
         $grpParams['name'] = 'from_email_address';
         CRM_Core_OptionValue::getValues($grpParams, $optionValues);
         $maxVal = $maxWt = 1;
         $insertEmailAddress = TRUE;
         if (!empty($optionValues)) {
             //make existing is_default = 0
             $query = "\nUPDATE  civicrm_option_value\n   SET  is_default = 0\n WHERE  option_group_id = %1";
             $params = array(1 => array($fmaGroupId, 'Integer'));
             CRM_Core_DAO::executeQuery($query, $params);
             //if domain from name and email exist as name or label in option value
             //table need to preserve that name and label  and take care that label
             //and name both remain unique in db.
             $labelValues = $nameValues = array();
             foreach ($optionValues as $id => $value) {
                 if ($value['label'] == $formEmailAddress) {
                     $labelValues = $value;
                 } elseif ($value['name'] == $formEmailAddress) {
                     $nameValues = $value;
                 }
             }
             //as we consider label so label should preserve.
             $updateValues = array();
             if (!empty($labelValues)) {
                 $updateValues = $labelValues;
             }
             //if matching name found need to preserve it.
             if (!empty($nameValues)) {
                 //copy domain from email address as label.
                 if (empty($updateValues)) {
                     $updateValues = $nameValues;
                     $updateValues['label'] = $formEmailAddress;
                 } else {
                     //since name is also imp so preserve it
                     //as name for domain email address record.
                     $updateValues['name'] = $nameValues['name'];
                     //name is unique so drop name value record.
                     //since we transfer this name to found label record.
                     CRM_Core_BAO_OptionValue::del($nameValues['id']);
                 }
             }
             if (!empty($updateValues)) {
                 $insertEmailAddress = FALSE;
                 //update label/name found record w/ manupulated values.
                 $updateValues['is_active'] = $updateValues['is_default'] = 1;
                 $optionValue = new CRM_Core_DAO_OptionValue();
                 $optionValue->copyValues($updateValues);
                 $optionValue->save();
             }
             //get the max value and wt.
             if ($insertEmailAddress) {
                 $query = "\nSELECT   max(ROUND(civicrm_option_value.value)) as maxVal,\n         max(civicrm_option_value.weight) as maxWt\n    FROM civicrm_option_value, civicrm_option_group\n   WHERE civicrm_option_group.name = 'from_Email_address'\n     AND civicrm_option_value.option_group_id = civicrm_option_group.id\nGROUP BY civicrm_option_group.id";
                 $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
                 if ($dao->fetch()) {
                     $maxWt += $dao->maxWt;
                     $maxVal += $dao->maxVal;
                 }
             }
         }
         if ($insertEmailAddress) {
             //insert domain from email address and name.
             $query = "\nINSERT INTO  `civicrm_option_value`\n             (`option_group_id`, `label`, `value`, `name` , `grouping`, `filter`, `is_default`,\n              `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`)\n     VALUES  ( %1, %2, %3, %2, NULL, 0, 1, %4, 'Default domain email address and from name.', 0, 0, 1, NULL)";
             $params = array(1 => array($fmaGroupId, 'Integer'), 2 => array($formEmailAddress, 'String'), 3 => array($maxVal, 'Integer'), 4 => array($maxWt, 'Integer'));
             CRM_Core_DAO::executeQuery($query, $params);
         }
         //drop civicrm_domain.email_name and
         //civicrm_domain.email_address.
         $query = "\nALTER TABLE `civicrm_domain`\n       DROP `email_name`,\n       DROP `email_address`";
         CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     }
 }
Example #14
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
  */
 public static function getDefaultValue($params)
 {
     $bao = new CRM_Core_BAO_OptionValue();
     $bao->option_group_id = $params['option_group_id'];
     if (isset($params['domain_id'])) {
         $bao->domain_id = $params['domain_id'];
     }
     $bao->selectAdd();
     $bao->whereAdd("value REGEXP '^[0-9]+\$'");
     $bao->selectAdd('(ROUND(COALESCE(MAX(CONVERT(value, UNSIGNED)),0)) +1) as nextvalue');
     $bao->find(TRUE);
     return $bao->nextvalue;
 }
 /**
  * check method getInstrumentFinancialAccount()
  */
 function testGetInstrumentFinancialAccount()
 {
     $paymentInstrumentValue = 1;
     $params = array('name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1);
     $ids = array();
     $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
     $optionParams = array('name' => 'Credit Card', 'value' => $paymentInstrumentValue);
     $optionValue = CRM_Core_BAO_OptionValue::retrieve($optionParams, $defaults);
     $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
     $financialParams = array('entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $financialAccount->id);
     CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, $ids);
     $financialAccountId = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($paymentInstrumentValue);
     $this->assertEquals($financialAccountId, $financialAccount->id, 'Verify Payment Instrument');
 }
/**
 * Deletes an existing OptionValue
 *
 * @param  array  $params
 *
 * {@example OptionValueDelete.php 0}
 *
 * @return array Api result
 * {@getfields OptionValue_create}
 * @access public
 */
function civicrm_api3_option_value_delete($params)
{
    return CRM_Core_BAO_OptionValue::del((int) $params['id']) ? civicrm_api3_create_success() : civicrm_api3_create_error('Could not delete OptionValue ' . $params['id']);
}
Example #17
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action == CRM_Core_Action::VIEW) {
         return;
     }
     $this->_params = $this->controller->exportValues($this->_name);
     if (!empty($this->_params['contact_edit_preferences'])) {
         $preferenceWeights = explode(',', $this->_params['contact_edit_preferences']);
         foreach ($preferenceWeights as $key => $val) {
             if (!$val) {
                 unset($preferenceWeights[$key]);
             }
         }
         $opGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'contact_edit_options', 'id', 'name');
         CRM_Core_BAO_OptionValue::updateOptionWeights($opGroupId, array_flip($preferenceWeights));
     }
     $config = CRM_Core_Config::singleton();
     if ($config->userSystem->is_drupal == '1' && module_exists("wysiwyg")) {
         variable_set('civicrm_wysiwyg_input_format', $this->_params['wysiwyg_input_format']);
     }
     $this->_config->editor_id = $this->_params['editor_id'];
     // set default editor to session if changed
     $session = CRM_Core_Session::singleton();
     $session->set('defaultWysiwygEditor', $this->_params['editor_id']);
     $this->postProcessCommon();
 }
Example #18
0
 /**
  * CRM-17951 Add accounts option values for refund and chargeback.
  *
  * Add Chargeback contribution status and Chargeback and Contra account relationships,
  * checking first if one exists.
  */
 public function addRefundAndChargeBackAccountsIfNotExist()
 {
     // First we enable and edit the record for Credit contra - this exists but is disabled for most sites.
     // Using the ensure function (below) will not enabled a disabled option (by design).
     CRM_Core_DAO::executeQuery("UPDATE civicrm_option_value v\n     INNER JOIN civicrm_option_group g on v.option_group_id=g.id and g.name='account_relationship'\n     SET v.is_active=1, v.label='Credit/Contra Revenue Account is', v.name='Credit/Contra Revenue Account is', v.description='Credit/Contra Revenue Account is'\n     WHERE v.name = 'Credit/Contra Account is';");
     CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('option_group_id' => 'account_relationship', 'name' => 'Chargeback Account is', 'label' => ts('Chargeback Account is'), 'is_active' => TRUE, 'component_id' => 'CiviContribute'));
     CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('option_group_id' => 'contribution_status', 'name' => 'Chargeback', 'label' => ts('Chargeback'), 'is_active' => TRUE, 'component_id' => 'CiviContribute'));
     return TRUE;
 }
Example #19
0
 /**
  * @param CRM_Core_Form $form
  */
 public static function basic(&$form)
 {
     $form->addElement('hidden', 'hidden_basic', 1);
     if ($form->_searchOptions['contactType']) {
         // add checkboxes for contact type
         //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
         // this is loaded onto then replace with something like '__' & test
         $separator = CRM_Core_DAO::VALUE_SEPARATOR;
         $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, $separator);
         if ($contactTypes) {
             $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;'));
         }
     }
     if ($form->_searchOptions['groups']) {
         // multiselect for groups
         if ($form->_group) {
             // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title)
             $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($form->_group, NULL, '&nbsp;&nbsp;', TRUE);
             $form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2'));
             $groupOptions = CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('group_type');
             $form->add('select', 'group_type', ts('Group Types'), $groupOptions, FALSE, array('id' => 'group_type', 'multiple' => 'multiple', 'class' => 'crm-select2'));
             $form->add('hidden', 'group_search_selected', 'group');
         }
     }
     if ($form->_searchOptions['tags']) {
         // multiselect for categories
         $contactTags = CRM_Core_BAO_Tag::getTags();
         if ($contactTags) {
             $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;'));
         }
         $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
         CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE);
         $used_for = CRM_Core_OptionGroup::values('tag_used_for');
         $tagsTypes = array();
         $showAllTagTypes = FALSE;
         foreach ($used_for as $key => $value) {
             //check tags for every type and find if there are any defined
             $tags = CRM_Core_BAO_Tag::getTagsUsedFor($key, FALSE, TRUE, NULL);
             // check if there are tags other than contact type, if no - keep checkbox hidden on adv search
             // we will hide searching contact by attachments tags until it will be implemented in core
             if (count($tags) && $key != 'civicrm_file' && $key != 'civicrm_contact') {
                 //if tags exists then add type to display in adv search form help text
                 $tagsTypes[] = ts($value);
                 $showAllTagTypes = TRUE;
             }
         }
         $tagTypesText = implode(" or ", $tagsTypes);
         if ($showAllTagTypes) {
             $form->add('checkbox', 'all_tag_types', ts('Include tags used for %1', array(1 => $tagTypesText)));
             $form->add('hidden', 'tag_types_text', $tagTypesText);
         }
     }
     // add text box for last name, first name, street name, city
     $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     // add text box for last name, first name, street name, city
     $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
     //added contact source
     $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'contact_source'));
     //added job title
     $form->addElement('text', 'job_title', ts('Job Title'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'job_title'));
     //added internal ID
     $form->addElement('text', 'contact_id', ts('Contact ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'id'));
     $form->addRule('contact_id', ts('Please enter valid Contact ID'), 'positiveInteger');
     //added external ID
     $form->addElement('text', 'external_identifier', ts('External ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'));
     if (CRM_Core_Permission::check('access deleted contacts') and CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_undelete', NULL)) {
         $form->add('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
     }
     // add checkbox for cms users only
     $form->addYesNo('uf_user', ts('CMS User?'), TRUE);
     // tag all search
     $form->add('text', 'tag_search', ts('All Tags'));
     // add search profiles
     // FIXME: This is probably a part of profiles - need to be
     // FIXME: eradicated from here when profiles are reworked.
     $types = array('Participant', 'Contribution', 'Membership');
     // get component profiles
     $componentProfiles = array();
     $componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types);
     $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1);
     $accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW);
     $searchProfiles = array();
     foreach ($ufGroups as $key => $var) {
         if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
             $searchProfiles[$key] = $var['title'];
         }
     }
     $form->add('select', 'uf_group_id', ts('Search Views'), array('0' => ts('- default view -')) + $searchProfiles, FALSE, array('class' => 'crm-select2'));
     $componentModes = CRM_Contact_Form_Search::getModeSelect();
     // unset contributions or participants if user does not have
     // permission on them
     if (!CRM_Core_Permission::access('CiviContribute')) {
         unset($componentModes['2']);
     }
     if (!CRM_Core_Permission::access('CiviEvent')) {
         unset($componentModes['3']);
     }
     if (!CRM_Core_Permission::access('CiviMember')) {
         unset($componentModes['5']);
     }
     if (!CRM_Core_Permission::check('view all activities')) {
         unset($componentModes['4']);
     }
     if (count($componentModes) > 1) {
         $form->add('select', 'component_mode', ts('Display Results As'), $componentModes, FALSE, array('class' => 'crm-select2'));
     }
     $form->addRadio('operator', ts('Search Operator'), array('AND' => ts('AND'), 'OR' => ts('OR')), array('allowClear' => FALSE));
     // add the option to display relationships
     $rTypes = CRM_Core_PseudoConstant::relationshipType();
     $rSelect = array('' => ts('- Select Relationship Type-'));
     foreach ($rTypes as $rid => $rValue) {
         if ($rValue['label_a_b'] == $rValue['label_b_a']) {
             $rSelect[$rid] = $rValue['label_a_b'];
         } else {
             $rSelect["{$rid}_a_b"] = $rValue['label_a_b'];
             $rSelect["{$rid}_b_a"] = $rValue['label_b_a'];
         }
     }
     $form->addElement('select', 'display_relationship_type', ts('Display Results as Relationship'), $rSelect, array('class' => 'crm-select2'));
     // checkboxes for DO NOT phone, email, mail
     // we take labels from SelectValues
     $t = CRM_Core_SelectValues::privacy();
     $form->add('select', 'privacy_options', ts('Privacy'), $t, FALSE, array('id' => 'privacy_options', 'multiple' => 'multiple', 'class' => 'crm-select2'));
     $form->addElement('select', 'privacy_operator', ts('Operator'), array('OR' => ts('OR'), 'AND' => ts('AND')));
     $options = array(1 => ts('Exclude'), 2 => ts('Include by Privacy Option(s)'));
     $form->addRadio('privacy_toggle', ts('Privacy Options'), $options, array('allowClear' => FALSE));
     // preferred communication method
     $comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
     $commPreff = array();
     foreach ($comm as $k => $v) {
         $commPreff[] = $form->createElement('advcheckbox', $k, NULL, $v);
     }
     $onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, '');
     $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold'));
     $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method'));
     //CRM-6138 Preferred Language
     $form->addSelect('preferred_language', array('class' => 'twenty', 'context' => 'search'));
     // Phone search
     $form->addElement('text', 'phone_numeric', ts('Phone Number'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'));
     $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $phoneType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
     $form->add('select', 'phone_location_type_id', ts('Phone Location'), array('' => ts('- any -')) + $locationType, FALSE, array('class' => 'crm-select2'));
     $form->add('select', 'phone_phone_type_id', ts('Phone Type'), array('' => ts('- any -')) + $phoneType, FALSE, array('class' => 'crm-select2'));
 }
Example #20
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_gid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             if ($this->_gName == 'phone_type') {
                 CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues));
             }
             CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_gLabel)), ts('Record Deleted'), 'success');
         } else {
             CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_gLabel)), ts('Sorry'), 'error');
             CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
         }
     } else {
         $params = $ids = array();
         $params = $this->exportValues();
         // allow multiple defaults within group.
         $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address');
         if (in_array($this->_gName, $allowMultiDefaults)) {
             if ($this->_gName == 'from_email_address') {
                 $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
             } elseif ($filter = CRM_Utils_Array::value('contactOptions', $params)) {
                 $params['filter'] = $filter;
                 $params['reset_default_for'] = array('filter' => "0, " . $params['filter']);
             }
             //make sure we should has to have space, CRM-6977
             if ($this->_gName == 'from_email_address') {
                 $params['label'] = str_replace('"<', '" <', $params['label']);
             }
         }
         // set value of filter if not present in params
         if ($this->_id && !array_key_exists('filter', $params)) {
             if ($this->_gName == 'participant_role') {
                 $params['filter'] = 0;
             } else {
                 $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id');
             }
         }
         $groupParams = array('name' => $this->_gName);
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         // CRM-11516
         if (!empty($params['financial_account_id'])) {
             $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
             $params = array('entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $params['financial_account_id']);
             CRM_Financial_BAO_FinancialTypeAccount::add($params);
         }
         CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_gLabel, 2 => $optionValue->label)), ts('Saved'), 'success');
     }
 }
Example #21
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;
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             CRM_Core_Session::setStatus(ts('Selected %1 Report has been deleted.', array(1 => $this->_GName)));
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/report/options/report_template', "reset=1"));
         } else {
             CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName)));
             CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
         }
     } else {
         // get the submitted form values.
         $params = $this->controller->exportValues($this->_name);
         $ids = array();
         $groupParams = array('name' => 'report_template');
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => 'Report Template', 2 => $optionValue->label)));
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/report/options/report_template', "reset=1"));
     }
 }
 protected function getContributionStatus()
 {
     return array('' => ts('-- please select --')) + CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('contribution_status');
 }
Example #24
0
 /**
  * @param $rev
  */
 public function upgrade_4_4_1($rev)
 {
     $config = CRM_Core_Config::singleton();
     // CRM-13327 upgrade handling for the newly added name badges
     $ogID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'name_badge', 'id', 'name');
     $nameBadges = array_flip(array_values(CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('name_badge')));
     unset($nameBadges['Avery 5395']);
     if (!empty($nameBadges)) {
         $dimension = '{"paper-size":"a4","orientation":"portrait","font-name":"times","font-size":6,"font-style":"","NX":2,"NY":4,"metric":"mm","lMargin":6,"tMargin":19,"SpaceX":0,"SpaceY":0,"width":100,"height":65,"lPadding":0,"tPadding":0}';
         $query = "UPDATE civicrm_option_value\n        SET value = '{$dimension}'\n        WHERE option_group_id = %1 AND name = 'Fattorini Name Badge 100x65'";
         CRM_Core_DAO::executeQuery($query, array(1 => array($ogID, 'Integer')));
     } else {
         $dimensions = array(1 => '{"paper-size":"a4","orientation":"landscape","font-name":"times","font-size":6,"font-style":"","NX":2,"NY":1,"metric":"mm","lMargin":25,"tMargin":27,"SpaceX":0,"SpaceY":35,"width":106,"height":150,"lPadding":5,"tPadding":5}', 2 => '{"paper-size":"a4","orientation":"portrait","font-name":"times","font-size":6,"font-style":"","NX":2,"NY":4,"metric":"mm","lMargin":6,"tMargin":19,"SpaceX":0,"SpaceY":0,"width":100,"height":65,"lPadding":0,"tPadding":0}', 3 => '{"paper-size":"a4","orientation":"portrait","font-name":"times","font-size":6,"font-style":"","NX":2,"NY":2,"metric":"mm","lMargin":10,"tMargin":28,"SpaceX":0,"SpaceY":0,"width":96,"height":121,"lPadding":5,"tPadding":5}');
         $insertStatements = array(1 => "({$ogID}, %1, '{$dimensions[1]}', %1, NULL, 0, NULL, 2, NULL, 0, 0, 1, NULL, NULL)", 2 => "({$ogID}, %2, '{$dimensions[2]}', %2, NULL, 0, NULL, 3, NULL, 0, 0, 1, NULL, NULL)", 3 => "({$ogID}, %3, '{$dimensions[3]}', %3, NULL, 0, NULL, 4, NULL, 0, 0, 1, NULL, NULL)");
         $queryParams = array(1 => array('A6 Badge Portrait 150x106', 'String'), 2 => array('Fattorini Name Badge 100x65', 'String'), 3 => array('Hanging Badge 3-3/4" x 4-3"/4', 'String'));
         foreach ($insertStatements as $values) {
             $query = 'INSERT INTO civicrm_option_value (`option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`) VALUES' . $values;
             CRM_Core_DAO::executeQuery($query, $queryParams);
         }
     }
     // CRM-12578 - Prior to this version a CSS file under drupal would disable core css
     if (!empty($config->customCSSURL) && strpos($config->userFramework, 'Drupal') === 0) {
         // The new setting doesn't exist yet - need to create it first
         $sql = '
     INSERT INTO civicrm_setting (group_name, name , value , domain_id , is_domain , created_date)
     VALUES (%1, %2, %3, %4, %5, now())';
         CRM_Core_DAO::executeQuery($sql, array(1 => array(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'String'), 2 => array('disable_core_css', 'String'), 3 => array(serialize(1), 'String'), 4 => array(CRM_Core_Config::domainID(), 'Positive'), 5 => array(1, 'Int')));
         Civi::service('settings_manager')->flush();
     }
     // CRM-13701 - Fix $config->timeInputFormat
     $sql = "\n      SELECT time_format\n      FROM   civicrm_preferences_date\n      WHERE  time_format IS NOT NULL\n      AND    time_format <> ''\n      LIMIT  1\n    ";
     $timeInputFormat = CRM_Core_DAO::singleValueQuery($sql);
     if ($timeInputFormat && $timeInputFormat != $config->timeInputFormat) {
         $params = array('timeInputFormat' => $timeInputFormat);
         CRM_Core_BAO_ConfigSetting::add($params);
     }
     // CRM-13698 - add 'Available' and 'No-show' activity statuses
     $insertStatus = array();
     $nsinc = $avinc = $inc = 0;
     if (!CRM_Core_OptionGroup::getValue('activity_status', 'Available', 'name')) {
         $insertStatus[] = "(%1, 'Available', %2, 'Available',  NULL, 0, NULL, %3, 0, 0, 1, NULL, NULL)";
         $avinc = $inc = 1;
     }
     if (!CRM_Core_OptionGroup::getValue('activity_status', 'No_show', 'name')) {
         $insertStatus[] = "(%1, 'No-show', %4, 'No_show',  NULL, 0, NULL, %5, 0, 0, 1, NULL, NULL)";
         $nsinc = $inc + 1;
     }
     if (!empty($insertStatus)) {
         $acOptionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_status', 'id', 'name');
         $maxVal = CRM_Core_DAO::singleValueQuery("SELECT MAX(ROUND(op.value)) FROM civicrm_option_value op WHERE op.option_group_id  = {$acOptionGroupID}");
         $maxWeight = CRM_Core_DAO::singleValueQuery("SELECT MAX(weight) FROM civicrm_option_value WHERE option_group_id = {$acOptionGroupID}");
         $p[1] = array($acOptionGroupID, 'Integer');
         if ($avinc) {
             $p[2] = array($avinc + $maxVal, 'Integer');
             $p[3] = array($avinc + $maxWeight, 'Integer');
         }
         if ($nsinc) {
             $p[4] = array($nsinc + $maxVal, 'Integer');
             $p[5] = array($nsinc + $maxWeight, 'Integer');
         }
         $insertStatus = implode(',', $insertStatus);
         $sql = "\nINSERT INTO\n   civicrm_option_value (`option_group_id`, label, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`)\nVALUES {$insertStatus}";
         CRM_Core_DAO::executeQuery($sql, $p);
     }
     $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.1')), 'runSql', $rev);
     $this->addTask('Patch word-replacement schema', 'wordReplacements_patch', $rev);
 }
Example #25
0
 /**
  * Build the form object.
  */
 public function preProcess()
 {
     CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity');
     $this->_atypefile = CRM_Utils_Array::value('atypefile', $_GET);
     $this->assign('atypefile', FALSE);
     if ($this->_atypefile) {
         $this->assign('atypefile', TRUE);
     }
     $session = CRM_Core_Session::singleton();
     $this->_currentUserId = $session->get('userID');
     $this->_currentlyViewedContactId = $this->get('contactId');
     if (!$this->_currentlyViewedContactId) {
         $this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     }
     $this->assign('contactId', $this->_currentlyViewedContactId);
     // Give the context.
     if (!isset($this->_context)) {
         $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
         if (CRM_Contact_Form_Search::isSearchContext($this->_context)) {
             $this->_context = 'search';
         } elseif (!in_array($this->_context, array('dashlet', 'dashletFullscreen')) && $this->_currentlyViewedContactId) {
             $this->_context = 'activity';
         }
         $this->_compContext = CRM_Utils_Request::retrieve('compContext', 'String', $this);
     }
     $this->assign('context', $this->_context);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
     if ($this->_action & CRM_Core_Action::DELETE) {
         if (!CRM_Core_Permission::check('delete activities')) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
         }
     }
     // CRM-6957
     // When we come from contact search, activity id never comes.
     // So don't try to get from object, it might gives you wrong one.
     // if we're not adding new one, there must be an id to
     // an activity we're trying to work on.
     if ($this->_action != CRM_Core_Action::ADD && get_class($this->controller) != 'CRM_Contact_Controller_Search') {
         $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     }
     $this->_activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
     $this->assign('atype', $this->_activityTypeId);
     $this->assign('activityId', $this->_activityId);
     // Check for required permissions, CRM-6264.
     if ($this->_activityId && in_array($this->_action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW)) && !CRM_Activity_BAO_Activity::checkPermission($this->_activityId, $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     if ($this->_action & CRM_Core_Action::VIEW && CRM_Activity_BAO_Activity::checkPermission($this->_activityId, CRM_Core_Action::UPDATE)) {
         $this->assign('permission', 'edit');
     }
     if (!$this->_activityTypeId && $this->_activityId) {
         $this->_activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'activity_type_id');
     }
     // Assigning Activity type name.
     if ($this->_activityTypeId) {
         $activityTName = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, 'AND v.value = ' . $this->_activityTypeId, 'label');
         if ($activityTName[$this->_activityTypeId]) {
             $this->_activityTypeName = $activityTName[$this->_activityTypeId];
             $this->assign('activityTName', $activityTName[$this->_activityTypeId]);
         }
     }
     // Set title.
     if (isset($activityTName)) {
         $activityName = CRM_Utils_Array::value($this->_activityTypeId, $activityTName);
         $this->assign('pageTitle', ts('%1 Activity', array(1 => $activityName)));
         if ($this->_currentlyViewedContactId) {
             $displayName = CRM_Contact_BAO_Contact::displayName($this->_currentlyViewedContactId);
             // Check if this is default domain contact CRM-10482.
             if (CRM_Contact_BAO_Contact::checkDomainContact($this->_currentlyViewedContactId)) {
                 $displayName .= ' (' . ts('default organization') . ')';
             }
             CRM_Utils_System::setTitle($displayName . ' - ' . $activityName);
         } else {
             CRM_Utils_System::setTitle(ts('%1 Activity', array(1 => $activityName)));
         }
     }
     // Check the mode when this form is called either single or as
     // search task action.
     if ($this->_activityTypeId || $this->_context == 'standalone' || $this->_currentlyViewedContactId) {
         $this->_single = TRUE;
         $this->assign('urlPath', 'civicrm/activity');
     } else {
         // Set the appropriate action.
         $url = CRM_Utils_System::currentPath();
         $urlArray = explode('/', $url);
         $searchPath = array_pop($urlArray);
         $searchType = 'basic';
         $this->_action = CRM_Core_Action::BASIC;
         switch ($searchPath) {
             case 'basic':
                 $searchType = $searchPath;
                 $this->_action = CRM_Core_Action::BASIC;
                 break;
             case 'advanced':
                 $searchType = $searchPath;
                 $this->_action = CRM_Core_Action::ADVANCED;
                 break;
             case 'builder':
                 $searchType = $searchPath;
                 $this->_action = CRM_Core_Action::PROFILE;
                 break;
             case 'custom':
                 $this->_action = CRM_Core_Action::COPY;
                 $searchType = $searchPath;
                 break;
         }
         parent::preProcess();
         $this->_single = FALSE;
         $this->assign('urlPath', "civicrm/contact/search/{$searchType}");
         $this->assign('urlPathVar', "_qf_Activity_display=true&qfKey={$this->controller->_key}");
     }
     $this->assign('single', $this->_single);
     $this->assign('action', $this->_action);
     if ($this->_action & CRM_Core_Action::VIEW) {
         // Get the tree of custom fields.
         $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Activity', $this, $this->_activityId, 0, $this->_activityTypeId);
     }
     if ($this->_activityTypeId) {
         // Set activity type name and description to template.
         list($this->_activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($this->_activityTypeId);
         $this->assign('activityTypeName', $this->_activityTypeName);
         $this->assign('activityTypeDescription', $activityTypeDescription);
     }
     // set user context
     $urlParams = $urlString = NULL;
     $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
     if (!$qfKey) {
         $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
     }
     // Validate the qfKey.
     if (!CRM_Utils_Rule::qfKey($qfKey)) {
         $qfKey = NULL;
     }
     if ($this->_context == 'fulltext') {
         $keyName = '&qfKey';
         $urlParams = 'force=1';
         $urlString = 'civicrm/contact/search/custom';
         if ($this->_action == CRM_Core_Action::UPDATE) {
             $keyName = '&key';
             $urlParams .= '&context=fulltext&action=view';
             $urlString = 'civicrm/contact/view/activity';
         }
         if ($qfKey) {
             $urlParams .= "{$keyName}={$qfKey}";
         }
         $this->assign('searchKey', $qfKey);
     } elseif (in_array($this->_context, array('standalone', 'home', 'dashlet', 'dashletFullscreen'))) {
         $urlParams = 'reset=1';
         $urlString = 'civicrm/dashboard';
     } elseif ($this->_context == 'search') {
         $urlParams = 'force=1';
         if ($qfKey) {
             $urlParams .= "&qfKey={$qfKey}";
         }
         $path = CRM_Utils_System::currentPath();
         if ($this->_compContext == 'advanced') {
             $urlString = 'civicrm/contact/search/advanced';
         } elseif ($path == 'civicrm/group/search' || $path == 'civicrm/contact/search' || $path == 'civicrm/contact/search/advanced' || $path == 'civicrm/contact/search/custom' || $path == 'civicrm/group/search') {
             $urlString = $path;
         } else {
             $urlString = 'civicrm/activity/search';
         }
         $this->assign('searchKey', $qfKey);
     } elseif ($this->_context != 'caseActivity') {
         $urlParams = "action=browse&reset=1&cid={$this->_currentlyViewedContactId}&selectedChild=activity";
         $urlString = 'civicrm/contact/view';
     }
     if ($urlString) {
         $session->pushUserContext(CRM_Utils_System::url($urlString, $urlParams));
     }
     // hack to retrieve activity type id from post variables
     if (!$this->_activityTypeId) {
         $this->_activityTypeId = CRM_Utils_Array::value('activity_type_id', $_POST);
     }
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         // We need to set it in the session for the code below to work.
         // CRM-3014
         // Need to assign custom data subtype to the template.
         $this->set('type', 'Activity');
         $this->set('subType', $this->_activityTypeId);
         $this->set('entityId', $this->_activityId);
         CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity', $this->_activityId);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // add attachments part
     CRM_Core_BAO_File::buildAttachment($this, 'civicrm_activity', $this->_activityId, NULL, TRUE);
     // figure out the file name for activity type, if any
     if ($this->_activityTypeId && ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, $this->_crmDir))) {
         $this->assign('activityTypeFile', $this->_activityTypeFile);
         $this->assign('crmDir', $this->_crmDir);
     }
     $this->setFields();
     if ($this->_activityTypeFile) {
         $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}";
         $className::preProcess($this);
     }
     $this->_values = $this->get('values');
     if (!is_array($this->_values)) {
         $this->_values = array();
         if (isset($this->_activityId) && $this->_activityId) {
             $params = array('id' => $this->_activityId);
             CRM_Activity_BAO_Activity::retrieve($params, $this->_values);
         }
         $this->set('values', $this->_values);
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity');
     }
 }
/**
 * Function to delete activity type
 *
 * @param activityTypeId int   activity type id to delete
 *
 * @return boolen
 *
 * @access public
 *
 * @deprecated - we will introduce OptionValue Delete- plse consider helping with this if not done
 * {@example ActivityTypeDelete.php 0}
 */
function civicrm_api3_activity_type_delete($params)
{
    civicrm_api3_verify_mandatory($params, NULL, array('activity_type_id'));
    $activityTypeId = $params['activity_type_id'];
    require_once 'CRM/Core/BAO/OptionValue.php';
    return CRM_Core_BAO_OptionValue::del($activityTypeId);
}
Example #27
0
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action == CRM_Core_Action::VIEW) {
         return;
     }
     $this->_params = $this->controller->exportValues($this->_name);
     if (!empty($this->_params['contact_edit_preferences'])) {
         $preferenceWeights = explode(',', $this->_params['contact_edit_preferences']);
         foreach ($preferenceWeights as $key => $val) {
             if (!$val) {
                 unset($preferenceWeights[$key]);
             }
         }
         $opGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'contact_edit_options', 'id', 'name');
         CRM_Core_BAO_OptionValue::updateOptionWeights($opGroupId, array_flip($preferenceWeights));
     }
     $this->_config->editor_id = $this->_params['editor_id'];
     $this->postProcessCommon();
     // If "Configure CKEditor" button was clicked
     if (!empty($this->_params['ckeditor_config'])) {
         // Suppress the "Saved" status message and redirect to the CKEditor Config page
         $session = CRM_Core_Session::singleton();
         $session->getStatus(TRUE);
         $url = CRM_Utils_System::url('civicrm/admin/ckeditor', 'reset=1');
         $session->pushUserContext($url);
     }
 }
Example #28
0
/**
 * Delete ActivityType.
 *
 * @param array $params
 *   Array including id of activity_type to delete.
 *
 * @return array
 *   API result array
 *
 * @deprecated use OptionValue api
 */
function civicrm_api3_activity_type_delete($params)
{
    return civicrm_api3_create_success(CRM_Core_BAO_OptionValue::del($params['id']), $params);
}
/**
 * Function to delete activity type
 *
 * @param activityTypeId int   activity type id to delete
 *
 * @return boolen
 *
 * @access public
 */
function civicrm_activity_type_delete($params)
{
    if (!isset($params['activity_type_id'])) {
        return civicrm_create_error(ts('Required parameter "activity_type_id" not found'));
    }
    $activityTypeId = $params['activity_type_id'];
    require_once 'CRM/Core/BAO/OptionValue.php';
    return CRM_Core_BAO_OptionValue::del($activityTypeId);
}
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_gid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             CRM_Core_Session::setStatus(ts('Selected Survey type has been deleted.'), ts('Record Deleted'), 'success');
         }
     } else {
         $params = $ids = array();
         $params = $this->exportValues();
         // set db value of filter in params if filter is non editable
         if ($this->_id && !array_key_exists('filter', $params)) {
             $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id');
         }
         $groupParams = array('name' => $this->_gName);
         $params['component_id'] = CRM_Core_Component::getComponentID('CiviCampaign');
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         CRM_Core_Session::setStatus(ts('The Survey type \'%1\' has been saved.', array(1 => $optionValue->label)), ts('Saved'), 'success');
     }
 }