More robustness, and some little bug fixes.
[moodle.git] / admin / auth.php
CommitLineData
35a48c9a 1<?PHP // $Id$
2 // config.php - allows admin to edit all configuration variables
3
4 include("../config.php");
5
6 require_login();
7
8 if (!$site = get_site()) {
9 redirect("index.php");
10 }
11
12 if (!isadmin()) {
13 error("Only the admin can use this page");
14 }
15
16
17/// If data submitted, then process and store.
18
19 if (match_referer() && isset($HTTP_POST_VARS)) {
20
21 $config = (object)$HTTP_POST_VARS;
22
23 validate_form($config, $err);
24
25 if (count($err) == 0) {
26 print_header();
27 foreach ($config as $name => $value) {
466558e3 28 if (! set_config($name, $value)) {
29 notify("Problem saving config $name as $value");
35a48c9a 30 }
31 }
32 redirect("auth.php", get_string("changessaved"), 1);
33 exit;
34
35 } else {
36 foreach ($err as $key => $value) {
37 $focus = "form.$key";
38 }
39 }
40 }
41
42/// Otherwise fill and print the form.
43
44 if (!isset($config)) {
45 $config = $CFG;
46 }
47
48 $modules = get_list_of_plugins("auth");
49 foreach ($modules as $module) {
50 $options[$module] = get_string("auth_$module"."title", "auth");
51 }
52 asort($options);
53 if (isset($_GET['auth'])) {
54 $auth = $_GET['auth'];
55 } else {
56 $auth = $config->auth;
57 }
58
59 if (! isset($config->guestloginbutton)) {
60 $config->guestloginbutton = 1;
61 }
50c4bd41 62 if (! isset($config->auth_instructions)) {
63 $config->auth_instructions = "";
64 }
65 if (! isset($config->changepassword)) {
66 $config->changepassword = "";
67 }
68 $user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "department", "address", "city", "country", "description", "idnumber", "lang");
69
70 foreach ($user_fields as $user_field) {
71 $user_field = "auth_user_$user_field";
72 if (! isset($config->$user_field)) {
73 $config->$user_field = "";
74 }
75 }
5eda92d0 76
77 if (empty($focus)) {
78 $focus = "";
79 }
80
35a48c9a 81 $guestoptions[0] = get_string("hide");
82 $guestoptions[1] = get_string("show");
83
84 $stradministration = get_string("administration");
85 $strauthentication = get_string("authentication");
86 $strauthenticationoptions = get_string("authenticationoptions","auth");
87 $strsettings = get_string("settings");
88
89 print_header("$site->shortname: $strauthenticationoptions", "$site->fullname",
90 "<A HREF=\"index.php\">$stradministration</A> -> $strauthenticationoptions", "$focus");
91
92 echo "<CENTER><P><B>";
93 echo "<form TARGET=\"_top\" NAME=\"authmenu\" method=\"post\" action=\"auth.php\">";
94 print_string("chooseauthmethod","auth");
95
96 choose_from_menu ($options, "auth", $auth, "","top.location='auth.php?auth='+document.authmenu.auth.options[document.authmenu.auth.selectedIndex].value", "");
97
98 echo "</B></P></CENTER>";
99
100 print_simple_box_start("center", "100%", "$THEME->cellheading");
101 print_heading($options[$auth]);
102
009b5933 103 echo "<BLOCKQUOTE><CENTER><P>";
35a48c9a 104 print_string("auth_$auth"."description", "auth");
009b5933 105 echo "</P></CENTER></BLOCKQUOTE>";
35a48c9a 106
107 echo "<HR>";
108
109 print_heading($strsettings);
110
111 echo "<table border=\"0\" width=\"100%\" cellpadding=\"4\">";
112
113 require("$CFG->dirroot/auth/$auth/config.html");
114
466558e3 115 if ($auth != "email" and $auth != "none") {
116 echo "<tr valign=\"top\">";
117 echo "<td align=right nowrap><p>";
118 print_string("changepassword", "auth");
119 echo ":</p></td>";
120 echo "<td>";
121 echo "<INPUT TYPE=\"text\" NAME=\"changepassword\" SIZE=40 VALUE=\"$config->changepassword\">";
122 echo "</td>";
123 echo "<td>";
124 print_string("changepasswordhelp","auth");
125 echo "</td></tr>";
126
127 }
128
35a48c9a 129 echo "<tr valign=\"top\">";
34daec9b 130 echo "<td align=right nowrap><p>";
131 print_string("guestloginbutton", "auth");
132 echo ":</p></td>";
35a48c9a 133 echo "<td>";
134 choose_from_menu($guestoptions, "guestloginbutton", $config->guestloginbutton, "");
135 echo "</td>";
136 echo "<td>";
137 print_string("showguestlogin","auth");
138 echo "</td></tr></table>";
139
466558e3 140
35a48c9a 141 echo "<CENTER><P><INPUT TYPE=\"submit\" VALUE=\"";
142 print_string("savechanges");
143 echo "\"></P></CENTER></FORM>";
144
145 print_simple_box_end();
146
147 print_footer();
148 exit;
149
150/// Functions /////////////////////////////////////////////////////////////////
151
152function validate_form(&$form, &$err) {
153
154 // if (empty($form->fullname))
155 // $err["fullname"] = get_string("missingsitename");
156
157 return;
158}
159
160
161?>