Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
popup_util.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Utilities functions to generate popup menu
8  *
9  * @author Anakeen
10  * @version $Id: popup_util.php,v 1.15 2005/10/07 14:07:53 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/Class.Doc.php");
18 
19 function popupInit($name, $items)
20 {
21  global $menuitems;
22  global $tmenus;
23  global $tsubmenu;
24  // ------------------------------------------------------
25  // definition of popup menu
26  $menuitems[$name] = $items;
27  $tsubmenu[$name] = array();
28  if (count($menuitems[$name]) == 0) {
29  $jsarray = "[]";
30  } else {
31  $jsarray = "[";
32  foreach ($menuitems[$name] as $ki => $imenu) {
33 
34  $jsarray.= '"' . $imenu . '",';
35  global $ {
36  $imenu
37  };
38  $ {
39  $imenu
40  } = 'v' . $ki;
41  $tsubmenu[$name]['v' . $ki] = "";
42  }
43  // replace last comma by ']'
44  $jsarray[mb_strlen($jsarray) - 1] = "]";
45  }
46  $tmenus[$name]["menuitems"] = $jsarray;
47  $tmenus[$name]["name"] = $name;
48  $tmenus[$name]["nbmitem"] = count($menuitems[$name]);
49  $tmenus[$name]["menulabel"] = '["' . implode('","', $tsubmenu[$name]) . '"]';
50  $tmenus[$name]["nbdiv"] = "";
51 }
52 
53 function popupAddItem($name, $imenu)
54 {
55  global $menuitems;
56  global $tmenus;
57  global $tsubmenu;
58  // ------------------------------------------------------
59  // definition of popup menu
60  $menuitems[$name][] = $imenu;
61 
62  $ki = count($menuitems[$name]) - 1;
63 
64  global $
65  {
66  $imenu
67  };
68  $
69  {
70  $imenu
71  } = 'v' . $ki;
72  $tsubmenu[$name]['v' . $ki] = "";
73 
74  $tmenus[$name]["menuitems"] = '["' . implode('","', $menuitems[$name]) . '"]';
75  $tmenus[$name]["nbmitem"] = count($menuitems[$name]);
76  $tmenus[$name]["menulabel"] = '["' . implode('","', $tsubmenu[$name]) . '"]';
77 }
78 function popupInitItem($name, $k)
79 {
80  global $tmenuaccess;
81  global $menuitems;
82 
83  if (!isset($tmenuaccess[$name][$k]["divid"])) {
84  $tmenuaccess[$name][$k]["divid"] = $k;
85 
86  foreach ($menuitems[$name] as $ki => $v) {
87  $tmenuaccess[$name][$k]['v' . $ki] = 2; // invisible
88 
89  }
90  }
91 }
92 
93 function popupSubMenu($name, $nameid, $mlabel)
94 {
95  global $tsubmenu;
96  global $$nameid;
97  $tsubmenu[$name][$$nameid] = $mlabel;
98 }
99 
100 function popupGetSubItems($name, $mlabel)
101 {
102  global $menuitems;
103  global $tmenus;
104  global $tsubmenu;
105 
106  $ti = array();
107  $ki = 0;
108  foreach ($tsubmenu[$name] as $k => $v) {
109  if ($v == $mlabel) {
110  $ti[] = $menuitems[$name][$ki];
111  }
112  $ki++;
113  }
114  return $ti;
115 }
116 function popupActive($name, $k, $nameid)
117 {
118  global $tmenuaccess;
119  global $$nameid;
120  popupInitItem($name, $k);
121  $tmenuaccess[$name][$k][$$nameid] = POPUP_ACTIVE;
122 }
123 
124 function popupInactive($name, $k, $nameid)
125 {
126  global $tmenuaccess;
127  global $$nameid;
128 
129  popupInitItem($name, $k);
130  $tmenuaccess[$name][$k][$$nameid] = POPUP_INACTIVE;
131 }
132 function popupInvisible($name, $k, $nameid)
133 {
134  global $tmenuaccess;
135  global $$nameid;
136 
137  popupInitItem($name, $k);
138  $tmenuaccess[$name][$k][$$nameid] = POPUP_INVISIBLE;
139 }
140 // active if Ctrl Key Pushed
141 function popupCtrlActive($name, $k, $nameid)
142 {
143  global $tmenuaccess;
144  global $$nameid;
145 
146  popupInitItem($name, $k);
147  $tmenuaccess[$name][$k][$$nameid] = POPUP_CTRLACTIVE;
148 }
149 // inactive if Ctrl Key Pushed
150 function popupCtrlInactive($name, $k, $nameid)
151 {
152  global $tmenuaccess;
153  global $$nameid;
154 
155  popupInitItem($name, $k);
156  $tmenuaccess[$name][$k][$$nameid] = POPUP_CTRLINACTIVE;
157 }
158 function popupGetAccessItem($name, $k, $nameid)
159 {
160  global $tmenuaccess;
161  global $$nameid;
162  return ($tmenuaccess[$name][$k][$$nameid]);
163 }
164 
165 function vcompare($a, $b)
166 {
167  $na = intval(substr($a, 1));
168  $nb = intval(substr($b, 1));
169 
170  if ($na == $nb) return 0;
171  return ($na < $nb) ? -1 : 1;
172 }
173 function popupNoCtrlKey()
174 {
175  global $tmenuaccess;
176  global $tsubmenu;
177  if (isset($tmenuaccess)) {
178  $kv = 0; // index for item
179  foreach ($tmenuaccess as $name => $v) foreach ($v as $ki => $vi) foreach ($vi as $kj => $vj) {
180  if ($vj == 3) {
181  $tmenuaccess[$name][$ki][$kj] = 1;
182  if ($tsubmenu[$name][$kj] == "") $tsubmenu[$name][$kj] = "ctrlkey";
183  }
184  }
185  }
186 }
187 
188 function popupGetAccess($popname)
189 {
190  global $tmenuaccess;
191  global $menuitems;
192 
193  $ta = $tmenuaccess[$popname][1];
194 
195  array_shift($ta);
196  $ti = $menuitems[$popname];
197  $tu = array();
198  foreach ($ta as $v) {
199  $tu[current($ti) ] = $v;
200  next($ti);
201  }
202  return $tu;
203 }
204 
205 function popupSetAccess($popname, $ta)
206 {
207  global $tmenuaccess;
208  global $menuitems;
209 
210  $ti = $menuitems[$popname];
211  foreach ($ta as $i => $a) {
212  $kt = array_keys($ti, $i);
213  if (count($kt) == 1) {
214  $k = $kt[0];
215  $tmenuaccess[$popname][1]["v$k"] = $a;
216  }
217  }
218 }
219 function popupGen($kdiv = "nothing")
220 {
221  global $tmenuaccess;
222  global $menuitems;
223  global $tmenus;
224  /*
225  * @var Action $action
226  */
227  global $action;
228  static $first = 1;
229  global $tcmenus; // closeAll menu
230  global $tsubmenu;
231 
232  if ($first) {
233  // static part
234  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/DHTMLapi.js");
235  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/geometry.js");
236  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/FDL/Layout/common.js");
237  $action->parent->AddJsRef($action->Getparam("CORE_PUBURL") . "/FDL/Layout/popupfunc.js");
238  // css pour popup
239  // $cssfile=DEFAULT_PUBDIR ."/FDL/Layout/popup.css";
240  // $csslay = new Layout($cssfile,$action);
241  // $action->parent->AddCssCode($csslay->gen());
242  $action->parent->AddCssRef("FDL:POPUP.CSS", true);
243  $first = 0;
244  }
245  $lpopup = new Layout(DEFAULT_PUBDIR . "/FDL/Layout/popup.js", $action);
246  if (isset($tmenuaccess)) {
247  $kv = 0; // index for item
248  $tma = array();
249  foreach ($tmenuaccess as $name => $v2) {
250  $nbdiv = 0;
251  foreach ($v2 as $k => $v) {
252  uksort($v, 'vcompare');
253 
254  $tma[$kv]["vmenuitems"] = "[";
255  foreach ($v as $ki => $vi) {
256  if ($ki[0] == 'v') // its a value
257  $tma[$kv]["vmenuitems"].= "" . $vi . ",";
258  }
259  // replace last comma by ']'
260  $tma[$kv]["vmenuitems"][mb_strlen($tma[$kv]["vmenuitems"]) - 1] = "]";
261 
262  $tma[$kv]["name"] = $name;
263  $tma[$kv]["divid"] = $v["divid"];
264  $kv++;
265  $nbdiv++;
266  }
267  $tmenus[$name]["nbdiv"] = $nbdiv;
268  $tmenus[$name]["menulabel"] = '["' . implode('","', $tsubmenu[$name]) . '"]';
269  }
270  $lpopup->SetBlockData("MENUACCESS", $tma);
271  $lpopup->SetBlockData("MENUS", $tmenus);
272  if (isset($tcmenus)) $tcmenus = array_merge($tcmenus, $tmenus);
273  else $tcmenus = $tmenus;
274  foreach ($tsubmenu as $kl => $vl) foreach ($vl as $sm) if ($sm != "") $tcmenus[$sm]["name"] = $sm;
275  $lpopup->SetBlockData("CMENUS", $tcmenus);
276  }
277  $action->parent->AddJsCode($lpopup->gen());
278 
279  if ($action->Read("navigator", "") == "EXPLORER") $action->lay->Set("divpos", "absolute");
280  else $action->lay->Set("divpos", "fixed");
281 
282  $tmenus = array(); // re-init (for next time)
283  $tmenuaccess = array();
284  // $menuitems[$name] = array();
285  unset($tmenus);
286  unset($tmenusaccess);
287  unset($tsubmenu);
288  unset($tmenuitems);
289 }
290 
291 function popupAddGen($kdiv = "nothing")
292 {
293  global $tmenuaccess;
294  global $menuitems;
295  global $tmenus;
296  /*
297  * @var Action $action
298  */
299  global $action;
300  global $tsubmenu;
301 
302  $lpopup = new Layout(DEFAULT_PUBDIR . "/FDL/Layout/popupadd.js");
303  if (isset($tmenuaccess)) {
304  reset($tmenuaccess);
305  $kv = 0; // index for item
306  $tma = array();
307  foreach ($tmenuaccess as $name => $v2) {
308  $nbdiv = 0;
309  foreach ($v2 as $k => $v) {
310  uksort($v, 'vcompare');
311 
312  $tma[$kv]["vmenuitems"] = "[";
313  foreach ($v as $ki => $vi) {
314  if ($ki[0] == 'v') // its a value
315  $tma[$kv]["vmenuitems"].= "" . $vi . ",";
316  }
317  // replace last comma by ']'
318  $tma[$kv]["vmenuitems"][mb_strlen($tma[$kv]["vmenuitems"]) - 1] = "]";
319 
320  $tma[$kv]["name"] = $name;
321  $tma[$kv]["divid"] = $v["divid"];
322  $kv++;
323  $nbdiv++;
324  }
325  $tmenus[$name]["nbdiv"] = $nbdiv;
326  $tmenus[$name]["menulabel"] = '["' . implode('","', $tsubmenu[$name]) . '"]';
327  }
328 
329  $lpopup->SetBlockData("ADDMENUACCESS", $tma);
330  $lpopup->SetBlockData("ADDMENUS", $tmenus);
331  }
332  $action->parent->AddJsCode($lpopup->gen());
333 
334  $tmenus = array(); // re-init (for next time)
335  $tmenuaccess = array();
336  // $menuitems[$name] = array();
337  unset($tmenus);
338  unset($tmenusaccess);
339  unset($tsubmenu);
340  unset($tmenuitems);
341 }
Layout is a template generator.
global $action
const POPUP_CTRLINACTIVE
Definition: Class.Doc.php:43
const POPUP_INVISIBLE
Definition: Class.Doc.php:44
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
const POPUP_CTRLACTIVE
Definition: Class.Doc.php:42
$sm
Definition: setStyle.php:373
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
const POPUP_INACTIVE
Definition: Class.Doc.php:40
const POPUP_ACTIVE
Definition: Class.Doc.php:41
← centre documentaire © anakeen