index.php 30 KB

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