gradebook.php 23 KB

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