index.php 35 KB

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