gradebook_edit_link.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. /**
  8. * Init
  9. */
  10. $language_file = array('gradebook', 'exercice', 'link');
  11. //$cidReset = true;
  12. //require_once '../inc/global.inc.php';
  13. require_once 'lib/be.inc.php';
  14. require_once 'lib/gradebook_functions.inc.php';
  15. require_once 'lib/fe/linkform.class.php';
  16. require_once 'lib/fe/linkaddeditform.class.php';
  17. api_block_anonymous_users();
  18. block_students();
  19. $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  20. //selected name of database
  21. $course_id = get_course_id_by_link_id($_GET['editlink']);
  22. $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
  23. $tbl_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  24. $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
  25. $linkarray = LinkFactory :: load($_GET['editlink']);
  26. $link = $linkarray[0];
  27. if ($link->is_locked() && !api_is_platform_admin()) {
  28. api_not_allowed();
  29. }
  30. $linkcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']):'';
  31. $linkedit = isset($_GET['editlink']) ? Security::remove_XSS($_GET['editlink']):'';
  32. $session_id = api_get_session_id();
  33. if ($session_id == 0) {
  34. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
  35. } else {
  36. $cats = Category :: load_session_categories(null, $session_id);
  37. }
  38. $form = new LinkAddEditForm(LinkAddEditForm :: TYPE_EDIT, $cats, null, $link, 'edit_link_form', api_get_self() . '?selectcat=' . $linkcat. '&editlink=' . $linkedit);
  39. if ($form->validate()) {
  40. $values = $form->exportValues();
  41. $parent_cat = Category :: load($values['select_gradebook']);
  42. $final_weight = null;
  43. /*
  44. if ($parent_cat[0]->get_parent_id() == 0) {
  45. $final_weight = $values['weight_mask'];
  46. } else {
  47. $cat = Category :: load($parent_cat[0]->get_parent_id());
  48. $global_weight = $cat[0]->get_weight();
  49. $final_weight = $values['weight_mask']/$global_weight*$parent_cat[0]->get_weight();
  50. }*/
  51. $final_weight = $values['weight_mask'];
  52. $link->set_weight($final_weight);
  53. if (!empty($values['select_gradebook'])) {
  54. $link->set_category_id($values['select_gradebook']);
  55. }
  56. $link->set_visible(empty ($values['visible']) ? 0 : 1);
  57. $link->save();
  58. //Update weight for attendance
  59. $sql = 'SELECT ref_id FROM '.$tbl_grade_links.' WHERE id = '.intval($_GET['editlink']).' AND type='.LINK_ATTENDANCE;
  60. $rs_attendance = Database::query($sql);
  61. if (Database::num_rows($rs_attendance) > 0) {
  62. $row_attendance = Database::fetch_array($rs_attendance);
  63. $attendance_id = $row_attendance['ref_id'];
  64. $upd_attendance = 'UPDATE '.$tbl_attendance.' SET attendance_weight ='.floatval($final_weight).' WHERE c_id = '.$course_id.' AND id = '.intval($attendance_id);
  65. Database::query($upd_attendance);
  66. }
  67. //Update weight into forum thread
  68. $sql_t = 'UPDATE '.$tbl_forum_thread.' SET thread_weight='.$final_weight.'
  69. WHERE c_id = '.$course_id.' AND thread_id=(SELECT ref_id FROM '.$tbl_grade_links.' WHERE id='.intval($_GET['editlink']).' and type=5) ';
  70. Database::query($sql_t);
  71. //Update weight into student publication(work)
  72. $sql_t = 'UPDATE '.$tbl_work.' SET weight='.$final_weight.'
  73. WHERE c_id = '.$course_id.' AND id = (SELECT ref_id FROM '.$tbl_grade_links.' WHERE id='.intval($_GET['editlink'] ).' AND type=3 )';
  74. Database::query($sql_t);
  75. header('Location: '.$_SESSION['gradebook_dest'].'?linkedited=&selectcat=' . $link->get_category_id());
  76. exit;
  77. }
  78. $interbreadcrumb[] = array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$linkcat,'name' => get_lang('Gradebook'));
  79. $htmlHeadXtra[] = '<script type="text/javascript">
  80. $(document).ready( function() {
  81. $("#hide_category_id").change(function(){
  82. $("#hide_category_id option:selected").each(function () {
  83. var cat_id = $(this).val();
  84. $.ajax({
  85. url: "'.api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight",
  86. data: "cat_id="+cat_id,
  87. success: function(return_value) {
  88. if (return_value != 0 ) {
  89. $("#max_weight").html(return_value);
  90. }
  91. },
  92. });
  93. });
  94. });
  95. });
  96. </script>';
  97. Display :: display_header(get_lang('EditLink'));
  98. $form->display();
  99. Display :: display_footer();