From 2c309dc22acf46e821273759222cb7fbef62fff6 Mon Sep 17 00:00:00 2001
From: martin
Date: Mon, 29 Jul 2002 15:45:46 +0000
Subject: [PATCH] Definition and use of new isediting() function for checking
whether a user is not only in editing mode, but ALLOWED to be editing the
current course. Used to show editing buttons etc
---
course/social.php | 4 ++--
course/weeks.php | 8 ++++----
index.php | 6 +++---
lib/moodlelib.php | 8 ++++++++
4 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/course/social.php b/course/social.php
index b75d58b453..4c08863e97 100644
--- a/course/social.php
+++ b/course/social.php
@@ -33,7 +33,7 @@
$readingicon[] = "
";
}
}
- if ($USER->editing) {
+ if (isediting($course->id)) {
$readingdata[] = "id§ion=0&add=reading\">Add reading...";
$readingicon[] = " ";
}
@@ -56,7 +56,7 @@
if (isteacher($USER->id) || isadmin()) {
print_simple_box("Admin", $align="CENTER", $width="100%", $color="$THEME->cellheading");
$adminicon[]="
";
- if ($USER->editing) {
+ if (isediting($course->id)) {
$admindata[]="id&edit=off\">Turn editing off";
} else {
$admindata[]="id&edit=on\">Turn editing on";
diff --git a/course/weeks.php b/course/weeks.php
index 2fb3834d03..b73bcd5d4c 100644
--- a/course/weeks.php
+++ b/course/weeks.php
@@ -62,7 +62,7 @@
if (isteacher($course->id)) {
$adminicon[]="
";
- if ($USER->editing) {
+ if (isediting($course->id)) {
$admindata[]="id&edit=off\">Turn editing off";
} else {
$admindata[]="id&edit=on\">Turn editing on";
@@ -135,7 +135,7 @@
$thisweek->id = insert_record("course_sections", $thisweek);
}
- if ($USER->editing) {
+ if (isediting($course->id)) {
$thisweek->summary .= " id>
";
}
@@ -152,7 +152,7 @@
echo "
modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">";
echo " modfullname\"";
echo " HREF=\"../mod/$mod->modname/view.php?id=$mod->id\">$instancename";
- if ($USER->editing) {
+ if (isediting($course->id)) {
echo make_editing_buttons($mod->id);
}
echo "
\n";
@@ -160,7 +160,7 @@
}
echo "\n";
- if ($USER->editing) {
+ if (isediting($course->id)) {
echo "";
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id§ion=$week&add=",
$modtypes, "section$week", "", "Add...");
diff --git a/index.php b/index.php
index b62f76cff1..7be9cf8938 100644
--- a/index.php
+++ b/index.php
@@ -28,7 +28,7 @@
$readings = list_all_readings();
- if ($site->newsitems > 0 or $readings or ($USER->editing and isadmin())) {
+ if ($site->newsitems > 0 or $readings or isediting($site->id)) {
print_simple_box(get_string("mainmenu"), $align="CENTER", $width="100%", $color="$THEME->cellheading");
@@ -45,7 +45,7 @@
echo "$reading";
}
}
- if ($USER->editing and isadmin()) {
+ if (isediting($site->id)) {
echo " wwwroot/course/mod.php?id=$site->id§ion=0&add=reading\">".
get_string("addreading", "reading")."... ";
} else {
@@ -99,7 +99,7 @@
|
- if ($USER->editing and isadmin()) {
+ if (isediting($site->id)) {
$site->summary .= "
";
}
print_simple_box($site->summary, "", "100%", $THEME->cellheading);
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 8d40bb7b0a..def4c7c1b8 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -948,6 +948,14 @@ function isguest($userid=0) {
return record_exists_sql("SELECT * FROM user WHERE user='$userid' AND username = 'guest' ");
}
+function isediting($courseid, $user=NULL) {
+ global $USER;
+ if (!$user){
+ $user = $USER;
+ }
+ return ($user->editing and isteacher($courseid, $user->id));
+}
+
function reset_login_count() {
global $SESSION;
--
2.39.5
|