mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
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.
This commit is contained in:
parent
38b68c5d6f
commit
1924074c76
168
admin/creators.php
Executable file
168
admin/creators.php
Executable file
@ -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 ";
|
||||
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> $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();
|
||||
|
||||
?>
|
@ -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] = "<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>";
|
||||
|
@ -82,6 +82,26 @@
|
||||
</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>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -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!");
|
||||
}
|
||||
|
@ -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;
|
||||
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;
|
||||
}
|
||||
$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;
|
||||
$fulladmin = "<P><A HREF=\"$CFG->wwwroot/admin/\">".get_string("admin")."</A>...";
|
||||
|
||||
print_side_block(get_string("administration"), "", $moddata, $modicon, $fulladmin, $width);
|
||||
|
@ -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",
|
||||
"<A HREF=\"$CFG->wwwroot/admin\">$stradministration</A> -> $strassignteachers");
|
||||
|
||||
$isadmin = isadmin(); /// cache value
|
||||
$courses = get_courses();
|
||||
|
||||
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
@ -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");
|
||||
}
|
||||
|
@ -65,7 +65,7 @@
|
||||
print_spacer(1,$side);
|
||||
}
|
||||
|
||||
if (isadmin()) {
|
||||
if (iscreator()) {
|
||||
if (!$firstcolumn) {
|
||||
echo "<TD WIDTH=\"$side\" VALIGN=TOP NOWRAP>"; $firstcolumn=true;
|
||||
}
|
||||
|
@ -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'.";
|
||||
|
@ -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";
|
||||
|
@ -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";
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user