index.php 32 KB

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