PageRenderTime 26ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/ASTRA_Demo_Server/udrive/www/astra/interact/spaceadmin/spaceinput.php

https://github.com/shafiqissani/ASTRA-College-Website
PHP | 374 lines | 215 code | 123 blank | 36 comment | 45 complexity | ac8500a729e91d0a3d54115366470e4b MD5 | raw file
  1. <?php
  2. // +------------------------------------------------------------------------+
  3. // | This file is part of Interact. |
  4. // | |
  5. // | This program is free software; you can redistribute it and/or modify |
  6. // | it under the terms of the GNU General Public License as published by |
  7. // | the Free Software Foundation (version 2) |
  8. // | |
  9. // | This program is distributed in the hope that it will be useful, but |
  10. // | WITHOUT ANY WARRANTY; without even the implied warranty of |
  11. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
  12. // | General Public License for more details. |
  13. // | |
  14. // | You should have received a copy of the GNU General Public License |
  15. // | along with this program; if not, you can view it at |
  16. // | http://www.opensource.org/licenses/gpl-license.php |
  17. // +------------------------------------------------------------------------+
  18. /**
  19. * Space input page
  20. *
  21. * Displays a page for adding modifying a new space
  22. *
  23. * @package SpaceAdmin
  24. * @author Glen Davies <glen.davies@cce.ac.nz>
  25. * @copyright Christchurch College of Education 2001
  26. * @version $Id: spaceinput.php,v 1.20 2007/07/30 01:57:07 glendavies Exp $
  27. *
  28. */
  29. /**
  30. * Include main system config file
  31. */
  32. require_once('../local/config.inc.php');
  33. if ($_SERVER['REQUEST_METHOD']=='GET') {
  34. $referer = isset($_GET['referer'])? $_GET['referer'] : '';
  35. $space_key = isset($_GET['space_key'])? $_GET['space_key'] : '';
  36. $parent_key = isset($_GET['parent_key'])? $_GET['parent_key'] : '';
  37. $action = isset($_GET['action'])? $_GET['action'] : '';
  38. } else {
  39. $referer = isset($_POST['referer'])? $_POST['referer'] : '';
  40. $space_key = isset($_POST['space_key'])? $_POST['space_key'] : '';
  41. $parent_key = isset($_POST['parent_key'])? $_POST['parent_key'] : '';
  42. $action = isset($_POST['action'])? $_POST['action'] : '';
  43. $submit = isset($_POST['submit'])? $_POST['submit'] : '';
  44. $delete_subs = isset($_POST['delete_subs'])? $_POST['delete_subs'] : '';
  45. $space_data = array();
  46. foreach($_POST as $key => $value ) {
  47. $space_data[$key] = $value;
  48. }
  49. }
  50. //get language strings
  51. require_once($CONFIG['LANGUAGE_CPATH'].'/space_strings.inc.php');
  52. //check to see if user is logged in. If not refer to Login page.
  53. $access_levels = authenticate();
  54. $accesslevel_key = $access_levels['accesslevel_key'];
  55. if ($_SESSION['userlevel_key']!=1 && $accesslevel_key!=1 && $accesslevel_key!=3) {
  56. $message = urlencode($general_strings['not_allowed']);
  57. header("Location: {$CONFIG['FULL_URL']}/index.php?message=$message");
  58. exit;
  59. }
  60. $group_access = $access_levels['groups'];
  61. if (!class_exists(InteractSpaceAdmin)) {
  62. require_once('lib.inc.php');
  63. }
  64. $objSpaceAdmin = new InteractSpaceAdmin();
  65. if (isset($action) && $action!='') {
  66. switch($action) {
  67. case add:
  68. $errors = $objSpaceAdmin->checkInputFormData($space_data);
  69. //if there are no errors then add the data
  70. if(count($errors) == 0) {
  71. $message = $objSpaceAdmin->addSpace($space_data);
  72. if ($message=='true') {
  73. if ($referer=='home') {
  74. $message = urlencode(sprintf($space_strings['space_added'], $general_strings['space_text']));
  75. header("Location: {$CONFIG['FULL_URL']}/index.php?message=$message");
  76. exit;
  77. } else if ($referer=='admin') {
  78. $message = urlencode(sprintf($space_strings['space_added'], $general_strings['space_text']));
  79. Header ("Location: {$CONFIG['FULL_URL']}/spaceadmin/spaceinput.php?referer=admin&message=$message");
  80. exit;
  81. } else {
  82. $message = urlencode(sprintf($space_strings['space_added'], $general_strings['space_text']));
  83. header("Location: {$CONFIG['FULL_URL']}/spaces/space.php?space_key=$parent_key&message=$message");
  84. exit;
  85. }
  86. }
  87. } else {
  88. $message = $general_strings['problem_below'];
  89. }
  90. break;
  91. case modify:
  92. $space_data = $objSpaceAdmin->getSpaceData($space_key);
  93. $action = 'modify2';
  94. $button = $general_strings['modify'];
  95. $title = sprintf($space_strings['modify_space'],$general_strings['space_text']);
  96. $delete_button = '<input type="submit" name="submit" value="'.$general_strings['delete'].'" onClick="return confirmDelete(\''.$general_strings['check'].'\')"/>';
  97. break;
  98. case modify2:
  99. switch($submit) {
  100. case $general_strings['modify']:
  101. $errors = $objSpaceAdmin->checkInputFormData($space_data);
  102. //if there are no errors then add the data
  103. if(count($errors) == 0) {
  104. $message = $objSpaceAdmin->modifySpace($space_data);
  105. if ($message===true) {
  106. $message = urlencode(sprintf($space_strings['space_modified'], $general_strings['space_text']));
  107. header("Location: {$CONFIG['FULL_URL']}/spaceadmin/admin.php?space_key=$space_key&message=$message");
  108. exit;
  109. }
  110. } else {
  111. $message = $general_strings['problem_below'];
  112. $action = 'modify2';
  113. $button = $general_strings['modify'];
  114. $title = sprintf($space_strings['modify_space'],$general_strings['space_text']);
  115. $delete_button = '<input type="submit" name="submit" value="'.$general_strings['delete'].'" onClick="return confirmDelete(\''.$general_strings['check'].'\')"/>';
  116. if (!isset($space_data['parent_keys']) || !is_array($space_data['parent_keys'])) {
  117. $space_data['parent_keys'] = array();
  118. }
  119. }
  120. break;
  121. case $general_strings['delete']:
  122. $objSpaceAdmin->deleteSpace($space_key, $delete_subs);
  123. $message = urlencode(sprintf($space_strings['space_deleted'], $general_strings['space_text']));
  124. header("Location: {$CONFIG['FULL_URL']}/index.php?message=$message");
  125. break;
  126. }
  127. break;
  128. } //end switch $action
  129. } else {
  130. $space_key = isset($_GET['space_key'])? $_GET['space_key'] : '';
  131. $referer = isset($_GET['referer'])? $_GET['referer'] : '';
  132. }
  133. //check refere, if server admin then show server admin navigation
  134. if ($referer=='admin') {
  135. $navigation_template = 'admin/adminnavigation.ihtml';
  136. } else {
  137. $navigation_template = 'navigation.ihtml';
  138. }
  139. require_once($CONFIG['TEMPLATE_CLASS_PATH'].'/template.inc');
  140. $t = new Template($CONFIG['TEMPLATES_PATH']);
  141. $t->set_file(array(
  142. 'header' => 'header.ihtml',
  143. 'navigation' => $navigation_template,
  144. 'form' => 'spaceadmin/spaceinput.ihtml',
  145. 'footer' => 'footer.ihtml'));
  146. // get page details for titles and breadcrumb navigation
  147. if (isset($space_key) && $space_key!='') {
  148. $current_space_key = $space_key;
  149. } else if (isset($parent_key) && $parent_key!=''){
  150. $current_space_key = $parent_key;
  151. } else {
  152. $current_space_key = '';
  153. }
  154. $page_details=get_page_details($current_space_key);
  155. set_common_template_vars($current_space_key,$module_key,$page_details, $message, $accesslevel_key, $group_accesslevel);
  156. if (!isset($action) || $action=='' || $action=='add') {
  157. $action = 'add';
  158. $space_data['access_level_key'] = 1;
  159. $space_data['visibility_key'] = 1;
  160. if (isset($page_details['space_name']) && $page_details['space_name']!='') {
  161. $title = sprintf($space_strings['add_subspace_to'], $general_strings['space_text'], $page_details['space_name']);
  162. } else {
  163. $title = sprintf($space_strings['add_space'], $general_strings['space_text']);
  164. }
  165. $button = $general_strings['add'];
  166. $space_data['show_members'] = 1;
  167. $space_data['parent_keys'] = array();
  168. if (isset($parent_key) && $parent_key!='') {
  169. $space_data['parent_keys'][0]=$parent_key;
  170. }
  171. $t->set_block('form', 'DeleteOptionsBlock', 'DOBlock');
  172. $t->set_var('DOBlock','');
  173. } else {
  174. $t->set_var('DELETE_SUB_STRING',sprintf($space_strings['delete_sub_spaces'],sprintf($space_strings['sub_sites'],$general_strings['space_plural'])));
  175. }
  176. $t->set_block('navigation', 'ModuleHeadingBlock', 'MHBlock');
  177. $t->set_var('MHBlock','');
  178. if (!class_exists('InteractHtml')) {
  179. require_once('../includes/lib/html.inc.php');
  180. }
  181. $html = new InteractHtml();
  182. $show_members_menu = $html->arrayToMenu(array('1' => $general_strings['yes'], '0' => $general_strings['no']),'show_members',$space_data['show_members']);
  183. $combine_names_menu = $html->arrayToMenu(array('1' => $general_strings['yes'], '0' => $general_strings['no']),'combine_names',$space_data['combine_names']);
  184. if (!isset($space_key) || $space_key=='') {
  185. $t->set_var('BREADCRUMBS','');
  186. $t->set_var('PAGE_TITLE',$title);
  187. $t->set_var('SPACE_TITLE','');
  188. $t->set_var("MAKE_MEMBER","");
  189. }
  190. $t->parse('CONTENTS', 'header', true);
  191. $t->set_var('NAME_ERROR',isset($errors['name'])? sprint_error($errors['name']):'');
  192. $t->set_var('DESCRIPTION_ERROR',isset($errors['description'])? sprint_error($errors['description']):'');
  193. $t->set_var('COPY_ERROR',isset($errors['copy_space'])? sprint_error($errors['copy_space']):'');
  194. $t->set_var('CODE_ERROR',isset($errors['code'])? sprint_error($errors['code']):'');
  195. $t->set_var('SHORT_NAME',isset($space_data['short_name'])? $space_data['short_name']: '');
  196. $t->set_var('NAME',isset($space_data['name'])? $space_data['name']: '');
  197. $t->set_var('DESCRIPTION',isset($space_data['description'])? $space_data['description']: '');
  198. $t->set_var('ACCESS_LEVEL_'.$space_data['access_level_key'].'_CHECKED','checked');
  199. $t->set_var('VISIBILITY_'.$space_data['visibility_key'].'_CHECKED','checked');
  200. $t->set_var('SHORT_DATE_MENU',$short_date_menu);
  201. $t->set_var('LONG_DATE_MENU',$long_date_menu);
  202. $t->set_var('PARENT_KEY',$parent_key);
  203. $t->set_var('STATUS_MENU',$status_menu);
  204. $t->set_var('TYPE_MENU',$type_menu);
  205. $t->set_var('TEMPLATE_MENU',$template_menu);
  206. $t->set_var('CATEGORY_MENU',$category_menu);
  207. $t->set_var('ACCESS_CODE',isset($space_data['access_code'])? $space_data['access_code']: '');
  208. $t->set_var('SPACE_KEY',$space_key);
  209. $t->set_var('COPY_space_short_name',$copy_space_short_name);
  210. $t->set_var('SORT_ORDER',$space_data['sort_order']);
  211. $t->set_var('REFERER',$referer);
  212. $t->set_var('SHOW_MEMBERS_MENU',$show_members_menu);
  213. $t->set_var('SPACE_NAME_STRING',$space_strings['name']);
  214. $t->set_var('SHORT_NAME_STRING',$space_strings['short_name']);
  215. $t->set_var('EXPLAIN_SHORT_NAME_STRING',$space_strings['explain_short_name']);
  216. $t->set_var('COMBINE_NAMES_STRING',sprintf($space_strings['combine_names'], $general_strings['space_text'], $general_strings['space_text']));
  217. $t->set_var('COMBINE_NAMES_MENU',$combine_names_menu);
  218. $t->set_var('DESCRIPTION_STRING',$general_strings['description']);
  219. $t->set_var('EXPLAIN_DESCRIPTION_STRING',$space_strings['explain_description']);
  220. $t->set_var('ACCESS_STRING',$space_strings['access']);
  221. $t->set_var('VISIBILITY_STRING',$space_strings['visibility']);
  222. $t->set_var('OPEN_STRING',$space_strings['open_logged_in']);
  223. $t->set_var('OPEN_PUBLIC_STRING',$space_strings['open_to_public']);
  224. $t->set_var('RESTRICTED_STRING',$space_strings['restrict_to_members']);
  225. $t->set_var('VISIBLE_STRING',$space_strings['visible']);
  226. $t->set_var('HIDDEN_STRING',$space_strings['hidden']);
  227. $t->set_var('OPTIONAL_SETTINGS_STRING',$general_strings['optional_settings']);
  228. $t->set_var('COPY_STRING',sprintf($space_strings['copy'], $general_strings['space_text']));
  229. $t->set_var('COPY_CODE_STRING',sprintf($space_strings['copy_code'], $general_strings['space_text']));
  230. $t->set_var('CODE_STRING',$space_strings['code']);
  231. $t->set_var('CODE',$space_data['code']);
  232. $t->set_var('SHOW_MEMBERS_STRING',$space_strings['show_members']);
  233. $t->set_var('SORT_ORDER_STRING',$general_strings['sort_order']);
  234. $t->set_var('EXPLAIN_SORT_ORDER_STRING',$space_strings['sort_explain']);
  235. $t->set_var('SPACE_INPUT_HEADING',$title);
  236. $t->set_var('DELETE_BUTTON',isset($delete_button)? $delete_button : '');
  237. $t->set_var('PARENT_SPACE_STRING',sprintf($space_strings['parent_space'], $general_strings['space_text']));
  238. $t->set_var('PARENT_SPACE_MENU',$objSpaceAdmin->getSpaceParentMenu(0, $parent_menu, $space_data['parent_keys'], $space_key) );
  239. $t->set_var('ACTION',$action);
  240. $t->set_var('BUTTON',$button);
  241. if ($referer=='admin') {
  242. admin_navigation();
  243. } else {
  244. get_navigation();
  245. }
  246. $t->parse('CONTENTS', 'form', true);
  247. $t->parse('CONTENTS', 'footer', true);
  248. $t->p('CONTENTS');
  249. $CONN->Close();
  250. exit;
  251. ?>