Too many bugs, not enough time!
[moodle.git] / admin / auth.php
blobfb804b8c3326559b20c6f15dd701cfaf3309139c
1 <?PHP // $Id$
2 // config.php - allows admin to edit all configuration variables
4 include("../config.php");
5 require_login();
7 if (!$site = get_site()) {
8 redirect("index.php");
11 if (!isadmin()) {
12 error("Only the admin can use this page");
16 /// If data submitted, then process and store.
18 if ($config = data_submitted()) {
20 $config = (array)$config;
21 validate_form($config, $err);
23 if (count($err) == 0) {
24 print_header();
25 foreach ($config as $name => $value) {
26 if (! set_config($name, $value)) {
27 notify("Problem saving config $name as $value");
30 redirect("auth.php", get_string("changessaved"), 1);
31 exit;
33 } else {
34 foreach ($err as $key => $value) {
35 $focus = "form.$key";
40 /// Otherwise fill and print the form.
42 if (empty($config)) {
43 $config = $CFG;
46 $modules = get_list_of_plugins("auth");
47 foreach ($modules as $module) {
48 $options[$module] = get_string("auth_$module"."title", "auth");
50 asort($options);
51 if (isset($_GET['auth'])) {
52 $auth = $_GET['auth'];
53 } else {
54 $auth = $config->auth;
56 require_once("$CFG->dirroot/auth/$auth/lib.php"); //just to make sure that current authentication functions are loaded
57 if (! isset($config->guestloginbutton)) {
58 $config->guestloginbutton = 1;
60 if (! isset($config->auth_instructions)) {
61 $config->auth_instructions = "";
63 if (! isset($config->changepassword)) {
64 $config->changepassword = "";
66 $user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "department", "address", "city", "country", "description", "idnumber", "lang");
68 foreach ($user_fields as $user_field) {
69 $user_field = "auth_user_$user_field";
70 if (! isset($config->$user_field)) {
71 $config->$user_field = "";
75 if (empty($focus)) {
76 $focus = "";
79 $guestoptions[0] = get_string("hide");
80 $guestoptions[1] = get_string("show");
82 $createoptions[0] = get_string("no");
83 $createoptions[1] = get_string("yes");
85 $stradministration = get_string("administration");
86 $strauthentication = get_string("authentication");
87 $strauthenticationoptions = get_string("authenticationoptions","auth");
88 $strsettings = get_string("settings");
89 $strusers = get_string("users");
91 print_header("$site->shortname: $strauthenticationoptions", "$site->fullname",
92 "<A HREF=\"index.php\">$stradministration</A> -> <a href=\"users.php\">$strusers</a> -> $strauthenticationoptions", "$focus");
94 echo "<CENTER><P><B>";
95 echo "<form TARGET=\"{$CFG->framename}\" NAME=\"authmenu\" method=\"post\" action=\"auth.php\">";
96 print_string("chooseauthmethod","auth");
98 choose_from_menu ($options, "auth", $auth, "","document.location='auth.php?auth='+document.authmenu.auth.options[document.authmenu.auth.selectedIndex].value", "");
100 echo "</B></P></CENTER>";
102 print_simple_box_start("center", "100%", "$THEME->cellheading");
103 print_heading($options[$auth]);
105 print_simple_box_start("center", "60%", "$THEME->cellcontent");
106 print_string("auth_$auth"."description", "auth");
107 print_simple_box_end();
109 echo "<hr>";
111 print_heading($strsettings);
113 echo "<table border=\"0\" width=\"100%\" cellpadding=\"4\">";
115 require_once("$CFG->dirroot/auth/$auth/config.html");
117 if ($auth != "email" and $auth != "none" and $auth != "manual") {
118 echo "<tr valign=\"top\">";
119 echo "<td align=right nowrap><p>";
120 print_string("changepassword", "auth");
121 echo ":</p></td>";
122 echo "<td>";
123 echo "<input type=\"text\" name=\"changepassword\" size=40 value=\"$config->changepassword\">";
124 echo "</td>";
125 echo "<td>";
126 print_string("changepasswordhelp","auth");
127 echo "</td></tr>";
131 echo "<tr valign=\"top\">";
132 echo "<td align=right nowrap><p>";
133 print_string("guestloginbutton", "auth");
134 echo ":</p></td>";
135 echo "<td>";
136 choose_from_menu($guestoptions, "guestloginbutton", $config->guestloginbutton, "");
137 echo "</td>";
138 echo "<td>";
139 print_string("showguestlogin","auth");
140 echo "</td></tr>";
142 if (function_exists('auth_user_create')){
143 echo "<tr valign=\"top\">";
144 echo "<td align=right nowrap><p>";
145 print_string("auth_user_create", "auth");
146 echo ":</p></td>";
147 echo "<td>";
148 choose_from_menu($createoptions, "auth_user_create", $config->auth_user_create, "");
149 echo "</td>";
150 echo "<td>";
151 print_string("auth_user_creation","auth");
152 echo "</td></tr>";
155 echo "</table><center><p><input type=\"submit\" value=\"";
156 print_string("savechanges");
157 echo "\"></p></center></form>";
159 print_simple_box_end();
161 print_footer();
162 exit;
164 /// Functions /////////////////////////////////////////////////////////////////
166 function validate_form(&$form, &$err) {
168 // if (empty($form->fullname))
169 // $err["fullname"] = get_string("missingsitename");
171 return;