-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.inc.php
1513 lines (1329 loc) · 46.3 KB
/
common.inc.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
<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2005 Sci-Tech Ontario Inc <[email protected]>
Copyright (C) 2005 James Grant <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, version 2.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
?>
<?
/// \note DRE 2018 modified
//if we dont set the charset any page that doesnt call send_header() (where it used to be set) would defualt to the server's encoding,
//which in many cases (like ysf-fsj.ca/sfiab) is UTF-8. This was causing a lot of the newly AJAX'd editors to fail on french characters,
//becuase they were being encoded improperly. Ideally, all the databases will be switched to UTF-8, but thats not a near-term possibility,
//so this is kind of a band-aid solution until we can make everything UTF8. Hope it doesnt break anything anywhere else!
header("Content-Type: text/html; charset=iso-8859-1");
//set error reporting to not show notices, for some reason some people's installation dont set this by default
//so we will set it in the code instead just to make sure
error_reporting(E_ALL ^ E_NOTICE);
define('REQUIREDFIELD','<span class="requiredfield">*</span>');
//figure out the directory to prepend to directoroy names, depending on if we are in a subdirectory or not
if(substr(getcwd(),-6)=="/admin")
$prependdir="../";
else if(substr(getcwd(),-7)=="/config")
$prependdir="../";
else if(substr(getcwd(),-3)=="/db")
$prependdir="../";
else if(substr(getcwd(),-8)=="/scripts")
$prependdir="../";
else
$prependdir="";
$sfiabversion=@file($prependdir."version.txt");
$config['version']=trim($sfiabversion[0]);
//make sure the data subdirectory is writable, if its not, then we're screwed, so make sure it is!
if(!is_writable($prependdir."data"))
{
echo "<html><head><title>SFIAB ERROR</title></head><body>";
echo "<h1>Science Fair In A Box - ERROR</h1>";
echo "data/ subdirectory is not writable by the web server";
echo "<br>";
echo "<h2>Details</h2>";
echo "The data/ subdirectory is used to store files uploaded through the SFIAB software. The web server must have write access to this directory in order to function properly. Please contact your system administrator (if you are the system administrator, chown/chmod the data directory appropriately).";
echo "<br>";
echo "</body></html>";
exit;
}
if(file_exists($prependdir."data/config.inc.php"))
{
require_once($prependdir."data/config.inc.php");
}
else
{
echo "<html><head><title>SFIAB</title></head><body>";
echo "<h1>Science Fair In A Box - Installation</h1>";
echo "It looks like this is a new installation of SFIAB, and the database has not yet been configured. Please choose from the following options: <br />";
echo "<br />";
echo "<a href=\"install.php\">Proceed with Fresh SFIAB Installation</a>";
echo "<br />";
echo "</body></html>";
exit;
}
/*
difference between MySQL <5.1 and 5.1:
in <5.1 in must have internall truncated it at 16 before comparing with the hard-coded 16 character database limit
in 5.1 it doesnt truncate and compares the full string with the hardcoded 16 character limit, so all our very long usernames
are now failing
James - Dec 30 2010
*/
$DBUSER=substr($DBUSER,0,16);
if(!mysql_connect($DBHOST,$DBUSER,$DBPASS))
{
echo "<html><head><title>SFIAB ERROR</title></head><body>";
echo "<h1>Science Fair In A Box - ERROR</h1>";
echo "Cannot connect to database!";
echo "</body></html>";
exit;
}
if(!mysql_select_db($DBNAME))
{
echo "<html><head><title>SFIAB ERROR</title></head><body>";
echo "<h1>Science Fair In A Box - ERROR</h1>";
echo "Cannot select database!";
echo "</body></html>";
exit;
}
//this will silently fail on mysql 4.x, but is needed on mysql5.x to ensure we're only using iso-8859-1 (/latin1) encodings
@mysql_query("SET NAMES latin1");
//find out the fair year and any other 'year=0' configuration parameters (things that dont change as the years go on)
$q=@mysql_query("SELECT * FROM config WHERE year='0'");
//we might get an error if installation step 2 is not done (ie, the config table doesnt even exist)
if(mysql_error())
{
echo "<html><head><title>SFIAB ERROR</title></head><body>";
echo "<h1>Science Fair In A Box - ERROR</h1>";
echo "SFIAB installation is not complete. Please go to <A href=\"install2.php\">Installer Step 2</a> to complete the installation process";
echo "<br>";
echo "</body></html>";
exit;
}
//if we have 0 (<1) then install2 is not done, which would get caught above,
//if we have 1 (<2) then insatll3 is not done (no entries for FAIRYEAR and SFIABDIRECTORY)
if(mysql_num_rows($q)<2)
{
echo "<html><head><title>SFIAB ERROR</title></head><body>";
echo "<h1>Science Fair In A Box - ERROR</h1>";
echo "SFIAB installation is not complete. Please go to <A href=\"install3.php\">Installer Step 3</a> to complete the installation process";
echo "<br>";
echo "</body></html>";
exit;
}
else
{
while($r=mysql_fetch_object($q))
{
$config[$r->var]=$r->val;
}
}
$dbdbversion=$config['DBVERSION'];
$dbcodeversion=@file($prependdir."db/db.code.version.txt");
$dbcodeversion=trim($dbcodeversion[0]);
if(!$dbdbversion)
{
echo "<html><head><title>SFIAB ERROR</title></head><body>";
echo "<h1>Science Fair In A Box - ERROR</h1>";
echo "SFIAB installation is not complete. Please go to <A href=\"install2.php\">Installer Step 2</a> to complete the installation process";
echo "<br>";
echo "</body></html>";
exit;
}
if($dbcodeversion!=$dbdbversion)
{
echo "<html><head><title>SFIAB ERROR</title></head><body>";
echo "<h1>Science Fair In A Box - ERROR</h1>";
echo "SFIAB database and code are mismatched";
echo "<br>";
echo "Please run the db_update.php script in order to update";
echo "<br>";
echo "your database to the same version as the code";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<h2>Details</h2>";
echo "Current SFIAB codebase requires DB version: ".$dbcodeversion;
echo "<br>";
echo "Current SFIAB database is detected as version: ".$dbdbversion;
echo "<br>";
echo "</body></html>";
exit;
}
/* Check that magic_quotes is OFF */
if(get_magic_quotes_gpc()) {
?>
<html><head><title>SFIAB ERROR</title></head><body>
<h1>Science Fair In A Box - ERROR</h1>
<p>Your PHP configuration has magic_quotes ENABLED. They should be
disabled, and are disabled in the .htaccess file, so your server is
ignoring the .htaccess file or overriding it.
<p>Magic quotes is DEPRECATED as of PHP 5.3.0, REMOVE as of 6.0, but ON
by default for any PHP < 5.3.0.
<p>It's a pain in the butt because PHP runs urldecode() on all inputs
from GET and POST, but if it sees the string has quotes, then it escapes
existing quotes before passing it to us. This is a problem for json_decode
where we do not want this behaviour, and thus need to pass through stripslashes()
first, but only if magicquotes is ON. If it's off, stripslashes will
break json_decode.
<p>Add <pre>php_flag magic_quotes_gpc off</pre> to the .htacces, or add
<pre>php_flag magic_quotes_gpc=off</pre> to php.ini
<br></body></html>
<?
exit;
}
//now pull the rest of the configuration
$q=mysql_query("SELECT * FROM config WHERE year='".$config['FAIRYEAR']."'");
while($r=mysql_fetch_object($q))
{
$config[$r->var]=$r->val;
}
//now pull the dates
$q=mysql_query("SELECT * FROM dates WHERE year='".$config['FAIRYEAR']."'");
while($r=mysql_fetch_object($q))
{
$config['dates'][$r->name]=$r->date;
}
//and now pull the theme
require_once("theme/{$config['theme']}/theme.php");
require_once("theme/{$config['theme_icons']}/icons.php");
require_once("committee.inc.php");
if($config['SFIABDIRECTORY'] == '') {
session_name("SFIABSESSID");
session_set_cookie_params(0,'/');
} else {
session_name("SFIABSESSID".ereg_replace("[^A-Za-z]","_",$config['SFIABDIRECTORY']));
session_set_cookie_params(0,$config['SFIABDIRECTORY']);
}
session_start();
//detect the browser first, so we know what icons to use - we store this in the config array as well
//even though its not configurable by the fair
if(stristr($_SERVER['HTTP_USER_AGENT'],"MSIE"))
$config['icon_extension']="gif";
else
$config['icon_extension']="png";
//now get the languages, and make sure we have at least one active language
$q=mysql_query("SELECT * FROM languages WHERE active='Y' ORDER BY langname");
if(mysql_num_rows($q)==0)
{
echo "No active languages defined, defaulting to English";
$config['languages']['en']="English";
}
else
{
while($r=mysql_fetch_object($q))
{
$config['languages'][$r->lang]=$r->langname;
}
}
//now if no language has been set yet, lets set it to the default language
if(!$_SESSION['lang'])
{
//first try the default language, if that doesnt work, use "en"
if($config['default_language'])
$_SESSION['lang']=$config['default_language'];
else
$_SESSION['lang']="en";
}
//only allow debug to get set if we're using a development version (odd numbered ending)
if(substr($config['version'], -1) % 2 != 0)
if($_GET['debug']) $_SESSION['debug']=$_GET['debug'];
//if the user has switched languages, go ahead and switch the session variable
if($_GET['switchlanguage'])
{
//first, make sure its a valid language:
if($config['languages'][$_GET['switchlanguage']])
{
$_SESSION['lang']=$_GET['switchlanguage'];
}
else
{
//invalid language, dont do anything
}
}
function i18n($str,$args=array(),$argsdesc=array(),$forcelang="")
{
if(!$str)
return "";
if($forcelang)
{
$savelang=$_SESSION['lang'];
$_SESSION['lang']=$forcelang;
}
if($_SESSION['lang'])
{
if($_SESSION['lang']=="en")
{
for($x=1;$x<=count($args);$x++)
{
$str=str_replace("%$x",$args[$x-1],$str);
}
if($forcelang) $_SESSION['lang']=$savelang;
return $str;
}
else
{
$q=mysql_query("SELECT * FROM translations WHERE lang='".$_SESSION['lang']."' AND strmd5='".md5($str)."'");
if($r=@mysql_fetch_object($q))
{
if($r->val)
{
$ret=$r->val;
for($x=1;$x<=count($args);$x++)
{
$ret=str_replace("%$x",$args[$x-1],$ret);
}
if($forcelang) $_SESSION['lang']=$savelang;
return $ret;
}
else
{
for($x=1;$x<=count($args);$x++)
{
$str=str_replace("%$x",$args[$x-1],$str);
}
if($forcelang) $_SESSION['lang']=$savelang;
return "{{".$str."}}";
}
}
else
{
if(count($argsdesc))
{
$argsdescstring="";
$n=1;
foreach($argsdesc AS $ad)
{
$argsdescstring.="%$n=$ad, ";
$n++;
}
$argsdescstring=substr($argsdescstring,0,-2);
$argsdescstring="'".mysql_escape_string($argsdescstring)."'";
}
else
$argsdescstring="null";
mysql_query("INSERT INTO translations (lang,strmd5,str,argsdesc) VALUES ('".$_SESSION['lang']."','".md5($str)."','".mysql_escape_string($str)."',$argsdescstring)");
for($x=1;$x<=count($args);$x++)
{
$str=str_replace("%$x",$args[$x-1],$str);
}
if($forcelang) $_SESSION['lang']=$savelang;
return "{{".$str."}}";
}
}
}
else
{
//no language set, assume english
if($forcelang) $_SESSION['lang']=$savelang;
return $str;
}
}
function error($str,$type="normal")
{
if($type=="normal")
return "<div class=\"error\">$str</div><br />";
else if($type=="inline")
return "<span class=\"error\">$str</span><br />";
}
function notice($str,$type="normal")
{
if($type=="normal")
return "<div class=\"notice\">$str</div><br />";
else if($type=="inline")
return "<span class=\"notice\">$str</span><br />";
}
function happy($str,$type="normal")
{
if($type=="normal")
return "<div class=\"happy\">$str</div><br />";
else if($type=="inline")
return "<span class=\"happy\">$str</span><br />";
}
function display_messages()
{
/* Dump any messages in the queue */
if(is_array($_SESSION['messages'])) {
foreach($_SESSION['messages'] as $m) echo $m;
}
$_SESSION['messages'] = array();
}
$HEADER_SENT=false;
function send_header($title="", $nav=null, $icon=null, $titletranslated=false)
{
global $HEADER_SENT;
global $config;
global $prependdir;
//do this so we can use send_header() a little more loosly and not worry about it being sent more than once.
if($HEADER_SENT) return;
else $HEADER_SENT=true;
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head><title><? if($title && !$titletranslated) echo i18n($title); else if($title) echo $title; else echo i18n($config['fairname']); ?></title>
<link rel="stylesheet" href="<?=$config['SFIABDIRECTORY']?>/theme/<?=$config['theme']?>/jquery-ui-1.7.2.custom.css" type="text/css" media="all" />
<link rel="stylesheet" href="<?=$config['SFIABDIRECTORY']?>/theme/<?=$config['theme']?>/sfiab.css" type="text/css" media="all" />
<link rel="stylesheet" href="<?=$config['SFIABDIRECTORY']?>/tableeditor.css" type="text/css" media="all" />
</head>
<body>
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/sfiab.js"></script>
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/tablesorter/jquery.tablesorter.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.tableview').tablesorter();
});
</script>
<?
//if we're under /admin or /config we also want the translation editor
if(substr(getcwd(),-6)=="/admin" || substr(getcwd(),-7)=="/config")
require_once("../translationseditor.inc.php");
?>
<div id="notice_area" class="notice_area"></div>
<div id="header">
<?
if(file_exists($prependdir."data/logo-100.gif"))
echo "<img align=\"left\" height=\"50\" src=\"".$config['SFIABDIRECTORY']."/data/logo-100.gif\">";
echo "<h1>".i18n($config['fairname'])."</h1>";
echo "<div align=\"right\" style=\"font-size: 0.75em;\">";
if(isset($_SESSION['users_type'])) {
$types = array('volunteer' => 'Volunteer', 'judge' => 'Judge',
'student'=>'Participant','committee'=>'Committee Member',
'fair'=>'Science Fair');
if($_SESSION['users_type'] != false) {
echo i18n($types[$_SESSION['users_type']]);
}
echo " {$_SESSION['email']}: ";
if($_SESSION['multirole'] == true) {
echo "<a href=\"{$config['SFIABDIRECTORY']}/user_multirole.php\">[".i18n('Switch Roles')."]</a> ";
}
echo "<a href=\"{$config['SFIABDIRECTORY']}/user_login.php?action=logout\">[".i18n("Logout")."]</a>";
} else if(isset($_SESSION['email'])) {
/* Backwards compatible login settings */
if(isset($_SESSION['registration_id'])) {
echo i18n('Participant');
echo " {$_SESSION['email']}: ";
echo "<a href=\"{$config['SFIABDIRECTORY']}/register_participants.php?action=logout\">[".i18n("Logout")."]</a>";
} else {
echo " ";
}
} else {
echo i18n('Not Logged In');
}
echo "</div>";
?>
<hr />
</div>
<table cellpadding="5" width="100%">
<tr><td width="175">
<?
//if the date is greater than the date/time that the confirmed participants gets posted,
//then we will show the registration confirmation page as a link in the menu,
$registrationconfirmationlink="";
//only display it if a date is set to begin with.
if($config['dates']['postparticipants'] && $config['dates']['postparticipants']!="0000-00-00 00:00:00")
{
$q=mysql_query("SELECT (NOW()>'".$config['dates']['regclose']."') AS test");
$r=mysql_fetch_object($q);
if($r->test==1)
{
$registrationconfirmationlink="<li><a href=\"".$config['SFIABDIRECTORY']."/confirmed_participants.php\">".i18n("Confirmed Participants")."</a></li>";
}
}
?>
<div id="left">
<?
if(is_array($nav)) {
$navkeys=array_keys($nav);
switch($navkeys[2]) {
case "Fundraising":
echo "<ul class=\"mainnav\">\n";
echo "<li><h4 style=\"text-align: center;\">".i18n("Fundraising")."</h4></li>\n";
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/fundraising.php\">".i18n("Fundraising Dashboard").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/fundraising_setup.php\">".i18n("Fundraising Setup").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/fundraising_campaigns.php\">".i18n("Manage Appeals").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/donors.php\">".i18n("Manage Donors/Sponsors").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/fundraising_reports.php\">".i18n("Fundraising Reports").'</a></li>';
echo "</ul><br />\n";
break;
default:
//no special menu
break;
}
}
?>
<ul class="mainnav">
<?
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/index.php\">".i18n("Home Page").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/important_dates.php\">".i18n("Important Dates").'</a></li>';
echo $registrationconfirmationlink;
/*
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/register_participants.php\">".i18n("Participant Registration").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/user_login.php?type=judge\">".i18n("Judges Registration").'</a></li>';
if($config['volunteer_enable'] == 'yes') {
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/user_login.php?type=volunteer\">".i18n("Volunteer Registration").'</a></li>';
}
*/
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/committees.php\">".i18n("Committee").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/winners.php\">".i18n("Winners").'</a></li>';
echo '</ul>';
?>
<br />
<ul class="mainnav">
<?
if($_SESSION['users_type'] == 'committee') {
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/user_personal.php\">".i18n("My Profile").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/committee_main.php\">".i18n("Committee Home").'</a></li>';
if(committee_auth_has_access("admin")){
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/\">".i18n("Fair Administration").'</a></li>';
}
if(committee_auth_has_access("config")){
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/config/\">".i18n("Configuration").'</a></li>';
}
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/user_login.php?action=logout\">".i18n("Logout").'</a></li>';
} else if($_SESSION['users_type']=="judge") {
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/user_personal.php\">".i18n("My Profile").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/judge_main.php\">".i18n("Judge Home").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/user_login.php?action=logout\">".i18n("Logout").'</a></li>';
} else if($_SESSION['users_type']=="volunteer") {
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/user_personal.php\">".i18n("My Profile").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/volunteer_main.php\">".i18n("Volunteer Home").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/user_login.php?action=logout\">".i18n("Logout").'</a></li>';
} else if($_SESSION['users_type']=="sponsor") {
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/user_personal.php\">".i18n("My Profile").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/sponsor_main.php\">".i18n("Sponsor Home").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/user_login.php?action=logout\">".i18n("Logout").'</a></li>';
} else if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode']) {
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/schoolaccess.php\">".i18n("School Home").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/schoolaccess.php?action=logout\">".i18n("Logout").'</a></li>';
}
else if($_SESSION['registration_number'] && $_SESSION['registration_id']) {
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/register_participants_main.php\">".i18n("Participant Home").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/register_participants.php?action=logout\">".i18n("Logout")."</a></li>\n";
} else {
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/login.php\">".i18n("Login/Register").'</a></li>';
}
?></ul>
<div class="aligncenter">
<?
if(count($config['languages'])>1) {
echo "<br />";
echo "<form name=\"languageselect\" method=\"get\" action=\"".$_SERVER['PHP_SELF']."\">";
echo "<select name=\"switchlanguage\" onchange=\"document.forms.languageselect.submit()\">\n";
foreach($config['languages'] AS $key=>$val) {
if($_SESSION['lang']==$key) $selected="selected=\"selected\""; else $selected="";
echo "<option $selected value=\"$key\">$val</option>";
}
echo "</select>";
echo "</form>";
}
?>
</div>
<?
echo "<br /><ul class=\"mainnav\">\n";
echo "<li><a href=\"{$config["SFIABDIRECTORY"]}/contact.php\">".i18n("Contact Us")."</a></li>\n";
echo "</ul>";
?>
</div>
<?
echo "<br /><ul class=\"mainnav\">\n";
echo "<li><a href=\"http://seab-sciencefair.com/mediawiki/index.php\">".i18n("Praxis Open Science Fair Wiki")."</a></li>\n";
echo "</ul>";
echo "<br /><ul class=\"mainnav\">\n";
echo "<li><a href=\"http://praxismedhat.com/\">".i18n("Praxis Society ")."</a></li>\n";
echo "</ul>";
?>
</td><td>
<?
if(is_array($nav)) {
echo "<div id=\"mainwhere\">".i18n('You are here:').' ';
foreach($nav as $t=>$l) {
echo "<a href=\"{$config['SFIABDIRECTORY']}/$l\">".i18n($t).'</a> » ';
}
if(!$titletranslated)
echo i18n($title);
else
echo $title;
echo '</div>';
}
?>
<div id="main">
<?
if(committee_auth_has_access("config") || committee_auth_has_access("admin"))
committee_warnings();
if(committee_auth_has_access("config"))
config_warnings();
if(committee_auth_has_access("admin"))
admin_warnings();
echo "<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\"><tr>";
if($icon && theme_icon($icon)) {
echo "<td width=\"40\">";
echo theme_icon($icon);
echo "</td><td>";
}
else
echo "<td>";
if($title && !$titletranslated)
echo "<h2>".i18n($title)."</h2>";
else if($title)
echo "<h2>".$title."</h2>";
//if we're under /admin or /config then we want to show the ? help icon
if(substr(getcwd(),-6)=="/admin" || substr(getcwd(),-7)=="/config")
{
if($_SERVER['REDIRECT_SCRIPT_URL'])
$fname=substr($_SERVER['REDIRECT_SCRIPT_URL'],strlen($config['SFIABDIRECTORY'])+1);
else
$fname=substr($_SERVER['PHP_SELF'],strlen($config['SFIABDIRECTORY'])+1);
echo "</td><td align=\"right\"><a target=\"_sfiabhelp\" href=\"http://www.sfiab.ca/wiki/index.php/Help_$fname\"><img border=\"0\" src=\"".$config['SFIABDIRECTORY']."/images/32/help.".$config['icon_extension']."\"></a>";
}
"</td></tr>";
echo "</table>";
display_messages();
}
/* END OF send_header */
function send_footer()
{
global $config;
?>
</td></tr></table>
</div>
<div id="footer">
<?
//we only show the debug session variables if we have an ODD numbered version.
if(substr($config['version'], -1) % 2 != 0)
{
$revision=exec("svn info |grep Revision");
$extra=" (Development $revision)";
if($_SESSION['debug']=="true")
$extra.=" DEBUG: ".print_r($_SESSION,true);
}
echo "<a target=\"blank\" href=\"http://www.sfiab.ca\">SFIAB Version ".$config['version']."{$extra}</a>";
?>
</div>
<div id="debug" style="display:<?=($_SESSION['debug']=='true')?'block':'none'?>; font-family:monospace; white-space:pre; " >Debug...</div>
<iframe id="content" src="" style="visibility:hidden; width:0px; height:0px"></iframe>
</body>
</html>
<?
}
function send_popup_header($title="")
{
global $HEADER_SENT;
global $config;
//do this so we can use send_header() a little more loosly and not worry about it being sent more than once.
if($HEADER_SENT) return;
else $HEADER_SENT=true;
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head><title><?=i18n($title)?></title>
<link rel="stylesheet" href="<?=$config['SFIABDIRECTORY']?>/theme/<?=$config['theme']?>/jquery-ui-1.7.2.custom.css" type="text/css" media="all" />
<link rel="stylesheet" href="<?=$config['SFIABDIRECTORY']?>/theme/<?=$config['theme']?>/sfiab.css" type="text/css" media="all" />
<link media=all href="<?=$config['SFIABDIRECTORY']?>/tableeditor.css" type=text/css rel=stylesheet>
</head>
<body onload="window.focus()">
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/sfiab.js"></script>
<div id="notice_area" class="notice_area"></div>
<?
if($title)
echo "<h2>".i18n($title)."</h2>";
}
function send_popup_footer()
{
?>
<br />
<br />
<div id="footer">
<?
global $config;
$lastdigit=$config['version'][strlen($config['version'])-1];
if($lastdigit%2!=0)
{
echo "DEBUG:";
print_r($_SESSION);
}
echo "SFIAB Version ".$config['version'];
?>
</div>
<div id="debug" style="display:<?=($_SESSION['debug']=='true')?'block':'none'?>">Debug...</div>
<iframe id="content" src="" style="visibility:hidden; width:0px; height:0px"></iframe>
</body>
</html>
<?
}
function emit_month_selector($name,$selected="")
{
echo "<select name=\"$name\">\n";
$months=array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
echo "<option value=\"\">".i18n("Month")."</option>\n";
for($x=1;$x<=12;$x++)
{
if($x==$selected)
$s="selected=\"selected\"";
else
$s="";
echo "<option $s value=\"$x\">".$months[$x]."</option>\n";
}
echo "</select>\n";
}
function emit_day_selector($name,$selected="")
{
echo "<select name=\"$name\">\n";
echo "<option value=\"\">".i18n("Day")."</option>\n";
for($x=1;$x<=31;$x++)
echo "<option value=\"".($x<10?"0":"")."$x\" ".($selected==$x?"selected=\"selected\"":"").">$x</option>\n";
echo "</select>\n";
}
function emit_year_selector($name,$selected="",$min=0,$max=0)
{
$curyear=date("Y");
echo "<select name=\"$name\">\n";
echo "<option value=\"\">".i18n("Year")."</option>\n";
if($min&&$max)
{
for($x=$min;$x<=$max;$x++)
echo "<option value=\"$x\" ".($selected==$x?"selected=\"selected\"":"").">$x</option>\n";
}
else
{
//if we arent given a min and max, lets show current year + 5
for($x=$curyear;$x<$curyear+5;$x++)
echo "<option value=\"$x\" ".($selected==$x?"selected=\"selected\"":"").">$x</option>\n";
}
echo "</select>\n";
}
function emit_date_selector($name,$selected="")
{
if($selected)
{
list($year,$month,$day)=split("-",$selected);
}
echo "<table cellpadding=0>";
echo "<tr><td>";
emit_year_selector($name."_year",$year);
echo "</td><td>";
emit_month_selector($name."_month",$month);
echo "</td><td>";
emit_day_selector($name."_day",$day);
echo "</td></tr>";
echo "</table>";
}
function emit_hour_selector($name,$selected="")
{
if($selected!="") $selected=(int)$selected;
echo "<select name=\"$name\">\n";
echo "<option value=\"\">HH</option>\n";
for($x=0;$x<=23;$x++)
{
if($x===$selected)
$sel="selected";
else
$sel="";
echo "<option value=\"$x\" $sel>".sprintf("%02d",$x)."</option>\n";
}
echo "</select>\n";
}
function emit_minute_selector($name,$selected="")
{
$mins=array("00","05","10","15","20","25","30","35","40","45","50","55");
echo "<select name=\"$name\">\n";
echo "<option value=\"\">MM</option>\n";
for($x=0;$x<count($mins);$x++)
echo "<option value=\"".$mins[$x]."\" ".($selected==$mins[$x]?"selected":"").">$mins[$x]</option>\n";
echo "</select>\n";
}
function emit_time_selector($name,$selected="")
{
if($selected)
{
list($hour,$minute,$second)=split(":",$selected);
}
echo "<table cellpadding=0>";
echo "<tr><td>";
emit_hour_selector($name."_hour",$hour);
echo "</td><td>";
emit_minute_selector($name."_minute",$minute);
echo "</td></tr>";
echo "</table>";
}
function emit_province_selector($name,$selected="",$extra="")
{
global $config;
$q=mysql_query("SELECT * FROM provinces WHERE countries_code='".mysql_escape_string($config['country'])."' ORDER BY province");
if(mysql_num_rows($q)==1)
{
$r=mysql_fetch_object($q);
echo "<input type=\"hidden\" name=\"$name\" value=\"$r-code\">";
echo i18n($r->province);
}
else
{
echo "<select name=\"$name\" $extra>\n";
echo "<option value=\"\">".i18n("Select a {$config['provincestate']}")."</option>\n";
while($r=mysql_fetch_object($q))
{
if($r->code == $selected) $sel="selected=\"selected\""; else $sel="";
echo "<option $sel value=\"$r->code\">".i18n($r->province);
echo "</option>\n";
}
echo "</select>\n";
}
}
function outputStatus($status)
{
$ret="";
switch($status)
{
case 'incomplete':
$ret.="<div class=\"incomplete\">";
$ret.= i18n("Incomplete");
$ret.= "</div>";
break;
case 'complete':
$ret.= "<div class=\"complete\">";
$ret.= i18n("Complete");
$ret.= "</div>";
break;
case 'empty':
$ret.="<div class=\"incomplete\">";
$ret.= i18n("Empty");
$ret.= "</div>";
break;
default:
$ret.=i18n("Unknown");
break;
}
return $ret;
}
//returns true if its a valid email address, false if its not
function isEmailAddress($str) {
if(eregi('^[+a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $str))
return true;
else
return false;
}
function communication_get_user_replacements(&$u) {
global $config;
$rep = array('FAIRNAME' => $config['fairname'],
'NAME' => $u['name'],
'EMAIL' => $u['email'],
'PASSWORD' => $u['password'],
'SALUTATION' => $u['salutation'],
'FIRSTNAME' => $u['firstname'],
'LASTNAME' => $u['lastname'],
'ORGANIZATION' => $u['sponsor']['organization'],
);
return $rep;
}
function communication_replace_vars($text, &$u, $otherrep=array()) {
global $config;
if($u) {
$userrep=communication_get_user_replacements($u);
}
else {
$userrep=array();
}
$rep=array_merge($userrep,$otherrep);
foreach($rep AS $k=>$v) {
$text=ereg_replace("\[$k\]",$v,$text);
}
return $text;
}
//
/// DRE 2018 MODIFIED
// email_send is James' string evaluation and concatenation function
// that uses a database entry to craft emails from
// $val is the name of the 'emails' table entry that is chosen to find the boilerplate text
// $to is a fully formed email address - usually from a MySQL table
// $sub_subject - is an array of "subject modifiers" that are variable string substitutions into the boilerplate that is
// $sub_body - is a similar array of "body modifiers" that are specific entries in the database.
// This function crafts the email and then it is ready to be sent out into the wild.
function email_send($val,$to,$sub_subject=array(),$sub_body=array())
{
global $config;
/* Standard substitutions that are constant no matter who
* the $to is */
$urlproto = $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
$urlmain = "$urlproto{$_SERVER['HTTP_HOST']}{$config['SFIABDIRECTORY']}";
$urllogin = "$urlmain/login.php";
$stdsub = array("FAIRNAME"=>i18n($config['fairname']),
"URLMAIN"=>$urlmain,
"URLLOGIN"=>$urllogin,
);
/* Add standard subs to existing sub arrays */
// Testing remove automatics, does it stop email send?
//$sub_subject = array_merge($sub_subject, $stdsub);
//$sub_body = array_merge($sub_body, $stdsub);
//if our "to" doesnt look like a valid email, then forget about sending it.
if(!isEmailAddress($to))
return false;
// fetches data from the database
$q=mysql_query("SELECT * FROM emails WHERE val='$val'");
// extracts an object from the
if($r=mysql_fetch_object($q))
{
// DRE 2018 removed internationalization
// $subject=i18n($r->subject);
$subject=$r->subject;
// $body=i18n($r->body);
$body=$r->body;
// DRE 2018 - This is where he does the [FAIRNAME] array substitution into the text