gradebook_edit_link.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $language_file = array('gradebook','link');
  4. //$cidReset = true;
  5. require_once ('../inc/global.inc.php');
  6. require_once ('lib/be.inc.php');
  7. require_once ('lib/gradebook_functions.inc.php');
  8. require_once ('lib/fe/linkform.class.php');
  9. require_once ('lib/fe/linkaddeditform.class.php');
  10. api_block_anonymous_users();
  11. block_students();
  12. $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  13. $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  14. //selected name of database
  15. $my_db_name=get_database_name_by_link_id(Security::remove_XSS($_GET['editlink']));
  16. $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD,$my_db_name);
  17. $tbl_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION,$my_db_name);
  18. $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE,$my_db_name);
  19. $linkarray = LinkFactory :: load(Security::remove_XSS($_GET['editlink']));
  20. $link = $linkarray[0];
  21. $linkcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']):'';
  22. $linkedit = isset($_GET['editlink']) ? Security::remove_XSS($_GET['editlink']):'';
  23. $form = new LinkAddEditForm(LinkAddEditForm :: TYPE_EDIT,
  24. null,
  25. null,
  26. $link,
  27. 'edit_link_form',
  28. api_get_self() . '?selectcat=' . $linkcat
  29. . '&editlink=' . $linkedit);
  30. if ($form->validate()) {
  31. $values = $form->exportValues();
  32. $link->set_weight($values['weight']);
  33. $link->set_visible(empty ($values['visible']) ? 0 : 1);
  34. $link->save();
  35. //Update weight for attendance
  36. $sql = 'SELECT ref_id FROM '.$tbl_grade_links.' WHERE id = '.intval($_GET['editlink']).' AND type='.LINK_ATTENDANCE;
  37. $rs_attendance = Database::query($sql);
  38. if (Database::num_rows($rs_attendance) > 0) {
  39. $row_attendance = Database::fetch_array($rs_attendance);
  40. $attendance_id = $row_attendance['ref_id'];
  41. $upd_attendance = 'UPDATE '.$tbl_attendance.' SET attendance_weight ='.floatval($values['weight']).' WHERE id = '.intval($attendance_id);
  42. Database::query($upd_attendance);
  43. }
  44. //Update weight into forum thread
  45. $sql_t='UPDATE '.$tbl_forum_thread.' SET thread_weight='.$values['weight'].' WHERE thread_id=(SELECT ref_id FROM '.$tbl_grade_links.' where id='.intval($_GET['editlink']).' and type=5);';
  46. Database::query($sql_t);
  47. //Update weight into student publication(work)
  48. $sql_t='UPDATE '.$tbl_work.' SET weight='.$values['weight'].' WHERE id=(SELECT ref_id FROM '.$tbl_grade_links.' where id='.intval($_GET['editlink']).' and type=3);';
  49. Database::query($sql_t);
  50. header('Location: '.$_SESSION['gradebook_dest'].'?linkedited=&selectcat=' . $link->get_category_id());
  51. exit;
  52. }
  53. $interbreadcrumb[] = array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$linkcat,'name' => get_lang('Gradebook'));
  54. Display :: display_header(get_lang('EditLink'));
  55. $form->display();
  56. Display :: display_footer();