123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Script
- * @package chamilo.gradebook
- */
- api_block_anonymous_users();
- GradebookUtils::block_students();
- $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
- //selected name of database
- $course_id = GradebookUtils::get_course_id_by_link_id($_GET['editlink']);
- $tbl_forum_thread = Database:: get_course_table(TABLE_FORUM_THREAD);
- $tbl_attendance = Database:: get_course_table(TABLE_ATTENDANCE);
- $em = Database::getManager();
- $linkarray = LinkFactory :: load($_GET['editlink']);
- /** @var AbstractLink $link */
- $link = $linkarray[0];
- if ($link->is_locked() && !api_is_platform_admin()) {
- api_not_allowed();
- }
- $linkcat = isset($_GET['selectcat']) ? (int) $_GET['selectcat'] : 0;
- $linkedit = isset($_GET['editlink']) ? Security::remove_XSS($_GET['editlink']):'';
- $course_code = api_get_course_id();
- $session_id = api_get_session_id();
- if ($session_id == 0) {
- $cats = Category:: load(
- null,
- null,
- $course_code,
- null,
- null,
- $session_id,
- false
- ); //already init
- } else {
- $cats = Category :: load_session_categories(null, $session_id);
- }
- $form = new LinkAddEditForm(
- LinkAddEditForm :: TYPE_EDIT,
- $cats,
- null,
- $link,
- 'edit_link_form',
- api_get_self() . '?selectcat=' . $linkcat. '&editlink=' . $linkedit.'&'.api_get_cidreq()
- );
- if ($form->validate()) {
- $values = $form->exportValues();
- $parent_cat = Category :: load($values['select_gradebook']);
- $final_weight = $values['weight_mask'];
- $link->set_weight($final_weight);
- if (!empty($values['select_gradebook'])) {
- $link->set_category_id($values['select_gradebook']);
- }
- $link->set_visible(empty($values['visible']) ? 0 : 1);
- $link->save();
- //Update weight for attendance
- $gradebookLink = $em->find('ChamiloCoreBundle:GradebookLink', intval($_GET['editlink']));
- if ($gradebookLink && $gradebookLink->getType() == LINK_ATTENDANCE) {
- $sql = '
- UPDATE ' . $tbl_attendance . ' SET attendance_weight =' . floatval($final_weight) . '
- WHERE c_id = '.$course_id.' AND id = ' . $gradebookLink->getRefId();
- Database::query($sql);
- }
- //Update weight into forum thread
- if ($gradebookLink && $gradebookLink->getType() == LINK_FORUM_THREAD) {
- $sql_t = '
- UPDATE ' . $tbl_forum_thread . ' SET thread_weight=' . $final_weight . '
- WHERE c_id = ' . $course_id . ' AND thread_id = ' . $gradebookLink->getRefId();
- Database::query($sql_t);
- }
- //Update weight into student publication(work)
- if ($gradebookLink && $gradebookLink->getType() == LINK_STUDENTPUBLICATION) {
- $sql_t = '
- UPDATE ' . $tbl_work . ' SET weight=' . $final_weight . '
- WHERE c_id = ' . $course_id . ' AND id = ' . $gradebookLink->getRefId();
- Database::query($sql_t);
- }
- header('Location: '.$_SESSION['gradebook_dest'].'?linkedited=&selectcat=' . $link->get_category_id().'&'.api_get_cidreq());
- exit;
- }
- $interbreadcrumb[] = array(
- 'url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$linkcat,
- 'name' => get_lang('Gradebook')
- );
- $htmlHeadXtra[] = '<script>
- $(document).ready( function() {
- $("#hide_category_id").change(function() {
- $("#hide_category_id option:selected").each(function () {
- var cat_id = $(this).val();
- $.ajax({
- url: "'.api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight",
- data: "cat_id="+cat_id,
- success: function(return_value) {
- if (return_value != 0 ) {
- $("#max_weight").html(return_value);
- }
- }
- });
- });
- });
- });
- </script>';
- Display :: display_header(get_lang('EditLink'));
- $form->display();
- Display :: display_footer();
|