ajax.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // Include functions if not already included
  3. require_once('functions.php');
  4. // Upgrade environment
  5. upgradeCheck();
  6. // Lazyload settings
  7. $databaseConfig = configLazy('config/config.php');
  8. // Get Action
  9. if (isset($_POST['submit'])) { $action = $_POST['submit']; }
  10. if (isset($_POST['action'])) { $action = $_POST['action']; }
  11. if (isset($_GET['action'])) { $action = $_GET['action']; }
  12. if (isset($_GET['a'])) { $action = $_GET['a']; }
  13. unset($_POST['action']);
  14. // No Action
  15. if (!isset($action)) {
  16. debug_out('No Action Specified!',1);
  17. }
  18. // Process Request
  19. switch ($_SERVER['REQUEST_METHOD']) {
  20. case 'GET':
  21. switch ($action) {
  22. case 'emby-image':
  23. getEmbyImage();
  24. break;
  25. case 'plex-image':
  26. getPlexImage();
  27. break;
  28. case 'emby-streams':
  29. echo getEmbyStreams(12);
  30. break;
  31. case 'plex-streams':
  32. echo getPlexStreams(12);
  33. break;
  34. case 'emby-recent':
  35. echo getEmbyRecent($_GET['type'], 12);
  36. break;
  37. case 'plex-recent':
  38. echo getPlexRecent($_GET['type'], 12);
  39. break;
  40. case 'sabnzbd-update':
  41. break;
  42. case 'nzbget-update':
  43. break;
  44. default:
  45. debug_out('Unsupported Action!',1);
  46. }
  47. break;
  48. case 'POST':
  49. // Check if the user is an admin and is allowed to commit values
  50. qualifyUser('admin', true);
  51. switch ($action) {
  52. case 'upload-images':
  53. uploadFiles('images/', array('jpg', 'png', 'svg', 'jpeg', 'bmp'));
  54. break;
  55. case 'remove-images':
  56. removeFiles('images/'.(isset($_POST['file'])?$_POST['file']:''));
  57. break;
  58. case 'update-config':
  59. header('Content-Type: application/json');
  60. $notifyExplode = explode("-", NOTIFYEFFECT);
  61. if (updateConfig($_POST)) {
  62. $msg = array(
  63. 'html' => '<strong>'.translate("SETTINGS_SAVED").'</strong>',
  64. 'icon' => 'floppy-o',
  65. 'type' => 'success',
  66. 'length' => '5000',
  67. 'layout' => $notifyExplode[0],
  68. 'effect' => $notifyExplode[1],
  69. );
  70. } else {
  71. $msg = array(
  72. 'html' => '<strong>'.translate("SETTINGS__NOT_SAVED").'</strong>',
  73. 'icon' => 'floppy-o',
  74. 'type' => 'failed',
  75. 'length' => '5000',
  76. 'layout' => $notifyExplode[0],
  77. 'effect' => $notifyExplode[1],
  78. );
  79. }
  80. echo json_encode($msg);
  81. break;
  82. case 'editCSS':
  83. write_ini_file($_POST["css-show"], "custom.css");
  84. echo '<script>window.top.location = window.top.location.href.split(\'#\')[0];</script>';
  85. break;
  86. default:
  87. debug_out('Unsupported Action!',1);
  88. }
  89. break;
  90. case 'PUT':
  91. debug_out('Unsupported Action!',1);
  92. break;
  93. case 'DELETE':
  94. debug_out('Unsupported Action!',1);
  95. break;
  96. default:
  97. debug_out('Unknown Request Type!',1);
  98. }