gradebook.php 21 KB

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