about summary refs log tree commit diff stats
path: root/central/trunk/addsub.php
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2008-08-17 01:28:41 +0000
committerKelly Rauchenberger <fefferburbia@gmail.com>2008-08-17 01:28:41 +0000
commitd1bb2bc4a10548a716899b706b6d4cb2151b6c0f (patch)
treee59161654a9d5ac71fa0c9c5c9e9f06a55cfa905 /central/trunk/addsub.php
parent3a6543c2882af5b1377b417119a852619d6f3dd6 (diff)
downloadinstadisc-d1bb2bc4a10548a716899b706b6d4cb2151b6c0f.tar.gz
instadisc-d1bb2bc4a10548a716899b706b6d4cb2151b6c0f.tar.bz2
instadisc-d1bb2bc4a10548a716899b706b6d4cb2151b6c0f.zip
Central: Created Add Subscription page
Refs #25
Diffstat (limited to 'central/trunk/addsub.php')
-rw-r--r--central/trunk/addsub.php94
1 files changed, 94 insertions, 0 deletions
diff --git a/central/trunk/addsub.php b/central/trunk/addsub.php new file mode 100644 index 0000000..fd46234 --- /dev/null +++ b/central/trunk/addsub.php
@@ -0,0 +1,94 @@
1<?php
2
3/* InstaDisc Server - A Four Island Project */
4
5include('includes/instadisc.php');
6include('includes/template.php');
7
8if (!isset($_GET['submit']))
9{
10 showForm('',array());
11} else {
12 $numOfErrors = 0;
13 $errors = array();
14
15 if ($_POST['url'] == '')
16 {
17 addError($numOfErrors, $errors, 'url', 'URL is a required field');
18 }
19
20 if ($numOfErrors > 0)
21 {
22 showForm($_POST['url'], $errors);
23 } else {
24 $key = instaDisc_generateSubscriptionActivation($_SESSION['username'], $_POST['url']);
25 if ($key !== FALSE)
26 {
27 $template = new FITemplate('addedsub');
28 $template->add('SITENAME', instaDisc_getConfig('siteName'));
29 $template->add('KEY', $key);
30 $template->display();
31 } else {
32 addError($numOfErrors, $errors, '', 'Unknown error');
33 showForm($_POST['url'], $errors);
34 }
35 }
36}
37
38function showForm($url, $errors)
39{
40 $template = new FITemplate('addsub');
41 $template->add('SITENAME', instaDisc_getConfig('siteName'));
42
43 if (isset($errors[1]))
44 {
45 $template->adds_block('ERROR', array('ex'=>'1'));
46
47 foreach ($errors as $name => $value)
48 {
49 $template->adds_block('ERRORS', array( 'NAME' => $name,
50 'MSG' => $value['msg']));
51 }
52 }
53
54 $template->add('URL_ERR', ifErrors($errors, 'url'));
55
56 doErrors($template, $errors, 'url');
57
58 $template->add('URL', $url);
59
60 $template->display();
61}
62
63function ifErrors($errors, $id)
64{
65 foreach ($errors as $name => $value)
66 {
67 if ($value['field'] == $id)
68 {
69 return ' error';
70 }
71 }
72
73 return '';
74}
75
76function doErrors($template, $errors, $id)
77{
78 foreach ($errors as $name => $value)
79 {
80 if ($value['field'] == $id)
81 {
82 $template->adds_block(strtoupper($id) . '_ERRS', array( 'NAME' => $name,
83 'VALUE' => $value['msg']));
84 }
85 }
86}
87
88function addError(&$numOfErrors, &$errors, $field, $msg)
89{
90 $numOfErrors++;
91 $errors[$numOfErrors] = array('field' => $field, 'msg' => $msg);
92}
93
94?>