PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/shafiqissani/ASTRA-College-Website
PHP | 223 lines | 123 code | 63 blank | 37 comment | 16 complexity | 4713304d9f8299dc63306a70358b4571 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. * Display and set space preferences
  20. *
  21. * Allows space administrators to displays and modify space preferences
  22. *
  23. * @package SpaceAdmin
  24. * @author Glen Davies <glen.davies@cce.ac.nz>
  25. * @copyright Christchurch College of Education 2001
  26. * @version $Id: preferences.php,v 1.15 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. //get language strings
  34. require_once($CONFIG['LANGUAGE_CPATH'].'/space_strings.inc.php');
  35. if ($_SERVER['REQUEST_METHOD']=='GET') {
  36. $space_key = $_GET['space_key'];
  37. } else {
  38. $space_key = $_POST['space_key'];
  39. $new_user_alert = $_POST['new_user_alert'];
  40. $status_key = $_POST['status_key'];
  41. $code = $_POST['code'];
  42. $name = $_POST['name'];
  43. $short_date_key = $_POST['short_date_key'];
  44. $long_date_key = $_POST['long_date_key'];
  45. $submit = $_POST['submit'];
  46. }
  47. //check we have the required variables
  48. check_variables(true,false);
  49. //check to see if user is logged in. If not refer to Login page.
  50. $access_levels = authenticate();
  51. $accesslevel_key = $access_levels['accesslevel_key'];
  52. authenticate_admins($level='space_only');
  53. $group_access = $access_levels['groups'];
  54. $page_details=get_page_details($space_key);
  55. if (!$submit) {
  56. $sql = "SELECT new_user_alert,status_key,code,name,short_date_format_key, long_date_format_key FROM {$CONFIG['DB_PREFIX']}spaces WHERE space_key='$space_key'";
  57. $rs = $CONN->Execute($sql);
  58. while (!$rs->EOF) {
  59. $new_user_alert = $rs->fields[0];
  60. $status_key = $rs->fields[1];
  61. $code = $rs->fields[2];
  62. $name = $rs->fields[3];
  63. $short_date_key =$rs->fields[4];
  64. $long_date_key =$rs->fields[5];
  65. $rs->MoveNext();
  66. }
  67. $rs->Close();
  68. $alert_menu='<select name="new_user_alert">';
  69. if ($new_user_alert=='true') {
  70. $alert_menu.='<option value="true" selected="selected">'.$general_strings['yes'].'</option>';
  71. $alert_menu.='<option value="false" >'.$general_strings['no'].'</option></select>';
  72. } else {
  73. $alert_menu.='<option value="true" >'.$general_strings['yes'].'</option>';
  74. $alert_menu.='<option value="false" selected="selected">'.$general_strings['no'].'</option></select>';
  75. }
  76. } else {
  77. $errors = check_form_input();
  78. if(count($errors) == 0) {
  79. $name = $name;
  80. $code = $code;
  81. $sql = "UPDATE {$CONFIG['DB_PREFIX']}spaces SET new_user_alert='$new_user_alert',status_key='$status_key',code='$code',name='$name', short_date_format_key='$short_date_key', long_date_format_key='$long_date_key' WHERE space_key='$space_key'";
  82. $CONN->Execute($sql);
  83. $message = urlencode($space_strings['preferences_updated']);
  84. header("Location: {$CONFIG['FULL_URL']}/spaceadmin/admin.php?space_key=$space_key&message=$message");
  85. } else {
  86. $message = $general_strings['problem_below'];
  87. }
  88. }
  89. $status_sql = "SELECT name, Spacestatus_key FROM {$CONFIG['DB_PREFIX']}spacestatus ORDER BY name";
  90. $status_menu = make_menu($status_sql,'status_key',$status_key,'4');
  91. $short_date_sql = "select format, format_key from {$CONFIG['DB_PREFIX']}date_formats WHERE type='short' ORDER BY format_key";
  92. $short_date_menu = make_menu($short_date_sql,"short_date_key",$short_date_key,"2");
  93. $long_date_sql = "select format, format_key from {$CONFIG['DB_PREFIX']}date_formats WHERE type='long' ORDER BY format_key";
  94. $long_date_menu = make_menu($long_date_sql,"long_date_key",$long_date_key,"2");
  95. require_once($CONFIG['TEMPLATE_CLASS_PATH'].'/template.inc');
  96. $t = new Template($CONFIG['TEMPLATES_PATH']);
  97. $t->set_file(array(
  98. 'header' => 'header.ihtml',
  99. 'navigation' => 'navigation.ihtml',
  100. 'form' => 'spaceadmin/preferences.ihtml',
  101. 'footer' => 'footer.ihtml'
  102. ));
  103. set_common_template_vars($space_key,$module_key,$page_details, $message, $accesslevel_key, $group_accesslevel);
  104. //format any errors from form submission
  105. $name_error = sprint_error($errors['name']);
  106. $code_error = sprint_error($errors['code']);
  107. $t->parse('CONTENTS', 'header', true);
  108. get_navigation();
  109. $t->set_var('NAME_ERROR',$name_error);
  110. $t->set_var('CODE_ERROR',$code_error);
  111. $t->set_var('ALERT_MENU',$alert_menu);
  112. $t->set_var('STATUS_MENU',$status_menu);
  113. $t->set_var('SHORT_DATE_MENU',$short_date_menu);
  114. $t->set_var('LONG_DATE_MENU',$long_date_menu);
  115. $t->set_var('SPACE_KEY',$space_key);
  116. $t->set_var('NAME',$name);
  117. $t->set_var('CODE',$code);
  118. $t->set_var('PREFERENCES_STRING',$space_strings['preferences']);
  119. $t->set_var('SHORT_DATE_STRING',$space_strings['short_date']);
  120. $t->set_var('LONG_DATE_STRING',$space_strings['long_date']);
  121. $t->set_var('NAME_STRING',$space_strings['name']);
  122. $t->set_var('CODE_STRING',$space_strings['code']);
  123. $t->set_var('STATUS_STRING',$space_strings['status']);
  124. $t->set_var('EMAIL_ADMINS_STRING',sprintf($space_strings['email_admins'], $general_strings['space_text']));
  125. $t->set_var('SUBMIT_STRING',$general_strings['submit']);
  126. $t->parse('CONTENTS','form', true);
  127. $t->parse('CONTENTS', 'footer', true);
  128. print_headers();
  129. $t->p('CONTENTS');
  130. $CONN->Close();
  131. exit;
  132. function check_form_input()
  133. {
  134. global $code,$CONN,$space_key,$name, $space_strings, $CONFIG;
  135. // Initialize the errors array
  136. $errors = array();
  137. //check to see if we have all the information we need
  138. if(!$name) {
  139. $errors['name'] = $space_strings['no_name'];
  140. }
  141. if(!$code) {
  142. $errors['code'] = $space_strings['no_code'];
  143. } else {
  144. //check that code is not used by another space
  145. $sql = "SELECT space_key FROM {$CONFIG['DB_PREFIX']}spaces WHERE code='$code'";
  146. $rs = $CONN->Execute($sql);
  147. if (!$rs->EOF) {
  148. while (!$rs->EOF) {
  149. $space_key2 = $rs->fields[0];
  150. $rs->MoveNext();
  151. }
  152. $rs->Close();
  153. if ($space_key!=$space_key2) {
  154. $errors['code'] = $space_strings['code_in_use'];
  155. }
  156. }
  157. }
  158. return $errors;
  159. } //end check_form_input
  160. ?>