Qual: Still work onto menu management rewrite.

This commit is contained in:
Laurent Destailleur 2013-02-24 21:16:36 +01:00
parent 7238c5156e
commit b61c576343
8 changed files with 1175 additions and 1129 deletions

View File

@ -385,20 +385,17 @@ class Menubase
*/ */
function menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) function menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
{ {
global $langs, $user, $conf; global $langs, $user, $conf; // To export to dol_eval function
global $mainmenu,$leftmenu; // To export to dol_eval function global $mainmenu,$leftmenu; // To export to dol_eval function
$mainmenu=$mymainmenu; // To export to dol_eval function $mainmenu=$mymainmenu; // To export to dol_eval function
$leftmenu=$myleftmenu; // To export to dol_eval function $leftmenu=$myleftmenu; // To export to dol_eval function
$newTabMenu=array(); $newTabMenu=array();
if (is_array($tabMenu))
{
foreach($tabMenu as $val) foreach($tabMenu as $val)
{ {
if ($val['type']=='top') $newTabMenu[]=$val; if ($val['type']=='top') $newTabMenu[]=$val;
} }
}
return $newTabMenu; return $newTabMenu;
} }
@ -411,7 +408,7 @@ class Menubase
* @param string $myleftmenu Value for leftmenu to filter menu to load (always '') * @param string $myleftmenu Value for leftmenu to filter menu to load (always '')
* @param int $type_user 0=Menu for backoffice, 1=Menu for front office * @param int $type_user 0=Menu for backoffice, 1=Menu for front office
* @param string $menu_handler Filter on name of menu_handler used (auguria, eldy...) * @param string $menu_handler Filter on name of menu_handler used (auguria, eldy...)
* @param array &$tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) * @param array &$tabMenu Array with menu entries already loaded
* @return array Menu array for particular mainmenu value or full tabArray * @return array Menu array for particular mainmenu value or full tabArray
*/ */
function menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) function menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
@ -419,14 +416,10 @@ class Menubase
global $langs, $user, $conf; // To export to dol_eval function global $langs, $user, $conf; // To export to dol_eval function
global $mainmenu,$leftmenu; // To export to dol_eval function global $mainmenu,$leftmenu; // To export to dol_eval function
// We initialize newmenu with first already found menu entries
$this->newmenu = $newmenu;
$mainmenu=$mymainmenu; // To export to dol_eval function $mainmenu=$mymainmenu; // To export to dol_eval function
$leftmenu=$myleftmenu; // To export to dol_eval function $leftmenu=$myleftmenu; // To export to dol_eval function
if (is_array($tabMenu)) // Detect what is top mainmenu id
{
$menutopid=''; $menutopid='';
foreach($tabMenu as $key => $val) foreach($tabMenu as $key => $val)
{ {
@ -438,6 +431,9 @@ class Menubase
} }
} }
// We initialize newmenu with first already found menu entries
$this->newmenu = $newmenu;
// Now edit this->newmenu->list to add entries found into tabMenu that are childs of mainmenu claimed, using the fk_menu link (old method) // Now edit this->newmenu->list to add entries found into tabMenu that are childs of mainmenu claimed, using the fk_menu link (old method)
$this->recur($tabMenu, $menutopid, 1); $this->recur($tabMenu, $menutopid, 1);
@ -485,7 +481,6 @@ class Menubase
} }
} }
} }
}
return $this->newmenu; return $this->newmenu;
} }

View File

