Private_drive::index()   B
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 85
Code Lines 54

Duplication

Lines 10
Ratio 11.76 %

Importance

Changes 0
Metric Value
cc 6
eloc 54
nc 4
nop 0
dl 10
loc 85
rs 8.3367
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
defined('BASEPATH') OR exit('No direct script access allowed');
4
5
class Private_drive extends My_Force_Login {
6
7
    public function __construct() {
8
        parent::__construct();
9
        $this->load->model('computing-support/Private_drive_model', 'private_drive_model');
10
    }
11
12
    public function index() {
13
14
        if (in_array('CN=Dashboard_CS_NS,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups']) ||
15
                in_array('CN=Dashboard_Section_Manager,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups']) ||
16
                in_array('CN=Dashboard_Faculty_Head,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
17
18
            $this->load->helper('form');
19
            $this->load->library('form_validation');
20
            //validation
21
            $this->form_validation->set_rules('user', 'Staff requiring access', 'trim|required|min_length[3]');
22
            $this->form_validation->set_rules('path', 'Path', 'trim|required|min_length[13]');
23
            $this->form_validation->set_rules('access', 'Access Level', 'trim|required');
24
            $this->form_validation->set_rules('approver', 'Approve by', 'trim|required');
25
26
            if ($this->form_validation->run() === FALSE) {
27
28
                $this->load->view('templates/header');
29
                $this->load->view('computing-support/private-drive/view');
30
                $this->load->view('templates/footer');
31
            } else {
32
33
                $requester = $this->input->post('logged');
34
                $user = $this->input->post('user');
35
                $path = $this->input->post('path');
36
                $access = $this->input->post('access');
37
                $approver = $this->input->post('approver');
38
39
                preg_match('#\((.*?)\)#', $user, $user_un);
40
                $user_un = $user_un[1];
41
42
                if ($this->private_drive_model->create($requester, $user, $user_un, $path, $access, $approver)) {
43
44
                    $username = $user_un;
45
                    $user_email = $this->private_drive_model->get_email_username($username);
46
47
                    $this->email->from('[email protected]', 'Private Drive Access');
48
                    $this->email->to($user_email);
49
                    $this->email->cc($_SESSION['ldap']['email']);
50
                    $this->email->subject('Private Drive Access Request');
51
                    $this->email->message('Access to a private drive has been requested for ' . $user . ' by ' . $requester . '. 
52
                    This request is currently waiting for approval by ' . $approver . '. 
53
                            
54
                    You can check the status of the request at the following link:
55
                    https://intranet.cant-col.ac.uk/dashboard/computing-support/private-drive/check
56
                            
57
                    If this request was made by mistake; you can cancel the request using the same link.
58
                            
59
                    Folder path: ' . $path . '
60
                    Access level: ' . $access);
61
                    $this->email->send();
62
63
                    $full_name = $approver;
64
                    $faculty_email = $this->private_drive_model->get_email_approver($full_name);
65
66
                    $this->email->from('[email protected]', 'Private Drive Access');
67
                    $this->email->to($faculty_email);
68
                    $this->email->subject('Private Drive Access Request');
69
                    $this->email->message('Access to a private drive has been requested for ' . $user . ' by ' . $requester . '.
70
                    You have been marked as the approver for this request.
71
                            
72
                    Please approve or reject this request using the following link:
73
                    https://intranet.cant-col.ac.uk/dashboard/computing-support/private-drive/check
74
                            
75
                    Folder path: ' . $path . '
76
                    Access level: ' . $access);
77
                    $this->email->send();
78
79
                    $this->load->view('templates/header');
80
                    $this->load->view('computing-support/private-drive/complete');
81
                    $this->load->view('templates/footer');
82 View Code Duplication
                } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
83
84
                    $data = new stdClass();
85
                    $data->error = 'There was a problem requesting access. Please try again.';
86
87
                    // failed to create user
88
                    $this->load->view('templates/header');
89
                    $this->load->view('computing-support/private-drive/view', $data);
90
                    $this->load->view('templates/footer');
91
                }
92
            }
93
        } else {
94
            redirect('permissions');
95
        }
96
    }
97
98 View Code Duplication
    public function history() {
0 ignored issues
show
Duplication introduced by
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...
99
100
        if (in_array('CN=DG06,OU=Distribution Groups,OU=Email Groups,OU=Accounts,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
101
102
            $data = array();
103
            $data['private_drive'] = $this->private_drive_model->get_all();
104
105
            $this->load->view('templates/header');
106
            $this->load->view('computing-support/private-drive/history', $data);
107
            $this->load->view('templates/footer');
108
        } else {
109
            redirect('permissions');
110
        }
111
    }
112
113
    public function check() {
114
115
        $data = array();
116
        $data['private_drive'] = $this->private_drive_model->check_status();
117
118
        $this->load->view('templates/header');
119
        $this->load->view('computing-support/private-drive/check', $data);
120
        $this->load->view('templates/footer');
121
    }
122
123 View Code Duplication
    public function pending() {
0 ignored issues
show
Duplication introduced by
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...
124
125
        if (in_array('CN=Dashboard_CS_NS,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
126
127
            $data = array();
128
            $data['private_drive'] = $this->private_drive_model->get_pending();
129
130
            $this->load->view('templates/header');
131
            $this->load->view('computing-support/private-drive/pending', $data);
132
            $this->load->view('templates/footer');
133
        } else {
134
            redirect('permissions');
135
        }
136
    }
137
138
    public function cancel() {
139
140
        $id = $_GET['id'];
141
        $check_user = $this->private_drive_model->match_id_user($id);
142
        if ($check_user[0]['requested'] == $_SESSION['ldap']['full_name'] || $check_user[0]['user'] == $_SESSION['ldap']['full_name'] || $check_user[0]['approver'] == $_SESSION['ldap']['full_name']) {
143
144
            if (isset($_GET['id'])) {
145
146
                $id = $_GET['id'];
147
                $this->private_drive_model->cancel($id);
148
149
                $function = 'private_drive_CANCEL_' . $id;
150
                $this->user_model->function_log($function);
151
152
                redirect($_SERVER['HTTP_REFERER']);
153
            }
154
            redirect($_SERVER['HTTP_REFERER']);
155
        } else {
156
            redirect($_SERVER['HTTP_REFERER']);
157
        }
158
    }
159
160 View Code Duplication
    public function fh_reject() {
0 ignored issues
show
Duplication introduced by
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...
161
162
        if (in_array('CN=Dashboard_Faculty_Head,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
163
164
            if (isset($_GET['id'])) {
165
166
                $id = $_GET['id'];
167
                $this->private_drive_model->fh_reject($id);
168
169
                $get_request = $this->private_drive_model->get_request($id);
170
                
171
                $requester_un = $get_request[0]['requester_un'];
172
                $requester_email = $this->private_drive_model->get_email_username($requester_un);
173
                
174
                $user_un = $get_request[0]['user_un'];
175
                $user_email = $this->private_drive_model->get_email_username($user_un);
176
177
                $this->email->from('[email protected]', 'Private Drive Access');
178
                $this->email->to($requester_email);
179
                $this->email->cc($user_email);
180
                $this->email->subject('Private Drive Access Request Rejected');
181
                $this->email->message('Access to a private drive has been requested for ' . $get_request[0]['user'] . ' by ' . $get_request[0]['requester'] . ' has been rejected by ' . $get_request[0]['approver'] . '.
182
                            
183
                You can view the status of this request and others like it using the below link:
184
                https://intranet.cant-col.ac.uk/dashboard/computing-support/private-drive/check
185
                            
186
                Folder path: ' . $get_request[0]['path'] . '
187
                Access level: ' . $get_request[0]['access']);
188
                $this->email->send();
189
190
                $function = 'private_drive_FH_REJECT_' . $id;
191
                $this->user_model->function_log($function);
192
193
                redirect($_SERVER['HTTP_REFERER']);
194
            }
195
196
            redirect($_SERVER['HTTP_REFERER']);
197
        } else {
198
            redirect($_SERVER['HTTP_REFERER']);
199
        }
200
    }
201
202
    public function fh_approve() {
203
204
        if (in_array('CN=Dashboard_Faculty_Head,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
205
206
            if (isset($_GET['id'])) {
207
208
                $id = $_GET['id'];
209
                $this->private_drive_model->fh_approve($id);
210
                
211
                $get_request = $this->private_drive_model->get_request($id);
212
213
                $this->email->from('[email protected]', 'Private Drive Access');
214
                $this->email->to('[email protected]');
215
                $this->email->cc('[email protected]');
216
                $this->email->subject('Private Drive Access Request Approved');
217
                $this->email->message('Access to a private drive has been requested for ' . $get_request[0]['user'] . ' by ' . $get_request[0]['requester'] . ' has been approved by ' . $get_request[0]['approver'] . '.
218
                            
219
                This request needs to be actioned
220
                            
221
                View the details of the request at the following link:
222
                https://intranet.cant-col.ac.uk/dashboard/computing-support/private-drive/pending
223
                            
224
                Folder path: ' . $get_request[0]['path'] . '
225
                Access level: ' . $get_request[0]['access']);
226
                $this->email->send();
227
228
                $function = 'private_drive_FH_APPROVED_' . $id;
229
                $this->user_model->function_log($function);
230
231
                redirect($_SERVER['HTTP_REFERER']);
232
            }
233
            redirect($_SERVER['HTTP_REFERER']);
234
        } else {
235
            redirect($_SERVER['HTTP_REFERER']);
236
        }
237
    }
238
239 View Code Duplication
    public function cs_reject() {
0 ignored issues
show
Duplication introduced by
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...
240
241
        if (in_array('CN=Dashboard_CS_NS,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
242
243
            if (isset($_GET['id'])) {
244
245
                $id = $_GET['id'];
246
                $this->private_drive_model->cs_reject($id);
247
                
248
                $get_request = $this->private_drive_model->get_request($id);
249
                
250
                $requester_un = $get_request[0]['requester_un'];
251
                $requester_email = $this->private_drive_model->get_email_username($requester_un);
252
                
253
                $user_un = $get_request[0]['user_un'];
254
                $user_email = $this->private_drive_model->get_email_username($user_un);
255
256
                $this->email->from('[email protected]', 'Private Drive Access');
257
                $this->email->to($requester_email);
258
                $this->email->cc($user_email);
259
                $this->email->subject('Private Drive Access Request Rejected');
260
                $this->email->message('Access to a private drive has been requested for ' . $get_request[0]['user'] . ' by ' . $get_request[0]['requester'] . ' and approved by ' . $get_request[0]['approver'] . ' has been rejected by Computing Support.
261
                            
262
                You can view the status of this request and others like it using the below link:
263
                https://intranet.cant-col.ac.uk/dashboard/computing-support/private-drive/check
264
                            
265
                Folder path: ' . $get_request[0]['path'] . '
266
                Access level: ' . $get_request[0]['access']);
267
                $this->email->send();
268
269
                $function = 'private_drive_CS_REJECT_' . $id;
270
                $this->user_model->function_log($function);
271
272
                redirect($_SERVER['HTTP_REFERER']);
273
            }
274
275
            redirect($_SERVER['HTTP_REFERER']);
276
        } else {
277
            redirect($_SERVER['HTTP_REFERER']);
278
        }
279
    }
280
281 View Code Duplication
    public function cs_approve() {
0 ignored issues
show
Duplication introduced by
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...
282
283
        if (in_array('CN=Dashboard_CS_NS,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
284
285
            if (isset($_GET['id'])) {
286
287
                $id = $_GET['id'];
288
                $this->private_drive_model->cs_approve($id);
289
                
290
                $get_request = $this->private_drive_model->get_request($id);
291
                
292
                $requester_un = $get_request[0]['requester_un'];
293
                $requester_email = $this->private_drive_model->get_email_username($requester_un);
294
                
295
                $user_un = $get_request[0]['user_un'];
296
                $user_email = $this->private_drive_model->get_email_username($user_un);
297
298
                $this->email->from('[email protected]', 'Private Drive Access');
299
                $this->email->to($requester_email);
300
                $this->email->cc($user_email);
301
                $this->email->subject('Private Drive Access Request Actioned');
302
                $this->email->message('Access to a private drive has been requested for ' . $get_request[0]['user'] . ' by ' . $get_request[0]['requester'] . ' and approved by ' . $get_request[0]['approver'] . ' has been actioned by Computing Support.
303
                            
304
                For the permissions to be applied, you must log out and on again.
305
                
306
                You can view your other requests at the following link.
307
                https://intranet.cant-col.ac.uk/dashboard/computing-support/private-drive/check
308
                            
309
                Folder path: ' . $get_request[0]['path'] . '
310
                Access level: ' . $get_request[0]['access']);
311
                $this->email->send();
312
313
                $function = 'private_drive_CS_APPROVED_' . $id;
314
                $this->user_model->function_log($function);
315
316
                redirect($_SERVER['HTTP_REFERER']);
317
            }
318
            redirect($_SERVER['HTTP_REFERER']);
319
        } else {
320
            redirect($_SERVER['HTTP_REFERER']);
321
        }
322
    }
323
324
}
325