00001 <?PHP
00026 class HTMLMenus extends MetaObject implements iUIControl
00027 {
00028 protected $m_MenuItemsXml = null;
00029
00036 function __construct(&$xmlArr)
00037 {
00038 $this->readMetadata($xmlArr);
00039 BizSystem::clientProxy()->appendStyles("menu", "menu.css");
00040 BizSystem::clientProxy()->appendScripts("menu-ie-js", '<!--[if gte IE 5.5]>
00041 <script language="JavaScript" src="".Resource::getJsUrl()."/ie_menu.js" type="text/JavaScript"></script>
00042 <![endif]-->', false);
00043 }
00044
00051 protected function readMetadata(&$xmlArr)
00052 {
00053 $this->m_Name = $xmlArr["MENU"]["ATTRIBUTES"]["NAME"];
00054 $this->m_Package = $xmlArr["MENU"]["ATTRIBUTES"]["PACKAGE"];
00055 $this->m_Class = $xmlArr["MENU"]["ATTRIBUTES"]["CLASS"];
00056 $this->m_MenuItemsXml = $xmlArr["MENU"]["MENUITEM"];
00057 }
00058
00064 public function render()
00065 {
00066
00067 $sHTML = "<ul id='navmenu'>\n";
00068 $sHTML .= $this->renderMenuItems($this->m_MenuItemsXml);
00069 $sHTML .= "</ul>";
00070 return $sHTML;
00071 }
00072
00079 protected function renderMenuItems(&$menuItemArray)
00080 {
00081 $sHTML = "";
00082 if (isset($menuItemArray["ATTRIBUTES"]))
00083 {
00084 $sHTML .= $this->renderSingleMenuItem($menuItemArray);
00085 }
00086 else
00087 {
00088 foreach ($menuItemArray as $menuItem)
00089 {
00090 $sHTML .= $this->renderSingleMenuItem($menuItem);
00091 }
00092 }
00093 return $sHTML;
00094 }
00095
00102 protected function renderSingleMenuItem(&$menuItem)
00103 {
00104 $profile = BizSystem::getUserProfile();
00105 $svcobj = BizSystem::getService(ACCESS_SERVICE);
00106 $role = isset($profile["ROLE"]) ? $profile["ROLE"] : null;
00107
00108 if (array_key_exists('URL', $menuItem["ATTRIBUTES"]))
00109 {
00110 $url = $menuItem["ATTRIBUTES"]["URL"];
00111 }
00112 elseif (array_key_exists('VIEW', $menuItem["ATTRIBUTES"]))
00113 {
00114 $view = $menuItem["ATTRIBUTES"]["VIEW"];
00115
00116
00117 if ($svcobj->allowViewAccess($view, $role))
00118 {
00119 $url="javascript:GoToView('".$view."')";
00120 }
00121 else
00122 {
00123 return '';
00124 }
00125 }
00126
00127 $caption = $this->translate($menuItem["ATTRIBUTES"]["CAPTION"]);
00128 $target = $menuItem["ATTRIBUTES"]["TARGET"];
00129 $icon = $menuItem["ATTRIBUTES"]["ICON"];
00130 $img = $icon ? "<img src='".Resource::getImageUrl()."/$icon' class=menu_img> " : "";
00131
00132 if ($view)
00133 $url="javascript:GoToView('".$view."')";
00134
00135 if ($target)
00136 $sHTML .= "<li><a href=\"".$url."\" target='$target'>$img".$caption."</a>";
00137 else
00138 $sHTML .= "<li><a href=\"".$url."\">$img".$caption."</a>";
00139 if ($menuItem["MENUITEM"])
00140 {
00141 $sHTML .= "\n<ul>\n";
00142 $sHTML .= $this->renderMenuItems($menuItem["MENUITEM"]);
00143 $sHTML .= "</ul>";
00144 }
00145 $sHTML .= "</li>\n";
00146
00147 return $sHTML;
00148 }
00149
00155 public function rerender()
00156 {
00157 return $this->render();
00158 }
00159
00160 protected function translate($caption)
00161 {
00162 $module = $this->getModuleName($this->m_Name);
00163 return I18n::t($caption, $this->getTransKey(caption), $module);
00164 }
00165
00166 protected function getTransKey($name)
00167 {
00168 $shortFormName = substr($this->m_Name,intval(strrpos($this->m_Name,'.'))+1);
00169 return strtoupper($shortFormName.'_'.$name);
00170 }
00171 }
00172
00173 ?>