Completed
Push — master ( d460d6...884aac )
by Patrick
03:18
created

ProfilesLeadPage::print_page()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
cc 3
eloc 7
c 3
b 1
f 1
nc 3
nop 1
dl 0
loc 22
rs 9.2
1
<?php
2
require_once('class.ProfilesPage.php');
3
require_once('class.FlipSession.php');
4
class ProfilesLeadPage extends FlipAdminPage
5
{
6
    private $is_lead;
7
8
    function __construct($title)
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...
9
    {
10
        parent::__construct($title);
11
        if($this->user == false)
12
        {
13
            $this->is_lead = false;
14
        }
15
        else
16
        {
17
            $this->is_lead = $this->user->isInGroupNamed('Leads');
18
            if(!$this->is_lead)
19
            {
20
                $this->is_lead = $this->user->isInGroupNamed('CC');
21
            }
22
        }
23
        if($this->is_lead)
24
        {
25
            $this->is_admin = $this->is_lead;
26
        }
27
        $this->add_leads_css();
28
        $this->add_links();
29
        $this->addWellKnownJS(JS_DATATABLE, false);
30
        $this->addWellKnownJS(JQUERY_VALIDATE);
31
        $this->addWellKnownJS(JS_METISMENU);
32
        $this->addJSByURI('../_admin/js/admin.js');
33
        $this->addWellKnownJS(JS_LOGIN);
34
    }
35
36
    function add_leads_css()
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...
37
    {
38
        $this->addWellKnownCSS(CSS_DATATABLE);
39
        $this->addCSSByURI('../css/profiles.css');
40
        $this->addCSSByURI('css/lead.css');
41
    }
42
43
    function add_links()
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...
44
    {
45
         $dirMenu = array(
46
             'All' => 'directory.php',
47
             'AAR' => 'directory.php?filter=aar',
48
             'AFs' => 'directory.php?filter=af',
49
             'CC'  => 'directory.php?filter=cc',
50
             '360/24/7 Department' => 'directory.php?filter=360',
51
             'Art' => 'directory.php?filter=Art',
52
             'City Planning' => 'directory.php?filter=CityPlanning',
53
             'Communications' => 'directory.php?filter=Comm',
54
             'Genesis' => 'directory.php?filter=Genesis',
55
             'Safety' => 'directory.php?filter=Safety',
56
             'Site-Ops' => 'directory.php?filter=site-ops',
57
             'Site Prep' => 'directory.php?filter=siteprep',
58
             'Site Sign-Off' => 'directory.php?filter=sign-off',
59
             'Volunteer Coordinator' => 'directory.php?filter=vc'
60
         );
61
         $this->addLink('<span class="fa fa-dashboard"></span> Dashboard', 'index.php');
62
         $this->addLink('<span class="fa fa-th-list"></span> Directory', false, $dirMenu);
63
    }
64
65
    function add_header()
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...
66
    {
67
        $sites = '';
68
        $log = '';
0 ignored issues
show
Unused Code introduced by
$log is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
69
        foreach($this->sites as $link => $site_name)
0 ignored issues
show
Bug introduced by
The property sites does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
70
        {
71
            $sites .= '<li><a href="'.$site_name.'">'.$link.'</a></li>';
72
        }
73
        if(!FlipSession::isLoggedIn())
74
        {
75
            $log = '<a href="../login.php?return='.$this->current_url().'"><span class="glyphicon glyphicon-log-in"></span></a>';
0 ignored issues
show
Deprecated Code introduced by
The method WebPage::current_url() has been deprecated with message: 1.0.0 This funciton is deprectated and will be remoted. Please use currentURL() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
76
        }
77
        else
78
        {
79
            $log = '<a href="../logout.php"><span class="glyphicon glyphicon-log-out"></span></a>';
80
        }
81
        $this->body = '<div id="wrapper">
82
                  <nav class="navbar navbar-default navbar-static-top" role=navigation" style="margin-bottom: 0">
83
                      <div class="navbar-header">
84
                          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
85
                              <span class="sr-only">Toggle Navigation</span>
86
                              <span class="icon-bar"></span>
87
                              <span class="icon-bar"></span>
88
                              <span class="icon-bar"></span>
89
                          </button>
90
                          <a class="navbar-brand" href="index.php">Leads</a>
91
                      </div>
92
                      <ul class="nav navbar-top-links navbar-right links">
93
                           <a href="../">
94
                              <span class="glyphicon glyphicon-home"></span>
95
                           </a>
96
                           &nbsp;&nbsp;
97
                          '.$log.'
98
                          <li class="dropdown">
99
                              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
100
                                  <span class="glyphicon glyphicon-link"></span>
101
                                  <b class="caret"></b>
102
                              </a>
103
                              <ul class="dropdown-menu dropdown-sites">
104
                                  '.$sites.'
105
                              </ul>
106
                          </li>
107
                      </ul>
108
                      <div class="navbar-default sidebar" role="navigation">
109
                          <div class="sidebar-nav navbar-collapse" style="height: 1px;">
110
                              <ul class="nav" id="side-menu">
111
                                  <li>
112
                                      <a href="index.php"><span class="glyphicon glyphicon-dashboard"></span> Dashboard</a>
113
                                  </li>
114
                                  <li>
115
                                      <a href="#"><span class="glyphicon glyphicon-th-list"></span> Directory</a>
116
                                      <ul class="nav nav-second-level collapse">
117
                                          <li><a href="directory.php">All</a></li>
118
                                          <li><a href="directory.php?filter=aar">AAR</a></li>
119
                                          <li><a href="directory.php?filter=af">AFs</a></li>
120
                                          <li><a href="directory.php?filter=cc">CC</a></li>
121
                                          <li><a href="directory.php?filter=360">360/24/7 Department</a></li>
122
                                          <li><a href="directory.php?filter=Art">Art</a></li>
123
                                          <li><a href="directory.php?filter=CityPlanning">City Planning</a></li>
124
                                          <li><a href="directory.php?filter=Comm">Communications</a></li>
125
                                          <li><a href="directory.php?filter=Safety">Safety</a></li>
126
                                          <li><a href="directory.php?filter=site-ops">Site-Ops</a></li>
127
                                          <li><a href="directory.php?filter=siteprep">Site Prep</a></li>
128
                                          <li><a href="directory.php?filter=sign-off">Site Sign-Off</a></li>
129
                                          <li><a href="directory.php?filter=vc">Volunteer Coordinator</a></li>
130
                                      </ul>
131
                                  </li>
132
                              </ul>
133
                          </div>
134
                      </div>
135
                  </nav>
136
                  <div id="page-wrapper" style="min-height: 538px;">'.$this->body.'</div></div>';
137
        $this->add_login_form();
138
    }
139
140
    function print_page($header = true)
0 ignored issues
show
Unused Code introduced by
The parameter $header 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...
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...
141
    {
142
        if($this->user == false)
143
        {
144
            $this->body = '
145
        <div class="row">
146
            <div class="col-lg-12">
147
                <h1 class="page-header">You must <a href="/login.php?return='.$this->currentURL().'">log in <span class="glyphicon glyphicon-log-in"></span></a> to access the Burning Flipside Profile Admin system!</h1>
148
            </div>
149
        </div>';
150
        }
151
        else if($this->is_lead === false)
152
        {
153
            $this->body = '
154
        <div class="row">
155
            <div class="col-lg-12">
156
                <h1 class="page-header">You must be a lead to access this page!</h1>
157
            </div>
158
        </div>';
159
        }
160
        parent::printPage(true);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (printPage() instead of print_page()). Are you sure this is correct? If so, you might want to change this to $this->printPage().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
161
    }
162
163
    function add_login_form()
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...
164
    {
165
        $this->body .= '<div class="modal fade" role="dialog" id="login-dialog" title="Login" aria-hidden="true">
166
                            <div class="modal-dialog">
167
                                <div class="modal-content">
168
                                    <div class="modal-header">
169
                                        <button type="button" class="close" data-dismiss="modal">
170
                                            <span aria-hidden="true">&times;</span>
171
                                            <span class="sr-only">Close</span>
172
                                        </button>
173
                                        <h4 class="modal-title">Login</h4>
174
                                    </div>
175
                                    <div class="modal-body">
176
                                        <form id="login_dialog_form" role="form">
177
                                            <input class="form-control" type="text" name="username" placeholder="Username or Email" required autofocus/>
178
                                            <input class="form-control" type="password" name="password" placeholder="Password" required/>
179
                                            <input type="hidden" name="return" value="'.$this->current_url().'"/>
0 ignored issues
show
Deprecated Code introduced by
The method WebPage::current_url() has been deprecated with message: 1.0.0 This funciton is deprectated and will be remoted. Please use currentURL() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
180
                                            <button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
181
                                        </form>
182
                                    </div>
183
                                </div>
184
                            </div>
185
                        </div>';
186
    }
187
}
188
?>
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...
189