index.php 35 KB

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