index.php 33 KB

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