Example #1
0
 /**
  * Upgrades for adding a Bussiness Coordinator in the Business case
  * @return bool
  */
 public function upgrade_1007()
 {
     $gid = CRM_Core_DAO::singleValueQuery("SELECT id from civicrm_custom_group where name = 'Add_Keyqualifications'");
     CRM_Core_DAO::executeQuery("UPDATE `civicrm_custom_field` SET label = 'Assessment SC/BC' WHERE `name` = 'Assessment_SC' AND custom_group_id = '" . $gid . "'");
     CRM_Core_DAO::executeQuery("UPDATE `civicrm_custom_field` SET label = 'Remarks SC/BC' WHERE `name` = 'Remarks' AND custom_group_id = '" . $gid . "'");
     CRM_Utils_System::flushCache();
     CRM_Core_DAO::executeQuery("UPDATE `civicrm_option_value` SET label = 'Request Approval Business Programme BC' WHERE label = 'Request Approval Business Programme SC' and option_group_id = 2");
     CRM_Core_DAO::executeQuery("UPDATE `civicrm_option_value` SET label = 'Business Debriefing BC', name = 'Business Debriefing BC' WHERE name = 'Business Debriefing SC' and option_group_id = 2");
     CRM_Utils_System::flushCache();
     $this->executeCustomDataFile('xml/request_approval_bc.xml');
     CRM_Utils_System::flushCache();
     $this->executeCustomDataFile('xml/request_approval_cc.xml');
     CRM_Utils_System::flushCache();
     $checkQry = 'SELECT COUNT(*) AS relCount FROM civicrm_relationship_type WHERE name_a_b = %1';
     $countRelType = CRM_Core_DAO::singleValueQuery($checkQry, array(1 => array('Business Coordinator', 'String')));
     if ($countRelType == 0) {
         CRM_Core_DAO::executeQuery("INSERT INTO civicrm_relationship_type\n        (name_a_b, label_a_b, name_b_a, label_b_a, description, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b, is_reserved, is_active)\n        VALUES\n        ('Business Coordinator', 'Business Coordinator', 'Business Coordinator', 'Business Coordinator', 'Business Coordinator relationship', NULL, 'Individual', NULL, NULL, NULL, '1')");
     }
     CRM_Utils_System::flushCache();
     $gid = CRM_Core_DAO::singleValueQuery("SELECT id from civicrm_custom_group where name = 'Business_Data'");
     $fid = CRM_Core_DAO::singleValueQuery("SELECT id from civicrm_custom_field where custom_group_id = '" . $gid . "' and name = 'Position_of_Visitors'");
     if ($fid) {
         civicrm_api3('CustomField', 'delete', array('id' => $fid));
     }
     return true;
 }
Example #2
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_Core_DAO_LocationType');
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_LocationType::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Location type has been deleted.'), ts('Record Deleted'), 'success');
         return;
     }
     // store the submitted values in an array
     $params = $this->exportValues();
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
     // action is taken depending upon the mode
     $locationType = new CRM_Core_DAO_LocationType();
     $locationType->name = $params['name'];
     $locationType->display_name = $params['display_name'];
     $locationType->vcard_name = $params['vcard_name'];
     $locationType->description = $params['description'];
     $locationType->is_active = $params['is_active'];
     $locationType->is_default = $params['is_default'];
     if ($params['is_default']) {
         $query = "UPDATE civicrm_location_type SET is_default = 0";
         CRM_Core_DAO::executeQuery($query);
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $locationType->id = $this->_id;
     }
     $locationType->save();
     CRM_Core_Session::setStatus(ts("The location type '%1' has been saved.", array(1 => $locationType->name)), ts('Saved'), 'success');
 }
Example #3
0
 static function deleteGroup($group = null)
 {
     $dao = new CRM_Core_DAO_Cache();
     if (!empty($group)) {
         $dao->group_name = $group;
     }
     $dao->delete();
     // also reset ACL Cache
     require_once 'CRM/ACL/BAO/Cache.php';
     CRM_ACL_BAO_Cache::resetCache();
     // also reset memory cache if any
     CRM_Utils_System::flushCache();
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache();
     $params = $this->exportValues();
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_OptionGroup::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected option group has been deleted.'), ts('Record Deleted'), 'success');
     } else {
         $params = $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['optionGroup'] = $this->_id;
         }
         $optionGroup = CRM_Core_BAO_OptionGroup::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The Option Group \'%1\' has been saved.', array(1 => $optionGroup->name)), ts('Saved'), 'success');
     }
 }
 public function postProcess()
 {
     if (!empty($_POST['_qf_UpdateConfigBackend_next_cleanup'])) {
         $config = CRM_Core_Config::singleton();
         // cleanup templates_c directory
         $config->cleanup(1, FALSE);
         // clear all caches
         CRM_Core_Config::clearDBCache();
         CRM_Utils_System::flushCache();
         parent::rebuildMenu();
         CRM_Core_BAO_WordReplacement::rebuild();
         CRM_Core_Session::setStatus(ts('Cache has been cleared and menu has been rebuilt successfully.'), ts("Success"), "success");
     }
     if (!empty($_POST['_qf_UpdateConfigBackend_next_resetpaths'])) {
         $msg = CRM_Core_BAO_ConfigSetting::doSiteMove();
         CRM_Core_Session::setStatus($msg, ts("Success"), "success");
     }
     return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/updateConfigBackend', 'reset=1'));
 }
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_Queryrunner_DAO_Query');
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Queryrunner_BAO_Query::del($this->_id);
         CRM_Core_Session::setStatus("", ts('Query Deleted.'), "success");
         return;
     }
     $values = $this->controller->exportValues($this->_name);
     $ts = strtotime(trim("{$values['scheduled_run_date']} {$values['scheduled_run_date_time']}"));
     $dao = new CRM_Queryrunner_DAO_Query();
     $dao->id = $this->_id;
     $dao->name = $values['name'];
     $dao->machine_name = strtolower(CRM_Utils_String::munge($dao->name, '_', null));
     $dao->description = $values['description'];
     $dao->query = $values['query'];
     $dao->run_frequency = $values['run_frequency'];
     $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
     $dao->scheduled_run = $ts ?: 0;
     $dao->save();
 }
/**
 * CRM-15191 - Hack to ensure the cache gets cleared after updating a custom field
 */
