16 include_once (
"Class.DbObj.php");
62 create table docrel ( sinitid int not null,
70 create index i_docrelc on docrel(cinitid);
71 create index i_docrels on docrel(sinitid);
72 create unique index docrel_u on docrel(sinitid,cinitid,type);
78 include_once (
"Class.QueryDb.php");
79 if (empty($this->sinitid)) {
82 $q =
new QueryDb($this->dbaccess, get_class($this));
83 $q->AddQuery(sprintf(
"sinitid = %d", $this->sinitid));
84 if ($reltype !=
"")
$q->AddQuery(
"type='$reltype'");
85 if (
$doctype !=
"")
$q->AddQuery(
"doctype='$doctype'");
86 $userid = $action->user->id;
88 $l =
$q->Query(0, $limit,
"TABLE");
89 if (is_array($l))
return $l;
94 include_once (
"Class.QueryDb.php");
95 $q =
new QueryDb($this->dbaccess, get_class($this));
96 $q->AddQuery(
"cinitid=" . $this->sinitid);
97 if ($reltype !=
"")
$q->AddQuery(
"type='$reltype'");
98 if (
$doctype !=
"")
$q->AddQuery(
"doctype='$doctype'");
99 $l =
$q->Query(0, $limit,
"TABLE");
100 if (is_array($l))
return $l;
114 else $this->
exec_query(
"delete from docrel where sinitid=" .
$sinitid .
" and type != 'folder'");
125 $nattr =
$doc->GetNormalAttributes();
127 $savePoint = uniqid(
"dcp:initrelation");
130 foreach ($nattr as $k => $v) {
131 if (isset(
$doc->$k) && ($v->type ==
"docid" || $v->type ==
"account")) {
134 if (
$doc->getOldRawValue($v->id) ===
false) {
139 pg_query($this->dbid, sprintf(
"delete from docrel where sinitid=%d and type='%s'",
$doc->initid, pg_escape_string($v->id)));
140 if ($v->inArray()) $tv = array_unique(
$doc->getMultipleRawValues($v->id));
145 foreach ($tv as $relid) {
146 if (strpos($relid,
'<BR>') !==
false) {
147 $tt = explode(
'<BR>', $relid);
148 foreach ($tt as $brelid) {
149 if (is_numeric($brelid)) $tvrel[] = intval($brelid);
151 } elseif (is_numeric($relid)) {
152 $tvrel[] = intval($relid);
155 $tvrel = array_unique($tvrel);
169 $tv = array_filter($tv,
function (
$a)
173 if (count($tv) > 0) {
175 $sql = sprintf(
"select distinct on (initid, icon, title) initid, icon, title from docread where initid in (SELECT initid from docread where %s) and locked != -1;", getsqlcond($tv,
'id',
true));
181 while ($row = @pg_fetch_array($this->res,
$c, PGSQL_ASSOC)) {
182 $tin[] = sprintf(
"%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",
$doc->initid, $row[
"initid"], $this->escapePgCopyChars(
$doc->title) , $this->
escapePgCopyChars($row[
"title"]) ,
$doc->icon, $row[
"icon"], $reltype,
$doc->doctype);
186 pg_copy_from($this->dbid,
"docrel", $tin);
194 $str = str_replace(
"\\",
"\\\\", $str);
196 $str = str_replace(
"\r",
" ", $str);
197 $str = str_replace(
"\n",
" ", $str);
198 $str = str_replace(
"\t",
" ", $str);
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
exec_query($sql, $lvl=0, $prepare=false)
initRelations(&$doc, $force=false)
resetRelations($type="", $sinitid=0)
lockPoint($exclusiveLock, $exclusiveLockPrefix= '')
getIRelations($reltype="", $doctype="", $limit=0)
getRelations($reltype="", $doctype="", $limit=0)
copyRelations(&$tv, &$doc, $reltype)