gradebook_edit_link.php 4.5 KB

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