Permalink
Browse files

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
  • Loading branch information...
1 parent 3c720cc commit 2c309dc22acf46e821273759222cb7fbef62fff6 martin committed Jul 29, 2002
Showing with 17 additions and 9 deletions.
  1. +2 −2 course/social.php
  2. +4 −4 course/weeks.php
  3. +3 −3 index.php
  4. +8 −0 lib/moodlelib.php
View
4 course/social.php
@@ -33,7 +33,7 @@
$readingicon[] = "<IMG SRC=\"../mod/reading/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"Reading\">";
}
}
- if ($USER->editing) {
+ if (isediting($course->id)) {
$readingdata[] = "<A HREF=\"mod.php?id=$course->id&section=0&add=reading\">Add reading...</A>";
$readingicon[] = "&nbsp;";
}
@@ -56,7 +56,7 @@
if (isteacher($USER->id) || isadmin()) {
print_simple_box("Admin", $align="CENTER", $width="100%", $color="$THEME->cellheading");
$adminicon[]="<IMG SRC=\"../pix/i/edit.gif\" HEIGHT=16 WIDTH=16 ALT=\"Edit\">";
- if ($USER->editing) {
+ if (isediting($course->id)) {
$admindata[]="<A HREF=\"view.php?id=$course->id&edit=off\">Turn editing off</A>";
} else {
$admindata[]="<A HREF=\"view.php?id=$course->id&edit=on\">Turn editing on</A>";
View
8 course/weeks.php
@@ -62,7 +62,7 @@
if (isteacher($course->id)) {
$adminicon[]="<IMG SRC=\"../pix/i/edit.gif\" HEIGHT=16 WIDTH=16 ALT=\"Edit\">";
- if ($USER->editing) {
+ if (isediting($course->id)) {
$admindata[]="<A HREF=\"view.php?id=$course->id&edit=off\">Turn editing off</A>";
} else {
$admindata[]="<A HREF=\"view.php?id=$course->id&edit=on\">Turn editing on</A>";
@@ -135,7 +135,7 @@
$thisweek->id = insert_record("course_sections", $thisweek);
}
- if ($USER->editing) {
+ if (isediting($course->id)) {
$thisweek->summary .= "&nbsp;<A HREF=editweek.php?id=$thisweek->id><IMG SRC=\"../pix/t/edit.gif\" BORDER=0 ALT=\"Edit summary\"></A></P>";
}
@@ -152,15 +152,15 @@
echo "<IMG SRC=\"../mod/$mod->modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">";
echo " <A TITLE=\"$mod->modfullname\"";
echo " HREF=\"../mod/$mod->modname/view.php?id=$mod->id\">$instancename</A>";
- if ($USER->editing) {
+ if (isediting($course->id)) {
echo make_editing_buttons($mod->id);
}
echo "<BR>\n";
}
}
echo "</UL></P>\n";
- if ($USER->editing) {
+ if (isediting($course->id)) {
echo "<DIV ALIGN=right>";
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$week&add=",
$modtypes, "section$week", "", "Add...");
View
6 index.php
@@ -28,7 +28,7 @@
<TD VALIGN="TOP" NOWRAP>
<? $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 "<LI>$reading";
}
}
- if ($USER->editing and isadmin()) {
+ if (isediting($site->id)) {
echo "<P align=right><A HREF=\"$CFG->wwwroot/course/mod.php?id=$site->id&section=0&add=reading\">".
get_string("addreading", "reading")."</A>...</P>";
} else {
@@ -99,7 +99,7 @@
</TD>
<TD WIDTH="30%" VALIGN="TOP">
<?
- if ($USER->editing and isadmin()) {
+ if (isediting($site->id)) {
$site->summary .= "<BR><CENTER><A HREF=\"admin/site.php\"><IMG SRC=\"pix/i/edit.gif\" BORDER=0></A>";
}
print_simple_box($site->summary, "", "100%", $THEME->cellheading);
View
8 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;

0 comments on commit 2c309dc

Please sign in to comment.