function civicrm_api3_custom_field_setvalue($params)
{
    require_once 'api/v3/Generic/Setvalue.php';
    $result = civicrm_api3_generic_setValue(array("entity" => 'custom_field', 'params' => $params));
    if (empty($result['is_error'])) {
        CRM_Utils_System::flushCache();
    }
    return $result;
}
 public function testCreateCustomFields()
 {
     $this->webtestLogin();
     $cid_all = $this->_createContact("all_data", "move_custom_data");
     $cid_from_missing = $this->_createContact("source_missing", "move_custom_data");
     $cid_to_missing = $this->_createContact("destination_missing", "move_custom_data");
     $from_group_id = $this->_buildCustomFieldSet("source");
     CRM_Utils_System::flushCache();
     $to_group_id = $this->_buildCustomFieldSet("destination");
     $this->_fillCustomDataForContact($cid_all, $from_group_id);
     $this->_fillCustomDataForContact($cid_to_missing, $from_group_id);
     $this->_fillCustomDataForContact($cid_all, $to_group_id);
     $this->_fillCustomDataForContact($cid_from_missing, $to_group_id);
     //to verify data hasn't been lost, we load the values for each contact
     $pre_move_values = array();
     $pre_move_values[$cid_all]['source'] = $this->_loadDataFromApi($cid_all, $from_group_id);
     $pre_move_values[$cid_all]['destination'] = $this->_loadDataFromApi($cid_all, $to_group_id);
     $pre_move_values[$cid_from_missing]['source'] = $this->_loadDataFromApi($cid_from_missing, $from_group_id);
     $pre_move_values[$cid_from_missing]['destination'] = $this->_loadDataFromApi($cid_from_missing, $to_group_id);
     $pre_move_values[$cid_to_missing]['source'] = $this->_loadDataFromApi($cid_to_missing, $from_group_id);
     $pre_move_values[$cid_to_missing]['destination'] = $this->_loadDataFromApi($cid_to_missing, $to_group_id);
     //ok, so after all that setup, we are now good to actually move a field
     //first, pick a random field from the source group to move
     $fields = $this->webtest_civicrm_api("CustomField", "get", array('custom_group_id' => $from_group_id));
     $field_to_move = array_rand($fields['values']);
     //move the field
     $this->_moveCustomField($field_to_move, $from_group_id, $to_group_id);
     //now lets verify the data, load up the new values from the api...
     $post_move_values = array();
     $post_move_values[$cid_all]['source'] = $this->_loadDataFromApi($cid_all, $from_group_id, TRUE);
     $post_move_values[$cid_all]['destination'] = $this->_loadDataFromApi($cid_all, $to_group_id);
     $post_move_values[$cid_from_missing]['source'] = $this->_loadDataFromApi($cid_from_missing, $from_group_id);
     $post_move_values[$cid_from_missing]['destination'] = $this->_loadDataFromApi($cid_from_missing, $to_group_id);
     $post_move_values[$cid_to_missing]['source'] = $this->_loadDataFromApi($cid_to_missing, $from_group_id);
     $post_move_values[$cid_to_missing]['destination'] = $this->_loadDataFromApi($cid_to_missing, $to_group_id);
     // Make sure that only the appropriate values have changed.
     foreach (array($cid_all, $cid_from_missing, $cid_to_missing) as $cid) {
         foreach (array('source', 'destination') as $fieldset) {
             foreach ($pre_move_values[$cid][$fieldset] as $id => $value) {
                 if ($id != $field_to_move) {
                     //All fields that were there should still be there
                     $this->assertTrue(isset($post_move_values[$cid][$fieldset][$id]), "A custom field that was not moved is missing!");
                     //All fields should have the same value as when we started
                     $this->assertTrue($post_move_values[$cid][$fieldset][$id] == $value, "A custom field value has changed in the source custom field set");
                 }
             }
         }
         //check that the field is actually moved
         $this->assertTrue(!isset($post_move_values[$cid]['source'][$field_to_move]), "Moved field is still present in the source fieldset");
         $this->assertTrue(isset($post_move_values[$cid]['destination'][$field_to_move]), "Moved field is not present in the destination fieldset");
         $this->assertTrue($pre_move_values[$cid]['source'][$field_to_move] == $post_move_values[$cid]['destination'][$field_to_move], "The moved field has changed values!");
     }
     //Go to the contacts page and check that the custom field is in the right group
     $this->openCiviPage('contact/view', "reset=1&cid={$cid_all}");
     //load the names of the custom fieldsets
     $source = $this->webtest_civicrm_api("CustomGroup", "get", array('id' => $from_group_id));
     $source = $source['values'][$from_group_id];
     $destination = $this->webtest_civicrm_api("CustomGroup", "get", array('id' => $to_group_id));
     $destination = $destination['values'][$to_group_id];
     //assert that the moved custom field is missing from the source fieldset
     $this->assertElementNotContainsText("css=div." . $source['name'], $fields['values'][$field_to_move]['label'], "Moved value still displays in the old fieldset on the contact record");
     $this->assertElementContainsText("css=div." . $destination['name'], $fields['values'][$field_to_move]['label'], "Moved value does not display in the new fieldset on the contact record");
 }
Example #9
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache();
     // get values from form
     $params = $this->exportValues();
     $params['id'] = $this->_config['id'];
     //$params['day_start_at'] = date('His', strtotime($params['day_start_at']));
     //$params['day_end_at'] = date('His', strtotime($params['day_end_at']));
     if (!isset($params['log_confirmation_email'])) {
         $params['log_confirmation_email'] = 0;
     }
     if (!isset($params['unlimited_resource_time_config'])) {
         $params['unlimited_resource_time_config'] = 0;
     }
     // submit to BAO for updating
     $set = CRM_Booking_BAO_BookingConfig::create($params);
     $url = CRM_Utils_System::url('civicrm/admin/setting/preferences/booking', 'reset=1');
     // show message
     CRM_Core_Session::setStatus(ts('The Booking configuration has been saved.'), ts('Saved'), 'success');
     $session = CRM_Core_Session::singleton();
     $session->replaceUserContext($url);
 }
Example #10
0
 /**
  * function to add the event
  *
  * @param array $params reference array contains the values submitted by the form
  * 
  * @access public
  * @static 
  * @return object
  */
 static function add(&$params)
 {
     require_once 'CRM/Utils/System.php';
     CRM_Utils_System::flushCache();
     require_once 'CRM/Utils/Hook.php';
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::pre('edit', 'Event', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Event', null, $params);
     }
     $event = new CRM_Event_DAO_Event();
     $event->copyValues($params);
     $result = $event->save();
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::post('edit', 'Event', $event->id, $event);
     } else {
         CRM_Utils_Hook::post('create', 'Event', $event->id, $event);
     }
     return $result;
 }
