]> git.mjollnir.org Git - moodle.git/commitdiff
Added support for nonadmin course creation.
authorpaca70 <paca70>
Mon, 24 Feb 2003 18:48:55 +0000 (18:48 +0000)
committerpaca70 <paca70>
Mon, 24 Feb 2003 18:48:55 +0000 (18:48 +0000)
Course creators are managed by /admin/creator.php , same way that admins.
Or if authetication module have 'auth_iscreator'-function (right now only ldap-module have) ,
users are added to creators at login time.

20 files changed:
admin/creators.php [new file with mode: 0755]
admin/index.php
auth/ldap/config.html
auth/ldap/lib.php
course/edit.php
course/lib.php
course/teacher.php
index.php
lang/en/auth.php
lang/en/moodle.php
lang/fi/auth.php
lib/datalib.php
lib/db/mysql.php
lib/db/mysql.sql
lib/db/postgres7.php
lib/db/postgres7.sql
lib/moodlelib.php
lib/setup.php
login/index.php
version.php

diff --git a/admin/creators.php b/admin/creators.php
new file mode 100755 (executable)
index 0000000..d09dd2c
--- /dev/null
@@ -0,0 +1,168 @@
+<?PHP  
+      // Admin only  script to assign administrative rights to users
+      // !!! based on admin.php (cut and pasted, then mangled)
+
+       require_once("../config.php");
+
+    optional_variable($add, "");
+    optional_variable($remove, "");
+
+    if (! $site = get_site()) {
+        redirect("$CFG->wwwroot/admin/");
+    }
+
+    require_login();
+
+    if (!isadmin()) {
+        error("You must be an administrator to use this page.");
+    }
+
+    $primaryadmin = get_admin();
+
+/// If you want any administrator to have the ability to assign admin
+/// rights, then comment out the following if statement
+    if ($primaryadmin->id != $USER->id) {
+        error("You must be the primary administrator to use this page.");
+    }
+
+/// assign all of the configurable language strings
+    $stringstoload = array (
+        "assigncreators",
+        "administration",
+        "existingcreators",
+        "noexistingcreators",
+        "potentialcreators",
+        "nopotentialcreators",
+        "addcreator",
+        "removecreator",
+        "search",
+        "searchagain",
+        "toomanytoshow",
+        );
+
+    foreach ($stringstoload as $stringtoload){
+        $strstringtoload = "str" . $stringtoload;
+        $$strstringtoload = get_string($stringtoload);
+    }
+
+       print_header("$site->shortname: $course->shortname: $strassigncreators", 
+                 "$site->fullname", 
+                 "<A HREF=\"$CFG->wwwroot/admin\">$stradministration</A> -> 
+                  <A HREF=\"{$_SERVER['PHP_SELF']}\">$strassigncreators</A>", "");
+
+/// Get all existing creators
+    $creators = get_creators();
+
+/// Add an creator if one is specified
+    if ($_REQUEST['add']) {
+        $user = @get_record("user", "id", $_REQUEST['add']) or
+            error("That account (id = {$_REQUEST['add']}) doesn't exist");
+
+        if ($creators) {
+            foreach ($creators as $aa) {
+                if ($aa->id == $user->id) {
+                    error("That user is already a creator .");
+                }            
+            }
+        }
+
+        $creator->userid = $user->id;
+        $creator->id = insert_record("user_coursecreators", $creator);
+        $creators[] = $user;
+    }
+
+/// Remove an creator if one is specified.
+    if ($_REQUEST['remove']) {
+
+        $user = @get_record("user", "id", $_REQUEST['remove']) or 
+            error("That account (id = {$_REQUEST['remove']}) doesn't exist");
+
+        if ($creators) {
+            foreach ($creators as $key => $aa) {
+                if ($aa->id == $user->id) {
+                        delete_records("user_coursecreators","userid",$user->id);
+                        unset($creators[$key]);
+                } 
+            }
+        }
+    }
+
+
+/// Print the lists of existing and potential creators
+    echo "<TABLE CELLPADDING=2 CELLSPACING=10 ALIGN=CENTER>";
+    echo "<TR><TH WIDTH=50%>$strexistingcreators</TH><TH WIDTH=50%>$strpotentialcreators</TH></TR>";
+    echo "<TR><TD WIDTH=50% NOWRAP VALIGN=TOP>";
+
+/// First, show existing creators
+
+    if (! $creators) { 
+        echo "<P ALIGN=CENTER>$strnoexistingcreators</A>";
+
+    } else {
+        foreach ($creators as $creator) {
+            echo "<P ALIGN=right>$creator->firstname $creator->lastname,
+            $creator->email &nbsp;&nbsp; ";
+                echo "<A HREF=\"{$_SERVER['PHP_SELF']}?remove=$creator->id\"
+                TITLE=\"$strremovecreator\"><IMG SRC=\"../pix/t/right.gif\"
+                BORDER=0></A>";
+            echo "</P>";
+        }
+    }
+
+    echo "<TD WIDTH=50% NOWRAP VALIGN=TOP>";
+
+/// Print list of potential  creators
+
+    if ($search) {
+        $users = get_users_search($search);
+    } else {
+        $users = get_users_confirmed();
+    }
+
+    
+    if ($users) {
+        foreach ($users as $user) {  // Remove users who are already creators
+            if ($creators) {
+                foreach ($creators as $creator) {
+                    if ($creator->id == $user->id) {
+                        continue 2;
+                    }
+                }
+            }
+            $potential[] = $user;
+        }
+    }
+
+    if (! $potential) { 
+        echo "<P ALIGN=CENTER>$strnopotentialcreators</A>";
+        if ($search) {
+            echo "<FORM ACTION={$_SERVER['PHP_SELF']} METHOD=POST>";
+            echo "<INPUT TYPE=text NAME=search SIZE=20>";
+            echo "<INPUT TYPE=submit VALUE=\"$strsearchagain\">";
+            echo "</FORM>";
+        }
+
+    } else {
+        if ($search) {
+            echo "<P ALIGN=CENTER>($strsearchresults)</P>";
+        }
+        if (count($potential) <= 20) {
+            foreach ($potential as $user) {
+                echo "<P ALIGN=LEFT><A HREF=\"{$_SERVER['PHP_SELF']}?add=$user->id\"
+                TITLE=\"$straddcreator\"><IMG SRC=\"../pix/t/left.gif\" BORDER=0></A>&nbsp;&nbsp;$user->firstname $user->lastname, $user->email";
+            }
+        } else {
+            echo "<P ALIGN=CENTER>There are too many users to show.<BR>";
+            echo "Enter a search word here.";
+            echo "<FORM ACTION={$_SERVER['PHP_SELF']} METHOD=POST>";
+            echo "<INPUT TYPE=text NAME=search SIZE=20>";
+            echo "<INPUT TYPE=submit VALUE=\"$strsearch\">";
+            echo "</FORM>";
+        }
+    }
+
+    echo "</TR></TABLE>";
+
+    print_footer();
+
+?>
index d2da23f24ef0dcdc662d0d4de1707a6f6e141fc3..d057df515c8b4bb3bff4c7ee751f8294cee43907 100644 (file)
     }
 
 /// Check for valid admin user
