index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Session view
  5. * @package chamilo.session
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. */
  8. // Language files that should be included.
  9. $language_file = array('courses', 'index','tracking','exercice', 'admin');
  10. $cidReset = true;
  11. require_once '../inc/global.inc.php';
  12. $libpath = api_get_path(LIBRARY_PATH);
  13. require_once $libpath.'course.lib.php';
  14. //require_once $libpath.'usermanager.lib.php';
  15. require_once $libpath.'sessionmanager.lib.php';
  16. require_once $libpath.'usermanager.lib.php';
  17. require_once $libpath.'formvalidator/FormValidator.class.php';
  18. require_once $libpath.'text.lib.php';
  19. require_once $libpath.'tracking.lib.php';
  20. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  21. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  22. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  23. api_block_anonymous_users(); // Only users who are logged in can proceed.
  24. $this_section = SECTION_COURSES;
  25. $htmlHeadXtra[] = api_get_jquery_ui_js(true);
  26. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('Course'));
  27. Display :: display_header($nameTools);
  28. $session_id = intval($_GET['session_id']);
  29. if (empty($session_id)) {
  30. api_not_allowed();
  31. }
  32. $session_info = SessionManager::fetch($session_id);
  33. $session_list = SessionManager::get_sessions_by_coach(api_get_user_id());
  34. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  35. $course_select = array();
  36. $session_select = array();
  37. foreach ($session_list as $item) {
  38. $session_select[$item['id']] = $item['name'];
  39. }
  40. // Session list form
  41. if (count($session_select) > 1) {
  42. $form = new FormValidator('exercise_admin', 'get', api_get_self().'?session_id='.$session_id);
  43. $form->addElement('select', 'session_id', get_lang('SessionList'), $session_select, 'onchange="javascript:change_session()"');
  44. $defaults['session_id'] = $session_id;
  45. $form->setDefaults($defaults);
  46. $form->display();
  47. //if ($form->validate()) {}
  48. }
  49. //Listing LPs from all courses
  50. /*
  51. $lps = array();
  52. if (!empty($course_list)) {
  53. foreach ($course_list as $item) {
  54. $list = new LearnpathList(api_get_user_id(),$item['code']);
  55. $flat_list = $list->get_flat_list();
  56. $lps[$item['code']] = $flat_list;
  57. foreach ($flat_list as $item) {
  58. //var_dump(get_week_from_day($item['publicated_on']));
  59. }
  60. }
  61. }*/
  62. //Getting all sessions where I'm subscribed
  63. $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
  64. $my_session_list = array();
  65. $final_array = array();
  66. if (!empty($new_session_list)) {
  67. foreach($new_session_list as $item) {
  68. $my_session_id = $item['id_session'];
  69. if (isset($my_session_id) && !in_array($my_session_id, $my_session_list) && $session_id == $my_session_id) {
  70. $final_array[$my_session_id]['name'] = $item['session_name'];
  71. //Get all courses by session where I'm subscribed
  72. $my_course_list = UserManager::get_courses_list_by_session(api_get_user_id(), $my_session_id );
  73. $course = array();
  74. foreach ($my_course_list as $my_course) {
  75. $course_info = api_get_course_info($my_course['code']);
  76. //Getting all exercises from the current course
  77. $exercise_list = get_all_exercises($course_info, $my_session_id);
  78. //Exercises we skip
  79. /*if (empty($exercise_list)) {
  80. continue;
  81. } */
  82. $exercise_course_list = array();
  83. $course['name'] = $course_info['name'];
  84. if (!empty($exercise_list)) {
  85. foreach($exercise_list as $exercise_item) {
  86. $exercise = new Exercise($course_info['real_id']);
  87. $exercise->read($exercise_item['id']);
  88. $exercise_course_list[$exercise_item['id']] = $exercise;
  89. //Reading all Exercise results by user, exercise_id, code, and session
  90. $user_results = get_all_exercise_results_by_user(api_get_user_id(), $exercise_item['id'], $my_course['code'], $my_session_id);
  91. //print_r($user_results);
  92. $course['exercises'][$exercise_item['id']]['name'] = $exercise->exercise;
  93. $course['exercises'][$exercise_item['id']]['data'] = $user_results;
  94. //print_r($user_results);
  95. }
  96. $final_array[$my_session_id]['data'][$my_course['code']] = $course;
  97. }
  98. }
  99. }
  100. $my_session_list[] = $my_session_id;
  101. }
  102. }
  103. //If the requested session does not exist in my list we stop the script
  104. if (!api_is_platform_admin()) {
  105. if (!in_array($session_id, $my_session_list)) {
  106. api_not_allowed();
  107. }
  108. }
  109. //print_r($my_session_list); exit;
  110. require_once api_get_path(LIBRARY_PATH).'pear/HTML/Table.php';
  111. $html = '';
  112. //Final data to be show
  113. $my_real_array =array();
  114. foreach($final_array as $session_data) {
  115. //Session name
  116. $html .=Display::tag('h1',$session_data['name']);
  117. $course_list = $session_data['data'];
  118. if (!empty($course_list))
  119. foreach ($course_list as $my_course_code=>$course_data) {
  120. //Course table
  121. $table = new HTML_Table(array('class' => 'data_table'));
  122. $row = 0;
  123. $column = 0;
  124. //Course headers
  125. /*$header_names = array(get_lang('Course'),get_lang('Exercise'),get_lang('Attempt'),get_lang('Results'),get_lang('Score'), get_lang('Ranking'));
  126. foreach ($header_names as $item) {
  127. $table->setHeaderContents($row, $column, $item);
  128. $column++;
  129. }
  130. $row = 1;
  131. $column = 0;
  132. $table->setCellContents($row, $column, $course_data['name']);
  133. $column++;*/
  134. if (!empty($course_data['exercises'])) {
  135. //Exercises
  136. foreach ($course_data['exercises'] as $my_exercise_id => $exercise_data) {
  137. $best_score_data = get_best_score($my_exercise_id, $my_course_code, $session_id);
  138. $best_score = show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']);
  139. //Exercise results
  140. $counter = 1;
  141. foreach ($exercise_data['data'] as $exercise_result) {
  142. $my_exercise_result = array($exercise_data['name'], $exercise_result['exe_id']);
  143. $column = 1;
  144. $platform_score = show_score($exercise_result['exe_result'], $exercise_result['exe_weighting']);
  145. $position = get_exercise_result_ranking($my_score, $exercise_result['exe_id'], $my_exercise_id, $my_course_code,$session_id);
  146. $my_real_array[]= array( 'date' => api_get_local_time($exercise_result['exe_date']),
  147. 'course' => $course_data['name'],
  148. 'exercise' => $exercise_data['name'],
  149. 'attempt' => $counter,
  150. 'result' => $platform_score,
  151. 'best_result' => $best_score,
  152. 'position' => $position
  153. );
  154. $counter++;
  155. foreach ($my_exercise_result as $data) {
  156. //$my_real_array[]= array('session'=>$session_data['name'],'course'=>$course_data['name'], 'exercise'=>$exercise_data['name'],'result'=>$exercise_result['exe_id']) ;
  157. $table->setCellContents($row, $column, $data);
  158. //$table->updateCellAttributes($row, $column, 'align="center"');
  159. $column++;
  160. }
  161. $row++;
  162. }
  163. }
  164. }
  165. $html .=$table->toHtml();
  166. }
  167. }
  168. echo Display::tag('h1', $session_info['name']);
  169. //All Learnpaths grid settings (First tab, first subtab)
  170. $url = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_default&session_id='.$session_id;
  171. $columns = array(get_lang('PublicationDate'),get_lang('Course'), get_lang('LearningPath'));
  172. $column_model = array(array('name'=>'date', 'index'=>'date', 'width'=>'150', 'align'=>'left', 'sortable'=>'false'),
  173. array('name'=>'course', 'index'=>'course', 'width'=>'400', 'align'=>'left', 'sortable'=>'false'),
  174. array('name'=>'lp', 'index'=>'lp', 'width'=>'200', 'align'=>'center','sortable'=>'false'));
  175. //$extra_params['autowidth'] = 'true'; //use the width of the parent
  176. //$extra_params['forceFit'] = 'true'; //use the width of the parent
  177. //$extra_params['altRows'] = 'true'; //zebra style
  178. //Per course grid settings
  179. $url_course = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_course&session_id='.$session_id;
  180. $extra_params_course['grouping'] = 'true';
  181. $extra_params_course['groupingView'] = array('groupField' => array('course'),
  182. 'groupColumnShow' => array('false'),
  183. 'groupText' => array('<b>'.get_lang('Course').' {0}</b>'));
  184. //$extra_params_course['autowidth'] = 'true'; //use the width of the parent
  185. //Per Week grid
  186. $url_week = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_week&session_id='.$session_id;
  187. $column_week = array(get_lang('PeriodWeek'), get_lang('PublicationDate'), get_lang('Course'), get_lang('LearningPath'));
  188. $column_week_model = array (
  189. array('name'=>'week', 'index'=>'week', 'width'=>'80', 'align'=>'left', 'sortable'=>'false'),
  190. array('name'=>'date', 'index'=>'date', 'width'=>'150', 'align'=>'left', 'sortable'=>'false'),
  191. array('name'=>'course', 'index'=>'course', 'width'=>'400', 'align'=>'left', 'sortable'=>'false'),
  192. array('name'=>'lp', 'index'=>'lp', 'width'=>'200', 'align'=>'center','sortable'=>'false'));
  193. $extra_params_week['grouping'] = 'true';
  194. $extra_params_week['groupingView'] = array('groupField'=>array('week'),
  195. 'groupColumnShow'=>'false',
  196. 'groupText' => array('<b>'.get_lang('PeriodWeek').' {0}</b>'));
  197. //$extra_params_week['autowidth'] = 'true'; //use the width of the parent
  198. //MyQCM grid
  199. $column_exercise = array(get_lang('PublicationDate'), get_lang('Course'), get_lang('Exercise'),get_lang('Attempts'), get_lang('Result'), get_lang('BestResultInCourse'), get_lang('Position'));
  200. $column_exercise_model = array(
  201. array('name'=>'date', 'index'=>'date', 'width'=>'130','align'=>'left', 'sortable'=>'true'),
  202. array('name'=>'course', 'index'=>'course', 'width'=>'200','align'=>'left', 'sortable'=>'true'),
  203. array('name'=>'exercise', 'index'=>'exercise', 'width'=>'200','align'=>'left', 'sortable'=>'true'),
  204. array('name'=>'attempt', 'index'=>'attempt', 'width'=>'60', 'align'=>'center', 'sortable'=>'true'),
  205. array('name'=>'result', 'index'=>'result', 'width'=>'140', 'align'=>'center', 'sortable'=>'true'),
  206. array('name'=>'best_result','index'=>'best_result','width'=>'140','align'=>'center', 'sortable'=>'true'),
  207. array('name'=>'position', 'index'=>'position', 'width'=>'50', 'align'=>'center', 'sortable'=>'true')
  208. );
  209. //$extra_params_exercise['grouping'] = 'true';
  210. //$extra_params_exercise['groupingView'] = array('groupField'=>array('course'),'groupColumnShow'=>'false','groupText' => array('<b>'.get_lang('Course').' {0}</b>'));
  211. //$extra_params_exercise['groupingView'] = array('groupField'=>array('course'),'groupColumnShow'=>'false','groupText' => array('<b>'.get_lang('Course').' {0} - {1} Item(s)</b>'));
  212. ?>
  213. <br />
  214. <script>
  215. function change_session() {
  216. document.exercise_admin.submit();
  217. }
  218. $(function() {
  219. /*Binds a tab id in the url */
  220. $("#tabs").bind('tabsselect', function(event, ui) {
  221. window.location.href=ui.tab;
  222. });
  223. $('#tabs').tabs();
  224. $( "#sub_tab" ).tabs();
  225. <?php
  226. echo Display::grid_js('list_default', $url, $columns, $column_model,$extra_params,array(), '');
  227. echo Display::grid_js('list_course', $url_course, $columns, $column_model,$extra_params_course,array(),'');
  228. echo Display::grid_js('list_week', $url_week, $column_week, $column_week_model, $extra_params_week,array(),'');
  229. echo Display::grid_js('exercises', '', $column_exercise,$column_exercise_model, $extra_params_exercise, $my_real_array);
  230. ?>
  231. });
  232. </script>
  233. <?php
  234. $my_reporting = Tracking::show_user_progress(api_get_user_id(), $session_id, '&session_id='.$session_id.'#tabs-3', false);
  235. $my_reporting .= '<br />'.Tracking::show_course_detail(api_get_user_id(), $_GET['course'], $_GET['session_id']);
  236. //Main headers
  237. $headers = array(get_lang('LearningPaths'), get_lang('MyQCM'), get_lang('MyStatistics'));
  238. //Subheaders
  239. $sub_header = array(get_lang('AllLearningPaths'), get_lang('PerWeek'), get_lang('ByCourse'));
  240. //Sub headers data
  241. $tabs = Display::tabs($sub_header, array(Display::grid_html('list_default'), Display::grid_html('list_week'), Display::grid_html('list_course')),'sub_tab');
  242. //Main headers data
  243. echo Display::tabs($headers, array($tabs, Display::grid_html('exercises'),$my_reporting));
  244. Display :: display_footer();