Example #11
0
 /**
  * Common Process.
  *
  * @todo Document what I do.
  *
  * @param array $params
  */
 public function commonProcess(&$params)
 {
     // save autocomplete search options
     if (!empty($params['autocompleteContactSearch'])) {
         $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['autocompleteContactSearch'])) . CRM_Core_DAO::VALUE_SEPARATOR;
         CRM_Core_BAO_Setting::setItem($value, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_autocomplete_options');
         unset($params['autocompleteContactSearch']);
     }
     // save autocomplete contact reference options
     if (!empty($params['autocompleteContactReference'])) {
         $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['autocompleteContactReference'])) . CRM_Core_DAO::VALUE_SEPARATOR;
         CRM_Core_BAO_Setting::setItem($value, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_reference_options');
         unset($params['autocompleteContactReference']);
     }
     // save components to be enabled
     if (array_key_exists('enableComponents', $params)) {
         civicrm_api3('setting', 'create', array('enable_components' => $params['enableComponents']));
         unset($params['enableComponents']);
     }
     // save checksum timeout
     if (!empty($params['checksumTimeout'])) {
         CRM_Core_BAO_Setting::setItem($params['checksumTimeout'], CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'checksum_timeout');
     }
     // update time for date formats when global time is changed
     if (!empty($params['timeInputFormat'])) {
         $query = "\nUPDATE civicrm_preferences_date\nSET    time_format = %1\nWHERE  time_format IS NOT NULL\nAND    time_format <> ''\n";
         $sqlParams = array(1 => array($params['timeInputFormat'], 'String'));
         CRM_Core_DAO::executeQuery($query, $sqlParams);
     }
     // verify ssl peer option
     if (isset($params['verifySSL'])) {
         CRM_Core_BAO_Setting::setItem($params['verifySSL'], CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL');
         unset($params['verifySSL']);
     }
     // force secure URLs
     if (isset($params['enableSSL'])) {
         CRM_Core_BAO_Setting::setItem($params['enableSSL'], CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enableSSL');
         unset($params['enableSSL']);
     }
     $settings = array_intersect_key($params, $this->_settings);
     $result = civicrm_api('setting', 'create', $settings + array('version' => 3));
     foreach ($settings as $setting => $settingGroup) {
         //@todo array_diff this
         unset($params[$setting]);
     }
     CRM_Core_BAO_ConfigSetting::create($params);
     CRM_Core_Config::clearDBCache();
     CRM_Utils_System::flushCache();
     CRM_Core_Resources::singleton()->resetCacheCode();
     CRM_Core_Session::setStatus(" ", ts('Changes Saved'), "success");
 }
Example #12
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache();
     if ($this->_action & CRM_Core_Action::DELETE) {
         $isDelete = CRM_Contact_BAO_ContactType::del($this->_id);
         if ($isDelete) {
             CRM_Core_Session::setStatus(ts('Selected contact type has been deleted.'), ts('Record Deleted'), 'success');
         } else {
             CRM_Core_Session::setStatus(ts("Selected contact type can not be deleted. Make sure contact type doesn't have any associated custom data or group."), ts('Sorry'), 'error');
         }
         return;
     }
     // store the submitted values in an array
     $params = $this->exportValues();
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
         // Force Enabled = true for built-in contact types to fix problems caused by CRM-6471 (parent_id is NULL for these types)
         if (is_null($this->_parentId)) {
             $params['is_active'] = 1;
         }
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $params['name'] = ucfirst(CRM_Utils_String::munge($params['label']));
     }
     $contactType = CRM_Contact_BAO_ContactType::add($params);
     CRM_Core_Session::setStatus(ts("The Contact Type '%1' has been saved.", array(1 => $contactType->label)), ts('Saved'), 'success');
 }
Example #13
0
 /**
  * Do general cleanup of caches, temp directories and temp tables
  * CRM-8739
  *
  * @param bool $sessionReset
  */
 public function cleanupCaches($sessionReset = TRUE)
 {
     // cleanup templates_c directory
     $this->cleanup(1, FALSE);
     // clear all caches
     self::clearDBCache();
     CRM_Utils_System::flushCache();
     if ($sessionReset) {
         $session = CRM_Core_Session::singleton();
         $session->reset(2);
     }
 }
 /**
  * Move a custom data field from one group (table) to another
  *
  * @param int $fieldID
  *   FK to civicrm_custom_field.
  * @param int $newGroupID
  *   FK to civicrm_custom_group.
  *
  * @return void
  */
 public static function moveField($fieldID, $newGroupID)
 {
     $validation = self::_moveFieldValidate($fieldID, $newGroupID);
     if (TRUE !== $validation) {
         CRM_Core_Error::fatal(implode(' ', $validation));
     }
     $field = new CRM_Core_DAO_CustomField();
     $field->id = $fieldID;
     $field->find(TRUE);
     $newGroup = new CRM_Core_DAO_CustomGroup();
     $newGroup->id = $newGroupID;
     $newGroup->find(TRUE);
     $oldGroup = new CRM_Core_DAO_CustomGroup();
     $oldGroup->id = $field->custom_group_id;
     $oldGroup->find(TRUE);
     $add = clone $field;
     $add->custom_group_id = $newGroup->id;
     self::createField($add, 'add');
     $sql = "INSERT INTO {$newGroup->table_name} (entity_id, {$field->column_name})\n            SELECT entity_id, {$field->column_name} FROM {$oldGroup->table_name}\n            ON DUPLICATE KEY UPDATE {$field->column_name} = {$oldGroup->table_name}.{$field->column_name}\n            ";
     CRM_Core_DAO::executeQuery($sql);
     $del = clone $field;
     $del->custom_group_id = $oldGroup->id;
     self::createField($del, 'delete');
     $add->save();
     CRM_Utils_System::flushCache();
 }
