Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.Dir.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Folder document definition
8  *
9  * @author Anakeen
10  * @version $Id: Class.Dir.php,v 1.81 2008/09/03 08:35:24 marc Exp $
11  * @package FDL
12  */
13 /**
14  */
15 
16 include_once ("FDL/Class.PDir.php");
17 include_once ("FDL/Class.QueryDir.php");
18 /**
19  * Folder document Class
20  *
21  */
22 class Dir extends PDir
23 {
24 
25  var $defDoctype = 'D';
26  private $authfam = false;
27  private $norestrict = false;
28 
29  public $eviews = array(
30  "FDL:EDITBODYCARD",
31  "FDL:EDITRESTRICTION"
32  );
33  function __construct($dbaccess = '', $id = '', $res = '', $dbid = 0)
34  {
35  parent::__construct($dbaccess, $id, $res, $dbid);
36  if ($this->fromid == "") $this->fromid = FAM_DIR;
37  }
38  /**
39  * get the home and basket folder
40  * @param bool $create set to false to disable auto creation
41  * @return bool|\Dir false if the dir does not exists and $create is false, home document either
42  */
43  function GetHome($create = true)
44  {
45  global $action;
46 
47  include_once ("FDL/freedom_util.php");
48  include_once ("FDL/Lib.Dir.php");
49  $rq = internalGetDocCollection($this->dbaccess, 0, 0, 1, array(
50  "owner = -" . $this->userid
51  ) , $this->userid, "LIST", "DIR");
52 
53  if (count($rq) > 0) $home = $rq[0];
54  else {
55  if (!$create) return false;
56  /* @var Dir $home */
57  $home = createDoc($this->dbaccess, "DIR");
58 
59  if (!$home) $action->exitError(sprintf(_("no privilege to create this kind (%d) of document") , getFamIdFromName($this->dbaccess, "DIR")));
60 
61  $home->owner = - $this->userid;
62  include_once ("Class.User.php");
63  $user = new Account("", $this->userid);
64  $home->title = $user->firstname . " " . $user->lastname;
65  $home->setTitle($home->title);
66  $home->icon = 'fldhome.gif';
67  $home->name = 'FLDHOME_' . $this->getSystemUserId();
68  $home->Add();
69  /* @var DocSearch $privlocked */
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")));
72 
73  $privlocked->title = (_("locked document of ") . $home->title);
74  $privlocked->Add();
75  $privlocked->AddQuery("select * from doc where (doctype!='Z') and" . " (locked=" . $this->userid . ") ");
76  $home->insertDocument($privlocked->id);
77  }
78  // add basket in home
79  if (getParam("FREEDOM_IDBASKET") == "") {
80 
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")));
83 
84  $query = new QueryDb($this->dbaccess, "_BASKET");
85  $query->AddQuery("owner = " . $this->userid);
86  $rq = $query->Query();
87  if ($query->nb == 0) {
88  $bas->setvalue("ba_title", _("Document basket"));
89  $bas->setvalue("ba_desc", sprintf(_("basket of %s") , $home->title));
90  $home->name = sprintf('FLDBASKET_%d', $this->getSystemUserId());
91  $bas->Add();
92  $home->insertDocument($bas->id);
93  $basid = $bas->id;
94  } else {
95  $basid = $rq[0]->id;
96  }
97  global $action;
98  $action->parent->param->Set("FREEDOM_IDBASKET", $basid, Param::PARAM_USER . $this->userid, $action->parent->GetIdFromName("FREEDOM"));
99  }
100 
101  return $home;
102  }
103  /**
104  * clear containt of this folder
105  *
106  * @return string error message, if no error empty string
107  */
108  function Clear()
109  {
110  if ($this->isLocked(true)) return sprintf(_("folder is locked. Cannot containt modification"));
111  // need this privilege
112  $err = $this->Control("modify");
113  if ($err != "") return $err;
114  $this->addHistoryEntry(_("Folder cleared"));
115  $this->addLog('clearcontent');
116  $err = $this->exec_query("delete from fld where dirid=" . $this->initid);
117  $this->updateFldRelations();
118  return $err;
119  }
120  /**
121  * hook method use before insert document in folder
122  *
123  * @api hook method use before insert document in folder
124  *
125  * @param int $docid document identifier to insert
126  * @param bool $multiple flag to indicate if the insertion is a part of grouped insertion
127  * @return string error message if not empty the insertion will be aborted
128  */
129  function preInsertDocument($docid, $multiple = false)
130  {
131  return "";
132  }
133  /**
134  * virtual method use before insert document in folder
135  *
136  * @deprecated hook use Dir::preInsertDocument instead
137  *
138  * @param int $docid document identifier to insert
139  * @param bool $multiple flag to indicate if the insertion is a part of grouped insertion
140  * @return string error message if not empty the insert will be aborted
141  */
142  function preInsertDoc($docid, $multiple = false)
143  {
144  deprecatedFunction("hook");
145  }
146  /**
147  * virtual method use after insert document in folder
148  * @api hook method called after insert document in folder
149  * @see Dir::insertDocument
150  * @param int $docid document identifier to insert
151  * @param bool $multiple flag to indicate if the insertion is a part of grouped insertion
152  * @return string error message
153  */
154  function postInsertDocument($docid, $multiple = false)
155  {
156  return "";
157  }
158  /**
159  * virtual method use after insert document in folder
160  *
161  * @deprecated hook use Dir::postInsertDocument instead
162  *
163  * @param int $docid document identifier to insert
164  * @param bool $multiple flag to indicate if the insertion is a part of grouped insertion
165  * @return string error message
166  */
167  function postInsertDoc($docid, $multiple = false)
168  {
169  deprecatedFunction("hook");
170  }
171  /**
172  * hook method use after insert multiple document in this folder
173  * must be redefined to optimize algorithm
174  *
175  *
176  * @api hook method called after insert several documents in folder
177  * @see Dir::insertMultipleDocuments
178  * @see Dir::postInsertDocument
179  *
180  * @param array $tdocid array of document identifier to insert
181  * @return string warning message
182  */
183  function postInsertMultipleDocuments($tdocid)
184  {
185  return '';
186  }
187  /**
188  * hook method use after insert multiple document in this folder
189  * must be redefined to optimize algorithm
190  *
191  * @api hook method called before insert several documents in folder
192  * @see Dir::preInsertDocument
193  * @see Dir::insertMultipleDocuments
194  *
195  * @param array $tdocid array of document identifier to insert
196  * @return string warning message
197  */
198  function preInsertMultipleDocuments($tdocid)
199  {
200  return '';
201  }
202  /**
203  * hook method use after insert multiple document in this folder
204  * must be redefined to optimize algorithm
205  *
206  * @deprecated hook use {@Dir::postInsertMultipleDocuments} instead
207  *
208  * @param array $tdocid array of document identifier to insert
209  * @return string warning message
210  */
211  function postMInsertDoc($tdocid)
212  {
213  deprecatedFunction("hook");
214  return $this->postInsertMultipleDocuments($tdocid);
215  }
216  /**
217  * hook method use after unlink document in folder
218  *
219  * @api hook method use before remove document to folder
220  *
221  * @param int $docid document identifier to unlink
222  * @param bool $multiple flag to indicate if the insertion is a part of grouped insertion
223  * @return string error message if not empty the insert will be aborted
224  */
225  function preRemoveDocument($docid, $multiple = false)
226  {
227  }
228  /**
229  * hook method use after unlink document in folder
230  *
231  * @api hook method use after remove document of folder
232  *
233  * @param int $docid document identifier to unlink
234  * @param bool $multiple flag to indicate if the insertion is a part of grouped insertion
235  * @return string error message
236  */
237  function postRemoveDocument($docid, $multiple = false)
238  {
239  return "";
240  }
241  /**
242  * hook method use after unlink document in folder
243  *
244  * @deprecated hook use {@link Doc::preRemoveDocument} instead
245  *
246  * @param int $docid document identifier to unlink
247  * @param bool $multiple flag to indicate if the insertion is a part of grouped insertion
248  * @return string error message if not empty the insert will be aborted
249  */
250  function preUnlinkDoc($docid, $multiple = false)
251  {
252  deprecatedFunction("hook");
253  }
254  /**
255  * hook method use after unlink document in folder
256  *
257  * @deprecated hook use {@link Doc::postRemoveDocument} instead
258  *
259  * @param int $docid document identifier to unlink
260  * @param bool $multiple flag to indicate if the insertion is a part of grouped insertion
261  * @return string error message
262  */
263  function postUnlinkDoc($docid, $multiple = false)
264  {
265  deprecatedFunction("hook");
266  }
267  /**
268  * Test if current user can add or delete document in this folder
269  *
270  * @return string error message, if no error empty string
271  */
272  function canModify()
273  {
274  if ($this->isLocked(true)) return sprintf(_("folder is locked. Cannot containt modification"));
275  // need this privilege
276  $err = $this->Control("modify");
277  return $err;
278  }
279  /**
280  * add a document reference in this folder
281  *
282  * if mode is latest the user always see latest revision
283  * if mode is static the user see the revision which has been inserted
284  *
285  * @deprecated use {@link Dir::insertDocument} instead
286  * @see Dir::insertDocument
287  *
288  * @param int $docid document ident for the insertion
289  * @param string $mode latest|static
290  * @param bool $noprepost if true if the virtuals methods {@link Dir::preInsertDoc()} and {@link Dir::postInsertDoc()} are not called
291  * @param bool $forcerestrict if true don't test restriction (if have)
292  * @param bool $nocontrol if true no test acl "modify"
293  * @return string error message, if no error empty string
294  */
295  function AddFile($docid, $mode = "latest", $noprepost = false, $forcerestrict = false, $nocontrol = false)
296  {
298  return $this->insertDocument($docid, $mode, $noprepost, $forcerestrict, $nocontrol);
299  }
300  /**
301  * add a document reference in this folder
302  *
303  * if mode is latest the user always see latest revision
304  * if mode is static the user see the revision which has been inserted
305  *
306  * @api add a document reference in this folder
307  *
308  * @param int $docid document ident for the insertion
309  * @param string $mode latest|static
310  * @param bool $noprepost if true if the virtuals methods {@link Dir::preInsertDoc()} and {@link Dir::postInsertDoc()} are not called
311  * @param bool $forcerestrict if true don't test restriction (if have)
312  * @param bool $nocontrol if true no test acl "modify"
313  * @return string error message, if no error empty string
314  */
315  function insertDocument($docid, $mode = "latest", $noprepost = false, $forcerestrict = false, $nocontrol = false)
316  {
317  $err = '';
318  if (!$nocontrol) {
319  $err = $this->canModify();
320  if ($err != "") return $err;
321  }
322 
323  $doc = new_Doc($this->dbaccess, $docid);
324  $qf = new QueryDir($this->dbaccess);
325  switch ($mode) {
326  case "static":
327  $qf->qtype = 'F'; // fixed document
328  $qf->childid = $doc->id; // initial doc
329  break;
330 
331  case "latest":
332  default:
333  if (!$doc->isAffected()) {
334  return sprintf(_("Cannot add in %s folder, doc id (%d) unknown") , $this->title, $docid);
335  }
336  $qf->qtype = 'S'; // single user query
337  $qf->childid = $doc->initid; // initial doc
338  break;
339  }
340  $qf->dirid = $this->initid; // the reference folder is the initial id
341  $qf->query = "";
342  if (!$qf->Exists()) {
343  // use pre virtual method
344  if (!$noprepost) $err = $this->preInsertDocument($doc->id);
345  if ($err != "") return $err;
346  // verify if doc family is autorized
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);
348 
349  $err = $qf->Add();
350  if ($err == "") {
351  AddLogMsg(sprintf(_("Add %s in %s folder") , $doc->title, $this->title));
352  $this->addHistoryEntry(sprintf(_("Document %s inserted") , $doc->title));
353  $doc->addHistoryEntry(sprintf(_("Document inserted in %s folder") , $this->title, HISTO_INFO, "MOVEADD"));
354 
355  $this->addLog('addcontent', array(
356  "insert" => array(
357  "id" => $doc->id,
358  "title" => $doc->title
359  )
360  ));
361  // add default folder privilege to the doc
362  if ($doc->profid == 0) { // only if no privilege yet
363  switch ($doc->defProfFamId) {
364  case FAM_ACCESSDOC:
365  $profid = $this->getRawValue("FLD_PDOCID", 0);
366  if ($profid > 0) {
367  $doc->setProfil($profid);
368  $err = $doc->modify(true, array(
369  "profid",
370  "dprofid"
371  ) , true);
372  if ($err == "") $doc->addHistoryEntry(sprintf(_("Change profil to default document profil : %d") , $profid));
373  }
374  break;
375 
376  case FAM_ACCESSDIR:
377  $profid = $this->getRawValue("FLD_PDIRID", 0);
378  if ($profid > 0) {
379  $doc->setProfil($profid);
380  // copy default privilege if not set
381  if ($doc->getRawValue("FLD_PDIRID") == "") {
382  $doc->setValue("FLD_PDIRID", $this->getRawValue("FLD_PDIRID"));
383  $doc->setValue("FLD_PDIR", $this->getRawValue("FLD_PDIR"));
384  }
385  if ($doc->getRawValue("FLD_PDOCID") == "") {
386  $doc->setValue("FLD_PDOCID", $this->getRawValue("FLD_PDOCID"));
387  $doc->setValue("FLD_PDOC", $this->getRawValue("FLD_PDOC"));
388  }
389  $err = $doc->modify();
390  if ($err == "") $doc->addHistoryEntry(sprintf(_("Change profil to default subfolder profil : %d") , $profid));
391  }
392  break;
393  }
394  }
395  }
396  if ($doc->prelid == "") {
397  $doc->prelid = $this->initid;
398  $doc->modify(true, array(
399  "prelid"
400  ) , true);
401  }
402 
403  if ($err == "") {
404  global $action;
405  $action->AddActionDone("ADDFILE", $this->initid);
406 
407  $this->updateFldRelations();
408  // use post virtual method
409  if (!$noprepost) $err = $this->postInsertDocument($doc->id, false);
410  }
411  }
412  return $err;
413  }
414  // --------------------------------------------------------------------
415 
416  /**
417  * insert multiple document reference in this folder
418  *
419  * if mode is latest the user always see latest revision
420  * if mode is static the user see the revision which has been inserted
421  *
422  * @deprecated use {@link Dir::InsertMultipleDocuments} instead
423  * @see insertMultipleDocuments::InsertMultipleDocuments
424  *
425  * @param $tdocs
426  * @param string $mode latest|static
427  * @param boolean $noprepost not call preInsert and postInsert method (default if false)
428  * @param array $tinserted
429  * @param array $twarning
430  * @internal param \doc $array array document for the insertion
431  * @return string error message, if no error empty string
432  */
433  function InsertMDoc($tdocs, $mode = "latest", $noprepost = false, &$tinserted = array() , &$twarning = array())
434  {
436  return $this->insertMultipleDocuments($tdocs, $mode, $noprepost, $tinserted, $twarning);
437  }
438  /**
439  * insert multiple document reference in this folder
440  *
441  * if mode is latest the user always see latest revision
442  * if mode is static the user see the revision which has been inserted
443  *
444  * @api insert multiple document reference in this folder
445  *
446  * @param array $tdocs documents for the insertion
447  * @param string $mode latest|static static is not implemented yet
448  * @param boolean $noprepost not call preInsert and postInsert method (default if false)
449  * @param array $tinserted
450  * @param array $twarning
451  * @param array $info
452  * @return string error message, if no error empty string
453  */
454  function insertMultipleDocuments(array $tdocs, $mode = "latest", $noprepost = false, &$tinserted = array() , &$twarning = array() , &$info = array())
455  {
456  $insertError = array();
457  if (!$noprepost) {
458  $tdocids = array();
459  $isStatic = ($mode === "static");
460  foreach ($tdocs as $v) {
461  if (!empty($v["initid"])) {
462  $tdocids[] = ($isStatic) ? $v["id"] : $v["initid"];
463  }
464  }
465  $err = $this->preInsertMultipleDocuments($tdocids);
466  $info = array(
467  "error" => $err,
468  "preInsertMultipleDocuments" => $err,
469  "postInsertDocument" => array() ,
470  "postInsertMultipleDocuments" => '',
471  "preInsertDocument" => array() ,
472  "modifyError" => ""
473  );
474  if ($err != "") return $err;
475  }
476  $err = $this->canModify();
477  if ($err != "") {
478  $info = array(
479  "error" => $err,
480  "preInsertMultipleDocuments" => "",
481  "postInsertDocument" => array() ,
482  "postInsertMultipleDocuments" => '',
483  "preInsertDocument" => array() ,
484  "modifyError" => $err
485  );
486  return $err;
487  }
488  $tAddeddocids = array();
489  // verify if doc family is autorized
490  $qf = new QueryDir($this->dbaccess);
491  $tmsg = array();
492  foreach ($tdocs as $tdoc) {
493  if (!$this->isAuthorized($tdoc["fromid"])) {
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;
496  } else {
497  switch ($mode) {
498  case "static":
499 
500  $qf->qtype = 'F'; // fixed document
501  $docid = $tdoc["id"];
502  $qf->childid = $tdoc["id"]; // initial doc
503  break;
504 
505  case "latest":
506  default:
507 
508  $qf->qtype = 'S'; // single user query
509  $docid = $tdoc["initid"];
510  $qf->childid = $tdoc["initid"]; // initial doc
511  break;
512  }
513 
514  $insertOne = "";
515  $qf->dirid = $this->initid; // the reference folder is the initial id
516  $qf->query = "";
517  // use post virtual method
518  if (!$noprepost) $insertOne = $this->preInsertDocument($tdoc["initid"], true);
519 
520  if ($insertOne == "") {
521  $insertOne = $qf->Add();
522  if ($insertOne == "") {
523  AddLogMsg(sprintf(_("Add %s in %s folder") , $tdoc["title"], $this->title));
524  $this->addHistoryEntry(sprintf(_("Document %s inserted") , $tdoc["title"]) , HISTO_INFO, "MODCONTAIN");
525 
526  $this->addLog('addcontent', array(
527  "insert" => array(
528  "id" => $tdoc["id"],
529  "title" => $tdoc["title"]
530  )
531  ));
532  $tAddeddocids[] = $docid;
533  $tinserted[$docid] = sprintf(_("Document %s inserted") , $tdoc["title"]);
534  // use post virtual method
535  if (!$noprepost) {
536  $tmsg[$docid] = $this->postInsertDocument($tdoc["initid"], true);
537  }
538  }
539  } else {
540  $twarning[$docid] = $insertOne;
541  }
542  $insertError[$docid] = $insertOne;
543  }
544  }
545  // use post virtual method
546  $msg = '';
547  if (!$noprepost) {
548  $this->updateFldRelations();
549  $msg = $this->postInsertMultipleDocuments($tAddeddocids);
550  $err.= $msg;
551  }
552  // integrate pre insert errors
553  foreach ($insertError as $oneError) {
554  if ($oneError) {
555  $err.= ($err) ? ', ' : '';
556  $err.= $oneError;
557  }
558  }
559  // integrate postInsert Error
560  foreach ($tmsg as $oneError) {
561  if ($oneError) {
562  $err.= ($err) ? ', ' : '';
563  $err.= $oneError;
564  }
565  }
566  $info = array(
567  "error" => $err,
568  "preInsertMultipleDocuments" => '',
569  "postInsertDocument" => $tmsg,
570  "postInsertMultipleDocuments" => $msg,
571  "preInsertDocument" => $insertError,
572  "modifyError" => ""
573  );
574  return $err;
575  }
576  /**
577  * insert multiple static document reference in this folder
578  * be carreful : not verify restriction folders
579  * to be use when many include (verification constraint must ne set before by caller)
580  *
581  * @param array $tdocids identifier documents for the insertion
582  * @return string error message, if no error empty string
583  */
584  function QuickInsertMSDocId($tdocids)
585  {
586 
587  $err = $this->canModify();
588  if ($err != "") return $err;
589  $qf = new QueryDir($this->dbaccess);
590  $qf->qtype = 'S'; // single user query
591  $qf->dirid = $this->initid; // the reference folder is the initial id
592  $qf->query = "";
593  foreach ($tdocids as $docid) {
594  $tcopy[$docid]["childid"] = $docid;
595  }
596 
597  $err = $qf->Adds($tcopy, true);
598  $this->updateFldRelations();
599 
600  return $err;
601  }
602  /**
603  * insert all static document which are included in $docid in this folder
604  * be carreful : not verify restriction folders
605  * to be use when many include (verification constraint must ne set before by caller)
606  *
607  * @param int $docid identifier document for the insertion (must be initial id)
608  * @return string error message, if no error empty string
609  */
611  {
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"));
614  // need this privilege
615  $err = $this->Control("modify");
616  if ($err != "") return $err;
617 
618  $err = $this->exec_Query(sprintf("insert INTO fld (select %d,query,childid,qtype from fld where dirid=%d);", $this->initid, $docid));
619 
620  $this->updateFldRelations();
621  return $err;
622  }
623  // --------------------------------------------------------------------
624  function getQids($docid)
625  {
626  // return array of queries id includes in a directory
627  // --------------------------------------------------------------------
628  $tableid = array();
629 
630  $doc = new_Doc($this->dbaccess, $docid);
631  $query = new QueryDb($this->dbaccess, "QueryDir");
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();
635 
636  if ($query->nb > 0) {
637  foreach ($tableq as $k => $v) {
638  $tableid[$k] = $v->id;
639  }
640  unset($tableq);
641  }
642 
643  return ($tableid);
644  }
645  // --------------------------------------------------------------------
646 
647  /**
648  * remove a document reference from this folder
649  *
650  * @deprecated use {@link Dir::removeDocument} instead
651  * @see Dir::removeDocument
652  *
653  * @param int $docid document ident for the deletion
654  * @param bool $noprepost if true then the virtuals methods {@link Dir::preUnlinkDoc()} and {@link Dir::postUnlinkDoc()} are not called
655  * @param bool $nocontrol if true no test acl "modify"
656  * @return string error message, if no error empty string
657  */
658  function DelFile($docid, $noprepost = false, $nocontrol = false)
659  {
661  return $this->removeDocument($docid, $noprepost, $nocontrol);
662  }
663  /**
664  * delete a document reference from this folder
665  *
666  * @api remove a document reference from this folder
667  *
668  * @param int $docid document ident for the deletion
669  * @param bool $noprepost if true then the virtuals methods {@link Dir::preRemoveDocument()} and {@link Dir::postRemoveDocument()} are not called
670  * @param bool $nocontrol if true no test acl "modify"
671  * @return string error message, if no error empty string
672  */
673  function removeDocument($docid, $noprepost = false, $nocontrol = false)
674  {
675  $err = '';
676  if (!$nocontrol) {
677  $err = $this->canModify();
678  if ($err != "") return $err;
679  }
680  // use pre virtual method
681  if (!$noprepost) $err = $this->preRemoveDocument($docid);
682  if ($err != "") return $err;
683 
684  $doc = new_Doc($this->dbaccess, $docid);
685  $docid = $doc->initid;
686  //if (count($qids) == 0) $err = sprintf(_("cannot delete link : link not found for doc %d in folder %d"),$docid, $this->initid);
687  if ($err != "") return $err;
688  // search original query
689  $qf = new QueryDir($this->dbaccess, array(
690  $this->initid,
691  $docid
692  ));
693  if (!($qf->isAffected())) $err = sprintf(_("cannot delete link : initial query not found for doc %d in folder %d") , $docid, $this->initid);
694 
695  if ($err != "") return $err;
696 
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);
698 
699  if ($err != "") return $err;
700  $qf->Delete();
701 
702  if ($doc->prelid == $this->initid) {
703  $doc->prelid = "";
704  $doc->modify(true, array(
705  "prelid"
706  ) , true);
707  }
708 
709  AddLogMsg(sprintf(_("Delete %d in %s folder") , $docid, $this->title));
710 
711  $this->addLog('delcontent', array(
712  "insert" => array(
713  "id" => $doc->id,
714  "title" => $doc->title
715  )
716  ));
717  $this->addHistoryEntry(sprintf(_("Document %s umounted") , $doc->title) , HISTO_INFO, "MODCONTAIN");
718  $doc->addHistoryEntry(sprintf(_("Document unlinked of %s folder") , $this->title, HISTO_INFO, "MOVEUNLINK"));
719  // use post virtual method
720  if (!$noprepost) {
721  $this->updateFldRelations();
722  $err = $this->postRemoveDocument($docid);
723  }
724 
725  global $action;
726  $action->AddActionDone("DELFILE", $this->initid);
727 
728  return $err;
729  }
730  /**
731  * move a document from me to a folder
732  * @param integer $docid the document identifier to move
733  * @param integer $movetoid target destination
734  * @return string error message (empty if null)
735  */
736  function moveDocument($docid, $movetoid)
737  {
738  $err = $this->canModify();
739  if ($err == "") {
740  $fromtoid = $this->initid;
741  /* @var Dir $da */
742  $da = new_doc($this->dbaccess, $movetoid);
743  if ($da->isAlive()) {
744  if (method_exists($da, "addFile")) {
745  $err = $da->insertDocument($docid);
746  if ($err == "") {
747  if (($fromtoid) && ($fromtoid != $movetoid)) {
748  if ($this->isAlive()) {
749  if (method_exists($this, "delFile")) {
750  $err = $this->removeDocument($docid);
751  if ($err == "") {
752  $doc = new_doc($this->dbaccess, $docid, true);
753  if ($doc->isAlive()) {
754  $doc->prelid = $da->initid;
755  $err = $doc->modify(true, array(
756  "prelid"
757  ) , true);
758  }
759  }
760  } else $err = sprintf(_("document %s is not a folder") , $this->getTitle());
761  }
762  } else {
763  if ($err == "") {
764  $doc = new_doc($this->dbaccess, $docid, true);
765  if ($doc->isAlive()) {
766  $doc->prelid = $da->initid;
767  $err = $doc->modify(true, array(
768  "prelid"
769  ) , true);
770  }
771  }
772  }
773  }
774  } else $err = sprintf(_("document %s is not a folder") , $da->getTitle());
775  }
776  }
777  return $err;
778  }
779  // --------------------------------------------------------------------
780  function postStore()
781  {
782  // don't see restriction frame is not needed
783  $allbut = $this->getRawValue("FLD_ALLBUT");
784  $tfamid = $this->getMultipleRawValues("FLD_FAMIDS");
785 
786  if (($allbut === "0") && ((count($tfamid) == 0) || ((count($tfamid) == 1) && ($tfamid[0] == 0)))) {
787  $this->clearValue("FLD_ALLBUT");
788  $this->modify();
789  }
790  return "";
791  }
792  /**
793  * @deprecated use postStore() instead
794  * @return string
795  */
796  public function postModify()
797  {
799  return self::postStore();
800  }
801 
802  function hasNoRestriction()
803  {
804  if (!$this->authfam) {
805  $this->getAuthorizedFamilies();
806  }
807  return ($this->norestrict);
808  }
809  /**
810  * return families that can be use in insertion
811  * @param int $classid : restrict for same usefor families
812  * @param bool $verifyCreate set to true if you want to get only families the user can create (icreate acl)
813  * @return array
814  */
815  function getAuthorizedFamilies($classid = 0, $verifyCreate = false)
816  {
817 
818  if (!$this->authfam) {
819  $tfamid = $this->getMultipleRawValues("FLD_FAMIDS");
820  $tfam = $this->getMultipleRawValues("FLD_FAM");
821  $tsubfam = $this->getMultipleRawValues("FLD_SUBFAM");
822  $allbut = $this->getRawValue("FLD_ALLBUT");
823 
824  if (($allbut != "1") && ((count($tfamid) == 0) || ((count($tfamid) == 1) && ($tfamid[0] == 0)))) {
825  $this->norestrict = true;
826  return array();
827  }
828 
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");
834 
835  foreach ($tallfam as $cdoc) {
836  $tclassdoc[$cdoc["id"]] = $cdoc;
837  // $tclassdoc += $this->GetChildFam($cdoc["id"]);
838 
839  }
840  // suppress undesirable families
841  reset($tfamid);
842  foreach ($tfamid as $k => $famid) {
843 
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) ]);
849  }
850  }
851  }
852  } else {
853  //add families
854  foreach ($tfamid as $k => $famid) {
855  $tfdoc = getTDoc($this->dbaccess, $famid);
856  if ($tfdoc && ((!$verifyCreate) || controlTdoc($tfdoc, 'icreate'))) {
857  $tclassdoc[intval($famid) ] = array(
858  "id" => ($tsubfam[$k] == "no") ? (-intval($famid)) : intval($famid) ,
859  "title" => $tfam[$k]
860  );
861  }
862  if ($tsubfam[$k] != "no") $tclassdoc+= $this->GetChildFam(intval($famid));
863  }
864  }
865  $this->authfam = $tclassdoc;
866  }
867  return $this->authfam;
868  }
869  /**
870  * return families that can be use in insertion
871  * @param int $classid : restrict for same usefor families
872  * @return bool
873  */
874  public function isAuthorized($classid)
875  {
876  if (!$this->authfam) {
877  $this->getAuthorizedFamilies();
878  }
879  if ($this->norestrict) return true;
880  if (!$classid) return true;
881 
882  if (isset($this->authfam[$classid])) return true;
883 
884  return false;
885  }
886  /**
887  * return document includes in folder
888  * @param bool $controlview if false all document are returned else only visible for current user document are return
889  * @param array $filter to add list sql filter for selected document
890  * @param int|string $famid family identifier to restrict search
891  * @param string $qtype type os result TABLE|LIST|ITEM
892  * @param string $trash
893  * @return array array of document array
894  */
895  public function getContent($controlview = true, array $filter = array() , $famid = "", $qtype = "TABLE", $trash = "")
896  {
897  include_once ("FDL/Lib.Dir.php");
898  if ($controlview) $uid = $this->userid;
899  else $uid = 1;
900  $tdoc = internalGetDocCollection($this->dbaccess, $this->initid, 0, "ALL", $filter, $uid, $qtype, $famid, false, "title", true, $trash);
901  return $tdoc;
902  }
903  /**
904  * update folder relations
905  */
906  public function updateFldRelations()
907  {
908  return; //inhibit folder relation (too slow for great folder)
909 
910  }
911  /**
912  * return number of item in the static folder
913  * @param bool $onlyprimary set to true if you wnat only document linked by primary relation
914  * @return int -1 if it is not a static folder
915  */
916  public function count($onlyprimary = false)
917  {
918  if ($onlyprimary) {
919  $tdoc = $this->getPrimaryChild();
920  if ($tdoc) return count($tdoc);
921  } else {
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);
925  }
926  return -1;
927  }
928  /**
929  * return array of document identificators included in folder
930  * @return array of initial identificators (initid)
931  */
932  public function getContentInitid()
933  {
934  $query = sprintf("select childid from fld where dirid=%d and qtype='S'", $this->initid);
935  $initids = array();
936  $err = simpleQuery($this->dbaccess, $query, $initids, true, false);
937  if ($err == "") return $initids;
938 
939  return array();
940  }
941  /**
942  * get document which primary relation is this folder
943  *
944  *
945  * @return array of doc (array document)
946  */
947  public function getPrimaryChild()
948  {
949  $filter[] = "prelid=" . $this->initid;
950  return $this->getContent(true, $filter);
951  }
952 
953  protected function postAffect(array $data, $more, $reset)
954  {
955  $this->authfam = false;
956  $this->norestrict = false;
957  }
958  /**
959  * delete all document which primary relation is the folder (recurively)
960  * different of {@link Dir::Clear()}
961  * all document are put in the trash (zombie mode)
962  * @return array of possible errors. Empty array means no errors
963  */
964  public function deleteItems()
965  {
966  $filter[] = "prelid=" . $this->initid;
967  $lpdoc = $this->getContent(false, $filter, "", "ITEM");
968 
969  $terr = array();
970  while ($doc = getNextDoc($this->dbaccess, $lpdoc)) {
971  $coulddelete = true;
972  if ($doc->doctype == 'D') {
973  /* @var Dir $doc */
974  $terr = array_merge($terr, $doc->deleteItems());
975  foreach ($terr as $err) {
976  if ($err != "") $coulddelete = false;
977  }
978  }
979  if ($coulddelete) $terr[$doc->id] = $doc->delete();
980  }
981  $this->addHistoryEntry(_("Folder cleared") , HISTO_INFO, "MODCONTAIN");
982  return $terr;
983  }
984  /**
985  * copy (clone) all documents which primary relation is the folder (recurively)
986  * the others documents are just linked
987  * all document are put in $indirid folder id
988  * @param int $indirid the folder where put the copies
989  * @return array of possible errors. Empty array means no errors
990  */
991  public function copyItems($indirid)
992  {
993  $filter = array();
994  $lpdoc = $this->getContent(false, $filter, "", "ITEM");
995 
996  $terr = array();
997  $fld = new_doc($this->dbaccess, $indirid);
998  if ($fld->doctype == 'D') {
999  /* @var Dir $fld */
1000  $err = $fld->control("modify");
1001  if ($err == "") {
1002  while ($doc = getNextDoc($this->dbaccess, $lpdoc)) {
1003  if ($doc->prelid == $this->initid) {
1004  // copy
1005  $copy = $doc->duplicate();
1006  if (is_object($copy)) {
1007  $fld->insertDocument($copy->initid);
1008  if ($doc->doctype == 'D') {
1009  /* @var Dir $doc */
1010  $terr = array_merge($terr, $doc->copyItems($copy->id));
1011  }
1012  }
1013  } else {
1014  // link
1015  $fld->insertDocument($doc->initid);
1016  }
1017  }
1018  }
1019  }
1020  return $terr;
1021  }
1022  /**
1023  * delete the folder and its containt
1024  * different of {@link Dir::Clear()}
1025  * all document are put in the trash (zombie mode)
1026  * @return string error message, if no error empty string
1027  */
1028  public function deleteRecursive()
1029  {
1030  $err = $this->predocdelete(); // test before try recursive deletion
1031  if ($err != "") return $err;
1032  $coulddelete = true;
1033  $terr = $this->deleteItems();
1034  $err = "";
1035  foreach ($terr as $err1) {
1036  if ($err1 != "") {
1037  $coulddelete = false;
1038  $err.= "\n$err1";
1039  }
1040  }
1041  if ($coulddelete) $err = $this->delete();
1042  return $err;
1043  }
1044  /**
1045  * restore all document which primary relation is the folder (recurively)
1046  *
1047  *
1048  * @return array an array of errors
1049  */
1050  function reviveItems()
1051  {
1052  $filter[] = "prelid=" . $this->initid;
1053  $lpdoc = $this->getContent(true, $filter, "", "ITEM", "only");
1054  $terr = array();
1055  while ($doc = getNextDoc($this->dbaccess, $lpdoc)) {
1056  if ($doc->defDoctype == 'D') {
1057  /*
1058  * @var Dir $doc
1059  */
1060  $terr = array_merge($terr, $doc->reviveItems());
1061  }
1062  $terr[$doc->id] = $doc->undelete();
1063  }
1064  return $terr;
1065  }
1066 }
getNextDoc($dbaccess, &$tres)
$tdoc
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
global $action
addLog($code= '', $arg= '', $comment= '', $level= '', $uid= '')
Definition: Class.Doc.php:4762
deleteItems()
Definition: Class.Dir.php:964
exec_query($sql, $lvl=0, $prepare=false)
postModify()
Definition: Class.Dir.php:796
const HISTO_INFO
Clear()
Definition: Class.Dir.php:108
$eviews
Definition: Class.Dir.php:29
$profid
Definition: Class.Doc.php:411
postStore()
Definition: Class.Dir.php:780
static getSystemUserId()
Definition: Class.Doc.php:8981
canModify()
Definition: Class.Dir.php:272
AddFile($docid, $mode="latest", $noprepost=false, $forcerestrict=false, $nocontrol=false)
Definition: Class.Dir.php:295
postUnlinkDoc($docid, $multiple=false)
Definition: Class.Dir.php:263
clearValue($attrid)
Definition: Class.Doc.php:4409
preInsertDocument($docid, $multiple=false)
Definition: Class.Dir.php:129
controlTdoc(&$tdoc, $aclname)
count($onlyprimary=false)
Definition: Class.Dir.php:916
getQids($docid)
Definition: Class.Dir.php:624
const FAM_ACCESSDOC
Definition: Class.Doc.php:31
postInsertDoc($docid, $multiple=false)
Definition: Class.Dir.php:167
GetHome($create=true)
Definition: Class.Dir.php:43
InsertMDoc($tdocs, $mode="latest", $noprepost=false, &$tinserted=array(), &$twarning=array())
Definition: Class.Dir.php:433
QuickInsertMSDocId($tdocids)
Definition: Class.Dir.php:584
isAlive()
Definition: Class.Doc.php:6647
__construct($dbaccess= '', $id= '', $res= '', $dbid=0)
Definition: Class.Dir.php:33
isAuthorized($classid)
Definition: Class.Dir.php:874
updateFldRelations()
Definition: Class.Dir.php:906
getContent($controlview=true, array $filter=array(), $famid="", $qtype="TABLE", $trash="")
Definition: Class.Dir.php:895
modify($nopost=false, $sfields="", $nopre=false)
removeDocument($docid, $noprepost=false, $nocontrol=false)
Definition: Class.Dir.php:673
postInsertDocument($docid, $multiple=false)
Definition: Class.Dir.php:154
const PARAM_USER
Definition: Class.Param.php:34
getPrimaryChild()
Definition: Class.Dir.php:947
postMInsertDoc($tdocid)
Definition: Class.Dir.php:211
AddLogMsg($msg, $cut=80)
Definition: Lib.Common.php:77
preInsertDoc($docid, $multiple=false)
Definition: Class.Dir.php:142
insertFolder($docid)
Definition: Class.Dir.php:610
postInsertMultipleDocuments($tdocid)
Definition: Class.Dir.php:183
$docid
Definition: cleanFamily.php:13
preInsertMultipleDocuments($tdocid)
Definition: Class.Dir.php:198
GetClassesDoc($dbaccess, $userid, $classid=0, $qtype="LIST", $extraFilters=array())
Definition: Lib.Dir.php:906
isLocked($my=false)
Definition: Class.Doc.php:1449
postRemoveDocument($docid, $multiple=false)
Definition: Class.Dir.php:237
getContentInitid()
Definition: Class.Dir.php:932
getMultipleRawValues($idAttr, $def="", $index=-1)
Definition: Class.Doc.php:3240
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
getParam($param, $defv="")
Definition: Class.Doc.php:8686
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)
Definition: Lib.Dir.php:428
getFamIdFromName($dbaccess, $name)
getTitle($id="-1", $def="", $latest=false)
Definition: Class.Doc.php:8715
preUnlinkDoc($docid, $multiple=false)
Definition: Class.Dir.php:250
deprecatedFunction($msg= '')
Definition: Lib.Common.php:86
const FAM_ACCESSDIR
Definition: Class.Doc.php:32
deleteRecursive()
Definition: Class.Dir.php:1028
new_Doc($dbaccess, $id= '', $latest=false)
insertMultipleDocuments(array $tdocs, $mode="latest", $noprepost=false, &$tinserted=array(), &$twarning=array(), &$info=array())
Definition: Class.Dir.php:454
copyItems($indirid)
Definition: Class.Dir.php:991
postAffect(array $data, $more, $reset)
Definition: Class.Dir.php:953
preRemoveDocument($docid, $multiple=false)
Definition: Class.Dir.php:225
const FAM_DIR
Definition: Class.Doc.php:30
$info
Definition: geticon.php:30
if(($docid!==0)&&(!is_numeric($docid))) $query
DelFile($docid, $noprepost=false, $nocontrol=false)
Definition: Class.Dir.php:658
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
moveDocument($docid, $movetoid)
Definition: Class.Dir.php:736
insertDocument($docid, $mode="latest", $noprepost=false, $forcerestrict=false, $nocontrol=false)
Definition: Class.Dir.php:315
if($file) if($subject==""&&$file) if($subject=="") $err
addHistoryEntry($comment= '', $level=DocHisto::INFO, $code= '', $uid= '')
Definition: Class.Doc.php:4707
getRawValue($idAttr, $def="")
Definition: Class.Doc.php:3117
$defDoctype
Definition: Class.Dir.php:25
reviveItems()
Definition: Class.Dir.php:1050
$initid
Definition: Class.Doc.php:361
hasNoRestriction()
Definition: Class.Dir.php:802
getAuthorizedFamilies($classid=0, $verifyCreate=false)
Definition: Class.Dir.php:815
$data
← centre documentaire © anakeen