gradebook.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. <?php
  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= true;
  24. $_in_course = false;
  25. //make sure the destination for scripts is index.php instead of gradebook.php
  26. require_once '../inc/global.inc.php';
  27. $_SESSION['gradebook_dest'] = 'gradebook.php';
  28. $this_section = SECTION_MYGRADEBOOK;
  29. require_once 'lib/be.inc.php';
  30. require_once 'lib/scoredisplay.class.php';
  31. require_once 'lib/gradebook_functions.inc.php';
  32. require_once 'lib/fe/catform.class.php';
  33. require_once 'lib/fe/evalform.class.php';
  34. require_once 'lib/fe/linkform.class.php';
  35. require_once 'lib/gradebook_data_generator.class.php';
  36. require_once 'lib/fe/gradebooktable.class.php';
  37. require_once 'lib/fe/displaygradebook.php';
  38. require_once 'lib/fe/userform.class.php';
  39. require_once api_get_path(LIBRARY_PATH).'ezpdf/class.ezpdf.php';
  40. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  41. $htmlHeadXtra[] = '<script type="text/javascript">
  42. $(document).ready( function() {
  43. for (i=0;i<$(".actions").length;i++) {
  44. if ($(".actions:eq("+i+")").html()=="<table border=\"0\"></table>" || $(".actions:eq("+i+")").html()=="" || $(".actions:eq("+i+")").html()==null) {
  45. $(".actions:eq("+i+")").hide();
  46. }
  47. }
  48. } );
  49. </script>';
  50. api_block_anonymous_users();
  51. $htmlHeadXtra[]= '<script type="text/javascript">
  52. function confirmation ()
  53. {
  54. if (confirm("' . get_lang('DeleteAll') . '?"))
  55. {return true;}
  56. else
  57. {return false;}
  58. }
  59. </script>';
  60. $filter_confirm_msg = true;
  61. $filter_warning_msg = true;
  62. // --------------------------------------------------------------------------------
  63. // - ACTIONS -
  64. // --------------------------------------------------------------------------------
  65. $my_selectcat =isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : '';
  66. if ($my_selectcat!='') {
  67. $my_db_name = get_database_name_by_link_id($my_selectcat);
  68. $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD,$my_db_name);
  69. $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  70. }
  71. //this is called when there is no data for the course admin
  72. if (isset ($_GET['createallcategories'])) {
  73. block_students();
  74. $coursecat= Category :: get_not_created_course_categories(api_get_user_id());
  75. if (!count($coursecat) == 0) {
  76. foreach ($coursecat as $row) {
  77. $cat= new Category();
  78. $cat->set_name($row[1]);
  79. $cat->set_course_code($row[0]);
  80. $cat->set_description(null);
  81. $cat->set_user_id(api_get_user_id());
  82. $cat->set_parent_id(0);
  83. $cat->set_weight(0);
  84. $cat->set_visible(0);
  85. $cat->add();
  86. unset ($cat);
  87. }
  88. }
  89. header('Location: '.$_SESSION['gradebook_dest'].'?addallcat=&selectcat=0');
  90. exit;
  91. }
  92. //move a category
  93. $selectcat=isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : '';
  94. if (isset ($_GET['movecat'])) {
  95. $move_cat=Security::remove_XSS($_GET['movecat']);
  96. block_students();
  97. $cats= Category :: load($move_cat);
  98. if (!isset ($_GET['targetcat'])) {
  99. $move_form= new CatForm(CatForm :: TYPE_MOVE,
  100. $cats[0],
  101. 'move_cat_form',
  102. null,
  103. api_get_self() . '?movecat=' . $move_cat
  104. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  105. if ($move_form->validate()) {
  106. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  107. . '&movecat=' . $move_cat
  108. . '&targetcat=' . $move_form->exportValue('move_cat'));
  109. exit;
  110. }
  111. } else {
  112. $get_target_cat=Security::remove_XSS($_GET['targetcat']);
  113. $targetcat= Category :: load($get_target_cat);
  114. $course_to_crsind = ($cats[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  115. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  116. $cats[0]->move_to_cat($targetcat[0]);
  117. header('Location: ' . api_get_self() . '?categorymoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  118. exit;
  119. }
  120. unset ($targetcat);
  121. }
  122. unset ($cats);
  123. }
  124. //move an evaluation
  125. if (isset ($_GET['moveeval'])) {
  126. block_students();
  127. $get_move_eval=Security::remove_XSS($_GET['moveeval']);
  128. $evals= Evaluation :: load($get_move_eval);
  129. if (!isset ($_GET['targetcat'])) {
  130. $move_form= new EvalForm(EvalForm :: TYPE_MOVE,
  131. $evals[0],
  132. null,
  133. 'move_eval_form',
  134. null,
  135. api_get_self() . '?moveeval=' . $get_move_eval
  136. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  137. if ($move_form->validate()) {
  138. header('Location: ' .api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  139. . '&moveeval=' . $get_move_eval
  140. . '&targetcat=' . $move_form->exportValue('move_cat'));
  141. exit;
  142. }
  143. } else {
  144. $get_target_cat=Security::remove_XSS($_GET['targetcat']);
  145. $targetcat= Category :: load($get_target_cat);
  146. $course_to_crsind = ($evals[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  147. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  148. $evals[0]->move_to_cat($targetcat[0]);
  149. header('Location: ' . api_get_self() . '?evaluationmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  150. exit;
  151. }
  152. unset ($targetcat);
  153. }
  154. unset ($evals);
  155. }
  156. //move a link
  157. if (isset ($_GET['movelink'])) {
  158. block_students();
  159. $get_move_link=Security::remove_XSS($_GET['movelink']);
  160. $link= LinkFactory :: load($get_move_link);
  161. $move_form= new LinkForm(LinkForm :: TYPE_MOVE, null, $link[0], 'move_link_form', null, api_get_self() . '?movelink=' . $get_move_link . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  162. if ($move_form->validate()) {
  163. $targetcat= Category :: load($move_form->exportValue('move_cat'));
  164. $link[0]->move_to_cat($targetcat[0]);
  165. unset ($link);
  166. header('Location: ' . api_get_self(). '?linkmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  167. exit;
  168. }
  169. }
  170. //parameters for categories
  171. if (isset ($_GET['visiblecat'])) {
  172. block_students();
  173. if (isset ($_GET['set_visible'])) {
  174. $visibility_command= 1;
  175. } else {
  176. $visibility_command= 0;
  177. }
  178. $cats= Category :: load(Security::remove_XSS($_GET['visiblecat']));
  179. $cats[0]->set_visible($visibility_command);
  180. $cats[0]->save();
  181. $cats[0]->apply_visibility_to_children();
  182. unset ($cats);
  183. if ($visibility_command) {
  184. $confirmation_message = get_lang('ViMod');
  185. $filter_confirm_msg = false;
  186. } else {
  187. $confirmation_message = get_lang('InViMod');
  188. $filter_confirm_msg = false;
  189. }
  190. }
  191. if (isset ($_GET['deletecat'])) {
  192. block_students();
  193. $cats= Category :: load(Security::remove_XSS($_GET['deletecat']));
  194. //delete all categories,subcategories and results
  195. if ($cats[0] != null) {
  196. if ($cats[0]->get_id() != 0) {
  197. // better don't try to delete the root...
  198. $cats[0]->delete_all();
  199. }
  200. }
  201. $confirmation_message = get_lang('CategoryDeleted');
  202. $filter_confirm_msg = false;
  203. }
  204. //parameters for evaluations
  205. if (isset ($_GET['visibleeval'])) {
  206. block_students();
  207. if (isset ($_GET['set_visible'])) {
  208. $visibility_command= 1;
  209. } else {
  210. $visibility_command= 0;
  211. }
  212. $eval= Evaluation :: load(Security::remove_XSS($_GET['visibleeval']));
  213. $eval[0]->set_visible($visibility_command);
  214. $eval[0]->save();
  215. unset ($eval);
  216. if ($visibility_command) {
  217. $confirmation_message = get_lang('ViMod');
  218. $filter_confirm_msg = false;
  219. } else {
  220. $confirmation_message = get_lang('InViMod');
  221. $filter_confirm_msg = false;
  222. }
  223. }
  224. if (isset ($_GET['deleteeval'])) {
  225. block_students();
  226. $eval= Evaluation :: load(Security::remove_XSS($_GET['deleteeval']));
  227. if ($eval[0] != null) {
  228. $eval[0]->delete_with_results();
  229. }
  230. $confirmation_message = get_lang('GradebookEvaluationDeleted');
  231. $filter_confirm_msg = false;
  232. }
  233. //parameters for links
  234. if (isset ($_GET['visiblelink'])) {
  235. block_students();
  236. if (isset ($_GET['set_visible'])) {
  237. $visibility_command= 1;
  238. }else {
  239. $visibility_command= 0;
  240. }
  241. $link= LinkFactory :: load(Security::remove_XSS($_GET['visiblelink']));
  242. $link[0]->set_visible($visibility_command);
  243. $link[0]->save();
  244. unset ($link);
  245. if ($visibility_command) {
  246. $confirmation_message = get_lang('ViMod');
  247. $filter_confirm_msg = false;
  248. } else {
  249. $confirmation_message = get_lang('InViMod');
  250. $filter_confirm_msg = false;
  251. }
  252. }
  253. if (isset ($_GET['deletelink'])) {
  254. block_students();
  255. //fixing #5229
  256. if (!empty($_GET['deletelink'])) {
  257. $link= LinkFactory :: load(Security::remove_XSS($_GET['deletelink']));
  258. if ($link[0] != null) {
  259. $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='.Security::remove_XSS($_GET['deletelink']).');';
  260. Database::query($sql);
  261. $link[0]->delete();
  262. }
  263. unset ($link);
  264. $confirmation_message = get_lang('LinkDeleted');
  265. $filter_confirm_msg = false;
  266. }
  267. }
  268. $course_to_crsind = isset ($course_to_crsind) ? $course_to_crsind : '';
  269. if ($course_to_crsind && !isset($_GET['confirm'])) {
  270. block_students();
  271. if (!isset($_GET['movecat']) && !isset($_GET['moveeval'])) {
  272. die ('Error: movecat or moveeval not defined');
  273. }
  274. $button = '<form name="confirm"
  275. method="post"
  276. action="'.api_get_self() .'?confirm='
  277. .(isset($_GET['movecat']) ? '&movecat=' . Security::remove_XSS($_GET['movecat'])
  278. : '&moveeval=' . Security::remove_XSS($_GET['moveeval']) )
  279. .'&selectcat=' . Security::remove_XSS($_GET['selectcat'])
  280. .'&targetcat=' . Security::remove_XSS($_GET['targetcat']).'">
  281. <input type="submit" value="'.' '.get_lang('Ok').' '.'">
  282. </form>';
  283. $warning_message = get_lang('MoveWarning').'<br><br>'.$button;
  284. $filter_warning_msg = false;
  285. }
  286. //actions on the sortabletable
  287. if (isset ($_POST['action'])) {
  288. block_students();
  289. $number_of_selected_items= count($_POST['id']);
  290. if ($number_of_selected_items == '0') {
  291. $warning_message = get_lang('NoItemsSelected');
  292. $filter_warning_msg = false;
  293. }
  294. else {
  295. switch ($_POST['action']) {
  296. case 'deleted' :
  297. $number_of_deleted_categories= 0;
  298. $number_of_deleted_evaluations= 0;
  299. $number_of_deleted_links= 0;
  300. foreach ($_POST['id'] as $indexstr) {
  301. if (api_substr($indexstr, 0, 4) == 'CATE') {
  302. $cats= Category :: load(api_substr($indexstr, 4));
  303. if ($cats[0] != null) {
  304. $cats[0]->delete_all();
  305. }
  306. $number_of_deleted_categories++;
  307. }
  308. if (api_substr($indexstr, 0, 4) == 'EVAL') {
  309. $eval= Evaluation :: load(api_substr($indexstr, 4));
  310. if ($eval[0] != null) {
  311. $eval[0]->delete_with_results();
  312. }
  313. $number_of_deleted_evaluations++;
  314. }
  315. if (api_substr($indexstr, 0, 4) == 'LINK') {
  316. $id = api_substr($indexstr, 4);
  317. if (!empty($id)) {
  318. $link= LinkFactory :: load();
  319. if ($link[0] != null) {
  320. $link[0]->delete();
  321. }
  322. $number_of_deleted_links++;
  323. }
  324. }
  325. }
  326. $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>';
  327. $filter_confirm_msg = false;
  328. break;
  329. case 'setvisible' :
  330. foreach ($_POST['id'] as $indexstr)
  331. {
  332. if (api_substr($indexstr, 0, 4) == 'CATE')
  333. {
  334. $cats= Category :: load(api_substr($indexstr, 4));
  335. $cats[0]->set_visible(1);
  336. $cats[0]->save();
  337. $cats[0]->apply_visibility_to_children();
  338. }
  339. if (api_substr($indexstr, 0, 4) == 'EVAL')
  340. {
  341. $eval= Evaluation :: load(api_substr($indexstr, 4));
  342. $eval[0]->set_visible(1);
  343. $eval[0]->save();
  344. }
  345. if (api_substr($indexstr, 0, 4) == 'LINK')
  346. {
  347. $link= LinkFactory :: load(api_substr($indexstr, 4));
  348. $link[0]->set_visible(1);
  349. $link[0]->save();
  350. }
  351. }
  352. $confirmation_message = get_lang('ItemsVisible');
  353. $filter_confirm_msg = false;
  354. break;
  355. case 'setinvisible' :
  356. foreach ($_POST['id'] as $indexstr)
  357. {
  358. if (api_substr($indexstr, 0, 4) == 'CATE')
  359. {
  360. $cats= Category :: load(api_substr($indexstr, 4));
  361. $cats[0]->set_visible(0);
  362. $cats[0]->save();
  363. $cats[0]->apply_visibility_to_children();
  364. }
  365. if (api_substr($indexstr, 0, 4) == 'EVAL')
  366. {
  367. $eval= Evaluation :: load(api_substr($indexstr, 4));
  368. $eval[0]->set_visible(0);
  369. $eval[0]->save();
  370. }
  371. if (api_substr($indexstr, 0, 4) == 'LINK')
  372. {
  373. $link= LinkFactory :: load(api_substr($indexstr, 4));
  374. $link[0]->set_visible(0);
  375. $link[0]->save();
  376. }
  377. }
  378. $confirmation_message = get_lang('ItemsInVisible');
  379. $filter_confirm_msg = false;
  380. break;
  381. }
  382. }
  383. }
  384. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  385. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  386. . '&search='.Security::remove_XSS($_POST['keyword']));
  387. exit;
  388. }
  389. // --------------------------------------------------------------------------------
  390. // - DISPLAY HEADERS AND MESSAGES -
  391. // --------------------------------------------------------------------------------
  392. if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) {
  393. if (isset ($_GET['studentoverview'])) {
  394. $interbreadcrumb[]= array (
  395. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  396. 'name' => get_lang('Gradebook')
  397. );
  398. Display :: display_header(get_lang('FlatView'));
  399. }
  400. elseif (isset ($_GET['search'])) {
  401. $interbreadcrumb[]= array (
  402. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  403. 'name' => get_lang('Gradebook')
  404. );
  405. Display :: display_header(get_lang('SearchResults'));
  406. } else {
  407. $interbreadcrumb[]= array (
  408. 'url' => $_SESSION['gradebook_dest'],
  409. 'name' => get_lang('Gradebook')
  410. );
  411. if ((isset($_GET['selectcat']) && $_GET['selectcat']>0)) {
  412. $interbreadcrumb[]= array (
  413. 'url' => $_SESSION['gradebook_dest'].'?selectcat=0',
  414. 'name' => get_lang('Details')
  415. );
  416. }
  417. Display :: display_header('');
  418. }
  419. }
  420. if (isset ($_GET['categorymoved'])) {
  421. Display :: display_confirmation_message(get_lang('CategoryMoved'),false);
  422. }
  423. if (isset ($_GET['evaluationmoved'])) {
  424. Display :: display_confirmation_message(get_lang('EvaluationMoved'),false);
  425. }
  426. if (isset ($_GET['linkmoved'])) {
  427. Display :: display_confirmation_message(get_lang('LinkMoved'),false);
  428. }
  429. if (isset ($_GET['addcat'])) {
  430. Display :: display_confirmation_message(get_lang('CategoryAdded'),false);
  431. }
  432. if (isset ($_GET['linkadded'])) {
  433. Display :: display_confirmation_message(get_lang('LinkAdded'),false);
  434. }
  435. if (isset ($_GET['addresult'])) {
  436. Display :: display_confirmation_message(get_lang('ResultAdded'),false);
  437. }
  438. if (isset ($_GET['editcat'])) {
  439. Display :: display_confirmation_message(get_lang('CategoryEdited'),false);
  440. }
  441. if (isset ($_GET['editeval'])) {
  442. Display :: display_confirmation_message(get_lang('EvaluationEdited'),false);
  443. }
  444. if (isset ($_GET['linkedited'])) {
  445. Display :: display_confirmation_message(get_lang('LinkEdited'),false);
  446. }
  447. if (isset ($_GET['nolinkitems'])) {
  448. Display :: display_warning_message(get_lang('NoLinkItems'),false);
  449. }
  450. if (isset ($_GET['addallcat'])) {
  451. Display :: display_normal_message(get_lang('AddAllCat'),false);
  452. }
  453. if (isset ($confirmation_message)) {
  454. Display :: display_confirmation_message($confirmation_message,$filter_confirm_msg);
  455. }
  456. if (isset ($warning_message)) {
  457. Display :: display_warning_message($warning_message,$filter_warning_msg);
  458. }
  459. if (isset ($move_form)) {
  460. Display :: display_normal_message($move_form->toHtml(),false);
  461. }
  462. // --------------------------------------------------------------------------------
  463. // - LOAD DATA & DISPLAY TABLE -
  464. // --------------------------------------------------------------------------------
  465. $is_platform_admin= api_is_platform_admin();
  466. $is_course_admin= api_is_allowed_to_create_course();
  467. //load data for category, evaluation and links
  468. if (!isset ($_GET['selectcat']) || empty ($_GET['selectcat'])) {
  469. $category= 0;
  470. } else {
  471. $category= Security::remove_XSS($_GET['selectcat']);
  472. }
  473. // search form
  474. $simple_search_form= new UserForm(UserForm :: TYPE_SIMPLE_SEARCH, null, 'simple_search_form', null, api_get_self() . '?selectcat=' . $selectcat);
  475. $values= $simple_search_form->exportValues();
  476. $keyword = '';
  477. if (isset($_GET['search']) && !empty($_GET['search'])) {
  478. $keyword = Security::remove_XSS($_GET['search']);
  479. }
  480. if ($simple_search_form->validate() && (empty($keyword))) {
  481. $keyword = $values['keyword'];
  482. }
  483. if (!empty($keyword)) {
  484. $cats= Category :: load($category);
  485. $allcat= array ();
  486. if ((isset($_GET['selectcat']) && $_GET['selectcat']==0) && isset($_GET['search'])) {
  487. $allcat= $cats[0]->get_subcategories(null);
  488. $allcat_info = Category :: find_category($keyword,$allcat);
  489. $alleval=array();
  490. $alllink=array();
  491. } else {
  492. $alleval = Evaluation :: find_evaluations($keyword, $cats[0]->get_id());
  493. $alllink = LinkFactory :: find_links($keyword, $cats[0]->get_id());
  494. }
  495. } elseif (isset ($_GET['studentoverview'])) {
  496. $cats= Category :: load($category);
  497. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  498. $allcat= array ();
  499. $alleval= $cats[0]->get_evaluations($stud_id, true);
  500. $alllink= $cats[0]->get_links($stud_id, true);
  501. if (isset ($_GET['exportpdf'])) {
  502. $datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
  503. $header_names = array(get_lang('Name'),get_lang('Description'),get_lang('Weight'),get_lang('Date'),get_lang('Results'));
  504. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  505. $newarray = array();
  506. foreach ($data_array as $data) {
  507. $newarray[] = array_slice($data, 1);
  508. }
  509. $pdf= new Cezpdf();
  510. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  511. $pdf->ezSetMargins(30, 30, 50, 30);
  512. $pdf->ezSetY(810);
  513. $pdf->ezText(get_lang('FlatView').' ('. date('j/n/Y g:i') .')',12,array('justification'=>'center'));
  514. $pdf->line(50,790,550,790);
  515. $pdf->line(50,40,550,40);
  516. $pdf->ezSetY(750);
  517. $pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=> 500));
  518. $pdf->ezStream();
  519. exit;
  520. }
  521. } elseif (!empty($_GET['export_certificate'])){
  522. $user_id = strval(intval($_GET['user']));
  523. if (!api_is_allowed_to_edit(true,true)) {
  524. $user_id = api_get_user_id();
  525. }
  526. $category = Category :: load (Security::remove_XSS($_GET['cat_id']));
  527. if ($category[0]->is_certificate_available($user_id)) {
  528. $user= get_user_info_from_id($user_id);
  529. $scoredisplay = ScoreDisplay :: instance();
  530. $scorecourse = $category[0]->calc_score($user_id);
  531. $scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
  532. $cattotal = Category :: load(0);
  533. $scoretotal= $cattotal[0]->calc_score($user_id);
  534. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal,SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  535. //prepare all necessary variables:
  536. $organization_name = api_get_setting('Institution');
  537. $portal_name = api_get_setting('siteName');
  538. $stud_fn = $user['firstname'];
  539. $stud_ln = $user['lastname'];
  540. $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'),$organization_name,$stud_fn.' '.$stud_ln,$category[0]->get_name(),$scorecourse_display);
  541. $certif_text = str_replace("\\n","\n",$certif_text);
  542. $date = date('d/m/Y',time());
  543. $pdf= new Cezpdf('a4','landscape');
  544. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  545. $pdf->ezSetMargins(30, 30, 50, 50);
  546. //line Y coordinates in landscape mode are upside down (500 is on top, 10 is on the bottom)
  547. $pdf->line(50,50,790,50);
  548. $pdf->line(50,550,790,550);
  549. $pdf->ezSetY(450);
  550. $pdf->ezImage(api_get_path(SYS_CODE_PATH).'img/dokeos_logo_certif.png',1,400,'','center','');
  551. $pdf->ezSetY(480);
  552. $pdf->ezText($certif_text,28,array('justification'=>'center'));
  553. //$pdf->ezSetY(750);
  554. $pdf->ezSetY(50);
  555. $pdf->ezText($date,18,array('justification'=>'center'));
  556. $pdf->ezSetY(580);
  557. $pdf->ezText($organization_name,22,array('justification'=>'left'));
  558. $pdf->ezSetY(580);
  559. $pdf->ezText($portal_name,22,array('justification'=>'right'));
  560. $pdf->ezStream();
  561. }
  562. exit;
  563. } else {
  564. $cats= Category :: load($category);
  565. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  566. $allcat= $cats[0]->get_subcategories($stud_id);
  567. $alleval= $cats[0]->get_evaluations($stud_id);
  568. $alllink= $cats[0]->get_links($stud_id);
  569. }
  570. $addparams = array ('selectcat' => $cats[0]->get_id());
  571. if (isset($_GET['search'])) {
  572. $addparams['search'] = $keyword;
  573. }
  574. if (isset ($_GET['studentoverview'])) {
  575. $addparams['studentoverview'] = '';
  576. }
  577. if (count($allcat_info)>=0 && (isset($_GET['selectcat']) && $_GET['selectcat']==0) && isset($_GET['search']) && strlen(trim($_GET['search']))>0 ) {
  578. $allcat=$allcat_info;
  579. } else {
  580. $allcat=$allcat;
  581. }
  582. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval, $alllink, $addparams);
  583. if (((empty ($allcat)) && (empty ($alleval)) && (empty ($alllink)) && (!$is_platform_admin) && ($is_course_admin) && (!isset ($_GET['selectcat']))) && api_is_course_tutor()) {
  584. 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);
  585. }
  586. //here we are in a sub category
  587. if ($category != '0') {
  588. DisplayGradebook :: display_header_gradebook($cats[0], 1, $_GET['selectcat'], $is_course_admin, $is_platform_admin, $simple_search_form);
  589. } else {
  590. //this is the root category
  591. DisplayGradebook :: display_header_gradebook($cats[0], (((count($allcat) == '0') && (!isset ($_GET['search']))) ? 0 : 1), 0, $is_course_admin, $is_platform_admin, $simple_search_form);
  592. }
  593. $gradebooktable->display();
  594. Display :: display_footer();