gradebook.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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 '../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. $htmlHeadXtra[] = '<script type="text/javascript">
  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 type="text/javascript">
  32. function confirmation ()
  33. {
  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. $selectcat=isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : '';
  67. if (isset ($_GET['movecat'])) {
  68. $move_cat = Security::remove_XSS($_GET['movecat']);
  69. GradebookUtils::block_students();
  70. $cats= Category :: load($move_cat);
  71. if (!isset ($_GET['targetcat'])) {
  72. $move_form= new CatForm(CatForm :: TYPE_MOVE,
  73. $cats[0],
  74. 'move_cat_form',
  75. null,
  76. api_get_self() . '?movecat=' . $move_cat
  77. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  78. if ($move_form->validate()) {
  79. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['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=' . Security::remove_XSS($_GET['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
  109. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  110. if ($move_form->validate()) {
  111. header('Location: ' .api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['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=' . Security::remove_XSS($_GET['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='.Security::remove_XSS($_GET['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=' . Security::remove_XSS($_GET['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=' . Security::remove_XSS($_GET['moveeval']) )
  257. .'&selectcat=' . Security::remove_XSS($_GET['selectcat'])
  258. .'&targetcat=' . Security::remove_XSS($_GET['targetcat']).'">
  259. <input type="submit" value="'.' '.get_lang('Ok').' '.'">
  260. </form>';
  261. $warning_message = get_lang('MoveWarning').'<br><br>'.$button;
  262. $filter_warning_msg = false;
  263. }
  264. //actions on the sortabletable
  265. if (isset ($_POST['action'])) {
  266. GradebookUtils::block_students();
  267. $number_of_selected_items= count($_POST['id']);
  268. if ($number_of_selected_items == '0') {
  269. $warning_message = get_lang('NoItemsSelected');
  270. $filter_warning_msg = false;
  271. }
  272. else {
  273. switch ($_POST['action']) {
  274. case 'deleted' :
  275. $number_of_deleted_categories= 0;
  276. $number_of_deleted_evaluations= 0;
  277. $number_of_deleted_links= 0;
  278. foreach ($_POST['id'] as $indexstr) {
  279. if (api_substr($indexstr, 0, 4) == 'CATE') {
  280. $cats= Category :: load(api_substr($indexstr, 4));
  281. if ($cats[0] != null) {
  282. $cats[0]->delete_all();
  283. }
  284. $number_of_deleted_categories++;
  285. }
  286. if (api_substr($indexstr, 0, 4) == 'EVAL') {
  287. $eval= Evaluation :: load(api_substr($indexstr, 4));
  288. if ($eval[0] != null) {
  289. $eval[0]->delete_with_results();
  290. }
  291. $number_of_deleted_evaluations++;
  292. }
  293. if (api_substr($indexstr, 0, 4) == 'LINK') {
  294. $id = api_substr($indexstr, 4);
  295. if (!empty($id)) {
  296. $link= LinkFactory :: load();
  297. if ($link[0] != null) {
  298. $link[0]->delete();
  299. }
  300. $number_of_deleted_links++;
  301. }
  302. }
  303. }
  304. $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>';
  305. $filter_confirm_msg = false;
  306. break;
  307. case 'setvisible' :
  308. foreach ($_POST['id'] as $indexstr) {
  309. if (api_substr($indexstr, 0, 4) == 'CATE') {
  310. $cats = Category:: load(api_substr($indexstr, 4));
  311. $cats[0]->set_visible(1);
  312. $cats[0]->save();
  313. $cats[0]->apply_visibility_to_children();
  314. }
  315. if (api_substr($indexstr, 0, 4) == 'EVAL') {
  316. $eval = Evaluation:: load(api_substr($indexstr, 4));
  317. $eval[0]->set_visible(1);
  318. $eval[0]->save();
  319. }
  320. if (api_substr($indexstr, 0, 4) == 'LINK') {
  321. $link = LinkFactory:: load(api_substr($indexstr, 4));
  322. $link[0]->set_visible(1);
  323. $link[0]->save();
  324. }
  325. }
  326. $confirmation_message = get_lang('ItemsVisible');
  327. $filter_confirm_msg = false;
  328. break;
  329. case 'setinvisible' :
  330. foreach ($_POST['id'] as $indexstr) {
  331. if (api_substr($indexstr, 0, 4) == 'CATE') {
  332. $cats = Category:: load(api_substr($indexstr, 4));
  333. $cats[0]->set_visible(0);
  334. $cats[0]->save();
  335. $cats[0]->apply_visibility_to_children();
  336. }
  337. if (api_substr($indexstr, 0, 4) == 'EVAL') {
  338. $eval = Evaluation:: load(api_substr($indexstr, 4));
  339. $eval[0]->set_visible(0);
  340. $eval[0]->save();
  341. }
  342. if (api_substr($indexstr, 0, 4) == 'LINK') {
  343. $link = LinkFactory:: load(api_substr($indexstr, 4));
  344. $link[0]->set_visible(0);
  345. $link[0]->save();
  346. }
  347. }
  348. $confirmation_message = get_lang('ItemsInVisible');
  349. $filter_confirm_msg = false;
  350. break;
  351. }
  352. }
  353. }
  354. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  355. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  356. . '&search='.Security::remove_XSS($_POST['keyword']));
  357. exit;
  358. }
  359. // DISPLAY HEADERS AND MESSAGES -
  360. if (!isset($_GET['exportpdf']) && !isset($_GET['export_certificate'])) {
  361. if (isset ($_GET['studentoverview'])) {
  362. $interbreadcrumb[]= array (
  363. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat'].'&'.api_get_cidreq()),
  364. 'name' => get_lang('ToolGradebook')
  365. );
  366. Display :: display_header(get_lang('FlatView'));
  367. } elseif (isset ($_GET['search'])) {
  368. if ($_SESSION['gradebook_dest'] == 'index.php') {
  369. $gradebook_dest = Security::remove_XSS($_SESSION['gradebook_dest']).'?cidReq='.Security::remove_XSS($_GET['course']).'&amp;';
  370. } else {
  371. $gradebook_dest = Security::remove_XSS($_SESSION['gradebook_dest']);
  372. }
  373. $interbreadcrumb[]= array ('url' => $gradebook_dest,'name' => get_lang('Gradebook'));
  374. if ((isset($_GET['selectcat']) && $_GET['selectcat']>0)) {
  375. if (!empty($_GET['course'])) {
  376. $interbreadcrumb[]= array ('url' => $gradebook_dest.'selectcat='.Security::remove_XSS($_GET['selectcat']),'name' => get_lang('Details'));
  377. } else {
  378. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=0','name' => get_lang('Details'));
  379. }
  380. }
  381. Display :: display_header('');
  382. } else {
  383. Display :: display_header('');
  384. }
  385. }
  386. if (isset($_GET['categorymoved'])) {
  387. Display :: display_confirmation_message(get_lang('CategoryMoved'),false);
  388. }
  389. if (isset($_GET['evaluationmoved'])) {
  390. Display :: display_confirmation_message(get_lang('EvaluationMoved'),false);
  391. }
  392. if (isset($_GET['linkmoved'])) {
  393. Display :: display_confirmation_message(get_lang('LinkMoved'),false);
  394. }
  395. if (isset ($_GET['addcat'])) {
  396. Display :: display_confirmation_message(get_lang('CategoryAdded'),false);
  397. }
  398. if (isset ($_GET['linkadded'])) {
  399. Display :: display_confirmation_message(get_lang('LinkAdded'),false);
  400. }
  401. if (isset ($_GET['addresult'])) {
  402. Display :: display_confirmation_message(get_lang('ResultAdded'),false);
  403. }
  404. if (isset ($_GET['editcat'])) {
  405. Display :: display_confirmation_message(get_lang('CategoryEdited'),false);
  406. }
  407. if (isset ($_GET['editeval'])) {
  408. Display :: display_confirmation_message(get_lang('EvaluationEdited'),false);
  409. }
  410. if (isset ($_GET['linkedited'])) {
  411. Display :: display_confirmation_message(get_lang('LinkEdited'),false);
  412. }
  413. if (isset ($_GET['nolinkitems'])) {
  414. Display :: display_warning_message(get_lang('NoLinkItems'),false);
  415. }
  416. if (isset ($_GET['addallcat'])) {
  417. Display :: display_normal_message(get_lang('AddAllCat'),false);
  418. }
  419. if (isset ($confirmation_message)) {
  420. Display :: display_confirmation_message($confirmation_message,$filter_confirm_msg);
  421. }
  422. if (isset ($warning_message)) {
  423. Display :: display_warning_message($warning_message,$filter_warning_msg);
  424. }
  425. if (isset ($move_form)) {
  426. Display :: display_normal_message($move_form->toHtml(),false);
  427. }
  428. // LOAD DATA & DISPLAY TABLE -
  429. $is_platform_admin= api_is_platform_admin();
  430. $is_course_admin= api_is_allowed_to_edit();
  431. //load data for category, evaluation and links
  432. if (!isset ($_GET['selectcat']) || empty ($_GET['selectcat'])) {
  433. $category= 0;
  434. } else {
  435. $category= Security::remove_XSS($_GET['selectcat']);
  436. }
  437. // search form
  438. $simple_search_form = new UserForm(
  439. UserForm :: TYPE_SIMPLE_SEARCH,
  440. null,
  441. 'simple_search_form',
  442. null,
  443. api_get_self().'?selectcat='.$selectcat
  444. );
  445. $values= $simple_search_form->exportValues();
  446. $keyword = '';
  447. if (isset($_GET['search']) && !empty($_GET['search'])) {
  448. $keyword = Security::remove_XSS($_GET['search']);
  449. }
  450. if ($simple_search_form->validate() && (empty($keyword))) {
  451. $keyword = $values['keyword'];
  452. }
  453. if (!empty($keyword)) {
  454. $cats= Category :: load($category);
  455. $allcat= array ();
  456. if ((isset($_GET['selectcat']) && $_GET['selectcat']==0) && isset($_GET['search'])) {
  457. $allcat= $cats[0]->get_subcategories(null);
  458. $allcat_info = Category::find_category($keyword,$allcat);
  459. $alleval=array();
  460. $alllink=array();
  461. } else {
  462. $alleval = Evaluation::find_evaluations($keyword, $cats[0]->get_id());
  463. $alllink = LinkFactory::find_links($keyword, $cats[0]->get_id());
  464. }
  465. } elseif (isset ($_GET['studentoverview'])) {
  466. //@todo this code seems to be deprecated because the gradebook tab is off
  467. $cats= Category :: load($category);
  468. $stud_id= (api_is_allowed_to_edit() ? null : api_get_user_id());
  469. $allcat= array ();
  470. $alleval= $cats[0]->get_evaluations($stud_id, true);
  471. $alllink= $cats[0]->get_links($stud_id, true);
  472. if (isset ($_GET['exportpdf'])) {
  473. $datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
  474. $header_names = array(
  475. get_lang('Name'),
  476. get_lang('Description'),
  477. get_lang('Weight'),
  478. get_lang('Date'),
  479. get_lang('Results'),
  480. );
  481. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  482. $newarray = array();
  483. foreach ($data_array as $data) {
  484. $newarray[] = array_slice($data, 1);
  485. }
  486. $pdf= new Cezpdf();
  487. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  488. $pdf->ezSetMargins(30, 30, 50, 30);
  489. $pdf->ezSetY(810);
  490. $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'));
  491. $pdf->line(50,790,550,790);
  492. $pdf->line(50,40,550,40);
  493. $pdf->ezSetY(750);
  494. $pdf->ezTable(
  495. $newarray,
  496. $header_names,
  497. '',
  498. array(
  499. 'showHeadings' => 1,
  500. 'shaded' => 1,
  501. 'showLines' => 1,
  502. 'rowGap' => 3,
  503. 'width' => 500,
  504. )
  505. );
  506. $pdf->ezStream();
  507. exit;
  508. }
  509. } elseif (!empty($_GET['export_certificate'])){
  510. //@todo this code seems not to be used
  511. $user_id = strval(intval($_GET['user']));
  512. if (!api_is_allowed_to_edit(true,true)) {
  513. $user_id = api_get_user_id();
  514. }
  515. $category = Category :: load ($_GET['cat_id']);
  516. if ($category[0]->is_certificate_available($user_id)) {
  517. $user = api_get_user_info($user_id);
  518. $scoredisplay = ScoreDisplay :: instance();
  519. $scorecourse = $category[0]->calc_score($user_id);
  520. $scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
  521. $cattotal = Category :: load(0);
  522. $scoretotal= $cattotal[0]->calc_score($user_id);
  523. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal,SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  524. //prepare all necessary variables:
  525. $organization_name = api_get_setting('Institution');
  526. $portal_name = api_get_setting('siteName');
  527. $stud_fn = $user['firstname'];
  528. $stud_ln = $user['lastname'];
  529. $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'),$organization_name,$stud_fn.' '.$stud_ln,$category[0]->get_name(),$scorecourse_display);
  530. $certif_text = str_replace("\\n","\n",$certif_text);
  531. $date = api_convert_and_format_date(null, DATE_FORMAT_SHORT);
  532. $pdf= new Cezpdf('a4','landscape');
  533. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  534. $pdf->ezSetMargins(30, 30, 50, 50);
  535. //line Y coordinates in landscape mode are upside down (500 is on top, 10 is on the bottom)
  536. $pdf->line(50,50,790,50);
  537. $pdf->line(50,550,790,550);
  538. $pdf->ezSetY(450);
  539. $pdf->ezSetY(480);
  540. $pdf->ezText($certif_text,28,array('justification'=>'center'));
  541. //$pdf->ezSetY(750);
  542. $pdf->ezSetY(50);
  543. $pdf->ezText($date,18,array('justification'=>'center'));
  544. $pdf->ezSetY(580);
  545. $pdf->ezText($organization_name,22,array('justification'=>'left'));
  546. $pdf->ezSetY(580);
  547. $pdf->ezText($portal_name,22,array('justification'=>'right'));
  548. $pdf->ezStream();
  549. }
  550. exit;
  551. } else {
  552. $cats= Category :: load($category);
  553. $stud_id= (api_is_allowed_to_edit() ? null : api_get_user_id());
  554. $allcat= $cats[0]->get_subcategories($stud_id);
  555. $alleval= $cats[0]->get_evaluations($stud_id);
  556. $alllink= $cats[0]->get_links($stud_id);
  557. }
  558. $addparams = array ('selectcat' => $cats[0]->get_id());
  559. if (isset($_GET['search'])) {
  560. $addparams['search'] = $keyword;
  561. }
  562. if (isset ($_GET['studentoverview'])) {
  563. $addparams['studentoverview'] = '';
  564. }
  565. if (isset($allcat_info) && count($allcat_info)>=0 && (isset($_GET['selectcat']) && $_GET['selectcat']==0) && isset($_GET['search']) && strlen(trim($_GET['search']))>0 ) {
  566. $allcat=$allcat_info;
  567. } else {
  568. $allcat=$allcat;
  569. }
  570. $gradebooktable = new GradebookTable(
  571. $cats[0],
  572. $allcat,
  573. $alleval,
  574. $alllink,
  575. $addparams
  576. );
  577. if (((empty ($allcat)) && (empty ($alleval)) && (empty ($alllink)) && (!$is_platform_admin) && ($is_course_admin) && (!isset ($_GET['selectcat']))) && api_is_course_tutor()) {
  578. 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);
  579. }
  580. // Here we are in a sub category
  581. if ($category != '0') {
  582. DisplayGradebook:: header(
  583. $cats[0],
  584. 1,
  585. $_GET['selectcat'],
  586. $is_course_admin,
  587. $is_platform_admin,
  588. $simple_search_form
  589. );
  590. } else {
  591. // This is the root category
  592. DisplayGradebook:: header(
  593. $cats[0],
  594. (((count($allcat) == '0') && (!isset ($_GET['search']))) ? 0 : 1),
  595. 0,
  596. $is_course_admin,
  597. $is_platform_admin,
  598. $simple_search_form
  599. );
  600. }
  601. $gradebooktable->display();
  602. Display :: display_footer();