class_list.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. // $Id: class_list.php 9406 2006-10-10 11:28:36Z bmol $
  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. $langFile = 'admin';
  26. $cidReset = true;
  27. require ('../inc/global.inc.php');
  28. $this_section = SECTION_PLATFORM_ADMIN;
  29. /**
  30. * Gets the total number of classes
  31. */
  32. function get_number_of_classes()
  33. {
  34. $tbl_class = Database :: get_main_table(MAIN_CLASS_TABLE);
  35. $sql = "SELECT COUNT(*) AS number_of_classes FROM $tbl_class";
  36. if (isset ($_GET['keyword']))
  37. {
  38. $sql .= " WHERE (name LIKE '%".mysql_real_escape_string(trim($_GET['keyword']))."%')";
  39. }
  40. $res = api_sql_query($sql, __FILE__, __LINE__);
  41. $obj = mysql_fetch_object($res);
  42. return $obj->number_of_classes;
  43. }
  44. /**
  45. * Gets the information about some classes
  46. * @param int $from
  47. * @param int $number_of_items
  48. * @param string $direction
  49. */
  50. function get_class_data($from, $number_of_items, $column, $direction)
  51. {
  52. $tbl_class_user = Database :: get_main_table(MAIN_CLASS_USER_TABLE);
  53. $tbl_class = Database :: get_main_table(MAIN_CLASS_TABLE);
  54. $sql = "SELECT id AS col0,
  55. name AS col1,
  56. COUNT(user_id) AS col2,
  57. id AS col3
  58. FROM $tbl_class
  59. LEFT JOIN $tbl_class_user ON id=class_id ";
  60. if (isset ($_GET['keyword']))
  61. {
  62. $sql .= " WHERE (name LIKE '%".mysql_real_escape_string(trim($_GET['keyword']))."%')";
  63. }
  64. $sql .= "GROUP BY id,name ORDER BY col$column $direction LIMIT $from,$number_of_items";
  65. $res = api_sql_query($sql, __FILE__, __LINE__);
  66. $classes = array ();
  67. while ($class = mysql_fetch_row($res))
  68. {
  69. $classes[] = $class;
  70. }
  71. return $classes;
  72. }
  73. /**
  74. * Filter for sortable table to display edit icons for class
  75. */
  76. function modify_filter($class_id)
  77. {
  78. $result = '<a href="class_information.php?id='.$class_id.'"><img src="../img/info_small.gif" border="0" title="'.get_lang('Info').'" alt="'.get_lang('Info').'"/></a>';
  79. $result .= '<a href="class_edit.php?idclass='.$class_id.'"><img src="../img/edit.gif" border="0" title="'.get_lang('Edit').'" alt="'.get_lang('Edit').'"/></a>';
  80. $result .= '<a href="class_list.php?action=delete_class&amp;class_id='.$class_id.'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang("ConfirmYourChoice")))."'".')) return false;"><img src="../img/delete.gif" border="0" title="'.get_lang('Delete').'" alt="'.get_lang('Delete').'"/></a>';
  81. $result .= '<a href="subscribe_user2class.php?idclass='.$class_id.'"><img src="../img/group_small.gif" border="0" alt="'.get_lang('AddUsersToAClass').'" title="'.get_lang('AddUsersToAClass').'"/></a>';
  82. return $result;
  83. }
  84. api_protect_admin_script();
  85. require (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  86. require (api_get_path(LIBRARY_PATH).'classmanager.lib.php');
  87. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  88. $tool_name = get_lang('ClassList');
  89. //$interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('PlatformAdmin'));
  90. Display :: display_header($tool_name);
  91. //api_display_tool_title($tool_name);
  92. if (isset ($_POST['action']))
  93. {
  94. switch ($_POST['action'])
  95. {
  96. // Delete selected classes
  97. case 'delete_classes' :
  98. $classes = $_POST['class'];
  99. if (count($classes) > 0)
  100. {
  101. foreach ($classes as $index => $class_id)
  102. {
  103. ClassManager :: delete_class($class_id);
  104. }
  105. Display :: display_normal_message(get_lang('ClassesDeleted'));
  106. }
  107. break;
  108. }
  109. }
  110. if (isset ($_GET['action']))
  111. {
  112. switch ($_GET['action'])
  113. {
  114. case 'delete_class' :
  115. ClassManager :: delete_class($_GET['class_id']);
  116. Display :: display_normal_message(get_lang('ClassDeleted'));
  117. }
  118. }
  119. // Create a search-box
  120. $form = new FormValidator('search_simple','get','','',null,false);
  121. $renderer =& $form->defaultRenderer();
  122. $renderer->setElementTemplate('<span>{element}</span> ');
  123. $form->addElement('text','keyword',get_lang('keyword'));
  124. $form->addElement('submit','submit',get_lang('Search'));
  125. $form->display();
  126. // Create the sortable table with class information
  127. $table = new SortableTable('classes', 'get_number_of_classes', 'get_class_data', 1);
  128. $table->set_additional_parameters(array('keyword'=>$_GET['keyword']));
  129. $table->set_header(0, '', false);
  130. $table->set_header(1, get_lang('ClassName'));
  131. $table->set_header(2, get_lang('NumberOfUsers'));
  132. $table->set_header(3, '', false);
  133. $table->set_column_filter(3, 'modify_filter');
  134. $table->set_form_actions(array ('delete_classes' => get_lang('DeleteSelectedClasses')),'class');
  135. $table->display();
  136. /*
  137. ==============================================================================
  138. FOOTER
  139. ==============================================================================
  140. */
  141. Display :: display_footer();
  142. ?>