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