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::loadSessionCategories(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 $sql = 'SELECT ref_id FROM '.$tbl_grade_links.' WHERE id = '.intval($_GET['editlink']).' AND type='.LINK_ATTENDANCE; $rs_attendance = Database::query($sql); if (Database::num_rows($rs_attendance) > 0) { $row_attendance = Database::fetch_array($rs_attendance); $attendance_id = $row_attendance['ref_id']; $sql = 'UPDATE '.$tbl_attendance.' SET attendance_weight ='.api_float_val($final_weight).' WHERE c_id = '.$course_id.' AND id = '.intval($attendance_id); Database::query($sql); } //Update weight into forum thread $sql = 'UPDATE '.$tbl_forum_thread.' SET thread_weight = '.api_float_val($final_weight).' WHERE c_id = '.$course_id.' AND thread_id = ( SELECT ref_id FROM '.$tbl_grade_links.' WHERE id='.intval($_GET['editlink']).' AND type = 5 )'; Database::query($sql); //Update weight into student publication(work) $em ->createQuery(' UPDATE ChamiloCourseBundle:CStudentPublication w SET w.weight = :final_weight WHERE w.cId = :course AND w.id = ( SELECT l.refId FROM ChamiloCoreBundle:GradebookLink l WHERE l.id = :link AND l.type = :type ) ') ->execute([ 'final_weight' => $final_weight, 'course' => $course_id, 'link' => intval($_GET['editlink']), 'type' => LINK_STUDENTPUBLICATION, ]); $logInfo = [ 'tool' => TOOL_GRADEBOOK, 'tool_id' => 0, 'tool_id_detail' => 0, 'action' => 'edit-link', 'action_details' => '', ]; Event::registerLog($logInfo); header('Location: '.Category::getUrl().'linkedited=&selectcat='.$link->get_category_id()); exit; } $interbreadcrumb[] = [ 'url' => Category::getUrl().'selectcat='.$linkcat, 'name' => get_lang('Gradebook'), ]; $htmlHeadXtra[] = ''; Display :: display_header(get_lang('EditLink')); $form->display(); Display :: display_footer();