session.php 5.9 KB

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