2014-01-22 10:12:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-02-17 16:01:46 +00:00
|
|
|
* @name Settings Module
|
|
|
|
* @author Tobias Reich
|
|
|
|
* @copyright 2014 by Tobias Reich
|
2014-01-22 10:12:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
|
|
|
|
|
|
|
function getSettings() {
|
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
|
|
|
$result = $database->query('SELECT * FROM lychee_settings;');
|
|
|
|
|
|
|
|
while($row = $result->fetch_object()) {
|
2014-02-17 16:01:46 +00:00
|
|
|
$return[$row->key] = $row->value;
|
2014-01-22 10:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function setLogin($oldPassword = '', $username, $password) {
|
|
|
|
|
|
|
|
global $settings;
|
|
|
|
|
|
|
|
if ($oldPassword==$settings['password']) {
|
|
|
|
|
|
|
|
if (!setUsername($username)) exit('Error: Updating username failed!');
|
|
|
|
if (!setPassword($password)) exit('Error: Updating password failed!');
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
exit('Error: Current password entered incorrectly!');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function setUsername($username) {
|
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
|
|
|
$username = htmlentities($username);
|
|
|
|
if (strlen($username)>50) return false;
|
|
|
|
|
|
|
|
$result = $database->query("UPDATE lychee_settings SET value = '$username' WHERE `key` = 'username';");
|
|
|
|
|
|
|
|
if (!$result) return false;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPassword($password) {
|
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
|
|
|
if (strlen($password)<1||strlen($password)>50) return false;
|
|
|
|
|
|
|
|
$result = $database->query("UPDATE lychee_settings SET value = '$password' WHERE `key` = 'password';");
|
|
|
|
|
|
|
|
if (!$result) return false;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-23 21:42:15 +00:00
|
|
|
function setDropboxKey($key) {
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
2014-02-23 21:42:15 +00:00
|
|
|
if (strlen($key)<1||strlen($key)>50) return false;
|
2014-01-22 10:12:51 +00:00
|
|
|
|
2014-02-23 21:42:15 +00:00
|
|
|
$result = $database->query("UPDATE lychee_settings SET value = '$key' WHERE `key` = 'dropboxKey';");
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
if (!$result) return false;
|
|
|
|
return true;
|
|
|
|
|
2014-02-23 21:42:15 +00:00
|
|
|
}
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
function setSorting($type, $order) {
|
|
|
|
|
|
|
|
global $database;
|
|
|
|
|
|
|
|
$sorting = 'ORDER BY ';
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
|
|
|
|
case 'id': $sorting .= 'id';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'title': $sorting .= 'title';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'description': $sorting .= 'description';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'public': $sorting .= 'public';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'type': $sorting .= 'type';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'star': $sorting .= 'star';
|
|
|
|
break;
|
|
|
|
|
2014-03-20 17:54:23 +00:00
|
|
|
case 'take': $sorting .= 'UNIX_TIMESTAMP(STR_TO_DATE(CONCAT(takedate,"-",taketime),"%d.%m.%Y-%H:%i:%S"))';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: exit('Error: Unknown type for sorting!');
|
2014-01-22 10:12:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$sorting .= ' ';
|
|
|
|
|
|
|
|
switch ($order) {
|
|
|
|
|
|
|
|
case 'ASC': $sorting .= 'ASC';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'DESC': $sorting .= 'DESC';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: exit('Error: Unknown order for sorting!');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = $database->query("UPDATE lychee_settings SET value = '$sorting' WHERE `key` = 'sorting';");
|
|
|
|
|
|
|
|
if (!$result) return false;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|