index.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  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. /*
  21. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/jqplot/jquery.jqplot.min.css');
  22. $htmlHeadXtra[] = api_get_js('jqplot/jquery.jqplot.min.js');
  23. $htmlHeadXtra[] = api_get_js('jqplot/plugins/jqplot.donutRenderer.min.js');*/
  24. $htmlHeadXtra[] = '<script>
  25. var show_icon = "../img/view_more_stats.gif";
  26. var hide_icon = "../img/view_less_stats.gif";
  27. $(document).ready(function() {
  28. $("body").on("click", ".view_children", function() {
  29. var id = $(this).attr("data-cat-id");
  30. $(".hidden_"+id).removeClass("hidden");
  31. $(this).removeClass("view_children");
  32. $(this).find("img").attr("src", hide_icon);
  33. $(this).attr("class", "hide_children");
  34. });
  35. $("body").on("click", ".hide_children", function(event) {
  36. var id = $(this).attr("data-cat-id");
  37. $(".hidden_"+id).addClass("hidden");
  38. $(this).removeClass("hide_children");
  39. $(this).addClass("view_children");
  40. $(this).find("img").attr("src", show_icon);
  41. });
  42. /*
  43. var s1 = [["a",25]];
  44. var s2 = [["a", 0], ["a", 10], ["a", 10], ["a", 5]];
  45. var plot3 = $.jqplot("chart3", [s1, s2], {
  46. colors: ["#000", "#fff"],
  47. seriesDefaults: {
  48. // make this a donut chart.
  49. renderer:$.jqplot.DonutRenderer,
  50. rendererOptions:{
  51. // Donuts can be cut into slices like pies.
  52. sliceMargin: 3 ,
  53. // Pies and donuts can start at any arbitrary angle.
  54. startAngle: -90,
  55. showDataLabels: true,
  56. // By default, data labels show the percentage of the donut/pie.
  57. // You can show the data "value" or data "label" instead.
  58. dataLabels: "value"
  59. }
  60. }
  61. });*/
  62. for (i=0;i<$(".actions").length;i++) {
  63. 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) {
  64. $(".actions:eq("+i+")").hide();
  65. }
  66. }
  67. });
  68. </script>';
  69. api_block_anonymous_users();
  70. $htmlHeadXtra[]= '<script type="text/javascript">
  71. function confirmation() {
  72. if (confirm("' . get_lang('DeleteAll') . '?")) {
  73. return true;
  74. } else {
  75. return false;
  76. }
  77. }
  78. </script>';
  79. $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
  80. $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
  81. $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  82. $filter_confirm_msg = true;
  83. $filter_warning_msg = true;
  84. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  85. $first_time = null;
  86. if (empty($cats)) {
  87. //first time
  88. $cats = Category :: load(0, null, $course_code, null, null, $session_id, false);
  89. $first_time = 1;
  90. }
  91. $_GET['selectcat'] = $cats[0]->get_id();
  92. if (isset($_GET['isStudentView'])) {
  93. if ( (isset($_GET['selectcat']) && $_GET['selectcat']>0) && (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) {
  94. $interbreadcrumb[]= array ('url' => 'index.php'.'?selectcat=0&amp;isStudentView='.$_GET['isStudentView'],'name' => get_lang('ToolGradebook'));
  95. }
  96. }
  97. if ((isset($_GET['selectcat']) && $_GET['selectcat']>0) &&
  98. (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview')
  99. ) {
  100. Display :: display_header();
  101. //Introduction tool: student view
  102. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  103. $category = $_GET['selectcat'];
  104. $cats = Category :: load ($category, null, null, null, null, null, false);
  105. $allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  106. $alleval = $cats[0]->get_evaluations($stud_id);
  107. $alllink = $cats[0]->get_links($stud_id);
  108. $addparams = array();
  109. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  110. $gradebooktable->display();
  111. Display :: display_footer();
  112. exit;
  113. } else {
  114. if (!isset($_GET['selectcat']) &&
  115. ($_SESSION['studentview']=='studentview') ||
  116. (isset($_GET['isStudentView']) && $_GET['isStudentView']=='true')
  117. ) {
  118. Display :: display_header(get_lang('Gradebook'));
  119. //Introduction tool: student view
  120. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  121. $addparams=array();
  122. $cats = Category :: load (0, null, null, null, null, null, false);
  123. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  124. $alleval= $cats[0]->get_evaluations($stud_id);
  125. $alllink= $cats[0]->get_links($stud_id);
  126. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  127. $gradebooktable->display();
  128. Display :: display_footer();
  129. exit;
  130. }
  131. }
  132. // ACTIONS
  133. //this is called when there is no data for the course admin
  134. if (isset($_GET['createallcategories'])) {
  135. GradebookUtils::block_students();
  136. $coursecat= Category :: get_not_created_course_categories($stud_id);
  137. if (!count($coursecat) == 0) {
  138. foreach ($coursecat as $row) {
  139. $cat= new Category();
  140. $cat->set_name($row[1]);
  141. $cat->set_course_code($row[0]);
  142. $cat->set_description(null);
  143. $cat->set_user_id($stud_id);
  144. $cat->set_parent_id(0);
  145. $cat->set_weight(0);
  146. $cat->set_visible(0);
  147. $cat->add();
  148. unset ($cat);
  149. }
  150. }
  151. header('Location: '.$_SESSION['gradebook_dest'].'?addallcat=&selectcat=0');
  152. exit;
  153. }
  154. //show logs evaluations
  155. if (isset($_GET['visiblelog'])) {
  156. header('Location: ' . api_get_self().'/gradebook_showlog_eval.php');
  157. exit;
  158. }
  159. //move a category
  160. if (isset($_GET['movecat'])) {
  161. GradebookUtils::block_students();
  162. $cats= Category :: load($_GET['movecat']);
  163. if (!isset ($_GET['targetcat'])) {
  164. $move_form= new CatForm(CatForm :: TYPE_MOVE,
  165. $cats[0],
  166. 'move_cat_form',
  167. null,
  168. api_get_self() . '?movecat=' . Security::remove_XSS($_GET['movecat'])
  169. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  170. if ($move_form->validate()) {
  171. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  172. . '&movecat=' . Security::remove_XSS($_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=' . Security::remove_XSS($_GET['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(EvalForm :: TYPE_MOVE,
  194. $evals[0],
  195. null,
  196. 'move_eval_form',
  197. null,
  198. api_get_self() . '?moveeval=' . Security::remove_XSS($_GET['moveeval'])
  199. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  200. if ($move_form->validate()) {
  201. header('Location: ' .api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['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=' . Security::remove_XSS($_GET['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=' . Security::remove_XSS($_GET['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=' . Security::remove_XSS($_GET['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=' . Security::remove_XSS($_GET['movecat'])
  383. : '&moveeval=' . Security::remove_XSS($_GET['moveeval']) )
  384. .'&selectcat=' . Security::remove_XSS($_GET['selectcat'])
  385. .'&targetcat=' . Security::remove_XSS($_GET['targetcat']).'">
  386. <input type="submit" value="'.get_lang('Ok').'">
  387. </form>';
  388. $warning_message = get_lang('MoveWarning').'<br><br>'.$button;
  389. $filter_warning_msg = false;
  390. }
  391. $action = isset($_GET['action']) ? $_GET['action'] : null;
  392. switch ($action) {
  393. case 'lock':
  394. $category_to_lock = Category :: load($_GET['category_id']);
  395. $category_to_lock[0]->lock_all_items(1);
  396. $confirmation_message = get_lang('GradebookLockedAlert');
  397. break;
  398. case 'unlock':
  399. if (api_is_platform_admin()) {
  400. $category_to_lock = Category :: load($_GET['category_id']);
  401. $category_to_lock[0]->lock_all_items(0);
  402. $confirmation_message = get_lang('EvaluationHasBeenUnLocked');
  403. }
  404. break;
  405. case 'export_table':
  406. //table will be export below
  407. ob_start();
  408. break;
  409. }
  410. //actions on the sortabletable
  411. if (isset($_POST['action'])) {
  412. GradebookUtils::block_students();
  413. $number_of_selected_items= count($_POST['id']);
  414. if ($number_of_selected_items == '0') {
  415. $warning_message = get_lang('NoItemsSelected');
  416. $filter_warning_msg = false;
  417. } else {
  418. switch ($_POST['action']) {
  419. case 'deleted':
  420. $number_of_deleted_categories= 0;
  421. $number_of_deleted_evaluations= 0;
  422. $number_of_deleted_links= 0;
  423. foreach ($_POST['id'] as $indexstr) {
  424. if (substr($indexstr, 0, 4) == 'CATE') {
  425. $cats= Category :: load(substr($indexstr, 4));
  426. if ($cats[0] != null) {
  427. $cats[0]->delete_all();
  428. }
  429. $number_of_deleted_categories++;
  430. }
  431. if (substr($indexstr, 0, 4) == 'EVAL') {
  432. $eval= Evaluation :: load(substr($indexstr, 4));
  433. if ($eval[0] != null) {
  434. $eval[0]->delete_with_results();
  435. }
  436. $number_of_deleted_evaluations++;
  437. }
  438. if (substr($indexstr, 0, 4) == 'LINK') {
  439. //fixing #5229
  440. $id = substr($indexstr, 4);
  441. if (!empty($id)) {
  442. $link= LinkFactory :: load($id);
  443. if ($link[0] != null) {
  444. $link[0]->delete();
  445. }
  446. $number_of_deleted_links++;
  447. }
  448. }
  449. }
  450. $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>';
  451. $filter_confirm_msg = false;
  452. break;
  453. case 'setvisible':
  454. foreach ($_POST['id'] as $indexstr) {
  455. if (substr($indexstr, 0, 4) == 'CATE') {
  456. $cats = Category :: load(substr($indexstr, 4));
  457. $cats[0]->set_visible(1);
  458. $cats[0]->save();
  459. $cats[0]->apply_visibility_to_children();
  460. }
  461. if (substr($indexstr, 0, 4) == 'EVAL') {
  462. $eval= Evaluation :: load(substr($indexstr, 4));
  463. $eval[0]->set_visible(1);
  464. $eval[0]->save();
  465. }
  466. if (substr($indexstr, 0, 4) == 'LINK') {
  467. $link= LinkFactory :: load(substr($indexstr, 4));
  468. $link[0]->set_visible(1);
  469. $link[0]->save();
  470. }
  471. }
  472. $confirmation_message = get_lang('ItemsVisible');
  473. $filter_confirm_msg = false;
  474. break;
  475. case 'setinvisible':
  476. foreach ($_POST['id'] as $indexstr) {
  477. if (substr($indexstr, 0, 4) == 'CATE') {
  478. $cats = Category :: load(substr($indexstr, 4));
  479. $cats[0]->set_visible(0);
  480. $cats[0]->save();
  481. $cats[0]->apply_visibility_to_children();
  482. }
  483. if (substr($indexstr, 0, 4) == 'EVAL') {
  484. $eval= Evaluation :: load(substr($indexstr, 4));
  485. $eval[0]->set_visible(0);
  486. $eval[0]->save();
  487. }
  488. if (substr($indexstr, 0, 4) == 'LINK') {
  489. $link= LinkFactory :: load(substr($indexstr, 4));
  490. $link[0]->set_visible(0);
  491. $link[0]->save();
  492. }
  493. }
  494. $confirmation_message = get_lang('ItemsInVisible');
  495. $filter_confirm_msg = false;
  496. break;
  497. }
  498. }
  499. }
  500. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  501. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  502. . '&search='.Security::remove_XSS($_POST['keyword']));
  503. exit;
  504. }
  505. // DISPLAY HEADERS AND MESSAGES
  506. if (!isset($_GET['exportpdf'])) {
  507. if (isset ($_GET['studentoverview'])) {
  508. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('ToolGradebook'));
  509. Display :: display_header(get_lang('FlatView'));
  510. } elseif (isset ($_GET['search'])) {
  511. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('ToolGradebook'));
  512. Display :: display_header(get_lang('SearchResults'));
  513. } elseif(isset ($_GET['selectcat'])) {
  514. $interbreadcrumb[]= array ( 'url' =>'#','name' => get_lang('ToolGradebook'));
  515. if (!isset($_GET['gradebooklist_direction'])) {
  516. //$interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('Details'));
  517. }
  518. Display :: display_header('');
  519. } else {
  520. Display :: display_header(get_lang('ToolGradebook'));
  521. }
  522. }
  523. if (isset ($_GET['categorymoved'])) {
  524. Display :: display_confirmation_message(get_lang('CategoryMoved'),false);
  525. }
  526. if (isset ($_GET['evaluationmoved'])) {
  527. Display :: display_confirmation_message(get_lang('EvaluationMoved'),false);
  528. }
  529. if (isset ($_GET['linkmoved'])) {
  530. Display :: display_confirmation_message(get_lang('LinkMoved'),false);
  531. }
  532. if (isset ($_GET['addcat'])) {
  533. Display :: display_confirmation_message(get_lang('CategoryAdded'),false);
  534. }
  535. if (isset ($_GET['linkadded'])) {
  536. Display :: display_confirmation_message(get_lang('LinkAdded'),false);
  537. }
  538. if (isset ($_GET['addresult'])) {
  539. Display :: display_confirmation_message(get_lang('ResultAdded'),false);
  540. }
  541. if (isset ($_GET['editcat'])) {
  542. Display :: display_confirmation_message(get_lang('CategoryEdited'),false);
  543. }
  544. if (isset ($_GET['editeval'])) {
  545. Display :: display_confirmation_message(get_lang('EvaluationEdited'),false);
  546. }
  547. if (isset ($_GET['linkedited'])) {
  548. Display :: display_confirmation_message(get_lang('LinkEdited'),false);
  549. }
  550. if (isset ($_GET['nolinkitems'])){
  551. Display :: display_warning_message(get_lang('NoLinkItems'),false);
  552. }
  553. if (isset ($_GET['addallcat'])){
  554. Display :: display_normal_message(get_lang('AddAllCat'),false);
  555. }
  556. if (isset ($confirmation_message)){
  557. Display :: display_confirmation_message($confirmation_message,$filter_confirm_msg);
  558. }
  559. if (isset ($warning_message)){
  560. Display :: display_warning_message($warning_message,$filter_warning_msg);
  561. }
  562. if (isset ($move_form)){
  563. Display :: display_normal_message($move_form->toHtml(),false);
  564. }
  565. // LOAD DATA & DISPLAY TABLE
  566. $is_platform_admin = api_is_platform_admin();
  567. $is_course_admin = api_is_allowed_to_edit(null, true);
  568. //load data for category, evaluation and links
  569. if (empty($_GET['selectcat'])) {
  570. $category = 0;
  571. } else {
  572. $category = $_GET['selectcat'];
  573. }
  574. $simple_search_form='';
  575. if (isset($_GET['studentoverview'])) {
  576. //@todo this code also seems to be deprecated ...
  577. $cats = Category :: load($category);
  578. $stud_id= (api_is_allowed_to_edit() ? null : $stud_id);
  579. $allcat= array ();
  580. $alleval= $cats[0]->get_evaluations($stud_id, true);
  581. $alllink= $cats[0]->get_links($stud_id, true);
  582. if (isset ($_GET['exportpdf'])) {
  583. $datagen = new GradebookDataGenerator($allcat,$alleval, $alllink);
  584. $header_names = array(
  585. get_lang('Name'),
  586. get_lang('Description'),
  587. get_lang('Weight'),
  588. get_lang('Date'),
  589. get_lang('Results'),
  590. );
  591. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  592. $newarray = array();
  593. foreach ($data_array as $data) {
  594. $newarray[] = array_slice($data, 1);
  595. }
  596. $pdf= new Cezpdf();
  597. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  598. $pdf->ezSetMargins(30, 30, 50, 30);
  599. $pdf->ezSetY(810);
  600. $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'));
  601. $pdf->line(50,790,550,790);
  602. $pdf->line(50,40,550,40);
  603. $pdf->ezSetY(750);
  604. $pdf->ezTable(
  605. $newarray,
  606. $header_names,
  607. '',
  608. array(
  609. 'showHeadings' => 1,
  610. 'shaded' => 1,
  611. 'showLines' => 1,
  612. 'rowGap' => 3,
  613. 'width' => 500,
  614. )
  615. );
  616. $pdf->ezStream();
  617. exit;
  618. }
  619. } else {
  620. //Student view
  621. //in any other case (no search, no pdf), print the available gradebooks
  622. // Important note: loading a category will actually load the *contents* of
  623. // this category. This means that, to show the categories of a course,
  624. // we have to show the root category and show its subcategories that
  625. // are inside this course. This is done at the time of calling
  626. // $cats[0]->get_subcategories(), not at the time of doing Category::load()
  627. // $category comes from GET['selectcat']
  628. //if $category = 0 (which happens when GET['selectcat'] is undefined)
  629. // then Category::load() will create a new 'root' category with empty
  630. // course and session fields in memory (Category::create_root_category())
  631. if ($_in_course === true) {
  632. // When *inside* a course, we want to make sure there is one (and only
  633. // one) category for this course or for this session.
  634. //hack for delete a gradebook from inside course
  635. /*
  636. $clean_deletecat = isset($_GET['deletecat']) ? intval($_GET['deletecat']) : null;
  637. if (!empty($clean_deletecat)) {
  638. exit;
  639. }
  640. //end hack*/
  641. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  642. if (empty($cats)) {
  643. // There is no category for this course+session, so create one
  644. $cat = new Category();
  645. if (!empty($session_id)) {
  646. $s_name = api_get_session_name($session_id);
  647. $cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name);
  648. $cat->set_session_id($session_id);
  649. } else {
  650. $cat->set_name($course_code);
  651. }
  652. $cat->set_course_code($course_code);
  653. $cat->set_description(null);
  654. $cat->set_user_id($stud_id);
  655. $cat->set_parent_id(0);
  656. $cat->set_weight(100);
  657. $cat->set_visible(0);
  658. $cat->set_certificate_min_score(75);
  659. $can_edit = api_is_allowed_to_edit(true, true);
  660. if ($can_edit) {
  661. $cat->add();
  662. }
  663. unset($cat);
  664. }
  665. unset($cats);
  666. }
  667. $cats = Category::load($category, null, null, null, null, null, false);
  668. //with this fix the teacher only can view 1 gradebook
  669. if (api_is_platform_admin()) {
  670. $stud_id = (api_is_allowed_to_edit() ? null : api_get_user_id());
  671. } else {
  672. $stud_id = $stud_id;
  673. }
  674. $allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  675. $alleval = $cats[0]->get_evaluations($stud_id);
  676. $alllink = $cats[0]->get_links($stud_id);
  677. }
  678. // add params to the future links (in the table shown)
  679. $addparams = array('selectcat' => $cats[0]->get_id());
  680. if (isset($_GET['studentoverview'])) {
  681. $addparams['studentoverview'] = '';
  682. }
  683. //$addparams['cidReq']='';
  684. if (isset($_GET['cidReq']) && $_GET['cidReq']!='') {
  685. $addparams['cidReq'] = Security::remove_XSS($_GET['cidReq']);
  686. } else {
  687. $addparams['cidReq']='';
  688. }
  689. $no_qualification = false;
  690. // Show certificate link.
  691. $certificate = array();
  692. echo '<div class="actions" align="right">';
  693. if ($category != '0') {
  694. $cat = new Category();
  695. $category_id = intval($_GET['selectcat']);
  696. $course_id = CourseManager::get_course_by_category($category_id);
  697. $show_message = $cat->show_message_resource_delete($course_id);
  698. if ($show_message == '') {
  699. // Student
  700. if (!api_is_allowed_to_edit() && !api_is_excluded_user_type()) {
  701. $certificate = Category::register_user_certificate(
  702. $category_id,
  703. $stud_id
  704. );
  705. if (!empty($certificate)) {
  706. echo Display::url(
  707. get_lang('DownloadCertificatePdf'),
  708. $certificate['pdf_url'],
  709. ['class' => 'btn btn-default']
  710. );
  711. }
  712. $currentScore = Category::getCurrentScore($stud_id, $category_id, $course_code, $session_id, true);
  713. Category::registerCurrentScore($currentScore, $stud_id, $category_id);
  714. }
  715. }
  716. }
  717. if (!api_is_allowed_to_edit(null, true)) {
  718. echo Display::url(
  719. get_lang('DownloadReportPdf'),
  720. api_get_self()."?".api_get_self()."&action=export_table",
  721. ['class' => 'btn btn-default']
  722. );
  723. }
  724. echo '</div>';
  725. if (api_is_allowed_to_edit(null, true)) {
  726. // Tool introduction
  727. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  728. if ((isset ($_GET['selectcat']) && $_GET['selectcat']<>0)) {
  729. //
  730. } else {
  731. if ((
  732. (isset ($_GET['selectcat']) && $_GET['selectcat'] == 0) || (
  733. (isset($_GET['cidReq']) && $_GET['cidReq'] !== ''))
  734. ) ||
  735. isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false'
  736. ) {
  737. $cats = Category:: load(
  738. null,
  739. null,
  740. $course_code,
  741. null,
  742. null,
  743. $session_id,
  744. false
  745. );
  746. }
  747. }
  748. }
  749. if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
  750. echo '<meta http-equiv="refresh" content="0;url='.api_get_self().'?cidReq='.$course_code.'" />';
  751. } else {
  752. $cats = Category::load(null, null, $course_code, null, null, $session_id, false);
  753. if (!empty($cats)) {
  754. if ((api_get_setting('gradebook_enable_grade_model') == 'true') &&
  755. (
  756. api_is_platform_admin() || (api_is_allowed_to_edit(null, true) &&
  757. api_get_setting('teachers_can_change_grade_model_settings') == 'true')
  758. )
  759. ) {
  760. // Getting grade models.
  761. $obj = new GradeModel();
  762. $grade_models = $obj->get_all();
  763. $grade_model_id = $cats[0]->get_grade_model_id();
  764. // No children.
  765. if ((count($cats) == 1 && empty($grade_model_id)) ||
  766. (count($cats) == 1 && $grade_model_id != -1)
  767. ) {
  768. if (!empty($grade_models)) {
  769. $form_grade = new FormValidator('grade_model_settings');
  770. $obj->fill_grade_model_select_in_form($form_grade, 'grade_model_id', $grade_model_id);
  771. $form->addButtonSave(get_lang('Save'));
  772. if ($form_grade->validate()) {
  773. $value = $form_grade->exportValue('grade_model_id');
  774. $gradebook = new Gradebook();
  775. $gradebook->update(array('id'=> $cats[0]->get_id(), 'grade_model_id' => $value), true);
  776. //do something
  777. $obj = new GradeModel();
  778. $components = $obj->get_components($value);
  779. foreach ($components as $component) {
  780. $gradebook = new Gradebook();
  781. $params = array();
  782. $params['name'] = $component['acronym'];
  783. $params['description'] = $component['title'];
  784. $params['user_id'] = api_get_user_id();
  785. $params['parent_id'] = $cats[0]->get_id();
  786. $params['weight'] = $component['percentage'];
  787. $params['session_id'] = api_get_session_id();
  788. $params['course_code'] = api_get_course_id();
  789. $params['grade_model_id'] = api_get_session_id();
  790. $gradebook->save($params);
  791. }
  792. // Reloading cats
  793. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  794. } else {
  795. $form_grade->display();
  796. }
  797. }
  798. }
  799. }
  800. $i = 0;
  801. $allcat = array();
  802. /** @var Category $cat */
  803. foreach ($cats as $cat) {
  804. $allcat = $cat->get_subcategories($stud_id, $course_code, $session_id);
  805. $alleval = $cat->get_evaluations($stud_id);
  806. $alllink = $cat->get_links($stud_id, true);
  807. if ($cat->get_parent_id() != 0) {
  808. $i++;
  809. } else {
  810. // This is the father
  811. // Create gradebook/add gradebook links.
  812. DisplayGradebook::header(
  813. $cat,
  814. 0,
  815. $cat->get_id(),
  816. $is_course_admin,
  817. $is_platform_admin,
  818. $simple_search_form,
  819. false,
  820. true,
  821. $certificate
  822. );
  823. if (api_is_allowed_to_edit(null,true) &&
  824. api_get_setting('gradebook_enable_grade_model') == 'true'
  825. ) {
  826. //Showing the grading system
  827. if (!empty($grade_models[$grade_model_id])) {
  828. Display::display_normal_message(get_lang('GradeModel').': '.$grade_models[$grade_model_id]['name']);
  829. }
  830. }
  831. $exportToPdf = false;
  832. if ($action == 'export_table') {
  833. $exportToPdf = true;
  834. }
  835. $gradebooktable = new GradebookTable(
  836. $cat,
  837. $allcat,
  838. $alleval,
  839. $alllink,
  840. $addparams,
  841. $exportToPdf
  842. );
  843. if (api_is_allowed_to_edit()) {
  844. $gradebooktable->td_attributes = [
  845. 4 => 'class=centered'
  846. ];
  847. } else {
  848. $gradebooktable->td_attributes = [
  849. 3 => 'class=centered',
  850. 4 => 'class=centered',
  851. 5 => 'class=centered',
  852. 6 => 'class=centered',
  853. 7 => 'class=centered'
  854. ];
  855. }
  856. $table = $gradebooktable->return_table();
  857. $graph = $gradebooktable->getGraph();
  858. if ($action == 'export_table') {
  859. ob_clean();
  860. $params = array(
  861. //'filename' => get_lang('FlatView') . '_' . api_get_utc_datetime(),
  862. 'pdf_title' => get_lang('Report'),
  863. 'course_code' => api_get_course_id(),
  864. 'session_info' => api_get_session_info(api_get_session_id()),
  865. 'add_signatures' => false,
  866. 'student_info' => api_get_user_info()
  867. );
  868. $pdf = new PDF('A4', $params['orientation'], $params);
  869. $pdf->html_to_pdf_with_template($table.$graph);
  870. } else {
  871. echo $table;
  872. echo $graph;
  873. }
  874. }
  875. }
  876. }
  877. }
  878. api_set_in_gradebook();
  879. Display :: display_footer();