2010-10-02 23:31:14 +02:00
< ? php
2013-02-24 21:16:36 +01:00
/* Copyright ( C ) 2010 - 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2010 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2010-10-02 23:31:14 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2010-10-02 23:31:14 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-08-01 01:45:11 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2010-10-02 23:31:14 +02:00
* or see http :// www . gnu . org /
*/
/**
2011-10-24 14:11:49 +02:00
* \file htdocs / core / menus / standard / auguria . lib . php
2010-10-02 23:31:14 +02:00
* \brief Library for file auguria menus
*/
2013-03-30 14:27:13 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/menubase.class.php' ;
2010-10-02 23:31:14 +02:00
/**
* Core function to output top menu auguria
*
2012-02-17 10:04:10 +01:00
* @ param DoliDB $db Database handler
* @ param string $atarget Target
2013-03-29 16:16:26 +01:00
* @ param int $type_user 0 = Menu for backoffice , 1 = Menu for front office
2016-05-17 19:49:37 +02:00
* @ param array $tabMenu If array with menu entries already loaded , we put this array here ( in most cases , it ' s empty )
* @ param Menu $menu Object Menu to return back list of menu entries
2013-03-29 16:16:26 +01:00
* @ param int $noout Disable output ( Initialise & $menu only ) .
2016-06-12 20:23:25 +02:00
* @ param string $mode 'top' , 'topnb' , 'left' , 'jmobile'
2014-04-25 20:11:38 +02:00
* @ return int 0
2010-10-02 23:31:14 +02:00
*/
2016-06-12 20:23:25 +02:00
function print_auguria_menu ( $db , $atarget , $type_user , & $tabMenu , & $menu , $noout = 0 , $mode = '' )
2010-10-02 23:31:14 +02:00
{
global $user , $conf , $langs , $dolibarr_main_db_name ;
2013-03-30 14:27:13 +01:00
$mainmenu = $_SESSION [ " mainmenu " ];
$leftmenu = $_SESSION [ " leftmenu " ];
2013-02-24 21:16:36 +01:00
2013-02-27 21:40:43 +01:00
$id = 'mainmenu' ;
2013-01-02 21:35:28 +01:00
$listofmodulesforexternal = explode ( ',' , $conf -> global -> MAIN_MODULES_FOR_EXTERNAL );
2013-03-29 16:16:26 +01:00
// Show personalized menus
2013-01-15 12:48:46 +01:00
$menuArbo = new Menubase ( $db , 'auguria' );
2012-01-03 09:41:01 +01:00
$newTabMenu = $menuArbo -> menuTopCharger ( '' , '' , $type_user , 'auguria' , $tabMenu );
2010-10-02 23:31:14 +02:00
2013-03-29 16:16:26 +01:00
if ( empty ( $noout )) print_start_menu_array_auguria ();
2011-11-26 18:32:48 +01:00
2017-05-16 13:27:32 +02:00
$usemenuhider = ( GETPOST ( 'testmenuhider' , 'int' ) || ! empty ( $conf -> global -> MAIN_TESTMENUHIDER ));
2017-06-13 15:57:30 +02:00
2016-06-12 20:23:25 +02:00
// Show/Hide vertical menu
2016-11-07 10:14:04 +01:00
if ( $mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ))
2016-06-12 20:23:25 +02:00
{
$showmode = 1 ;
$classname = 'class="tmenu menuhider"' ;
$idsel = 'menu' ;
2017-06-13 15:57:30 +02:00
2017-06-27 04:25:41 +02:00
$menu -> add ( '#' , '' , 0 , $showmode , $atarget , " xxx " , '' , 0 , $id , $idsel , $classname );
2016-06-12 20:23:25 +02:00
}
2017-06-13 15:57:30 +02:00
2011-09-20 18:12:52 +02:00
$num = count ( $newTabMenu );
for ( $i = 0 ; $i < $num ; $i ++ )
2010-10-02 23:31:14 +02:00
{
2013-01-02 21:35:28 +01:00
$idsel = ( empty ( $newTabMenu [ $i ][ 'mainmenu' ]) ? 'none' : $newTabMenu [ $i ][ 'mainmenu' ]);
$showmode = dol_auguria_showmenu ( $type_user , $newTabMenu [ $i ], $listofmodulesforexternal );
if ( $showmode == 1 )
2010-10-02 23:31:14 +02:00
{
2017-12-09 15:35:01 +01:00
$substitarray = array ( '__LOGIN__' => $user -> login , '__USER_ID__' => $user -> id , '__USER_SUPERVISOR_ID__' => $user -> fk_user );
$substitarray [ '__USERID__' ] = $user -> id ; // For backward compatibility
$newTabMenu [ $i ][ 'url' ] = make_substitutions ( $newTabMenu [ $i ][ 'url' ], $substitarray );
2017-09-23 03:22:48 +02:00
2013-03-29 16:16:26 +01:00
$url = $shorturl = $newTabMenu [ $i ][ 'url' ];
2017-06-13 15:57:30 +02:00
2013-03-29 16:16:26 +01:00
if ( ! preg_match ( " /^(http: \ / \ /|https: \ / \ /)/i " , $newTabMenu [ $i ][ 'url' ]))
2010-10-02 23:31:14 +02:00
{
2016-06-29 14:09:18 +02:00
$tmp = explode ( '?' , $newTabMenu [ $i ][ 'url' ], 2 );
2013-07-07 13:17:48 +02:00
$url = $shorturl = $tmp [ 0 ];
2013-07-07 03:26:51 +02:00
$param = ( isset ( $tmp [ 1 ]) ? $tmp [ 1 ] : '' );
2017-06-27 10:34:41 +02:00
// Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined.
2017-06-13 15:57:30 +02:00
if (( ! preg_match ( '/mainmenu/i' , $param )) && ( ! preg_match ( '/leftmenu/i' , $param )) && ! empty ( $newTabMenu [ $i ][ 'url' ]))
2016-06-29 19:43:42 +02:00
{
2017-06-27 10:34:41 +02:00
$param .= ( $param ? '&' : '' ) . 'mainmenu=' . $newTabMenu [ $i ][ 'mainmenu' ] . '&leftmenu=' ;
2016-06-29 19:43:42 +02:00
}
2017-06-13 15:57:30 +02:00
if (( ! preg_match ( '/mainmenu/i' , $param )) && ( ! preg_match ( '/leftmenu/i' , $param )) && empty ( $newTabMenu [ $i ][ 'url' ]))
2016-06-29 19:43:42 +02:00
{
$param .= ( $param ? '&' : '' ) . 'leftmenu=' ;
}
2013-01-02 21:35:28 +01:00
//$url.="idmenu=".$newTabMenu[$i]['rowid']; // Already done by menuLoad
2013-07-07 03:26:51 +02:00
$url = dol_buildpath ( $url , 1 ) . ( $param ? '?' . $param : '' );
2017-06-27 04:25:41 +02:00
//$shorturl = $shorturl.($param?'?'.$param:'');
$shorturl = $url ;
2017-06-27 10:34:41 +02:00
2017-06-27 04:25:41 +02:00
if ( DOL_URL_ROOT ) $shorturl = preg_replace ( '/^' . preg_quote ( DOL_URL_ROOT , '/' ) . '/' , '' , $shorturl );
2010-10-02 23:31:14 +02:00
}
2015-09-12 18:00:19 +02:00
2017-05-19 00:52:13 +02:00
// TODO Find a generic solution
if ( preg_match ( '/search_project_user=__search_project_user__/' , $shorturl ))
{
$search_project_user = GETPOST ( 'search_project_user' , 'int' );
if ( $search_project_user ) $shorturl = preg_replace ( '/search_project_user=__search_project_user__/' , 'search_project_user=' . $search_project_user , $shorturl );
else $shorturl = preg_replace ( '/search_project_user=__search_project_user__/' , '' , $shorturl );
}
2017-06-14 10:48:34 +02:00
2013-01-02 21:35:28 +01:00
// Define the class (top menu selected or not)
if ( ! empty ( $_SESSION [ 'idmenu' ]) && $newTabMenu [ $i ][ 'rowid' ] == $_SESSION [ 'idmenu' ]) $classname = 'class="tmenusel"' ;
else if ( ! empty ( $_SESSION [ " mainmenu " ]) && $newTabMenu [ $i ][ 'mainmenu' ] == $_SESSION [ " mainmenu " ]) $classname = 'class="tmenusel"' ;
else $classname = 'class="tmenu"' ;
2010-10-02 23:31:14 +02:00
}
2013-02-27 21:40:43 +01:00
else if ( $showmode == 2 ) $classname = 'class="tmenu"' ;
2017-06-27 04:25:41 +02:00
$menu -> add ( $shorturl , $newTabMenu [ $i ][ 'titre' ], 0 , $showmode , ( $newTabMenu [ $i ][ 'target' ] ? $newTabMenu [ $i ][ 'target' ] : $atarget ), ( $newTabMenu [ $i ][ 'mainmenu' ] ? $newTabMenu [ $i ][ 'mainmenu' ] : $newTabMenu [ $i ][ 'rowid' ]), ( $newTabMenu [ $i ][ 'leftmenu' ] ? $newTabMenu [ $i ][ 'leftmenu' ] : '' ), $newTabMenu [ $i ][ 'position' ], $id , $idsel , $classname );
}
// Sort on position
$menu -> liste = dol_sort_array ( $menu -> liste , 'position' );
// Output menu entries
foreach ( $menu -> liste as $menkey => $menuval )
{
2017-06-27 10:34:41 +02:00
if ( empty ( $noout )) print_start_menu_entry_auguria ( $menuval [ 'idsel' ], $menuval [ 'classname' ], $menuval [ 'enabled' ]);
2017-06-27 04:25:41 +02:00
if ( empty ( $noout )) print_text_menu_entry_auguria ( $menuval [ 'titre' ], $menuval [ 'enabled' ], ( $menuval [ 'url' ] != '#' ? DOL_URL_ROOT : '' ) . $menuval [ 'url' ], $menuval [ 'id' ], $menuval [ 'idsel' ], $menuval [ 'classname' ], ( $menuval [ 'target' ] ? $menuval [ 'target' ] : $atarget ));
if ( empty ( $noout )) print_end_menu_entry_auguria ( $menuval [ 'enabled' ]);
2010-10-02 23:31:14 +02:00
}
2013-08-06 03:01:56 +02:00
$showmode = 1 ;
2013-08-27 14:53:24 +02:00
if ( empty ( $noout )) print_start_menu_entry_auguria ( '' , 'class="tmenuend"' , $showmode );
if ( empty ( $noout )) print_end_menu_entry_auguria ( $showmode );
2013-07-28 05:35:51 +02:00
2013-03-29 16:16:26 +01:00
if ( empty ( $noout )) print_end_menu_array_auguria ();
2010-10-02 23:31:14 +02:00
print " \n " ;
2014-04-25 20:11:38 +02:00
return 0 ;
2010-10-02 23:31:14 +02:00
}
2012-03-19 17:18:11 +01:00
/**
2012-05-01 23:40:23 +02:00
* Output start menu array
2012-03-19 17:18:11 +01:00
*
* @ return void
*/
2010-10-02 23:31:14 +02:00
function print_start_menu_array_auguria ()
{
2016-07-31 13:20:40 +02:00
global $conf ;
2017-06-13 15:57:30 +02:00
2012-05-01 23:40:23 +02:00
print '<div class="tmenudiv">' ;
2016-07-31 13:20:40 +02:00
print '<ul class="tmenu"' . ( empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ) ? '' : ' title="Top menu"' ) . '>' ;
2010-10-02 23:31:14 +02:00
}
2012-03-19 17:18:11 +01:00
/**
2012-05-01 23:40:23 +02:00
* Output start menu entry
2012-03-19 17:18:11 +01:00
*
* @ param string $idsel Text
2012-05-09 00:28:02 +02:00
* @ param string $classname String to add a css class
2013-03-24 03:51:49 +01:00
* @ param int $showmode 0 = hide , 1 = allowed or 2 = not allowed
2012-03-19 17:18:11 +01:00
* @ return void
*/
2013-03-24 03:51:49 +01:00
function print_start_menu_entry_auguria ( $idsel , $classname , $showmode )
2010-10-02 23:31:14 +02:00
{
2013-03-24 03:51:49 +01:00
if ( $showmode )
{
print '<li ' . $classname . ' id="mainmenutd_' . $idsel . '">' ;
2018-02-05 23:06:48 +01:00
//print '<div class="tmenuleft tmenusep"></div>';
print '<div class="tmenucenter">' ;
2013-03-24 03:51:49 +01:00
}
2010-10-02 23:31:14 +02:00
}
2012-03-19 17:18:11 +01:00
/**
* Output menu entry
*
* @ param string $text Text
2013-03-29 16:16:26 +01:00
* @ param int $showmode 0 = hide , 1 = allowed or 2 = not allowed
2013-02-27 21:40:43 +01:00
* @ param string $url Url
* @ param string $id Id
* @ param string $idsel Id sel
* @ param string $classname Class name
* @ param string $atarget Target
2012-03-19 17:18:11 +01:00
* @ return void
*/
2013-03-15 18:00:29 +01:00
function print_text_menu_entry_auguria ( $text , $showmode , $url , $id , $idsel , $classname , $atarget )
2010-10-02 23:31:14 +02:00
{
2013-03-30 14:27:13 +01:00
global $langs ;
if ( $showmode == 1 )
{
2016-09-03 12:56:49 +02:00
print '<a class="tmenuimage" tabindex="-1" href="' . $url . '"' . ( $atarget ? ' target="' . $atarget . '"' : '' ) . '>' ;
2015-01-30 15:47:27 +01:00
print '<div class="' . $id . ' ' . $idsel . ' topmenuimage"><span class="' . $id . ' tmenuimage" id="mainmenuspan_' . $idsel . '"></span></div>' ;
2013-03-30 14:27:13 +01:00
print '</a>' ;
print '<a ' . $classname . ' id="mainmenua_' . $idsel . '" href="' . $url . '"' . ( $atarget ? ' target="' . $atarget . '"' : '' ) . '>' ;
print '<span class="mainmenuaspan">' ;
print $text ;
print '</span>' ;
print '</a>' ;
}
if ( $showmode == 2 )
{
2016-10-21 17:24:22 +02:00
print '<div class="' . $id . ' ' . $idsel . ' topmenuimage tmenudisabled"><span class="' . $id . '" id="mainmenuspan_' . $idsel . '"></span></div>' ;
2013-03-30 14:27:13 +01:00
print '<a class="tmenudisabled" id="mainmenua_' . $idsel . '" href="#" title="' . dol_escape_htmltag ( $langs -> trans ( " NotAllowed " )) . '">' ;
2013-03-05 15:42:26 +01:00
print '<span class="mainmenuaspan">' ;
print $text ;
print '</span>' ;
print '</a>' ;
2013-02-27 21:40:43 +01:00
}
2010-10-02 23:31:14 +02:00
}
2012-03-19 17:18:11 +01:00
/**
* Output end menu entry
*
2013-03-24 03:51:49 +01:00
* @ param int $showmode 0 = hide , 1 = allowed or 2 = not allowed
2012-03-19 17:18:11 +01:00
* @ return void
*/
2013-03-24 03:51:49 +01:00
function print_end_menu_entry_auguria ( $showmode )
2010-10-02 23:31:14 +02:00
{
2013-03-24 03:51:49 +01:00
if ( $showmode )
{
print '</div></li>' ;
}
2013-03-29 16:16:26 +01:00
print " \n " ;
2010-10-02 23:31:14 +02:00
}
2012-03-19 17:18:11 +01:00
/**
* Output menu array
*
* @ return void
*/
2010-10-02 23:31:14 +02:00
function print_end_menu_array_auguria ()
{
2012-05-01 23:40:23 +02:00
print '</ul>' ;
2013-02-24 21:16:36 +01:00
print '</div>' ;
2010-10-02 23:31:14 +02:00
print " \n " ;
}
/**
* Core function to output left menu auguria
*
2013-03-05 15:42:26 +01:00
* @ param DoliDB $db Database handler
* @ param array $menu_array_before Table of menu entries to show before entries of menu handler
* @ param array $menu_array_after Table of menu entries to show after entries of menu handler
2015-10-30 09:36:57 +01:00
* @ param array $tabMenu If array with menu entries already loaded , we put this array here ( in most cases , it ' s empty )
2014-09-27 16:00:11 +02:00
* @ param Menu $menu Object Menu to return back list of menu entries
2013-03-29 16:16:26 +01:00
* @ param int $noout Disable output ( Initialise & $menu only ) .
* @ param string $forcemainmenu 'x' = Force mainmenu to mainmenu = 'x'
* @ param string $forceleftmenu 'all' = Force leftmenu to '' ( = all )
2015-10-30 09:36:57 +01:00
* @ param array $moredata An array with more data to output
2014-04-25 20:11:38 +02:00
* @ return int Nb of entries
2010-10-02 23:31:14 +02:00
*/
2015-10-30 09:36:57 +01:00
function print_left_auguria_menu ( $db , $menu_array_before , $menu_array_after , & $tabMenu , & $menu , $noout = 0 , $forcemainmenu = '' , $forceleftmenu = '' , $moredata = null )
2010-10-02 23:31:14 +02:00
{
2013-02-24 21:16:36 +01:00
global $user , $conf , $langs , $dolibarr_main_db_name , $mysoc ;
2013-03-05 15:42:26 +01:00
$newmenu = $menu ;
2013-02-24 21:16:36 +01:00
2013-03-29 16:16:26 +01:00
$mainmenu = ( $forcemainmenu ? $forcemainmenu : $_SESSION [ " mainmenu " ]);
$leftmenu = ( $forceleftmenu ? '' : ( empty ( $_SESSION [ " leftmenu " ]) ? 'none' : $_SESSION [ " leftmenu " ]));
2013-02-24 21:16:36 +01:00
2017-05-16 13:27:32 +02:00
$usemenuhider = ( GETPOST ( 'testmenuhider' , 'int' ) || ! empty ( $conf -> global -> MAIN_TESTMENUHIDER ));
2016-11-07 10:14:04 +01:00
global $usemenuhider ;
2017-06-13 15:57:30 +02:00
2013-02-24 21:16:36 +01:00
// Show logo company
2015-03-24 14:08:56 +01:00
if ( empty ( $noout ) && ! empty ( $conf -> global -> MAIN_SHOW_LOGO ) && empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ))
2013-02-24 21:16:36 +01:00
{
$mysoc -> logo_mini = $conf -> global -> MAIN_INFO_SOCIETE_LOGO_MINI ;
if ( ! empty ( $mysoc -> logo_mini ) && is_readable ( $conf -> mycompany -> dir_output . '/logos/thumbs/' . $mysoc -> logo_mini ))
{
2017-03-31 11:39:12 +02:00
$urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&modulepart=mycompany&file=' . urlencode ( 'thumbs/' . $mysoc -> logo_mini );
2013-02-24 21:16:36 +01:00
}
2015-03-24 14:08:56 +01:00
else
{
$urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.png' ;
}
$title = $langs -> trans ( " GoIntoSetupToChangeLogo " );
print " \n " . '<!-- Show logo on menu -->' . " \n " ;
2015-09-22 11:24:31 +02:00
print '<div class="blockvmenuimpair blockvmenulogo">' . " \n " ;
2015-03-24 14:08:56 +01:00
print '<div class="menu_titre" id="menu_titre_logo"></div>' ;
print '<div class="menu_top" id="menu_top_logo"></div>' ;
print '<div class="menu_contenu" id="menu_contenu_logo">' ;
2017-05-06 20:43:14 +02:00
print '<div class="center"><img title="' . dol_escape_htmltag ( $title ) . '" alt="" src="' . $urllogo . '" style="max-width: 70%"></div>' . " \n " ;
2015-03-24 14:08:56 +01:00
print '</div>' ;
print '<div class="menu_end" id="menu_end_logo"></div>' ;
print '</div>' . " \n " ;
2013-02-24 21:16:36 +01:00
}
2017-11-14 15:10:46 +01:00
if ( is_array ( $moredata ) && ! empty ( $moredata [ 'searchform' ])) // searchform can contains select2 code or link to show old search form or link to switch on search page
2015-10-30 09:36:57 +01:00
{
print " \n " ;
print " <!-- Begin SearchForm --> \n " ;
print '<div id="blockvmenusearch" class="blockvmenusearch">' . " \n " ;
print $moredata [ 'searchform' ];
print '</div>' . " \n " ;
print " <!-- End SearchForm --> \n " ;
}
2017-06-13 15:57:30 +02:00
2017-06-27 11:12:03 +02:00
if ( is_array ( $moredata ) && ! empty ( $moredata [ 'bookmarks' ]))
{
print " \n " ;
print " <!-- Begin Bookmarks --> \n " ;
print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">' . " \n " ;
print $moredata [ 'bookmarks' ];
print '</div>' . " \n " ;
print " <!-- End Bookmarks --> \n " ;
}
2013-04-15 13:11:29 +02:00
// We update newmenu with entries found into database
2013-02-24 21:16:36 +01:00
$menuArbo = new Menubase ( $db , 'auguria' );
$newmenu = $menuArbo -> menuLeftCharger ( $newmenu , $mainmenu , $leftmenu ,( $user -> societe_id ? 1 : 0 ), 'auguria' , $tabMenu );
2013-06-05 16:24:32 +02:00
// We update newmenu for special dynamic menus
if ( $conf -> banque -> enabled && $user -> rights -> banque -> lire && $mainmenu == 'bank' ) // Entry for each bank account
{
2017-06-14 11:28:42 +02:00
include_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ; // Required for to get Account::TYPE_CASH for example
2013-06-05 16:24:32 +02:00
$sql = " SELECT rowid, label, courant, rappro, courant " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " bank_account " ;
$sql .= " WHERE entity = " . $conf -> entity ;
$sql .= " AND clos = 0 " ;
$sql .= " ORDER BY label " ;
2013-07-07 03:26:51 +02:00
2013-06-05 16:24:32 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$numr = $db -> num_rows ( $resql );
$i = 0 ;
2013-07-07 03:26:51 +02:00
2017-10-03 16:00:52 +02:00
if ( $numr > 0 ) $newmenu -> add ( '/compta/bank/list.php' , $langs -> trans ( " BankAccounts " ), 0 , $user -> rights -> banque -> lire );
2013-07-07 03:26:51 +02:00
2013-06-05 16:24:32 +02:00
while ( $i < $numr )
{
$objp = $db -> fetch_object ( $resql );
2014-09-18 21:18:25 +02:00
$newmenu -> add ( '/compta/bank/card.php?id=' . $objp -> rowid , $objp -> label , 1 , $user -> rights -> banque -> lire );
2016-03-02 11:08:57 +01:00
if ( $objp -> rappro && $objp -> courant != Account :: TYPE_CASH && empty ( $objp -> clos )) // If not cash account and not closed and can be reconciliate
2013-06-05 16:24:32 +02:00
{
2017-10-03 16:00:52 +02:00
$newmenu -> add ( '/compta/bank/bankentries_list.php?id=' . $objp -> rowid , $langs -> trans ( " Conciliate " ), 2 , $user -> rights -> banque -> consolidate );
2013-06-05 16:24:32 +02:00
}
$i ++ ;
}
}
else dol_print_error ( $db );
$db -> free ( $resql );
2013-04-15 13:11:29 +02:00
}
2015-01-30 15:47:27 +01:00
2015-01-03 15:07:54 +01:00
if ( ! empty ( $conf -> accounting -> enabled ) && ! empty ( $user -> rights -> accounting -> mouvements -> lire ) && $mainmenu == 'accountancy' ) // Entry in accountancy journal for each bank account
{
2017-08-29 12:43:47 +02:00
$newmenu -> add ( '' , $langs -> trans ( " Journalization " ), 0 , $user -> rights -> accounting -> comptarapport -> lire , '' , 'accountancy' , 'accountancy' );
2015-01-03 15:07:54 +01:00
2017-06-18 22:17:32 +02:00
// Multi journal
$sql = " SELECT rowid, code, label, nature " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " accounting_journal " ;
$sql .= " WHERE entity = " . $conf -> entity ;
2017-08-29 12:43:47 +02:00
$sql .= " AND active = 1 " ;
$sql .= " ORDER BY label DESC " ;
2017-06-18 22:17:32 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$numr = $db -> num_rows ( $resql );
$i = 0 ;
if ( $numr > 0 )
{
while ( $i < $numr )
{
$objp = $db -> fetch_object ( $resql );
$nature = '' ;
2017-08-29 12:43:47 +02:00
2017-06-18 22:17:32 +02:00
// Must match array $sourceList defined into journals_list.php
2017-07-07 06:09:49 +02:00
if ( $objp -> nature == 2 && ! empty ( $conf -> facture -> enabled )) $nature = " sells " ;
if ( $objp -> nature == 3 && ! empty ( $conf -> fournisseur -> enabled )) $nature = " purchases " ;
if ( $objp -> nature == 4 && ! empty ( $conf -> banque -> enabled )) $nature = " bank " ;
if ( $objp -> nature == 5 && ! empty ( $conf -> expensereport -> enabled )) $nature = " expensereports " ;
2017-06-18 22:17:32 +02:00
if ( $objp -> nature == 1 ) $nature = " various " ;
2018-04-01 21:26:52 +02:00
if ( $objp -> nature == 8 ) $nature = " inventory " ;
2017-06-18 22:17:32 +02:00
if ( $objp -> nature == 9 ) $nature = " hasnew " ;
// To enable when page exists
2018-05-24 21:13:48 +02:00
if ( ! empty ( $conf -> global -> ACCOUNTANCY_SHOW_DEVELOP_JOURNAL ))
2017-06-18 22:17:32 +02:00
{
2018-04-01 21:26:52 +02:00
if ( $nature == 'various' || $nature == 'hasnew' || $nature == 'inventory' ) $nature = '' ;
2017-06-18 22:17:32 +02:00
}
if ( $nature )
{
if ( $usemenuhider || empty ( $leftmenu ) || preg_match ( '/accountancy/' , $leftmenu )) $newmenu -> add ( '/accountancy/journal/' . $nature . 'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal=' . $objp -> rowid , dol_trunc ( $objp -> label , 25 ), 2 , $user -> rights -> accounting -> comptarapport -> lire );
}
$i ++ ;
}
}
else
{
// Should not happend. Entries are added
$newmenu -> add ( '' , $langs -> trans ( " NoJournalDefined " ), 2 , $user -> rights -> accounting -> comptarapport -> lire );
}
}
else dol_print_error ( $db );
$db -> free ( $resql );
/*
2016-01-31 07:31:48 +01:00
$sql = " SELECT rowid, label, accountancy_journal " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " bank_account " ;
$sql .= " WHERE entity = " . $conf -> entity ;
$sql .= " AND clos = 0 " ;
$sql .= " ORDER BY label " ;
2015-01-03 15:07:54 +01:00
2016-01-31 07:31:48 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$numr = $db -> num_rows ( $resql );
$i = 0 ;
2015-01-03 15:07:54 +01:00
2016-01-31 07:31:48 +01:00
if ( $numr > 0 )
while ( $i < $numr )
{
$objp = $db -> fetch_object ( $resql );
2017-02-22 01:27:57 +01:00
$newmenu -> add ( '/accountancy/journal/bankjournal.php?id_account=' . $objp -> rowid , $langs -> trans ( " Journal " ) . ' - ' . $objp -> label , 1 , $user -> rights -> accounting -> comptarapport -> lire , '' , 'accountancy' , 'accountancy_journal' );
2016-01-31 07:31:48 +01:00
$i ++ ;
2015-01-03 15:07:54 +01:00
}
}
2016-01-31 07:31:48 +01:00
else dol_print_error ( $db );
$db -> free ( $resql );
// Add other journal
2017-02-22 01:27:57 +01:00
$newmenu -> add ( " /accountancy/journal/sellsjournal.php?leftmenu=journal " , $langs -> trans ( " SellsJournal " ), 1 , $user -> rights -> accounting -> comptarapport -> lire , '' , 'accountancy' , 'accountancy_journal' );
$newmenu -> add ( " /accountancy/journal/purchasesjournal.php?leftmenu=journal " , $langs -> trans ( " PurchasesJournal " ), 1 , $user -> rights -> accounting -> comptarapport -> lire , '' , 'accountancy' , 'accountancy_journal' );
$newmenu -> add ( " /accountancy/journal/expensereportsjournal.php?leftmenu=journal " , $langs -> trans ( " ExpenseReportsJournal " ), 1 , $user -> rights -> accounting -> comptarapport -> lire , '' , 'accountancy' , 'accountancy_journal' );
2017-06-18 22:17:32 +02:00
*/
2015-01-03 15:07:54 +01:00
}
2013-04-15 13:11:29 +02:00
if ( $conf -> ftp -> enabled && $mainmenu == 'ftp' ) // Entry for FTP
{
2013-06-05 16:24:32 +02:00
$MAXFTP = 20 ;
$i = 1 ;
while ( $i <= $MAXFTP )
{
$paramkey = 'FTP_NAME_' . $i ;
//print $paramkey;
if ( ! empty ( $conf -> global -> $paramkey ))
{
$link = " /ftp/index.php?idmenu= " . $_SESSION [ " idmenu " ] . " &numero_ftp= " . $i ;
2013-07-07 03:26:51 +02:00
2013-06-05 16:24:32 +02:00
$newmenu -> add ( $link , dol_trunc ( $conf -> global -> $paramkey , 24 ));
}
$i ++ ;
}
2013-07-07 03:26:51 +02:00
}
2013-04-15 13:11:29 +02:00
// Build final $menu_array = $menu_array_before +$newmenu->liste + $menu_array_after
2013-02-24 21:16:36 +01:00
//var_dump($menu_array_before);exit;
//var_dump($menu_array_after);exit;
$menu_array = $newmenu -> liste ;
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 );
//var_dump($menu_array);exit;
2013-03-30 14:27:13 +01:00
if ( ! is_array ( $menu_array )) return 0 ;
2013-02-24 21:16:36 +01:00
// Show menu
2018-04-06 14:04:52 +02:00
$invert = empty ( $conf -> global -> MAIN_MENU_INVERT ) ? " " : " invert " ;
2013-03-29 16:16:26 +01:00
if ( empty ( $noout ))
{
2017-06-10 16:13:37 +02:00
$altok = 0 ; $blockvmenuopened = false ; $lastlevel0 = '' ;
2013-04-01 16:02:16 +02:00
$num = count ( $menu_array );
2017-06-10 16:13:37 +02:00
for ( $i = 0 ; $i < $num ; $i ++ ) // Loop on each menu entry
2013-02-24 21:16:36 +01:00
{
2013-04-01 16:02:16 +02:00
$showmenu = true ;
if ( ! empty ( $conf -> global -> MAIN_MENU_HIDE_UNAUTHORIZED ) && empty ( $menu_array [ $i ][ 'enabled' ])) $showmenu = false ;
2017-06-10 16:13:37 +02:00
// Begin of new left menu block
2013-04-01 16:02:16 +02:00
if ( empty ( $menu_array [ $i ][ 'level' ]) && $showmenu )
2013-02-24 21:16:36 +01:00
{
2015-10-30 09:36:57 +01:00
$altok ++ ;
2013-06-14 19:51:53 +02:00
$blockvmenuopened = true ;
2016-06-12 20:31:01 +02:00
$lastopened = true ;
for ( $j = ( $i + 1 ); $j < $num ; $j ++ )
{
if ( empty ( $menu_array [ $j ][ 'level' ])) $lastopened = false ;
2017-06-13 15:57:30 +02:00
}
2015-10-30 09:36:57 +01:00
if ( $altok % 2 == 0 )
2013-04-01 16:02:16 +02:00
{
2018-04-06 14:04:52 +02:00
print '<div class="blockvmenu blockvmenuimpair' . $invert . ( $lastopened ? ' blockvmenulast' : '' ) . ( $altok == 1 ? ' blockvmenufirst' : '' ) . '">' . " \n " ;
2013-04-01 16:02:16 +02:00
}
else
{
2018-04-06 14:04:52 +02:00
print '<div class="blockvmenu blockvmenupair' . $invert . ( $lastopened ? ' blockvmenulast' : '' ) . ( $altok == 1 ? ' blockvmenufirst' : '' ) . '">' . " \n " ;
2013-04-01 16:02:16 +02:00
}
2013-02-24 21:16:36 +01:00
}
2017-06-10 16:13:37 +02:00
// Add tabulation
2013-04-01 16:02:16 +02:00
$tabstring = '' ;
$tabul = ( $menu_array [ $i ][ 'level' ] - 1 );
if ( $tabul > 0 )
2013-02-24 21:16:36 +01:00
{
2013-04-01 16:02:16 +02:00
for ( $j = 0 ; $j < $tabul ; $j ++ )
{
2017-06-10 16:13:37 +02:00
$tabstring .= ' ' ;
2013-04-01 16:02:16 +02:00
}
2013-02-24 21:16:36 +01:00
}
2017-12-09 15:35:01 +01:00
// $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution
$substitarray = array ( '__LOGIN__' => $user -> login , '__USER_ID__' => $user -> id , '__USER_SUPERVISOR_ID__' => $user -> fk_user );
$substitarray [ '__USERID__' ] = $user -> id ; // For backward compatibility
$menu_array [ $i ][ 'url' ] = make_substitutions ( $menu_array [ $i ][ 'url' ], $substitarray );
2018-04-06 14:04:52 +02:00
$url = $shorturl = $shorturlwithoutparam = $menu_array [ $i ][ 'url' ];
if ( ! preg_match ( " /^(http: \ / \ /|https: \ / \ /)/i " , $menu_array [ $i ][ 'url' ]))
2013-02-24 21:16:36 +01:00
{
2018-04-06 14:04:52 +02:00
$tmp = explode ( '?' , $menu_array [ $i ][ 'url' ], 2 );
$url = $shorturl = $tmp [ 0 ];
$param = ( isset ( $tmp [ 1 ]) ? $tmp [ 1 ] : '' ); // params in url of the menu link
// Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined.
if (( ! preg_match ( '/mainmenu/i' , $param )) && ( ! preg_match ( '/leftmenu/i' , $param )) && ! empty ( $menu_array [ $i ][ 'mainmenu' ]))
{
$param .= ( $param ? '&' : '' ) . 'mainmenu=' . $menu_array [ $i ][ 'mainmenu' ] . '&leftmenu=' ;
}
if (( ! preg_match ( '/mainmenu/i' , $param )) && ( ! preg_match ( '/leftmenu/i' , $param )) && empty ( $menu_array [ $i ][ 'mainmenu' ]))
{
$param .= ( $param ? '&' : '' ) . 'leftmenu=' ;
}
//$url.="idmenu=".$menu_array[$i]['rowid']; // Already done by menuLoad
$url = dol_buildpath ( $url , 1 ) . ( $param ? '?' . $param : '' );
$shorturlwithoutparam = $shorturl ;
$shorturl = $shorturl . ( $param ? '?' . $param : '' );
2013-02-24 21:16:36 +01:00
}
2013-04-01 16:02:16 +02:00
2018-04-06 14:04:52 +02:00
print '<!-- Process menu entry with mainmenu=' . $menu_array [ $i ][ 'mainmenu' ] . ', leftmenu=' . $menu_array [ $i ][ 'leftmenu' ] . ', level=' . $menu_array [ $i ][ 'level' ] . ' enabled=' . $menu_array [ $i ][ 'enabled' ] . ', position=' . $menu_array [ $i ][ 'position' ] . ' -->' . " \n " ;
2013-07-07 03:26:51 +02:00
2017-06-10 16:13:37 +02:00
// Menu level 0
2013-04-01 16:02:16 +02:00
if ( $menu_array [ $i ][ 'level' ] == 0 )
2013-02-24 21:16:36 +01:00
{
2017-06-10 16:13:37 +02:00
if ( $menu_array [ $i ][ 'enabled' ]) // Enabled so visible
2013-04-01 16:02:16 +02:00
{
2018-04-06 14:04:52 +02:00
print '<div class="menu_titre">' . $tabstring ;
if ( $shorturlwithoutparam ) print '<a class="vmenu" href="' . $url . '"' . ( $menu_array [ $i ][ 'target' ] ? ' target="' . $menu_array [ $i ][ 'target' ] . '"' : '' ) . '>' ;
else print '<span class="vmenu">' ;
print ( $menu_array [ $i ][ 'prefix' ] ? $menu_array [ $i ][ 'prefix' ] : '' ) . $menu_array [ $i ][ 'titre' ];
if ( $shorturlwithoutparam ) print '</a>' ;
else print '</span>' ;
print '</div>' . " \n " ;
2017-06-10 16:13:37 +02:00
$lastlevel0 = 'enabled' ;
2013-04-01 16:02:16 +02:00
}
2017-06-10 16:13:37 +02:00
else if ( $showmenu ) // Not enabled but visible (so greyed)
2013-04-01 16:02:16 +02:00
{
print '<div class="menu_titre">' . $tabstring . '<font class="vmenudisabled">' . $menu_array [ $i ][ 'titre' ] . '</font></div>' . " \n " ;
2017-06-10 16:13:37 +02:00
$lastlevel0 = 'greyed' ;
}
else
{
$lastlevel0 = 'hidden' ;
2013-04-01 16:02:16 +02:00
}
if ( $showmenu )
2017-06-10 16:13:37 +02:00
{
2013-04-01 16:02:16 +02:00
print '<div class="menu_top"></div>' . " \n " ;
2017-06-10 16:13:37 +02:00
}
2013-02-24 21:16:36 +01:00
}
2018-04-06 14:04:52 +02:00
2017-06-10 16:13:37 +02:00
// Menu level > 0
2013-04-01 16:02:16 +02:00
if ( $menu_array [ $i ][ 'level' ] > 0 )
2013-02-24 21:16:36 +01:00
{
2017-06-13 15:57:30 +02:00
$cssmenu = '' ;
if ( $menu_array [ $i ][ 'url' ]) $cssmenu = ' menu_contenu' . dol_string_nospecial ( preg_replace ( '/\.php.*$/' , '' , $menu_array [ $i ][ 'url' ]));
2017-06-10 16:13:37 +02:00
if ( $menu_array [ $i ][ 'enabled' ] && $lastlevel0 == 'enabled' ) // Enabled so visible, except if parent was not enabled.
2013-04-01 16:02:16 +02:00
{
2017-06-13 15:57:30 +02:00
print '<div class="menu_contenu' . $cssmenu . '">' . $tabstring ;
2018-04-06 14:04:52 +02:00
if ( $shorturlwithoutparam ) print '<a class="vsmenu" href="' . $url . '"' . ( $menu_array [ $i ][ 'target' ] ? ' target="' . $menu_array [ $i ][ 'target' ] . '"' : '' ) . '>' ;
2015-05-04 11:41:30 +02:00
else print '<span class="vsmenu">' ;
2013-04-01 16:02:16 +02:00
print $menu_array [ $i ][ 'titre' ];
2018-04-06 14:04:52 +02:00
if ( $shorturlwithoutparam ) print '</a>' ;
2015-05-04 11:41:30 +02:00
else print '</span>' ;
2013-04-01 16:02:16 +02:00
// If title is not pure text and contains a table, no carriage return added
if ( ! strstr ( $menu_array [ $i ][ 'titre' ], '<table' )) print '<br>' ;
print '</div>' . " \n " ;
}
2017-06-10 16:13:37 +02:00
else if ( $showmenu && $lastlevel0 == 'enabled' ) // Not enabled but visible (so greyed), except if parent was not enabled.
2013-04-01 16:02:16 +02:00
{
2017-06-13 15:57:30 +02:00
print '<div class="menu_contenu' . $cssmenu . '">' . $tabstring . '<font class="vsmenudisabled vsmenudisabledmargin">' . $menu_array [ $i ][ 'titre' ] . '</font><br></div>' . " \n " ;
2013-04-01 16:02:16 +02:00
}
2013-02-24 21:16:36 +01:00
}
2013-04-01 16:02:16 +02:00
2013-06-14 19:51:53 +02:00
// If next is a new block or if there is nothing after
2017-06-10 16:13:37 +02:00
if ( empty ( $menu_array [ $i + 1 ][ 'level' ])) // End menu block
2013-02-24 21:16:36 +01:00
{
2013-04-01 16:02:16 +02:00
if ( $showmenu )
print '<div class="menu_end"></div>' . " \n " ;
2017-06-10 16:13:37 +02:00
if ( $blockvmenuopened ) { print '</div>' . " \n " ; $blockvmenuopened = false ; }
2013-02-24 21:16:36 +01:00
}
}
2017-06-13 15:57:30 +02:00
2017-06-10 16:13:37 +02:00
if ( $altok ) print '<div class="blockvmenuend"></div>' ; // End menu block
2013-03-29 16:16:26 +01:00
}
2013-03-30 20:34:13 +01:00
2013-02-24 21:16:36 +01:00
return count ( $menu_array );
2010-10-02 23:31:14 +02:00
}
2013-01-02 21:35:28 +01:00
/**
* Function to test if an entry is enabled or not
*
* @ param string $type_user 0 = We need backoffice menu , 1 = We need frontoffice menu
2014-09-27 16:00:11 +02:00
* @ param array $menuentry Array for menu entry
* @ param array $listofmodulesforexternal Array with list of modules allowed to external users
2013-01-02 21:35:28 +01:00
* @ return int 0 = Hide , 1 = Show , 2 = Show gray
*/
function dol_auguria_showmenu ( $type_user , & $menuentry , & $listofmodulesforexternal )
{
2013-03-10 13:22:51 +01:00
global $conf ;
2013-01-02 21:35:28 +01:00
//print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
//print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
if ( empty ( $menuentry [ 'enabled' ])) return 0 ; // Entry disabled by condition
if ( $type_user && $menuentry [ 'module' ])
{
$tmploops = explode ( '|' , $menuentry [ 'module' ]);
$found = 0 ;
foreach ( $tmploops as $tmploop )
{
2013-02-24 21:16:36 +01:00
if ( in_array ( $tmploop , $listofmodulesforexternal )) {
$found ++ ; break ;
}
2013-01-02 21:35:28 +01:00
}
if ( ! $found ) return 0 ; // Entry is for menus all excluded to external users
}
if ( ! $menuentry [ 'perms' ] && $type_user ) return 0 ; // No permissions and user is external
2013-01-10 08:27:12 +01:00
if ( ! $menuentry [ 'perms' ] && ! empty ( $conf -> global -> MAIN_MENU_HIDE_UNAUTHORIZED )) return 0 ; // No permissions and option to hide when not allowed, even for internal user, is on
if ( ! $menuentry [ 'perms' ]) return 2 ; // No permissions and user is external
2013-01-02 21:35:28 +01:00
return 1 ;
}