class_list.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. // $Id: class_list.php 20441 2009-05-10 07:39:15Z ivantcholakov $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) Olivier Brouckaert
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * @package dokeos.admin
  23. ==============================================================================
  24. */
  25. $language_file = 'admin';
  26. $cidReset = true;
  27. require '../inc/global.inc.php';
  28. $this_section = SECTION_PLATFORM_ADMIN;
  29. api_protect_admin_script();
  30. /**
  31. * Gets the total number of classes.
  32. */
  33. function get_number_of_classes() {
  34. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  35. $sql = "SELECT COUNT(*) AS number_of_classes FROM $tbl_class";
  36. if (isset ($_GET['keyword'])) {
  37. $sql .= " WHERE (name LIKE '%".Database::escape_string(trim($_GET['keyword']))."%')";
  38. }
  39. $res = Database::query($sql);
  40. $obj = Database::fetch_object($res);
  41. return $obj->number_of_classes;
  42. }
  43. /**
  44. * Gets the information about some classes.
  45. * @param int $from
  46. * @param int $number_of_items
  47. * @param string $direction
  48. */
  49. function get_class_data($from, $number_of_items, $column, $direction) {
  50. $tbl_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
  51. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  52. $from = Database::escape_string($from);
  53. $number_of_items = Database::escape_string($number_of_items);
  54. $column = Database::escape_string($column);
  55. $direction = Database::escape_string($direction);
  56. $sql = "SELECT id AS col0, name AS col1, COUNT(user_id) AS col2, id AS col3
  57. FROM $tbl_class
  58. LEFT JOIN $tbl_class_user ON id=class_id ";
  59. if (isset ($_GET['keyword'])) {
  60. $sql .= " WHERE (name LIKE '%".Database::escape_string(trim($_GET['keyword']))."%')";
  61. }
  62. $sql .= " GROUP BY id,name ORDER BY col$column $direction LIMIT $from,$number_of_items";
  63. $res = Database::query($sql);
  64. $classes = array ();
  65. while ($class = Database::fetch_row($res)) {
  66. $classes[] = $class;
  67. }
  68. return $classes;
  69. }
  70. /**
  71. * Filter for sortable table to display edit icons for class
  72. */
  73. function modify_filter($class_id) {
  74. $class_id = Security::remove_XSS($class_id);
  75. $result = '<a href="class_information.php?id='.$class_id.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>';
  76. $result .= '<a href="class_edit.php?idclass='.$class_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  77. $result .= '<a href="class_list.php?action=delete_class&amp;class_id='.$class_id.'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."'".')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
  78. $result .= '<a href="subscribe_user2class.php?idclass='.$class_id.'">'.Display::return_icon('add_multiple_users.gif', get_lang('AddUsersToAClass')).'</a>';
  79. return $result;
  80. }
  81. require api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  82. require api_get_path(LIBRARY_PATH).'classmanager.lib.php';
  83. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  84. $tool_name = get_lang('ClassList');
  85. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  86. Display :: display_header($tool_name);
  87. //api_display_tool_title($tool_name);
  88. if (isset($_POST['action'])) {
  89. switch ($_POST['action']) {
  90. // Delete selected classes
  91. case 'delete_classes' :
  92. $classes = $_POST['class'];
  93. if (count($classes) > 0) {
  94. foreach ($classes as $index => $class_id) {
  95. ClassManager :: delete_class($class_id);
  96. }
  97. Display :: display_normal_message(get_lang('ClassesDeleted'));
  98. }
  99. break;
  100. }
  101. }
  102. if (isset($_GET['action'])) {
  103. switch ($_GET['action']) {
  104. case 'delete_class':
  105. ClassManager :: delete_class($_GET['class_id']);
  106. Display :: display_normal_message(get_lang('ClassDeleted'));
  107. break;
  108. case 'show_message':
  109. Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
  110. break;
  111. }
  112. }
  113. // Create a search-box
  114. $form = new FormValidator('search_simple', 'get', '', '', null, false);
  115. $renderer =& $form->defaultRenderer();
  116. $renderer->setElementTemplate('<span>{element}</span> ');
  117. $form->addElement('text', 'keyword', get_lang('keyword'));
  118. $form->addElement('submit', 'submit', get_lang('Search'));
  119. $form->display();
  120. // Create the sortable table with class information
  121. $table = new SortableTable('classes', 'get_number_of_classes', 'get_class_data', 1);
  122. $table->set_additional_parameters(array('keyword' => $_GET['keyword']));
  123. $table->set_header(0, '', false);
  124. $table->set_header(1, get_lang('ClassName'));
  125. $table->set_header(2, get_lang('NumberOfUsers'));
  126. $table->set_header(3, '', false);
  127. $table->set_column_filter(3, 'modify_filter');
  128. $table->set_form_actions(array ('delete_classes' => get_lang('DeleteSelectedClasses')), 'class');
  129. $table->display();
  130. // Displaying the footer.
  131. Display :: display_footer();