index.php 30 KB

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