index.php 30 KB

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