index.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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(
  114. 'title'=> $course_data['title'].$icons,
  115. //'recent_lps' => $icons,
  116. //'max_mutation_date' => substr(api_get_local_time($max_mutation_date),0,10),
  117. 'exercise_count' => $exercise_count,
  118. 'lp_count' => $lp_count,
  119. 'only_title' => $course_data['only_title'],
  120. 'link' => $course_data['link']
  121. );
  122. }
  123. }
  124. //If the requested session does not exist in my list we stop the script
  125. if (!api_is_platform_admin()) {
  126. if (!in_array($session_id, $my_session_list)) {
  127. api_not_allowed(true);
  128. }
  129. }
  130. //If session is not active we stop de script
  131. if (!api_is_allowed_to_session_edit()) {
  132. //api_not_allowed();
  133. }
  134. Display::display_header(get_lang('Session'));
  135. $session_select = array();
  136. foreach ($session_list as $item) {
  137. $session_select[$item['id']] = $item['name'];
  138. }
  139. // Session list form
  140. if (count($session_select) > 1) {
  141. $form = new FormValidator('exercise_admin', 'get', api_get_self().'?session_id='.$session_id);
  142. $form->addElement('select', 'session_id', get_lang('SessionList'), $session_select, 'onchange="javascript:change_session()"');
  143. $defaults['session_id'] = $session_id;
  144. $form->setDefaults($defaults);
  145. $form->display();
  146. }
  147. if (empty($session_id)) {
  148. $user_list = UserManager::get_user_list();
  149. } else {
  150. $user_list = SessionManager::get_users_by_session($session_id);
  151. }
  152. //Final data to be show
  153. $my_real_array = array();
  154. $new_exercises = array();
  155. $now = time();
  156. foreach ($final_array as $session_data) {
  157. $my_course_list = isset($session_data['data']) ? $session_data['data']: array();
  158. if (!empty($my_course_list))
  159. foreach ($my_course_list as $my_course_code => $course_data) {
  160. if (isset($course_id) && !empty($course_id)) {
  161. if ($course_id != $course_data['id']) {
  162. continue;
  163. }
  164. }
  165. if (!empty($course_data['exercises'])) {
  166. //Exercises
  167. foreach ($course_data['exercises'] as $my_exercise_id => $exercise_data) {
  168. $best_score_data = ExerciseLib::get_best_attempt_in_course($my_exercise_id, $course_data['id'], $session_id);
  169. $best_score = '';
  170. if (!empty($best_score_data)) {
  171. $best_score = ExerciseLib::show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']);
  172. }
  173. //Exercise results
  174. $counter = 1;
  175. foreach ($exercise_data as $exercise_item) {
  176. $result_list = $exercise_item['results'];
  177. $exercise_info = $exercise_item['exercise_data'];
  178. if ($exercise_info->start_time == '0000-00-00 00:00:00') {
  179. $start_date = '-';
  180. } else {
  181. $start_date = $exercise_info->start_time;
  182. }
  183. if (!empty($result_list)) {
  184. foreach ($result_list as $exercise_result) {
  185. $platform_score = ExerciseLib::show_score($exercise_result['exe_result'], $exercise_result['exe_weighting']);
  186. $my_score = 0;
  187. if(!empty($exercise_result['exe_weighting']) && intval($exercise_result['exe_weighting']) != 0) {
  188. $my_score = $exercise_result['exe_result']/$exercise_result['exe_weighting'];
  189. }
  190. $position = ExerciseLib::get_exercise_result_ranking($my_score, $exercise_result['exe_id'], $my_exercise_id, $course_data['id'], $session_id, $user_list);
  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. 'status' => Display::return_icon('quiz.gif', get_lang('Attempted'),'', ICON_SIZE_SMALL),
  194. 'date' => $start_date,
  195. 'course' => $course_data['name'],
  196. 'exercise' => $exercise_info->exercise,
  197. 'attempt' => $counter,
  198. 'result' => $platform_score,
  199. 'best_result' => $best_score,
  200. 'position' => $position
  201. );
  202. $counter++;
  203. }
  204. } else {
  205. //We check the date validation of the exercise if the user can make it
  206. if ($exercise_info->start_time != '0000-00-00 00:00:00') {
  207. $allowed_time = api_strtotime($exercise_info->start_time, 'UTC');
  208. if ($now < $allowed_time) {
  209. continue;
  210. }
  211. }
  212. $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));
  213. $new_exercises[] = array(
  214. 'status' => Display::return_icon('star.png', get_lang('New'), array('width'=>ICON_SIZE_SMALL)),
  215. 'date' => $start_date,
  216. 'course' => $course_data['name'],
  217. 'exercise' => $exercise_info->exercise,
  218. 'attempt' => '-',
  219. 'result' => '-',
  220. 'best_result' => '-',
  221. 'position' => '-'
  222. );
  223. }
  224. }
  225. }
  226. }
  227. }
  228. }
  229. $my_real_array = ArrayClass::msort($my_real_array, 'date', 'asc');
  230. if (!empty($new_exercises)) {
  231. $my_real_array = array_merge($new_exercises, $my_real_array);
  232. }
  233. $back_url = '';
  234. if (!empty($course_id)) {
  235. //$back_url = Display::url(Display::return_icon('back.png',get_lang('back.png')), api_get_path(WEB_CODE_PATH).'session/?session_id='.$session_id);
  236. }
  237. $dates = SessionManager::parse_session_dates($session_info);
  238. echo Display::page_header($back_url.' '.$session_info['name']." <small>$dates<small>");
  239. if (!empty($new_course_list)) {
  240. echo '<div id="session_course_list" class="row">';
  241. foreach ($new_course_list as $course_item) {
  242. echo '<div class="span3">';
  243. echo '<div class="big_icon">';
  244. echo Display::url(Display::return_icon('course.png', $course_item['only_title'], array(), ICON_SIZE_BIG), $course_item['link']);
  245. echo '</div>';
  246. echo '<div class="content">';
  247. echo $course_item['title'];
  248. echo '</div>';
  249. echo '</div>';
  250. }
  251. echo '</div>';
  252. }
  253. // All Learnpaths grid settings (First tab, first subtab)
  254. $columns_courses = array(get_lang('Title'), get_lang('NumberOfPublishedExercises'), get_lang('NumberOfPublishedLps'));
  255. $column_model_courses = array(
  256. array('name'=>'title', 'index'=>'title', 'width'=>'400px', 'align'=>'left', 'sortable'=>'true'),
  257. array('name'=>'exercise_count', 'index'=>'exercise_count', 'width'=>'180px', 'align'=>'left', 'sortable'=>'true'),
  258. array('name'=>'lp_count', 'index'=>'lp_count', 'width'=>'180px', 'align'=>'left', 'sortable'=>'true')
  259. );
  260. $extra_params_courses['height'] = '100%';
  261. $extra_params_courses['autowidth'] = 'true'; //use the width of the parent
  262. $url = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_default&session_id='.$session_id.'&course_id='.$course_id;
  263. $columns = array(get_lang('PublicationDate'), get_lang('Course'), get_lang('LearningPaths'));
  264. $column_model = array(
  265. array('name'=>'date', 'index'=>'date', 'width'=>'120', 'align'=>'left', 'sortable'=>'true'),
  266. array('name'=>'course', 'index'=>'course', 'width'=>'300', 'align'=>'left', 'sortable'=>'true', 'wrap_cell' => 'true'),
  267. array('name'=>'lp', 'index'=>'lp', 'width'=>'440', 'align'=>'left', 'sortable'=>'true')
  268. );
  269. $extra_params = array();
  270. /*
  271. $extra_params['sortname'] = 'date';
  272. $extra_params['sortorder'] = 'asc';
  273. $extra_params['pgbuttons'] = false;
  274. $extra_params['recordtext'] = '';
  275. $extra_params['pgtext'] = '';
  276. $extra_params['height'] = "100%";
  277. */
  278. //$extra_params['autowidth'] = 'true'; //use the width of the parent
  279. //$extra_params['width'] = '90%';
  280. //$extra_params['autowidth'] = 'true'; //use the width of the parent
  281. //$extra_params['forceFit'] = 'true'; //use the width of the parent
  282. //$extra_params['altRows'] = 'true'; //zebra style
  283. $extra_params['height'] = '100%';
  284. $extra_params['autowidth'] = 'true'; //use the width of the parent
  285. //Per course grid settings
  286. $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;
  287. $extra_params_course = array();
  288. $extra_params_course['grouping'] = 'true';
  289. $extra_params_course['groupingView'] = array('groupCollapse' => false,
  290. 'groupField' => array('course'),
  291. 'groupColumnShow' => array(false),
  292. 'groupText' => array('<b>'.get_lang('Course').' {0}</b>'));
  293. $extra_params_course['autowidth'] = 'true'; //use the width of the parent
  294. $extra_params_course['height'] = "100%";
  295. //Per Week grid
  296. $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;
  297. $column_week = array(get_lang('PeriodWeek'), get_lang('PublicationDate'), get_lang('Course'), get_lang('LearningPaths'));
  298. $column_week_model = array (
  299. array('name'=>'week', 'index'=>'week', 'width'=>'40', 'align'=>'left', 'sortable'=>'false'),
  300. array('name'=>'date', 'index'=>'date', 'width'=>'120', 'align'=>'left', 'sortable'=>'false'),
  301. array('name'=>'course', 'index'=>'course', 'width'=>'300', 'align'=>'left', 'sortable'=>'true', 'wrap_cell' => 'true'),
  302. array('name'=>'lp', 'index'=>'lp', 'width'=>'440', 'align'=>'left', 'sortable'=>'true')
  303. );
  304. $extra_params_week = array();
  305. $extra_params_week['grouping'] = 'true';
  306. //For more details see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:grouping
  307. $extra_params_week['groupingView'] = array(
  308. 'groupCollapse' => false,
  309. 'groupDataSorted' => false,
  310. 'groupField' => array('week'),
  311. 'groupOrder' => array('desc'),
  312. 'groupColumnShow' => false,
  313. 'groupText' => array('<b>'.get_lang('PeriodWeek').' {0}</b>')
  314. );
  315. $extra_params_week['autowidth'] = 'true'; //use the width of the parent
  316. $extra_params_week['height'] = '100%';
  317. //MyQCM grid
  318. $column_exercise = array(
  319. get_lang('Status'), get_lang('ExerciseStartDate'), get_lang('Course'), get_lang('Exercise'),get_lang('Attempts'), get_lang('Result'), get_lang('BestResultInCourse'), get_lang('Ranking')
  320. );
  321. $column_exercise_model = array(
  322. array('name'=>'status', 'index'=>'status', 'width'=>'40', 'align'=>'left', 'sortable'=>'false'),
  323. array('name'=>'date', 'index'=>'date', 'width'=>'130','align'=>'left', 'sortable'=>'true'),
  324. array('name'=>'course', 'index'=>'course', 'width'=>'200','align'=>'left', 'sortable'=>'true', 'wrap_cell' => 'true'),
  325. array('name'=>'exercise', 'index'=>'exercise', 'width'=>'200','align'=>'left', 'sortable'=>'false'),
  326. array('name'=>'attempt', 'index'=>'attempt', 'width'=>'60', 'align'=>'center', 'sortable'=>'true'),
  327. array('name'=>'result', 'index'=>'result', 'width'=>'120','align'=>'center', 'sortable'=>'true'),
  328. array('name'=>'best_result','index'=>'best_result','width'=>'140','align'=>'center', 'sortable'=>'true'),
  329. array('name'=>'position', 'index'=>'position', 'width'=>'55', 'align'=>'center', 'sortable'=>'true')
  330. );
  331. $extra_params_exercise['height'] = '100%';
  332. $extra_params_exercise['autowidth'] = 'true';
  333. //$extra_params_exercise['sortname'] = 'status';
  334. //$extra_params_exercise['sortorder'] = 'desc';
  335. //$extra_params_exercise['grouping'] = 'true';
  336. //$extra_params_exercise['groupingView'] = array('groupField'=>array('course'),'groupColumnShow'=>'false','groupText' => array('<b>'.get_lang('Course').' {0}</b>'));
  337. //$extra_params_exercise['groupingView'] = array('groupField'=>array('course'),'groupColumnShow'=>'false','groupText' => array('<b>'.get_lang('Course').' {0} - {1} Item(s)</b>'));
  338. ?>
  339. <br />
  340. <script>
  341. function change_session() {
  342. document.exercise_admin.submit();
  343. }
  344. $(function() {
  345. //js used when generating images on the fly see function Tracking::show_course_detail()
  346. $(".dialog").dialog("destroy");
  347. $(".dialog").dialog({
  348. autoOpen: false,
  349. show: "blind",
  350. resizable: false,
  351. height:300,
  352. width:550,
  353. modal: true
  354. });
  355. $(".opener").click(function() {
  356. var my_id = $(this).attr('id');
  357. var big_image = '#main_graph_' + my_id;
  358. $( big_image ).dialog("open");
  359. return false;
  360. });
  361. /* Binds a tab id in the url */
  362. $("#tabs").bind('tabsselect', function(event, ui) {
  363. window.location.href=ui.tab;
  364. });
  365. <?php
  366. //Displays js code to use a jqgrid
  367. echo Display::grid_js('courses', false, $columns_courses, $column_model_courses, $extra_params_courses, $new_course_list);
  368. echo Display::grid_js('list_default', $url, $columns, $column_model,$extra_params,array(), '');
  369. echo Display::grid_js('list_course', $url_by_course, $columns, $column_model,$extra_params_course,array(),'');
  370. echo Display::grid_js('list_week', $url_week, $column_week, $column_week_model, $extra_params_week,array(),'');
  371. echo Display::grid_js('exercises', '', $column_exercise, $column_exercise_model, $extra_params_exercise, $my_real_array);
  372. ?>
  373. // Generate tabs with jquery-ui
  374. $('#tabs').tabs();
  375. $( "#sub_tab" ).tabs();
  376. });
  377. </script>
  378. <?php
  379. $my_reporting = Tracking::show_user_progress(api_get_user_id(), $session_id, '#tabs-4', false);
  380. if (!empty($my_reporting)) {
  381. $my_reporting .= '<br />'.Tracking::show_course_detail(api_get_user_id(), $_GET['course'], $session_id);
  382. }
  383. if (empty($my_reporting)) {
  384. $my_reporting = Display::return_message(get_lang('NoDataAvailable'), 'warning');
  385. }
  386. // Main headers
  387. $headers = array(get_lang('Courses'), get_lang('LearningPaths'), get_lang('MyQCM'), get_lang('MyStatistics'));
  388. // Subheaders
  389. $sub_header = array(get_lang('AllLearningPaths'), get_lang('PerWeek'), get_lang('ByCourse'));
  390. //Sub headers data
  391. $lp_tabs = Display::tabs($sub_header, array(Display::grid_html('list_default'), Display::grid_html('list_week'), Display::grid_html('list_course')), 'sub_tab');
  392. $courses_tab = Display::grid_html('courses');
  393. //Main headers data
  394. echo Display::tabs($headers, array($courses_tab, $lp_tabs, Display::grid_html('exercises'), $my_reporting));
  395. Display::display_footer();