@ -51,12 +51,47 @@ $left=($langs->trans("DIRECTION")=='rtl'?'right':'left');
*/ */
// URL http://mydolibarr/core/getmenu_jmobime?mainmenu=mainmenu&leftmenu=leftmenu can be used for tests // URL http://mydolibarr/core/getmenu_jmobime?mainmenu=mainmenu&leftmenu=leftmenu can be used for tests
$arrayofjs=array('/includes/jquery/plugins/mobile/jquery.mobile-latest.min.js');
$arrayofcss=array('/includes/jquery/plugins/mobile/jquery.mobile-latest.min.css');
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
print '<body>'."\n"; print '<body>'."\n";
print 'zzz'."\n"; if (empty($user->societe_id)) // If internal user or not defined
{
$conf->standard_menu=(empty($conf->global->MAIN_MENU_STANDARD_FORCED)?(empty($conf->global->MAIN_MENU_STANDARD)?'eldy_menu.php':$conf->global->MAIN_MENU_STANDARD):$conf->global->MAIN_MENU_STANDARD_FORCED);
$conf->smart_menu=(empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?(empty($conf->global->MAIN_MENU_SMARTPHONE)?'smartphone_menu.php':$conf->global->MAIN_MENU_SMARTPHONE):$conf->global->MAIN_MENU_SMARTPHONE_FORCED);
}
else // If external user
{
$conf->standard_menu=(empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?(empty($conf->global->MAIN_MENUFRONT_STANDARD)?'eldy_menu.php':$conf->global->MAIN_MENUFRONT_STANDARD):$conf->global->MAIN_MENUFRONT_STANDARD_FORCED);
$conf->smart_menu=(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE)?'smartphone_menu.php':$conf->global->MAIN_MENUFRONT_SMARTPHONE):$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED);
}
// Load the menu manager (only if not already done)
$file_menu=empty($conf->browser->phone)?$conf->standard_menu:$conf->smart_menu;
if (GETPOST('menu')) $file_menu=GETPOST('menu'); // example: menu=eldy_menu.php
if (! class_exists('MenuManager'))
{
$menufound=0;
$dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']);
foreach($dirmenus as $dirmenu)
{
$menufound=dol_include_once($dirmenu."standard/".$file_menu);
if ($menufound) break;
}
if (! $menufound) // If failed to include, we try with standard
{
dol_syslog("You define a menu manager '".$file_menu."' that can not be loaded.", LOG_WARNING);
$file_menu='eldy_menu.php';
include_once DOL_DOCUMENT_ROOT."/core/menus/standard/".$file_menu;
}
}
$menumanager = new MenuManager($db, empty($user->societe_id)?0:1);
$menumanager->showmenu('jmobile');
print '</body></html>'."\n"; print '</body></html>'."\n";
$db->close();
?> ?>

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2010-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -55,7 +55,6 @@ function print_auguria_menu($db,$atarget,$type_user,&$tabMenu)
$idsel=(empty($newTabMenu[$i]['mainmenu'])?'none':$newTabMenu[$i]['mainmenu']); $idsel=(empty($newTabMenu[$i]['mainmenu'])?'none':$newTabMenu[$i]['mainmenu']);
$showmode=dol_auguria_showmenu($type_user,$newTabMenu[$i],$listofmodulesforexternal); $showmode=dol_auguria_showmenu($type_user,$newTabMenu[$i],$listofmodulesforexternal);
if ($showmode == 1) if ($showmode == 1)
{ {
// Define url // Define url
@ -220,11 +219,10 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM
if (is_array($menu_array_before)) $menu_array=array_merge($menu_array_before, $menu_array); if (is_array($menu_array_before)) $menu_array=array_merge($menu_array_before, $menu_array);
if (is_array($menu_array_after)) $menu_array=array_merge($menu_array, $menu_array_after); if (is_array($menu_array_after)) $menu_array=array_merge($menu_array, $menu_array_after);
//var_dump($menu_array);exit; //var_dump($menu_array);exit;
if (! is_array($menu_array)) return 0;
// Show menu // Show menu
$alt=0; $alt=0;
if (is_array($menu_array))
{
$num=count($menu_array); $num=count($menu_array);
for ($i = 0; $i < $num; $i++) for ($i = 0; $i < $num; $i++)
{ {
@ -306,7 +304,6 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM
print "</div><!-- end blockvmenu pair/impair -->\n"; print "</div><!-- end blockvmenu pair/impair -->\n";
} }
} }
}
return count($menu_array); return count($menu_array);
} }
@ -332,7 +329,9 @@ function dol_auguria_showmenu($type_user, &$menuentry, &$listofmodulesforexterna
$found=0; $found=0;
foreach($tmploops as $tmploop) foreach($tmploops as $tmploop)
{ {
if (in_array($tmploop, $listofmodulesforexternal)) { $found++; break; } if (in_array($tmploop, $listofmodulesforexternal)) {
$found++; break;
}
} }
if (! $found) return 0; // Entry is for menus all excluded to external users if (! $found) return 0; // Entry is for menus all excluded to external users
} }

