index.php 34 KB

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