/mods/_core/courses/admin/default_mods.php

https://github.com/harriswong/ATutor · PHP · 202 lines · 150 code · 35 blank · 17 comment · 46 complexity · c1b13675de54aa862c290f134156e297 MD5 · raw file

  1. <?php
  2. /****************************************************************/
  3. /* ATutor */
  4. /****************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* Inclusive Design Institute */
  7. /* http://atutor.ca */
  8. /* */
  9. /* This program is free software. You can redistribute it and/or*/
  10. /* modify it under the terms of the GNU General Public License */
  11. /* as published by the Free Software Foundation. */
  12. /****************************************************************/
  13. // $Id$
  14. define('AT_INCLUDE_PATH', '../../../../include/');
  15. require (AT_INCLUDE_PATH.'vitals.inc.php');
  16. admin_authenticate(AT_ADMIN_PRIV_ADMIN);
  17. if (isset($_POST['cancel'])) {
  18. $msg->addFeedback('CANCELLED');
  19. header('Location: courses.php');
  20. exit;
  21. }
  22. if (isset($_POST['up'])) {
  23. $up = key($_POST['up']);
  24. $_new_modules = array();
  25. if (isset($_POST['main'])) {
  26. foreach ($_POST['main'] as $m) {
  27. if ($m == $up) {
  28. $last_m = array_pop($_new_modules);
  29. $_new_modules[] = $m;
  30. $_new_modules[] = $last_m;
  31. } else {
  32. $_new_modules[] = $m;
  33. }
  34. }
  35. $_POST['main'] = $_new_modules;
  36. }
  37. if (isset($_POST['home'])) {
  38. $_new_modules = array();
  39. foreach ($_POST['home'] as $m) {
  40. if ($m == $up) {
  41. $last_m = array_pop($_new_modules);
  42. $_new_modules[] = $m;
  43. $_new_modules[] = $last_m;
  44. } else {
  45. $_new_modules[] = $m;
  46. }
  47. }
  48. $_POST['home'] = $_new_modules;
  49. }
  50. $_POST['submit'] = TRUE;
  51. } else if (isset($_POST['down'])) {
  52. $_new_modules = array();
  53. $down = key($_POST['down']);
  54. if (isset($_POST['main'])) {
  55. foreach ($_POST['main'] as $m) {
  56. if ($m == $down) {
  57. $found = TRUE;
  58. continue;
  59. }
  60. $_new_modules[] = $m;
  61. if ($found) {
  62. $_new_modules[] = $down;
  63. $found = FALSE;
  64. }
  65. }
  66. $_POST['main'] = $_new_modules;
  67. }
  68. if (isset($_POST['home'])) {
  69. $_new_modules = array();
  70. foreach ($_POST['home'] as $m) {
  71. if ($m == $down) {
  72. $found = TRUE;
  73. continue;
  74. }
  75. $_new_modules[] = $m;
  76. if ($found) {
  77. $_new_modules[] = $down;
  78. $found = FALSE;
  79. }
  80. }
  81. $_POST['home'] = $_new_modules;
  82. }
  83. $_POST['submit'] = TRUE;
  84. }
  85. if (isset($_POST['submit'])) {
  86. if (isset($_POST['main'])) {
  87. $_POST['main'] = array_unique($_POST['main']);
  88. $_POST['main'] = array_filter($_POST['main']); // remove empties
  89. $main_defaults = implode('|', $_POST['main']);
  90. } else {
  91. $main_defaults = '';
  92. }
  93. if (isset($_POST['home'])) {
  94. $_POST['home'] = array_unique($_POST['home']);
  95. $_POST['home'] = array_filter($_POST['home']); // remove empties
  96. $home_defaults = implode('|', $_POST['home']);
  97. } else {
  98. $home_defaults = '';
  99. }
  100. if (!($_config_defaults['main_defaults'] == $main_defaults) && (strlen($main_defaults) < 256)) {
  101. $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES('main_defaults', '$main_defaults')";
  102. $result = mysql_query($sql, $db);
  103. $sql = "DELETE FROM ".TABLE_PREFIX."config WHERE name='main_defaults_2'";
  104. } else if (!($_config_defaults['main_defaults'] == $main_defaults) && (strlen($main_defaults) > 255)) {
  105. // we don't have to worry about chopping in the middle since they'll be combined anyway
  106. $main_defaults_1 = substr($main_defaults, 0, 255);
  107. $main_defaults_2 = substr($main_defaults, 255);
  108. $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES('main_defaults', '$main_defaults_1')";
  109. $result = mysql_query($sql, $db);
  110. $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES('main_defaults_2', '$main_defaults_2')";
  111. } else if ($_config_defaults['main_defaults'] == $main_defaults) {
  112. $sql = "DELETE FROM ".TABLE_PREFIX."config WHERE name='main_defaults' OR name='name_defaults_2'";
  113. }
  114. $result = mysql_query($sql, $db);
  115. if (!($_config_defaults['home_defaults'] == $home_defaults) && (strlen($home_defaults) < 256)) {
  116. $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES('home_defaults', '$home_defaults')";
  117. $result = mysql_query($sql, $db);
  118. $sql = "DELETE FROM ".TABLE_PREFIX."config WHERE name='home_defaults_2'";
  119. } else if (!($_config_defaults['home_defaults'] == $home_defaults) && (strlen($home_defaults) > 255)) {
  120. // we don't have to worry about chopping in the middle since they'll be combined anyway
  121. $home_defaults_1 = substr($home_defaults, 0, 255);
  122. $home_defaults_2 = substr($home_defaults, 255);
  123. $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES('home_defaults', '$home_defaults_1')";
  124. $result = mysql_query($sql, $db);
  125. $sql = "REPLACE INTO ".TABLE_PREFIX."config VALUES('home_defaults_2', '$home_defaults_2')";
  126. } else if ($_config_defaults['home_defaults'] == $home_defaults) {
  127. $sql = "DELETE FROM ".TABLE_PREFIX."config WHERE name='home_defaults' OR name='home_defaults_2'";
  128. }
  129. $result = mysql_query($sql, $db);
  130. $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
  131. header('Location: '.$_SERVER['PHP_SELF']);
  132. exit;
  133. }
  134. require(AT_INCLUDE_PATH.'header.inc.php');
  135. $main_defaults = explode('|', $_config['main_defaults']);
  136. $home_defaults = explode('|', $_config['home_defaults']);
  137. $main_defaults = array_filter($main_defaults); // remove empties
  138. $home_defaults = array_filter($home_defaults); // remove empties
  139. ?>
  140. <?php
  141. $module_list = $moduleFactory->getModules(AT_MODULE_STATUS_ENABLED);
  142. $keys = array_keys($module_list);
  143. foreach ($keys as $dir_name) {
  144. $module =& $module_list[$dir_name];
  145. if ($module->getStudentTools()) {
  146. $student_tools[] = $module->getStudentTools();
  147. }
  148. }
  149. $count = 0;
  150. //main mods
  151. $_current_modules = $main_defaults;
  152. $num_main = count($_current_modules);
  153. //main and home merged
  154. $_current_modules = array_merge($_current_modules, array_diff($home_defaults, $main_defaults));
  155. $num_modules = count($_current_modules);
  156. //all other mods
  157. $_current_modules = array_merge($_current_modules, array_diff($student_tools, $_current_modules));
  158. ?>
  159. <?php
  160. $savant->assign('current_modules', $_current_modules);
  161. $savant->assign('home_defaults', $home_defaults);
  162. $savant->assign('main_defaults', $main_defaults);
  163. $savant->assign('num_modules', $num_modules);
  164. $savant->assign('num_main', $num_main);
  165. $savant->assign('pages', $_pages);
  166. $savant->display('admin/courses/default_mods.tmpl.php');
  167. require(AT_INCLUDE_PATH.'footer.inc.php'); ?>