16 include_once (
"FDL/Class.PDir.php");
17 include_once (
"FDL/Class.QueryDir.php");
26 private $authfam =
false;
27 private $norestrict =
false;
36 if ($this->fromid ==
"") $this->fromid =
FAM_DIR;
47 include_once (
"FDL/freedom_util.php");
48 include_once (
"FDL/Lib.Dir.php");
50 "owner = -" . $this->userid
51 ) , $this->userid,
"LIST",
"DIR");
53 if (
count($rq) > 0) $home = $rq[0];
55 if (!$create)
return false;
57 $home =
createDoc($this->dbaccess,
"DIR");
59 if (!$home) $action->exitError(sprintf(_(
"no privilege to create this kind (%d) of document") ,
getFamIdFromName($this->dbaccess,
"DIR")));
62 include_once (
"Class.User.php");
64 $home->title =
$user->firstname .
" " .
$user->lastname;
65 $home->setTitle($home->title);
66 $home->icon =
'fldhome.gif';
70 $privlocked =
createDoc($this->dbaccess,
"SEARCH");
71 if (!$privlocked) $action->exitError(sprintf(_(
"no privilege to create this kind (%d) of document") ,
getFamIdFromName($this->dbaccess,
"SEARCH")));
73 $privlocked->title = (_(
"locked document of ") . $home->title);
75 $privlocked->AddQuery(
"select * from doc where (doctype!='Z') and" .
" (locked=" . $this->userid .
") ");
76 $home->insertDocument($privlocked->id);
79 if (
getParam(
"FREEDOM_IDBASKET") ==
"") {
81 $bas =
createDoc($this->dbaccess,
"BASKET");
82 if (!$bas) $action->exitError(sprintf(_(
"no privilege to create this kind (%d) of document") ,
getFamIdFromName($this->dbaccess,
"BASKET")));
85 $query->AddQuery(
"owner = " . $this->userid);
88 $bas->setvalue(
"ba_title", _(
"Document basket"));
89 $bas->setvalue(
"ba_desc", sprintf(_(
"basket of %s") , $home->title));
92 $home->insertDocument($bas->id);
98 $action->parent->param->Set(
"FREEDOM_IDBASKET", $basid,
Param::PARAM_USER . $this->userid, $action->parent->GetIdFromName(
"FREEDOM"));
110 if ($this->
isLocked(
true))
return sprintf(_(
"folder is locked. Cannot containt modification"));
112 $err = $this->Control(
"modify");
115 $this->
addLog(
'clearcontent');
116 $err = $this->
exec_query(
"delete from fld where dirid=" . $this->initid);
274 if ($this->
isLocked(
true))
return sprintf(_(
"folder is locked. Cannot containt modification"));
276 $err = $this->Control(
"modify");
295 function AddFile(
$docid, $mode =
"latest", $noprepost =
false, $forcerestrict =
false, $nocontrol =
false)
315 function insertDocument(
$docid, $mode =
"latest", $noprepost =
false, $forcerestrict =
false, $nocontrol =
false)
324 $qf =
new QueryDir($this->dbaccess);
328 $qf->childid =
$doc->id;
333 if (!
$doc->isAffected()) {
334 return sprintf(_(
"Cannot add in %s folder, doc id (%d) unknown") , $this->title,
$docid);
337 $qf->childid =
$doc->initid;
342 if (!$qf->Exists()) {
347 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);
351 AddLogMsg(sprintf(_(
"Add %s in %s folder") ,
$doc->title, $this->title));
353 $doc->addHistoryEntry(sprintf(_(
"Document inserted in %s folder") , $this->title,
HISTO_INFO,
"MOVEADD"));
355 $this->
addLog(
'addcontent', array(
358 "title" =>
$doc->title
362 if (
$doc->profid == 0) {
363 switch (
$doc->defProfFamId) {
372 if (
$err ==
"")
$doc->addHistoryEntry(sprintf(_(
"Change profil to default document profil : %d") ,
$profid));
381 if (
$doc->getRawValue(
"FLD_PDIRID") ==
"") {
385 if (
$doc->getRawValue(
"FLD_PDOCID") ==
"") {
390 if (
$err ==
"")
$doc->addHistoryEntry(sprintf(_(
"Change profil to default subfolder profil : %d") ,
$profid));
396 if (
$doc->prelid ==
"") {
398 $doc->modify(
true, array(
405 $action->AddActionDone(
"ADDFILE", $this->initid);
433 function InsertMDoc($tdocs, $mode =
"latest", $noprepost =
false, &$tinserted = array() , &$twarning = array())
456 $insertError = array();
459 $isStatic = ($mode ===
"static");
460 foreach ($tdocs as $v) {
461 if (!empty($v[
"initid"])) {
462 $tdocids[] = ($isStatic) ? $v[
"id"] : $v[
"initid"];
468 "preInsertMultipleDocuments" =>
$err,
469 "postInsertDocument" => array() ,
470 "postInsertMultipleDocuments" =>
'',
471 "preInsertDocument" => array() ,
480 "preInsertMultipleDocuments" =>
"",
481 "postInsertDocument" => array() ,
482 "postInsertMultipleDocuments" =>
'',
483 "preInsertDocument" => array() ,
484 "modifyError" =>
$err
488 $tAddeddocids = array();
490 $qf =
new QueryDir($this->dbaccess);
492 foreach ($tdocs as
$tdoc) {
494 $warn = sprintf(_(
"Cannot add %s in %s folder, restriction set to add this kind of document") , $tdoc[
"title"], $this->title);
495 $twarning[$tdoc[
'id']] = $warn;
502 $qf->childid = $tdoc[
"id"];
510 $qf->childid = $tdoc[
"initid"];
520 if ($insertOne ==
"") {
521 $insertOne = $qf->Add();
522 if ($insertOne ==
"") {
523 AddLogMsg(sprintf(_(
"Add %s in %s folder") , $tdoc[
"title"], $this->title));
526 $this->
addLog(
'addcontent', array(
529 "title" => $tdoc[
"title"]
533 $tinserted[
$docid] = sprintf(_(
"Document %s inserted") , $tdoc[
"title"]);
540 $twarning[
$docid] = $insertOne;
542 $insertError[
$docid] = $insertOne;
553 foreach ($insertError as $oneError) {
560 foreach ($tmsg as $oneError) {
568 "preInsertMultipleDocuments" =>
'',
569 "postInsertDocument" => $tmsg,
570 "postInsertMultipleDocuments" => $msg,
571 "preInsertDocument" => $insertError,
589 $qf =
new QueryDir($this->dbaccess);
593 foreach ($tdocids as
$docid) {
597 $err = $qf->Adds($tcopy,
true);
612 if (!is_numeric(
$docid))
return sprintf(_(
"Dir::insertFolder identifier [%s] must be numeric") ,
$docid);
613 if ($this->
isLocked(
true))
return sprintf(_(
"folder is locked. Cannot containt modification"));
615 $err = $this->Control(
"modify");
618 $err = $this->exec_Query(sprintf(
"insert INTO fld (select %d,query,childid,qtype from fld where dirid=%d);", $this->initid,
$docid));
632 $query->AddQuery(
"dirid=" . $this->
id);
633 $query->AddQuery(
"((childid=$docid) and (qtype='F')) OR ((childid={$doc->initid}) and (qtype='S'))");
634 $tableq =
$query->Query();
637 foreach ($tableq as $k => $v) {
638 $tableid[$k] = $v->id;
689 $qf =
new QueryDir($this->dbaccess, array(
693 if (!($qf->isAffected()))
$err = sprintf(_(
"cannot delete link : initial query not found for doc %d in folder %d") ,
$docid, $this->initid);
697 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);
702 if (
$doc->prelid == $this->initid) {
704 $doc->modify(
true, array(
709 AddLogMsg(sprintf(_(
"Delete %d in %s folder") ,
$docid, $this->title));
711 $this->
addLog(
'delcontent', array(
714 "title" =>
$doc->title
718 $doc->addHistoryEntry(sprintf(_(
"Document unlinked of %s folder") , $this->title,
HISTO_INFO,
"MOVEUNLINK"));
726 $action->AddActionDone(
"DELFILE", $this->initid);
742 $da = new_doc($this->dbaccess, $movetoid);
743 if ($da->isAlive()) {
744 if (method_exists($da,
"addFile")) {
747 if (($fromtoid) && ($fromtoid != $movetoid)) {
749 if (method_exists($this,
"delFile")) {
752 $doc = new_doc($this->dbaccess,
$docid,
true);
753 if (
$doc->isAlive()) {
754 $doc->prelid = $da->initid;
760 }
else $err = sprintf(_(
"document %s is not a folder") , $this->
getTitle());
764 $doc = new_doc($this->dbaccess,
$docid,
true);
765 if (
$doc->isAlive()) {
766 $doc->prelid = $da->initid;
774 }
else $err = sprintf(_(
"document %s is not a folder") , $da->getTitle());
786 if (($allbut ===
"0") && ((
count($tfamid) == 0) || ((
count($tfamid) == 1) && ($tfamid[0] == 0)))) {
799 return self::postStore();
804 if (!$this->authfam) {
807 return ($this->norestrict);
818 if (!$this->authfam) {
824 if (($allbut !=
"1") && ((
count($tfamid) == 0) || ((
count($tfamid) == 1) && ($tfamid[0] == 0)))) {
825 $this->norestrict =
true;
829 $this->norestrict =
false;;
830 $tclassdoc = array();
831 if ($allbut !=
"1") {
832 include_once (
"FDL/Lib.Dir.php");
833 $tallfam =
GetClassesDoc($this->dbaccess, $this->userid, $classid,
"TABLE");
835 foreach ($tallfam as $cdoc) {
836 $tclassdoc[$cdoc[
"id"]] = $cdoc;
842 foreach ($tfamid as $k =>
$famid) {
844 unset($tclassdoc[intval(
$famid) ]);
845 if ($tsubfam[$k] !=
"yes") {
846 $tnofam = $this->GetChildFam(intval(
$famid));
847 foreach ($tnofam as $ka => $va) {
848 unset($tclassdoc[intval($ka) ]);
854 foreach ($tfamid as $k =>
$famid) {
856 if ($tfdoc && ((!$verifyCreate) ||
controlTdoc($tfdoc,
'icreate'))) {
857 $tclassdoc[intval(
$famid) ] = array(
858 "id" => ($tsubfam[$k] ==
"no") ? (-intval(
$famid)) : intval(
$famid) ,
862 if ($tsubfam[$k] !=
"no") $tclassdoc+= $this->GetChildFam(intval(
$famid));
865 $this->authfam = $tclassdoc;
867 return $this->authfam;
876 if (!$this->authfam) {
879 if ($this->norestrict)
return true;
880 if (!$classid)
return true;
882 if (isset($this->authfam[$classid]))
return true;
897 include_once (
"FDL/Lib.Dir.php");
900 $tdoc =
internalGetDocCollection($this->dbaccess, $this->initid, 0,
"ALL",
$filter, $uid, $qtype,
$famid,
false,
"title",
true, $trash);
916 public function count($onlyprimary =
false)
922 $q =
new QueryDb($this->dbaccess,
"QueryDir");
923 $tv =
$q->Query(0, 0,
"TABLE",
"select childid from fld where dirid=" . $this->initid .
" and qtype='S'");
924 if (is_array($tv))
return count($tv);
934 $query = sprintf(
"select childid from fld where dirid=%d and qtype='S'", $this->initid);
937 if (
$err ==
"")
return $initids;
955 $this->authfam =
false;
956 $this->norestrict =
false;
972 if (
$doc->doctype ==
'D') {
974 $terr = array_merge($terr,
$doc->deleteItems());
975 foreach ($terr as
$err) {
976 if ($err !=
"") $coulddelete =
false;
979 if ($coulddelete) $terr[
$doc->id] =
$doc->delete();
997 $fld = new_doc($this->dbaccess, $indirid);
998 if ($fld->doctype ==
'D') {
1000 $err = $fld->control(
"modify");
1003 if (
$doc->prelid == $this->initid) {
1005 $copy =
$doc->duplicate();
1006 if (is_object($copy)) {
1007 $fld->insertDocument($copy->initid);
1008 if (
$doc->doctype ==
'D') {
1010 $terr = array_merge($terr,
$doc->copyItems($copy->id));
1015 $fld->insertDocument(
$doc->initid);
1030 $err = $this->predocdelete();
1032 $coulddelete =
true;
1035 foreach ($terr as $err1) {
1037 $coulddelete =
false;
1041 if ($coulddelete)
$err = $this->
delete();
1056 if (
$doc->defDoctype ==
'D') {
1060 $terr = array_merge($terr,
$doc->reviveItems());
1062 $terr[
$doc->id] =
$doc->undelete();
getNextDoc($dbaccess, &$tres)
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
addLog($code= '', $arg= '', $comment= '', $level= '', $uid= '')
exec_query($sql, $lvl=0, $prepare=false)
AddFile($docid, $mode="latest", $noprepost=false, $forcerestrict=false, $nocontrol=false)
postUnlinkDoc($docid, $multiple=false)
preInsertDocument($docid, $multiple=false)
controlTdoc(&$tdoc, $aclname)
count($onlyprimary=false)
postInsertDoc($docid, $multiple=false)
InsertMDoc($tdocs, $mode="latest", $noprepost=false, &$tinserted=array(), &$twarning=array())
QuickInsertMSDocId($tdocids)
__construct($dbaccess= '', $id= '', $res= '', $dbid=0)
getContent($controlview=true, array $filter=array(), $famid="", $qtype="TABLE", $trash="")
modify($nopost=false, $sfields="", $nopre=false)
removeDocument($docid, $noprepost=false, $nocontrol=false)
postInsertDocument($docid, $multiple=false)
preInsertDoc($docid, $multiple=false)
postInsertMultipleDocuments($tdocid)
preInsertMultipleDocuments($tdocid)
GetClassesDoc($dbaccess, $userid, $classid=0, $qtype="LIST", $extraFilters=array())
postRemoveDocument($docid, $multiple=false)
getMultipleRawValues($idAttr, $def="", $index=-1)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
getParam($param, $defv="")
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)
preUnlinkDoc($docid, $multiple=false)
deprecatedFunction($msg= '')
new_Doc($dbaccess, $id= '', $latest=false)
insertMultipleDocuments(array $tdocs, $mode="latest", $noprepost=false, &$tinserted=array(), &$twarning=array(), &$info=array())
postAffect(array $data, $more, $reset)
preRemoveDocument($docid, $multiple=false)
if(($docid!==0)&&(!is_numeric($docid))) $query
DelFile($docid, $noprepost=false, $nocontrol=false)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
moveDocument($docid, $movetoid)
insertDocument($docid, $mode="latest", $noprepost=false, $forcerestrict=false, $nocontrol=false)
if($file) if($subject==""&&$file) if($subject=="") $err
addHistoryEntry($comment= '', $level=DocHisto::INFO, $code= '', $uid= '')
getRawValue($idAttr, $def="")
getAuthorizedFamilies($classid=0, $verifyCreate=false)