gradebook_edit_link.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. //$cidReset = true;
  8. require_once '../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_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
  16. $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
  17. $linkarray = LinkFactory :: load($_GET['editlink']);
  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 = null;
  42. /*
  43. if ($parent_cat[0]->get_parent_id() == 0) {
  44. $final_weight = $values['weight_mask'];
  45. } else {
  46. $cat = Category :: load($parent_cat[0]->get_parent_id());
  47. $global_weight = $cat[0]->get_weight();
  48. $final_weight = $values['weight_mask']/$global_weight*$parent_cat[0]->get_weight();
  49. }*/
  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 ='.floatval($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_t = 'UPDATE '.$tbl_forum_thread.' SET thread_weight='.$final_weight.'
  71. WHERE c_id = '.$course_id.' AND thread_id=(
  72. SELECT ref_id FROM '.$tbl_grade_links.'
  73. WHERE id='.intval($_GET['editlink']).' and type=5
  74. ) ';
  75. Database::query($sql_t);
  76. //Update weight into student publication(work)
  77. $sql_t = 'UPDATE '.$tbl_work.' SET
  78. weight='.$final_weight.'
  79. WHERE c_id = '.$course_id.' AND id = (
  80. SELECT ref_id FROM '.$tbl_grade_links.'
  81. WHERE id='.intval($_GET['editlink'] ).' AND type=3
  82. )';
  83. Database::query($sql_t);
  84. header('Location: '.$_SESSION['gradebook_dest'].'?linkedited=&selectcat=' . $link->get_category_id().'&'.api_get_cidreq());
  85. exit;
  86. }
  87. $interbreadcrumb[] = array(
  88. 'url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$linkcat,
  89. 'name' => get_lang('Gradebook')
  90. );
  91. $htmlHeadXtra[] = '<script type="text/javascript">
  92. $(document).ready( function() {
  93. $("#hide_category_id").change(function() {
  94. $("#hide_category_id option:selected").each(function () {
  95. var cat_id = $(this).val();
  96. $.ajax({
  97. url: "'.api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight",
  98. data: "cat_id="+cat_id,
  99. success: function(return_value) {
  100. if (return_value != 0 ) {
  101. $("#max_weight").html(return_value);
  102. }
  103. }
  104. });
  105. });
  106. });
  107. });
  108. </script>';
  109. Display :: display_header(get_lang('EditLink'));
  110. $form->display();
  111. Display :: display_footer();