-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfxns.php
548 lines (380 loc) · 16.1 KB
/
fxns.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
<?php
/* This file contains controls and functions of the DTS 2
*/
/* FUNCTIONS ARE GROUPED AND ARRANGED AS FOLLOWS:
1. Logic Functions - Functions that implement business rules, such as access to document or track
2. Activity Functions - Functions that does things in the background with impact in record
3. PAGE ELEMENT FUNCTIONS
4. Table Formatting Functions
SQL Statements
*/
function make_urls_into_links($plain_text) {
return preg_replace(
'@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-~]*(\?\S+)?)?)?)@',
'<a href="$1">$1</a>', $plain_text);
}
function display_success()
{
echo "Success.<br />";
display_home();
}
function display_record()
{
echo "<p align='center'><a href='outputrecordsummaryreport.php'>View summary of outputs and records</a> || ";
echo "<a href='searchoutput.php'>Search records of agency outputs</a> || ";
echo "<a href='searchdmsrecord.php'>Search in DMS records</a> || ";
echo "<a href='recordsummarybyoffice.php'>Summary of documents/records by office</a> || ";
echo "<a href='recordslatest.php'>View latest recorded documents</a> </p>";
}
function get_officecreatorname($officeid){
// This function gets the name of the office from the GET['officeid']
require("db.php");
$get_officecreatorname = "select name, acronym, type from office where id = $officeid";
$processgetoffice = $db->query($get_officecreatorname);
$row = $processgetoffice->fetch_assoc();
$dcreatorofficename = $row['name'];
$dcreatorofficeacronym = $row['acronym'];
$dcreatorofficetype = $row['type'];
echo "<h1 align='center'>$dcreatorofficename</h1>";
}
function get_officename($officeid){
// This function gets generic name of office
require("db.php");
$get_officename = "select name, acronym, type from office where id = $officeid";
$processgetoffice = $db->query($get_officename);
$row = $processgetoffice->fetch_assoc();
$dcreatorofficename = $row['name'];
$dcreatorofficeacronym = $row['acronym'];
$dcreatorofficetype = $row['type'];
}
// LOGIC FUNCTIONS
function check_user_office($id, $officeid){
require("db.php");
$check_user_office = "select id from employeeoffice where employeeid = $id and officeid = $officeid and status = 'Active'";
$process = $db->query($check_user_office);
$get_officename = "select name, acronym, type from office where id = $officeid";
$processgetoffice = $db->query($get_officename);
$row = $processgetoffice->fetch_assoc();
$dcreatorofficename = $row['name'];
$dcreatorofficeacronym = $row['acronym'];
$dcreatorofficetype = $row['type'];
if($process->num_rows < 1){
//return;
header("Location: notauthorized.php");
}
}
function check_document_exists($did){
// This sequence checks if the Document ID exists.
require("db.php");
$checkdid = "select id from document where id = $did";
$proccheckdid = $db->query($checkdid);
if($proccheckdid->num_rows < 1){
header("Location: documentdoesnotexist.php");
return;
}
}
function check_document_track_present($did, $trackid){
require("db.php");
$getrow = "select id from track where documentid = $did and id = $trackid";
$process = $db->query($getrow);
if($process->num_rows < 1){
header("Location: inconsistentparameter.php");
}
}
// ACTIVITY FUNCTIONS
function registeractivity($employeeid, $activity){
require("db.php");
$registeractivityhistory = "insert into systemrecord (employeeid, Action) values ('$employeeid', '".$activity."')";
$processhistory = $db->query($registeractivityhistory);
}
function check_usersignin(){
if(!isset($_SESSION['id'])) {
header("Location: signin.php");
}
}
function check_user_documentaccess($did, $id){
require("db.php");
// This sequence checks that the user is allowed to access this document.
// First test is if the user is the creator.
$checkdidcreator = "select id from document where id = $did and creator = $id";
$proccheckcreator = $db->query($checkdidcreator);
if($proccheckcreator->num_rows < 1){
//echo $id."<br />";
//echo $did."<br />";
echo "You are not creator of this document.<br />";
//Second test is if the user is within the office where the document was created.
$checkofficecreator = "select employeeoffice.id from employeeoffice, document where document.id = $did and document.creatoroffice = employeeoffice.officeid and employeeoffice.employeeid = $id";
$proccheckofficecreator = $db->query($checkofficecreator);
if($proccheckofficecreator->num_rows < 1){
echo "You do not belong to the office that created this document.<br />";
$canclosedocument = 'No';
//return;
// Third test is if the user is within the office where the document was routed to.
$selectuseroffice = "select officeid from employeeoffice where employeeid = $id and status = 'Active'";
$proc223 = $db->query($selectuseroffice);
while ($row4 = $proc223->fetch_assoc())
{
// check if the office is recipient
$checkifofficeisrecipient = "select trackid from documenttrackrecipientofficeemployee where employeeid = $id and documentid = $did";
$proc224 = $db->query($checkifofficeisrecipient);
if($proc224->num_rows < 1)
{
echo "None of your offices or committees is not a recipient of this document.<br />";
// Final check: Check if the document is routed to the individual user
$checkindividualrecipient = "select TrackID from trackdocumentindividual where DocumentID = $did and RecipientPerson = $id";
$proccheckindividualrecipient = $db->query($checkindividualrecipient);
if($proccheckindividualrecipient->num_rows < 1){
header("Location: notauthorized.php");
return;
}
echo "Good for office recipient access<br />";
}
}
//echo "Good for user within office of office creator<br />";
}
}
}
function check_trackid($trackid, $id){
require("db.php");
// This function checks if the trackid should be accessible to the user.
$check_tracker_user = "select * from documenttrackrecipientofficeemployee where trackid = $trackid and employeeid = $id";
$process = $db->query($check_tracker_user);
if($process->num_rows < 1){
header("Location: notauthorized.php");
}
}
function check_did_and_trackid($did, $trackid){
require("db.php");
// This function checks the URL to prevent associating track to a document that is not connected to it
$check_did_trackid = "select id, documentid from track where id = $trackid and documentid = $did";
$process = $db->query($check_did_trackid);
if($process->num_rows == 0){
//$row = $process->fetch_assoc();
//$dtid = $row['id'];
//$ddid = $row['documentid'];
header("Location: inconsistentparameter.php");
// ?did=$ddid&trackid=$dtid
}
}
function close_track($id, $did, $trackid){
require("db.php");
$close_trackid = "update track SET status = 'Acted upon' where id = $trackid";
if($db->query($close_trackid) === TRUE){
registeractivity($id, "Closed Tracking ID no. $trackid");
header("Location:documentactionb.php?did=$did&trackid=$trackid");
} else {
echo "Error: ".$db->error;
}
}
// PAGE ELEMENT FUNCTIONS
function agencyname(){
$agencyname = "AnyAgency"; // Edit this
echo $agencyname;
}
function display_header(){
echo "<p align='center'><b>";
agencyname();
echo "</b></p>";
}
function display_home()
{
echo "<br />Go <a href='index.php'>home</a>.<br />";
}
function check_documentsecurityclass($did){
require("db.php");
$getsecurityclass = "select securityclass from document where id = $did";
$procgetsecurityclass = $db->query($getsecurityclass);
$row1 = $procgetsecurityclass->fetch_assoc();
$dbsecurityclass = $row1['securityclass'];
if($dbsecurityclass <> 'Unrestricted'){
echo "<p align='center'><b>This document is classified as $dbsecurityclass. Exercise necessary diligence in routing this document whether in paper or through online.</b></p>";
}
}
function display_main(){
echo "<p align='center'>";
echo "<a href='index.php'>Home</a> || ";
echo "<a href='createdocument.php'>Create a Document</a> || ";
echo "<a href='docaging.php'>View Document by Aging</a> || "; // This shows summary of open documents with aging
echo "<a href='search.php'>Search for a Document</a> || ";
echo "<a href='signout.php'>Sign out</a> ";
echo "</p>";
}
function display_rms(){
echo "<p align='center'>";
echo "<a href='createoutputtype.php'>Create a document type</a> || ";
echo "<a href='documentdashboard.php'>View All Document Dashboard</a> || ";
echo "<a href='removerole.php'>Remove role</a> || ";
echo "<a href='removerole.php'>Remove role</a> ";
echo "</p>";
}
function display_useractiveoffice_drop($id){
require("db.php");
echo "<b>Source Office</b>: ";
echo "<br />";
echo "<select name='sourceoffice'>";
echo "<option value=''></option>";
$selectactiveoffice = "select office.id, office.name from office, employeeoffice where employeeoffice.officeid = office.id and employeeoffice.employeeid = $id and employeeoffice.status = 'Active' order by office.name asc";
$processselectactiveoffice = $db->query($selectactiveoffice);
while ($dbofficeactive = $processselectactiveoffice->fetch_assoc()){
echo "<option value=".$dbofficeactive['id'].">".$dbofficeactive['name']."</option>";
}
echo "</select>";
}
function document_details_table($did){
require("db.php");
$getdocumentdetails = "select name, securityclass, timeline, creator, creatoroffice, status, contenttype, onlinelink, creationdate, status, signatory from document where id = $did";
$processgetdocumentdetails = $db->query($getdocumentdetails);
$row4 = $processgetdocumentdetails->fetch_assoc();
$dname = $row4['name'];
$dsecurityclass = $row4['securityclass'];
$dtimeline = $row4['timeline'];
$dcreator = $row4['creator'];
$dcreatoroffice = $row4['creatoroffice'];
$dstatus = $row4['status'];
$dcontenttype = $row4['contenttype'];
$donlinelink = $row4['onlinelink'];
$dcreationdate = $row4['creationdate'];
$dstatus = $row4['status'];
$dsignatory = $row4['signatory'];
$get_officecreatorname = "select name, acronym from office where id = $dcreatoroffice";
$processgetoffice = $db->query($get_officecreatorname);
$row = $processgetoffice->fetch_assoc();
$dcreatorofficename = $row['name'];
$dcreatorofficeacronym = $row['acronym'];
$get_individualcreatorname = "select firstname, lastname from employee where id = $dcreator";
$processgetindividualcreatorname = $db->query($get_individualcreatorname);
$row6 = $processgetindividualcreatorname->fetch_assoc();
$icfname = $row6['firstname'];
$iclname = $row6['lastname'];
echo "<h2 align='center'>Document Details</h2>";
start_table();
cell_blue_lft('Document Name and Control No.');
echo "<td>$dname || $did</td>";
cell_blue_lft('Security Class');
if($dsecurityclass == 'Top Secret'){
echo "<td style='background-color:#000000' align='center'><b><font color='white'>$dsecurityclass</font></b></td>"; // Black Background
} else if ($dsecurityclass == 'Secret') {
echo "<td style='background-color:#ff0000' align='center'><b><font color='white'>$dsecurityclass</font></b></td>"; // Red Background
} else if ($dsecurityclass == 'Confidential') {
echo "<td style='background-color:#0000FF' align='center'><b><font color='white'>$dsecurityclass</font></b></td>"; //
} else if ($dsecurityclass == 'Restricted'){
echo "<td style='background-color:#87CEFA' align='center'><b>$dsecurityclass</b></td>";
} else {
echo "<td align='center'><b>$dsecurityclass</b></td>";
}
echo "</tr>";
cell_blue_lft('Creator Office');
cell_lft($dcreatorofficename);
cell_blue_lft('Document Timeline');
cell_ctr($dtimeline);
echo "<tr>";
cell_blue_lft('Signatory');
cell_lft($dsignatory);
cell_blue_lft('Online Link');
if($donlinelink == null){
$donlinelink = "None";
} else {
$donlinelink = "<a target='_blank' href='$donlinelink'>View File</a>";
}
cell_ctr($donlinelink);
echo "</tr>";
echo "<tr>";
cell_blue_lft('Document Author');
echo "<td>$icfname $iclname</td>";
cell_blue_lft('Creation Date and Status');
cell_ctr("$dcreationdate / $dstatus");
echo "</tr>";
end_table();
$dsecurityclass = $dsecurityclass;
}
// TABLE FORMATTING FUNCTIONS
function start_table(){
echo "<table>";
echo "<table border='1' style='width:100%'>";
echo "<tr>";
}
function end_table(){
echo "</table>";
}
function cell_blue_lft($value){
echo "<td style='background-color:#87CEFA'>$value</td>";
}
function cell_blue_hdr_ctr($value){
echo "<td style='background-color:#87CEFA' align='center'><b>$value</b></td>";
}
function cell_blue_hdr_span($value, $span){
echo "<td style='background-color:#87CEFA' align='center' colspan='$span'><b>$value</b></td>";
}
function cell_ctr($value){
echo "<td align='center'>$value</td>";
}
function cell_ctr_link($value, $link){
echo "<td align='center'><a href='$link'>$value</a></td>";
}
function cell_ctr_span($value, $span){
echo "<td align='center' colspan='$span'>$value</td>";
}
function cell_lft($value){
echo "<td>$value</td>";
}
function cell_blue_ctr($value){
echo "<td style='background-color:#87CEFA' align='center'>$value</td>";
}
function cell_blue_ctr_order($value, $pagelink, $othervalue, $ordervalue){
echo "<td style='background-color:#87CEFA' align='center'><b><a href='$pagelink?$othervalue&orderby=$ordervalue'>$value</b></a></td>";
}
function header1($value){
echo "<h1 align='center'>$value</h1>";
}
function header2($value){
echo "<h2 align='center'>$value</h2>";
}
function boldtext($value){
echo "<b>$value</b>";
}
function italtext($value){
echo "<i>$value</i>";
}
function bolditaltext($value){
echo "<b><i>$value</i></b>";
}
// TABLE SQL STATEMENTS
/*
create view documentindividualtrack as select track.documentid as "DocumentID",
track.id as "TrackID",
track.recipientifperson as "RecipientPerson",
track.status as "TrackStatus"
from document, track
where track.documentid = document.id
and document.status = 'Open'
and track.status <> 'Acted Upon'
order by DocumentID ASC, TrackID ASC
*/
/*
create view trackdocumentindividual3 as
select track.documentid as "DocumentID",
document.name as "DocumentName",
track.id as "TrackID",
document.creationdate as "DocCreationDate",
track.source as "SourcePerson",
track.recipientifperson as "RecipientPerson",
track.status as "TrackStatus"
from document, track
where track.documentid = document.id
and document.status = 'Open'
and track.status <> 'Acted On'
order by DocumentID ASC, TrackID ASC
*/
/*
create view trackdocumentoffice as
select track.id as "TrackID",
document.id as "DocumentID",
document.creatoroffice as "DocumentCreatorOffice",
track.creationdate as "trackdate"
track.sourceoffice as "TrackSourceOffice",
track.recipientifoffice as "TrackRecipientOffice"
from track, document
where document.id = track.documentid and
track.status = "Sent" OR "Read"
*/
?>