Completed
Push — master ( f5f8b9...bcfe8b )
by Patrick
15s
created

FlipAdminPage   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 7
Bugs 4 Features 0
Metric Value
c 7
b 4
f 0
dl 0
loc 157
rs 10
wmc 18
lcom 2
cbo 2

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A userIsAdmin() 0 8 3
B addHeader() 0 45 3
A addAllLinks() 0 12 3
B printPage() 0 22 4
B add_card() 0 26 1
A getDropdown() 0 14 2
1
<?php
2
require_once('class.FlipPage.php');
3
4
class FlipAdminPage extends FlipPage
5
{
6
    public $user;
7
    public $is_admin = false;
8
9
    function __construct($title, $adminGroup = 'LDAPAdmins')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
    protected function userIsAdmin($adminGroup)
24
    {
25
        if($this->user === false || $this->user === null)
26
        {
27
            return false;
28
        }
29
        return $this->user->isInGroupNamed($adminGroup);
30
    }
31
32
    function addAllLinks()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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>';
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
    function addHeader()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
61
    {
62
        $sites   = $this->getSiteLinksForHeader();
63
        $sideNav = $this->getLinksMenus();
64
        $log     = '<a href="https://profiles.burningflipside.com/logout.php"><i class="fa fa-sign-out"></i></a>';
65
        if($this->user === false || $this->user === null)
66
        {
67
            $log = '<a href="https://profiles.burningflipside.com/login.php?return='.$this->currentUrl().'"><i class="fa fa-sign-in"></i></a>';
68
        }
69
        $this->body = '<div id="wrapper">
70
                  <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
71
                      <div class="navbar-header">
72
                          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
73
                              <span class="sr-only">Toggle Navigation</span>
74
                              <span class="icon-bar"></span>
75
                              <span class="icon-bar"></span>
76
                              <span class="icon-bar"></span>
77
                          </button>
78
                          <a class="navbar-brand" href="index.php">'.$this->title.'</a>
79
                      </div>
80
                      <ul class="nav navbar-top-links navbar-right">
81
                          <a href="..">
82
                              <i class="fa fa-home"></i>
83
                          </a>
84
                          &nbsp;&nbsp;'.$log.'
85
                          <li class="dropdown">
86
                              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
87
                                  <i class="fa fa-link"></i>
88
                                  <b class="caret"></b>
89
                              </a>
90
                              <ul class="dropdown-menu dropdown-sites">
91
                                  '.$sites.'
92
                              </ul>
93
                          </li>
94
                      </ul>
95
                      <div class="navbar-default sidebar" role="navigation">
96
                          <div class="sidebar-nav navbar-collapse" style="height: 1px;">
97
                              <ul class="nav" id="side-menu">
98
                                  '.$sideNav.'
99
                              </ul>
100
                          </div>
101
                      </div>
102
                  </nav>
103
                  <div id="page-wrapper" style="min-height: 538px;">'.$this->body.'</div></div>';
104
    }
105
106
    const CARD_GREEN  = 'panel-green';
107
    const CARD_BLUE   = 'panel-primary';
108
    const CARD_YELLOW = 'panel-yellow';
109
    const CARD_RED    = 'panel-red';
110
111
    function add_card($iconName, $bigText, $littleText, $link = '#', $color = self::CARD_BLUE, $textColor = false)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Unused Code introduced by
The parameter $textColor is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
112
    {
113
        $card = '<div class="col-lg-3 col-md-6">
114
                     <div class="panel '.$color.'">
115
                         <div class="panel-heading">
116
                             <div class="row">
117
                                 <div class="col-xs-3">
118
                                     <i class="fa '.$iconName.'" style="font-size: 5em;"></i>
119
                                 </div>
120
                                 <div class="col-xs-9 text-right">
121
                                     <div style="font-size: 40px;">'.$bigText.'</div>
122
                                     <div>'.$littleText.'</div>
123
                                 </div>
124
                             </div>
125
                         </div>
126
                         <a href="'.$link.'">
127
                         <div class="panel-footer">
128
                             <span class="pull-left">View Details</span>
129
                             <span class="pull-right fa fa-arrow-circle-right"></span>
130
                             <div class="clearfix"></div>
131
                         </div>
132
                         </a>
133
                     </div>
134
                 </div>';
135
        $this->body .= $card;
136
    }
137
138
    function printPage($header = true)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
139
    {
140
        if($this->user === false || $this->user === null)
141
        {
142
            $this->body = '
143
        <div class="row">
144
            <div class="col-lg-12">
145
                <h1 class="page-header">You must <a href="'.$this->loginUrl.'?return='.$this->currentUrl().'">log in <span class="glyphicon glyphicon-log-in"></span></a> to access the '.$this->title.' Admin system!</h1>
146
            </div>
147
        </div>';
148
        }
149
        else if($this->is_admin === false)
150
        {
151
            $this->body = '
152
        <div class="row">
153
            <div class="col-lg-12">
154
                <h1 class="page-header">The current user does not have access rights to the '.$this->title.' Admin system!</h1>
155
            </div>
156
        </div>';
157
        }
158
        parent::printPage();
159
    }
160
}
161
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
162
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
163