session.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos SPRL
  6. Copyright (c) various contributors
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. /*
  19. * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  20. * Somes fixes by Julio Montoya
  21. */
  22. ob_start();
  23. $nameTools= 'Sessions';
  24. // name of the language file that needs to be included
  25. $language_file = array ('registration', 'index', 'trad4all', 'tracking');
  26. $cidReset = true;
  27. require '../inc/global.inc.php';
  28. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  29. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  30. api_block_anonymous_users();
  31. $this_section = "session_my_space";
  32. api_block_anonymous_users();
  33. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  34. Display :: display_header($nameTools);
  35. // Database Table Definitions
  36. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  37. $tbl_sessions = Database :: get_main_table(TABLE_MAIN_SESSION);
  38. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  39. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  40. $export_csv = false;
  41. if (isset($_GET['export']) && $_GET['export'] == 'csv') {
  42. $export_csv = true;
  43. }
  44. /*
  45. ===============================================================================
  46. FUNCTION
  47. ===============================================================================
  48. */
  49. function count_sessions_coached() {
  50. global $nb_sessions;
  51. return $nb_sessions;
  52. }
  53. function sort_sessions($a, $b) {
  54. global $tracking_column;
  55. if ($a[$tracking_column] > $b[$tracking_column]) {
  56. return 1;
  57. } else {
  58. return -1;
  59. }
  60. }
  61. function rsort_sessions($a, $b) {
  62. global $tracking_column;
  63. if ($b[$tracking_column] > $a[$tracking_column]) {
  64. return 1;
  65. } else {
  66. return -1;
  67. }
  68. }
  69. /*
  70. ===============================================================================
  71. MAIN CODE
  72. ===============================================================================
  73. */
  74. if (isset($_GET['id_coach']) && $_GET['id_coach'] != '') {
  75. $id_coach = $_GET['id_coach'];
  76. } else {
  77. $id_coach = $_user['user_id'];
  78. }
  79. $a_sessions = Tracking :: get_sessions_coached_by_user($id_coach);
  80. $nb_sessions = count($a_sessions);
  81. if ($export_csv) {
  82. $csv_content = array();
  83. }
  84. if ($nb_sessions > 0) {
  85. echo '<div align="right">
  86. <a href="javascript: void(0);" onclick="javascript: window.print();"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
  87. <a href="'.api_get_self().'?export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
  88. </div>';
  89. $table = new SortableTable('tracking', 'count_sessions_coached');
  90. $table -> set_header(0, get_lang('Title'));
  91. $table -> set_header(1, get_lang('Status'));
  92. $table -> set_header(2, get_lang('Date'));
  93. $table -> set_header(3, get_lang('Details'), false);
  94. $all_data = array();
  95. foreach ($a_sessions as $session) {
  96. $row = array();
  97. $row[] = $session['name'];
  98. $row[] = $session['status'];
  99. if ($session['date_start'] != '0000-00-00' && $session['date_end'] != '0000-00-00') {
  100. $row[] = get_lang('From').' '.format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($session['date_start'])).' '.get_lang('To').' '.format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($session['date_end']));
  101. } else {
  102. $row[] = ' - ';
  103. }
  104. if ($export_csv) {
  105. $csv_content[] = $row;
  106. }
  107. if (isset($_GET['id_coach']) && $_GET['id_coach'] != '') {
  108. $row[] = '<a href="student.php?id_session='.$session['id'].'&id_coach='.$_GET['id_coach'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  109. } else {
  110. $row[] = '<a href="course.php?id_session='.$session['id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  111. }
  112. $all_data[] = $row;
  113. }
  114. if (!isset($tracking_column)) {
  115. $tracking_column = 0;
  116. }
  117. if ($_GET['tracking_direction'] == 'DESC') {
  118. usort($all_data, 'rsort_sessions');
  119. } else {
  120. usort($all_data, 'sort_sessions');
  121. }
  122. if ($export_csv) {
  123. usort($csv_content, 'sort_sessions');
  124. }
  125. foreach ($all_data as $row) {
  126. $table -> addRow($row);
  127. }
  128. $table -> setColAttributes(3, array('align' => 'center'));
  129. $table -> display();
  130. if ($export_csv) {
  131. ob_end_clean();
  132. Export :: export_table_csv($csv_content, 'reporting_student_list');
  133. }
  134. } else {
  135. get_lang('NoSession');
  136. }
  137. /*
  138. ==============================================================================
  139. FOOTER
  140. ==============================================================================
  141. */
  142. Display::display_footer();