18 include_once (
"Lib.Prefix.php");
40 if (isset($action->parent)) $action->parent->AddLogMsg($msg, $cut);
49 if (isset($action->parent)) $action->parent->log->deprecated(
"Deprecated : " . $msg);
54 if (isset($action->parent)) $action->parent->AddWarningMsg($msg);
66 if (
$user->isAffected()) {
69 $pren =
'"' . trim(str_replace(
'"',
'-', ucwords(strtolower(
$user->getDisplayName(
$user->id))))) .
'" <';
72 return $pren .
$user->getMail() . $postn;
80 if (isset($tmp) && !empty($tmp)) {
83 $tmp =
getParam(
'CORE_TMPDIR', $def);
101 if ($action)
return $action->getParam(
$name, $def);
116 static $params = null;
120 $err =
simpleQuery(
"",
"select name, val from paramv where (type = 'G') or (type='A' and appid = (select id from application where name ='CORE'));", $tparams);
122 foreach ($tparams as $p) {
123 $params[$p[
'name']] = $p[
'val'];
127 if (array_key_exists(
$name, $params) ==
false) {
128 error_log(sprintf(
"parameter %s not found use %s instead",
$name, $def));
130 return $params[
$name] ? $params[
$name] : $def;
141 if ($action)
return $action->read(
$name, $def);
147 if (strstr($layfile,
'..')) {
150 if (!strstr($layfile,
'.')) $layfile.=
".xml";
151 $socStyle = Getparam(
"CORE_SOCSTYLE");
152 $style = Getparam(
"STYLE");
153 $root = Getparam(
"CORE_PUBDIR");
154 if ($socStyle !=
"") {
155 $file = $root .
"/STYLE/$socStyle/Layout/$layfile";
156 if (file_exists(
$file)) {
160 $file = $root .
"/STYLE/$socStyle/Layout/" . strtolower($layfile);
161 if (file_exists(
$file)) {
165 $file = $root .
"/STYLE/$style/Layout/$layfile";
166 if (file_exists(
$file)) {
170 $file = $root .
"/STYLE/$style/Layout/" . strtolower($layfile);
171 if (file_exists(
$file)) {
176 $file = $root .
"/$app/Layout/$layfile";
177 if (file_exists(
$file)) {
181 $file = $root .
"/$app/Layout/" . strtolower($layfile);
182 if (file_exists(
$file)) {
196 $s = mb_strtoupper(mb_substr(
$s, 0, 1,
'UTF-8') ,
'UTF-8') . mb_substr(
$s, 1, mb_strlen(
$s) ,
'UTF-8');
202 list($a_micro, $a_int) = explode(
' ',
$a);
203 list($b_micro, $b_int) = explode(
' ', $b);
204 if ($a_int > $b_int) {
205 return ($a_int - $b_int) + ($a_micro - $b_micro);
206 } elseif ($a_int == $b_int) {
207 if ($a_micro > $b_micro) {
208 return ($a_int - $b_int) + ($a_micro - $b_micro);
209 } elseif ($a_micro < $b_micro) {
210 return ($b_int - $a_int) + ($b_micro - $a_micro);
215 return ($b_int - $a_int) + ($b_micro - $a_micro);
220 $td = @debug_backtrace(
false);
221 if (!is_array($td))
return;
223 foreach (
$t as $k =>
$s) {
224 unset(
$t[$k][
"args"]);
233 if (!isset($CORE_DBID) || !($CORE_DBID[
$dbaccess])) {
234 $CORE_DBID[
$dbaccess] = pg_connect($dbaccess);
235 if (!$CORE_DBID[$dbaccess]) {
237 error_log(
"Fail to DB connect to : $dbaccess");
238 header(
'HTTP/1.0 503 DB connection unavalaible');
262 error_log(
"Deprecated call to getDbEnv() : use getFreedomContext()");
268 $freedomctx = getenv(
"freedom_context");
269 if ($freedomctx ==
false || $freedomctx ==
"") {
277 static $pg_service = null;
280 if ($pg_service)
return $pg_service;
283 if ($freedomctx !=
"") {
284 $filename =
"$pubdir/context/$freedomctx/dbaccess.php";
290 include (
"dbaccess.php");
293 error_log(
"Undefined pgservice_core in dbaccess.php");
302 static $pg_service = null;
305 if ($pg_service)
return $pg_service;
308 if ($freedomctx !=
"") {
309 $filename =
"$pubdir/context/$freedomctx/dbaccess.php";
315 include (
"dbaccess.php");
318 error_log(
"Undefined pgservice_freedom in dbaccess.php");
327 error_log(
"Deprecated call to getDbName(dbaccess) : use getServiceName(dbaccess)");
333 if (preg_match(
"/service='?([a-zA-Z0-9_.-]+)/",
$dbaccess, $reg)) {
352 if ($SQLDEBUG) $sqlt1 = microtime();
355 if (pg_numrows(
$r) > 0) {
356 if ($singlecolumn) $result = pg_fetch_all_columns(
$r, 0);
357 else $result = pg_fetch_all(
$r);
358 if ($singleresult) $result = $result[0];
360 if ($singleresult) $result =
false;
365 $TSQLDELAY[] = array(
367 "s" => str_replace(array(
380 }
else $err = sprintf(_(
"cannot connect to %s") ,
$dbaccess);
387 if (array_key_exists(
'authtype',
$_GET)) {
388 return $_GET[
'authtype'];
391 if ($freedomctx ==
"") {
394 if ($freedomctx !=
"") {
395 $filename =
"$pubdir/context/$freedomctx/dbaccess.php";
401 if ($freedom_authtype ==
"") {
402 $freedom_authtype =
"apache";
405 return trim($freedom_authtype);
412 if ($freedomctx ==
"") {
415 if ($freedomctx !=
"") {
416 $filename =
"$pubdir/context/$freedomctx/dbaccess.php";
422 if ($freedom_authprovider ==
"") {
423 $freedom_authprovider =
"apache";
426 return trim($freedom_authprovider);
440 if ($freedomctx ==
"") {
443 if ($freedomctx !=
"") {
444 $filename =
"$pubdir/context/$freedomctx/dbaccess.php";
449 if (!is_array($freedom_authtypeparams)) {
450 printf(_(
"filename %s does not contain freedom_authtypeparams variable. May be old syntax for configuration file") ,
$filename);
454 if (!array_key_exists(
getAuthType() , $freedom_authtypeparams)) {
455 error_log(__FUNCTION__ .
":" . __LINE__ .
"> authtype " .
getAuthType() .
" does not exists in freedom_authtypeparams");
466 if ($provider ==
"")
return array();
468 if ($freedomctx ==
"") {
471 if ($freedomctx !=
"") {
472 $filename =
"$pubdir/context/$freedomctx/dbaccess.php";
478 if (!is_array($freedom_providers)) {
482 if (!array_key_exists($provider, $freedom_providers)) {
483 error_log(__FUNCTION__ .
":" . __LINE__ .
"provider " . $provider .
" does not exists in freedom_providers");
487 return $freedom_providers[$provider];
497 function getWshCmd($nice =
false, $userid = 0, $sudo =
false)
500 $wsh =
"export freedom_context=\"$freedomctx\";";
501 if ($nice) $wsh.=
"nice -n +10 ";
502 if ($sudo) $wsh.=
"sudo ";
503 $wsh.= escapeshellarg(GetParam(
"CORE_PUBDIR")) .
"/wsh.php ";
504 $userid = intval($userid);
505 if ($userid > 0) $wsh.=
"--userid=$userid ";
515 if ($action)
return $action->user->id;
525 $foutname = uniqid(
getTmpDir() .
"/bgexec");
526 $fout = fopen($foutname,
"w+");
527 fwrite($fout,
"#!/bin/bash\n");
528 foreach ($tcmd as $v) {
529 fwrite($fout,
"$v\n");
532 chmod($foutname, 0700);
534 exec(
"exec nohup $foutname > /dev/null 2>&1 &", $result,
$err);
541 wbar(
'-',
'-', $text);
546 static $preste, $ptotal;
553 if (file_exists(
"$fbar.lck")) {
559 $ffbar = fopen(
$fbar, $wmode);
560 fputs($ffbar,
"$reste/$total/$text\n");
567 include_once (
"Class.QueryDb.php");
569 $q->AddQuery(
"name='VERSION'");
570 $l =
$q->Query(0, 0,
"TABLE");
572 foreach ($l as $k => $v) {
573 $nv+= intval(str_replace(
'.',
'', $v[
"val"]));
594 if (
$to ==
"")
return '';
596 if ($forcelink ==
"mailto" || $forcelink ==
"squirrel") {
599 $target = strtolower(GetParam(
"CORE_MAIL_LINK",
"optimal"));
602 if ($action->user->iddomain > 9) {
604 $query->basic_elem->sup_where = array(
611 $queryact =
new QueryDb($action->dbaccess,
"Action");
612 $queryact->AddQuery(
"id_application=" .
$list[0][
"id"]);
613 $queryact->AddQuery(
"root='Y'");
614 $listact = $queryact->Query(0, 0,
"TABLE");
615 $root_acl_name = $listact[0][
"acl"];
616 if ($action->HasPermission($root_acl_name,
$list[0][
"id"])) {
623 $prot = (
$_SERVER[
"HTTPS"] ==
"on" ?
"https" :
"http");
628 if (is_array($anchorattr)) {
629 foreach ($anchorattr as $k => $v) $attrcode.=
' ' . $k .
'="' . $v .
'"';
637 $link.=
'href="' . $prot .
"://" . $host .
":" .
$port .
"/" . GetParam(
"CORE_MAIL_SQUIRRELBASE",
"squirrel") .
"/src/compose.php?";
638 $link.=
"&send_to=" .
$to;
640 $link.= (
$cc !=
"" ?
'&cc=' .
$cc :
'');
641 $link.= (
$bcc !=
"" ?
'&bcc=' .
$bcc :
'');
651 $link.=
'href="mailto:' .
$to .
'"';
653 $link.= (
$cc !=
"" ?
'&cc=' .
$cc :
'');
654 $link.= (
$bcc !=
"" ?
'&bcc=' .
$bcc :
'');
663 $link =
'<span ' . $classcode .
'>' . $acontent .
'</span>';
681 if (is_array($string))
return seems_utf8(implode(
'', $string));
692 for ($i = 0; $i < strlen($Str); $i++) {
693 if (ord($Str[$i]) < 0x80) $n = 0; # 0bbbbbbb
694 elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n = 1; # 110bbbbb
695 elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n = 2; # 1110bbbb
696 elseif ((ord($Str[$i]) & 0xF0) == 0xF0) $n = 3; # 1111bbbb
697 else return false; # Does not match any model
698 for ($j = 0; $j < $n; $j++) { #
n octets that match 10bbbbbb follow ?
699 if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
return false;
710 if (@include_once (
'FDL/Lib.Usercard.php')) {
711 $usefreedom = (GetParam(
"USE_FREEDOM_USER") !=
"no");
723 include_once (
'Class.User.php');
724 include_once (
'Class.Session.php');
731 $action->Set(
"",
$core);
733 $lang = $action->Getparam(
"CORE_LANG");
740 include_once (
'Class.User.php');
741 include_once (
'Class.Session.php');
744 $action->user =
new User();
745 $action->user->setLoginName($login);
755 if ($charspace ==
"") {
756 $charspace =
"[:alnum:]";
759 $charspace = preg_replace(
"/(\[:[a-z]+:)(\d+)(\])/e",
"str_repeat('\\1\\3',\\2)", $charspace);
761 $charspace = preg_replace(array(
763 "/\[:extrastrong:\]/",
770 "[:lower:][:upper:][:digit:]",
771 "[:extra:],;:=+*/(){}[]&@#!?\"'<>",
773 "abcdefghijklmnopqrstuvwxyz",
774 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
780 for ($i = 0; $i < $length; $i++) {
781 $passwd.= substr($charspace, rand(0, strlen($charspace) - 1) , 1);
792 return substr(
getParam(
"CORE_LCDATE") , 0, 3);
801 if (empty($core_lang)) {
802 $core_lang =
getParam(
"CORE_LANG",
"fr_FR");
804 $lng = substr($core_lang, 0, 2);
805 if (preg_match(
'#^[a-z0-9_\.-]+$#i', $core_lang) && file_exists(
"locale/" . $lng .
"/lang.php")) {
806 include (
"locale/" . $lng .
"/lang.php");
808 include (
"locale/fr/lang.php");
810 if (!isset(
$lang) || !isset(
$lang[$core_lang]) || !is_array(
$lang[$core_lang])) {
813 return $lang[$core_lang];
824 setlocale(LC_MESSAGES,
$lang);
825 setlocale(LC_CTYPE,
$lang);
826 setlocale(LC_MONETARY,
$lang);
827 setlocale(LC_TIME,
$lang);
830 if (is_file(
"$pubdir/locale/.gettextnumber")) {
831 $number = trim(@file_get_contents(
"$pubdir/locale/.gettextnumber"));
837 $td =
"freedom-catalog$number";
839 putenv(
"LANG=" .
$lang);
840 bindtextdomain($td,
"$pubdir/locale");
841 bind_textdomain_codeset($td,
'utf-8');
843 mb_internal_encoding(
'UTF-8');