changing settings is now possible

This commit is contained in:
nilsding 2014-08-18 17:49:20 +02:00
parent 1efa145cf2
commit 4364ad8706
5 changed files with 56 additions and 18 deletions

View File

@ -2113,7 +2113,5 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
}(jQuery);
function a(b){
var c = document.getElementById("recent-count");
var d = document.getElementById("recent-btn");
c.disabled = d.disabled = b;
document.getElementById("recent-count").disabled = b;
}

File diff suppressed because one or more lines are too long

View File

@ -75,11 +75,8 @@ if (!isset($notemplate)) {
// show recent?
$res = $sql->query("SELECT `value` FROM `config` WHERE `key` = \"recent_public\";")->fetch_assoc();
$recent_public = $res['value'] === "true" ? true : false;
$recent_count = 0;
if ($recent_public) {
$res = $sql->query("SELECT `value` FROM `config` WHERE `key` = \"recent_count\";")->fetch_assoc();
$recent_count = (int) $res['value'];
}
$res = $sql->query("SELECT `value` FROM `config` WHERE `key` = \"recent_count\";")->fetch_assoc();
$recent_count = (int) $res['value'];
// the flash
$message = null;

45
ucp.php
View File

@ -71,7 +71,50 @@ switch ($_GET['page']) {
case "settings": {
check_privileges();
$tpl->draw("settings");
if (!isset($_POST['action'])) {
$tpl->draw("settings");
} else {
switch ($_POST['action']) {
case "generic": {
if (isset($_POST['sitename'])) {
$sql->query("UPDATE `config` SET `value`='" . $sql->real_escape_string(trim($_POST['sitename'])) . "' WHERE `key`='sitename'");
}
if (isset($_POST['recent_check'])) {
$sql->query("UPDATE `config` SET `value`='true' WHERE `key`='recent_public'");
} else {
$sql->query("UPDATE `config` SET `value`='false' WHERE `key`='recent_public'");
}
if (isset($_POST['recent_count'])) {
if (is_numeric($_POST['recent_count'])) {
$sql->query("UPDATE `config` SET `value`='" . (int) $_POST['recent_count'] . "' WHERE `key`='recent_count'");
}
}
$_SESSION['flash'] = "Successfully saved changes.";
header('Location: ucp.php?page=settings');
exit();
break;
}
case "password": {
if (isset($_POST['password_change']) && isset($_POST['password_verify'])) {
if ($_POST['password_change'] === $_POST['password_verify']) {
if (strlen($_POST['password_change']) > 3) {
$sql->query("UPDATE `config` SET `value`='" . $sql->real_escape_string(crypt_password($_POST['password_change'], gen_salt(22))) . "' WHERE `key`='password';");
$_SESSION['flash'] = "Successfully changed password.";
header('Location: ucp.php?page=settings');
exit();
}
}
}
$_SESSION['flash'] = "The passwords did not match or your password is shorter than 3 characters.";
header('Location: ucp.php?page=settings');
exit();
break;
}
default: {
$tpl->draw("settings");
}
}
}
break;
}
case "inbox":

View File

@ -15,32 +15,32 @@
<form role="form" action="ucp.php?page=settings" method="POST">
<div class="form-group">
<label for="sitename">Site Name</label>
<input type="text" class="form-control" id="sitename" placeholder="3 words about your mom" value="{$site_name}">
<input type="text" class="form-control" name="sitename" placeholder="3 words about your mom" value="{$site_name}">
</div>
<div class="checkbox">
<label>
<input id="recent_check" type="checkbox" onchange="a(!this.checked)"{if="$recent_public"} checked{/if}> Show Recent Answers
<input id="recent_check" name="recent_check" type="checkbox" onchange="a(!this.checked)"{if="$recent_public"} checked{/if}> Show Recent Answers
</label>
</div>
<div class="form-group">
<label for="recent">Recent Answers</label>
<input type="number" class="form-control" id="recent-count" name="recent_count" value="5"{if="!$recent_public"} disabled{/if}>
<input type="number" class="form-control" id="recent-count" name="recent_count" value="{$recent_count}"{if="!$recent_public"} disabled{/if}>
</div>
<button type="submit" class="btn btn-default" id="recent-btn"{if="!$recent_public"} disabled{/if}>Submit</button>
<input type="hidden" name="generic">
<button type="submit" class="btn btn-default" id="recent-btn">Submit</button>
<input type="hidden" name="action" value="generic">
</form>
<hr/>
<form role="form" action="ucp.php?page=settings" method="POST">
<div class="form-group">
<label for="password_change">New Password</label>
<input type="password" class="form-control" id="password_change" placeholder="Password">
<input type="password" class="form-control" name="password_change" placeholder="Password">
</div>
<div class="form-group">
<label for="password_verify">Repeat New Password</label>
<input type="password" class="form-control" id="password_verify" placeholder="Password">
<input type="password" class="form-control" name="password_verify" placeholder="Password">
</div>
<button type="submit" class="btn btn-default">Change Password</button>
<input type="hidden" name="password">
<input type="hidden" name="action" value="password">
</form>
</div>
</div>