index.php 36 KB

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