diff options
Diffstat (limited to 'series/core/trunk/admin/addsub.php')
| -rw-r--r-- | series/core/trunk/admin/addsub.php | 129 |
1 files changed, 129 insertions, 0 deletions
| diff --git a/series/core/trunk/admin/addsub.php b/series/core/trunk/admin/addsub.php new file mode 100644 index 0000000..26a8109 --- /dev/null +++ b/series/core/trunk/admin/addsub.php | |||
| @@ -0,0 +1,129 @@ | |||
| 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['id'] == '') | ||
| 30 | { | ||
| 31 | addError($numOfErrors, $errors, 'id', 'Subscription ID is a required field'); | ||
| 32 | } | ||
| 33 | |||
| 34 | if ($_POST['title'] == '') | ||
| 35 | { | ||
| 36 | addError($numOfErrors, $errors, 'title', 'Title is a required field'); | ||
| 37 | } | ||
| 38 | |||
| 39 | if ($_POST['url'] == '') | ||
| 40 | { | ||
| 41 | addError($numOfErrors, $errors, 'url', 'Subscription URL is a required field'); | ||
| 42 | } | ||
| 43 | |||
| 44 | if ($_POST['category'] == '') | ||
| 45 | { | ||
| 46 | addError($numOfErrors, $errors, 'category', 'Category is a required field'); | ||
| 47 | } | ||
| 48 | |||
| 49 | if ($numOfErrors > 0) | ||
| 50 | { | ||
| 51 | showForm($_POST['id'], $_POST['title'], $_POST['url'], $_POST['category'], $_POST['password'], $errors); | ||
| 52 | } else { | ||
| 53 | instaDisc_addSubscription($_POST['id'], $_POST['title'], $_POST['url'], $_POST['category'], $_POST['password']); | ||
| 54 | |||
| 55 | $template = new FITemplate('addedsub'); | ||
| 56 | $template->add('SITENAME', instaDisc_getConfig('siteName')); | ||
| 57 | $template->display(); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | function showForm($id, $title, $url, $category, $password, $errors) | ||
| 62 | { | ||
| 63 | $template = new FITemplate('addsub'); | ||
| 64 | $template->add('SITENAME', instaDisc_getConfig('siteName')); | ||
| 65 | |||
| 66 | if (isset($errors[1])) | ||
| 67 | { | ||
| 68 | $template->adds_block('ERROR', array('ex'=>'1')); | ||
| 69 | |||
| 70 | foreach ($errors as $name => $value) | ||
| 71 | { | ||
| 72 | $template->adds_block('ERRORS', array( 'NAME' => $name, | ||
| 73 | 'MSG' => $value['msg'])); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | $template->add('ID_ERR', ifErrors($errors, 'id')); | ||
| 78 | $template->add('TITLE_ERR', ifErrors($errors, 'title')); | ||
| 79 | $template->add('URL_ERR', ifErrors($errors, 'url')); | ||
| 80 | $template->add('CATEGORY_ERR', ifErrors($category, 'url')); | ||
| 81 | $template->add('PASSWORD_ERR', ifErrors($password, 'url')); | ||
| 82 | |||
| 83 | doErrors($template, $errors, 'id'); | ||
| 84 | doErrors($template, $errors, 'title'); | ||
| 85 | doErrors($template, $errors, 'url'); | ||
| 86 | doErrors($template, $errors, 'category'); | ||
| 87 | doErrors($template, $errors, 'password'); | ||
| 88 | |||
| 89 | $template->add('ID', $id); | ||
| 90 | $template->add('TITLE', $title); | ||
| 91 | $template->add('URL', $url); | ||
| 92 | $template->add('CATEGORY', $category); | ||
| 93 | $template->add('PASSWORD', $password); | ||
| 94 | |||
| 95 | $template->display(); | ||
| 96 | } | ||
| 97 | |||
| 98 | function ifErrors($errors, $id) | ||
| 99 | { | ||
| 100 | foreach ($errors as $name => $value) | ||
| 101 | { | ||
| 102 | if ($value['field'] == $id) | ||
| 103 | { | ||
| 104 | return ' error'; | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | return ''; | ||
| 109 | } | ||
| 110 | |||
| 111 | function doErrors($template, $errors, $id) | ||
| 112 | { | ||
| 113 | foreach ($errors as $name => $value) | ||
| 114 | { | ||
| 115 | if ($value['field'] == $id) | ||
| 116 | { | ||
| 117 | $template->adds_block(strtoupper($id) . '_ERRS', array( 'NAME' => $name, | ||
| 118 | 'VALUE' => $value['msg'])); | ||
| 119 | } | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | function addError(&$numOfErrors, &$errors, $field, $msg) | ||
| 124 | { | ||
| 125 | $numOfErrors++; | ||
| 126 | $errors[$numOfErrors] = array('field' => $field, 'msg' => $msg); | ||
| 127 | } | ||
| 128 | |||
| 129 | ?> | ||
