Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
generic_list.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * View set of documents of same family
8  *
9  * @author Anakeen
10  * @version $Id: generic_list.php,v 1.43 2008/10/30 09:23:46 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/viewfolder.php");
18 include_once ("GENERIC/generic_util.php");
19 /**
20  * View list of document from folder (or searches)
21  * @param Action &$action current action
22  * @global string $dirid Http var : folder identifier to see
23  * @global string $catg Http var :
24  * @global string $page Http var : page number
25  * @global string $tabs Http var : tab number 1 for ABC, 2 for DEF, if onglet=Y..
26  * @global string $onglet Http var : [Y|N] Y if want see alphabetics tabs
27  * @global string $famid Http var : main family identifier
28  * @global string $sqlorder Http var : order by attribute
29  * @global string $gview Http var : [abstract|column] view mode
30  */
32 {
33  // Set the globals elements
34  // Get all the params
35  $dirid = getHttpVars("dirid"); // directory to see
36  $catgid = getHttpVars("catg", $dirid); // category
37  $startpage = getHttpVars("page", "0"); // page to see
38  $tab = getHttpVars("tab", "0"); // tab to see 1 for ABC, 2 for DEF, ...
39  $onglet = getHttpVars("onglet"); // if you want onglet
40  $famid = getHttpVars("famid"); // family restriction
41  $clearkey = (getHttpVars("clearkey", "N") == "Y"); // delete last user key search
42  $sqlorder = getHttpVars("sqlorder"); // family restriction
43  $onefamOrigin = getHttpVars("onefam"); // onefam orgigin
44  $target = "finfo$famid";
45  setHttpVar("target", $target);
46  if (!($famid > 0)) $famid = getDefFam($action);
47 
48  $searchMode = $action->getParam("GENE_SEARCHMODE", "words");
49  if ($onefamOrigin) {
50  $onefamSearchMode = ApplicationParameterManager::getParameterValue($onefamOrigin, "ONEFAM_SEARCHMODE");
51  if ($onefamSearchMode) {
52  $searchMode = $onefamSearchMode;
53  }
54  }
55  $paginationType = "basic";
56  $column = generic_viewmode($action, $famid); // choose the good view mode
57  $dbaccess = $action->dbaccess;
58  $packGeneric = "";
59  $action->parent->addJsRef($action->getParam("CORE_JSURL") . "/DHTMLapi.js", false, $packGeneric);
60  $action->parent->addJsRef($action->getParam("CORE_JSURL") . "/geometry.js", false, $packGeneric);
61  $action->parent->addJsRef($action->getParam("CORE_JSURL") . "/AnchorPosition.js", false, $packGeneric);
62  $action->parent->addJsRef($action->getParam("CORE_PUBURL") . "/FDL/Layout/common.js", false, $packGeneric);
63  $action->parent->addJsRef($action->getParam("CORE_PUBURL") . "/FDL/Layout/popupfunc.js", false, $packGeneric);
64  $action->parent->addCssRef("css/dcp/main.css");
65  $action->parent->addCssRef("GENERIC:generic_list.css", true);
66 
67  $applicationPaginationConfig = json_decode(ApplicationParameterManager::getParameterValue($onefamOrigin, "ONEFAM_FAMCONFIG") , true);
68  if (!empty($applicationPaginationConfig)) {
69  $famName = getNameFromId($dbaccess, $famid);
70  if (isset($applicationPaginationConfig[$famName]) && isset($applicationPaginationConfig[$famName]["paginationType"]) && !empty($applicationPaginationConfig[$famName]["paginationType"])) {
71  $paginationType = $applicationPaginationConfig[$famName]["paginationType"];
72  } else if (isset($applicationPaginationConfig["*"]) && isset($applicationPaginationConfig["*"]["paginationType"]) && !empty($applicationPaginationConfig["*"]["paginationType"])) {
73  $paginationType = $applicationPaginationConfig["*"]["paginationType"];
74  }
75  }
76  //change famid if it is a simplesearch
77  $sfamid = $famid;
78  if ($dirid) {
79  $dir = new_doc($dbaccess, $dirid);
80  if ($dir->isAlive() && ($dir->defDoctype == 'S')) {
81  $sfamid = $dir->getRawValue("se_famid");
82  }
83  }
84  if ($onglet) {
85  $wonglet = ($onglet != 'N');
86  } else {
87  $wonglet = (getTabLetter($action, $famid) == 'Y');
88  }
89 
91  $catg = new_Doc($dbaccess, $catgid);
92  $action->lay->set("folderid", "0");
93  $pds = "";
94  if ($catg->doctype == 'D') $action->lay->set("folderid", $catg->id);
95  $action->lay->set("pds", "");
96  if ($catgid) {
97  $catg = new_Doc($dbaccess, $catgid);
98  $catgid = $catg->id;
99  $pds = $catg->urlWhatEncodeSpec("");
100  $action->lay->set("pds", $pds);
101 
102  $action->lay->set("fldtitle", $dir->getHTMLTitle());
103  } else {
104  if ($dirid == 0) {
105  $action->lay->set("fldtitle", _("precise search"));
106  $action->lay->set("pds", "");
107  } else {
108  $action->lay->set("fldtitle", $dir->getHTMLTitle());
109  }
110  }
111 
112  $action->lay->eSet("ONEFAMORIGIN", $onefamOrigin);
113  $action->lay->eSet("famtarget", $target);
114  $action->lay->eSet("dirid", $dir->id);
115  $action->lay->eSet("tab", $tab);
116  $action->lay->eSet("catg", $catgid);
117  $action->lay->eSet("famid", $famid);
118  $slice = $action->getParam("CARD_SLICE_LIST", 5);
119  // $action->lay->set("next",$start+$slice);
120  //$action->lay->set("prev",$start-$slice);
121  $action->lay->set("nexticon", "");
122  $action->lay->set("previcon", "");
123  if ($searchMode === "words") {
124  $action->lay->set("SearchPlaceHolder", ___("Search words", "generic"));
125  } else {
126  $action->lay->set("SearchPlaceHolder", ___("Search characters", "generic"));
127  }
128 
129  if ($sqlorder == "") {
130  /* This should be in sync with the default value $def from getDefUSort() */
131  $sqlorder = getDefUSort($action, "-revdate", $sfamid);
132  setHttpVar("sqlorder", $sqlorder);
133  }
134 
135  if ($famid > 0) {
136  if ($sqlorder != "") {
137  $ndoc = createDoc($dbaccess, $sfamid, false);
138  if ($sqlorder[0] == "-") {
139  $sqlorder = substr($sqlorder, 1);
140  }
141  if (!in_array($sqlorder, $ndoc->fields)) {
142  setHttpVar("sqlorder", "");
143  }
144  }
145  }
146  if ($clearkey) {
147  $action->setParamU("GENE_LATESTTXTSEARCH", setUkey($action, $famid, $keyword = ''));
148  }
149  $only = false;
150  if ($dirid) {
151  if ($dir->fromid == 38) {
152  $famid = 0; // special researches
153  setHttpVar("sqlorder", "--"); // no sort possible
154 
155  }
156  $only = (getInherit($action, $famid) == "N");
157  viewfolder($action, true, false, $column, $slice, array() , ($only) ? -(abs($famid)) : abs($famid) , $paginationType);
158  // can see next
159  $action->lay->set("nexticon", $action->getIcon("next.png", N_("next") , 16));
160  }
162 
163  if ($startpage > 0) {
164  // can see prev
165  $action->lay->set("previcon", $action->getIcon("prev.png", N_("prev") , 16));
166  }
167 
168  if ($dirid && $wonglet) {
169  // hightlight the selected part (ABC, DEF, ...)
170  $onglet = array(
171  array(
172  "onglabel" => "A B C",
173  "ongdir" => "1"
174  ) ,
175  array(
176  "onglabel" => "D E F",
177  "ongdir" => "2"
178  ) ,
179  array(
180  "onglabel" => "G H I",
181  "ongdir" => "3"
182  ) ,
183  array(
184  "onglabel" => "J K L",
185  "ongdir" => "4"
186  ) ,
187  array(
188  "onglabel" => "M N O",
189  "ongdir" => "5"
190  ) ,
191  array(
192  "onglabel" => "P Q R S",
193  "ongdir" => "6"
194  ) ,
195  array(
196  "onglabel" => "T U V",
197  "ongdir" => "7"
198  ) ,
199  array(
200  "onglabel" => "W X Y Z",
201  "ongdir" => "8"
202  ) ,
203  array(
204  "onglabel" => "A - Z",
205  "ongdir" => "0"
206  )
207  );
208 
209  foreach ($onglet as $k => $v) {
210  if ($v["ongdir"] == $tab) $onglet[$k]["ongclass"] = "onglets";
211  else $onglet[$k]["ongclass"] = "onglet";
212  $onglet[$k]["onglabel"] = str_replace(" ", "<BR>", $v["onglabel"]);
213  }
214 
215  $action->lay->setBlockData("ONGLET", $onglet);
216  }
217  $paginationConfig = array(
218  "type" => $paginationType,
219  "onefamconfig" => $onefamOrigin,
220  "tab" => $tab,
221  "dirid" => $dirid,
222  "catg" => $catgid,
223  "famid" => $famid,
224  "pds" => $pds,
225  "onglet" => $wonglet ? "Y" : "N"
226  );
227  $action->parent->setVolatileParam("paginationConfig", $paginationConfig);
228  $action->lay->set("onglet", $wonglet ? "Y" : "N");
229  $action->lay->set("hasOnglet", (!empty($wonglet)));
230 
231  $action->lay->eSet("tkey", getDefUKey($action));
232 }
233 
235 {
236  $prefview = getHttpVars("gview");
237 
238  $tmode = explode(",", $action->getParam("GENE_VIEWMODE"));
239  // explode parameters
240  $tview = array();
241  $tview[$famid] = '';
242  foreach ($tmode as $v) {
243  if ($v) {
244  list($fid, $vmode) = explode("|", $v);
245  $tview[$fid] = $vmode;
246  }
247  }
248  switch ($prefview) {
249  case "column":
250  case "abstract":
251  $tview[$famid] = $prefview;
252  // implode parameters to change user preferences
253  $tmode = array();
254  foreach ($tview as $k => $v) {
255  if ($k > 0) $tmode[] = "$k|$v";
256  }
257  $pmode = implode(",", $tmode);
258  $action->setParamU("GENE_VIEWMODE", $pmode);
259 
260  break;
261  }
262 
263  switch ($tview[$famid]) {
264  case "column":
265  $action->layout = $action->getLayoutFile("generic_listv.xml");
266  $action->lay = new Layout($action->layout, $action);
267  // $action->parent->addJsRef($action->getParam("CORE_PUBURL")."/FREEDOM/Layout/sorttable.js");
268  // $column=true;
269  $column = 2;
270  break;
271 
272  case "abstract":
273  default:
274  $action->layout = $action->getLayoutFile("generic_list.xml");
275  $action->lay = new Layout($action->layout, $action);
276  $column = false;
277 
278  break;
279  }
280  return $column;
281 }
282 
283 function getFamilySearches(Action $action, $dbaccess, $famid, $only = false)
284 {
285  // search searches in primary folder
286 
287  /*
288  * @var DocFam $fdoc
289  */
290  $fdoc = new_Doc($dbaccess, $famid);
291  $dirid = getHttpVars("dirid"); // search
292  $catgid = getHttpVars("catg", $dirid); // primary directory
293  if ($catgid == 0) $catgid = $dirid;
294 
295  $action->lay->set("ONESEARCH", false);
296  $utreeSearch = array();
297  $streeSearch = array();
298  $hasSysSearch = false;
299  if ($famid) {
300  if (isset($fdoc->dfldid) && $fdoc->dfldid > 0) {
301  // shared searches
302  $s = new SearchDoc($action->dbaccess, 5);
303  $s->useCollection($fdoc->dfldid);
304  $s->setObjectReturn();
305  $s->search();
306  $dl = $s->getDocumentList();
307  /*
308  * @var Doc $search
309  */
310  foreach ($dl as $ids => $search) {
311  if (($search->doctype == "S") && ($search->fromid != $fdoc->id)) {
312  if ($search->control("execute") != '') {
313  continue;
314  }
315  $stitle = $search->getHTMLTitle();
316 
317  $streeSearch[$ids]["id"] = $ids;
318  $streeSearch[$ids]["title"] = $stitle;
319  $streeSearch[$ids]["selected"] = ($ids == $catgid) ? "1" : "0";
320  $streeSearch[$ids]["isreport"] = "0";
321  $streeSearch[$ids]["gui_color"] = $search->getRawValue(\Dcp\AttributeIdentifiers\Search::gui_color);
322  $streeSearch[$ids]["isparam"] = "0";
323  $keys = $search->getRawValue("se_keys");
324  if (preg_match('/\?/', $keys)) {
325  $streeSearch[$ids]["title"] = "(P)" . $stitle;
326  $streeSearch[$ids]["isparam"] = "1";
327  }
328  if ($search->fromid == 25) {
329  $streeSearch[$ids]["title"] = "(R)" . $stitle;
330  $streeSearch[$ids]["isreport"] = "1";
331  }
332  }
333  }
334  }
335  $hasSysSearch = count($streeSearch) > 0;
336  $action->lay->set("ONESEARCH", ($hasSysSearch));
337 
338  $action->lay->setBlockData("SYSSEARCH", $streeSearch);
339  // search user searches for family
340  $s = new SearchDoc($action->dbaccess, 5);
341  $s->addFilter("owner=%d", $action->user->id);
342  // Need take account of generic parameter GENE_INHERIT
343  $child = $fdoc->getChildFam();
344  if ($only || count($child) == 0) {
345  $s->addFilter("se_famid='%s'", $fdoc->id);
346  } else {
347  $childIds = array_keys($child);
348  $childIds[] = $fdoc->id;
349  $s->addFilter($s->sqlcond($childIds, "se_famid"));
350  }
351 
352  $s->addFilter("usefor!='G'");
353  $s->addFilter("doctype != 'T'");
354  $s->addFilter("se_memo='yes'");
355  $s->setObjectReturn(true);
356  $dl = $s->search()->getDocumentList();
357  $action->lay->set("MSEARCH", false);
358  foreach ($dl as $ids => $search) {
359  if (!isset($streeSearch[$ids])) {
360  if ($search->control("execute") != '') {
361  continue;
362  }
363  $stitle = $search->getHTMLTitle();
364  $utreeSearch[$ids]["id"] = $ids;
365  $utreeSearch[$ids]["title"] = $stitle;
366  $utreeSearch[$ids]["selected"] = ($ids == $catgid) ? "1" : "0";
367  $utreeSearch[$ids]["isreport"] = "0";
368  $utreeSearch[$ids]["isparam"] = "0";
369  $utreeSearch[$ids]["gui_color"] = $search->getRawValue(\Dcp\AttributeIdentifiers\Search::gui_color);
370  $keys = $search->getRawValue("se_keys");
371  if (preg_match('/\?/', $keys)) {
372  $utreeSearch[$ids]["title"] = "(P)" . $stitle;
373  $utreeSearch[$ids]["isparam"] = "1";
374  }
375  if ($search->fromid == 25) {
376  $utreeSearch[$ids]["title"] = "(R)" . $stitle;
377  $utreeSearch[$ids]["isreport"] = "1";
378  }
379  }
380  }
381  }
382  $action->lay->set("MSEARCH", (count($utreeSearch) > 0 && $hasSysSearch));
383  $action->lay->setBlockData("USERSEARCH", $utreeSearch);
384  if (count($streeSearch) + count($utreeSearch) > 0) {
385  $action->lay->set("ONESEARCH", true);
386  }
387 }
Layout is a template generator.
global $action
getDefUSort(Action &$action, $def="-revdate", $famid="")
viewfolder(Action &$action, $with_abstract=false, $with_popup=true, $column=false, $slice="-", $sqlfilters=array(), $famid="", $paginationType="none")
Definition: viewfolder.php:34
static getParameterValue($application, $parameterName)
if($famId) $s
if(!function_exists('pgettext')) ___($message, $context="")
Definition: Lib.Common.php:46
getDefFam(Action &$action)
setParamU($name, $val)
$search
getLayoutFile($layname)
generic_viewmode(Action &$action, $famid)
getTabLetter(Action &$action, $famid="")
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
getHttpVars($name, $def="", $scope="all")
Definition: Lib.Http.php:124
new_Doc($dbaccess, $id= '', $latest=false)
setUkey(Action &$action, $famid, $key)
$dir
Definition: resizeimg.php:144
getParam($name, $def="")
getNameFromId($dbaccess, $id)
getFamilySearches(Action $action, $dbaccess, $famid, $only=false)
generic_list(&$action)
getDefUKey(Action &$action)
$keyword
$dbaccess
Definition: checkVault.php:17
getInherit(Action &$action, $famid="")
N_($s)
Definition: Lib.Common.php:18
← centre documentaire © anakeen