gradebook_edit_link.php 4.3 KB

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