More robust creator adding/removing, using new functions in moodlelib.php

This commit is contained in:
moodler 2003-08-17 08:58:18 +00:00
parent 3041b0f88a
commit aa34b7869e

View file

@ -59,43 +59,25 @@
"<a href=\"index.php\">$stradministration</a> -> <a href=\"users.php\">$strusers</a> -> "<a href=\"index.php\">$stradministration</a> -> <a href=\"users.php\">$strusers</a> ->
$strassigncreators", ""); $strassigncreators", "");
/// Add a creator if one is specified
if (!empty($_GET['add'])) {
if (! add_creator($add)) {
error("Could not add that creator!");
}
}
/// Remove a creator if one is specified.
if (!empty($_GET['remove'])) {
if (! remove_creator($remove)) {
error("Could not remove that creator!");
}
}
/// Get all existing creators /// Get all existing creators
$creators = get_creators(); $creators = get_creators();
/// Add an creator if one is specified
if ($add) {
$user = @get_record("user", "id", $add) or
error("That account (id = $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 ($remove) {
$user = @get_record("user", "id", $remove) or
error("That account (id = $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 /// Print the lists of existing and potential creators
echo "<table cellpadding=2 cellspacing=10 align=center>"; echo "<table cellpadding=2 cellspacing=10 align=center>";
echo "<tr><th width=50%>$strexistingcreators</th><th width=50%>$strpotentialcreators</th></tr>"; echo "<tr><th width=50%>$strexistingcreators</th><th width=50%>$strpotentialcreators</th></tr>";