course_information.php 6.0 KB

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