Example #15
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_SMS_DAO_Provider');
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_SMS_BAO_Provider::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Provider has been deleted.'), ts('Deleted'), 'success');
         return;
     }
     $recData = $values = $this->controller->exportValues($this->_name);
     $recData['is_active'] = CRM_Utils_Array::value('is_active', $recData, 0);
     $recData['is_default'] = CRM_Utils_Array::value('is_default', $recData, 0);
     if ($this->_action & CRM_Core_Action::UPDATE) {
         CRM_SMS_BAO_Provider::updateRecord($recData, $this->_id);
     } elseif ($this->_action & CRM_Core_Action::ADD) {
         CRM_SMS_BAO_Provider::saveRecord($recData);
     }
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache();
     $params = $this->exportValues();
     // delete action
     // TODO::Make sure we cannot delete if the entity is linked to bookings
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Booking_BAO_AdhocChargesItem::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected additional charges item has been deleted.'), ts('Record Deleted'), 'success');
     } else {
         $params = $this->exportValues();
         if ($this->_id) {
             $params['id'] = $this->_id;
             if (!isset($params['is_active'])) {
                 $params['is_active'] = 0;
             }
         }
         $set = CRM_Booking_BAO_AdhocChargesItem::create($params);
         // udpate action
         if ($this->_action & CRM_Core_Action::UPDATE) {
             CRM_Core_Session::setStatus(ts('The Record \'%1\' has been saved.', array(1 => $set->label)), ts('Saved'), 'success');
         } else {
             $url = CRM_Utils_System::url('civicrm/admin/adhoc_charges_item', 'reset=1&action=browse&sid=' . $set->id);
             CRM_Core_Session::setStatus(ts("Your additional charges item '%1' has been added.", array(1 => $set->label)), ts('Saved'), 'success');
             $session = CRM_Core_Session::singleton();
             $session->replaceUserContext($url);
         }
     }
 }
Example #17
0
 /**
  * Process the form when submitted.
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_Core_DAO_Group');
     $updateNestingCache = FALSE;
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Contact_BAO_Group::discard($this->_id);
         CRM_Core_Session::setStatus(ts("The Group '%1' has been deleted.", array(1 => $this->_title)), ts('Group Deleted'), 'success');
         $updateNestingCache = TRUE;
     } else {
         // store the submitted values in an array
         $params = $this->controller->exportValues($this->_name);
         $params['is_active'] = CRM_Utils_Array::value('is_active', $this->_groupValues, 1);
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $params['id'] = $this->_id;
         }
         if ($this->_action & CRM_Core_Action::UPDATE && isset($this->_groupOrganizationID)) {
             $params['group_organization'] = $this->_groupOrganizationID;
         }
         $params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
         $groupTypeIds = array();
         $groupType = CRM_Utils_Array::value('group_type', $params);
         if (is_array($groupType)) {
             foreach ($groupType as $type => $selected) {
                 if ($selected) {
                     $groupTypeIds[] = $type;
                 }
             }
         }
         $params['group_type'] = $groupTypeIds;
         $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_id, 'Group');
         $group = CRM_Contact_BAO_Group::create($params);
         //Remove any parent groups requested to be removed
         if (!empty($this->_groupValues['parents'])) {
             $parentGroupIds = explode(',', $this->_groupValues['parents']);
             foreach ($parentGroupIds as $parentGroupId) {
                 if (isset($params["remove_parent_group_{$parentGroupId}"])) {
                     CRM_Contact_BAO_GroupNesting::remove($parentGroupId, $group->id);
                     $updateNestingCache = TRUE;
                 }
             }
         }
         CRM_Core_Session::setStatus(ts('The Group \'%1\' has been saved.', array(1 => $group->title)), ts('Group Saved'), 'success');
         // Add context to the session, in case we are adding members to the group
         if ($this->_action & CRM_Core_Action::ADD) {
             $this->set('context', 'amtg');
             $this->set('amtgID', $group->id);
             $session = CRM_Core_Session::singleton();
             $session->pushUserContext(CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id));
         }
     }
     // update the nesting cache
     if ($updateNestingCache) {
         CRM_Contact_BAO_GroupNestingCache::update();
     }
 }
Example #18
0
 /**
  *  Common setup functions for all unit tests.
  */
 protected function setUp()
 {
     $session = CRM_Core_Session::singleton();
     $session->set('userID', NULL);
     $this->errorScope = CRM_Core_TemporaryErrorScope::useException();
     // REVERT
     //  Use a temporary file for STDIN
     $GLOBALS['stdin'] = tmpfile();
     if ($GLOBALS['stdin'] === FALSE) {
         echo "Couldn't open temporary file\n";
         exit(1);
     }
     //  Get and save a connection to the database
     $this->_dbconn = $this->getConnection();
     // reload database before each test
     //        $this->_populateDB();
     // "initialize" CiviCRM to avoid problems when running single tests
     // FIXME: look at it closer in second stage
     $GLOBALS['civicrm_setting']['domain']['fatalErrorHandler'] = 'CiviUnitTestCase_fatalErrorHandler';
     $GLOBALS['civicrm_setting']['domain']['backtrace'] = 1;
     // disable any left-over test extensions
     CRM_Core_DAO::executeQuery('DELETE FROM civicrm_extension WHERE full_name LIKE "test.%"');
     // reset all the caches
     CRM_Utils_System::flushCache();
     // initialize the object once db is loaded
     \Civi::reset();
     $config = CRM_Core_Config::singleton(TRUE, TRUE);
     // ugh, performance
     // when running unit tests, use mockup user framework
     $this->hookClass = CRM_Utils_Hook::singleton();
     // Make sure the DB connection is setup properly
     $config->userSystem->setMySQLTimeZone();
     $env = new CRM_Utils_Check_Component_Env();
     CRM_Utils_Check::singleton()->assertValid($env->checkMysqlTime());
     // clear permissions stub to not check permissions
     $config->userPermissionClass->permissions = NULL;
     //flush component settings
     CRM_Core_Component::getEnabledComponents(TRUE);
     error_reporting(E_ALL);
     $this->_sethtmlGlobals();
 }
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_Financial_DAO_PaymentProcessorType');
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Financial_BAO_PaymentProcessorType::del($this->_id);
         return;
     }
     $values = $this->controller->exportValues($this->_name);
     if (!empty($values['is_default'])) {
         $query = "\nUPDATE civicrm_payment_processor SET is_default = 0";
         CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     }
     $dao = new CRM_Financial_DAO_PaymentProcessorType();
     $dao->id = $this->_id;
     $dao->is_default = CRM_Utils_Array::value('is_default', $values, 0);
     $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
     $dao->is_recur = CRM_Utils_Array::value('is_recur', $values, 0);
     $dao->name = $values['name'];
     $dao->description = $values['description'];
     foreach ($this->_fields as $field) {
         $dao->{$field['name']} = trim($values[$field['name']]);
         if (empty($dao->{$field['name']})) {
             $dao->{$field['name']} = 'null';
         }
     }
     $dao->save();
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_Core_DAO_Job');
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_Job::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Scheduled Job has been deleted.'));
         return;
     }
     $values = $this->controller->exportValues($this->_name);
     $domainID = CRM_Core_Config::domainID();
     $dao = new CRM_Core_DAO_Job();
     $dao->id = $this->_id;
     $dao->domain_id = $domainID;
     $dao->run_frequency = $values['run_frequency'];
     $dao->parameters = $values['parameters'];
     $dao->name = $values['name'];
     $dao->api_prefix = $values['api_prefix'];
     $dao->api_entity = $values['api_entity'];
     $dao->api_action = $values['api_action'];
     $dao->description = $values['description'];
     $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
     $dao->save();
 }
