From 1924074c762cdcac5c3f58a2bb575943f56d8578 Mon Sep 17 00:00:00 2001 From: paca70 Date: Mon, 24 Feb 2003 18:48:55 +0000 Subject: [PATCH] Added support for nonadmin course creation. 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. --- admin/creators.php | 168 ++++++++++++++++++++++++++++++++++++++++++ admin/index.php | 32 ++++---- auth/ldap/config.html | 20 +++++ auth/ldap/lib.php | 132 +++++++++++++++++++++------------ course/edit.php | 16 +++- course/lib.php | 76 ++++++++++--------- course/teacher.php | 41 ++++++++--- index.php | 2 +- lang/en/auth.php | 2 + lang/en/moodle.php | 7 ++ lang/fi/auth.php | 4 + lib/datalib.php | 11 +++ lib/db/mysql.php | 9 +++ lib/db/mysql.sql | 12 +++ lib/db/postgres7.php | 10 ++- lib/db/postgres7.sql | 4 + lib/moodlelib.php | 43 ++++++++++- lib/setup.php | 2 +- login/index.php | 3 +- version.php | 2 +- 20 files changed, 482 insertions(+), 114 deletions(-) create mode 100755 admin/creators.php diff --git a/admin/creators.php b/admin/creators.php new file mode 100755 index 0000000000..d09dd2c898 --- /dev/null +++ b/admin/creators.php @@ -0,0 +1,168 @@ +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", + "wwwroot/admin\">$stradministration -> + $strassigncreators", ""); + +/// 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 ""; + echo ""; + echo "
$strexistingcreators$strpotentialcreators
"; + +/// First, show existing creators + + if (! $creators) { + echo "

$strnoexistingcreators"; + + } else { + foreach ($creators as $creator) { + echo "

$creator->firstname $creator->lastname, + $creator->email    "; + echo "id\" + TITLE=\"$strremovecreator\">"; + echo "

"; + } + } + + echo "
"; + +/// 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 "

$strnopotentialcreators"; + if ($search) { + echo "

"; + echo ""; + echo ""; + echo "
"; + } + + } else { + if ($search) { + echo "

($strsearchresults)

"; + } + if (count($potential) <= 20) { + foreach ($potential as $user) { + echo "

id\" + TITLE=\"$straddcreator\">  $user->firstname $user->lastname, $user->email"; + } + } else { + echo "

There are too many users to show.
"; + echo "Enter a search word here."; + echo "

"; + echo ""; + echo ""; + echo "
"; + } + } + + echo "
"; + + print_footer(); + +?> diff --git a/admin/index.php b/admin/index.php index d2da23f24e..d057df515c 100644 --- a/admin/index.php +++ b/admin/index.php @@ -315,8 +315,8 @@ } /// 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"); } @@ -324,28 +324,34 @@ $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] = "

".get_string("configvariables")."

". + if (isadmin()) { + $table->head = array (get_string("site"), get_string("courses"), get_string("users")); + $table->align = array ("CENTER", "CENTER", "CENTER"); + $table->data[0][0] = "

".get_string("configvariables")."

". "

".get_string("sitesettings")."

". "

id\">".get_string("sitelogs")."

". "

".get_string("choosetheme")."

". "

".get_string("checklanguage")."

"; - if (file_exists("$CFG->dirroot/admin/$CFG->dbtype")) { - $table->data[0][0] .= "

dbtype/frame.php\">".get_string("managedatabase")."

"; - } - $table->data[0][1] = "

".get_string("addnewcourse")."

". + if (file_exists("$CFG->dirroot/admin/$CFG->dbtype")) { + $table->data[0][0] .= "

dbtype/frame.php\">".get_string("managedatabase")."

"; + } + $table->data[0][1] = "

".get_string("addnewcourse")."

". "

".get_string("assignteachers")."

". "

".get_string("deletecourse")."

". "

".get_string("categories")."

"; - $table->data[0][2] = "

".get_string("addnewuser")."

". + $table->data[0][2] = "

".get_string("addnewuser")."

". "

".get_string("edituser")."

". "

".get_string("assignadmins")."

". + "

".get_string("assigncreators")."

". "

".get_string("authentication")."

