about summary refs log tree commit diff stats
path: root/series/trunk/admin/editsub.php
diff options
context:
space:
mode:
Diffstat (limited to 'series/trunk/admin/editsub.php')
-rw-r--r--series/trunk/admin/editsub.php151
1 files changed, 151 insertions, 0 deletions
diff --git a/series/trunk/admin/editsub.php b/series/trunk/admin/editsub.php new file mode 100644 index 0000000..cafd217 --- /dev/null +++ b/series/trunk/admin/editsub.php
@@ -0,0 +1,151 @@
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 */
14require_once('includes/instadisc.php');
15
16if (!isset($_SESSION['username']))
17{
18 header('Location: index.php');
19 exit;
20}
21
22if (!instaDisc_isAdmin($_SESSION['username']))
23{
24 $subs = instaDisc_listSubscriptions($_SESSION['username']);
25 $i=0;
26 $notfound=1;
27 for ($i=0;isset($subs[$i]);$i++)
28 {
29 if (!isset($_GET['submit']))
30 {
31 if ($subs[$i]['identity'] == $_POST['id'])
32 {
33 $notfound=0;
34 }
35 } else {
36 if ($subs[$i]['id'] == $_GET['subid'])
37 {
38 $notfound=0;
39 }
40 }
41 }
42
43 if ($notfound == 1)
44 {
45 header('Location: index.php');
46 exit;
47 }
48}
49
50if (!isset($_GET['submit']))
51{
52 $sub = instaDisc_getSubscription($_GET['subid']);
53 showForm($sub['identity'],$sub['title'],$sub['category'],$sub['url'],$sub['password'],array());
54} else {
55 $numOfErrors = 0;
56 $errors = array();
57
58 if ($_POST['title'] == '')
59 {
60 addError($numOfErrors, $errors, 'title', 'Title is a required field');
61 }
62
63 if ($_POST['url'] == '')
64 {
65 addError($numOfErrors, $errors, 'url', 'Subscription URL is a required field');
66 }
67
68 if ($_POST['category'] == '')
69 {
70 addError($numOfErrors, $errors, 'category', 'Category is a required field');
71 }
72
73 if ($numOfErrors > 0)
74 {
75 showForm($_POST['id'], $_POST['title'], $_POST['url'], $_POST['category'], $_POST['password'], $errors);
76 } else {
77 instaDisc_initSubscription($_SESSION['username'], $_POST['id'], $_POST['url'], $_POST['title'], $_POST['category'], $_POST['personal'], $_POST['password']);
78
79 $template = new FITemplate('editedsub');
80 $template->add('SITENAME', instaDisc_getConfig('siteName'));
81 $template->display();
82 }
83}
84
85function showForm($id, $title, $url, $category, $password, $errors)
86{
87 $template = new FITemplate('editsub');
88 $template->add('SITENAME', instaDisc_getConfig('siteName'));
89
90 if (isset($errors[1]))
91 {
92 $template->adds_block('ERROR', array('ex'=>'1'));
93
94 foreach ($errors as $name => $value)
95 {
96 $template->adds_block('ERRORS', array( 'NAME' => $name,
97 'MSG' => $value['msg']));
98 }
99 }
100
101 $template->add('TITLE_ERR', ifErrors($errors, 'title'));
102 $template->add('URL_ERR', ifErrors($errors, 'url'));
103 $template->add('CATEGORY_ERR', ifErrors($errors, 'url'));
104 $template->add('PASSWORD_ERR', ifErrors($errors, 'url'));
105
106 doErrors($template, $errors, 'title');
107 doErrors($template, $errors, 'url');
108 doErrors($template, $errors, 'category');
109 doErrors($template, $errors, 'password');
110
111 $template->add('ID', $id);
112 $template->add('TITLE', $title);
113 $template->add('URL', $url);
114 $template->add('CATEGORY', $category);
115 $template->add('PASSWORD', $password);
116
117 $template->display();
118}
119
120function ifErrors($errors, $id)
121{
122 foreach ($errors as $name => $value)
123 {
124 if ($value['field'] == $id)
125 {
126 return ' error';
127 }
128 }
129
130 return '';
131}
132
133function doErrors($template, $errors, $id)
134{
135 foreach ($errors as $name => $value)
136 {
137 if ($value['field'] == $id)
138 {
139 $template->adds_block(strtoupper($id) . '_ERRS', array( 'NAME' => $name,
140 'VALUE' => $value['msg']));
141 }
142 }
143}
144
145function addError(&$numOfErrors, &$errors, $field, $msg)
146{
147 $numOfErrors++;
148 $errors[$numOfErrors] = array('field' => $field, 'msg' => $msg);
149}
150
151?>