View File

@ -126,9 +126,15 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu)
$classname = 'class="tmenu"'; $classname = 'class="tmenu"';
} }
$chaine=""; $chaine="";
if (! empty($conf->product->enabled)) { $chaine.=$langs->trans("Products"); } if (! empty($conf->product->enabled)) {
if (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) { $chaine.="/"; } $chaine.=$langs->trans("Products");
if (! empty($conf->service->enabled)) { $chaine.=$langs->trans("Services"); } }
if (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) {
$chaine.="/";
}
if (! empty($conf->service->enabled)) {
$chaine.=$langs->trans("Services");
}
$idsel='products'; $idsel='products';
if ($showmode == 1) if ($showmode == 1)
@ -449,7 +455,6 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu)
$idsel=(empty($newTabMenu[$i]['mainmenu'])?'none':$newTabMenu[$i]['mainmenu']); $idsel=(empty($newTabMenu[$i]['mainmenu'])?'none':$newTabMenu[$i]['mainmenu']);
$showmode=dol_eldy_showmenu($type_user,$newTabMenu[$i],$listofmodulesforexternal); $showmode=dol_eldy_showmenu($type_user,$newTabMenu[$i],$listofmodulesforexternal);
if ($showmode == 1) if ($showmode == 1)
{ {
if (preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url'])) if (preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url']))
@ -603,7 +608,6 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
*/ */
if ($mainmenu) if ($mainmenu)
{ {
/* /*
* Menu HOME * Menu HOME
*/ */
@ -1338,11 +1342,10 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
if (is_array($menu_array_before)) $menu_array=array_merge($menu_array_before, $menu_array); if (is_array($menu_array_before)) $menu_array=array_merge($menu_array_before, $menu_array);
if (is_array($menu_array_after)) $menu_array=array_merge($menu_array, $menu_array_after); if (is_array($menu_array_after)) $menu_array=array_merge($menu_array, $menu_array_after);
//var_dump($menu_array);exit; //var_dump($menu_array);exit;
if (! is_array($menu_array)) return 0;
// Show menu // Show menu
$alt=0; $alt=0;
if (is_array($menu_array))
{
$num=count($menu_array); $num=count($menu_array);
for ($i = 0; $i < $num; $i++) for ($i = 0; $i < $num; $i++)
{ {
@ -1421,12 +1424,31 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
print "</div>\n"; print "</div>\n";
} }
} }
}
return count($menu_array); return count($menu_array);
} }
/**
* Core function to output top menu eldy
*
* @param DoliDB $db Database handler
* @param string $atarget Target
* @param int $type_user 0=Menu for backoffice, 1=Menu for front office
* @param array &$tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty)
* @return void
*/
function print_jmobile_eldy_menu($db,$atarget,$type_user,&$tabMenu)
{
print '<ul data-role="listview" data-inset="true">
<li><a href="#">Acura</a></li>
<li><a href="#">Audi</a></li>
<li><a href="#">BMW</a></li>
<li><a href="#">Cadillac</a></li>
<li><a href="#">Ferrari</a></li>
</ul>';
}
/** /**
* Function to test if an entry is enabled or not * Function to test if an entry is enabled or not
* *

View File

@ -98,7 +98,7 @@ class MenuManager
/** /**
* Show menu * Show menu
* *
* @param string $mode 'top' or 'left' * @param string $mode 'top', 'left', 'jmobile'
* @return int Number of menu entries shown * @return int Number of menu entries shown
*/ */
function showmenu($mode) function showmenu($mode)
@ -116,6 +116,7 @@ class MenuManager
$res='ErrorBadParameterForMode'; $res='ErrorBadParameterForMode';
if ($mode == 'top') $res=print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu); if ($mode == 'top') $res=print_eldy_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu);
if ($mode == 'left') $res=print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu); if ($mode == 'left') $res=print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu);
if ($mode == 'jmobile') $res=print_jmobile_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu);
return $res; return $res;
} }

