index.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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= 'gradebook';
  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_PATH).'javascript/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 = "../img/view_more_stats.gif";
  42. var hide_icon = "../img/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. $catsResult = array();
  103. if (api_get_session_id() != 0) {
  104. $session_id = api_get_session_id();
  105. $cats = Category :: load_session_categories(null, $session_id); //already init
  106. $catsResult = $cats;
  107. } else {
  108. $cats = Category :: load(null, null, $course_code, null, null, null, false);
  109. }
  110. $first_time = null;
  111. if (empty($cats)) {
  112. $cats = Category :: load(0, null, $course_code, null, null, $session_id, false);//first time
  113. $first_time = 1;
  114. }
  115. $_GET['selectcat'] = $cats[0]->get_id();
  116. if (isset($_GET['isStudentView'])) {
  117. if ( (isset($_GET['selectcat']) && $_GET['selectcat']>0) && (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) {
  118. $interbreadcrumb[]= array ('url' => 'index.php'.'?selectcat=0&amp;isStudentView='.$_GET['isStudentView'],'name' => get_lang('ToolGradebook'));
  119. }
  120. }
  121. if ((isset($_GET['selectcat']) && $_GET['selectcat']>0) && (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview')) {
  122. Display :: display_header();
  123. //Introduction tool: student view
  124. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  125. $category= $_GET['selectcat'];
  126. $cats = Category :: load ($category, null, null, null, null, null, false);
  127. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  128. $alleval= $cats[0]->get_evaluations($stud_id);
  129. $alllink= $cats[0]->get_links($stud_id);
  130. $addparams=array();
  131. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  132. $gradebooktable->display();
  133. Display :: display_footer();
  134. exit;
  135. } else {
  136. if ( !isset($_GET['selectcat']) && ($_SESSION['studentview']=='studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='true') ) {
  137. // 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()) ) {
  138. Display :: display_header(get_lang('Gradebook'));
  139. //Introduction tool: student view
  140. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  141. $addparams=array();
  142. $cats = Category :: load (0, null, null, null, null, null, false);
  143. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  144. $alleval= $cats[0]->get_evaluations($stud_id);
  145. $alllink= $cats[0]->get_links($stud_id);
  146. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  147. $gradebooktable->display();
  148. Display :: display_footer();
  149. exit;
  150. }
  151. }
  152. // ACTIONS
  153. //this is called when there is no data for the course admin
  154. if (isset ($_GET['createallcategories'])) {
  155. block_students();
  156. $coursecat= Category :: get_not_created_course_categories($stud_id);
  157. if (!count($coursecat) == 0) {
  158. foreach ($coursecat as $row) {
  159. $cat= new Category();
  160. $cat->set_name($row[1]);
  161. $cat->set_course_code($row[0]);
  162. $cat->set_description(null);
  163. $cat->set_user_id($stud_id);
  164. $cat->set_parent_id(0);
  165. $cat->set_weight(0);
  166. $cat->set_visible(0);
  167. $cat->add();
  168. unset ($cat);
  169. }
  170. }
  171. header('Location: '.$_SESSION['gradebook_dest'].'?addallcat=&selectcat=0');
  172. exit;
  173. }
  174. //show logs evaluations
  175. if (isset ($_GET['visiblelog'])) {
  176. header('Location: ' . api_get_self().'/gradebook_showlog_eval.php');
  177. exit;
  178. }
  179. //move a category
  180. if (isset ($_GET['movecat'])) {
  181. block_students();
  182. $cats= Category :: load($_GET['movecat']);
  183. if (!isset ($_GET['targetcat'])) {
  184. $move_form= new CatForm(CatForm :: TYPE_MOVE,
  185. $cats[0],
  186. 'move_cat_form',
  187. null,
  188. api_get_self() . '?movecat=' . Security::remove_XSS($_GET['movecat'])
  189. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  190. if ($move_form->validate()) {
  191. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  192. . '&movecat=' . Security::remove_XSS($_GET['movecat'])
  193. . '&targetcat=' . $move_form->exportValue('move_cat'));
  194. exit;
  195. }
  196. } else {
  197. $targetcat= Category :: load($_GET['targetcat']);
  198. $course_to_crsind = ($cats[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  199. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  200. $cats[0]->move_to_cat($targetcat[0]);
  201. header('Location: ' . api_get_self() . '?categorymoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  202. exit;
  203. }
  204. unset ($targetcat);
  205. }
  206. unset ($cats);
  207. }
  208. //move an evaluation
  209. if (isset ($_GET['moveeval'])) {
  210. block_students();
  211. $evals= Evaluation :: load($_GET['moveeval']);
  212. if (!isset ($_GET['targetcat'])) {
  213. $move_form= new EvalForm(EvalForm :: TYPE_MOVE,
  214. $evals[0],
  215. null,
  216. 'move_eval_form',
  217. null,
  218. api_get_self() . '?moveeval=' . Security::remove_XSS($_GET['moveeval'])
  219. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  220. if ($move_form->validate()) {
  221. header('Location: ' .api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  222. . '&moveeval=' . Security::remove_XSS($_GET['moveeval'])
  223. . '&targetcat=' . $move_form->exportValue('move_cat'));
  224. exit;
  225. }
  226. } else {
  227. $targetcat= Category :: load($_GET['targetcat']);
  228. $course_to_crsind = ($evals[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  229. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  230. $evals[0]->move_to_cat($targetcat[0]);
  231. header('Location: ' . api_get_self() . '?evaluationmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  232. exit;
  233. }
  234. unset ($targetcat);
  235. }
  236. unset ($evals);
  237. }
  238. //move a link
  239. if (isset ($_GET['movelink'])) {
  240. block_students();
  241. $link= LinkFactory :: load($_GET['movelink']);
  242. $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']));
  243. if ($move_form->validate()) {
  244. $targetcat= Category :: load($move_form->exportValue('move_cat'));
  245. $link[0]->move_to_cat($targetcat[0]);
  246. unset ($link);
  247. header('Location: ' . api_get_self(). '?linkmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  248. exit;
  249. }
  250. }
  251. //parameters for categories
  252. if (isset ($_GET['visiblecat'])) {
  253. block_students();
  254. if (isset ($_GET['set_visible'])) {
  255. $visibility_command= 1;
  256. } else {
  257. $visibility_command= 0;
  258. }
  259. $cats= Category :: load($_GET['visiblecat']);
  260. $cats[0]->set_visible($visibility_command);
  261. $cats[0]->save();
  262. $cats[0]->apply_visibility_to_children();
  263. unset ($cats);
  264. if ($visibility_command) {
  265. $confirmation_message = get_lang('ViMod');
  266. $filter_confirm_msg = false;
  267. } else {
  268. $confirmation_message = get_lang('InViMod');
  269. $filter_confirm_msg = false;
  270. }
  271. }
  272. if (isset($_GET['deletecat'])) {
  273. block_students();
  274. $cats = Category :: load($_GET['deletecat']);
  275. //delete all categories,subcategories and results
  276. if ($cats[0] != null) {
  277. if ($cats[0]->get_id() != 0) {
  278. // better don't try to delete the root...
  279. $cats[0]->delete_all();
  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 = (SELECT ref_id FROM '.$tbl_grade_links.' WHERE id='.$get_delete_link.' AND type = '.LINK_FORUM_THREAD.');';
  364. Database::query($sql);
  365. // clean attendance
  366. $sql = 'UPDATE '.$tbl_attendance.' SET attendance_qualify_max=0, attendance_weight = 0, attendance_qualify_title=""
  367. WHERE c_id = '.$course_id.' AND id = (SELECT ref_id FROM '.$tbl_grade_links.' WHERE id='.$get_delete_link.' AND type = '.LINK_ATTENDANCE.');';
  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. 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. }
  406. //actions on the sortabletable
  407. if (isset ($_POST['action'])) {
  408. block_students();
  409. $number_of_selected_items= count($_POST['id']);
  410. if ($number_of_selected_items == '0') {
  411. $warning_message = get_lang('NoItemsSelected');
  412. $filter_warning_msg = false;
  413. } else {
  414. switch ($_POST['action']) {
  415. case 'deleted' :
  416. $number_of_deleted_categories= 0;
  417. $number_of_deleted_evaluations= 0;
  418. $number_of_deleted_links= 0;
  419. foreach ($_POST['id'] as $indexstr) {
  420. if (substr($indexstr, 0, 4) == 'CATE') {
  421. $cats= Category :: load(substr($indexstr, 4));
  422. if ($cats[0] != null) {
  423. $cats[0]->delete_all();
  424. }
  425. $number_of_deleted_categories++;
  426. }
  427. if (substr($indexstr, 0, 4) == 'EVAL') {
  428. $eval= Evaluation :: load(substr($indexstr, 4));
  429. if ($eval[0] != null) {
  430. $eval[0]->delete_with_results();
  431. }
  432. $number_of_deleted_evaluations++;
  433. }
  434. if (substr($indexstr, 0, 4) == 'LINK') {
  435. //fixing #5229
  436. $id = substr($indexstr, 4);
  437. if (!empty($id)) {
  438. $link= LinkFactory :: load($id);
  439. if ($link[0] != null) {
  440. $link[0]->delete();
  441. }
  442. $number_of_deleted_links++;
  443. }
  444. }
  445. }
  446. $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>';
  447. $filter_confirm_msg = false;
  448. break;
  449. case 'setvisible' :
  450. foreach ($_POST['id'] as $indexstr) {
  451. if (substr($indexstr, 0, 4) == 'CATE') {
  452. $cats= Category :: load(substr($indexstr, 4));
  453. $cats[0]->set_visible(1);
  454. $cats[0]->save();
  455. $cats[0]->apply_visibility_to_children();
  456. }
  457. if (substr($indexstr, 0, 4) == 'EVAL') {
  458. $eval= Evaluation :: load(substr($indexstr, 4));
  459. $eval[0]->set_visible(1);
  460. $eval[0]->save();
  461. }
  462. if (substr($indexstr, 0, 4) == 'LINK') {
  463. $link= LinkFactory :: load(substr($indexstr, 4));
  464. $link[0]->set_visible(1);
  465. $link[0]->save();
  466. }
  467. }
  468. $confirmation_message = get_lang('ItemsVisible');
  469. $filter_confirm_msg = false;
  470. break;
  471. case 'setinvisible' :
  472. foreach ($_POST['id'] as $indexstr) {
  473. if (substr($indexstr, 0, 4) == 'CATE') {
  474. $cats= Category :: load(substr($indexstr, 4));
  475. $cats[0]->set_visible(0);
  476. $cats[0]->save();
  477. $cats[0]->apply_visibility_to_children();
  478. }
  479. if (substr($indexstr, 0, 4) == 'EVAL') {
  480. $eval= Evaluation :: load(substr($indexstr, 4));
  481. $eval[0]->set_visible(0);
  482. $eval[0]->save();
  483. }
  484. if (substr($indexstr, 0, 4) == 'LINK') {
  485. $link= LinkFactory :: load(substr($indexstr, 4));
  486. $link[0]->set_visible(0);
  487. $link[0]->save();
  488. }
  489. }
  490. $confirmation_message = get_lang('ItemsInVisible');
  491. $filter_confirm_msg = false;
  492. break;
  493. }
  494. }
  495. }
  496. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  497. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  498. . '&search='.Security::remove_XSS($_POST['keyword']));
  499. exit;
  500. }
  501. // DISPLAY HEADERS AND MESSAGES
  502. if (!isset($_GET['exportpdf'])) {
  503. if (isset ($_GET['studentoverview'])) {
  504. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('ToolGradebook'));
  505. Display :: display_header(get_lang('FlatView'));
  506. } elseif (isset ($_GET['search'])) {
  507. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('ToolGradebook'));
  508. Display :: display_header(get_lang('SearchResults'));
  509. } elseif(isset ($_GET['selectcat'])) {
  510. $interbreadcrumb[]= array ( 'url' =>'#','name' => get_lang('ToolGradebook'));
  511. if (!isset($_GET['gradebooklist_direction'])) {
  512. //$interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('Details'));
  513. }
  514. Display :: display_header('');
  515. } else {
  516. Display :: display_header(get_lang('ToolGradebook'));
  517. }
  518. }
  519. if (isset ($_GET['categorymoved'])) {
  520. Display :: display_confirmation_message(get_lang('CategoryMoved'),false);
  521. }
  522. if (isset ($_GET['evaluationmoved'])) {
  523. Display :: display_confirmation_message(get_lang('EvaluationMoved'),false);
  524. }
  525. if (isset ($_GET['linkmoved'])) {
  526. Display :: display_confirmation_message(get_lang('LinkMoved'),false);
  527. }
  528. if (isset ($_GET['addcat'])) {
  529. Display :: display_confirmation_message(get_lang('CategoryAdded'),false);
  530. }
  531. if (isset ($_GET['linkadded'])) {
  532. Display :: display_confirmation_message(get_lang('LinkAdded'),false);
  533. }
  534. if (isset ($_GET['addresult'])) {
  535. Display :: display_confirmation_message(get_lang('ResultAdded'),false);
  536. }
  537. if (isset ($_GET['editcat'])) {
  538. Display :: display_confirmation_message(get_lang('CategoryEdited'),false);
  539. }
  540. if (isset ($_GET['editeval'])) {
  541. Display :: display_confirmation_message(get_lang('EvaluationEdited'),false);
  542. }
  543. if (isset ($_GET['linkedited'])) {
  544. Display :: display_confirmation_message(get_lang('LinkEdited'),false);
  545. }
  546. if (isset ($_GET['nolinkitems'])){
  547. Display :: display_warning_message(get_lang('NoLinkItems'),false);
  548. }
  549. if (isset ($_GET['addallcat'])){
  550. Display :: display_normal_message(get_lang('AddAllCat'),false);
  551. }
  552. if (isset ($confirmation_message)){
  553. Display :: display_confirmation_message($confirmation_message,$filter_confirm_msg);
  554. }
  555. if (isset ($warning_message)){
  556. Display :: display_warning_message($warning_message,$filter_warning_msg);
  557. }
  558. if (isset ($move_form)){
  559. Display :: display_normal_message($move_form->toHtml(),false);
  560. }
  561. // LOAD DATA & DISPLAY TABLE
  562. $is_platform_admin = api_is_platform_admin();
  563. $is_course_admin = api_is_allowed_to_edit(null, true);
  564. //load data for category, evaluation and links
  565. if (empty ($_GET['selectcat'])) {
  566. $category= 0;
  567. } else {
  568. $category= $_GET['selectcat'];
  569. }
  570. $simple_search_form='';
  571. if (isset($_GET['studentoverview'])) {
  572. //@todo this code also seems to be deprecated ...
  573. $cats= Category :: load($category);
  574. $stud_id= (api_is_allowed_to_edit() ? null : $stud_id);
  575. $allcat= array ();
  576. $alleval= $cats[0]->get_evaluations($stud_id, true);
  577. $alllink= $cats[0]->get_links($stud_id, true);
  578. if (isset ($_GET['exportpdf'])) {
  579. $datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
  580. $header_names = array(get_lang('Name'),get_lang('Description'),get_lang('Weight'),get_lang('Date'),get_lang('Results'));
  581. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  582. $newarray = array();
  583. foreach ($data_array as $data) {
  584. $newarray[] = array_slice($data, 1);
  585. }
  586. $pdf= new Cezpdf();
  587. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  588. $pdf->ezSetMargins(30, 30, 50, 30);
  589. $pdf->ezSetY(810);
  590. $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'));
  591. $pdf->line(50,790,550,790);
  592. $pdf->line(50,40,550,40);
  593. $pdf->ezSetY(750);
  594. $pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=> 500));
  595. $pdf->ezStream();
  596. exit;
  597. }
  598. } else {
  599. //Student view
  600. //in any other case (no search, no pdf), print the available gradebooks
  601. // Important note: loading a category will actually load the *contents* of
  602. // this category. This means that, to show the categories of a course,
  603. // we have to show the root category and show its subcategories that
  604. // are inside this course. This is done at the time of calling
  605. // $cats[0]->get_subcategories(), not at the time of doing Category::load()
  606. // $category comes from GET['selectcat']
  607. //if $category = 0 (which happens when GET['selectcat'] is undefined)
  608. // then Category::load() will create a new 'root' category with empty
  609. // course and session fields in memory (Category::create_root_category())
  610. if ($_in_course === true) {
  611. // When *inside* a course, we want to make sure there is one (and only
  612. // one) category for this course or for this session.
  613. //hack for delete a gradebook from inside course
  614. /*
  615. $clean_deletecat = isset($_GET['deletecat']) ? intval($_GET['deletecat']) : null;
  616. if (!empty($clean_deletecat)) {
  617. exit;
  618. }
  619. //end hack*/
  620. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  621. if (empty($cats)) {
  622. // There is no category for this course+session, so create one
  623. $cat= new Category();
  624. if (!empty($session_id)) {
  625. $s_name = api_get_session_name($session_id);
  626. $cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name);
  627. $cat->set_session_id($session_id);
  628. } else {
  629. $cat->set_name($course_code);
  630. }
  631. $cat->set_course_code($course_code);
  632. $cat->set_description(null);
  633. $cat->set_user_id($stud_id);
  634. $cat->set_parent_id(0);
  635. $cat->set_weight(100);
  636. $cat->set_visible(0);
  637. $cat->set_certificate_min_score(75);
  638. $can_edit = api_is_allowed_to_edit(true, true);
  639. if ($can_edit) {
  640. $cat->add();
  641. }
  642. unset ($cat);
  643. }
  644. unset($cats);
  645. }
  646. $cats = Category :: load ($category, null, null, null, null, null, false);
  647. //with this fix the teacher only can view 1 gradebook
  648. if (api_is_platform_admin()) {
  649. $stud_id = (api_is_allowed_to_edit() ? null : api_get_user_id());
  650. } else {
  651. $stud_id = $stud_id;
  652. }
  653. $allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  654. $alleval = $cats[0]->get_evaluations($stud_id);
  655. $alllink = $cats[0]->get_links($stud_id);
  656. //whether we found a category or not, we now have a category object with
  657. // empty or full subcats
  658. }
  659. // add params to the future links (in the table shown)
  660. $addparams = array ('selectcat' => $cats[0]->get_id());
  661. if (isset ($_GET['studentoverview'])) {
  662. $addparams['studentoverview'] = '';
  663. }
  664. //$addparams['cidReq']='';
  665. if (isset($_GET['cidReq']) && $_GET['cidReq']!='') {
  666. $addparams['cidReq']=Security::remove_XSS($_GET['cidReq']);
  667. } else {
  668. $addparams['cidReq']='';
  669. }
  670. $no_qualification = false;
  671. //here we are in a sub category
  672. if ($category != '0') {
  673. $cat = new Category();
  674. $category_id = intval($_GET['selectcat']);
  675. $course_id = Database::get_course_by_category($category_id);
  676. $show_message = $cat->show_message_resource_delete($course_id);
  677. if ($show_message == '') {
  678. //student
  679. if (!api_is_allowed_to_edit()) {
  680. $certificate_html = Category::register_user_certificate($category_id, $stud_id);
  681. if ($certificate_html) {
  682. echo $certificate_html;
  683. }
  684. } //end hack
  685. }
  686. }
  687. if (api_is_allowed_to_edit(null, true)) {
  688. // Tool introduction
  689. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  690. if ( (isset ($_GET['selectcat']) && $_GET['selectcat']<>0) ) {
  691. //
  692. } else {
  693. if (((isset ($_GET['selectcat']) && $_GET['selectcat']==0) || ((isset($_GET['cidReq']) && $_GET['cidReq']!==''))) || isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') {
  694. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  695. }
  696. }
  697. }
  698. if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
  699. echo '<meta http-equiv="refresh" content="0;url='.api_get_self().'?cidReq='.$course_code.'" />';
  700. } else {
  701. $cats = Category::load(null, null, $course_code, null, null, $session_id, false);
  702. if (!empty($cats)) {
  703. if ((api_get_setting('gradebook_enable_grade_model') == 'true') &&
  704. (api_is_platform_admin() || (api_is_allowed_to_edit(null, true) &&
  705. api_get_setting('teachers_can_change_grade_model_settings') == 'true'))
  706. ) {
  707. // Getting grade models.
  708. $obj = new GradeModel();
  709. $grade_models = $obj->get_all();
  710. $grade_model_id = $cats[0]->get_grade_model_id();
  711. // No children.
  712. if ((count($cats) == 1 && empty($grade_model_id)) ||
  713. (count($cats) == 1 && $grade_model_id != -1)
  714. ) {
  715. if (!empty($grade_models)) {
  716. $form_grade = new FormValidator('grade_model_settings');
  717. $obj->fill_grade_model_select_in_form($form_grade, 'grade_model_id', $grade_model_id);
  718. $form_grade->addElement('style_submit_button', 'submit', get_lang('Save'), 'class="save"');
  719. if ($form_grade->validate()) {
  720. $value = $form_grade->exportValue('grade_model_id');
  721. $gradebook = new Gradebook();
  722. $gradebook->update(array('id'=> $cats[0]->get_id(), 'grade_model_id' => $value), true);
  723. //do something
  724. $obj = new GradeModel();
  725. $components = $obj->get_components($value);
  726. foreach ($components as $component) {
  727. $gradebook = new Gradebook();
  728. $params = array();
  729. $params['name'] = $component['acronym'];
  730. $params['description'] = $component['title'];
  731. $params['user_id'] = api_get_user_id();
  732. $params['parent_id'] = $cats[0]->get_id();
  733. $params['weight'] = $component['percentage'];
  734. $params['session_id'] = api_get_session_id();
  735. $params['course_code'] = api_get_course_id();
  736. $params['grade_model_id'] = api_get_session_id();
  737. $gradebook->save($params);
  738. }
  739. //Reloading cats
  740. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  741. } else {
  742. $form_grade->display();
  743. }
  744. }
  745. }
  746. }
  747. $i = 0;
  748. $allcat = array();
  749. foreach ($cats as $cat) {
  750. if ($session_id != 0) {
  751. $allcatSession = $catsResult;
  752. foreach ($allcatSession as $catSession) {
  753. if ($catSession->get_parent_id() == 0) {
  754. continue;
  755. }
  756. $allcat[] = $catSession;
  757. }
  758. } else {
  759. $allcat = $cat->get_subcategories($stud_id, $course_code, $session_id);
  760. }
  761. $alleval = $cat->get_evaluations($stud_id);
  762. $alllink = $cat->get_links($stud_id,true);
  763. if ($cat->get_parent_id() != 0) {
  764. $i++;
  765. } else {
  766. // This is the father
  767. // Create gradebook/add gradebook links.
  768. DisplayGradebook::display_header_gradebook(
  769. $cat,
  770. 0,
  771. $cat->get_id(),
  772. $is_course_admin,
  773. $is_platform_admin,
  774. $simple_search_form,
  775. false,
  776. true
  777. );
  778. if (api_is_allowed_to_edit(null,true) &&
  779. api_get_setting('gradebook_enable_grade_model') == 'true'
  780. ) {
  781. //Showing the grading system
  782. if (!empty($grade_models[$grade_model_id])) {
  783. Display::display_normal_message(get_lang('GradeModel').': '.$grade_models[$grade_model_id]['name']);
  784. }
  785. }
  786. $gradebooktable = new GradebookTable($cat, $allcat, $alleval, $alllink, $addparams);
  787. $gradebooktable->display();
  788. }
  789. }
  790. }
  791. }
  792. Display :: display_footer();