Example #21
0
 /**
  * This function is to make a copy of a Event, including
  * all the fields in the event Wizard
  *
  * @param int $id the event id to copy
  *        obj     $newEvent    object of CRM_Event_DAO_Event
  *        boolean $afterCreate call to copy after the create function
  * @param null $newEvent
  * @param bool $afterCreate
  *
  * @return void
  * @access public
  */
 static function copy($id, $newEvent = NULL, $afterCreate = FALSE)
 {
     $defaults = $eventValues = array();
     //get the require event values.
     $eventParams = array('id' => $id);
     $returnProperties = array('loc_block_id', 'is_show_location', 'default_fee_id', 'default_discount_fee_id', 'is_template');
     CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties);
     // since the location is sharable, lets use the same loc_block_id.
     $locBlockId = CRM_Utils_Array::value('loc_block_id', $eventValues);
     $fieldsFix = $afterCreate ? array() : array('prefix' => array('title' => ts('Copy of') . ' '));
     if (empty($eventValues['is_show_location'])) {
         $fieldsFix['prefix']['is_show_location'] = 0;
     }
     if ($newEvent && is_a($newEvent, 'CRM_Event_DAO_Event')) {
         $copyEvent = $newEvent;
     }
     if (!isset($copyEvent)) {
         $copyEvent =& CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event', array('id' => $id), array('loc_block_id' => $locBlockId ? $locBlockId : NULL), $fieldsFix);
     }
     CRM_Price_BAO_PriceSet::copyPriceSet('civicrm_event', $id, $copyEvent->id);
     $copyUF =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
     $copyTellFriend =& CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
     $copyPCP =& CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id), array('replace' => array('target_entity_id' => $copyEvent->id)));
     if ($eventValues['is_template']) {
         $field = 'event_template';
     } else {
         $field = 'civicrm_event';
     }
     $mappingId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', $field, 'id', 'entity_value');
     $oldData = array('entity_value' => $id, 'mapping_id' => $mappingId);
     if ($copyEvent->is_template == 1) {
         $field = 'event_template';
     } else {
         $field = 'civicrm_event';
     }
     $copyMappingId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', $field, 'id', 'entity_value');
     $newData = array('entity_value' => $copyEvent->id, 'mapping_id' => $copyMappingId);
     $copyReminder =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule', $oldData, $newData);
     if (!$afterCreate) {
         //copy custom data
         $extends = array('event');
         $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends);
         if ($groupTree) {
             foreach ($groupTree as $groupID => $group) {
                 $table[$groupTree[$groupID]['table_name']] = array('entity_id');
                 foreach ($group['fields'] as $fieldID => $field) {
                     $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name'];
                 }
             }
             foreach ($table as $tableName => $tableColumns) {
                 $insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') ';
                 $tableColumns[0] = $copyEvent->id;
                 $select = 'SELECT ' . implode(', ', $tableColumns);
                 $from = ' FROM ' . $tableName;
                 $where = " WHERE {$tableName}.entity_id = {$id}";
                 $query = $insert . $select . $from . $where;
                 $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
             }
         }
     }
     $copyEvent->save();
     CRM_Utils_System::flushCache();
     if (!$afterCreate) {
         CRM_Utils_Hook::copy('Event', $copyEvent);
     }
     return $copyEvent;
 }
