This repository has been archived by the owner on Oct 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Browse.php
executable file
·1237 lines (1055 loc) · 43.5 KB
/
Browse.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
/**
* Class for retriving data for listing purposes.
*
* This file is part of OpenEvsys.
*
* Copyright (C) 2009 Human Rights Information and Documentation Systems,
* HURIDOCnameS), http://www.huridocs.org/, info@huridocs.org
*
* OpenEvsys is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenEvsys is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author J P Fonseka <jo@respere.com>
* @author Kethees S <ks@respere.com>
* @author Nilushan Silva <nilushan@respere.com>
* @author Mahesh K K S <jo@respere.com>>
*
* @package OpenEvsys
* @subpackage DataModel
*
*/
interface BrowseStrategy
{
public function ExecuteQuery($query);
}
class Browse implements BrowseStrategy
{
public function __construct($table = false, $pkeyarr=false, $db=false, $options=array())
{
global $global;
$this->db = $global['db'];
}
public static function setPager(shnPager &$pager)
{
$this->pager = $pager;
}
function ExecuteQuery($qry)
{
$db = $this->db; if (!$db) return false;
$save = $db->SetFetchMode(ADODB_FETCH_ASSOC);
$rows = $db->GetAll($qry);
$db->SetFetchMode($save);
if(sizeof($rows) > 0)
return $rows;
else
return null;
}
function ExecuteNonQuery($qry)
{
$db = $this->db; if (!$db) return false;
//$save = $db->SetFetchMode(ADODB_FETCH_ASSOC);
$ret = $db->Execute($qry);
return $ret;
}
function AutoExecute($table, $array , $option)
{
$db = $this->db; if (!$db) return false;
return $db->AutoExecute($table,$array,$option);
}
function GetInsertID()
{
$db = $this->db; if (!$db) return false;
return $db->Insert_ID();
}
public static function getExecuteSql($sql)
{
$pager = new shnPager($sql);
return $pager;
}
public static function getSaveQueryList($options=null)
{
global $global;
$sql = "SELECT * FROM save_query WHERE 1=1 ";
if(isset($options['save_query_record_number'])){
$name = $global['db']->qstr("%{$options['save_query_record_number']}%");
$where .="AND name LIKE $name";
}
if(isset($options['name'])){
$name = $global['db']->qstr("%{$options['name']}%");
$where .="AND name LIKE $name";
}
if(isset($options['description'])){
$description = $global['db']->qstr("%{$options['description']}%");
$where .="AND description LIKE $description";
}
if(isset($options['created_date'])){
$created_date = $global['db']->qstr("%{$options['created_date']}%");
$where .="AND created_date LIKE $created_date";
}
if(isset($options['created_by'])){
$created_by = $global['db']->qstr("%{$options['created_by']}%");
$where .="AND created_by LIKE $created_by";
}
$sql = $sql . $where;
$pager = new shnPager($sql);
return $pager;
}
public static function getPersonVictimRoleList($person_id)
{
global $conf;
$sql = "SELECT a.act_record_number as record_number,
IFNULL(l.msgstr , v.english) as 'further_infor',
a.event,
e.event_title,
e.initial_date,
e.final_date
FROM person p
INNER JOIN act a ON p.person_record_number = a.victim
INNER JOIN event e ON e.event_record_number = a.event
INNER JOIN mt_vocab v ON a.type_of_act = v.vocab_number
LEFT JOIN mt_vocab_l10n l ON ( l.msgid = v.vocab_number AND l.locale = '{$conf['locale']}' )";
$where = " WHERE p.person_record_number = '$person_id'";
$sql .= $where;
$pager = new shnPager($sql);
return $pager;
}
public static function getPersonSourceRoleList($person_id)
{
global $conf;
$sql = "SELECT i.information_record_number as record_number,
IFNULL(l.msgstr , v.english) as 'further_infor',
i.event,
e.event_title,
e.initial_date,
e.final_date
FROM person p
INNER JOIN information i ON p.person_record_number = i.source
INNER JOIN event e ON e.event_record_number = i.event
INNER JOIN mt_vocab v ON i.source_connection_to_information = v.vocab_number
LEFT JOIN mt_vocab_l10n l ON ( l.msgid = v.vocab_number AND l.locale = '{$conf['locale']}' )";
$where = " WHERE p.person_record_number = '$person_id'";
$sql .= $where;
$pager = new shnPager($sql);
return $pager;
}
public static function getPersonPerpetratorRoleList($person_id)
{
global $conf;
$sql = "SELECT i.involvement_record_number as record_number,
IFNULL(l.msgstr , v.english) as 'further_infor',
i.event,
e.event_title,
e.initial_date,
e.final_date
FROM person p
INNER JOIN involvement i ON p.person_record_number = i.perpetrator
INNER JOIN event e ON e.event_record_number = i.event
INNER JOIN mt_vocab v ON i.degree_of_involvement = v.vocab_number
LEFT JOIN mt_vocab_l10n l ON ( l.msgid = v.vocab_number AND l.locale = '{$conf['locale']}' )";
$where = " WHERE p.person_record_number = '$person_id'";
$sql .= $where;
$pager = new shnPager($sql);
return $pager;
}
public static function getPersonInterveningPartyRoleList($person_id)
{
global $conf;
$sql = "SELECT i.intervention_record_number as record_number,
IFNULL(l.msgstr , v.english) as 'further_infor',
i.event,
e.event_title,
e.initial_date,
e.final_date
FROM person p
INNER JOIN intervention i ON p.person_record_number = i.intervening_party
INNER JOIN event e ON e.event_record_number = i.event
INNER JOIN mlt_intervention_type_of_intervention mlt
ON mlt.record_number=i.intervention_record_number
INNER JOIN mt_vocab v ON mlt.vocab_number = v.vocab_number
LEFT JOIN mt_vocab_l10n l ON ( l.msgid = v.vocab_number AND l.locale = '{$conf['locale']}' )";
$where = " WHERE p.person_record_number = '$person_id'";
$sql .= $where;
$pager = new shnPager($sql);
return $pager;
}
public static function getBiographyList($person_id)
{
global $conf;
$sql = "SELECT
bd.biographic_details_record_number,
bd.related_person,
rp.person_name,
IFNULL(l.msgstr , mt.english) as 'relationship_type',
bd.initial_date,
bd.final_date
FROM biographic_details AS bd
INNER JOIN person p ON bd.person = p.person_record_number
LEFT JOIN person rp ON bd.related_person = rp.person_record_number
LEFT JOIN mt_vocab mt ON bd.type_of_relationship = mt.vocab_number
LEFT JOIN mt_vocab_l10n l ON ( l.msgid = mt.vocab_number AND l.locale = '{$conf['locale']}' )
WHERE person = '$person_id'";
$browse = new Browse();
$rows = $browse->ExecuteQuery($sql);
return $rows;
}
public static function getRelativeInfo($person_id)
{
global $conf;
$sql = "SELECT
bd.biographic_details_record_number,
bd.related_person,
p.person_name,
IFNULL(l.msgstr , mt.english) AS 'relationship_type',
bd.initial_date,
bd.final_date ,
bd.person
FROM biographic_details AS bd
INNER JOIN person p ON bd.person = p.person_record_number
LEFT JOIN person rp ON bd.related_person = rp.person_record_number
LEFT JOIN mt_vocab mt ON bd.type_of_relationship = mt.vocab_number
LEFT JOIN mt_vocab_l10n l ON ( l.msgid = mt.vocab_number AND l.locale = '{$conf['locale']}' )
WHERE bd.related_person = '$person_id'";
$browse = new Browse();
$rows = $browse->ExecuteQuery($sql);
return $rows;
}
public static function getBiographyListArray($biographics)
{
global $conf;
$sql = "SELECT
bd.biographic_details_record_number,
bd.related_person,
rp.person_name,
IFNULL(l.msgstr , mt.english) AS 'relationship_type',
bd.initial_date,
bd.final_date
FROM biographic_details AS bd
INNER JOIN person p ON bd.person = p.person_record_number
LEFT JOIN person rp ON bd.related_person = rp.person_record_number
LEFT JOIN mt_vocab mt ON bd.type_of_relationship = mt.vocab_number
LEFT JOIN mt_vocab_l10n l ON ( l.msgid = mt.vocab_number AND l.locale = '{$conf['locale']}' )";
$where =' WHERE bd.biographic_details_record_number IN (';
if($biographics != null){
foreach($biographics as $biographic)
$where .= " '$biographic' ,";
$sql = $sql . rtrim($where,',') . " )";
$browse = new Browse();
$rows = $browse->ExecuteQuery($sql);
}
else{
$rows = null;
}
return $rows;
}
public static function getPersonVictimList($data)
{
$sql = "SELECT DISTINCT p.*
FROM person AS p
INNER JOIN act AS a ON p.person_record_number = a.victim
INNER JOIN involvement as i ON a.act_record_number = i.act
INNER JOIN person AS p2 ON i.perpetrator = p2.person_record_number
WHERE a.event='{$data['event_id']}'";
$pager = new shnPager($sql);
return $pager;
}
public static function getImportErrorLogList()
{
$sql = "SELECT i.*
FROM import_log_report AS i ";
$pager = new shnPager($sql);
return $pager;
}
public static function getUserListArray($users){
$sql = "SELECT * , u.username as username FROM user AS u
LEFT JOIN user_profile AS up ON u.username=up.username";
$where =' WHERE u.username IN (';
foreach($users as $user)
$where .= " '$user' ,";
$sql = $sql . rtrim($where,',') . " )";
$browse = new Browse();
$rows = $browse->ExecuteQuery($sql);
return $rows;
}
public static function getSourceListforEvent($event = null, $person = null)
{
global $conf;
$browse = new Browse();
$sql = "SELECT i.source,
i.related_person,
i.related_event,
i.event,
i.information_record_number,
i.date_of_source_material,
p.person_name,
p.reliability_as_source,
IFNULL(l.msgstr , v.english) AS 'connection'
FROM event e
INNER JOIN information i ON e.event_record_number = i.event
INNER JOIN person p ON i.source = p.person_record_number
INNER JOIN mt_vocab v ON i.source_connection_to_information = v.vocab_number
LEFT JOIN mt_vocab_l10n l ON ( l.msgid = v.vocab_number AND l.locale = '{$conf['locale']}' ) ";
if($event != null && $person != null){
$where = "WHERE event = '$event' AND i.source = '$person' ";
}
else if($event != null){
$where = "WHERE event = '$event'";
}
$sql .= $where;
$rows = $browse->ExecuteQuery($sql);
return $rows;
}
public static function getSourceListArray($informations = null)
{
global $conf;
$sql = "SELECT i.source,
i.related_person,
i.related_event,
i.event,
i.information_record_number,
i.date_of_source_material,
p.person_name,
p. reliability_as_source,
IFNULL(l.msgstr , v.english) AS 'connection'
FROM event e
INNER JOIN information i ON e.event_record_number = i.event
INNER JOIN person p ON i.source = p.person_record_number
INNER JOIN mt_vocab v ON i.source_connection_to_information = v.vocab_number
LEFT JOIN mt_vocab_l10n l ON ( l.msgid = v.vocab_number AND l.locale = '{$conf['locale']}' ) ";
$where =' WHERE i.information_record_number IN (';
if($informations != null){
foreach($informations as $information)
$where .= " '$information' ,";
$sql = $sql . rtrim($where,',') . " )";
$browse = new Browse();
$rows = $browse->ExecuteQuery($sql);
}
else{
$rows = null;
}
return $rows;
}
public static function getVpList($event)
{
$browse = new Browse();
$res = $browse->ExecuteQuery("
SELECT
(SELECT count(*) FROM involvement WHERE act = act_record_number) AS inv_count,
initial_date ,
p.person_name AS vname ,
p.person_record_number AS victim_record_number,
a.victim ,
type_of_act,
act_record_number,
i.perpetrator,
p2.person_name AS pname,
p2.person_record_number AS perpetrator_record_number,
i.involvement_record_number,
i.degree_of_involvement
FROM act AS a
INNER JOIN person AS p ON a.victim = p.person_record_number
LEFT JOIN involvement as i ON a.act_record_number = i.act
LEFT JOIN person AS p2 ON i.perpetrator = p2.person_record_number
WHERE a.event='$event' ORDER BY act_record_number");
return $res;
}
public static function getVpListArray($acts)
{
$sql = "SELECT initial_date ,
p.person_name AS vname ,
a.victim ,
type_of_act,
act_record_number,
i.perpetrator,
p2.person_name AS pname,
i.involvement_record_number,
i.degree_of_involvement
FROM act AS a
INNER JOIN person AS p ON a.victim = p.person_record_number
LEFT JOIN involvement as i ON a.act_record_number = i.act
LEFT JOIN person AS p2 ON i.perpetrator = p2.person_record_number";
$where =' WHERE a.act_record_number IN (';
if($acts != null){
foreach($acts as $act)
$where .= " '$act' ,";
$sql = $sql . rtrim($where,',') . " )";
$browse = new Browse();
$rows = $browse->ExecuteQuery($sql);
}
else{
$rows = null;
}
return $rows;
}
public static function getVpListInvArray($invs)
{
$sql = "SELECT initial_date ,
p.person_name AS vname ,
a.victim ,
type_of_act,
act_record_number,
i.perpetrator,
p2.person_name AS pname,
i.involvement_record_number,
i.degree_of_involvement
FROM act AS a
INNER JOIN person AS p ON a.victim = p.person_record_number
LEFT JOIN involvement as i ON a.act_record_number = i.act
LEFT JOIN person AS p2 ON i.perpetrator = p2.person_record_number";
$where =' WHERE i.involvement_record_number IN (';
if($invs != null){
foreach($invs as $inv)
$where .= " '$inv' ,";
$sql = $sql . rtrim($where,',') . " )";
$browse = new Browse();
$rows = $browse->ExecuteQuery($sql);
}
else{
$rows = null;
}
return $rows;
}
public static function getIntvList($event)
{
$browse = new Browse();
$res = $browse->ExecuteQuery("
Select i.date_of_intervention,
ip.person_name,
i.intervening_party,
i.intervention_record_number
From intervention AS i
LEFT JOIN person AS ip ON i.intervening_party=ip.person_record_number
WHERE i.event='$event'");
return $res;
}
public static function getIntvTypes($intervention)
{
$browse = new Browse();
$res = $browse->ExecuteQuery("
Select
mlt.vocab_number AS type_of_intervention
From intervention AS i
LEFT JOIN mlt_intervention_type_of_intervention AS mlt
ON mlt.record_number=i.intervention_record_number
WHERE i.intervention_record_number='$intervention'");
return $res;
}
public static function getIntvListArray($interventions)
{
$sql = "Select i.date_of_intervention,
ip.person_name,
mlt.vocab_number AS type_of_intervention,
i.intervening_party,
i.intervention_record_number
From intervention AS i
LEFT JOIN person AS ip ON i.intervening_party=ip.person_record_number
LEFT JOIN mlt_intervention_type_of_intervention AS mlt
ON mlt.record_number=i.intervention_record_number";
$where =' WHERE i.intervention_record_number IN (';
if($interventions != null){
foreach($interventions as $intervention)
$where .= " '$intervention' ,";
$sql = $sql . rtrim($where,',') . " )";
$browse = new Browse();
$rows = $browse->ExecuteQuery($sql);
}
else{
$rows = null;
}
return $rows;
}
public static function getUserList()
{
$sql = "SELECT U.username, first_name, last_name, organization, designation, email, address , role ,status FROM user_profile AS UP RIGHT JOIN user AS U ON U.username = UP.username";
//filter options
$pager = new shnPager($sql);
return $pager;
}
public static function getPerpetrator($id)
{
$browse = new Browse();
$res = $browse->ExecuteQuery("Select person_name from person where person_record_number = '$id'");
return $res;
}
public static function getEntityFields($entity)
{
global $conf;
$browse = new Browse();
$sql = "Select d.* ,
IFNULL(l.msgstr , d.field_label) AS 'field_label_l10n'
FROM data_dict d
LEFT JOIN data_dict_l10n l ON ( l.msgid = d.field_number AND l.locale = '{$conf['locale']}' )
WHERE entity = '$entity' ORDER BY CAST(label_number as UNSIGNED)";
$res = $browse->ExecuteQuery($sql);
return $res;
}
public static function getSecondaryEntityFields($entity,$secondary_entity)
{
global $conf;
$sql = " SELECT
d.*,
ss.field_option AS shuffel_search,
sr.field_option AS shuffel_search_view
FROM data_dict AS d
INNER JOIN sec_entity_entities AS se ON (d.entity=se.entity )
LEFT JOIN sec_entity_fields AS ss ON ( se.entity_key = ss.entity_key AND ss.field_name = d.field_name AND ss.field_option='search')
LEFT JOIN sec_entity_fields AS sr ON ( se.entity_key = sr.entity_key AND sr.field_name = d.field_name AND sr.field_option='search_view')
WHERE d.entity='$entity' AND se.sec_entity='$secondary_entity' ORDER BY CAST(label_number as UNSIGNED)";
$browse = new Browse();
$res = $browse->ExecuteQuery($sql);
return $res;
}
public static function getChainOfEvents($eid)
{
$sql = "SELECT coe.chain_of_events_record_number as coe_id,
coe.related_event,
coe.type_of_chain_of_events,
e.initial_date,
e.event_title
FROM chain_of_events as coe
INNER JOIN event as e ON e.event_record_number = coe.related_event";
$where = " WHERE coe.event = '$eid'";
$sql .= $where;
$browse = new Browse();
$res = $browse->ExecuteQuery($sql);
return $res;
}
public static function getActsOfEvents($eid)
{
$sql = "SELECT act_record_number, event, initial_date, final_date, type_of_act, exact_location
FROM act ";
$where = " WHERE event = '$eid'";
$sql .= $where;
$browse = new Browse();
$res = $browse->ExecuteQuery($sql);
return $res;
}
public static function getInvolvementsOfEvents($eid)
{
$sql = "SELECT involvement_record_number, act, event, degree_of_involvement, latest_status_as_perpetrator_in_the_act, remarks
FROM involvement";
$where = " WHERE event = '$eid'";
$sql .= $where;
$browse = new Browse();
$res = $browse->ExecuteQuery($sql);
return $res;
}
public static function getInformationsOfEvents($eid)
{
$sql = "SELECT information_record_number, source_connection_to_information, date_of_source_material, remarks, reliability_of_information
FROM information";
$where = " WHERE event = '$eid'";
$sql .= $where;
$browse = new Browse();
$res = $browse->ExecuteQuery($sql);
return $res;
}
public static function getInterventionsOfEvents($eid)
{
$sql = "SELECT intervention_record_number,impact_on_the_situation, date_of_intervention, remarks, intervention_status
FROM intervention";
$where = " WHERE event = '$eid'";
$sql .= $where;
$browse = new Browse();
$res = $browse->ExecuteQuery($sql);
return $res;
}
public static function getEventCOE($eid)
{
$sql = "SELECT coe.chain_of_events_record_number as coe_id, coe.event,
coe.type_of_chain_of_events, e.initial_date, e.event_title
FROM chain_of_events as coe
INNER JOIN event as e ON e.event_record_number = coe.event";
$where = " WHERE coe.related_event = '$eid'";
$sql .= $where;
$browse = new Browse();
$res = $browse->ExecuteQuery($sql);
return $res;
}
public static function getCOEListArray($coes)
{
$sql = "SELECT coe.chain_of_events_record_number as coe_id,
coe.related_event,
coe.type_of_chain_of_events,
e.initial_date,
e.event_title
FROM chain_of_events as coe
INNER JOIN event as e ON e.event_record_number = coe.related_event";
$where =' WHERE coe.chain_of_events_record_number IN (';
if($coes != null){
foreach($coes as $coe)
$where .= " '$coe' ,";
$sql = $sql . rtrim($where,',') . " )";
$browse = new Browse();
$rows = $browse->ExecuteQuery($sql);
}
else{
$rows = null;
}
return $rows;
}
public static function getEvent($eid)
{
$browse = new Browse();
$res = $browse->ExecuteQuery("SELECT * FROM event WHERE event_record_number='$eid'");
return $res;
}
public static function getFields($entity)
{
global $conf;
$browse = new Browse();
$sql = "SELECT
field_number,
field_label,
field_name,
field_type,
label_number,
clar_note,
enabled ,
visible_new ,
visible_edit ,
visible_view,
visible_browse,
visible_browse_editable ,
visible_search ,
visible_search_display,
required ,
validation ,
essential,
l.msgstr AS field_label_l10n
FROM data_dict
LEFT JOIN data_dict_l10n as l ON ( l.msgid = field_number AND l.locale = '{$conf['locale']}' )
WHERE entity='$entity' ORDER BY CAST(label_number as UNSIGNED)";
$res = $browse->ExecuteQuery($sql);
return $res;
}
public static function getFieldsIds($entity)
{
$browse = new Browse();
$res = $browse->ExecuteQuery("SELECT field_number,field_name , essential FROM data_dict WHERE entity='$entity' ORDER BY CAST(label_number as UNSIGNED)");
return $res;
}
public static function getAuditLogForEvent($event_record_number){
$browse = new Browse();
$sql = "SELECT audit_log.* FROM audit_log WHERE module='events' AND module_record_number='$event_record_number'
UNION
SELECT audit_log.* FROM audit_log
inner JOIN (SELECT distinct(`record_number`) FROM audit_log WHERE module='events' AND module_record_number='$event_record_number' and `entity`='person') as p
ON p.record_number = audit_log.record_number
ORDER BY timestamp ASC" ;
$pager = new shnPager($sql);
return $pager;
}
public static function getAuditLogForPerson($person_record_number){
$browse = new Browse();
$res = $browse->ExecuteQuery("SELECT * FROM audit_log WHERE module='person' AND module_record_number='$person_record_number'
UNION
SELECT * FROM audit_log WHERE entity='person' AND module = 'events' AND record_number='$person_record_number' ORDER BY timestamp
");
return $res;
}
public static function getAuditLogForDocument($document_record_number){
$browse = new Browse();
$sql = "SELECT * FROM audit_log WHERE module='docu' AND module_record_number='$document_record_number'
UNION
SELECT * FROM audit_log WHERE (entity LIKE '%_doc' OR entity ='supporting_docs_meta') AND record_number='$document_record_number'
ORDER BY timestamp ";
$res = $browse->ExecuteQuery($sql);
return $res;
}
public static function gethelp($id){
global $global;global $conf;
$browse= new Browse();
$id = $global['db']->qstr($id);
// $sql = "SELECT * FROM help WHERE field_number = $id ";
$sql = "SELECT
d.field_number ,
IFNULL(dl.msgstr , d.field_label) as 'field_label',
IFNULL(hl.definition , h.definition) as 'definition',
IFNULL(hl.guidelines , h.guidelines) as 'guidelines',
IFNULL(hl.entry , h.entry) as 'entry',
IFNULL(hl.examples , h.examples) as 'examples'
FROM data_dict AS d
LEFT JOIN help AS h ON h.field_number = d.field_number
LEFT JOIN help_l10n AS hl ON (hl.field_number = d.field_number AND hl.locale = '{$conf['locale']}')
LEFT JOIN data_dict_l10n AS dl ON (d.field_number = dl.msgid AND dl.locale = '{$conf['locale']}' )
WHERE d.field_number = $id ";
$res = $browse->ExecuteQuery($sql);
return $res;
}
public static function getAllDocuments(BrowseStrategy $browse , $data = null)
{
$sql = "SELECT docs.doc_id as doc_id, docs.uri as uri, meta.title as title, meta.creator as creator, meta.description as description, meta.dateCreated as dateCreated, meta.dateSubmitted as dateSubmitted, meta.format as format, meta.language as language, meta.subject as subject FROM supporting_docs as docs, supporting_docs_meta as meta WHERE docs.doc_id=meta.doc_id";
//filter options
if($data['title']!='')
$and = " AND meta.title LIKE '%{$data['title']}%'";
if($data['creator']!='')
$and = " AND meta.creator LIKE '%{$data['creator']}%'";
if($data['dateCreated']!='')
$and = " AND meta.dateCreated LIKE '%{$data['dateCreated']}%'";
if($data['dateSubmitted']!='')
$and = " AND meta.dateSubmitted LIKE '%{$data['dateSubmitted']}%'";
if($data['Description']!='')
$and = " AND meta.description LIKE '%{$data['Description']}%'";
$sql = $sql.$and;
return $browse->ExecuteQuery($sql);
}
public static function getDocumentLinks($doc_id , $entity = null)
{
if(!isset($entity)) return null;
$sql = "SELECT * FROM {$entity}_doc WHERE doc_id = '$doc_id'";
$browse = new Browse();
return $browse->ExecuteQuery($sql);
}
public static function getHelpText($entity,$filter = null)
{
global $global;global $conf;
$entity = $global['db']->qstr($entity);
$sql = "SELECT
IFNULL(dl.msgstr , d.field_label) as 'field_label',
d.field_number,
h.definition,
h.guidelines,
h.entry,
h.examples,
l.definition as l10n_definition,
l.guidelines as l10n_guidelines,
l.entry as l10n_entry,
l.examples as l10n_examples
FROM data_dict AS d
LEFT JOIN help AS h ON d.field_number = h.field_number
LEFT JOIN help_l10n AS l ON (d.field_number = l.field_number AND l.locale = '{$conf['locale']}')
LEFT JOIN data_dict_l10n AS dl ON (d.field_number = dl.msgid AND dl.locale = '{$conf['locale']}' )
WHERE entity=$entity ";
if(isset($filter))
$sql = $sql . " AND huri_code LIKE '$filter' ";
// $sql = $sql." ORDER BY huri_code";
$pager = new shnPager($sql);
return $pager;
}
public static function getFieldHelpText($entity,$filter )
{
global $global;global $conf;
$entity = $global['db']->qstr($entity);
$filter = $global['db']->qstr($filter);
$sql = "SELECT
IFNULL(dl.msgstr , d.field_label) as 'field_label',
d.field_number,
h.definition,
h.guidelines,
h.entry,
h.examples,
l.definition as l10n_definition,
l.guidelines as l10n_guidelines,
l.entry as l10n_entry,
l.examples as l10n_examples
FROM data_dict AS d
LEFT JOIN help AS h ON d.field_number = h.field_number
LEFT JOIN help_l10n AS l ON (d.field_number = l.field_number AND l.locale = '{$conf['locale']}')
LEFT JOIN data_dict_l10n AS dl ON (d.field_number = dl.msgid AND dl.locale = '{$conf['locale']}' )
WHERE d.entity=$entity ";
$sql = $sql . " AND d.field_number = $filter ";
$res = $global['db']->GetRow($sql);
if(count($res)>0)
return $res;
else
return false;
}
public static function getHuriTermsForListCodePaged($fieldName,$filter = null , $filterValues=null ){
global $global;global $conf;
if( is_numeric($fieldName) ){
$listCode = (int)$fieldName;
}
if(is_array($filterValues)){
$huricode = $filterValues['huricode'];
$mt_term = $filterValues['mt_term'];
if(!( $mt_term=='' ||$mt_term == null) ){
$whereMt = " (english LIKE '%$mt_term%' OR l.msgstr LIKE '%$mt_term%') ";
}
if(!( $huricode=='' ||$huricode == null) ){
$whereHuri = " huri_code LIKE '$huricode%' ";
}
if($whereMt != null && $huricode!= null){
$filterWhere = " AND $whereHuri AND $whereMt ";;
}else if($whereMt == null && $huricode == null){
$filterWhere = null ;
}
else{
$filterWhere = " AND $whereHuri $whereMt ";;
}
}
$sql = "SELECT
vocab_number ,
huri_code ,
english AS 'mt_term' ,
list_code ,
l.msgstr AS 'mt_term_l10n' ,
visible
FROM mt_vocab
LEFT JOIN mt_vocab_l10n as l ON (l.msgid = vocab_number AND l.locale = '{$conf['locale']}' )
WHERE TRIM(list_code)='$listCode' $filterWhere ";
if(isset($filter))
$sql = $sql . " AND huri_code LIKE '$filter' ";
$sql = $sql." ORDER BY huri_code";
$pager = new shnPager($sql);
return $pager;
}
public static function getHuriTermsForListCodePaged2($fieldName,$filter){
global $global;global $conf;
if( is_numeric($fieldName) ){
$listCode = (int)$fieldName;
}
$sql = "SELECT
count(vocab_number)
FROM mt_vocab
LEFT JOIN mt_vocab_l10n as l ON (l.msgid = vocab_number AND l.locale = '{$conf['locale']}' )
WHERE TRIM(list_code)='$listCode' ";
if(isset($filter))
$sql = $sql . " AND huri_code LIKE '$filter' ";
$sql = $sql." ORDER BY huri_code";
$res = $global['db']->getOne($sql);
if($res > 1){
return true;
}
else{
return false;
}
}
public static function getTheChildren($fieldName,$filter){
global $global;global $conf;
if( is_numeric($fieldName) ){
$listCode = (int)$fieldName;
}
$sql = "SELECT
vocab_number
FROM mt_vocab
LEFT JOIN mt_vocab_l10n as l ON (l.msgid = vocab_number AND l.locale = '{$conf['locale']}' )
WHERE TRIM(list_code)='$listCode' ";
if(isset($filter))
$sql = $sql . " AND huri_code LIKE '$filter' ";
$sql = $sql." ORDER BY huri_code";
$res = $global['db']->getAll($sql);
return $res;
}
public static function getHuriTermsForListArray($vocab_numbers)
{