index.php 33 KB

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