"; - + } else { /// user is coursecreator + $table->head = array (get_string("courses")); + $table->align = array ("CENTER"); + $table->data[0][1] = "

".get_string("addnewcourse")."

". + "

".get_string("assignteachers")."

"; + } + print_table($table); - echo "
"; print_single_button("$CFG->wwwroot/doc", NULL, get_string("documentation")); echo "
"; diff --git a/auth/ldap/config.html b/auth/ldap/config.html index 22faf427df..bb13d3b011 100644 --- a/auth/ldap/config.html +++ b/auth/ldap/config.html @@ -82,6 +82,26 @@ + +

ldap_memberattribute: + + + + + + + + + +

ldap_creators: + + + + + + + +

ldap_create_context: diff --git a/auth/ldap/lib.php b/auth/ldap/lib.php index 8f42a5919e..a1355d946c 100644 --- a/auth/ldap/lib.php +++ b/auth/ldap/lib.php @@ -1,5 +1,6 @@ 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; +} + ?> diff --git a/course/edit.php b/course/edit.php index 97f0a7588e..f29b9c5d60 100644 --- a/course/edit.php +++ b/course/edit.php @@ -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"); } } @@ -58,7 +58,17 @@ $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!"); } diff --git a/course/lib.php b/course/lib.php index 59f945028d..94ad198c96 100644 --- a/course/lib.php +++ b/course/lib.php @@ -614,40 +614,48 @@ function print_admin_links ($siteid, $width=180) { global $CFG; $icon = "wwwroot/pix/i/settings.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">"; - $moddata[]="wwwroot/admin/config.php\">".get_string("configvariables").""; - $modicon[]=$icon; - $moddata[]="wwwroot/admin/site.php\">".get_string("sitesettings").""; - $modicon[]=$icon; - $moddata[]="wwwroot/course/log.php?id=$siteid\">".get_string("sitelogs").""; - $modicon[]=$icon; - $moddata[]="wwwroot/theme/index.php\">".get_string("choosetheme").""; - $modicon[]=$icon; - $moddata[]="wwwroot/admin/lang.php\">".get_string("checklanguage").""; - $modicon[]=$icon; - if (file_exists("$CFG->dirroot/admin/$CFG->dbtype")) { - $moddata[]="wwwroot/admin/$CFG->dbtype/frame.php\">".get_string("managedatabase").""; - $modicon[]=$icon; - } - $moddata[]="


"; - $modicon[]=""; - $moddata[]="wwwroot/course/edit.php\">".get_string("addnewcourse").""; - $modicon[]=$icon; - $moddata[]="wwwroot/course/categories.php\">".get_string("categories").""; - $modicon[]=$icon; - $moddata[]="wwwroot/course/teacher.php\">".get_string("assignteachers").""; - $modicon[]=$icon; - $moddata[]="wwwroot/course/delete.php\">".get_string("deletecourse").""; - $modicon[]=$icon; - $moddata[]="
"; - $modicon[]=""; - $moddata[]="wwwroot/admin/user.php?newuser=true\">".get_string("addnewuser").""; - $modicon[]=$icon; - $moddata[]="wwwroot/admin/user.php\">".get_string("edituser").""; - $modicon[]=$icon; - $moddata[]="wwwroot/admin/admin.php\">".get_string("assignadmins").""; - $modicon[]=$icon; - $moddata[]="wwwroot/admin/auth.php\">".get_string("authentication").""; - $modicon[]=$icon; + if (isadmin()) { + $moddata[]="wwwroot/admin/config.php\">".get_string("configvariables").""; + $modicon[]=$icon; + $moddata[]="wwwroot/admin/site.php\">".get_string("sitesettings").""; + $modicon[]=$icon; + $moddata[]="wwwroot/course/log.php?id=$siteid\">".get_string("sitelogs").""; + $modicon[]=$icon; + $moddata[]="wwwroot/theme/index.php\">".get_string("choosetheme").""; + $modicon[]=$icon; + $moddata[]="wwwroot/admin/lang.php\">".get_string("checklanguage").""; + $modicon[]=$icon; + if (file_exists("$CFG->dirroot/admin/$CFG->dbtype")) { + $moddata[]="wwwroot/admin/$CFG->dbtype/frame.php\">".get_string("managedatabase").""; + $modicon[]=$icon; + } + $moddata[]="
"; + $modicon[]=""; + } + if (iscreator()) { + $moddata[]="wwwroot/course/edit.php\">".get_string("addnewcourse").""; + $modicon[]=$icon; + $moddata[]="wwwroot/course/teacher.php\">".get_string("assignteachers").""; + $modicon[]=$icon; + } + if (isadmin()) { + $moddata[]="wwwroot/course/categories.php\">".get_string("categories").""; + $modicon[]=$icon; + $moddata[]="wwwroot/course/delete.php\">".get_string("deletecourse").""; + $modicon[]=$icon; + $moddata[]="
"; + $modicon[]=""; + $moddata[]="wwwroot/admin/user.php?newuser=true\">".get_string("addnewuser").""; + $modicon[]=$icon; + $moddata[]="wwwroot/admin/user.php\">".get_string("edituser").""; + $modicon[]=$icon; + $moddata[]="wwwroot/admin/admin.php\">".get_string("assignadmins").""; + $modicon[]=$icon; + $moddata[]="wwwroot/admin/admin.php\">".get_string("assigncreators").""; + $modicon[]=$icon; + $moddata[]="wwwroot/admin/auth.php\">".get_string("authentication").""; + $modicon[]=$icon; + } $fulladmin = "

wwwroot/admin/\">".get_string("admin")."..."; print_side_block(get_string("administration"), "", $moddata, $modicon, $fulladmin, $width); diff --git a/course/teacher.php b/course/teacher.php index fce25fbd78..6e5656481f 100644 --- a/course/teacher.php +++ b/course/teacher.php @@ -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"); @@ -31,19 +31,28 @@ if (!$id) { print_header("$site->shortname: $strassignteachers", "$site->fullname", "wwwroot/admin\">$stradministration -> $strassignteachers"); - - if ($courses = get_courses()) { - - print_heading(get_string("choosecourse")); - print_simple_box_start("CENTER"); - foreach ($courses as $course) { - echo "id\">$course->fullname
"; - } - 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 "id\">$course->fullname
\n"; + $coursesfound = TRUE; + } + } + + print_simple_box_end(); + + if ($coursesfound == FALSE) { print_heading(get_string("nocoursesyet")); print_continue("$CFG->wwwroot/admin/"); } + print_footer(); exit; } @@ -67,6 +76,10 @@ /// 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"); } @@ -96,6 +109,10 @@ /// 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"); } diff --git a/index.php b/index.php index ec259321bc..d9c8cb9194 100644 --- a/index.php +++ b/index.php @@ -65,7 +65,7 @@ print_spacer(1,$side); } - if (isadmin()) { + if (iscreator()) { if (!$firstcolumn) { echo ""; $firstcolumn=true; } diff --git a/lang/en/auth.php b/lang/en/auth.php index 1e8c107141..3a6e8b20a6 100644 --- a/lang/en/auth.php +++ b/lang/en/auth.php @@ -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 <> 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'."; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 07a04f6fe4..a7d32190b5 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -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"; diff --git a/lang/fi/auth.php b/lang/fi/auth.php index 6a18613a97..48517a1450 100644 --- a/lang/fi/auth.php +++ b/lang/fi/auth.php @@ -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 <> 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"; diff --git a/lib/datalib.php b/lib/datalib.php index 1293c75598..91787ecbad 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -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 diff --git a/lib/db/mysql.php b/lib/db/mysql.php index e3a6300686..6b4f86f8d3 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -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; } diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index 30ffb85097..5e65510d18 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -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'); diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 6d71be1f0f..e9a184f350 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -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; } diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index d82c8fca21..8dc0153f93 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -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'); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 3d4dc00d73..0c3bf45530 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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); } diff --git a/lib/setup.php b/lib/setup.php index 198e866ff3..9a1f7da4e3 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -133,7 +133,7 @@ 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 diff --git a/login/index.php b/login/index.php index 3fd4e2d5e7..25fd20a9e2 100644 --- a/login/index.php +++ b/login/index.php @@ -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"); } diff --git a/version.php b/version.php index 748327b834..f6d13655be 100644 --- a/version.php +++ b/version.php @@ -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 -- 2.39.5