More robustness, and some little bug fixes.
[moodle.git] / admin / auth.php
1 <?PHP  // $Id$
2        // config.php - allows admin to edit all configuration variables
4     include("../config.php");
6     require_login();
8     if (!$site = get_site()) {
9         redirect("index.php");
10     }
12     if (!isadmin()) {
13         error("Only the admin can use this page");
14     }
17 /// If data submitted, then process and store.
19         if (match_referer() && isset($HTTP_POST_VARS)) {
21         $config = (object)$HTTP_POST_VARS;
23         validate_form($config, $err);
25         if (count($err) == 0) {
26             print_header();
27             foreach ($config as $name => $value) {
28                 if (! set_config($name, $value)) {
29                     notify("Problem saving config $name as $value");
30                 }
31             }
32             redirect("auth.php", get_string("changessaved"), 1);
33             exit;
35         } else {
36             foreach ($err as $key => $value) {
37                 $focus = "form.$key";
38             }
39         }
40         }
42 /// Otherwise fill and print the form.
44     if (!isset($config)) {
45         $config = $CFG;
46     }
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         } 
59     if (! isset($config->guestloginbutton)) {
60         $config->guestloginbutton = 1;
61     }
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");
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     }
77     if (empty($focus)) {
78         $focus = "";
79     }
81     $guestoptions[0] = get_string("hide");
82     $guestoptions[1] = get_string("show");
84     $stradministration        = get_string("administration");
85     $strauthentication        = get_string("authentication");
86     $strauthenticationoptions = get_string("authenticationoptions","auth");
87     $strsettings = get_string("settings");
89     print_header("$site->shortname: $strauthenticationoptions", "$site->fullname",
90                   "<A HREF=\"index.php\">$stradministration</A> -> $strauthenticationoptions", "$focus");
92     echo "<CENTER><P><B>";
93     echo "<form TARGET=\"_top\" NAME=\"authmenu\" method=\"post\" action=\"auth.php\">";
94     print_string("chooseauthmethod","auth");
96         choose_from_menu ($options, "auth", $auth, "","top.location='auth.php?auth='+document.authmenu.auth.options[document.authmenu.auth.selectedIndex].value", "");
98     echo "</B></P></CENTER>";
99         
100     print_simple_box_start("center", "100%", "$THEME->cellheading");
101     print_heading($options[$auth]);
103     echo "<BLOCKQUOTE><CENTER><P>";
104     print_string("auth_$auth"."description", "auth");
105     echo "</P></CENTER></BLOCKQUOTE>";
107     echo "<HR>";
109     print_heading($strsettings);
111     echo "<table border=\"0\" width=\"100%\" cellpadding=\"4\">";
113     require("$CFG->dirroot/auth/$auth/config.html");
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>";
127     }
129     echo "<tr valign=\"top\">";
130         echo "<td align=right nowrap><p>";
131     print_string("guestloginbutton", "auth");
132     echo ":</p></td>";
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>";
141     echo "<CENTER><P><INPUT TYPE=\"submit\" VALUE=\"";
142     print_string("savechanges");
143     echo "\"></P></CENTER></FORM>";
145     print_simple_box_end(); 
147     print_footer();
148     exit; 
150 /// Functions /////////////////////////////////////////////////////////////////
152 function validate_form(&$form, &$err) {
154    // if (empty($form->fullname))
155    //     $err["fullname"] = get_string("missingsitename");
157     return;
161 ?>