Example #22
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache();
     $params = $this->exportValues();
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Booking_BAO_Slot::delByResource($this->_id);
         CRM_Booking_BAO_Resource::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected resource has been deleted.'), ts('Record Deleted'), 'success');
     } else {
         $params = $this->exportValues();
         // If the is_active (enabled) checkbox is NOT set, it is NOT sent down in the form
         // The DAO definition for is_active has a default of '1'
         // So if not set it is by default ENABLED when in fact it should be DISABLED
         if (!isset($params['is_active'])) {
             $params['is_active'] = 0;
         }
         if ($this->_id) {
             $params['id'] = $this->_id;
         }
         $resource = CRM_Booking_BAO_Resource::create($params);
         CRM_Core_Session::setStatus(ts('The Record \'%1\' has been saved.', array(1 => $resource->label)), ts('Saved'), 'success');
     }
 }
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache();
     if ($this->_action & CRM_Core_Action::DELETE) {
         try {
             CRM_Extension_System::singleton()->getManager()->uninstall(array($this->_key));
             CRM_Core_Session::setStatus("", ts('Extension Uninstalled'), "success");
         } catch (CRM_Extension_Exception_DependencyException $e) {
             // currently only thrown for payment-processor dependencies
             CRM_Core_Session::setStatus(ts('Cannot uninstall this extension - there is at least one payment processor using the payment processor type provided by it.'), ts('Uninstall Error'), 'error');
         }
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         CRM_Extension_System::singleton()->getManager()->install(array($this->_key));
         CRM_Core_Session::setStatus("", ts('Extension Installed'), "success");
     }
     if ($this->_action & CRM_Core_Action::ENABLE) {
         CRM_Extension_System::singleton()->getManager()->enable(array($this->_key));
         CRM_Core_Session::setStatus("", ts('Extension Enabled'), "success");
     }
     if ($this->_action & CRM_Core_Action::DISABLE) {
         CRM_Extension_System::singleton()->getManager()->disable(array($this->_key));
         CRM_Core_Session::setStatus("", ts('Extension Disabled'), "success");
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $result = civicrm_api('Extension', 'download', array('version' => 3, 'key' => $this->_key));
         if (!CRM_Utils_Array::value('is_error', $result, FALSE)) {
             CRM_Core_Session::setStatus("", ts('Extension Upgraded'), "success");
         } else {
             CRM_Core_Session::setStatus($result['error_message'], ts('Extension Upgrade Failed'), "error");
         }
     }
     CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1&action=browse'));
 }
 /**
  * Takes an associative array and creates a custom group object.
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params
  *   (reference) an assoc array of name/value pairs.
  *
  * @return CRM_Core_DAO_CustomGroup
  */
 public static function create(&$params)
 {
     // create custom group dao, populate fields and then save.
     $group = new CRM_Core_DAO_CustomGroup();
     if (isset($params['title'])) {
         $group->title = $params['title'];
     }
     if (in_array($params['extends'][0], array('ParticipantRole', 'ParticipantEventName', 'ParticipantEventType'))) {
         $group->extends = 'Participant';
     } else {
         $group->extends = $params['extends'][0];
     }
     $group->extends_entity_column_id = 'null';
     if ($params['extends'][0] == 'ParticipantRole' || $params['extends'][0] == 'ParticipantEventName' || $params['extends'][0] == 'ParticipantEventType') {
         $group->extends_entity_column_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $params['extends'][0], 'value', 'name');
     }
     //this is format when form get submit.
     $extendsChildType = CRM_Utils_Array::value(1, $params['extends']);
     //lets allow user to pass direct child type value, CRM-6893
     if (!empty($params['extends_entity_column_value'])) {
         $extendsChildType = $params['extends_entity_column_value'];
     }
     if (!CRM_Utils_System::isNull($extendsChildType)) {
         $extendsChildType = implode(CRM_Core_DAO::VALUE_SEPARATOR, $extendsChildType);
         if (CRM_Utils_Array::value(0, $params['extends']) == 'Relationship') {
             $extendsChildType = str_replace(array('_a_b', '_b_a'), array('', ''), $extendsChildType);
         }
         if (substr($extendsChildType, 0, 1) != CRM_Core_DAO::VALUE_SEPARATOR) {
             $extendsChildType = CRM_Core_DAO::VALUE_SEPARATOR . $extendsChildType . CRM_Core_DAO::VALUE_SEPARATOR;
         }
     } else {
         $extendsChildType = 'null';
     }
     $group->extends_entity_column_value = $extendsChildType;
     if (isset($params['id'])) {
         $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'weight', 'id');
     } else {
         $oldWeight = 0;
     }
     $group->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomGroup', $oldWeight, CRM_Utils_Array::value('weight', $params, FALSE));
     $fields = array('style', 'collapse_display', 'collapse_adv_display', 'help_pre', 'help_post', 'is_active', 'is_multiple');
     foreach ($fields as $field) {
         if (isset($params[$field]) || $field == 'is_multiple') {
             $group->{$field} = CRM_Utils_Array::value($field, $params, FALSE);
         }
     }
     $group->max_multiple = isset($params['is_multiple']) ? isset($params['max_multiple']) && $params['max_multiple'] >= '0' ? $params['max_multiple'] : 'null' : 'null';
     $tableName = $oldTableName = NULL;
     if (isset($params['id'])) {
         $group->id = $params['id'];
         //check whether custom group was changed from single-valued to multiple-valued
         $isMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'is_multiple');
         if ((!empty($params['is_multiple']) || $isMultiple) && $params['is_multiple'] != $isMultiple) {
             $oldTableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name');
         }
     } else {
         $group->created_id = CRM_Utils_Array::value('created_id', $params);
         $group->created_date = CRM_Utils_Array::value('created_date', $params);
         // we do this only once, so name never changes
         if (isset($params['name'])) {
             $group->name = CRM_Utils_String::munge($params['name'], '_', 64);
         } else {
             $group->name = CRM_Utils_String::munge($group->title, '_', 64);
         }
         if (isset($params['table_name'])) {
             $tableName = $params['table_name'];
             if (CRM_Core_DAO_AllCoreTables::isCoreTable($tableName)) {
                 // Bad idea.  Prevent group creation because it might lead to a broken configuration.
                 CRM_Core_Error::fatal(ts("Cannot create custom table because %1 is already a core table.", array('1' => $tableName)));
             }
         }
     }
     if (array_key_exists('is_reserved', $params)) {
         $group->is_reserved = $params['is_reserved'] ? 1 : 0;
     }
     $op = isset($params['id']) ? 'edit' : 'create';
     CRM_Utils_Hook::pre($op, 'CustomGroup', CRM_Utils_Array::value('id', $params), $params);
     // enclose the below in a transaction
     $transaction = new CRM_Core_Transaction();
     $group->save();
     if (!isset($params['id'])) {
         if (!isset($params['table_name'])) {
             $munged_title = strtolower(CRM_Utils_String::munge($group->title, '_', 42));
             $tableName = "civicrm_value_{$munged_title}_{$group->id}";
         }
         $group->table_name = $tableName;
         CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomGroup', $group->id, 'table_name', $tableName);
         // now create the table associated with this group
         self::createTable($group);
     } elseif ($oldTableName) {
         CRM_Core_BAO_SchemaHandler::changeUniqueToIndex($oldTableName, CRM_Utils_Array::value('is_multiple', $params));
     }
     if (CRM_Utils_Array::value('overrideFKConstraint', $params) == 1) {
         $table = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name');
         CRM_Core_BAO_SchemaHandler::changeFKConstraint($table, self::mapTableName($params['extends'][0]));
     }
     $transaction->commit();
     // reset the cache
     CRM_Utils_System::flushCache();
     if ($tableName) {
         CRM_Utils_Hook::post('create', 'CustomGroup', $group->id, $group);
     } else {
         CRM_Utils_Hook::post('edit', 'CustomGroup', $group->id, $group);
     }
     return $group;
 }
