gradebook.php 23 KB

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