index.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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. use \ChamiloSession as Session;
  12. // Language files that should be included.
  13. $language_file = array('learnpath', 'courses', 'index','tracking','exercice', 'admin');
  14. $cidReset = true;
  15. require_once '../inc/global.inc.php';
  16. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  17. api_block_anonymous_users(); // Only users who are logged in can proceed.
  18. $this_section = SECTION_COURSES;
  19. $htmlHeadXtra[] = api_get_jqgrid_js();
  20. if (empty($_GET['session_id'])) {
  21. api_not_allowed(true);
  22. }
  23. $session_id = isset($_GET['session_id']) ? intval($_GET['session_id']): null;
  24. $course_id = isset($_GET['course_id']) ? intval($_GET['course_id']) : null;
  25. $_SESSION['id_session'] = $session_id;
  26. // Clear the exercise session just in case
  27. if (isset ($_SESSION['objExercise'])) {
  28. Session::erase('objExercise');
  29. }
  30. $session_info = SessionManager::fetch($session_id);
  31. $session_list = SessionManager::get_sessions_by_general_coach(api_get_user_id());
  32. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  33. //Getting all sessions where I'm subscribed
  34. $new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
  35. $user_course_list = array();
  36. foreach ($new_session_list as $session_item) {
  37. $user_course_list[] = $session_item['code'];
  38. }
  39. $my_session_list = array();
  40. $final_array = array();
  41. if (!empty($new_session_list)) {
  42. foreach ($new_session_list as $item) {
  43. $my_session_id = isset($item['id_session']) ? $item['id_session'] : null;
  44. if (isset($my_session_id) && !in_array($my_session_id, $my_session_list) && $session_id == $my_session_id) {
  45. $final_array[$my_session_id]['name'] = $item['session_name'];
  46. //Get all courses by session where I'm subscribed
  47. $my_course_list = UserManager::get_courses_list_by_session(api_get_user_id(), $my_session_id);
  48. foreach ($my_course_list as $my_course) {
  49. $course = array();
  50. $course_info = api_get_course_info_by_id($my_course['id']);
  51. //Getting all exercises from the current course
  52. $exercise_list = ExerciseLib::get_all_exercises($course_info, $my_session_id, true);
  53. $course['name'] = $course_info['name'];
  54. $course['id'] = $course_info['real_id'];
  55. if (!empty($exercise_list)) {
  56. foreach ($exercise_list as $exercise_item) {
  57. //Loading the exercise
  58. $exercise = new Exercise($course_info['real_id']);
  59. $exercise->read($exercise_item['id']);
  60. $visible_return = $exercise->is_visible();
  61. if ($visible_return['value'] != false) {
  62. //$exercise_course_list[$exercise_item['id']] = $exercise;
  63. //Reading all Exercise results by user, exercise_id, code, and session
  64. $user_results = getExerciseResultsByUser(api_get_user_id(), $exercise_item['id'], $my_course['real_id'], $my_session_id);
  65. $course['exercises'][$exercise_item['id']]['data']['exercise_data'] = $exercise;
  66. $course['exercises'][$exercise_item['id']]['data']['results'] = $user_results;
  67. }
  68. }
  69. $final_array[$my_session_id]['data'][$my_course['code']] = $course;
  70. }
  71. }
  72. }
  73. $my_session_list[] = $my_session_id;
  74. }
  75. }
  76. if (!empty($course_list)) {
  77. foreach ($course_list as $course_data) {
  78. if (in_array($course_data['code'], $user_course_list)) {
  79. $course_data['only_title'] = $course_data['title'];
  80. $course_data['link'] = api_get_course_url($course_data['code'], $session_id);
  81. $course_data['title'] = Display::url($course_data['title'], api_get_course_url($course_data['code'], $session_id));
  82. } else {
  83. continue;
  84. }
  85. $list = new LearnpathList(api_get_user_id(),$course_data['code'], $session_id, 'publicated_on ASC', true);
  86. $lp_list = $list->get_flat_list();
  87. $lp_count = count($lp_list);
  88. $course_info = api_get_course_info($course_data['code']);
  89. $exercise_count = count(ExerciseLib::get_all_exercises($course_info, $session_id, true));
  90. $max_mutation_date = '';
  91. $last_date = Tracking::get_last_connection_date_on_the_course(api_get_user_id(), $course_data['id'], $session_id, false);
  92. $icons = '';
  93. foreach ($lp_list as $item) {
  94. if ($item['modified_on'] == '0000-00-00 00:00:00' || empty($item['modified_on'])) {
  95. $lp_date_original = $item['created_on'];
  96. $image = 'new.gif';
  97. $label = get_lang('LearnpathAdded');
  98. } else {
  99. $lp_date_original = $item['modified_on'];
  100. $image = 'moderator_star.png';
  101. $label = get_lang('LearnpathUpdated');
  102. }
  103. $mutation_date = api_strtotime($item['publicated_on']) > api_strtotime($lp_date_original) ? $item['publicated_on'] : $lp_date_original;
  104. if (api_strtotime($mutation_date) > api_strtotime($max_mutation_date)) {
  105. $max_mutation_date = $mutation_date;
  106. }
  107. if (strtotime($last_date) < strtotime($lp_date_original)) {
  108. if (empty($icons)) {
  109. $icons .= ' '.Display::return_icon($image, get_lang('TitleNotification').': '.$label.' - '.$lp_date_original).' ';
  110. }
  111. }
  112. }
  113. $new_course_list[] = array('title'=> $course_data['title'].$icons,
  114. // 'recent_lps' => $icons,
  115. //'max_mutation_date' => substr(api_get_local_time($max_mutation_date),0,10),
  116. 'exercise_count' => $exercise_count,
  117. 'lp_count' => $lp_count,
  118. 'only_title' => $course_data['only_title'],
  119. 'link' => $course_data['link']
  120. );
  121. }
  122. }
  123. //If the requested session does not exist in my list we stop the script
  124. if (!api_is_platform_admin()) {
  125. if (!in_array($session_id, $my_session_list)) {
  126. api_not_allowed(true);
  127. }
  128. }
  129. //If session is not active we stop de script
  130. if (!api_is_allowed_to_session_edit()) {
  131. //api_not_allowed();
  132. }
  133. Display::display_header(get_lang('Session'));
  134. $session_select = array();
  135. foreach ($session_list as $item) {
  136. $session_select[$item['id']] = $item['name'];
  137. }
  138. // Session list form
  139. if (count($session_select) > 1) {
  140. $form = new FormValidator('exercise_admin', 'get', api_get_self().'?session_id='.$session_id);
  141. $form->addElement('select', 'session_id', get_lang('SessionList'), $session_select, 'onchange="javascript:change_session()"');
  142. $defaults['session_id'] = $session_id;
  143. $form->setDefaults($defaults);
  144. $form->display();
  145. }
  146. if (empty($session_id)) {
  147. $user_list = UserManager::get_user_list();
  148. } else {
  149. $user_list = SessionManager::get_users_by_session($session_id);
  150. }
  151. //Final data to be show
  152. $my_real_array = array();
  153. $new_exercises = array();
  154. $now = time();
  155. foreach($final_array as $session_data) {
  156. $my_course_list = isset($session_data['data']) ? $session_data['data']: array();
  157. if (!empty($my_course_list))
  158. foreach ($my_course_list as $my_course_code => $course_data) {
  159. if (isset($course_id) && !empty($course_id)) {
  160. if ($course_id != $course_data['id']) {
  161. continue;
  162. }
  163. }
  164. if (!empty($course_data['exercises'])) {
  165. //Exercises
  166. foreach ($course_data['exercises'] as $my_exercise_id => $exercise_data) {
  167. $best_score_data = ExerciseLib::get_best_attempt_in_course($my_exercise_id, $course_data['id'], $session_id);
  168. $best_score = '';
  169. if (!empty($best_score_data)) {
  170. $best_score = ExerciseLib::show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']);
  171. }
  172. //Exercise results
  173. $counter = 1;
  174. foreach ($exercise_data as $exercise_item) {
  175. $result_list = $exercise_item['results'];
  176. $exercise_info = $exercise_item['exercise_data'];
  177. if ($exercise_info->start_time == '0000-00-00 00:00:00') {
  178. $start_date = '-';
  179. } else {
  180. $start_date = $exercise_info->start_time;
  181. }
  182. if (!empty($result_list)) {
  183. foreach ($result_list as $exercise_result) {
  184. $platform_score = ExerciseLib::show_score($exercise_result['exe_result'], $exercise_result['exe_weighting']);
  185. $my_score = 0;
  186. if(!empty($exercise_result['exe_weighting']) && intval($exercise_result['exe_weighting']) != 0) {
  187. $my_score = $exercise_result['exe_result']/$exercise_result['exe_weighting'];
  188. }
  189. $position = ExerciseLib::get_exercise_result_ranking($my_score, $exercise_result['exe_id'], $my_exercise_id, $course_data['id'], $session_id, $user_list);
  190. //$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'));
  191. $exercise_info->exercise = Display::url($exercise_info->exercise, api_get_path(WEB_CODE_PATH)."exercice/result.php?cidReq=$my_course_code&id={$exercise_result['exe_id']}&id_session=$session_id&show_headers=1", array('target'=>SESSION_LINK_TARGET,'class'=>'exercise-result-link'));
  192. $my_real_array[]= array(
  193. //'date' => api_get_local_time($exercise_result['exe_date']),
  194. 'status' => Display::return_icon('quiz.gif', get_lang('Attempted'),'', ICON_SIZE_SMALL),
  195. 'date' => $start_date,
  196. 'course' => $course_data['name'],
  197. 'exercise' => $exercise_info->exercise,
  198. 'attempt' => $counter,
  199. 'result' => $platform_score,
  200. 'best_result' => $best_score,
  201. 'position' => $position
  202. );
  203. $counter++;
  204. }
  205. } else {
  206. //We check the date validation of the exercise if the user can make it
  207. if ($exercise_info->start_time != '0000-00-00 00:00:00') {
  208. $allowed_time = api_strtotime($exercise_info->start_time, 'UTC');
  209. if ($now < $allowed_time) {
  210. continue;
  211. }
  212. }
  213. $exercise_info->exercise = Display::url($exercise_info->exercise, api_get_path(WEB_CODE_PATH)."exercice/overview.php?cidReq=$my_course_code&exerciseId={$exercise_info->id}&id_session=$session_id", array('target'=>SESSION_LINK_TARGET));
  214. $new_exercises[]= array(
  215. //'date' => api_get_local_time($exercise_result['exe_date']),
  216. 'status' => Display::return_icon('star.png', get_lang('New'), array('width'=>ICON_SIZE_SMALL)),
  217. 'date' => $start_date,
  218. 'course' => $course_data['name'],
  219. 'exercise' => $exercise_info->exercise,
  220. 'attempt' => '-',
  221. 'result' => '-',
  222. 'best_result' => '-',
  223. 'position' => '-'
  224. );
  225. }
  226. }
  227. }
  228. }
  229. }
  230. }
  231. $my_real_array = ArrayClass::msort($my_real_array, 'date','asc');
  232. if (!empty($new_exercises)) {
  233. $my_real_array = array_merge($new_exercises, $my_real_array);
  234. }
  235. $back_url = '';
  236. if (!empty($course_id)) {
  237. //$back_url = Display::url(Display::return_icon('back.png',get_lang('back.png')), api_get_path(WEB_CODE_PATH).'session/?session_id='.$session_id);
  238. }
  239. $dates = SessionManager::parse_session_dates($session_info);
  240. echo Display::page_header($back_url.' '.$session_info['name']." <small>$dates<small>");
  241. if (!empty($new_course_list)) {
  242. echo '<div id="session_course_list" class="row">';
  243. foreach ($new_course_list as $course_item) {
  244. echo '<div class="span3">';
  245. echo '<div class="big_icon">';
  246. echo Display::url(Display::return_icon('course.png', $course_item['only_title'], array(), ICON_SIZE_BIG), $course_item['link']);
  247. echo '</div>';
  248. echo '<div class="content">';
  249. echo $course_item['title'];
  250. echo '</div>';
  251. echo '</div>';
  252. }
  253. echo '</div>';
  254. }
  255. //All Learnpaths grid settings (First tab, first subtab)
  256. $columns_courses = array(get_lang('Title'), get_lang('NumberOfPublishedExercises'), get_lang('NumberOfPublishedLps'));
  257. $column_model_courses = array(
  258. array('name'=>'title', 'index'=>'title', 'width'=>'400px', 'align'=>'left', 'sortable'=>'true'),
  259. //array('name'=>'recent_lps', 'index'=>'recent_lps', 'width'=>'10px', 'align'=>'left', 'sortable'=>'false'),
  260. // array('name'=>'max_mutation_date', 'index'=>'max_mutation_date', 'width'=>'120px', 'align'=>'left', 'sortable'=>'true'),
  261. array('name'=>'exercise_count', 'index'=>'exercise_count', 'width'=>'180px', 'align'=>'left', 'sortable'=>'true'),
  262. array('name'=>'lp_count', 'index'=>'lp_count', 'width'=>'180px', 'align'=>'left', 'sortable'=>'true')
  263. );
  264. $extra_params_courses['height'] = '100%';
  265. $extra_params_courses['autowidth'] = 'true'; //use the width of the parent
  266. //$extra_params_courses['gridview'] = "false";
  267. /*$extra_params_courses['rowNum'] = 9000;
  268. $extra_params_courses['height'] = "100%";
  269. $extra_params_courses['autowidth'] = 'false'; //use the width of the parent
  270. $extra_params_courses['recordtext'] = '';
  271. $extra_params_courses['pgtext'] = '';
  272. $extra_params_courses['pgbuttons'] = false;*/
  273. //$extra_params_courses['width'] = '50%';
  274. //$extra_params_courses['autowidth'] = 'true';
  275. $url = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_default&session_id='.$session_id.'&course_id='.$course_id;
  276. $columns = array(get_lang('PublicationDate'), get_lang('Course'), get_lang('LearningPaths'));
  277. $column_model = array(array('name'=>'date', 'index'=>'date', 'width'=>'120', 'align'=>'left', 'sortable'=>'true'),
  278. array('name'=>'course', 'index'=>'course', 'width'=>'300', 'align'=>'left', 'sortable'=>'true', 'wrap_cell' => 'true'),
  279. array('name'=>'lp', 'index'=>'lp', 'width'=>'440', 'align'=>'left', 'sortable'=>'true'));
  280. $extra_params = array();
  281. /*
  282. $extra_params['sortname'] = 'date';
  283. $extra_params['sortorder'] = 'asc';
  284. $extra_params['pgbuttons'] = false;
  285. $extra_params['recordtext'] = '';
  286. $extra_params['pgtext'] = '';
  287. $extra_params['height'] = "100%";
  288. */
  289. //$extra_params['autowidth'] = 'true'; //use the width of the parent
  290. //$extra_params['width'] = '90%';
  291. //$extra_params['autowidth'] = 'true'; //use the width of the parent
  292. //$extra_params['forceFit'] = 'true'; //use the width of the parent
  293. //$extra_params['altRows'] = 'true'; //zebra style
  294. $extra_params['height'] = '100%';
  295. $extra_params['autowidth'] = 'true'; //use the width of the parent
  296. //Per course grid settings
  297. $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;
  298. $extra_params_course = array();
  299. $extra_params_course['grouping'] = 'true';
  300. $extra_params_course['groupingView'] = array('groupCollapse' => false,
  301. 'groupField' => array('course'),
  302. 'groupColumnShow' => array(false),
  303. 'groupText' => array('<b>'.get_lang('Course').' {0}</b>'));
  304. $extra_params_course['autowidth'] = 'true'; //use the width of the parent
  305. $extra_params_course['height'] = "100%";
  306. //Per Week grid
  307. $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;
  308. $column_week = array(get_lang('PeriodWeek'), get_lang('PublicationDate'), get_lang('Course'), get_lang('LearningPaths'));
  309. $column_week_model = array (
  310. array('name'=>'week', 'index'=>'week', 'width'=>'40', 'align'=>'left', 'sortable'=>'false'),
  311. array('name'=>'date', 'index'=>'date', 'width'=>'120', 'align'=>'left', 'sortable'=>'false'),
  312. array('name'=>'course', 'index'=>'course', 'width'=>'300', 'align'=>'left', 'sortable'=>'true', 'wrap_cell' => 'true'),
  313. array('name'=>'lp', 'index'=>'lp', 'width'=>'440', 'align'=>'left', 'sortable'=>'true'));
  314. $extra_params_week = array();
  315. $extra_params_week['grouping'] = 'true';
  316. //For more details see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:grouping
  317. $extra_params_week['groupingView'] = array('groupCollapse' => false,
  318. 'groupDataSorted' => false,
  319. 'groupField' => array('week'),
  320. 'groupOrder' => array('desc'),
  321. 'groupColumnShow' => false,
  322. 'groupText' => array('<b>'.get_lang('PeriodWeek').' {0}</b>'));
  323. $extra_params_week['autowidth'] = 'true'; //use the width of the parent
  324. $extra_params_week['height'] = '100%';
  325. //MyQCM grid
  326. $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'));
  327. $column_exercise_model = array(
  328. array('name'=>'status', 'index'=>'status', 'width'=>'40', 'align'=>'left', 'sortable'=>'false'),
  329. array('name'=>'date', 'index'=>'date', 'width'=>'130','align'=>'left', 'sortable'=>'true'),
  330. array('name'=>'course', 'index'=>'course', 'width'=>'200','align'=>'left', 'sortable'=>'true', 'wrap_cell' => 'true'),
  331. array('name'=>'exercise', 'index'=>'exercise', 'width'=>'200','align'=>'left', 'sortable'=>'false'),
  332. array('name'=>'attempt', 'index'=>'attempt', 'width'=>'60', 'align'=>'center', 'sortable'=>'true'),
  333. array('name'=>'result', 'index'=>'result', 'width'=>'120','align'=>'center', 'sortable'=>'true'),
  334. array('name'=>'best_result','index'=>'best_result','width'=>'140','align'=>'center', 'sortable'=>'true'),
  335. array('name'=>'position', 'index'=>'position', 'width'=>'55', 'align'=>'center', 'sortable'=>'true')
  336. );
  337. $extra_params_exercise['height'] = '100%';
  338. $extra_params_exercise['autowidth'] = 'true';
  339. //$extra_params_exercise['sortname'] = 'status';
  340. //$extra_params_exercise['sortorder'] = 'desc';
  341. //$extra_params_exercise['grouping'] = 'true';
  342. //$extra_params_exercise['groupingView'] = array('groupField'=>array('course'),'groupColumnShow'=>'false','groupText' => array('<b>'.get_lang('Course').' {0}</b>'));
  343. //$extra_params_exercise['groupingView'] = array('groupField'=>array('course'),'groupColumnShow'=>'false','groupText' => array('<b>'.get_lang('Course').' {0} - {1} Item(s)</b>'));
  344. ?>
  345. <br />
  346. <script>
  347. function change_session() {
  348. document.exercise_admin.submit();
  349. }
  350. $(function() {
  351. //js used when generating images on the fly see function Tracking::show_course_detail()
  352. $(".dialog").dialog("destroy");
  353. $(".dialog").dialog({
  354. autoOpen: false,
  355. show: "blind",
  356. resizable: false,
  357. height:300,
  358. width:550,
  359. modal: true
  360. });
  361. $(".opener").click(function() {
  362. var my_id = $(this).attr('id');
  363. var big_image = '#main_graph_' + my_id;
  364. $( big_image ).dialog("open");
  365. return false;
  366. });
  367. /* Binds a tab id in the url */
  368. $("#tabs").bind('tabsselect', function(event, ui) {
  369. window.location.href=ui.tab;
  370. });
  371. <?php
  372. //Displays js code to use a jqgrid
  373. echo Display::grid_js('courses', false, $columns_courses, $column_model_courses, $extra_params_courses, $new_course_list);
  374. echo Display::grid_js('list_default', $url, $columns, $column_model,$extra_params,array(), '');
  375. echo Display::grid_js('list_course', $url_by_course, $columns, $column_model,$extra_params_course,array(),'');
  376. echo Display::grid_js('list_week', $url_week, $column_week, $column_week_model, $extra_params_week,array(),'');
  377. echo Display::grid_js('exercises', '', $column_exercise, $column_exercise_model, $extra_params_exercise, $my_real_array);
  378. ?>
  379. //Generate tabs with jquery-ui
  380. $('#tabs').tabs();
  381. $( "#sub_tab" ).tabs();
  382. });
  383. </script>
  384. <?php
  385. $my_reporting = Tracking::show_user_progress(api_get_user_id(), $session_id, '#tabs-4', false);
  386. if (!empty($my_reporting)) {
  387. $my_reporting .= '<br />'.Tracking::show_course_detail(api_get_user_id(), $_GET['course'], $session_id);
  388. }
  389. if (empty($my_reporting)) {
  390. $my_reporting = Display::return_message(get_lang('NoDataAvailable'), 'warning');
  391. }
  392. //Main headers
  393. $headers = array(get_lang('Courses'), get_lang('LearningPaths'), get_lang('MyQCM'), get_lang('MyStatistics'));
  394. //Subheaders
  395. $sub_header = array(get_lang('AllLearningPaths'), get_lang('PerWeek'), get_lang('ByCourse'));
  396. //Sub headers data
  397. $lp_tabs = Display::tabs($sub_header, array(Display::grid_html('list_default'), Display::grid_html('list_week'), Display::grid_html('list_course')), 'sub_tab');
  398. $courses_tab = Display::grid_html('courses');
  399. //Main headers data
  400. echo Display::tabs($headers, array($courses_tab, $lp_tabs, Display::grid_html('exercises'), $my_reporting));
  401. Display::display_footer();