gradebook_edit_link.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. $linkcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']):'';
  28. $linkedit = isset($_GET['editlink']) ? Security::remove_XSS($_GET['editlink']):'';
  29. $cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
  30. $form = new LinkAddEditForm(LinkAddEditForm :: TYPE_EDIT, $cats, null, $link, 'edit_link_form', api_get_self() . '?selectcat=' . $linkcat. '&editlink=' . $linkedit);
  31. if ($form->validate()) {
  32. $values = $form->exportValues();
  33. $link->set_weight($values['weight']);
  34. $link->set_visible(empty ($values['visible']) ? 0 : 1);
  35. $link->save();
  36. //Update weight for attendance
  37. $sql = 'SELECT ref_id FROM '.$tbl_grade_links.' WHERE c_id = '.$course_id.' AND id = '.intval($_GET['editlink']).' AND type='.LINK_ATTENDANCE;
  38. $rs_attendance = Database::query($sql);
  39. if (Database::num_rows($rs_attendance) > 0) {
  40. $row_attendance = Database::fetch_array($rs_attendance);
  41. $attendance_id = $row_attendance['ref_id'];
  42. $upd_attendance = 'UPDATE '.$tbl_attendance.' SET attendance_weight ='.floatval($values['weight']).' WHERE c_id = '.$course_id.' AND id = '.intval($attendance_id);
  43. Database::query($upd_attendance);
  44. }
  45. //Update weight into forum thread
  46. $sql_t = 'UPDATE '.$tbl_forum_thread.' SET thread_weight='.$values['weight'].'
  47. WHERE c_id = '.$course_id.' AND thread_id=(SELECT ref_id FROM '.$tbl_grade_links.' WHERE id='.intval($_GET['editlink']).' and type=5 AND c_id = '.$course_id.' ) ';
  48. Database::query($sql_t);
  49. //Update weight into student publication(work)
  50. $sql_t = 'UPDATE '.$tbl_work.' SET weight='.$values['weight'].'
  51. WHERE c_id = '.$course_id.' AND id = (SELECT ref_id FROM '.$tbl_grade_links.' WHERE c_id = '.$course_id.' AND id='.intval($_GET['editlink'] ).' AND type=3 )';
  52. Database::query($sql_t);
  53. header('Location: '.$_SESSION['gradebook_dest'].'?linkedited=&selectcat=' . $link->get_category_id());
  54. exit;
  55. }
  56. $interbreadcrumb[] = array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$linkcat,'name' => get_lang('Gradebook'));
  57. $htmlHeadXtra[] = '<script type="text/javascript">
  58. $(document).ready( function() {
  59. $("#hide_category_id").change(function(){
  60. $("#hide_category_id option:selected").each(function () {
  61. var cat_id = $(this).val();
  62. $.ajax({
  63. url: "'.api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight",
  64. data: "cat_id="+cat_id,
  65. success: function(return_value) {
  66. if (return_value != 0 ) {
  67. $("#max_weight").html(return_value);
  68. }
  69. },
  70. });
  71. });
  72. });
  73. });
  74. </script>';
  75. Display :: display_header(get_lang('EditLink'));
  76. $form->display();
  77. Display :: display_footer();