Merge pull request #1579 from pratik-joshi/CRM-13324
[civicrm-core.git] / api / api.php
CommitLineData
6a488035
TO
1<?php
2
3/**
4 * File for the CiviCRM APIv3 API wrapper
5 *
6 * @package CiviCRM_APIv3
7 * @subpackage API
8 *
9 * @copyright CiviCRM LLC (c) 2004-2013
10 * @version $Id: api.php 30486 2010-11-02 16:12:09Z shot $
11 */
12
11e09c59 13/**
6a488035
TO
14 * @param string $entity
15 * type of entities to deal with
16 * @param string $action
17 * create, get, delete or some special action name.
18 * @param array $params
19 * array to be passed to function
20 */
21function civicrm_api($entity, $action, $params, $extra = NULL) {
5270c026
XD
22 $apiRequest = array();
23 $apiRequest['entity'] = CRM_Utils_String::munge($entity);
24 $apiRequest['action'] = CRM_Utils_String::munge($action);
25 $apiRequest['version'] = civicrm_get_api_version($params);
26 $apiRequest['params'] = $params;
27 $apiRequest['extra'] = $extra;
28
a9396478
TO
29 $apiWrappers = array(
30 CRM_Utils_API_HTMLInputCoder::singleton(),
0e4d4398 31 CRM_Utils_API_NullOutputCoder::singleton(),
ac830223 32 CRM_Utils_API_ReloadOption::singleton(),
c8463688 33 CRM_Utils_API_MatchOption::singleton(),
a9396478 34 );
5270c026
XD
35 CRM_Utils_Hook::apiWrappers($apiWrappers,$apiRequest);
36
6a488035
TO
37 try {
38 require_once ('api/v3/utils.php');
39 require_once 'api/Exception.php';
40 if (!is_array($params)) {
41 throw new API_Exception('Input variable `params` is not an array', 2000);
42 }
43 _civicrm_api3_initialize();
44 $errorScope = CRM_Core_TemporaryErrorScope::useException();
6a488035
TO
45 // look up function, file, is_generic
46 $apiRequest += _civicrm_api_resolve($apiRequest);
eb917190 47 if (strtolower($action) == 'create' || strtolower($action) == 'delete') {
6a488035
TO
48 $apiRequest['is_transactional'] = 1;
49 $transaction = new CRM_Core_Transaction();
50 }
51
91cd40ea
ML
52 // support multi-lingual requests
53 if ($language = CRM_Utils_Array::value('option.language', $params)) {
54 _civicrm_api_set_locale($language);
55 }
56
6a488035
TO
57 _civicrm_api3_api_check_permission($apiRequest['entity'], $apiRequest['action'], $apiRequest['params']);
58
59 // we do this before we
60 _civicrm_api3_swap_out_aliases($apiRequest);
61 if (strtolower($action) != 'getfields') {
9ec90e57 62 if (!CRM_Utils_Array::value('id', $apiRequest['params'])) {
6a488035
TO
63 $apiRequest['params'] = array_merge(_civicrm_api3_getdefaults($apiRequest), $apiRequest['params']);
64 }
65 //if 'id' is set then only 'version' will be checked but should still be checked for consistency
66 civicrm_api3_verify_mandatory($apiRequest['params'], NULL, _civicrm_api3_getrequired($apiRequest));
67 }
68
a9396478 69 // For input filtering, process $apiWrappers in forward order
6a488035
TO
70 foreach ($apiWrappers as $apiWrapper) {
71 $apiRequest = $apiWrapper->fromApiInput($apiRequest);
72 }
73
74 $function = $apiRequest['function'];
75 if ($apiRequest['function'] && $apiRequest['is_generic']) {
76 // Unlike normal API implementations, generic implementations require explicit
77 // knowledge of the entity and action (as well as $params). Bundle up these bits
78 // into a convenient data structure.
79 $result = $function($apiRequest);
80 }
81 elseif ($apiRequest['function'] && !$apiRequest['is_generic']) {
82 _civicrm_api3_validate_fields($apiRequest['entity'], $apiRequest['action'], $apiRequest['params']);
83
84 $result = isset($extra) ? $function($apiRequest['params'], $extra) : $function($apiRequest['params']);
85 }
86 else {
87 return civicrm_api3_create_error("API (" . $apiRequest['entity'] . "," . $apiRequest['action'] . ") does not exist (join the API team and implement it!)");
88 }
89
a9396478
TO
90 // For output filtering, process $apiWrappers in reverse order
91 foreach (array_reverse($apiWrappers) as $apiWrapper) {
6a488035
TO
92 $result = $apiWrapper->toApiOutput($apiRequest, $result);
93 }
94
95 if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) {
96 if ($result['is_error'] === 0) {
97 return 1;
98 }
99 else {
100 return 0;
101 }
102 }
103 if (CRM_Utils_Array::value('format.only_id', $apiRequest['params']) && isset($result['id'])) {
104 return $result['id'];
105 }
106 if (CRM_Utils_Array::value('is_error', $result, 0) == 0) {
107 _civicrm_api_call_nested_api($apiRequest['params'], $result, $apiRequest['action'], $apiRequest['entity'], $apiRequest['version']);
108 }
109 if (function_exists('xdebug_time_index')
110 && CRM_Utils_Array::value('debug', $apiRequest['params'])
111 // result would not be an array for getvalue
112 && is_array($result)
113 ) {
114 $result['xdebug']['peakMemory'] = xdebug_peak_memory_usage();
115 $result['xdebug']['memory'] = xdebug_memory_usage();
116 $result['xdebug']['timeIndex'] = xdebug_time_index();
117 }
118
119 return $result;
120 }
121 catch(PEAR_Exception $e) {
122 if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) {
123 return 0;
124 }
c56bd790
XD
125 $error = $e->getCause();
126 if ($error instanceof DB_Error) {
127 $data["error_code"] = DB::errorMessage($error->getCode());
128 $data["sql"] = $error->getDebugInfo();
129 }
6a488035 130 if (CRM_Utils_Array::value('debug', $apiRequest['params'])) {
9aeec998 131 if(method_exists($e, 'getUserInfo')) {
132 $data['debug_info'] = $error->getUserInfo();
133 }
134 if(method_exists($e, 'getExtraData')) {
135 $data['debug_info'] = $data + $error->getExtraData();
136 }
6a488035
TO
137 $data['trace'] = $e->getTraceAsString();
138 }
139 else{
140 $data['tip'] = "add debug=1 to your API call to have more info about the error";
141 }
142 $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest);
143 if (CRM_Utils_Array::value('is_transactional', $apiRequest)) {
144 $transaction->rollback();
145 }
146 return $err;
147 }
148 catch (API_Exception $e){
149 if(!isset($apiRequest)){
150 $apiRequest = array();
151 }
152 if (CRM_Utils_Array::value('format.is_success', CRM_Utils_Array::value('params',$apiRequest)) == 1) {
153 return 0;
154 }
155 $data = $e->getExtraParams();
156 $data['entity'] = CRM_Utils_Array::value('entity', $apiRequest);
157 $data['action'] = CRM_Utils_Array::value('action', $apiRequest);
158 $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest, $e->getCode());
159 if (CRM_Utils_Array::value('debug', CRM_Utils_Array::value('params',$apiRequest))
160 && empty($data['trace']) // prevent recursion
161 ) {
162 $err['trace'] = $e->getTraceAsString();
163 }
164 if (CRM_Utils_Array::value('is_transactional', $apiRequest)) {
165 $transaction->rollback();
166 }
167 return $err;
168 }
169 catch(Exception $e) {
170 if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) {
171 return 0;
172 }
173 $data = array();
174 $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest, $e->getCode());
175 if (CRM_Utils_Array::value('debug', $apiRequest['params'])) {
176 $err['trace'] = $e->getTraceAsString();
177 }
178 if (CRM_Utils_Array::value('is_transactional', $apiRequest)) {
179 $transaction->rollback();
180 }
181 return $err;
182 }
183}
184
185/**
186 * Look up the implementation for a given API request
187 *
188 * @param $apiRequest array with keys:
189 * - entity: string, required
190 * - action: string, required
191 * - params: array
192 * - version: scalar, required
193 *
194 * @return array with keys
195 * - function: callback (mixed)
196 * - is_generic: boolean
197 */
198function _civicrm_api_resolve($apiRequest) {
199 static $cache;
200 $cachekey = strtolower($apiRequest['entity']) . ':' . strtolower($apiRequest['action']) . ':' . $apiRequest['version'];
201 if (isset($cache[$cachekey])) {
202 return $cache[$cachekey];
203 }
204
205 $camelName = _civicrm_api_get_camel_name($apiRequest['entity'], $apiRequest['version']);
206 $actionCamelName = _civicrm_api_get_camel_name($apiRequest['action']);
207
208 // Determine if there is an entity-specific implementation of the action
209 $stdFunction = civicrm_api_get_function_name($apiRequest['entity'], $apiRequest['action'], $apiRequest['version']);
210 if (function_exists($stdFunction)) {
211 // someone already loaded the appropriate file
212 // FIXME: This has the affect of masking bugs in load order; this is included to provide bug-compatibility
213 $cache[$cachekey] = array('function' => $stdFunction, 'is_generic' => FALSE);
214 return $cache[$cachekey];
215 }
216
217 $stdFiles = array(
218 // By convention, the $camelName.php is more likely to contain the function, so test it first
219 'api/v' . $apiRequest['version'] . '/' . $camelName . '.php',
220 'api/v' . $apiRequest['version'] . '/' . $camelName . '/' . $actionCamelName . '.php',
221 );
222 foreach ($stdFiles as $stdFile) {
6a488035
TO
223 if (CRM_Utils_File::isIncludable($stdFile)) {
224 require_once $stdFile;
225 if (function_exists($stdFunction)) {
226 $cache[$cachekey] = array('function' => $stdFunction, 'is_generic' => FALSE);
227 return $cache[$cachekey];
228 }
229 }
230 }
231
232 // Determine if there is a generic implementation of the action
233 require_once 'api/v3/Generic.php';
234 # $genericFunction = 'civicrm_api3_generic_' . $apiRequest['action'];
235 $genericFunction = civicrm_api_get_function_name('generic', $apiRequest['action'], $apiRequest['version']);
236 $genericFiles = array(
237 // By convention, the Generic.php is more likely to contain the function, so test it first
238 'api/v' . $apiRequest['version'] . '/Generic.php',
239 'api/v' . $apiRequest['version'] . '/Generic/' . $actionCamelName . '.php',
240 );
241 foreach ($genericFiles as $genericFile) {
6a488035
TO
242 if (CRM_Utils_File::isIncludable($genericFile)) {
243 require_once $genericFile;
244 if (function_exists($genericFunction)) {
245 $cache[$cachekey] = array('function' => $genericFunction, 'is_generic' => TRUE);
246 return $cache[$cachekey];
247 }
248 }
249 }
250
251 $cache[$cachekey] = array('function' => FALSE, 'is_generic' => FALSE);
252 return $cache[$cachekey];
253}
6b359437 254/**
255 * Version 3 wrapper for civicrm_api. Throws exception
256 * @param string $entity type of entities to deal with
257 * @param string $action create, get, delete or some special action name.
258 * @param array $params array to be passed to function
259 *
260 * @return array
261 *
262 */
c4ac4df4 263function civicrm_api3($entity, $action, $params) {
6b359437 264 $params['version'] = 3;
265 $result = civicrm_api($entity, $action, $params);
d661281d 266 if(is_array($result) && !empty($result['is_error'])){
6b359437 267 throw new CiviCRM_API3_Exception($result['error_message'], CRM_Utils_Array::value('error_code', $result, 'undefined'), $result);
268 }
c4ac4df4 269 return $result;
6b359437 270}
6a488035
TO
271
272/**
273 * Load/require all files related to an entity.
274 *
275 * This should not normally be called because it's does a file-system scan; it's
276 * only appropriate when introspection is really required (eg for "getActions").
277 *
278 * @param string $entity
279 * @return void
280 */
281function _civicrm_api_loadEntity($entity, $version = 3) {
282 /*
283 $apiRequest = array();
284 $apiRequest['entity'] = $entity;
285 $apiRequest['action'] = 'pretty sure it will never exist. Trick to [try to] force resolve to scan everywhere';
286 $apiRequest['version'] = $version;
287 // look up function, file, is_generic
288 $apiRequest = _civicrm_api_resolve($apiRequest);
289 */
290
291 $camelName = _civicrm_api_get_camel_name($entity, $version);
292
293 // Check for master entity file; to match _civicrm_api_resolve(), only load the first one
6a488035
TO
294 $stdFile = 'api/v' . $version . '/' . $camelName . '.php';
295 if (CRM_Utils_File::isIncludable($stdFile)) {
296 require_once $stdFile;
297 }
298
299 // Check for standalone action files; to match _civicrm_api_resolve(), only load the first one
300 $loaded_files = array(); // array($relativeFilePath => TRUE)
301 $include_dirs = array_unique(explode(PATH_SEPARATOR, get_include_path()));
302 foreach ($include_dirs as $include_dir) {
303 $action_dir = implode(DIRECTORY_SEPARATOR, array($include_dir, 'api', "v${version}", $camelName));
304 if (! is_dir($action_dir)) {
305 continue;
306 }
307
308 $iterator = new DirectoryIterator($action_dir);
309 foreach ($iterator as $fileinfo) {
310 $file = $fileinfo->getFilename();
311 if (array_key_exists($file, $loaded_files)) {
312 continue; // action provided by an earlier item on include_path
313 }
314
315 $parts = explode(".", $file);
316 if (end($parts) == "php" && !preg_match('/Tests?\.php$/', $file) ) {
317 require_once $action_dir . DIRECTORY_SEPARATOR . $file;
318 $loaded_files[$file] = TRUE;
319 }
320 }
321 }
322}
323
324/**
325 *
326 * @deprecated
327 */
328function civicrm_api_get_function_name($entity, $action, $version = NULL) {
329
330 if (empty($version)) {
331 $version = civicrm_get_api_version();
332 }
333
334 $entity = _civicrm_api_get_entity_name_from_camel($entity);
335 return 'civicrm_api3' . '_' . $entity . '_' . $action;
336}
337
338/**
339 * We must be sure that every request uses only one version of the API.
340 *
341 * @param $desired_version : array or integer
342 * One chance to set the version number.
343 * After that, this version number will be used for the remaining request.
344 * This can either be a number, or an array(.., 'version' => $version, ..).
345 * This allows to directly pass the $params array.
346 */
347function civicrm_get_api_version($desired_version = NULL) {
348
349 if (is_array($desired_version)) {
350 // someone gave the full $params array.
351 $params = $desired_version;
352 $desired_version = empty($params['version']) ? NULL : (int) $params['version'];
353 }
354 if (isset($desired_version) && is_integer($desired_version)) {
355 $_version = $desired_version;
356 }
357 else {
358 // we will set the default to version 3 as soon as we find that it works.
359 $_version = 3;
360 }
361 return $_version;
362}
363
364/**
365 * Check if the result is an error. Note that this function has been retained from
366 * api v2 for convenience but the result is more standardised in v3 and param
367 * 'format.is_success' => 1
368 * will result in a boolean success /fail being returned if that is what you need.
369 *
370 * @param array $params (reference ) input parameters
371 *
372 * @return boolean true if error, false otherwise
373 * @static void
374 * @access public
375 */
376function civicrm_error($result) {
377 if (is_array($result)) {
378 return (array_key_exists('is_error', $result) &&
379 $result['is_error']
380 ) ? TRUE : FALSE;
381 }
382 return FALSE;
383}
384
385function _civicrm_api_get_camel_name($entity, $version = NULL) {
6a488035
TO
386 if (empty($version)) {
387 $version = civicrm_get_api_version();
388 }
389
6a488035
TO
390 $fragments = explode('_', $entity);
391 foreach ($fragments as & $fragment) {
392 $fragment = ucfirst($fragment);
393 }
394 // Special case: UFGroup, UFJoin, UFMatch, UFField
395 if ($fragments[0] === 'Uf') {
396 $fragments[0] = 'UF';
397 }
398 return implode('', $fragments);
399}
400
11e09c59 401/**
6a488035
TO
402 * Call any nested api calls
403 */
404function _civicrm_api_call_nested_api(&$params, &$result, $action, $entity, $version) {
405 $entity = _civicrm_api_get_entity_name_from_camel($entity);
406 if(strtolower($action) == 'getsingle'){
407 // I don't understand the protocol here, but we don't want
408 // $result to be a recursive array
409 // $result['values'][0] = $result;
410 $oldResult = $result;
411 $result = array('values' => array(0 => $oldResult));
412 }
413 foreach ($params as $field => $newparams) {
414 if ((is_array($newparams) || $newparams === 1) && $field <> 'api.has_parent' && substr($field, 0, 3) == 'api') {
415
416 // 'api.participant.delete' => 1 is a valid options - handle 1 instead of an array
417 if ($newparams === 1) {
418 $newparams = array('version' => $version);
419 }
420 // can be api_ or api.
421 $separator = $field[3];
422 if (!($separator == '.' || $separator == '_')) {
423 continue;
424 }
425 $subAPI = explode($separator, $field);
426
427 $subaction = empty($subAPI[2]) ? $action : $subAPI[2];
428 $subParams = array(
429 'debug' => CRM_Utils_Array::value('debug', $params),
430 );
431 $subEntity = $subAPI[1];
432
433 foreach ($result['values'] as $idIndex => $parentAPIValues) {
434
435 if (strtolower($subEntity) != 'contact') {
436 //contact spits the dummy at activity_id so what else won't it like?
437 //set entity_id & entity table based on the parent's id & entity. e.g for something like
438 //note if the parent call is contact 'entity_table' will be set to 'contact' & 'id' to the contact id from
439 //the parent call.
440 //in this case 'contact_id' will also be set to the parent's id
441 $subParams["entity_id"] = $parentAPIValues['id'];
442 $subParams['entity_table'] = 'civicrm_' . _civicrm_api_get_entity_name_from_camel($entity);
443 $subParams[strtolower($entity) . "_id"] = $parentAPIValues['id'];
444 }
445 if (strtolower($entity) != 'contact' && CRM_Utils_Array::value(strtolower($subEntity . "_id"), $parentAPIValues)) {
446 //e.g. if event_id is in the values returned & subentity is event then pass in event_id as 'id'
447 //don't do this for contact as it does some wierd things like returning primary email &
448 //thus limiting the ability to chain email
449 //TODO - this might need the camel treatment
450 $subParams['id'] = $parentAPIValues[$subEntity . "_id"];
451 }
452
453 if (CRM_Utils_Array::value('entity_table', $result['values'][$idIndex]) == $subEntity) {
454 $subParams['id'] = $result['values'][$idIndex]['entity_id'];
455 }
456 // if we are dealing with the same entity pass 'id' through (useful for get + delete for example)
457 if (strtolower($entity) == strtolower($subEntity)) {
458 $subParams['id'] = $result['values'][$idIndex]['id'];
459 }
460
461
462 $subParams['version'] = $version;
463 if(!empty($params['check_permissions'])){
464 $subParams['check_permissions'] = $params['check_permissions'];
465 }
466 $subParams['sequential'] = 1;
467 $subParams['api.has_parent'] = 1;
468 if (array_key_exists(0, $newparams)) {
469 // it is a numerically indexed array - ie. multiple creates
470 foreach ($newparams as $entity => $entityparams) {
471 $subParams = array_merge($subParams, $entityparams);
472 _civicrm_api_replace_variables($subAPI[1], $subaction, $subParams, $result['values'][$idIndex], $separator);
473 $result['values'][$result['id']][$field][] = civicrm_api($subEntity, $subaction, $subParams);
474 if ($result['is_error'] === 1) {
475 throw new Exception($subEntity . ' ' . $subaction . 'call failed with' . $result['error_message']);
476 }
477 }
478 }
479 else {
480
481 $subParams = array_merge($subParams, $newparams);
482 _civicrm_api_replace_variables($subAPI[1], $subaction, $subParams, $result['values'][$idIndex], $separator);
483 $result['values'][$idIndex][$field] = civicrm_api($subEntity, $subaction, $subParams);
484 if (!empty($result['is_error'])) {
485 throw new Exception($subEntity . ' ' . $subaction . 'call failed with' . $result['error_message']);
486 }
487 }
488 }
489 }
490 }
491 if(strtolower($action) == 'getsingle'){
492 $result = $result['values'][0];
493 }
494}
495
11e09c59 496/**
6a488035
TO
497 * Swap out any $values vars - ie. the value after $value is swapped for the parent $result
498 * 'activity_type_id' => '$value.testfield',
499 'tag_id' => '$value.api.tag.create.id',
500 'tag1_id' => '$value.api.entity.create.0.id'
501 */
502function _civicrm_api_replace_variables($entity, $action, &$params, &$parentResult, $separator = '.') {
503
504
505 foreach ($params as $field => $value) {
506
507 if (is_string($value) && substr($value, 0, 6) == '$value') {
508 $valuesubstitute = substr($value, 7);
509
510 if (!empty($parentResult[$valuesubstitute])) {
511 $params[$field] = $parentResult[$valuesubstitute];
512 }
513 else {
514
515 $stringParts = explode($separator, $value);
516 unset($stringParts[0]);
517
518 $fieldname = array_shift($stringParts);
519
520 //when our string is an array we will treat it as an array from that . onwards
521 $count = count($stringParts);
522 while ($count > 0) {
523 $fieldname .= "." . array_shift($stringParts);
524 if (array_key_exists($fieldname, $parentResult) && is_array($parentResult[$fieldname])) {
525 $arrayLocation = $parentResult[$fieldname];
526 foreach ($stringParts as $key => $value) {
527 $arrayLocation = CRM_Utils_Array::value($value, $arrayLocation);
528 }
529 $params[$field] = $arrayLocation;
530 }
531 $count = count($stringParts);
532 }
533 }
534 }
535 }
536}
537
11e09c59 538/**
6a488035
TO
539 * Convert possibly camel name to underscore separated entity name
540 *
541 * @param string $entity entity name in various formats e.g. Contribution, contribution, OptionValue, option_value, UFJoin, uf_join
542 * @return string $entity entity name in underscore separated format
47e6af81
CW
543 *
544 * FIXME: Why isn't this called first thing in civicrm_api wrapper?
6a488035
TO
545 */
546function _civicrm_api_get_entity_name_from_camel($entity) {
547 if ($entity == strtolower($entity)) {
548 return $entity;
549 }
550 else {
551 $entity = ltrim(strtolower(str_replace('U_F',
552 'uf',
553 // That's CamelCase, beside an odd UFCamel that is expected as uf_camel
554 preg_replace('/(?=[A-Z])/', '_$0', $entity)
555 )), '_');
556 }
557 return $entity;
558}
11e09c59
TO
559
560/**
6a488035
TO
561 * Having a DAO object find the entity name
562 * @param object $bao DAO being passed in
563 */
564function _civicrm_api_get_entity_name_from_dao($bao){
565 $daoName = str_replace("BAO", "DAO", get_class($bao));
edc091f1 566 return _civicrm_api_get_entity_name_from_camel(CRM_Core_DAO_AllCoreTables::getBriefName($daoName));
6a488035
TO
567}
568
91cd40ea
ML
569/**
570 * Sets the tsLocale and dbLocale for multi-lingual sites.
571 * Some code duplication from CRM/Core/BAO/ConfigSetting.php retrieve()
572 * to avoid regressions from refactoring.
573 */
574function _civicrm_api_set_locale($lcMessagesRequest) {
575 // We must validate whether the locale is valid, otherwise setting a bad
576 // dbLocale could probably lead to sql-injection.
577 $domain = new CRM_Core_DAO_Domain();
578 $domain->id = CRM_Core_Config::domainID();
579 $domain->find(TRUE);
580
581 if ($domain->config_backend) {
582 $defaults = unserialize($domain->config_backend);
583
584 // are we in a multi-language setup?
585 $multiLang = $domain->locales ? TRUE : FALSE;
586 $lcMessages = NULL;
587
588 // on multi-lang sites based on request and civicrm_uf_match
589 if ($multiLang) {
590 $languageLimit = array();
591 if (array_key_exists('languageLimit', $defaults) && is_array($defaults['languageLimit'])) {
592 $languageLimit = $defaults['languageLimit'];
593 }
594
595 if (in_array($lcMessagesRequest, array_keys($languageLimit))) {
596 $lcMessages = $lcMessagesRequest;
597 }
598 else {
599 throw new API_Exception(ts('Language not enabled: %1', array(1 => $lcMessagesRequest)));
600 }
601 }
602
603 global $dbLocale;
604
605 // set suffix for table names - use views if more than one language
606 if ($lcMessages) {
607 $dbLocale = $multiLang && $lcMessages ? "_{$lcMessages}" : '';
608
609 // FIXME: an ugly hack to fix CRM-4041
610 global $tsLocale;
611 $tsLocale = $lcMessages;
612 }
613 }
614}