settings.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 setCheckForUpdates() {
  41. global $database;
  42. $result = $database->query("SELECT value FROM lychee_settings WHERE `key` = 'checkForUpdates';");
  43. $row = $result->fetch_object();
  44. if ($row->value==0) $checkForUpdates = 1;
  45. else $checkForUpdates = 0;
  46. $result = $database->query("UPDATE lychee_settings SET value = '$checkForUpdates' WHERE `key` = 'checkForUpdates';");
  47. if (!$result) return false;
  48. return true;
  49. }*/
  50. function setSorting($type, $order) {
  51. global $database;
  52. $sorting = 'ORDER BY ';
  53. switch ($type) {
  54. case 'id': $sorting .= 'id';
  55. break;
  56. case 'title': $sorting .= 'title';
  57. break;
  58. case 'description': $sorting .= 'description';
  59. break;
  60. case 'public': $sorting .= 'public';
  61. break;
  62. case 'type': $sorting .= 'type';
  63. break;
  64. case 'star': $sorting .= 'star';
  65. break;
  66. default: exit('Error: Unknown type for sorting!');
  67. }
  68. $sorting .= ' ';
  69. switch ($order) {
  70. case 'ASC': $sorting .= 'ASC';
  71. break;
  72. case 'DESC': $sorting .= 'DESC';
  73. break;
  74. default: exit('Error: Unknown order for sorting!');
  75. }
  76. $result = $database->query("UPDATE lychee_settings SET value = '$sorting' WHERE `key` = 'sorting';");
  77. if (!$result) return false;
  78. return true;
  79. }
  80. ?>