index.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. <?php // $Id: $
  2. /* For licensing terms, see /license.txt */
  3. $language_file= 'gradebook';
  4. // $cidReset : This is the main difference with gradebook.php, here we say,
  5. // basically, that we are inside a course, and many things depend from that
  6. $cidReset= false;
  7. $_in_course = true;
  8. require_once '../inc/global.inc.php';
  9. $course_code = api_get_course_id();
  10. //make sure the destination for scripts is index.php instead of gradebook.php
  11. $_SESSION['gradebook_dest'] = 'index.php';
  12. /*if (isset($_GET['cidReq'])) {
  13. $this_section = SECTION_COURSES;
  14. } else {
  15. $this_section = SECTION_MYGRADEBOOK;
  16. }*/
  17. $this_section = SECTION_COURSES;
  18. require_once 'lib/be.inc.php';
  19. require_once 'lib/scoredisplay.class.php';
  20. require_once 'lib/gradebook_functions.inc.php';
  21. require_once 'lib/fe/catform.class.php';
  22. require_once 'lib/fe/evalform.class.php';
  23. require_once 'lib/fe/linkform.class.php';
  24. require_once 'lib/gradebook_data_generator.class.php';
  25. require_once 'lib/fe/gradebooktable.class.php';
  26. require_once 'lib/fe/displaygradebook.php';
  27. require_once 'lib/fe/userform.class.php';
  28. require_once api_get_path(LIBRARY_PATH).'ezpdf/class.ezpdf.php';
  29. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  30. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  31. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  32. $htmlHeadXtra[] = '<script type="text/javascript">
  33. $(document).ready( function() {
  34. for (i=0;i<$(".actions").length;i++) {
  35. if ($(".actions:eq("+i+")").html()=="<table border=\"0\"></table>" || $(".actions:eq("+i+")").html()=="" || $(".actions:eq("+i+")").html()==null || $(".actions:eq("+i+")").html().split("<TBODY></TBODY>").length==2) {
  36. $(".actions:eq("+i+")").hide();
  37. }
  38. }
  39. } );
  40. </script>';
  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_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
  53. $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  54. $status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
  55. $filter_confirm_msg = true;
  56. $filter_warning_msg = true;
  57. $session_id = api_get_session_id();
  58. ///direct access to one evaluation
  59. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
  60. if (empty($cats))
  61. {
  62. $cats = Category :: load(0, null, $course_code, null, null, $session_id, false);//first time
  63. $first_time=1;
  64. }
  65. $_GET['selectcat'] = $cats[0]->get_id();
  66. if (isset($_GET['isStudentView'])) {
  67. if ( (isset($_GET['selectcat']) && $_GET['selectcat']>0) && (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) {
  68. $interbreadcrumb[]= array (
  69. 'url' => 'index.php'.'?selectcat=0&amp;isStudentView='.$_GET['isStudentView'],
  70. 'name' => get_lang('ToolGradebook')
  71. );
  72. }
  73. }
  74. if ( (isset($_GET['selectcat']) && $_GET['selectcat']>0) && (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) {
  75. Display :: display_header();
  76. //Introduction tool: student view
  77. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  78. $category= $_GET['selectcat'];
  79. $stud_id=api_get_user_id();
  80. $course_code=api_get_course_id();
  81. $session_id=api_get_session_id();
  82. $cats = Category :: load ($category, null, null, null, null, null, false);
  83. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  84. $alleval= $cats[0]->get_evaluations($stud_id);
  85. $alllink= $cats[0]->get_links($stud_id);
  86. $addparams=array();
  87. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  88. $gradebooktable->display();
  89. Display :: display_footer();
  90. exit;
  91. } else {
  92. if ( !isset($_GET['selectcat']) && ($_SESSION['studentview']=='studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='true') ) {
  93. // if ( !isset($_GET['selectcat']) && ($_SESSION['studentview']=='studentview') && ($status<>1 && !api_is_platform_admin()) || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='true' && $status<>1 && !api_is_platform_admin()) ) {
  94. Display :: display_header(get_lang('Gradebook'));
  95. //Introduction tool: student view
  96. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  97. $stud_id=api_get_user_id();
  98. $course_code=api_get_course_id();
  99. $session_id=api_get_session_id();
  100. $addparams=array();
  101. $cats = Category :: load (0, null, null, null, null, null, false);
  102. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  103. $alleval= $cats[0]->get_evaluations($stud_id);
  104. $alllink= $cats[0]->get_links($stud_id);
  105. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  106. $gradebooktable->display();
  107. Display :: display_footer();
  108. exit;
  109. }
  110. }
  111. // ACTIONS
  112. //this is called when there is no data for the course admin
  113. if (isset ($_GET['createallcategories'])) {
  114. block_students();
  115. $coursecat= Category :: get_not_created_course_categories(api_get_user_id());
  116. if (!count($coursecat) == 0) {
  117. foreach ($coursecat as $row) {
  118. $cat= new Category();
  119. $cat->set_name($row[1]);
  120. $cat->set_course_code($row[0]);
  121. $cat->set_description(null);
  122. $cat->set_user_id(api_get_user_id());
  123. $cat->set_parent_id(0);
  124. $cat->set_weight(0);
  125. $cat->set_visible(0);
  126. $cat->add();
  127. unset ($cat);
  128. }
  129. }
  130. header('Location: '.$_SESSION['gradebook_dest'].'?addallcat=&selectcat=0');
  131. exit;
  132. }
  133. //show logs evaluations
  134. if (isset ($_GET['visiblelog'])) {
  135. header('Location: ' . api_get_self().'/gradebook_showlog_eval.php');
  136. exit;
  137. }
  138. //move a category
  139. if (isset ($_GET['movecat'])) {
  140. block_students();
  141. $cats= Category :: load($_GET['movecat']);
  142. if (!isset ($_GET['targetcat'])) {
  143. $move_form= new CatForm(CatForm :: TYPE_MOVE,
  144. $cats[0],
  145. 'move_cat_form',
  146. null,
  147. api_get_self() . '?movecat=' . Security::remove_XSS($_GET['movecat'])
  148. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  149. if ($move_form->validate()) {
  150. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  151. . '&movecat=' . Security::remove_XSS($_GET['movecat'])
  152. . '&targetcat=' . $move_form->exportValue('move_cat'));
  153. exit;
  154. }
  155. } else {
  156. $targetcat= Category :: load($_GET['targetcat']);
  157. $course_to_crsind = ($cats[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  158. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  159. $cats[0]->move_to_cat($targetcat[0]);
  160. header('Location: ' . api_get_self() . '?categorymoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  161. exit;
  162. }
  163. unset ($targetcat);
  164. }
  165. unset ($cats);
  166. }
  167. //move an evaluation
  168. if (isset ($_GET['moveeval'])) {
  169. block_students();
  170. $evals= Evaluation :: load($_GET['moveeval']);
  171. if (!isset ($_GET['targetcat'])) {
  172. $move_form= new EvalForm(EvalForm :: TYPE_MOVE,
  173. $evals[0],
  174. null,
  175. 'move_eval_form',
  176. null,
  177. api_get_self() . '?moveeval=' . Security::remove_XSS($_GET['moveeval'])
  178. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  179. if ($move_form->validate()) {
  180. header('Location: ' .api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  181. . '&moveeval=' . Security::remove_XSS($_GET['moveeval'])
  182. . '&targetcat=' . $move_form->exportValue('move_cat'));
  183. exit;
  184. }
  185. } else {
  186. $targetcat= Category :: load($_GET['targetcat']);
  187. $course_to_crsind = ($evals[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  188. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  189. $evals[0]->move_to_cat($targetcat[0]);
  190. header('Location: ' . api_get_self() . '?evaluationmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  191. exit;
  192. }
  193. unset ($targetcat);
  194. }
  195. unset ($evals);
  196. }
  197. //move a link
  198. if (isset ($_GET['movelink'])) {
  199. block_students();
  200. $link= LinkFactory :: load($_GET['movelink']);
  201. $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']));
  202. if ($move_form->validate()) {
  203. $targetcat= Category :: load($move_form->exportValue('move_cat'));
  204. $link[0]->move_to_cat($targetcat[0]);
  205. unset ($link);
  206. header('Location: ' . api_get_self(). '?linkmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  207. exit;
  208. }
  209. }
  210. //parameters for categories
  211. if (isset ($_GET['visiblecat'])) {
  212. block_students();
  213. if (isset ($_GET['set_visible'])) {
  214. $visibility_command= 1;
  215. } else {
  216. $visibility_command= 0;
  217. }
  218. $cats= Category :: load($_GET['visiblecat']);
  219. $cats[0]->set_visible($visibility_command);
  220. $cats[0]->save();
  221. $cats[0]->apply_visibility_to_children();
  222. unset ($cats);
  223. if ($visibility_command) {
  224. $confirmation_message = get_lang('ViMod');
  225. $filter_confirm_msg = false;
  226. } else {
  227. $confirmation_message = get_lang('InViMod');
  228. $filter_confirm_msg = false;
  229. }
  230. }
  231. if (isset ($_GET['deletecat'])) {
  232. block_students();
  233. $cats= Category :: load($_GET['deletecat']);
  234. //delete all categories,subcategories and results
  235. if ($cats[0] != null) {
  236. if ($cats[0]->get_id() != 0) {
  237. // better don't try to delete the root...
  238. $cats[0]->delete_all();
  239. }
  240. }
  241. $confirmation_message = get_lang('CategoryDeleted');
  242. $filter_confirm_msg = false;
  243. }
  244. //parameters for evaluations
  245. if (isset ($_GET['visibleeval'])) {
  246. block_students();
  247. if (isset ($_GET['set_visible'])) {
  248. $visibility_command= 1;
  249. } else {
  250. $visibility_command= 0;
  251. }
  252. $eval= Evaluation :: load($_GET['visibleeval']);
  253. $eval[0]->set_visible($visibility_command);
  254. $eval[0]->save();
  255. unset ($eval);
  256. if ($visibility_command) {
  257. $confirmation_message = get_lang('ViMod');
  258. $filter_confirm_msg = false;
  259. } else {
  260. $confirmation_message = get_lang('InViMod');
  261. $filter_confirm_msg = false;
  262. }
  263. }
  264. if (isset ($_GET['deleteeval'])) {
  265. block_students();
  266. $eval= Evaluation :: load($_GET['deleteeval']);
  267. if ($eval[0] != null) {
  268. $eval[0]->delete_with_results();
  269. }
  270. $confirmation_message = get_lang('GradebookEvaluationDeleted');
  271. $filter_confirm_msg = false;
  272. }
  273. //parameters for links
  274. if (isset ($_GET['visiblelink'])) {
  275. block_students();
  276. if (isset ($_GET['set_visible'])) {
  277. $visibility_command= 1;
  278. } else {
  279. $visibility_command= 0;
  280. }
  281. $link= LinkFactory :: load($_GET['visiblelink']);
  282. $link[0]->set_visible($visibility_command);
  283. $link[0]->save();
  284. unset ($link);
  285. if ($visibility_command) {
  286. $confirmation_message = get_lang('ViMod');
  287. $filter_confirm_msg = false;
  288. } else {
  289. $confirmation_message = get_lang('InViMod');
  290. $filter_confirm_msg = false;
  291. }
  292. }
  293. if (isset ($_GET['deletelink'])) {
  294. block_students();
  295. $get_delete_link=Security::remove_XSS($_GET['deletelink']);
  296. //fixing #5229
  297. if (!empty($get_delete_link)) {
  298. $link= LinkFactory :: load($get_delete_link);
  299. if ($link[0] != null) {
  300. // clean forum qualify
  301. $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_delete_link.' AND type = '.LINK_FORUM_THREAD.');';
  302. Database::query($sql);
  303. // clean attendance
  304. $sql='UPDATE '.$tbl_attendance.' SET attendance_qualify_max=0, attendance_weight = 0, attendance_qualify_title="" WHERE id=(SELECT ref_id FROM '.$tbl_grade_links.' WHERE id='.$get_delete_link.' AND type = '.LINK_ATTENDANCE.');';
  305. Database::query($sql);
  306. $link[0]->delete();
  307. }
  308. unset ($link);
  309. $confirmation_message = get_lang('LinkDeleted');
  310. $filter_confirm_msg = false;
  311. }
  312. }
  313. if (!empty($course_to_crsind) && !isset($_GET['confirm'])) {
  314. block_students();
  315. if (!isset($_GET['movecat']) && !isset($_GET['moveeval'])) {
  316. die ('Error: movecat or moveeval not defined');
  317. }
  318. $button = '<form name="confirm"
  319. method="post"
  320. action="'.api_get_self() .'?confirm='
  321. .(isset($_GET['movecat']) ? '&movecat=' . Security::remove_XSS($_GET['movecat'])
  322. : '&moveeval=' . Security::remove_XSS($_GET['moveeval']) )
  323. .'&selectcat=' . Security::remove_XSS($_GET['selectcat'])
  324. .'&targetcat=' . Security::remove_XSS($_GET['targetcat']).'">
  325. <input type="submit" value="'.get_lang('Ok').'">
  326. </form>';
  327. $warning_message = get_lang('MoveWarning').'<br><br>'.$button;
  328. $filter_warning_msg = false;
  329. }
  330. //actions on the sortabletable
  331. if (isset ($_POST['action'])) {
  332. block_students();
  333. $number_of_selected_items= count($_POST['id']);
  334. if ($number_of_selected_items == '0') {
  335. $warning_message = get_lang('NoItemsSelected');
  336. $filter_warning_msg = false;
  337. } else {
  338. switch ($_POST['action']) {
  339. case 'deleted' :
  340. $number_of_deleted_categories= 0;
  341. $number_of_deleted_evaluations= 0;
  342. $number_of_deleted_links= 0;
  343. foreach ($_POST['id'] as $indexstr) {
  344. if (substr($indexstr, 0, 4) == 'CATE') {
  345. $cats= Category :: load(substr($indexstr, 4));
  346. if ($cats[0] != null) {
  347. $cats[0]->delete_all();
  348. }
  349. $number_of_deleted_categories++;
  350. }
  351. if (substr($indexstr, 0, 4) == 'EVAL') {
  352. $eval= Evaluation :: load(substr($indexstr, 4));
  353. if ($eval[0] != null) {
  354. $eval[0]->delete_with_results();
  355. }
  356. $number_of_deleted_evaluations++;
  357. }
  358. if (substr($indexstr, 0, 4) == 'LINK') {
  359. //fixing #5229
  360. $id = substr($indexstr, 4);
  361. if (!empty($id)) {
  362. $link= LinkFactory :: load($id);
  363. if ($link[0] != null) {
  364. $link[0]->delete();
  365. }
  366. $number_of_deleted_links++;
  367. }
  368. }
  369. }
  370. $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>';
  371. $filter_confirm_msg = false;
  372. break;
  373. case 'setvisible' :
  374. foreach ($_POST['id'] as $indexstr) {
  375. if (substr($indexstr, 0, 4) == 'CATE') {
  376. $cats= Category :: load(substr($indexstr, 4));
  377. $cats[0]->set_visible(1);
  378. $cats[0]->save();
  379. $cats[0]->apply_visibility_to_children();
  380. }
  381. if (substr($indexstr, 0, 4) == 'EVAL') {
  382. $eval= Evaluation :: load(substr($indexstr, 4));
  383. $eval[0]->set_visible(1);
  384. $eval[0]->save();
  385. }
  386. if (substr($indexstr, 0, 4) == 'LINK') {
  387. $link= LinkFactory :: load(substr($indexstr, 4));
  388. $link[0]->set_visible(1);
  389. $link[0]->save();
  390. }
  391. }
  392. $confirmation_message = get_lang('ItemsVisible');
  393. $filter_confirm_msg = false;
  394. break;
  395. case 'setinvisible' :
  396. foreach ($_POST['id'] as $indexstr) {
  397. if (substr($indexstr, 0, 4) == 'CATE') {
  398. $cats= Category :: load(substr($indexstr, 4));
  399. $cats[0]->set_visible(0);
  400. $cats[0]->save();
  401. $cats[0]->apply_visibility_to_children();
  402. }
  403. if (substr($indexstr, 0, 4) == 'EVAL') {
  404. $eval= Evaluation :: load(substr($indexstr, 4));
  405. $eval[0]->set_visible(0);
  406. $eval[0]->save();
  407. }
  408. if (substr($indexstr, 0, 4) == 'LINK') {
  409. $link= LinkFactory :: load(substr($indexstr, 4));
  410. $link[0]->set_visible(0);
  411. $link[0]->save();
  412. }
  413. }
  414. $confirmation_message = get_lang('ItemsInVisible');
  415. $filter_confirm_msg = false;
  416. break;
  417. }
  418. }
  419. }
  420. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  421. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  422. . '&search='.Security::remove_XSS($_POST['keyword']));
  423. exit;
  424. }
  425. // DISPLAY HEADERS AND MESSAGES
  426. if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) {
  427. if (isset ($_GET['studentoverview'])) {
  428. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('ToolGradebook'));
  429. Display :: display_header(get_lang('FlatView'));
  430. } elseif (isset ($_GET['search'])) {
  431. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('ToolGradebook'));
  432. Display :: display_header(get_lang('SearchResults'));
  433. } elseif(isset ($_GET['selectcat'])) {
  434. $interbreadcrumb[]= array ( 'url' => $_SESSION['gradebook_dest'],'name' => get_lang('ToolGradebook'));
  435. if (!isset($_GET['gradebooklist_direction'])) {
  436. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('Details'));
  437. }
  438. Display :: display_header('');
  439. } else {
  440. Display :: display_header(get_lang('ToolGradebook'));
  441. /*if ( ($_SESSION['studentview']=='studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='true') ) {
  442. $cats = Category :: load (0, null, null, null, null, null, false);
  443. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  444. $alleval= $cats[0]->get_evaluations($stud_id);
  445. $alllink= $cats[0]->get_links($stud_id);
  446. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  447. $gradebooktable->display();
  448. Display :: display_footer();
  449. exit;
  450. }*/
  451. }
  452. }
  453. if (isset ($_GET['categorymoved'])) {
  454. Display :: display_confirmation_message(get_lang('CategoryMoved'),false);
  455. }
  456. if (isset ($_GET['evaluationmoved'])) {
  457. Display :: display_confirmation_message(get_lang('EvaluationMoved'),false);
  458. }
  459. if (isset ($_GET['linkmoved'])) {
  460. Display :: display_confirmation_message(get_lang('LinkMoved'),false);
  461. }
  462. if (isset ($_GET['addcat'])) {
  463. Display :: display_confirmation_message(get_lang('CategoryAdded'),false);
  464. }
  465. if (isset ($_GET['linkadded'])) {
  466. Display :: display_confirmation_message(get_lang('LinkAdded'),false);
  467. }
  468. if (isset ($_GET['addresult'])) {
  469. Display :: display_confirmation_message(get_lang('ResultAdded'),false);
  470. }
  471. if (isset ($_GET['editcat'])) {
  472. Display :: display_confirmation_message(get_lang('CategoryEdited'),false);
  473. }
  474. if (isset ($_GET['editeval'])) {
  475. Display :: display_confirmation_message(get_lang('EvaluationEdited'),false);
  476. }
  477. if (isset ($_GET['linkedited'])) {
  478. Display :: display_confirmation_message(get_lang('LinkEdited'),false);
  479. }
  480. if (isset ($_GET['nolinkitems'])){
  481. Display :: display_warning_message(get_lang('NoLinkItems'),false);
  482. }
  483. if (isset ($_GET['addallcat'])){
  484. Display :: display_normal_message(get_lang('AddAllCat'),false);
  485. }
  486. if (isset ($confirmation_message)){
  487. Display :: display_confirmation_message($confirmation_message,$filter_confirm_msg);
  488. }
  489. if (isset ($warning_message)){
  490. Display :: display_warning_message($warning_message,$filter_warning_msg);
  491. }
  492. if (isset ($move_form)){
  493. Display :: display_normal_message($move_form->toHtml(),false);
  494. }
  495. // LOAD DATA & DISPLAY TABLE
  496. $is_platform_admin= api_is_platform_admin();
  497. $is_course_admin= api_is_allowed_to_create_course();
  498. //load data for category, evaluation and links
  499. if (empty ($_GET['selectcat'])) {
  500. $category= 0;
  501. } else {
  502. $category= $_GET['selectcat'];
  503. }
  504. $simple_search_form='';
  505. // search disabled in course context
  506. /*
  507. $simple_search_form= new UserForm(UserForm :: TYPE_SIMPLE_SEARCH, null, 'simple_search_form', null, api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']));
  508. $values= $simple_search_form->exportValues();
  509. $keyword = '';
  510. if (isset($_GET['search']) && !empty($_GET['search']))
  511. $keyword = Security::remove_XSS($_GET['search']);
  512. if ($simple_search_form->validate() && (empty($keyword)))
  513. $keyword = $values['keyword'];
  514. */
  515. /* search disabled in course context
  516. if (!empty($keyword))
  517. {
  518. $cats= Category :: load($category);
  519. $allcat= array ();
  520. $alleval= Evaluation :: find_evaluations($keyword, $cats[0]->get_id());
  521. $alllink= LinkFactory :: find_links($keyword, $cats[0]->get_id());
  522. }
  523. else
  524. */
  525. if (isset ($_GET['studentoverview'])) {
  526. $cats= Category :: load($category);
  527. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  528. $allcat= array ();
  529. $alleval= $cats[0]->get_evaluations($stud_id, true);
  530. $alllink= $cats[0]->get_links($stud_id, true);
  531. if (isset ($_GET['exportpdf'])) {
  532. $datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
  533. $header_names = array(get_lang('Name'),get_lang('Description'),get_lang('Weight'),get_lang('Date'),get_lang('Results'));
  534. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  535. $newarray = array();
  536. foreach ($data_array as $data) {
  537. $newarray[] = array_slice($data, 1);
  538. }
  539. $pdf= new Cezpdf();
  540. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  541. $pdf->ezSetMargins(30, 30, 50, 30);
  542. $pdf->ezSetY(810);
  543. $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'));
  544. $pdf->line(50,790,550,790);
  545. $pdf->line(50,40,550,40);
  546. $pdf->ezSetY(750);
  547. $pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=> 500));
  548. $pdf->ezStream();
  549. exit;
  550. }
  551. } elseif (!empty($_GET['export_certificate'])) {
  552. $user_id = strval(intval($_GET['user']));
  553. if (!api_is_allowed_to_edit(true,true)) {
  554. $user_id = api_get_user_id();
  555. }
  556. $category = Category :: load($category); //hack replace $category = Category :: load ($_GET['cat_id']); to get de course name in certificates
  557. if ($category[0]->is_certificate_available($user_id)) {
  558. $user= get_user_info_from_id($user_id);
  559. $scoredisplay = ScoreDisplay :: instance();
  560. $scorecourse = $category[0]->calc_score($user_id);
  561. $scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
  562. $cattotal = Category :: load($_GET['cat_id']);
  563. $scoretotal= $cattotal[0]->calc_score($user_id);
  564. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal,SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  565. global $charset;
  566. //prepare all necessary variables:
  567. $organization_name = api_get_setting('Institution');
  568. $portal_name = api_get_setting('siteName');
  569. $stud_fn = $user['firstname'];
  570. $stud_ln = $user['lastname'];
  571. $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'),$organization_name,$stud_fn.' '.$stud_ln,$category[0]->get_name(),$scorecourse_display);
  572. $certif_text = str_replace("\\n","\n",$certif_text);
  573. $date = date('d/m/Y',time());
  574. $path_info= UserManager::get_user_picture_path_by_id($user_id,'system',true);
  575. $path_directory_user_certificate=$path_info['dir'].'certificate/';
  576. if (!is_dir($path_info['dir'])) {
  577. mkdir($path_info['dir'],0777);
  578. }
  579. if (!is_dir($path_directory_user_certificate)) {
  580. mkdir($path_directory_user_certificate,0777);
  581. }
  582. if (is_dir($path_directory_user_certificate)) {
  583. $user_id = api_get_user_id();
  584. $cat_id = intval($_GET['cat_id']);
  585. $name=md5($user_id.$cat_id);
  586. //generate document HTML
  587. $course_id = api_get_course_id();
  588. $content_html = DocumentManager::replace_user_info_into_html($course_id);
  589. $new_content=explode('</head>',$content_html);
  590. if ($new_content[0]!='') {
  591. $new_content_html=$new_content[1];
  592. $my_path_certificate=$path_directory_user_certificate.$name.'.html';
  593. $path_image=api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/images/gallery';
  594. $new_content_html=str_replace('../images/gallery',$path_image,$new_content_html);
  595. $path_image_in_default_course=api_get_path(WEB_CODE_PATH).'default_course_document';
  596. $new_content_html=str_replace('/main/default_course_document',$path_image_in_default_course,$new_content_html);
  597. $new_content_html = str_replace('/main/img/', api_get_path(WEB_IMG_PATH), $new_content_html);
  598. //add print header
  599. $print= '
  600. <style media="print" type="text/css">
  601. #imprimir {
  602. visibility:hidden;
  603. }
  604. </style>';
  605. $print ='<a href="javascript:window.print();" style="float:right; padding:4px;" id="imprimir"><img src="'.api_get_path(WEB_CODE_PATH).'img/printmgr.gif" alt="' . get_lang('Print') . '" /> ' . get_lang('Print') . '</a>';
  606. //add header
  607. $new_content_html=$new_content[0].$print.'</head>'.$new_content_html;
  608. if ($cat_id=strval(intval($cat_id))) {
  609. if (UserManager::is_user_certified($cat_id,$user_id)===true){
  610. header('Content-Type: text/html; charset='. $charset);
  611. echo $new_content_html;
  612. exit;
  613. } else {
  614. $my_new_content_html=$new_content_html;
  615. $my_new_content_html=mb_convert_encoding($my_new_content_html,'UTF-8',$charset);
  616. file_put_contents($my_path_certificate,$my_new_content_html);
  617. header('Content-Type: text/html; charset='. $charset);
  618. echo $new_content_html;
  619. }
  620. $path_certificate='/'.$name.'.html';
  621. update_user_info_about_certificate($cat_id,$user_id,$path_certificate);
  622. exit;
  623. }
  624. } else {
  625. Display :: display_reduced_header();
  626. Display :: display_warning_message(get_lang('NoCertificateAvailable'));
  627. }
  628. }
  629. /*$pdf= new Cezpdf('a4','landscape');
  630. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  631. $pdf->ezSetMargins(30, 30, 50, 50);
  632. //line Y coordinates in landscape mode are upside down (500 is on top, 10 is on the bottom)
  633. $pdf->line(50,50,790,50);
  634. $pdf->line(50,550,790,550);
  635. $pdf->ezSetY(450);
  636. $pdf->ezImage(api_get_path(SYS_CODE_PATH).'img/dokeos_logo_certif.png',1,400,'','center','');
  637. $pdf->ezSetY(480);
  638. $pdf->ezText($certif_text,28,array('justification'=>'center'));
  639. //$pdf->ezSetY(750);
  640. $pdf->ezSetY(50);
  641. $pdf->ezText($date,18,array('justification'=>'center'));
  642. $pdf->ezSetY(580);
  643. $pdf->ezText($organization_name,22,array('justification'=>'left'));
  644. $pdf->ezSetY(580);
  645. $pdf->ezText($portal_name,22,array('justification'=>'right'));
  646. $pdf->ezStream();*/
  647. }
  648. exit;
  649. } else { //in any other case (no search, no pdf), print the available gradebooks
  650. // Important note: loading a category will actually load the *contents* of
  651. // this category. This means that, to show the categories of a course,
  652. // we have to show the root category and show its subcategories that
  653. // are inside this course. This is done at the time of calling
  654. // $cats[0]->get_subcategories(), not at the time of doing Category::load()
  655. // $category comes from GET['selectcat']
  656. $course_code = api_get_course_id();
  657. $session_id = api_get_session_id();
  658. //if $category = 0 (which happens when GET['selectcat'] is undefined)
  659. // then Category::load() will create a new 'root' category with empty
  660. // course and session fields in memory (Category::create_root_category())
  661. if ($_in_course === true) {
  662. // When *inside* a course, we want to make sure there is one (and only
  663. // one) category for this course or for this session.
  664. //hack for delete a gradebook from inside course
  665. $clean_deletecat=Security::remove_XSS($_GET['deletecat']);
  666. if (!empty($clean_deletecat))
  667. {
  668. exit;
  669. }
  670. //end hack
  671. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  672. if (empty($cats)) {
  673. // There is no category for this course+session, so create one
  674. $cat= new Category();
  675. $course_code = api_get_course_id();
  676. $session_id = api_get_session_id();
  677. if (!empty($session_id)) {
  678. $my_session_id=api_get_session_id();
  679. $s_name = api_get_session_name($my_session_id);
  680. $cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name);
  681. $cat->set_session_id($session_id);
  682. } else {
  683. $cat->set_name($course_code);
  684. }
  685. $cat->set_course_code($course_code);
  686. $cat->set_description(null);
  687. $cat->set_user_id(api_get_user_id());
  688. $cat->set_parent_id(0);
  689. $cat->set_weight(100);
  690. $cat->set_visible(0);
  691. $can_edit = api_is_allowed_to_edit(true, true);
  692. if ($can_edit) {
  693. $cat->add();
  694. }
  695. unset ($cat);
  696. }
  697. unset($cats);
  698. }
  699. $cats = Category :: load ($category, null, null, null, null, null, false);
  700. //with this fix the teacher only can view 1 gradebook
  701. //$stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  702. if (api_is_platform_admin()) {
  703. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  704. } else {
  705. $stud_id= api_get_user_id();
  706. }
  707. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  708. $alleval= $cats[0]->get_evaluations($stud_id);
  709. $alllink= $cats[0]->get_links($stud_id);
  710. //whether we found a category or not, we now have a category object with
  711. // empty or full subcats
  712. }
  713. // add params to the future links (in the table shown)
  714. $addparams = array ('selectcat' => $cats[0]->get_id());
  715. /*
  716. if (isset($_GET['search'])) {
  717. $addparams['search'] = $keyword;
  718. }
  719. */
  720. if (isset ($_GET['studentoverview'])) {
  721. $addparams['studentoverview'] = '';
  722. }
  723. //$addparams['cidReq']='';
  724. if (isset($_GET['cidReq']) && $_GET['cidReq']!='') {
  725. $addparams['cidReq']=Security::remove_XSS($_GET['cidReq']);
  726. } else {
  727. $addparams['cidReq']='';
  728. }
  729. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  730. $no_qualification = false;
  731. if (( count($allcat) == 0) && ( count($alleval) == 0 ) && ( count($alllink) == 0 )) {
  732. $no_qualification = true;
  733. if ((($is_course_admin) && (!isset ($_GET['selectcat']))) && api_is_course_tutor()) {
  734. 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);
  735. }
  736. }
  737. //here we are in a sub category
  738. if ($category != '0') {
  739. $cat=new Category();
  740. //$dblib=new Database();
  741. $category_id = intval($_GET['selectcat']);
  742. $course_id=Database::get_course_by_category($category_id);
  743. $show_message=$cat->show_message_resource_delete($course_id);
  744. if ($show_message=='') {
  745. //hack for inside courses menu cat
  746. if (api_is_allowed_to_edit()) {
  747. $op_cat_weight= '<strong>'.get_lang('Weight').'</strong>'.': '.((intval($cats[0]->get_weight())>0) ? $cats[0]->get_weight() : 0);
  748. $opt_cat_cert_min= '<strong>'.get_lang('CertificateMinScore').'</strong>'.': '.(intval($cats[0]->get_certificate_min_score()>0) ? $cats[0]->get_certificate_min_score() : 0);
  749. $opt_cat_descrip= '<strong>'.get_lang('GradebookDescriptionLog').'</strong>'.': '.(($cats[0]->get_description() == "" || is_null($cats[0]->get_description())) ? get_lang('None') : $cats[0]->get_description());
  750. $visibility_icon= ($cats[0]->is_visible() == 0) ? 'invisible' : 'visible';
  751. $visibility_command= ($cats[0]->is_visible() == 0) ? 'set_visible' : 'set_invisible';
  752. echo '<div class="actions" align="right">';
  753. $modify_icons= '<a href="gradebook_edit_cat.php?editcat=' . $cats[0]->get_id() . ' &amp;cidReq='.$cats[0]->get_course_code().'"><img src="../img/edit.gif" border="0" title="' . get_lang('EditCategory') . '" alt="'.get_lang('EditCategory').'" />'.get_lang('EditCategory').'</a>';
  754. $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?deletecat=' . $cats[0]->get_id() . '&amp;selectcat=0&amp;cidReq='.$cats[0]->get_course_code().'" onclick="return confirmation();"><img src="../img/delete.gif" border="0" title="' . get_lang('DeleteAll') . '" alt="'.get_lang('DeleteAll').'" />'.get_lang('DeleteAll').'</a>';
  755. $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?visiblecat=' . $cats[0]->get_id() . '&amp;' . $visibility_command . '=&amp;selectcat=0 "><img src="../img/' . $visibility_icon . '.gif" border="0" title="' . get_lang('Visible') . '" alt="'.get_lang('Visible').'" />'.get_lang('Visible').'</a>';
  756. $opt_cat_descrip1 = strip_tags($opt_cat_descrip);
  757. echo '<div align="left" style="float:left"><img src="../img/info3.gif" border="0" title="' . $opt_cat_descrip1 . '" alt="'.$opt_cat_descrip1.'" /> '.$op_cat_weight.' '.'&nbsp;&nbsp;'.$opt_cat_cert_min.'&nbsp;&nbsp;'.$opt_cat_descrip.'</div>';
  758. echo $modify_icons;
  759. echo '</div>';
  760. } else {
  761. // generating the total score for a course
  762. $stud_id= api_get_user_id();
  763. $cats_course = Category :: load ($category_id, null, null, null, null, null, false);
  764. $alleval_course= $cats_course[0]->get_evaluations($stud_id,true);
  765. $alllink_course= $cats_course[0]->get_links($stud_id,true);
  766. $evals_links = array_merge($alleval_course, $alllink_course);
  767. $item_value=0;
  768. $item_total=0;
  769. for ($count=0; $count < count($evals_links); $count++) {
  770. $item = $evals_links[$count];
  771. $score = $item->calc_score($stud_id);
  772. $score_denom=($score[1]==0) ? 1 : $score[1];
  773. $item_value+=$score[0]/$score_denom*$item->get_weight();
  774. $item_total+=$item->get_weight();
  775. }
  776. $item_value = number_format($item_value, 2, '.', ' ');
  777. $cattotal = Category :: load($category_id);
  778. $scoretotal= $cattotal[0]->calc_score(api_get_user_id());
  779. $scoretotal_display = (isset($scoretotal)? round($scoretotal[0],2).'/'.round($scoretotal[1],2).' ('.round(($scoretotal[0] / $scoretotal[1]) * 100,2) . ' %)': '-');
  780. $my_score_in_gradebook = round($scoretotal[0],2);
  781. //show certificate
  782. $certificate_min_score=$cats[0]->get_certificate_min_score();
  783. if (isset($certificate_min_score) && (int)$item_value >= (int)$certificate_min_score) {
  784. $certificates = '<a href="'.api_get_path(WEB_CODE_PATH) .'gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']).'?export_certificate=yes&cat_id='.$cats[0]->get_id().'"><img src="'.api_get_path(WEB_CODE_PATH) . 'img/dokeos.gif" />'.get_lang('Certificates').'</a>&nbsp;'.get_lang('langTotal').': '.$scoretotal_display;
  785. echo '<div class="actions" align="right">';
  786. echo $certificates;
  787. echo '</div>';
  788. }
  789. } //end hack
  790. DisplayGradebook :: display_header_gradebook($cats[0], 0, $category_id, $is_course_admin, $is_platform_admin, $simple_search_form, false, true);
  791. }
  792. } else {
  793. //this is the root category
  794. //DisplayGradebook :: display_header_gradebook($cats[0], 0, 0, $is_course_admin, $is_platform_admin, $simple_search_form, false, false);
  795. }
  796. if (api_is_allowed_to_edit(null, true)) {
  797. /*
  798. -----------------------------------------------------------
  799. Introduction section (teacher edit)
  800. -----------------------------------------------------------
  801. */
  802. // Tool introduction
  803. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  804. if ( (isset ($_GET['selectcat']) && $_GET['selectcat']<>0) ) {
  805. //
  806. } else {
  807. if ( ((isset ($_GET['selectcat']) && $_GET['selectcat']==0) || ((isset($_GET['cidReq']) && $_GET['cidReq']!==''))) || isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') {
  808. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  809. if(!$first_time=1) {
  810. DisplayGradebook :: display_reduce_header_gradebook($cats[0],$is_course_admin, $is_platform_admin, $simple_search_form, false, false);
  811. }
  812. }
  813. }
  814. }
  815. if($first_time==1 && api_is_allowed_to_edit(null,true))
  816. {
  817. echo '<meta http-equiv="refresh" content="0;url='.api_get_self().'?cidReq='.$course_code.'" />';
  818. } else {
  819. $gradebooktable->display();
  820. }
  821. Display :: display_footer();