index.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. <?php // $Id: $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos Latinoamerica SAC
  6. Copyright (c) 2006-2008 Dokeos SPRL
  7. Copyright (c) 2006 Ghent University (UGent)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. $language_file= 'gradebook';
  21. // $cidReset : This is the main difference with gradebook.php, here we say,
  22. // basically, that we are inside a course, and many things depend from that
  23. $cidReset= false;
  24. $_in_course = true;
  25. require_once ('../inc/global.inc.php');
  26. $course_code = api_get_course_id();
  27. //make sure the destination for scripts is index.php instead of gradebook.php
  28. $_SESSION['gradebook_dest'] = 'index.php';
  29. $this_section = SECTION_MYGRADEBOOK;
  30. require_once ('lib/be.inc.php');
  31. require_once ('lib/scoredisplay.class.php');
  32. require_once ('lib/gradebook_functions.inc.php');
  33. require_once ('lib/fe/catform.class.php');
  34. require_once ('lib/fe/evalform.class.php');
  35. require_once ('lib/fe/linkform.class.php');
  36. require_once ('lib/gradebook_data_generator.class.php');
  37. require_once ('lib/fe/gradebooktable.class.php');
  38. require_once ('lib/fe/displaygradebook.php');
  39. require_once ('lib/fe/userform.class.php');
  40. require_once (api_get_path(LIBRARY_PATH).'ezpdf/class.ezpdf.php');
  41. api_block_anonymous_users();
  42. $htmlHeadXtra[]= '<script type="text/javascript">
  43. function confirmation ()
  44. {
  45. if (confirm("' . get_lang('DeleteAll') . '?"))
  46. {return true;}
  47. else
  48. {return false;}
  49. }
  50. </script>';
  51. $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
  52. $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  53. $filter_confirm_msg = true;
  54. $filter_warning_msg = true;
  55. // --------------------------------------------------------------------------------
  56. // - ACTIONS -
  57. // --------------------------------------------------------------------------------
  58. //this is called when there is no data for the course admin
  59. if (isset ($_GET['createallcategories'])) {
  60. block_students();
  61. $coursecat= Category :: get_not_created_course_categories(api_get_user_id());
  62. if (!count($coursecat) == 0) {
  63. foreach ($coursecat as $row) {
  64. $cat= new Category();
  65. $cat->set_name($row[1]);
  66. $cat->set_course_code($row[0]);
  67. $cat->set_description(null);
  68. $cat->set_user_id(api_get_user_id());
  69. $cat->set_parent_id(0);
  70. $cat->set_weight(0);
  71. $cat->set_visible(0);
  72. $cat->add();
  73. unset ($cat);
  74. }
  75. }
  76. header('Location: '.$_SESSION['gradebook_dest'].'?addallcat=&selectcat=0');
  77. exit;
  78. }
  79. //show logs evaluations
  80. if (isset ($_GET['visiblelog'])) {
  81. header('Location: ' . api_get_self().'/gradebook_showlog_eval.php');
  82. exit;
  83. }
  84. //move a category
  85. if (isset ($_GET['movecat'])) {
  86. block_students();
  87. $cats= Category :: load($_GET['movecat']);
  88. if (!isset ($_GET['targetcat'])) {
  89. $move_form= new CatForm(CatForm :: TYPE_MOVE,
  90. $cats[0],
  91. 'move_cat_form',
  92. null,
  93. api_get_self() . '?movecat=' . Security::remove_XSS($_GET['movecat'])
  94. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  95. if ($move_form->validate()) {
  96. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  97. . '&movecat=' . Security::remove_XSS($_GET['movecat'])
  98. . '&targetcat=' . $move_form->exportValue('move_cat'));
  99. exit;
  100. }
  101. } else {
  102. $targetcat= Category :: load($_GET['targetcat']);
  103. $course_to_crsind = ($cats[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  104. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  105. $cats[0]->move_to_cat($targetcat[0]);
  106. header('Location: ' . api_get_self() . '?categorymoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  107. exit;
  108. }
  109. unset ($targetcat);
  110. }
  111. unset ($cats);
  112. }
  113. //move an evaluation
  114. if (isset ($_GET['moveeval'])) {
  115. block_students();
  116. $evals= Evaluation :: load($_GET['moveeval']);
  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=' . Security::remove_XSS($_GET['moveeval'])
  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=' . Security::remove_XSS($_GET['moveeval'])
  128. . '&targetcat=' . $move_form->exportValue('move_cat'));
  129. exit;
  130. }
  131. } else {
  132. $targetcat= Category :: load($_GET['targetcat']);
  133. $course_to_crsind = ($evals[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  134. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  135. $evals[0]->move_to_cat($targetcat[0]);
  136. header('Location: ' . api_get_self() . '?evaluationmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  137. exit;
  138. }
  139. unset ($targetcat);
  140. }
  141. unset ($evals);
  142. }
  143. //move a link
  144. if (isset ($_GET['movelink'])) {
  145. block_students();
  146. $link= LinkFactory :: load($_GET['movelink']);
  147. $move_form= new LinkForm(LinkForm :: TYPE_MOVE, null, $link[0], 'move_link_form', null, api_get_self() . '?movelink=' . $_GET['movelink'] . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  148. if ($move_form->validate()) {
  149. $targetcat= Category :: load($move_form->exportValue('move_cat'));
  150. $link[0]->move_to_cat($targetcat[0]);
  151. unset ($link);
  152. header('Location: ' . api_get_self(). '?linkmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  153. exit;
  154. }
  155. }
  156. //parameters for categories
  157. if (isset ($_GET['visiblecat'])) {
  158. block_students();
  159. if (isset ($_GET['set_visible'])) {
  160. $visibility_command= 1;
  161. } else {
  162. $visibility_command= 0;
  163. }
  164. $cats= Category :: load($_GET['visiblecat']);
  165. $cats[0]->set_visible($visibility_command);
  166. $cats[0]->save();
  167. $cats[0]->apply_visibility_to_children();
  168. unset ($cats);
  169. if ($visibility_command) {
  170. $confirmation_message = get_lang('ViMod');
  171. $filter_confirm_msg = false;
  172. } else {
  173. $confirmation_message = get_lang('InViMod');
  174. $filter_confirm_msg = false;
  175. }
  176. }
  177. if (isset ($_GET['deletecat'])) {
  178. block_students();
  179. $cats= Category :: load($_GET['deletecat']);
  180. //delete all categories,subcategories and results
  181. if ($cats[0] != null) {
  182. if ($cats[0]->get_id() != 0) {
  183. // better don't try to delete the root...
  184. $cats[0]->delete_all();
  185. }
  186. }
  187. $confirmation_message = get_lang('CategoryDeleted');
  188. $filter_confirm_msg = false;
  189. }
  190. //parameters for evaluations
  191. if (isset ($_GET['visibleeval'])) {
  192. block_students();
  193. if (isset ($_GET['set_visible'])) {
  194. $visibility_command= 1;
  195. } else {
  196. $visibility_command= 0;
  197. }
  198. $eval= Evaluation :: load($_GET['visibleeval']);
  199. $eval[0]->set_visible($visibility_command);
  200. $eval[0]->save();
  201. unset ($eval);
  202. if ($visibility_command) {
  203. $confirmation_message = get_lang('ViMod');
  204. $filter_confirm_msg = false;
  205. } else {
  206. $confirmation_message = get_lang('InViMod');
  207. $filter_confirm_msg = false;
  208. }
  209. }
  210. if (isset ($_GET['deleteeval'])) {
  211. block_students();
  212. $eval= Evaluation :: load($_GET['deleteeval']);
  213. if ($eval[0] != null) {
  214. $eval[0]->delete_with_results();
  215. }
  216. $confirmation_message = get_lang('GradebookEvaluationDeleted');
  217. $filter_confirm_msg = false;
  218. }
  219. //parameters for links
  220. if (isset ($_GET['visiblelink'])) {
  221. block_students();
  222. if (isset ($_GET['set_visible'])) {
  223. $visibility_command= 1;
  224. } else {
  225. $visibility_command= 0;
  226. }
  227. $link= LinkFactory :: load($_GET['visiblelink']);
  228. $link[0]->set_visible($visibility_command);
  229. $link[0]->save();
  230. unset ($link);
  231. if ($visibility_command) {
  232. $confirmation_message = get_lang('ViMod');
  233. $filter_confirm_msg = false;
  234. } else {
  235. $confirmation_message = get_lang('InViMod');
  236. $filter_confirm_msg = false;
  237. }
  238. }
  239. if (isset ($_GET['deletelink'])) {
  240. block_students();
  241. $link= LinkFactory :: load($_GET['deletelink']);
  242. if ($link[0] != null) {
  243. $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='.$_GET['deletelink'].');';
  244. api_sql_query($sql);
  245. $link[0]->delete();
  246. }
  247. unset ($link);
  248. $confirmation_message = get_lang('LinkDeleted');
  249. $filter_confirm_msg = false;
  250. }
  251. if ($course_to_crsind && !isset($_GET['confirm'])) {
  252. block_students();
  253. if (!isset($_GET['movecat']) && !isset($_GET['moveeval'])) {
  254. die ('Error: movecat or moveeval not defined');
  255. }
  256. $button = '<form name="confirm"
  257. method="post"
  258. action="'.api_get_self() .'?confirm='
  259. .(isset($_GET['movecat']) ? '&movecat=' . Security::remove_XSS($_GET['movecat'])
  260. : '&moveeval=' . Security::remove_XSS($_GET['moveeval']) )
  261. .'&selectcat=' . Security::remove_XSS($_GET['selectcat'])
  262. .'&targetcat=' . Security::remove_XSS($_GET['targetcat']).'">
  263. <input type="submit" value="'.get_lang('Ok').'">
  264. </form>';
  265. $warning_message = get_lang('MoveWarning').'<br><br>'.$button;
  266. $filter_warning_msg = false;
  267. }
  268. //actions on the sortabletable
  269. if (isset ($_POST['action'])) {
  270. block_students();
  271. $number_of_selected_items= count($_POST['id']);
  272. if ($number_of_selected_items == '0') {
  273. $warning_message = get_lang('NoItemsSelected');
  274. $filter_warning_msg = false;
  275. } else {
  276. switch ($_POST['action']) {
  277. case 'deleted' :
  278. $number_of_deleted_categories= 0;
  279. $number_of_deleted_evaluations= 0;
  280. $number_of_deleted_links= 0;
  281. foreach ($_POST['id'] as $indexstr) {
  282. if (substr($indexstr, 0, 4) == 'CATE') {
  283. $cats= Category :: load(substr($indexstr, 4));
  284. if ($cats[0] != null) {
  285. $cats[0]->delete_all();
  286. }
  287. $number_of_deleted_categories++;
  288. }
  289. if (substr($indexstr, 0, 4) == 'EVAL') {
  290. $eval= Evaluation :: load(substr($indexstr, 4));
  291. if ($eval[0] != null) {
  292. $eval[0]->delete_with_results();
  293. }
  294. $number_of_deleted_evaluations++;
  295. }
  296. if (substr($indexstr, 0, 4) == 'LINK') {
  297. $link= LinkFactory :: load(substr($indexstr, 4));
  298. if ($link[0] != null) {
  299. $link[0]->delete();
  300. }
  301. $number_of_deleted_links++;
  302. }
  303. }
  304. $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>';
  305. $filter_confirm_msg = false;
  306. break;
  307. case 'setvisible' :
  308. foreach ($_POST['id'] as $indexstr) {
  309. if (substr($indexstr, 0, 4) == 'CATE') {
  310. $cats= Category :: load(substr($indexstr, 4));
  311. $cats[0]->set_visible(1);
  312. $cats[0]->save();
  313. $cats[0]->apply_visibility_to_children();
  314. }
  315. if (substr($indexstr, 0, 4) == 'EVAL') {
  316. $eval= Evaluation :: load(substr($indexstr, 4));
  317. $eval[0]->set_visible(1);
  318. $eval[0]->save();
  319. }
  320. if (substr($indexstr, 0, 4) == 'LINK') {
  321. $link= LinkFactory :: load(substr($indexstr, 4));
  322. $link[0]->set_visible(1);
  323. $link[0]->save();
  324. }
  325. }
  326. $confirmation_message = get_lang('ItemsVisible');
  327. $filter_confirm_msg = false;
  328. break;
  329. case 'setinvisible' :
  330. foreach ($_POST['id'] as $indexstr) {
  331. if (substr($indexstr, 0, 4) == 'CATE') {
  332. $cats= Category :: load(substr($indexstr, 4));
  333. $cats[0]->set_visible(0);
  334. $cats[0]->save();
  335. $cats[0]->apply_visibility_to_children();
  336. }
  337. if (substr($indexstr, 0, 4) == 'EVAL') {
  338. $eval= Evaluation :: load(substr($indexstr, 4));
  339. $eval[0]->set_visible(0);
  340. $eval[0]->save();
  341. }
  342. if (substr($indexstr, 0, 4) == 'LINK') {
  343. $link= LinkFactory :: load(substr($indexstr, 4));
  344. $link[0]->set_visible(0);
  345. $link[0]->save();
  346. }
  347. }
  348. $confirmation_message = get_lang('ItemsInVisible');
  349. $filter_confirm_msg = false;
  350. break;
  351. }
  352. }
  353. }
  354. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  355. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  356. . '&search='.Security::remove_XSS($_POST['keyword']));
  357. exit;
  358. }
  359. // --------------------------------------------------------------------------------
  360. // - DISPLAY HEADERS AND MESSAGES -
  361. // --------------------------------------------------------------------------------
  362. if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) {
  363. if (isset ($_GET['studentoverview'])) {
  364. $interbreadcrumb[]= array (
  365. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  366. 'name' => get_lang('Gradebook')
  367. );
  368. Display :: display_header(get_lang('FlatView'));
  369. } elseif (isset ($_GET['search'])) {
  370. $interbreadcrumb[]= array (
  371. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  372. 'name' => get_lang('Gradebook')
  373. );
  374. Display :: display_header(get_lang('SearchResults'));
  375. } elseif(isset ($_GET['selectcat'])) {
  376. $interbreadcrumb[]= array (
  377. 'url' => $_SESSION['gradebook_dest'],
  378. 'name' => get_lang('Gradebook')
  379. );
  380. $interbreadcrumb[]= array (
  381. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  382. 'name' => get_lang('Details')
  383. );
  384. Display :: display_header();
  385. } else {
  386. Display :: display_header(get_lang('Gradebook'));
  387. }
  388. }
  389. if (isset ($_GET['categorymoved'])) {
  390. Display :: display_confirmation_message(get_lang('CategoryMoved'),false);
  391. }
  392. if (isset ($_GET['evaluationmoved'])) {
  393. Display :: display_confirmation_message(get_lang('EvaluationMoved'),false);
  394. }
  395. if (isset ($_GET['linkmoved'])) {
  396. Display :: display_confirmation_message(get_lang('LinkMoved'),false);
  397. }
  398. if (isset ($_GET['addcat'])) {
  399. Display :: display_confirmation_message(get_lang('CategoryAdded'),false);
  400. }
  401. if (isset ($_GET['linkadded'])) {
  402. Display :: display_confirmation_message(get_lang('LinkAdded'),false);
  403. }
  404. if (isset ($_GET['addresult'])) {
  405. Display :: display_confirmation_message(get_lang('ResultAdded'),false);
  406. }
  407. if (isset ($_GET['editcat'])) {
  408. Display :: display_confirmation_message(get_lang('CategoryEdited'),false);
  409. }
  410. if (isset ($_GET['editeval'])) {
  411. Display :: display_confirmation_message(get_lang('EvaluationEdited'),false);
  412. }
  413. if (isset ($_GET['linkedited'])) {
  414. Display :: display_confirmation_message(get_lang('LinkEdited'),false);
  415. }
  416. if (isset ($_GET['nolinkitems'])){
  417. Display :: display_warning_message(get_lang('NoLinkItems'),false);
  418. }
  419. if (isset ($_GET['addallcat'])){
  420. Display :: display_normal_message(get_lang('AddAllCat'),false);
  421. }
  422. if (isset ($confirmation_message)){
  423. Display :: display_confirmation_message($confirmation_message,$filter_confirm_msg);
  424. }
  425. if (isset ($warning_message)){
  426. Display :: display_warning_message($warning_message,$filter_warning_msg);
  427. }
  428. if (isset ($move_form)){
  429. Display :: display_normal_message($move_form->toHtml(),false);
  430. }
  431. // --------------------------------------------------------------------------------
  432. // - LOAD DATA & DISPLAY TABLE -
  433. // --------------------------------------------------------------------------------
  434. $is_platform_admin= api_is_platform_admin();
  435. $is_course_admin= api_is_allowed_to_create_course();
  436. //load data for category, evaluation and links
  437. if (empty ($_GET['selectcat'])) {
  438. $category= 0;
  439. } else {
  440. $category= $_GET['selectcat'];
  441. }
  442. // search disabled in course context
  443. /*
  444. $simple_search_form= new UserForm(UserForm :: TYPE_SIMPLE_SEARCH, null, 'simple_search_form', null, api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']));
  445. $values= $simple_search_form->exportValues();
  446. $keyword = '';
  447. if (isset($_GET['search']) && !empty($_GET['search']))
  448. $keyword = Security::remove_XSS($_GET['search']);
  449. if ($simple_search_form->validate() && (empty($keyword)))
  450. $keyword = $values['keyword'];
  451. */
  452. /* search disabled in course context
  453. if (!empty($keyword))
  454. {
  455. $cats= Category :: load($category);
  456. $allcat= array ();
  457. $alleval= Evaluation :: find_evaluations($keyword, $cats[0]->get_id());
  458. $alllink= LinkFactory :: find_links($keyword, $cats[0]->get_id());
  459. }
  460. else
  461. */
  462. if (isset ($_GET['studentoverview'])) {
  463. $cats= Category :: load($category);
  464. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  465. $allcat= array ();
  466. $alleval= $cats[0]->get_evaluations($stud_id, true);
  467. $alllink= $cats[0]->get_links($stud_id, true);
  468. if (isset ($_GET['exportpdf'])) {
  469. $datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
  470. $header_names = array(get_lang('Name'),get_lang('Description'),get_lang('Weight'),get_lang('Date'),get_lang('Results'));
  471. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  472. $newarray = array();
  473. foreach ($data_array as $data) {
  474. $newarray[] = array_slice($data, 1);
  475. }
  476. $pdf= new Cezpdf();
  477. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  478. $pdf->ezSetMargins(30, 30, 50, 30);
  479. $pdf->ezSetY(810);
  480. $pdf->ezText(get_lang('FlatView').' ('. date('j/n/Y g:i') .')',12,array('justification'=>'center'));
  481. $pdf->line(50,790,550,790);
  482. $pdf->line(50,40,550,40);
  483. $pdf->ezSetY(750);
  484. $pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=> 500));
  485. $pdf->ezStream();
  486. exit;
  487. }
  488. } elseif (!empty($_GET['export_certificate'])) {
  489. $user_id = strval(intval($_GET['user']));
  490. if (!api_is_allowed_to_edit(true,true)) {
  491. $user_id = api_get_user_id();
  492. }
  493. $category = Category :: load ($_GET['cat']);
  494. if ($category[0]->is_certificate_available($user_id)) {
  495. $user= get_user_info_from_id($user_id);
  496. $scoredisplay = ScoreDisplay :: instance();
  497. $scorecourse = $category[0]->calc_score($user_id);
  498. $scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
  499. $cattotal = Category :: load(0);
  500. $scoretotal= $cattotal[0]->calc_score($user_id);
  501. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal,SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  502. //prepare all necessary variables:
  503. $organization_name = api_get_setting('Institution');
  504. $portal_name = api_get_setting('siteName');
  505. $stud_fn = $user['firstname'];
  506. $stud_ln = $user['lastname'];
  507. $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'),$organization_name,$stud_fn.' '.$stud_ln,$category[0]->get_name(),$scorecourse_display);
  508. $certif_text = str_replace("\\n","\n",$certif_text);
  509. $date = date('d/m/Y',time());
  510. $pdf= new Cezpdf('a4','landscape');
  511. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  512. $pdf->ezSetMargins(30, 30, 50, 50);
  513. //line Y coordinates in landscape mode are upside down (500 is on top, 10 is on the bottom)
  514. $pdf->line(50,50,790,50);
  515. $pdf->line(50,550,790,550);
  516. $pdf->ezSetY(450);
  517. $pdf->ezImage(api_get_path(SYS_CODE_PATH).'img/dokeos_logo_certif.png',1,400,'','center','');
  518. $pdf->ezSetY(480);
  519. $pdf->ezText($certif_text,28,array('justification'=>'center'));
  520. //$pdf->ezSetY(750);
  521. $pdf->ezSetY(50);
  522. $pdf->ezText($date,18,array('justification'=>'center'));
  523. $pdf->ezSetY(580);
  524. $pdf->ezText($organization_name,22,array('justification'=>'left'));
  525. $pdf->ezSetY(580);
  526. $pdf->ezText($portal_name,22,array('justification'=>'right'));
  527. $pdf->ezStream();
  528. }
  529. exit;
  530. } else { //in any other case (no search, no pdf), print the available gradebooks
  531. // Important note: loading a category will actually load the *contents* of
  532. // this category. This means that, to show the categories of a course,
  533. // we have to show the root category and show its subcategories that
  534. // are inside this course. This is done at the time of calling
  535. // $cats[0]->get_subcategories(), not at the time of doing Category::load()
  536. // $category comes from GET['selectcat']
  537. $course_code = api_get_course_id();
  538. $session_id = api_get_session_id();
  539. //if $category = 0 (which happens when GET['selectcat'] is undefined)
  540. // then Category::load() will create a new 'root' category with empty
  541. // course and session fields in memory (Category::create_root_category())
  542. if ($_in_course === true) {
  543. // When *inside* a course, we want to make sure there is one (and only
  544. // one) category for this course or for this session.
  545. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  546. if (empty($cats)) {
  547. // There is no category for this course+session, so create one
  548. $cat= new Category();
  549. $course_code = api_get_course_id();
  550. $session_id = api_get_session_id();
  551. if (!empty($session_id)) {
  552. $s_name = api_get_session_name();
  553. $cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name);
  554. $cat->set_session_id($session_id);
  555. } else {
  556. $cat->set_name($course_code);
  557. }
  558. $cat->set_course_code($course_code);
  559. $cat->set_description(null);
  560. $cat->set_user_id(api_get_user_id());
  561. $cat->set_parent_id(0);
  562. $cat->set_weight(100);
  563. $cat->set_visible(0);
  564. $can_edit = api_is_allowed_to_edit(true, true);
  565. if ($can_edit) {
  566. $cat->add();
  567. }
  568. unset ($cat);
  569. }
  570. unset($cats);
  571. }
  572. $cats = Category :: load ($category, null, null, null, null, null, false);
  573. //with this fix the teacher only can view 1 gradebook
  574. //$stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  575. if (api_is_platform_admin()) {
  576. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  577. } else {
  578. $stud_id= api_get_user_id();
  579. }
  580. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  581. $alleval= $cats[0]->get_evaluations($stud_id);
  582. $alllink= $cats[0]->get_links($stud_id);
  583. //whether we found a category or not, we now have a category object with
  584. // empty or full subcats
  585. }
  586. // add params to the future links (in the table shown)
  587. $addparams = array ('selectcat' => $cats[0]->get_id());
  588. /*
  589. if (isset($_GET['search'])) {
  590. $addparams['search'] = $keyword;
  591. }
  592. */
  593. if (isset ($_GET['studentoverview'])) {
  594. $addparams['studentoverview'] = '';
  595. }
  596. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  597. $no_qualification = false;
  598. if (( count($allcat) == 0) && ( count($alleval) == 0 ) && ( count($alllink) == 0 )) {
  599. $no_qualification = true;
  600. if (($is_course_admin) && (!isset ($_GET['selectcat']))) {
  601. 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);
  602. }
  603. }
  604. //here we are in a sub category
  605. if ($category != '0') {
  606. DisplayGradebook :: display_header_gradebook($cats[0], 0, $_GET['selectcat'], $is_course_admin, $is_platform_admin, $simple_search_form, false, true);
  607. } else {
  608. //this is the root category
  609. //DisplayGradebook :: display_header_gradebook($cats[0], 0, 0, $is_course_admin, $is_platform_admin, $simple_search_form, false, false);
  610. }
  611. if (api_is_platform_admin() || api_is_allowed_to_create_course()) {
  612. if (!isset ($_GET['selectcat'])) {
  613. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  614. DisplayGradebook :: display_reduce_header_gradebook($cats[0],$is_course_admin, $is_platform_admin, $simple_search_form, false, false);
  615. }
  616. }
  617. $gradebooktable->display();
  618. Display :: display_footer();