-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.case.php
executable file
·1953 lines (1510 loc) · 62.4 KB
/
class.case.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
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
require_once 'class.layout.php';
require_once 'class.borrower.php';
require_once 'class.search.php';
require_once 'class.dbh.php';
error_reporting(0);
/**
* Class lqCase - Controller class for Case functionally
*
*
* This class handles all aspects of manipulating cases,
* a case is merely an ongoing query
*
* @author Peter Lorimer <[email protected]>
* @license Interleaf
* @copyright Interleaf Technology Ltd
* @package LQ
* Date: 22 July 2011
*/
class lqCase {
/**
* Function __construct()
*
* Class constructor, not yet used
*
*/
public function __construct()
{
}
/**
* Function __destruct()
*
* Class destructor, not yet used
*
*/
public function __destruct()
{
}
public function getLineItems($case_id)
{
global $dbh;
$even = 2;
$query = "select * from case_history where case_id =" . $case_id . " limit 0,6";
$res = $dbh->query($query);
//echo $query;
$data = "<table style='border-left:solid black 1px; border-right:solid black 1px;border-top:solid black 1px;border-bottom:solid black 1px;' width=85%>";//"<tr><th>Case#</th><th>User</th><td>Date</th><th>Details</th></tr>";
while ($obj = $dbh->fetch($res,''))
{
if ($even%2==0)
$color = '#f2f2f2';
else $color = '#d1d1d1';
$data .= '<tr bgcolor=' . $color . '><td>' .
'</td><td><font size=1>' . substr($obj->history_date,0,10) . '</font></td><td><font size=1>' .
substr($obj->history,0,160) . '</font></td></tr>';
$even++;
}
$data .= "</table>";
return $data;
}
/**
* Function __searchForm()
*
* Generates the HTML output for the case search form
*
*/
public function searchForm()
{
$html = "<center><font color=red size=+1><i>" . $_GET['error'] . "</i></font>
<form name=searchForm id=searchForm method=post autocomplete=off onSubmit='return validateSearchForm();'>
<p> <br><br>
<table cellspacing = 10 cellpadding=10>
<tr><td colspan=2><table cellspacing=5><tr><td>Search Type</td>
<td width=15> </td>
<td><input type=radio name=type value='local' checked></td>
<td>Local</td><td width=25> <td><input type=radio name=type value='consortium'></td><td>Consortium</td></tr></table>
<tr><td colspan=2><br><br></td></tr>
<tr><td align=right>Criteria </td><td>
<select id = criteria name=criteria onChange=toggleHidden(document.getElementById('search_dept')); appendOptionLast(count2++,\'undefined\'); >
<!-- <option value=none>Please choose ...</option> -->
<option value='all'>Everything</option>
<option value='case_id'>Case ID</option>
<option value='borrower'>Borrower</option>
<option value='department'>Department</option>
<option value='subject'>Subject</option>
<option value='header'>Case Header</option>
<option value='detail'>Case Details</option>
</select>
<span id=criteria_error class=criteria_error> -- Please choose a criteria</span>
</td></tr>
<tr ><td></td>
<td><select name= department id=search_dept class=hidden_dept>
<option value=0>Choose a department</option>";
$deptArr = Department::listAll($_SESSION['library_id']);
foreach ($deptArr as $obj)
{
$html .= '<option value = "' . $obj->department_id . '">' .
$obj->department . '</option>';
}
$html .= "
</select>
<span id=dept_error class=dept_error> -- Please choose a department</span>
</td></tr>
<tr><td align=right>Keyword </td><td><input type=text id=keywords name=keywords size=32 onkeyup=\"ajax_showSearchOptions(this,'getCountriesByLetters',event); return doFocus();\" onBlur=doBlur();></td></tr>
<tr><td align=right>From</td><td><input type=text name = from size=10 id=calendar4 onClick=document.getElementById('keywords').focus()>
To <input type=text name = to size=10 id=calendar5>
<span id=date_error class=date_error> -- In order to search by date blease chose both a from and to date</span>
</td></tr>
<tr><td colspan=2 align = right><center><input type=submit class = lq-button name=search value='Search'></td></tr>
</table> </p>
</form>
";
return $html;
}
/**
* Function searchResults()
*
* Displays the results form a case search in an HTML table
*
* {@source}
*/
public function searchResults($user_id='',$home='')
{
global $dbh;
$sTerm = $_POST['keywords'];
$from = lqCase::convertDate($_POST['from'],'us');
$to = lqCase::convertDate($_POST['to'],'us');
$even = 2;
if (isset($_POST['department']) && !empty($_POST['department']))
{
$department = $_POST['department'];
}
if (isset($_POST['keywords']) && !empty($_POST['keywords']))
{
$sTerm = $_POST['keywords'];
}
if (strpos(substr($sTerm,0,2),'"') == 1 && strpos(substr($sTerm,strlen($sTerm)-2,strlen($sTerm)),'"') == 1 )
{
$phrase = 'true';
}
else { $phrase = 'false';}
if (isset($_REQUEST['search']) || !empty($home))
{
switch ($_POST['criteria'])
{
case "borrower":
$results = lqSearch::searchByBorrower($sTerm);
lqSearch::displayResults($results);
break;
case "case_id":
$results = lqSearch::searchByCaseId($sTerm);
break;
case "header":
$results = lqSearch::searchByCaseHeader($sTerm);
lqSearch::displayResults($results);
break;
case "detail":
$results = lqSearch::searchByCaseDetails($sTerm);
lqSearch::displayResults($results);
break;
case "subject":
$results = lqSearch::searchBySubject($sTerm);
debug("in here" . $results);
lqSearch::displayResults($results);
break;
case "department":
$results = lqSearch::searchByDepartment($_POST['department'], $sTerm);
//die($_POST['department']);
lqSearch::displayResults($results);
break;
case "all":
$results = lqSearch::searchAll($sTerm);
lqSearch::displayResults($results);
break;
default:
$results = lqSearch::openCases($_SESSION['user_id']);
lqSearch::displayResults($results);
}
}
}
/**
public function searchResults1($user_id='',$home='')
{
global $dbh;
$sTerm = $_POST['keywords'];
$from = lqCase::convertDate($_POST['from'],'us');
$to = lqCase::convertDate($_POST['to'],'us');
$even = 2;
if (isset($_POST['keywords']) && !empty($_POST['keywords']))
{
$sTerm = $_POST['keywords'];
}
if (strpos(substr($sTerm,0,2),'"') == 1 && strpos(substr($sTerm,strlen($sTerm)-2,strlen($sTerm)),'"') == 1 )
{
$phrase = 'true';
}
else { $phrase = 'false';}
if (isset($sTerm))
{
$likeClause = " case_header LIKE '%" . $sTerm . "%'";
}
else { $likeClause = " 1 "; }
if (empty($user_id))
{
$user_id = $_SESSION['user_id'];
}
if ($home != '')
{
$extra = ' AND assigned_to = ' . $_SESSION['user_id'];
}
if ($_POST['type'] != 'local' && empty($home))
{
$query = "SELECT * from cases WHERE " .
$likeClause . " " .
" AND status = 'Open'";
}
else {
$query = "SELECT * from cases WHERE " .
$likeClause . " AND library_id = "
. $_SESSION['library_id'] .
" AND status = 'Open'";
}
if (isset($extra) && !empty($extra))
{
$query .= " " . $extra;
}
if (empty($home))
{
$caption = "Search Results";
}
else
{
$caption = "Open cases for " . $_SESSION['username'];
// $caption = "Search Results";
}
if (isset($_POST['search']) || !empty($home))
{
switch ($_POST['criteria'])
{
case "borrower":
lqSearch::searchByBorrower($_POST['criteria']);
break;
$borArr = explode(" ",$sTerm);
$whereClause = " WHERE surname = '" . substr($borArr[0],0,strlen($borArr[0])-1) . "' and firstname like '" . $borArr[1] . "%'";
/* foreach ($borArr as $bor)
{
if (!empty($bor))
$whereClause .= " or surname LIKE '%" . $bor . "%' or firstname like '%" .
$bor . "%' ";
}
*/ /*
$sql = "SELECT borrower_id FROM borrower" . $whereClause;
$res = $dbh->query($sql);
if (empty($from) || empty($to))
$borquery = "select * from cases where borrower_id in ( " .$sql . ")";
else
$borquery = "select * from cases where borrower_id in ( " .$sql . ") AND added_date BETWEEN '" . $from . "' AND '" . $to . "'";
debug("BORROWER Q" . $borquery);
break;
case "subject";
$query = "select distinct(case_id) from subjects, subject_case, cases where subject_case.subject_id=subjects.subject_id
AND subject_case.case_id = cases.caseid AND
subjects.subject LIKE '%" . $sTerm . "%' order by added_date desc";
break;
case "department":
$extra .= " AND department_id = " . $_POST['department'];
if (!empty($sTerm) )
$extra .= " AND (case_header LIKE '%" . $sTerm . "%' OR case_detail LIKE '%" . $sTerm . "%'" .
" OR case_response LIKE '%" . $sTerm . "%'" .
")"
;
if (!empty($from) && !empty($to))
{
$extra .= " AND added_date BETWEEN '" . $from . "' AND '" . $to . "' ";
}
break;
case "header":
$extra .= " AND case_header LIKE '%" . $sTerm . "%'";
if (!empty($from) && !empty($to))
{
$extra .= " AND added_date BETWEEN '" . $from . "' AND '" . $to . "' ";
}
break;
case "detail":
$extra .= " AND case_detail LIKE '%" . $sTerm . "%'";
if (!empty($from) && !empty($to))
{
$extra .= " AND added_date BETWEEN '" . $from . "' AND '" . $to . "' ";
}
break;
case "all":
$sTermArr = explode(" ", $sTerm);
$extra .= " AND (case_header LIKE '%" . $sTerm . "%'";
foreach ($sTermArr as $term)
{
if (!empty($term))
$extra .=
" or case_header LIKE '%" . $term . "%'" .
" or case_detail LIKE '%" . $term . "%'" .
" or case_response LIKE '%" . $term . "%'";
}
$extra .= ")";
break;
case "header":
$extra .= " AND case_detail LIKE '%" . $sTerm . "%'";
break;
}
// Find individual case
if ($_POST['criteria'] == 'case_id')
{
$sql = "SELECT * FROM cases WHERE caseid=" . $sTerm;
$res = $dbh->query($sql);
if (@$dbh->rows($res) > 0)
{
header("Location: /?op=cases&caseid=" . $sTerm);
}
else
{
print "<script>alert('This case does not exist');</script>";
$searchError = "Case+'<b>" . $sTerm . "</b>'+does+not+exist";
header("Location: /?op=search&error=" . $searchError);
}
}
if ($phrase == 'false' && $_POST['criteria'] == 'all')
{
$sTermArr = explode(" ",$sTerm);
/* $extra .= " AND (1 ";
foreach ($sTermArr as $term)
{
if (strlen($term) > 0)
$extra .= " OR case_header LIKE '%" . trim(trim($term,'\\"')) . "%' " .
" OR case_response LIKE '%" . trim(trim($term,'\\"')) . "%' " .
" OR case_detail LIKE '%" . trim(trim($term,'\\"')) . "%' ";
}
$extra .= ")";
*/ /*
if (!empty($from) && !empty($to))
{
$extra .= " and caseid in (
select caseid from cases where added_date between '" . $from . "' AND '" . $to . "')";
}
// $extra .= ") ";
$extra1 = $extra;
}
else {
$extra1 = lqCase::no_magic_quotes($extra);
}
if ($_POST['criteria'] == "subject")
{
$res = $dbh->query($query);
while ($obj = $dbh->fetch($res,''))
{
$subjArr[] = $obj->case_id;
}
$query = "SELECT * from cases WHERE 0 ";
$extra1 = "";
foreach ($subjArr as $case)
{
$extra1 .= " or caseid =" . $case;
}
$query = "select * from subject_case, subjects,cases where subject_case.subject_id=subjects.subject_id
AND subject_case.case_id = cases.caseid AND subjects.subject LIKE '%" . $sTerm ."%' ";
if (!empty($from) && !empty($to))
{
$query .= " AND caseid in ( select caseid from cases where added_date between
'" . $from . "' AND '" . $to . "' ) ";
}
debug("Search Query - Subject\r\n" . $query);
}
else {
if ($sTerm[0] == '"' && $sterm[strlen($sTerm)-1] == '"')
{
$sTerm2 = substr($sTerm,1,strlen($sTerm)-2);
$extra1 = " and case_header = '" . $sTerm2 . "' or case_detail = '" . $sTerm2 . "' or case_response = '" . $sTerm2 . "'";
}
if ($_POST['type'] == 'local')
{
$query = "SELECT distinct(caseid), status, cases.borrower_id, added_date, deadline_date, case_header, assigned_to from cases WHERE " .
" cases.library_id = "
. $_SESSION['library_id'] . $extra1 ;
debug("EXTRA: " . $extra1);
}
else {
$query = "SELECT distinct(caseid), status, cases.borrower_id, added_date, deadline_date, case_header, assigned_to from cases
WHERE ( (1" . $extra1 . ") AND status = 'open' or cases.library_id = " . $_SESSION['library_id'] . $extra1 . ")"
;
}
}
debug("Search query\r\n" . $query);
if ($_POST['criteria'] == "borrower")
{
$res = $dbh->query($borquery);
}
else
$res = $dbh->query($query);
$op = $_GET['op'];
if ($op == "")
$op = "home";
debug("SEARCH QUERY EXECUTED:" . $query);
debug("SEARCH TYPE:" . $_POST['type']);
$numRows = $dbh->rows($res);
if ($numRows <= 0 )
{
if ($op == "home")
echo "<p><font color=green><i>You have no open cases</i></font></p>";
else
echo "<p><font color=red><i>Your search returned no results. Please try a different search</i></font></p>";
}
else {
if ($sTerm == '')
$sTerm = ' none';
if ($home == '')
$caption .= ' - Showing ' . $numRows;
echo '<table border="0" cellpadding="0">
<tr><th class=admin colspan=7><font color=black>' . $caption .
'</font></th></tr>
<tr class = "admin">
<th class="admin" width="60" align=center>Case Id</th>
<th class="admin" width="60" align=center>Status</th>
<th class="admin" width="90" align=center>Date Added</th>
<th class="admin" width="160">Header</th>
<th class="admin" width="240">Borrower</th>
<th class="admin" width="100" align=center>Library</th>
</tr>
';
$today = date("Y-m-d");
while ($obj = $dbh->fetch($res,''))
{
$deadline = $obj->deadline_date;
debug("DEADLINE:DATE" . $deadline . ":" . $today);
if ($today >= $deadline)
$textColor = "red";
else $textColor = "black";
$theBorrower = new Borrower($obj->borrower_id);
if (empty($theBorrower->surName) && empty($theBorrower->firstName))
$borrowerName = "Anonymous";
else
$borrowerName = $theBorrower->surName . ', ' . $theBorrower->firstName;
if ($even%2==0)
$color = '#f2f2f2';
else $color = '#d1d1d1';
echo ' <tr bgcolor = ' . $color . '><td><a href=?op=cases&caseid=' . $obj->caseid . '>' .
$obj->caseid . '</a></td><td>' . $obj->status . '</td><td><font color=' . $textColor . '>'. lqCase::convertDate(substr($obj->added_date,0,10),'eu') .
'</font></a></td><td width="400"><a href=?op=cases&caseid=' . $obj->caseid . '>' . substr($obj->case_header,0,50) . '...' .
'</a></td><td>' . $borrowerName . '</td><td>' . $this->getLibrary($obj->caseid)->library . '</td>
</tr>';
$even++;
}
echo '</table>';
}
}
}*/
public function getLibrary($case_id)
{
global $dbh;
$query = "SELECT library.library_id, library.library from cases, library where cases.library_id=library.library_id and caseid = " . $case_id;
$res = $dbh->query($query);
$obj = $dbh->fetch($res);
// die($query);
return($obj);
}
/**
* Function getCatList()
*
* Creates a hash map of global category names with the id as an index
*
* {@source}
* @return array $catMap
*/
public function getCatList()
{
global $dbh;
$subjectsMap = array();
$sql = "SELECT category_id, category FROM category order by category asc";
$res = $dbh->query($sql);
while ($row = $dbh->fetch($res,'array'))
{
$catMap[$row['category_id']] = $row['category'];
}
return $catMap;
}
/**
* Function subjectId()
*
* Returns the subject_id given a subject name
* {@source}
* @param string $subject
*
* @return integer $subject_id
*/
public function subjectId($subject)
{
global $dbh;
$sql = "SELECT subject_id FROM subjects where subject = '" . $subject . "'";
$res = $dbh->query($sql);
$obj = $dbh->fetch($res,'');
return $obj->subject_id;
}
/**
* Function getSubjectList()
*
* Creates a hash map of global suject names with the id as an index
* based on a user supplied search term
*
* {@source}
* @param string $term
* @return array $subjectMap
*/
public function getSubjectList($term)
{
global $dbh;
$subjectsMap = array();
$sql = "SELECT subject_id, subject FROM subjects where subject = '" . $this->sanitizeFormData($term) . "' order by subject asc";
$res = $dbh->query($sql);
$rows = $dbh->rows($res);
if ($rows == 0)
{
$sql = "SELECT subject_id, subject FROM subjects where subject like '" . $this->sanitizeFormData($term) . "%' order by subject asc";
$res = $dbh->query($sql);
}
while ($row = $dbh->fetch($res,'array'))
{
$subjectsMap[$row['subject_id']] = $row['subject'];
}
return $subjectsMap;
}
/**
* Function addSubjects()
*
* Takes a list of subjects and adds them to the database
*
* {@source}
* @param string $data
*
*/
public function addSubjects($data)
{
global $dbh;
$subjArr = preg_split('/\R/',$data);
foreach ($subjArr as $subj)
{
$subj1 = preg_replace('/(?<!,) /', '_', $subj);
$sql = "INSERT INTO subjects (subject) VALUES ('" .$subj1 . "')";
$dbg[] = $sql;
}
echo '<!--';
print_r($dbg);
echo '-->';
}
/**
* Function departmentId()
*
* Returns the department given a case_id
* {@source}
* @param integer $case_id
*
* @return integer $department_id
*/
public function departmentId($case_id)
{
global $dbh;
$sql = "SELECT department_id FROM cases where caseid = " . $case_id;
$res = $dbh->query($sql);
$obj = $dbh->fetch($res,'');
$sql = "SELECT * FROM department where department_id = " . $obj->department_id;
$res = $dbh->query($sql);
$obj = $dbh->fetch($res,'');
return $obj;
}
public function sanitizeFormData($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
/**
* Function addCatForm()
*
* Generates the HTML for adding a category user input
*
*/
public function addCatForm($page)
{
echo '<h2 align="center">' . $page . '</h2><br>';
$form = new HTML_Form();
$output = '<p>' .
$form->startForm('#', 'post', 'frmAddCat',array('name'=>'addUser','autocomplete'=>'off','onSubmit'=>'return validateCatForm()')) .
'<center><table><tr><td>' .
$form->addLabelFor('catname', 'Category Name') . ' </td><td>' .
$form->addInput('text', 'catname', $name, array('id'=>'catname', 'size'=>32, 'maxlength'=>50) ) .
'<span id="catame_error" class="catname_error"> -- This Field is Required</span></td></tr><tr>' .
'<td colspan="2" align=center>' . $form->addInput('submit', 'btnAddCategory', "Add this Category",array('class'=>'lq-button')) . '</td></tr>
</table>
</center><br><br>';
return $output;
}
/**
* Function addCat()
*
* Adds a category based on user input
*
* {@source}
*/
public function addCat()
{
global $dbh;
$cat = $_REQUEST['catname'];
$query = "SELECT category FROM category where category = '" . $cat . "'";
$res = $dbh->query($query);
$rows = $dbh->rows($res);
if (!empty($cat))
{
if ($rows > 0)
{
$errorStack[] = "ERROR: " . $cat . " is already in the database";
}
else {
$query = "INSERT INTO category (category)" .
"VALUES ('" .
$cat .
"')"
;
if ($res = $dbh->query($query))
{
echo "<script>alert('Record Added'); location.href='?op=editcat';</script>";
}
else
echo "<script>alert('There was an error adding this record'); location.href='?op=editcat';</script>";
}
if (count($errorStack) > 0)
{
foreach ($errorStack as $error)
{
echo '<span class="errorStack"><center>' . $error . '</center></span>';
}
}
}
}
public function saveCat($cat_id,$cat)
{
global $dbh;
$query = "UPDATE category SET category = '" . $cat . "' WHERE category_id = " . $cat_id;
$dbh->query($query);
header("Location: ?op=editcat");
}
/**
* Function viewCats()
*
* Displays categories with option to edit or delete
*
*
*/
public function viewCats()
{
global $dbh;
$even = 2;
if (isset($_REQUEST['cid']) && !empty($_REQUEST['cid']))
{
$query = "SELECT * FROM category WHERE category_id = " . $_REQUEST['cid'];
$res = $dbh->query($query);
$row = $dbh->fetch($res,'');
echo "<center><form action = ?op=savecat METHOD=POST><input type=text name=cat value = '" . $row->category . "'>
<input type=hidden name=cat_id value=" . $_REQUEST['cid'] . ">
<input type=submit value=Update class=lq-button></form></center>";
}
else {
$query = "SELECT * from category";
$res = $dbh->query($query);
echo '<center><h2>View / Modify Categories </h2><br>
<table width=600>
<tr bgcolor = "#343434">
<th class=admin>Id</th><th class=admin>Category Name</th>
<th colspan="2" class=admin>Action</th>
</tr>';
while ($row = $dbh->fetch($res,''))
{
if ($even%2==0)
$color = '#e0e0e0';
else $color = '#a1a1a1';
echo '<tr bgcolor=' . $color . ' class="results"><td>' . $row->category_id . '</td>
<td class="results">' . $row->category . '</td>
<td align=right width=30><a href =?op=editcat&cid=' . $row->category_id . '>Edit</a></td><td align=right width=40><a href=?op=delcat&cid=' . $row->category_id . '>Delete</td></tr>';
$even++;
}
echo '</table>';
}
}
/**
* Function delCats()
*
* Deletes a category
*
*
*/
public function delCat()
{
global $dbh;
$id = $_REQUEST['cid'];
if (!empty($id))
{
$query = "DELETE FROM category where category_id = " . $id;
$res = $dbh->query($query);
}
if ($res)
{
echo '<script>alert("Record Deleted"); location.href="?op=editcat"</script>';
}
else {
echo '<script>alert("ERROR:\r\n This record cannot be deleted. Please contact your systems administrator, the message acssociated with this error is \"Referrential Integrity Violation\""); location.href="?op=editcat"</script>';
}
}
public function isMember($borrower_id)
{
global $dbh;
$rtn = array();
$sql = "SELECT member FROM borrower WHERE borrower_id = " . $borrower_id;
$res = $dbh->query($sql);
$obj = $dbh->fetch($res,'');
$rtn[0] = $obj->member;
if ($obj->member == 1)
$rtn[1] = 'true';
else
$rtn[1] = 'false';
return $rtn;
}
/**
* Function processCaseData()
*
* Processes Case data by addin/updating a database record based on user input
* This function adds data to several tables insice a transaction with rollback
* capabilities
*
* {@sourse}
*
*/
public function processCaseData()
{
global $dbh;
$borrower = str_replace("'","`",$_REQUEST['borrower']);
$department_id = 1;
$borrower_id = $this->sanitizeFormData($_REQUEST['borrower_hidden']);
$status = $this->sanitizeFormData($_REQUEST['status']);
$borrowerType = $this->sanitizeFormData($_REQUEST['borrowerType']);
$borrowerIsMember = $this->sanitizeFormData($_REQUEST['borrowerIsMember']);
if ($borrowerIsMember == '')
$borrowerIsMember = 0;
$addrStreet = $this->sanitizeFormData($_REQUEST['addrStreet']);
$addrArea = $this->sanitizeFormData($_REQUEST['addrArea']);
$addrTown = $this->sanitizeFormData($_REQUEST['addrTown']);
$addrCounty = $this->sanitizeFormData($_REQUEST['addrCounty']);
$country = $this->sanitizeFormData($_REQUEST['country']);
$phone = $this->sanitizeFormData($_REQUEST['phone']);
$email = $this->sanitizeFormData($_REQUEST['email']);
$dateAdded = lqCase::convertDate(substr($this->sanitizeFormData($_REQUEST['dateAdded']),0,10),'us');
$deadline = $this->sanitizeFormData($_REQUEST['deadline']);
$source = $this->sanitizeFormData($_REQUEST['source']);
$reviewAfter = $this->sanitizeFormData($_REQUEST['reviewAfter']);
$category_id = $this->sanitizeFormData($_REQUEST['category']);
$caseHeader = $this->sanitizeFormData($_REQUEST['caseHeader']);
$subjects = $_REQUEST['subjects'];
$caseDetail = $this->sanitizeFormData($_REQUEST['caseDetail']);
$caseResponse = $this->sanitizeFormData($_REQUEST['caseResponse']);
$caseHistory = $this->sanitizeFormData($_REQUEST['caseHistory']);
$referredTo = $this->sanitizeFormData($_REQUEST['referredTo']);
$caseNotes = $this->sanitizeFormData($_REQUEST['caseNotes']);
$responseDate = $this->sanitizeFormData($_REQUEST['responseDate']);
$responseType = $this->sanitizeFormData($_REQUEST['responseType']);
$querySrc = $this->sanitizeFormData($_REQUEST['sourceType']);
$publish = $this->sanitizeFormData($_REQUEST['publish']);
$assigned_to = $this->sanitizeFormData($_REQUEST['assignedTo']);
$assigned_by = $this->sanitizeFormData($_REQUEST['assignedBy']);
$referred_to = $this->sanitizeFormData($_REQUEST['referredTo']);
$category = $this->sanitizeFormData($_REQUEST['category']);
$error = false;
if (empty($borrowerIsMember))