-    if (!isadmin()) {
-        error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
+    if (!iscreator()) {
+        error("You need to be an admin user or teacher to use this page.", "$CFG->wwwroot/login/index.php");
     }
 
 
 
     $stradministration = get_string("administration");
     print_header("$site->shortname: $stradministration","$site->fullname: $stradministration", "$stradministration");
-
-    $table->head  = array (get_string("site"), get_string("courses"), get_string("users"));
-    $table->align = array ("CENTER", "CENTER", "CENTER");
-    $table->data[0][0] = "<P><A HREF=\"config.php\">".get_string("configvariables")."</A></P>".
+    if (isadmin()) {
+        $table->head  = array (get_string("site"), get_string("courses"), get_string("users"));
+               $table->align = array ("CENTER", "CENTER", "CENTER");
+               $table->data[0][0] = "<P><A HREF=\"config.php\">".get_string("configvariables")."</A></P>".
                          "<P><A HREF=\"site.php\">".get_string("sitesettings")."</A></P>".
                          "<P><A HREF=\"../course/log.php?id=$site->id\">".get_string("sitelogs")."</A></P>".
                          "<P><A HREF=\"../theme/index.php\">".get_string("choosetheme")."</A></P>".
                          "<P><A HREF=\"lang.php\">".get_string("checklanguage")."</A></P>";
-    if (file_exists("$CFG->dirroot/admin/$CFG->dbtype")) {
-        $table->data[0][0] .= "<P><A HREF=\"$CFG->dbtype/frame.php\">".get_string("managedatabase")."</A></P>";
-    }
-    $table->data[0][1] = "<P><A HREF=\"../course/edit.php\">".get_string("addnewcourse")."</A></P>".
+               if (file_exists("$CFG->dirroot/admin/$CFG->dbtype")) {
+            $table->data[0][0] .= "<P><A HREF=\"$CFG->dbtype/frame.php\">".get_string("managedatabase")."</A></P>";
+               }
+               $table->data[0][1] = "<P><A HREF=\"../course/edit.php\">".get_string("addnewcourse")."</A></P>".
                          "<P><A HREF=\"../course/teacher.php\">".get_string("assignteachers")."</A></P>".
                          "<P><A HREF=\"../course/delete.php\">".get_string("deletecourse")."</A></P>".
                          "<P><A HREF=\"../course/categories.php\">".get_string("categories")."</A></P>";
-    $table->data[0][2] = "<P><A HREF=\"user.php?newuser=true\">".get_string("addnewuser")."</A></P>".
+               $table->data[0][2] = "<P><A HREF=\"user.php?newuser=true\">".get_string("addnewuser")."</A></P>".
                          "<P><A HREF=\"user.php\">".get_string("edituser")."</A></P>".
                          "<P><A HREF=\"admin.php\">".get_string("assignadmins")."</A></P>".
+                         "<P><A HREF=\"creators.php\">".get_string("assigncreators")."</A></P>".
                          "<P><A HREF=\"auth.php\">".get_string("authentication")."</A></P>";
-
+    } else { /// user is coursecreator
+           $table->head  = array (get_string("courses"));
+               $table->align = array ("CENTER");
+               $table->data[0][1] = "<P><A HREF=\"../course/edit.php\">".get_string("addnewcourse")."</A></P>".
+                 "<P><A HREF=\"../course/teacher.php\">".get_string("assignteachers")."</A></P>";
+       }
+    
     print_table($table);
-
     echo "<BR><DIV align=center>";
     print_single_button("$CFG->wwwroot/doc", NULL, get_string("documentation"));
     echo "</DIV>";
index 22faf427dfd739a41ef958506cc3cc657f07e7d5..bb13d3b011d1a7cb7e68e6c84d7aed23bf12a113 100644 (file)
     </TD>
 </TR>
 
+<TR VALIGN=TOP BGCOLOR="<?=$THEME->cellheading2 ?>">
+        <TD ALIGN=RIGHT><P>ldap_memberattribute:</TD>
+        <TD>
+    <INPUT name=ldap_memberattribute TYPE=text SIZE=30 VALUE="<?=$config->ldap_memberattribute?>">
+    <? if (isset($err["ldap_memberattribute"])) formerr($err["ldap_memberattribute"]); ?>
+    </TD><TD>
+    <? print_string("auth_ldap_memberattribute","auth") ?>
+    </TD>
+</TR>
+
+<TR VALIGN=TOP BGCOLOR="<?=$THEME->cellheading2 ?>">
+        <TD ALIGN=RIGHT><P>ldap_creators:</TD>
+        <TD>
+    <INPUT name=ldap_creators TYPE=text SIZE=30 VALUE="<?=$config->ldap_creators?>">
+    <? if (isset($err["ldap_creators"])) formerr($err["ldap_creators"]); ?>
+    </TD><TD>
+    <? print_string("auth_ldap_creators","auth") ?>
+    </TD>
+</TR>
+
 <TR VALIGN=TOP BGCOLOR="<?=$THEME->cellheading2 ?>">
        <TD ALIGN=RIGHT><P>ldap_create_context:</TD>
        <TD>
index 8f42a5919ee6ab6ee379793707e24900000cc695..a1355d946cdb214bf3e53cc7a1c0f36389586a3d 100644 (file)
@@ -1,5 +1,6 @@
 <?PHP  // $Id$
 //CHANGELOG:
+//24.02.2003 Added support for coursecreators
 //20.02.2003 Added support for user creation
 //12.10.2002 Reformatted source for consistency
 //03.10.2002 First version to CVS
@@ -83,55 +84,14 @@ function auth_get_userinfo($username){
     return $result;
 }
 
-
-
-function auth_get_userlist($filter="*") {
-/// returns all users from ldap servers
+function auth_get_userlist () {
     global $CFG;
-
-    $fresult = array();
-    $ldap_connection = auth_ldap_connect();
-
-    auth_ldap_bind($ldap_connection);
-
-    if (! isset($CFG->ldap_objectclass)) {
-        $CFG->ldap_objectclass="objectClass=*";
-    }
-
-    $contexts = explode(";",$CFG->ldap_contexts);
-  
-    if (!empty($CFG->ldap_create_context)){
-         array_push($contexts, $CFG->ldap_create_context);
-    }
-
-    foreach ($contexts as $context) {
-
-        if ($CFG->ldap_search_sub) {
-            //use ldap_search to find first user from subtree
-            $ldap_result = ldap_search($ldap_connection, $context, 
-                                       "(&(".$CFG->ldap_user_attribute."=".$filter.")(".$CFG->ldap_objectclass."))", 
-                                       array($CFG->ldap_user_attribute));
-        } else {
-            //search only in this context
-            $ldap_result = ldap_list($ldap_connection, $context, 
-                                     "(&(".$CFG->ldap_user_attribute."=".$filter.")(".$CFG->ldap_objectclass."))",
-                                     array($CFG->ldap_user_attribute));
-        }
-
-        $users = ldap_get_entries($ldap_connection, $ldap_result);
-
-        //add found users to list
-        for ($i=0;$i<$users['count'];$i++) {
-            array_push($fresult, ($users[$i][$CFG->ldap_user_attribute][0]) );
-        }
-    }
-
-    return $fresult;
+    return auth_ldap_get_userlist("($CFG->ldap_user_attribute=*)");
 }
-
 function auth_user_exists ($username) {
-//returns true if given usernname exist on ldap
-   $users = auth_get_userlist($username);
+   global $CFG; 
+   //returns true if given usernname exist on ldap
+   $users = auth_ldap_get_userlist("($CFG->ldap_user_attribute=$username)");
    return count($users); 
 }
 
@@ -198,6 +158,37 @@ function auth_user_disable ($username) {
     return $result;
 }
 
+function auth_iscreator($username=0) {
+///if user is member of creator group return true
+   global $CFG, $USER;
+
+   $ldapconnect = auth_ldap_connect();
+   $ldapbind = auth_ldap_bind($ldapconnect);
+
+   if (! $username) {
+       $username=$USER->username;
+   }
+   
+   if ((! $CFG->ldap_creators) OR (! $CFG->ldap_memberattribute)) {
+      return false;
+   } else {
+      $groups = explode(";",$CFG->ldap_creators);
+   }
+
+
+   //build filter
+   $filter = "(& ($CFG->ldap_user_attribute=$username)(|";
+   foreach ($groups as $group){
+       $filter .= "($CFG->ldap_memberattribute=$group)";
+   }
+   $filter .= "))";
+   //search
+   $result = auth_ldap_get_userlist($filter);
+   
+   return count($result);
+
+}
+
 //PRIVATE FUNCTIONS starts
 //private functions are named as auth_ldap*
 
@@ -304,4 +295,53 @@ function auth_ldap_attributes (){
     }
        return $moodleattributes;
 }
+
+function auth_ldap_get_userlist($filter="*") {
+/// returns all users from ldap servers
+    global $CFG;
+
+    $fresult = array();
+    $ldap_connection = auth_ldap_connect();
+
+    auth_ldap_bind($ldap_connection);
+
+    if (! isset($CFG->ldap_objectclass)) {
+        $CFG->ldap_objectclass="objectClass=*";
+    }
+
+    if ($filter=="*") {
+       $filter = "(&(".$CFG->ldap_user_attribute."=*)(".$CFG->ldap_objectclass."))";
+    }
+
+    $contexts = explode(";",$CFG->ldap_contexts);
+    if (!empty($CFG->ldap_create_context)){
+          array_push($contexts, $CFG->ldap_create_context);
+    }
+
+    foreach ($contexts as $context) {
+
+        if ($CFG->ldap_search_sub) {
+            //use ldap_search to find first user from subtree
+            $ldap_result = ldap_search($ldap_connection, $context,
+                                       $filter,
+                                       array($CFG->ldap_user_attribute));
+        } else {
+            //search only in this context
+            $ldap_result = ldap_list($ldap_connection, $context,
+                                     $filter,
+                                     array($CFG->ldap_user_attribute));
+        }
+
+        $users = ldap_get_entries($ldap_connection, $ldap_result);
+
+        //add found users to list
+        for ($i=0;$i<$users['count'];$i++) {
+            array_push($fresult, ($users[$i][$CFG->ldap_user_attribute][0]) );
+        }
+    }
+   
+    return $fresult;
+}
+
 ?>
index 97f0a7588e16c088795039435f690be437fe5bde..f29b9c5d600c28b667d51c12683acc078e3b185b 100644 (file)
@@ -19,8 +19,8 @@
     } else {  // Admin is creating a new course
         require_login();
 
-        if (!isadmin()) {
-            error("Only administrators can use this page");
+        if (!iscreator()) {
+            error("Only administrators and teachers can use this page");
         }
     }
 
                     $section->id = insert_record("course_sections", $section);
 
                     add_to_log($newid, "course", "new", "view.php?id=$newid", "");
-                           redirect("teacher.php?id=$newid", get_string("changessaved"));
+                    $teacher = array();
+                    $teacher[userid] = $USER->id;
+                    $teacher[course] = $newid;
+                    $teacher[authority] = 1;   // First teacher is the main teacher
+                    
+                           $mainteacher = insert_record("user_teachers", $teacher);
+                    if (!$mainteacher) {
+                                         error("Could not add main teacher to new course!");
+                                       }
+                    
+                    redirect("teacher.php?id=$newid", get_string("changessaved"));
                 } else {
                     error("Serious Error! Could not create the new course!");
                 }
