gradebook_edit_link.php 4.4 KB

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