index.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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. if (isset($_GET['isStudentView'])) {
  56. if ( (isset($_GET['selectcat']) && $_GET['selectcat']>0) && (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) {
  57. $interbreadcrumb[]= array (
  58. 'url' => 'index.php'.'?selectcat=0&amp;isStudentView='.$_GET['isStudentView'],
  59. 'name' => get_lang('Gradebook')
  60. );
  61. }
  62. }
  63. if ( (isset($_GET['selectcat']) && $_GET['selectcat']>0) && (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) {
  64. Display :: display_header(get_lang('Details'));
  65. $category= $_GET['selectcat'];
  66. $stud_id=api_get_user_id();
  67. $course_code=api_get_course_id();
  68. $session_id=api_get_session_id();
  69. $cats = Category :: load ($category, null, null, null, null, null, false);
  70. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  71. $alleval= $cats[0]->get_evaluations($stud_id);
  72. $alllink= $cats[0]->get_links($stud_id);
  73. $addparams=array();
  74. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  75. $gradebooktable->display();
  76. Display :: display_footer();
  77. exit;
  78. } else {
  79. if ( !isset($_GET['selectcat']) && ($_SESSION['studentview']=='studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='true') ) {
  80. Display :: display_header(get_lang('Gradebook'));
  81. $stud_id=api_get_user_id();
  82. $course_code=api_get_course_id();
  83. $session_id=api_get_session_id();
  84. $addparams=array();
  85. $cats = Category :: load (0, null, null, null, null, null, false);
  86. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  87. $alleval= $cats[0]->get_evaluations($stud_id);
  88. $alllink= $cats[0]->get_links($stud_id);
  89. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  90. $gradebooktable->display();
  91. Display :: display_footer();
  92. exit;
  93. }
  94. }
  95. // --------------------------------------------------------------------------------
  96. // - ACTIONS -
  97. // --------------------------------------------------------------------------------
  98. //this is called when there is no data for the course admin
  99. if (isset ($_GET['createallcategories'])) {
  100. block_students();
  101. $coursecat= Category :: get_not_created_course_categories(api_get_user_id());
  102. if (!count($coursecat) == 0) {
  103. foreach ($coursecat as $row) {
  104. $cat= new Category();
  105. $cat->set_name($row[1]);
  106. $cat->set_course_code($row[0]);
  107. $cat->set_description(null);
  108. $cat->set_user_id(api_get_user_id());
  109. $cat->set_parent_id(0);
  110. $cat->set_weight(0);
  111. $cat->set_visible(0);
  112. $cat->add();
  113. unset ($cat);
  114. }
  115. }
  116. header('Location: '.$_SESSION['gradebook_dest'].'?addallcat=&selectcat=0');
  117. exit;
  118. }
  119. //show logs evaluations
  120. if (isset ($_GET['visiblelog'])) {
  121. header('Location: ' . api_get_self().'/gradebook_showlog_eval.php');
  122. exit;
  123. }
  124. //move a category
  125. if (isset ($_GET['movecat'])) {
  126. block_students();
  127. $cats= Category :: load($_GET['movecat']);
  128. if (!isset ($_GET['targetcat'])) {
  129. $move_form= new CatForm(CatForm :: TYPE_MOVE,
  130. $cats[0],
  131. 'move_cat_form',
  132. null,
  133. api_get_self() . '?movecat=' . Security::remove_XSS($_GET['movecat'])
  134. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  135. if ($move_form->validate()) {
  136. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  137. . '&movecat=' . Security::remove_XSS($_GET['movecat'])
  138. . '&targetcat=' . $move_form->exportValue('move_cat'));
  139. exit;
  140. }
  141. } else {
  142. $targetcat= Category :: load($_GET['targetcat']);
  143. $course_to_crsind = ($cats[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  144. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  145. $cats[0]->move_to_cat($targetcat[0]);
  146. header('Location: ' . api_get_self() . '?categorymoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  147. exit;
  148. }
  149. unset ($targetcat);
  150. }
  151. unset ($cats);
  152. }
  153. //move an evaluation
  154. if (isset ($_GET['moveeval'])) {
  155. block_students();
  156. $evals= Evaluation :: load($_GET['moveeval']);
  157. if (!isset ($_GET['targetcat'])) {
  158. $move_form= new EvalForm(EvalForm :: TYPE_MOVE,
  159. $evals[0],
  160. null,
  161. 'move_eval_form',
  162. null,
  163. api_get_self() . '?moveeval=' . Security::remove_XSS($_GET['moveeval'])
  164. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  165. if ($move_form->validate()) {
  166. header('Location: ' .api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  167. . '&moveeval=' . Security::remove_XSS($_GET['moveeval'])
  168. . '&targetcat=' . $move_form->exportValue('move_cat'));
  169. exit;
  170. }
  171. } else {
  172. $targetcat= Category :: load($_GET['targetcat']);
  173. $course_to_crsind = ($evals[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  174. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  175. $evals[0]->move_to_cat($targetcat[0]);
  176. header('Location: ' . api_get_self() . '?evaluationmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  177. exit;
  178. }
  179. unset ($targetcat);
  180. }
  181. unset ($evals);
  182. }
  183. //move a link
  184. if (isset ($_GET['movelink'])) {
  185. block_students();
  186. $link= LinkFactory :: load($_GET['movelink']);
  187. $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']));
  188. if ($move_form->validate()) {
  189. $targetcat= Category :: load($move_form->exportValue('move_cat'));
  190. $link[0]->move_to_cat($targetcat[0]);
  191. unset ($link);
  192. header('Location: ' . api_get_self(). '?linkmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  193. exit;
  194. }
  195. }
  196. //parameters for categories
  197. if (isset ($_GET['visiblecat'])) {
  198. block_students();
  199. if (isset ($_GET['set_visible'])) {
  200. $visibility_command= 1;
  201. } else {
  202. $visibility_command= 0;
  203. }
  204. $cats= Category :: load($_GET['visiblecat']);
  205. $cats[0]->set_visible($visibility_command);
  206. $cats[0]->save();
  207. $cats[0]->apply_visibility_to_children();
  208. unset ($cats);
  209. if ($visibility_command) {
  210. $confirmation_message = get_lang('ViMod');
  211. $filter_confirm_msg = false;
  212. } else {
  213. $confirmation_message = get_lang('InViMod');
  214. $filter_confirm_msg = false;
  215. }
  216. }
  217. if (isset ($_GET['deletecat'])) {
  218. block_students();
  219. $cats= Category :: load($_GET['deletecat']);
  220. //delete all categories,subcategories and results
  221. if ($cats[0] != null) {
  222. if ($cats[0]->get_id() != 0) {
  223. // better don't try to delete the root...
  224. $cats[0]->delete_all();
  225. }
  226. }
  227. $confirmation_message = get_lang('CategoryDeleted');
  228. $filter_confirm_msg = false;
  229. }
  230. //parameters for evaluations
  231. if (isset ($_GET['visibleeval'])) {
  232. block_students();
  233. if (isset ($_GET['set_visible'])) {
  234. $visibility_command= 1;
  235. } else {
  236. $visibility_command= 0;
  237. }
  238. $eval= Evaluation :: load($_GET['visibleeval']);
  239. $eval[0]->set_visible($visibility_command);
  240. $eval[0]->save();
  241. unset ($eval);
  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['deleteeval'])) {
  251. block_students();
  252. $eval= Evaluation :: load($_GET['deleteeval']);
  253. if ($eval[0] != null) {
  254. $eval[0]->delete_with_results();
  255. }
  256. $confirmation_message = get_lang('GradebookEvaluationDeleted');
  257. $filter_confirm_msg = false;
  258. }
  259. //parameters for links
  260. if (isset ($_GET['visiblelink'])) {
  261. block_students();
  262. if (isset ($_GET['set_visible'])) {
  263. $visibility_command= 1;
  264. } else {
  265. $visibility_command= 0;
  266. }
  267. $link= LinkFactory :: load($_GET['visiblelink']);
  268. $link[0]->set_visible($visibility_command);
  269. $link[0]->save();
  270. unset ($link);
  271. if ($visibility_command) {
  272. $confirmation_message = get_lang('ViMod');
  273. $filter_confirm_msg = false;
  274. } else {
  275. $confirmation_message = get_lang('InViMod');
  276. $filter_confirm_msg = false;
  277. }
  278. }
  279. if (isset ($_GET['deletelink'])) {
  280. block_students();
  281. $link= LinkFactory :: load($_GET['deletelink']);
  282. if ($link[0] != null) {
  283. $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'].');';
  284. api_sql_query($sql);
  285. $link[0]->delete();
  286. }
  287. unset ($link);
  288. $confirmation_message = get_lang('LinkDeleted');
  289. $filter_confirm_msg = false;
  290. }
  291. if (!empty($course_to_crsind) && !isset($_GET['confirm'])) {
  292. block_students();
  293. if (!isset($_GET['movecat']) && !isset($_GET['moveeval'])) {
  294. die ('Error: movecat or moveeval not defined');
  295. }
  296. $button = '<form name="confirm"
  297. method="post"
  298. action="'.api_get_self() .'?confirm='
  299. .(isset($_GET['movecat']) ? '&movecat=' . Security::remove_XSS($_GET['movecat'])
  300. : '&moveeval=' . Security::remove_XSS($_GET['moveeval']) )
  301. .'&selectcat=' . Security::remove_XSS($_GET['selectcat'])
  302. .'&targetcat=' . Security::remove_XSS($_GET['targetcat']).'">
  303. <input type="submit" value="'.get_lang('Ok').'">
  304. </form>';
  305. $warning_message = get_lang('MoveWarning').'<br><br>'.$button;
  306. $filter_warning_msg = false;
  307. }
  308. //actions on the sortabletable
  309. if (isset ($_POST['action'])) {
  310. block_students();
  311. $number_of_selected_items= count($_POST['id']);
  312. if ($number_of_selected_items == '0') {
  313. $warning_message = get_lang('NoItemsSelected');
  314. $filter_warning_msg = false;
  315. } else {
  316. switch ($_POST['action']) {
  317. case 'deleted' :
  318. $number_of_deleted_categories= 0;
  319. $number_of_deleted_evaluations= 0;
  320. $number_of_deleted_links= 0;
  321. foreach ($_POST['id'] as $indexstr) {
  322. if (substr($indexstr, 0, 4) == 'CATE') {
  323. $cats= Category :: load(substr($indexstr, 4));
  324. if ($cats[0] != null) {
  325. $cats[0]->delete_all();
  326. }
  327. $number_of_deleted_categories++;
  328. }
  329. if (substr($indexstr, 0, 4) == 'EVAL') {
  330. $eval= Evaluation :: load(substr($indexstr, 4));
  331. if ($eval[0] != null) {
  332. $eval[0]->delete_with_results();
  333. }
  334. $number_of_deleted_evaluations++;
  335. }
  336. if (substr($indexstr, 0, 4) == 'LINK') {
  337. $link= LinkFactory :: load(substr($indexstr, 4));
  338. if ($link[0] != null) {
  339. $link[0]->delete();
  340. }
  341. $number_of_deleted_links++;
  342. }
  343. }
  344. $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>';
  345. $filter_confirm_msg = false;
  346. break;
  347. case 'setvisible' :
  348. foreach ($_POST['id'] as $indexstr) {
  349. if (substr($indexstr, 0, 4) == 'CATE') {
  350. $cats= Category :: load(substr($indexstr, 4));
  351. $cats[0]->set_visible(1);
  352. $cats[0]->save();
  353. $cats[0]->apply_visibility_to_children();
  354. }
  355. if (substr($indexstr, 0, 4) == 'EVAL') {
  356. $eval= Evaluation :: load(substr($indexstr, 4));
  357. $eval[0]->set_visible(1);
  358. $eval[0]->save();
  359. }
  360. if (substr($indexstr, 0, 4) == 'LINK') {
  361. $link= LinkFactory :: load(substr($indexstr, 4));
  362. $link[0]->set_visible(1);
  363. $link[0]->save();
  364. }
  365. }
  366. $confirmation_message = get_lang('ItemsVisible');
  367. $filter_confirm_msg = false;
  368. break;
  369. case 'setinvisible' :
  370. foreach ($_POST['id'] as $indexstr) {
  371. if (substr($indexstr, 0, 4) == 'CATE') {
  372. $cats= Category :: load(substr($indexstr, 4));
  373. $cats[0]->set_visible(0);
  374. $cats[0]->save();
  375. $cats[0]->apply_visibility_to_children();
  376. }
  377. if (substr($indexstr, 0, 4) == 'EVAL') {
  378. $eval= Evaluation :: load(substr($indexstr, 4));
  379. $eval[0]->set_visible(0);
  380. $eval[0]->save();
  381. }
  382. if (substr($indexstr, 0, 4) == 'LINK') {
  383. $link= LinkFactory :: load(substr($indexstr, 4));
  384. $link[0]->set_visible(0);
  385. $link[0]->save();
  386. }
  387. }
  388. $confirmation_message = get_lang('ItemsInVisible');
  389. $filter_confirm_msg = false;
  390. break;
  391. }
  392. }
  393. }
  394. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  395. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  396. . '&search='.Security::remove_XSS($_POST['keyword']));
  397. exit;
  398. }
  399. // --------------------------------------------------------------------------------
  400. // - DISPLAY HEADERS AND MESSAGES -
  401. // --------------------------------------------------------------------------------
  402. if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) {
  403. if (isset ($_GET['studentoverview'])) {
  404. $interbreadcrumb[]= array (
  405. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  406. 'name' => get_lang('Gradebook')
  407. );
  408. Display :: display_header(get_lang('FlatView'));
  409. } elseif (isset ($_GET['search'])) {
  410. $interbreadcrumb[]= array (
  411. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  412. 'name' => get_lang('Gradebook')
  413. );
  414. Display :: display_header(get_lang('SearchResults'));
  415. } elseif(isset ($_GET['selectcat'])) {
  416. $interbreadcrumb[]= array (
  417. 'url' => $_SESSION['gradebook_dest'],
  418. 'name' => get_lang('Gradebook')
  419. );
  420. if (!isset($_GET['gradebooklist_direction'])) {
  421. $interbreadcrumb[]= array (
  422. 'url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  423. 'name' => get_lang('Details')
  424. );
  425. }
  426. Display :: display_header('');
  427. } else {
  428. Display :: display_header(get_lang('Gradebook'));
  429. /*if ( ($_SESSION['studentview']=='studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='true') ) {
  430. $cats = Category :: load (0, null, null, null, null, null, false);
  431. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  432. $alleval= $cats[0]->get_evaluations($stud_id);
  433. $alllink= $cats[0]->get_links($stud_id);
  434. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  435. $gradebooktable->display();
  436. Display :: display_footer();
  437. exit;
  438. }*/
  439. }
  440. }
  441. if (isset ($_GET['categorymoved'])) {
  442. Display :: display_confirmation_message(get_lang('CategoryMoved'),false);
  443. }
  444. if (isset ($_GET['evaluationmoved'])) {
  445. Display :: display_confirmation_message(get_lang('EvaluationMoved'),false);
  446. }
  447. if (isset ($_GET['linkmoved'])) {
  448. Display :: display_confirmation_message(get_lang('LinkMoved'),false);
  449. }
  450. if (isset ($_GET['addcat'])) {
  451. Display :: display_confirmation_message(get_lang('CategoryAdded'),false);
  452. }
  453. if (isset ($_GET['linkadded'])) {
  454. Display :: display_confirmation_message(get_lang('LinkAdded'),false);
  455. }
  456. if (isset ($_GET['addresult'])) {
  457. Display :: display_confirmation_message(get_lang('ResultAdded'),false);
  458. }
  459. if (isset ($_GET['editcat'])) {
  460. Display :: display_confirmation_message(get_lang('CategoryEdited'),false);
  461. }
  462. if (isset ($_GET['editeval'])) {
  463. Display :: display_confirmation_message(get_lang('EvaluationEdited'),false);
  464. }
  465. if (isset ($_GET['linkedited'])) {
  466. Display :: display_confirmation_message(get_lang('LinkEdited'),false);
  467. }
  468. if (isset ($_GET['nolinkitems'])){
  469. Display :: display_warning_message(get_lang('NoLinkItems'),false);
  470. }
  471. if (isset ($_GET['addallcat'])){
  472. Display :: display_normal_message(get_lang('AddAllCat'),false);
  473. }
  474. if (isset ($confirmation_message)){
  475. Display :: display_confirmation_message($confirmation_message,$filter_confirm_msg);
  476. }
  477. if (isset ($warning_message)){
  478. Display :: display_warning_message($warning_message,$filter_warning_msg);
  479. }
  480. if (isset ($move_form)){
  481. Display :: display_normal_message($move_form->toHtml(),false);
  482. }
  483. // --------------------------------------------------------------------------------
  484. // - LOAD DATA & DISPLAY TABLE -
  485. // --------------------------------------------------------------------------------
  486. $is_platform_admin= api_is_platform_admin();
  487. $is_course_admin= api_is_allowed_to_create_course();
  488. //load data for category, evaluation and links
  489. if (empty ($_GET['selectcat'])) {
  490. $category= 0;
  491. } else {
  492. $category= $_GET['selectcat'];
  493. }
  494. $simple_search_form='';
  495. // search disabled in course context
  496. /*
  497. $simple_search_form= new UserForm(UserForm :: TYPE_SIMPLE_SEARCH, null, 'simple_search_form', null, api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']));
  498. $values= $simple_search_form->exportValues();
  499. $keyword = '';
  500. if (isset($_GET['search']) && !empty($_GET['search']))
  501. $keyword = Security::remove_XSS($_GET['search']);
  502. if ($simple_search_form->validate() && (empty($keyword)))
  503. $keyword = $values['keyword'];
  504. */
  505. /* search disabled in course context
  506. if (!empty($keyword))
  507. {
  508. $cats= Category :: load($category);
  509. $allcat= array ();
  510. $alleval= Evaluation :: find_evaluations($keyword, $cats[0]->get_id());
  511. $alllink= LinkFactory :: find_links($keyword, $cats[0]->get_id());
  512. }
  513. else
  514. */
  515. if (isset ($_GET['studentoverview'])) {
  516. $cats= Category :: load($category);
  517. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  518. $allcat= array ();
  519. $alleval= $cats[0]->get_evaluations($stud_id, true);
  520. $alllink= $cats[0]->get_links($stud_id, true);
  521. if (isset ($_GET['exportpdf'])) {
  522. $datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
  523. $header_names = array(get_lang('Name'),get_lang('Description'),get_lang('Weight'),get_lang('Date'),get_lang('Results'));
  524. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  525. $newarray = array();
  526. foreach ($data_array as $data) {
  527. $newarray[] = array_slice($data, 1);
  528. }
  529. $pdf= new Cezpdf();
  530. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  531. $pdf->ezSetMargins(30, 30, 50, 30);
  532. $pdf->ezSetY(810);
  533. $pdf->ezText(get_lang('FlatView').' ('. date('j/n/Y g:i') .')',12,array('justification'=>'center'));
  534. $pdf->line(50,790,550,790);
  535. $pdf->line(50,40,550,40);
  536. $pdf->ezSetY(750);
  537. $pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=> 500));
  538. $pdf->ezStream();
  539. exit;
  540. }
  541. } elseif (!empty($_GET['export_certificate'])) {
  542. $user_id = strval(intval($_GET['user']));
  543. if (!api_is_allowed_to_edit(true,true)) {
  544. $user_id = api_get_user_id();
  545. }
  546. $category = Category :: load ($_GET['cat_id']);
  547. if ($category[0]->is_certificate_available($user_id)) {
  548. $user= get_user_info_from_id($user_id);
  549. $scoredisplay = ScoreDisplay :: instance();
  550. $scorecourse = $category[0]->calc_score($user_id);
  551. $scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
  552. $cattotal = Category :: load($_GET['cat_id']);
  553. $scoretotal= $cattotal[0]->calc_score($user_id);
  554. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal,SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  555. //prepare all necessary variables:
  556. $organization_name = api_get_setting('Institution');
  557. $portal_name = api_get_setting('siteName');
  558. $stud_fn = $user['firstname'];
  559. $stud_ln = $user['lastname'];
  560. $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'),$organization_name,$stud_fn.' '.$stud_ln,$category[0]->get_name(),$scorecourse_display);
  561. $certif_text = str_replace("\\n","\n",$certif_text);
  562. $date = date('d/m/Y',time());
  563. $pdf= new Cezpdf('a4','landscape');
  564. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  565. $pdf->ezSetMargins(30, 30, 50, 50);
  566. //line Y coordinates in landscape mode are upside down (500 is on top, 10 is on the bottom)
  567. $pdf->line(50,50,790,50);
  568. $pdf->line(50,550,790,550);
  569. $pdf->ezSetY(450);
  570. $pdf->ezImage(api_get_path(SYS_CODE_PATH).'img/dokeos_logo_certif.png',1,400,'','center','');
  571. $pdf->ezSetY(480);
  572. $pdf->ezText($certif_text,28,array('justification'=>'center'));
  573. //$pdf->ezSetY(750);
  574. $pdf->ezSetY(50);
  575. $pdf->ezText($date,18,array('justification'=>'center'));
  576. $pdf->ezSetY(580);
  577. $pdf->ezText($organization_name,22,array('justification'=>'left'));
  578. $pdf->ezSetY(580);
  579. $pdf->ezText($portal_name,22,array('justification'=>'right'));
  580. $pdf->ezStream();
  581. }
  582. exit;
  583. } else { //in any other case (no search, no pdf), print the available gradebooks
  584. // Important note: loading a category will actually load the *contents* of
  585. // this category. This means that, to show the categories of a course,
  586. // we have to show the root category and show its subcategories that
  587. // are inside this course. This is done at the time of calling
  588. // $cats[0]->get_subcategories(), not at the time of doing Category::load()
  589. // $category comes from GET['selectcat']
  590. $course_code = api_get_course_id();
  591. $session_id = api_get_session_id();
  592. //if $category = 0 (which happens when GET['selectcat'] is undefined)
  593. // then Category::load() will create a new 'root' category with empty
  594. // course and session fields in memory (Category::create_root_category())
  595. if ($_in_course === true) {
  596. // When *inside* a course, we want to make sure there is one (and only
  597. // one) category for this course or for this session.
  598. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  599. if (empty($cats)) {
  600. // There is no category for this course+session, so create one
  601. $cat= new Category();
  602. $course_code = api_get_course_id();
  603. $session_id = api_get_session_id();
  604. if (!empty($session_id)) {
  605. $my_session_id=api_get_session_id();
  606. $s_name = api_get_session_name($my_session_id);
  607. $cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name);
  608. $cat->set_session_id($session_id);
  609. } else {
  610. $cat->set_name($course_code);
  611. }
  612. $cat->set_course_code($course_code);
  613. $cat->set_description(null);
  614. $cat->set_user_id(api_get_user_id());
  615. $cat->set_parent_id(0);
  616. $cat->set_weight(100);
  617. $cat->set_visible(0);
  618. $can_edit = api_is_allowed_to_edit(true, true);
  619. if ($can_edit) {
  620. $cat->add();
  621. }
  622. unset ($cat);
  623. }
  624. unset($cats);
  625. }
  626. $cats = Category :: load ($category, null, null, null, null, null, false);
  627. //with this fix the teacher only can view 1 gradebook
  628. //$stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  629. if (api_is_platform_admin()) {
  630. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  631. } else {
  632. $stud_id= api_get_user_id();
  633. }
  634. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  635. $alleval= $cats[0]->get_evaluations($stud_id);
  636. $alllink= $cats[0]->get_links($stud_id);
  637. //whether we found a category or not, we now have a category object with
  638. // empty or full subcats
  639. }
  640. // add params to the future links (in the table shown)
  641. $addparams = array ('selectcat' => $cats[0]->get_id());
  642. /*
  643. if (isset($_GET['search'])) {
  644. $addparams['search'] = $keyword;
  645. }
  646. */
  647. if (isset ($_GET['studentoverview'])) {
  648. $addparams['studentoverview'] = '';
  649. }
  650. //$addparams['cidReq']='';
  651. if (isset($_GET['cidReq']) && $_GET['cidReq']!='') {
  652. $addparams['cidReq']=$_GET['cidReq'];
  653. } else {
  654. $addparams['cidReq']='';
  655. }
  656. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  657. $no_qualification = false;
  658. if (( count($allcat) == 0) && ( count($alleval) == 0 ) && ( count($alllink) == 0 )) {
  659. $no_qualification = true;
  660. if ((($is_course_admin) && (!isset ($_GET['selectcat']))) && api_is_course_tutor()) {
  661. 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);
  662. }
  663. }
  664. //here we are in a sub category
  665. if ($category != '0') {
  666. $cat=new Category();
  667. $dblib=new Database();
  668. $category_id=Security::remove_XSS($_GET['selectcat']);
  669. $course_id=$dblib->get_course_by_category($category_id);
  670. $show_message=$cat->show_message_resource_delete($course_id);
  671. if ($show_message=='') {
  672. DisplayGradebook :: display_header_gradebook($cats[0], 0, $_GET['selectcat'], $is_course_admin, $is_platform_admin, $simple_search_form, false, true);
  673. }
  674. } else {
  675. //this is the root category
  676. //DisplayGradebook :: display_header_gradebook($cats[0], 0, 0, $is_course_admin, $is_platform_admin, $simple_search_form, false, false);
  677. }
  678. if (api_is_platform_admin() || api_is_allowed_to_create_course() && api_is_course_tutor()) {
  679. if ( (isset ($_GET['selectcat']) && $_GET['selectcat']<>0) ) {
  680. //
  681. } else {
  682. if ( ((isset ($_GET['selectcat']) && $_GET['selectcat']==0) || ((isset($_GET['cidReq']) && $_GET['cidReq']!==''))) || isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') {
  683. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  684. DisplayGradebook :: display_reduce_header_gradebook($cats[0],$is_course_admin, $is_platform_admin, $simple_search_form, false, false);
  685. }
  686. }
  687. }
  688. $gradebooktable->display();
  689. Display :: display_footer();