Completed
Push — master ( 617293...ba97ae )
by Patrick
38:43 queued 01:21
created

VolunteerAdminPage::addLinks()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 5
nop 0
dl 0
loc 39
rs 8.6737
c 0
b 0
f 0
1
<?php
2
require_once('class.FlipSession.php');
3
require_once('app/VolunteerAutoload.php');
4
require_once('../../class.SecurePage.php');
5
class VolunteerAdminPage extends \Http\FlipAdminPage
6
{
7
    use SecureWebPage;
8
9
    public $isLead;
10
    public $isAuthorized;
11
    public $secure_root;
12
13
    public function __construct($title)
14
    {
15
        $this->isLead = false;
16
        $this->isAuthorized = false;
17
        parent::__construct($title, 'VolunteerAdmins');
18
        $this->getAdminInfo();
19
        $this->addLinks();
20
        $this->addCSS('https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/css/select2.min.css');
21
        $this->addJS('https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/js/select2.min.js');
22
        //Neither Firefox nor Safari have support for datetime-local. This is roughly equivalent
23
        $this->addCSS('https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css');
24
        $this->addJS('https://cdn.jsdelivr.net/npm/flatpickr');
25
        $this->addJS('js/admin.js');
26
        $this->addJS('../js/dialog.js');
27
        $this->secure_root = $this->getSecureRoot();
28
        $this->content['loginUrl'] = $this->secure_root.'api/v1/login';
29
    }
30
31
    protected function getAdminInfo()
32
    {
33
        if($this->is_admin === false && $this->user)
34
        {
35
            //Is the user a lead or otherwise authorized to manipulate a department?
36
            $this->isLead = $this->user->isInGroupNamed('Leads');
37
            if($this->isLead)
38
            {
39
                 $this->is_admin = true;
40
            }
41
            else
42
            {
43
                //Is this user the assistant for a department?
44
                $uid = $this->user->uid;
45
                $email = $this->user->mail;
46
                $filter = new \Data\Filter("others eq $uid or others eq $email");
47
                $dataTable = DataSetFactory::getDataTableByNames('fvs','departments');
48
                $depts = $dataTable->read($filter);
49
                $this->isLead = !empty($depts);
50
                $this->is_admin = true;
51
            }
52
        }
53
    }
54
55
    protected function addLinks()
56
    {
57
        $this->content['header']['sidebar'] = array();
58
        if($this->user === false || $this->user === null)
59
        {
60
            return;
61
        }
62
        $this->content['header']['sidebar']['Dashboard'] = array('icon' => 'fa-tachometer-alt', 'url' => 'index.php');
63
        if($this->isLead === false)
64
        {
65
            $this->content['header']['sidebar']['Events'] = array('icon' => 'fa-calendar-alt', 'url' => 'events.php');
66
            $this->content['header']['sidebar']['Departments'] = array('icon' => 'fa-building', 'url' => 'departments.php');
67
        }
68
        $charts_menu = array(
69
            'Shift Schedules' => 'shift_schedules.php',
70
            'Shift Stats' => 'shift_stats.php',
71
            'T-Shirts' => 'tshirts.php',
72
            'Participant Shifts' => 'vol_shifts.php',
73
            'Volunteers without Shifts' => 'no_shifts.php',
74
            'Empty Shifts' => 'report_empty_shifts.php',
75
            'Early Entry' => 'report_early_entry.php'
76
        );
77
        $shifts_menu = array(
78
            'Add/Edit Shifts' => 'shifts.php',
79
            'Pending Shifts' => 'pending.php'
80
        );
81
        $this->content['header']['sidebar']['Roles'] = array('icon' => 'fa-address-card', 'url' => 'roles.php');
82
        $this->content['header']['sidebar']['Shifts'] = array('icon' => 'fa-tshirt', 'menu' => $shifts_menu);
83
        $this->content['header']['sidebar']['Volunteers'] = array('icon' => 'fa-user', 'url' => 'volunteers.php');
84
        $this->content['header']['sidebar']['Reports'] = array('icon' => 'fa-chart-bar', 'menu' => $charts_menu);
85
        $this->content['header']['sidebar']['Contact'] = array('icon' => 'fa-envelope', 'url' => 'contact.php');
86
        if($this->user && $this->user->isInGroupNamed('VolunteerAdmins'))
87
        {
88
            $admin_menu = array(
89
                'Email Text' => 'emails.php'
90
            );
91
            $this->content['header']['sidebar']['Admin'] = array('icon' => 'fa-cog', 'menu' => $admin_menu);
92
        }
93
    }
94
}
95