session.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* For licensing terms, see /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', 'admin');
  11. $cidReset = true;
  12. require_once '../inc/global.inc.php';
  13. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  14. require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
  15. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  16. api_block_anonymous_users();
  17. $this_section = SECTION_TRACKING;
  18. api_block_anonymous_users();
  19. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  20. Display :: display_header($nameTools);
  21. // Database Table Definitions
  22. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  23. $tbl_sessions = Database :: get_main_table(TABLE_MAIN_SESSION);
  24. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  25. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  26. $export_csv = false;
  27. if (isset($_GET['export']) && $_GET['export'] == 'csv') {
  28. $export_csv = true;
  29. }
  30. /*
  31. ===============================================================================
  32. FUNCTION
  33. ===============================================================================
  34. */
  35. function count_sessions_coached() {
  36. global $nb_sessions;
  37. return $nb_sessions;
  38. }
  39. function sort_sessions($a, $b) {
  40. global $tracking_column;
  41. if ($a[$tracking_column] > $b[$tracking_column]) {
  42. return 1;
  43. } else {
  44. return -1;
  45. }
  46. }
  47. function rsort_sessions($a, $b) {
  48. global $tracking_column;
  49. if ($b[$tracking_column] > $a[$tracking_column]) {
  50. return 1;
  51. } else {
  52. return -1;
  53. }
  54. }
  55. /*
  56. ===============================================================================
  57. MAIN CODE
  58. ===============================================================================
  59. */
  60. if (isset($_GET['id_coach']) && $_GET['id_coach'] != '') {
  61. $id_coach = intval($_GET['id_coach']);
  62. } else {
  63. $id_coach = $_user['user_id'];
  64. }
  65. if (api_is_drh() || api_is_session_admin() || api_is_platform_admin()) {
  66. $a_sessions = SessionManager::get_sessions_followed_by_drh($_user['user_id']);
  67. if (!api_is_session_admin()) {
  68. $menu_items[] = '<a href="index.php?view=drh_students&amp;display=yourstudents">'.get_lang('Students').'</a>';
  69. $menu_items[] = '<a href="teachers.php">'.get_lang('Trainers').'</a>';
  70. $menu_items[] = '<a href="course.php">'.get_lang('Courses').'</a>';
  71. }
  72. $menu_items[] = get_lang('Sessions');
  73. echo '<div class="actions-title" style ="font-size:10pt;">';
  74. $nb_menu_items = count($menu_items);
  75. if ($nb_menu_items > 1) {
  76. foreach ($menu_items as $key => $item) {
  77. echo $item;
  78. if ($key != $nb_menu_items - 1) {
  79. echo '&nbsp;|&nbsp;';
  80. }
  81. }
  82. }
  83. if (count($a_sessions) > 0) {
  84. echo '&nbsp;&nbsp;<a href="javascript: void(0);" onclick="javascript: window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a> ';
  85. echo '<a href="'.api_get_self().'?export=csv"><img align="absbottom" src="../img/csv.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>';
  86. }
  87. echo '</div>';
  88. echo '<h4>'.get_lang('YourSessionsList').'</h4>';
  89. } else {
  90. /*if (api_is_platform_admin()) {
  91. $a_sessions = SessionManager::get_sessions_list();
  92. } else {*/
  93. $a_sessions = Tracking :: get_sessions_coached_by_user($id_coach);
  94. //}
  95. }
  96. $nb_sessions = count($a_sessions);
  97. if ($export_csv) {
  98. $csv_content = array();
  99. }
  100. if ($nb_sessions > 0) {
  101. if (!api_is_drh()) {
  102. echo '<div align="right">
  103. <a href="javascript: void(0);" onclick="javascript: window.print();"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
  104. <a href="'.api_get_self().'?export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
  105. </div>';
  106. }
  107. $table = new SortableTable('tracking', 'count_sessions_coached');
  108. $table->set_header(0, get_lang('Title'));
  109. $table->set_header(1, get_lang('Date'));
  110. $table->set_header(2, get_lang('NbCoursesPerSession'));
  111. $table->set_header(3, get_lang('Details'), false);
  112. $all_data = array();
  113. foreach ($a_sessions as $session) {
  114. $row = array();
  115. $row[] = $session['name'];
  116. //$row[] = $session['status'];
  117. if ($session['date_start'] != '0000-00-00' && $session['date_end'] != '0000-00-00') {
  118. $row[] = get_lang('From').' '. api_convert_and_format_date($session['date_start'], DATE_FORMAT_SHORT, date_default_timezone_get()).' '.get_lang('To').' '.api_convert_and_format_date($session['date_end'], DATE_FORMAT_SHORT, date_default_timezone_get());
  119. } else {
  120. $row[] = ' - ';
  121. }
  122. $row[] = count(Tracking::get_courses_list_from_session($session['id']));
  123. if ($export_csv) {
  124. $csv_content[] = $row;
  125. }
  126. if (isset($_GET['id_coach']) && $_GET['id_coach'] != '') {
  127. $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>';
  128. } else {
  129. $row[] = '<a href="course.php?id_session='.$session['id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  130. }
  131. $all_data[] = $row;
  132. }
  133. if (!isset($tracking_column)) {
  134. $tracking_column = 0;
  135. }
  136. if ($_GET['tracking_direction'] == 'DESC') {
  137. usort($all_data, 'rsort_sessions');
  138. } else {
  139. usort($all_data, 'sort_sessions');
  140. }
  141. if ($export_csv) {
  142. usort($csv_content, 'sort_sessions');
  143. }
  144. foreach ($all_data as $row) {
  145. $table -> addRow($row);
  146. }
  147. $table -> setColAttributes(2, array('align' => 'center'));
  148. $table -> display();
  149. if ($export_csv) {
  150. ob_end_clean();
  151. Export :: export_table_csv($csv_content, 'reporting_student_list');
  152. exit;
  153. }
  154. } else {
  155. echo get_lang('NoSession');
  156. }
  157. /*
  158. ==============================================================================
  159. FOOTER
  160. ==============================================================================
  161. */
  162. Display::display_footer();