index 59f945028d478d0d7a2f7bda962788b9ea4d3c65..94ad198c966f3b54b199b8b1c827885da99d3fe7 100644 (file)
@@ -614,40 +614,48 @@ function print_admin_links ($siteid, $width=180) {
     global $CFG;
     
     $icon = "<IMG SRC=\"$CFG->wwwroot/pix/i/settings.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
-    $moddata[]="<A HREF=\"$CFG->wwwroot/admin/config.php\">".get_string("configvariables")."</A>";
-    $modicon[]=$icon;
-    $moddata[]="<A HREF=\"$CFG->wwwroot/admin/site.php\">".get_string("sitesettings")."</A>";
-    $modicon[]=$icon;
-    $moddata[]="<A HREF=\"$CFG->wwwroot/course/log.php?id=$siteid\">".get_string("sitelogs")."</A>";
-    $modicon[]=$icon;
-    $moddata[]="<A HREF=\"$CFG->wwwroot/theme/index.php\">".get_string("choosetheme")."</A>";
-    $modicon[]=$icon;
-    $moddata[]="<A HREF=\"$CFG->wwwroot/admin/lang.php\">".get_string("checklanguage")."</A>";
-    $modicon[]=$icon;
-    if (file_exists("$CFG->dirroot/admin/$CFG->dbtype")) {
-        $moddata[]="<A HREF=\"$CFG->wwwroot/admin/$CFG->dbtype/frame.php\">".get_string("managedatabase")."</A>";
-        $modicon[]=$icon;
-    }
-    $moddata[]="<HR>";
-    $modicon[]="";
-    $moddata[]="<A HREF=\"$CFG->wwwroot/course/edit.php\">".get_string("addnewcourse")."</A>";
-    $modicon[]=$icon;
-    $moddata[]="<A HREF=\"$CFG->wwwroot/course/categories.php\">".get_string("categories")."</A>";
-    $modicon[]=$icon;
-    $moddata[]="<A HREF=\"$CFG->wwwroot/course/teacher.php\">".get_string("assignteachers")."</A>";
-    $modicon[]=$icon;
-    $moddata[]="<A HREF=\"$CFG->wwwroot/course/delete.php\">".get_string("deletecourse")."</A>";
-    $modicon[]=$icon;
-    $moddata[]="<HR>";
-    $modicon[]="";
-    $moddata[]="<A HREF=\"$CFG->wwwroot/admin/user.php?newuser=true\">".get_string("addnewuser")."</A>";
-    $modicon[]=$icon;
-    $moddata[]="<A HREF=\"$CFG->wwwroot/admin/user.php\">".get_string("edituser")."</A>";
-    $modicon[]=$icon;
-    $moddata[]="<A HREF=\"$CFG->wwwroot/admin/admin.php\">".get_string("assignadmins")."</A>";
-    $modicon[]=$icon;
-    $moddata[]="<A HREF=\"$CFG->wwwroot/admin/auth.php\">".get_string("authentication")."</A>";
-    $modicon[]=$icon;
+    if (isadmin()) {
+           $moddata[]="<A HREF=\"$CFG->wwwroot/admin/config.php\">".get_string("configvariables")."</A>";
+               $modicon[]=$icon;
+               $moddata[]="<A HREF=\"$CFG->wwwroot/admin/site.php\">".get_string("sitesettings")."</A>";
+               $modicon[]=$icon;
+               $moddata[]="<A HREF=\"$CFG->wwwroot/course/log.php?id=$siteid\">".get_string("sitelogs")."</A>";
+               $modicon[]=$icon;
+               $moddata[]="<A HREF=\"$CFG->wwwroot/theme/index.php\">".get_string("choosetheme")."</A>";
+               $modicon[]=$icon;
+               $moddata[]="<A HREF=\"$CFG->wwwroot/admin/lang.php\">".get_string("checklanguage")."</A>";
+               $modicon[]=$icon;
+               if (file_exists("$CFG->dirroot/admin/$CFG->dbtype")) {
+            $moddata[]="<A HREF=\"$CFG->wwwroot/admin/$CFG->dbtype/frame.php\">".get_string("managedatabase")."</A>";
+                       $modicon[]=$icon;
+               }
+               $moddata[]="<HR>";
+               $modicon[]="";
+    }
+    if (iscreator()) {
+           $moddata[]="<A HREF=\"$CFG->wwwroot/course/edit.php\">".get_string("addnewcourse")."</A>";
+               $modicon[]=$icon;
+               $moddata[]="<A HREF=\"$CFG->wwwroot/course/teacher.php\">".get_string("assignteachers")."</A>";
+               $modicon[]=$icon;
+    }
+    if (isadmin()) {
+           $moddata[]="<A HREF=\"$CFG->wwwroot/course/categories.php\">".get_string("categories")."</A>";
+               $modicon[]=$icon;
+               $moddata[]="<A HREF=\"$CFG->wwwroot/course/delete.php\">".get_string("deletecourse")."</A>";
+               $modicon[]=$icon;
+               $moddata[]="<HR>";
+               $modicon[]="";
+               $moddata[]="<A HREF=\"$CFG->wwwroot/admin/user.php?newuser=true\">".get_string("addnewuser")."</A>";
+               $modicon[]=$icon;
+               $moddata[]="<A HREF=\"$CFG->wwwroot/admin/user.php\">".get_string("edituser")."</A>";
+               $modicon[]=$icon;
+               $moddata[]="<A HREF=\"$CFG->wwwroot/admin/admin.php\">".get_string("assignadmins")."</A>";
+               $modicon[]=$icon;
+        $moddata[]="<A HREF=\"$CFG->wwwroot/admin/admin.php\">".get_string("assigncreators")."</A>";
+               $modicon[]=$icon;
+               $moddata[]="<A HREF=\"$CFG->wwwroot/admin/auth.php\">".get_string("authentication")."</A>";
+               $modicon[]=$icon;
+    }
     $fulladmin = "<P><A HREF=\"$CFG->wwwroot/admin/\">".get_string("admin")."</A>...";
 
     print_side_block(get_string("administration"), "", $moddata, $modicon, $fulladmin, $width);
index fce25fbd7824d4dd326c02a46b5b15daa50e85ec..6e5656481f0f2203f40dac3968aa5f1534019a9f 100644 (file)
@@ -12,8 +12,8 @@
 
     require_login();
 
-    if (!isadmin()) {
-        error("You must be an administrator to use this page.");
+    if (!iscreator()) {
+        error("You must be an administrator or teacher to use this page.");
     }
 
     $strassignteachers = get_string("assignteachers");
     if (!$id) {
            print_header("$site->shortname: $strassignteachers", "$site->fullname", 
                      "<A HREF=\"$CFG->wwwroot/admin\">$stradministration</A> -> $strassignteachers");
-
-        if ($courses = get_courses()) {
-
-            print_heading(get_string("choosecourse"));
-            print_simple_box_start("CENTER");
-            foreach ($courses as $course) {
-                echo "<A HREF=\"teacher.php?id=$course->id\">$course->fullname</A><BR>";
-            }
-            print_simple_box_end();
-        } else {
+        
+        $isadmin = isadmin(); /// cache value
+        $courses = get_courses();
+        
+
+               print_heading(get_string("choosecourse"));
+               print_simple_box_start("CENTER");
+        
+               foreach ($courses as $course) {
+                   if ($isadmin OR ismainteacher($course->id, $USER->id)){
+                           echo "<A HREF=\"teacher.php?id=$course->id\">$course->fullname</A><BR>\n";
+                               $coursesfound = TRUE;
+                       }
+               }       
+               
+        print_simple_box_end();
+        
+        if ($coursesfound == FALSE) {         
             print_heading(get_string("nocoursesyet"));
             print_continue("$CFG->wwwroot/admin/");
         }
+
         print_footer();
         exit;
     }
 /// Add a teacher if one is specified
 
     if (!empty($add)) {
+           if (!ismainteacher($course->id, $USER->id)){
+                   error("You must be an administrator or teacher to modify this course.");
+        }
+
         if (! $user = get_record("user", "id", $add)) {
             error("That teacher (id = $add) doesn't exist", "teacher.php?id=$course->id");
         }
 /// Remove a teacher if one is specified.
 
     if (!empty($remove)) {
+
+        if (!ismainteacher($course->id, $USER->id)){
+               error("You must be an administrator or teacher to modify this course.");
+               }
         if (! $user = get_record("user", "id", $remove)) {
             error("That teacher (id = $remove) doesn't exist", "teacher.php?id=$course->id");
         }
index ec259321bcb9c0dfe76a021227dc6619049b1088..d9c8cb91947f6e8ddb6e94ef1bc36e985b7cfdae 100644 (file)
--- a/index.php
+++ b/index.php
@@ -65,7 +65,7 @@
          print_spacer(1,$side);
      }
  
-     if (isadmin()) {
+     if (iscreator()) {
          if (!$firstcolumn) {
              echo "<TD WIDTH=\"$side\" VALIGN=TOP NOWRAP>"; $firstcolumn=true;
          }
index 1e8c10714121cbd23a20b0679ee2c4a6f08275ba..3a6e8b20a62887dfbb3d08722790fd0005258998 100644 (file)
@@ -26,7 +26,9 @@ $string['auth_ldap_bind_dn'] = "If you want to use bind-user to search users, sp
 $string['auth_ldap_create_context'] = "If you enable user creation with email confirmation, specify context where users are created. This context should be different from other users to prevent security issues. You don't need to add this context to ldap_context-variable, Moodle will search for users from this context automaticly.";
 $string['auth_ldap_bind_pw'] = "Password for bind-user.";
 $string['auth_ldap_contexts'] = "List of contexts where users are located. Separate different contexts with ';'. For example: 'ou=users,o=org; ou=others,o=org'";
+$string['auth_ldap_creators'] = "List of groups what member are allowed to create new courses. Separate multiple groups with ';'. Usualy something like 'cn=teachers,ou=staff,o=myorg'";
 $string['auth_ldap_host_url'] = "Specify LDAP host in URL-form like 'ldap://ldap.myorg.com/' or 'ldaps://ldap.myorg.com/' ";
+$string['auth_ldap_memberattribute'] = "Specify users member attribute, when users belogs to group. Usualy member";
 $string['auth_ldap_search_sub'] = "Put value &lt;&gt; 0 if  you like to search users from subcontexts.";
 $string['auth_ldap_update_userinfo'] = "Update user information (firstname, lastname, address..) from LDAP to Moodle. Look at /auth/ldap/attr_mappings.php for mapping information";
 $string['auth_ldap_user_attribute'] = "The attribute used to name/search users. Usually 'cn'.";
index 07a04f6fe43e4148f46c8547ae254c31660e17a1..a7d32190b57d61c63c224e508f1c7e32d5b0831d 100644 (file)
@@ -15,6 +15,7 @@ $string['addnewcourse'] = "Add a new course";
 $string['addnewuser'] = "Add a new user";
 $string['address'] = "Address";
 $string['addadmin'] = "Add admin";
+$string['addcreator'] = "Add course creator";
 $string['addteacher'] = "Add teacher";
 $string['admin'] = "Admin";
 $string['administration'] = "Administration";
@@ -32,6 +33,7 @@ $string['alreadyconfirmed'] = "Registration has already been confirmed";
 $string['answer'] = "Answer";
 $string['assessment'] = "Assessment";
 $string['assignadmins'] = "Assign admins";
+$string['assigncreators'] = "Assign course creators";
 $string['assignteachers'] = "Assign teachers";
 $string['authentication'] = "Authentication";
 $string['availablecourses'] = "Available Courses";
@@ -169,6 +171,7 @@ $string['enteremailaddress'] = "Enter in your email address to reset your
 $string['error'] = "Error";
 $string['errortoomanylogins'] = "Sorry, you have exceeded the allowed number of login attempts. Restart your browser.";
 $string['existingadmins'] = "Existing admins";
+$string['existingcreators'] = "Existing course creators";
 $string['existingteachers'] = "Existing teachers";
 $string['feedback'] = "Feedback";
 $string['filemissing'] = "\$a is missing";
@@ -370,12 +373,14 @@ $string['never'] = "Never";
 $string['no'] = "No";
 $string['nocoursesyet'] = "No courses in this category";
 $string['noexistingadmins'] = "No existing admins, this is a serious error and you should never have seen this message.";
+$string['noexistingcreators'] = "No existing creators";
 $string['noexistingteachers'] = "No existing teachers";
 $string['nofilesyet'] = "No files have been uploaded to your course yet";
 $string['nograde'] = "No grade";
 $string['noimagesyet'] = "No images have been uploaded to your course yet";
 $string['none'] = "None";
 $string['nopotentialadmins'] = "No potential admins";
+$string['nopotentialcreators'] = "No potential course creators";
 $string['nopotentialteachers'] = "No potential teachers";
 $string['normal'] = "Normal";
 $string['nostudentsyet'] = "No students enrolled in this course yet";
@@ -413,6 +418,7 @@ $string['people'] = "People";
 $string['personalprofile'] = "Personal profile";
 $string['phone'] = "Phone";
 $string['potentialadmins'] = "Potential admins";
+$string['potentialcreators'] = "Potential course creators";
 $string['potentialteachers'] = "Potential teachers";
 $string['preferredlanguage'] = "Preferred language";
 $string['preview'] = "Preview";
@@ -421,6 +427,7 @@ $string['question'] = "Question";
 $string['readme'] = "README";   // This is a file name
 $string['recentactivity'] = "Recent activity";
 $string['removeadmin'] = "Remove admin";
+$string['removecreator'] = "Remove course creator";
 $string['removeteacher'] = "Remove teacher";
 $string['rename'] = "Rename";
 $string['resources'] = "Resources";
index 6a18613a97de5a6f0651888d20ac93cd76fb6491..48517a14500d68cca5ae1d6404780f96bf144df0 100644 (file)
@@ -25,6 +25,7 @@ $string['auth_imaptype'] = "IMAP-palvelimen tyyppi.  katso ohjeesta (yll
 $string['auth_ldap_bind_dn'] = "Jos haluat käyttää välitys-käyttäjää yhteyden muodostamiseen,määriritä se tähän. Esim. 'cn=ldapuser,ou=public,o=org'";
 $string['auth_ldap_bind_pw'] = "Salasana välityskäyttäjälle.";
 $string['auth_ldap_contexts'] = "Lista konteksteista joisssa käyttäjät sijaitsevat. Erota kontekstit toisistaan ';'-merkillä. Esim: 'ou=users,o=org; ou=others,o=org'";
+$string['auth_ldap_create_context'] = "Jos luoda käyttäjät automaattisesti ldap-hakemistoon, määritä tässä konteksti jonne käyttäjät luodaan. On hyvä käyttää jotain eritystä kontekstia, jotta vältyt tietoturva riskeiltä.";
 $string['auth_ldap_host_url'] = "Määritä LDAP-palvelin URL-muodossa. Esim. 'ldap://ldap.myorg.com/' tai 'ldaps://ldap.myorg.com/' ";
 $string['auth_ldap_search_sub'] = "Aseta arvo &lt;&gt; 0 jos haluat hakea käyttäjiä myös alikonteksteista.";
 $string['auth_ldap_update_userinfo'] = "Päivitä käyttäjätiedot LDAP:ista moodleen (firstname, lastname, address..) .";
@@ -47,6 +48,9 @@ $string['auth_pop3host'] = "POP3 palvelimen osoite. K
 $string['auth_pop3port'] = "Palvelimen portti (110 , yleensä)";
 $string['auth_pop3title'] = "Käytä POP3-palvelinta";
 $string['auth_pop3type'] = "Palvelimen tyyppi. Jos käytätte salattua yhteyttä valitse pop3cert.";
+$string['auth_user_create'] = "Käyttäjän luonti";
+$string['auth_user_creation'] = "Vooivatko  käyttäjät voivat itse luoda tunnuksensa. Käyttäjä tiedot tarkistetaan sähköpostin avulla. Jos aktivoit tämän vaihtoehdon , muista myös määritellä autentikointi-modulin muut asetukset tähän liittyen.";
+$string['auth_usernameexists'] = "Käyttäjätunnus on jo käytössä. Valitse joku toinen.";
 $string['authenticationoptions'] = "Käyttäjätunnistus asetukset";
 $string['authinstructions'] = "Tähän voi kirjoittaa ohjeet opiskelijoille mitä tunnusta ja salasanaa heidän tulisi käyttää. Tämä teksti näkyy kirjaantumissivulla.";
 $string['changepassword'] = "Salasanan vaihto URL";
index 1293c7559810248ce900c2f8926eb2289c87a993..91787ecbad30c6667c8e7e751915455bcf78a7be 100644 (file)
@@ -790,6 +790,17 @@ function get_admins() {
                              ORDER BY u.id ASC");
 }
 
+function get_creators() {
+/// Returns list of all admins
+
+    global $CFG;
+
+    return get_records_sql("SELECT u.*
+                              FROM {$CFG->prefix}user u,
+                                   {$CFG->prefix}user_coursecreators a
+                             WHERE a.userid = u.id
+                             ORDER BY u.id ASC");
+}
 
 function get_teacher($courseid) {
 /// Returns $user object of the main teacher for a course
index e3a63006863bf1de321db3393a64e8fcac4acb26..6b4f86f8d3caf08a7901094c3ab28f0a5f869ee3 100644 (file)
@@ -254,6 +254,15 @@ function main_upgrade($oldversion=0) {
         execute_sql(" ALTER TABLE `log_display` CHANGE `module` `module` VARCHAR( 20 ) NOT NULL ");
     }
 
+       if ($oldversion < 2003032400) {
+           execute_sql("CREATE TABLE `$CFG->prefix_user_coursecreators` (
+                                   `id` int(10) unsigned NOT NULL auto_increment,
+                                   `userid` int(10) unsigned NOT NULL default '0',
+                                    PRIMARY KEY  (`id`),
+                                   UNIQUE KEY `id` (`id`)
+                                   ) TYPE=MyISAM COMMENT='One record per course creator'");
+       }
+
     return true;
 }
 
index 30ffb850977c8f0153ae455081e7ffb5bc6ab4c4..5e65510d1856a2c7deb36da9560c7b55272ce203 100644 (file)
@@ -227,6 +227,18 @@ CREATE TABLE `prefix_user_teachers` (
   UNIQUE KEY `id` (`id`)
 ) TYPE=MyISAM COMMENT='One record per teacher per course';
 
+#
+# Table structure for table `user_admins`
+#
+
+CREATE TABLE `prefix_user_coursecreators` (
+  `id` int(10) unsigned NOT NULL auto_increment,
+  `userid` int(10) unsigned NOT NULL default '0',
+  PRIMARY KEY  (`id`),
+  UNIQUE KEY `id` (`id`)
+) TYPE=MyISAM COMMENT='One record per course creator';
+# --------------------------------------------------------
+
 INSERT INTO prefix_log_display VALUES ('user', 'view', 'user', 'CONCAT(firstname," ",lastname)');
 INSERT INTO prefix_log_display VALUES ('course', 'view', 'course', 'fullname');
 INSERT INTO prefix_log_display VALUES ('course', 'update', 'course', 'fullname');
index 6d71be1f0f8851e996af9877924cd91da0953b29..e9a184f350bcc28711e5a8240195e9eef79397c1 100644 (file)
@@ -38,7 +38,15 @@ function main_upgrade($oldversion=0) {
         $new->action = "enrol";
         insert_record("log_display", $new);
     }
-
+    
+       //support user based course creating
+    if ($oldversion < 2003032400) {
+           execute_sql("CREATE TABLE $CFG->prefix_user_coursecreators (
+                                  id int8 SERIAL PRIMARY KEY,
+                                  userid int8  NOT NULL default '0'
+                                  )");
+       }
+       
     return true;
 }
 
index d82c8fca21eed4513676151d7ef34cc21947b476..8dc0153f933c3977008c2a36735f00e099dab5eb 100644 (file)
@@ -135,6 +135,10 @@ CREATE TABLE prefix_user_teachers (
    role varchar(40) NOT NULL default ''
 );
 
+CREATE TABLE mdl_user_coursecreators (
+   id SERIAL8 PRIMARY KEY,
+   userid int8  NOT NULL default '0'
+);
 
 INSERT INTO prefix_log_display VALUES ('user', 'view', 'user', 'CONCAT(firstname," ",lastname)');
 INSERT INTO prefix_log_display VALUES ('course', 'view', 'course', 'fullname');
index 3d4dc00d732276666679ff2077ff322fbbf22f18..0c3bf455305d06463599268cd0983859a2e60c6d 100644 (file)
@@ -405,6 +405,29 @@ function isteacher($courseid, $userid=0) {
     return record_exists("user_teachers", "userid", $userid, "course", $courseid);
 }
 
+function iscreator ($userid=0) {
+/// Can user create new courses?
+    global $USER;
+    if (isadmin($userid)) {  // admins can do anything
+        return true;
+    }
+       if (empty($userid)) {
+        return record_exists("user_coursecreators", "userid", $USER->id);
+    }
+
+    return record_exists("user_coursecreators", "userid", $userid);
+}
+
+function ismainteacher ($course, $userid){
+///is user the main teacher of course
+global $USER;
+
+    if (isadmin($userid)) {  // admins can do anything the teacher can
+        return true;
+    }
+    
+    return record_exists("user_teachers", "userid", $userid, "course", $course, "authority","1");
+}
 
 function isstudent($courseid, $userid=0) {
 /// Is the user a student in this course?
@@ -540,8 +563,26 @@ function authenticate_user_login($username, $password) {
     require_once("$CFG->dirroot/auth/$CFG->auth/lib.php");
 
     if (auth_user_login($username, $password)) {  // Successful authentication
-
         if ($user = get_user_info_from_db("username", $username)) {
+          if (function_exists('auth_iscreator')) {
+             if (auth_iscreator($username)) {
+                 if (! record_exists("user_coursecreators", "userid", $user->id)) {
+                     $cdata['userid']=$user->id;
+                     $creator = insert_record("user_coursecreators",$cdata);
+                     if (! $creator) {
+                         error("Cannot add user to course creators.");
+                     }
+                 }
+             } else {
+                 if ( record_exists("user_coursecreators", "userid", $user->id)) {
+                    $creator = delete_record("user_coursecreators", "userid", $user->id);
+                    if (! $creator) {
+                         error("Cannot remove user from course creators.");
+                    }
+                 }
+            }
+          }
+
             if ($md5password <> $user->password) {   // Update local copy of password for reference
                 set_field("user", "password", $md5password, "username", $username);
             }
index 198e866ff38e1a0935fc6be916d50c3bed842a42..9a1f7da4e37dd6c59da15dc5689d75c1b0540e68 100644 (file)
 
     class object {};
     
-    session_start();
+    @session_start();
     if (! isset($_SESSION["SESSION"])) { $_SESSION["SESSION"] = new object; }
     if (! isset($_SESSION["USER"]))    { $_SESSION["USER"]    = new object; }
     extract($_SESSION);  // Makes $SESSION and $USER available for read-only access
index 3fd4e2d5e7c7ca837e6b1f33242b74af11391bf1..25fd20a9e2f4f6ab99aab863ad9bd13478e0d9f4 100644 (file)
@@ -37,6 +37,7 @@
             $USER = $user;
             $USER->loggedin = true;
             $USER->site = $CFG->wwwroot;   // for added security
+            
             if ($USER->username == "guest") {
                 $USER->lang = $CFG->lang;  // Guest language always same as site
             }
@@ -45,7 +46,7 @@
             if (!update_user_in_db()) {
                 error("Weird error: User not found");
             }
-
+            
             if (!update_user_login_times()) {
                 error("Wierd error: could not update login records");
             }
index 748327b834542d0acf6f4e1f84f2911f734cfe67..f6d13655bee28259143c3fcd721f621f95c3ad76 100644 (file)
@@ -5,7 +5,7 @@
 // database to determine whether upgrades should
 // be performed (see lib/db/*.php)
 
-$version = 2003021600;   // The current version is a date (YYYYMMDDXX)
+$version = 2003032400;   // The current version is a date (YYYYMMDDXX)
 
 $release = "1.0.9 development";  // User-friendly version number