index.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  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 type="text/javascript">
  32. $(document).ready( function() {
  33. for (i=0;i<$(".actions").length;i++) {
  34. 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) {
  35. $(".actions:eq("+i+")").hide();
  36. }
  37. }
  38. } );
  39. </script>';
  40. api_block_anonymous_users();
  41. $htmlHeadXtra[]= '<script type="text/javascript">
  42. function confirmation ()
  43. {
  44. if (confirm("' . get_lang('DeleteAll') . '?"))
  45. {return true;}
  46. else
  47. {return false;}
  48. }
  49. </script>';
  50. $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
  51. $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
  52. $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  53. $status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
  54. $filter_confirm_msg = true;
  55. $filter_warning_msg = true;
  56. $session_id = api_get_session_id();
  57. ///direct access to one evaluation
  58. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
  59. if (empty($cats))
  60. {
  61. $cats = Category :: load(0, null, $course_code, null, null, $session_id, false);//first time
  62. $first_time=1;
  63. }
  64. $_GET['selectcat'] = $cats[0]->get_id();
  65. if (isset($_GET['isStudentView'])) {
  66. if ( (isset($_GET['selectcat']) && $_GET['selectcat']>0) && (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) {
  67. $interbreadcrumb[]= array (
  68. 'url' => 'index.php'.'?selectcat=0&amp;isStudentView='.$_GET['isStudentView'],
  69. 'name' => get_lang('ToolGradebook')
  70. );
  71. }
  72. }
  73. if ( (isset($_GET['selectcat']) && $_GET['selectcat']>0) && (isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) {
  74. Display :: display_header();
  75. //Introduction tool: student view
  76. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  77. $category= $_GET['selectcat'];
  78. $stud_id=api_get_user_id();
  79. $course_code=api_get_course_id();
  80. $session_id=api_get_session_id();
  81. $cats = Category :: load ($category, null, null, null, null, null, false);
  82. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  83. $alleval= $cats[0]->get_evaluations($stud_id);
  84. $alllink= $cats[0]->get_links($stud_id);
  85. $addparams=array();
  86. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  87. $gradebooktable->display();
  88. Display :: display_footer();
  89. exit;
  90. } else {
  91. if ( !isset($_GET['selectcat']) && ($_SESSION['studentview']=='studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='true') ) {
  92. // 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()) ) {
  93. Display :: display_header(get_lang('Gradebook'));
  94. //Introduction tool: student view
  95. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  96. $stud_id=api_get_user_id();
  97. $course_code=api_get_course_id();
  98. $session_id=api_get_session_id();
  99. $addparams=array();
  100. $cats = Category :: load (0, null, null, null, null, null, false);
  101. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  102. $alleval= $cats[0]->get_evaluations($stud_id);
  103. $alllink= $cats[0]->get_links($stud_id);
  104. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  105. $gradebooktable->display();
  106. Display :: display_footer();
  107. exit;
  108. }
  109. }
  110. // ACTIONS
  111. //this is called when there is no data for the course admin
  112. if (isset ($_GET['createallcategories'])) {
  113. block_students();
  114. $coursecat= Category :: get_not_created_course_categories(api_get_user_id());
  115. if (!count($coursecat) == 0) {
  116. foreach ($coursecat as $row) {
  117. $cat= new Category();
  118. $cat->set_name($row[1]);
  119. $cat->set_course_code($row[0]);
  120. $cat->set_description(null);
  121. $cat->set_user_id(api_get_user_id());
  122. $cat->set_parent_id(0);
  123. $cat->set_weight(0);
  124. $cat->set_visible(0);
  125. $cat->add();
  126. unset ($cat);
  127. }
  128. }
  129. header('Location: '.$_SESSION['gradebook_dest'].'?addallcat=&selectcat=0');
  130. exit;
  131. }
  132. //show logs evaluations
  133. if (isset ($_GET['visiblelog'])) {
  134. header('Location: ' . api_get_self().'/gradebook_showlog_eval.php');
  135. exit;
  136. }
  137. //move a category
  138. if (isset ($_GET['movecat'])) {
  139. block_students();
  140. $cats= Category :: load($_GET['movecat']);
  141. if (!isset ($_GET['targetcat'])) {
  142. $move_form= new CatForm(CatForm :: TYPE_MOVE,
  143. $cats[0],
  144. 'move_cat_form',
  145. null,
  146. api_get_self() . '?movecat=' . Security::remove_XSS($_GET['movecat'])
  147. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  148. if ($move_form->validate()) {
  149. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  150. . '&movecat=' . Security::remove_XSS($_GET['movecat'])
  151. . '&targetcat=' . $move_form->exportValue('move_cat'));
  152. exit;
  153. }
  154. } else {
  155. $targetcat= Category :: load($_GET['targetcat']);
  156. $course_to_crsind = ($cats[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  157. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  158. $cats[0]->move_to_cat($targetcat[0]);
  159. header('Location: ' . api_get_self() . '?categorymoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  160. exit;
  161. }
  162. unset ($targetcat);
  163. }
  164. unset ($cats);
  165. }
  166. //move an evaluation
  167. if (isset ($_GET['moveeval'])) {
  168. block_students();
  169. $evals= Evaluation :: load($_GET['moveeval']);
  170. if (!isset ($_GET['targetcat'])) {
  171. $move_form= new EvalForm(EvalForm :: TYPE_MOVE,
  172. $evals[0],
  173. null,
  174. 'move_eval_form',
  175. null,
  176. api_get_self() . '?moveeval=' . Security::remove_XSS($_GET['moveeval'])
  177. . '&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  178. if ($move_form->validate()) {
  179. header('Location: ' .api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  180. . '&moveeval=' . Security::remove_XSS($_GET['moveeval'])
  181. . '&targetcat=' . $move_form->exportValue('move_cat'));
  182. exit;
  183. }
  184. } else {
  185. $targetcat= Category :: load($_GET['targetcat']);
  186. $course_to_crsind = ($evals[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null);
  187. if (!($course_to_crsind && !isset($_GET['confirm']))) {
  188. $evals[0]->move_to_cat($targetcat[0]);
  189. header('Location: ' . api_get_self() . '?evaluationmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  190. exit;
  191. }
  192. unset ($targetcat);
  193. }
  194. unset ($evals);
  195. }
  196. //move a link
  197. if (isset ($_GET['movelink'])) {
  198. block_students();
  199. $link= LinkFactory :: load($_GET['movelink']);
  200. $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']));
  201. if ($move_form->validate()) {
  202. $targetcat= Category :: load($move_form->exportValue('move_cat'));
  203. $link[0]->move_to_cat($targetcat[0]);
  204. unset ($link);
  205. header('Location: ' . api_get_self(). '?linkmoved=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  206. exit;
  207. }
  208. }
  209. //parameters for categories
  210. if (isset ($_GET['visiblecat'])) {
  211. block_students();
  212. if (isset ($_GET['set_visible'])) {
  213. $visibility_command= 1;
  214. } else {
  215. $visibility_command= 0;
  216. }
  217. $cats= Category :: load($_GET['visiblecat']);
  218. $cats[0]->set_visible($visibility_command);
  219. $cats[0]->save();
  220. $cats[0]->apply_visibility_to_children();
  221. unset ($cats);
  222. if ($visibility_command) {
  223. $confirmation_message = get_lang('ViMod');
  224. $filter_confirm_msg = false;
  225. } else {
  226. $confirmation_message = get_lang('InViMod');
  227. $filter_confirm_msg = false;
  228. }
  229. }
  230. if (isset ($_GET['deletecat'])) {
  231. block_students();
  232. $cats= Category :: load($_GET['deletecat']);
  233. //delete all categories,subcategories and results
  234. if ($cats[0] != null) {
  235. if ($cats[0]->get_id() != 0) {
  236. // better don't try to delete the root...
  237. $cats[0]->delete_all();
  238. }
  239. }
  240. $confirmation_message = get_lang('CategoryDeleted');
  241. $filter_confirm_msg = false;
  242. }
  243. //parameters for evaluations
  244. if (isset ($_GET['visibleeval'])) {
  245. block_students();
  246. if (isset ($_GET['set_visible'])) {
  247. $visibility_command= 1;
  248. } else {
  249. $visibility_command= 0;
  250. }
  251. $eval= Evaluation :: load($_GET['visibleeval']);
  252. $eval[0]->set_visible($visibility_command);
  253. $eval[0]->save();
  254. unset ($eval);
  255. if ($visibility_command) {
  256. $confirmation_message = get_lang('ViMod');
  257. $filter_confirm_msg = false;
  258. } else {
  259. $confirmation_message = get_lang('InViMod');
  260. $filter_confirm_msg = false;
  261. }
  262. }
  263. //parameters for evaluations
  264. if (isset($_GET['lockedeval'])) {
  265. block_students();
  266. $locked = Security::remove_XSS($_GET['lockedeval']);
  267. if (isset($_GET['typelocked']) && api_is_platform_admin()){
  268. $type_locked = 0;
  269. $confirmation_message = get_lang('EvaluationHasBeenUnLocked');
  270. } else {
  271. $type_locked = 1;
  272. $confirmation_message = get_lang('EvaluationHasBeenLocked');
  273. }
  274. $eval= Evaluation :: load($locked);
  275. if ($eval[0] != null) {
  276. $eval[0]->locked_evaluation($locked, $type_locked);
  277. }
  278. $filter_confirm_msg = false;
  279. }
  280. if (isset ($_GET['deleteeval'])) {
  281. block_students();
  282. $eval= Evaluation :: load($_GET['deleteeval']);
  283. if ($eval[0] != null) {
  284. $eval[0]->delete_with_results();
  285. }
  286. $confirmation_message = get_lang('GradebookEvaluationDeleted');
  287. $filter_confirm_msg = false;
  288. }
  289. //parameters for links
  290. if (isset ($_GET['visiblelink'])) {
  291. block_students();
  292. if (isset ($_GET['set_visible'])) {
  293. $visibility_command= 1;
  294. } else {
  295. $visibility_command= 0;
  296. }
  297. $link= LinkFactory :: load($_GET['visiblelink']);
  298. $link[0]->set_visible($visibility_command);
  299. $link[0]->save();
  300. unset ($link);
  301. if ($visibility_command) {
  302. $confirmation_message = get_lang('ViMod');
  303. $filter_confirm_msg = false;
  304. } else {
  305. $confirmation_message = get_lang('InViMod');
  306. $filter_confirm_msg = false;
  307. }
  308. }
  309. if (isset ($_GET['deletelink'])) {
  310. block_students();
  311. $get_delete_link=Security::remove_XSS($_GET['deletelink']);
  312. //fixing #5229
  313. if (!empty($get_delete_link)) {
  314. $link= LinkFactory :: load($get_delete_link);
  315. if ($link[0] != null) {
  316. // clean forum qualify
  317. $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.');';
  318. Database::query($sql);
  319. // clean attendance
  320. $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.');';
  321. Database::query($sql);
  322. $link[0]->delete();
  323. }
  324. unset ($link);
  325. $confirmation_message = get_lang('LinkDeleted');
  326. $filter_confirm_msg = false;
  327. }
  328. }
  329. if (!empty($course_to_crsind) && !isset($_GET['confirm'])) {
  330. block_students();
  331. if (!isset($_GET['movecat']) && !isset($_GET['moveeval'])) {
  332. die ('Error: movecat or moveeval not defined');
  333. }
  334. $button = '<form name="confirm"
  335. method="post"
  336. action="'.api_get_self() .'?confirm='
  337. .(isset($_GET['movecat']) ? '&movecat=' . Security::remove_XSS($_GET['movecat'])
  338. : '&moveeval=' . Security::remove_XSS($_GET['moveeval']) )
  339. .'&selectcat=' . Security::remove_XSS($_GET['selectcat'])
  340. .'&targetcat=' . Security::remove_XSS($_GET['targetcat']).'">
  341. <input type="submit" value="'.get_lang('Ok').'">
  342. </form>';
  343. $warning_message = get_lang('MoveWarning').'<br><br>'.$button;
  344. $filter_warning_msg = false;
  345. }
  346. //actions on the sortabletable
  347. if (isset ($_POST['action'])) {
  348. block_students();
  349. $number_of_selected_items= count($_POST['id']);
  350. if ($number_of_selected_items == '0') {
  351. $warning_message = get_lang('NoItemsSelected');
  352. $filter_warning_msg = false;
  353. } else {
  354. switch ($_POST['action']) {
  355. case 'deleted' :
  356. $number_of_deleted_categories= 0;
  357. $number_of_deleted_evaluations= 0;
  358. $number_of_deleted_links= 0;
  359. foreach ($_POST['id'] as $indexstr) {
  360. if (substr($indexstr, 0, 4) == 'CATE') {
  361. $cats= Category :: load(substr($indexstr, 4));
  362. if ($cats[0] != null) {
  363. $cats[0]->delete_all();
  364. }
  365. $number_of_deleted_categories++;
  366. }
  367. if (substr($indexstr, 0, 4) == 'EVAL') {
  368. $eval= Evaluation :: load(substr($indexstr, 4));
  369. if ($eval[0] != null) {
  370. $eval[0]->delete_with_results();
  371. }
  372. $number_of_deleted_evaluations++;
  373. }
  374. if (substr($indexstr, 0, 4) == 'LINK') {
  375. //fixing #5229
  376. $id = substr($indexstr, 4);
  377. if (!empty($id)) {
  378. $link= LinkFactory :: load($id);
  379. if ($link[0] != null) {
  380. $link[0]->delete();
  381. }
  382. $number_of_deleted_links++;
  383. }
  384. }
  385. }
  386. $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>';
  387. $filter_confirm_msg = false;
  388. break;
  389. case 'setvisible' :
  390. foreach ($_POST['id'] as $indexstr) {
  391. if (substr($indexstr, 0, 4) == 'CATE') {
  392. $cats= Category :: load(substr($indexstr, 4));
  393. $cats[0]->set_visible(1);
  394. $cats[0]->save();
  395. $cats[0]->apply_visibility_to_children();
  396. }
  397. if (substr($indexstr, 0, 4) == 'EVAL') {
  398. $eval= Evaluation :: load(substr($indexstr, 4));
  399. $eval[0]->set_visible(1);
  400. $eval[0]->save();
  401. }
  402. if (substr($indexstr, 0, 4) == 'LINK') {
  403. $link= LinkFactory :: load(substr($indexstr, 4));
  404. $link[0]->set_visible(1);
  405. $link[0]->save();
  406. }
  407. }
  408. $confirmation_message = get_lang('ItemsVisible');
  409. $filter_confirm_msg = false;
  410. break;
  411. case 'setinvisible' :
  412. foreach ($_POST['id'] as $indexstr) {
  413. if (substr($indexstr, 0, 4) == 'CATE') {
  414. $cats= Category :: load(substr($indexstr, 4));
  415. $cats[0]->set_visible(0);
  416. $cats[0]->save();
  417. $cats[0]->apply_visibility_to_children();
  418. }
  419. if (substr($indexstr, 0, 4) == 'EVAL') {
  420. $eval= Evaluation :: load(substr($indexstr, 4));
  421. $eval[0]->set_visible(0);
  422. $eval[0]->save();
  423. }
  424. if (substr($indexstr, 0, 4) == 'LINK') {
  425. $link= LinkFactory :: load(substr($indexstr, 4));
  426. $link[0]->set_visible(0);
  427. $link[0]->save();
  428. }
  429. }
  430. $confirmation_message = get_lang('ItemsInVisible');
  431. $filter_confirm_msg = false;
  432. break;
  433. }
  434. }
  435. }
  436. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  437. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  438. . '&search='.Security::remove_XSS($_POST['keyword']));
  439. exit;
  440. }
  441. // DISPLAY HEADERS AND MESSAGES
  442. if (!isset($_GET['exportpdf']) and !isset($_GET['export_certificate'])) {
  443. if (isset ($_GET['studentoverview'])) {
  444. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('ToolGradebook'));
  445. Display :: display_header(get_lang('FlatView'));
  446. } elseif (isset ($_GET['search'])) {
  447. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('ToolGradebook'));
  448. Display :: display_header(get_lang('SearchResults'));
  449. } elseif(isset ($_GET['selectcat'])) {
  450. $interbreadcrumb[]= array ( 'url' => $_SESSION['gradebook_dest'],'name' => get_lang('ToolGradebook'));
  451. if (!isset($_GET['gradebooklist_direction'])) {
  452. $interbreadcrumb[]= array ('url' => $_SESSION['gradebook_dest'].'?selectcat=' . Security::remove_XSS($_GET['selectcat']),'name' => get_lang('Details'));
  453. }
  454. Display :: display_header('');
  455. } else {
  456. Display :: display_header(get_lang('ToolGradebook'));
  457. /*if ( ($_SESSION['studentview']=='studentview') || (isset($_GET['isStudentView']) && $_GET['isStudentView']=='true') ) {
  458. $cats = Category :: load (0, null, null, null, null, null, false);
  459. $allcat= $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
  460. $alleval= $cats[0]->get_evaluations($stud_id);
  461. $alllink= $cats[0]->get_links($stud_id);
  462. $gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
  463. $gradebooktable->display();
  464. Display :: display_footer();
  465. exit;
  466. }*/
  467. }
  468. }
  469. if (isset ($_GET['categorymoved'])) {
  470. Display :: display_confirmation_message(get_lang('CategoryMoved'),false);
  471. }
  472. if (isset ($_GET['evaluationmoved'])) {
  473. Display :: display_confirmation_message(get_lang('EvaluationMoved'),false);
  474. }
  475. if (isset ($_GET['linkmoved'])) {
  476. Display :: display_confirmation_message(get_lang('LinkMoved'),false);
  477. }
  478. if (isset ($_GET['addcat'])) {
  479. Display :: display_confirmation_message(get_lang('CategoryAdded'),false);
  480. }
  481. if (isset ($_GET['linkadded'])) {
  482. Display :: display_confirmation_message(get_lang('LinkAdded'),false);
  483. }
  484. if (isset ($_GET['addresult'])) {
  485. Display :: display_confirmation_message(get_lang('ResultAdded'),false);
  486. }
  487. if (isset ($_GET['editcat'])) {
  488. Display :: display_confirmation_message(get_lang('CategoryEdited'),false);
  489. }
  490. if (isset ($_GET['editeval'])) {
  491. Display :: display_confirmation_message(get_lang('EvaluationEdited'),false);
  492. }
  493. if (isset ($_GET['linkedited'])) {
  494. Display :: display_confirmation_message(get_lang('LinkEdited'),false);
  495. }
  496. if (isset ($_GET['nolinkitems'])){
  497. Display :: display_warning_message(get_lang('NoLinkItems'),false);
  498. }
  499. if (isset ($_GET['addallcat'])){
  500. Display :: display_normal_message(get_lang('AddAllCat'),false);
  501. }
  502. if (isset ($confirmation_message)){
  503. Display :: display_confirmation_message($confirmation_message,$filter_confirm_msg);
  504. }
  505. if (isset ($warning_message)){
  506. Display :: display_warning_message($warning_message,$filter_warning_msg);
  507. }
  508. if (isset ($move_form)){
  509. Display :: display_normal_message($move_form->toHtml(),false);
  510. }
  511. // LOAD DATA & DISPLAY TABLE
  512. $is_platform_admin = api_is_platform_admin();
  513. $is_course_admin = api_is_allowed_to_create_course();
  514. //load data for category, evaluation and links
  515. if (empty ($_GET['selectcat'])) {
  516. $category= 0;
  517. } else {
  518. $category= $_GET['selectcat'];
  519. }
  520. $simple_search_form='';
  521. // search disabled in course context
  522. /*
  523. $simple_search_form= new UserForm(UserForm :: TYPE_SIMPLE_SEARCH, null, 'simple_search_form', null, api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat']));
  524. $values= $simple_search_form->exportValues();
  525. $keyword = '';
  526. if (isset($_GET['search']) && !empty($_GET['search']))
  527. $keyword = Security::remove_XSS($_GET['search']);
  528. if ($simple_search_form->validate() && (empty($keyword)))
  529. $keyword = $values['keyword'];
  530. */
  531. /* search disabled in course context
  532. if (!empty($keyword))
  533. {
  534. $cats= Category :: load($category);
  535. $allcat= array ();
  536. $alleval= Evaluation :: find_evaluations($keyword, $cats[0]->get_id());
  537. $alllink= LinkFactory :: find_links($keyword, $cats[0]->get_id());
  538. }
  539. else
  540. */
  541. if (isset ($_GET['studentoverview'])) {
  542. //@todo this code also seems to be deprecated ...
  543. $cats= Category :: load($category);
  544. $stud_id= (api_is_allowed_to_create_course() ? null : api_get_user_id());
  545. $allcat= array ();
  546. $alleval= $cats[0]->get_evaluations($stud_id, true);
  547. $alllink= $cats[0]->get_links($stud_id, true);
  548. if (isset ($_GET['exportpdf'])) {
  549. $datagen = new GradebookDataGenerator ($allcat,$alleval, $alllink);
  550. $header_names = array(get_lang('Name'),get_lang('Description'),get_lang('Weight'),get_lang('Date'),get_lang('Results'));
  551. $data_array = $datagen->get_data(GradebookDataGenerator :: GDG_SORT_NAME,0,null,true);
  552. $newarray = array();
  553. foreach ($data_array as $data) {
  554. $newarray[] = array_slice($data, 1);
  555. }
  556. $pdf= new Cezpdf();
  557. $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
  558. $pdf->ezSetMargins(30, 30, 50, 30);
  559. $pdf->ezSetY(810);
  560. $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'));
  561. $pdf->line(50,790,550,790);
  562. $pdf->line(50,40,550,40);
  563. $pdf->ezSetY(750);
  564. $pdf->ezTable($newarray,$header_names,'',array('showHeadings'=>1,'shaded'=>1,'showLines'=>1,'rowGap'=>3,'width'=> 500));
  565. $pdf->ezStream();
  566. exit;
  567. }
  568. } elseif (!empty($_GET['export_certificate'])) {
  569. $user_id = strval(intval($_GET['user']));
  570. if (!api_is_allowed_to_edit(true,true)) {
  571. $user_id = api_get_user_id();
  572. }
  573. $category = Category :: load($category); //hack replace $category = Category :: load ($_GET['cat_id']); to get de course name in certificates
  574. if ($category[0]->is_certificate_available($user_id)) {
  575. $user= get_user_info_from_id($user_id);
  576. $scoredisplay = ScoreDisplay :: instance();
  577. $scorecourse = $category[0]->calc_score($user_id);
  578. $scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable'));
  579. $cattotal = Category :: load($_GET['cat_id']);
  580. $scoretotal= $cattotal[0]->calc_score($user_id);
  581. $scoretotal_display = (isset($scoretotal) ? $scoredisplay->display_score($scoretotal,SCORE_PERCENT) : get_lang('NoResultsAvailable'));
  582. global $charset;
  583. //prepare all necessary variables:
  584. $organization_name = api_get_setting('Institution');
  585. $portal_name = api_get_setting('siteName');
  586. $stud_fn = $user['firstname'];
  587. $stud_ln = $user['lastname'];
  588. $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'),$organization_name,$stud_fn.' '.$stud_ln,$category[0]->get_name(),$scorecourse_display);
  589. $certif_text = str_replace("\\n","\n",$certif_text);
  590. $date = date('d/m/Y',time());
  591. $path_info= UserManager::get_user_picture_path_by_id($user_id,'system',true);
  592. $path_directory_user_certificate=$path_info['dir'].'certificate/';
  593. if (!is_dir($path_info['dir'])) {
  594. mkdir($path_info['dir'],0777);
  595. }
  596. if (!is_dir($path_directory_user_certificate)) {
  597. mkdir($path_directory_user_certificate,0777);
  598. }
  599. if (is_dir($path_directory_user_certificate)) {
  600. $user_id = api_get_user_id();
  601. $cat_id = intval($_GET['cat_id']);
  602. $name=md5($user_id.$cat_id);
  603. //generate document HTML
  604. $course_id = api_get_course_id();
  605. $content_html = DocumentManager::replace_user_info_into_html($course_id);
  606. $new_content=explode('</head>',$content_html);
  607. if ($new_content[0]!='') {
  608. $new_content_html=$new_content[1];
  609. $my_path_certificate=$path_directory_user_certificate.$name.'.html';
  610. $path_image=api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/images/gallery';
  611. $new_content_html=str_replace('../images/gallery',$path_image,$new_content_html);
  612. $path_image_in_default_course=api_get_path(WEB_CODE_PATH).'default_course_document';
  613. $new_content_html=str_replace('/main/default_course_document',$path_image_in_default_course,$new_content_html);
  614. $new_content_html = str_replace('/main/img/', api_get_path(WEB_IMG_PATH), $new_content_html);
  615. //add print header
  616. $print= '
  617. <style media="print" type="text/css">
  618. #imprimir {
  619. visibility:hidden;
  620. }
  621. </style>';
  622. $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>';
  623. //add header
  624. $new_content_html=$new_content[0].$print.'</head>'.$new_content_html;
  625. if ($cat_id=strval(intval($cat_id))) {
  626. if (UserManager::is_user_certified($cat_id,$user_id)===true){
  627. header('Content-Type: text/html; charset='. $charset);
  628. echo $new_content_html;
  629. exit;
  630. } else {
  631. $my_new_content_html=$new_content_html;
  632. $my_new_content_html=mb_convert_encoding($my_new_content_html,'UTF-8',$charset);
  633. file_put_contents($my_path_certificate,$my_new_content_html);
  634. header('Content-Type: text/html; charset='. $charset);
  635. echo $new_content_html;
  636. }
  637. $path_certificate='/'.$name.'.html';
  638. update_user_info_about_certificate($cat_id,$user_id,$path_certificate);
  639. exit;
  640. }
  641. } else {
  642. Display :: display_reduced_header();
  643. Display :: display_warning_message(get_lang('NoCertificateAvailable'));
  644. }
  645. }
  646. }
  647. exit;
  648. } else {
  649. //Student view
  650. //in any other case (no search, no pdf), print the available gradebooks
  651. // Important note: loading a category will actually load the *contents* of
  652. // this category. This means that, to show the categories of a course,
  653. // we have to show the root category and show its subcategories that
  654. // are inside this course. This is done at the time of calling
  655. // $cats[0]->get_subcategories(), not at the time of doing Category::load()
  656. // $category comes from GET['selectcat']
  657. $course_code = api_get_course_id();
  658. $session_id = api_get_session_id();
  659. //if $category = 0 (which happens when GET['selectcat'] is undefined)
  660. // then Category::load() will create a new 'root' category with empty
  661. // course and session fields in memory (Category::create_root_category())
  662. if ($_in_course === true) {
  663. // When *inside* a course, we want to make sure there is one (and only
  664. // one) category for this course or for this session.
  665. //hack for delete a gradebook from inside course
  666. $clean_deletecat=Security::remove_XSS($_GET['deletecat']);
  667. if (!empty($clean_deletecat)) {
  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().'">'.Display::return_icon('edit.png', get_lang('EditCategory'),'','22').'</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();">'.Display::return_icon('delete.png', get_lang('DeleteAll'),'','22').'</a>';
  755. $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?visiblecat=' . $cats[0]->get_id() . '&amp;' . $visibility_command . '=&amp;selectcat=0 ">'.Display::return_icon($visibility_icon.'.png', get_lang('Visible'),'','22').'</a>';
  756. $opt_cat_descrip1 = strip_tags($opt_cat_descrip);
  757. echo '<div align="left" style="float:left">'.Display::return_icon('info.png', $opt_cat_descrip1,'','22').'</a>'.$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. /*
  780. //Overwritten the old total with the real total of the gradebook if the line below is deleted, then when a user doesn't finish a test the total will be different from the real total
  781. $scoretotal[1] = $item_total;
  782. //$scoretotal_display = (isset($scoretotal)? round($scoretotal[0],2).'/'.round($scoretotal[1],2).' ('.round(($scoretotal[0] / $scoretotal[1]) * 100,2) . ' %)': '-');
  783. */
  784. //Do not remove this the gradebook/lib/fe/gradebooktable.class.php file load this variable as a global
  785. $my_score_in_gradebook = round($scoretotal[0],2);
  786. //Show certificate
  787. $certificate_min_score=$cats[0]->get_certificate_min_score();
  788. $scoredisplay = ScoreDisplay :: instance();
  789. $scoretotal_display = $scoredisplay->display_score($scoretotal,SCORE_DIV_PERCENT); //a student always sees only the teacher's repartition
  790. //$score_compare = ($scoretotal[0] / $scoretotal[1]) * 100; //build the total percentage obtained in order to compare it to the minimum certification percentage
  791. if (isset($certificate_min_score) && $item_value >= $certificate_min_score) {
  792. $url = api_get_path(WEB_CODE_PATH) .'gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']).'?export_certificate=yes&cat_id='.$cats[0]->get_id();
  793. //$certificates.= '<img src="'.api_get_path(WEB_CODE_PATH) . 'img/logo.gif" />'.get_lang('Certificates').'</a>&nbsp;<strong>'.get_lang('Total').': '.$scoretotal_display.'</strong>';
  794. $certificates = Display::url(Display::return_icon('certificate.png', get_lang('Certificates'), array(), 48), $url, array('target'=>'_blank'));
  795. echo '<div class="actions" align="right">';
  796. echo $certificates;
  797. echo '</div>';
  798. }
  799. } //end hack
  800. DisplayGradebook::display_header_gradebook($cats[0], 0, $category_id, $is_course_admin, $is_platform_admin, $simple_search_form, false, true);
  801. }
  802. } else {
  803. //this is the root category
  804. //DisplayGradebook :: display_header_gradebook($cats[0], 0, 0, $is_course_admin, $is_platform_admin, $simple_search_form, false, false);
  805. }
  806. if (api_is_allowed_to_edit(null, true)) {
  807. /*
  808. Introduction section (teacher edit)
  809. */
  810. // Tool introduction
  811. Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
  812. if ( (isset ($_GET['selectcat']) && $_GET['selectcat']<>0) ) {
  813. //
  814. } else {
  815. if ( ((isset ($_GET['selectcat']) && $_GET['selectcat']==0) || ((isset($_GET['cidReq']) && $_GET['cidReq']!==''))) || isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') {
  816. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
  817. if(!$first_time=1) {
  818. DisplayGradebook :: display_reduce_header_gradebook($cats[0],$is_course_admin, $is_platform_admin, $simple_search_form, false, false);
  819. }
  820. }
  821. }
  822. }
  823. if($first_time==1 && api_is_allowed_to_edit(null,true)) {
  824. echo '<meta http-equiv="refresh" content="0;url='.api_get_self().'?cidReq='.$course_code.'" />';
  825. } else {
  826. $gradebooktable->display();
  827. }
  828. Display :: display_footer();