index.php 35 KB

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