gradebook.php 24 KB

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