diff options
Diffstat (limited to 'series/trunk/admin/adduser.php')
-rw-r--r-- | series/trunk/admin/adduser.php | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/series/trunk/admin/adduser.php b/series/trunk/admin/adduser.php new file mode 100644 index 0000000..dcad5d5 --- /dev/null +++ b/series/trunk/admin/adduser.php | |||
@@ -0,0 +1,110 @@ | |||
1 | <?php | ||
2 | |||
3 | /* InstaDisc Series - A Four Island Project */ | ||
4 | |||
5 | /** | ||
6 | * require_once() is used to ensure | ||
7 | * the ACP files are being called by | ||
8 | * admin.php instead of their actual | ||
9 | * locations admin/. | ||
10 | * The _once() part ensures no problem | ||
11 | * arises as includes/instadisc.php has | ||
12 | * already been included from admin.php | ||
13 | */ | ||
14 | require_once('includes/instadisc.php'); | ||
15 | |||
16 | if (!isset($_SESSION['username'])) | ||
17 | { | ||
18 | header('Location: index.php'); | ||
19 | exit; | ||
20 | } | ||
21 | |||
22 | if (!isset($_GET['submit'])) | ||
23 | { | ||
24 | showForm('','',array()); | ||
25 | } else { | ||
26 | $numOfErrors = 0; | ||
27 | $errors = array(); | ||
28 | |||
29 | if ($_POST['username'] == '') | ||
30 | { | ||
31 | addError($numOfErrors, $errors, 'username', 'Username is a required field'); | ||
32 | } | ||
33 | |||
34 | if ($_POST['password'] == '') | ||
35 | { | ||
36 | addError($numOfErrors, $errors, 'password', 'Password is a required field'); | ||
37 | } | ||
38 | |||
39 | if ($numOfErrors > 0) | ||
40 | { | ||
41 | showForm($_POST['username'], $_POST['password'], $errors); | ||
42 | } else { | ||
43 | instaDisc_addUser($_POST['username'], $_POST['password']); | ||
44 | |||
45 | $template = new FITemplate('addeduser'); | ||
46 | $template->add('SITENAME', instaDisc_getConfig('siteName')); | ||
47 | $template->display(); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | function showForm($username, $password, $errors) | ||
52 | { | ||
53 | $template = new FITemplate('adduser'); | ||
54 | $template->add('SITENAME', instaDisc_getConfig('siteName')); | ||
55 | |||
56 | if (isset($errors[1])) | ||
57 | { | ||
58 | $template->adds_block('ERROR', array('ex'=>'1')); | ||
59 | |||
60 | foreach ($errors as $name => $value) | ||
61 | { | ||
62 | $template->adds_block('ERRORS', array( 'NAME' => $name, | ||
63 | 'MSG' => $value['msg'])); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | $template->add('USERNAME_ERR', ifErrors($errors, 'username')); | ||
68 | $template->add('PASSWORD_ERR', ifErrors($errors, 'password')); | ||
69 | |||
70 | doErrors($template, $errors, 'username'); | ||
71 | doErrors($template, $errors, 'password'); | ||
72 | |||
73 | $template->add('USERNAME', $username); | ||
74 | $template->add('PASSWORD', $password); | ||
75 | |||
76 | $template->display(); | ||
77 | } | ||
78 | |||
79 | function ifErrors($errors, $id) | ||
80 | { | ||
81 | foreach ($errors as $name => $value) | ||
82 | { | ||
83 | if ($value['field'] == $id) | ||
84 | { | ||
85 | return ' error'; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | return ''; | ||
90 | } | ||
91 | |||
92 | function doErrors($template, $errors, $id) | ||
93 | { | ||
94 | foreach ($errors as $name => $value) | ||
95 | { | ||
96 | if ($value['field'] == $id) | ||
97 | { | ||
98 | $template->adds_block(strtoupper($id) . '_ERRS', array( 'NAME' => $name, | ||
99 | 'VALUE' => $value['msg'])); | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | |||
104 | function addError(&$numOfErrors, &$errors, $field, $msg) | ||
105 | { | ||
106 | $numOfErrors++; | ||
107 | $errors[$numOfErrors] = array('field' => $field, 'msg' => $msg); | ||
108 | } | ||
109 | |||
110 | ?> | ||