session.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /*
  4. * Sessions reporting
  5. * @package chamilo.reporting
  6. */
  7. ob_start();
  8. $nameTools= 'Sessions';
  9. // name of the language file that needs to be included
  10. $language_file = array ('registration', 'index', 'trad4all', 'tracking', 'admin');
  11. $cidReset = true;
  12. require_once '../inc/global.inc.php';
  13. api_block_anonymous_users();
  14. $this_section = SECTION_TRACKING;
  15. api_block_anonymous_users();
  16. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  17. Display :: display_header($nameTools);
  18. $export_csv = false;
  19. if (isset($_GET['export']) && $_GET['export'] == 'csv') {
  20. $export_csv = true;
  21. }
  22. /*
  23. FUNCTION
  24. */
  25. function count_sessions_coached() {
  26. global $nb_sessions;
  27. return $nb_sessions;
  28. }
  29. function sort_sessions($a, $b) {
  30. global $tracking_column;
  31. if ($a[$tracking_column] > $b[$tracking_column]) {
  32. return 1;
  33. } else {
  34. return -1;
  35. }
  36. }
  37. function rsort_sessions($a, $b) {
  38. global $tracking_column;
  39. if ($b[$tracking_column] > $a[$tracking_column]) {
  40. return 1;
  41. } else {
  42. return -1;
  43. }
  44. }
  45. /* MAIN CODE */
  46. if (isset($_GET['id_coach']) && $_GET['id_coach'] != '') {
  47. $id_coach = intval($_GET['id_coach']);
  48. } else {
  49. $id_coach = api_get_user_id();
  50. }
  51. if (api_is_drh() || api_is_session_admin() || api_is_platform_admin()) {
  52. $a_sessions = SessionManager :: get_sessions_coached_by_user(api_get_user_id());
  53. $a_sessions_drh = SessionManager::get_sessions_followed_by_drh(api_get_user_id());
  54. if (!empty($a_sessions_drh)) {
  55. $a_sessions = array_merge($a_sessions, $a_sessions_drh);
  56. }
  57. if (!api_is_session_admin()) {
  58. $menu_items[] = Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );
  59. $menu_items[] = Display::url(Display::return_icon('user.png', get_lang('Students'), array(), 32), "index.php?view=drh_students&amp;display=yourstudents");
  60. $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), 32), 'teachers.php');
  61. $menu_items[] = Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), 32), 'course.php');
  62. $menu_items[] = Display::return_icon('session_na.png', get_lang('Sessions'), array(), 32);
  63. }
  64. echo '<div class="actions">';
  65. $nb_menu_items = count($menu_items);
  66. if ($nb_menu_items > 1) {
  67. foreach ($menu_items as $key => $item) {
  68. echo $item;
  69. }
  70. }
  71. if (count($a_sessions) > 0) {
  72. echo '<span style="float:right">';
  73. echo Display::url(Display::return_icon('printer.png', get_lang('Print'), array(), 32), 'javascript: void(0);', array('onclick'=>'javascript: window.print();'));
  74. echo Display::url(Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), array(), 32), api_get_self().'?export=csv');
  75. echo '</span>';
  76. }
  77. echo '</div>';
  78. echo Display::page_header(get_lang('YourSessionsList'));
  79. } else {
  80. /*if (api_is_platform_admin()) {
  81. $a_sessions = SessionManager::get_sessions_list();
  82. } else {*/
  83. $a_sessions = SessionManager :: get_sessions_coached_by_user($id_coach);
  84. //}
  85. }
  86. $nb_sessions = count($a_sessions);
  87. if ($export_csv) {
  88. $csv_content = array();
  89. }
  90. if ($nb_sessions > 0) {
  91. $table = new SortableTable('tracking', 'count_sessions_coached');
  92. $table->set_header(0, get_lang('Title'));
  93. $table->set_header(1, get_lang('Date'));
  94. $table->set_header(2, get_lang('NbCoursesPerSession'));
  95. $table->set_header(3, get_lang('Details'), false);
  96. $all_data = array();
  97. foreach ($a_sessions as $session) {
  98. $row = array();
  99. $row[] = $session['name'];
  100. $row[] = SessionManager::parse_session_dates($session);
  101. $row[] = count(Tracking::get_courses_list_from_session($session['id']));
  102. if ($export_csv) {
  103. $csv_content[] = $row;
  104. }
  105. if (isset($_GET['id_coach']) && $_GET['id_coach'] != '') {
  106. $row[] = '<a href="student.php?id_session='.$session['id'].'&id_coach='.intval($_GET['id_coach']).'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  107. } else {
  108. $row[] = '<a href="course.php?id_session='.$session['id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  109. }
  110. $all_data[] = $row;
  111. }
  112. if (!isset($tracking_column)) {
  113. $tracking_column = 0;
  114. }
  115. if ($_GET['tracking_direction'] == 'DESC') {
  116. usort($all_data, 'rsort_sessions');
  117. } else {
  118. usort($all_data, 'sort_sessions');
  119. }
  120. if ($export_csv) {
  121. usort($csv_content, 'sort_sessions');
  122. }
  123. foreach ($all_data as $row) {
  124. $table -> addRow($row);
  125. }
  126. //$table -> setColAttributes(2, array('align' => 'center'));
  127. $table -> display();
  128. if ($export_csv) {
  129. ob_end_clean();
  130. Export :: export_table_csv($csv_content, 'reporting_student_list');
  131. exit;
  132. }
  133. } else {
  134. echo get_lang('NoSession');
  135. }
  136. Display::display_footer();