session.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /*
  4. * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  5. * Somes fixes by Julio Montoya
  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');
  11. $cidReset = true;
  12. require '../inc/global.inc.php';
  13. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  14. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  15. api_block_anonymous_users();
  16. $this_section = "session_my_space";
  17. api_block_anonymous_users();
  18. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  19. Display :: display_header($nameTools);
  20. // Database Table Definitions
  21. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  22. $tbl_sessions = Database :: get_main_table(TABLE_MAIN_SESSION);
  23. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  24. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  25. $export_csv = false;
  26. if (isset($_GET['export']) && $_GET['export'] == 'csv') {
  27. $export_csv = true;
  28. }
  29. /*
  30. ===============================================================================
  31. FUNCTION
  32. ===============================================================================
  33. */
  34. function count_sessions_coached() {
  35. global $nb_sessions;
  36. return $nb_sessions;
  37. }
  38. function sort_sessions($a, $b) {
  39. global $tracking_column;
  40. if ($a[$tracking_column] > $b[$tracking_column]) {
  41. return 1;
  42. } else {
  43. return -1;
  44. }
  45. }
  46. function rsort_sessions($a, $b) {
  47. global $tracking_column;
  48. if ($b[$tracking_column] > $a[$tracking_column]) {
  49. return 1;
  50. } else {
  51. return -1;
  52. }
  53. }
  54. /*
  55. ===============================================================================
  56. MAIN CODE
  57. ===============================================================================
  58. */
  59. if (isset($_GET['id_coach']) && $_GET['id_coach'] != '') {
  60. $id_coach = intval($_GET['id_coach']);
  61. } else {
  62. $id_coach = $_user['user_id'];
  63. }
  64. $a_sessions = Tracking :: get_sessions_coached_by_user($id_coach);
  65. $nb_sessions = count($a_sessions);
  66. if ($export_csv) {
  67. $csv_content = array();
  68. }
  69. if ($nb_sessions > 0) {
  70. echo '<div align="right">
  71. <a href="javascript: void(0);" onclick="javascript: window.print();"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
  72. <a href="'.api_get_self().'?export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
  73. </div>';
  74. $table = new SortableTable('tracking', 'count_sessions_coached');
  75. $table -> set_header(0, get_lang('Title'));
  76. $table -> set_header(1, get_lang('Status'));
  77. $table -> set_header(2, get_lang('Date'));
  78. $table -> set_header(3, get_lang('Details'), false);
  79. $all_data = array();
  80. foreach ($a_sessions as $session) {
  81. $row = array();
  82. $row[] = $session['name'];
  83. $row[] = $session['status'];
  84. if ($session['date_start'] != '0000-00-00' && $session['date_end'] != '0000-00-00') {
  85. $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']));
  86. } else {
  87. $row[] = ' - ';
  88. }
  89. if ($export_csv) {
  90. $csv_content[] = $row;
  91. }
  92. if (isset($_GET['id_coach']) && $_GET['id_coach'] != '') {
  93. $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>';
  94. } else {
  95. $row[] = '<a href="course.php?id_session='.$session['id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  96. }
  97. $all_data[] = $row;
  98. }
  99. if (!isset($tracking_column)) {
  100. $tracking_column = 0;
  101. }
  102. if ($_GET['tracking_direction'] == 'DESC') {
  103. usort($all_data, 'rsort_sessions');
  104. } else {
  105. usort($all_data, 'sort_sessions');
  106. }
  107. if ($export_csv) {
  108. usort($csv_content, 'sort_sessions');
  109. }
  110. foreach ($all_data as $row) {
  111. $table -> addRow($row);
  112. }
  113. $table -> setColAttributes(3, array('align' => 'center'));
  114. $table -> display();
  115. if ($export_csv) {
  116. ob_end_clean();
  117. Export :: export_table_csv($csv_content, 'reporting_student_list');
  118. exit;
  119. }
  120. } else {
  121. get_lang('NoSession');
  122. }
  123. /*
  124. ==============================================================================
  125. FOOTER
  126. ==============================================================================
  127. */
  128. Display::display_footer();