gradebook.php 22 KB

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