gradebook.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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. $_SESSION['gradebook_dest'] = 'index.php';
  15. $this_section = SECTION_COURSES;
  16. } else {
  17. $_SESSION['gradebook_dest'] = '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: '.$_SESSION['gradebook_dest'].'?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(EvalForm :: TYPE_MOVE,
  104. $evals[0],
  105. null,
  106. 'move_eval_form',
  107. null,
  108. api_get_self().'?moveeval='.$get_move_eval.'&selectcat='.$selectcat
  109. );
  110. if ($move_form->validate()) {
  111. header('Location: '.api_get_self().'?selectcat='.$selectcat
  112. . '&moveeval='.$get_move_eval
  113. . '&targetcat='.$move_form->exportValue('move_cat'));
  114. exit;
  115. }
  116. } else {
  117. $get_target_cat = Security::remove_XSS($_GET['targetcat']);
  118. $targetcat = Category :: load($get_target_cat);
  119. $course_to_crsind = ($evals[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  120. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  121. $evals[0]->move_to_cat($targetcat[0]);
  122. header('Location: '.api_get_self().'?evaluationmoved=&selectcat='.$selectcat);
  123. exit;
  124. }
  125. unset($targetcat);
  126. }
  127. unset($evals);
  128. }
  129. // Move a link
  130. if (isset($_GET['movelink'])) {
  131. GradebookUtils::block_students();
  132. $get_move_link = Security::remove_XSS($_GET['movelink']);
  133. $link = LinkFactory :: load($get_move_link);
  134. $move_form = new LinkForm(
  135. LinkForm :: TYPE_MOVE,
  136. null,
  137. $link[0],
  138. 'move_link_form',
  139. null,
  140. api_get_self().'?movelink='.$get_move_link.'&selectcat='.$selectcat
  141. );
  142. if ($move_form->validate()) {
  143. $targetcat = Category :: load($move_form->exportValue('move_cat'));
  144. $link[0]->move_to_cat($targetcat[0]);
  145. unset($link);
  146. header('Location: '.api_get_self().'?linkmoved=&selectcat='.$selectcat);
  147. exit;
  148. }
  149. }
  150. //parameters for categories
  151. if (isset($_GET['visiblecat'])) {
  152. GradebookUtils::block_students();
  153. if (isset($_GET['set_visible'])) {
  154. $visibility_command = 1;
  155. } else {
  156. $visibility_command = 0;
  157. }
  158. $cats = Category :: load($_GET['visiblecat']);
  159. $cats[0]->set_visible($visibility_command);
  160. $cats[0]->save();
  161. $cats[0]->apply_visibility_to_children();
  162. unset($cats);
  163. if ($visibility_command) {
  164. $confirmation_message = get_lang('ViMod');
  165. $filter_confirm_msg = false;
  166. } else {
  167. $confirmation_message = get_lang('InViMod');
  168. $filter_confirm_msg = false;
  169. }
  170. }
  171. if (isset($_GET['deletecat'])) {
  172. GradebookUtils::block_students();
  173. $cats = Category :: load($_GET['deletecat']);
  174. //delete all categories,subcategories and results
  175. if ($cats[0] != null) {
  176. if ($cats[0]->get_id() != 0) {
  177. // better don't try to delete the root...
  178. $cats[0]->delete_all();
  179. }
  180. }
  181. $confirmation_message = get_lang('CategoryDeleted');
  182. $filter_confirm_msg = false;
  183. }
  184. //parameters for evaluations
  185. if (isset($_GET['visibleeval'])) {
  186. GradebookUtils::block_students();
  187. if (isset($_GET['set_visible'])) {
  188. $visibility_command = 1;
  189. } else {
  190. $visibility_command = 0;
  191. }
  192. $eval = Evaluation :: load($_GET['visibleeval']);
  193. $eval[0]->set_visible($visibility_command);
  194. $eval[0]->save();
  195. unset($eval);
  196. if ($visibility_command) {
  197. $confirmation_message = get_lang('ViMod');
  198. $filter_confirm_msg = false;
  199. } else {
  200. $confirmation_message = get_lang('InViMod');
  201. $filter_confirm_msg = false;
  202. }
  203. }
  204. if (isset($_GET['deleteeval'])) {
  205. GradebookUtils::block_students();
  206. $eval = Evaluation :: load($_GET['deleteeval']);
  207. if ($eval[0] != null) {
  208. $eval[0]->delete_with_results();
  209. }
  210. $confirmation_message = get_lang('GradebookEvaluationDeleted');
  211. $filter_confirm_msg = false;
  212. }
  213. //parameters for links
  214. if (isset($_GET['visiblelink'])) {
  215. GradebookUtils::block_students();
  216. if (isset ($_GET['set_visible'])) {
  217. $visibility_command = 1;
  218. } else {
  219. $visibility_command = 0;
  220. }
  221. $link = LinkFactory :: load($_GET['visiblelink']);
  222. $link[0]->set_visible($visibility_command);
  223. $link[0]->save();
  224. unset($link);
  225. if ($visibility_command) {
  226. $confirmation_message = get_lang('ViMod');
  227. $filter_confirm_msg = false;
  228. } else {
  229. $confirmation_message = get_lang('InViMod');
  230. $filter_confirm_msg = false;
  231. }
  232. }
  233. if (isset ($_GET['deletelink'])) {
  234. GradebookUtils::block_students();
  235. //fixing #5229
  236. if (!empty($_GET['deletelink'])) {
  237. $link = LinkFactory:: load($_GET['deletelink']);
  238. if ($link[0] != null) {
  239. $link[0]->delete();
  240. }
  241. unset($link);
  242. $confirmation_message = get_lang('LinkDeleted');
  243. $filter_confirm_msg = false;
  244. }
  245. }
  246. $course_to_crsind = isset ($course_to_crsind) ? $course_to_crsind : '';
  247. if ($course_to_crsind && !isset($_GET['confirm'])) {
  248. GradebookUtils::block_students();
  249. if (!isset($_GET['movecat']) && !isset($_GET['moveeval'])) {
  250. die ('Error: movecat or moveeval not defined');
  251. }
  252. $button = '<form name="confirm"
  253. method="post"
  254. action="'.api_get_self().'?confirm='
  255. .(isset($_GET['movecat']) ? '&movecat='.Security::remove_XSS($_GET['movecat'])
  256. : '&moveeval='.intval($_GET['moveeval'])).'&selectcat='.$selectcat.'&targetcat='.Security::remove_XSS($_GET['targetcat']).'">
  257. <input type="submit" value="'.' '.get_lang('Ok').' '.'">
  258. </form>';
  259. $warning_message = get_lang('MoveWarning').'<br><br>'.$button;
  260. $filter_warning_msg = false;
  261. }
  262. //actions on the sortabletable
  263. if (isset($_POST['action'])) {
  264. GradebookUtils::block_students();
  265. $number_of_selected_items = count($_POST['id']);
  266. if ($number_of_selected_items == '0') {
  267. $warning_message = get_lang('NoItemsSelected');
  268. $filter_warning_msg = false;
  269. } else {
  270. switch ($_POST['action']) {
  271. case 'deleted':
  272. $number_of_deleted_categories = 0;
  273. $number_of_deleted_evaluations = 0;
  274. $number_of_deleted_links = 0;
  275. foreach ($_POST['id'] as $indexstr) {
  276. if (api_substr($indexstr, 0, 4) == 'CATE') {
  277. $cats = Category :: load(api_substr($indexstr, 4));
  278. if ($cats[0] != null) {
  279. $cats[0]->delete_all();
  280. }
  281. $number_of_deleted_categories++;
  282. }
  283. if (api_substr($indexstr, 0, 4) == 'EVAL') {
  284. $eval = Evaluation :: load(api_substr($indexstr, 4));
  285. if ($eval[0] != null) {
  286. $eval[0]->delete_with_results();
  287. }
  288. $number_of_deleted_evaluations++;
  289. }
  290. if (api_substr($indexstr, 0, 4) == 'LINK') {
  291. $id = api_substr($indexstr, 4);
  292. if (!empty($id)) {
  293. $link = LinkFactory :: load();
  294. if ($link[0] != null) {
  295. $link[0]->delete();
  296. }
  297. $number_of_deleted_links++;
  298. }
  299. }
  300. }
  301. $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>';
  302. $filter_confirm_msg = false;
  303. break;
  304. case 'setvisible' :
  305. foreach ($_POST['id'] as $indexstr) {
  306. if (api_substr($indexstr, 0, 4) == 'CATE') {
  307. $cats = Category:: load(api_substr($indexstr, 4));
  308. $cats[0]->set_visible(1);
  309. $cats[0]->save();
  310. $cats[0]->apply_visibility_to_children();
  311. }
  312. if (api_substr($indexstr, 0, 4) == 'EVAL') {
  313. $eval = Evaluation:: load(api_substr($indexstr, 4));
  314. $eval[0]->set_visible(1);
  315. $eval[0]->save();
  316. }
  317. if (api_substr($indexstr, 0, 4) == 'LINK') {
  318. $link = LinkFactory:: load(api_substr($indexstr, 4));
  319. $link[0]->set_visible(1);
  320. $link[0]->save();
  321. }
  322. }
  323. $confirmation_message = get_lang('ItemsVisible');
  324. $filter_confirm_msg = false;
  325. break;
  326. case 'setinvisible' :
  327. foreach ($_POST['id'] as $indexstr) {
  328. if (api_substr($indexstr, 0, 4) == 'CATE') {
  329. $cats = Category:: load(api_substr($indexstr, 4));
  330. $cats[0]->set_visible(0);
  331. $cats[0]->save();
  332. $cats[0]->apply_visibility_to_children();
  333. }
  334. if (api_substr($indexstr, 0, 4) == 'EVAL') {
  335. $eval = Evaluation:: load(api_substr($indexstr, 4));
  336. $eval[0]->set_visible(0);
  337. $eval[0]->save();
  338. }
  339. if (api_substr($indexstr, 0, 4) == 'LINK') {
  340. $link = LinkFactory:: load(api_substr($indexstr, 4));
  341. $link[0]->set_visible(0);
  342. $link[0]->save();
  343. }
  344. }
  345. $confirmation_message = get_lang('ItemsInVisible');
  346. $filter_confirm_msg = false;
  347. break;
  348. }
  349. }
  350. }
  351. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  352. header('Location: '.api_get_self().'?selectcat='.$selectcat
  353. . '&search='.Security::remove_XSS($_POST['keyword']));
  354. exit;
  355. }
  356. if (isset($_GET['categorymoved'])) {
  357. Display::addFlash(Display::return_message(get_lang('CategoryMoved'), 'confirmation', false));
  358. }
  359. if (isset($_GET['evaluationmoved'])) {
  360. Display::addFlash(Display::return_message(get_lang('EvaluationMoved'), 'confirmation', false));
  361. }
  362. if (isset($_GET['linkmoved'])) {
  363. Display::addFlash(Display::return_message(get_lang('LinkMoved'), 'confirmation', false));
  364. }
  365. if (isset ($_GET['addcat'])) {
  366. Display::addFlash(Display::return_message(get_lang('CategoryAdded'), 'confirmation', false));
  367. }
  368. if (isset ($_GET['linkadded'])) {
  369. Display::addFlash(Display::return_message(get_lang('LinkAdded'), 'confirmation', false));
  370. }
  371. if (isset ($_GET['addresult'])) {
  372. Display::addFlash(Display::return_message(get_lang('ResultAdded'), 'confirmation', false));
  373. }
  374. if (isset ($_GET['editcat'])) {
  375. Display::addFlash(Display::return_message(get_lang('CategoryEdited'), 'confirmation', false));
  376. }
  377. if (isset ($_GET['editeval'])) {
  378. Display::addFlash(Display::return_message(get_lang('EvaluationEdited'), 'confirmation', false));
  379. }
  380. if (isset ($_GET['linkedited'])) {
  381. Display::addFlash(Display::return_message(get_lang('LinkEdited'), 'confirmation', false));
  382. }
  383. if (isset ($_GET['nolinkitems'])) {
  384. Display::addFlash(Display::return_message(get_lang('NoLinkItems'), 'warning', false));
  385. }
  386. if (isset ($_GET['addallcat'])) {
  387. Display::addFlash(Display::return_message(get_lang('AddAllCat'), 'normal', false));
  388. }
  389. if (isset ($confirmation_message)) {
  390. Display::addFlash(Display::return_message($confirmation_message, 'confirmation', $filter_confirm_msg));
  391. }
  392. if (isset ($warning_message)) {
  393. Display::addFlash(Display::return_message($warning_message, 'warning', $filter_warning_msg));
  394. }
  395. if (isset ($move_form)) {
  396. Display::addFlash(Display::return_message($move_form->toHtml(), 'normal', false));
  397. }
  398. // DISPLAY HEADERS AND MESSAGES -
  399. if (!isset($_GET['exportpdf']) && !isset($_GET['export_certificate'])) {
  400. if (isset ($_GET['studentoverview'])) {
  401. $interbreadcrumb[] = array(
  402. 'url' => $_SESSION['gradebook_dest'].'?selectcat='.$selectcat.'&'.api_get_cidreq(),
  403. 'name' => get_lang('ToolGradebook')
  404. );
  405. Display :: display_header(get_lang('FlatView'));
  406. } elseif (isset ($_GET['search'])) {
  407. if ($_SESSION['gradebook_dest'] == 'index.php') {
  408. $gradebook_dest = Security::remove_XSS($_SESSION['gradebook_dest']).'?'.api_get_cidreq().'&amp;';
  409. } else {
  410. $gradebook_dest = Security::remove_XSS($_SESSION['gradebook_dest']);
  411. }
  412. $interbreadcrumb[] = array('url' => $gradebook_dest, 'name' => get_lang('Gradebook'));
  413. if ((isset($_GET['selectcat']) && $_GET['selectcat'] > 0)) {
  414. if (!empty($_GET['course'])) {
  415. $interbreadcrumb[] = array('url' => $gradebook_dest.'selectcat='.$selectcat, 'name' => get_lang('Details'));
  416. } else {
  417. $interbreadcrumb[] = array('url' => $_SESSION['gradebook_dest'].'?selectcat=0', 'name' => get_lang('Details'));
  418. }
  419. }
  420. Display :: display_header('');
  421. } else {
  422. Display :: display_header('');
  423. }
  424. }
  425. // LOAD DATA & DISPLAY TABLE -
  426. $is_platform_admin = api_is_platform_admin();
  427. $is_course_admin = api_is_allowed_to_edit();
  428. //load data for category, evaluation and links
  429. if (empty($selectcat)) {
  430. $category = 0;
  431. } else {
  432. $category = $selectcat;
  433. }
  434. // search form
  435. $simple_search_form = new UserForm(
  436. UserForm :: TYPE_SIMPLE_SEARCH,
  437. null,
  438. 'simple_search_form',
  439. null,
  440. api_get_self().'?selectcat='.$selectcat
  441. );
  442. $values = $simple_search_form->exportValues();
  443. $keyword = '';
  444. if (isset($_GET['search']) && !empty($_GET['search'])) {
  445. $keyword = Security::remove_XSS($_GET['search']);
  446. }
  447. if ($simple_search_form->validate() && (empty($keyword))) {
  448. $keyword = $values['keyword'];
  449. }
  450. if (!empty($keyword)) {
  451. $cats = Category :: load($category);
  452. $allcat = array();
  453. if ((isset($_GET['selectcat']) && $_GET['selectcat'] == 0) && isset($_GET['search'])) {
  454. $allcat = $cats[0]->get_subcategories(null);
  455. $allcat_info = Category::find_category($keyword, $allcat);
  456. $alleval = array();
  457. $alllink = array();
  458. } else {
  459. $alleval = Evaluation::find_evaluations($keyword, $cats[0]->get_id());
  460. $alllink = LinkFactory::find_links($keyword, $cats[0]->get_id());
  461. }
  462. } elseif (isset ($_GET['studentoverview'])) {
  463. //@todo this code seems to be deprecated because the gradebook tab is off
  464. $cats = Category :: load($category);
  465. $stud_id = (api_is_allowed_to_edit() ? null : api_get_user_id());
  466. $allcat = array();
  467. $alleval = $cats[0]->get_evaluations($stud_id, true);
  468. $alllink = $cats[0]->get_links($stud_id, true);
  469. if (isset ($_GET['exportpdf'])) {
  470. $datagen = new GradebookDataGenerator($allcat, $alleval, $alllink);
  471. $header_names = array(
  472. get_lang('Name'),
  473. get_lang('Description'),
  474. get_lang('Weight'),
  475. get_lang('Date'),
  476. get_lang('Results'),
  477. );
  478. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME, 0, null, true);
  479. $newarray = array();
  480. foreach ($data_array as $data) {
  481. $newarray[] = array_slice($data, 1);
  482. }
  483. $pdf = new Cezpdf();
  484. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  485. $pdf->ezSetMargins(30, 30, 50, 30);
  486. $pdf->ezSetY(810);
  487. $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'));
  488. $pdf->line(50, 790, 550, 790);
  489. $pdf->line(50, 40, 550, 40);
  490. $pdf->ezSetY(750);
  491. $pdf->ezTable(
  492. $newarray,
  493. $header_names,
  494. '',
  495. array(
  496. 'showHeadings' => 1,
  497. 'shaded' => 1,
  498. 'showLines' => 1,
  499. 'rowGap' => 3,
  500. 'width' => 500,
  501. )
  502. );
  503. $pdf->ezStream();
  504. exit;
  505. }
  506. } elseif (!empty($_GET['export_certificate'])) {
  507. //@todo this code seems not to be used
  508. $user_id = strval(intval($_GET['user']));
  509. if (!api_is_allowed_to_edit(true, true)) {
  510. $user_id = api_get_user_id();
  511. }
  512. $category = Category :: load($_GET['cat_id']);
  513. if ($category[0]->is_certificate_available($user_id)) {
  514. $user = api_get_user_info($user_id);
  515. $scoredisplay = ScoreDisplay :: instance();
  516. $scorecourse = $category[0]->calc_score($user_id);
  517. $scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse, SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
  518. $cattotal = Category :: load(0);
  519. $scoretotal = $cattotal[0]->calc_score($user_id);
  520. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal, SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  521. //prepare all necessary variables:
  522. $organization_name = api_get_setting('Institution');
  523. $portal_name = api_get_setting('siteName');
  524. $stud_fn = $user['firstname'];
  525. $stud_ln = $user['lastname'];
  526. $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'), $organization_name, $stud_fn.' '.$stud_ln, $category[0]->get_name(), $scorecourse_display);
  527. $certif_text = str_replace("\\n", "\n", $certif_text);
  528. $date = api_convert_and_format_date(null, DATE_FORMAT_SHORT);
  529. $pdf = new Cezpdf('a4', 'landscape');
  530. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  531. $pdf->ezSetMargins(30, 30, 50, 50);
  532. //line Y coordinates in landscape mode are upside down (500 is on top, 10 is on the bottom)
  533. $pdf->line(50, 50, 790, 50);
  534. $pdf->line(50, 550, 790, 550);
  535. $pdf->ezSetY(450);
  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_edit() ? 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 (isset($allcat_info) && 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(
  568. $cats[0],
  569. $allcat,
  570. $alleval,
  571. $alllink,
  572. $addparams
  573. );
  574. if (((empty($allcat)) && (empty ($alleval)) && (empty ($alllink)) && (!$is_platform_admin) && ($is_course_admin) && (!isset($_GET['selectcat']))) &&
  575. api_is_course_tutor()
  576. ) {
  577. echo Display::return_message(
  578. get_lang('GradebookWelcomeMessage').
  579. '<br /><br />
  580. <form name="createcat" method="post" action="' . api_get_self().'?createallcategories=1">
  581. <input type="submit" value="' . get_lang('CreateAllCat').'"></form>',
  582. 'normal',
  583. false
  584. );
  585. }
  586. // Here we are in a sub category
  587. if ($category != '0') {
  588. DisplayGradebook:: header(
  589. $cats[0],
  590. 1,
  591. $_GET['selectcat'],
  592. $is_course_admin,
  593. $is_platform_admin,
  594. $simple_search_form
  595. );
  596. } else {
  597. // This is the root category
  598. DisplayGradebook:: header(
  599. $cats[0],
  600. count($allcat) == '0' && !isset($_GET['search']) ? 0 : 1,
  601. 0,
  602. $is_course_admin,
  603. $is_platform_admin,
  604. $simple_search_form
  605. );
  606. }
  607. $gradebooktable->display();
  608. Display :: display_footer();