index.php 33 KB

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