View File

@ -28,12 +28,10 @@ define('NOCSRFCHECK',1); // This is login page. We must be able to go on it from
require 'main.inc.php'; require 'main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
// If not defined, we select menu "home" // If not defined, we select menu "home"
$_GET['mainmenu']=GETPOST('mainmenu', 'alpha')?GETPOST('mainmenu', 'alpha'):'home'; $_GET['mainmenu']=GETPOST('mainmenu', 'alpha')?GETPOST('mainmenu', 'alpha'):'home';
$action=GETPOST('action'); $action=GETPOST('action');
$hookmanager->initHooks(array('index')); $hookmanager->initHooks(array('index'));
@ -54,28 +52,14 @@ if (!isset($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_IN
* View * View
*/ */
// If smartphone mode, we do not show main page, we show only menu // If smartphone mode, we do not show main page, we show only menu. TODO Remove this
if (preg_match('/^smartphone/',$conf->smart_menu) && ! empty($conf->browser->phone)) if (preg_match('/^smartphone/',$conf->smart_menu) && ! empty($conf->browser->phone))
{ {
$limitmenuto=GETPOST('limitmenuto')?GETPOST('limitmenuto'):0;
$limitmenuto=1; // A virer
// Load the smartphone menu manager
$result=@include_once DOL_DOCUMENT_ROOT ."/core/menus/smartphone/".$conf->smart_menu;
if (! $result) // If failed to include, we try with standard
{
$conf->smart_menu='smartphone_backoffice.php';
include_once DOL_DOCUMENT_ROOT ."/core/menus/smartphone/".$conf->smart_menu;
}
$menusmart = new MenuSmart($db, $user->societe_id?1:0);
include_once DOL_DOCUMENT_ROOT.'/theme/phones/smartphone/tpl/menu.tpl.php'; include_once DOL_DOCUMENT_ROOT.'/theme/phones/smartphone/tpl/menu.tpl.php';
exit; exit;
} }
llxHeader('',$langs->trans("HomeArea"));
llxHeader();
print_fiche_titre($langs->trans("HomeArea")); print_fiche_titre($langs->trans("HomeArea"));

View File

@ -920,7 +920,7 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs
if (! defined('DISABLE_JQUERY') && ! $disablejs && $conf->use_javascript_ajax) if (! defined('DISABLE_JQUERY') && ! $disablejs && $conf->use_javascript_ajax)
{ {
print '<!-- Includes for JQuery (Ajax library) -->'."\n"; print '<!-- Includes CSS for JQuery (Ajax library) -->'."\n";
$jquerytheme = 'smoothness'; $jquerytheme = 'smoothness';
if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME; if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
if (constant('JS_JQUERY_UI')) print '<link rel="stylesheet" type="text/css" href="'.JS_JQUERY_UI.'css/'.$jquerytheme.'/jquery-ui.min.css" />'."\n"; // JQuery if (constant('JS_JQUERY_UI')) print '<link rel="stylesheet" type="text/css" href="'.JS_JQUERY_UI.'css/'.$jquerytheme.'/jquery-ui.min.css" />'."\n"; // JQuery
@ -951,7 +951,7 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs
} }
} }
print '<!-- Includes for Dolibarr, modules or specific pages-->'."\n"; print '<!-- Includes CSS for Dolibarr theme -->'."\n";
// Output style sheets (optioncss='print' or ''). Note: $conf->css looks like '/theme/eldy/style.css.php' // Output style sheets (optioncss='print' or ''). Note: $conf->css looks like '/theme/eldy/style.css.php'
$themepath=dol_buildpath((empty($conf->global->MAIN_FORCETHEMEDIR)?'':$conf->global->MAIN_FORCETHEMEDIR).$conf->css,1); $themepath=dol_buildpath((empty($conf->global->MAIN_FORCETHEMEDIR)?'':$conf->global->MAIN_FORCETHEMEDIR).$conf->css,1);
$themesubdir=''; $themesubdir='';
@ -982,7 +982,7 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs
foreach($filescss as $cssfile) foreach($filescss as $cssfile)
{ {
// cssfile is a relative path // cssfile is a relative path
print '<!-- Added by module '.$modcss. '-->'."\n".'<link rel="stylesheet" type="text/css" title="default" href="'.dol_buildpath($cssfile,1); print '<!-- Includes CSS added by module '.$modcss. '-->'."\n".'<link rel="stylesheet" type="text/css" title="default" href="'.dol_buildpath($cssfile,1);
// We add params only if page is not static, because some web server setup does not return content type text/css if url has parameters, so browser cache is not used. // We add params only if page is not static, because some web server setup does not return content type text/css if url has parameters, so browser cache is not used.
if (!preg_match('/\.css$/i',$cssfile)) print $themeparam; if (!preg_match('/\.css$/i',$cssfile)) print $themeparam;
print '">'."\n"; print '">'."\n";
@ -994,7 +994,7 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs
{ {
foreach($arrayofcss as $cssfile) foreach($arrayofcss as $cssfile)
{ {
print '<!-- Added by page -->'."\n".'<link rel="stylesheet" type="text/css" title="default" href="'.dol_buildpath($cssfile,1); print '<!-- Includes CSS added by page -->'."\n".'<link rel="stylesheet" type="text/css" title="default" href="'.dol_buildpath($cssfile,1);
// We add params only if page is not static, because some web server setup does not return content type text/css if url has parameters and browser cache is not used. // We add params only if page is not static, because some web server setup does not return content type text/css if url has parameters and browser cache is not used.
if (!preg_match('/\.css$/i',$cssfile)) print $themeparam; if (!preg_match('/\.css$/i',$cssfile)) print $themeparam;
print '">'."\n"; print '">'."\n";
@ -1142,14 +1142,14 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs
foreach($filesjs as $jsfile) foreach($filesjs as $jsfile)
{ {
// jsfile is a relative path // jsfile is a relative path
print '<!-- Added by module '.$modjs. '-->'."\n".'<script type="text/javascript" src="'.dol_buildpath($jsfile,1).'"></script>'."\n"; print '<!-- Include JS added by module '.$modjs. '-->'."\n".'<script type="text/javascript" src="'.dol_buildpath($jsfile,1).'"></script>'."\n";
} }
} }
} }
// JS forced by page in top_htmlhead (relative url starting with /) // JS forced by page in top_htmlhead (relative url starting with /)
if (is_array($arrayofjs)) if (is_array($arrayofjs))
{ {
print '<!-- Includes JS specific to page -->'."\n"; print '<!-- Includes JS added by page -->'."\n";
foreach($arrayofjs as $jsfile) foreach($arrayofjs as $jsfile)
{ {
if (preg_match('/^http/i',$jsfile)) if (preg_match('/^http/i',$jsfile))

View File

@ -13,8 +13,18 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/ */
// Load the smartphone menu manager
$result=@include_once DOL_DOCUMENT_ROOT ."/core/menus/smartphone/".$conf->smart_menu;
if (! $result) // If failed to include, we try with standard
{
$conf->smart_menu='smartphone_menu.php';
include_once DOL_DOCUMENT_ROOT ."/core/menus/smartphone/".$conf->smart_menu;
}
$menusmart = new MenuSmart($db, $user->societe_id?1:0);
top_httphead(); top_httphead();
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
@ -50,7 +60,7 @@ jQuery(document).bind("mobileinit", function(){
</ul> </ul>
--> -->
<?php $menusmart->showmenu($limitmenuto); ?> <?php $menusmart->showmenu(1); ?>
</div><!-- /content --> </div><!-- /content -->