gradebook.php 22 KB

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