From aa34b7869ef7444345e04f8d836f4a989194a0f4 Mon Sep 17 00:00:00 2001
From: moodler <moodler>
Date: Sun, 17 Aug 2003 08:58:18 +0000
Subject: [PATCH] More robust creator adding/removing, using new functions in
 moodlelib.php

---
 admin/creators.php | 40 +++++++++++-----------------------------
 1 file changed, 11 insertions(+), 29 deletions(-)

diff --git a/admin/creators.php b/admin/creators.php
index 3505abab01..5c0055c3ae 100755
--- a/admin/creators.php
+++ b/admin/creators.php
@@ -59,42 +59,24 @@
                  "<a href=\"index.php\">$stradministration</a> -> <a href=\"users.php\">$strusers</a> ->
                   $strassigncreators", "");
 
-/// Get all existing creators
-    $creators = get_creators();
+/// Add a creator if one is specified
 
-/// 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 .");
-                }            
-            }
+    if (!empty($_GET['add'])) {
+        if (! add_creator($add)) {
+            error("Could not add that 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]);
-                } 
-            }
+/// 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
+    $creators = get_creators();
 
 /// Print the lists of existing and potential creators
     echo "<table cellpadding=2 cellspacing=10 align=center>";
-- 
2.39.5