Completed
Push — master ( c9e75c...9f5802 )
by Patrick
12:31 queued 10:30
created

class.FlipAdminPage.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
require_once('class.LoginRequiredPage.php');
3
4
class FlipAdminPage extends LoginRequiredPage
5
{
6
    public $user;
7
    public $is_admin = false;
8
9
    public function __construct($title, $adminGroup = 'LDAPAdmins')
10
    {
11
        $this->user = FlipSession::getUser();
12
        $this->is_admin = $this->userIsAdmin($adminGroup);
13
        parent::__construct($title);
14
        $adminCSS = '/css/common/admin.min.css';
15
        if($this->minified !== 'min')
16
        {
17
            $adminCSS = '/css/common/admin.css';
18
        }
19
        $this->addCSSByURI($adminCSS);
20
        $this->addWellKnownJS(JS_METISMENU, false);
21
    }
22
23 View Code Duplication
    protected function userIsAdmin($adminGroup)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        if($this->user === false || $this->user === null)
26
        {
27
            return false;
28
        }
29
        return $this->user->isInGroupNamed($adminGroup);
30
    }
31
32
    protected function addAllLinks()
33
    {
34
        if($this->user === false || $this->user === null)
35
        {
36
            $this->addLink('<i class="fa fa-sign-in"></i> Login', $this->loginUrl);
37
        }
38
        else
39
        {
40
            $this->add_links();
41
            $this->addLink('<i class="fa fa-sign-out"></i> Logout', $this->logoutUrl);
42
        }
43
    }
44
45
    protected function getDropdown($link, $name)
46
    {
47
        $ret  = '<li class="nav-item">';
48
        $href = $this->getHrefForDropdown($link);
49
        $ret .= $this->createLink($name.' <i class="fa fa-arrow-right"></i>', $href);
50
        $ret .= '<ul>';
51
        $subNames = array_keys($link);
52
        foreach($subNames as $subName)
53
        {
54
            $ret .= $this->getLinkByName($subName, $link);
55
        }
56
        $ret .= '</ul></li>';
57
        return $ret;
58
    }
59
60
    protected function addHeader()
61
    {
62
        $sites   = $this->getSiteLinksForHeader();
63
        $sideNav = $this->getLinksMenus();
64
        $log     = '<a href="'.$this->logoutUrl.'" class="nav-link"><i class="fa fa-sign-out"></i></a>';
65
        if($this->user === false || $this->user === null)
66
        {
67
            $log = '<a href="'.$this->loginUrl.'?return='.$this->currentUrl().'" class="nav-link"><i class="fa fa-sign-in"></i></a>';
68
        }
69
        $this->body = '<div id="wrapper">
70
                  <nav class="navbar navbar-expand-lg navbar-light bg-light" role="navigation" style="margin-bottom: 0">
71
                      <a class="navbar-brand" href="index.php">'.$this->title.'</a>
72
                      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
73
                          <span class="navbar-toggler-icon"></span>
74
                      </button>
75
                      <div class="collapse navbar-collapse" id="navbarSupportedContent">
76
                        <ul class="navbar-nav mr-auto"></ul>
77
                        <ul class="navbar-nav navbar-right">
78
                          <li class="nav-item">
79
                            <a href=".." class="nav-link">
80
                              <i class="fa fa-home"></i>
81
                            </a>
82
                          </li>
83
                          <li class="nav-item">
84
                            '.$log.'
85
                          </li>
86
                          <li class="nav-item dropdown">
87
                              <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">
88
                                  <i class="fa fa-link"></i>
89
                                  <b class="caret"></b>
90
                              </a>
91
                              <ul class="dropdown-menu dropdown-menu-right">
92
                                  '.$sites.'
93
                              </ul>
94
                          </li>
95
                        </ul>
96
                      </div>
97
                  </nav>
98
                  <div class="row flex-xl-nowrap">
99
                    <div class="col-12 col-md-3 col-xl-2 bd-sidebar">
100
                      <nav class="collapse bd-links" id="navSide">
101
                        <ul class="nav flex-column" id="side-menu">
102
                                  '.$sideNav.'
103
                        </ul>
104
                      </nav>
105
                    </div>
106
                  <main id="page-wrapper" class="col-12 col-md-9 col-xl-8 py-md-3 pl-md-5" role="main">'.$this->body.'</main></div>';
107
    }
108
109
    const CARD_GREEN  = 'bg-success';
110
    const CARD_BLUE   = 'bg-primary';
111
    const CARD_YELLOW = 'bg-warning';
112
    const CARD_RED    = 'bg-danger';
113
114
    public function add_card($iconName, $bigText, $littleText, $link = '#', $color = self::CARD_BLUE)
115
    {
116
        $card = '<div class="col-lg-3 col-md-6 text-white">
117
                     <div class="card '.$color.'">
118
                         <div class="card-header">
119
                             <div class="row">
120
                                 <div class="col-xs-3">
121
                                     <i class="fa '.$iconName.'" style="font-size: 5em;"></i>
122
                                 </div>
123
                                 <div class="col-xs-9 text-right">
124
                                     <div style="font-size: 40px;">'.$bigText.'</div>
125
                                     <div>'.$littleText.'</div>
126
                                 </div>
127
                             </div>
128
                         </div>
129
                         <a class="text-white card-link" href="'.$link.'">
130
                         <div class="card-footer">
131
                             <span class="pull-left">View Details</span>
132
                             <span class="pull-right fa fa-arrow-circle-right"></span>
133
                             <div class="clearfix"></div>
134
                         </div>
135
                         </a>
136
                     </div>
137
                 </div>';
138
        $this->body .= $card;
139
    }
140
141
    public function isAdmin()
142
    {
143
        return $this->is_admin;
144
    }
145
146
    public function printPage($header = true)
147
    {
148
        if($this->isAdmin() === false)
149
        {
150
            $this->body = '
151
        <div class="row">
152
            <div class="col-lg-12">
153
                <h1 class="page-header">The current user does not have access rights to the '.$this->title.' Admin system!</h1>
154
            </div>
155
        </div>';
156
        }
157
        parent::printPage($header);
158
    }
159
}
160
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
161