18 include_once (
"FDL/Class.PDir.php");
19 include_once (
"FDL/Class.QueryDir.php");
23 define(
"UNCLASS_FLD", 10);
32 private $authfam =
false;
33 private $norestrict =
false;
42 if ($this->fromid ==
"") $this->fromid =
FAM_DIR;
52 include_once (
"FDL/freedom_util.php");
53 include_once (
"FDL/Lib.Dir.php");
55 "owner = -" . $this->userid
56 ) , $this->userid,
"LIST",
"DIR");
60 if (!$create)
return false;
61 $home =
createDoc($this->dbaccess,
"DIR");
63 if (!$home) $action->exitError(sprintf(_(
"no privilege to create this kind (%d) of document") ,
getFamIdFromName(
$dbaccess,
"DIR")));
65 $home->owner = - $this->userid;
66 include_once (
"Class.User.php");
68 $home->title =
$user->firstname .
" " .
$user->lastname;
69 $home->setTitle($home->title);
70 $home->icon =
'fldhome.gif';
74 $privlocked =
createDoc($this->dbaccess,
"SEARCH");
75 if (!$privlocked) $action->exitError(sprintf(_(
"no privilege to create this kind (%d) of document") ,
getFamIdFromName(
$dbaccess,
"SEARCH")));
77 $privlocked->title = (_(
"locked document of ") . $home->title);
79 $privlocked->AddQuery(
"select * from doc where (doctype!='Z') and" .
" (locked=" . $this->userid .
") ");
80 $home->AddFile($privlocked->id);
83 if (
getParam(
"FREEDOM_IDBASKET") ==
"") {
85 $bas =
createDoc($this->dbaccess,
"BASKET");
86 if (!$bas) $action->exitError(sprintf(_(
"no privilege to create this kind (%d) of document") ,
getFamIdFromName(
$dbaccess,
"BASKET")));
89 $query->AddQuery(
"owner = " . $this->userid);
92 $bas->setvalue(
"ba_title", _(
"Document basket"));
93 $bas->setvalue(
"ba_desc", sprintf(_(
"basket of %s") , $home->title));
96 $home->AddFile($bas->id);
102 $action->parent->param->Set(
"FREEDOM_IDBASKET", $basid,
PARAM_USER . $this->userid, $action->parent->GetIdFromName(
"FREEDOM"));
103 $action->parent->session->close();
115 if ($this->
isLocked(
true))
return sprintf(_(
"folder is locked. Cannot containt modification"));
120 $this->
addLog(
'clearcontent');
121 $err = $this->
exec_query(
"delete from fld where dirid=" . $this->initid);
151 foreach ($tdocid as
$docid) {
180 if ($this->
isLocked(
true))
return sprintf(_(
"folder is locked. Cannot containt modification"));
197 function AddFile(
$docid,
$mode =
"latest", $noprepost =
false, $forcerestrict =
false, $nocontrol =
false)
214 if (!
$doc->isAffected())
return sprintf(_(
"Cannot add in %s folder, doc id (%d) unknown") ,
$this->title,
$docid);
221 if (!
$qf->Exists()) {
226 if ((!$forcerestrict) && (!$this->
isAuthorized(
$doc->fromid)))
return sprintf(_(
"Cannot add %s in %s folder, restriction set to add this kind of document") ,
$doc->title, $this->title);
230 AddLogMsg(sprintf(_(
"Add %s in %s folder") ,
$doc->title, $this->title));
231 $this->
AddComment(sprintf(_(
"Document %s inserted") ,
$doc->title));
232 $doc->addComment(sprintf(_(
"Document inserted in %s folder") , $this->title,
HISTO_INFO,
"MOVEADD"));
234 $this->
addLog(
'addcontent', array(
237 "title" =>
$doc->title
241 if (
$doc->profid == 0) {
242 switch (
$doc->defProfFamId) {
251 if (
$err ==
"")
$doc->addComment(sprintf(_(
"Change profil to default document profil : %d") ,
$profid));
260 if (
$doc->getValue(
"FLD_PDIRID") ==
"") {
261 $doc->setValue(
"FLD_PDIRID", $this->
getValue(
"FLD_PDIRID"));
262 $doc->setValue(
"FLD_PDIR", $this->
getValue(
"FLD_PDIR"));
264 if (
$doc->getValue(
"FLD_PDOCID") ==
"") {
265 $doc->setValue(
"FLD_PDOCID", $this->
getValue(
"FLD_PDOCID"));
266 $doc->setValue(
"FLD_PDOC", $this->
getValue(
"FLD_PDOC"));
269 if (
$err ==
"")
$doc->addComment(sprintf(_(
"Change profil to default subfolder profil : %d") ,
$profid));
275 if (
$doc->prelid ==
"") {
277 $doc->modify(
true, array(
284 $action->AddActionDone(
"ADDFILE", $this->initid);
305 function InsertMDoc($tdocs,
$mode =
"latest", $noprepost =
false, &$tinserted = array() , &$twarning = array())
310 $tAddeddocids = array();
313 foreach ($tdocs as $k =>
$tdoc) {
316 $warn = sprintf(_(
"Cannot add %s in %s folder, restriction set to add this kind of document") ,
$tdoc[
"title"], $this->title);
317 $twarning[
$docid] = $warn;
346 AddLogMsg(sprintf(_(
"Add %s in %s folder") ,
$tdoc[
"title"], $this->title));
349 $this->
addLog(
'addcontent', array(
352 "title" =>
$tdoc[
"title"]
356 $tinserted[
$docid] = sprintf(_(
"Document %s inserted") ,
$tdoc[
"title"]);
391 foreach ($tdocids as $k =>
$docid) {
395 $err =
$qf->Adds($tcopy,
true);
410 if (!is_numeric(
$docid))
return sprintf(_(
"Dir::insertFolder identificator [%s] must be numeric") ,
$docid);
411 if ($this->
isLocked(
true))
return sprintf(_(
"folder is locked. Cannot containt modification"));
416 $err = $this->exec_Query(sprintf(
"insert INTO fld (select %d,query,childid,qtype from fld where dirid=%d);", $this->initid,
$docid));
430 $query->AddQuery(
"dirid=" . $this->
id);
431 $query->AddQuery(
"((childid=$docid) and (qtype='F')) OR ((childid={$doc->initid}) and (qtype='S'))");
432 $tableq =
$query->Query();
435 while (list($k, $v) = each($tableq)) {
436 $tableid[$k] = $v->id;
472 if (!(
$qf->isAffected()))
$err = sprintf(_(
"cannot delete link : initial query not found for doc %d in folder %d") ,
$docid, $this->initid);
476 if (
$qf->qtype ==
"M")
$err = sprintf(_(
"cannot delete link for doc %d in folder %d : the document comes from a user query. Delete initial query if you want delete this document") ,
$docid, $this->initid);
481 if (
$doc->prelid == $this->initid) {
483 $doc->modify(
true, array(
488 AddLogMsg(sprintf(_(
"Delete %d in %s folder") ,
$docid, $this->title));
490 $this->
addLog(
'delcontent', array(
493 "title" =>
$doc->title
497 $doc->addComment(sprintf(_(
"Document unlinked of %s folder") , $this->title,
HISTO_INFO,
"MOVEUNLINK"));
505 $action->AddActionDone(
"DELFILE", $this->initid);
520 $da = new_doc($this->dbaccess, $movetoid);
521 if ($da->isAlive()) {
522 if (method_exists($da,
"addFile")) {
525 if (($fromtoid) && ($fromtoid != $movetoid)) {
527 if (method_exists($this,
"delFile")) {
530 $doc = new_doc($this->dbaccess,
$docid,
true);
531 if (
$doc->isAlive()) {
532 $doc->prelid = $da->initid;
538 }
else $err = sprintf(_(
"document %s is not a folder") , $this->
getTitle());
542 $doc = new_doc($this->dbaccess,
$docid,
true);
543 if (
$doc->isAlive()) {
544 $doc->prelid = $da->initid;
552 }
else $err = sprintf(_(
"document %s is not a folder") , $da->getTitle());
561 $allbut = $this->
getValue(
"FLD_ALLBUT");
562 $tfamid = $this->
getTValue(
"FLD_FAMIDS");
564 if (($allbut ===
"0") && ((
count($tfamid) == 0) || ((
count($tfamid) == 1) && ($tfamid[0] == 0)))) {
566 $this->deleteValue(
"FLD_ALLBUT");
572 if (!$this->authfam) {
575 return ($this->norestrict);
584 if (!$this->authfam) {
586 $tfamid = $this->
getTValue(
"FLD_FAMIDS");
588 $tsubfam = $this->
getTValue(
"FLD_SUBFAM");
589 $allbut = $this->
getValue(
"FLD_ALLBUT");
591 if (($allbut !=
"1") && ((
count($tfamid) == 0) || ((
count($tfamid) == 1) && ($tfamid[0] == 0)))) {
592 $this->norestrict =
true;
596 $this->norestrict =
false;;
597 $tclassdoc = array();
598 if ($allbut !=
"1") {
599 include_once (
"FDL/Lib.Dir.php");
600 $tallfam =
GetClassesDoc($this->dbaccess, $this->userid, $classid,
"TABLE");
602 foreach ($tallfam as $k => $cdoc) {
603 $tclassdoc[$cdoc[
"id"]] = $cdoc;
609 while (list($k,
$famid) = each($tfamid)) {
611 unset($tclassdoc[intval(
$famid) ]);
612 if ($tsubfam[$k] !=
"yes") {
614 foreach ($tnofam as $ka => $va) {
615 unset($tclassdoc[intval($ka) ]);
621 foreach ($tfamid as $k =>
$famid) {
623 if ($tfdoc && ((!$verifyCreate) ||
controlTdoc($tfdoc,
'icreate'))) {
624 $tclassdoc[intval(
$famid) ] = array(
625 "id" => ($tsubfam[$k] ==
"no") ? (-intval(
$famid)) : intval(
$famid) ,
632 $this->authfam = $tclassdoc;
634 $this->kauthfam = array_keys($this->authfam);
635 return $this->authfam;
643 if (!$this->authfam) {
646 if ($this->norestrict)
return true;
647 if (!$classid)
return true;
649 if (isset($this->authfam[$classid]))
return true;
663 include_once (
"FDL/Lib.Dir.php");
664 if ($controlview)
$uid = $this->userid;
666 $tdoc =
getChildDoc($this->dbaccess, $this->initid, 0,
"ALL",
$filter,
$uid, $qtype,
$famid,
false,
"title",
true, $trash);
675 if ($this->doctype ==
'T')
return;
676 include_once (
"FDL/Class.DocRel.php");
678 $or =
new DocRel($this->dbaccess);
680 $or->resetRelations(
"folder");
681 $q =
new QueryDb($this->dbaccess,
"QueryDir");
682 $tv =
$q->Query(0, 0,
"TABLE",
"select childid from fld where dirid=" . $this->initid .
" and qtype='S'");
685 foreach ($tv as $tq) {
686 $tid[] = $tq[
"childid"];
688 $or->copyRelations(
$tid, $this,
'folder');
696 public function count($onlyprimary =
false)
702 $q =
new QueryDb($this->dbaccess,
"QueryDir");
703 $tv =
$q->Query(0, 0,
"TABLE",
"select childid from fld where dirid=" . $this->initid .
" and qtype='S'");
704 if (is_array($tv))
return count($tv);
714 $query = sprintf(
"select childid from fld where dirid=%d and qtype='S'", $this->initid);
717 if (
$err ==
"")
return $initids;
734 $this->authfam =
false;
735 $this->norestrict =
false;
751 if (
$doc->doctype ==
'D') {
752 $terr = array_merge($terr,
$doc->deleteItems());
753 foreach ($terr as
$id =>
$err) {
754 if (
$err !=
"") $coulddelete =
false;
757 if ($coulddelete) $terr[
$doc->id] =
$doc->delete();
775 $fld = new_doc($this->dbaccess, $indirid);
776 if ($fld->doctype ==
'D') {
777 $err = $fld->control(
"modify");
780 if (
$doc->prelid == $this->initid) {
782 $copy =
$doc->copy();
783 if (is_object($copy)) {
784 $fld->addFile($copy->initid);
786 if (
$doc->doctype ==
'D') {
787 $terr = array_merge($terr,
$doc->copyItems($copy->id));
792 $fld->addFile(
$doc->initid);
807 $err = $this->predocdelete();
812 foreach ($terr as
$id => $err1) {
814 $coulddelete =
false;
818 if ($coulddelete)
$err = $this->
delete();
833 if (
$doc->defDoctype ==
'D') $terr = array_merge($terr,
$doc->reviveItems());