Passed
Push — master ( 65bdac...4e88da )
by Alxarafe
32:38
created

AlixarView::llxHeader()   A

Complexity

Conditions 6
Paths 16

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 10
nc 16
nop 11
dl 0
loc 23
rs 9.2222
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/* Copyright (C) 2019       Alxarafe                    <[email protected]>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
 */
17
namespace Alixar\Base;
18
19
use Alxarafe\Helpers\Debug;
20
use Alixar\Helpers\Globals;
21
use Alixar\Helpers\DolUtils;
22
23
/**
24
 * This class contains the methods and attributes common to all Alixar view
25
 *
26
 * @author Alxarafe
27
 */
28
class AlixarView extends \Alixar\Base\AlixarBasicView
29
{
30
31
    public $menumanager;
32
33
    public function __construct($ctrl)
34
    {
35
        parent::__construct($ctrl);
36
        $this->menumanager = $this->ctrl->menumanager;
37
    }
38
39
    public function getTopMenu()
40
    {
41
        $ret[] = [
0 ignored issues
show
Comprehensibility Best Practice introduced by
$ret was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ret = array(); before regardless.
Loading history...
42
            'text' => '<i class="fa fa-cog fa-fw"></i> Config',
43
            'href' => '?call=EditConfig',
44
        ];
45
        $ret[] = [
46
            'text' => '<i class="fa fa-database fa-fw"></i> Database',
47
            'href' => 'index.html',
48
            'options' => [
49
                [
50
                    'text' => '<i class="fa fa-address-book fa-fw"></i> People',
51
                    'href' => '?call=People'
52
                ],
53
                [
54
                    'text' => '<i class="fa fa-automobile fa-fw"></i> Vehicles',
55
                    'href' => '?call=Vehicles',
56
                    'options' => [
57
                        'text' => '<i class="fa fa-address-book fa-fw"></i> People',
58
                        'href' => '?call=People'
59
                    ]
60
                ]
61
            ]
62
        ];
63
64
        return $ret;
65
    }
66
67
    public function getLeftMenu(): array
68
    {
69
        $ret[] = [
0 ignored issues
show
Comprehensibility Best Practice introduced by
$ret was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ret = array(); before regardless.
Loading history...
70
            'text' => '<i class="fa fa-cog fa-fw"></i> Config',
71
            'href' => '?call=EditConfig',
72
        ];
73
        $ret[] = [
74
            'text' => '<i class="fa fa-database fa-fw"></i> Database',
75
            'href' => 'index.html',
76
            'options' => [
77
                [
78
                    'text' => '<i class="fa fa-address-book fa-fw"></i> People',
79
                    'href' => '?call=People'
80
                ],
81
                [
82
                    'text' => '<i class="fa fa-automobile fa-fw"></i> Vehicles',
83
                    'href' => '?call=Vehicles',
84
                    'options' => [
85
                        'text' => '<i class="fa fa-address-book fa-fw"></i> People',
86
                        'href' => '?call=People'
87
                    ]
88
                ]
89
            ]
90
        ];
91
92
        return $ret;
93
    }
94
95
    /**
96
     * 	Show HTML header HTML + BODY + Top menu + left menu + DIV
97
     *
98
     * @param 	string 	$head				Optionnal head lines
99
     * @param 	string 	$title				HTML title
100
     * @param	string	$help_url			Url links to help page
101
     * 		                            	Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
102
     *                                  	For other external page: http://server/url
103
     * @param	string	$target				Target to use on links
104
     * @param 	int    	$disablejs			More content into html header
105
     * @param 	int    	$disablehead		More content into html header
106
     * @param 	array  	$arrayofjs			Array of complementary js files
107
     * @param 	array  	$arrayofcss			Array of complementary css files
108
     * @param	string	$morequerystring	Query string to add to the link "print" to get same parameters (use only if autodetect fails)
109
     * @param   string  $morecssonbody      More CSS on body tag.
110
     * @param	string	$replacemainareaby	Replace call to main_area() by a print of this string
111
     * @return	void
112
     */
113
    function llxHeader($head = '', $title = '', $help_url = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $morequerystring = '', $morecssonbody = '', $replacemainareaby = '')
114
    {
115
//global $conf;
116
// html header
117
        $this->top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
118
119
        print '<body id="mainbody"' . ($morecssonbody ? ' class="' . $morecssonbody . '"' : '') . '>' . "\n";
120
121
// top menu and left menu area
122
        if (empty(Globals::$conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu', 'int')) {
123
            $this->top_menu($head, $title, $target, $disablejs, $disablehead, $arrayofjs, $arrayofcss, $morequerystring, $help_url);
124
        }
125
126
        if (empty(Globals::$conf->dol_hide_leftmenu)) {
127
            $this->left_menu('', $help_url, '', '', 1, $title, 1);  // $menumanager is retreived with a global $menumanager inside this function
128
        }
129
130
// main area
131
        if ($replacemainareaby) {
132
            print $replacemainareaby;
133
            return;
134
        }
135
        $this->main_area($title);
136
    }
137
138
    /**
139
     *  Show an HTML header + a BODY + The top menu bar
140
     *
141
     *  @param      string	$head    			Lines in the HEAD
142
     *  @param      string	$title   			Title of web page
143
     *  @param      string	$target  			Target to use in menu links (Example: '' or '_top')
144
     * 	@param		int		$disablejs			Do not output links to js (Ex: qd fonction utilisee par sous formulaire Ajax)
145
     * 	@param		int		$disablehead		Do not output head section
146
     * 	@param		array	$arrayofjs			Array of js files to add in header
147
     * 	@param		array	$arrayofcss			Array of css files to add in header
148
     *  @param		string	$morequerystring	Query string to add to the link "print" to get same parameters (use only if autodetect fails)
149
     *  @param      string	$helppagename    	Name of wiki page for help ('' by default).
150
     * 				     		                Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
151
     * 						                    For other external page: http://server/url
152
     *  @return		void
153
     */
154
    function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $morequerystring = '', $helppagename = '')
155
    {
156
// global Globals::$user, Globals::$conf, Globals::$langs, $db;
157
// global $dolibarr_main_authentication, $dolibarr_main_demo;
158
// global Globals::$hookManager, $menumanager;
159
160
        $searchform = '';
161
        $bookmarks = '';
162
163
// Instantiate hooks of thirdparty module
164
        Globals::$hookManager->initHooks(array('toprightmenu'));
165
166
        $toprightmenu = '';
167
168
// For backward compatibility with old modules
169
        if (empty(Globals::$conf->headerdone)) {
170
            $this->top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
171
            print '<body id="mainbody">';
172
        }
173
174
        /*
175
         * Top menu
176
         */
177
        if ((empty(Globals::$conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu', 'int')) && (!defined('NOREQUIREMENU') || !constant('NOREQUIREMENU'))) {
178
            print "\n" . '<!-- Start top horizontal -->' . "\n";
179
180
            print '<div class="side-nav-vert' . (DolUtils::GETPOST('dol_invisible_topmenu', 'int') ? ' hidden' : '') . '"><div id="id-top">';  // dol_invisible_topmenu differs from dol_hide_topmenu: dol_invisible_topmenu means we output menu but we make it invisible.
181
// Show menu entries
182
            print '<div id="tmenu_tooltip' . (empty(Globals::$conf->global->MAIN_MENU_INVERT) ? '' : 'invert') . '" class="tmenu">' . "\n";
183
            $this->menumanager->atarget = $target;
184
            $this->menumanager->showmenu('top', array('searchform' => $searchform, 'bookmarks' => $bookmarks));      // This contains a \n
185
            print "</div>\n";
186
187
// Define link to login card
188
            $appli = constant('DOL_APPLICATION_TITLE');
189
            if (!empty(Globals::$conf->global->MAIN_APPLICATION_TITLE)) {
190
                $appli = Globals::$conf->global->MAIN_APPLICATION_TITLE;
191
if (preg_match('/\d\.\d/', $appli)) {
192
                    if (!preg_match('/' . preg_quote(DOL_VERSION) . '/', $appli))
193
                        $appli .= " (" . DOL_VERSION . ")"; // If new title contains a version that is different than core
194
                } else
195
                    $appli .= " " . DOL_VERSION;
196
            } else
197
                $appli .= " " . DOL_VERSION;
198
199
            if (!empty(Globals::$conf->global->MAIN_FEATURES_LEVEL))
200
                $appli .= "<br>" . Globals::$langs->trans("LevelOfFeature") . ': ' . Globals::$conf->global->MAIN_FEATURES_LEVEL;
201
202
$logouttext = '';
203
            if (empty(Globals::$conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
204
//$logouthtmltext=$appli.'<br>';
205
                if ($_SESSION["dol_authmode"] != 'forceuser' && $_SESSION["dol_authmode"] != 'http') {
206
                    $logouthtmltext .= Globals::$langs->trans("Logout") . '<br>';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $logouthtmltext does not exist. Did you maybe mean $logouttext?
Loading history...
207
208
//$logouttext .='<a accesskey="l" href="'.DOL_BASE_URI.'/user/logout.php">';
209
                    $logouttext .= '<a accesskey="l" href="' . BASE_URI . '?controller=user&method=logout">';
210
//$logouttext .= img_picto(Globals::$langs->trans('Logout').":".Globals::$langs->trans('Logout'), 'logout_top.png', 'class="login"', 0, 0, 1);
211
                    $logouttext .= '<span class="fa fa-sign-out atoplogin"></span>';
212
                    $logouttext .= '</a>';
213
                } else {
214
                    $logouthtmltext .= Globals::$langs->trans("NoLogoutProcessWithAuthMode", $_SESSION["dol_authmode"]);
215
                    $logouttext .= img_picto(Globals::$langs->trans('Logout') . ":" . Globals::$langs->trans('Logout'), 'logout_top.png', 'class="login"', 0, 0, 1);
216
}
217
            }
218
219
            print '<div class="login_block">' . "\n";
220
221
// Add login user link
222
            $toprightmenu .= '<div class="login_block_user">';
223
224
// Login name with photo and tooltip
225
            $mode = -1;
226
            $toprightmenu .= '<div class="inline-block nowrap"><div class="inline-block login_block_elem login_block_elem_name" style="padding: 0px;">';
227
            $toprightmenu .= Globals::$user->getNomUrl($mode, '', 1, 0, 11, 0, (Globals::$user->firstname ? 'firstname' : -1), 'atoplogin');
228
            $toprightmenu .= '</div></div>';
229
230
            $toprightmenu .= '</div>' . "\n";
231
232
            $toprightmenu .= '<div class="login_block_other">';
233
234
// Execute hook printTopRightMenu (hooks should output string like '<div class="login"><a href="">mylink</a></div>')
235
            $parameters = array();
236
            $result = Globals::$hookManager->executeHooks('printTopRightMenu', $parameters);    // Note that $action and $object may have been modified by some hooks
237
            if (is_numeric($result)) {
238
                if ($result == 0)
239
                    $toprightmenu .= Globals::$hookManager->resPrint;  // add
240
                else
241
                    $toprightmenu = Globals::$hookManager->resPrint;      // replace
242
            }
243
            else {
244
                $toprightmenu .= $result; // For backward compatibility
245
            }
246
247
// Link to module builder
248
            if (!empty(Globals::$conf->modulebuilder->enabled)) {
249
//$text = '<a href="' . DOL_BASE_URI . '/modulebuilder/index.php?mainmenu=home&leftmenu=admintools" target="_modulebuilder">';
250
                $text = '<a href="' . BASE_URI . '?controller=modulebuilder&method=index&mainmenu=home&leftmenu=admintools" target="_modulebuilder">';
251
//$text.= img_picto(":".Globals::$langs->trans("ModuleBuilder"), 'printer_top.png', 'class="printer"');
252
                $text .= '<span class="fa fa-bug atoplogin"></span>';
253
                $text .= '</a>';
254
                $toprightmenu .= @Form::textwithtooltip('', Globals::$langs->trans("ModuleBuilder"), 2, 1, $text, 'login_block_elem', 2);
255
            }
256
257
// Link to print main content area
258
            if (empty(Globals::$conf->global->MAIN_PRINT_DISABLELINK) && empty(Globals::$conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && Globals::$conf->browser->layout != 'phone') {
259
                $qs = dol_escape_htmltag($_SERVER["QUERY_STRING"]);
260
261
                if (is_array($_POST)) {
262
                    foreach ($_POST as $key => $value) {
263
                        if ($key !== 'action' && $key !== 'password' && !is_array($value)) {
264
                            $qs .= '&' . $key . '=' . urlencode($value);
265
                        }
266
                    }
267
                }
268
                $qs .= (($qs && $morequerystring) ? '&' : '') . $morequerystring;
269
                $text = '<a href="' . dol_escape_htmltag($_SERVER["PHP_SELF"]) . '?' . $qs . ($qs ? '&' : '') . 'optioncss=print" target="_blank">';
270
//$text.= img_picto(":".Globals::$langs->trans("PrintContentArea"), 'printer_top.png', 'class="printer"');
271
                $text .= '<span class="fa fa-print atoplogin"></span>';
272
                $text .= '</a>';
273
                $toprightmenu .= @Form::textwithtooltip('', Globals::$langs->trans("PrintContentArea"), 2, 1, $text, 'login_block_elem', 2);
274
            }
275
276
// Link to Dolibarr wiki pages
277
            if (empty(Globals::$conf->global->MAIN_HELP_DISABLELINK) && empty(Globals::$conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
278
                Globals::$langs->load("help");
279
280
$helpbaseurl = '';
281
                $helppage = '';
282
                $mode = '';
283
284
                if (empty($helppagename)) {
285
                    $helppagename = 'EN:User_documentation|FR:Documentation_utilisateur|ES:Documentación_usuarios';
286
                }
287
// Get helpbaseurl, helppage and mode from helppagename and langs
288
                $arrayres = getHelpParamFor($helppagename, Globals::$langs);
289
                $helpbaseurl = $arrayres['helpbaseurl'];
290
                $helppage = $arrayres['helppage'];
291
                $mode = $arrayres['mode'];
292
293
// Link to help pages
294
                if ($helpbaseurl && $helppage) {
295
                    $text = '';
296
                    if (!empty(Globals::$conf->global->MAIN_SHOWDATABASENAMEINHELPPAGESLINK)) {
297
                        Globals::$langs->load('admin');
298
$appli .= '<br>' . Globals::$langs->trans("Database") . ': ' . $db->database_name;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $db seems to be never defined.
Loading history...
299
}
300
                    $title = $appli . '<br>';
301
                    $title .= Globals::$langs->trans($mode == 'wiki' ? 'GoToWikiHelpPage' : 'GoToHelpPage');
302
                    if ($mode == 'wiki') {
303
                        $title .= ' - ' . Globals::$langs->trans("PageWiki") . ' &quot;' . dol_escape_htmltag(strtr($helppage, '_', ' ')) . '&quot;';
304
                    }
305
                    $text .= '<a class="help" target="_blank" rel="noopener" href="';
306
                    if ($mode == 'wiki') {
307
                        $text .= sprintf($helpbaseurl, urlencode(html_entity_decode($helppage)));
308
                    } else {
309
                        $text .= sprintf($helpbaseurl, $helppage);
310
                    }
311
                    $text .= '">';
312
//$text.=img_picto('', 'helpdoc_top').' ';
313
                    $text .= '<span class="fa fa-question-circle atoplogin"></span>';
314
//$toprightmenu.=Globals::$langs->trans($mode == 'wiki' ? 'OnlineHelp': 'Help');
315
//if ($mode == 'wiki') $text.=' ('.dol_trunc(strtr($helppage,'_',' '),8).')';
316
                    $text .= '</a>';
317
//$toprightmenu.='</div>'."\n";
318
                    $toprightmenu .= @Form::textwithtooltip('', $title, 2, 1, $text, 'login_block_elem', 2);
319
                }
320
            }
321
322
// Logout link
323
            $toprightmenu .= @Form::textwithtooltip('', $logouthtmltext, 2, 1, $logouttext, 'login_block_elem', 2);
324
325
            $toprightmenu .= '</div>';
326
327
            print $toprightmenu;
328
329
            print "</div>\n";  // end div class="login_block"
330
331
            print '</div></div>';
332
333
            print '<div style="clear: both;"></div>';
334
            print "<!-- End top horizontal menu -->\n\n";
335
        }
336
337
        if (empty(Globals::$conf->dol_hide_leftmenu) && empty(Globals::$conf->dol_use_jmobile))
338
            print '<!-- Begin div id-container --><div id="id-container" class="id-container' . ($morecss ? ' ' . $morecss : '') . '">';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $morecss seems to be never defined.
Loading history...
339
    }
340
341
    /**
342
     *  Show left menu bar
343
     *
344
     *  @param  array	$menu_array_before 	       	Table of menu entries to show before entries of menu handler. This param is deprectaed and must be provided to ''.
345
     *  @param  string	$helppagename    	       	Name of wiki page for help ('' by default).
346
     * 				     		                   	Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
347
     * 									         	For other external page: http://server/url
348
     *  @param  string	$notused             		Deprecated. Used in past to add content into left menu. Hooks can be used now.
349
     *  @param  array	$menu_array_after           Table of menu entries to show after entries of menu handler
350
     *  @param  int		$leftmenuwithoutmainarea    Must be set to 1. 0 by default for backward compatibility with old modules.
351
     *  @param  string	$title                      Title of web page
352
     *  @param  string  $acceptdelayedhtml          1 if caller request to have html delayed content not returned but saved into global $delayedhtmlcontent (so caller can show it at end of page to avoid flash FOUC effect)
353
     *  @return	void
354
     */
355
    function left_menu($menu_array_before, $helppagename = '', $notused = '', $menu_array_after = '', $leftmenuwithoutmainarea = 0, $title = '', $acceptdelayedhtml = 0)
356
    {
357
// global Globals::$user, Globals::$conf, Globals::$langs, $db, $form;
358
// global Globals::$hookManager, $menumanager;
359
360
        $searchform = '';
361
        $bookmarks = '';
362
363
        if (!empty($menu_array_before))
364
            dol_syslog("Deprecated parameter menu_array_before was used when calling main::left_menu function. Menu entries of module should now be defined into module descriptor and not provided when calling left_menu.", LOG_WARNING);
365
366
        if (empty(Globals::$conf->dol_hide_leftmenu) && (!defined('NOREQUIREMENU') || !constant('NOREQUIREMENU'))) {
367
// Instantiate hooks of thirdparty module
368
            Globals::$hookManager->initHooks(array('searchform', 'leftblock'));
369
370
            print "\n" . '<!-- Begin side-nav id-left -->' . "\n" . '<div class="side-nav"><div id="id-left">' . "\n";
371
372
            if (Globals::$conf->browser->layout == 'phone')
373
                Globals::$conf->global->MAIN_USE_OLD_SEARCH_FORM = 1; // Select into select2 is awfull on smartphone. TODO Is this still true with select2 v4 ?
374
375
print "\n";
376
377
            if (!is_object($form)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $form seems to be never defined.
Loading history...
378
                $form = new Form($db);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $db seems to be never defined.
Loading history...
379
            }
380
            $selected = -1;
381
            $usedbyinclude = 1;
382
            include_once DOL_BASE_PATH . '/core/ajax/selectsearchbox.php'; // This set $arrayresult
383
384
            if (Globals::$conf->use_javascript_ajax && empty(Globals::$conf->global->MAIN_USE_OLD_SEARCH_FORM)) {
385
//$searchform.=$form->selectArrayAjax('searchselectcombo', DOL_BASE_URI.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'vmenusearchselectcombo', 1, Globals::$langs->trans("Search"), 1);
386
$searchform .= $form->selectArrayFilter('searchselectcombo', $arrayresult, $selected, '', 1, 0, (empty(Globals::$conf->global->MAIN_SEARCHBOX_CONTENT_LOADED_BEFORE_KEY) ? 1 : 0), 'vmenusearchselectcombo', 1, Globals::$langs->trans("Search"), 1);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $arrayresult seems to be never defined.
Loading history...
387
} else {
388
                foreach ($arrayresult as $key => $val) {
389
//$searchform.=printSearchForm($val['url'], $val['url'], $val['label'], 'maxwidth100', 'sall', $val['shortcut'], 'searchleft', img_picto('',$val['img']));
390
                    $searchform .= printSearchForm($val['url'], $val['url'], $val['label'], 'maxwidth125', 'sall', $val['shortcut'], 'searchleft', img_picto('', $val['img'], '', false, 1, 1));
391
                }
392
            }
393
394
// Execute hook printSearchForm
395
            $parameters = array('searchform' => $searchform);
396
397
            $reshook = Globals::$hookManager->executeHooks('printSearchForm', $parameters);    // Note that $action and $object may have been modified by some hooks
398
            if (empty($reshook)) {
399
                $searchform .= Globals::$hookManager->resPrint;
400
            } else
401
                $searchform = Globals::$hookManager->resPrint;
402
403
// Force special value for $searchform
404
            if (!empty(Globals::$conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) || empty(Globals::$conf->use_javascript_ajax)) {
405
                $urltosearch = DOL_BASE_URI . '/core/search_page.php?showtitlebefore=1';
406
                $searchform = '<div class="blockvmenuimpair blockvmenusearchphone"><div id="divsearchforms1"><a href="' . $urltosearch . '" alt="' . dol_escape_htmltag(Globals::$langs->trans("ShowSearchFields")) . '">' . Globals::$langs->trans("Search") . '...</a></div></div>';
407
            } elseif (Globals::$conf->use_javascript_ajax &&!empty(Globals::$conf->global->MAIN_USE_OLD_SEARCH_FORM)) {
408
$searchform = '<div class="blockvmenuimpair blockvmenusearchphone"><div id="divsearchforms1"><a href="#" alt="' . dol_escape_htmltag(Globals::$langs->trans("ShowSearchFields")) . '">' . Globals::$langs->trans("Search") . '...</a></div><div id="divsearchforms2" style="display: none">' . $searchform . '</div>';
409
$searchform .= '<script type="text/javascript">
410
            	jQuery(document).ready(function () {
411
            		jQuery("#divsearchforms1").click(function(){
412
	                   jQuery("#divsearchforms2").toggle();
413
	               });
414
            	});
415
                </script>' . "\n";
416
                $searchform .= '</div>';
417
            }
418
419
// Define $bookmarks
420
            if (!empty(Globals::$conf->bookmark->enabled) && Globals::$user->rights->bookmark->lire) {
421
                include_once DOL_BASE_PATH . '/bookmarks/bookmarks.lib.php';
422
                Globals::$langs->load("bookmarks");
423
424
                $bookmarks = printBookmarksList($db, Globals::$langs);
425
}
426
427
// Left column
428
            print '<!-- Begin left menu -->' . "\n";
429
430
            print '<div class="vmenu"' . (empty(Globals::$conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '' : ' title="Left menu"') . '>' . "\n\n";
431
432
// Show left menu with other forms
433
            $this->menumanager->menu_array = $menu_array_before;
434
            $this->menumanager->menu_array_after = $menu_array_after;
435
            $this->menumanager->showmenu('left', array('searchform' => $searchform, 'bookmarks' => $bookmarks)); // output menu_array and menu found in database
436
// Dolibarr version + help + bug report link
437
            print "\n";
438
            print "<!-- Begin Help Block-->\n";
439
            print '<div id="blockvmenuhelp" class="blockvmenuhelp">' . "\n";
440
441
// Version
442
            if (empty(Globals::$conf->global->MAIN_HIDE_VERSION)) {    // Version is already on help picto and on login page.
443
                $doliurl = 'https://www.dolibarr.org';
444
//local communities
445
                if (preg_match('/fr/i', Globals::$langs->defaultlang))
446
                    $doliurl = 'https://www.dolibarr.fr';
447
                if (preg_match('/es/i', Globals::$langs->defaultlang))
448
                    $doliurl = 'https://www.dolibarr.es';
449
                if (preg_match('/de/i', Globals::$langs->defaultlang))
450
                    $doliurl = 'https://www.dolibarr.de';
451
                if (preg_match('/it/i', Globals::$langs->defaultlang))
452
                    $doliurl = 'https://www.dolibarr.it';
453
                if (preg_match('/gr/i', Globals::$langs->defaultlang))
454
                    $doliurl = 'https://www.dolibarr.gr';
455
456
                $appli = constant('DOL_APPLICATION_TITLE');
457
                if (!empty(Globals::$conf->global->MAIN_APPLICATION_TITLE)) {
458
                    $appli = Globals::$conf->global->MAIN_APPLICATION_TITLE;
459
$doliurl = '';
460
                    if (preg_match('/\d\.\d/', $appli)) {
461
                        if (!preg_match('/' . preg_quote(DOL_VERSION) . '/', $appli))
462
                            $appli .= " (" . DOL_VERSION . ")"; // If new title contains a version that is different than core
463
                    } else
464
                        $appli .= " " . DOL_VERSION;
465
                } else
466
                    $appli .= " " . DOL_VERSION;
467
                print '<div id="blockvmenuhelpapp" class="blockvmenuhelp">';
468
                if ($doliurl)
469
                    print '<a class="help" target="_blank" rel="noopener" href="' . $doliurl . '">';
470
                else
471
                    print '<span class="help">';
472
                print $appli;
473
                if ($doliurl)
474
                    print '</a>';
475
                else
476
                    print '</span>';
477
                print '</div>' . "\n";
478
            }
479
480
// Link to bugtrack
481
            if (!empty(Globals::$conf->global->MAIN_BUGTRACK_ENABLELINK)) {
482
                require_once DOL_BASE_PATH . '/core/lib/functions2.lib.php';
483
484
                $bugbaseurl = 'https://github.com/Dolibarr/dolibarr/issues/new';
485
                $bugbaseurl .= '?title=';
486
                $bugbaseurl .= urlencode("Bug: ");
487
                $bugbaseurl .= '&body=';
488
                $bugbaseurl .= urlencode("# Bug\n");
489
                $bugbaseurl .= urlencode("\n");
490
                $bugbaseurl .= urlencode("## Environment\n");
491
                $bugbaseurl .= urlencode("- **Version**: " . DOL_VERSION . "\n");
492
                $bugbaseurl .= urlencode("- **OS**: " . php_uname('s') . "\n");
493
                $bugbaseurl .= urlencode("- **Web server**: " . $_SERVER["SERVER_SOFTWARE"] . "\n");
494
                $bugbaseurl .= urlencode("- **PHP**: " . php_sapi_name() . ' ' . phpversion() . "\n");
495
                $bugbaseurl .= urlencode("- **Database**: " . $db::LABEL . ' ' . $db->getVersion() . "\n");
496
                $bugbaseurl .= urlencode("- **URL**: " . $_SERVER["REQUEST_URI"] . "\n");
497
                $bugbaseurl .= urlencode("\n");
498
                $bugbaseurl .= urlencode("## Report\n");
499
                print '<div id="blockvmenuhelpbugreport" class="blockvmenuhelp">';
500
                print '<a class="help" target="_blank" rel="noopener" href="' . $bugbaseurl . '">' . Globals::$langs->trans("FindBug") . '</a>';
501
                print '</div>';
502
            }
503
504
            print "</div>\n";
505
            print "<!-- End Help Block-->\n";
506
            print "\n";
507
508
            print "</div>\n";
509
            print "<!-- End left menu -->\n";
510
            print "\n";
511
512
// Execute hook printLeftBlock
513
            $parameters = array();
514
            $reshook = Globals::$hookManager->executeHooks('printLeftBlock', $parameters);    // Note that $action and $object may have been modified by some hooks
515
            print Globals::$hookManager->resPrint;
516
517
            print '</div></div> <!-- End side-nav id-left -->'; // End div id="side-nav" div id="id-left"
518
        }
519
520
        print "\n";
521
        print '<!-- Begin right area -->' . "\n";
522
523
        if (empty($leftmenuwithoutmainarea))
524
            main_area($title);
525
    }
526
527
    /**
528
     *  Begin main area
529
     *
530
     *  @param	string	$title		Title
531
     *  @return	void
532
     */
533
    function main_area($title = '')
534
    {
535
// global Globals::$conf, Globals::$langs;
536
537
        if (empty(Globals::$conf->dol_hide_leftmenu))
538
    print '<div id="id-right">';
539
540
        print "\n";
541
542
        print '<!-- Begin div class="fiche" -->' . "\n" . '<div class="fiche">' . "\n";
543
544
        if (!empty(Globals::$conf->global->MAIN_ONLY_LOGIN_ALLOWED))
545
            print info_admin(Globals::$langs->trans("WarningYouAreInMaintenanceMode", Globals::$conf->global->MAIN_ONLY_LOGIN_ALLOWED));
546
}
547
548
    /**
549
     *  Return helpbaseurl, helppage and mode
550
     *
551
     *  @param	string		$helppagename		Page name ('EN:xxx,ES:eee,FR:fff...' or 'http://localpage')
552
     *  @param  Translate	Globals::$langs				Language
553
     *  @return	array		Array of help urls
554
     */
555
    function getHelpParamFor($helppagename, $langs)
556
    {
557
        $helpbaseurl = '';
558
        $helppage = '';
559
        $mode = '';
560
561
        if (preg_match('/^http/i', $helppagename)) {
562
// If complete URL
563
            $helpbaseurl = '%s';
564
            $helppage = $helppagename;
565
            $mode = 'local';
566
        } else {
567
// If WIKI URL
568
            if (preg_match('/^es/i', Globals::$langs->defaultlang)) {
569
                $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s';
570
                if (preg_match('/ES:([^|]+)/i', $helppagename, $reg))
571
                    $helppage = $reg[1];
572
            }
573
            if (preg_match('/^fr/i', Globals::$langs->defaultlang)) {
574
                $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s';
575
                if (preg_match('/FR:([^|]+)/i', $helppagename, $reg))
576
                    $helppage = $reg[1];
577
            }
578
            if (empty($helppage)) { // If help page not already found
579
                $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s';
580
                if (preg_match('/EN:([^|]+)/i', $helppagename, $reg))
581
                    $helppage = $reg[1];
582
            }
583
            $mode = 'wiki';
584
        }
585
        return array('helpbaseurl' => $helpbaseurl, 'helppage' => $helppage, 'mode' => $mode);
586
    }
587
588
    /**
589
     *  Show a search area.
590
     *  Used when the javascript quick search is not used.
591
     *
592
     *  @param  string	$urlaction          Url post
593
     *  @param  string	$urlobject          Url of the link under the search box
594
     *  @param  string	$title              Title search area
595
     *  @param  string	$htmlmorecss        Add more css
596
     *  @param  string	$htmlinputname      Field Name input form
597
     *  @param	string	$accesskey			Accesskey
598
     *  @param  string  $prefhtmlinputname  Complement for id to avoid multiple same id in the page
599
     *  @param	string	$img				Image to use
600
     *  @param	string	$showtitlebefore	Show title before input text instead of into placeholder. This can be set when output is dedicated for text browsers.
601
     *  @return	string
602
     */
603
    function printSearchForm($urlaction, $urlobject, $title, $htmlmorecss, $htmlinputname, $accesskey = '', $prefhtmlinputname = '', $img = '', $showtitlebefore = 0)
604
    {
605
        // global Globals::$conf, Globals::$langs, Globals::$user;
606
607
        $ret = '';
608
        $ret .= '<form action="' . $urlaction . '" method="post" class="searchform">';
609
        $ret .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
610
        $ret .= '<input type="hidden" name="mode" value="search">';
611
        $ret .= '<input type="hidden" name="savelogin" value="' . dol_escape_htmltag(Globals::$user->login) . '">';
612
        if ($showtitlebefore)
613
            $ret .= $title . ' ';
614
        $ret .= '<input type="text" class="flat ' . $htmlmorecss . '"';
615
        $ret .= ' style="text-indent: 22px; background-image: url(\'' . $img . '\'); background-repeat: no-repeat; background-position: 3px;"';
616
        $ret .= ($accesskey ? ' accesskey="' . $accesskey . '"' : '');
617
        $ret .= ' placeholder="' . strip_tags($title) . '"';
618
        $ret .= ' name="' . $htmlinputname . '" id="' . $prefhtmlinputname . $htmlinputname . '" />';
619
//$ret.='<input type="submit" class="button" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px" value="'.Globals::$langs->trans("Go").'">';
620
        $ret .= '<button type="submit" class="button" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px">';
621
        $ret .= '<span class="fa fa-search"></span>';
622
        $ret .= '</button>';
623
        $ret .= "</form>\n";
624
        return $ret;
625
    }
626
627
    /**
628
     * Show HTML footer
629
     * Close div /DIV class=fiche + /DIV id-right + /DIV id-container + /BODY + /HTML.
630
     * If global var $delayedhtmlcontent was filled, we output it just before closing the body.
631
     *
632
     * @param	string	$comment    				A text to add as HTML comment into HTML generated page
633
     * @param	string	$zone						'private' (for private pages) or 'public' (for public pages)
634
     * @param	int		$disabledoutputofmessages	Clear all messages stored into session without diplaying them
635
     * @return	void
636
     */
637
    function llxFooter($comment = '', $zone = 'private', $disabledoutputofmessages = 0)
638
    {
639
        // global Globals::$conf, Globals::$langs, Globals::$user, $object;
640
        // global $delayedhtmlcontent;
641
        // global $contextpage, $page, $limit;
642
643
        $ext = 'layout=' . Globals::$conf->browser->layout . '&version=' . urlencode(DOL_VERSION);
644
645
// Global html output events ($mesgs, $errors, $warnings)
646
        dol_htmloutput_events($disabledoutputofmessages);
647
648
// Code for search criteria persistence.
649
// Globals::$user->lastsearch_values was set by the GETPOST when form field search_xxx exists
650
        if (is_object(Globals::$user) && !empty(Globals::$user->lastsearch_values_tmp) && is_array(Globals::$user->lastsearch_values_tmp)) {
651
// Clean and save data
652
            foreach (Globals::$user->lastsearch_values_tmp as $key => $val) {
653
                unset($_SESSION['lastsearch_values_tmp_' . $key]);   // Clean array to rebuild it just after
654
                if (count($val) && empty($_POST['button_removefilter'])) { // If there is search criteria to save and we did not click on 'Clear filter' button
655
                    if (empty($val['sortfield']))
656
                        unset($val['sortfield']);
657
                    if (empty($val['sortorder']))
658
                        unset($val['sortorder']);
659
                    dol_syslog('Save lastsearch_values_tmp_' . $key . '=' . json_encode($val, 0) . " (systematic recording of last search criterias)");
660
                    $_SESSION['lastsearch_values_tmp_' . $key] = json_encode($val);
661
                    unset($_SESSION['lastsearch_values_' . $key]);
662
                }
663
            }
664
        }
665
666
667
        $relativepathstring = $_SERVER["PHP_SELF"];
668
// Clean $relativepathstring
669
        if (constant('DOL_BASE_URI'))
670
            $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_BASE_URI'), '/') . '/', '', $relativepathstring);
671
        $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
672
        $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
673
        if (preg_match('/list\.php$/', $relativepathstring)) {
674
            unset($_SESSION['lastsearch_contextpage_tmp_' . $relativepathstring]);
675
            unset($_SESSION['lastsearch_page_tmp_' . $relativepathstring]);
676
            unset($_SESSION['lastsearch_limit_tmp_' . $relativepathstring]);
677
678
            if (!empty($contextpage))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $contextpage seems to never exist and therefore empty should always be true.
Loading history...
679
                $_SESSION['lastsearch_contextpage_tmp_' . $relativepathstring] = $contextpage;
680
            if (!empty($page) && $page > 1)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $page seems to never exist and therefore empty should always be true.
Loading history...
681
                $_SESSION['lastsearch_page_tmp_' . $relativepathstring] = $page;
682
            if (!empty($limit) && $limit != Globals::$conf->limit)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $limit seems to never exist and therefore empty should always be true.
Loading history...
683
                $_SESSION['lastsearch_limit_tmp_' . $relativepathstring] = $limit;
684
685
            unset($_SESSION['lastsearch_contextpage_' . $relativepathstring]);
686
            unset($_SESSION['lastsearch_page_' . $relativepathstring]);
687
            unset($_SESSION['lastsearch_limit_' . $relativepathstring]);
688
        }
689
690
// Core error message
691
        if (!empty(Globals::$conf->global->MAIN_CORE_ERROR)) {
692
// Ajax version
693
            if (Globals::$conf->use_javascript_ajax) {
694
                $title = img_warning() . ' ' . Globals::$langs->trans('CoreErrorTitle');
695
print ajax_dialog($title, Globals::$langs->trans('CoreErrorMessage'));
0 ignored issues
show
Bug introduced by
Are you sure the usage of ajax_dialog($title, Alix...ns('CoreErrorMessage')) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
696
}
697
// html version
698
            else {
699
                $msg = img_warning() . ' ' . Globals::$langs->trans('CoreErrorMessage');
700
                print '<div class="error">' . $msg . '</div>';
701
            }
702
703
//define("MAIN_CORE_ERROR",0);      // Constant was defined and we can't change value of a constant
704
        }
705
706
        print "\n\n";
707
708
        print '</div> <!-- End div class="fiche" -->' . "\n"; // End div fiche
709
710
        if (empty(Globals::$conf->dol_hide_leftmenu))
711
            print '</div> <!-- End div id-right -->' . "\n"; // End div id-right
712
713
        if (empty(Globals::$conf->dol_hide_leftmenu) && empty(Globals::$conf->dol_use_jmobile))
714
            print '</div> <!-- End div id-container -->' . "\n"; // End div container
715
716
        print "\n";
717
        if ($comment)
718
            print '<!-- ' . $comment . ' -->' . "\n";
719
720
        printCommonFooter($zone);
721
722
        if (!empty($delayedhtmlcontent))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $delayedhtmlcontent seems to never exist and therefore empty should always be true.
Loading history...
723
            print $delayedhtmlcontent;
724
725
        if (!empty(Globals::$conf->use_javascript_ajax)) {
726
            print "\n" . '<!-- Includes JS Footer of Dolibarr -->' . "\n";
727
            print '<script type="text/javascript" src="' . BASE_URI . '?controller=core/js/&method=lib_foot.js&lang=' . Globals::$langs->defaultlang . ($ext ? '&' . $ext : '') . '"></script>' . "\n";
728
        }
729
730
// Wrapper to add log when clicking on download or preview
731
        if (!empty(Globals::$conf->blockedlog->enabled) && is_object($object) && $object->id > 0 && $object->statut > 0) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $object seems to be never defined.
Loading history...
732
            if (in_array($object->element, array('facture'))) {       // Restrict for the moment to element 'facture'
733
                print "\n<!-- JS CODE TO ENABLE log when making a download or a preview of a document -->\n";
734
735
                ?>
736
                <script type="text/javascript">
737
                    jQuery(document).ready(function () {
738
                        $('a.documentpreview').click(function () {
739
                            $.post('<?php echo DOL_BASE_URI . "/blockedlog/ajax/block-add.php" ?>'
740
                                    , {
741
                                        id:<?php echo $object->id; ?>
742
                                        , element: '<?php echo $object->element ?>'
743
                                        , action: 'DOC_PREVIEW'
744
                                    }
745
                            );
746
                        });
747
                        $('a.documentdownload').click(function () {
748
                            $.post('<?php echo DOL_BASE_URI . "/blockedlog/ajax/block-add.php" ?>'
749
                                    , {
750
                                        id:<?php echo $object->id; ?>
751
                                        , element: '<?php echo $object->element ?>'
752
                                        , action: 'DOC_DOWNLOAD'
753
                                    }
754
                            );
755
                        });
756
                    });
757
                </script>
758
                <?php
759
            }
760
        }
761
762
// A div for the address popup
763
        print "\n<!-- A div to allow dialog popup -->\n";
764
        print '<div id="dialogforpopup" style="display: none;"></div>' . "\n";
765
766
        print "</body>\n";
767
768
        print "<!-- Alixar debugBar footer -->";
769
        print Debug::getRenderFooter(); // Includes Alixar debugBar footer
770
771
        print "</html>\n";
772
    }
773
}
774