| Conditions | 44 |
| Paths | 48 |
| Total Lines | 215 |
| Code Lines | 136 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 140 | public function showmenu($mode, $moredata = null) |
||
| 141 | { |
||
| 142 | global $conf, $langs, $user; |
||
| 143 | |||
| 144 | require_once DOL_DOCUMENT_ROOT . '/core/menus/standard/auguria.lib.php'; |
||
| 145 | |||
| 146 | if ($this->type_user == 1) { |
||
| 147 | $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED = 1; |
||
| 148 | $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED = 1; |
||
| 149 | } |
||
| 150 | |||
| 151 | require_once DOL_DOCUMENT_ROOT . '/core/class/menu.class.php'; |
||
| 152 | $this->menu = new Menu(); |
||
| 153 | |||
| 154 | if (!getDolGlobalString('MAIN_MENU_INVERT')) { |
||
| 155 | if ($mode == 'top') { |
||
| 156 | print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode); |
||
| 157 | } |
||
| 158 | if ($mode == 'left') { |
||
| 159 | print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata); |
||
|
|
|||
| 160 | } |
||
| 161 | } else { |
||
| 162 | $conf->global->MAIN_SHOW_LOGO = 0; |
||
| 163 | if ($mode == 'top') { |
||
| 164 | print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0); |
||
| 165 | } |
||
| 166 | if ($mode == 'left') { |
||
| 167 | print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode); |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | if ($mode == 'topnb') { |
||
| 172 | print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); |
||
| 173 | return $this->menu->getNbOfVisibleMenuEntries(); |
||
| 174 | } |
||
| 175 | |||
| 176 | if ($mode == 'jmobile') { // Used to get menu in xml ul/li |
||
| 177 | print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); |
||
| 178 | |||
| 179 | // $this->menu->liste is top menu |
||
| 180 | //var_dump($this->menu->liste);exit; |
||
| 181 | $lastlevel = []; |
||
| 182 | $showmenu = true; // Is current menu shown - define here to keep static code checker happy |
||
| 183 | print '<!-- Generate menu list from menu handler ' . $this->name . ' -->' . "\n"; |
||
| 184 | foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu' |
||
| 185 | print '<ul class="ulmenu" data-inset="true">'; |
||
| 186 | print '<li class="lilevel0">'; |
||
| 187 | if ($val['enabled'] == 1) { |
||
| 188 | $substitarray = ['__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user]; |
||
| 189 | $substitarray['__USERID__'] = $user->id; // For backward compatibility |
||
| 190 | $val['url'] = make_substitutions($val['url'], $substitarray); |
||
| 191 | |||
| 192 | $relurl = dol_buildpath($val['url'], 1); |
||
| 193 | $canonurl = preg_replace('/\?.*$/', '', $val['url']); |
||
| 194 | |||
| 195 | print '<a class="alilevel0" href="#">'; |
||
| 196 | |||
| 197 | // Add font-awesome |
||
| 198 | if ($val['level'] == 0 && !empty($val['prefix'])) { |
||
| 199 | print str_replace('<span class="', '<span class="paddingright pictofixedwidth ', $val['prefix']); |
||
| 200 | } |
||
| 201 | |||
| 202 | print $val['titre']; |
||
| 203 | print '</a>' . "\n"; |
||
| 204 | |||
| 205 | // Search submenu for this mainmenu entry |
||
| 206 | $tmpmainmenu = $val['mainmenu']; |
||
| 207 | $tmpleftmenu = 'all'; |
||
| 208 | $submenu = new Menu(); |
||
| 209 | print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $submenu, 1, $tmpmainmenu, $tmpleftmenu); |
||
| 210 | if (!empty($submenu->liste[0]['url'])) { |
||
| 211 | $nexturl = dol_buildpath($submenu->liste[0]['url'], 1); |
||
| 212 | } else { |
||
| 213 | $nexturl = ''; |
||
| 214 | } |
||
| 215 | |||
| 216 | $canonrelurl = preg_replace('/\?.*$/', '', $relurl); |
||
| 217 | $canonnexturl = preg_replace('/\?.*$/', '', $nexturl); |
||
| 218 | //var_dump($canonrelurl); |
||
| 219 | //var_dump($canonnexturl); |
||
| 220 | print '<ul>' . "\n"; |
||
| 221 | if ( |
||
| 222 | ($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], ['tools'])) |
||
| 223 | || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false) |
||
| 224 | ) { |
||
| 225 | // We add sub entry |
||
| 226 | print str_pad('', 1) . '<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic |
||
| 227 | print '<a href="' . $relurl . '">'; |
||
| 228 | |||
| 229 | if ($val['level'] == 0) { |
||
| 230 | print '<span class="fas fa-home fa-fw paddingright pictofixedwidth" aria-hidden="true"></span>'; |
||
| 231 | } |
||
| 232 | |||
| 233 | if ($langs->trans(ucfirst($val['mainmenu']) . "Dashboard") == ucfirst($val['mainmenu']) . "Dashboard") { // No translation |
||
| 234 | if (in_array($val['mainmenu'], ['cashdesk', 'externalsite', 'website', 'collab', 'takepos'])) { |
||
| 235 | print $langs->trans("Access"); |
||
| 236 | } else { |
||
| 237 | print $langs->trans("Dashboard"); |
||
| 238 | } |
||
| 239 | } else { |
||
| 240 | print $langs->trans(ucfirst($val['mainmenu']) . "Dashboard"); |
||
| 241 | } |
||
| 242 | print '</a>'; |
||
| 243 | print '</li>' . "\n"; |
||
| 244 | } |
||
| 245 | |||
| 246 | if ($val['level'] == 0) { |
||
| 247 | if ($val['enabled']) { |
||
| 248 | $lastlevel[0] = 'enabled'; |
||
| 249 | } elseif ($showmenu) { // Not enabled but visible (so greyed) |
||
| 250 | $lastlevel[0] = 'greyed'; |
||
| 251 | } else { |
||
| 252 | $lastlevel[0] = 'hidden'; |
||
| 253 | } |
||
| 254 | } |
||
| 255 | |||
| 256 | $lastlevel2 = []; |
||
| 257 | foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu' |
||
| 258 | $showmenu = true; |
||
| 259 | if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($val2['enabled'])) { |
||
| 260 | $showmenu = false; |
||
| 261 | } |
||
| 262 | |||
| 263 | // If at least one parent is not enabled, we do not show any menu of all children |
||
| 264 | if ($val2['level'] > 0) { |
||
| 265 | $levelcursor = $val2['level'] - 1; |
||
| 266 | while ($levelcursor >= 0) { |
||
| 267 | if ($lastlevel2[$levelcursor] != 'enabled') { |
||
| 268 | $showmenu = false; |
||
| 269 | } |
||
| 270 | $levelcursor--; |
||
| 271 | } |
||
| 272 | } |
||
| 273 | |||
| 274 | if ($showmenu) { // Visible (option to hide when not allowed is off or allowed) |
||
| 275 | $substitarray = ['__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user]; |
||
| 276 | $substitarray['__USERID__'] = $user->id; // For backward compatibility |
||
| 277 | $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__ |
||
| 278 | |||
| 279 | if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) { |
||
| 280 | $relurl2 = dol_buildpath($val2['url'], 1); |
||
| 281 | } else { |
||
| 282 | $relurl2 = $val2['url']; |
||
| 283 | } |
||
| 284 | $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']); |
||
| 285 | //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']); |
||
| 286 | if (in_array($canonurl2, ['/admin/index.php', '/admin/tools/index.php', '/core/tools.php'])) { |
||
| 287 | $relurl2 = ''; |
||
| 288 | } |
||
| 289 | |||
| 290 | $disabled = ''; |
||
| 291 | if (!$val2['enabled']) { |
||
| 292 | $disabled = " vsmenudisabled"; |
||
| 293 | } |
||
| 294 | |||
| 295 | print str_pad('', $val2['level'] + 1); |
||
| 296 | print '<li class="lilevel' . ($val2['level'] + 1); |
||
| 297 | if ($val2['level'] == 0) { |
||
| 298 | print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic |
||
| 299 | } |
||
| 300 | print $disabled . '">'; // ui-btn to highlight on clic |
||
| 301 | if ($relurl2) { |
||
| 302 | if ($val2['enabled']) { // Allowed |
||
| 303 | print '<a href="' . $relurl2 . '"'; |
||
| 304 | //print ' data-ajax="false"'; |
||
| 305 | print '>'; |
||
| 306 | $lastlevel2[$val2['level']] = 'enabled'; |
||
| 307 | } else { // Not allowed but visible (greyed) |
||
| 308 | print '<a href="#" class="vsmenudisabled">'; |
||
| 309 | $lastlevel2[$val2['level']] = 'greyed'; |
||
| 310 | } |
||
| 311 | } else { |
||
| 312 | if ($val2['enabled']) { // Allowed |
||
| 313 | $lastlevel2[$val2['level']] = 'enabled'; |
||
| 314 | } else { |
||
| 315 | $lastlevel2[$val2['level']] = 'greyed'; |
||
| 316 | } |
||
| 317 | } |
||
| 318 | |||
| 319 | if ($val2['level'] == 0 && !empty($val2['prefix'])) { |
||
| 320 | print $val2['prefix']; |
||
| 321 | } else { |
||
| 322 | print '<i class="fa fa-does-not-exists fa-fw paddingright pictofixedwidth"></i>'; |
||
| 323 | } |
||
| 324 | |||
| 325 | print $val2['titre']; |
||
| 326 | if ($relurl2) { |
||
| 327 | print '</a>'; |
||
| 328 | } |
||
| 329 | print '</li>' . "\n"; |
||
| 330 | } |
||
| 331 | } |
||
| 332 | //var_dump($submenu); |
||
| 333 | print '</ul>'; |
||
| 334 | } |
||
| 335 | if ($val['enabled'] == 2) { |
||
| 336 | print '<span class="spanlilevel0 vsmenudisabled">'; |
||
| 337 | |||
| 338 | // Add font-awesome |
||
| 339 | if ($val['level'] == 0 && !empty($val['prefix'])) { |
||
| 340 | print $val['prefix']; |
||
| 341 | } |
||
| 342 | |||
| 343 | print $val['titre']; |
||
| 344 | print '</span>'; |
||
| 345 | } |
||
| 346 | print '</li>'; |
||
| 347 | print '</ul>' . "\n"; |
||
| 348 | } |
||
| 349 | } |
||
| 350 | |||
| 351 | unset($this->menu); |
||
| 352 | |||
| 353 | //print 'xx'.$mode; |
||
| 354 | return 0; |
||
| 355 | } |
||
| 357 |