index.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Gradebook controller
  5. * @package chamilo.gradebook
  6. */
  7. $language_file = array('gradebook', 'exercice');
  8. // $cidReset : This is the main difference with gradebook.php, here we say,
  9. // basically, that we are inside a course, and many things depend from that
  10. //$cidReset = false;
  11. $_in_course = true;
  12. require_once '../inc/global.inc.php';
  13. $current_course_tool = TOOL_GRADEBOOK;
  14. api_protect_course_script();
  15. $course_code = api_get_course_id();
  16. $stud_id = api_get_user_id();
  17. $session_id = api_get_session_id();
  18. //make sure the destination for scripts is index.php instead of gradebook.php
  19. $_SESSION['gradebook_dest'] = 'index.php';
  20. $this_section = SECTION_COURSES;
  21. /*
  22. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/jqplot/jquery.jqplot.min.css');
  23. $htmlHeadXtra[] = api_get_js('jqplot/jquery.jqplot.min.js');
  24. $htmlHeadXtra[] = api_get_js('jqplot/plugins/jqplot.donutRenderer.min.js');*/
  25. $htmlHeadXtra[] = '<script>
  26. var show_icon = "../img/view_more_stats.gif";
  27. var hide_icon = "../img/view_less_stats.gif";
  28. $(document).ready(function() {
  29. $("body").on("click", ".view_children", function() {
  30. var id = $(this).attr("data-cat-id");
  31. $(".hidden_"+id).removeClass("hidden");
  32. $(this).removeClass("view_children");
  33. $(this).find("img").attr("src", hide_icon);
  34. $(this).attr("class", "hide_children");
  35. });
  36. $("body").on("click", ".hide_children", function(event) {
  37. var id = $(this).attr("data-cat-id");
  38. $(".hidden_"+id).addClass("hidden");
  39. $(this).removeClass("hide_children");
  40. $(this).addClass("view_children");
  41. $(this).find("img").attr("src", show_icon);
  42. });
  43. /*
  44. var s1 = [["a",25]];
  45. var s2 = [["a", 0], ["a", 10], ["a", 10], ["a", 5]];
  46. var plot3 = $.jqplot("chart3", [s1, s2], {
  47. colors: ["#000", "#fff"],
  48. seriesDefaults: {
  49. // make this a donut chart.
  50. renderer:$.jqplot.DonutRenderer,
  51. rendererOptions:{
  52. // Donuts can be cut into slices like pies.
  53. sliceMargin: 3 ,
  54. // Pies and donuts can start at any arbitrary angle.
  55. startAngle: -90,
  56. showDataLabels: true,
  57. // By default, data labels show the percentage of the donut/pie.
  58. // You can show the data "value" or data "label" instead.
  59. dataLabels: "value"
  60. }
  61. }
  62. });*/
  63. for (i=0;i<$(".actions").length;i++) {
  64. if ($(".actions:eq("+i+")").html()=="<table border=\"0\"></table>" || $(".actions:eq("+i+")").html()=="" || $(".actions:eq("+i+")").html()==null || $(".actions:eq("+i+")").html().split("<TBODY></TBODY>").length==2) {
  65. $(".actions:eq("+i+")").hide();
  66. }
  67. }
  68. });
  69. </script>';
  70. api_block_anonymous_users();
  71. $htmlHeadXtra[]= '<script type="text/javascript">
  72. function confirmation() {
  73. if (confirm("' . get_lang('DeleteAll') . '?")) {
  74. return true;
  75. } else {
  76. return false;
  77. }
  78. }
  79. </script>';
  80. $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
  81. $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
  82. $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  83. $filter_confirm_msg = true;
  84. $filter_warning_msg = true;
  85. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  86. $first_time = null;
  87. if (empty($cats)) {
  88. //first time
  89. $cats = Category :: load(0, null, $course_code, null, null, $session_id, false);
  90. $first_time = 1;
  91. }
  92. $_GET['selectcat'] = $cats[0]->get_id();
  93. if (isset($_GET['isStudentView'])) {
  94. if ( (isset($_GET['selectcat']) && $_GET['selectcat']>0) && (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) {
  95. $interbreadcrumb[]= array ('url' => 'index.php'.'?selectcat=0&amp;isStudentView='.$_GET['isStudentView'],'name' => get_lang('ToolGradebook'));
  96. }
  97. }
  98. if ((isset($_GET['selectcat']) && $_GET['selectcat']>0) &&
  99. (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview')
  100. ) {
  101. Display :: display_header();
  102. //Introduction tool: student view
  103. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  104. $category = $_GET['selectcat'];
  105. $cats = Category :: load ($category, null, null, null, null, null, false);
  106. $allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  107. $alleval = $cats[0]->get_evaluations($stud_id);
  108. $alllink = $cats[0]->get_links($stud_id);
  109. $addparams = array();
  110. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  111. $gradebooktable->display();
  112. Display :: display_footer();
  113. exit;
  114. } else {
  115. if (!isset($_GET['selectcat']) &&
  116. ($_SESSION['studentview']=='studentview') ||
  117. (isset($_GET['isStudentView']) && $_GET['isStudentView']=='true')
  118. ) {
  119. Display :: display_header(get_lang('Gradebook'));
  120. //Introduction tool: student view
  121. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  122. $addparams=array();
  123. $cats = Category :: load (0, null, null, null, null, null, false);
  124. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  125. $alleval= $cats[0]->get_evaluations($stud_id);
  126. $alllink= $cats[0]->get_links($stud_id);
  127. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  128. $gradebooktable->display();
  129. Display :: display_footer();
  130. exit;
  131. }
  132. }
  133. // ACTIONS
  134. //this is called when there is no data for the course admin
  135. if (isset ($_GET['createallcategories'])) {
  136. GradebookUtils::block_students();
  137. $coursecat= Category :: get_not_created_course_categories($stud_id);
  138. if (!count($coursecat) == 0) {
  139. foreach ($coursecat as $row) {
  140. $cat= new Category();
  141. $cat->set_name($row[1]);
  142. $cat->set_course_code($row[0]);
  143. $cat->set_description(null);
  144. $cat->set_user_id($stud_id);
  145. $cat->set_parent_id(0);
  146. $cat->set_weight(0);
  147. $cat->set_visible(0);
  148. $cat->add();
  149. unset ($cat);
  150. }
  151. }
  152. header('Location: '.$_SESSION['gradebook_dest'].'?addallcat=&selectcat=0');
  153. exit;
  154. }
  155. //show logs evaluations
  156. if (isset ($_GET['visiblelog'])) {
  157. header('Location: ' . api_get_self().'/gradebook_showlog_eval.php');
  158. exit;
  159. }
  160. //move a category
  161. if (isset ($_GET['movecat'])) {
  162. GradebookUtils::block_students();
  163. $cats= Category :: load($_GET['movecat']);
  164. if (!isset ($_GET['targetcat'])) {
  165. $move_form= new CatForm(CatForm :: TYPE_MOVE,
  166. $cats[0],
  167. 'move_cat_form',
  168. null,
  169. api_get_self() . '?movecat=' . Security::remove_XSS($_GET['movecat'])
  170. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  171. if ($move_form->validate()) {
  172. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  173. . '&movecat=' . Security::remove_XSS($_GET['movecat'])
  174. . '&targetcat=' . $move_form->exportValue('move_cat'));
  175. exit;
  176. }
  177. } else {
  178. $targetcat= Category :: load($_GET['targetcat']);
  179. $course_to_crsind = ($cats[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  180. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  181. $cats[0]->move_to_cat($targetcat[0]);
  182. header('Location: ' . api_get_self() . '?categorymoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  183. exit;
  184. }
  185. unset ($targetcat);
  186. }
  187. unset ($cats);
  188. }
  189. //move an evaluation
  190. if (isset ($_GET['moveeval'])) {
  191. GradebookUtils::block_students();
  192. $evals= Evaluation :: load($_GET['moveeval']);
  193. if (!isset ($_GET['targetcat'])) {
  194. $move_form= new EvalForm(EvalForm :: TYPE_MOVE,
  195. $evals[0],
  196. null,
  197. 'move_eval_form',
  198. null,
  199. api_get_self() . '?moveeval=' . Security::remove_XSS($_GET['moveeval'])
  200. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  201. if ($move_form->validate()) {
  202. header('Location: ' .api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  203. . '&moveeval=' . Security::remove_XSS($_GET['moveeval'])
  204. . '&targetcat=' . $move_form->exportValue('move_cat'));
  205. exit;
  206. }
  207. } else {
  208. $targetcat= Category :: load($_GET['targetcat']);
  209. $course_to_crsind = ($evals[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  210. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  211. $evals[0]->move_to_cat($targetcat[0]);
  212. header('Location: ' . api_get_self() . '?evaluationmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  213. exit;
  214. }
  215. unset ($targetcat);
  216. }
  217. unset ($evals);
  218. }
  219. //move a link
  220. if (isset ($_GET['movelink'])) {
  221. GradebookUtils::block_students();
  222. $link= LinkFactory :: load($_GET['movelink']);
  223. $move_form = new LinkForm(
  224. LinkForm :: TYPE_MOVE,
  225. null,
  226. $link[0],
  227. 'move_link_form',
  228. null,
  229. api_get_self() . '?movelink=' . $_GET['movelink'] . '&selectcat=' . Security::remove_XSS($_GET['selectcat'])
  230. );
  231. if ($move_form->validate()) {
  232. $targetcat= Category :: load($move_form->exportValue('move_cat'));
  233. $link[0]->move_to_cat($targetcat[0]);
  234. unset ($link);
  235. header('Location: ' . api_get_self(). '?linkmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  236. exit;
  237. }
  238. }
  239. //parameters for categories
  240. if (isset ($_GET['visiblecat'])) {
  241. GradebookUtils::block_students();
  242. if (isset ($_GET['set_visible'])) {
  243. $visibility_command= 1;
  244. } else {
  245. $visibility_command= 0;
  246. }
  247. $cats= Category :: load($_GET['visiblecat']);
  248. $cats[0]->set_visible($visibility_command);
  249. $cats[0]->save();
  250. $cats[0]->apply_visibility_to_children();
  251. unset ($cats);
  252. if ($visibility_command) {
  253. $confirmation_message = get_lang('ViMod');
  254. $filter_confirm_msg = false;
  255. } else {
  256. $confirmation_message = get_lang('InViMod');
  257. $filter_confirm_msg = false;
  258. }
  259. }
  260. if (isset($_GET['deletecat'])) {
  261. GradebookUtils::block_students();
  262. $cats = Category :: load($_GET['deletecat']);
  263. if (isset($cats[0])) {
  264. //delete all categories,subcategories and results
  265. if ($cats[0] != null) {
  266. if ($cats[0]->get_id() != 0) {
  267. // better don't try to delete the root...
  268. $cats[0]->delete_all();
  269. }
  270. }
  271. }
  272. $confirmation_message = get_lang('CategoryDeleted');
  273. $filter_confirm_msg = false;
  274. }
  275. //parameters for evaluations
  276. if (isset ($_GET['visibleeval'])) {
  277. GradebookUtils::block_students();
  278. if (isset ($_GET['set_visible'])) {
  279. $visibility_command= 1;
  280. } else {
  281. $visibility_command= 0;
  282. }
  283. $eval= Evaluation :: load($_GET['visibleeval']);
  284. $eval[0]->set_visible($visibility_command);
  285. $eval[0]->save();
  286. unset ($eval);
  287. if ($visibility_command) {
  288. $confirmation_message = get_lang('ViMod');
  289. $filter_confirm_msg = false;
  290. } else {
  291. $confirmation_message = get_lang('InViMod');
  292. $filter_confirm_msg = false;
  293. }
  294. }
  295. //parameters for evaluations
  296. if (isset($_GET['lockedeval'])) {
  297. GradebookUtils::block_students();
  298. $locked = Security::remove_XSS($_GET['lockedeval']);
  299. if (isset($_GET['typelocked']) && api_is_platform_admin()){
  300. $type_locked = 0;
  301. $confirmation_message = get_lang('EvaluationHasBeenUnLocked');
  302. } else {
  303. $type_locked = 1;
  304. $confirmation_message = get_lang('EvaluationHasBeenLocked');
  305. }
  306. $eval = Evaluation :: load($locked);
  307. if ($eval[0] != null) {
  308. $eval[0]->lock($type_locked);
  309. }
  310. $filter_confirm_msg = false;
  311. }
  312. if (isset ($_GET['deleteeval'])) {
  313. GradebookUtils::block_students();
  314. $eval= Evaluation :: load($_GET['deleteeval']);
  315. if ($eval[0] != null) {
  316. $eval[0]->delete_with_results();
  317. }
  318. $confirmation_message = get_lang('GradebookEvaluationDeleted');
  319. $filter_confirm_msg = false;
  320. }
  321. //parameters for links
  322. if (isset ($_GET['visiblelink'])) {
  323. GradebookUtils::block_students();
  324. if (isset ($_GET['set_visible'])) {
  325. $visibility_command= 1;
  326. } else {
  327. $visibility_command= 0;
  328. }
  329. $link= LinkFactory :: load($_GET['visiblelink']);
  330. if (isset($link) && isset($link[0])) {
  331. $link[0]->set_visible($visibility_command);
  332. $link[0]->save();
  333. }
  334. unset ($link);
  335. if ($visibility_command) {
  336. $confirmation_message = get_lang('ViMod');
  337. $filter_confirm_msg = false;
  338. } else {
  339. $confirmation_message = get_lang('InViMod');
  340. $filter_confirm_msg = false;
  341. }
  342. }
  343. $course_id = api_get_course_int_id();
  344. if (isset ($_GET['deletelink'])) {
  345. GradebookUtils::block_students();
  346. $get_delete_link = intval($_GET['deletelink']);
  347. //fixing #5229
  348. if (!empty($get_delete_link)) {
  349. $link= LinkFactory :: load($get_delete_link);
  350. if ($link[0] != null) {
  351. // clean forum qualify
  352. $sql = 'UPDATE '.$tbl_forum_thread.' SET thread_qualify_max=0,thread_weight=0,thread_title_qualify=""
  353. WHERE c_id = '.$course_id.' AND thread_id = (
  354. SELECT ref_id FROM '.$tbl_grade_links.'
  355. WHERE id='.$get_delete_link.' AND type = '.LINK_FORUM_THREAD.'
  356. )';
  357. Database::query($sql);
  358. // clean attendance
  359. $sql = 'UPDATE '.$tbl_attendance.' SET attendance_qualify_max=0, attendance_weight = 0, attendance_qualify_title=""
  360. WHERE c_id = '.$course_id.' AND id = (
  361. SELECT ref_id FROM '.$tbl_grade_links.'
  362. WHERE id='.$get_delete_link.' AND type = '.LINK_ATTENDANCE.'
  363. )';
  364. Database::query($sql);
  365. $link[0]->delete();
  366. }
  367. unset ($link);
  368. $confirmation_message = get_lang('LinkDeleted');
  369. $filter_confirm_msg = false;
  370. }
  371. }
  372. if (!empty($course_to_crsind) && !isset($_GET['confirm'])) {
  373. GradebookUtils::block_students();
  374. if (!isset($_GET['movecat']) && !isset($_GET['moveeval'])) {
  375. die ('Error: movecat or moveeval not defined');
  376. }
  377. $button = '<form name="confirm" method="post" action="'.api_get_self() .'?confirm='
  378. .(isset($_GET['movecat']) ? '&movecat=' . Security::remove_XSS($_GET['movecat'])
  379. : '&moveeval=' . Security::remove_XSS($_GET['moveeval']) )
  380. .'&selectcat=' . Security::remove_XSS($_GET['selectcat'])
  381. .'&targetcat=' . Security::remove_XSS($_GET['targetcat']).'">
  382. <input type="submit" value="'.get_lang('Ok').'">
  383. </form>';
  384. $warning_message = get_lang('MoveWarning').'<br><br>'.$button;
  385. $filter_warning_msg = false;
  386. }
  387. $action = isset($_GET['action']) ? $_GET['action'] : null;
  388. switch ($action) {
  389. case 'lock':
  390. $category_to_lock = Category :: load($_GET['category_id']);
  391. $category_to_lock[0]->lock_all_items(1);
  392. $confirmation_message = get_lang('GradebookLockedAlert');
  393. break;
  394. case 'unlock':
  395. if (api_is_platform_admin()) {
  396. $category_to_lock = Category :: load($_GET['category_id']);
  397. $category_to_lock[0]->lock_all_items(0);
  398. $confirmation_message = get_lang('EvaluationHasBeenUnLocked');
  399. }
  400. break;
  401. }
  402. //actions on the sortabletable
  403. if (isset ($_POST['action'])) {
  404. GradebookUtils::block_students();
  405. $number_of_selected_items= count($_POST['id']);
  406. if ($number_of_selected_items == '0') {
  407. $warning_message = get_lang('NoItemsSelected');
  408. $filter_warning_msg = false;
  409. } else {
  410. switch ($_POST['action']) {
  411. case 'deleted' :
  412. $number_of_deleted_categories= 0;
  413. $number_of_deleted_evaluations= 0;
  414. $number_of_deleted_links= 0;
  415. foreach ($_POST['id'] as $indexstr) {
  416. if (substr($indexstr, 0, 4) == 'CATE') {
  417. $cats= Category :: load(substr($indexstr, 4));
  418. if ($cats[0] != null) {
  419. $cats[0]->delete_all();
  420. }
  421. $number_of_deleted_categories++;
  422. }
  423. if (substr($indexstr, 0, 4) == 'EVAL') {
  424. $eval= Evaluation :: load(substr($indexstr, 4));
  425. if ($eval[0] != null) {
  426. $eval[0]->delete_with_results();
  427. }
  428. $number_of_deleted_evaluations++;
  429. }
  430. if (substr($indexstr, 0, 4) == 'LINK') {
  431. //fixing #5229
  432. $id = substr($indexstr, 4);
  433. if (!empty($id)) {
  434. $link= LinkFactory :: load($id);
  435. if ($link[0] != null) {
  436. $link[0]->delete();
  437. }
  438. $number_of_deleted_links++;
  439. }
  440. }
  441. }
  442. $confirmation_message = get_lang('DeletedCategories') . ' : <b>' . $number_of_deleted_categories . '</b><br />' . get_lang('DeletedEvaluations') . ' : <b>' . $number_of_deleted_evaluations . '</b><br />' . get_lang('DeletedLinks') . ' : <b>' . $number_of_deleted_links . '</b><br /><br />' . get_lang('TotalItems') . ' : <b>' . $number_of_selected_items . '</b>';
  443. $filter_confirm_msg = false;
  444. break;
  445. case 'setvisible' :
  446. foreach ($_POST['id'] as $indexstr) {
  447. if (substr($indexstr, 0, 4) == 'CATE') {
  448. $cats= Category :: load(substr($indexstr, 4));
  449. $cats[0]->set_visible(1);
  450. $cats[0]->save();
  451. $cats[0]->apply_visibility_to_children();
  452. }
  453. if (substr($indexstr, 0, 4) == 'EVAL') {
  454. $eval= Evaluation :: load(substr($indexstr, 4));
  455. $eval[0]->set_visible(1);
  456. $eval[0]->save();
  457. }
  458. if (substr($indexstr, 0, 4) == 'LINK') {
  459. $link= LinkFactory :: load(substr($indexstr, 4));
  460. $link[0]->set_visible(1);
  461. $link[0]->save();
  462. }
  463. }
  464. $confirmation_message = get_lang('ItemsVisible');
  465. $filter_confirm_msg = false;
  466. break;
  467. case 'setinvisible' :
  468. foreach ($_POST['id'] as $indexstr) {
  469. if (substr($indexstr, 0, 4) == 'CATE') {
  470. $cats= Category :: load(substr($indexstr, 4));
  471. $cats[0]->set_visible(0);
  472. $cats[0]->save();
  473. $cats[0]->apply_visibility_to_children();
  474. }
  475. if (substr($indexstr, 0, 4) == 'EVAL') {
  476. $eval= Evaluation :: load(substr($indexstr, 4));
  477. $eval[0]->set_visible(0);
  478. $eval[0]->save();
  479. }
  480. if (substr($indexstr, 0, 4) == 'LINK') {
  481. $link= LinkFactory :: load(substr($indexstr, 4));
  482. $link[0]->set_visible(0);
  483. $link[0]->save();
  484. }
  485. }
  486. $confirmation_message = get_lang('ItemsInVisible');
  487. $filter_confirm_msg = false;
  488. break;
  489. }
  490. }
  491. }
  492. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  493. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  494. . '&search='.Security::remove_XSS($_POST['keyword']));
  495. exit;
  496. }
  497. // DISPLAY HEADERS AND MESSAGES
  498. if (!isset($_GET['exportpdf'])) {
  499. if (isset ($_GET['studentoverview'])) {
  500. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('ToolGradebook'));
  501. Display :: display_header(get_lang('FlatView'));
  502. } elseif (isset ($_GET['search'])) {
  503. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('ToolGradebook'));
  504. Display :: display_header(get_lang('SearchResults'));
  505. } elseif(isset ($_GET['selectcat'])) {
  506. $interbreadcrumb[]= array ( 'url' =>'#','name' => get_lang('ToolGradebook'));
  507. if (!isset($_GET['gradebooklist_direction'])) {
  508. //$interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('Details'));
  509. }
  510. Display :: display_header('');
  511. } else {
  512. Display :: display_header(get_lang('ToolGradebook'));
  513. }
  514. }
  515. if (isset ($_GET['categorymoved'])) {
  516. Display :: display_confirmation_message(get_lang('CategoryMoved'),false);
  517. }
  518. if (isset ($_GET['evaluationmoved'])) {
  519. Display :: display_confirmation_message(get_lang('EvaluationMoved'),false);
  520. }
  521. if (isset ($_GET['linkmoved'])) {
  522. Display :: display_confirmation_message(get_lang('LinkMoved'),false);
  523. }
  524. if (isset ($_GET['addcat'])) {
  525. Display :: display_confirmation_message(get_lang('CategoryAdded'),false);
  526. }
  527. if (isset ($_GET['linkadded'])) {
  528. Display :: display_confirmation_message(get_lang('LinkAdded'),false);
  529. }
  530. if (isset ($_GET['addresult'])) {
  531. Display :: display_confirmation_message(get_lang('ResultAdded'),false);
  532. }
  533. if (isset ($_GET['editcat'])) {
  534. Display :: display_confirmation_message(get_lang('CategoryEdited'),false);
  535. }
  536. if (isset ($_GET['editeval'])) {
  537. Display :: display_confirmation_message(get_lang('EvaluationEdited'),false);
  538. }
  539. if (isset ($_GET['linkedited'])) {
  540. Display :: display_confirmation_message(get_lang('LinkEdited'),false);
  541. }
  542. if (isset ($_GET['nolinkitems'])){
  543. Display :: display_warning_message(get_lang('NoLinkItems'),false);
  544. }
  545. if (isset ($_GET['addallcat'])){
  546. Display :: display_normal_message(get_lang('AddAllCat'),false);
  547. }
  548. if (isset ($confirmation_message)){
  549. Display :: display_confirmation_message($confirmation_message,$filter_confirm_msg);
  550. }
  551. if (isset ($warning_message)){
  552. Display :: display_warning_message($warning_message,$filter_warning_msg);
  553. }
  554. if (isset ($move_form)){
  555. Display :: display_normal_message($move_form->toHtml(),false);
  556. }
  557. // LOAD DATA & DISPLAY TABLE
  558. $is_platform_admin = api_is_platform_admin();
  559. $is_course_admin = api_is_allowed_to_edit(null, true);
  560. //load data for category, evaluation and links
  561. if (empty($_GET['selectcat'])) {
  562. $category= 0;
  563. } else {
  564. $category= $_GET['selectcat'];
  565. }
  566. $simple_search_form='';
  567. if (isset($_GET['studentoverview'])) {
  568. //@todo this code also seems to be deprecated ...
  569. $cats= Category :: load($category);
  570. $stud_id= (api_is_allowed_to_edit() ? null : $stud_id);
  571. $allcat= array ();
  572. $alleval= $cats[0]->get_evaluations($stud_id, true);
  573. $alllink= $cats[0]->get_links($stud_id, true);
  574. if (isset ($_GET['exportpdf'])) {
  575. $datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
  576. $header_names = array(get_lang('Name'),get_lang('Description'),get_lang('Weight'),get_lang('Date'),get_lang('Results'));
  577. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  578. $newarray = array();
  579. foreach ($data_array as $data) {
  580. $newarray[] = array_slice($data, 1);
  581. }
  582. $pdf= new Cezpdf();
  583. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  584. $pdf->ezSetMargins(30, 30, 50, 30);
  585. $pdf->ezSetY(810);
  586. $pdf->ezText(get_lang('FlatView').' ('. api_convert_and_format_date(null, DATE_FORMAT_SHORT). ' ' . api_convert_and_format_date(null, TIME_NO_SEC_FORMAT) .')',12,array('justification'=>'center'));
  587. $pdf->line(50,790,550,790);
  588. $pdf->line(50,40,550,40);
  589. $pdf->ezSetY(750);
  590. $pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=> 500));
  591. $pdf->ezStream();
  592. exit;
  593. }
  594. } else {
  595. //Student view
  596. //in any other case (no search, no pdf), print the available gradebooks
  597. // Important note: loading a category will actually load the *contents* of
  598. // this category. This means that, to show the categories of a course,
  599. // we have to show the root category and show its subcategories that
  600. // are inside this course. This is done at the time of calling
  601. // $cats[0]->get_subcategories(), not at the time of doing Category::load()
  602. // $category comes from GET['selectcat']
  603. //if $category = 0 (which happens when GET['selectcat'] is undefined)
  604. // then Category::load() will create a new 'root' category with empty
  605. // course and session fields in memory (Category::create_root_category())
  606. if ($_in_course === true) {
  607. // When *inside* a course, we want to make sure there is one (and only
  608. // one) category for this course or for this session.
  609. //hack for delete a gradebook from inside course
  610. /*
  611. $clean_deletecat = isset($_GET['deletecat']) ? intval($_GET['deletecat']) : null;
  612. if (!empty($clean_deletecat)) {
  613. exit;
  614. }
  615. //end hack*/
  616. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  617. if (empty($cats)) {
  618. // There is no category for this course+session, so create one
  619. $cat= new Category();
  620. if (!empty($session_id)) {
  621. $s_name = api_get_session_name($session_id);
  622. $cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name);
  623. $cat->set_session_id($session_id);
  624. } else {
  625. $cat->set_name($course_code);
  626. }
  627. $cat->set_course_code($course_code);
  628. $cat->set_description(null);
  629. $cat->set_user_id($stud_id);
  630. $cat->set_parent_id(0);
  631. $cat->set_weight(100);
  632. $cat->set_visible(0);
  633. $cat->set_certificate_min_score(75);
  634. $can_edit = api_is_allowed_to_edit(true, true);
  635. if ($can_edit) {
  636. $cat->add();
  637. }
  638. unset ($cat);
  639. }
  640. unset($cats);
  641. }
  642. $cats = Category::load($category, null, null, null, null, null, false);
  643. //with this fix the teacher only can view 1 gradebook
  644. if (api_is_platform_admin()) {
  645. $stud_id = (api_is_allowed_to_edit() ? null : api_get_user_id());
  646. } else {
  647. $stud_id = $stud_id;
  648. }
  649. $allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  650. $alleval = $cats[0]->get_evaluations($stud_id);
  651. $alllink = $cats[0]->get_links($stud_id);
  652. //whether we found a category or not, we now have a category object with
  653. // empty or full subcats
  654. }
  655. // add params to the future links (in the table shown)
  656. $addparams = array ('selectcat' => $cats[0]->get_id());
  657. if (isset ($_GET['studentoverview'])) {
  658. $addparams['studentoverview'] = '';
  659. }
  660. //$addparams['cidReq']='';
  661. if (isset($_GET['cidReq']) && $_GET['cidReq']!='') {
  662. $addparams['cidReq']=Security::remove_XSS($_GET['cidReq']);
  663. } else {
  664. $addparams['cidReq']='';
  665. }
  666. $no_qualification = false;
  667. // Show certificate link.
  668. $certificate = array();
  669. if ($category != '0') {
  670. $cat = new Category();
  671. $category_id = intval($_GET['selectcat']);
  672. $course_id = CourseManager::get_course_by_category($category_id);
  673. $show_message = $cat->show_message_resource_delete($course_id);
  674. if ($show_message == '') {
  675. // Student
  676. if (!api_is_allowed_to_edit() && !apiIsExcludedUserType()) {
  677. $certificate = Category::register_user_certificate(
  678. $category_id,
  679. $stud_id
  680. );
  681. if (!empty($certificate)) {
  682. echo '<div class="actions" align="right">';
  683. echo $certificate['pdf_link'];
  684. echo '</div>';
  685. }
  686. }
  687. }
  688. }
  689. if (api_is_allowed_to_edit(null, true)) {
  690. // Tool introduction
  691. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  692. if ((isset ($_GET['selectcat']) && $_GET['selectcat']<>0)) {
  693. //
  694. } else {
  695. if ((
  696. (isset ($_GET['selectcat']) && $_GET['selectcat'] == 0) || (
  697. (isset($_GET['cidReq']) && $_GET['cidReq'] !== ''))
  698. ) ||
  699. isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false'
  700. ) {
  701. $cats = Category:: load(
  702. null,
  703. null,
  704. $course_code,
  705. null,
  706. null,
  707. $session_id,
  708. false
  709. );
  710. }
  711. }
  712. }
  713. if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
  714. echo '<meta http-equiv="refresh" content="0;url='.api_get_self().'?cidReq='.$course_code.'" />';
  715. } else {
  716. $cats = Category::load(null, null, $course_code, null, null, $session_id, false);
  717. if (!empty($cats)) {
  718. if ((api_get_setting('gradebook_enable_grade_model') == 'true') &&
  719. (
  720. api_is_platform_admin() || (api_is_allowed_to_edit(null, true) &&
  721. api_get_setting('teachers_can_change_grade_model_settings') == 'true')
  722. )
  723. ) {
  724. // Getting grade models.
  725. $obj = new GradeModel();
  726. $grade_models = $obj->get_all();
  727. $grade_model_id = $cats[0]->get_grade_model_id();
  728. // No children.
  729. if ((count($cats) == 1 && empty($grade_model_id)) ||
  730. (count($cats) == 1 && $grade_model_id != -1)
  731. ) {
  732. if (!empty($grade_models)) {
  733. $form_grade = new FormValidator('grade_model_settings');
  734. $obj->fill_grade_model_select_in_form($form_grade, 'grade_model_id', $grade_model_id);
  735. $form_grade->addElement('style_submit_button', 'submit', get_lang('Save'), 'class="save"');
  736. if ($form_grade->validate()) {
  737. $value = $form_grade->exportValue('grade_model_id');
  738. $gradebook = new Gradebook();
  739. $gradebook->update(array('id'=> $cats[0]->get_id(), 'grade_model_id' => $value), true);
  740. //do something
  741. $obj = new GradeModel();
  742. $components = $obj->get_components($value);
  743. foreach ($components as $component) {
  744. $gradebook = new Gradebook();
  745. $params = array();
  746. $params['name'] = $component['acronym'];
  747. $params['description'] = $component['title'];
  748. $params['user_id'] = api_get_user_id();
  749. $params['parent_id'] = $cats[0]->get_id();
  750. $params['weight'] = $component['percentage'];
  751. $params['session_id'] = api_get_session_id();
  752. $params['course_code'] = api_get_course_id();
  753. $params['grade_model_id'] = api_get_session_id();
  754. $gradebook->save($params);
  755. }
  756. // Reloading cats
  757. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  758. } else {
  759. $form_grade->display();
  760. }
  761. }
  762. }
  763. }
  764. $i = 0;
  765. $allcat = array();
  766. /** @var Category $cat */
  767. foreach ($cats as $cat) {
  768. $allcat = $cat->get_subcategories($stud_id, $course_code, $session_id);
  769. $alleval = $cat->get_evaluations($stud_id);
  770. $alllink = $cat->get_links($stud_id, true);
  771. if ($cat->get_parent_id() != 0) {
  772. $i++;
  773. } else {
  774. // This is the father
  775. // Create gradebook/add gradebook links.
  776. DisplayGradebook::display_header_gradebook(
  777. $cat,
  778. 0,
  779. $cat->get_id(),
  780. $is_course_admin,
  781. $is_platform_admin,
  782. $simple_search_form,
  783. false,
  784. true,
  785. $certificate
  786. );
  787. if (api_is_allowed_to_edit(null,true) &&
  788. api_get_setting('gradebook_enable_grade_model') == 'true'
  789. ) {
  790. //Showing the grading system
  791. if (!empty($grade_models[$grade_model_id])) {
  792. Display::display_normal_message(get_lang('GradeModel').': '.$grade_models[$grade_model_id]['name']);
  793. }
  794. }
  795. $gradebooktable = new GradebookTable($cat, $allcat, $alleval, $alllink, $addparams);
  796. $gradebooktable->display();
  797. }
  798. }
  799. }
  800. }
  801. Display :: display_footer();