diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2008-08-25 14:17:08 +0000 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2008-08-25 14:17:08 +0000 |
commit | 681a40af319373510f30793d3b892bd9700213fb (patch) | |
tree | 06bae9ed1f84f044d2edc45e0a75303e92239ba8 /central/trunk/activatesub.php | |
parent | 19ecd42bcc8f3da1cdfce989126f009cb7b990d0 (diff) | |
download | instadisc-681a40af319373510f30793d3b892bd9700213fb.tar.gz instadisc-681a40af319373510f30793d3b892bd9700213fb.tar.bz2 instadisc-681a40af319373510f30793d3b892bd9700213fb.zip |
Central: Added Activate Subscription form
Also added an option to the user panel that allows you to edit configuration values if you're an admin. Refs #25
Diffstat (limited to 'central/trunk/activatesub.php')
-rw-r--r-- | central/trunk/activatesub.php | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/central/trunk/activatesub.php b/central/trunk/activatesub.php new file mode 100644 index 0000000..46a05ec --- /dev/null +++ b/central/trunk/activatesub.php | |||
@@ -0,0 +1,124 @@ | |||
1 | <?php | ||
2 | |||
3 | /* InstaDisc Server - A Four Island Project */ | ||
4 | |||
5 | include('includes/instadisc.php'); | ||
6 | include('includes/template.php'); | ||
7 | |||
8 | if (isset($_SESSION['username'])) | ||
9 | { | ||
10 | if (!isset($_GET['submit'])) | ||
11 | { | ||
12 | showForm('',array()); | ||
13 | } else { | ||
14 | $numOfErrors = 0; | ||
15 | $errors = array(); | ||
16 | |||
17 | $getpending = "SELECT * FROM pending2 WHERE username = \"" . mysql_real_escape_string($_SESSION['username']) . "\" AND url = \"" . mysql_real_escape_string($_POST['url']) . "\""; | ||
18 | $getpending2 = mysql_query($getpending); | ||
19 | $getpending3 = mysql_fetch_array($getpending2); | ||
20 | if ($getpending3['username'] != $_POST['username']) | ||
21 | { | ||
22 | addError($numOfErrors, $errors, 'url', 'Subscription could not be found'); | ||
23 | } | ||
24 | |||
25 | if ($numOfErrors > 0) | ||
26 | { | ||
27 | showForm($_POST['url'], $errors); | ||
28 | } else { | ||
29 | if ($_POST['submit'] == "Verify") | ||
30 | { | ||
31 | switch (instaDisc_addSubscription($_SESSION['username'], $_POST['url'])) | ||
32 | { | ||
33 | case 0: | ||
34 | $template = new FITemplate('activatedsub'); | ||
35 | $template->add('SITENAME', instaDisc_getConfig('siteName')); | ||
36 | $template->display(); | ||
37 | break; | ||
38 | |||
39 | case 1: | ||
40 | addError($numOfErrors, $errors, '', 'Unknown error'); | ||
41 | showForm($_POST['url'], $errors); | ||
42 | break; | ||
43 | |||
44 | case 2: | ||
45 | addError($numOfErrors, $errors, 'url', 'Subscription could not be found'); | ||
46 | showForm($_POST['url'], $errors); | ||
47 | break; | ||
48 | |||
49 | case 3: | ||
50 | addError($numOfErrors, $errors, '', 'Subscription File is not well-formed'); | ||
51 | showForm($_POST['url'], $errors); | ||
52 | break; | ||
53 | |||
54 | case 4: | ||
55 | addError($numOfErrors, $errors, '', 'Key in Subscription File is incorrect'); | ||
56 | showForm($_POST['url'], $errors); | ||
57 | break; | ||
58 | } | ||
59 | } else { | ||
60 | instaDisc_cancelSubscription($_SESSION['username'], $_POST['url']); | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | } else { | ||
65 | header('Location: index.php'); | ||
66 | } | ||
67 | |||
68 | function showForm($url, $errors) | ||
69 | { | ||
70 | $template = new FITemplate('activatesub'); | ||
71 | $template->add('SITENAME', instaDisc_getConfig('siteName')); | ||
72 | |||
73 | if (isset($errors[1])) | ||
74 | { | ||
75 | $template->adds_block('ERROR', array('ex'=>'1')); | ||
76 | |||
77 | foreach ($errors as $name => $value) | ||
78 | { | ||
79 | $template->adds_block('ERRORS', array( 'NAME' => $name, | ||
80 | 'MSG' => $value['msg'])); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | $template->add('URL_ERR', ifErrors($errors, 'url')); | ||
85 | |||
86 | doErrors($template, $errors, 'url'); | ||
87 | |||
88 | $template->add('URL', $url); | ||
89 | |||
90 | $template->display(); | ||
91 | } | ||
92 | |||
93 | function ifErrors($errors, $id) | ||
94 | { | ||
95 | foreach ($errors as $name => $value) | ||
96 | { | ||
97 | if ($value['field'] == $id) | ||
98 | { | ||
99 | return ' error'; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | return ''; | ||
104 | } | ||
105 | |||
106 | function doErrors($template, $errors, $id) | ||
107 | { | ||
108 | foreach ($errors as $name => $value) | ||
109 | { | ||
110 | if ($value['field'] == $id) | ||
111 | { | ||
112 | $template->adds_block(strtoupper($id) . '_ERRS', array( 'NAME' => $name, | ||
113 | 'VALUE' => $value['msg'])); | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | |||
118 | function addError(&$numOfErrors, &$errors, $field, $msg) | ||
119 | { | ||
120 | $numOfErrors++; | ||
121 | $errors[$numOfErrors] = array('field' => $field, 'msg' => $msg); | ||
122 | } | ||
123 | |||
124 | ?> | ||