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

LoginView::vars()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 11
rs 9.9666
c 0
b 0
f 0
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\Views;
18
19
use Alxarafe\Helpers\Skin;
20
use Alixar\Helpers\Globals;
21
use Alixar\Helpers\DolUtils;
22
use Alixar\Helpers\DolUtils2;
23
24
// require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
25
26
class LoginView extends \Alixar\Base\AlixarBasicView
27
{
28
29
    public $backgroundImage;
30
    public $mainLoginBackgroundImage;
31
    public $useJMobile;
32
    public $focusElement;
33
    public $url;
34
    public $token;
35
    public $hideTopmenu;
36
    public $hideLeftmenu;
37
    public $optimizeSmallscreen;
38
    public $noMouseHover;
39
40
    public function __construct($ctrl)
41
    {
42
        parent::__construct($ctrl);
43
        $this->draw();
44
        $this->vars();
45
        Skin::setTemplate('login');
46
    }
47
48
    public function vars()
49
    {
50
        $this->backgroundImage = Globals::$conf->global->ADD_UNSPLASH_LOGIN_BACKGROUND ?? null;
51
        $this->mainLoginBackgroundImage = Globals::$conf->global->MAIN_LOGIN_BACKGROUND ?? 'img/logo.';
52
        $this->focusElement = $focus_element ?? false;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $focus_element seems to never exist and therefore isset should always be false.
Loading history...
53
        $this->token = $_SESSION['newtoken'];
54
        $this->hideTopmenu = DolUtils::GETPOST('dol_hide_topmenu', 'int', 3);
55
        $this->hideLeftmenu = DolUtils::GETPOST('dol_hide_leftmenu', 'int', 3);
56
        $this->optimizeSmallscreen = DolUtils::GETPOST('dol_optimize_smallscreen', 'int', 3);
57
        $this->noMouseHover = DolUtils::GETPOST('dol_no_mouse_hover', 'int', 3);
58
        $this->useJMobile = DolUtils::GETPOST('dol_use_jmobile', 'int', 3) ?? Globals::$conf->dol_use_jmobile ?? false;
59
    }
60
61
    public function draw()
62
    {
63
        header('Cache-Control: Public, must-revalidate');
64
        header("Content-type: text/html; charset=" . Globals::$conf->file->character_set_client);
65
66
// Need global variable $title to be defined by caller (like dol_loginfunction)
67
// Caller can also set 	$morelogincontent = array(['options']=>array('js'=>..., 'table'=>...);
68
// Protection to avoid direct call of template
69
        if (empty(Globals::$conf) || !is_object(Globals::$conf)) {
70
            print "Error, template page can't be called as URL";
71
            exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
72
        }
73
74
75
        if (DolUtils::GETPOST('dol_hide_topmenu')) {
76
            Globals::$conf->dol_hide_topmenu = 1;
77
        }
78
        if (DolUtils::GETPOST('dol_hide_leftmenu')) {
79
            Globals::$conf->dol_hide_leftmenu = 1;
80
        }
81
        if (DolUtils::GETPOST('dol_optimize_smallscreen')) {
82
            Globals::$conf->dol_optimize_smallscreen = 1;
83
        }
84
        if (DolUtils::GETPOST('dol_no_mouse_hover')) {
85
            Globals::$conf->dol_no_mouse_hover = 1;
86
        }
87
        if (DolUtils::GETPOST('dol_use_jmobile')) {
88
            Globals::$conf->dol_use_jmobile = 1;
89
        }
90
91
// If we force to use jmobile, then we reenable javascript
92
        if (!empty(Globals::$conf->dol_use_jmobile)) {
93
            Globals::$conf->use_javascript_ajax = 1;
94
        }
95
96
        $php_self = DolUtils::dol_escape_htmltag($_SERVER['PHP_SELF']);
97
        $php_self .= DolUtils::dol_escape_htmltag($_SERVER["QUERY_STRING"]) ? '?' . DolUtils::dol_escape_htmltag($_SERVER["QUERY_STRING"]) : '';
98
        if (!preg_match('/mainmenu=/', $php_self)) {
99
            $php_self .= (preg_match('/\?/', $php_self) ? '&' : '?') . 'mainmenu=home';
100
        }
101
102
        $this->url = $php_self;
103
104
105
// Javascript code on logon page only to detect user tz, dst_observed, dst_first, dst_second
106
        /*
107
          $arrayofjs=array(
108
          '/includes/jstz/jstz.min.js'.(empty(Globals::$conf->dol_use_jmobile)?'':'?version='.urlencode(DOL_VERSION)),
109
          '/core/js/dst.js'.(empty(Globals::$conf->dol_use_jmobile)?'':'?version='.urlencode(DOL_VERSION))
110
          );
111
         */
112
        $arrayofjs = array(
113
            DOL_BASE_URI . '/includes/jstz/jstz.min.js' . (empty(Globals::$conf->dol_use_jmobile) ? '' : '?version=' . urlencode(DOL_VERSION)),
114
            DOL_BASE_URI . '/core/js/dst.js' . (empty(Globals::$conf->dol_use_jmobile) ? '' : '?version=' . urlencode(DOL_VERSION))
115
        );
116
117
        // $titletruedolibarrversion is defined by dol_loginfunction in security2.lib.php.
118
        // We must keep the @, some tools use it to know it is login page and find true dolibarr version.
119
        // $titleofloginpage = Globals::$langs->trans('Login') . ' @ ' . $titletruedolibarrversion;
120
        $titleofloginpage = Globals::$langs->trans('Login') . ' @ ' . DOL_VERSION;
121
122
        $disablenofollow = 1;
123
        if (!preg_match('/' . constant('DOL_APPLICATION_TITLE') . '/', $this->title)) {
124
            $disablenofollow = 0;
125
        }
126
127
        print $this->top_htmlhead('', $titleofloginpage, 0, 0, $arrayofjs, array(), 0, $disablenofollow);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->top_htmlhead('', ...), 0, $disablenofollow) targeting Alixar\Base\AlixarBasicView::top_htmlhead() 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...
128
129
130
        $colorbackhmenu1 = '60,70,100';      // topmenu
131
        if (!isset(Globals::$conf->global->THEME_ELDY_TOPMENU_BACK1)) {
132
            Globals::$conf->global->THEME_ELDY_TOPMENU_BACK1 = $colorbackhmenu1;
133
        }
134
        $colorbackhmenu1 = empty($user->conf->THEME_ELDY_ENABLE_PERSONALIZED) ? (empty(Globals::$conf->global->THEME_ELDY_TOPMENU_BACK1) ? $colorbackhmenu1 : Globals::$conf->global->THEME_ELDY_TOPMENU_BACK1) : (empty($user->conf->THEME_ELDY_TOPMENU_BACK1) ? $colorbackhmenu1 : $user->conf->THEME_ELDY_TOPMENU_BACK1);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $user seems to be never defined.
Loading history...
135
        $colorbackhmenu1 = join(',', DolUtils2::colorStringToArray($colorbackhmenu1));    // Normalize value to 'x,y,z'
136
    }
137
}
138