Example #25
0
 /**
  * Process the form submission.
  *
  *
  * @return Void
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_Financial_DAO_PaymentProcessor');
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Financial_BAO_PaymentProcessor::del($this->_id);
         CRM_Core_Session::setStatus("", ts('Payment Processor Deleted.'), "success");
         return NULL;
     }
     $values = $this->controller->exportValues($this->_name);
     $domainID = CRM_Core_Config::domainID();
     if (!empty($values['is_default'])) {
         $query = "UPDATE civicrm_payment_processor SET is_default = 0 WHERE domain_id = {$domainID}";
         CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     }
     $this->updatePaymentProcessor($values, $domainID, FALSE);
     $this->updatePaymentProcessor($values, $domainID, TRUE);
     CRM_Core_Session::setStatus(ts('Payment processor %1 has been saved.', array(1 => "<em>{$values['name']}</em>")), ts('Saved'), 'success');
 }
Example #26
0
 /**
  * Common Process.
  *
  * @todo Document what I do.
  *
  * @param array $params
  */
 public function commonProcess(&$params)
 {
     // save autocomplete search options
     if (!empty($params['contact_autocomplete_options'])) {
         Civi::settings()->set('contact_autocomplete_options', CRM_Utils_Array::implodePadded(array_keys($params['contact_autocomplete_options'])));
         unset($params['contact_autocomplete_options']);
     }
     // save autocomplete contact reference options
     if (!empty($params['contact_reference_options'])) {
         Civi::settings()->set('contact_reference_options', CRM_Utils_Array::implodePadded(array_keys($params['contact_reference_options'])));
         unset($params['contact_reference_options']);
     }
     // save components to be enabled
     if (array_key_exists('enableComponents', $params)) {
         civicrm_api3('setting', 'create', array('enable_components' => $params['enableComponents']));
         unset($params['enableComponents']);
     }
     // verify ssl peer option
     if (isset($params['verifySSL'])) {
         Civi::settings()->set('verifySSL', $params['verifySSL']);
         unset($params['verifySSL']);
     }
     // force secure URLs
     if (isset($params['enableSSL'])) {
         Civi::settings()->set('enableSSL', $params['enableSSL']);
         unset($params['enableSSL']);
     }
     $settings = array_intersect_key($params, $this->_settings);
     $result = civicrm_api('setting', 'create', $settings + array('version' => 3));
     foreach ($settings as $setting => $settingGroup) {
         //@todo array_diff this
         unset($params[$setting]);
     }
     if (!empty($result['error_message'])) {
         CRM_Core_Session::setStatus($result['error_message'], ts('Save Failed'), 'error');
     }
     //CRM_Core_BAO_ConfigSetting::create($params);
     $params = CRM_Core_BAO_ConfigSetting::filterSkipVars($params);
     if (!empty($params)) {
         CRM_Core_Error::fatal('Unrecognized setting. This may be a config field which has not been properly migrated to a setting. (' . implode(', ', array_keys($params)) . ')');
     }
     CRM_Core_Config::clearDBCache();
     CRM_Utils_System::flushCache();
     CRM_Core_Resources::singleton()->resetCacheCode();
     CRM_Core_Session::setStatus(" ", ts('Changes Saved'), "success");
 }
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_Core_DAO_Job');
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_Job::del($this->_id);
         CRM_Core_Session::setStatus("", ts('Scheduled Job Deleted.'), "success");
         return;
     }
     $values = $this->controller->exportValues($this->_name);
     $domainID = CRM_Core_Config::domainID();
     $dao = new CRM_Core_DAO_Job();
     $dao->id = $this->_id;
     $dao->domain_id = $domainID;
     $dao->run_frequency = $values['run_frequency'];
     $dao->parameters = $values['parameters'];
     $dao->name = $values['name'];
     $dao->api_entity = $values['api_entity'];
     $dao->api_action = $values['api_action'];
     $dao->description = $values['description'];
     $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
     $dao->save();
     /************************************
      * begin com.klangsoft.flexiblejobs *
      ************************************/
     $ts = strtotime(trim("{$values['schedule_at']} {$values['schedule_at_time']}"));
     if ($ts < time()) {
         $ts = NULL;
     } else {
         // warn about monthly/quarterly scheduling, if applicable
         if ($dao->run_frequency == 'Monthly' || $dao->run_frequency == 'Quarter') {
             $info = getdate($ts);
             if ($info['mday'] > 28) {
                 CRM_Core_Session::setStatus(ts('Relative month values are calculated based on the length of month(s) that they pass through.
           The result will land on the same day of the month except for days 29-31 when the target month contains fewer days than the previous month.
           For example, if a job is scheduled to run on August 31st, the following invocation will occur on October 1st, and then the 1st of every month thereafter.
           To avoid this issue, please schedule Monthly and Quarterly jobs to run within the first 28 days of the month.'), ts('Warning'), 'info', array('expires' => 0));
             }
         }
     }
     CRM_Core_BAO_Setting::setItem($ts ?: NULL, 'com.klangsoft.flexiblejobs', 'job_' . $dao->id);
     /**********************************
      * end com.klangsoft.flexiblejobs *
      **********************************/
     // CRM-11143 - Give warning message if update_greetings is Enabled (is_active) since it generally should not be run automatically via execute action or runjobs url.
     if ($values['api_action'] == 'update_greeting' && CRM_Utils_Array::value('is_active', $values) == 1) {
         // pass "wiki" as 6th param to docURL2 if you are linking to a page in wiki.civicrm.org
         $docLink = CRM_Utils_System::docURL2("Managing Scheduled Jobs", NULL, NULL, NULL, NULL, "wiki");
         $msg = ts('The update greeting job can be very resource intensive and is typically not necessary to run on a regular basis. If you do choose to enable the job, we recommend you do not run it with the force=1 option, which would rebuild greetings on all records. Leaving that option absent, or setting it to force=0, will only rebuild greetings for contacts that do not currently have a value stored. %1', array(1 => $docLink));
         CRM_Core_Session::setStatus($msg, ts('Warning: Update Greeting job enabled'), 'alert');
     }
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache();
     $params = $this->exportValues();
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Booking_BAO_ResourceConfigOption::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected resource configuration option has been deleted.'), ts('Record Deleted'), 'success');
     } else {
         $params = $this->exportValues();
         $params['set_id'] = $this->_sid;
         // If the is_active (enabled) checkbox is NOT set, it is NOT sent down in the form
         // The DAO definition for is_active has a default of '1'
         // So if not set it is by default ENABLED when in fact it should be DISABLED
         if (!isset($params['is_active'])) {
             $params['is_active'] = 0;
         }
         if ($this->_id) {
             $params['id'] = $this->_id;
         }
         $resource = CRM_Booking_BAO_ResourceConfigOption::create($params);
         CRM_Core_Session::setStatus(ts('The Record \'%1\' has been saved.', array(1 => $resource->label)), ts('Saved'), 'success');
     }
     $url = CRM_Utils_System::url('civicrm/admin/resource/config_set/config_option', 'reset=1&action=browse&sid=' . $this->_sid);
     $session = CRM_Core_Session::singleton();
     $session->replaceUserContext($url);
 }
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_Core_DAO_Job');
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_Job::del($this->_id);
         CRM_Core_Session::setStatus("", ts('Scheduled Job Deleted.'), "success");
         return;
     }
     $values = $this->controller->exportValues($this->_name);
     $domainID = CRM_Core_Config::domainID();
     $dao = new CRM_Core_DAO_Job();
     $dao->id = $this->_id;
     $dao->domain_id = $domainID;
     $dao->run_frequency = $values['run_frequency'];
     $dao->parameters = $values['parameters'];
     $dao->name = $values['name'];
     $dao->api_entity = $values['api_entity'];
     $dao->api_action = $values['api_action'];
     $dao->description = $values['description'];
     $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
     $dao->save();
     /************************************
      * begin com.klangsoft.flexiblejobs *
      ************************************/
     $ts = strtotime($values['schedule_at']);
     if ($ts < time()) {
         $ts = null;
     }
     CRM_Core_BAO_Setting::setItem($ts ?: null, 'com.klangsoft.flexiblejobs', 'job_' . $dao->id);
     /**********************************
      * end com.klangsoft.flexiblejobs *
      **********************************/
     // CRM-11143 - Give warning message if update_greetings is Enabled (is_active) since it generally should not be run automatically via execute action or runjobs url.
     if ($values['api_action'] == 'update_greeting' && CRM_Utils_Array::value('is_active', $values) == 1) {
         // pass "wiki" as 6th param to docURL2 if you are linking to a page in wiki.civicrm.org
         $docLink = CRM_Utils_System::docURL2("Managing Scheduled Jobs", NULL, NULL, NULL, NULL, "wiki");
         $msg = ts('The update greeting job can be very resource intensive and is typically not necessary to run on a regular basis. If you do choose to enable the job, we recommend you do not run it with the force=1 option, which would rebuild greetings on all records. Leaving that option absent, or setting it to force=0, will only rebuild greetings for contacts that do not currently have a value stored. %1', array(1 => $docLink));
         CRM_Core_Session::setStatus($msg, ts('Warning: Update Greeting job enabled'), 'alert');
     }
 }
