Commit 63625276 authored by Thomas Fradet's avatar Thomas Fradet
Browse files

fix capacities and param names

parent ca7d1cff
...@@ -65,3 +65,10 @@ Ajout d'un lien pour revenir au cours, visible par l'étudiant et l'enseignant. ...@@ -65,3 +65,10 @@ Ajout d'un lien pour revenir au cours, visible par l'étudiant et l'enseignant.
#### Lien vers l'édition #### Lien vers l'édition
Ajout d'un bouton en haut de page pour éditer le parcours, visible uniquement par l'enseignant. Ajout d'un bouton en haut de page pour éditer le parcours, visible uniquement par l'enseignant.
### Gestion des droits
Ajout de vérification du droit d'éditer le cours pour les interfaces d'édition de parcours. Modification de noms de paramètres.
...@@ -52,9 +52,7 @@ class block_career extends block_base ...@@ -52,9 +52,7 @@ class block_career extends block_base
*/ */
public function get_content() public function get_content()
{ {
global $CFG; global $CFG, $COURSE, $DB, $USER;
global $COURSE;
global $DB;
if ($this->content !== null) { if ($this->content !== null) {
return $this->content; return $this->content;
...@@ -97,8 +95,11 @@ class block_career extends block_base ...@@ -97,8 +95,11 @@ class block_career extends block_base
if (empty($request)) { if (empty($request)) {
$this->content->text .= "<p>" . get_string('any_carrer', 'block_career') . "</p>"; $this->content->text .= "<p>" . get_string('any_carrer', 'block_career') . "</p>";
} }
if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/career/career_list.php?courseid=' . $COURSE->id . '" type="button " class="btn btn-primary btn-career-block mt-3">Gérer les parcours</a>';
}
$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/career/career_list.php?course=' . $COURSE->id . '" type="button " class="btn btn-primary btn-career-block mt-3">Gérer les parcours</a>';
// $this->content->text .= "<p></p>"; // $this->content->text .= "<p></p>";
......
<?php <?php
define('NO_OUTPUT_BUFFERING', true); // define('NO_OUTPUT_BUFFERING', true);
require_once('../../config.php'); require_once('../../config.php');
require_once('entity/block_career_ressource.php'); require_once('entity/block_career_ressource.php');
require_once('entity/block_career_section.php'); require_once('entity/block_career_section.php');
require_once('view/view_career_list.php'); require_once('view/view_career_list.php');
global $COURSE; global $USER, $DB, $CFG;
global $USER; require_once($CFG->libdir . '/adminlib.php');
global $DB;
global $CFG; $id_course = required_param('courseid', PARAM_INT);
require_once($CFG->libdir . '/adminlib.php');
$url = new moodle_url('/blocks/career/career_list.php', array('courseid' => $id_course));
$id_course = required_param('course', PARAM_INT);
$url = new moodle_url('/blocks/career/career_list.php', array('course' => $id_course));
//Check if the user has capability to update course //Check if the user has capability to update course
if (!has_capability('moodle/course:update', $context = context_course::instance($id_course), $USER->id)) { if (!has_capability('moodle/course:update', $context = context_course::instance($id_course), $USER->id)) {
header("Location: {$_SERVER['HTTP_REFERER']}"); $link = $CFG->wwwroot . '/course/view.php?id=' . $id_course;
exit; header("Location: {$link}");
} exit;
}
$PAGE->set_url($url);
$PAGE->set_pagelayout('admin'); $PAGE->set_url($url);
$PAGE->set_pagelayout('admin');
$course = $DB->get_record('course', array('id' => $id_course), '*', MUST_EXIST);
require_login($course, false, NULL); $course = $DB->get_record('course', array('id' => $id_course), '*', MUST_EXIST);
require_login($course, false, NULL);
$PAGE->set_title(get_string('title_plugin', 'block_career'));
$PAGE->set_heading($OUTPUT->heading($COURSE->fullname, 2, 'headingblock header outline')); $PAGE->set_title(get_string('title_plugin', 'block_career'));
$PAGE->set_heading($OUTPUT->heading($COURSE->fullname, 2, 'headingblock header outline'));
$ressource = new block_career_ressource();
$section = new block_career_section(); // $ressource = new block_career_ressource();
echo $OUTPUT->header(); // $section = new block_career_section();
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">"; echo $OUTPUT->header();
$content = new view_career_list(); // echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">";
echo $content->get_content(); $content = new view_career_list();
echo $OUTPUT->footer(); echo $content->get_content();
\ No newline at end of file echo $OUTPUT->footer();
\ No newline at end of file
<?php <?php
ob_start(); ob_start();
require_once('../../config.php'); require_once('../../config.php');
global $COURSE, $DB, $CFG; global $COURSE, $DB, $CFG, $USER;
require_once("$CFG->libdir/formslib.php"); require_once("$CFG->libdir/formslib.php");
require_once('entity/block_career_ressource.php'); require_once('entity/block_career_ressource.php');
require_once('entity/block_career_section.php'); require_once('entity/block_career_section.php');
require_once('view/view_career_setting.php'); require_once('view/view_career_setting.php');
$id_course = required_param('course', PARAM_INT); $id_course = required_param('courseid', PARAM_INT);
$url = new moodle_url('/blocks/career/career_setting.php', array('course' => $id_course)); $url = new moodle_url('/blocks/career/career_setting.php', array('courseid' => $id_course));
$PAGE->set_pagelayout('course'); $PAGE->set_pagelayout('course');
$PAGE->set_url($url); $PAGE->set_url($url);
$course = $DB->get_record('course', array('id' => $id_course), '*', MUST_EXIST); // $course = $DB->get_record('course', array('id' => $id_course), '*', MUST_EXIST);
require_login($course, false, NULL); require_login($id_course, false, NULL);
// $COURSE is === "1" before require_login !!!
$PAGE->set_title(get_string('title_plugin', 'block_career'));
$PAGE->set_heading($OUTPUT->heading($COURSE->fullname, 2, 'headingblock header outline')); if (!has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
echo $OUTPUT->header(); $link = $CFG->wwwroot . '/course/view.php?id=' . $COURSE->id;
$PAGE->requires->js("/blocks/career/js/jquery.min.js"); header("Location: {$link}");
$PAGE->requires->js("/blocks/career/js/file.js"); exit;
}
$PAGE->set_title(get_string('title_plugin', 'block_career'));
$PAGE->set_heading($OUTPUT->heading($COURSE->fullname, 2, 'headingblock header outline'));
echo $OUTPUT->header();
$PAGE->requires->js("/blocks/career/js/jquery.min.js");
$PAGE->requires->js("/blocks/career/js/file.js");
// echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">"; // echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">";
$content = new view_career_setting(); $content = new view_career_setting();
echo $content->get_content(); echo $content->get_content();
// Delete career // Delete career
if (isset($_GET["delete"]) && $_GET["delete"] == 1) { if (isset($_GET["delete"]) && $_GET["delete"] == 1) {
$DB->execute("DELETE FROM {block_career} WHERE id = ?", array($_GET["id"])); $DB->execute("DELETE FROM {block_career} WHERE id = ?", array($_GET["id"]));
header("Location: $CFG->wwwroot/blocks/career/career_list.php?course=" . $_GET["course"]); header("Location: $CFG->wwwroot/blocks/career/career_list.php?courseid=" . $_GET["courseid"]);
} }
if (!empty($_POST["careerName"])) { if (!empty($_POST["careerName"])) {
$ressourses = ""; $ressourses = "";
foreach ($_POST["ressource"] as $value) { foreach ($_POST["ressource"] as $value) {
if ($value === end($_POST["ressource"])) { if ($value === end($_POST["ressource"])) {
$ressourses .= "$value"; $ressourses .= "$value";
} else { } else {
$ressourses .= "$value,"; $ressourses .= "$value,";
}
} }
}
//$record is use for insert/update in database //$record is use for insert/update in database
$record = new stdClass(); $record = new stdClass();
$record->course = intval($_GET["course"]); $record->course = intval($_GET["courseid"]);
$record->name = $_POST["careerName"]; $record->name = $_POST["careerName"];
$record->description = $_POST["descriptionName"]["text"]; $record->description = $_POST["descriptionName"]["text"];
// if (isset($_FILES['imageName']['tmp_name'])) { // if (isset($_FILES['imageName']['tmp_name'])) {
// $pathDir = "img/"; // $pathDir = "img/";
// $pathFile = $pathDir . basename($_FILES["imageName"]["name"]); // $pathFile = $pathDir . basename($_FILES["imageName"]["name"]);
...@@ -61,22 +68,22 @@ ...@@ -61,22 +68,22 @@
// } else { // } else {
// $record->image = $_POST["imagePath"]; // $record->image = $_POST["imagePath"];
// } // }
$record->image = ""; $record->image = "";
$record->ressources = $ressourses; $record->ressources = $ressourses;
if ($_POST["careerId"] != 0) { if ($_POST["careerId"] != 0) {
$record->id = intval($_POST["careerId"]); $record->id = intval($_POST["careerId"]);
$lastinsertid = $DB->update_record('block_career', $record); $lastinsertid = $DB->update_record('block_career', $record);
} else { } else {
$lastinsertid = $DB->insert_record('block_career', $record); $lastinsertid = $DB->insert_record('block_career', $record);
} }
if ($lastinsertid != 0) { if ($lastinsertid != 0) {
header("Location: $CFG->wwwroot/blocks/career/career_list.php?course=" . $_GET["course"]); header("Location: $CFG->wwwroot/blocks/career/career_list.php?courseid=" . $_GET["courseid"]);
}
} }
}
echo $OUTPUT->footer();
echo $OUTPUT->footer();
<?php <?php
class view_career_list class view_career_list
{ {
/** /**
* @return string * @return string
*/ */
public function get_content() public function get_content()
{ {
global $DB, $CFG; global $DB, $CFG, $COURSE, $USER;
$content = "<h2>" . get_string('title_plugin', 'block_career') . "</h2>"; if (!has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
$content .= "<div class='alert alert-info'>" . get_string('heading_plugin', 'block_career') . "</div>"; $link = $CFG->wwwroot . '/course/view.php?id=' . $COURSE->id;
header("Location: {$link}");
$request = $DB->get_records_sql('SELECT * FROM {block_career} WHERE course = ?', array($_GET["course"])); exit;
}
$content = "<h2>" . get_string('title_plugin', 'block_career') . "</h2>";
$content .= "<div class='alert alert-info'>" . get_string('heading_plugin', 'block_career') . "</div>";
$request = $DB->get_records_sql('SELECT * FROM {block_career} WHERE course = ?', array($_GET["courseid"]));
// $image = ""; // $image = "";
foreach ($request as $value) { foreach ($request as $value) {
// if (file_get_contents($value->image) != null) { // if (file_get_contents($value->image) != null) {
// $image = "<img src='$value->image' class='img_moodle_course'/>"; // $image = "<img src='$value->image' class='img_moodle_course'/>";
// } // }
$content .= "<div class='card card-block mb-3'> $content .= "<div class='card card-block mb-3'>
<div class='card-body'> <div class='card-body'>
<h2 class='card-title'>$value->name</h2> <h2 class='card-title'>$value->name</h2>
<p class='card-text'>$value->description</p> <p class='card-text'>$value->description</p>
<a href='$CFG->wwwroot/blocks/career/career_setting.php?course=" . $_GET["course"] . "&id=$value->id' class='btn btn-primary btn-sm path-list-edit-link'>Modifier</a> <a href='$CFG->wwwroot/blocks/career/career_setting.php?courseid=" . $_GET["courseid"] . "&pathid=$value->id' class='btn btn-primary btn-sm path-list-edit-link'>Modifier</a>
</div> </div>
</div>"; </div>";
// $content .= "<div class='card card_block'> // $content .= "<div class='card card_block'>
// <div class='row'> // <div class='row'>
...@@ -39,17 +45,17 @@ ...@@ -39,17 +45,17 @@
// <div class='col-lg-1 col-md-1 padding_column'><a style='color:black' href='$CFG->wwwroot/blocks/career/career_setting.php?course=" . $_GET["course"] . "&id=$value->id'><i class=\"fa fa-cog fa-2x\"></a></i></div> // <div class='col-lg-1 col-md-1 padding_column'><a style='color:black' href='$CFG->wwwroot/blocks/career/career_setting.php?course=" . $_GET["course"] . "&id=$value->id'><i class=\"fa fa-cog fa-2x\"></a></i></div>
// </div> // </div>
// </div>"; // </div>";
} }
if (empty($request)) { if (empty($request)) {
$content .= "<p>" . get_string('any_carrer', 'block_career') . "</p>"; $content .= "<p>" . get_string('any_carrer', 'block_career') . "</p>";
} }
// Button for adding course to the list // Button for adding course to the list
$content .= "<a href='$CFG->wwwroot/blocks/career/career_setting.php?course=" . $_GET["course"] . "' class='btn btn-primary'>" . get_string('add_path', 'block_career') . "</a>"; $content .= "<a href='$CFG->wwwroot/blocks/career/career_setting.php?courseid=" . $COURSE->id . "' class='btn btn-primary'>" . get_string('add_path', 'block_career') . "</a>";
return $content; return $content;
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -28,8 +28,8 @@ class view_career_setting extends moodleform ...@@ -28,8 +28,8 @@ class view_career_setting extends moodleform
global $DB, $CFG; global $DB, $CFG;
$mform = $this->_form; $mform = $this->_form;
$careerId = optional_param('id', NULL, PARAM_INT); $careerId = optional_param('pathid', NULL, PARAM_INT);
$course = required_param('course', PARAM_INT); $course = required_param('courseid', PARAM_INT);
$name = ""; $name = "";
$description = ""; $description = "";
...@@ -74,7 +74,7 @@ class view_career_setting extends moodleform ...@@ -74,7 +74,7 @@ class view_career_setting extends moodleform
$sections = block_career_section::get_sections_by_id_course($course); $sections = block_career_section::get_sections_by_id_course($course);
$content .= '<div class="row"><form class="col-12" action="career_setting.php?course=' . $course . '" method="post" enctype="multipart/form-data">'; $content .= '<div class="row"><form class="col-12" action="career_setting.php?courseid=' . $course . '" method="post" enctype="multipart/form-data">';
$content .= $temp; $content .= $temp;
...@@ -173,12 +173,12 @@ class view_career_setting extends moodleform ...@@ -173,12 +173,12 @@ class view_career_setting extends moodleform
<div class="row mt-3"> <div class="row mt-3">
<div class="col"> <div class="col">
<input type="hidden" name="careerId" value="'.$careerId.'"> <input type="hidden" name="careerId" value="'.$careerId.'">
<a href=' . $CFG->wwwroot . "/blocks/career/career_list.php?course=" . $course . ' class="btn btn-secondary">Annuler</a> '; <a href=' . $CFG->wwwroot . "/blocks/career/career_list.php?courseid=" . $course . ' class="btn btn-secondary">Annuler</a> ';
if ($careerId != 0) { if ($careerId != 0) {
$content .= "<a href='$CFG->wwwroot/blocks/career/career_setting.php?course=$course&delete=1&id=$careerId' class='btn btn-danger'>Supprimer</a> "; $content .= "<a href='$CFG->wwwroot/blocks/career/career_setting.php?courseid=$course&delete=1&id=$careerId' class='btn btn-danger'>Supprimer</a> ";
} }
$content .= ' $content .= '
......
...@@ -52,7 +52,7 @@ $sections = array_combine($keys,$sections); ...@@ -52,7 +52,7 @@ $sections = array_combine($keys,$sections);
ksort($sections); ksort($sections);
$cours_url = $CFG->wwwroot . "/course/view.php?id=" . $COURSE->id; $cours_url = $CFG->wwwroot . "/course/view.php?id=" . $COURSE->id;
$edit_url = $CFG->wwwroot . "/blocks/career/career_setting.php?course=" . $COURSE->id . "&id=" . $careerId; $edit_url = $CFG->wwwroot . "/blocks/career/career_setting.php?courseid=" . $COURSE->id . "&pathid=" . $careerId;
?> ?>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment