18 include_once (
"Class.DbObj.php");
64 create table docrel ( sinitid int not null,
72 create index i_docrelc on docrel(cinitid);
73 create index i_docrels on docrel(sinitid);
74 create unique index docrel_u on docrel(sinitid,cinitid,type);
80 include_once (
"Class.QueryDb.php");
81 $q =
new QueryDb($this->dbaccess, get_class($this));
82 $q->AddQuery(
"sinitid=" . $this->sinitid);
83 if ($reltype !=
"")
$q->AddQuery(
"type='$reltype'");
84 if (
$doctype !=
"")
$q->AddQuery(
"doctype='$doctype'");
85 $userid = $action->user->id;
87 $l =
$q->Query(0, $limit,
"TABLE");
88 if (is_array($l))
return $l;
93 include_once (
"Class.QueryDb.php");
94 $q =
new QueryDb($this->dbaccess, get_class($this));
95 $q->AddQuery(
"cinitid=" . $this->sinitid);
96 if ($reltype !=
"")
$q->AddQuery(
"type='$reltype'");
97 if (
$doctype !=
"")
$q->AddQuery(
"doctype='$doctype'");
98 $l =
$q->Query(0, $limit,
"TABLE");
99 if (is_array($l))
return $l;
113 else $this->
exec_query(
"delete from docrel where sinitid=" .
$sinitid .
" and type != 'folder'");
124 $nattr =
$doc->GetNormalAttributes();
126 $savePoint = uniqid(
"initrelation");
128 pg_query($this->dbid,
"lock table docrel in exclusive mode");
129 foreach ($nattr as $k => $v) {
130 if (isset(
$doc->$k) && ($v->type ==
"docid" || $v->type ==
"account")) {
133 if (
$doc->getOldValue($v->id) ===
false) {
138 pg_query($this->dbid, sprintf(
"delete from docrel where sinitid=%d and type='%s'",
$doc->initid, pg_escape_string($v->id)));
139 if ($v->inArray()) $tv = array_unique(
$doc->getTValue($v->id));
144 foreach ($tv as $relid) {
145 if (strpos($relid,
'<BR>') !==
false) {
146 $tt = explode(
'<BR>', $relid);
147 foreach ($tt as $brelid) {
148 if (is_numeric($brelid)) $tvrel[] = intval($brelid);
150 } elseif (is_numeric($relid)) {
151 $tvrel[] = intval($relid);
154 $tvrel = array_unique($tvrel);
168 $tv = array_filter($tv,
function (
$a)
172 if (count($tv) > 0) {
174 $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));
180 while ($row = @pg_fetch_array($this->res,
$c, PGSQL_ASSOC)) {
181 $tin[] = sprintf(
"%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",
$doc->initid, $row[
"initid"], str_replace(
"\t",
" ",
$doc->title) , str_replace(
"\t",
" ", $row[
"title"]) ,
$doc->icon, $row[
"icon"], $reltype,
$doc->doctype);
185 pg_copy_from($this->dbid,
"docrel", $tin);