Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
family_defaultmenu.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Generate bar menu
8  *
9  * @author Anakeen
10  * @version $Id: barmenu.php,v 1.54 2008/08/14 09:59:14 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 require_once "GENERIC/generic_util.php";
18 require_once "FDL/Lib.Attr.php";
19 // -----------------------------------
21 {
22  // -----------------------------------
23  global $dbaccess; // use in getChildCatg function
24  $dirid = $action->getArgument("dirid", getDefFld($action)); // folder where search
25  $catg = $action->getArgument("catg", 1); // catg where search
26  $pds = $action->getArgument("pds"); // special extra parameters used by parametrable searches
27  $dbaccess = $action->dbaccess;
28 
29  $onefamOrigin = $action->getArgument("onefam"); // onefam origin
30  $famid = getDefFam($action);
31  $defaultMenu = array();
32  $fdoc = new_Doc($dbaccess, $famid);
33 
34  if ($catg > 1) {
35  $fld = new_Doc($dbaccess, $catg);
36  } else {
37  $fld = new_Doc($dbaccess, $dirid);
38  }
39  //change famid if it is a simplesearch
40  $sfdoc = $fdoc; // search family
41  if ($fld->isAlive()) {
42  $sfamid = $fld->getRawValue("se_famid");
43  if ($sfamid && $sfamid != $fdoc->id) {
44  $sfdoc = new_Doc($dbaccess, $sfamid);
45  if (!$sfdoc->isAlive()) {
46  $sfdoc = $fdoc; // restore if dead
47 
48  }
49  }
50  }
51  $defaultMenuCreate = array();
52  if (($fdoc->control("create") == "") && ($fdoc->control("icreate") == "")) {
53  $child[$famid] = array(
54  "title" => $fdoc->getTitle() ,
55  "id" => $famid,
56  "name" => $fdoc->name
57  );
58  } else {
59  $child = array();
60  }
61 
62  $onlyonefam = (getInherit($action, $famid) == "N");
63  if (!$onlyonefam) {
64  $child+= $fdoc->GetChildFam($fdoc->id, true);
65  }
66 
67  if ($action->HasPermission("GENERIC")) {
68  foreach ($child as $vid) {
69  $defaultMenuCreate[] = array(
70  "label" => DocFam::getLangTitle($vid) ,
71  "target" => "finfo",
72  "url" => sprintf("?app=GENERIC&amp;action=GENERIC_EDIT&amp;classid=%s", $vid["id"])
73  );
74  }
75  }
76  if (count($defaultMenuCreate)) {
77  $defaultMenu["create"] = array(
78  "label" => _("Creation") ,
79  "title" => _("Document creation") ,
80  "items" => $defaultMenuCreate
81  );
82  }
83  //--------------------- enum menu -----------------------
84  $lattr = $sfdoc->getNormalAttributes();
85  /*
86  * @var NormalAttribute $a
87  */
88  foreach ($lattr as $a) {
89  if ((($a->type == "enum") || ($a->type == "enumlist")) && (($a->phpfile != "-") && ($a->getOption("bmenu") != "no"))) {
90  $tmkind = array();
91  $enum = $a->getenum();
92  $enumItems = array();
93  foreach ($enum as $kk => $ki) {
94  $klabel = $a->getenumLabel($kk);
95  $tmpArray = explode('/', $klabel, substr_count($kk, '.') + 0);
96  $klabel = array_pop($tmpArray);
97  $enumItems[] = array(
98  "label" => $klabel,
99  "data-level" => (substr_count($kk, '.') - substr_count($kk, '\.')) ,
100  "href" => sprintf("?app=GENERIC&amp;action=GENERIC_SEARCH_KIND&amp;onefam=%s&amp;famid=%s&amp;kid=%s&amp;aid=%s&amp;catg=%s%s", $onefamOrigin, $famid, urlencode($kk) , $a->id, $catg, $pds)
101  );
102  $tmkind[] = $a->id . $kk;
103  }
104  $defaultMenu[$a->id] = array(
105  "title" => sprintf(_("Filter on %s") , $a->getLabel()) ,
106  "label" => $a->getLabel() ,
107  "items" => $enumItems
108  );
109  }
110  }
111  //--------------------- tools menu -----------------------
112  $toolsItemMenu = array();
113  if (empty($onefamOrigin) && $action->HasPermission("GENERIC")) {
114  $d = new_doc($dbaccess, 16);
115  if ($d->control("create") == "" && $d->control("icreate") == "") {
116  $toolsItemMenu['newsearch'] = array(
117  "label" => _("New search") ,
118  "target" => "finfo",
119  "url" => sprintf('?app=GENERIC&amp;action=GENERIC_EDIT&amp;se_memo=yes&amp;classid=16&amp;onlysubfam=%s&amp;sfamid=%s', $famid, $famid)
120  );
121  }
122 
123  $d = new_doc($dbaccess, 25);
124  if ($d->control("create") == "" && $d->control("icreate") == "") {
125  $toolsItemMenu['newreport'] = array(
126  "label" => _("New report") ,
127  "target" => "finfo",
128  "url" => sprintf('?app=GENERIC&amp;action=GENERIC_EDIT&amp;se_memo=yes&amp;classid=25&amp;onlysubfam=%s&amp;sfamid=%s', $famid, $famid)
129  );
130  }
131  }
132 
133  if (empty($onefamOrigin) && ($dirid < 1000000000) && ($catg > 1)) {
134  $toolsItemMenu['memosearch'] = array(
135  "label" => _("memosearch") ,
136  "target" => "fhidden",
137  "url" => sprintf('?app=GENERIC&amp;action=GENERIC_MEMOSEARCH&amp;famid=%s&amp;
138  psearchid=%s', $famid, $catg)
139  );
140  }
141 
142  if (empty($onefamOrigin)) {
143  $toolsItemMenu['viewsearch'] = array(
144  "label" => _("View my searches") ,
145  "target" => "_overlay",
146  "url" => sprintf('?app=GENERIC&amp;action=GENERIC_SEARCH&amp;catg=0&amp;onefam=%s&amp;mysearches=yes&amp;famid=%s', $onefamOrigin, $famid)
147  );
148  } else {
149  $toolsItemMenu['viewsearch'] = array(
150  "label" => _("Handle my searches") ,
151  "target" => "_overlay",
152  "url" => sprintf('?app=%s&amp;action=ONEFAM_MANAGE_SEARCH&amp;famId=%s', $onefamOrigin, $famid)
153  );
154  }
155 
156  if (empty($onefamOrigin) && $action->HasPermission("GED", "FREEDOM")) {
157  $toolsItemMenu['folders'] = array(
158  "label" => _("folders") ,
159  "target" => "freedom$famid",
160  "url" => sprintf('?app=FREEDOM&amp;action=FREEDOM_FRAME&amp;dirid=%s&amp;famid=%s', getDefFld($action) , $famid)
161  );
162  }
163 
164  $toolsItemMenu['prefs'] = array(
165  "label" => _("Preferences") ,
166  "target" => "_self",
167  "url" => sprintf('?app=GENERIC&amp;action=GENERIC_PREFS&amp;dirid=%s&amp;famid=%s&amp;onefam=%s', getDefFld($action) , $famid, $onefamOrigin)
168  );
169 
170  $lmenu = $fdoc->GetMenuAttributes();
171  $firstGlobalMenu = true;
172  foreach ($lmenu as $k => $v) {
173  if ($v->getOption("global") == "yes") {
174  $confirm = ($v->getOption("lconfirm") == "yes");
175 
176  $vis = MENU_ACTIVE;
177  if ($v->precond != "") $vis = $fdoc->ApplyMethod($v->precond, MENU_ACTIVE);
178  if ($vis == MENU_ACTIVE) {
179 
180  $textConfirm = '';
181  if ($firstGlobalMenu) {
182  $toolsItemMenu['family'] = array(
183  "label" => sprintf("%s", $fdoc->getHTMLTitle()) ,
184  "class" => "ui-widget-header"
185  );
186  $firstGlobalMenu = false;
187  }
188 
189  if ($confirm) {
190  $textConfirm = $v->getOption("tconfirm");
191  if (!$textConfirm) $textConfirm = sprintf(_("Sure %s ?") , addslashes($v->getLabel()));
192  }
193  $toolsItemMenu[$v->id] = array(
194  "label" => $v->getLabel() ,
195  "target" => $v->getOption("mtarget", $v->getoption('ltarget', $v->id)) ,
196  "confirm" => $textConfirm,
197  "url" => $fdoc->urlWhatEncode($v->link)
198  );
199  }
200  }
201  }
202  //----------------------------
203  // sort menu
204  $tsort = array();
205  $tsort["-"] = array(
206  "said" => "",
207  "satitle" => _("no sort") ,
208  "aorder" => ""
209  );
210  /*
211  * @var DocFam $sfdoc
212  */
213  $props = $sfdoc->getSortProperties();
214  foreach ($props as $propName => $config) {
215  if ($config['sort'] != 'asc' && $config['sort'] != 'desc') {
216  continue;
217  }
218  switch ($propName) {
219  case 'state':
220  if ($sfdoc->wid > 0) {
221  $tsort["state"] = array(
222  "said" => "state",
223  "satitle" => _("state") ,
224  "aorder" => getAttributeOrder($action, $propName, $config['sort'])
225  );
226  }
227  break;
228 
229  case 'title':
230  $tsort["title"] = array(
231  "said" => "title",
232  "satitle" => _("doctitle") ,
233  "aorder" => getAttributeOrder($action, $propName, $config['sort'])
234  );
235  break;
236 
237  case 'initid':
238  $tsort["initid"] = array(
239  "said" => "initid",
240  "satitle" => _("createdate") ,
241  "aorder" => getAttributeOrder($action, $propName, $config['sort'])
242  );
243  break;
244 
245  default:
246  $label = Doc::$infofields[$propName]['label'];
247  if ($label != '') {
248  $label = _($label);
249  }
250  $tsort[$propName] = array(
251  "said" => $propName,
252  "satitle" => $label,
253  "aorder" => getAttributeOrder($action, $propName, $config['sort'])
254  );
255  }
256  }
257 
258  foreach ($tsort as $k => $v) {
259  $tmsort[$v["said"]] = "sortdoc" . $v["said"];
260  }
261  $lattr = $sfdoc->GetSortAttributes();
262  foreach ($lattr as $k => $a) {
263  $pType = parseType($a->type);
264 
265  if ($pType['type'] == 'docid') {
266  $doctitleAttr = $a->getOption('doctitle');
267  if ($doctitleAttr != '') {
268  /*
269  * @var NormalAttribute $sortAttribute
270  */
271  $sortAttribute = false;
272  if ($doctitleAttr == 'auto') {
273  $sortAttribute = $sfdoc->getAttribute(sprintf("%s_title", $a->id));
274  } else {
275  $sortAttribute = $sfdoc->getAttribute($doctitleAttr);
276  }
277  if ($sortAttribute === false) {
278  $action->log->error(sprintf("Could not find doctitle attribute '%s' for attribute '%s'", $doctitleAttr, $a->id));
279  continue;
280  }
281  $tsort[$sortAttribute->id] = array(
282  "said" => $sortAttribute->id,
283  "satitle" => $a->getLabel() ,
284  "aorder" => getAttributeOrder($action, $sortAttribute->id, $sortAttribute->getOption('sortable'))
285  );
286  $tmsort[$sortAttribute->id] = "sortdoc" . $sortAttribute->id;
287  continue;
288  }
289  }
290 
291  $tsort[$a->id] = array(
292  "said" => $a->id,
293  "satitle" => $a->getLabel() ,
294  "aorder" => getAttributeOrder($action, $a->id, $a->getOption('sortable'))
295  );
296  $tmsort[$a->id] = "sortdoc" . $a->id;
297  }
298  // select the current sort
299  $csort = $action->getArgument("sqlorder");
300  if ($csort == "") $csort = getDefUSort($action, "--");
301 
302  if (($csort == '') || ($csort == '--')) {
303  $csort = '-';
304  $cselect = "&bull;";
305  } else if ($csort[0] == '-') {
306  $csort = substr($csort, 1);
307  $cselect = "&uarr;";
308  } else {
309  $cselect = "&darr;";
310  }
311 
312  $sortTitle = _("Sort");
313  $sortItemMenu = array();
314  foreach ($tsort as $k => $v) {
315  $dsort = ($csort == $k) ? $cselect : "&nbsp;"; // use puce
316  if ($csort == $k) $sortTitle = $v["satitle"] . $cselect;
317  $sortItemMenu[] = array(
318  "label" => $dsort . '&nbsp;' . $v["satitle"],
319  "href" => sprintf("javascript:sendSort('%s','%s','%s','%s','%s')", $onefamOrigin, $dirid, $catg, $famid, $v["aorder"])
320  );
321  }
322  $defaultMenu["sort"] = array(
323  "title" => _("Sort") ,
324  "label" => $sortTitle,
325  "items" => $sortItemMenu
326  );
327  $defaultMenu["tools"] = array(
328  "label" => _("Tools") ,
329  "items" => $toolsItemMenu
330  );
331  return $defaultMenu;
332 }
333 function getAttributeOrder(Action & $action, $attrName, $orderBy)
334 {
335  $usort = getDefUSort($action, "__UNDEFINED");
336  if ($usort != "__UNDEFINED") {
337  /*
338  * Invert the sort sign and extract attr name
339  */
340  if ((!empty($usort)) && $usort[0] == "-") {
341  $invertedSortSign = "";
342  $sortAttr = substr($usort, 1);
343  } else {
344  $invertedSortSign = "-";
345  $sortAttr = $usort;
346  }
347  /*
348  * If the sort is on the same attr, then
349  * we set sort on the same attr but with
350  * the inverted sign
351  */
352  if ($sortAttr == $attrName) {
353  return $invertedSortSign . $attrName;
354  }
355  }
356  /*
357  * By default, we set the sort sign from the
358  * 'sortable' option or the 'sort' property parameter
359  */
360  if ($orderBy === 'desc') {
361  return "-" . $attrName;
362  }
363  return $attrName;
364 }
static $infofields
Definition: Class.Doc.php:105
global $action
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
getDefUSort(Action &$action, $def="-revdate", $famid="")
getDefFld(Action &$action)
family_defaultmenu(Action &$action)
getDefFam(Action &$action)
$d
Definition: dav.php:77
const MENU_ACTIVE
Definition: Class.Doc.php:36
error($msg)
getAttributeOrder(Action &$action, $attrName, $orderBy)
new_Doc($dbaccess, $id= '', $latest=false)
parseType($type)
Definition: Lib.Attr.php:29
static getLangTitle($values)
static getArgument($k, $def= '')
$dbaccess
Definition: checkVault.php:17
getInherit(Action &$action, $famid="")
← centre documentaire © anakeen