gradebook.php 23 KB

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