-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.php
1041 lines (972 loc) · 30.1 KB
/
global.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
//
// File: global.php
//
// Description: This file is part of PHP RegPortal, which is derived
// from Deadlock PHP User Management System.
// The changes made to this include revisions to support using
// PDO for database operations and support for Apache httpd.conf
// based configuration and having authenticaiton via
// mod_dbd/mod_authn_dbd, rather than .htaccess and .htpasswd.
// This has resulted in significant rewrite of base code, hence
// new project, which is not backward compatible with Deadlock
//
// Note: All original Deadlock notices remain intact and this code is in
// turn provided under GNU General Public Licence V3 as per
// Deadlock code.
// The Tux Logo has been removed and replaceid with MySQL & PostgreSQL
// logo's as key aim was to make this version RDBMS agnostic via
// PHPs PDO functions.
// The new RegPortal logo includes original Deadlock logo (in miniture)
// in recognition of the fact that this is derived work.
// The Apache logo is included in the new logo, as this program
// generates Apache specific outputs... and assumes Apache is the
// underlying Web Server. However this code is not ensured
// or otherwise related to Apache Software Foundation.
//
/******************************************************************************
* This file is part of the Deadlock PHP User Management System. *
* *
* File Description: Show information for a specific user *
* *
* Deadlock 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; either version 2 of the License, or *
* (at your option) any later version. *
* *
* Deadlock 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 Deadlock; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
// make sure we are not in an install script
if(!strstr($_SERVER['PHP_SELF'],'install')){
// make sure deadlock is installed, if not, send the user to the install page
if(!defined("DEADLOCK_INSTALLED")){
redirect('../install/install.php?db_config_path=' . $db_config_path);
}
// make sure the install directory does not exist
// if(file_exists('../install/')){
// die('Please remove the install directory before continuing.');
//}
}
// if the user stops the script, it will continue to run. this is needed especially to generate a large htpasswd or to send bulk mail
ignore_user_abort(true);
// this is to prevent the script from timing out for the same reasons as above
@set_time_limit(0);
// str_ireplace() for php 4
require_once('func/str_ireplace.php');
// get the software version
require_once('version.php');
//
// check if need .htXXX writing stuff
//
if ($pdodb['mechanism'] == 'htaccess') {
include('global-ht.php');
}
if ($pdodb['provider'] == 'mysql') {
include('global-mysql.php');
}
elseif ($pdodb['provider'] == 'pgsql') {
include('global-pgsql.php');
}
else {
die("RegPortal unable to continue, due to unsupported RDBMS provider: " . $pdodb['provider']);
}
// if magic quotes gpc is enabled, this will removed the slashes from certain variables
if (get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST, &$_FILES);
while (list($key, $val) = each($process)) {
foreach ($val as $k => $v) {
unset($process[$key][$k]);
if (is_array($v)) {
$process[$key][($key < 5 ? $k : stripslashes($k))] = $v;
$process[] =& $process[$key][($key < 5 ? $k : stripslashes($k))];
} else {
$process[$key][stripslashes($k)] = stripslashes($v);
}
}
}
}
// Turn debugging on or off
function debug_mode($setting){
if($setting){
ini_set('display_errors','On');
} else {
ini_set('display_errors','Off');
}
}
// Encrypt a password for a .htpasswd file.
function enc_pass($pass,$digest=false,$digestuser=null,$digestrealm=null)
{
if($digest){
$pass = md5($digestuser.':'.$digestrealm.':'.$pass);
return $pass;
} else {
if (CRYPT_STD_DES == 1) {
$pass = crypt(trim($pass), random_string(2,1,0,0));
return $pass;
}
}
}
// This function generates a menu of countries and allows you to have one selected.
function country_menu ($selected){
$countries = array("Not Selected",
"Afghanistan",
"Albania",
"Algeria",
"American Samoa",
"Andorra",
"Angola",
"Anguilla",
"Antarctica",
"Antigua and Barbuda",
"Argentina",
"Armenia",
"Aruba",
"Australia",
"Austria",
"Azerbaijan",
"Bahamas",
"Bahrain",
"Bangladesh",
"Barbados",
"Belarus",
"Belgium",
"Belize",
"Benin",
"Bermuda",
"Bhutan",
"Bolivia",
"Bosnia and Herzegovina",
"Botswana",
"Bouvet Island",
"Brazil",
"British Indian Ocean Terr.",
"Brunei Darussalam",
"Bulgaria",
"Burkina Faso",
"Burundi",
"Cambodia",
"Cameroon",
"Canada",
"Cape Verde",
"Cayman Islands",
"Central African Republic",
"Chad",
"Chile",
"China",
"Christmas Island",
"Cocos (Keeling) Islands",
"Colombia",
"Comoros",
"Congo",
"Cook Islands",
"Costa Rica",
"Cote d'Ivoire",
"Croatia (Hrvatska)",
"Cuba",
"Cyprus",
"Czech Republic",
"Denmark",
"Djibouti",
"Dominica",
"Dominican Republic",
"East Timor",
"Ecuador",
"Egypt",
"El Salvador",
"Equatorial Guinea",
"Eritrea",
"Estonia",
"Ethiopia",
"Falkland Islands/Malvinas",
"Faroe Islands",
"Fiji",
"Finland",
"France",
"France, Metropolitan",
"French Guiana",
"French Polynesia",
"French Southern Terr.",
"Gabon",
"Gambia",
"Georgia",
"Germany",
"Ghana",
"Gibraltar",
"Greece",
"Greenland",
"Grenada",
"Guadeloupe",
"Guam",
"Guatemala",
"Guinea",
"Guinea-Bissau",
"Guyana",
"Haiti",
"Heard & McDonald Is.",
"Honduras",
"Hong Kong",
"Hungary",
"Iceland",
"India",
"Indonesia",
"Iran",
"Iraq",
"Ireland",
"Israel",
"Italy",
"Jamaica",
"Japan",
"Jordan",
"Kazakhstan",
"Kenya",
"Kiribati",
"Korea, North",
"Korea, South",
"Kuwait",
"Kyrgyzstan",
"Lao People's Dem. Rep.",
"Latvia",
"Lebanon",
"Lesotho",
"Liberia",
"Libyan Arab Jamahiriya",
"Liechtenstein",
"Lithuania",
"Luxembourg",
"Macau",
"Macedonia",
"Madagascar",
"Malawi",
"Malaysia",
"Maldives",
"Mali",
"Malta",
"Marshall Islands",
"Martinique",
"Mauritania",
"Mauritius",
"Mayotte",
"Mexico",
"Micronesia",
"Moldova",
"Monaco",
"Mongolia",
"Montserrat",
"Morocco",
"Mozambique",
"Myanmar",
"Namibia",
"Nauru",
"Nepal",
"Netherlands",
"Netherlands Antilles",
"New Caledonia",
"New Zealand",
"Nicaragua",
"Niger",
"Nigeria",
"Niue",
"Norfolk Island",
"Northern Mariana Is.",
"Norway",
"Oman",
"Pakistan",
"Palau",
"Panama",
"Papua New Guinea",
"Paraguay",
"Peru",
"Philippines",
"Pitcairn",
"Poland",
"Portugal",
"Puerto Rico",
"Qatar",
"Reunion",
"Romania",
"Russian Federation",
"Rwanda",
"S.Georgia & S.Sandwich Is.",
"Saint Kitts and Nevis",
"Saint Lucia",
"Samoa",
"San Marino",
"Sao Tome & Principe",
"Saudi Arabia",
"Senegal",
"Seychelles",
"Sierra Leone",
"Singapore",
"Slovakia (Slovak Republic)",
"Slovenia",
"Solomon Islands",
"Somalia",
"South Africa",
"Spain",
"Sri Lanka",
"St. Helena",
"St. Pierre & Miquelon",
"St. Vincent & Grenadines",
"Sudan",
"Suriname",
"Svalbard & Jan Mayen Is.",
"Swaziland",
"Sweden",
"Switzerland",
"Syrian Arab Republic",
"Taiwan",
"Tajikistan",
"Tanzania",
"Thailand",
"Togo",
"Tokelau",
"Tonga",
"Trinidad and Tobago",
"Tunisia",
"Turkey",
"Turkmenistan",
"Turks & Caicos Islands",
"Tuvalu",
"U.S. Minor Outlying Is.",
"Uganda",
"Ukraine",
"United Arab Emirates",
"United Kingdom",
"United States",
"Uruguay",
"Uzbekistan",
"Vanuatu",
"Vatican (Holy See)",
"Venezuela",
"Vietnam",
"Virgin Islands (British)",
"Virgin Islands (U.S.)",
"Wallis & Futuna Is.",
"Western Sahara",
"Yemen",
"Yugoslavia",
"Zaire",
"Zambia",
"Zimbabwe");
$menu_code = '<select name="country">'."\n";
foreach ($countries as $country){
if($selected == $country) $select_text = ' selected="selected"'; else $select_text = NULL;
$menu_code .= '<option value="'.$country.'"'.$select_text.'>'.htmlentities($country).'</option>'."\n";
}
$menu_code .= '</select>';
return $menu_code;
}
// A mail function which makes it easier to provide a from address.
function sendmail ($to,$from,$subject,$message,$html=false){
$headers = "From: {$from}\r\n";
if($html){
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
}
if(mail($to,$subject,$message,$headers)){
return true;
} else {
return false;
}
}
// random string generator
function random_string($len,$lett=1,$num=1,$cap=1) {
srand(date("s"));
$possible="";
if($lett){
$possible.="abcdefghijklmnopqrstuvwxyz";
if($cap){
$possible.="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
}
if($num){
$possible.="1234567890";
}
$str="";
while(strlen($str)<$len) {
$str.=substr($possible,(rand()%(strlen($possible))),1);
}
return($str);
}
// This generates a string of x number of *s
function password_filler($password){
$len = strlen($password);
$string = '';
for($i=0; $i<$len; $i++){
$string .= '*';
}
return $string;
}
// Check to see if a user exists in the database
// Return true if the user exists
function check_user_exists($dbh,$username,$prefix){
$result = $dbh->query('SELECT id FROM '.$prefix.'users WHERE username=' . $dbh->quote($username));
if($result->rowCount() == 0){
return false;
} else {
return true;
}
}
// Check to see if a verification code is correct for a certain user
// Return true if it is correct
function check_verification_code($dbh,$username,$code,$prefix){
$result = $dbh->query('SELECT id FROM '.$prefix.'users WHERE username=' . $dbh->quote($username) . ' and email_verify_code='.PDO::quote($code));
if($result->rowCount() == 0){
return false;
} else {
return true;
}
}
// this is to authenticate a user. this checks to see if a username and password combo exist in the database.
// returns true if the combo exists.
function check_login_info($dbh,$username,$password,$prefix){
$result = $dbh->query('SELECT id FROM '.$prefix.'users WHERE username='.$dbh->quote($username).' and password='.PDO::quote($password));
if($result->rowCount() == 0){
return false;
} else {
return true;
}
}
// Update a user's status
function UpdateUserStatus($dbh,$username,$newstatus,$prefix){
$sql = 'UPDATE '.$prefix.'users SET status='.$newstatus.' WHERE username='.$dbh->quote($username);
if($dbh->query($sql)){
return true;
} else {
db_failure($dbh, $dbh->errorInfo);
}
}
// get a user's current status
function GetCurrentStatus($dbh,$username,$prefix){
$sql = 'SELECT status FROM '.$prefix.'users WHERE username='.$dbh->quote($username);
if(!$result=$dbh->query($sql)){
db_failure($dbh, $dbh->errorInfo);
}
$row = $result->fetch(PDO::FETCH_ASSOC);
return $row[0];
}
// Check to see if an email address exists in the database
// Return true if the user exists
// the $username argument is for the configuration page. if it is set, if the user that has the email specified is $username, the script will return false
function check_email_exists($dbh,$email,$prefix,$username=''){
if(empty($username)){
$result = $dbh->query('SELECT id FROM '.$prefix.'users WHERE email='.$dbh->quote($email));
} else {
$result = $dbh->query('SELECT id FROM '.$prefix.'users WHERE email='.$dbh->quote($email).' and username !='.PDO::quote($username));
}
if($result->rowCount() == 0){
return false;
} else {
return true;
}
}
// Count the number of users in the database
function count_users ($dbh,$prefix){
$result = $dbh->query('SELECT id FROM '.$prefix.'users WHERE status=2');
return $result->rowCount();
}
// count the number of users who have no verified their email
function count_inactive_users ($dbh,$prefix){
$result = $dbh->query('SELECT id FROM '.$prefix.'users WHERE status=0');
return $result->rowCount();
}
function UpdateUserField($dbh,$username,$field,$value,$prefix){
$sql = 'UPDATE '.$prefix.'users SET '.$field.' = '.$dbh->quote($value).' WHERE username = '.$dbh->quote($username);
if(!$dbh->query($sql)){
db_failure($dbh, $dbh->errorInfo, $sql);
}
}
function FormatPhoneNumber($phone){
if(strlen($phone) != 10){
return($phone);
}
$area = substr($phone,0,3);
$prefix = substr($phone,3,3);
$number = substr($phone,6,4);
$phone = "(".$area.") ".$prefix." ".$number;
return($phone);
}
function count_pending_users($dbh,$prefix){
$result = $dbh->query('SELECT id FROM '.$prefix.'users WHERE status=1');
return $result->rowCount();
}
// This function gets the email body and subject from the text files in /emails
function get_email_subject ($dbh,$prefix,$email_name){
$sql = 'SELECT subject FROM '.$prefix.'emails WHERE name='.$dbh->quote($email_name);
if(!$result = $dbh->query($sql)){
db_failure($dbh, $dbh->errorInfo(), $sql);
}
$row = $result->fetch(PDO::FETCH_ASSOC);
$output = $row['subject'];
return $output;
}
function get_email_body ($dbh,$firstname,$lastname,$email,$username,$password,$login_url,
$deadlock_url,$admin_email,$prefix,$email_name){
$sql = 'SELECT body FROM '.$prefix.'emails WHERE name='.$dbh->quote($email_name);
if(!$result = $dbh->query($sql)){
db_failure($dbh, $dbh->errorInfo(), $sql);
}
$row = $result->fetch(PDO::FETCH_ASSOC);
$output = $row['body'];
$output = str_ireplace(
array('<%FirstName%>','<%LastName%>','<%Email%>','<%Username%>','<%Password%>','<%LoginURL%>','<%AdminEmail%>','<%RegPortalURL%>'),
array($firstname,$lastname,$email,$username,$password,$login_url,$admin_email,$deadlock_url), $output);
return $output;
}
// gets the body of an email, and replaces codes with values from the database
// if the send veriable is set to true, not only will the script genertate the email, but it will send it
function get_email_body_sql($dbh,$emailname,$username,$prefix,$send=false){
$sql = 'SELECT body FROM '.$prefix.'emails WHERE name='.$dbh->quote($emailname);
if(!$result = $dbh->query($sql)){
db_failure($dbh, $dbh->errorInfo(), $sql);
}
$row = $result->fetch(PDO::FETCH_ASSOC);
$output = stripslashes($row['body']);
$config = get_config($prefix);
$sql = 'SELECT * FROM '.$prefix.'users WHERE username='.$dbh->quote($username);
if($result = $dbh->query($sql)){
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$output = str_ireplace(
array('<%FirstName%>','<%LastName%>','<%Email%>','<%Username%>','<%Password%>','<%LoginURL%>','<%AdminEmail%>','<%RegPortalURL%>'),
array($row['firstname'],$row['lastname'],$row['email'],$row['username'],$row['password'],$config['protected_area_url'],$config['admin_email'],$config['deadlock_url']), $output);
if($send){
sendmail($row['email'],$config['admin_email'],get_email_subject($prefix,$emailname),$output);
}
}
} else {
db_failure($dbh, $dbh->errorInfo(), $sql);
}
return $output;
}
// this function adds the email verification code to the database
function AddEmailVerifyCode($dbh,$username,$code,$prefix){
$sql = 'UPDATE '.$prefix.'users SET email_verify_code = '.$dbh->quote($code).' WHERE username = '.PDO::quote($username).' LIMIT 1;';
if(!$dbh->query($sql)){
db_failure($dbh, $dbh->errorInfo(), $sql);
}
}
// This function removes a user from the mysql database
// $username- the user to remove, $prefix- the prefix of the users table
function remove_user ($dbh,$username,$table_prefix){
$sql = 'DELETE FROM '.$table_prefix.'users WHERE username = '.$dbh->quote($username);
if($dbh->query($sql)){
return true;
} else {
return false;
}
}
// Starts session
function admin_sessions ($expire,$param){
// set the session name so it does not conflict
session_name('admin_sid');
// Start the session
session_start();
// check to see if the current session has expired
if(isset($_SESSION['start_time'])){
if((time() - $_SESSION['start_time']) > $expire){
session_destroy();
redirect('./login.php' . $param);
}
}
// if session has not expired, set session start time
$_SESSION['start_time'] = time();
}
// This will generate an html dropdown menu of all users in the database.
// This is used on the email page to generate the menu.
function generate_user_menu ($dbh,$prefix,$selected){
$sql ='SELECT * FROM '.$prefix.'users WHERE status=2 ORDER BY username';
if($result = $dbh->query($sql)){
if($result->rowCount() > 0){
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$username[] = stripslashes($row['username']);
$id[] = stripslashes($row['id']);
$name[] = stripslashes($row['firstname']).' '.stripslashes($row['lastname']);
}
$code = null;
for($i=0;$i<$result->rowCount();$i++){
if($selected == $username[$i]) $select = ' selected="selected"'; else $select=null;
$code .= '<option value="'.$id[$i].'"'.$select.'>'.$name[$i]. ' - ' .$username[$i].'</option>'."\n";
}
return $code;
} else {
return null;
}
} else {
db_failure($dbh, $dbh->errorInfo(), $sql);
}
}
// generate request list rows
function generate_request_list($dbh,$prefix){
$sql = 'SELECT * FROM '.$prefix.'users WHERE status=1 ORDER BY lastname';
if($result = $dbh->query($sql)){
if($result->rowCount() > 0){
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$username[] = stripslashes($row['username']);
$email[] = stripslashes($row['email']);
$name[] = stripslashes($row['lastname']).', '.stripslashes($row['firstname']);
}
$code = "";
for($i=0;$i < $result->rowCount();$i++){
$code .= '<tr class="style2"><td>'.$name[$i].'</td><td>'.$username[$i].'</td><td>'.$email[$i].'</td><td><a href="./userinfo.php?user='.$username[$i].'&ref=request"><img src="../images/info15px.gif" alt="Info" border="0" title="More Information" /></a> <a href="#" onclick="denyuser(\''.$username[$i].'\')"><img src="../images/delete15px.gif" alt="Deny" border="0" title="Deny" /></a> <a href="#" onclick="acceptuser(\''.$username[$i].'\')"><img src="../images/accept15px.gif" alt="Accept" border="0" title="Accept" /></a></tr>'."\n";
}
return $code;
} else {
return '<tr><td colspan="4"><span class="style11">There are currently no users pending approval.</span></td></tr>';
}
} else {
db_failure($dbh, $dbh->errorInfo(), $sql);
}
}
// this function is used on the configuration page to check whether or not a checkbox field should be checked by default
function ConfigCheckboxCheck($Submitted,$PostField,$ConfigOption){
if(isset($Submitted)){
if(isset($PostField)){
return 'checked="checked" ';
} else {
return '';
}
} else {
if($ConfigOption == 'true'){
return 'checked="checked" ';
} else {
return '';
}
}
}
// this function is used on the configuration page to print out the date format selection menu
function ConfigDateSelects($PostField,$ConfigOption){
$date_formats = array('D d M, Y','D d M, Y g:i a','D d M, Y H:i','D M d, Y','D M d, Y g:i a','D M d, Y H:i','jS F Y','jS F Y, g:i a','jS F Y, H:i','F jS Y','F jS Y, g:i a','F jS Y, H:i','j/n/Y','j/n/Y, g:i a','j/n/Y, H:i','n/j/Y','n/j/Y, g:i a','n/j/Y, H:i','Y-m-d','Y-m-d, g:i a','Y-m-d, H:i');
$current_time = time();
$buffer = '';
if(empty($PostField)){
$selected_format = $ConfigOption;
} else {
$selected_format = $PostField;
}
foreach ($date_formats as $format) {
if($format == $selected_format) $selected = ' selected="selected" '; else $selected=NULL;
$buffer .= '<option value="'.$format.'"'.$selected.'>'.htmlentities(date($format,$current_time)).'</option>'."\n";
}
return $buffer;
}
//
// Function: ConfigMechanismSelect
//
// Description: Set the protection mechanism options.
//
function ConfigMechanismSelects($PostField,$ConfigOption){
$options = array("htaccess", "mod_dbd");
$buffer = '';
if(empty($PostField)){
$current = $ConfigOption;
} else {
$current = $PostField;
}
foreach ($options as $opt) {
if($opt == $current)
$selected = ' selected="selected" '; else $selected=NULL;
$buffer .= '<option value="' . $opt . '"' . $selected . '>' . $opt . '</option>' . "\n";
}
return $buffer;
}
// this function is used on the configuration page to print out the verification type selection menu
function ConfigVerificationSelects($PostField,$ConfigOptionVerifyEmail,$ConfigOptionRequireAdminAccept){
$options = Array('None'=>'0','Email Confirmation'=>'1','Admin Approval'=>'2','Email and Admin'=>'3');
$buffer = '';
if(empty($PostField)){
if($ConfigOptionVerifyEmail=='true' && $ConfigOptionRequireAdminAccept=='true'){
$selected_validation = '3';
} elseif($ConfigOptionVerifyEmail=='true' && $ConfigOptionRequireAdminAccept!='true') {
$selected_validation = '1';
} elseif($ConfigOptionVerifyEmail!='true' && $ConfigOptionRequireAdminAccept=='true'){
$selected_validation = '2';
} elseif($ConfigOptionVerifyEmail!='true' && $ConfigOptionRequireAdminAccept!='true'){
$selected_validation = '0';
}
} else {
$selected_validation = $PostField;
}
foreach ($options as $text => $value){
if($selected_validation == $value) $selected = ' selected="selected" '; else $selected = NULL;
$buffer .= '<option value="'.$value.'"'.$selected.'>'.$text.'</option>';
}
return $buffer;
}
// this function checks whther or not a radio button should be selected. this function is for the configuration page.
function ConfigRadioCheck($PostField,$ConfigOption,$Button){
// which button are we checking, on or off?
if($Button=='off'){
if(!isset($PostField)){
if($ConfigOption!='true'){
return ' checked="checked"';
}
} elseif($PostField!='true') {
return ' checked="checked"';
}
} else {
if(!isset($PostField)){
if($ConfigOption=='true'){
return ' checked="checked"';
}
} elseif($PostField=='true') {
return ' checked="checked"';
}
}
}
// this function gives text fields a default value. this function is for the configuration page.
function ConfigTextField($PostField,$ConfigOption){
if(isset($PostField)){
return $PostField;
} else {
return $ConfigOption;
}
}
function ConfigAuthTypeSelects($PostField,$ConfigOption){
if(!empty($PostField)){
$selected = $PostField;
} else {
$selected = $ConfigOption;
}
$options = array('Basic'=>'false','Digest'=>'true');
$buffer = '';
foreach($options as $name => $value){
if($value == $selected) $isselected = ' selected="selected"'; else $isselected = null;
$buffer .= '<option value="'.$value.'"'.$isselected.'>'.$name.'</option>';
}
return $buffer;
}
// this function is to approve a user account
function accept_user_request($dbh,$username,$prefix){
$sql = 'UPDATE `'.$prefix.'users` SET `status` = \'2\' WHERE `username`=\''.$username.'\'';
if($dbh->query($sql)){
return true;
} else {
return false;
}
}
// Take config options from database and put them in an array
function get_config($dbh, $prefix){
if($stmt = $dbh->query('SELECT * FROM '.$prefix.'config')){
while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
$config[$row->option_name] = $row->value;
}
return $config;
} else {
db_failure($dbh, $dbh->errorInfo());
}
}
// Update an option on the configuration page
function ConfigUpdateOption($dbh,$Option,$OptionDisplayName,$Value,$prefix){
$sql = 'UPDATE '.$prefix.'config SET value = \''.$Value.'\' WHERE option_name = \''.$Option.'\'';
if($dbh->query($sql)){
return true;
} else {
db_failure($dbh, $dbh->errorInfo(), $sql);
}
}
// this option updates any pending user's status to verified
function ConfigUpdateApprovalStatus($dbh,$prefix){
$sql = 'UPDATE '.$prefix.'users SET status = \'2\' WHERE status = \'1\'';
if($dbh->query($sql)){
return true;
} else {
db_failure($dbh, $dbh->errorInfo(), $sql);
}
}
// same as above function except updates users who have not validated their email
function ConfigUpdateInactiveStatus($dbh,$prefix,$newstatus){
$sql = 'UPDATE '.$prefix.'users SET status = \''.$newstatus.'\' WHERE status = \'0\'';
if($dbh->query($sql)){
return true;
} else {
db_failure($dbh, $dbh->errorInfo(), $sql);
}
}
// Function: validate_password
//
// Description: Check to make sure a password meets password requirements.
// This check against length and regex based contraints.
// Returns true if the password is good, false if it is not
//
function validate_password ($password,$minlength,$maxlength,$patt_1, $patt_2){
/* echo 'validate_password> ' . $password . ', ' . $minlength . ', ' . $maxlength . ', "' .
$patt_1 . '", "' . $patt_2 . '"!'; */
if(strlen($password) >= $minlength && strlen($password) <= $maxlength){
if(preg_match($patt_1 , $password)
&& preg_match($patt_2, $password) ){
return true;
} else {
/* echo 'validate_password> pattern check failed!'; */
return false;
}
} else {
/* echo 'validate_password> lengh check failed!'; */
return false;
}
}
// This will simply make sure usernames are the correct length and are alphanumeric
// Returns true if the username is valid.
function validate_username ($username,$minlength=5,$maxlength=15){
if(strlen($username) >= $minlength && strlen($username) <= $maxlength){
if(ctype_alnum($username)){
return true;
} else {
return false;
}
} else {
return false;
}
}
// This will simply make sure names are the correct length and are alphanumeric
// Returns true if the username is valid.
function validate_name ($name,$minlength=1,$maxlength=15){
if(strlen($name) >= $minlength && strlen($name) <= $maxlength){
if(ctype_alnum(str_replace(array('-',' '),null,$name))){
return true;
} else {
return false;
}
} else {
return false;
}
}
// Function to validate an email address. This will return true if the email address is valid.
function validate_email_address($email) {
// First, we check that there's one @ symbol, and that the lengths are right
if (!preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!preg_match("/^(([A-Za-z0-9!#$%&'*+\/=?^_`{|}~-][A-Za-z0-9!#$%&'*+\/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/", $local_array[$i])) {
return false;
}
}
if (!preg_match("/^\[?[0-9\.]+\]?$/", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/", $domain_array[$i])) {
return false;
}
}
}
return true;
}
function show_footer($version) {
print 'Powered by <a href="http://code.google.com/p/php-reg-portal/">PHP RegPortal</a>';
}
function show_user_footer($version) {
return 'Powered by <a href="http://code.google.com/p/php-reg-portal/">PHP RegPortal</a>';
}
function show_bottom_nav ($admin_path){
print '<a href="'.$admin_path.'index.php">Home</a> |
User List |
Requests |
New User |
Email |
Stats |
Config |
<a href="'.$admin_path.'login.php?cmd=logout">Logout</a>';
}
// This is a function to use when checking fields that can be set to optional.
function validate_optional_fields($string,$setting){
if($setting=="true"){
if(empty($string)){
return false;
} else {
return true;
}
} else {
return true;
}
}
// If the string equals the value then returns true
// This is for a field that can be set to optional.
function match_string($string,$value,$option=1){
if($option=="true"){
if($string == $value){
return true;
} else {
return false;
}
} else {
return false;
}
}
// this checks to see if the phone number is numeric,
// but also allows you to disable the check
function validate_phone($phone,$required_digits,$option){
if($option=="true" || !empty($phone)){
if(is_numeric($phone) && strlen($phone) >= $required_digits){
return true;
} else {
return false;
}
} else {
return true;
}
}
/**
* Chop a string into a smaller string.
*
* @author Aidan Lister <aidan@php.net>
* @version 1.1.0
* @link http://aidanlister.com/repos/v/function.str_chop.php
* @param mixed $string The string you want to shorten
* @param int $length The length you want to shorten the string to
* @param bool $center If true, chop in the middle of the string
* @param mixed $append String appended if it is shortened
*/
function str_chop($string, $length = 60, $center = false, $append = null)
{
// Set the default append string
if ($append === null) {
$append = ($center === true) ? '..' : '..';
}