gradebook_edit_link.php 4.6 KB

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