17 include_once (
"FDL/Lib.Util.php");
27 if (count($Table) > 0) {
28 $sql_cond =
"(($column = '$Table[0]') ";
29 for ($i = 1; $i < count($Table); $i++) {
30 $sql_cond = $sql_cond .
"OR ($column = '$Table[$i]') ";
32 $sql_cond = $sql_cond .
")";
43 if (count($Table) > 0) {
45 $sql_cond =
"$column in (";
46 $sql_cond.= implode(
",", $Table);
49 foreach ($Table as & $v) $v = pg_escape_string($v);
50 $sql_cond =
"$column in ('";
51 $sql_cond.= implode(
"','", $Table);
65 if (count(
$a) == 0)
return false;
85 if ($errno == E_WARNING && (substr_count($errstr,
"DOMDocument::loadXML()") > 0)) {
86 throw new DOMException($errstr);
145 if (isset($sharedDoc) && ((!
$latest) || ($sharedDoc->locked != - 1))) {
146 if (($sharedDoc->doctype !=
'W') || (!isset($sharedDoc->doc))) {
147 if ($sharedDoc->id == $id) {
148 $sharedDoc->cached = 1;
158 $classname =
"Doc$fromid";
160 }
else if ($fromid == - 1) $classname =
"DocFam";
163 if ($classname !=
"") {
164 if (!include_once (
"FDL$gen/Class.$classname.php")) {
165 AddWarningMsg(sprintf(
"cannot include %s class", $classname));
178 if ((
$doc->doctype !=
'C') || (count(
$doc->attributes->attr) > 0)) {
216 include_once (
"FDL/Class.DocFam.php");
222 if (!$cdoc->isAffected())
return false;
224 $err = $cdoc->control(
'create');
225 if (
$err !=
"")
return false;
228 $classname =
"Doc" . $fromid;
230 include_once (
"FDL$GEN/Class.$classname.php");
234 $doc->revision =
"0";
237 $doc->fromid = $fromid;
239 $err =
$doc->setProfil($cdoc->cprofid);
240 $doc->setCvid($cdoc->ccvid);
241 $doc->wid = $cdoc->wid;
243 $doc->icon = $cdoc->icon;
244 $doc->usefor = $cdoc->usefor;
245 $doc->atags = $cdoc->atags;
246 if ($defaultvalues)
$doc->setDefaultValues($cdoc->getDefValues());
281 if (!($id > 0))
return false;
282 if (!is_numeric($id))
return false;
286 $result = pg_query($dbid, sprintf(
"select fromid from docfrom where id=%d", $id));
288 if (pg_num_rows($result) > 0) {
289 $arr = pg_fetch_array($result, 0, PGSQL_ASSOC);
290 $fromid = $arr[
"fromid"];
306 if (!($id > 0))
return false;
307 if (!is_numeric($id))
return false;
310 $result = pg_query($dbid, sprintf(
"SELECT name from docfam where id=(select fromid from docfrom where id=%d)", $id));
312 if (pg_num_rows($result) > 0) {
313 $arr = pg_fetch_array($result, 0, PGSQL_ASSOC);
314 $fromname = $arr[
"name"];
329 if (!($id > 0))
return false;
330 if (!is_numeric($id))
return false;
333 $result = pg_query($dbid,
"select fromid from docfam where id=$id;");
335 if (pg_num_rows($result) > 0) {
336 $arr = pg_fetch_array($result, 0, PGSQL_ASSOC);
337 $fromid = intval($arr[
"fromid"]);
354 if (!
$latest)
$sql = sprintf(
"select title, doctype, locked, initid, name from docread where id=%d", $id);
355 else $sql = sprintf(
"select title, doctype, locked, initid, name from docread where initid=(select initid from docread where id=%d) order by id desc limit 1", $id);
378 if (($id > 0) && count($prop) > 0) {
379 $sProps = implode(
',', $prop);
380 if (!
$latest)
$sql = sprintf(
"select %s, doctype, locked, initid from docread where id=%d", $sProps, $id);
381 else $sql = sprintf(
"select %s, doctype, locked, initid from docread where initid=(select initid from docread where id=%d) order by id desc limit 1", $sProps, $id);
384 if (!$t)
return null;
404 if (!($id > 0))
return false;
408 if ($fromid > 0) $table =
"doc$fromid";
409 else if ($fromid == - 1) $table =
"docfam";
410 if ($fromid == 0)
return false;
412 if (count($sqlfilters) > 0) $sqlcond =
"and (" . implode(
") and (", $sqlfilters) .
")";
413 if (count($result) == 0) {
415 $sql = sprintf(
"select *,getaperm('%s',profid) as uperm from only %s where id=%d %s", $userMemberOf, $table, $id, $sqlcond);
418 $scol = implode($result,
",");
419 $sql =
"select $scol from only $table where id=$id $sqlcond;";
422 if ($SQLDEBUG) $sqlt1 = microtime();
423 $result = pg_query($dbid,
$sql);
427 $TSQLDELAY[] = array(
432 if (($result) && (pg_num_rows($result) > 0)) {
433 $arr = pg_fetch_array($result, 0, PGSQL_ASSOC);
449 if (isset($t[$k]) && ($t[$k] !=
""))
return $t[$k];
450 if (strpos($t[
"attrids"],
"£$k") !== 0) {
452 $tvalues = explode(
"£", $t[
"values"]);
453 $tattrids = explode(
"£", $t[
"attrids"]);
454 foreach ($tattrids as $ka => $va) {
456 if (!isset($t[$va])) $t[$va] = $tvalues[$ka];
458 if ($tvalues[$ka] !=
"")
return $tvalues[$ka];
474 $tvalues = explode(
"£", $t[
"values"]);
475 $tattrids = explode(
"£", $t[
"attrids"]);
476 foreach ($tattrids as $ka => $va) {
478 if (!isset($t[$va])) $t[$va] = $tvalues[$ka];
490 if (isset(
$a->ordered) && isset($b->ordered)) {
491 if (
$a->ordered == $b->ordered)
return 0;
492 if (
$a->ordered > $b->ordered)
return 1;
495 if (isset(
$a->ordered))
return 1;
496 if (isset($b->ordered))
return -1;
502 if (
$a[
"cv_order"] == $b[
"cv_order"]) {
505 return (
$a[
"cv_order"] < $b[
"cv_order"]) ? -1 : 1;
518 static $_ODocCtrol =
false;
519 static $_memberOf =
false;
526 if ((
$tdoc[
"profid"] <= 0) || ($action->user->id == 1))
return true;
527 if (!isset(
$tdoc[
"uperm"])) {
528 $sql = sprintf(
"select getaperm('%s',%d) as uperm", $_memberOf,
$tdoc[
'profid']);
532 $err = $_ODocCtrol->ControlUp(
$tdoc[
"uperm"], $aclname);
545 static $_OgetDocObject;
547 if ($v[
"doctype"] ==
"C") {
548 if (!isset($_OgetDocObject[$k][
"family"])) $_OgetDocObject[$k][
"family"] =
new DocFam(
$dbaccess);
549 $_OgetDocObject[$k][
"family"]->Affect($v,
true);
550 $v[
"fromid"] =
"family";
552 if (!isset($_OgetDocObject[$k][$v[
"fromid"]])) $_OgetDocObject[$k][$v[
"fromid"]] =
createDoc(
$dbaccess, $v[
"fromid"],
false,
false);
555 $_OgetDocObject[$k][$v[
"fromid"]]->Affect($v,
true);
557 return $_OgetDocObject[$k][$v[
"fromid"]];
566 $tdoc = pg_fetch_array($res, NULL, PGSQL_ASSOC);
567 if (
$tdoc ===
false)
return false;
578 if ($n ===
false)
return false;
579 $tdoc = pg_fetch_array($n, NULL, PGSQL_ASSOC);
580 if (
$tdoc ===
false) {
582 if ($n ===
false)
return false;
583 $tdoc = pg_fetch_array($n, NULL, PGSQL_ASSOC);
584 if (
$tdoc ===
false)
return false;
596 foreach ($tres as $res) $n+= pg_num_rows($res);
609 include_once (
"FDL/Class.DocFam.php");
611 if (!isset($tFamIdName)) {
612 $tFamIdName = array();
614 $ql =
$q->Query(0, 0,
"TABLE");
615 foreach ($ql as $k => $v) {
616 if ($v[
"name"] !=
"") $tFamIdName[$v[
"name"]] = $v[
"id"];
619 if (isset($tFamIdName[$name])) {
620 return $tFamIdName[$name];
622 if (isset($tFamIdName[strtoupper($name) ])) {
623 return $tFamIdName[strtoupper($name) ];
625 $name = strtolower($name);
626 foreach ($tFamIdName as $famName =>
$famId) {
627 if (strtolower($famName) === $name) {
646 $fromonly = ($only) ?
"only" :
"";
663 static $first =
true;
666 if (!$name || strpos($name,
"\n") !==
false) {
673 @pg_prepare($dbid,
"getidfromname",
'select id from docname where name=$1');
677 $result = pg_execute($dbid,
"getidfromname", array(
680 $n = pg_num_rows($result);
682 $arr = pg_fetch_array($result, ($n - 1) , PGSQL_ASSOC);
694 simpleQuery(
getDbAccess() , sprintf(
"select initid from docread, docname where docread.id=docname.id and docname.name= '%s';", pg_escape_string($name)) , $initid,
true,
true);
707 static $first =
true;
713 @pg_prepare($dbid,
"getNameFromId",
'select name from docread where id=$1');
716 $result = pg_execute($dbid,
"getNameFromId", array(
719 $n = pg_num_rows($result);
721 $arr = pg_fetch_array($result, ($n - 1) , PGSQL_ASSOC);
722 $name = $arr[
"name"];
734 foreach ($tFamIdName as $k => $v) {
735 $action->lay->set(
"IDFAM_$k", $v);
746 if ($userid ==
"")
return false;
747 include_once (
"FDL/Lib.Dir.php");
750 if (!
$user->isAffected())
return false;
753 "us_whatid = '$userid'"
758 "us_whatid = '$userid'"
762 if (count(
$tdoc) == 0)
return false;
770 if ($i !=
$r)
return $i;
771 return $tdoc[
'title'];
782 if (!
$tdoc)
return null;
783 return (
$tdoc[
"locked"] == - 1);
791 if ($doc->id && $doc->fromid > 0) {
792 simpleQuery($doc->dbaccess, sprintf(
"select id from only doc%d where initid=%d and locked != -1 order by id", $doc->fromid, $doc->initid) ,
$r);
796 foreach (
$r as $docInfo) {
797 simpleQuery($doc->dbaccess, sprintf(
"update doc set locked= -1 where id=%d", $docInfo[
"id"]));
798 $rid[] = $docInfo[
"id"];
799 if ($docInfo[
"id"] == $doc->id) {
806 $action->log->warning(sprintf(_(
"Fix multiple alive document for \"%s\" #%s") , $doc->
getTitle() , implode(
', ', $rid)));
813 if ($vis ==
"I")
return $vis;
814 if ($fvis ==
"H")
return $fvis;
815 if (($fvis ==
"R") && (($vis ==
"W") || ($vis ==
"U") || ($vis ==
"S")))
return $fvis;
816 if (($fvis ==
"R") && ($vis ==
"O"))
return "H";
817 if (($fvis ==
"O") && ($vis ==
"W"))
return $fvis;
818 if (($fvis ==
"S") && (($vis ==
"W") || ($vis ==
"O")))
return $fvis;
819 if ($fvis ==
"I")
return $fvis;
821 if ($ffvis && ($vis ==
'W' || $vis ==
'O' || $vis ==
'S')) {
822 if ($ffvis ==
'S')
return 'S';
823 if ($ffvis ==
'R')
return 'R';
841 if (!($initid > 0))
return false;
845 simpleQuery(
$dbaccess, sprintf(
"select fromid from docread where initid=%d order by id desc limit 1", $initid) , $tf,
true);
846 if (count($tf) > 0) {
850 if ($fromid > 0) $table =
"doc$fromid";
851 else if ($fromid == - 1) $table =
"docfam";
854 if (count($sqlfilters) > 0) $sqlcond =
"and (" . implode(
") and (", $sqlfilters) .
")";
856 $userid = $action->user->id;
859 $sql = sprintf(
"select *,getaperm('%s',profid) as uperm from only %s where initid=%d and doctype != 'T' and locked != -1 %s", $userMember, $table, $initid, $sqlcond);
863 $sql = sprintf(
"select *,getaperm('%s',profid) as uperm from only %s where initid=%d and doctype != 'T' %s order by id desc limit 1", $userMember, $table, $initid, $sqlcond);
867 if ($result && (count($result) > 0)) {
868 if (count($result) > 1)
addWarningMsg(sprintf(
"document %d : multiple alive revision", $initid));
887 if (!is_array($ids))
return null;
890 foreach ($ids as $k => $v) $ids[$k] = intval($v);
891 $sids = implode($ids,
",");
892 $sql = sprintf(
"SELECT id,initid from docread where initid in (SELECT initid from docread where id in (%s)) and locked != -1;", $sids);
893 $result = @pg_query($dbid,
$sql);
895 $arr = pg_fetch_all($result);
897 foreach ($arr as $v) $tlids[$v[
"initid"]] = $v[
"id"];
911 if (is_array($initid))
return null;
913 simpleQuery(
$dbaccess, sprintf(
"select id from docread where initid='%d' and locked != -1", $initid) , $id,
true,
true);
914 if ($id > 0)
return $id;
916 simpleQuery(
$dbaccess, sprintf(
"select id from docread where initid='%d' order by id desc limit 1", $initid) , $id,
true,
true);
917 if ($id > 0)
return $id;
919 simpleQuery(
$dbaccess, sprintf(
"select id from docread where initid=(select initid from docread where id=%d) and locked != -1", $initid) , $id,
true,
true);
920 if ($id > 0)
return $id;
935 if (!($initid > 0))
return false;
938 $sql = sprintf(
"select fromid from docread where initid=%d and revision=%d", $initid, $rev);
940 if ($fromid > 0) $table =
"doc$fromid";
941 else if ($fromid == - 1) $table =
"docfam";
944 $sql = sprintf(
"select *,getaperm('%s',profid) as uperm from only %s where initid=%d and revision=%d ", $userMember, $table, $initid, $rev);
964 $initid = intval($initid);
965 if (!($initid > 0))
return false;
968 if ($fromid == - 1) $table =
"docfam";
970 $result = @pg_query($dbid,
"SELECT revision from $table where initid=$initid order by revision desc limit 1;");
971 if ($result && (pg_num_rows($result) > 0)) {
972 $arr = pg_fetch_array($result, 0, PGSQL_ASSOC);
973 return $arr[
'revision'];
987 if (
$err !=
"")
return false;
988 $dir->setValue(
"BA_TITLE", sprintf(_(
"root for %s") ,
$doc->title));
989 $dir->setValue(
"BA_DESC", _(
"default folder"));
990 $dir->setValue(
"FLD_ALLBUT",
"1");
991 $dir->setValue(
"FLD_FAM",
$doc->title .
"\n" . _(
"folder") .
"\n" . _(
"search"));
993 $dir->setValue(
"FLD_SUBFAM",
"yes\nyes\nyes");
1008 $uid = $action->user->id;
1009 $pname = sprintf(
"PERSONAL-PROFIL-%d", $uid);
1011 if (!$p->isAffected()) {
1016 $p->setValue(
"ba_title", sprintf(_(
"Personal profile for %s %s") , $action->user->firstname, $action->user->lastname));
1017 $p->setValue(
"prf_desc", sprintf(_(
"Only %s %s can view and edit") , $action->user->firstname, $action->user->lastname));
1021 $err = $p->setControl();
1022 $p->setProfil($p->id);
1037 if (!$node)
return false;
1038 $document = $node->ownerDocument;
1039 $nodeAsString = $document->saveXML($node);
1040 preg_match(
'!<.*?>(.*)</.*?>!s', $nodeAsString, $match);
1050 $html = preg_replace(
"/<\/?span[^>]*>/s",
"", $html);
1051 $html = preg_replace(
"/<\/?font[^>]*>/s",
"", $html);
1052 $html = preg_replace(
"/<\/?meta[^>]*>/s",
"", $html);
1053 $html = preg_replace(
"/<style[^>]*>.*?<\/style>/s",
"", $html);
1054 $html = preg_replace(
"/<([^>]*) style=\"[^\"]*\"/s",
"<\\1", $html);
1055 $html = preg_replace(
"/<([^>]*) class=\"[^\"]*\"/s",
"<\\1", $html);
GetSqlCond2($Table, $column)
static getMemberOfVector($uid=0, $strict=false)
getNextDoc($dbaccess, &$tres)
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
fixMultipleAliveDocument(Doc &$doc)
static set($key, &$item, $force=false)
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
getDocFromUserId($dbaccess, $userid)
controlTdoc(&$tdoc, $aclname)
getIdFromTitle($dbaccess, $title, $famid="", $only=false)
getLatestTDoc($dbaccess, $initid, $sqlfilters=array(), $fromid=false)
getDocProperties($id, $latest=true, array $prop=array("title"))
getNextDbObject($dbaccess, $res)
getMyProfil($dbaccess, $create=true)
getDocTitle($id, $latest=true)
isFixedDoc($dbaccess, $id)
getFromName($dbaccess, $id)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
internalGetDocCollection($dbaccess, $dirid, $start="0", $slice="ALL", $sqlfilters=array(), $userid=1, $qtype="LIST", $fromid="", $distinct=false, $orderby="title", $latest=true, $trash="", &$debug=null, $folderRecursiveLevel=2, $join= '',\SearchDoc &$searchDoc=null)
getFamIdFromName($dbaccess, $name)
getTitle($id="-1", $def="", $latest=false)
new_Doc($dbaccess, $id= '', $latest=false)
GetSqlCond($Table, $column, $integer=false)
getFamFromId($dbaccess, $id)
getNameFromId($dbaccess, $id)
getRevTDoc($dbaccess, $initid, $rev)
ComputeVisibility($vis, $fvis, $ffvis= '')
getFromId($dbaccess, $id)
setFamidInLayout(Action &$action)
getLatestDocIds($dbaccess, $ids)
getLatestRevisionNumber($dbaccess, $initid, $fromid=0)
getIdFromName($dbaccess, $name)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
if($file) if($subject==""&&$file) if($subject=="") $err
addHistoryEntry($comment= '', $level=DocHisto::INFO, $code= '', $uid= '')
getLatestDocId($dbaccess, $initid)
HandleXmlError($errno, $errstr, $errfile, $errline)
getDocObject($dbaccess, $v, $k=0)