Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Zone/Generic/barmenu.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  * Generate bar menu
9  *
10  * @author Anakeen 2000
11  * @version $Id: barmenu.php,v 1.54 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 ("GENERIC/generic_util.php");
20 // -----------------------------------
21 function barmenu(&$action)
22 {
23  // -----------------------------------
24  global $dbaccess; // use in getChildCatg function
25 
26  $dirid = GetHttpVars("dirid", getDefFld($action)); // folder where search
27  $catg = GetHttpVars("catg", 1); // catg where search
28  if ($action->Read("navigator", "") == "EXPLORER") {
29  // special for position style
30  $action->lay->set("positionstyle", "");
31  $action->lay->set("fhelp", "_blank");
32  } else {
33  $action->lay->set("positionstyle", "fixed");
34  $action->lay->set("fhelp", "fhidden");
35  }
36 
37  $dbaccess = $action->GetParam("FREEDOM_DB");
38 
40 
41  $fdoc = new_Doc($dbaccess, $famid);
42 
43  if ($catg > 1) $fld = new_Doc($dbaccess, $catg);
44  else $fld = new_Doc($dbaccess, $dirid);
45  //change famid if it is a simplesearch
46  $sfamid = $famid;
47  $sfdoc = $fdoc; // search family
48  if ($fld->isAlive()) {
49  $sfamid = $fld->getValue("se_famid");
50  if ($sfamid && $sfamid != $fdoc->id) {
51  $sfdoc = new_Doc($dbaccess, $sfamid);
52  if (!$sfdoc->isAlive()) {
53  $sfdoc = $fdoc; // restore if dead
54 
55  }
56  }
57  }
58 
59  $action->lay->set("pds", $fld->urlWhatEncodeSpec("")); // parameters for searches
60  if (($fdoc->control("create") == "") && ($fdoc->control("icreate") == "")) {
61  $child[$famid] = array(
62  "title" => $fdoc->getTitle() ,
63  "id" => $famid
64  );
65  } else $child = array();
66 
67  $onlyonefam = (getInherit($action, $famid) == "N");
68  if (!$onlyonefam) $child+= $fdoc->GetChildFam($fdoc->id, true);
69 
70  $tchild = array();
71  $tnewmenu = array();
72  foreach ($child as $k => $vid) {
73  $tchild[] = array(
74  "stitle" => DocFam::getLangTitle($vid) ,
75  "subfam" => $vid["id"]
76  );
77  $tnewmenu[] = "newdoc" . $k;
78  }
79  $action->lay->SetBlockData("NEWFAM", $tchild);
80 
81  $action->lay->Set("dcreate", (count($tchild) > 0) ? "" : "none");
82  $action->lay->Set("cancreate", (count($tchild) > 0));
83 
84  $action->lay->Set("ftitle", $fdoc->gettitle());
85 
86  $action->lay->Set("famid", $famid);
87  $action->lay->Set("splitmode", getSplitMode($action, $famid));
88 
89  include_once ("FDL/popup_util.php");
90  include_once ("FDL/Lib.Attr.php");
91  //--------------------- kind menu -----------------------
92  $lattr = $sfdoc->getNormalAttributes();
93 
94  $tkind = array();
95  foreach ($lattr as $k => $a) {
96  if ((($a->type == "enum") || ($a->type == "enumlist")) && (($a->phpfile != "-") && ($a->getOption("bmenu") != "no"))) {
97 
98  $tkind[] = array(
99  "kindname" => $a->getLabel() ,
100  "kindid" => $a->id,
101  "vkind" => "kind" . $a->id
102  );
103  $tvkind = array();
104  $tmkind = array();
105  $enum = $a->getenum();
106  foreach ($enum as $kk => $ki) {
107  $klabel = $a->getenumLabel($ki);
108 
109  $klabel = array_pop(explode('/', $klabel, substr_count($kk, '.') + 0));
110  $tvkind[] = array(
111  "ktitle" => $klabel,
112  "level" => (substr_count($kk, '.') - substr_count($kk, '\.')) * 20,
113  "kid" => str_replace('\.', '.', $kk) ,
114  "urlkid" => urlencode($kk)
115  );
116  $tmkind[] = $a->id . $kk;
117  }
118  $action->lay->SetBlockData("kind" . $a->id, $tvkind);
119 
120  popupInit($a->id . "menu", $tmkind);
121  foreach ($tmkind as $km => $vid) {
122  popupActive($a->id . "menu", 1, $vid);
123  }
124  }
125  }
126 
127  $action->lay->SetBlockData("KIND", $tkind);
128  $action->lay->SetBlockData("MKIND", $tkind);
129 
130  $action->lay->Set("nbcol", 4 + count($tkind));
131  //--------------------- construction of menu -----------------------
132  popupInit("newmenu", $tnewmenu);
133 
134  popupInit("helpmenu", array(
135  'help',
136  'imvcard',
137  'folders',
138  'newdsearch',
139  'newreport',
140  'viewdsearch',
141  'memosearch',
142  'isplit',
143  'cview',
144  'aview',
145  'kindedit',
146  'prefs'
147  ));
148 
149  $lmenu = $fdoc->GetMenuAttributes();
150  foreach ($lmenu as $k => $v) {
151  if ($v->getOption("global") == "yes") {
152  $confirm = ($v->getOption("lconfirm") == "yes");
153  $tmenu[$k] = array(
154  "mid" => $v->id,
155  "mtitle" => $v->getLabel() ,
156  "confirm" => ($confirm) ? "true" : "false",
157  "tconfirm" => ($confirm) ? sprintf(_("Sure %s ?") , addslashes($v->getLabel())) : "",
158  "murl" => addslashes($fdoc->urlWhatEncode($v->link))
159  );
160 
161  popupAddItem('helpmenu', $v->id);
162  $vis = MENU_ACTIVE;
163  if ($v->precond != "") $vis = $fdoc->ApplyMethod($v->precond, MENU_ACTIVE);
164  if ($vis == MENU_ACTIVE) popupActive("helpmenu", 1, $v->id);
165  }
166  }
167 
168  $action->lay->setBlockData("FAMMENU", $tmenu);
169 
170  if ($action->HasPermission("GENERIC_MASTER")) popupActive("helpmenu", 1, 'kindedit');
171  else popupInvisible("helpmenu", 1, 'kindedit');
172 
173  if ($action->HasPermission("GENERIC")) {
174 
175  while (list($k, $vid) = each($tnewmenu)) {
176  popupActive("newmenu", 1, $vid);
177  }
178  } else {
179 
180  while (list($k, $vid) = each($tnewmenu)) {
181  popupInactive("newmenu", 1, $vid);
182  }
183  }
184 
185  if (($dirid < 1000000000) && ($catg > 1)) popupActive("helpmenu", 1, 'memosearch');
186  else popupInvisible("helpmenu", 1, 'memosearch');
187 
188  if ($action->HasPermission("GENERIC_MASTER")) {
189  popupActive("helpmenu", 1, 'imvcard');
190  } else {
191  popupInvisible("helpmenu", 1, 'imvcard');
192  }
193 
194  popupInvisible("helpmenu", 1, 'isplit');
195  popupInvisible("helpmenu", 1, 'cview');
196  popupInvisible("helpmenu", 1, 'aview');
197  popupActive("helpmenu", 1, 'prefs');
198  popupActive("helpmenu", 1, 'newdsearch');
199  popupActive("helpmenu", 1, 'newreport');
200  popupActive("helpmenu", 1, 'viewdsearch');
201 
202  popupInactive("helpmenu", 1, 'help'); // for the moment need to rewrite documentation
203  popupInvisible("helpmenu", 1, 'folders');
204  if ($idappfree = $action->parent->Exists("FREEDOM")) {
205 
206  $permission = new Permission($action->dbaccess, array(
207  $action->user->id,
208  $idappfree
209  ));
210 
211  if (($action->user->id == 1) || ($permission->isAffected() && (count($permission->privileges) > 0))) {
212  popupActive("helpmenu", 1, 'folders');
213  }
214  }
215 
216  $action->lay->Set("topid", getDefFld($action));
217  $action->lay->Set("dirid", $dirid);
218  $action->lay->Set("catg", $catg);
219  //----------------------------
220  // sort menu
221  $tsort = array(
222  "-" => array(
223  "said" => "",
224  "satitle" => _("no sort")
225  ) ,
226  "title" => array(
227  "said" => "title",
228  "satitle" => _("doctitle")
229  ) ,
230  "initid" => array(
231  "said" => "initid",
232  "satitle" => _("createdate")
233  ) ,
234  "revdate" => array(
235  "said" => "revdate",
236  "satitle" => _("revdate")
237  )
238  );
239  if ($sfdoc->wid > 0) {
240  $tsort["state"] = array(
241  "said" => "state",
242  "satitle" => _("state")
243  );
244  }
245  $tmsort[] = "sortdesc";
246  while (list($k, $v) = each($tsort)) {
247  $tmsort[$v["said"]] = "sortdoc" . $v["said"];
248  }
249  $lattr = $sfdoc->GetSortAttributes();
250  foreach ($lattr as $k => $a) {
251  $pType = parseType($a->type);
252 
253  if ($pType['type'] == 'docid') {
254  $doctitleAttr = $a->getOption('doctitle');
255  if ($doctitleAttr != '') {
256  $sortAttribute = false;
257  if ($doctitleAttr == 'auto') {
258  $sortAttribute = $sfdoc->getAttribute(sprintf("%s_title", $a->id));
259  } else {
260  $sortAttribute = $sfdoc->getAttribute($doctitleAttr);
261  }
262  if ($sortAttribute === false) {
263  $action->log->error(sprintf("Could not find doctitle attribute '%s' for attribute '%s'", $doctitleAttr, $a->id));
264  continue;
265  }
266  $tsort[$sortAttribute->id] = array(
267  "said" => $sortAttribute->id,
268  "satitle" => sprintf("%s (title)", $a->getLabel())
269  );
270  $tmsort[$sortAttribute->id] = "sortdoc" . $sortAttribute->id;
271  continue;
272  }
273  }
274 
275  $tsort[$a->id] = array(
276  "said" => $a->id,
277  "satitle" => $a->getLabel()
278  );
279  $tmsort[$a->id] = "sortdoc" . $a->id;
280  }
281 
282  $action->lay->set("ukey", getDefUKey($action));
283  // select the current sort
284  $csort = GetHttpVars("sqlorder");
285  if ($csort == "") $csort = getDefUSort($action, "--");
286 
287  if (($csort == '') || ($csort == '--')) {
288  $csort = '-';
289  $cselect = "&bull;";
290  } else if ($csort[0] == '-') {
291  $csort = substr($csort, 1);
292  $cselect = "&uarr;";
293  } else {
294  $cselect = "&darr;";
295  }
296 
297  $action->lay->set("sortby", _("Sort"));
298  foreach ($tsort as $k => $v) {
299  $tsort[$k]["dsort"] = ($csort == $k) ? $cselect : "&nbsp;"; // use puce
300  if ($csort == $k) $action->lay->set("sortby", $v["satitle"] . $cselect);
301  }
302  popupInit("sortmenu", $tmsort);
303  reset($tmsort);
304  while (list($k, $v) = each($tmsort)) {
305  popupActive("sortmenu", 1, $v);
306  }
307  $action->lay->SetBlockData("USORT", $tsort);
308 
309  popupGen(1);
310 }
311 ?>
← centre documentaire © anakeen - published under CC License - Dynacase