Skip to content
Snippets Groups Projects
suivi_edit.php 3.18 KiB
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 *
 * @package    format_iena
 * @copyright  2018 Softia/Université lorraine
 * @author     vrignaud camille / Thomas Fradet
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

use format_iena\output;


define('NO_OUTPUT_BUFFERING', true);



require_once('../../../config.php');
require_once($CFG->dirroot. '/course/format/iena/classes/form/edittable_form.php');



$PAGE->requires->css('/course/format/iena/styles.css');

//On va déjà chercher en BDD s'il y a des options









function init_page($course) {
    global $PAGE;
    // Defines the id of the course with a get parameter.
    // Getting DB information (*)  of the course.

    $PAGE->set_title($course->fullname);
    $PAGE->set_heading($course->fullname . " – " .get_string('table_progress', 'format_iena'));
    $PAGE->set_pagelayout('incourse');

    // Cache le menu dans le header.
    $coursenode = $PAGE->navbar->add(get_string('table_progress', 'format_iena'),
        null, navigation_node::TYPE_CONTAINER, null, 'suiviena');
    $coursenode->make_active();
    $coursenode->force_open();

}


$courseid = required_param('courseid', PARAM_INT);
// Define the url of the view.
$url = new moodle_url('/course/format/iena/suivi_edit.php', array('courseid' => $courseid));
$PAGE->set_url($url);
$returnurl=new moodle_url('/course/format/iena/suivi_unit.php', array('courseid' => $courseid));

$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
require_login($course);


$context = context_course::instance($COURSE->id);

if (!has_capability('course/iena:suivi', $context = context_course::instance($courseid), $USER->id)) {
    $link = $CFG->wwwroot . '/course/view.php?id=' . $courseid;
    header("Location: {$link}");
    exit;
}



    init_page($course, $PAGE);
    
    $data = [];
    $obj=new \format_iena\output\course_format_iena_table_option();
    $obj->setCourseid($courseid);
    $obj->setUserid($USER->id);
    $obj->get_request_options();
    $arraycustomform=$obj->listoptions;
    $arraycustomform["courseid"]=$courseid;
    $mform= new edittable_form(null, $arraycustomform);
    // Form processing and displaying is done here.

    if ($mform->is_cancelled()) {
        redirect($returnurl);
    } else if ($fromform = $mform->get_data()) {
        $obj->check_options_state($fromform);
        redirect($returnurl);
    }
    echo $OUTPUT->header();

    $data["form"]=$mform->render();
    $renderer = $PAGE->get_renderer('format_iena');
    $renderer->display_edit_page($data);
    echo $OUTPUT->footer();