gradebook.php 21 KB

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