1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed'); |
4
|
|
|
|
5
|
|
|
class Ownership extends My_Force_Login { |
6
|
|
|
|
7
|
|
|
public function __construct() { |
8
|
|
|
parent::__construct(); |
9
|
|
|
$this->load->library('grocery_CRUD'); |
10
|
|
|
$this->load->model('computing-support/Ownership_model', 'ownership_model'); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
public function index() { |
14
|
|
|
|
15
|
|
|
$this->load->helper('form'); |
16
|
|
|
$this->load->library('form_validation'); |
17
|
|
|
|
18
|
|
|
// validation rules |
19
|
|
|
$this->form_validation->set_rules('staff_full', 'Staff Full Name', 'trim|required|min_length[6]'); |
20
|
|
|
$this->form_validation->set_rules('make', 'Device Make', 'trim|required|min_length[3]'); |
21
|
|
|
$this->form_validation->set_rules('model', 'Device Model', 'trim|required|min_length[3]'); |
22
|
|
|
$this->form_validation->set_rules('sn', 'Device Serial Number', 'trim|required|min_length[3]'); |
23
|
|
|
|
24
|
|
|
if ($this->form_validation->run() === false) { |
25
|
|
|
|
26
|
|
|
$this->load->view('templates/header'); |
27
|
|
|
$this->load->view('computing-support/ownership/view'); |
28
|
|
|
$this->load->view('templates/footer'); |
29
|
|
|
} else { |
30
|
|
|
|
31
|
|
|
$logged = $this->input->post('logged'); |
32
|
|
|
$staff_full = $this->input->post('staff_full'); |
33
|
|
|
$make = $this->input->post('make'); |
34
|
|
|
$model = $this->input->post('model'); |
35
|
|
|
$sn = $this->input->post('sn'); |
36
|
|
|
|
37
|
|
|
if ($this->ownership_model->create($logged, $staff_full, $make, $model, $sn)) { |
38
|
|
|
|
39
|
|
|
$staff_email = $this->ownership_model->email_id($staff_full); |
40
|
|
|
|
41
|
|
|
$this->email->from('[email protected]', 'Ownership Transfer'); |
42
|
|
|
$this->email->to($staff_email[0]['email']); |
43
|
|
|
$this->email->subject('Ownership Transfer Request'); |
44
|
|
|
$this->email->message('An IT equipment ownership transfer request has been submitted.' |
45
|
|
|
. 'You must accept the terms and conditions at the following link before it can be approved by Computing Support.' |
46
|
|
|
. '' |
47
|
|
|
. 'https://intranet.cant-col.ac.uk/dashboard/computing-support/ownership/check' |
48
|
|
|
. '' |
49
|
|
|
. 'Use the same link to cancel the request or/and check the progress.'); |
50
|
|
|
$this->email->send(); |
51
|
|
|
|
52
|
|
|
$function = 'ownership_application'; |
53
|
|
|
$this->user_model->function_log($function); |
54
|
|
|
|
55
|
|
|
// user created |
56
|
|
|
$this->load->view('templates/header'); |
57
|
|
|
$this->load->view('computing-support/ownership/requested'); |
58
|
|
|
$this->load->view('templates/footer'); |
59
|
|
|
} else { |
60
|
|
|
|
61
|
|
|
$function = 'ownership_error'; |
62
|
|
|
$this->user_model->function_log($function); |
63
|
|
|
|
64
|
|
|
$data = new stdClass(); |
65
|
|
|
$data->error = 'There was a problem submitting this request. Please try again.'; |
66
|
|
|
|
67
|
|
|
// failed to create user |
68
|
|
|
$this->load->view('templates/header'); |
69
|
|
|
$this->load->view('computing-support/ownership/view', $data); |
70
|
|
|
$this->load->view('templates/footer'); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
View Code Duplication |
public function history() { |
|
|
|
|
76
|
|
|
|
77
|
|
|
if (in_array('CN=DG06,OU=Distribution Groups,OU=Email Groups,OU=Accounts,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) { |
78
|
|
|
|
79
|
|
|
$data = array(); |
80
|
|
|
$data['ownership'] = $this->ownership_model->get_all_ownership(); |
81
|
|
|
|
82
|
|
|
$this->load->view('templates/header'); |
83
|
|
|
$this->load->view('computing-support/ownership/history', $data); |
84
|
|
|
$this->load->view('templates/footer'); |
85
|
|
|
} else { |
86
|
|
|
redirect('permissions'); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
View Code Duplication |
public function review() { |
|
|
|
|
91
|
|
|
|
92
|
|
|
if (in_array('CN=Dashboard_Admin,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) { |
93
|
|
|
|
94
|
|
|
$data = array(); |
95
|
|
|
$data['ownership'] = $this->ownership_model->get_pending_ownership(); |
96
|
|
|
|
97
|
|
|
$this->load->view('templates/header'); |
98
|
|
|
$this->load->view('computing-support/ownership/review', $data); |
99
|
|
|
$this->load->view('templates/footer'); |
100
|
|
|
} else { |
101
|
|
|
redirect('permissions'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function check() { |
106
|
|
|
|
107
|
|
|
$data = array(); |
108
|
|
|
$data['ownership'] = $this->ownership_model->check_ownership(); |
109
|
|
|
|
110
|
|
|
$this->load->view('templates/header'); |
111
|
|
|
$this->load->view('computing-support/ownership/check', $data); |
112
|
|
|
$this->load->view('templates/footer'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
View Code Duplication |
public function approve() { |
|
|
|
|
116
|
|
|
|
117
|
|
|
if (in_array('CN=Dashboard_Admin,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) { |
118
|
|
|
|
119
|
|
|
if (isset($_GET['id'])) { |
120
|
|
|
|
121
|
|
|
$id = $_GET['id']; |
122
|
|
|
$this->ownership_model->approve($id); |
123
|
|
|
|
124
|
|
|
$check_user = $this->ownership_model->match_id_user($id); |
125
|
|
|
$staff_full = $check_user[0]['staff_full']; |
126
|
|
|
|
127
|
|
|
$staff_email = $this->ownership_model->email_id($staff_full); |
128
|
|
|
|
129
|
|
|
$this->email->from('[email protected]', 'Ownership Transfer'); |
130
|
|
|
$this->email->to($staff_email[0]['email']); |
131
|
|
|
$this->email->subject('Ownership Transfer Request'); |
132
|
|
|
$this->email->message('Your IT equipment ownership request has been approved.' |
133
|
|
|
. '' |
134
|
|
|
. 'https://intranet.cant-col.ac.uk/dashboard/computing-support/ownership/check' |
135
|
|
|
. '' |
136
|
|
|
. 'Check the progress of other requests and the history of your transfers.'); |
137
|
|
|
$this->email->send(); |
138
|
|
|
|
139
|
|
|
$function = 'ownership_APPROVE_' . $id; |
140
|
|
|
$this->user_model->function_log($function); |
141
|
|
|
|
142
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
146
|
|
|
} else { |
147
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
View Code Duplication |
public function reject() { |
|
|
|
|
152
|
|
|
|
153
|
|
|
if (in_array('CN=Dashboard_Admin,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) { |
154
|
|
|
|
155
|
|
|
if (isset($_GET['id'])) { |
156
|
|
|
|
157
|
|
|
$id = $_GET['id']; |
158
|
|
|
$this->ownership_model->reject($id); |
159
|
|
|
|
160
|
|
|
$check_user = $this->ownership_model->match_id_user($id); |
161
|
|
|
$staff_full = $check_user[0]['staff_full']; |
162
|
|
|
|
163
|
|
|
$staff_email = $this->ownership_model->email_id($staff_full); |
164
|
|
|
|
165
|
|
|
$this->email->from('[email protected]', 'Ownership Transfer'); |
166
|
|
|
$this->email->to($staff_email[0]['email']); |
167
|
|
|
$this->email->subject('Ownership Transfer Request'); |
168
|
|
|
$this->email->message('Your IT equipment ownership request has been rejected.' |
169
|
|
|
. '' |
170
|
|
|
. 'https://intranet.cant-col.ac.uk/dashboard/computing-support/ownership/check'); |
171
|
|
|
$this->email->send(); |
172
|
|
|
|
173
|
|
|
$function = 'ownership_REJECT_' . $id; |
174
|
|
|
$this->user_model->function_log($function); |
175
|
|
|
|
176
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
180
|
|
|
} else { |
181
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function cancel() { |
186
|
|
|
|
187
|
|
|
$id = $_GET['id']; |
188
|
|
|
$check_user = $this->ownership_model->match_id_user($id); |
189
|
|
|
if ($check_user[0]['staff_full'] == $_SESSION['ldap']['full_name']) { |
190
|
|
|
|
191
|
|
|
if (isset($_GET['id'])) { |
192
|
|
|
|
193
|
|
|
$id = $_GET['id']; |
194
|
|
|
$this->ownership_model->cancel($id); |
195
|
|
|
|
196
|
|
|
$function = 'ownership_CANCEL_' . $id; |
197
|
|
|
$this->user_model->function_log($function); |
198
|
|
|
|
199
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
200
|
|
|
} |
201
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
202
|
|
|
} else { |
203
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
207
|
|
View Code Duplication |
public function terms() { |
|
|
|
|
208
|
|
|
|
209
|
|
|
$id = $_GET['id']; |
210
|
|
|
$check_user = $this->ownership_model->match_id_user($id); |
211
|
|
|
if ($check_user[0]['staff_full'] == $_SESSION['ldap']['full_name']) { |
212
|
|
|
|
213
|
|
|
if (isset($_GET['id'])) { |
214
|
|
|
|
215
|
|
|
$id = $_GET['id']; |
216
|
|
|
$this->ownership_model->terms($id); |
217
|
|
|
|
218
|
|
|
$this->email->from('[email protected]', 'Ownership Transfer'); |
219
|
|
|
$this->email->to('[email protected]'); |
220
|
|
|
$this->email->bcc('[email protected]'); |
221
|
|
|
$this->email->subject('Ownership Transfer Request'); |
222
|
|
|
$this->email->message('A new IT equipment ownership transfer request has been submitted.' |
223
|
|
|
. '' |
224
|
|
|
. 'Review all pending requests below.' |
225
|
|
|
. '' |
226
|
|
|
. 'https://intranet.cant-col.ac.uk/dashboard/computing-support/ownership/review'); |
227
|
|
|
$this->email->send(); |
228
|
|
|
|
229
|
|
|
$function = 'ownership_TERMS_' . $id; |
230
|
|
|
$this->user_model->function_log($function); |
231
|
|
|
|
232
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
233
|
|
|
} |
234
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
235
|
|
|
} else { |
236
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|
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.