class_list.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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) {
  34. $tbl_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
  35. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  36. $from = Database::escape_string($from);
  37. $number_of_items = Database::escape_string($number_of_items);
  38. $column = Database::escape_string($column);
  39. $direction = Database::escape_string($direction);
  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(get_lang("ConfirmYourChoice"))."'".')) return false;">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  63. return $result;
  64. }
  65. $tool_name = get_lang('ClassList');
  66. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  67. if (isset($_POST['action'])) {
  68. switch ($_POST['action']) {
  69. // Delete selected classes
  70. case 'delete_classes' :
  71. $classes = $_POST['class'];
  72. if (count($classes) > 0) {
  73. foreach ($classes as $index => $class_id) {
  74. ClassManager :: delete_class($class_id);
  75. }
  76. $message = Display :: return_message(get_lang('ClassesDeleted'));
  77. }
  78. break;
  79. }
  80. }
  81. if (isset($_GET['action'])) {
  82. switch ($_GET['action']) {
  83. case 'delete_class':
  84. ClassManager :: delete_class($_GET['class_id']);
  85. $message = Display :: return_message(get_lang('ClassDeleted'));
  86. break;
  87. case 'show_message':
  88. $message = Display :: return_message(Security::remove_XSS(stripslashes($_GET['message'])));
  89. break;
  90. }
  91. }
  92. // Create a search-box
  93. $form = new FormValidator('search_simple', 'get', '', '', null, false);
  94. $renderer =& $form->defaultRenderer();
  95. $renderer->setElementTemplate('<span>{element}</span> ');
  96. $form->addElement('text', 'keyword', get_lang('keyword'));
  97. $form->addElement('button', 'submit', get_lang('Search'));
  98. $content .= $form->return_form();
  99. // Create the sortable table with class information
  100. $table = new SortableTable('classes', 'get_number_of_classes', 'get_class_data', 1);
  101. $table->set_additional_parameters(array('keyword' => $_GET['keyword']));
  102. $table->set_header(0, '', false);
  103. $table->set_header(1, get_lang('ClassName'));
  104. $table->set_header(2, get_lang('NumberOfUsers'));
  105. $table->set_header(3, '', false);
  106. $table->set_column_filter(3, 'modify_filter');
  107. $table->set_form_actions(array ('delete_classes' => get_lang('DeleteSelectedClasses')), 'class');
  108. $content .= $table->return_table();
  109. $actions .= Display::url(Display::return_icon('add.png', get_lang('Add'), array(), ICON_SIZE_MEDIUM), 'class_add.php');
  110. $actions .= Display::url(Display::return_icon('import_csv.png', get_lang('AddUsersToAClass'), array(), ICON_SIZE_MEDIUM), 'class_user_import.php');
  111. $actions .= Display::url(Display::return_icon('import_csv.png', get_lang('ImportClassListCSV'), array(), ICON_SIZE_MEDIUM), 'class_import.php');
  112. $app['title'] = $tool_name;
  113. $tpl = $app['template'];
  114. $tpl->assign('content', $content);
  115. $tpl->assign('actions', $actions);
  116. $tpl->assign('message', $message);
  117. $tpl->display_one_col_template();