/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { parent::preProcess(); require_once 'CRM/Utils/Rule.php'; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= '&qfKey=' . $qfKey; } $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/search/custom', $urlParams); $session->replaceUserContext($url); //get the survey id from user submitted values. $this->_surveyId = CRM_Utils_Array::value('survey_id', $this->get('formValues')); $isHeld = CRM_Utils_Array::value('status_id', $this->get('formValues')); if (!$this->_surveyId || !$isHeld) { CRM_Core_Error::statusBounce(ts("Please search with 'Is Held' and 'Survey Id' filters to apply this action.")); } $session = CRM_Core_Session::singleton(); if (empty($this->_contactIds) || !$session->get('userID')) { CRM_Core_Error::statusBounce(ts("Could not find contacts for release voters resevation Or Missing Interviewer contact.")); } $this->_interviewerId = $session->get('userID'); $surveyDetails = array(); $params = array('id' => $this->_surveyId); $this->_surveyDetails = CRM_Campaign_BAO_Survey::retrieve($params, $surveyDetails); $numVoters = CRM_Core_DAO::singleValueQuery("SELECT COUNT(*) FROM " . self::ACTIVITY_SURVEY_DETAIL_TABLE . " WHERE status_id = 'H' AND survey_id = %1 AND interviewer_id = %2", array(1 => array($this->_surveyId, 'Integer'), 2 => array($this->_interviewerId, 'Integer'))); if (!isset($numVoters) || $numVoters < 1) { CRM_Core_Error::statusBounce(ts("All voters held by you are already released for this survey.")); } $this->assign('surveyTitle', $surveyDetails['title']); }
/** * build all the data structures needed to build the form * * @return void * @access public */ public function preProcess() { $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); $this->_caseId = CRM_Utils_Request::retrieve('id', 'Positive', $this); $context = CRM_Utils_Request::retrieve('context', 'String', $this); //get current client name. require_once 'CRM/Contact/BAO/Contact.php'; $this->assign('currentClientName', CRM_Contact_BAO_Contact::displayName($this->_contactId)); //set the context. $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactId}&selectedChild=case"); if ($context == 'search') { $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey require_once 'CRM/Utils/Rule.php'; $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/case/search', $urlParams); } else { if ($context == 'dashboard') { $url = CRM_Utils_System::url('civicrm/case', 'reset=1'); } } $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); }
function _encodeHeaders($input, $params = array()) { require_once 'CRM/Utils/Rule.php'; $emailValues = array(); foreach ($input as $fieldName => $fieldValue) { $fieldNames = $emails = array(); $hasValue = false; //multiple email w/ comma separate. $fieldValues = explode(',', $fieldValue); foreach ($fieldValues as $index => $value) { $value = trim($value); //might be case we have only email address. if (CRM_Utils_Rule::email($value)) { $hasValue = true; $emails[$index] = $value; $fieldNames[$index] = 'FIXME_HACK_FOR_NO_NAME'; } else { $matches = array(); if (preg_match('/^(.*)<([^<]*)>$/', $value, $matches)) { $hasValue = true; $emails[$index] = $matches[2]; $fieldNames[$index] = trim($matches[1]); } } } //get formatted values back in input if ($hasValue) { $input[$fieldName] = implode(',', $fieldNames); $emailValues[$fieldName] = implode(',', $emails); } } // encode the email-less headers $input = parent::_encodeHeaders($input, $params); // add emails back to headers, quoting these headers along the way foreach ($emailValues as $fieldName => $value) { $emails = explode(',', $value); $fieldNames = explode(',', $input[$fieldName]); foreach ($fieldNames as $index => &$name) { $name = str_replace('\\', '\\\\', $name); $name = str_replace('"', '\\"', $name); // CRM-5640 -if the name was actually doubly-quoted, // strip these(the next line will add them back); if (substr($name, 0, 2) == '\\"' && substr($name, -2) == '\\"') { $name = substr($name, 2, -2); } } //combine fieldNames and emails. $mergeValues = array(); foreach ($emails as $index => $email) { if ($fieldNames[$index] == 'FIXME_HACK_FOR_NO_NAME') { $mergeValues[] = $email; } else { $mergeValues[] = "\"{$fieldNames[$index]}\" <{$email}>"; } } //finally get values in. $input[$fieldName] = implode(',', $mergeValues); } return $input; }
/** * Build all the data structures needed to build the form. */ public function preProcess() { $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); $context = CRM_Utils_Request::retrieve('context', 'String', $this); //get current client name. $this->assign('currentClientName', CRM_Contact_BAO_Contact::displayName($cid)); //set the context. $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$cid}&selectedChild=case"); if ($context == 'search') { $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); //validate the qfKey $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/case/search', $urlParams); } elseif ($context == 'dashboard') { $url = CRM_Utils_System::url('civicrm/case', 'reset=1'); } elseif (in_array($context, array('dashlet', 'dashletFullscreen'))) { $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); } $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); }
function preProcess() { $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE); $oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, FALSE); if ($oid) { $this->_id = CRM_Utils_Request::retrieve('oid', 'Positive', $this, FALSE); } else { $this->assign('hide_contact', TRUE); $this->_id = $cid; } if (!CRM_Utils_Rule::positiveInteger($this->_id)) { CRM_Core_Error::fatal('We need a valid discount ID for view'); } $this->assign('id', $this->_id); $defaults = array(); $params = array('id' => $this->_id); require_once 'CRM/CiviDiscount/BAO/Item.php'; CRM_CiviDiscount_BAO_Item::retrieve($params, $defaults); require_once 'CRM/CiviDiscount/BAO/Track.php'; if ($cid) { $rows = CRM_CiviDiscount_BAO_Track::getUsageByContact($this->_id); } else { $rows = CRM_CiviDiscount_BAO_Track::getUsageByOrg($this->_id); } $this->assign('rows', $rows); $this->assign('code_details', $defaults); $this->ajaxResponse['tabCount'] = count($rows); if (!empty($defaults['code'])) { CRM_Utils_System::setTitle($defaults['code']); } }
/** * takes an associative array and creates a financial transaction object * * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Core_BAO_FinancialTrxn object * @access public * @static */ static function create(&$params) { $trxn = new CRM_Core_DAO_FinancialTrxn(); $trxn->copyValues($params); require_once 'CRM/Utils/Rule.php'; if (!CRM_Utils_Rule::currencyCode($trxn->currency)) { require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::singleton(); $trxn->currency = $config->defaultCurrency; } // if a transaction already exists for a contribution id, lets get the finTrxnId and entityFinTrxId $fids = self::getFinancialTrxnIds($params['contribution_id'], 'civicrm_contribution'); if ($fids['financialTrxnId']) { $trxn->id = $fids['financialTrxnId']; } $trxn->save(); $contributionAmount = CRM_Utils_Array::value('net_amount', $params); if (!$contributionAmount && isset($params['total_amount'])) { $contributionAmount = $params['total_amount']; } // save to entity_financial_trxn table $entity_financial_trxn_params = array('entity_table' => "civicrm_contribution", 'entity_id' => $params['contribution_id'], 'financial_trxn_id' => $trxn->id, 'amount' => $contributionAmount, 'currency' => $trxn->currency); $entity_trxn =& new CRM_Core_DAO_EntityFinancialTrxn(); $entity_trxn->copyValues($entity_financial_trxn_params); if ($fids['entityFinancialTrxnId']) { $entity_trxn->id = $fids['entityFinancialTrxnId']; } $entity_trxn->save(); return $trxn; }
/** * Build all the data structures needed to build the form. * * @return void */ public function preProcess() { $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); if ($id) { $this->_contributionIds = array($id); $this->_componentClause = " civicrm_contribution.id IN ( {$id} ) "; $this->_single = TRUE; $this->assign('totalSelectedContributions', 1); } else { parent::preProcess(); } // check that all the contribution ids have pending status $query = "\nSELECT count(*)\nFROM civicrm_contribution\nWHERE contribution_status_id != 1\nAND {$this->_componentClause}"; $count = CRM_Core_DAO::singleValueQuery($query); if ($count != 0) { CRM_Core_Error::statusBounce("Please select only online contributions with Completed status."); } // we have all the contribution ids, so now we get the contact ids parent::setContactIDs(); $this->assign('single', $this->_single); $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/contribute/search', $urlParams); $breadCrumb = array(array('url' => $url, 'title' => ts('Search Results'))); CRM_Utils_System::appendBreadCrumb($breadCrumb); CRM_Utils_System::setTitle(ts('Print Contribution Receipts')); }
/** * params must contain at least id=xx & {one of the fields from getfields}=value */ function civicrm_api3_generic_setValue($apiRequest) { $entity = $apiRequest['entity']; $params = $apiRequest['params']; // we can't use _spec, doesn't work with generic civicrm_api3_verify_mandatory($params, NULL, array('id', 'field', 'value')); $id = $params['id']; if (!is_numeric($id)) { return civicrm_api3_create_error(ts('Please enter a number'), array('error_code' => 'NaN', 'field' => "id")); } $field = CRM_Utils_String::munge($params['field']); $value = $params['value']; $fields = civicrm_api($entity, 'getFields', array("version" => 3, "sequential")); // getfields error, shouldn't happen. if ($fields['is_error']) { return $fields; } $fields = $fields['values']; if (!array_key_exists($field, $fields)) { return civicrm_api3_create_error("Param 'field' ({$field}) is invalid. must be an existing field", array("error_code" => "invalid_field", "fields" => array_keys($fields))); } $def = $fields[$field]; if (array_key_exists('required', $def) && empty($value)) { return civicrm_api3_create_error(ts("This can't be empty, please provide a value"), array("error_code" => "required", "field" => $field)); } switch ($def['type']) { case 1: //int if (!is_numeric($value)) { return civicrm_api3_create_error("Param '{$field}' must be a number", array('error_code' => 'NaN')); } case 2: //string require_once "CRM/Utils/Rule.php"; if (!CRM_Utils_Rule::xssString($value)) { return civicrm_api3_create_error(ts('Illegal characters in input (potential scripting attack)'), array('error_code' => 'XSS')); } if (array_key_exists('maxlength', $def)) { $value = substr($value, 0, $def['maxlength']); } break; case 16: //boolean $value = (bool) $value; break; case 4: //date //date default: return civicrm_api3_create_error("Param '{$field}' is of a type not managed yet. Join the API team and help us implement it", array('error_code' => 'NOT_IMPLEMENTED')); } if (CRM_Core_DAO::setFieldValue(_civicrm_api3_get_DAO($entity), $id, $field, $value)) { $entity = array('id' => $id, $field => $value); CRM_Utils_Hook::post('edit', $entity, $id, $entity); return civicrm_api3_create_success($entity); } else { return civicrm_api3_create_error("error assigning {$field}={$value} for {$entity} (id={$id})"); } }
/** * Convert a display name into a potential variable * name that we could use in forms/code * * @param name Name of the string * @return string An equivalent variable name * * @access public * @return string (or null) * @static */ static function titleToVar($title, $maxLength = 31) { $variable = self::munge($title); require_once "CRM/Utils/Rule.php"; if (CRM_Utils_Rule::title($variable, $maxLength)) { return $variable; } return null; }
/** * Convert a display name into a potential variable * name that we could use in forms/code * * @param name Name of the string * * @param int $maxLength * * @return string An equivalent variable name * * @access public * * @return string (or null) * @static */ static function titleToVar($title, $maxLength = 31) { $variable = self::munge($title, '_', $maxLength); if (CRM_Utils_Rule::title($variable, $maxLength)) { return $variable; } // if longer than the maxLength lets just return a substr of the // md5 to prevent errors downstream return substr(md5($title), 0, $maxLength); }
/** * Convert a display name into a potential variable * name that we could use in forms/code * * @param name Name of the string * @return string An equivalent variable name * * @access public * @return string (or null) * @static */ function titleToVar($title) { if (!CRM_Utils_Rule::title($title)) { return null; } $variable = CRM_Utils_String::munge($title); if (CRM_Utils_Rule::variable($variable)) { return $variable; } return null; }
/** * @param string $name * Symbolic name for the check. * @param string $message * Printable message (short or long). * @param string $title * Printable message (short). * @param string $level * The severity of the message. Use PSR-3 log levels. * * @see Psr\Log\LogLevel */ public function __construct($name, $message, $title, $level = \Psr\Log\LogLevel::WARNING) { $this->name = $name; $this->message = $message; $this->title = $title; // Handle non-integer severity levels. if (!CRM_Utils_Rule::integer($level)) { $level = CRM_Utils_Check::severityMap($level); } $this->level = $level; }
/** * Checks wether a contact is a member of a group * * This function is a copy of CRM_Contact_BAO_GroupContact::isContactInGroup but with * a change so that the group contact cache won't be rebuild. Which somehow resulted * in a deadlock * * @param $contact_id * @param $group_id * @return bool */ public static function isContactInGroup($contact_id, $group_id) { if (!CRM_Utils_Rule::positiveInteger($contact_id) || !CRM_Utils_Rule::positiveInteger($group_id)) { return FALSE; } $params = array(array('group', 'IN', array($group_id => 1), 0, 0), array('contact_id', '=', $contact_id, 0, 0)); list($contacts, $_) = CRM_Contact_BAO_Query::apiQuery($params, array('contact_id'), null, null, 0, 1, false, false, true); if (!empty($contacts)) { return TRUE; } return FALSE; }
/** * Form rule to validate the date selector and/or if we should deliver * immediately. * * Warning: if you make changes here, be sure to also make them in * Retry.php * * @param array $params The form values * @return boolean True if either we deliver immediately, or the * date is properly set. * @static */ function &formRule(&$params) { if ($params['now']) { return true; } if (!CRM_Utils_Rule::qfDate($params['start_date'])) { return array('start_date' => ts('Start date is not valid.')); } if (CRM_Utils_Date::format($params['start_date']) < date('YmdHi00')) { return array('start_date' => ts('Start date cannot be earlier than the current time.')); } return true; }
/** * takes an associative array and creates a financial transaction object * * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Contribute_BAO_FinancialTrxn object * @access public * @static */ function create(&$params) { $trxn =& new CRM_Contribute_DAO_FinancialTrxn(); $trxn->copyValues($params); $trxn->domain_id = CRM_Core_Config::domainID(); require_once 'CRM/Utils/Rule.php'; if (!CRM_Utils_Rule::currencyCode($contribution->currency)) { require_once 'CRM/Core/Config.php'; $config =& CRM_Core_Config::singleton(); $contribution->currency = $config->defaultCurrency; } return $trxn->save(); }
/** * Delete a relationship. * * @param array $params * * @return array * API Result Array */ function civicrm_api3_relationship_delete($params) { if (!CRM_Utils_Rule::integer($params['id'])) { return civicrm_api3_create_error('Invalid value for relationship ID'); } $relationBAO = new CRM_Contact_BAO_Relationship(); $relationBAO->id = $params['id']; if (!$relationBAO->find(TRUE)) { return civicrm_api3_create_error('Relationship id is not valid'); } else { $relationBAO->del($params['id']); return civicrm_api3_create_success('Deleted relationship successfully'); } }
/** * Retrieve assignee_id by activity_id * * @param int $id ID of the activity * * @return void * * @access public * */ static function retrieveAssigneeIdsByActivityId($activity_id) { $assigneeArray = array(); if (!CRM_Utils_Rule::positiveInteger($activity_id)) { return $assigneeArray; } $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $sql = "\nSELECT contact_id\nFROM civicrm_activity_contact\nINNER JOIN civicrm_contact ON contact_id = civicrm_contact.id\nWHERE activity_id = %1\nAND record_type_id = {$assigneeID}\nAND civicrm_contact.is_deleted = 0\n"; $assignment = CRM_Core_DAO::executeQuery($sql, array(1 => array($activity_id, 'Integer'))); while ($assignment->fetch()) { $assigneeArray[] = $assignment->contact_id; } return $assigneeArray; }
/** * Process the uploaded file. * * @return void */ public function postProcess() { $params = $this->controller->exportValues($this->_name); $exportParams = $this->controller->exportValues('Select'); $currentPath = CRM_Utils_System::currentPath(); $urlParams = NULL; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams = "&qfKey={$qfKey}"; } //get the button name $buttonName = $this->controller->getButtonName('done'); $buttonName1 = $this->controller->getButtonName('next'); if ($buttonName == '_qf_Map_done') { $this->set('exportColumnCount', NULL); $this->controller->resetPage($this->_name); return CRM_Utils_System::redirect(CRM_Utils_System::url($currentPath, 'force=1' . $urlParams)); } if ($this->controller->exportValue($this->_name, 'addMore')) { $this->set('exportColumnCount', $this->_exportColumnCount); return; } $mapperKeys = $params['mapper'][1]; $checkEmpty = 0; foreach ($mapperKeys as $value) { if ($value[0]) { $checkEmpty++; } } if (!$checkEmpty) { $this->set('mappingId', NULL); CRM_Utils_System::redirect(CRM_Utils_System::url($currentPath, '_qf_Map_display=true' . $urlParams)); } if ($buttonName1 == '_qf_Map_next') { if (!empty($params['updateMapping'])) { //save mapping fields CRM_Core_BAO_Mapping::saveMappingFields($params, $params['mappingId']); } if (!empty($params['saveMapping'])) { $mappingParams = array('name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => $this->get('mappingTypeId')); $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams); //save mapping fields CRM_Core_BAO_Mapping::saveMappingFields($params, $saveMapping->id); } } //get the csv file CRM_Export_BAO_Export_Relationship::exportComponents($this->get('selectAll'), $this->get('componentIds'), $this->get('queryParams'), $this->get(CRM_Utils_Sort::SORT_ORDER), $mapperKeys, $this->get('returnProperties'), $this->get('exportMode'), $this->get('componentClause'), $this->get('componentTable'), $this->get('mergeSameAddress'), $this->get('mergeSameHousehold'), $exportParams); }
/** * Build all the data structures needed to build the form. * * @return void */ public function preProcess() { $session = CRM_Core_Session::singleton(); $this->set('searchRows', ''); $ssID = $this->get('ssID'); if (isset($ssID)) { $urlParams = 'reset=1&force=1&ssID=' . $ssID; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/grant/search', $urlParams); $session->replaceUserContext($url); return; } }
/** * Build all the data structures needed to build the form. */ public function preProcess() { $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE); $lid = CRM_Utils_Request::retrieve('lid', 'Positive', $this, FALSE); $eid = CRM_Utils_Request::retrieve('eid', 'Positive', $this, FALSE); $profileGID = CRM_Utils_Request::retrieve('profileGID', 'Integer', $this, FALSE); $this->assign('profileGID', $profileGID); $context = CRM_Utils_Request::retrieve('context', 'String', $this); $type = 'Contact'; if ($cid) { $ids = array($cid); $this->_single = TRUE; if ($profileGID) { // this does a check and ensures that the user has permission on this profile // CRM-11766 $profileIDs = CRM_Profile_Page_Listings::getProfileContact($profileGID); if (!in_array($cid, $profileIDs)) { CRM_Core_Error::fatal(); } } elseif ($context) { $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $session = CRM_Core_Session::singleton(); $urlString = "civicrm/contact/search/{$context}"; if ($context == 'search') { $urlString = 'civicrm/contact/search'; } $url = CRM_Utils_System::url($urlString, $urlParams); $session->replaceUserContext($url); } } elseif ($eid) { $ids = $eid; $type = 'Event'; } else { if ($profileGID) { $ids = CRM_Profile_Page_Listings::getProfileContact($profileGID); } else { parent::preProcess(); $ids = $this->_contactIds; } } self::createMapXML($ids, $lid, $this, TRUE, $type); $this->assign('single', $this->_single); }
/** * function to retrieve id of target contact by activity_id * * @param int $id ID of the activity * * @return mixed * * @access public * */ static function retrieveTargetIdsByActivityId($activity_id) { $targetArray = array(); require_once 'CRM/Utils/Rule.php'; if (!CRM_Utils_Rule::positiveInteger($activity_id)) { return $targetArray; } $target =& new CRM_Activity_BAO_ActivityTarget(); $target->activity_id = $activity_id; $target->find(); $count = 1; while ($target->fetch()) { $targetArray[$count] = $target->target_contact_id; $count++; } return $targetArray; }
/** * Retrieve assignee_id by activity_id * * @param int $id ID of the activity * * @return void * * @access public * */ static function retrieveAssigneeIdsByActivityId($activity_id) { $assigneeArray = array(); require_once 'CRM/Utils/Rule.php'; if (!CRM_Utils_Rule::positiveInteger($activity_id)) { return $assigneeArray; } $assignment =& new CRM_Activity_BAO_ActivityAssignment(); $assignment->activity_id = $activity_id; $assignment->find(); $count = 1; while ($assignment->fetch()) { $assigneeArray[$count] = $assignment->assignee_contact_id; $count++; } return $assigneeArray; }
/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { parent::preProcess(); require_once 'CRM/Utils/Rule.php'; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= '&qfKey=' . $qfKey; } $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/search/custom', $urlParams); $session->replaceUserContext($url); if (empty($this->_contactIds) || !$session->get('userID')) { CRM_Core_Error::statusBounce(ts("Could not find contacts for voter reservation Or Missing Interviewer contact.")); } $this->_interviewerId = $session->get('userID'); }
/** * takes an associative array and creates a financial transaction object * * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Contribute_BAO_FinancialTrxn object * @access public * @static */ static function create(&$params) { $trxn =& new CRM_Contribute_DAO_FinancialTrxn(); $trxn->copyValues($params); require_once 'CRM/Utils/Rule.php'; if (!CRM_Utils_Rule::currencyCode($trxn->currency)) { require_once 'CRM/Core/Config.php'; $config =& CRM_Core_Config::singleton(); $trxn->currency = $config->defaultCurrency; } // if a transaction already exists for a contribution id, lets get the id $id = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_FinancialTrxn', $trxn->contribution_id, 'id', 'contribution_id'); if ($id) { $trxn->id = $id; } return $trxn->save(); }
/** * File for the CiviCRM APIv3 group functions * * @package CiviCRM_APIv3 * @subpackage API_pcpteams * @copyright CiviCRM LLC (c) 2004-2014 */ function civicrm_api3_pcpteams_create($params) { // since we are allowing html input from the user // we also need to purify it, so lets clean it up // $params['pcp_title'] = $pcp['title']; // $params['pcp_contact_id'] = $pcp['contact_id']; $htmlFields = array('intro_text', 'page_text', 'title'); foreach ($htmlFields as $field) { if (!empty($params[$field])) { $params[$field] = CRM_Utils_String::purifyHTML($params[$field]); } } $entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($params['page_type']); $pcpBlock = new CRM_PCP_DAO_PCPBlock(); $pcpBlock->entity_table = $entity_table; $pcpBlock->entity_id = $params['page_id']; $pcpBlock->find(TRUE); $params['pcp_block_id'] = $pcpBlock->id; $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']); // 1 -> waiting review // 2 -> active / approved (default for now) $params['status_id'] = CRM_Utils_Array::value('status_id', $params, 2); // active by default for now $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 1); $pcp = CRM_Pcpteams_BAO_PCP::create($params, FALSE); //Custom Set $customFields = CRM_Core_BAO_CustomField::getFields('PCP', FALSE, FALSE, NULL, NULL, TRUE); $isCustomValueSet = FALSE; foreach ($customFields as $fieldID => $fieldValue) { list($tableName, $columnName, $cgId) = CRM_Core_BAO_CustomField::getTableColumnGroup($fieldID); if (!empty($params[$columnName]) || !empty($params["custom_{$fieldID}"])) { $isCustomValueSet = TRUE; //FIXME: to find out the custom value exists, set -1 as default now $params["custom_{$fieldID}_-1"] = !empty($params[$columnName]) ? $params[$columnName] : $params["custom_{$fieldID}"]; } } if ($isCustomValueSet) { $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $pcp->id, 'PCP'); CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_pcp', $pcp->id); } //end custom set $values = array(); @_civicrm_api3_object_to_array_unique_fields($pcp, $values[$pcp->id]); return civicrm_api3_create_success($values, $params, 'Pcpteams', 'create'); }
/** * Build all the data structures needed to build the form. * * @return void */ public function preProcess() { $session = CRM_Core_Session::singleton(); //this is done to unset searchRows variable assign during AddToHousehold and AddToOrganization $this->set('searchRows', ''); $ssID = $this->get('ssID'); $path = 'force=1'; if (isset($ssID)) { $path .= "&reset=1&ssID={$ssID}"; } $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); if (CRM_Utils_Rule::qfKey($qfKey)) { $path .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/event/search', $path); $session->replaceUserContext($url); CRM_Utils_System::redirect($url); }
/** * Retrieve assignee_id by activity_id * * @param int $id ID of the activity * * @return void * * @access public * */ static function retrieveAssigneeIdsByActivityId($activity_id) { $assigneeArray = array(); if (!CRM_Utils_Rule::positiveInteger($activity_id)) { return $assigneeArray; } $sql = ' SELECT assignee_contact_id FROM civicrm_activity_assignment JOIN civicrm_contact ON assignee_contact_id = civicrm_contact.id WHERE activity_id = %1 AND civicrm_contact.is_deleted = 0 '; $assignment = CRM_Core_DAO::executeQuery($sql, array(1 => array($activity_id, 'Integer'))); while ($assignment->fetch()) { $assigneeArray[] = $assignment->assignee_contact_id; } return $assigneeArray; }
/** * function to retrieve id of target contact by activity_id * * @param int $id ID of the activity * * @return mixed * * @access public * */ static function retrieveTargetIdsByActivityId($activity_id) { $targetArray = array(); if (!CRM_Utils_Rule::positiveInteger($activity_id)) { return $targetArray; } $sql = ' SELECT target_contact_id FROM civicrm_activity_target JOIN civicrm_contact ON target_contact_id = civicrm_contact.id WHERE activity_id = %1 AND civicrm_contact.is_deleted = 0 '; $target = CRM_Core_DAO::executeQuery($sql, array(1 => array($activity_id, 'Integer'))); while ($target->fetch()) { $targetArray[] = $target->target_contact_id; } return $targetArray; }
/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { $session = CRM_Core_Session::singleton(); //this is done to unset searchRows variable assign during AddToHousehold and AddToOrganization $this->set('searchRows', ''); $context = $this->get('context'); if (in_array($context, array('smog', 'amtg'))) { $urlParams = 'reset=1&force=1&context=smog&gid='; $urlParams .= $context == 'smog' ? $this->get('gid') : $this->get('amtgID'); $session->replaceUserContext(CRM_Utils_System::url('civicrm/group/search', $urlParams)); return; } $ssID = $this->get('ssID'); if ($this->_action == CRM_Core_Action::BASIC) { $fragment = 'search'; } else { if ($this->_action == CRM_Core_Action::PROFILE) { $fragment = 'search/builder'; } else { if ($this->_action == CRM_Core_Action::ADVANCED) { $fragment = 'search/advanced'; } else { $fragment = 'search/custom'; } } } $path = 'force=1'; if (isset($ssID)) { $path .= "&reset=1&ssID={$ssID}"; } if (!CRM_Contact_Form_Search::isSearchContext($context)) { $context = 'search'; } $path .= "&context={$context}"; //set the user context for redirection of task actions $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); require_once 'CRM/Utils/Rule.php'; if (CRM_Utils_Rule::qfKey($qfKey)) { $path .= "&qfKey={$qfKey}"; } $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $path); $session->replaceUserContext($url); return; }
/** * Create relationship type. * * @param array $params * Array per getfields metadata. * * @return array */ function civicrm_api3_relationship_type_create($params) { if (!isset($params['label_a_b'])) { $params['label_a_b'] = $params['name_a_b']; } if (!isset($params['label_b_a'])) { $params['label_b_a'] = $params['name_b_a']; } $ids = array(); if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) { return civicrm_api3_create_error('Invalid value for relationship type ID'); } else { $ids['relationshipType'] = CRM_Utils_Array::value('id', $params); } $relationType = CRM_Contact_BAO_RelationshipType::add($params, $ids); $relType = array(); _civicrm_api3_object_to_array($relationType, $relType[$relationType->id]); return civicrm_api3_create_success($relType, $params, 'RelationshipType', 'create', $relationType); }