index.php 28 KB

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