index.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. <?php // $Id: $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos Latinoamerica SAC
  6. Copyright (c) 2006-2008 Dokeos SPRL
  7. Copyright (c) 2006 Ghent University (UGent)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. $language_file= 'gradebook';
  21. // $cidReset : This is the main difference with gradebook.php, here we say,
  22. // basically, that we are inside a course, and many things depend from that
  23. $cidReset= false;
  24. $_in_course = true;
  25. require_once '../inc/global.inc.php';
  26. $course_code = api_get_course_id();
  27. //make sure the destination for scripts is index.php instead of gradebook.php
  28. $_SESSION['gradebook_dest'] = 'index.php';
  29. $this_section = SECTION_MYGRADEBOOK;
  30. require_once 'lib/be.inc.php';
  31. require_once 'lib/scoredisplay.class.php';
  32. require_once 'lib/gradebook_functions.inc.php';
  33. require_once 'lib/fe/catform.class.php';
  34. require_once 'lib/fe/evalform.class.php';
  35. require_once 'lib/fe/linkform.class.php';
  36. require_once 'lib/gradebook_data_generator.class.php';
  37. require_once 'lib/fe/gradebooktable.class.php';
  38. require_once 'lib/fe/displaygradebook.php';
  39. require_once 'lib/fe/userform.class.php';
  40. require_once api_get_path(LIBRARY_PATH).'ezpdf/class.ezpdf.php';
  41. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  42. $htmlHeadXtra[] = '<script type="text/javascript">
  43. $(document).ready( function() {
  44. for (i=0;i<$(".actions").length;i++) {
  45. 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) {
  46. $(".actions:eq("+i+")").hide();
  47. }
  48. }
  49. } );
  50. </script>';
  51. api_block_anonymous_users();
  52. $htmlHeadXtra[]= '<script type="text/javascript">
  53. function confirmation ()
  54. {
  55. if (confirm("' . get_lang('DeleteAll') . '?"))
  56. {return true;}
  57. else
  58. {return false;}
  59. }
  60. </script>';
  61. $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
  62. $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  63. $status=CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
  64. $filter_confirm_msg = true;
  65. $filter_warning_msg = true;
  66. ///direct access to one evaluation
  67. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
  68. if (empty($cats))
  69. {
  70. $cats = Category :: load(0, null, $course_code, null, null, $session_id, false);//first time
  71. $first_time=1;
  72. }
  73. $_GET['selectcat'] = $cats[0]->get_id();
  74. //
  75. if (isset($_GET['isStudentView'])) {
  76. if ( (isset($_GET['selectcat']) && $_GET['selectcat']>0) && (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) {
  77. $interbreadcrumb[]= array (
  78. 'url' => 'index.php'.'?selectcat=0&amp;isStudentView='.$_GET['isStudentView'],
  79. 'name' => get_lang('Gradebook')
  80. );
  81. }
  82. }
  83. if ( (isset($_GET['selectcat']) && $_GET['selectcat']>0) && (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) {
  84. Display :: display_header();
  85. //Introduction tool: student view
  86. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  87. $category= $_GET['selectcat'];
  88. $stud_id=api_get_user_id();
  89. $course_code=api_get_course_id();
  90. $session_id=api_get_session_id();
  91. $cats = Category :: load ($category, null, null, null, null, null, false);
  92. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  93. $alleval= $cats[0]->get_evaluations($stud_id);
  94. $alllink= $cats[0]->get_links($stud_id);
  95. $addparams=array();
  96. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  97. $gradebooktable->display();
  98. Display :: display_footer();
  99. exit;
  100. } else {
  101. if ( !isset($_GET['selectcat']) && ($_SESSION['studentview']=='studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='true') ) {
  102. // 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()) ) {
  103. Display :: display_header(get_lang('Gradebook'));
  104. //Introduction tool: student view
  105. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  106. $stud_id=api_get_user_id();
  107. $course_code=api_get_course_id();
  108. $session_id=api_get_session_id();
  109. $addparams=array();
  110. $cats = Category :: load (0, null, null, null, null, null, false);
  111. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  112. $alleval= $cats[0]->get_evaluations($stud_id);
  113. $alllink= $cats[0]->get_links($stud_id);
  114. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  115. $gradebooktable->display();
  116. Display :: display_footer();
  117. exit;
  118. }
  119. }
  120. // --------------------------------------------------------------------------------
  121. // - ACTIONS -
  122. // --------------------------------------------------------------------------------
  123. //this is called when there is no data for the course admin
  124. if (isset ($_GET['createallcategories'])) {
  125. block_students();
  126. $coursecat= Category :: get_not_created_course_categories(api_get_user_id());
  127. if (!count($coursecat) == 0) {
  128. foreach ($coursecat as $row) {
  129. $cat= new Category();
  130. $cat->set_name($row[1]);
  131. $cat->set_course_code($row[0]);
  132. $cat->set_description(null);
  133. $cat->set_user_id(api_get_user_id());
  134. $cat->set_parent_id(0);
  135. $cat->set_weight(0);
  136. $cat->set_visible(0);
  137. $cat->add();
  138. unset ($cat);
  139. }
  140. }
  141. header('Location: '.$_SESSION['gradebook_dest'].'?addallcat=&selectcat=0');
  142. exit;
  143. }
  144. //show logs evaluations
  145. if (isset ($_GET['visiblelog'])) {
  146. header('Location: ' . api_get_self().'/gradebook_showlog_eval.php');
  147. exit;
  148. }
  149. //move a category
  150. if (isset ($_GET['movecat'])) {
  151. block_students();
  152. $cats= Category :: load($_GET['movecat']);
  153. if (!isset ($_GET['targetcat'])) {
  154. $move_form= new CatForm(CatForm :: TYPE_MOVE,
  155. $cats[0],
  156. 'move_cat_form',
  157. null,
  158. api_get_self() . '?movecat=' . Security::remove_XSS($_GET['movecat'])
  159. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  160. if ($move_form->validate()) {
  161. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  162. . '&movecat=' . Security::remove_XSS($_GET['movecat'])
  163. . '&targetcat=' . $move_form->exportValue('move_cat'));
  164. exit;
  165. }
  166. } else {
  167. $targetcat= Category :: load($_GET['targetcat']);
  168. $course_to_crsind = ($cats[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  169. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  170. $cats[0]->move_to_cat($targetcat[0]);
  171. header('Location: ' . api_get_self() . '?categorymoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  172. exit;
  173. }
  174. unset ($targetcat);
  175. }
  176. unset ($cats);
  177. }
  178. //move an evaluation
  179. if (isset ($_GET['moveeval'])) {
  180. block_students();
  181. $evals= Evaluation :: load($_GET['moveeval']);
  182. if (!isset ($_GET['targetcat'])) {
  183. $move_form= new EvalForm(EvalForm :: TYPE_MOVE,
  184. $evals[0],
  185. null,
  186. 'move_eval_form',
  187. null,
  188. api_get_self() . '?moveeval=' . Security::remove_XSS($_GET['moveeval'])
  189. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  190. if ($move_form->validate()) {
  191. header('Location: ' .api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  192. . '&moveeval=' . Security::remove_XSS($_GET['moveeval'])
  193. . '&targetcat=' . $move_form->exportValue('move_cat'));
  194. exit;
  195. }
  196. } else {
  197. $targetcat= Category :: load($_GET['targetcat']);
  198. $course_to_crsind = ($evals[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  199. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  200. $evals[0]->move_to_cat($targetcat[0]);
  201. header('Location: ' . api_get_self() . '?evaluationmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  202. exit;
  203. }
  204. unset ($targetcat);
  205. }
  206. unset ($evals);
  207. }
  208. //move a link
  209. if (isset ($_GET['movelink'])) {
  210. block_students();
  211. $link= LinkFactory :: load($_GET['movelink']);
  212. $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']));
  213. if ($move_form->validate()) {
  214. $targetcat= Category :: load($move_form->exportValue('move_cat'));
  215. $link[0]->move_to_cat($targetcat[0]);
  216. unset ($link);
  217. header('Location: ' . api_get_self(). '?linkmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  218. exit;
  219. }
  220. }
  221. //parameters for categories
  222. if (isset ($_GET['visiblecat'])) {
  223. block_students();
  224. if (isset ($_GET['set_visible'])) {
  225. $visibility_command= 1;
  226. } else {
  227. $visibility_command= 0;
  228. }
  229. $cats= Category :: load($_GET['visiblecat']);
  230. $cats[0]->set_visible($visibility_command);
  231. $cats[0]->save();
  232. $cats[0]->apply_visibility_to_children();
  233. unset ($cats);
  234. if ($visibility_command) {
  235. $confirmation_message = get_lang('ViMod');
  236. $filter_confirm_msg = false;
  237. } else {
  238. $confirmation_message = get_lang('InViMod');
  239. $filter_confirm_msg = false;
  240. }
  241. }
  242. if (isset ($_GET['deletecat'])) {
  243. block_students();
  244. $cats= Category :: load($_GET['deletecat']);
  245. //delete all categories,subcategories and results
  246. if ($cats[0] != null) {
  247. if ($cats[0]->get_id() != 0) {
  248. // better don't try to delete the root...
  249. $cats[0]->delete_all();
  250. }
  251. }
  252. $confirmation_message = get_lang('CategoryDeleted');
  253. $filter_confirm_msg = false;
  254. }
  255. //parameters for evaluations
  256. if (isset ($_GET['visibleeval'])) {
  257. block_students();
  258. if (isset ($_GET['set_visible'])) {
  259. $visibility_command= 1;
  260. } else {
  261. $visibility_command= 0;
  262. }
  263. $eval= Evaluation :: load($_GET['visibleeval']);
  264. $eval[0]->set_visible($visibility_command);
  265. $eval[0]->save();
  266. unset ($eval);
  267. if ($visibility_command) {
  268. $confirmation_message = get_lang('ViMod');
  269. $filter_confirm_msg = false;
  270. } else {
  271. $confirmation_message = get_lang('InViMod');
  272. $filter_confirm_msg = false;
  273. }
  274. }
  275. if (isset ($_GET['deleteeval'])) {
  276. block_students();
  277. $eval= Evaluation :: load($_GET['deleteeval']);
  278. if ($eval[0] != null) {
  279. $eval[0]->delete_with_results();
  280. }
  281. $confirmation_message = get_lang('GradebookEvaluationDeleted');
  282. $filter_confirm_msg = false;
  283. }
  284. //parameters for links
  285. if (isset ($_GET['visiblelink'])) {
  286. block_students();
  287. if (isset ($_GET['set_visible'])) {
  288. $visibility_command= 1;
  289. } else {
  290. $visibility_command= 0;
  291. }
  292. $link= LinkFactory :: load($_GET['visiblelink']);
  293. $link[0]->set_visible($visibility_command);
  294. $link[0]->save();
  295. unset ($link);
  296. if ($visibility_command) {
  297. $confirmation_message = get_lang('ViMod');
  298. $filter_confirm_msg = false;
  299. } else {
  300. $confirmation_message = get_lang('InViMod');
  301. $filter_confirm_msg = false;
  302. }
  303. }
  304. if (isset ($_GET['deletelink'])) {
  305. block_students();
  306. $get_delete_link=Security::remove_XSS($_GET['deletelink']);
  307. $link= LinkFactory :: load($get_delete_link);
  308. if ($link[0] != null) {
  309. $sql='UPDATE '.$tbl_forum_thread.' SET thread_qualify_max=0,thread_weight=0,thread_title_qualify="" WHERE thread_id=(SELECT ref_id FROM '.$tbl_grade_links.' where id='.$get_delete_link.');';
  310. Database::query($sql);
  311. $link[0]->delete();
  312. }
  313. unset ($link);
  314. $confirmation_message = get_lang('LinkDeleted');
  315. $filter_confirm_msg = false;
  316. }
  317. if (!empty($course_to_crsind) && !isset($_GET['confirm'])) {
  318. block_students();
  319. if (!isset($_GET['movecat']) && !isset($_GET['moveeval'])) {
  320. die ('Error: movecat or moveeval not defined');
  321. }
  322. $button = '<form name="confirm"
  323. method="post"
  324. action="'.api_get_self() .'?confirm='
  325. .(isset($_GET['movecat']) ? '&movecat=' . Security::remove_XSS($_GET['movecat'])
  326. : '&moveeval=' . Security::remove_XSS($_GET['moveeval']) )
  327. .'&selectcat=' . Security::remove_XSS($_GET['selectcat'])
  328. .'&targetcat=' . Security::remove_XSS($_GET['targetcat']).'">
  329. <input type="submit" value="'.get_lang('Ok').'">
  330. </form>';
  331. $warning_message = get_lang('MoveWarning').'<br><br>'.$button;
  332. $filter_warning_msg = false;
  333. }
  334. //actions on the sortabletable
  335. if (isset ($_POST['action'])) {
  336. block_students();
  337. $number_of_selected_items= count($_POST['id']);
  338. if ($number_of_selected_items == '0') {
  339. $warning_message = get_lang('NoItemsSelected');
  340. $filter_warning_msg = false;
  341. } else {
  342. switch ($_POST['action']) {
  343. case 'deleted' :
  344. $number_of_deleted_categories= 0;
  345. $number_of_deleted_evaluations= 0;
  346. $number_of_deleted_links= 0;
  347. foreach ($_POST['id'] as $indexstr) {
  348. if (substr($indexstr, 0, 4) == 'CATE') {
  349. $cats= Category :: load(substr($indexstr, 4));
  350. if ($cats[0] != null) {
  351. $cats[0]->delete_all();
  352. }
  353. $number_of_deleted_categories++;
  354. }
  355. if (substr($indexstr, 0, 4) == 'EVAL') {
  356. $eval= Evaluation :: load(substr($indexstr, 4));
  357. if ($eval[0] != null) {
  358. $eval[0]->delete_with_results();
  359. }
  360. $number_of_deleted_evaluations++;
  361. }
  362. if (substr($indexstr, 0, 4) == 'LINK') {
  363. $link= LinkFactory :: load(substr($indexstr, 4));
  364. if ($link[0] != null) {
  365. $link[0]->delete();
  366. }
  367. $number_of_deleted_links++;
  368. }
  369. }
  370. $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>';
  371. $filter_confirm_msg = false;
  372. break;
  373. case 'setvisible' :
  374. foreach ($_POST['id'] as $indexstr) {
  375. if (substr($indexstr, 0, 4) == 'CATE') {
  376. $cats= Category :: load(substr($indexstr, 4));
  377. $cats[0]->set_visible(1);
  378. $cats[0]->save();
  379. $cats[0]->apply_visibility_to_children();
  380. }
  381. if (substr($indexstr, 0, 4) == 'EVAL') {
  382. $eval= Evaluation :: load(substr($indexstr, 4));
  383. $eval[0]->set_visible(1);
  384. $eval[0]->save();
  385. }
  386. if (substr($indexstr, 0, 4) == 'LINK') {
  387. $link= LinkFactory :: load(substr($indexstr, 4));
  388. $link[0]->set_visible(1);
  389. $link[0]->save();
  390. }
  391. }
  392. $confirmation_message = get_lang('ItemsVisible');
  393. $filter_confirm_msg = false;
  394. break;
  395. case 'setinvisible' :
  396. foreach ($_POST['id'] as $indexstr) {
  397. if (substr($indexstr, 0, 4) == 'CATE') {
  398. $cats= Category :: load(substr($indexstr, 4));
  399. $cats[0]->set_visible(0);
  400. $cats[0]->save();
  401. $cats[0]->apply_visibility_to_children();
  402. }
  403. if (substr($indexstr, 0, 4) == 'EVAL') {
  404. $eval= Evaluation :: load(substr($indexstr, 4));
  405. $eval[0]->set_visible(0);
  406. $eval[0]->save();
  407. }
  408. if (substr($indexstr, 0, 4) == 'LINK') {
  409. $link= LinkFactory :: load(substr($indexstr, 4));
  410. $link[0]->set_visible(0);
  411. $link[0]->save();
  412. }
  413. }
  414. $confirmation_message = get_lang('ItemsInVisible');
  415. $filter_confirm_msg = false;
  416. break;
  417. }
  418. }
  419. }
  420. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  421. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  422. . '&search='.Security::remove_XSS($_POST['keyword']));
  423. exit;
  424. }
  425. // --------------------------------------------------------------------------------
  426. // - DISPLAY HEADERS AND MESSAGES -
  427. // --------------------------------------------------------------------------------
  428. if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) {
  429. if (isset ($_GET['studentoverview'])) {
  430. $interbreadcrumb[]= array (
  431. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  432. 'name' => get_lang('Gradebook')
  433. );
  434. Display :: display_header(get_lang('FlatView'));
  435. } elseif (isset ($_GET['search'])) {
  436. $interbreadcrumb[]= array (
  437. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  438. 'name' => get_lang('Gradebook')
  439. );
  440. Display :: display_header(get_lang('SearchResults'));
  441. } elseif(isset ($_GET['selectcat'])) {
  442. $interbreadcrumb[]= array (
  443. 'url' => $_SESSION['gradebook_dest'],
  444. 'name' => get_lang('Gradebook')
  445. );
  446. Display :: display_header('');
  447. } else {
  448. Display :: display_header(get_lang('Gradebook'));
  449. /*if ( ($_SESSION['studentview']=='studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='true') ) {
  450. $cats = Category :: load (0, null, null, null, null, null, false);
  451. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  452. $alleval= $cats[0]->get_evaluations($stud_id);
  453. $alllink= $cats[0]->get_links($stud_id);
  454. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  455. $gradebooktable->display();
  456. Display :: display_footer();
  457. exit;
  458. }*/
  459. }
  460. }
  461. if (isset ($_GET['categorymoved'])) {
  462. Display :: display_confirmation_message(get_lang('CategoryMoved'),false);
  463. }
  464. if (isset ($_GET['evaluationmoved'])) {
  465. Display :: display_confirmation_message(get_lang('EvaluationMoved'),false);
  466. }
  467. if (isset ($_GET['linkmoved'])) {
  468. Display :: display_confirmation_message(get_lang('LinkMoved'),false);
  469. }
  470. if (isset ($_GET['addcat'])) {
  471. Display :: display_confirmation_message(get_lang('CategoryAdded'),false);
  472. }
  473. if (isset ($_GET['linkadded'])) {
  474. Display :: display_confirmation_message(get_lang('LinkAdded'),false);
  475. }
  476. if (isset ($_GET['addresult'])) {
  477. Display :: display_confirmation_message(get_lang('ResultAdded'),false);
  478. }
  479. if (isset ($_GET['editcat'])) {
  480. Display :: display_confirmation_message(get_lang('CategoryEdited'),false);
  481. }
  482. if (isset ($_GET['editeval'])) {
  483. Display :: display_confirmation_message(get_lang('EvaluationEdited'),false);
  484. }
  485. if (isset ($_GET['linkedited'])) {
  486. Display :: display_confirmation_message(get_lang('LinkEdited'),false);
  487. }
  488. if (isset ($_GET['nolinkitems'])){
  489. Display :: display_warning_message(get_lang('NoLinkItems'),false);
  490. }
  491. if (isset ($_GET['addallcat'])){
  492. Display :: display_normal_message(get_lang('AddAllCat'),false);
  493. }
  494. if (isset ($confirmation_message)){
  495. Display :: display_confirmation_message($confirmation_message,$filter_confirm_msg);
  496. }
  497. if (isset ($warning_message)){
  498. Display :: display_warning_message($warning_message,$filter_warning_msg);
  499. }
  500. if (isset ($move_form)){
  501. Display :: display_normal_message($move_form->toHtml(),false);
  502. }
  503. // --------------------------------------------------------------------------------
  504. // - LOAD DATA & DISPLAY TABLE -
  505. // --------------------------------------------------------------------------------
  506. $is_platform_admin= api_is_platform_admin();
  507. $is_course_admin= api_is_allowed_to_create_course();
  508. //load data for category, evaluation and links
  509. if (empty ($_GET['selectcat'])) {
  510. $category= 0;
  511. } else {
  512. $category= $_GET['selectcat'];
  513. }
  514. $simple_search_form='';
  515. // search disabled in course context
  516. /*
  517. $simple_search_form= new UserForm(UserForm :: TYPE_SIMPLE_SEARCH, null, 'simple_search_form', null, api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']));
  518. $values= $simple_search_form->exportValues();
  519. $keyword = '';
  520. if (isset($_GET['search']) && !empty($_GET['search']))
  521. $keyword = Security::remove_XSS($_GET['search']);
  522. if ($simple_search_form->validate() && (empty($keyword)))
  523. $keyword = $values['keyword'];
  524. */
  525. /* search disabled in course context
  526. if (!empty($keyword))
  527. {
  528. $cats= Category :: load($category);
  529. $allcat= array ();
  530. $alleval= Evaluation :: find_evaluations($keyword, $cats[0]->get_id());
  531. $alllink= LinkFactory :: find_links($keyword, $cats[0]->get_id());
  532. }
  533. else
  534. */
  535. if (isset ($_GET['studentoverview'])) {
  536. $cats= Category :: load($category);
  537. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  538. $allcat= array ();
  539. $alleval= $cats[0]->get_evaluations($stud_id, true);
  540. $alllink= $cats[0]->get_links($stud_id, true);
  541. if (isset ($_GET['exportpdf'])) {
  542. $datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
  543. $header_names = array(get_lang('Name'),get_lang('Description'),get_lang('Weight'),get_lang('Date'),get_lang('Results'));
  544. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  545. $newarray = array();
  546. foreach ($data_array as $data) {
  547. $newarray[] = array_slice($data, 1);
  548. }
  549. $pdf= new Cezpdf();
  550. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  551. $pdf->ezSetMargins(30, 30, 50, 30);
  552. $pdf->ezSetY(810);
  553. $pdf->ezText(get_lang('FlatView').' ('. date('j/n/Y g:i') .')',12,array('justification'=>'center'));
  554. $pdf->line(50,790,550,790);
  555. $pdf->line(50,40,550,40);
  556. $pdf->ezSetY(750);
  557. $pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=> 500));
  558. $pdf->ezStream();
  559. exit;
  560. }
  561. } elseif (!empty($_GET['export_certificate'])) {
  562. $user_id = strval(intval($_GET['user']));
  563. if (!api_is_allowed_to_edit(true,true)) {
  564. $user_id = api_get_user_id();
  565. }
  566. $category = Category :: load ($_GET['cat_id']);
  567. if ($category[0]->is_certificate_available($user_id)) {
  568. $user= get_user_info_from_id($user_id);
  569. $scoredisplay = ScoreDisplay :: instance();
  570. $scorecourse = $category[0]->calc_score($user_id);
  571. $scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
  572. $cattotal = Category :: load($_GET['cat_id']);
  573. $scoretotal= $cattotal[0]->calc_score($user_id);
  574. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal,SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  575. //prepare all necessary variables:
  576. $organization_name = api_get_setting('Institution');
  577. $portal_name = api_get_setting('siteName');
  578. $stud_fn = $user['firstname'];
  579. $stud_ln = $user['lastname'];
  580. $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'),$organization_name,$stud_fn.' '.$stud_ln,$category[0]->get_name(),$scorecourse_display);
  581. $certif_text = str_replace("\\n","\n",$certif_text);
  582. $date = date('d/m/Y',time());
  583. $pdf= new Cezpdf('a4','landscape');
  584. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  585. $pdf->ezSetMargins(30, 30, 50, 50);
  586. //line Y coordinates in landscape mode are upside down (500 is on top, 10 is on the bottom)
  587. $pdf->line(50,50,790,50);
  588. $pdf->line(50,550,790,550);
  589. $pdf->ezSetY(450);
  590. $pdf->ezImage(api_get_path(SYS_CODE_PATH).'img/dokeos_logo_certif.png',1,400,'','center','');
  591. $pdf->ezSetY(480);
  592. $pdf->ezText($certif_text,28,array('justification'=>'center'));
  593. //$pdf->ezSetY(750);
  594. $pdf->ezSetY(50);
  595. $pdf->ezText($date,18,array('justification'=>'center'));
  596. $pdf->ezSetY(580);
  597. $pdf->ezText($organization_name,22,array('justification'=>'left'));
  598. $pdf->ezSetY(580);
  599. $pdf->ezText($portal_name,22,array('justification'=>'right'));
  600. $pdf->ezStream();
  601. }
  602. exit;
  603. } else { //in any other case (no search, no pdf), print the available gradebooks
  604. // Important note: loading a category will actually load the *contents* of
  605. // this category. This means that, to show the categories of a course,
  606. // we have to show the root category and show its subcategories that
  607. // are inside this course. This is done at the time of calling
  608. // $cats[0]->get_subcategories(), not at the time of doing Category::load()
  609. // $category comes from GET['selectcat']
  610. $course_code = api_get_course_id();
  611. $session_id = api_get_session_id();
  612. //if $category = 0 (which happens when GET['selectcat'] is undefined)
  613. // then Category::load() will create a new 'root' category with empty
  614. // course and session fields in memory (Category::create_root_category())
  615. if ($_in_course === true) {
  616. // When *inside* a course, we want to make sure there is one (and only
  617. // one) category for this course or for this session.
  618. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  619. if (empty($cats)) {
  620. // There is no category for this course+session, so create one
  621. $cat= new Category();
  622. $course_code = api_get_course_id();
  623. $session_id = api_get_session_id();
  624. if (!empty($session_id)) {
  625. $my_session_id=api_get_session_id();
  626. $s_name = api_get_session_name($my_session_id);
  627. $cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name);
  628. $cat->set_session_id($session_id);
  629. } else {
  630. $cat->set_name($course_code);
  631. }
  632. $cat->set_course_code($course_code);
  633. $cat->set_description(null);
  634. $cat->set_user_id(api_get_user_id());
  635. $cat->set_parent_id(0);
  636. $cat->set_weight(100);
  637. $cat->set_visible(0);
  638. $can_edit = api_is_allowed_to_edit(true, true);
  639. if ($can_edit) {
  640. $cat->add();
  641. }
  642. unset ($cat);
  643. }
  644. unset($cats);
  645. }
  646. $cats = Category :: load ($category, null, null, null, null, null, false);
  647. //with this fix the teacher only can view 1 gradebook
  648. //$stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  649. if (api_is_platform_admin()) {
  650. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  651. } else {
  652. $stud_id= api_get_user_id();
  653. }
  654. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  655. $alleval= $cats[0]->get_evaluations($stud_id);
  656. $alllink= $cats[0]->get_links($stud_id);
  657. //whether we found a category or not, we now have a category object with
  658. // empty or full subcats
  659. }
  660. // add params to the future links (in the table shown)
  661. $addparams = array ('selectcat' => $cats[0]->get_id());
  662. /*
  663. if (isset($_GET['search'])) {
  664. $addparams['search'] = $keyword;
  665. }
  666. */
  667. if (isset ($_GET['studentoverview'])) {
  668. $addparams['studentoverview'] = '';
  669. }
  670. //$addparams['cidReq']='';
  671. if (isset($_GET['cidReq']) && $_GET['cidReq']!='') {
  672. $addparams['cidReq']=Security::remove_XSS($_GET['cidReq']);
  673. } else {
  674. $addparams['cidReq']='';
  675. }
  676. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  677. $no_qualification = false;
  678. if (( count($allcat) == 0) && ( count($alleval) == 0 ) && ( count($alllink) == 0 )) {
  679. $no_qualification = true;
  680. if ((($is_course_admin) && (!isset ($_GET['selectcat']))) && api_is_course_tutor()) {
  681. 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);
  682. }
  683. }
  684. //here we are in a sub category
  685. if ($category != '0') {
  686. $cat=new Category();
  687. //$dblib=new Database();
  688. $category_id=Security::remove_XSS($_GET['selectcat']);
  689. $course_id=Database::get_course_by_category($category_id);
  690. $show_message=$cat->show_message_resource_delete($course_id);
  691. if ($show_message=='') {
  692. DisplayGradebook :: display_header_gradebook($cats[0], 0, $category_id, $is_course_admin, $is_platform_admin, $simple_search_form, false, true);
  693. }
  694. } else {
  695. //this is the root category
  696. //DisplayGradebook :: display_header_gradebook($cats[0], 0, 0, $is_course_admin, $is_platform_admin, $simple_search_form, false, false);
  697. }
  698. if (api_is_platform_admin() || api_is_allowed_to_create_course() || $status==1) {
  699. /*
  700. -----------------------------------------------------------
  701. Introduction section (teacher edit)
  702. -----------------------------------------------------------
  703. */
  704. // Tool introduction
  705. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  706. if ( (isset ($_GET['selectcat']) && $_GET['selectcat']<>0) ) {
  707. //
  708. } else {
  709. if ( ((isset ($_GET['selectcat']) && $_GET['selectcat']==0) || ((isset($_GET['cidReq']) && $_GET['cidReq']!==''))) || isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') {
  710. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  711. if(!$first_time=1)
  712. {
  713. DisplayGradebook :: display_reduce_header_gradebook($cats[0],$is_course_admin, $is_platform_admin, $simple_search_form, false, false);
  714. }
  715. }
  716. }
  717. }
  718. if($first_time==1 && api_is_allowed_to_edit())
  719. {
  720. echo '<meta http-equiv="refresh" content="0;url='.api_get_self().'?cidReq='.$course_code.'" />';
  721. }
  722. else
  723. {
  724. $gradebooktable->display();
  725. }
  726. Display :: display_footer();