Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
viewfolder.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * View folder containt
9  *
10  * @author Anakeen 2003
11  * @version $Id: viewfolder.php,v 1.92 2008/08/14 09:59:14 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 
19 include_once ("FDL/Class.SearchDoc.php");
20 include_once ("FDL/Class.DocAttr.php");
21 include_once ("FDL/freedom_util.php");
22 include_once ("FDL/Class.QueryDir.php");
23 // -----------------------------------
24 // -----------------------------------
25 function viewfolder(&$action, $with_abstract = false, $with_popup = true, $column = false, $slice = "-", // view all document (not slice by slice)
26 $sqlfilters = array() , // more filters to see specials doc
27 $famid = "") // folder containt special fam id
28 
29 {
30  // -----------------------------------
31  // Get all the params
32  $dirid = GetHttpVars("dirid"); // directory to see
33  $refresh = GetHttpVars("refresh", "no"); // force folder refresh
34  $startpage = GetHttpVars("page", "0"); // page number
35  $target = GetHttpVars("target", "fdoc"); // target for hyperlinks
36  $sqlorder = GetHttpVars("sqlorder"); // order sort attribute
37  $viewone = (GetHttpVars("viewone", "N") == "Y"); // direct view if only one
38  if ($slice == "-") $slice = $action->GetParam("FDL_FOLDERMAXITEM", 1000);
39  // $column = ($with_popup && ($action->getParam("FREEDOM_VIEW")=="column"));
40  // Set the globals elements
41  $baseurl = $action->GetParam("CORE_BASEURL");
42  $standurl = $action->GetParam("CORE_STANDURL");
43  $dbaccess = $action->GetParam("FREEDOM_DB");
44 
45  $dir = new_Doc($dbaccess, $dirid);
46 
47  $dirid = $dir->id; // use initial id for directories
48  $distinct = false;
49 
50  $action->lay->set("RSS", ($dir->getValue("gui_isrss") == "yes" ? true : false));
51  $action->lay->set("rsslink", $dir->getRssLink());
52  $action->lay->set("foldername", $dir->getHtmlTitle());
53  // control open
54  if ($dir->defDoctype == 'S') {
55  $aclctrl = "execute";
56  if ($sqlorder == "") $sqlorder = $dir->getValue("se_orderby");
57  } else $aclctrl = "open";
58  if (($err = $dir->Control($aclctrl)) != "") $action->exitError($err);
59 
60  $action->lay->Set("dirtitle", stripslashes($dir->getHtmlTitle()));
61  $action->lay->Set("dirid", $dirid);
62 
63  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/subwindow.js");
64  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/resizeimg.js");
65  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/geometry.js");
66 
67  $action->lay->set("VALTERN", ($action->GetParam("FDL_VIEWALTERN", "yes") == "yes"));
68 
69  if ($dirid == "") {
70  $action->exitError(_("cannot see unknow folder"));
71  }
72 
73  if ($startpage > 0) {
74  $pagefolder = $action->Read("pagefolder");
75  $start = $pagefolder[$startpage];
76  } else $start = 0;
77 
78  $terr = getChildDocError($dbaccess, $dirid);
79  if (count($terr) > 0) {
80  if ($dir->defDoctype == 'S') {
81  redirect($action, "FDL", "IMPCARD&zone=FREEDOM:PARAMDSEARCH:T&id=$dirid", $action->GetParam("CORE_STANDURL") , true);
82  } else {
83  $action->addWarningMsg(implode("\n", $terr));
84  redirect($action, "FDL", "FDL_CARD&id=$dirid", $action->GetParam("CORE_STANDURL") , true);
85  }
86  }
87 
88  $sd = new SearchDoc($dbaccess, $famid);
89  $sd->setSlice($slice);
90  $sd->setStart($start);
91  if ($dirid) $sd->useCollection($dirid);
92  $sd->excludeConfidential();
93  $sd->distinct = $distinct;
94  $sd->setOrder($sqlorder);
95  if ($sqlfilters) foreach ($sqlfilters as $filter) $sd->addFilter($filter);
96  $sd->setObjectReturn();
97  //$ldoc = getChildDoc($dbaccess, $dirid,$start,$slice,$sqlfilters,$action->user->id,"TABLE",$famid,
98  //$distinct, $sqlorder);
99  $sd->search();
100 
101  if ($viewone && ($sd->count() == 1)) {
102 
103  $doc1 = $sd->nextDoc();
104 
105  if ($doc1->doctype == "D") redirect($action, "FREEDOM", "OPENFOLIO&id=" . $doc1->initid, $action->GetParam("CORE_STANDURL"));
106  else redirect($action, "FDL", "FDL_CARD&latest=Y&id=" . $doc1->id, $action->GetParam("CORE_STANDURL"));
107  exit;
108  }
109  $famid = abs($famid);
110  if ($with_popup) {
111  // Set Popup
112  include_once ("FDL/popup_util.php");
113  // ------------------------------------------------------
114  // definition of popup menu
115  popupInit("popuplist", array(
116  'vprop',
117  'editdoc',
118  'cancel',
119  'copy',
120  'addbasket',
121  'duplicate',
122  'ifld',
123  'delete'
124  ));
125  }
126 
127  $kdiv = 1;
128  $tdoc = array();
129 
130  $nbseedoc = 0;
131  if (!$sd->searchError()) {
132  // get date format
133  if ($action->GetParam("CORE_LANG") == "fr_FR") { // date format depend of locale
134  $fdate = "%d/%m/%y";
135  } else {
136  $fdate = "%x";
137  }
138 
139  $nbdoc = 0;
140  $prevFromId = - 2;
141 
142  $tfamdoc = array();
143  $lattr = array();
144 
145  $k = 0;
146  while ($doc = $sd->nextDoc()) {
147 
148  if ($doc->isConfidential()) continue;
149  $nbseedoc++;
150 
151  $nbdoc++; // one more visible doc
152  $docid = $doc->id;
153 
154  $tdoc[$k]["id"] = $docid;
155  $tdoc[$k]["fromid"] = $doc->fromid;
156  // search title for freedom item
157  $title = $doc->getHtmlTitle();
158  $tdoc[$k]["title"] = $title;
159 
160  if ($doc->doctype == "C") $tdoc[$k]["title"] = "<B>" . $title . "</B>";
161 
162  if (strlen($title) > 20) $tdoc[$k]["abrvtitle"] = mb_substr($title, 0, 12) . " ... " . mb_substr($title, -5);
163  else $tdoc[$k]["abrvtitle"] = $title;
164 
165  if (isset($doc->_highlight) && $doc->_highlight != "") {
166  $tdoc[$k]["highlight"] = $doc->_highlight;
167  } else $tdoc[$k]["highlight"] = $title;
168  $tdoc[$k]["icontitle"] = $tdoc[$k]["highlight"];
169 
170  $tdoc[$k]["profid"] = $doc->profid;
171  $tdoc[$k]["revdate"] = strftime($fdate, intval($doc->revdate));
172 
173  $tdoc[$k]["iconsrc"] = $doc->geticon();
174 
175  $tdoc[$k]["divid"] = $kdiv;
176 
177  $tdoc[$k]["locked"] = "";
178  $tdoc[$k]["emblem"] = $action->GetImageUrl("1x1.png");
179  $tdoc[$k]["emblemt"] = "";
180  $tdoc[$k]["emblemw"] = "0";
181  $tdoc[$k]["canedit"] = 1;
182  $tdoc[$k]["postitid"] = ($doc->postitid > 0) ? $doc->postitid : false;
183  $tdoc[$k]["forumid"] = ($doc->forumid > 0) ? $doc->forumid : false;
184  $tdoc[$k]["inDomain"] = $doc->isInDomain();
185 
186  $tdoc[$k]["emblem"] = $doc->getEmblem();
187  if ($doc->confidential > 0) {
188  // $tdoc[$k]["emblem"] = $action->GetImageUrl("confidential.gif");
189  $tdoc[$k]["emblemt"] = _("confidential");
190  //$tdoc[$k]["emblemw"] ="12";
191  $tdoc[$k]["canedit"] = false;
192  $tdoc[$k]["locked"] = sprintf("<img src=\"%s\" title=\"%s\" width=\"20px\">", $tdoc[$k]["emblem"], $tdoc[$k]["emblemt"]);
193  } else if ($doc->locked == - 1) {
194  // $tdoc[$k]["emblem"] = $action->GetImageUrl("revised.gif");
195  $tdoc[$k]["emblemt"] = _("fixed");
196  // $tdoc[$k]["emblemw"] ="12";
197  $tdoc[$k]["canedit"] = false;
198  $tdoc[$k]["locked"] = sprintf("<img src=\"%s\" title=\"%s\" width=\"20px\">", $tdoc[$k]["emblem"], $tdoc[$k]["emblemt"]);
199  } else if ($doc->lockdomainid > 0) {
200  // $tdoc[$k]["emblem"] = $action->GetImageUrl("clef1.gif");
201  $tdoc[$k]["emblemt"] = _("domain locked");
202  // $tdoc[$k]["emblemw"] ="12";
203  $tdoc[$k]["locked"] = sprintf("<img src=\"%s\" title=\"%s\" width=\"20px\">", $tdoc[$k]["emblem"], $tdoc[$k]["emblemt"]);
204  } else if ((abs($doc->locked) == $action->parent->user->id)) {
205  // $tdoc[$k]["emblem"] = $action->GetImageUrl("clef1.gif");
206  $tdoc[$k]["emblemt"] = _("locked");
207  // $tdoc[$k]["emblemw"] ="12";
208  $tdoc[$k]["locked"] = sprintf("<img src=\"%s\" title=\"%s\" width=\"20px\">", $tdoc[$k]["emblem"], $tdoc[$k]["emblemt"]);
209  } else if ($doc->locked != 0) {
210  // $tdoc[$k]["emblem"] = $action->GetImageUrl("clef2.gif");
211  $tdoc[$k]["emblemt"] = _("locked");
212  // $tdoc[$k]["emblemw"] ="12";
213  $tdoc[$k]["canedit"] = false;
214  $tdoc[$k]["locked"] = sprintf("<img src=\"%s\" title=\"%s\" width=\"20px\">", $tdoc[$k]["emblem"], $tdoc[$k]["emblemt"]);
215  } else if ($doc->archiveid != 0) {
216  // $tdoc[$k]["emblem"] = $action->GetImageUrl("archive.png");
217  $tdoc[$k]["emblemt"] = _("archived");
218  // $tdoc[$k]["emblemw"] ="12";
219  $tdoc[$k]["canedit"] = false;
220  $tdoc[$k]["locked"] = sprintf("<img src=\"%s\" title=\"%s\" width=\"20px\">", $tdoc[$k]["emblem"], $tdoc[$k]["emblemt"]);
221  } else if ($doc->control("edit") != "") {
222  // $tdoc[$k]["emblem"] = $action->GetImageUrl("nowrite.png");
223  $tdoc[$k]["emblemt"] = _("read-only");
224  // $tdoc[$k]["emblemw"] ="12";
225  $tdoc[$k]["canedit"] = false;
226  $tdoc[$k]["locked"] = sprintf("<img src=\"%s\" title=\"%s\" width=\"20px\">", $tdoc[$k]["emblem"], $tdoc[$k]["emblemt"]);
227  }
228  //else if ($doc->lmodify == "Y") if ($doc->doctype == 'F') $tdoc[$k]["locked"] = $action->GetIcon("changed2.gif",N_("changed"), 20,20);
229  $tdoc[$k]["iconsrc"] = $doc->geticon();
230 
231  if ($with_popup) {
232  // ------------------------------
233  // define popup accessibility
234  popupInvisible("popuplist", $kdiv, 'vprop'); // don't use : idem like simple clic
235  popupActive("popuplist", $kdiv, 'cancel');
236  popupActive("popuplist", $kdiv, 'copy');
237 
238  if (!$action->getParam("FREEDOM_IDBASKET")) popupInvisible("popuplist", $kdiv, 'addbasket');
239  else popupActive("popuplist", $kdiv, 'addbasket');
240  popupActive("popuplist", $kdiv, 'ifld');
241  popupActive("popuplist", $kdiv, 'duplicate');
242 
243  if ($dirid > 0) popupActive("popuplist", $kdiv, 'delete');
244  else popupInactive("popuplist", $kdiv, 'delete');
245 
246  if ($doc->doctype == 'C') {
247  popupInvisible("popuplist", $kdiv, 'editdoc');
248  } else {
249  $cud = ($doc->CanLockFile() == "");
250  if ($cud) {
251  popupActive("popuplist", $kdiv, 'editdoc');
252  } else {
253  popupInactive("popuplist", $kdiv, 'editdoc');
254  }
255  }
256 
257  if ($dir->defDoctype != 'D') {
258  // it's a search :: inhibit duplicate and suppress reference
259  popupInvisible("popuplist", $kdiv, 'duplicate');
260  popupInvisible("popuplist", $kdiv, 'delete');
261  }
262  }
263 
264  $kdiv++;
265  if ($doc->isRevisable()) $tdoc[$k]["revision"] = $doc->revision;
266  else $tdoc[$k]["revision"] = "";
267  if ($doc->state) {
268  $tdoc[$k]["state"] = $action->Text($doc->getState()); //$action->Text($doc->state);
269  $tdoc[$k]["statecolor"] = $doc->getStateColor("transparent");
270  } else {
271  $tdoc[$k]["state"] = "";
272  $tdoc[$k]["statecolor"] = "transparent";
273  }
274 
275  if (($doc->doctype == 'D') || ($doc->doctype == 'S')) $tdoc[$k]["isfld"] = "true";
276  else $tdoc[$k]["isfld"] = "false";
277  // ----------------------------------------------------------
278  // ABSTRACT MODE
279  // ----------------------------------------------------------
280  if ($with_abstract) {
281  if (!$doc->isConfidential()) {
282  // search abstract attribute for freedom item
283  $doc->ApplyMask(); // apply mask attribute
284  if ($with_abstract === 2) {
285  $tdoc[$k]["ABSTRACTVALUES"] = getAbstractDetail($doc, $target);
286  } else {
287  $tdoc[$k]["ABSTRACTVALUES"] = $doc->viewDoc($doc->defaultabstract, $target, true, $abstract);
288  $tdoc[$k]["LOrR"] = ($k % 2 == 0) ? "left" : "right";
289  }
290  } else $tdoc[$k]["ABSTRACTVALUES"] = "";
291  }
292  // ----------------------------------------------------------
293  // COLUMN MODE
294  // ----------------------------------------------------------
295  if ($column) {
296  $adoc = $doc->getFamDoc();
297  /* Check if the family header has already been generated */
298  $famdocAlreadyExists = false;
299  foreach ($tfamdoc as $famdoc) {
300  if ($famdoc['fid'] == $doc->fromid) {
301  $famdocAlreadyExists = true;
302  break;
303  }
304  }
305  if (!$famdocAlreadyExists) {
306  /* Generate the family header */
307  $tfamdoc[] = array(
308  "iconfamsrc" => $tdoc[$k]["iconsrc"],
309  "ftitle" => $adoc->title,
310  "fid" => $doc->fromid,
311  "blockattr" => "BATT" . $doc->fromid,
312  "blockvalue" => "BVAL" . $doc->fromid
313  );
314  // create the TR head
315  /* Store and remember abstract attributes for each new processed family */
316  $lattr[$doc->fromid] = $adoc->GetAbstractAttributes();
317  $taname = array();
318  $emptytableabstract = array();
319  foreach ($lattr[$doc->fromid] as $ka => $attr) {
320  if (($attr->mvisibility == 'H') || ($attr->mvisibility == 'I')) unset($lattr[$doc->fromid][$ka]);
321  }
322 
323  foreach ($lattr[$doc->fromid] as $ka => $attr) {
324  $emptytableabstract[$attr->id]["value"] = "-";
325  $taname[$attr->id]["aname"] = $attr->getLabel();
326  }
327  $action->lay->SetBlockData("BATT" . $doc->fromid, $taname);
328  }
329 
330  /* Stack up the documents values in tdoc */
331  $tvalues = array();
332 
333  if ($doc->isConfidential()) {
334  foreach ($lattr[$doc->fromid] as $ka => $attr) {
335  $tvalues[] = "x";
336  }
337  } else {
338  foreach ($lattr[$doc->fromid] as $ka => $attr) {
339  //$tvalues[]=$doc->getValue($attr->id,"-");
340  if ($attr->type == "image") $tvalues[] = '<img src="' . $doc->getHtmlValue($attr, $doc->getValue($attr->id, "-") , $target) . '&height=30" height="30">';
341  else $tvalues[] = ($doc->getValue($attr->id) ? $doc->getHtmlValue($attr, $doc->getValue($attr->id) , $target) : '-');
342  }
343  }
344  $tdoc[$k]["values"] = implode('</td><td class="tlist">', $tvalues);
345  }
346 
347  $k++;
348  }
349 
350  if ($column == 1) {
351  /* Order tdoc by 'fromid', 'title' */
352  $collator = new Collator($action->GetParam("CORE_LANG", "fr_FR"));
353  usort($tdoc, function($a, $b) use ($collator) {
354  $cmp = ($a['fromid'] - $b['fromid']);
355  return ($cmp == 0) ? $collator->compare($a['title'], $b['title']) : $cmp;
356  });
357  } else {
358  if ((GetHttpVars("sqlorder") == "") && ($slice >= $action->GetParam("FDL_FOLDERMAXITEM", 1000))) uasort($tdoc, "orderbytitle");
359  }
360  } else {
361  //error in search
362  addWarningMsg($sd->getError());
363  addLogMsg($sd->getSearchInfo());
364  }
365  // Out
366  //------------------------------
367  // display popup action
368  $tboo[0]["boo"] = "";
369  $action->lay->SetBlockData("VIEWPROP", $tboo);
370 
371  $action->lay->Set("nbdiv", $kdiv - 1);
372  if ($column) {
373  /*
374  * Sort documents with same fromid into separate lists
375  */
376  $tdocByFromId = array();
377  foreach ($tdoc as $doc) {
378  $tdocByFromId[$doc['fromid']] []= $doc;
379  }
380  /*
381  * Set the BVAL<fromid> blocks with the list of
382  * documents from the same family
383  */
384  foreach ($tdocByFromId as $fromid => $documentList) {
385  $action->lay->SetBlockData("BVAL" . $fromid, $documentList);
386  }
387  /* Order tfamdoc by 'ftitle' */
388  $collator = new Collator($action->GetParam("CORE_LANG", "fr_FR"));
389  usort($tfamdoc, function($a, $b) use ($collator) {
390  return $collator->compare($a['ftitle'], $b['ftitle']);
391  });
392  $action->lay->SetBlockData("TABLEBODY", $tfamdoc);
393  } else {
394  $action->lay->SetBlockData("TABLEBODY", $tdoc);
395  }
396 
397  if ($with_popup) {
398  // display popup js
399  popupGen($kdiv - 1);
400  }
401 
402  if ($with_popup || $column) {
403  // js : manage icons
404  $licon = new Layout($action->Getparam("CORE_PUBDIR") . "/FDL/Layout/manageicon.js", $action);
405  $licon->Set("nbdiv", $kdiv - 1);
406  $action->parent->AddJsCode($licon->gen());
407  }
408  // when slicing
409  $pagefolder[$startpage + 1] = $nbseedoc + $start;
410  $action->Register("pagefolder", $pagefolder);
411  $action->lay->Set("next", $startpage + 1);
412  $action->lay->Set("prev", $startpage - 1);
413 
414  $action->lay->Set("nbdoc", $nbdoc);
415  $action->lay->Set("wtarget", $target);
416 
417  return $nbdoc;
418 }
419 
420 function orderbyfromidtitle($a, $b)
421 {
422  $cmp = ($a['fromid'] - $b['fromid']);
423  return ($cmp == 0) ? strcasecmp($a['title'], $b['title']) : $cmp;
424 }
425 
426 function orderbytitle($a, $b)
427 {
428  return strcasecmp($a["title"], $b["title"]);
429 }
430 
432 {
433  $tout = array();
434  $lattr = $doc->GetAbstractAttributes();
435  $emptytableabstract = array();
436  foreach ($lattr as $ka => $attr) {
437  $val = $doc->GetHtmlAttrValue($ka, $target, 2, -1, true, true);
438 
439  if ($val) $tout[] = $val;
440  }
441  return implode(" - ", $tout);
442 }
443 ?>
← centre documentaire © anakeen - published under CC License - Dynacase