name = safe_post("name");
$this->timezone = safe_post("timezone");
$this->auto_subscribe =
(safe_post("auto_subscribe") == "on" ? true : false);
$this->locale = safe_post("locale");
$this->submitted = true;
}
}
public function title()
{
return loc("profile_options_section");
}
public function make_output()
{
$u = logged_user();
$alc = available_locales();
$lcs = array();
foreach ($alc as $lc)
{
array_push($lcs, array(
"value" => $lc->ietf(), "caption" => $lc->name()));
}
$this->make_profile_option($opts, $u, "name", "text");
$this->make_profile_option($opts, $u, "timezone", "select", timezone_identifiers_list());
$this->make_profile_option($opts, $u, "locale", "select", $lcs);
$this->make_profile_option($opts, $u, "auto_subscribe", "checkbox");
$s = "";
if ($this->error !== "")
$s .= html::wrap_div("bt_forum_error", $this->error) . "
";
$s .= "
";
return $s;
}
public function save()
{
if (!$this->submitted)
return true;
if (!$this->verify())
return false;
$u = logged_user();
$p = $u->profile();
$p->set_name($this->name);
$p->set_timezone($this->timezone);
$p->set_auto_subscribe($this->auto_subscribe);
$p->set_locale($this->locale);
$p->save();
return true;
}
private function verify()
{
if ($this->name === "")
{
$this->error = loc("profile_name_empty");
return false;
}
return true;
}
private function make_profile_option(&$opts, $u, $name, $type, $choices = null)
{
$v = "";
if ($this->submitted)
$v = $this->{$name};
else
$v = $u->profile()->{$name}();
$opts[$name] = array(
"type" => $type,
"value" => $v,
"choices" => $choices,
"help" => loc("user_option_" . $name . "_help"));
}
}
class password_section extends section
{
private $submitted = false;
private $current = "";
private $password1 = "";
private $password2 = "";
private $error = "";
private $success = "";
public function __construct()
{
if (isset($_POST["submit"]) && safe_post("t") == "p")
{
$this->current = safe_post("p");
$this->password1 = safe_post("p1");
$this->password2 = safe_post("p2");
$this->submitted = true;
}
}
public function title()
{
return loc("profile_password_section");
}
public function make_output()
{
$s = "";
if ($this->error !== "")
$s .= html::wrap_div("bt_forum_error", $this->error) . "
";
else if ($this->success != "")
$s .= html::wrap_div("bt_forum_success", $this->success) . "
";
$s .= "
";
return $s;
}
public function save()
{
if (!$this->submitted)
return true;
if (!$this->verify())
return false;
$this->success = loc("profile_password_okay");
return true;
}
private function verify()
{
$u = logged_user();
if (!$u->check_password($this->current))
{
sleep(1);
$this->error = loc("profile_password_bad");
return false;
}
if ($this->password1 === "" && $this->password2 === "")
{
$this->error = loc("profile_password_empty");
return false;
}
if ($this->password1 != $this->password2)
{
$this->error = loc("profile_password_mismatch");
return false;
}
return true;
}
}
$sections = array();
array_push($sections, new options_section);
array_push($sections, new password_section);
function output($ss)
{
foreach ($ss as $s)
echo make_section($s->title(), $s->make_output());
}
function save($ss)
{
$okay = true;
foreach ($ss as $s)
{
if (!$s->save())
$okay = false;
}
if ($okay)
{
header("location: " . $_SERVER["REQUEST_URI"]);
exit;
}
}
if (isset($_POST["submit"]))
save($sections);
output_head("", loc("profile_title"));
?>
" . loc("cp_back") . "
";
output($sections);
output_footer();
?>