-
Notifications
You must be signed in to change notification settings - Fork 29
/
class.module.php
executable file
·1702 lines (1601 loc) · 67.1 KB
/
class.module.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
<?
Class Module {
// GAME Project 2004
// Author: Herman Tolentino MD
// Generic Architecture for Modular Enterprise
// This is the internal module class that handles all
// module activities.
// IMPORTANT SECURITY VARIABLES:
//
// $_SESSION["validuser"]: is user logged in? true if logged in
// $_SESSION["isadmin"]: global privileges if true
// $_SESSION["userid"]: user_id of person logged in
//
// - the following are set in role table
// $_SESSION["priv_add"]: sees add buttons
// $_SESSION["priv_update"]: sees update button
// $_SESSION["priv_delete"]: sees delete button
//
// NODE VARIABLES:
// derived from config.xml
// $_SESSION["datanode"]["name"]: name of org
// $_SESSION["datanode"]["code"]: unique id of org
// $_SESSION["datanode"]["telephone"]: phone number
// $_SESSION["datanode"]["level"]: part of org in node tree
//
// WARNING: There is a not so nasty (non-fatal) bug when loading modules for the
// first time, be forewarned. When loading a module for the first
// time, it won't activate. We are looking for the source of the bug
// but feel free to contribute... It's open source anyway! And remove this
// comment when you have done so. Cheers!
//
function module () {
$this->author = "Herman Tolentino MD";
$this->version = "1.4";
// version 0.7
// added confirm_delete()
// 0.8: moved module functions out of index.php
// 0.9: added load sql
// 1.1: debugged permissions and added menu access by location
// security check precedence:
// location > module > menu
// 1.2 removed source code from main body (opens in separate window)
// 1.3 revamped consult notes
// 1.4 fixed formatting of module menu order
}
function _module() {
//
// main function for module
//
if (func_num_args()>0) {
$arg_list = func_get_args();
$post_vars = $arg_list[0];
$get_vars = $arg_list[1];
$post_files = $arg_list[2]; // comes from index.php
$validuser = $arg_list[3];
$isadmin = $arg_list[4];
//print_r($arg_list);
}
$module = new module;
switch ($get_vars["method"]) {
case "SQL":
if ($post_vars["submitsql"]) {
$module->process_module_sql($post_vars, $get_vars, $post_files);
}
$module->form_module_sql($post_vars, $get_vars);
break;
case "LOC":
if ($post_vars["submitaccess"]) {
$module->process_permissions($post_vars, $get_vars);
}
$module->form_locations($post_vars, $get_vars);
break;
case "MENU":
if ($get_vars["moveup"] || $get_vars["movedown"]) {
$module->process_order($post_vars, $get_vars);
//header("location: ".$_SERVER["PHP_SELF"]."?page=MODULES&method=MENU");
}
$module->form_menuorder($post_vars, $get_vars);
break;
case "HELP":
site::display_file("../module.help.php");
break;
case "PERMS":
if ($post_vars["submitaccess"]) {
$module->process_permissions($post_vars, $get_vars);
}
$module->form_permissions($post_vars, $get_vars);
break;
case "INIT":
if ($post_vars["submitinitmod"]=="Update Activation Status") {
$module->process_initmodule($post_vars);
// comment out line below for debugging
// while developing modules
//header("location: ".$_SERVER["PHP_SELF"]."?page=MODULES&method=INIT&initmod=1");
}
// module activation
$module->form_initmodule();
break;
case "MODDB":
default:
switch ($post_vars["submitmodule"]) {
case "Yes, Delete Module":
$module->delete_module($post_vars);
header("location: ".$_SERVER["PHP_SELF"]."?page=MODULES");
break;
case "Delete Module":
print "<font color='red' size='3'><b>Are you sure you want to DELETE this module?</b></font>";
$module->form_module($get_vars, $post_vars);
break;
case "Add Module":
default:
if ($module_id = $module->process_module($post_vars, $post_files)) {
// comment out line below for debugging
// while developing modules
//header("location: ".$_SERVER["PHP_SELF"]."?page=MODULES");
}
$module->form_module($get_vars, $post_vars);
$module->display_modules();
}
}
}
function get_version() {
return $this->version;
}
function confirm_delete() {
//
// global confirm delete using regular expressions
// include this for confirmation of all sql delete statements
//
// Example Usage:
// if (module::confirm_delete($menu_id, $post_vars, $get_vars)) {
// $sql = "delete from <table> where ...";
// if ($result = mysql_query($sql)) {
// header("location: "<previous page URL>);
// }
// } else {
// if ($post_vars["confirm_delete"]=="No") {
// header("location: "<previous page URL>);
// }
// }
//
if (func_num_args()>0) {
$arg_list = func_get_args();
$menu_id = $arg_list[0];
$post_vars = $arg_list[1];
$get_vars = $arg_list[2];
//print_r($post_vars);
}
if ($post_vars["confirm_delete"]) {
switch ($post_vars["confirm_delete"]) {
case "Yes":
return true;
break;
case "No":
header("location: ".$_SERVER["HTTP_REFERRER"]);
return false;
break;
}
} else {
print "<table>";
print "<form method='post' action='".$_SERVER["HTTP_REFERRER"]."'>";
print "<tr><td>";
foreach($get_vars as $key => $value) {
if (ereg("^delete", $value)) {
$delete_button = "Delete Icon";
}
}
foreach($post_vars as $key => $value) {
// store postvars again!
print "<input type='hidden' name='$key' value='$value' />";
if (ereg("^Delete", $value)) {
$delete_button = $value;
}
//print_r($value);
}
if ($delete_button) {
print "<font color='red' size='5'><b>You clicked on <u>$delete_button</u> button.</b></font><br />";
}
print "<font color='red' size='5'><b>Are you sure you want to do this?</b></font><br />";
print "<input type='submit' name='confirm_delete' value='Yes' class='textbox' style='font-weight: bold; font-size:14pt; background-color: #FFFF33; border: 2px solid black' id='Yes' /> ";
print "<input type='submit' name='confirm_delete' value='No' class='textbox' style='font-weight: bold; font-size:14pt; background-color: #FFCC33; border: 2px solid black' id='No' /> ";
print "</td></tr>";
print "</form>";
print "</table>";
return false;
}
}
function count() {
$sql = "select count(module_id) from modules";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
list($count) = mysql_fetch_array($result);
return $count;
}
}
}
function exec_menu() {
//
// this executes class methods based on menu id
//
if (func_num_args()>0) {
$arg_list = func_get_args();
$menu_id = $arg_list[0];
$post_vars = $arg_list[1];
$get_vars = $arg_list[2];
$validuser = $arg_list[3];
$isadmin = $arg_list[4];
}
$sql = "select c.module_name, m.menu_action ".
"from module_menu m, modules c ".
"where m.menu_id = $menu_id and c.module_id = m.module_id";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
list($module_name, $menu_action) = mysql_fetch_array($result);
// this string simulates a PHP command
// and is evaluated with PHP eval() below
$eval_string = $module_name."::".$menu_action."(\$menu_id,\$post_vars,\$get_vars,\$validuser,\$isadmin)".";";
eval("$eval_string");
}
}
}
// ---------------- MODULE INITIALIZATION METHODS -------------------
function set_dep() {
//
// establish dependencies through the
// table module_dependencies
//
if (func_num_args()) {
$arg_list = func_get_args();
$internal_module = $arg_list[0];
$external_module = $arg_list[1];
}
$sql = "insert into module_dependencies (module_id, req_module) ".
"values ('$internal_module','$external_module')";
if ($result = mysql_query($sql)) {
return true;
}
}
function set_lang() {
//
// creates entries in table term
// multilingualization engine from MBDSNET (c)2002-2004
// http://www.mbdsnet.org/
//
if (func_num_args()) {
$arg_list = func_get_args();
$term = $arg_list[0]; // constant term
$lang = $arg_list[1]; // language or dialect
$text = $arg_list[2]; // translated text
$is_english = $arg_list[3]; // is it english: Y or N
}
$sql = "insert into terms (termid, languageid, langtext, isenglish) ".
"values ('$term','$lang', '$text', '$english');";
if ($result = mysql_query($sql)) {
return true;
}
}
function set_menu() {
//
// creates entries in table module_menu
//
if (func_num_args()) {
$arg_list = func_get_args();
$module = $arg_list[0]; // module name
$menu_title = $arg_list[1]; // menu title (what is displayed)
$menu_cat = $arg_list[2]; // menu categories (top menu)
$menu_action = $arg_list[3]; // script executed in class
//print_r($arg_list);
}
// insert new menu entry
$sql = "insert into module_menu (module_id, menu_title, menu_cat, menu_action) ".
"values ('$module', '$menu_title', '$menu_cat', '$menu_action')";
if ($result = mysql_query($sql)) {
// make menu_rank equal menu_id as default
$insert_id = mysql_insert_id();
$sql_rank = "update module_menu set menu_rank = menu_id where menu_id = '$insert_id'";
$result_rank = mysql_query($sql_rank);
return true;
}
}
function set_detail() {
//
// updates table module
// for final activation verification
//
if (func_num_args()) {
$arg_list = func_get_args();
$description = $arg_list[0]; // module description
$version = $arg_list[1]; // module version
$author = $arg_list[2]; // module author
$module = $arg_list[3]; // module name
}
//print_r($arg_list);
$sql = "update modules set module_desc = '$description', ".
"module_version = '".$version."', module_author = '".$author."' ".
"where module_id = '$module';";
if ($result = mysql_query($sql)) {
$sql_flag = "update modules set module_init = 'Y' where module_id = '$module'";
$result_flag = mysql_query($sql_flag);
return true;
}
}
function execsql() {
//
// generic sql execution method
//
if (func_num_args()) {
$arg_list = func_get_args();
// print $sql below for diagnostics
$sql = $arg_list[0]; // SQL statement
}
if ($result = mysql_query($sql)) {
return true;
}
}
function load_sql () {
//
// load sql files from sql directory
//
if (func_num_args()) {
$arg_list = func_get_args();
$sql = $arg_list[0]; // SQL file
}
if (file_exists("../sql/$sql")) {
if ($fp = fopen("../sql/$sql", "r")) {
while (!feof ($fp)) {
$sql_buffer = fgets($fp, 4096);
if ($result = mysql_query($sql_buffer)) {
$sql_status[] .= $sql_buffer." - SUCCESS\n";
} else {
$sql_status[] .= $sql_buffer." - FAIL\n";
}
}
foreach($sql_status as $key =>$value) {
print nl2br($value);
}
fclose ($fp);
return true;
}
}
}
// ---------------- END OF MODULE INITIALIZATION METHODS ---------------
function display_modules() {
if (func_num_args()) {
$arg_list = func_get_args();
$post_vars = $arg_list[0];
}
print "<table width='650'>";
print "<tr valign='top'><td colspan='3'>";
print "<span class='module'>LOADED MODULES</span><br><br>";
print "</td></tr>";
print "<tr valign='top'><td colspan='5'>";
print "<b>INSTRUCTIONS: Click on module name to see details (and source code). Do not forget to set module and menu item permissions for site users in <b>MODULES->Grant Permissions</b>.</b><br><br>";
print "</td></tr>";
print "<tr valign='top'><td><b>ID</b></td><td><b>NAME</b></td><td><b>INIT STATUS</b></td><td><b>VERSION</b></td><td><b>DESCRIPTION</b></td></tr>";
$sql = "select module_id, module_name, module_init, module_version, module_desc ".
"from modules order by module_name";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
while (list($id, $name, $init, $version, $desc) = mysql_fetch_array($result)) {
print "<tr class='tinylight' valign='top'><td>$id</td><td><a href='".$_SERVER["SELF"]."?page=MODULES&module_id=$id#mod_$id'>$name</a></td><td>".($init=="N"?"No <a href='".$_SERVER["PHP_SELF"]."?page=MODULES&method=INIT'>[<b>activate</b>]</a>":"Yes")."</td><td>$version</td><td>".($desc?"$desc":"<font color='red'>empty</font>")."</td></tr>";
}
} else {
print "<tr valign='top'><td colspan='4'>";
print "<font color='red'>No modules loaded.</font><br>";
print "</td></tr>";
}
}
print "</table><br>";
}
function show_modules() {
if (func_num_args()) {
$arg_list = func_get_args();
$module_id = $arg_list[0];
}
$sql = "select module_id, module_name ".
"from modules order by module_name";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
$ret_val .= "<select name='module' class='textbox'>";
$ret_val .= "<option value=''>Select Module</option>";
while (list($id, $name) = mysql_fetch_array($result)) {
$ret_val .= "<option value='$id' ".($module_id==$id?"selected":"").">$name</option>";
}
$ret_val .= "</select>";
return $ret_val;
}
}
}
function delete_module() {
//
// delete module from database
// including all references
// delete all files
// Author: Herman Tolentino
//
if (func_num_args()) {
$arg_list = func_get_args();
$post_vars = $arg_list[0];
print_r($post_vars);
// important variables
$module_id = $post_vars["module_id"];
$module_name = $this->module_name($module_id);
// rewrite _modules.php so that only registered
// modules appear
//$this->rewrite_modules();
if (!$post_vars["leave_sql"]) {
if (class_exists($module_name)) {
$eval_string = $module_name."::drop_tables()".";";
eval("$eval_string");
}
}
$sql = "delete from modules where module_id = '$module_name'";
if ($result = mysql_query($sql)) {
// remove files
unlink("../modules/_uploads/class.$module_name.php.gz");
unlink("../modules/$module_name/class.$module_name.php");
// remove directory
rmdir("../modules/$module_name");
}
}
}
function module_name() {
//
// gets module name based on module_id
//
if (func_num_args()) {
$arg_list = func_get_args();
$id = $arg_list[0];
$sql = "select module_name from modules where module_id = '$id'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
list($name) = mysql_fetch_array($result);
return $name;
}
}
}
}
function module_id() {
//
// gets module id based on module_name
//
if (func_num_args()) {
$arg_list = func_get_args();
$name = trim($arg_list[0]);
$sql = "select module_id from modules where module_name = '$name'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
list($id) = mysql_fetch_array($result);
return $id;
}
}
}
}
function menu_module_id() {
//
// gets module id for menu item
//
if (func_num_args()) {
$arg_list = func_get_args();
$menu = trim($arg_list[0]);
$sql = "select module_id from module_menu where menu_id = '$menu'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
list($id) = mysql_fetch_array($result);
return $id;
}
}
}
}
// ---------------------- MODULE SUBMISSION METHODS ----------------------
function process_module() {
//
// process module submissions
//
if (func_num_args()>0) {
$arg_list = func_get_args();
$post_vars = $arg_list[0];
$post_files = $arg_list[1];
//print_r($post_files);
if(isset($_FILES)):
$arr_file = explode('.',$_FILES["module_file"]["name"]);
if($arr_file[2]=='php' && $arr_file[3]=='gz'):
$uploadfile = "../modules/_uploads/".$_FILES["module_file"]["name"];
echo 'Module uploaded is in correct format';
if (move_uploaded_file($_FILES["module_file"]["tmp_name"], $uploadfile)):
return $this->uncompress($uploadfile);
endif;
else:
echo "<font color='red'>NOTE:</font> The GAME module parser will only accept modules that are in class.modulename.php.gz format.";
endif;
endif;
}
}
function form_module() {
//
// for uploading new modules
//
if (func_num_args()) {
$arg_list = func_get_args();
$get_vars = $arg_list[0];
$post_vars = $arg_list[1];
if ($get_vars["module_id"]) {
$sql = "select module_id, module_name, module_desc, module_version, module_init, module_author from modules ".
"where module_id = '".$get_vars["module_id"]."'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
$module = mysql_fetch_array($result);
//print_r($image);
}
}
}
}
print "<table width='500'>";
print "<form enctype='multipart/form-data' action = '".$_SERVER["SELF"]."?page=".$get_vars["page"]."&module_id=".$get_vars["module_id"]."' name='form_module' method='post'>";
print "<tr valign='top'><td>";
print "<a name='mod_".$module["module_id"]."'>";
print "<span class='module'>MODULE DATABASE</span><br><br>";
print "</td></tr>";
if ($get_vars["module_id"]) {
print "<tr valign='top'><td>";
print "<table width='500' cellpadding='2' cellspacing='0' style='border: 2px solid black'>";
print "<tr valign='top'><td bgcolor='#FFFF99'>";
print "<b>Module Name:</b> ".$module["module_name"]."<br>";
print "<b>Module Version:</b> ".$module["module_version"]."<br>";
print "<b>Module Author:</b><br>".$module["module_author"]."<br>";
print "<b>Module Description:</b><br>".$module["module_desc"]."<br><br>";
$class = "class.".$module["module_name"].".php";
print "<b>Source Code:</b> <a href='../source.php?class=$class' target='_blank'>VIEW</a>";
print "</td><td bgcolor='#99FF66'>";
print "<b>Module Requires:</b><br>".$this->requires($module["module_name"])."<br>";
print "<b>Module Dependents:</b><br>".$this->depends($module["module_name"])."<br>";
print "<br></td></tr>";
print "<tr valign='top'><td>";
print "<span class='boxtitle'>LEAVE SQL TABLES</span><br> ";
print "<input type='checkbox' name='leave_sql' checked value='1' ".($post_vars["leave_sql"]?"checked":"")."> Check to leave tables intact<br>";
print "</td></tr></table>";
print "</td></tr>";
} else {
print "<tr valign='top'><td>";
print "<span class='boxtitle'>MODULE FILE</span><br> ";
print "<input type='file' class='textbox' size='35' style='border: 1px solid black' maxlength='100' name='module_file' value='".($image["image_filename"]?$image["module_file"]:$post_vars["module_file"])."'>";
print "</td></tr>";
}
print "<tr><td><br>";
if ($get_vars["module_id"]) {
print "<input type='hidden' name='module_id' value='".$get_vars["module_id"]."'>";
if ($post_vars["noconfirm"]) {
print "<input type='submit' value = 'Yes, Delete Module' class='textbox' name='submitmodule' style='border: 1px solid #000000'> ";
} else {
print "<input type='hidden' name='noconfirm' value='1'>";
print "<input type='submit' value = 'Delete Module' class='textbox' name='submitmodule' style='border: 1px solid #000000'> ";
}
} else {
print "<input type='hidden' name='MAX_FILE_SIZE' value='200000'>";
print "<input type='submit' value = 'Add Module' class='textbox' name='submitmodule' style='border: 1px solid #000000'> ";
}
print "</td></tr>";
print "</form>";
print "</table><br>";
if ($get_vars["module_id"]) {
print "<small>";
//show_source("../modules/".$module["module_name"]."/class.".$module["module_name"].".php");
print "</small>";
}
}
function requires() {
if (func_num_args()) {
$arg_list = func_get_args();
$module_name = $arg_list[0];
}
$sql = "select req_module ".
"from module_dependencies ".
"where module_id = '$module_name' order by req_module";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
$i=0;
while (list($name) = mysql_fetch_array($result)) {
$i++;
$ret_val .= "$i. $name -> ".(class_exists($name)?"<font color='#6666FF'><b>installed</b></font>":"<b><a href='".$_SERVER["PHP_SELF"]."?page=MODULES&method=MODDB'><font color='red'>missing</font></a></b>")."<br>";
}
return $ret_val;
}
}
}
function depends() {
if (func_num_args()) {
$arg_list = func_get_args();
$module_name = $arg_list[0];
}
$sql = "select module_id ".
"from module_dependencies ".
"where req_module = '$module_name' order by req_module";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
$i=0;
while (list($name) = mysql_fetch_array($result)) {
$i++;
$ret_val .= "$i. $name -> ".(class_exists($name)?"<font color='#6666FF'><b>installed</b></font>":"<font color='red'><b>missing</b></font>")."<br>";
}
return $ret_val;
} else {
return "<font color='red'>none</font>";
}
}
}
function uncompress() {
// WHAT THIS DOES:
// 1. Reads file uploaded to modules/_uploads
// 2. Uncompresses it and stores it to $contents
// 3. Writes directory modules/$main
// 4. Writes class file into modules/$main
//
// IMPORTANT
// File must be of format class.<modname>.php.gz
//
$maxfilesize = 250000;
if (func_num_args()>0) {
$arg_list = func_get_args();
$file = $arg_list[0];
}
$fp = gzopen("$file", "r");
$contents = gzread($fp, $maxfilesize);
// the following are placeholders, only $main matters:
// $xx = class
// $yy = php
// $zz = gz
list($xx,$main,$yy,$zz) = explode(".",basename($file));
// create module directory
$dir = @mkdir("../modules/$main");
// write $contents to file
if ($fp2 = fopen("../modules/$main/class.$main.php", "w+")) {
fwrite($fp2, $contents);
fclose($fp2);
// update database
$sql = "insert into modules (module_id, module_name) values ('$main', '$main')";
if ($result = mysql_query($sql)) {
$id = mysql_insert_id();
return $id;
} else {
$sql = "select module_id from modules where module_name = '$main'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
list($id) = mysql_fetch_array($result);
return $id;
}
}
}
}
fclose($fp);
}
// ---------------------- MODULE ACTIVATION METHODS ----------------------
function form_initmodule() {
//
// activation form for modules
//
if (func_num_args()) {
$arg_list = func_get_args();
$module_id = $arg_list[0];
$post_vars = $arg_list[1];
}
print "<table width='500'>";
print "<form action = '".$_SERVER["SELF"]."?page=MODULES&method=INIT' name='form_initmodule' method='post'>";
print "<tr valign='top'><td>";
print "<span class='module'>MODULE ACTIVATION</span><br><br>";
print "</td></tr>";
print "<tr valign='top'><td>";
print "<span class='boxtitle'>CHECK TO ACTIVATE MODULES</span><br> ";
$sql = "select module_id, module_name, module_version, module_init from modules order by module_name";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
print "<tr valign='top'><td>";
print "<b>NOTE:</b> The unchecked modules can be activated. Do not forget to set module permissions in <b>MODULES->Grant Permissions</b> to enable site users to see corresponding menu entries for this module.<br>";
print "</td></tr>";
print "<tr valign='top'><td>";
while (list($mid, $mname, $mversion, $minit) = mysql_fetch_array($result)) {
print "<input type='checkbox' name='initmod[]' value='$mid' ".($minit["module_init"]=='Y'?"checked":"")."> $mname ($mversion) ".($mversion?"<font color='red'><b>active</b></font>":"<font color='#CCCCCC'><b>inactive</b></font>")."<br>";
}
print "</td></tr>";
}
}
print "<tr><td>";
print "<input type='hidden' name='module_id' value='$module_id'>";
print "<br><input type='submit' value = 'Update Activation Status' class='textbox' name='submitinitmod' style='border: 1px solid #000000'> ";
print "</td></tr>";
print "</form>";
print "</table><br>";
}
function get_menu_id() {
if (func_num_args()) {
$arg_list = func_get_args();
$menu_action = $arg_list[0];
}
$sql = "select menu_id from module_menu where menu_action = '$menu_action'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
list($menu_id) = mysql_fetch_array($result);
return $menu_id;
}
}
}
function error_message() {
if (func_num_args()) {
$arg_list = func_get_args();
$error_id = $arg_list[0];
}
$sql = "select error_name from errorcodes where error_id = '$error_id'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
list($error_name) = mysql_fetch_array($result);
print "<font color='red' size='4'><b>".$error_name."</b></font><br><br>";
}
}
}
function process_initmodule() {
//
// called from menu
// writes ../modules/_modules.php and ../modules/_menu.php
//
if (func_num_args()>0) {
$arg_list = func_get_args();
$post_vars = $arg_list[0];
//print_r($post_vars);
if ($post_vars["initmod"]) {
$sql = "update modules set module_init = 'N'";
$result = mysql_query($sql);
$generation_date = date("Y-m-d H:i:s");
$modswitch .= "<?\n";
$modswitch .= "// BEGIN SERVER CODE: DO NOT EDIT\n".
"// Server generated code\n".
"// Generated ".$generation_date."\n".
"// Module: _menu.php\n".
"// Author: Herman Tolentino MD\n".
"//\n";
$modswitch .= "if (\$HTTP_GET_VARS[\"menu_id\"] && $_SESSION["validuser"]) {\n";
$modswitch .= "\tswitch (\$HTTP_GET_VARS[\"menu_id\"]) {\n";
$modphp .= "<?\n";
$modphp .= "// BEGIN SERVER CODE: DO NOT EDIT\n".
"// Server generated code\n".
"// Generated ".$generation_date."\n".
"// Module: _module.php\n".
"// Author: Herman Tolentino MD\n".
"//\n";
foreach ($post_vars["initmod"] as $key=>$value) {
$modname = $this->module_name($value);
$sql_menu = "select menu_id, menu_action from module_menu where module_id = '".$modname."'";
if ($result = mysql_query($sql_menu)) {
if (mysql_num_rows($result)) {
while (list($m_id,$m_action) = mysql_fetch_array($result)) {
$modswitch .= "\tcase $m_id:\n";
$modswitch .= "\t\t\$".$modname."->".$m_action."(\$menu_id, \$HTTP_POST_VARS, \$HTTP_GET_VARS,\$_SESSION[\"validuser\"],\$_SESSION[\"isadmin\"]);\n";
$modswitch .= "\t\tbreak;\n";
}
}
}
$modphp .= "if (file_exists('../modules/$modname/class.$modname.php')) {\n";
$modphp .= "\tinclude '../modules/$modname/class.$modname.php';\n";
$modphp .= "\t\$$modname = new $modname;\n";
$modphp .= "\tif (!\$module->activated('$value') && \$initmod) {\n";
$modphp .= "\t\t\$".$modname."->init_sql();\n";
$modphp .= "\t\t\$".$modname."->init_menu();\n";
$modphp .= "\t\t\$".$modname."->init_deps();\n";
$modphp .= "\t\t\$".$modname."->init_lang();\n";
$modphp .= "\t\t\$".$modname."->init_help();\n";
$modphp .= "\t}\n";
$modphp .= "}\n";
// flag module as activated
$sql_flag = "update modules set module_init = 'Y' where module_id = '$value'";
$result_flag = mysql_query($sql_flag);
}
$modphp .= "\n// END SERVER CODE\n";
$modphp .= "\n?>";
$modswitch .= "\t}\n";
$modswitch .= "}\n";
$modswitch .= "\n// END SERVER CODE\n";
$modswitch .= "\n?>";
if ($fp_modphp = fopen("../modules/_modules.php", "w+")) {
if (fwrite($fp_modphp, $modphp)) {
fclose($fp_modphp);
}
}
if ($fp_modswitch = fopen("../modules/_menu.php", "w+")) {
if (fwrite($fp_modswitch, $modswitch)) {
fclose($fp_modswitch);
}
}
} else {
$sql = "update modules set module_init = 'N'";
$result = mysql_query($sql);
}
}
}
function activated() {
if (func_num_args()>0) {
$arg_list = func_get_args();
$module_id = $arg_list[0];
}
$sql = "select module_init from modules where module_id = '$module_id'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
list($init) = mysql_fetch_array($result);
if ($init=='Y') {
return true;
} else {
return false;
}
}
}
}
function req_activation() {
// answers question: are there modules that require activation?
// returns Y if there are any
$sql = "select count(module_id) from modules where module_init = 'N'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
list($count) = mysql_fetch_array($result);
if ($count>0) {
return true;
} else {
return false;
}
}
}
}
// ---------------------- MODULE PERMISSIONS METHODS ----------------------
function module_permission_status() {
//
// get permission status for modules
// per user
//
if (func_num_args()) {
$arg_list = func_get_args();
$module = $arg_list[0];
$user_id = $arg_list[1];
}
$sql = "select module_id from module_permissions ".
"where module_id = '".$module."' and user_id = '".$user_id."'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
if (list($module_id) = mysql_fetch_array($result)) {
return $module_id;
}
}
}
return 0;
}
function menu_permission_status() {
//
// get permission status for menu items per module
// per user
//
if (func_num_args()) {
$arg_list = func_get_args();
$menu_id = $arg_list[0];
$user_id = $arg_list[1];
}
$sql = "select menu_id from module_menu_permissions ".
"where menu_id = '".$menu_id."' and user_id = '".$user_id."'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
if (list($menu_id) = mysql_fetch_array($result)) {
return $menu_id;
}
}
}
return 0;
}
function location_permission_status() {
//
// get permission status for menu items per location
// per user
//
if (func_num_args()) {
$arg_list = func_get_args();
$menu_id = $arg_list[0];
$location_id = $arg_list[1];
}
$sql = "select menu_id from module_menu_location ".
"where menu_id = '".$menu_id."' and location_id = '".$location_id."'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
if (list($menu_id) = mysql_fetch_array($result)) {
return $menu_id;
}
}
}
return 0;
}
function location_user_permission_status() {
//
// get permission status for menu items per location
// per user
//
if (func_num_args()) {
$arg_list = func_get_args();
$location_id = $arg_list[0];
$user_id = $arg_list[1];
}
$sql = "select user_id from module_user_location ".
"where user_id = '".$user_id."' and location_id = '".$location_id."'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
if (list($user_id) = mysql_fetch_array($result)) {
return $user_id;
}
}
}
return 0;
}
function process_permissions() {
if (func_num_args()>0) {
$arg_list = func_get_args();
$post_vars = $arg_list[0];
$get_vars = $arg_list[1];
//print_r($post_vars);
}
if ($post_vars["submitaccess"]=="Update Module Access") {
// delete all references of user in module_permissions
$sql_delete = "delete from module_permissions where user_id = '".$post_vars["module_user"]."'";
$result_delete = mysql_query($sql_delete);
if ($post_vars["modules"] && $post_vars["module_user"]) {
// .. update with new one
foreach($post_vars["modules"] as $key=>$value) {
$sql_new = "insert into module_permissions (module_id, user_id) ".
"values ('$value', '".$post_vars["module_user"]."')";
$result_new = mysql_query($sql_new);
}
}
}
if ($post_vars["submitaccess"]=="Update Menu Access") {