Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
family_barmenu.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Viem bar menu for generic application
8  *
9  * @author Anakeen
10  * @version $Id: generic_barmenu.php,v 1.10 2006/02/03 17:03:41 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once "GENERIC/family_defaultmenu.php";
18 // -----------------------------------
20 {
21  $onefamOrigin = $action->getArgument("onefam");
22  $famid = $action->getArgument("famid");
23  $action->parent->addJsRef('lib/jquery/jquery.js');
24  $action->parent->addJsRef('GENERIC:generic_list.js');
25  $packName = 'menubarjs';
26  $action->parent->addJsRef('lib/jquery-ui/devel-src/ui/jquery.ui.core.js', false, $packName);
27  $action->parent->addJsRef('lib/jquery-ui/devel-src/ui/jquery.ui.widget.js', false, $packName);
28  $action->parent->addJsRef('lib/jquery-ui/devel-src/ui/jquery.ui.position.js', false, $packName);
29  $action->parent->addJsRef('lib/jquery-ui/devel-src/ui/jquery.ui.button.js', false, $packName);
30  $action->parent->addJsRef('lib/jquery-ui/devel-src/ui/jquery.ui.menu.js', false, $packName);
31  $action->parent->addJsRef('lib/jquery-ui/devel-src/ui/jquery.ui.menubar.js', false, $packName);
32 
33  $action->parent->addCssRef('lib/jquery-ui/devel-src/themes/base/jquery.ui.all.css');
34  $defaultMenu = family_defaultmenu($action);
35  $menu = getOnefamMenu($onefamOrigin, $famid, $defaultMenu);
36  $action->lay->set("familyMenu", objectMenu2Html($menu, false));
37  $action->lay->set("famid", $action->getArgument("famid"));
38 }
39 
40 function getOnefamMenu($onefam, $famid, $defaultMenu)
41 {
42  if (!$onefam) {
43  return $defaultMenu;
44  }
45  $sql = sprintf("SELECT val from paramv where name = 'ONEFAM_MENU' and appid = (select id from application where name='%s')", pg_escape_string($onefam));
46  simpleQuery('', $sql, $onefamMenu, true, true);
47  if (!$onefamMenu) {
48  return $defaultMenu;
49  }
50  $confOnefam = json_decode($onefamMenu, true);
51  $famName = getNameFromId(getDbAccess() , $famid);
52  if (!isset($confOnefam["families"][$famName])) {
53  return $defaultMenu;
54  }
55  $specMenu = $confOnefam["families"][$famName];
56  if (!$specMenu) return $defaultMenu;
57  $standardMenu = $specMenu["standardMenu"];
58  if ($standardMenu) {
59  // modify standard
60  foreach ($standardMenu as $idMenu => $aMenu) {
61  if ($defaultMenu[$idMenu]) {
62  if ($aMenu["deleted"] == "all") {
63  $defaultMenu[$idMenu]["items"] = array();
64  }
65  if (is_array($aMenu["deleted"])) {
66  foreach ($aMenu["deleted"] as $kMenu) {
67  unset($defaultMenu[$idMenu]["items"][$kMenu]);
68  }
69  }
70  if (isset($aMenu["custom"]) && is_array($aMenu["custom"])) {
71  $defaultMenu[$idMenu]["items"] = array_merge($defaultMenu[$idMenu]["items"], $aMenu["custom"]);
72  }
73  if (count($defaultMenu[$idMenu]["items"]) == 0) {
74  $defaultMenu[$idMenu] = array();
75  }
76  } else {
77  addWarningMsg(sprintf("custom menu : standard menu '%s' not exists", $idMenu));
78  }
79  }
80  }
81  $customMenu = (isset($specMenu["customMenu"]) ? $specMenu["customMenu"] : null);
82  if (is_array($customMenu)) {
83  foreach ($customMenu as $kc => $cMenu) {
84  if (!empty($cMenu["before"])) {
85  $tmpMenu = array();
86  foreach ($defaultMenu as $kd => $dMenu) {
87  if ($kd == $cMenu["before"]) {
88  $tmpMenu[$kc] = $cMenu;
89  }
90  $tmpMenu[$kd] = $dMenu;
91  }
92  $defaultMenu = $tmpMenu;
93  } else {
94  $defaultMenu[$kc] = $cMenu;
95  }
96  }
97  $defaultMenu = array_merge($defaultMenu, $customMenu);
98  }
99  return $defaultMenu;
100 }
101 
102 /**
103  * Convert an array description menu to standard jQuery UI menu def
104  *
105  * @param array $menulist
106  * @param bool $ul with ul
107  * @param int $level
108  * @return string
109  */
110 function objectMenu2Html(array $menulist, $ul = true, $level = 0)
111 {
112  $htmlReturn = '';
113  if ($ul) {
114  $htmlReturn = '<ul>';
115  }
116  foreach ($menulist as $k => $aMenu) {
117  if (!empty($aMenu["items"])) {
118  $attrs = '';
119  foreach ($aMenu as $ki => $item) {
120  if ($ki != "items" && $ki != "label") {
121  $attrs.= sprintf(' %s="%s" ', $ki, $item);
122  }
123  }
124  $label = !empty($aMenu["label"]) ? _($aMenu["label"]) : "";
125  $htmlReturn.= sprintf('<li><a href="#%s"%s>%s</a>', $k, $attrs, mb_ucfirst($label));
126 
127  $htmlReturn.= objectMenu2Html($aMenu["items"], true, $level + 1);
128  } else {
129  $noanchor = (empty($aMenu["url"])) && (empty($aMenu["href"]));
130  $htmlReturn.= "\n<li";
131 
132  $htmlReturn.= " level=\"$level\" ";
133 
134  if ($level == 0) {
135  if (!empty($aMenu["url"])) {
136  $aMenu["href"] = $aMenu["url"];
137  }
138  $htmlReturn.= '><div role="button" class="div-button ui-button-text-only ui-button ui-widget ui-button-text-only ui-menubar-link" ';
139  }
140  if (!$noanchor) {
141  if ($level === 0) {
142  $htmlReturn.= "><a class='ui-button-text' ";
143  }else {
144  $htmlReturn.= "><a";
145  }
146  }
147  foreach ($aMenu as $ki => $item) {
148  if ($ki != "label") {
149  $htmlReturn.= sprintf(' %s="%s" ', $ki, $item);
150  }
151  }
152  $htmlReturn.= '>';
153  if (!empty($aMenu["label"])) {
154  $htmlReturn.= mb_ucfirst(_($aMenu["label"]));
155  }
156 
157  if (!$noanchor) {
158  $htmlReturn.= "</a> ";
159  }
160  if ($level == 0) {
161  $htmlReturn.= '</div>';
162  }
163  }
164  $htmlReturn.= "</li>\n";
165  }
166  if ($ul) {
167  $htmlReturn.= "</ul>\n";
168  }
169  return $htmlReturn;
170 }
global $action
getOnefamMenu($onefam, $famid, $defaultMenu)
addWarningMsg($msg)
Definition: Lib.Common.php:95
family_barmenu(Action &$action)
family_defaultmenu(Action &$action)
mb_ucfirst($s)
Definition: Lib.Common.php:105
getDbAccess()
Definition: Lib.Common.php:368
getNameFromId($dbaccess, $id)
objectMenu2Html(array $menulist, $ul=true, $level=0)
static getArgument($k, $def= '')
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
$packName
Definition: pack.php:56
if(!isset($query[$parms['q']])) if($parms['desc']!= 'desc'&&$parms['desc']!= 'asc') $menu
Definition: pginfo.php:65
← centre documentaire © anakeen