gradebook.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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. $link= LinkFactory :: load(Security::remove_XSS($_GET['deletelink']));
  256. if ($link[0] != null) {
  257. $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']).');';
  258. Database::query($sql);
  259. $link[0]->delete();
  260. }
  261. unset ($link);
  262. $confirmation_message = get_lang('LinkDeleted');
  263. $filter_confirm_msg = false;
  264. }
  265. $course_to_crsind = isset ($course_to_crsind) ? $course_to_crsind : '';
  266. if ($course_to_crsind && !isset($_GET['confirm'])) {
  267. block_students();
  268. if (!isset($_GET['movecat']) && !isset($_GET['moveeval'])) {
  269. die ('Error: movecat or moveeval not defined');
  270. }
  271. $button = '<form name="confirm"
  272. method="post"
  273. action="'.api_get_self() .'?confirm='
  274. .(isset($_GET['movecat']) ? '&movecat=' . Security::remove_XSS($_GET['movecat'])
  275. : '&moveeval=' . Security::remove_XSS($_GET['moveeval']) )
  276. .'&selectcat=' . Security::remove_XSS($_GET['selectcat'])
  277. .'&targetcat=' . Security::remove_XSS($_GET['targetcat']).'">
  278. <input type="submit" value="'.' '.get_lang('Ok').' '.'">
  279. </form>';
  280. $warning_message = get_lang('MoveWarning').'<br><br>'.$button;
  281. $filter_warning_msg = false;
  282. }
  283. //actions on the sortabletable
  284. if (isset ($_POST['action'])) {
  285. block_students();
  286. $number_of_selected_items= count($_POST['id']);
  287. if ($number_of_selected_items == '0') {
  288. $warning_message = get_lang('NoItemsSelected');
  289. $filter_warning_msg = false;
  290. }
  291. else {
  292. switch ($_POST['action']) {
  293. case 'deleted' :
  294. $number_of_deleted_categories= 0;
  295. $number_of_deleted_evaluations= 0;
  296. $number_of_deleted_links= 0;
  297. foreach ($_POST['id'] as $indexstr) {
  298. if (api_substr($indexstr, 0, 4) == 'CATE') {
  299. $cats= Category :: load(api_substr($indexstr, 4));
  300. if ($cats[0] != null) {
  301. $cats[0]->delete_all();
  302. }
  303. $number_of_deleted_categories++;
  304. }
  305. if (api_substr($indexstr, 0, 4) == 'EVAL') {
  306. $eval= Evaluation :: load(api_substr($indexstr, 4));
  307. if ($eval[0] != null) {
  308. $eval[0]->delete_with_results();
  309. }
  310. $number_of_deleted_evaluations++;
  311. }
  312. if (api_substr($indexstr, 0, 4) == 'LINK') {
  313. $link= LinkFactory :: load(api_substr($indexstr, 4));
  314. if ($link[0] != null) {
  315. $link[0]->delete();
  316. }
  317. $number_of_deleted_links++;
  318. }
  319. }
  320. $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>';
  321. $filter_confirm_msg = false;
  322. break;
  323. case 'setvisible' :
  324. foreach ($_POST['id'] as $indexstr)
  325. {
  326. if (api_substr($indexstr, 0, 4) == 'CATE')
  327. {
  328. $cats= Category :: load(api_substr($indexstr, 4));
  329. $cats[0]->set_visible(1);
  330. $cats[0]->save();
  331. $cats[0]->apply_visibility_to_children();
  332. }
  333. if (api_substr($indexstr, 0, 4) == 'EVAL')
  334. {
  335. $eval= Evaluation :: load(api_substr($indexstr, 4));
  336. $eval[0]->set_visible(1);
  337. $eval[0]->save();
  338. }
  339. if (api_substr($indexstr, 0, 4) == 'LINK')
  340. {
  341. $link= LinkFactory :: load(api_substr($indexstr, 4));
  342. $link[0]->set_visible(1);
  343. $link[0]->save();
  344. }
  345. }
  346. $confirmation_message = get_lang('ItemsVisible');
  347. $filter_confirm_msg = false;
  348. break;
  349. case 'setinvisible' :
  350. foreach ($_POST['id'] as $indexstr)
  351. {
  352. if (api_substr($indexstr, 0, 4) == 'CATE')
  353. {
  354. $cats= Category :: load(api_substr($indexstr, 4));
  355. $cats[0]->set_visible(0);
  356. $cats[0]->save();
  357. $cats[0]->apply_visibility_to_children();
  358. }
  359. if (api_substr($indexstr, 0, 4) == 'EVAL')
  360. {
  361. $eval= Evaluation :: load(api_substr($indexstr, 4));
  362. $eval[0]->set_visible(0);
  363. $eval[0]->save();
  364. }
  365. if (api_substr($indexstr, 0, 4) == 'LINK')
  366. {
  367. $link= LinkFactory :: load(api_substr($indexstr, 4));
  368. $link[0]->set_visible(0);
  369. $link[0]->save();
  370. }
  371. }
  372. $confirmation_message = get_lang('ItemsInVisible');
  373. $filter_confirm_msg = false;
  374. break;
  375. }
  376. }
  377. }
  378. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  379. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  380. . '&search='.Security::remove_XSS($_POST['keyword']));
  381. exit;
  382. }
  383. // --------------------------------------------------------------------------------
  384. // - DISPLAY HEADERS AND MESSAGES -
  385. // --------------------------------------------------------------------------------
  386. if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) {
  387. if (isset ($_GET['studentoverview'])) {
  388. $interbreadcrumb[]= array (
  389. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  390. 'name' => get_lang('Gradebook')
  391. );
  392. Display :: display_header(get_lang('FlatView'));
  393. }
  394. elseif (isset ($_GET['search'])) {
  395. $interbreadcrumb[]= array (
  396. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  397. 'name' => get_lang('Gradebook')
  398. );
  399. Display :: display_header(get_lang('SearchResults'));
  400. } else {
  401. $interbreadcrumb[]= array (
  402. 'url' => $_SESSION['gradebook_dest'],
  403. 'name' => get_lang('Gradebook')
  404. );
  405. if ((isset($_GET['selectcat']) && $_GET['selectcat']>0)) {
  406. $interbreadcrumb[]= array (
  407. 'url' => $_SESSION['gradebook_dest'].'?selectcat=0',
  408. 'name' => get_lang('Details')
  409. );
  410. }
  411. Display :: display_header('');
  412. }
  413. }
  414. if (isset ($_GET['categorymoved'])) {
  415. Display :: display_confirmation_message(get_lang('CategoryMoved'),false);
  416. }
  417. if (isset ($_GET['evaluationmoved'])) {
  418. Display :: display_confirmation_message(get_lang('EvaluationMoved'),false);
  419. }
  420. if (isset ($_GET['linkmoved'])) {
  421. Display :: display_confirmation_message(get_lang('LinkMoved'),false);
  422. }
  423. if (isset ($_GET['addcat'])) {
  424. Display :: display_confirmation_message(get_lang('CategoryAdded'),false);
  425. }
  426. if (isset ($_GET['linkadded'])) {
  427. Display :: display_confirmation_message(get_lang('LinkAdded'),false);
  428. }
  429. if (isset ($_GET['addresult'])) {
  430. Display :: display_confirmation_message(get_lang('ResultAdded'),false);
  431. }
  432. if (isset ($_GET['editcat'])) {
  433. Display :: display_confirmation_message(get_lang('CategoryEdited'),false);
  434. }
  435. if (isset ($_GET['editeval'])) {
  436. Display :: display_confirmation_message(get_lang('EvaluationEdited'),false);
  437. }
  438. if (isset ($_GET['linkedited'])) {
  439. Display :: display_confirmation_message(get_lang('LinkEdited'),false);
  440. }
  441. if (isset ($_GET['nolinkitems'])) {
  442. Display :: display_warning_message(get_lang('NoLinkItems'),false);
  443. }
  444. if (isset ($_GET['addallcat'])) {
  445. Display :: display_normal_message(get_lang('AddAllCat'),false);
  446. }
  447. if (isset ($confirmation_message)) {
  448. Display :: display_confirmation_message($confirmation_message,$filter_confirm_msg);
  449. }
  450. if (isset ($warning_message)) {
  451. Display :: display_warning_message($warning_message,$filter_warning_msg);
  452. }
  453. if (isset ($move_form)) {
  454. Display :: display_normal_message($move_form->toHtml(),false);
  455. }
  456. // --------------------------------------------------------------------------------
  457. // - LOAD DATA & DISPLAY TABLE -
  458. // --------------------------------------------------------------------------------
  459. $is_platform_admin= api_is_platform_admin();
  460. $is_course_admin= api_is_allowed_to_create_course();
  461. //load data for category, evaluation and links
  462. if (!isset ($_GET['selectcat']) || empty ($_GET['selectcat'])) {
  463. $category= 0;
  464. } else {
  465. $category= Security::remove_XSS($_GET['selectcat']);
  466. }
  467. // search form
  468. $simple_search_form= new UserForm(UserForm :: TYPE_SIMPLE_SEARCH, null, 'simple_search_form', null, api_get_self() . '?selectcat=' . $selectcat);
  469. $values= $simple_search_form->exportValues();
  470. $keyword = '';
  471. if (isset($_GET['search']) && !empty($_GET['search'])) {
  472. $keyword = Security::remove_XSS($_GET['search']);
  473. }
  474. if ($simple_search_form->validate() && (empty($keyword))) {
  475. $keyword = $values['keyword'];
  476. }
  477. if (!empty($keyword)) {
  478. $cats= Category :: load($category);
  479. $allcat= array ();
  480. if ((isset($_GET['selectcat']) && $_GET['selectcat']==0) && isset($_GET['search'])) {
  481. $allcat= $cats[0]->get_subcategories(null);
  482. $allcat_info = Category :: find_category($keyword,$allcat);
  483. $alleval=array();
  484. $alllink=array();
  485. } else {
  486. $alleval = Evaluation :: find_evaluations($keyword, $cats[0]->get_id());
  487. $alllink = LinkFactory :: find_links($keyword, $cats[0]->get_id());
  488. }
  489. } elseif (isset ($_GET['studentoverview'])) {
  490. $cats= Category :: load($category);
  491. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  492. $allcat= array ();
  493. $alleval= $cats[0]->get_evaluations($stud_id, true);
  494. $alllink= $cats[0]->get_links($stud_id, true);
  495. if (isset ($_GET['exportpdf'])) {
  496. $datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
  497. $header_names = array(get_lang('Name'),get_lang('Description'),get_lang('Weight'),get_lang('Date'),get_lang('Results'));
  498. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  499. $newarray = array();
  500. foreach ($data_array as $data) {
  501. $newarray[] = array_slice($data, 1);
  502. }
  503. $pdf= new Cezpdf();
  504. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  505. $pdf->ezSetMargins(30, 30, 50, 30);
  506. $pdf->ezSetY(810);
  507. $pdf->ezText(get_lang('FlatView').' ('. date('j/n/Y g:i') .')',12,array('justification'=>'center'));
  508. $pdf->line(50,790,550,790);
  509. $pdf->line(50,40,550,40);
  510. $pdf->ezSetY(750);
  511. $pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=> 500));
  512. $pdf->ezStream();
  513. exit;
  514. }
  515. } elseif (!empty($_GET['export_certificate'])){
  516. $user_id = strval(intval($_GET['user']));
  517. if (!api_is_allowed_to_edit(true,true)) {
  518. $user_id = api_get_user_id();
  519. }
  520. $category = Category :: load (Security::remove_XSS($_GET['cat']));
  521. if ($category[0]->is_certificate_available($user_id)) {
  522. $user= get_user_info_from_id($user_id);
  523. $scoredisplay = ScoreDisplay :: instance();
  524. $scorecourse = $category[0]->calc_score($user_id);
  525. $scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
  526. $cattotal = Category :: load(0);
  527. $scoretotal= $cattotal[0]->calc_score($user_id);
  528. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal,SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  529. //prepare all necessary variables:
  530. $organization_name = api_get_setting('Institution');
  531. $portal_name = api_get_setting('siteName');
  532. $stud_fn = $user['firstname'];
  533. $stud_ln = $user['lastname'];
  534. $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'),$organization_name,$stud_fn.' '.$stud_ln,$category[0]->get_name(),$scorecourse_display);
  535. $certif_text = str_replace("\\n","\n",$certif_text);
  536. $date = date('d/m/Y',time());
  537. $pdf= new Cezpdf('a4','landscape');
  538. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  539. $pdf->ezSetMargins(30, 30, 50, 50);
  540. //line Y coordinates in landscape mode are upside down (500 is on top, 10 is on the bottom)
  541. $pdf->line(50,50,790,50);
  542. $pdf->line(50,550,790,550);
  543. $pdf->ezSetY(450);
  544. $pdf->ezImage(api_get_path(SYS_CODE_PATH).'img/dokeos_logo_certif.png',1,400,'','center','');
  545. $pdf->ezSetY(480);
  546. $pdf->ezText($certif_text,28,array('justification'=>'center'));
  547. //$pdf->ezSetY(750);
  548. $pdf->ezSetY(50);
  549. $pdf->ezText($date,18,array('justification'=>'center'));
  550. $pdf->ezSetY(580);
  551. $pdf->ezText($organization_name,22,array('justification'=>'left'));
  552. $pdf->ezSetY(580);
  553. $pdf->ezText($portal_name,22,array('justification'=>'right'));
  554. $pdf->ezStream();
  555. }
  556. exit;
  557. } else {
  558. $cats= Category :: load($category);
  559. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  560. $allcat= $cats[0]->get_subcategories($stud_id);
  561. $alleval= $cats[0]->get_evaluations($stud_id);
  562. $alllink= $cats[0]->get_links($stud_id);
  563. }
  564. $addparams = array ('selectcat' => $cats[0]->get_id());
  565. if (isset($_GET['search'])) {
  566. $addparams['search'] = $keyword;
  567. }
  568. if (isset ($_GET['studentoverview'])) {
  569. $addparams['studentoverview'] = '';
  570. }
  571. if (count($allcat_info)>=0 && (isset($_GET['selectcat']) && $_GET['selectcat']==0) && isset($_GET['search']) && strlen(trim($_GET['search']))>0 ) {
  572. $allcat=$allcat_info;
  573. } else {
  574. $allcat=$allcat;
  575. }
  576. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval, $alllink, $addparams);
  577. if (((empty ($allcat)) && (empty ($alleval)) && (empty ($alllink)) && (!$is_platform_admin) && ($is_course_admin) && (!isset ($_GET['selectcat']))) && api_is_course_tutor()) {
  578. 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);
  579. }
  580. //here we are in a sub category
  581. if ($category != '0') {
  582. DisplayGradebook :: display_header_gradebook($cats[0], 1, $_GET['selectcat'], $is_course_admin, $is_platform_admin, $simple_search_form);
  583. } else {
  584. //this is the root category
  585. DisplayGradebook :: display_header_gradebook($cats[0], (((count($allcat) == '0') && (!isset ($_GET['search']))) ? 0 : 1), 0, $is_course_admin, $is_platform_admin, $simple_search_form);
  586. }
  587. $gradebooktable->display();
  588. Display :: display_footer();