Patch for postgresql happiness
[moodle.git] / admin / auth.php
blob7e6ffbed7cfaafbb2eeac6e77896d75fbb636a31
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");
15 if (!confirm_sesskey()) {
16 error(get_string('confirmsesskeybad', 'error'));
19 /// If data submitted, then process and store.
21 if ($config = data_submitted()) {
23 $config = (array)$config;
24 validate_form($config, $err);
26 if (count($err) == 0) {
27 print_header();
28 foreach ($config as $name => $value) {
29 if (! set_config($name, $value)) {
30 notify("Problem saving config $name as $value");
33 redirect("auth.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
34 exit;
36 } else {
37 foreach ($err as $key => $value) {
38 $focus = "form.$key";
43 /// Otherwise fill and print the form.
45 if (empty($config)) {
46 $config = $CFG;
49 $modules = get_list_of_plugins("auth");
50 foreach ($modules as $module) {
51 $options[$module] = get_string("auth_$module"."title", "auth");
53 asort($options);
54 if (isset($_GET['auth'])) {
55 $auth = $_GET['auth'];
56 } else {
57 $auth = $config->auth;
59 $auth = clean_filename($auth);
60 require_once("$CFG->dirroot/auth/$auth/lib.php"); //just to make sure that current authentication functions are loaded
61 if (! isset($config->guestloginbutton)) {
62 $config->guestloginbutton = 1;
64 if (! isset($config->auth_instructions)) {
65 $config->auth_instructions = "";
67 if (! isset($config->changepassword)) {
68 $config->changepassword = "";
70 $user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "department", "address", "city", "country", "description", "idnumber", "lang");
72 foreach ($user_fields as $user_field) {
73 $user_field = "auth_user_$user_field";
74 if (! isset($config->$user_field)) {
75 $config->$user_field = "";
79 if (empty($focus)) {
80 $focus = "";
83 $guestoptions[0] = get_string("hide");
84 $guestoptions[1] = get_string("show");
86 $createoptions[0] = get_string("no");
87 $createoptions[1] = get_string("yes");
89 $stradministration = get_string("administration");
90 $strauthentication = get_string("authentication");
91 $strauthenticationoptions = get_string("authenticationoptions","auth");
92 $strsettings = get_string("settings");
93 $strusers = get_string("users");
95 print_header("$site->shortname: $strauthenticationoptions", "$site->fullname",
96 "<A HREF=\"index.php\">$stradministration</A> -> <a href=\"users.php\">$strusers</a> -> $strauthenticationoptions", "$focus");
98 echo "<CENTER><P><B>";
99 echo "<form TARGET=\"{$CFG->framename}\" NAME=\"authmenu\" method=\"post\" action=\"auth.php\">";
100 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\">";
101 print_string("chooseauthmethod","auth");
103 choose_from_menu ($options, "auth", $auth, "","document.location='auth.php?sesskey=$USER->sesskey&auth='+document.authmenu.auth.options[document.authmenu.auth.selectedIndex].value", "");
105 echo "</B></P></CENTER>";
107 print_simple_box_start("center", "100%", "$THEME->cellheading");
108 print_heading($options[$auth]);
110 print_simple_box_start("center", "60%", "$THEME->cellcontent");
111 print_string("auth_$auth"."description", "auth");
112 print_simple_box_end();
114 echo "<hr>";
116 print_heading($strsettings);
118 echo "<table border=\"0\" width=\"100%\" cellpadding=\"4\">";
120 require_once("$CFG->dirroot/auth/$auth/config.html");
122 if ($auth != "email" and $auth != "none" and $auth != "manual") {
123 echo "<tr valign=\"top\">";
124 echo "<td align=right nowrap><p>";
125 print_string("changepassword", "auth");
126 echo ":</p></td>";
127 echo "<td>";
128 echo "<input type=\"text\" name=\"changepassword\" size=40 value=\"$config->changepassword\">";
129 echo "</td>";
130 echo "<td>";
131 print_string("changepasswordhelp","auth");
132 echo "</td></tr>";
136 echo "<tr valign=\"top\">";
137 echo "<td align=right nowrap><p>";
138 print_string("guestloginbutton", "auth");
139 echo ":</p></td>";
140 echo "<td>";
141 choose_from_menu($guestoptions, "guestloginbutton", $config->guestloginbutton, "");
142 echo "</td>";
143 echo "<td>";
144 print_string("showguestlogin","auth");
145 echo "</td></tr>";
147 if (function_exists('auth_user_create')){
148 echo "<tr valign=\"top\">";
149 echo "<td align=right nowrap><p>";
150 print_string("auth_user_create", "auth");
151 echo ":</p></td>";
152 echo "<td>";
153 choose_from_menu($createoptions, "auth_user_create", $config->auth_user_create, "");
154 echo "</td>";
155 echo "<td>";
156 print_string("auth_user_creation","auth");
157 echo "</td></tr>";
160 echo "</table><center><p><input type=\"submit\" value=\"";
161 print_string("savechanges");
162 echo "\"></p></center></form>";
164 print_simple_box_end();
166 print_footer();
167 exit;
169 /// Functions /////////////////////////////////////////////////////////////////
171 function validate_form(&$form, &$err) {
173 // if (empty($form->fullname))
174 // $err["fullname"] = get_string("missingsitename");
176 return;