gradebook.php 22 KB

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