Example #30
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     // flush caches so we reload details for future requests
     // CRM-11967
     CRM_Utils_System::flushCache();
     $formValues = $this->controller->exportValues($this->_name);
     $buttonName = $this->controller->getButtonName();
     // check if test button
     if ($buttonName == $this->_testButtonName) {
         if ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED) {
             CRM_Core_Session::setStatus(ts('You have selected "Disable Outbound Email". A test email can not be sent.'), ts("Email Disabled"), "error");
         } elseif ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB) {
             CRM_Core_Session::setStatus(ts('You have selected "Redirect to Database". A test email can not be sent.'), ts("Email Disabled"), "error");
         } else {
             $session = CRM_Core_Session::singleton();
             $userID = $session->get('userID');
             list($toDisplayName, $toEmail, $toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID);
             //get the default domain email address.CRM-4250
             list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
             if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') {
                 $fixUrl = CRM_Utils_System::url("civicrm/admin/domain", 'action=update&reset=1');
                 CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl)));
             }
             if (!$toEmail) {
                 CRM_Core_Error::statusBounce(ts('Cannot send a test email because your user record does not have a valid email address.'));
             }
             if (!trim($toDisplayName)) {
                 $toDisplayName = $toEmail;
             }
             $to = '"' . $toDisplayName . '"' . "<{$toEmail}>";
             $from = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
             $testMailStatusMsg = ts('Sending test email. FROM: %1 TO: %2.<br />', array(1 => $domainEmailAddress, 2 => $toEmail));
             $params = array();
             if ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SMTP) {
                 $subject = "Test for SMTP settings";
                 $message = "SMTP settings are correct.";
                 $params['host'] = $formValues['smtpServer'];
                 $params['port'] = $formValues['smtpPort'];
                 if ($formValues['smtpAuth']) {
                     $params['username'] = $formValues['smtpUsername'];
                     $params['password'] = $formValues['smtpPassword'];
                     $params['auth'] = TRUE;
                 } else {
                     $params['auth'] = FALSE;
                 }
                 // set the localhost value, CRM-3153, CRM-9332
                 $params['localhost'] = $_SERVER['SERVER_NAME'];
                 // also set the timeout value, lets set it to 30 seconds
                 // CRM-7510, CRM-9332
                 $params['timeout'] = 30;
                 $mailerName = 'smtp';
             } elseif ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SENDMAIL) {
                 $subject = "Test for Sendmail settings";
                 $message = "Sendmail settings are correct.";
                 $params['sendmail_path'] = $formValues['sendmail_path'];
                 $params['sendmail_args'] = $formValues['sendmail_args'];
                 $mailerName = 'sendmail';
             } elseif ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MAIL) {
                 $subject = "Test for PHP mail settings";
                 $message = "mail settings are correct.";
                 $mailerName = 'mail';
             }
             $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject);
             $mailer = Mail::factory($mailerName, $params);
             $errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
             $result = $mailer->send($toEmail, $headers, $message);
             unset($errorScope);
             if (!is_a($result, 'PEAR_Error')) {
                 CRM_Core_Session::setStatus($testMailStatusMsg . ts('Your %1 settings are correct. A test email has been sent to your email address.', array(1 => strtoupper($mailerName))), ts("Mail Sent"), "success");
             } else {
                 $message = CRM_Utils_Mail::errorMessage($mailer, $result);
                 CRM_Core_Session::setStatus($testMailStatusMsg . ts('Oops. Your %1 settings are incorrect. No test mail has been sent.', array(1 => strtoupper($mailerName))) . $message, ts("Mail Not Sent"), "error");
             }
         }
     }
     $mailingBackend = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
     if (!empty($mailingBackend)) {
         CRM_Core_BAO_ConfigSetting::formatParams($formValues, $mailingBackend);
     }
     // if password is present, encrypt it
     if (!empty($formValues['smtpPassword'])) {
         $formValues['smtpPassword'] = CRM_Utils_Crypt::encrypt($formValues['smtpPassword']);
     }
     CRM_Core_BAO_Setting::setItem($formValues, CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
 }