gradebook_edit_link.php 4.0 KB

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