class_list.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. /**
  7. * Code
  8. */
  9. $language_file = 'admin';
  10. $cidReset = true;
  11. require '../inc/global.inc.php';
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. api_protect_admin_script();
  14. /**
  15. * Gets the total number of classes.
  16. */
  17. function get_number_of_classes() {
  18. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  19. $sql = "SELECT COUNT(*) AS number_of_classes FROM $tbl_class";
  20. if (isset ($_GET['keyword'])) {
  21. $sql .= " WHERE (name LIKE '%".Database::escape_string(trim($_GET['keyword']))."%')";
  22. }
  23. $res = Database::query($sql);
  24. $obj = Database::fetch_object($res);
  25. return $obj->number_of_classes;
  26. }
  27. /**
  28. * Gets the information about some classes.
  29. * @param int $from
  30. * @param int $number_of_items
  31. * @param string $direction
  32. */
  33. function get_class_data($from, $number_of_items, $column, $direction = 'ASC') {
  34. $tbl_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
  35. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  36. $from = intval($from);
  37. $number_of_items = intval($number_of_items);
  38. $column = intval($column);
  39. $direction = ($direction == 'ASC'?'ASC':'DESC');
  40. $sql = "SELECT id AS col0, name AS col1, COUNT(user_id) AS col2, id AS col3
  41. FROM $tbl_class
  42. LEFT JOIN $tbl_class_user ON id=class_id ";
  43. if (isset ($_GET['keyword'])) {
  44. $sql .= " WHERE (name LIKE '%".Database::escape_string(trim($_GET['keyword']))."%')";
  45. }
  46. $sql .= " GROUP BY id,name ORDER BY col$column $direction LIMIT $from,$number_of_items";
  47. $res = Database::query($sql);
  48. $classes = array ();
  49. while ($class = Database::fetch_row($res)) {
  50. $classes[] = $class;
  51. }
  52. return $classes;
  53. }
  54. /**
  55. * Filter for sortable table to display edit icons for class
  56. */
  57. function modify_filter($class_id) {
  58. $class_id = Security::remove_XSS($class_id);
  59. $result = '<a href="class_information.php?id='.$class_id.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>';
  60. $result .= ' <a href="class_edit.php?idclass='.$class_id.'">'.Display::return_icon('edit.png', get_lang('Edit')).'</a>';
  61. $result .= ' <a href="subscribe_user2class.php?idclass='.$class_id.'">'.Display::return_icon('add_multiple_users.gif', get_lang('AddUsersToAClass')).'</a>';
  62. $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.png', get_lang('Delete')).'</a>';
  63. return $result;
  64. }
  65. require api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  66. require api_get_path(LIBRARY_PATH).'classmanager.lib.php';
  67. $tool_name = get_lang('ClassList');
  68. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  69. if (isset($_POST['action'])) {
  70. switch ($_POST['action']) {
  71. // Delete selected classes
  72. case 'delete_classes' :
  73. $classes = $_POST['class'];
  74. if (count($classes) > 0) {
  75. foreach ($classes as $index => $class_id) {
  76. ClassManager :: delete_class($class_id);
  77. }
  78. $message = Display :: return_message(get_lang('ClassesDeleted'));
  79. }
  80. break;
  81. }
  82. }
  83. if (isset($_GET['action'])) {
  84. switch ($_GET['action']) {
  85. case 'delete_class':
  86. ClassManager :: delete_class($_GET['class_id']);
  87. $message = Display :: return_message(get_lang('ClassDeleted'));
  88. break;
  89. case 'show_message':
  90. $message = Display :: return_message(Security::remove_XSS(stripslashes($_GET['message'])));
  91. break;
  92. }
  93. }
  94. // Create a search-box
  95. $form = new FormValidator('search_simple', 'get', '', '', null, false);
  96. $renderer =& $form->defaultRenderer();
  97. $renderer->setElementTemplate('<span>{element}</span> ');
  98. $form->addElement('text', 'keyword', get_lang('keyword'));
  99. $form->addElement('button', 'submit', get_lang('Search'));
  100. $content .= $form->return_form();
  101. // Create the sortable table with class information
  102. $table = new SortableTable('classes', 'get_number_of_classes', 'get_class_data', 1);
  103. $table->set_additional_parameters(array('keyword' => $_GET['keyword']));
  104. $table->set_header(0, '', false);
  105. $table->set_header(1, get_lang('ClassName'));
  106. $table->set_header(2, get_lang('NumberOfUsers'));
  107. $table->set_header(3, '', false);
  108. $table->set_column_filter(3, 'modify_filter');
  109. $table->set_form_actions(array ('delete_classes' => get_lang('DeleteSelectedClasses')), 'class');
  110. $content .= $table->return_table();
  111. $actions .= Display::url(Display::return_icon('add.png', get_lang('Add'), array(), ICON_SIZE_MEDIUM), 'class_add.php');
  112. $actions .= Display::url(Display::return_icon('import_csv.png', get_lang('AddUsersToAClass'), array(), ICON_SIZE_MEDIUM), 'class_user_import.php');
  113. $actions .= Display::url(Display::return_icon('import_csv.png', get_lang('ImportClassListCSV'), array(), ICON_SIZE_MEDIUM), 'class_import.php');
  114. $tpl = new Template($tool_name);
  115. $tpl->assign('content', $content);
  116. $tpl->assign('actions', $actions);
  117. $tpl->assign('message', $message);
  118. $tpl->display_one_col_template();