/** * takes an associative array and creates a contribution object * * the function extract all the params it needs to initialize the create a * contribution object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Contribute_BAO_Contribution object * @access public * @static */ function add(&$params, &$ids) { require_once 'CRM/Utils/Hook.php'; $duplicates = array(); if (CRM_Contribute_BAO_Contribution::checkDuplicate($params, $duplicates)) { $error =& CRM_Core_Error::singleton(); $d = implode(', ', $duplicates); $error->push(CRM_CORE_ERROR_DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Found matching contribution(s): {$d}"); return $error; } if (CRM_Utils_Array::value('contribution', $ids)) { CRM_Utils_Hook::pre('edit', 'Contribution', $ids['contribution'], $params); } else { CRM_Utils_Hook::pre('create', 'Contribution', null, $params); } $contribution =& new CRM_Contribute_BAO_Contribution(); $contribution->copyValues($params); $contribution->domain_id = CRM_Utils_Array::value('domain', $ids, CRM_Core_Config::domainID()); $contribution->id = CRM_Utils_Array::value('contribution', $ids); 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; } $result = $contribution->save(); if (CRM_Utils_Array::value('contribution', $ids)) { CRM_Utils_Hook::post('edit', 'Contribution', $contribution->id, $contribution); } else { CRM_Utils_Hook::post('create', 'Contribution', $contribution->id, $contribution); } return $result; }
/** * Takes an associative array and creates a contribution object. * * the function extract all the params it needs to initialize the create a * contribution object. the params array could contain additional unused name/value * pairs * * @param array $params * (reference ) an assoc array of name/value pairs. * * @return CRM_Contribute_BAO_Contribution * @todo move hook calls / extended logic to create - requires changing calls to call create not add */ public static function add(&$params) { if (!empty($params['id'])) { CRM_Utils_Hook::pre('edit', 'ContributionRecur', $params['id'], $params); } else { CRM_Utils_Hook::pre('create', 'ContributionRecur', NULL, $params); } // make sure we're not creating a new recurring contribution with the same transaction ID // or invoice ID as an existing recurring contribution $duplicates = array(); if (self::checkDuplicate($params, $duplicates)) { $error = CRM_Core_Error::singleton(); $d = implode(', ', $duplicates); $error->push(CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Found matching recurring contribution(s): {$d}"); return $error; } $recurring = new CRM_Contribute_BAO_ContributionRecur(); $recurring->copyValues($params); $recurring->id = CRM_Utils_Array::value('id', $params); // set currency for CRM-1496 if (empty($params['id']) && !isset($recurring->currency)) { $config = CRM_Core_Config::singleton(); $recurring->currency = $config->defaultCurrency; } $result = $recurring->save(); if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'ContributionRecur', $recurring->id, $recurring); } else { CRM_Utils_Hook::post('create', 'ContributionRecur', $recurring->id, $recurring); } if (!empty($params['custom']) && is_array($params['custom'])) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution_recur', $recurring->id); } return $result; }
/** * takes an associative array and creates a contribution object * * the function extract all the params it needs to initialize the create a * contribution object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Contribute_BAO_Contribution object * @access public * @static */ static function add(&$params, &$ids) { if (empty($params)) { return; } $duplicates = array(); if (self::checkDuplicate($params, $duplicates, CRM_Utils_Array::value('contribution', $ids))) { $error =& CRM_Core_Error::singleton(); $d = implode(', ', $duplicates); $error->push(CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Duplicate error - existing contribution record(s) have a matching Transaction ID or Invoice ID. Contribution record ID(s) are: {$d}"); return $error; } // first clean up all the money fields $moneyFields = array('total_amount', 'net_amount', 'fee_amount', 'non_deductible_amount'); //if priceset is used, no need to cleanup money if (CRM_UTils_Array::value('skipCleanMoney', $params)) { unset($moneyFields[0]); } foreach ($moneyFields as $field) { if (isset($params[$field])) { $params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]); } } if (CRM_Utils_Array::value('payment_instrument_id', $params)) { require_once 'CRM/Contribute/PseudoConstant.php'; $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument('name'); if ($params['payment_instrument_id'] != array_search('Check', $paymentInstruments)) { $params['check_number'] = 'null'; } } require_once 'CRM/Utils/Hook.php'; if (CRM_Utils_Array::value('contribution', $ids)) { CRM_Utils_Hook::pre('edit', 'Contribution', $ids['contribution'], $params); } else { CRM_Utils_Hook::pre('create', 'Contribution', null, $params); } $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->copyValues($params); $contribution->id = CRM_Utils_Array::value('contribution', $ids); // also add financial_trxn details as part of fix for CRM-4724 $contribution->trxn_result_code = CRM_Utils_Array::value('trxn_result_code', $params); $contribution->payment_processor = CRM_Utils_Array::value('payment_processor', $params); 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; } $result = $contribution->save(); // reset the group contact cache for this group require_once 'CRM/Contact/BAO/GroupContactCache.php'; CRM_Contact_BAO_GroupContactCache::remove(); if (CRM_Utils_Array::value('contribution', $ids)) { CRM_Utils_Hook::post('edit', 'Contribution', $contribution->id, $contribution); } else { CRM_Utils_Hook::post('create', 'Contribution', $contribution->id, $contribution); } return $result; }
function &error($errorCode = null, $errorMessage = null) { $e =& CRM_Core_Error::singleton(); if ($errorCode) { $e->push($errorCode, 0, null, $errorMessage); } else { $e->push(9001, 0, null, 'Unknown System Error.'); } return $e; }
/** * takes an associative array and creates a contribution object * * the function extract all the params it needs to initialize the create a * contribution object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Contribute_BAO_Contribution object * @access public * @static */ static function add(&$params, &$ids) { $duplicates = array(); if (self::checkDuplicate($params, $duplicates)) { $error =& CRM_Core_Error::singleton(); $d = implode(', ', $duplicates); $error->push(CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Found matching contribution(s): {$d}"); return $error; } $recurring =& new CRM_Contribute_BAO_ContributionRecur(); $recurring->copyValues($params); $recurring->id = CRM_Utils_Array::value('contribution', $ids); return $recurring->save(); }
/** * Takes an associative array and creates a contribution object. * * the function extract all the params it needs to initialize the create a * contribution object. the params array could contain additional unused name/value * pairs * * @param array $params * (reference ) an assoc array of name/value pairs. * @param array $ids * The array that holds all the db ids. * * @return CRM_Contribute_BAO_Contribution|void */ public static function add(&$params, $ids = array()) { if (empty($params)) { return NULL; } //per http://wiki.civicrm.org/confluence/display/CRM/Database+layer we are moving away from $ids array $contributionID = CRM_Utils_Array::value('contribution', $ids, CRM_Utils_Array::value('id', $params)); $duplicates = array(); if (self::checkDuplicate($params, $duplicates, $contributionID)) { $error = CRM_Core_Error::singleton(); $d = implode(', ', $duplicates); $error->push(CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Duplicate error - existing contribution record(s) have a matching Transaction ID or Invoice ID. Contribution record ID(s) are: {$d}"); return $error; } // first clean up all the money fields $moneyFields = array('total_amount', 'net_amount', 'fee_amount', 'non_deductible_amount'); //if priceset is used, no need to cleanup money if (!empty($params['skipCleanMoney'])) { unset($moneyFields[0]); } foreach ($moneyFields as $field) { if (isset($params[$field])) { $params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]); } } //set defaults in create mode if (!$contributionID) { CRM_Core_DAO::setCreateDefaults($params, self::getDefaults()); } self::calculateMissingAmountParams($params, $contributionID); if (!empty($params['payment_instrument_id'])) { $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument('name'); if ($params['payment_instrument_id'] != array_search('Check', $paymentInstruments)) { $params['check_number'] = 'null'; } } $setPrevContribution = TRUE; // CRM-13964 partial payment if (!empty($params['partial_payment_total']) && !empty($params['partial_amount_pay'])) { $partialAmtTotal = $params['partial_payment_total']; $partialAmtPay = $params['partial_amount_pay']; $params['total_amount'] = $partialAmtTotal; if ($partialAmtPay < $partialAmtTotal) { $params['contribution_status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Partially paid', 'name'); $params['is_pay_later'] = 0; $setPrevContribution = FALSE; } } if ($contributionID) { CRM_Utils_Hook::pre('edit', 'Contribution', $contributionID, $params); } else { CRM_Utils_Hook::pre('create', 'Contribution', NULL, $params); } $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->copyValues($params); $contribution->id = $contributionID; if (empty($contribution->id)) { // (only) on 'create', make sure that a valid currency is set (CRM-16845) if (!CRM_Utils_Rule::currencyCode($contribution->currency)) { $config = CRM_Core_Config::singleton(); $contribution->currency = $config->defaultCurrency; } } if ($contributionID && $setPrevContribution) { $params['prevContribution'] = self::getValues(array('id' => $contributionID), CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray); } $result = $contribution->save(); // Add financial_trxn details as part of fix for CRM-4724 $contribution->trxn_result_code = CRM_Utils_Array::value('trxn_result_code', $params); $contribution->payment_processor = CRM_Utils_Array::value('payment_processor', $params); //add Account details $params['contribution'] = $contribution; self::recordFinancialAccounts($params); // reset the group contact cache for this group CRM_Contact_BAO_GroupContactCache::remove(); if ($contributionID) { CRM_Utils_Hook::post('edit', 'Contribution', $contribution->id, $contribution); } else { CRM_Utils_Hook::post('create', 'Contribution', $contribution->id, $contribution); } return $result; }
/** * @param $message * @param int $code * @param string $level * @param array $params * * @return object */ public static function createError($message, $code = 8000, $level = 'Fatal', $params = NULL) { $error = CRM_Core_Error::singleton(); $error->push($code, $level, array($params), $message); return $error; }
/** * Process the mapped fields and map it into the uploaded file * preview the file and extract some summary statistics * * @return void * @access public */ public function postProcessOld() { $doGeocodeAddress = $this->controller->exportValue('DataSource', 'doGeocodeAddress'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); $newGroupName = $this->controller->exportValue($this->_name, 'newGroupName'); $newGroupDesc = $this->controller->exportValue($this->_name, 'newGroupDesc'); $groups = $this->controller->exportValue($this->_name, 'groups'); $allGroups = $this->get('groups'); $newTagName = $this->controller->exportValue($this->_name, 'newTagName'); $newTagDesc = $this->controller->exportValue($this->_name, 'newTagDesc'); $tag = $this->controller->exportValue($this->_name, 'tag'); $allTags = $this->get('tag'); $mapper = $this->controller->exportValue('MapField', 'mapper'); $mapperKeys = array(); $mapperLocTypes = array(); $mapperPhoneTypes = array(); $mapperRelated = array(); $mapperRelatedContactType = array(); $mapperRelatedContactDetails = array(); $mapperRelatedContactLocType = array(); $mapperRelatedContactPhoneType = array(); foreach ($mapper as $key => $value) { $mapperKeys[$key] = $mapper[$key][0]; if (is_numeric($mapper[$key][1])) { $mapperLocTypes[$key] = $mapper[$key][1]; } else { $mapperLocTypes[$key] = NULL; } if (CRM_Utils_Array::value($key, $mapperKeys) == 'phone') { $mapperPhoneTypes[$key] = $mapper[$key][2]; } else { $mapperPhoneTypes[$key] = NULL; } list($id, $first, $second) = explode('_', $mapper[$key][0]); if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') { $relationType = new CRM_Contact_DAO_RelationshipType(); $relationType->id = $id; $relationType->find(TRUE); $fieldName = "contact_type_{$second}"; $mapperRelatedContactType[$key] = $relationType->{$fieldName}; $mapperRelated[$key] = $mapper[$key][0]; $mapperRelatedContactDetails[$key] = $mapper[$key][1]; $mapperRelatedContactLocType[$key] = $mapper[$key][2]; $mapperRelatedContactPhoneType[$key] = $mapper[$key][3]; } else { $mapperRelated[$key] = NULL; $mapperRelatedContactType[$key] = NULL; $mapperRelatedContactDetails[$key] = NULL; $mapperRelatedContactLocType[$key] = NULL; $mapperRelatedContactPhoneType[$key] = NULL; } } $parser = new CRM_Contact_Import_Parser_Contact($mapperKeys, $mapperLocTypes, $mapperPhoneTypes, $mapperRelated, $mapperRelatedContactType, $mapperRelatedContactDetails, $mapperRelatedContactLocType, $mapperRelatedContactPhoneType); $mapFields = $this->get('fields'); $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); foreach ($mapper as $key => $value) { $header = array(); list($id, $first, $second) = explode('_', $mapper[$key][0]); if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') { $relationType = new CRM_Contact_DAO_RelationshipType(); $relationType->id = $id; $relationType->find(TRUE); $header[] = $relationType->name_a_b; $header[] = ucwords(str_replace("_", " ", $mapper[$key][1])); if (isset($mapper[$key][2])) { $header[] = $locationTypes[$mapper[$key][2]]; } if (isset($mapper[$key][3])) { $header[] = $phoneTypes[$mapper[$key][3]]; } } else { if (isset($mapFields[$mapper[$key][0]])) { $header[] = $mapFields[$mapper[$key][0]]; if (isset($mapper[$key][1])) { $header[] = $locationTypes[$mapper[$key][1]]; } if (isset($mapper[$key][2])) { $header[] = $phoneTypes[$mapper[$key][2]]; } } } $mapperFields[] = implode(' - ', $header); } $tableName = $this->get('importTableName'); //print "Running parser on table: $tableName<br/>"; $parser->run($tableName, $mapperFields, CRM_Import_Parser::MODE_IMPORT, $this->get('contactType'), $this->get('primaryKeyName'), $this->get('statusFieldName'), $onDuplicate, $this->get('statusID'), $this->get('totalRowCount'), $doGeocodeAddress, CRM_Contact_Import_Parser::DEFAULT_TIMEOUT, $this->get('contactSubType'), $this->get('dedupe')); // add the new contacts to selected groups $contactIds =& $parser->getImportedContacts(); // add the new related contacts to selected groups $relatedContactIds =& $parser->getRelatedImportedContacts(); $this->set('relatedCount', count($relatedContactIds)); $newGroupId = NULL; //changed below if-statement "if ($newGroup) {" to "if ($newGroupName) {" if ($newGroupName) { /* Create a new group */ $gParams = array('name' => $newGroupName, 'title' => $newGroupName, 'description' => $newGroupDesc, 'is_active' => TRUE); $group = CRM_Contact_BAO_Group::create($gParams); $groups[] = $newGroupId = $group->id; } if (is_array($groups)) { $groupAdditions = array(); foreach ($groups as $groupId) { $addCount = CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId); if (!empty($relatedContactIds)) { $addRelCount = CRM_Contact_BAO_GroupContact::addContactsToGroup($relatedContactIds, $groupId); } $totalCount = $addCount[1] + $addRelCount[1]; if ($groupId == $newGroupId) { $name = $newGroupName; $new = TRUE; } else { $name = $allGroups[$groupId]; $new = FALSE; } $groupAdditions[] = array('url' => CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $groupId), 'name' => $name, 'added' => $totalCount, 'notAdded' => $addCount[2] + $addRelCount[2], 'new' => $new); } $this->set('groupAdditions', $groupAdditions); } $newTagId = NULL; if ($newTagName) { /* Create a new Tag */ $tagParams = array('name' => $newTagName, 'title' => $newTagName, 'description' => $newTagDesc, 'is_active' => TRUE); $id = array(); $addedTag = CRM_Core_BAO_Tag::add($tagParams, $id); $tag[$addedTag->id] = 1; } //add Tag to Import if (is_array($tag)) { $tagAdditions = array(); foreach ($tag as $tagId => $val) { $addTagCount = CRM_Core_BAO_EntityTag::addContactsToTag($contactIds, $tagId); if (!empty($relatedContactIds)) { $addRelTagCount = CRM_Core_BAO_EntityTag::addContactsToTag($relatedContactIds, $tagId); } $totalTagCount = $addTagCount[1] + $addRelTagCount[1]; if ($tagId == $addedTag->id) { $tagName = $newTagName; $new = TRUE; } else { $tagName = $allTags[$tagId]; $new = FALSE; } $tagAdditions[] = array('url' => CRM_Utils_System::url('civicrm/contact/search', 'reset=1&force=1&context=smog&id=' . $tagId), 'name' => $tagName, 'added' => $totalTagCount, 'notAdded' => $addTagCount[2] + $addRelTagCount[2], 'new' => $new); } $this->set('tagAdditions', $tagAdditions); } // add all the necessary variables to the form $parser->set($this, CRM_Import_Parser::MODE_IMPORT); // check if there is any error occured $errorStack = CRM_Core_Error::singleton(); $errors = $errorStack->getErrors(); $errorMessage = array(); if (is_array($errors)) { foreach ($errors as $key => $value) { $errorMessage[] = $value['message']; } // there is no fileName since this is a sql import // so fudge it $config = CRM_Core_Config::singleton(); $errorFile = $config->uploadDir . "sqlImport.error.log"; if ($fd = fopen($errorFile, 'w')) { fwrite($fd, implode('\\n', $errorMessage)); } fclose($fd); $this->set('errorFile', $errorFile); $urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Contact_Import_Parser'; $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlparams)); $urlParams = 'type=' . CRM_Import_Parser::CONFLICT . '&parser=CRM_Contact_Import_Parser'; $this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); $urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Contact_Import_Parser'; $this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); } }
function &error($error = null) { $e =& CRM_Core_Error::singleton(); if (is_object($error)) { $e->push($error->getResponseCode(), 0, null, $error->getMessage()); } elseif (is_string($error)) { $e->push(9002, 0, null, $error); } else { $e->push(9001, 0, null, "Unknown System Error."); } return $e; }
/** * Process the mapped fields and map it into the uploaded file * preview the file and extract some summary statistics * * @return void * @access public */ public function postProcess() { $fileName = $this->controller->exportValue('UploadFile', 'uploadFile'); $skipColumnHeader = $this->controller->exportValue('UploadFile', 'skipColumnHeader'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); $config =& CRM_Core_Config::singleton(); $seperator = $config->fieldSeparator; $mapper = $this->controller->exportValue('MapField', 'mapper'); $mapperKeys = array(); $mapperLocType = array(); $mapperPhoneType = array(); foreach ($mapper as $key => $value) { $mapperKeys[$key] = $mapper[$key][0]; if (is_numeric($mapper[$key][1])) { $mapperLocType[$key] = $mapper[$key][1]; } else { $mapperLocType[$key] = null; } if (!is_numeric($mapper[$key][2])) { $mapperPhoneType[$key] = $mapper[$key][2]; } else { $mapperPhoneType[$key] = null; } } $parser =& new CRM_Activity_Import_Parser_Activity($mapperKeys, $mapperLocType, $mapperPhoneType); $mapFields = $this->get('fields'); foreach ($mapper as $key => $value) { $header = array(); if (isset($mapFields[$mapper[$key][0]])) { $header[] = $mapFields[$mapper[$key][0]]; } $mapperFields[] = implode(' - ', $header); } $parser->run($fileName, $seperator, $mapperFields, $skipColumnHeader, CRM_Activity_Import_Parser::MODE_IMPORT, $onDuplicate); // add all the necessary variables to the form $parser->set($this, CRM_Activity_Import_Parser::MODE_IMPORT); // check if there is any error occured $errorStack =& CRM_Core_Error::singleton(); $errors = $errorStack->getErrors(); $errorMessage = array(); if (is_array($errors)) { foreach ($errors as $key => $value) { $errorMessage[] = $value['message']; } $errorFile = $fileName['name'] . '.error.log'; if ($fd = fopen($errorFile, 'w')) { fwrite($fd, implode('\\n', $errorMessage)); } fclose($fd); $this->set('errorFile', $errorFile); $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', 'type=1&realm=activity')); $this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', 'type=2&realm=activity')); $this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', 'type=4&realm=activity')); } }
/** * Hash_call: Function to perform the API call to PayPal using API signature * @methodName is name of API method. * @nvpStr is nvp string. * returns an associtive array containing the response from the server. */ public function invokeAPI($args, $url = NULL) { if ($url === NULL) { if (empty($this->_paymentProcessor['url_api'])) { CRM_Core_Error::fatal(ts('Please set the API URL. Please refer to the documentation for more details')); } $url = $this->_paymentProcessor['url_api'] . 'nvp'; } if (!function_exists('curl_init')) { CRM_Core_Error::fatal("curl functions NOT available."); } //setting the curl parameters. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_VERBOSE, 1); //turning off the server and peer verification(TrustManager Concept). curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL')); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL') ? 2 : 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); $p = array(); foreach ($args as $n => $v) { $p[] = "{$n}=" . urlencode($v); } //NVPRequest for submitting to server $nvpreq = implode('&', $p); //setting the nvpreq as POST FIELD to curl curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq); //getting response from server $response = curl_exec($ch); //converting NVPResponse to an Associative Array $result = self::deformat($response); if (curl_errno($ch)) { $e = CRM_Core_Error::singleton(); $e->push(curl_errno($ch), 0, NULL, curl_error($ch)); return $e; } else { curl_close($ch); } if (strtolower($result['ack']) != 'success' && strtolower($result['ack']) != 'successwithwarning') { $e = CRM_Core_Error::singleton(); $e->push($result['l_errorcode0'], 0, NULL, "{$result['l_shortmessage0']} {$result['l_longmessage0']}"); return $e; } return $result; }
/** * hash_call: Function to perform the API call to PayPal using API signature * @paymentProcessor is the array of payment processor settings value. * @searchParamsnvpStr is the array of search params. * returns an associtive array containing the response from the server. * @param $paymentProcessor * @param $searchParams * @return array|object * @throws \Exception */ function invokeAPI($paymentProcessor, $searchParams) { $merchantID = $paymentProcessor['user_name']; $merchantKey = $paymentProcessor['password']; $siteURL = rtrim(str_replace('https://', '', $paymentProcessor['url_site']), '/'); $url = "https://{$merchantID}:{$merchantKey}@{$siteURL}/api/checkout/v2/reports/Merchant/{$merchantID}"; $xml = self::buildXMLQuery($searchParams); if (!function_exists('curl_init')) { CRM_Core_Error::fatal("curl functions NOT available."); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_VERBOSE, 1); //turning off the server and peer verification(TrustManager Concept). curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); //setting the nvpreq as POST FIELD to curl curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); //getting response from server $xmlResponse = curl_exec($ch); // strip slashes if needed if (get_magic_quotes_gpc()) { $xmlResponse = stripslashes($xmlResponse); } if (curl_errno($ch)) { $e =& CRM_Core_Error::singleton(); $e->push(curl_errno($ch), 0, NULL, curl_error($ch)); return $e; } else { curl_close($ch); } return self::getArrayFromXML($xmlResponse); }
/** * Process the mapped fields and map it into the uploaded file * preview the file and extract some summary statistics * * @return void * @access public */ public function postProcess() { $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); $config = CRM_Core_Config::singleton(); $seperator = $config->fieldSeparator; $mapper = $this->controller->exportValue('MapField', 'mapper'); $mapperKeys = array(); foreach ($mapper as $key => $value) { $mapperKeys[$key] = $mapper[$key][0]; } $parser = new CRM_Event_Import_Parser_Participant($mapperKeys); $mapFields = $this->get('fields'); foreach ($mapper as $key => $value) { $header = array(); if (isset($mapFields[$mapper[$key][0]])) { $header[] = $mapFields[$mapper[$key][0]]; } $mapperFields[] = implode(' - ', $header); } $parser->run($fileName, $seperator, $mapperFields, $skipColumnHeader, CRM_Import_Parser::MODE_IMPORT, $this->get('contactType'), $onDuplicate); // add all the necessary variables to the form $parser->set($this, CRM_Import_Parser::MODE_IMPORT); // check if there is any error occured $errorStack = CRM_Core_Error::singleton(); $errors = $errorStack->getErrors(); $errorMessage = array(); if (is_array($errors)) { foreach ($errors as $key => $value) { $errorMessage[] = $value['message']; } $errorFile = $fileName['name'] . '.error.log'; if ($fd = fopen($errorFile, 'w')) { fwrite($fd, implode('\\n', $errorMessage)); } fclose($fd); $this->set('errorFile', $errorFile); $urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Event_Import_Parser'; $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); $urlParams = 'type=' . CRM_Import_Parser::CONFLICT . '&parser=CRM_Event_Import_Parser'; $this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); $urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Event_Import_Parser'; $this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); } }
/** * Error reporting mechanism * * @param string $message Error Message * @param int $code Error Code * @param CRM_Core_DAO $dao A data access object on which we perform a rollback if non - empty * @return void * @access public */ function error($message, $code = null, $dao = null) { if ($dao) { $dao->query('ROLLBACK'); } $error =& CRM_Core_Error::singleton(); $error->push($code, $message); }
/** * Takes an associative array and creates a contribution object. * * the function extract all the params it needs to initialize the create a * contribution object. the params array could contain additional unused name/value * pairs * * @param array $params * (reference ) an assoc array of name/value pairs. * @param array $ids * The array that holds all the db ids. * * @return CRM_Contribute_BAO_Contribution|void */ public static function add(&$params, $ids = array()) { if (empty($params)) { return NULL; } //per http://wiki.civicrm.org/confluence/display/CRM/Database+layer we are moving away from $ids array $contributionID = CRM_Utils_Array::value('contribution', $ids, CRM_Utils_Array::value('id', $params)); $duplicates = array(); if (self::checkDuplicate($params, $duplicates, $contributionID)) { $error = CRM_Core_Error::singleton(); $d = implode(', ', $duplicates); $error->push(CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Duplicate error - existing contribution record(s) have a matching Transaction ID or Invoice ID. Contribution record ID(s) are: {$d}"); return $error; } // first clean up all the money fields $moneyFields = array('total_amount', 'net_amount', 'fee_amount', 'non_deductible_amount'); //if priceset is used, no need to cleanup money if (!empty($params['skipCleanMoney'])) { unset($moneyFields[0]); } foreach ($moneyFields as $field) { if (isset($params[$field])) { $params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]); } } //set defaults in create mode if (!$contributionID) { CRM_Core_DAO::setCreateDefaults($params, self::getDefaults()); } $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); //if contribution is created with cancelled or refunded status, add credit note id if (!empty($params['contribution_status_id'])) { // @todo - should we include Chargeback? If so use self::isContributionStatusNegative($params['contribution_status_id']) if ($params['contribution_status_id'] == array_search('Refunded', $contributionStatus) || $params['contribution_status_id'] == array_search('Cancelled', $contributionStatus)) { if (empty($params['creditnote_id']) || $params['creditnote_id'] == "null") { $params['creditnote_id'] = self::createCreditNoteId(); } } } else { // Since the fee amount is expecting this (later on) ensure it is always set. // It would only not be set for an update where it is unchanged. $params['contribution_status_id'] = civicrm_api3('Contribution', 'getvalue', array('id' => $contributionID, 'return' => 'contribution_status_id')); } if (!$contributionID && CRM_Utils_Array::value('membership_id', $params) && self::checkContributeSettings('deferred_revenue_enabled')) { $memberStartDate = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $params['membership_id'], 'start_date'); if ($memberStartDate) { $params['revenue_recognition_date'] = date('Ymd', strtotime($memberStartDate)); } } self::calculateMissingAmountParams($params, $contributionID); if (!empty($params['payment_instrument_id'])) { $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument('name'); if ($params['payment_instrument_id'] != array_search('Check', $paymentInstruments)) { $params['check_number'] = 'null'; } } $setPrevContribution = TRUE; // CRM-13964 partial payment if (!empty($params['partial_payment_total']) && !empty($params['partial_amount_pay'])) { $partialAmtTotal = $params['partial_payment_total']; $partialAmtPay = $params['partial_amount_pay']; $params['total_amount'] = $partialAmtTotal; if ($partialAmtPay < $partialAmtTotal) { $params['contribution_status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Partially paid', 'name'); $params['is_pay_later'] = 0; $setPrevContribution = FALSE; } } if ($contributionID && $setPrevContribution) { $params['prevContribution'] = self::getOriginalContribution($contributionID); } // CRM-16189 CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params, $contributionID); if ($contributionID && !empty($params['revenue_recognition_date']) && !empty($params['prevContribution']) && !($contributionStatus[$params['prevContribution']->contribution_status_id] == 'Pending') && !self::allowUpdateRevenueRecognitionDate($contributionID)) { unset($params['revenue_recognition_date']); } if (!isset($params['tax_amount']) && $setPrevContribution && (isset($params['total_amount']) || isset($params['financial_type_id']))) { $params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params); } if ($contributionID) { CRM_Utils_Hook::pre('edit', 'Contribution', $contributionID, $params); } else { CRM_Utils_Hook::pre('create', 'Contribution', NULL, $params); } $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->copyValues($params); $contribution->id = $contributionID; if (empty($contribution->id)) { // (only) on 'create', make sure that a valid currency is set (CRM-16845) if (!CRM_Utils_Rule::currencyCode($contribution->currency)) { $contribution->currency = CRM_Core_Config::singleton()->defaultCurrency; } } $result = $contribution->save(); // Add financial_trxn details as part of fix for CRM-4724 $contribution->trxn_result_code = CRM_Utils_Array::value('trxn_result_code', $params); $contribution->payment_processor = CRM_Utils_Array::value('payment_processor', $params); //add Account details $params['contribution'] = $contribution; self::recordFinancialAccounts($params); if (self::isUpdateToRecurringContribution($params)) { CRM_Contribute_BAO_ContributionRecur::updateOnNewPayment(!empty($params['contribution_recur_id']) ? $params['contribution_recur_id'] : $params['prevContribution']->contribution_recur_id, $contributionStatus[$params['contribution_status_id']]); } CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); if ($contributionID) { CRM_Utils_Hook::post('edit', 'Contribution', $contribution->id, $contribution); } else { CRM_Utils_Hook::post('create', 'Contribution', $contribution->id, $contribution); } return $result; }
/** * @param null $errorCode * @param null $errorMessage * * @return object */ public function &error($errorCode = NULL, $errorMessage = NULL) { $e = CRM_Core_Error::singleton(); if ($errorCode) { if ($errorCode == '101' || $errorCode == '102') { $display_error = ts('Card declined by bank. Please try with a different card.'); } elseif ($errorCode == '103') { $display_error = ts('Card reported lost or stolen. This incident will be reported.'); } elseif ($errorCode == '501') { $display_error = ts("It appears that this transaction is a duplicate. Have you already submitted the form once? If so there may have been a connection problem. Check your email for a receipt for this transaction. If you do not receive a receipt within 2 hours you can try your transaction again. If you continue to have problems please contact the site administrator."); } elseif ($errorCode == '509') { $display_error = $errorMessage; } else { $display_error = ts('We were unable to process your payment at this time. Please try again later.'); } $e->push($errorCode, 0, NULL, $display_error); } else { $e->push(9001, 0, NULL, ts('We were unable to process your payment at this time. Please try again later.')); } return $e; }
/** * takes an associative array and creates a contribution object * * the function extract all the params it needs to initialize the create a * contribution object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Contribute_BAO_Contribution object * @access public * @static */ static function add(&$params, $ids = array()) { if (empty($params)) { return; } //per http://wiki.civicrm.org/confluence/display/CRM/Database+layer we are moving away from $ids array $contributionID = CRM_Utils_Array::value('contribution', $ids, CRM_Utils_Array::value('id', $params)); $duplicates = array(); if (self::checkDuplicate($params, $duplicates, $contributionID)) { $error = CRM_Core_Error::singleton(); $d = implode(', ', $duplicates); $error->push(CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Duplicate error - existing contribution record(s) have a matching Transaction ID or Invoice ID. Contribution record ID(s) are: {$d}"); return $error; } // first clean up all the money fields $moneyFields = array('total_amount', 'net_amount', 'fee_amount', 'non_deductible_amount'); //if priceset is used, no need to cleanup money if (CRM_Utils_Array::value('skipCleanMoney', $params)) { unset($moneyFields[0]); } foreach ($moneyFields as $field) { if (isset($params[$field])) { $params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]); } } // CRM-13420, set payment instrument to default if payment_instrument_id is empty if (!$contributionID && !CRM_Utils_Array::value('payment_instrument_id', $params)) { $params['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1')); } if (CRM_Utils_Array::value('payment_instrument_id', $params)) { $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument('name'); if ($params['payment_instrument_id'] != array_search('Check', $paymentInstruments)) { $params['check_number'] = 'null'; } } // contribution status is missing, choose Completed as default status // do this for create mode only if (!$contributionID && !CRM_Utils_Array::value('contribution_status_id', $params)) { $params['contribution_status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'); } if ($contributionID) { CRM_Utils_Hook::pre('edit', 'Contribution', $contributionID, $params); } else { CRM_Utils_Hook::pre('create', 'Contribution', NULL, $params); } $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->copyValues($params); $contribution->id = $contributionID; if (!CRM_Utils_Rule::currencyCode($contribution->currency)) { $config = CRM_Core_Config::singleton(); $contribution->currency = $config->defaultCurrency; } if ($contributionID) { $params['prevContribution'] = self::getValues(array('id' => $contributionID), CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray); } $result = $contribution->save(); // Add financial_trxn details as part of fix for CRM-4724 $contribution->trxn_result_code = CRM_Utils_Array::value('trxn_result_code', $params); $contribution->payment_processor = CRM_Utils_Array::value('payment_processor', $params); //add Account details $params['contribution'] = $contribution; self::recordFinancialAccounts($params); // reset the group contact cache for this group CRM_Contact_BAO_GroupContactCache::remove(); if ($contributionID) { CRM_Utils_Hook::post('edit', 'Contribution', $contribution->id, $contribution); } else { CRM_Utils_Hook::post('create', 'Contribution', $contribution->id, $contribution); } return $result; }
/** * Process the mapped fields and map it into the uploaded file * preview the file and extract some summary statistics * * @return void */ public function postProcess() { $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); $config = CRM_Core_Config::singleton(); $seperator = $config->fieldSeparator; $mapper = $this->controller->exportValue('MapField', 'mapper'); $mapperKeys = array(); $mapperLocType = array(); $mapperPhoneType = array(); // Note: we keep the multi-dimension array (even thought it's not // needed in the case of memberships import) so that we can merge // the common code with contacts import later and subclass contact // and membership imports from there foreach ($mapper as $key => $value) { $mapperKeys[$key] = $mapper[$key][0]; if (!empty($mapper[$key][1]) && is_numeric($mapper[$key][1])) { $mapperLocType[$key] = $mapper[$key][1]; } else { $mapperLocType[$key] = NULL; } if (!empty($mapper[$key][2]) && !is_numeric($mapper[$key][2])) { $mapperPhoneType[$key] = $mapper[$key][2]; } else { $mapperPhoneType[$key] = NULL; } } $parser = new CRM_Member_Import_Parser_Membership($mapperKeys, $mapperLocType, $mapperPhoneType); $mapFields = $this->get('fields'); foreach ($mapper as $key => $value) { $header = array(); if (isset($mapFields[$mapper[$key][0]])) { $header[] = $mapFields[$mapper[$key][0]]; } $mapperFields[] = implode(' - ', $header); } $parser->run($fileName, $seperator, $mapperFields, $skipColumnHeader, CRM_Import_Parser::MODE_IMPORT, $this->get('contactType'), $onDuplicate); // add all the necessary variables to the form $parser->set($this, CRM_Import_Parser::MODE_IMPORT); // check if there is any error occurred $errorStack = CRM_Core_Error::singleton(); $errors = $errorStack->getErrors(); $errorMessage = array(); if (is_array($errors)) { foreach ($errors as $key => $value) { $errorMessage[] = $value['message']; } $errorFile = $fileName['name'] . '.error.log'; if ($fd = fopen($errorFile, 'w')) { fwrite($fd, implode('\\n', $errorMessage)); } fclose($fd); $this->set('errorFile', $errorFile); $urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Member_Import_Parser'; $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); $urlParams = 'type=' . CRM_Import_Parser::CONFLICT . '&parser=CRM_Member_Import_Parser'; $this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); $urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Member_Import_Parser'; $this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); } }
function &error($error = NULL) { $e = CRM_Core_Error::singleton(); if (is_object($error)) { $e->push($error->getResponseCode(), 0, NULL, $error->getMessage()); } elseif ($error && is_numeric($error)) { $e->push($error, 0, NULL, $this->errorString($error)); } elseif (is_string($error)) { $e->push(9002, 0, NULL, $error); } else { $e->push(9001, 0, NULL, "Unknown System Error."); } return $e; }
/** * Process the mapped fields and map it into the uploaded file * preview the file and extract some summary statistics * * @return void * @access public */ function postProcess() { $fileName = $this->controller->exportValue('UploadFile', 'uploadFile'); $skipColumnHeader = $this->controller->exportValue('UploadFile', 'skipColumnHeader'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); $seperator = ','; $mapper = $this->controller->exportValue('MapField', 'mapper'); $mapperKeys = array(); $mapperLocType = array(); $mapperPhoneType = array(); // Note: we keep the multi-dimension array (even thought it's not // needed in the case of contributions import) so that we can merge // the common code with contacts import later and subclass contact // and contribution imports from there foreach ($mapper as $key => $value) { $mapperKeys[$key] = $mapper[$key][0]; if (is_numeric($mapper[$key][1])) { $mapperLocType[$key] = $mapper[$key][1]; } else { $mapperLocType[$key] = null; } if (!is_numeric($mapper[$key][2])) { $mapperPhoneType[$key] = $mapper[$key][2]; } else { $mapperPhoneType[$key] = null; } } $parser =& new CRM_Contribute_Import_Parser_Contribution($mapperKeys, $mapperLocType, $mapperPhoneType); $mapFields = $this->get('fields'); foreach ($mapper as $key => $value) { $header = array(); if (isset($mapFields[$mapper[$key][0]])) { $header[] = $mapFields[$mapper[$key][0]]; } $mapperFields[] = implode(' - ', $header); } $parser->run($fileName, $seperator, $mapperFields, $skipColumnHeader, CRM_CONTRIBUTE_IMPORT_PARSER_MODE_IMPORT, $onDuplicate); // add all the necessary variables to the form $parser->set($this, CRM_CONTRIBUTE_IMPORT_PARSER_MODE_IMPORT); // check if there is any error occured $errorStack =& CRM_Core_Error::singleton(); $errors = $errorStack->getErrors(); $errorMessage = array(); $config =& CRM_Core_Config::singleton(); if (is_array($errors)) { foreach ($errors as $key => $value) { $errorMessage[] = $value['message']; } $errorFile = $fileName . '.error.log'; if ($fd = fopen($errorFile, 'w')) { fwrite($fd, implode('\\n', $errorMessage)); } fclose($fd); $this->set('errorFile', $errorFile); $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', 'type=1&realm=contribution')); $this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', 'type=2&realm=contribution')); $this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', 'type=4&realm=contribution')); } }
/** * Process the mapped fields and map it into the uploaded file * preview the file and extract some summary statistics * * @return void * @access public */ function postProcess() { $fileName = $this->controller->exportValue('UploadFile', 'uploadFile'); $skipColumnHeader = $this->controller->exportValue('UploadFile', 'skipColumnHeader'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); $newGroup = $this->controller->exportValue($this->_name, 'newGroup'); $newGroupName = $this->controller->exportValue($this->_name, 'newGroupName'); $newGroupDesc = $this->controller->exportValue($this->_name, 'newGroupDesc'); $groups = $this->controller->exportValue($this->_name, 'groups'); $allGroups = $this->get('groups'); $tagForContact = $this->controller->exportValue($this->_name, 'tag'); $allTags = $this->get('tag'); $seperator = ','; $mapper = $this->controller->exportValue('MapField', 'mapper'); $mapperKeys = array(); $mapperLocTypes = array(); $mapperPhoneTypes = array(); $mapperRelated = array(); $mapperRelatedContactType = array(); $mapperRelatedContactDetails = array(); $mapperRelatedContactLocType = array(); $mapperRelatedContactPhoneType = array(); foreach ($mapper as $key => $value) { $mapperKeys[$key] = $mapper[$key][0]; if (is_numeric($mapper[$key][1])) { $mapperLocTypes[$key] = $mapper[$key][1]; } else { $mapperLocTypes[$key] = null; } if (!is_numeric($mapper[$key][2])) { $mapperPhoneTypes[$key] = $mapper[$key][2]; } else { $mapperPhoneTypes[$key] = null; } list($id, $first, $second) = explode('_', $mapper[$key][0]); if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') { $relationType =& new CRM_Contact_DAO_RelationshipType(); $relationType->id = $id; $relationType->find(true); eval('$mapperRelatedContactType[$key] = $relationType->contact_type_' . $second . ';'); $mapperRelated[$key] = $mapper[$key][0]; $mapperRelatedContactDetails[$key] = $mapper[$key][1]; $mapperRelatedContactLocType[$key] = $mapper[$key][2]; $mapperRelatedContactPhoneType[$key] = $mapper[$key][3]; } else { $mapperRelated[$key] = null; $mapperRelatedContactType[$key] = null; $mapperRelatedContactDetails[$key] = null; $mapperRelatedContactLocType[$key] = null; $mapperRelatedContactPhoneType[$key] = null; } } $parser =& new CRM_Import_Parser_Contact($mapperKeys, $mapperLocTypes, $mapperPhoneTypes, $mapperRelated, $mapperRelatedContactType, $mapperRelatedContactDetails, $mapperRelatedContactLocType, $mapperRelatedContactPhoneType); $mapFields = $this->get('fields'); $locationTypes = CRM_Core_PseudoConstant::locationType(); $phoneTypes = CRM_Core_SelectValues::phoneType(); foreach ($mapper as $key => $value) { $header = array(); list($id, $first, $second) = explode('_', $mapper[$key][0]); if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') { $relationType =& new CRM_Contact_DAO_RelationshipType(); $relationType->id = $id; $relationType->find(true); $header[] = $relationType->name_a_b; $header[] = ucwords(str_replace("_", " ", $mapper[$key][1])); if (isset($mapper[$key][2])) { $header[] = $locationTypes[$mapper[$key][2]]; } if (isset($mapper[$key][3])) { $header[] = $phoneTypes[$mapper[$key][3]]; } } else { if (isset($mapFields[$mapper[$key][0]])) { $header[] = $mapFields[$mapper[$key][0]]; if (isset($mapper[$key][1])) { $header[] = $locationTypes[$mapper[$key][1]]; } if (isset($mapper[$key][2])) { $header[] = $phoneTypes[$mapper[$key][2]]; } } } $mapperFields[] = implode(' - ', $header); } $parser->run($fileName, $seperator, $mapperFields, $skipColumnHeader, CRM_IMPORT_PARSER_MODE_IMPORT, $this->get('contactType'), $onDuplicate); // add the new contacts to selected groups $contactIds =& $parser->getImportedContacts(); // add the new related contacts to selected groups $relatedContactIds =& $parser->getRelatedImportedContacts(); $this->set('relatedCount', count($relatedContactIds)); $newGroupId = null; //changed below if-statement "if ($newGroup) {" to "if ($newGroupName) {" if ($newGroupName) { /* Create a new group */ $gParams = array('domain_id' => CRM_Core_Config::domainID(), 'name' => $newGroupName, 'title' => $newGroupName, 'description' => $newGroupDesc, 'is_active' => true); $group =& CRM_Contact_BAO_Group::create($gParams); $groups[] = $newGroupId = $group->id; } if (is_array($groups)) { $groupAdditions = array(); foreach ($groups as $groupId) { $addCount =& CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId); if (!empty($relatedContactIds)) { $addRelCount =& CRM_Contact_BAO_GroupContact::addContactsToGroup($relatedContactIds, $groupId); } $totalCount = $addCount[1] + $addRelCount[1]; if ($groupId == $newGroupId) { $name = $newGroupName; $new = true; } else { $name = $allGroups[$groupId]; $new = false; } $groupAdditions[] = array('url' => CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $groupId), 'name' => $name, 'added' => $totalCount, 'notAdded' => $addCount[2], 'new' => $new); } $this->set('groupAdditions', $groupAdditions); } if (is_array($tagForContact)) { $tagAddition = array(); require_once "CRM/Core/BAO/EntityTag.php"; foreach ($tagForContact as $tagId => $selected) { $taggedContacts = CRM_Core_BAO_EntityTag::addContactsToTag($contactIds, $tagId); $tagName = $allTags[$tagId]; $tagAdditions[] = array('name' => $tagName, 'added' => $taggedContacts[1], 'notAdded' => $taggedContacts[2]); } $this->set('tagAdditions', $tagAdditions); } // add all the necessary variables to the form $parser->set($this, CRM_IMPORT_PARSER_MODE_IMPORT); // check if there is any error occured $errorStack =& CRM_Core_Error::singleton(); $errors = $errorStack->getErrors(); $errorMessage = array(); $config =& CRM_Core_Config::singleton(); if (is_array($errors)) { foreach ($errors as $key => $value) { $errorMessage[] = $value['message']; } $errorFile = $fileName . '.error.log'; if ($fd = fopen($errorFile, 'w')) { fwrite($fd, implode('\\n', $errorMessage)); } fclose($fd); $this->set('errorFile', $errorFile); $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', 'type=1')); $this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', 'type=2')); $this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', 'type=4')); } }
/** * Error reporting mechanism. * * @param string $message * Error Message. * @param int $code * Error Code. * @param CRM_Core_DAO $dao * A data access object on which we perform a rollback if non - empty. */ public function error($message, $code = NULL, $dao = NULL) { if ($dao) { $dao->query('ROLLBACK'); } $error = CRM_Core_Error::singleton(); $error->push($code, $message); }
function &error($error = null) { $e =& CRM_Core_Error::singleton(); if ($error) { $e->push($error['dc_response_code'], 0, null, $error['dc_response_message']); } else { $e->push(9001, 0, null, "Unknown System Error."); } return $e; }
function &error($errorCode = NULL, $errorMessage = NULL) { $e = CRM_Core_Error::singleton(); if ($errorCode) { $e->push($errorCode, 0, array(), $errorMessage); } else { $e->push(9001, 0, array(), 'Unknown System Error.'); } return $e; }
/** * create a CiviCRM error object and return * * @param Object a PEAR_Error object * * @return Object a CiviCRM Error object * @public */ function &error($error = null) { $e =& CRM_Core_Error::singleton(); if ($error) { $e->push($error->getCode(), 0, null, $error->getMessage()); } else { $e->push(9001, 0, null, "Unknown System Error."); } return $e; }
/** * Produces error message and returns from class. */ public function &errorExit($errorCode = NULL, $errorMessage = NULL) { $e = CRM_Core_Error::singleton(); if ($errorCode) { $e->push($errorCode, 0, NULL, $errorMessage); } else { $e->push(9000, 0, NULL, 'Unknown System Error.'); } return $e; }
/** * Function to do a 'standard' api create - when the api is only doing a $bao::create then use this. * * @param string $bao_name * Name of BAO Class. * @param array $params * Parameters passed into the api call. * @param string $entity * Entity - pass in if entity is non-standard & required $ids array. * * @throws API_Exception * @return array */ function _civicrm_api3_basic_create($bao_name, &$params, $entity = NULL) { _civicrm_api3_format_params_for_create($params, $entity); $args = array(&$params); if ($entity) { $ids = array($entity => CRM_Utils_Array::value('id', $params)); $args[] =& $ids; } if (method_exists($bao_name, 'create')) { $fct = 'create'; $fct_name = $bao_name . '::' . $fct; $bao = call_user_func_array(array($bao_name, $fct), $args); } elseif (method_exists($bao_name, 'add')) { $fct = 'add'; $fct_name = $bao_name . '::' . $fct; $bao = call_user_func_array(array($bao_name, $fct), $args); } else { $fct_name = '_civicrm_api3_basic_create_fallback'; $bao = _civicrm_api3_basic_create_fallback($bao_name, $params); } if (is_null($bao)) { return civicrm_api3_create_error('Entity not created (' . $fct_name . ')'); } elseif (is_a($bao, 'CRM_Core_Error')) { //some wierd circular thing means the error takes itself as an argument $msg = $bao->getMessages($bao); // the api deals with entities on a one-by-one basis. However, the contribution bao pushes entities // onto the error object - presumably because the contribution import is not handling multiple errors correctly // so we need to reset the error object here to avoid getting concatenated errors //@todo - the mulitple error handling should be moved out of the contribution object to the import / multiple entity processes CRM_Core_Error::singleton()->reset(); throw new API_Exception($msg); } else { $values = array(); _civicrm_api3_object_to_array($bao, $values[$bao->id]); return civicrm_api3_create_success($values, $params, $entity, 'create', $bao); } }