'links',
);
}
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
$iFilteredTotal = $iTotal;
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
$iFilteredTotal = $iTotal;
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
$iFilteredTotal = $iTotal;
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
$iFilteredTotal = $iTotal;
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
civicrm_subscription_history.method as method';
}
- $where = " WHERE contact_a.id = %1 AND civicrm_group.is_active = 1 AND civicrm_group.saved_search_id IS NULL";
+ $where = " WHERE contact_a.id = %1 AND civicrm_group.is_active = 1";
if ($excludeHidden) {
$where .= " AND civicrm_group.is_hidden = 0 ";
$from = CRM_Contact_BAO_Query::fromClause($tables);
+ //CRM-16945: seems hackish but as per CRM-16483 of using group criteria for Search Builder it is mandatory
+ //to include group_contact_cache clause when group table is present, so following code remove duplicacy
+ $from = str_replace("OR civicrm_group.id = civicrm_group_contact_cache.group_id", 'AND civicrm_group.saved_search_id IS NULL', $from);
+
$where .= " AND $permission ";
if ($onlyPublicGroups) {
$options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
- if (($fieldName == 'group' || $fieldName == 'group_id')) {
- // Enforce group visibility permissions
- if (!empty($props['check_permissions'])) {
- $options = CRM_Core_PseudoConstant::group();
- }
- if ($context == 'search' || $context == 'create') {
- // Sort group list by hierarchy
- $options = CRM_Contact_BAO_Group::getGroupsHierarchy($options, NULL, '- ', TRUE);
- }
+ // Sort group list by hierarchy
+ // TODO: This will only work when api.entity is "group_contact". What about others?
+ if (($fieldName == 'group' || $fieldName == 'group_id') && ($context == 'search' || $context == 'create')) {
+ $options = CRM_Contact_BAO_Group::getGroupsHierarchy($options, NULL, '- ', TRUE);
}
return $options;
}
public static function groupTree() {
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
$gids = CRM_Utils_Type::escape($_GET['gids'], 'String');
echo CRM_Contact_BAO_GroupNestingCache::json($gids);
CRM_Utils_System::civiExit();
* Delete custom value.
*/
public static function deleteCustomValue() {
- header('Content-Type: text/plain');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain');
$customValueID = CRM_Utils_Type::escape($_REQUEST['valueID'], 'Positive');
$customGroupID = CRM_Utils_Type::escape($_REQUEST['groupID'], 'Positive');
$userEmail
) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
- header('Content-Type: text/plain');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain');
if ($userEmail) {
echo $userEmail;
}
}
}
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
header('HTTP/1.0 403 Forbidden');
return;
}
- header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', CRM_Utils_Time::getTimeRaw() + $ttl));
- header("Content-Type: $mimeType");
- header("Content-Disposition: inline; filename=\"" . basename($file) . "\"");
- header("Cache-Control: max-age=$ttl, public");
- header('Pragma: public');
+ CRM_Utils_System::setHttpHeader('Expires', gmdate('D, d M Y H:i:s \G\M\T', CRM_Utils_Time::getTimeRaw() + $ttl));
+ CRM_Utils_System::setHttpHeader("Content-Type", $mimeType);
+ CRM_Utils_System::setHttpHeader("Content-Disposition", "inline; filename=\"" . basename($file) . "\"");
+ CRM_Utils_System::setHttpHeader("Cache-Control", "max-age=$ttl, public");
+ CRM_Utils_System::setHttpHeader('Pragma', 'public');
readfile($file);
}
$value['url'] = CRM_Utils_System::url($short['path'], $short['query'], FALSE);
}
$value['title'] = $short['title'];
- $value['ref'] = $short['ref'];
+ $value['ref'] = isset($short['ref']) ? $short['ref'] : '';
if (!empty($short['shortCuts'])) {
foreach ($short['shortCuts'] as $shortCut) {
$value['shortCuts'][] = self::setShortcutValues($shortCut);
*/
public function setWord($fileName = NULL) {
//Mark as a CSV file.
- header('Content-Type: application/vnd.ms-word');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/vnd.ms-word');
//Force a download and name the file using the current timestamp.
if (!$fileName) {
$fileName = 'Contacts_' . $_SERVER['REQUEST_TIME'] . '.doc';
}
- header("Content-Disposition: attachment; filename=Contacts_$fileName");
+ CRM_Utils_System::setHttpHeader("Content-Disposition", "attachment; filename=Contacts_$fileName");
}
/**
*/
public function setExcel($fileName = NULL) {
//Mark as an excel file.
- header('Content-Type: application/vnd.ms-excel');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/vnd.ms-excel');
//Force a download and name the file using the current timestamp.
if (!$fileName) {
$fileName = 'Contacts_' . $_SERVER['REQUEST_TIME'] . '.xls';
}
- header("Content-Disposition: attachment; filename=Contacts_$fileName");
+ CRM_Utils_System::setHttpHeader("Content-Disposition", "attachment; filename=Contacts_$fileName");
}
/**
}
/**
- * Instead of outputting a fatal error message, we'll just redirect to the entryURL if present
+ * Instead of outputting a fatal error message, we'll just redirect
+ * to the entryURL if present
*
* @return void
*/
public function invalidKeyRedirect() {
- if ($this->_entryURL) {
- CRM_Core_Session::setStatus(ts('Your browser session has expired and we are unable to complete your form submission. We have returned you to the initial step so you can complete and resubmit the form. If you experience continued difficulties, please contact us for assistance.'));
- return CRM_Utils_System::redirect($this->_entryURL);
- }
- else {
- self::invalidKeyCommon();
+ if ($this->_entryURL && $url_parts = parse_url($this->_entryURL)) {
+ // CRM-16832: Ensure local redirects only.
+ if (!empty($url_parts['path'])) {
+ // Prepend a slash, but don't duplicate it.
+ $redirect_url = '/' . ltrim($url_parts['path'], '/');
+ if (!empty($url_parts['query'])) {
+ $redirect_url .= '?' . $url_parts['query'];
+ }
+ CRM_Core_Session::setStatus(ts('Your browser session has expired and we are unable to complete your form submission. We have returned you to the initial step so you can complete and resubmit the form. If you experience continued difficulties, please contact us for assistance.'));
+ return CRM_Utils_System::redirect($redirect_url);
+ }
}
+ self::invalidKeyCommon();
}
}
$options = $props['options'];
}
else {
- $info = civicrm_api3($props['entity'], 'getoptions', $props + array('check_permissions' => 1));
+ $info = civicrm_api3($props['entity'], 'getoptions', $props);
$options = $info['values'];
}
if (!array_key_exists('placeholder', $props)) {
// CRM-11831 @see http://www.malsup.com/jquery/form/#file-upload
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
}
else {
$output = "<textarea>$output</textarea>";
// Encourage browsers to cache for a long time - 1 year
$ttl = 60 * 60 * 24 * 364;
}
- header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $ttl));
- header('Content-Type: application/javascript');
- header("Cache-Control: max-age=$ttl, public");
+ CRM_Utils_System::setHttpHeader('Expires', gmdate('D, d M Y H:i:s \G\M\T', time() + $ttl));
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/javascript');
+ CRM_Utils_System::setHttpHeader('Cache-Control', "max-age=$ttl, public");
}
}
if ($isError) {
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi') {
- header("Status: 500 Internal Server Error");
+ CRM_Utils_System::setHttpHeader("Status", "500 Internal Server Error");
}
else {
header("HTTP/1.1 500 Internal Server Error");
'class',
);
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($options, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
}
// overwrite - need to delete block which belongs to main-contact.
- if ($mainBlockId && ($operation == 2)) {
+ if (isset($mainBlockId) && $mainBlockId && ($operation == 2)) {
$deleteDAO = new $daoName();
$deleteDAO->id = $mainBlockId;
$deleteDAO->find(TRUE);
$errorFileName = $parserName::errorFileName($type);
$saveFileName = $parserName::saveFileName($type);
if (!empty($errorFileName) && !empty($saveFileName)) {
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Content-Description: File Transfer');
- header('Content-Type: text/csv');
- header('Content-Length: ' . filesize($errorFileName));
- header('Content-Disposition: attachment; filename=' . $saveFileName);
+ CRM_Utils_System::setHttpHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
+ CRM_Utils_System::setHttpHeader('Content-Description', 'File Transfer');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/csv');
+ CRM_Utils_System::setHttpHeader('Content-Length', filesize($errorFileName));
+ CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . $saveFileName);
readfile($errorFileName);
}
$zip = $config->customFileUploadDir . 'Financial_Transactions_' . date('YmdHis') . '.zip';
$result = $this->createZip($this->_downloadFile, $zip, TRUE);
if ($result) {
- header('Content-Type: application/zip');
- header('Content-Disposition: attachment; filename=' . CRM_Utils_File::cleanFileName(basename($zip)));
- header('Content-Length: ' . filesize($zip));
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/zip');
+ CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . CRM_Utils_File::cleanFileName(basename($zip)));
+ CRM_Utils_System::setHttpHeader('Content-Length', '' . filesize($zip));
ob_clean();
flush();
readfile($config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($zip)));
}
}
else {
- header('Content-Type: text/plain');
- header('Content-Disposition: attachment; filename=' . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0])));
- header('Content-Length: ' . filesize($this->_downloadFile[0]));
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain');
+ CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0])));
+ CRM_Utils_System::setHttpHeader('Content-Length', '' . filesize($this->_downloadFile[0]));
ob_clean();
flush();
readfile($config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0])));
'action',
);
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
if (!empty($params['is_unit_test'])) {
return array($groups, $iFilteredTotal);
}
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($groups, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
));
$fromAddress = civicrm_api3('OptionValue', 'get', $params + array(
'option_group_id' => "from_email_address",
+ 'domain_id' => CRM_Core_Config::domainID(),
));
CRM_Core_Resources::singleton()
->addSetting(array(
);
if ($type == 'html') {
- header('Content-Type: text/html; charset=utf-8');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/html; charset=utf-8');
print $mime->getHTMLBody();
}
else {
- header('Content-Type: text/plain; charset=utf-8');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain; charset=utf-8');
print $mime->getTXTBody();
}
CRM_Utils_System::civiExit();
CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success');
//CRM-15187
// dusplay message when membership type is changed
- if ($this->_id && !in_array($this->_memType, $this->_memTypeSelected)) {
+ if (($this->_action & CRM_Core_Action::UPDATE) && $this->_id && !in_array($this->_memType, $this->_memTypeSelected)) {
CRM_Core_Session::setStatus(
ts('The financial types associated with the old and new membership types are different. You may want to edit the contribution associated with this membership to adjust its financial type.'),
ts('Warning')
//Load the image
$chart = imagecreatefrompng($uploadUrl);
//convert it into formatted png
- header('Content-type: image/png');
+ CRM_Utils_System::setHttpHeader('Content-type', 'image/png');
//overwrite with same image
imagepng($chart, $uploadImg);
//delete the object
'dao' => 'CRM_Mailing_DAO_Mailing',
'fields' => array(
'delivered_count' => array(
- 'name' => 'id',
+ 'name' => 'event_queue_id',
'title' => ts('Delivered'),
),
'accepted_rate' => array(
'dao' => 'CRM_Mailing_DAO_Mailing',
'fields' => array(
'bounce_count' => array(
- 'name' => 'id',
+ 'name' => 'event_queue_id',
'title' => ts('Bounce'),
),
'bounce_rate' => array(
'dao' => 'CRM_Mailing_DAO_Mailing',
'fields' => array(
'open_count' => array(
- 'name' => 'id',
+ 'name' => 'event_queue_id',
'title' => ts('Opened'),
),
'open_rate' => array(
'dao' => 'CRM_Mailing_DAO_Mailing',
'fields' => array(
'click_count' => array(
- 'name' => 'id',
+ 'name' => 'event_queue_id',
'title' => ts('Clicks'),
),
'CTR' => array(
*/
public static function export2csv(&$form, &$rows) {
//Mark as a CSV file.
- header('Content-Type: text/csv');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/csv');
//Force a download and name the file using the current timestamp.
$datetime = date('Ymd-Gi', $_SERVER['REQUEST_TIME']);
- header('Content-Disposition: attachment; filename=Report_' . $datetime . '.csv');
+ CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=Report_' . $datetime . '.csv');
echo self::makeCsv($form, $rows);
CRM_Utils_System::civiExit();
}
return TRUE;
}
+ /**
+ * Queue Task Callback for CRM-16846
+ *
+ * Run a sql file without resetting locale to that version
+ */
+ public static function task_4_6_x_runOnlySql(CRM_Queue_TaskContext $ctx, $rev) {
+ $upgrade = new CRM_Upgrade_Form();
+ $smarty = CRM_Core_Smarty::singleton();
+ $smarty->assign('domainID', CRM_Core_Config::domainID());
+
+ $fileName = "CRM/Upgrade/Incremental/sql/$rev.mysql.tpl";
+
+ $upgrade->source($smarty->fetch($fileName), TRUE);
+
+ return TRUE;
+ }
+
}
--- /dev/null
+{* file to handle db changes in 4.6.7 during upgrade *}
if (!CRM_Utils_Array::value('is_error', $result, FALSE)) {
$reloadMode = $apiRequest['params']['options']['reload'];
}
+ $id = (!empty($apiRequest['params']['sequential'])) ? 0 : $result['id'];
}
switch ($reloadMode) {
if ($reloadResult['is_error']) {
throw new API_Exception($reloadResult['error_message']);
}
- $result['values'][$result['id']] = array_merge($result['values'][$result['id']], $reloadResult['values'][$result['id']]);
+ $result['values'][$id] = array_merge($result['values'][$id], $reloadResult['values'][$result['id']]);
return $result;
case 'selected':
$params = array(
- 'id' => $result['id'],
+ 'id' => $id,
'return' => $this->pickReturnFields($apiRequest),
);
$reloadResult = civicrm_api3($apiRequest['entity'], 'get', $params);
- $result['values'][$result['id']] = array_merge($result['values'][$result['id']], $reloadResult['values'][$result['id']]);
+ $result['values'][$id] = array_merge($result['values'][$id], $reloadResult['values'][$id]);
return $result;
default:
public static function send($calendar, $content_type = 'text/calendar', $charset = 'us-ascii', $fileName = NULL, $disposition = NULL) {
$config = CRM_Core_Config::singleton();
$lang = $config->lcMessages;
- header("Content-Language: $lang");
- // header( "Content-Type: $content_type; charset=$charset; profile=\"ICalendar\"" );
- header("Content-Type: $content_type; charset=$charset");
+ CRM_Utils_System::setHttpHeader("Content-Language", $lang);
+ CRM_Utils_System::setHttpHeader("Content-Type", "$content_type; charset=$charset");
if ($content_type == 'text/calendar') {
- header('Content-Length: ' . strlen($calendar));
- header("Content-Disposition: $disposition; filename=\"$fileName\"");
- header("Pragma: no-cache");
- header("Expires: 0");
- header("Cache-Control: no-cache, must-revalidate");
+ CRM_Utils_System::setHttpHeader('Content-Length', strlen($calendar));
+ CRM_Utils_System::setHttpHeader("Content-Disposition", "$disposition; filename=\"$fileName\"");
+ CRM_Utils_System::setHttpHeader("Pragma", "no-cache");
+ CRM_Utils_System::setHttpHeader("Expires", "0");
+ CRM_Utils_System::setHttpHeader("Cache-Control", "no-cache, must-revalidate");
}
echo $calendar;
* @param mixed $input
*/
public static function output($input) {
- header('Content-Type: application/json');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo json_encode($input);
CRM_Utils_System::civiExit();
}
return $pdf;
}
else {
- header('Content-Type: application/pdf');
- header('Content-Disposition: attachment; filename="' . $fileName . '"');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/pdf');
+ CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"');
echo $pdf;
}
}
$len = strlen($buf);
if ($echo) {
- header('Content-type: application/pdf');
- header("Content-Length: $len");
- header("Content-Disposition: inline; filename={$output}.pdf");
+ CRM_Utils_System::setHttpHeader('Content-type', 'application/pdf');
+ CRM_Utils_System::setHttpHeader("Content-Length", $len);
+ CRM_Utils_System::setHttpHeader("Content-Disposition", "inline; filename={$output}.pdf");
echo $buf;
CRM_Utils_System::civiExit();
}
}
if (!empty($requestParams['json'])) {
- header('Content-Type: application/json');
if (!empty($requestParams['prettyprint'])) {
- // Used by the api explorer
+ // Don't set content-type header for api explorer output
return self::jsonFormated(array_merge($result));
}
+ CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
return json_encode(array_merge($result));
}
* @param $pearError
*/
public static function fatal($pearError) {
- header('Content-Type: text/xml');
+ CRM_Utils_System::setHttpHeader('Content-Type', 'text/xml');
$error = array();
$error['code'] = $pearError->getCode();
$error['error_message'] = $pearError->getMessage();
$smarty = CRM_Core_Smarty::singleton();
CRM_Utils_System::setTitle("$entity::$tplfile inline $tpl");
if (!$smarty->template_exists($tpl)) {
- header("Status: 404 Not Found");
+ CRM_Utils_System::setHttpHeader("Status", "404 Not Found");
die ("Can't find the requested template file templates/$tpl");
}
if (array_key_exists('id', $_GET)) {// special treatmenent, because it's often used
));
}
- header('Location: ' . $url);
+ self::setHttpHeader('Location', $url);
self::civiExit();
}
) {
$now = gmdate('D, d M Y H:i:s') . ' GMT';
- header('Content-Type: ' . $mimeType);
- header('Expires: ' . $now);
+ self::setHttpHeader('Content-Type', $mimeType);
+ self::setHttpHeader('Expires', $now);
// lem9 & loic1: IE need specific headers
$isIE = strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE');
$fileString = "filename=\"{$name}\"";
}
if ($isIE) {
- header("Content-Disposition: inline; $fileString");
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
+ self::setHttpHeader("Content-Disposition", "inline; $fileString");
+ self::setHttpHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
+ self::setHttpHeader('Pragma', 'public');
}
else {
- header("Content-Disposition: $disposition; $fileString");
- header('Pragma: no-cache');
+ self::setHttpHeader("Content-Disposition", "$disposition; $fileString");
+ self::setHttpHeader('Pragma', 'no-cache');
}
if ($output) {
return NULL;
}
+ /**
+ * @param string $name
+ * @param string $value
+ */
+ public static function setHttpHeader($name, $value) {
+ CRM_Core_Config::singleton()->userSystem->setHttpHeader($name, $value);
+ }
+
}
public function appendCoreResources(&$list) {
}
+ /**
+ * @param string $name
+ * @param string $value
+ */
+ public function setHttpHeader($name, $value) {
+ header("$name: $value");
+ }
+
}
return $timezone;
}
+ /**
+ * @inheritDoc
+ */
+ public function setHttpHeader($name, $value) {
+ drupal_add_http_header($name, $value);
+ }
+
}
return $timezone;
}
+ /**
+ * @inheritDoc
+ */
+ public function setHttpHeader($name, $value) {
+ drupal_set_header("$name: $value");
+ }
+
}
$cache_backend->deleteAll();
}
}
+
+ /**
+ * @inheritDoc
+ */
+ public function setHttpHeader($name, $value) {
+ \Symfony\Component\HttpFoundation\Response->headers->set($name, $value);
+ }
}
*/
public function logout() {
session_destroy();
- header("Location:index.php");
+ CRM_Utils_System::setHttpHeader("Location", "index.php");
}
/**
*/
public function logout() {
session_destroy();
- header("Location:index.php");
+ CRM_Utils_System::setHttpHeader("Location", "index.php");
}
/**
foreach ($newparams as $entityparams) {
$subParams = array_merge($genericParams, $entityparams);
_civicrm_api_replace_variables($subParams, $result['values'][$idIndex], $separator);
- $result['values'][$result['id']][$field][] = $apiKernel->run($subEntity, $subaction, $subParams);
+ $result['values'][$idIndex][$field][] = $apiKernel->run($subEntity, $subaction, $subParams);
if ($result['is_error'] === 1) {
throw new \Exception($subEntity . ' ' . $subaction . 'call failed with' . $result['error_message']);
}
$count = count($stringParts);
}
}
+ // CRM-16168 If we have failed to swap it out we should unset it rather than leave the placeholder.
+ if (substr($params[$field], 0, 6) == '$value') {
+ $params[$field] = NULL;
+ }
}
}
}
* API result Array.
*/
function civicrm_api3_event_create($params) {
- civicrm_api3_verify_one_mandatory($params, NULL, array('event_type_id', 'template_id'));
+ // Required fields for creating an event
+ if (empty($params['id']) && empty($params['is_template'])) {
+ civicrm_api3_verify_mandatory($params, NULL, array(
+ 'start_date',
+ 'title',
+ array('event_type_id', 'template_id'),
+ ));
+ }
+ // Required fields for creating an event template
+ elseif (empty($params['id']) && !empty($params['is_template'])) {
+ civicrm_api3_verify_mandatory($params, NULL, array(
+ 'template_title',
+ ));
+ }
// Clone event from template
if (!empty($params['template_id']) && empty($params['id'])) {
* Array of parameters determined by getfields.
*/
function _civicrm_api3_event_create_spec(&$params) {
- $params['start_date']['api.required'] = 1;
- $params['title']['api.required'] = 1;
$params['is_active']['api.default'] = 1;
$params['financial_type_id']['api.aliases'] = array('contribution_type_id');
$params['is_template']['api.default'] = 0;
->where('c.is_opt_out = 0')
->where('c.do_not_email = 0')
->where('c.is_deceased = 0')
+ ->where('c.is_deleted = 0')
->groupBy('e.id')
->orderBy(array('e.is_bulkmail DESC', 'e.is_primary DESC'))
->toSQL();
* Note: We have to manually execute the ajax in order to add the secret extra "prettyprint" param
*/
function execute() {
+ var footer;
$('#api-result').html('<div class="crm-loading-element"></div>');
$.ajax({
url: CRM.url('civicrm/ajax/rest'),
type: _.includes(action, 'get') ? 'GET' : 'POST',
dataType: 'text'
}).done(function(text) {
+ // There may be debug information appended to the end of the json string
+ var footerPos = text.indexOf("\n}<");
+ if (footerPos) {
+ footer = text.substr(footerPos + 2);
+ text = text.substr(0, footerPos + 2);
+ }
$('#api-result').text(text);
prettyPrint('#api-result');
+ if (footer) {
+ $('#api-result').append(footer);
+ }
});
}
*}
{* template for custom data *}
{assign var="customDataGroupName" value=$customDataGroup.name}
+{strip}
+ {if $displayStyle neq 'tableOriented' and ($action eq 16 or $action eq 4)} {* Browse or View actions *}
+ <div class="form-item">
+ {include file="CRM/Custom/Page/CustomDataView.tpl"}
+ </div>
+ {/if}
+{/strip}
{foreach from=$viewCustomData item=customGroupWrapper}
{foreach from=$customGroupWrapper item=customGroup key=customGroupId}
{assign var="customRegion" value='contact-custom-data-'|cat:$customGroup.name}
</script>
{/literal}
{else}
- {strip}
- {if $action eq 16 or $action eq 4} {* Browse or View actions *}
- <div class="form-item">
- {include file="CRM/Custom/Page/CustomDataView.tpl"}
- </div>
- {/if}
- {/strip}
-
{if $mainEditForm}
<script type="text/javascript">
var showBlocks1 = new Array({$showBlocks1});
$this->assertAPISuccess($result['values'][$result['id']]['api.Email.create']);
}
+ /**
+ * When the reload option is combined with chaining, the reload should munge
+ * the chain results, even if sequential=1.
+ */
+ public function testReloadNoChainInterferenceSequential() {
+ $result = $this->callAPISuccess('contact', 'create', array(
+ 'sequential' => 1,
+ 'contact_type' => 'Individual',
+ 'first_name' => 'First',
+ 'last_name' => 'Last',
+ 'nick_name' => 'Firstie',
+ 'api.Email.create' => array(
+ 'email' => 'test@example.com',
+ ),
+ 'options' => array(
+ 'reload' => 1,
+ ),
+ ));
+ $this->assertEquals('First', $result['values'][0]['first_name']);
+ $this->assertEquals('munged', $result['values'][0]['nick_name']);
+ $this->assertAPISuccess($result['values'][0]['api.Email.create']);
+ }
+
/**
* An implementation of hook_civicrm_post used with all our test cases.
*
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License along with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+require_once 'CiviTest/CiviUnitTestCase.php';
+require_once 'CiviTest/CiviSeleniumSettings.php';
+
+/**
+ * Include configuration
+ */
+define('CIVICRM_SETTINGS_PATH', __DIR__ . '/civicrm.settings.dist.php');
+define('CIVICRM_SETTINGS_LOCAL_PATH', __DIR__ . '/civicrm.settings.local.php');
+define('CIVICRM_WEBTEST', 1);
+
+if (file_exists(CIVICRM_SETTINGS_LOCAL_PATH)) {
+ require_once CIVICRM_SETTINGS_LOCAL_PATH;
+}
+require_once CIVICRM_SETTINGS_PATH;
+
+
+/**
+ * Check that we handle redirects appropriately.
+ */
+class WebTest_Utils_RedirectTest extends CiviUnitTestCase {
+ protected $url;
+ protected $ch;
+
+ /**
+ * @param string|null $name
+ */
+ public function __construct($name = NULL) {
+ parent::__construct($name);
+
+ $this->settings = new CiviSeleniumSettings();
+ if (property_exists($this->settings, 'serverStartupTimeOut') && $this->settings->serverStartupTimeOut) {
+ global $CiviSeleniumTestCase_polled;
+ if (!$CiviSeleniumTestCase_polled) {
+ $CiviSeleniumTestCase_polled = TRUE;
+ CRM_Utils_Network::waitForServiceStartup(
+ $this->drivers[0]->getHost(),
+ $this->drivers[0]->getPort(),
+ $this->settings->serverStartupTimeOut
+ );
+ }
+ }
+ }
+
+ protected function setUp() {
+ parent::setUp();
+ //URL should eventually be adapted for multisite
+ $this->url = $this->settings->sandboxURL;
+
+ $this->ch = curl_init();
+ curl_setopt($this->ch, CURLOPT_HEADER, FALSE);
+ curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, FALSE);
+ // curl_setopt($this->ch, CURLOPT_ENCODING, 'gzip');
+ // curl_setopt($this->ch, CURLOPT_VERBOSE, 0);
+ }
+
+ /**
+ *
+ */
+ private function tryRedirect($input_url, $expected_url) {
+ // file_put_contents('php://stderr', $input_url . "\n", FILE_APPEND);
+ $url = $this->url . '/' . $input_url;
+ $expected_url = $this->url . '/' . $expected_url;
+ curl_setopt($this->ch, CURLOPT_URL, $url);
+ $req = curl_exec($this->ch);
+ $this->assertEquals(0, curl_errno($this->ch), 'cURL error: ' . curl_error($this->ch));
+ if (!curl_errno($this->ch)) {
+ $info = curl_getinfo($this->ch);
+ // file_put_contents('php://stderr', print_r($info,1), FILE_APPEND);
+ $this->assertEquals($expected_url, $info['redirect_url']);
+ $this->assertEquals('302', $info['http_code']);
+ }
+ }
+
+ /**
+ * Handle onsite redirects with absolute URL.
+ */
+ public function testAbsoluteOnsiteRedirect() {
+ $this->tryRedirect("civicrm/contribute/transact?qfKey=xxx&entryURL={$this->url}/civicrm/contribute/transact%3Fid%3D1", 'civicrm/contribute/transact?id=1');
+ }
+
+ /**
+ * Handle onsite redirects with slash prefix and query params.
+ */
+ public function testOnsiteRedirectWithSlashPrefixAndQueryParams() {
+ $this->tryRedirect('civicrm/contribute/transact?qfKey=xxx&entryURL=/civicrm/contribute/transact%3Fid%3D1', 'civicrm/contribute/transact?id=1');
+ }
+
+ /**
+ * Handle onsite redirects with non-CiviCRM paths.
+ */
+ public function testOtherpathRedirect() {
+ $this->tryRedirect('civicrm/contribute/transact?qfKey=xxx&entryURL=asdf', 'asdf');
+ }
+
+ /**
+ * Handle offsite redirects without path as onsite redirects.
+ */
+ public function testOffsiteRedirectNoPath() {
+ $this->tryRedirect('civicrm/contribute/transact?qfKey=xxx&entryURL=http://evil.example.com/', '');
+ }
+
+ /**
+ * Handle offsite redirects with paths as onsite redirects.
+ */
+ public function testOffsiteRedirectWithPath() {
+ $this->tryRedirect('civicrm/contribute/transact?qfKey=xxx&entryURL=http://evil.example.com/civicrm', 'civicrm');
+ }
+
+}
}
/**
- * Verify attempt to create individual with chained arrays.
+ * Verify attempt to create individual with chained arrays and sequential
+ */
+ public function testGetIndividualWithChainedArraysAndSequential() {
+ $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
+ $params['custom_' . $ids['custom_field_id']] = "custom string";
+
+ $moreids = $this->CustomGroupMultipleCreateWithFields();
+ $description = "/*this demonstrates the usage of chained api functions. In this case no notes or custom fields have been created ";
+ $subfile = "APIChainedArray";
+ $params = array(
+ 'sequential' => 1,
+ 'first_name' => 'abc3',
+ 'last_name' => 'xyz3',
+ 'contact_type' => 'Individual',
+ 'email' => 'man3@yahoo.com',
+ 'api.website.create' => array(
+ array(
+ 'url' => "http://civicrm.org",
+ ),
+ array(
+ 'url' => "https://civicrm.org",
+ ),
+ ),
+ );
+
+ $result = $this->callAPISuccess('Contact', 'create', $params);
+
+ // delete the contact and custom groups
+ $this->callAPISuccess('contact', 'delete', array('id' => $result['id']));
+ $this->customGroupDelete($ids['custom_group_id']);
+ $this->customGroupDelete($moreids['custom_group_id']);
+
+ $this->assertEquals($result['id'], $result['values'][0]['id']);
+ $this->assertArrayKeyExists('api.website.create', $result['values'][0]);
+ }
+
+ /**
+ * Verify attempt to create individual with chained arrays
*/
public function testGetIndividualWithChainedArrays() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$this->assertEquals("http://civicrm.org", $result['values'][$result['id']]['api.website.get']['values'][0]['url']);
}
+ /**
+ * Verify attempt to create individual with chained arrays and sequential.
+ *
+ * See https://issues.civicrm.org/jira/browse/CRM-15815
+ */
+ public function testCreateIndividualWithChainedArrayAndSequential() {
+ $params = array(
+ 'sequential' => 1,
+ 'first_name' => 'abc5',
+ 'last_name' => 'xyz5',
+ 'contact_type' => 'Individual',
+ 'email' => 'woman5@yahoo.com',
+ 'api.phone.create' => array(
+ array('phone' => '03-231 07 95'),
+ array('phone' => '03-232 51 62'),
+ ),
+ 'api.website.create' => array(
+ 'url' => 'http://civicrm.org',
+ ),
+ );
+ $result = $this->callAPISuccess('Contact', 'create', $params);
+
+ // I could try to parse the result to see whether the two phone numbers
+ // and the website are there, but I am not sure about the correct format.
+ // So I will just fetch it again before checking.
+ // See also http://forum.civicrm.org/index.php/topic,35393.0.html
+ $params = array(
+ 'sequential' => 1,
+ 'id' => $result['id'],
+ 'api.website.get' => array(),
+ 'api.phone.get' => array(),
+ );
+ $result = $this->callAPISuccess('Contact', 'get', $params);
+
+ // delete the contact
+ $this->callAPISuccess('contact', 'delete', $result);
+
+ $this->assertEquals(2, $result['values'][0]['api.phone.get']['count']);
+ $this->assertEquals(1, $result['values'][0]['api.website.get']['count']);
+ }
+
public function testGetIndividualWithChainedArraysFormats() {
$description = "This demonstrates the usage of chained api functions.\nIn this case no notes or custom fields have been created.";
$subfile = "APIChainedArrayFormats";
$this->callAPISuccess('event', 'delete', array('id' => $result['id']));
}
+ /**
+ * Chaining get event and loc block.
+ */
+ public function testChainingGetLocBlock() {
+ // create a loc block and an event for that loc block.
+ $eventParams = $this->_params[0];
+ $eventParams['loc_bloc_id'] = '$value.id';
+ $locBlockParams = array(
+ 'address' => array(
+ 'street_address' => 'Kipdorp 24',
+ 'postal_code' => '2000',
+ 'city' => 'Antwerpen',
+ 'country_id' => '1020',
+ 'location_type_id' => '1',
+ ),
+ 'api.Event.create' => $eventParams,
+ 'sequential' => 1,
+ );
+ $createResult = $this->callAPIAndDocument('LocBlock', 'create', $locBlockParams, __FUNCTION__, __FILE__);
+ $locBlockId = $createResult['id'];
+ $addressId = $createResult['values'][0]['address_id'];
+ $eventId = $createResult['values'][0]['api.Event.create']['id'];
+
+ // request the event with its loc block:
+ $check = $this->callAPISuccess($this->_entity, 'getsingle', array(
+ 'id' => $eventId,
+ 'api.LocBlock.get' => array('id' => '$value.loc_block_id'),
+ 'sequential' => 1,
+ ));
+
+ // assert
+ $this->assertEquals($eventId, $check['id'], ' in line ' . __LINE__);
+ $this->assertEquals(1, $check['api.LocBlock.get']['count'], ' in line ' . __LINE__);
+ $this->assertEquals($locBlockId, $check['api.LocBlock.get']['id'], ' in line ' . __LINE__);
+
+ // cleanup
+ $this->callAPISuccess($this->_entity, 'delete', array('id' => $eventId));
+ }
+
+ /**
+ * Chaining get event and non existing loc block.
+ *
+ * Even if there is no loc block, at least the event should be returned.
+ * http://forum.civicrm.org/index.php/topic,36113.0.html
+ */
+ public function testChainingGetNonExistingLocBlock() {
+ $params = $this->_params[0];
+ $result = $this->callAPISuccess($this->_entity, 'create', $params);
+
+ $check = $this->callAPISuccess($this->_entity, 'get', array(
+ 'id' => $result['id'],
+ // this chaining request should not break things:
+ 'api.LocBlock.get' => array('id' => '$value.loc_block_id'),
+ ));
+ $this->assertEquals($result['id'], $check['id']);
+
+ $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id']));
+ }
+
/**
* Check with complete array + custom field.
*
$description = "Demonstrate use of getfields to interrogate api.";
$params = array('action' => 'create');
$result = $this->callAPISuccess('event', 'getfields', $params);
- $this->assertEquals(1, $result['values']['title']['api.required']);
+ $this->assertEquals(1, $result['values']['is_active']['api.default']);
}
/**
$description = "Demonstrate use of getfields to interrogate api.";
$params = array('api_action' => 'create');
$result = $this->callAPISuccess('event', 'getfields', $params);
- $this->assertEquals(1, $result['values']['title']['api.required']);
+ $this->assertEquals(1, $result['values']['is_active']['api.default']);
}
public function testgetfieldsGet() {
$this->assertEquals(1, $result['values']['id']['api.required']);
}
+ public function testCreateFromTemplate() {
+ $templateParams = array(
+ 'summary' => 'Sign up now to learn the results of this unit test',
+ 'description' => 'This event is created from a template, so all the values should be the same as the original ones.',
+ 'event_type_id' => 1,
+ 'is_public' => 1,
+ 'end_date' => '2018-06-25 17:00:00',
+ 'is_online_registration' => 1,
+ 'registration_start_date' => '2017-06-25 17:00:00',
+ 'registration_end_date' => '2018-06-25 17:00:00',
+ 'max_participants' => 100,
+ 'event_full_text' => 'Sorry! We are already full',
+ );
+ $templateResult = $this->callAPISuccess('Event', 'create', array('is_template' => 1, 'template_title' => 'Test tpl') + $templateParams);
+ $eventResult = $this->callAPISuccess('Event', 'create', array(
+ 'template_id' => $templateResult['id'],
+ 'title' => 'Clone1',
+ 'start_date' => '2018-06-25 16:00:00',
+ ));
+ $eventResult = $this->callAPISuccess('Event', 'getsingle', array('id' => $eventResult['id']));
+ foreach ($templateParams as $param => $value) {
+ $this->assertEquals($value, $eventResult[$param]);
+ }
+ }
+
}