course_information.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script gives information about a course
  5. * @author Bart Mollet
  6. * @package chamilo.admin
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. api_protect_admin_script();
  12. if (!isset($_GET['code'])) {
  13. api_not_allowed(true);
  14. }
  15. $courseInfo = api_get_course_info($_GET['code']);
  16. if (empty($courseInfo)) {
  17. api_not_allowed(true);
  18. }
  19. $sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
  20. /**
  21. * @param array $course
  22. * @param int $session_id
  23. * @return array
  24. */
  25. function get_course_usage($course, $session_id = 0)
  26. {
  27. $courseId = $course['real_id'];
  28. $tables = [
  29. [
  30. Database::get_course_table(TABLE_LP_MAIN),
  31. get_lang(ucfirst(TOOL_LEARNPATH)),
  32. ],
  33. [
  34. Database::get_course_table(TABLE_FORUM),
  35. get_lang('Forums'),
  36. ],
  37. [
  38. Database::get_course_table(TABLE_QUIZ_TEST),
  39. get_lang(ucfirst(TOOL_QUIZ)),
  40. ],
  41. [
  42. Database::get_course_table(TABLE_DOCUMENT),
  43. get_lang(ucfirst(TOOL_DOCUMENT)),
  44. ],
  45. [
  46. Database::get_course_table(TABLE_GROUP),
  47. get_lang(ucfirst(TOOL_GROUP)),
  48. ],
  49. [
  50. Database::get_course_table(TABLE_AGENDA),
  51. get_lang('Calendar'),
  52. ],
  53. [
  54. Database::get_course_table(TABLE_LINK),
  55. get_lang(ucfirst(TOOL_LINK)),
  56. ],
  57. [
  58. Database::get_course_table(TABLE_ANNOUNCEMENT),
  59. get_lang(ucfirst(TOOL_ANNOUNCEMENT)),
  60. ]
  61. ];
  62. $usage = [];
  63. $conditionSession = '';
  64. if ($session_id !== '') {
  65. $session_id = intval($session_id);
  66. $conditionSession = " AND session_id = '$session_id' ";
  67. }
  68. foreach ($tables as $tableInfo) {
  69. $table = $tableInfo[0];
  70. $title = $tableInfo[1];
  71. $sql = "SELECT COUNT(*) count FROM $table
  72. WHERE c_id = '$courseId' $conditionSession ";
  73. $rs = Database::query($sql);
  74. $row = Database::fetch_array($rs);
  75. $usage[] = array(
  76. $title,
  77. $row['count']
  78. );
  79. }
  80. return $usage;
  81. }
  82. $interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  83. $interbreadcrumb[] = array("url" => 'course_list.php', "name" => get_lang('Courses'));
  84. $courseId = $courseInfo['real_id'];
  85. $tool_name = $courseInfo['title'].' ('.$courseInfo['visual_code'].')';
  86. Display::display_header($tool_name);
  87. ?>
  88. <div class="actions">
  89. <a href="<?php echo $courseInfo['course_public_url']; ?>">
  90. <?php Display::display_icon('home.png', get_lang('CourseHomepage'), array(), ICON_SIZE_MEDIUM); ?>
  91. </a>
  92. </div>
  93. <?php
  94. echo Display::page_header(get_lang('CourseUsage'));
  95. $table = new SortableTableFromArray(
  96. get_course_usage($courseInfo, $sessionId),
  97. 0,
  98. 20,
  99. 'usage_table'
  100. );
  101. $table->set_additional_parameters(array('code' => $courseInfo['code']));
  102. $table->set_other_tables(array('user_table', 'class_table'));
  103. $table->set_header(0, get_lang('Tool'), true);
  104. $table->set_header(1, get_lang('NumberOfItems'), true);
  105. $table->display();
  106. /**
  107. * Show all users subscribed in this course
  108. */
  109. echo Display::page_header(get_lang('Users'));
  110. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  111. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  112. $sql = "SELECT *, cu.status as course_status
  113. FROM $table_course_user cu, $table_user u";
  114. if (api_is_multiple_url_enabled()) {
  115. $sql .= " INNER JOIN ".Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER)." url_rel_user
  116. ON
  117. u.user_id = url_rel_user.user_id AND
  118. url_rel_user.access_url_id = ".api_get_current_access_url_id();
  119. }
  120. $sql .= " WHERE
  121. cu.user_id = u.user_id AND
  122. cu.c_id = '".$courseId."' AND
  123. cu.relation_type <> ".COURSE_RELATION_TYPE_RRHH;
  124. $res = Database::query($sql);
  125. $is_western_name_order = api_is_western_name_order();
  126. if (Database::num_rows($res) > 0) {
  127. $users = array();
  128. while ($obj = Database::fetch_object($res)) {
  129. $user = array();
  130. $user[] = $obj->official_code;
  131. if ($is_western_name_order) {
  132. $user[] = $obj->firstname;
  133. $user[] = $obj->lastname;
  134. } else {
  135. $user[] = $obj->lastname;
  136. $user[] = $obj->firstname;
  137. }
  138. $user[] = Display:: encrypted_mailto_link($obj->email, $obj->email);
  139. $user[] = $obj->course_status == 5 ? get_lang('Student') : get_lang('Teacher');
  140. $user[] = '<a href="user_information.php?user_id='.$obj->user_id.'">'.
  141. Display::return_icon('synthese_view.gif', get_lang('UserInfo')).'</a>';
  142. $users[] = $user;
  143. }
  144. $table = new SortableTableFromArray($users, 0, 20, 'user_table');
  145. $table->set_additional_parameters(array('code' => $courseInfo['code']));
  146. $table->set_other_tables(array('usage_table', 'class_table'));
  147. $table->set_header(0, get_lang('OfficialCode'), true);
  148. if ($is_western_name_order) {
  149. $table->set_header(1, get_lang('FirstName'), true);
  150. $table->set_header(2, get_lang('LastName'), true);
  151. } else {
  152. $table->set_header(1, get_lang('LastName'), true);
  153. $table->set_header(2, get_lang('FirstName'), true);
  154. }
  155. $table->set_header(3, get_lang('Email'), true);
  156. $table->set_header(4, get_lang('Status'), true);
  157. $table->set_header(5, '', false);
  158. $table->display();
  159. } else {
  160. echo get_lang('NoUsersInCourse');
  161. }
  162. $sessionList = SessionManager::get_session_by_course($courseInfo['real_id']);
  163. $url = api_get_path(WEB_CODE_PATH);
  164. if (!empty($sessionList)) {
  165. foreach ($sessionList as &$session) {
  166. $session[0] = Display::url($session[0], $url.'session/resume_session.php?id_session='.$session['id']);
  167. unset($session[1]);
  168. }
  169. echo Display::page_header(get_lang('Sessions'));
  170. $table = new SortableTableFromArray($sessionList, 0, 20, 'user_table');
  171. $table->display();
  172. }
  173. Display::display_footer();