index.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Session view
  5. * @package chamilo.session
  6. * @author Julio Montoya <gugli100@gmail.com> Beeznest
  7. */
  8. /**
  9. * Code
  10. */
  11. // Language files that should be included.
  12. $language_file = array('courses', 'index','tracking','exercice', 'admin');
  13. $cidReset = true;
  14. require_once '../inc/global.inc.php';
  15. $libpath = api_get_path(LIBRARY_PATH);
  16. require_once $libpath.'course.lib.php';
  17. //require_once $libpath.'usermanager.lib.php';
  18. require_once $libpath.'sessionmanager.lib.php';
  19. require_once $libpath.'usermanager.lib.php';
  20. require_once $libpath.'formvalidator/FormValidator.class.php';
  21. require_once $libpath.'tracking.lib.php';
  22. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  23. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  24. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  25. api_block_anonymous_users(); // Only users who are logged in can proceed.
  26. $this_section = SECTION_COURSES;
  27. $htmlHeadXtra[] = api_get_jquery_ui_js(true);
  28. Display::display_header(get_lang('Session'));
  29. if (empty($_GET['session_id'])) {
  30. api_not_allowed();
  31. }
  32. $session_id = isset($_GET['session_id']) ? intval($_GET['session_id']): null;
  33. $course_id = isset($_GET['course_id']) ? intval($_GET['course_id']) : null;
  34. $_SESSION['id_session'] = $session_id;
  35. $session_info = SessionManager::fetch($session_id);
  36. $session_list = SessionManager::get_sessions_by_coach(api_get_user_id());
  37. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  38. $session_select = array();
  39. foreach ($session_list as $item) {
  40. $session_select[$item['id']] = $item['name'];
  41. }
  42. // Session list form
  43. if (count($session_select) > 1) {
  44. $form = new FormValidator('exercise_admin', 'get', api_get_self().'?session_id='.$session_id);
  45. $form->addElement('select', 'session_id', get_lang('SessionList'), $session_select, 'onchange="javascript:change_session()"');
  46. $defaults['session_id'] = $session_id;
  47. $form->setDefaults($defaults);
  48. $form->display();
  49. }
  50. //Listing LPs from all courses
  51. /*
  52. $lps = array();
  53. if (!empty($course_list)) {
  54. foreach ($course_list as $item) {
  55. $list = new LearnpathList(api_get_user_id(),$item['code']);
  56. $flat_list = $list->get_flat_list();
  57. $lps[$item['code']] = $flat_list;
  58. foreach ($flat_list as $item) {
  59. //var_dump(get_week_from_day($item['publicated_on']));
  60. }
  61. }
  62. }*/
  63. //Getting all sessions where I'm subscribed
  64. $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
  65. $my_session_list = array();
  66. $final_array = array();
  67. if (!empty($new_session_list)) {
  68. foreach($new_session_list as $item) {
  69. $my_session_id = isset($item['id_session']) ? $item['id_session'] : null;
  70. if (isset($my_session_id) && !in_array($my_session_id, $my_session_list) && $session_id == $my_session_id) {
  71. $final_array[$my_session_id]['name'] = $item['session_name'];
  72. //Get all courses by session where I'm subscribed
  73. $my_course_list = UserManager::get_courses_list_by_session(api_get_user_id(), $my_session_id);
  74. foreach ($my_course_list as $my_course) {
  75. $course = array();
  76. $course_info = api_get_course_info($my_course['code']);
  77. //Getting all exercises from the current course
  78. $exercise_list = get_all_exercises($course_info, $my_session_id);
  79. //Exercises we skip
  80. /*if (empty($exercise_list)) {
  81. continue;
  82. } */
  83. //$exercise_course_list = array();
  84. $course['name'] = $course_info['name'];
  85. $course['id'] = $course_info['real_id'];
  86. if (!empty($exercise_list)) {
  87. foreach($exercise_list as $exercise_item) {
  88. //Loading the exercise
  89. $exercise = new Exercise($course_info['real_id']);
  90. $exercise->read($exercise_item['id']);
  91. //$exercise_course_list[$exercise_item['id']] = $exercise;
  92. //Reading all Exercise results by user, exercise_id, code, and session
  93. $user_results = get_all_exercise_results_by_user(api_get_user_id(), $exercise_item['id'], $my_course['code'], $my_session_id);
  94. $course['exercises'][$exercise_item['id']]['data']['exercise_data'] = $exercise;
  95. $course['exercises'][$exercise_item['id']]['data']['results'] = $user_results;
  96. }
  97. $final_array[$my_session_id]['data'][$my_course['code']] = $course;
  98. }
  99. }
  100. }
  101. $my_session_list[] = $my_session_id;
  102. }
  103. }
  104. //echo '<pre>';print_r($final_array);
  105. //If the requested session does not exist in my list we stop the script
  106. if (!api_is_platform_admin()) {
  107. if (!in_array($session_id, $my_session_list)) {
  108. api_not_allowed();
  109. }
  110. }
  111. //If session is not active we stop de script
  112. if (!api_is_allowed_to_session_edit()) {
  113. api_not_allowed();
  114. }
  115. //Final data to be show
  116. $my_real_array = $new_exercises = array();
  117. $now = time();
  118. foreach($final_array as $session_data) {
  119. $my_course_list = isset($session_data['data']) ? $session_data['data']: array();
  120. if (!empty($my_course_list))
  121. foreach ($my_course_list as $my_course_code=>$course_data) {
  122. //echo '<pre>'; print_r($course_data);
  123. if (isset($course_id) && !empty($course_id)) {
  124. if ($course_id != $course_data['id']) {
  125. continue;
  126. }
  127. }
  128. if (!empty($course_data['exercises'])) {
  129. //Exercises
  130. foreach ($course_data['exercises'] as $my_exercise_id => $exercise_data) {
  131. $best_score_data = get_best_attempt_in_course($my_exercise_id, $my_course_code, $session_id);
  132. $best_score = '';
  133. if (!empty($best_score_data)) {
  134. $best_score = show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']);
  135. }
  136. //Exercise results
  137. $counter = 1;
  138. foreach ($exercise_data as $exercise_item) {
  139. $result_list = $exercise_item['results'];
  140. $exercise_info = $exercise_item['exercise_data'];
  141. if ($exercise_info->start_time == '0000-00-00 00:00:00') {
  142. $start_date = '-';
  143. } else {
  144. $start_date = $exercise_info->start_time;
  145. }
  146. if (!empty($result_list)) {
  147. foreach ($result_list as $exercise_result) {
  148. //$my_exercise_result = array($exercise_info->exercise, $exercise_result['exe_id']);
  149. $column = 1;
  150. $platform_score = show_score($exercise_result['exe_result'], $exercise_result['exe_weighting']);
  151. $my_score = 0;
  152. if(!empty($exercise_result['exe_weighting']) && intval($exercise_result['exe_weighting']) != 0) {
  153. $my_score = $exercise_result['exe_result']/$exercise_result['exe_weighting'];
  154. }
  155. $position = get_exercise_result_ranking($my_score, $exercise_result['exe_id'], $my_exercise_id, $my_course_code,$session_id);
  156. $exercise_info->exercise = Display::url($exercise_info->exercise, api_get_path(WEB_CODE_PATH)."exercice/exercice.php?cidReq=$my_course_code&exerciseId={$exercise_info->id}&id_session=$session_id&show=result", array('target'=>SESSION_LINK_TARGET,'class'=>'exercise-result-link'));
  157. $my_real_array[]= array( //'date' => api_get_local_time($exercise_result['exe_date']),
  158. 'status' => Display::return_icon('quiz.gif', get_lang('Attempted'),'','22'),
  159. 'date' => $start_date,
  160. 'course' => $course_data['name'],
  161. 'exercise' => $exercise_info->exercise,
  162. 'attempt' => $counter,
  163. 'result' => $platform_score,
  164. 'best_result' => $best_score,
  165. 'position' => $position
  166. );
  167. $counter++;
  168. }
  169. } else {
  170. //We check the date validation of the exercise if the user can make it
  171. if ($exercise_info->start_time != '0000-00-00 00:00:00') {
  172. $allowed_time = api_strtotime($exercise_info->start_time);
  173. if ($now < $allowed_time) {
  174. continue;
  175. }
  176. }
  177. $exercise_info->exercise = Display::url($exercise_info->exercise, api_get_path(WEB_CODE_PATH)."exercice/exercise_submit.php?cidReq=$my_course_code&exerciseId={$exercise_info->id}&id_session=$session_id", array('target'=>SESSION_LINK_TARGET));
  178. $new_exercises[]= array( //'date' => api_get_local_time($exercise_result['exe_date']),
  179. 'status' => Display::return_icon('star.png', get_lang('New'), array('width'=>'22')),
  180. 'date' => $start_date,
  181. 'course' => $course_data['name'],
  182. 'exercise' => $exercise_info->exercise,
  183. 'attempt' => '-',
  184. 'result' => '-',
  185. 'best_result' => '-',
  186. 'position' => '-'
  187. );
  188. }
  189. }
  190. }
  191. }
  192. }
  193. }
  194. $my_real_array = msort($my_real_array, 'date','asc');
  195. if (!empty($new_exercises)) {
  196. $my_real_array = array_merge($new_exercises, $my_real_array);
  197. }
  198. $back_url = '';
  199. if (!empty($course_id)) {
  200. $back_url = Display::url(Display::return_icon('back.png',get_lang('back.png')), api_get_path(WEB_CODE_PATH).'session/?session_id='.$session_id);
  201. }
  202. $start = $end = $start_only = $end_only ='';
  203. if (!empty($session_info['date_start']) && $session_info['date_start'] != '0000-00-00') {
  204. $start = api_convert_and_format_date($session_info['date_start'], DATE_FORMAT_SHORT);
  205. $start_only = get_lang('From').' '.$session_info['date_start'];
  206. }
  207. if (!empty($session_info['date_start']) && $session_info['date_end'] != '0000-00-00') {
  208. $end = api_convert_and_format_date($session_info['date_end'], DATE_FORMAT_SHORT);
  209. $end_only = get_lang('Until').' '.$session_info['date_end'];
  210. }
  211. if (!empty($start) && !empty($end)) {
  212. $dates = Display::tag('i', sprintf(get_lang('FromDateXToDateY'),$start, $end));
  213. } else {
  214. $dates = Display::tag('i', $start_only.' '.$end_only);
  215. }
  216. echo Display::tag('h1', $back_url.' '.$session_info['name']);
  217. echo $dates.'<br />';
  218. //echo '<pre>';print_r($course_list);
  219. $new_course_list = array();
  220. if (!empty($course_list)) {
  221. foreach($course_list as $course_data) {
  222. $course_data['title'] = Display::url($course_data['title'], api_get_path(WEB_CODE_PATH).'session/?session_id='.$session_id.'&course_id='.$course_data['id'].'#tabs-2');
  223. $new_course_list[] = array('title'=>$course_data['title']);
  224. }
  225. }
  226. //All Learnpaths grid settings (First tab, first subtab)
  227. $columns_courses = array(get_lang('Title'));
  228. $column_model_courses = array(array('name'=>'title', 'index'=>'title', 'width'=>'880px', 'align'=>'left', 'sortable'=>'false'));
  229. $extra_params_courses['autowidth'] = 'false'; //use the width of the parent
  230. $url = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_default&session_id='.$session_id.'&course_id='.$course_id;
  231. $columns = array(get_lang('PublicationDate'),get_lang('Course'), get_lang('LearningPaths'));
  232. $column_model = array(array('name'=>'date', 'index'=>'date', 'width'=>'120', 'align'=>'left', 'sortable'=>'false'),
  233. array('name'=>'course', 'index'=>'course', 'width'=>'400', 'align'=>'left', 'sortable'=>'false'),
  234. array('name'=>'lp', 'index'=>'lp', 'width'=>'330', 'align'=>'left', 'sortable'=>'false'));
  235. $extra_params = array();
  236. //$extra_params['autowidth'] = 'true'; //use the width of the parent
  237. //$extra_params['forceFit'] = 'true'; //use the width of the parent
  238. //$extra_params['altRows'] = 'true'; //zebra style
  239. //Per course grid settings
  240. $url_by_course = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_course&session_id='.$session_id.'&course_id='.$course_id;
  241. $extra_params_course['grouping'] = 'true';
  242. $extra_params_course['groupingView'] = array('groupCollapse' => true,
  243. 'groupField' => array('course'),
  244. 'groupColumnShow' => array('false'),
  245. 'groupText' => array('<b>'.get_lang('Course').' {0}</b>'));
  246. //$extra_params_course['autowidth'] = 'true'; //use the width of the parent
  247. //Per Week grid
  248. $url_week = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_week&session_id='.$session_id.'&course_id='.$course_id;
  249. $column_week = array(get_lang('PeriodWeek'), get_lang('PublicationDate'), get_lang('Course'), get_lang('LearningPaths'));
  250. $column_week_model = array (
  251. array('name'=>'week', 'index'=>'week', 'width'=>'50', 'align'=>'left', 'sortable'=>'false'),
  252. array('name'=>'date', 'index'=>'date', 'width'=>'100', 'align'=>'left', 'sortable'=>'false'),
  253. array('name'=>'course', 'index'=>'course', 'width'=>'400', 'align'=>'left', 'sortable'=>'false'),
  254. array('name'=>'lp', 'index'=>'lp', 'width'=>'300', 'align'=>'left', 'sortable'=>'false'));
  255. $extra_params_week['grouping'] = 'true';
  256. //For more details see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:grouping
  257. $extra_params_week['groupingView'] = array('groupCollapse' => true,
  258. 'groupDataSorted' => true,
  259. 'groupField' => array('week'),
  260. 'groupColumnShow' => 'false',
  261. 'groupText' => array('<b>'.get_lang('PeriodWeek').' {0}</b>'));
  262. //$extra_params_week['autowidth'] = 'true'; //use the width of the parent
  263. //MyQCM grid
  264. $column_exercise = array(get_lang('Status'), get_lang('ExerciseStartDate'), get_lang('Course'), get_lang('Exercise'),get_lang('Attempts'), get_lang('Result'), get_lang('BestResultInCourse'), get_lang('Ranking'));
  265. $column_exercise_model = array(
  266. array('name'=>'status', 'index'=>'status', 'width'=>'40', 'align'=>'left', 'sortable'=>'false'),
  267. array('name'=>'date', 'index'=>'date', 'width'=>'130','align'=>'left', 'sortable'=>'true'),
  268. array('name'=>'course', 'index'=>'course', 'width'=>'200','align'=>'left', 'sortable'=>'true'),
  269. array('name'=>'exercise', 'index'=>'exercise', 'width'=>'200','align'=>'left', 'sortable'=>'false'),
  270. array('name'=>'attempt', 'index'=>'attempt', 'width'=>'60', 'align'=>'center', 'sortable'=>'true'),
  271. array('name'=>'result', 'index'=>'result', 'width'=>'120','align'=>'center', 'sortable'=>'true'),
  272. array('name'=>'best_result','index'=>'best_result','width'=>'140','align'=>'center', 'sortable'=>'true'),
  273. array('name'=>'position', 'index'=>'position', 'width'=>'55', 'align'=>'center', 'sortable'=>'true')
  274. );
  275. $extra_params_exercise['height'] = '300';
  276. //$extra_params_exercise['sortname'] = 'status';
  277. //$extra_params_exercise['sortorder'] = 'desc';
  278. //$extra_params_exercise['grouping'] = 'true';
  279. //$extra_params_exercise['groupingView'] = array('groupField'=>array('course'),'groupColumnShow'=>'false','groupText' => array('<b>'.get_lang('Course').' {0}</b>'));
  280. //$extra_params_exercise['groupingView'] = array('groupField'=>array('course'),'groupColumnShow'=>'false','groupText' => array('<b>'.get_lang('Course').' {0} - {1} Item(s)</b>'));
  281. ?>
  282. <br />
  283. <script>
  284. function change_session() {
  285. document.exercise_admin.submit();
  286. }
  287. $(function() {
  288. //js used when generating images on the fly see function Tracking::show_course_detail()
  289. $(".dialog").dialog("destroy");
  290. $(".dialog").dialog({
  291. autoOpen: false,
  292. show: "blind",
  293. resizable: false,
  294. height:300,
  295. width:550,
  296. modal: true
  297. });
  298. $(".opener").click(function() {
  299. var my_id = $(this).attr('id');
  300. var big_image = '#main_graph_' + my_id;
  301. $( big_image ).dialog("open");
  302. return false;
  303. });
  304. /* Binds a tab id in the url */
  305. $("#tabs").bind('tabsselect', function(event, ui) {
  306. window.location.href=ui.tab;
  307. });
  308. //Generate tabs with jquery-ui
  309. $('#tabs').tabs();
  310. $( "#sub_tab" ).tabs();
  311. <?php
  312. //Displays js code to use a jqgrid
  313. echo Display::grid_js('courses', '', $columns_courses, $column_model_courses, $extra_params_courses, $new_course_list);
  314. echo Display::grid_js('list_default', $url, $columns, $column_model,$extra_params,array(), '');
  315. echo Display::grid_js('list_course', $url_by_course, $columns, $column_model,$extra_params_course,array(),'');
  316. echo Display::grid_js('list_week', $url_week, $column_week, $column_week_model, $extra_params_week,array(),'');
  317. echo Display::grid_js('exercises', '', $column_exercise, $column_exercise_model, $extra_params_exercise, $my_real_array);
  318. ?>
  319. });
  320. </script>
  321. <?php
  322. $my_reporting = Tracking::show_user_progress(api_get_user_id(), $session_id, '&session_id='.$session_id.'#tabs-4', false);
  323. if (!empty($my_reporting)) {
  324. $my_reporting .= '<br />'.Tracking::show_course_detail(api_get_user_id(), $_GET['course'], $_GET['session_id']);
  325. }
  326. if (empty($my_reporting)) {
  327. $my_reporting = Display::return_message(get_lang('NoDataAvailable'), 'warning');
  328. }
  329. //Main headers
  330. $headers = array(get_lang('Courses'), get_lang('LearningPaths'), get_lang('MyQCM'), get_lang('MyStatistics'));
  331. //Subheaders
  332. $sub_header = array(get_lang('AllLearningPaths'), get_lang('PerWeek'), get_lang('ByCourse'));
  333. //Sub headers data
  334. $lp_tabs = Display::tabs($sub_header, array(Display::grid_html('list_default'), Display::grid_html('list_week'), Display::grid_html('list_course')),'sub_tab');
  335. $courses_tab = Display::grid_html('courses');
  336. //Main headers data
  337. echo Display::tabs($headers, array($courses_tab, $lp_tabs, Display::grid_html('exercises'), $my_reporting));
  338. Display::display_footer();