]> git.mjollnir.org Git - moodle.git/commitdiff
Definition and use of new isediting() function for checking whether a user
authormartin <martin>
Mon, 29 Jul 2002 15:45:46 +0000 (15:45 +0000)
committermartin <martin>
Mon, 29 Jul 2002 15:45:46 +0000 (15:45 +0000)
is not only in editing mode, but ALLOWED to be editing the current course.
Used to show editing buttons etc

course/social.php
course/weeks.php
index.php
lib/moodlelib.php

index b75d58b453cda1980d9d4d6be86d8036f32d32b1..4c08863e977204d4afe72c3858264e57516c2bc7 100644 (file)
@@ -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>";
index 2fb3834d032781a410a116430e72772455b6f612..b73bcd5d4cf36dd49578c93690421f0fb512fda7 100644 (file)
@@ -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>";
             $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>";
         }
 
                 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...");
index b62f76cff16736419c39db9e953bc911d14546ba..7be9cf89389bf14c1da1dcd3bdbcc331d6530c20 100644 (file)
--- a/index.php
+++ b/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);
index 8d40bb7b0a128a87bc58a102bb85c81aaa70e246..def4c7c1b86e2de857d6a2e98585fd69d1c0e2be 100644 (file)
@@ -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;