gradebook.php 21 KB

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