gradebook.php 24 KB

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