gradebook_edit_link.php 3.9 KB

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