settings.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * @name Settings Module
  4. * @author Tobias Reich
  5. * @copyright 2014 by Tobias Reich
  6. */
  7. if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
  8. function getSettings() {
  9. global $database;
  10. $result = $database->query('SELECT * FROM lychee_settings;');
  11. while($row = $result->fetch_object()) {
  12. $return[$row->key] = $row->value;
  13. }
  14. return $return;
  15. }
  16. function setLogin($oldPassword = '', $username, $password) {
  17. global $settings;
  18. if ($oldPassword==$settings['password']) {
  19. if (!setUsername($username)) exit('Error: Updating username failed!');
  20. if (!setPassword($password)) exit('Error: Updating password failed!');
  21. return true;
  22. }
  23. exit('Error: Current password entered incorrectly!');
  24. }
  25. function setUsername($username) {
  26. global $database;
  27. $username = htmlentities($username);
  28. if (strlen($username)>50) return false;
  29. $result = $database->query("UPDATE lychee_settings SET value = '$username' WHERE `key` = 'username';");
  30. if (!$result) return false;
  31. return true;
  32. }
  33. function setPassword($password) {
  34. global $database;
  35. if (strlen($password)<1||strlen($password)>50) return false;
  36. $result = $database->query("UPDATE lychee_settings SET value = '$password' WHERE `key` = 'password';");
  37. if (!$result) return false;
  38. return true;
  39. }
  40. function setDropboxKey($key) {
  41. global $database;
  42. if (strlen($key)<1||strlen($key)>50) return false;
  43. $result = $database->query("UPDATE lychee_settings SET value = '$key' WHERE `key` = 'dropboxKey';");
  44. if (!$result) return false;
  45. return true;
  46. }
  47. function setSorting($type, $order) {
  48. global $database;
  49. $sorting = 'ORDER BY ';
  50. switch ($type) {
  51. case 'id': $sorting .= 'id';
  52. break;
  53. case 'title': $sorting .= 'title';
  54. break;
  55. case 'description': $sorting .= 'description';
  56. break;
  57. case 'public': $sorting .= 'public';
  58. break;
  59. case 'type': $sorting .= 'type';
  60. break;
  61. case 'star': $sorting .= 'star';
  62. break;
  63. default: exit('Error: Unknown type for sorting!');
  64. }
  65. $sorting .= ' ';
  66. switch ($order) {
  67. case 'ASC': $sorting .= 'ASC';
  68. break;
  69. case 'DESC': $sorting .= 'DESC';
  70. break;
  71. default: exit('Error: Unknown order for sorting!');
  72. }
  73. $result = $database->query("UPDATE lychee_settings SET value = '$sorting' WHERE `key` = 'sorting';");
  74. if (!$result) return false;
  75. return true;
  76. }
  77. ?>