Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Lib.Common.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Common util functions
8  *
9  * @author Anakeen
10  * @version $Id: Lib.Common.php,v 1.50 2008/09/11 14:50:04 eric Exp $
11  * @package FDL
12  * @subpackage CORE
13  */
14 /**
15  */
16 include_once ("Lib.Prefix.php");
17 
18 function N_($s)
19 {
20  return ($s);
21 }
22 if (!function_exists('pgettext')) {
23  function pgettext($context, $msgid)
24  {
25  $contextString = "{$context}\004{$msgid}";
26  $translation = _($contextString);
27  if ($translation === $contextString) return $msgid;
28  else return $translation;
29  }
30 
31  function npgettext($context, $msgid, $msgid_plural, $num)
32  {
33  $contextString = "{$context}\004{$msgid}";
34  $contextStringp = "{$context}\004{$msgid_plural}";
35  $translation = ngettext($contextString, $contextStringp, $num);
36  if ($translation === $contextString) {
37  return $msgid;
38  } else if ($translation === $contextStringp) {
39  return $msgid_plural;
40  } else {
41  return $translation;
42  }
43  }
44 }
45 // New gettext keyword for regular strings with optional context argument
46 function ___($message, $context = "")
47 {
48  if ($context != "") {
49  return pgettext($context, $message);
50  } else {
51  return _($message);
52  }
53 }
54 // New gettext keyword for plural strings with optional context argument
55 function n___($message, $message_plural, $num, $context = "")
56 {
57  if ($context != "") {
58  return npgettext($context, $message, $message_plural, abs($num));
59  } else {
60  return ngettext($message, $message_plural, abs($num));
61  }
62 }
63 // to tag gettext without change text immediatly
64 // library of utilies functions
65 function print_r2($z, $ret = false)
66 {
67  print "<PRE>";
68  print_r($z, $ret);
69  print "</PRE>\n";
70  flush();
71 }
72 /**
73  * send a message to system log
74  * @param string $msg message to log
75  * @param int $cut size limit
76  */
77 function AddLogMsg($msg, $cut = 80)
78 {
79  global $action;
80  if (isset($action->parent)) $action->parent->AddLogMsg($msg, $cut);
81 }
82 /**
83  * send a message to system log
84  * @param string $msg
85  */
86 function deprecatedFunction($msg = '')
87 {
88  global $action;
89  if (isset($action->parent)) $action->parent->log->deprecated("Deprecated : " . $msg);
90 }
91 /**
92  * send a warning msg to the user interface
93  * @param string $msg
94  */
95 function addWarningMsg($msg)
96 {
97  global $action;
98  if (isset($action->parent)) $action->parent->addWarningMsg($msg);
99 }
100 /**
101  * like ucfirst for utf-8
102  * @param $s
103  * @return string
104  */
105 function mb_ucfirst($s)
106 {
107  if ($s) {
108  $s = mb_strtoupper(mb_substr($s, 0, 1, 'UTF-8') , 'UTF-8') . mb_substr($s, 1, mb_strlen($s) , 'UTF-8');
109  }
110  return $s;
111 }
112 
113 function mb_trim($string)
114 {
115  return preg_replace("/(^\s+)|(\s+$)/us", "", $string);
116 }
117 /**
118  * increase limit if current limit is lesser than
119  * @param int $limit new limit in seconds
120  */
121 function setMaxExecutionTimeTo($limit)
122 {
123  $im = intval(ini_get("max_execution_time"));
124  if ($im > 0 && $im < $limit && $limit >= 0) ini_set("max_execution_time", $limit);
125  if ($limit <= 0) ini_set("max_execution_time", 0);
126 }
127 /**
128  * get mail addr of a user
129  * @param int $userid system user identifier
130  * @param bool $full if true email is like : "John Doe" <John.doe@blackhole.net> else only system email address : john.doe@blackhole.net
131  * @return string mail address, false if user not exists
132  */
133 function getMailAddr($userid, $full = false)
134 {
135  $user = new Account("", $userid);
136 
137  if (!$user->isAffected()) {
138  return false;
139  }
140  $mailAddr = $user->getMail();
141  if ($full && $mailAddr !== '') {
142  /* Compose full address iif the user has a non-empty mail address */
143  $pren = '"' . trim(str_replace('"', '-', ucwords(strtolower($user->getDisplayName($user->id))))) . '" <';
144  $postn = '>';
145  return $pren . $mailAddr . $postn;
146  }
147  return $mailAddr;
148 }
149 
150 function getTmpDir($def = '/tmp')
151 {
152  static $tmp;
153  if (isset($tmp) && !empty($tmp)) {
154  return $tmp;
155  }
156  $tmp = getParam('CORE_TMPDIR', $def);
157  if (empty($tmp)) {
158  if (empty($def)) {
159  $tmp = './var/tmp';
160  } else {
161  $tmp = $def;
162  }
163  }
164 
165  if (substr($tmp, 0, 1) != '/') {
166  $tmp = DEFAULT_PUBDIR . '/' . $tmp;
167  }
168  /* Try to create the directory if it does not exists */
169  if (!is_dir($tmp)) {
170  mkdir($tmp);
171  }
172  /* Add suffix, and try to create the sub-directory */
173  $tmp = $tmp . '/dcp';
174  if (!is_dir($tmp)) {
175  mkdir($tmp);
176  }
177  /* We ignore any failure in the directory creation
178  * and return the expected tmp dir.
179  * The caller will have to handle subsequent
180  * errors...
181  */
182  return $tmp;
183 }
184 /**
185  * return value of parameters
186  *
187  * @brief must be in core or global type
188  * @param string $name param name
189  * @param string $def default value if value is empty
190  *
191  * @return string
192  */
193 function getParam($name, $def = "")
194 {
195  global $action;
196  if ($action) return $action->getParam($name, $def);
197  // if context not yet initialized
198  return getCoreParam($name, $def);
199 }
200 /**
201  * return value of a parameter
202  *
203  * @brief must be in core or global type
204  * @param string $name param name
205  * @param string $def default value if value is empty
206  *
207  * @return string
208  */
209 function getCoreParam($name, $def = "")
210 {
211  require_once ('WHAT/Class.ApplicationParameterManager.php');
212 
213  static $params = null;
214 
216  return $value;
217  }
218  if (empty($params)) {
219  $params = array();
220  $tparams = array();
221  $err = simpleQuery("", "select name, val from paramv where (type = 'G') or (type='A' and appid = (select id from application where name ='CORE'));", $tparams, false, false, false);
222  if ($err == "") {
223  foreach ($tparams as $p) {
224  $params[$p['name']] = $p['val'];
225  }
226  }
227  }
228  if (array_key_exists($name, $params) == false) {
229  error_log(sprintf("parameter %s not found use %s instead", $name, $def));
230  return $def;
231  }
232  return ($params[$name] === null) ? $def : $params[$name];
233 }
234 /**
235  *
236  * @param string $name the variable
237  * @param string $def default value if variable is not defined
238  * @return mixed
239  */
240 function getSessionValue($name, $def = "")
241 {
242  global $action;
243  if ($action) return $action->read($name, $def);
244  return null;
245 }
246 /**
247  * return current log in user
248  * @return Account
249  */
250 function getCurrentUser()
251 {
252  global $action;
253  if ($action) {
254  return $action->user;
255  }
256  return null;
257 }
258 function getLayoutFile($app, $layfile)
259 {
260  if (strstr($layfile, '..')) {
261  return "";
262  }
263  if (!strstr($layfile, '.')) $layfile.= ".xml";
264  $socStyle = Getparam("CORE_SOCSTYLE");
265  $style = Getparam("STYLE");
266  $root = DEFAULT_PUBDIR;
267  if ($socStyle != "") {
268  $file = $root . "/STYLE/$socStyle/Layout/$layfile";
269  if (file_exists($file)) {
270  return ($file);
271  }
272 
273  $file = $root . "/STYLE/$socStyle/Layout/" . strtolower($layfile);
274  if (file_exists($file)) {
275  return ($file);
276  }
277  } elseif ($style != "") {
278  $file = $root . "/STYLE/$style/Layout/$layfile";
279  if (file_exists($file)) {
280  return ($file);
281  }
282 
283  $file = $root . "/STYLE/$style/Layout/" . strtolower($layfile);
284  if (file_exists($file)) {
285  return ($file);
286  }
287  }
288 
289  $file = $root . "/$app/Layout/$layfile";
290  if (file_exists($file)) {
291  return ($file);
292  }
293 
294  $file = $root . "/$app/Layout/" . strtolower($layfile);
295  if (file_exists($file)) {
296  return ($file);
297  }
298 
299  return "";
300 }
301 
302 function microtime_diff($a, $b)
303 {
304  list($a_micro, $a_int) = explode(' ', $a);
305  list($b_micro, $b_int) = explode(' ', $b);
306  if ($a_int > $b_int) {
307  return ($a_int - $b_int) + ($a_micro - $b_micro);
308  } elseif ($a_int == $b_int) {
309  if ($a_micro > $b_micro) {
310  return ($a_int - $b_int) + ($a_micro - $b_micro);
311  } elseif ($a_micro < $b_micro) {
312  return ($b_int - $a_int) + ($b_micro - $a_micro);
313  } else {
314  return 0;
315  }
316  } else { // $a_int<$b_int
317  return ($b_int - $a_int) + ($b_micro - $a_micro);
318  }
319 }
320 /**
321  * return call stack
322  * @param int $slice last call to not return
323  * @return array
324  */
325 function getDebugStack($slice = 1)
326 {
327  $td = @debug_backtrace(false);
328  if (!is_array($td)) return array();
329  $t = array_slice($td, $slice);
330  foreach ($t as $k => $s) {
331  unset($t[$k]["args"]); // no set arg
332 
333  }
334  return $t;
335 }
336 /**
337  * @param int $slice
338  * @return void
339  */
340 function logDebugStack($slice = 1, $msg = "")
341 {
342  $st = getDebugStack(2);
343  $errors = [];
344  if ($msg) {
345  $errors[] = $msg;
346  }
347  foreach ($st as $k => $t) {
348  $errors[] = sprintf('%d) %s:%s %s::%s()', $k, isset($t["file"]) ? $t["file"] : 'closure', isset($t["line"]) ? $t["line"] : 0, isset($t["class"]) ? $t["class"] : '', $t["function"]);
349  }
350 
351  error_log(implode("\n", $errors));
352 }
354 {
355  global $CORE_DBID;
356  if (!$dbaccess) $dbaccess = getDbAccess();
357  if (!isset($CORE_DBID) || !($CORE_DBID[$dbaccess])) {
358  $CORE_DBID[$dbaccess] = pg_connect($dbaccess);
359  if (!$CORE_DBID[$dbaccess]) {
360  // fatal error
361  header('HTTP/1.0 503 DB connection unavalaible');
362  throw new \Dcp\Db\Exception('DB0101', $dbaccess);
363  }
364  }
365  return $CORE_DBID[$dbaccess];
366 }
367 
368 function getDbAccess()
369 {
370  return getDbAccessCore();
371 }
372 
373 function getDbAccessCore()
374 {
375  return "service='" . getServiceCore() . "'";
376 }
377 
379 {
380  return "service='" . getServiceFreedom() . "'";
381 }
382 /**
383  * @deprecated context notion are be deleted
384  * @return string
385  */
386 function getDbEnv()
387 {
388  error_log("Deprecated call to getDbEnv() : not necessary");
389  /** @noinspection PhpDeprecationInspection */
390  return getFreedomContext();
391 }
392 /**
393  * @deprecated context notion are be deleted
394  * @return string
395  */
397 {
398  $freedomctx = getenv("freedom_context");
399  if ($freedomctx == false || $freedomctx == "") {
400  return "default";
401  }
402  return $freedomctx;
403 }
404 
405 function getServiceCore()
406 {
407  static $pg_service = null;
408 
409  if ($pg_service) return $pg_service;
410  $pgservice_core = getDbAccessvalue('pgservice_core');
411 
412  if ($pgservice_core == "") {
413  error_log("Undefined pgservice_core in dbaccess.php");
414  exit(1);
415  }
416  $pg_service = $pgservice_core;
417  return $pg_service;
418 }
419 /**
420  * return variable from dbaccess.php
421  * @param string $varName
422  * @return string|null
423  * @throws Dcp\Exception
424  */
425 function getDbAccessValue($varName)
426 {
427  $included = false;
428  $filename = sprintf("%s/config/dbaccess.php", DEFAULT_PUBDIR);
429  if (file_exists($filename)) {
430  if (include ($filename)) {
431  $included = true;
432  }
433  } else {
434  $filename = ('dbaccess.php');
435  if (include ($filename)) {
436  $included = true;
437  }
438  }
439  if (!$included) {
440  throw new Dcp\Exception("FILE0005", $filename);
441  }
442 
443  if (!isset($$varName)) return null;
444  return $$varName;
445 }
447 {
448  static $pg_service = null;
449 
450  if ($pg_service) return $pg_service;
451  $pgservice_freedom = getDbAccessValue('pgservice_freedom');
452  if ($pgservice_freedom == "") {
453  error_log("Undefined pgservice_freedom in dbaccess.php");
454  exit(1);
455  }
456  $pg_service = $pgservice_freedom;
457  return $pg_service;
458 }
459 
461 {
462  error_log("Deprecated call to getDbName(dbaccess) : use getServiceName(dbaccess)");
463  return getServiceName($dbaccess);
464 }
465 
467 {
468  if (preg_match("/service='?([a-zA-Z0-9_.-]+)/", $dbaccess, $reg)) {
469  return $reg[1];
470  }
471  return '';
472 }
473 /**
474  * send simple query to database
475  * @param string $dbaccess access database coordonates
476  * @param string $query sql query
477  * @param string|bool|array &$result query result
478  * @param bool $singlecolumn set to true if only one field is return
479  * @param bool $singleresult set to true is only one row is expected (return the first row). If is combined with singlecolumn return the value not an array, if no results and $singlecolumn is true then $results is false
480  * @param bool $useStrict set to true to force exception or false to force no exception, if null use global parameter
481  * @throws Dcp\Db\Exception
482  * @return string error message. Empty message if no errors (when strict mode is not enable)
483  */
484 function simpleQuery($dbaccess, $query, &$result = array() , $singlecolumn = false, $singleresult = false, $useStrict = null)
485 {
486  global $SQLDEBUG;
487  static $sqlStrict = null;
488 
489  $dbid = getDbid($dbaccess);
490  $err = '';
491  if ($dbid) {
492  $result = array();
493  $sqlt1 = 0;
494  if ($SQLDEBUG) $sqlt1 = microtime();
495  $r = @pg_query($dbid, $query);
496  if ($r) {
497  if (pg_numrows($r) > 0) {
498  if ($singlecolumn) $result = pg_fetch_all_columns($r, 0);
499  else $result = pg_fetch_all($r);
500  if ($singleresult) $result = $result[0];
501  } else {
502  if ($singleresult && $singlecolumn) {
503  $result = false;
504  }
505  }
506  if ($SQLDEBUG) {
507  global $TSQLDELAY, $SQLDELAY;
508  $SQLDELAY+= microtime_diff(microtime() , $sqlt1); // to test delay of request
509  $TSQLDELAY[] = array(
510  "t" => sprintf("%.04f", microtime_diff(microtime() , $sqlt1)) ,
511  "s" => str_replace(array(
512  "from",
513  'where'
514  ) , array(
515  "\nfrom",
516  "\nwhere"
517  ) , $query) ,
518  "st" => getDebugStack(1)
519  );
520  }
521  } else {
522  $err = ErrorCode::getError('DB0100', pg_last_error($dbid) , $query);
523  }
524  } else {
526  }
527  if ($err) {
528 
529  if ($useStrict !== false) {
530  if ($sqlStrict === null) $sqlStrict = (getParam("CORE_SQLSTRICT") != "no");
531  if ($useStrict === true || $sqlStrict) {
532  throw new \Dcp\Db\Exception($err);
533  }
534  }
535  logDebugStack(-1, $err);
536  }
537 
538  return $err;
539 }
540 /**
541  * @param string $freedomctx
542  * @deprecated
543  * @return string
544  */
545 function getAuthType($freedomctx = "")
546 {
548 }
549 /**
550  * @param string $freedomctx
551  *
552  * @deprecated
553  * @return string
554  */
555 function getAuthProvider($freedomctx = "")
556 {
558 }
559 /**
560  * @param string $freedomctx
561  * @deprecated
562  * @return array
563  */
564 function getAuthProviderList($freedomctx = "")
565 {
567 }
568 /**
569  * @deprecated
570  * @param string $freedomctx
571  *
572  * @return array|mixed
573  * @throws \Dcp\Exception
574  */
575 function getAuthTypeParams($freedomctx = "")
576 {
578 }
579 /**
580  * @deprecated
581  */
582 function getAuthParam($freedomctx = "", $provider = "")
583 {
584  return Authenticator::getAuthParam($provider);
585 }
586 /**
587  * return shell commande for wsh
588  * depending of database (in case of several instances)
589  * @param bool $nice set to true if want nice mode
590  * @param int $userid the user identifier to send command (if 0 send like admin without specific user parameter)
591  * @param bool $sudo set to true if want to be send with sudo (need /etc/sudoers correctly configured)
592  * @return string the command
593  */
594 function getWshCmd($nice = false, $userid = 0, $sudo = false)
595 {
596  $wsh = '';
597  if ($nice) $wsh.= "nice -n +10 ";
598  if ($sudo) $wsh.= "sudo ";
599  $wsh.= escapeshellarg(DEFAULT_PUBDIR) . "/wsh.php ";
600  $userid = intval($userid);
601  if ($userid > 0) $wsh.= "--userid=$userid ";
602  return $wsh;
603 }
604 /**
605  * get the system user id
606  * @return int
607  */
608 function getUserId()
609 {
610  global $action;
611  if ($action) return $action->user->id;
612 
613  return 0;
614 }
615 /**
616  * exec list of unix command in background
617  * @param array $tcmd unix command strings
618  * @param $result
619  * @param $err
620  */
621 function bgexec($tcmd, &$result, &$err)
622 {
623  $foutname = uniqid(getTmpDir() . "/bgexec");
624  $fout = fopen($foutname, "w+");
625  fwrite($fout, "#!/bin/bash\n");
626  foreach ($tcmd as $v) {
627  fwrite($fout, "$v\n");
628  }
629  fclose($fout);
630  chmod($foutname, 0700);
631  // if (session_id()) session_write_close(); // necessary to close if not background cmd
632  exec("exec nohup $foutname > /dev/null 2>&1 &", $result, $err);
633  //if (session_id()) @session_start();
634 
635 }
636 
637 function wbartext($text)
638 {
639  wbar('-', '-', $text);
640 }
641 
642 function wbar($reste, $total, $text = "", $fbar = false)
643 {
644  static $preste, $ptotal;
645  if (!$fbar) $fbar = GetHttpVars("bar"); // for progress bar
646  if ($fbar) {
647  if ($reste === '-') $reste = $preste;
648  else $preste = $reste;
649  if ($total === '-') $total = $ptotal;
650  else $ptotal = $total;
651  if (file_exists("$fbar.lck")) {
652  $wmode = "w";
653  unlink("$fbar.lck");
654  } else {
655  $wmode = "a";
656  }
657  $ffbar = fopen($fbar, $wmode);
658  fputs($ffbar, "$reste/$total/$text\n");
659  fclose($ffbar);
660  }
661 }
662 
663 function getJsVersion()
664 {
665  include_once ("Class.QueryDb.php");
666  $q = new QueryDb("", "param");
667  $q->AddQuery("name='WVERSION'");
668  $l = $q->Query(0, 0, "TABLE");
669  $nv = 0;
670  foreach ($l as $k => $v) {
671  $nv+= intval(str_replace('.', '', $v["val"]));
672  }
673 
674  return $nv;
675 }
676 /**
677  * produce an anchor mailto '<a ...>'
678  * @param string $to a valid mail address or list separated by comma -supported by client-
679  * @param string $acontent
680  * @param string $subject
681  * @param string $cc
682  * @param string $bcc
683  * @param string $from
684  * @param array $anchorattr
685  * @param string $forcelink
686  * @internal param string $anchor content <a...>anchor content</a>
687  * @internal param array $treated as html anchor attribute : key is attribute name and value.. value
688  * @internal param string $force link to be produced according the value
689  * @return string like user admin dbname anakeen
690  */
691 function setMailtoAnchor($to, $acontent = "", $subject = "", $cc = "", $bcc = "", $from = "", $anchorattr = array() , $forcelink = "")
692 {
693 
694  global $action;
695 
696  if ($to == "") return '';
697  $classcode = '';
698  if ($forcelink == "mailto") {
699  $target = $forcelink;
700  } else {
701  $target = strtolower(GetParam("CORE_MAIL_LINK", "optimal"));
702  if ($target == "optimal") {
703  $target = "mailto";
704  }
705  }
706  $prot = ($_SERVER["HTTPS"] == "on" ? "https" : "http");
707  $host = $_SERVER["SERVER_NAME"];
708  $port = $_SERVER["SERVER_PORT"];
709 
710  $attrcode = "";
711  if (is_array($anchorattr)) {
712  foreach ($anchorattr as $k => $v) $attrcode.= ' ' . $k . '="' . $v . '"';
713  }
714 
715  $subject = str_replace(" ", "%20", $subject);
716 
717  switch ($target) {
718  case "mailto":
719  $link = '<a ';
720  $link.= 'href="mailto:' . $to . '"';
721  $link.= ($subject != "" ? '&Subject=' . $subject : '');
722  $link.= ($cc != "" ? '&cc=' . $cc : '');
723  $link.= ($bcc != "" ? '&bcc=' . $bcc : '');
724  $link.= '"';
725  $link.= $attrcode;
726  $link.= '>';
727  $link.= $acontent;
728  $link.= '</a>';
729  break;
730 
731  default:
732  $link = '<span ' . $classcode . '>' . $acontent . '</span>';
733  }
734  return $link;
735 }
736 /**
737  * Returns <kbd>true</kbd> if the string or array of string is encoded in UTF8.
738  *
739  * Example of use. If you want to know if a file is saved in UTF8 format :
740  * <code> $array = file('one file.txt');
741  * $isUTF8 = isUTF8($array);
742  * if (!$isUTF8) --> we need to apply utf8_encode() to be in UTF8
743  * else --> we are in UTF8 :)
744  * </code>
745  * @param mixed $string, or an array from a file() function.
746  * @return boolean
747  */
748 function isUTF8($string)
749 {
750  if (is_array($string)) return seems_utf8(implode('', $string));
751  else return seems_utf8($string);
752 }
753 /**
754  * Returns <kbd>true</kbd> if the string is encoded in UTF8.
755  *
756  * @param mixed $Str string
757  * @return boolean
758  */
759 function seems_utf8($Str)
760 {
761  return preg_match('!!u', $Str);
762 }
763 /**
764  * Initialise WHAT : set global $action whithout an authorized user
765  *
766  */
767 function WhatInitialisation($session = null)
768 {
769  global $action;
770  include_once ('Class.User.php');
771  include_once ('Class.Session.php');
772 
773  $CoreNull = "";
774  $core = new Application();
775  $core->Set("CORE", $CoreNull, $session);
776  if (!$session) {
777  $core->session = new Session();
778  }
779  $action = new Action();
780  $action->Set("", $core);
781  // i18n
782  $lang = $action->Getparam("CORE_LANG");
784 }
785 
787 {
788  global $action;
789  include_once ('Class.User.php');
790  include_once ('Class.Session.php');
791 
792  if ($login != "") {
793  $action->user = new Account(); //create user
794  $action->user->setLoginName($login);
795  }
796 }
797 /**
798  * Returns a random password of specified length composed
799  * with chars from the given charspace string or pattern
800  */
801 
802 function mkpasswd($length = 8, $charspace = "")
803 {
804  if ($charspace == "") {
805  $charspace = "[:alnum:]";
806  }
807  // Repeat a pattern e.g. [:a:3] -> [:a:][:a:][:a:]
808  $charspace = preg_replace_callback('/(\[:[a-z]+:)(\d+)(\])/', function ($matches)
809  {
810  return str_repeat($matches[1] . $matches[3], $matches[2]);
811  }
812  , $charspace);
813  // Expand [:patterns:]
814  $charspace = preg_replace(array(
815  "/\[:alnum:\]/",
816  "/\[:extrastrong:\]/",
817  "/\[:hex:\]/",
818  "/\[:lower:\]/",
819  "/\[:upper:\]/",
820  "/\[:digit:\]/",
821  "/\[:extra:\]/",
822  ) , array(
823  "[:lower:][:upper:][:digit:]",
824  "[:extra:],;:=+*/(){}[]&@#!?\"'<>",
825  "[:digit:]abcdef",
826  "abcdefghijklmnopqrstuvwxyz",
827  "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
828  "0123456789",
829  "-_.",
830  ) , $charspace);
831 
832  $passwd = "";
833  for ($i = 0; $i < $length; $i++) {
834  $passwd.= substr($charspace, rand(0, strlen($charspace) - 1) , 1);
835  }
836 
837  return $passwd;
838 }
839 /**
840  * return lcdate use in database : 'iso'
841  * Note: old 'dmy' format is not used since 3.2.8
842  * @return string 'iso'
843  */
844 function getLcdate()
845 {
846  return 'iso';
847 }
848 /**
849  *
850  * @param string $core_lang
851  * @return bool|array
852  */
853 function getLocaleConfig($core_lang = '')
854 {
855  if (empty($core_lang)) {
856  $core_lang = getParam("CORE_LANG", "fr_FR");
857  }
858  $lng = substr($core_lang, 0, 2);
859  if (preg_match('#^[a-z0-9_\.-]+$#i', $core_lang) && file_exists("locale/" . $lng . "/lang.php")) {
860  include ("locale/" . $lng . "/lang.php");
861  } else {
862  include ("locale/fr/lang.php");
863  }
864  if (!isset($lang) || !isset($lang[$core_lang]) || !is_array($lang[$core_lang])) {
865  return false;
866  }
867  return $lang[$core_lang];
868 }
869 
870 function getLocales()
871 {
872  static $locales = null;
873 
874  if ($locales === null) {
875  $lang = array();
876  include ('CORE/lang.php');
877  $locales = $lang;
878  }
879  return $locales;
880 }
881 /**
882  * use new locale language
883  * @param string $lang like fr_FR, en_US
884  * @throws \Dcp\Core\Exception
885  */
887 {
888  global $action;
889 
890  if (!$lang) {
891  return;
892  }
893  if ($action) {
894  $action->parent->param->SetVolatile("CORE_LANG", $lang);
895  $action->parent->setVolatileParam("CORE_LANG", $lang);
896  }
897  $lang.= ".UTF-8";
898  if (setlocale(LC_MESSAGES, $lang) === false) {
899  throw new Dcp\Core\Exception(sprintf(ErrorCodeCORE::CORE0011, $lang));
900  }
901  setlocale(LC_CTYPE, $lang);
902  setlocale(LC_MONETARY, $lang);
903  setlocale(LC_TIME, $lang);
904  //print $action->Getparam("CORE_LANG");
905  $number = 0;
906  $numberFile = sprintf("%s/locale/.gettextnumber", DEFAULT_PUBDIR);
907 
908  if (is_file($numberFile)) {
909  $number = trim(@file_get_contents($numberFile));
910  if ($number == "") {
911  $number = 0;
912  }
913  }
914  // Reset enum traduction cache
915  $a = null;
916  $enumAttr = new \NormalAttribute("", "", "", "", "", "", "", "", "", "", "", "", $a, "", "", "");
917  $enumAttr->resetEnum();
918 
919  $td = "main-catalog$number";
920 
921  putenv("LANG=" . $lang); // needed for old Linux kernel < 2.4
922  putenv("LANGUAGE="); // no use LANGUAGE variable
923  bindtextdomain($td, sprintf("%s/locale", DEFAULT_PUBDIR));
924  bind_textdomain_codeset($td, 'utf-8');
925  textdomain($td);
926  mb_internal_encoding('UTF-8');
927 }
928 // use UTF-8 by default
929 mb_internal_encoding('UTF-8');
logDebugStack($slice=1, $msg="")
Definition: Lib.Common.php:340
wbartext($text)
Definition: Lib.Common.php:637
seems_utf8($Str)
Definition: Lib.Common.php:759
global $SQLDEBUG
Definition: indexq.php:28
global $action
getDbAccessValue($varName)
Definition: Lib.Common.php:425
getMailAddr($userid, $full=false)
Definition: Lib.Common.php:133
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
$full
getDbAccessCore()
Definition: Lib.Common.php:373
Exception class use exceptionCode to identifiy correctly exception.
Definition: exceptions.php:19
$ret
static getAuthParam($provider="")
$message
$filename
addWarningMsg($msg)
Definition: Lib.Common.php:95
getLcdate()
Definition: Lib.Common.php:844
$file
if($famId) $s
if(!function_exists('pgettext')) ___($message, $context="")
Definition: Lib.Common.php:46
getAuthParam($freedomctx="", $provider="")
Definition: Lib.Common.php:582
static getError($code, $args=null)
Definition: ErrorCode.php:27
$lang
Definition: lang.php:18
getDbName($dbaccess)
Definition: Lib.Common.php:460
getLocaleConfig($core_lang= '')
Definition: Lib.Common.php:853
global $TSQLDELAY
Definition: indexq.php:29
isUTF8($string)
Definition: Lib.Common.php:748
global $SQLDELAY
Definition: indexq.php:28
$to
n___($message, $message_plural, $num, $context="")
Definition: Lib.Common.php:55
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
$subject
getAuthProvider($freedomctx="")
Definition: Lib.Common.php:555
AddLogMsg($msg, $cut=80)
Definition: Lib.Common.php:77
wbar($reste, $total, $text="", $fbar=false)
Definition: Lib.Common.php:642
getJsVersion()
Definition: Lib.Common.php:663
getLayoutFile($app, $layfile)
Definition: Lib.Common.php:258
getLocales()
Definition: Lib.Common.php:870
getFreedomContext()
Definition: Lib.Common.php:396
getAuthTypeParams($freedomctx="")
Definition: Lib.Common.php:575
getWshCmd($nice=false, $userid=0, $sudo=false)
Definition: Lib.Common.php:594
$app
getParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:193
getAuthType($freedomctx="")
Definition: Lib.Common.php:545
getDbid($dbaccess)
Definition: Lib.Common.php:353
mkpasswd($length=8, $charspace="")
Definition: Lib.Common.php:802
microtime_diff($a, $b)
Definition: Lib.Common.php:302
$login
Definition: dav.php:40
getServiceFreedom()
Definition: Lib.Common.php:446
setLanguage($lang)
Definition: Lib.Common.php:886
WhatInitialisation($session=null)
Definition: Lib.Common.php:767
getServiceCore()
Definition: Lib.Common.php:405
static getAuthTypeParams()
getDebugStack($slice=1)
Definition: Lib.Common.php:325
mb_ucfirst($s)
Definition: Lib.Common.php:105
$bcc
print
Definition: checklist.php:49
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
deprecatedFunction($msg= '')
Definition: Lib.Common.php:86
print_r2($z, $ret=false)
Definition: Lib.Common.php:65
getCurrentUser()
Definition: Lib.Common.php:250
getSessionValue($name, $def="")
Definition: Lib.Common.php:240
global $_SERVER
getDbAccessFreedom()
Definition: Lib.Common.php:378
getServiceName($dbaccess)
Definition: Lib.Common.php:466
getDbAccess()
Definition: Lib.Common.php:368
switch($command) exit
Definition: checkVault.php:46
getDbEnv()
Definition: Lib.Common.php:386
$cc
$fbar
$pgservice_core
Definition: pginfo.php:27
$from
setSystemLogin($login)
Definition: Lib.Common.php:786
setMaxExecutionTimeTo($limit)
Definition: Lib.Common.php:121
setMailtoAnchor($to, $acontent="", $subject="", $cc="", $bcc="", $from="", $anchorattr=array(), $forcelink="")
Definition: Lib.Common.php:691
$dbaccess
Definition: checkVault.php:17
if(($docid!==0)&&(!is_numeric($docid))) $query
getUserId()
Definition: Lib.Common.php:608
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
bgexec($tcmd, &$result, &$err)
Definition: Lib.Common.php:621
if($file) if($subject==""&&$file) if($subject=="") $err
getAuthProviderList($freedomctx="")
Definition: Lib.Common.php:564
N_($s)
Definition: Lib.Common.php:18
$value
mb_trim($string)
Definition: Lib.Common.php:113
$CoreNull
Definition: chgpasswd.php:32
getCoreParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:209
$core
Definition: chgpasswd.php:33
← centre documentaire © anakeen