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