From 681a40af319373510f30793d3b892bd9700213fb Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 25 Aug 2008 14:17:08 +0000 Subject: 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 --- central/trunk/activatesub.php | 124 +++++++++++++++++++++++++++++++++++ central/trunk/includes/instadisc.php | 22 +++++-- central/trunk/theme/activatedsub.tpl | 14 ++++ central/trunk/theme/activatesub.tpl | 51 ++++++++++++++ central/trunk/theme/userpanel.tpl | 8 +++ central/trunk/userpanel.php | 6 ++ 6 files changed, 220 insertions(+), 5 deletions(-) create mode 100644 central/trunk/activatesub.php create mode 100644 central/trunk/theme/activatedsub.tpl create mode 100644 central/trunk/theme/activatesub.tpl (limited to 'central/trunk') 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 @@ + 0) + { + showForm($_POST['url'], $errors); + } else { + if ($_POST['submit'] == "Verify") + { + switch (instaDisc_addSubscription($_SESSION['username'], $_POST['url'])) + { + case 0: + $template = new FITemplate('activatedsub'); + $template->add('SITENAME', instaDisc_getConfig('siteName')); + $template->display(); + break; + + case 1: + addError($numOfErrors, $errors, '', 'Unknown error'); + showForm($_POST['url'], $errors); + break; + + case 2: + addError($numOfErrors, $errors, 'url', 'Subscription could not be found'); + showForm($_POST['url'], $errors); + break; + + case 3: + addError($numOfErrors, $errors, '', 'Subscription File is not well-formed'); + showForm($_POST['url'], $errors); + break; + + case 4: + addError($numOfErrors, $errors, '', 'Key in Subscription File is incorrect'); + showForm($_POST['url'], $errors); + break; + } + } else { + instaDisc_cancelSubscription($_SESSION['username'], $_POST['url']); + } + } + } +} else { + header('Location: index.php'); +} + +function showForm($url, $errors) +{ + $template = new FITemplate('activatesub'); + $template->add('SITENAME', instaDisc_getConfig('siteName')); + + if (isset($errors[1])) + { + $template->adds_block('ERROR', array('ex'=>'1')); + + foreach ($errors as $name => $value) + { + $template->adds_block('ERRORS', array( 'NAME' => $name, + 'MSG' => $value['msg'])); + } + } + + $template->add('URL_ERR', ifErrors($errors, 'url')); + + doErrors($template, $errors, 'url'); + + $template->add('URL', $url); + + $template->display(); +} + +function ifErrors($errors, $id) +{ + foreach ($errors as $name => $value) + { + if ($value['field'] == $id) + { + return ' error'; + } + } + + return ''; +} + +function doErrors($template, $errors, $id) +{ + foreach ($errors as $name => $value) + { + if ($value['field'] == $id) + { + $template->adds_block(strtoupper($id) . '_ERRS', array( 'NAME' => $name, + 'VALUE' => $value['msg'])); + } + } +} + +function addError(&$numOfErrors, &$errors, $field, $msg) +{ + $numOfErrors++; + $errors[$numOfErrors] = array('field' => $field, 'msg' => $msg); +} + +?> diff --git a/central/trunk/includes/instadisc.php b/central/trunk/includes/instadisc.php index d07e53b..6b3d630 100644 --- a/central/trunk/includes/instadisc.php +++ b/central/trunk/includes/instadisc.php @@ -294,9 +294,6 @@ function instaDisc_addSubscription($username, $url) $getcode3 = mysql_fetch_array($getcode2); if ($getcode3['username'] == $username) { - $delcode = "DELETE FROM pending2 WHERE username = \"" . mysql_real_escape_string($username) . "\" AND url = \"" . mysql_real_escape_string($url) . "\""; - $delcode2 = mysql_query($delcode); - $c = curl_init(); curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_HEADER, false); @@ -324,15 +321,30 @@ function instaDisc_addSubscription($username, $url) $inssub = "INSERT INTO subscriptions (username,url,owner,category) VALUES (\"" . mysql_real_escape_string($username) . "\", \"" . mysql_real_escape_string($header['Subscription']) . "\", \"true\", \"" . mysql_real_escape_string($header['Category']) . "\")"; $inssub2 = mysql_query($inssub); - return true; + $delcode = "DELETE FROM pending2 WHERE username = \"" . mysql_real_escape_string($username) . "\" AND url = \"" . mysql_real_escape_string($url) . "\""; + $delcode2 = mysql_query($delcode); + + return 0; + } else { + return 4; } + } else { + return 3; } + } else { + return 3; } + } else { + return 3; } + } else { + return 3; } + } else { + return 2; } - return false; + return 1; } function instaDisc_listPendingSubscriptions($username) diff --git a/central/trunk/theme/activatedsub.tpl b/central/trunk/theme/activatedsub.tpl new file mode 100644 index 0000000..9bdcbf5 --- /dev/null +++ b/central/trunk/theme/activatedsub.tpl @@ -0,0 +1,14 @@ + + + <!--SITENAME--> InstaDisc Central Server + + + +
+

InstaDisc Subscription Activation

+ +

You've sucessfully activated your subscription! Back to User Panel +

+ + + diff --git a/central/trunk/theme/activatesub.tpl b/central/trunk/theme/activatesub.tpl new file mode 100644 index 0000000..f6dd6a0 --- /dev/null +++ b/central/trunk/theme/activatesub.tpl @@ -0,0 +1,51 @@ + + + <!--SITENAME--> InstaDisc Central Server + + + + +
+

InstaDisc Subscription Activation

+ +

If you've already requested a subscription be sponsered and added its Activation Key to its Subscription File, you can activate the subscription here: +

+ +
+ + +
Uh oh! Validation errors!

+

    + + + +
  1. + + + +
+
+ + +
+ User Details + +
+ +

* + +

+ + + + +
+
+ +
+ + +
+
+ + diff --git a/central/trunk/theme/userpanel.tpl b/central/trunk/theme/userpanel.tpl index 63be6f1..c10c0dc 100644 --- a/central/trunk/theme/userpanel.tpl +++ b/central/trunk/theme/userpanel.tpl @@ -21,6 +21,14 @@
  • Activate a Subscription
  • Manage subscriptions
  • + + +

    Since you are the almighty admin of this Central Server, you can edit configurational values! + +

    + diff --git a/central/trunk/userpanel.php b/central/trunk/userpanel.php index f28b8fb..d0570e1 100644 --- a/central/trunk/userpanel.php +++ b/central/trunk/userpanel.php @@ -10,6 +10,12 @@ if (isset($_SESSION['username'])) $template = new FITemplate('userpanel'); $template->add('SITENAME', instaDisc_getConfig('siteName')); $template->add('USERNAME', $_SESSION['username']); + + if (instaDisc_getConfig('owner') == $_SESSION['username']) + { + $template->adds_block('ADMIN',array('ex'=>1)); + } + $template->display(); } else { header('Location: index.php'); -- cgit 1.4.1