index.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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. //fixing #5229
  308. if (!empty($get_delete_link)) {
  309. $link= LinkFactory :: load($get_delete_link);
  310. if ($link[0] != null) {
  311. $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.');';
  312. Database::query($sql);
  313. $link[0]->delete();
  314. }
  315. unset ($link);
  316. $confirmation_message = get_lang('LinkDeleted');
  317. $filter_confirm_msg = false;
  318. }
  319. }
  320. if (!empty($course_to_crsind) && !isset($_GET['confirm'])) {
  321. block_students();
  322. if (!isset($_GET['movecat']) && !isset($_GET['moveeval'])) {
  323. die ('Error: movecat or moveeval not defined');
  324. }
  325. $button = '<form name="confirm"
  326. method="post"
  327. action="'.api_get_self() .'?confirm='
  328. .(isset($_GET['movecat']) ? '&movecat=' . Security::remove_XSS($_GET['movecat'])
  329. : '&moveeval=' . Security::remove_XSS($_GET['moveeval']) )
  330. .'&selectcat=' . Security::remove_XSS($_GET['selectcat'])
  331. .'&targetcat=' . Security::remove_XSS($_GET['targetcat']).'">
  332. <input type="submit" value="'.get_lang('Ok').'">
  333. </form>';
  334. $warning_message = get_lang('MoveWarning').'<br><br>'.$button;
  335. $filter_warning_msg = false;
  336. }
  337. //actions on the sortabletable
  338. if (isset ($_POST['action'])) {
  339. block_students();
  340. $number_of_selected_items= count($_POST['id']);
  341. if ($number_of_selected_items == '0') {
  342. $warning_message = get_lang('NoItemsSelected');
  343. $filter_warning_msg = false;
  344. } else {
  345. switch ($_POST['action']) {
  346. case 'deleted' :
  347. $number_of_deleted_categories= 0;
  348. $number_of_deleted_evaluations= 0;
  349. $number_of_deleted_links= 0;
  350. foreach ($_POST['id'] as $indexstr) {
  351. if (substr($indexstr, 0, 4) == 'CATE') {
  352. $cats= Category :: load(substr($indexstr, 4));
  353. if ($cats[0] != null) {
  354. $cats[0]->delete_all();
  355. }
  356. $number_of_deleted_categories++;
  357. }
  358. if (substr($indexstr, 0, 4) == 'EVAL') {
  359. $eval= Evaluation :: load(substr($indexstr, 4));
  360. if ($eval[0] != null) {
  361. $eval[0]->delete_with_results();
  362. }
  363. $number_of_deleted_evaluations++;
  364. }
  365. if (substr($indexstr, 0, 4) == 'LINK') {
  366. //fixing #5229
  367. $id = substr($indexstr, 4);
  368. if (!empty($id)) {
  369. $link= LinkFactory :: load($id);
  370. if ($link[0] != null) {
  371. $link[0]->delete();
  372. }
  373. $number_of_deleted_links++;
  374. }
  375. }
  376. }
  377. $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>';
  378. $filter_confirm_msg = false;
  379. break;
  380. case 'setvisible' :
  381. foreach ($_POST['id'] as $indexstr) {
  382. if (substr($indexstr, 0, 4) == 'CATE') {
  383. $cats= Category :: load(substr($indexstr, 4));
  384. $cats[0]->set_visible(1);
  385. $cats[0]->save();
  386. $cats[0]->apply_visibility_to_children();
  387. }
  388. if (substr($indexstr, 0, 4) == 'EVAL') {
  389. $eval= Evaluation :: load(substr($indexstr, 4));
  390. $eval[0]->set_visible(1);
  391. $eval[0]->save();
  392. }
  393. if (substr($indexstr, 0, 4) == 'LINK') {
  394. $link= LinkFactory :: load(substr($indexstr, 4));
  395. $link[0]->set_visible(1);
  396. $link[0]->save();
  397. }
  398. }
  399. $confirmation_message = get_lang('ItemsVisible');
  400. $filter_confirm_msg = false;
  401. break;
  402. case 'setinvisible' :
  403. foreach ($_POST['id'] as $indexstr) {
  404. if (substr($indexstr, 0, 4) == 'CATE') {
  405. $cats= Category :: load(substr($indexstr, 4));
  406. $cats[0]->set_visible(0);
  407. $cats[0]->save();
  408. $cats[0]->apply_visibility_to_children();
  409. }
  410. if (substr($indexstr, 0, 4) == 'EVAL') {
  411. $eval= Evaluation :: load(substr($indexstr, 4));
  412. $eval[0]->set_visible(0);
  413. $eval[0]->save();
  414. }
  415. if (substr($indexstr, 0, 4) == 'LINK') {
  416. $link= LinkFactory :: load(substr($indexstr, 4));
  417. $link[0]->set_visible(0);
  418. $link[0]->save();
  419. }
  420. }
  421. $confirmation_message = get_lang('ItemsInVisible');
  422. $filter_confirm_msg = false;
  423. break;
  424. }
  425. }
  426. }
  427. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  428. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  429. . '&search='.Security::remove_XSS($_POST['keyword']));
  430. exit;
  431. }
  432. // --------------------------------------------------------------------------------
  433. // - DISPLAY HEADERS AND MESSAGES -
  434. // --------------------------------------------------------------------------------
  435. if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) {
  436. if (isset ($_GET['studentoverview'])) {
  437. $interbreadcrumb[]= array (
  438. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  439. 'name' => get_lang('Gradebook')
  440. );
  441. Display :: display_header(get_lang('FlatView'));
  442. } elseif (isset ($_GET['search'])) {
  443. $interbreadcrumb[]= array (
  444. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  445. 'name' => get_lang('Gradebook')
  446. );
  447. Display :: display_header(get_lang('SearchResults'));
  448. } elseif(isset ($_GET['selectcat'])) {
  449. $interbreadcrumb[]= array (
  450. 'url' => $_SESSION['gradebook_dest'],
  451. 'name' => get_lang('Gradebook')
  452. );
  453. Display :: display_header('');
  454. } else {
  455. Display :: display_header(get_lang('Gradebook'));
  456. /*if ( ($_SESSION['studentview']=='studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='true') ) {
  457. $cats = Category :: load (0, null, null, null, null, null, false);
  458. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  459. $alleval= $cats[0]->get_evaluations($stud_id);
  460. $alllink= $cats[0]->get_links($stud_id);
  461. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  462. $gradebooktable->display();
  463. Display :: display_footer();
  464. exit;
  465. }*/
  466. }
  467. }
  468. if (isset ($_GET['categorymoved'])) {
  469. Display :: display_confirmation_message(get_lang('CategoryMoved'),false);
  470. }
  471. if (isset ($_GET['evaluationmoved'])) {
  472. Display :: display_confirmation_message(get_lang('EvaluationMoved'),false);
  473. }
  474. if (isset ($_GET['linkmoved'])) {
  475. Display :: display_confirmation_message(get_lang('LinkMoved'),false);
  476. }
  477. if (isset ($_GET['addcat'])) {
  478. Display :: display_confirmation_message(get_lang('CategoryAdded'),false);
  479. }
  480. if (isset ($_GET['linkadded'])) {
  481. Display :: display_confirmation_message(get_lang('LinkAdded'),false);
  482. }
  483. if (isset ($_GET['addresult'])) {
  484. Display :: display_confirmation_message(get_lang('ResultAdded'),false);
  485. }
  486. if (isset ($_GET['editcat'])) {
  487. Display :: display_confirmation_message(get_lang('CategoryEdited'),false);
  488. }
  489. if (isset ($_GET['editeval'])) {
  490. Display :: display_confirmation_message(get_lang('EvaluationEdited'),false);
  491. }
  492. if (isset ($_GET['linkedited'])) {
  493. Display :: display_confirmation_message(get_lang('LinkEdited'),false);
  494. }
  495. if (isset ($_GET['nolinkitems'])){
  496. Display :: display_warning_message(get_lang('NoLinkItems'),false);
  497. }
  498. if (isset ($_GET['addallcat'])){
  499. Display :: display_normal_message(get_lang('AddAllCat'),false);
  500. }
  501. if (isset ($confirmation_message)){
  502. Display :: display_confirmation_message($confirmation_message,$filter_confirm_msg);
  503. }
  504. if (isset ($warning_message)){
  505. Display :: display_warning_message($warning_message,$filter_warning_msg);
  506. }
  507. if (isset ($move_form)){
  508. Display :: display_normal_message($move_form->toHtml(),false);
  509. }
  510. // --------------------------------------------------------------------------------
  511. // - LOAD DATA & DISPLAY TABLE -
  512. // --------------------------------------------------------------------------------
  513. $is_platform_admin= api_is_platform_admin();
  514. $is_course_admin= api_is_allowed_to_create_course();
  515. //load data for category, evaluation and links
  516. if (empty ($_GET['selectcat'])) {
  517. $category= 0;
  518. } else {
  519. $category= $_GET['selectcat'];
  520. }
  521. $simple_search_form='';
  522. // search disabled in course context
  523. /*
  524. $simple_search_form= new UserForm(UserForm :: TYPE_SIMPLE_SEARCH, null, 'simple_search_form', null, api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']));
  525. $values= $simple_search_form->exportValues();
  526. $keyword = '';
  527. if (isset($_GET['search']) && !empty($_GET['search']))
  528. $keyword = Security::remove_XSS($_GET['search']);
  529. if ($simple_search_form->validate() && (empty($keyword)))
  530. $keyword = $values['keyword'];
  531. */
  532. /* search disabled in course context
  533. if (!empty($keyword))
  534. {
  535. $cats= Category :: load($category);
  536. $allcat= array ();
  537. $alleval= Evaluation :: find_evaluations($keyword, $cats[0]->get_id());
  538. $alllink= LinkFactory :: find_links($keyword, $cats[0]->get_id());
  539. }
  540. else
  541. */
  542. if (isset ($_GET['studentoverview'])) {
  543. $cats= Category :: load($category);
  544. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  545. $allcat= array ();
  546. $alleval= $cats[0]->get_evaluations($stud_id, true);
  547. $alllink= $cats[0]->get_links($stud_id, true);
  548. if (isset ($_GET['exportpdf'])) {
  549. $datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
  550. $header_names = array(get_lang('Name'),get_lang('Description'),get_lang('Weight'),get_lang('Date'),get_lang('Results'));
  551. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  552. $newarray = array();
  553. foreach ($data_array as $data) {
  554. $newarray[] = array_slice($data, 1);
  555. }
  556. $pdf= new Cezpdf();
  557. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  558. $pdf->ezSetMargins(30, 30, 50, 30);
  559. $pdf->ezSetY(810);
  560. $pdf->ezText(get_lang('FlatView').' ('. date('j/n/Y g:i') .')',12,array('justification'=>'center'));
  561. $pdf->line(50,790,550,790);
  562. $pdf->line(50,40,550,40);
  563. $pdf->ezSetY(750);
  564. $pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=> 500));
  565. $pdf->ezStream();
  566. exit;
  567. }
  568. } elseif (!empty($_GET['export_certificate'])) {
  569. $user_id = strval(intval($_GET['user']));
  570. if (!api_is_allowed_to_edit(true,true)) {
  571. $user_id = api_get_user_id();
  572. }
  573. $category = Category :: load($category); //hack replace $category = Category :: load ($_GET['cat_id']); to get de course name in certificates
  574. if ($category[0]->is_certificate_available($user_id)) {
  575. $user= get_user_info_from_id($user_id);
  576. $scoredisplay = ScoreDisplay :: instance();
  577. $scorecourse = $category[0]->calc_score($user_id);
  578. $scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
  579. $cattotal = Category :: load($_GET['cat_id']);
  580. $scoretotal= $cattotal[0]->calc_score($user_id);
  581. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal,SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  582. //prepare all necessary variables:
  583. $organization_name = api_get_setting('Institution');
  584. $portal_name = api_get_setting('siteName');
  585. $stud_fn = $user['firstname'];
  586. $stud_ln = $user['lastname'];
  587. $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'),$organization_name,$stud_fn.' '.$stud_ln,$category[0]->get_name(),$scorecourse_display);
  588. $certif_text = str_replace("\\n","\n",$certif_text);
  589. $date = date('d/m/Y',time());
  590. $pdf= new Cezpdf('a4','landscape');
  591. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  592. $pdf->ezSetMargins(30, 30, 50, 50);
  593. //line Y coordinates in landscape mode are upside down (500 is on top, 10 is on the bottom)
  594. $pdf->line(50,50,790,50);
  595. $pdf->line(50,550,790,550);
  596. $pdf->ezSetY(450);
  597. $pdf->ezImage(api_get_path(SYS_CODE_PATH).'img/dokeos_logo_certif.png',1,400,'','center','');
  598. $pdf->ezSetY(480);
  599. $pdf->ezText($certif_text,28,array('justification'=>'center'));
  600. //$pdf->ezSetY(750);
  601. $pdf->ezSetY(50);
  602. $pdf->ezText($date,18,array('justification'=>'center'));
  603. $pdf->ezSetY(580);
  604. $pdf->ezText($organization_name,22,array('justification'=>'left'));
  605. $pdf->ezSetY(580);
  606. $pdf->ezText($portal_name,22,array('justification'=>'right'));
  607. $pdf->ezStream();
  608. }
  609. exit;
  610. } else { //in any other case (no search, no pdf), print the available gradebooks
  611. // Important note: loading a category will actually load the *contents* of
  612. // this category. This means that, to show the categories of a course,
  613. // we have to show the root category and show its subcategories that
  614. // are inside this course. This is done at the time of calling
  615. // $cats[0]->get_subcategories(), not at the time of doing Category::load()
  616. // $category comes from GET['selectcat']
  617. $course_code = api_get_course_id();
  618. $session_id = api_get_session_id();
  619. //if $category = 0 (which happens when GET['selectcat'] is undefined)
  620. // then Category::load() will create a new 'root' category with empty
  621. // course and session fields in memory (Category::create_root_category())
  622. if ($_in_course === true) {
  623. // When *inside* a course, we want to make sure there is one (and only
  624. // one) category for this course or for this session.
  625. //hack for delete a gradebook from inside course
  626. $clean_deletecat=Security::remove_XSS($_GET['deletecat']);
  627. if (!empty($clean_deletecat))
  628. {
  629. exit;
  630. }
  631. //end hack
  632. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  633. if (empty($cats)) {
  634. // There is no category for this course+session, so create one
  635. $cat= new Category();
  636. $course_code = api_get_course_id();
  637. $session_id = api_get_session_id();
  638. if (!empty($session_id)) {
  639. $my_session_id=api_get_session_id();
  640. $s_name = api_get_session_name($my_session_id);
  641. $cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name);
  642. $cat->set_session_id($session_id);
  643. } else {
  644. $cat->set_name($course_code);
  645. }
  646. $cat->set_course_code($course_code);
  647. $cat->set_description(null);
  648. $cat->set_user_id(api_get_user_id());
  649. $cat->set_parent_id(0);
  650. $cat->set_weight(100);
  651. $cat->set_visible(0);
  652. $can_edit = api_is_allowed_to_edit(true, true);
  653. if ($can_edit) {
  654. $cat->add();
  655. }
  656. unset ($cat);
  657. }
  658. unset($cats);
  659. }
  660. $cats = Category :: load ($category, null, null, null, null, null, false);
  661. //with this fix the teacher only can view 1 gradebook
  662. //$stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  663. if (api_is_platform_admin()) {
  664. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  665. } else {
  666. $stud_id= api_get_user_id();
  667. }
  668. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  669. $alleval= $cats[0]->get_evaluations($stud_id);
  670. $alllink= $cats[0]->get_links($stud_id);
  671. //whether we found a category or not, we now have a category object with
  672. // empty or full subcats
  673. }
  674. // add params to the future links (in the table shown)
  675. $addparams = array ('selectcat' => $cats[0]->get_id());
  676. /*
  677. if (isset($_GET['search'])) {
  678. $addparams['search'] = $keyword;
  679. }
  680. */
  681. if (isset ($_GET['studentoverview'])) {
  682. $addparams['studentoverview'] = '';
  683. }
  684. //$addparams['cidReq']='';
  685. if (isset($_GET['cidReq']) && $_GET['cidReq']!='') {
  686. $addparams['cidReq']=Security::remove_XSS($_GET['cidReq']);
  687. } else {
  688. $addparams['cidReq']='';
  689. }
  690. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  691. $no_qualification = false;
  692. if (( count($allcat) == 0) && ( count($alleval) == 0 ) && ( count($alllink) == 0 )) {
  693. $no_qualification = true;
  694. if ((($is_course_admin) && (!isset ($_GET['selectcat']))) && api_is_course_tutor()) {
  695. 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);
  696. }
  697. }
  698. //here we are in a sub category
  699. if ($category != '0') {
  700. $cat=new Category();
  701. //$dblib=new Database();
  702. $category_id=Security::remove_XSS($_GET['selectcat']);
  703. $course_id=Database::get_course_by_category($category_id);
  704. $show_message=$cat->show_message_resource_delete($course_id);
  705. if ($show_message=='') {
  706. //hack for inside courses menu cat
  707. if (api_is_allowed_to_edit()) {
  708. $op_cat_weight= '<strong>'.get_lang('Weight').'</strong>'.': '.((intval($cats[0]->get_weight())>0) ? $cats[0]->get_weight() : 0);
  709. $opt_cat_cert_min= '<strong>'.get_lang('CertificateMinScore').'</strong>'.': '.(intval($cats[0]->get_certificate_min_score()>0) ? $cats[0]->get_certificate_min_score() : 0);
  710. $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());
  711. $visibility_icon= ($cats[0]->is_visible() == 0) ? 'invisible' : 'visible';
  712. $visibility_command= ($cats[0]->is_visible() == 0) ? 'set_visible' : 'set_invisible';
  713. echo '<div class="actions" align="right">';
  714. $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>';
  715. $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>';
  716. $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>';
  717. $opt_cat_descrip1 = strip_tags($opt_cat_descrip);
  718. 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>';
  719. echo $modify_icons;
  720. echo '</div>';
  721. }
  722. else
  723. {
  724. // generating the total score for a course
  725. $stud_id= api_get_user_id();
  726. $cats_course = Category :: load ($id, null, null, null, null, null, false);
  727. $alleval_course= $cats_course[0]->get_evaluations($stud_id,true);
  728. $alllink_course= $cats_course[0]->get_links($stud_id,true);
  729. $evals_links = array_merge($alleval_course, $alllink_course);
  730. $item_value=0;
  731. $item_total=0;
  732. for ($count=0; $count < count($evals_links); $count++) {
  733. $item = $evals_links[$count];
  734. $score = $item->calc_score($stud_id);
  735. $score_denom=($score[1]==0) ? 1 : $score[1];
  736. $item_value+=$score[0]/$score_denom*$item->get_weight();
  737. $item_total+=$item->get_weight();
  738. }
  739. $item_value = number_format($item_value, 2, '.', ' ');
  740. $cattotal = Category :: load($id);
  741. $scoretotal= $cattotal[0]->calc_score(api_get_user_id());
  742. $scoretotal_display = (isset($scoretotal)? round($scoretotal[0],2).'/'.round($scoretotal[1],2).'('.round(($scoretotal[0] / $scoretotal[1]) * 100,2) . ' %)': '-');
  743. //show certificate
  744. $certificate_min_score=$cats[0]->get_certificate_min_score();
  745. if (isset($certificate_min_score) && (int)$item_value >= (int)$certificate_min_score) {
  746. $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;
  747. echo '<div class="actions" align="right">';
  748. echo $certificates;
  749. echo '</div>';
  750. }
  751. } //end hack
  752. DisplayGradebook :: display_header_gradebook($cats[0], 0, $category_id, $is_course_admin, $is_platform_admin, $simple_search_form, false, true);
  753. }
  754. } else {
  755. //this is the root category
  756. //DisplayGradebook :: display_header_gradebook($cats[0], 0, 0, $is_course_admin, $is_platform_admin, $simple_search_form, false, false);
  757. }
  758. if (api_is_platform_admin() || api_is_allowed_to_create_course() || $status==1) {
  759. /*
  760. -----------------------------------------------------------
  761. Introduction section (teacher edit)
  762. -----------------------------------------------------------
  763. */
  764. // Tool introduction
  765. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  766. if ( (isset ($_GET['selectcat']) && $_GET['selectcat']<>0) ) {
  767. //
  768. } else {
  769. if ( ((isset ($_GET['selectcat']) && $_GET['selectcat']==0) || ((isset($_GET['cidReq']) && $_GET['cidReq']!==''))) || isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') {
  770. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  771. if(!$first_time=1)
  772. {
  773. DisplayGradebook :: display_reduce_header_gradebook($cats[0],$is_course_admin, $is_platform_admin, $simple_search_form, false, false);
  774. }
  775. }
  776. }
  777. }
  778. if($first_time==1 && api_is_allowed_to_edit())
  779. {
  780. echo '<meta http-equiv="refresh" content="0;url='.api_get_self().'?cidReq='.$course_code.'" />';
  781. }
  782. else
  783. {
  784. $gradebooktable->display();
  785. }
  786. Display :: display_footer();