index.php 33 KB

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