00001 <?php 00002 require_once TM_PATH . 'constants.php'; 00003 require_once TM_PATH . 'juelich/JuelichGlobals.php'; 00004 00014 class JuelichMenu { 00015 var $content = ''; 00016 var $l10n = ''; 00017 var $level1 = 0; 00018 var $level2 = 0; 00019 var $level3 = 0; 00020 var $nbsp = 0; 00021 var $sqlMenu = "SELECT menu.menu_id, m_parent, group_str, m_class, m_text, pfad_id FROM menu LEFT JOIN menu_l10n USING(menu_id) WHERE m_parent = %d AND l10n_id = %d ORDER BY m_sort"; 00034 function getMenu($l10n = L_DEUTSCH, 00035 $group0 = '', 00036 $group1 = '', 00037 $group2 = '') { 00038 $this->l10n = $l10n; 00039 if ($group0 != '' && $group0 != 'text') { 00040 $this->level1 = $this->getMenuId($group0); 00041 } 00042 if ($group1 != '' && $group0 != '') { 00043 $this->level2 = $this->getMenuId($group0 . '-' . $group1); 00044 } 00045 if ($group2 != '' && $group1 != '') { 00046 $this->level3 = $this->getMenuId($group0 00047 . '-' . $group1 00048 . '-' . $group2); 00049 } 00050 $this->makeMenu(); 00051 return $this->content; 00052 } 00053 00061 function makeMenu($parent = 0) { 00062 $sql = sprintf($this->sqlMenu, 00063 $parent, 00064 $this->l10n 00065 ); 00066 $menuData = array(); 00067 $db =& getDbReaderInstance(); 00068 $db->getAllRows($sql, $menuData); 00069 00070 foreach ($menuData as $row) { 00071 if ($row['group_str'] == 'break') { 00072 $this->content .= "<tr><td></td><td> </td><td></td></tr>\n"; 00073 continue; 00074 } 00075 $class = $row['m_class']; 00076 if ($row['menu_id'] == $this->level1 && $this->level2 == 0) { 00077 $class .= '-aktiv'; 00078 } 00079 elseif ($row['menu_id'] == $this->level2 && $this->level3 == 0) { 00080 $class .= '-aktiv'; 00081 } 00082 elseif ($row['menu_id'] == $this->level3) { 00083 $class .= '-aktiv'; 00084 } 00085 00086 if ($this->level1 == $parent && 00087 $parent != 0 && 00088 $this->level2 == 0 && 00089 $class != 'menu-aktiv' 00090 ) { 00091 $class .= '-gruppe'; 00092 } 00093 00094 if ($this->level2 == $parent && 00095 $parent != 0 && 00096 $class != 'menu-aktiv' 00097 ) { 00098 $class .= '-gruppe'; 00099 } 00100 00101 $nbsp = ''; 00102 switch ($this->nbsp) { 00103 case 1: 00104 $nbsp = ' '; 00105 break; 00106 case 2: 00107 $nbsp = ' '; 00108 break; 00109 default: 00110 break; 00111 } 00112 if ($row['m_text'] != '') { 00113 $this->content .= '<tr><td></td><td>' 00114 . $nbsp 00115 . $this->getLinkText($row['m_text'], $row['pfad_id'], $class) 00116 . "</td><td></td></tr>\n"; 00117 } 00118 if ($row['menu_id'] == $this->level1) { 00119 $this->nbsp = 1; 00120 $this->makeMenu($row['menu_id']); 00121 $this->nbsp = 0; 00122 } 00123 if ($row['menu_id'] == $this->level2) { 00124 $this->nbsp = 2; 00125 $this->makeMenu($row['menu_id']); 00126 $this->nbsp = 1; 00127 } 00128 } 00129 return; 00130 } 00131 00139 function getMenuId($idString) { 00140 $sqlPrep = "SELECT menu_id " 00141 . "FROM menu " 00142 . "WHERE group_str = '%s'"; 00143 $sql = sprintf($sqlPrep, 00144 $idString 00145 ); 00146 $db =& getDbReaderInstance(); 00147 $id = $db->getOneValue($sql); 00148 if (empty($id)) { 00149 include_once TM_PATH . 'juelich/web/JuelichError.php'; 00150 $error = new JuelichError; 00151 $error->printError(4, 'JuelichMenu: Ungültiger group_str: ' . $idString); 00152 exit(); 00153 } 00154 return $id; 00155 } 00156 00166 function getLinkText($text, $path, $class = 'menu') { 00167 $extern = false; 00168 $href = ''; 00169 00170 if ($path[0] == '/') { 00171 $extern = true; 00172 } 00173 00174 if (!$extern) { 00175 $href = '/site/' 00176 . str_replace('-', '/', $path); 00177 if (strpos($path, '.html') <= 0) { 00178 $href .= '/'; 00179 } 00180 } 00181 else { 00182 $href = $path; 00183 } 00184 00185 $linkText = '<a class="' 00186 . $class 00187 . '" href="' 00188 . $href 00189 . '"><b>' 00190 . $text 00191 . '</b></a>'; 00192 return $linkText; 00193 } 00194 } 00195 00196 ?>