class_list.php 5.0 KB

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