index.php 31 KB

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