gradebook_edit_link.php 3.8 KB

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