Przeglądaj źródła

Create front ajax function, roll in DL updates from homepage, rewrite dl updates on homepage

Cerothen 9 lat temu
rodzic
commit
e911ceddc0
6 zmienionych plików z 312 dodań i 270 usunięć
  1. 37 13
      ajax.php
  2. 96 118
      functions.php
  3. 58 133
      homepage.php
  4. 2 0
      index.php
  5. 112 0
      js/ajax.js
  6. 7 6
      settings.php

+ 37 - 13
ajax.php

@@ -17,47 +17,56 @@ unset($_POST['action']);
 
 // No Action
 if (!isset($action)) {
-	debug_out('No Action Specified!',1);
+	sendNotification(false, 'No Action Specified!');
 }
 
 // Process Request
+$response = array();
 switch ($_SERVER['REQUEST_METHOD']) {
 	case 'GET':
 		switch ($action) {
 			case 'emby-image':
 				qualifyUser(EMBYHOMEAUTH, true);
 				getEmbyImage();
+				die();
 				break;
 			case 'plex-image':
 				qualifyUser(PLEXHOMEAUTH, true);
 				getPlexImage();
+				die();
 				break;
 			case 'emby-streams':
 				qualifyUser(EMBYHOMEAUTH, true);
 				echo getEmbyStreams(12);
+				die();
 				break;
 			case 'plex-streams':
 				qualifyUser(PLEXHOMEAUTH, true);
 				echo getPlexStreams(12);
+				die();
 				break;
 			case 'emby-recent':
 				qualifyUser(EMBYHOMEAUTH, true);
 				echo getEmbyRecent($_GET['type'], 12);
+				die();
 				break;
 			case 'plex-recent':
 				qualifyUser(PLEXHOMEAUTH, true);
 				echo getPlexRecent($_GET['type'], 12);
+				die();
 				break;
 			case 'sabnzbd-update':
-				qualifyUser(NZBGETHOMEAUTH, true);
-				
+				qualifyUser(SABNZBDHOMEAUTH, true);
+				echo sabnzbdConnect($_GET['list'] ? $_GET['list'] : die('Error!'));
+				die();
 				break;
 			case 'nzbget-update':
 				qualifyUser(NZBGETHOMEAUTH, true);
-				
+				echo nzbgetConnect($_GET['list'] ? $_GET['list'] : die('Error!'));
+				die();
 				break;
 			default:
-				debug_out('Unsupported Action!',1);
+				sendNotification(false, 'Unsupported Action!');
 		}
 		break;
 	case 'POST':
@@ -66,44 +75,59 @@ switch ($_SERVER['REQUEST_METHOD']) {
 		switch ($action) {
 			case 'upload-images':
 				uploadFiles('images/', array('jpg', 'png', 'svg', 'jpeg', 'bmp'));
+				sendNotification(true);
 				break;
 			case 'remove-images':
 				removeFiles('images/'.(isset($_POST['file'])?$_POST['file']:''));
+				sendNotification(true);
 				break;
 			case 'update-config':
 				sendNotification(updateConfig($_POST));
 				break;
 			case 'editCSS':
 				write_ini_file($_POST["css-show"], "custom.css");
-				echo '<script>window.top.location = window.top.location.href.split(\'#\')[0];</script>';
+				$response['parent']['reload'] = true;
 				break;
 			case 'update-appearance':
 				sendNotification(updateDBOptions($_POST));
 				break;
 			case 'deleteDB':
 				deleteDatabase();
-				echo json_encode(array('result' => 'success'));
+				sendNotification(true, 'Database Deleted!');
 				break;
 			case 'upgradeInstall':
 				upgradeInstall();
-				echo json_encode(array('result' => 'success'));
+				$response['notify'] = sendNotification(true, 'Performing Checks',false);
+				$response['tab']['goto'] = 'updatedb.php';
 				break;
 			case 'deleteLog':
 				sendNotification(unlink(FAIL_LOG));
 				break;
+			case 'nav-test-tab':
+				$response['tab']['goto'] = 'homepage.php';
+				break;
+			case 'nav-test-tab':
+				$response['parent']['goto'] = 'homepage.php';
+				break;
 			default:
-				debug_out('Unsupported Action!',1);
+				sendNotification(false, 'Unsupported Action!');
 		}
 		break;
 	case 'PUT':
-		debug_out('Unsupported Action!',1);
+		sendNotification(false, 'Unsupported Action!');
 		break;
 	case 'DELETE':
-		debug_out('Unsupported Action!',1);
+		sendNotification(false, 'Unsupported Action!');
 		break;
 	default:
-		debug_out('Unknown Request Type!',1);
+		sendNotification(false, 'Unknown Request Type!');
 }
 
-
+if ($response) {
+	header('Content-Type: application/json');
+	echo json_encode($response);
+	die();
+} else {
+	sendNotification(false, 'Error: No Output Specified!');
+}
 

+ 96 - 118
functions.php

@@ -701,6 +701,7 @@ function getEmbyImage() {
 		$image_src = $embyAddress . '/Items/'.$itemId.'/Images/Primary?'.implode('&', $imgParams);
 		header('Content-type: image/jpeg');
 		readfile($image_src);
+		die();
 	} else {
 		debug_out('Invalid Request',1);
 	}
@@ -718,6 +719,7 @@ function getPlexImage() {
 		$image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . PLEXTOKEN;
 		header('Content-type: image/jpeg');
 		readfile($image_src);
+		die();
 	} else {
 		echo "Invalid Plex Request";	
 	}
@@ -1224,11 +1226,9 @@ function buildSettings($array) {
 				});
 				if (hasVals) {
 					console.log(newVals);
-					$.post(\'ajax.php?a='.(isset($array['submitAction'])?$array['submitAction']:'update-config').'\', newVals, function(data) {
-						console.log(data);
+					ajax_request(\'POST\', \''.(isset($array['submitAction'])?$array['submitAction']:'update-config').'\', newVals, function(data, code) {
 						$(\'#'.$pageID.'_form\').find(\'[data-changed=true]\').removeAttr(\'data-changed\');
-						parent.notify(data.html, data.icon, data.type, data.length, data.layout, data.effect);
-					}, \'json\');
+					});
 				} else {
 					parent.notify(\'Nothing to update!\', \'bullhorn\', \'success\', 5000, \'bar\', \'slidetop\');
 				}
@@ -1516,12 +1516,11 @@ function updateDBOptions($values) {
 }
 
 // Send AJAX notification
-function sendNotification($success, $message = false) {
-	header('Content-Type: application/json');
+function sendNotification($success, $message = false, $send = true) {
 	$notifyExplode = explode("-", NOTIFYEFFECT);
 	if ($success) {
 		$msg = array(
-			'html' => '<strong>'.translate("SETTINGS_SAVED").'</strong>'.($message?'<br>'.$message:''),
+			'html' => ($message?'<br>'.$message:'<strong>'.translate("SETTINGS_SAVED").'</strong>'),
 			'icon' => 'floppy-o',
 			'type' => 'success',
 			'length' => '5000',
@@ -1530,7 +1529,7 @@ function sendNotification($success, $message = false) {
 		);
 	} else {
 		$msg = array(
-			'html' => '<strong>'.translate("SETTINGS_NOT_SAVED").'</strong>'.($message?'<br>'.$message:''),
+			'html' => ($message?'<br>'.$message:'<strong>'.translate("SETTINGS_NOT_SAVED").'</strong>'),
 			'icon' => 'floppy-o',
 			'type' => 'failed',
 			'length' => '5000',
@@ -1538,8 +1537,14 @@ function sendNotification($success, $message = false) {
 			'effect' => $notifyExplode[1],
 		);
 	}
-	echo json_encode($msg);
-	die();
+	
+	// Send and kill script?
+	if ($send) {
+		header('Content-Type: application/json');
+		echo json_encode(array('notify'=>$msg));
+		die();
+	}
+	return $msg;
 }
 
 // Load colours from the database
@@ -1679,6 +1684,87 @@ function upgradeInstall() {
 	return true;
 }
 
+// NzbGET Items
+function nzbgetConnect($list = 'listgroups') {
+    $url = qualifyURL(NZBGETURL);
+    
+    $api = file_get_contents($url.'/'.NZBGETUSERNAME.':'.NZBGETPASSWORD.'/jsonrpc/'.$list);          
+    $api = json_decode($api, true);
+    
+    $gotNZB = array();
+    
+    foreach ($api['result'] AS $child) {
+        $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
+        $downloadStatus = $child['Status'];
+        $downloadCategory = $child['Category'];
+        if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
+        if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
+        if($child['Health'] <= "750"){ 
+            $downloadHealth = "danger"; 
+        }elseif($child['Health'] <= "900"){ 
+            $downloadHealth = "warning"; 
+        }elseif($child['Health'] <= "1000"){ 
+            $downloadHealth = "success"; 
+        }
+        
+        $gotNZB[] = '<tr>
+                        <td>'.$downloadName.'</td>
+                        <td>'.$downloadStatus.'</td>
+                        <td>'.$downloadCategory.'</td>
+                        <td>
+                            <div class="progress">
+                                <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
+                                    <p class="text-center">'.round($downloadPercent).'%</p>
+                                    <span class="sr-only">'.$downloadPercent.'% Complete</span>
+                                </div>
+                            </div>
+                        </td>
+                    </tr>';
+    }
+    
+	if ($gotNZB) {
+		return implode('',$gotNZB);
+	} else {
+		return '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>';
+	}
+}
+
+// Sabnzbd Items
+function sabnzbdConnect($list = 'queue') {
+    $url = qualifyURL(SABNZBDURL);
+	
+    $api = file_get_contents($url.'/api?mode='.$list.'&output=json&apikey='.SABNZBDKEY); 
+    $api = json_decode($api, true);
+    
+    $gotNZB = array();
+    
+    foreach ($api[$list]['slots'] AS $child) {
+        if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; } 
+        if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
+        $downloadStatus = $child['status'];
+        
+        $gotNZB[] = '<tr>
+                        <td>'.$downloadName.'</td>
+                        <td>'.$downloadStatus.'</td>
+                        <td>'.$downloadCategory.'</td>
+                        <td>
+                            <div class="progress">
+                                <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
+                                    <p class="text-center">'.round($downloadPercent).'%</p>
+                                    <span class="sr-only">'.$downloadPercent.'% Complete</span>
+                                </div>
+                            </div>
+                        </td>
+                    </tr>';
+    }
+    
+	if ($gotNZB) {
+		return implode('',$gotNZB);
+	} else {
+		return '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>';
+	}
+}
+
 // ==============
 
 function clean($strin) {
@@ -2078,114 +2164,6 @@ function getRadarrCalendar($array){
 
 }
 
-function nzbgetConnect($url, $username, $password, $list){
-    $url = qualifyURL(NZBGETURL);
-    
-    $api = file_get_contents("$url/$username:$password/jsonrpc/$list");
-                    
-    $api = json_decode($api, true);
-    
-    $i = 0;
-    
-    $gotNZB = "";
-    
-    foreach ($api['result'] AS $child) {
-        
-        $i++;
-        //echo '<pre>' . var_export($child, true) . '</pre>';
-        $downloadName = htmlentities($child['NZBName'], ENT_QUOTES);
-        $downloadStatus = $child['Status'];
-        $downloadCategory = $child['Category'];
-        if($list == "history"){ $downloadPercent = "100"; $progressBar = ""; }
-        if($list == "listgroups"){ $downloadPercent = (($child['FileSizeMB'] - $child['RemainingSizeMB']) / $child['FileSizeMB']) * 100; $progressBar = "progress-bar-striped active"; }
-        if($child['Health'] <= "750"){ 
-            $downloadHealth = "danger"; 
-        }elseif($child['Health'] <= "900"){ 
-            $downloadHealth = "warning"; 
-        }elseif($child['Health'] <= "1000"){ 
-            $downloadHealth = "success"; 
-        }
-        
-        $gotNZB .= '<tr>
-
-                        <td>'.$downloadName.'</td>
-                        <td>'.$downloadStatus.'</td>
-                        <td>'.$downloadCategory.'</td>
-
-                        <td>
-
-                            <div class="progress">
-
-                                <div class="progress-bar progress-bar-'.$downloadHealth.' '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
-
-                                    <p class="text-center">'.round($downloadPercent).'%</p>
-                                    <span class="sr-only">'.$downloadPercent.'% Complete</span>
-
-                                </div>
-
-                            </div>
-
-                        </td>
-
-                    </tr>';
-        
-        
-    }
-    
-    if($i > 0){ return $gotNZB; }
-    if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
-
-}
-
-function sabnzbdConnect($url, $key, $list){
-    $url = qualifyURL(SABNZBDURL);
-
-    $api = file_get_contents("$url/api?mode=$list&output=json&apikey=$key");
-                    
-    $api = json_decode($api, true);
-    
-    $i = 0;
-    
-    $gotNZB = "";
-    
-    foreach ($api[$list]['slots'] AS $child) {
-        
-        $i++;
-        if($list == "queue"){ $downloadName = $child['filename']; $downloadCategory = $child['cat']; $downloadPercent = (($child['mb'] - $child['mbleft']) / $child['mb']) * 100; $progressBar = "progress-bar-striped active"; } 
-        if($list == "history"){ $downloadName = $child['name']; $downloadCategory = $child['category']; $downloadPercent = "100"; $progressBar = ""; }
-        $downloadStatus = $child['status'];
-        
-        $gotNZB .= '<tr>
-
-                        <td>'.$downloadName.'</td>
-                        <td>'.$downloadStatus.'</td>
-                        <td>'.$downloadCategory.'</td>
-
-                        <td>
-
-                            <div class="progress">
-
-                                <div class="progress-bar progress-bar-success '.$progressBar.'" role="progressbar" aria-valuenow="'.$downloadPercent.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$downloadPercent.'%">
-
-                                    <p class="text-center">'.round($downloadPercent).'%</p>
-                                    <span class="sr-only">'.$downloadPercent.'% Complete</span>
-
-                                </div>
-
-                            </div>
-
-                        </td>
-
-                    </tr>';
-        
-        
-    }
-    
-    if($i > 0){ return $gotNZB; }
-    if($i == 0){ echo '<tr><td colspan="4"><p class="text-center">No Results</p></td></tr>'; }
-
-}
-
 function getHeadphonesCalendar($url, $key, $list){
 	$url = qualifyURL(HEADPHONESURL);
     

+ 58 - 133
homepage.php

@@ -103,6 +103,23 @@ $endDate = date('Y-m-d',strtotime("+".CALENDARENDDAY." days"));
 
         <link rel="stylesheet" href="css/style.css">
 
+        <!--Scripts-->
+        <script src="bower_components/jquery/dist/jquery.min.js"></script>
+        <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
+        <script src="bower_components/moment/min/moment.min.js"></script>
+        <script src="bower_components/jquery.nicescroll/jquery.nicescroll.min.js"></script>
+        <script src="bower_components/slimScroll/jquery.slimscroll.min.js"></script>
+        <script src="bower_components/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.js"></script>
+        <script src="bower_components/jquery.nicescroll/jquery.nicescroll.min.js"></script>
+        <script src="bower_components/cta/dist/cta.min.js"></script>
+        <script src="bower_components/fullcalendar/dist/fullcalendar.js"></script>
+
+        <script src="js/jqueri_ui_custom/jquery-ui.min.js"></script>
+	    <script src="js/jquery.mousewheel.min.js" type="text/javascript"></script>
+		
+		<!--Other-->
+		<script src="js/ajax.js?v=<?php echo INSTALLEDVERSION; ?>"></script>
+		
         <!--[if lt IE 9]>
         <script src="bower_components/html5shiv/dist/html5shiv.min.js"></script>
         <script src="bower_components/respondJs/dest/respond.min.js"></script>
@@ -183,7 +200,6 @@ endif; ?>
     </head>
 
     <body class="scroller-body" style="padding: 0px;">
-
         <div class="main-wrapper" style="position: initial;">
             <div id="content" class="container-fluid">
 <!-- <button id="numBnt">Numerical</button> -->
@@ -191,121 +207,72 @@ endif; ?>
                 <?php if((NZBGETURL != "" && qualifyUser(NZBGETHOMEAUTH)) || (SABNZBDURL != "" && qualifyUser(SABNZBDHOMEAUTH))) { ?>
                 <div id="downloadClientRow" class="row">
                     <sort>2</sort>
-
                     <div class="col-xs-12 col-md-12">
                         <div class="content-box">
-
                             <div class="tabbable panel with-nav-tabs panel-default">
-
                                 <div class="panel-heading">
-
                                     <div class="content-tools i-block pull-right">
-
                                         <a id="getDownloader" class="repeat-btn">
-
                                             <i class="fa fa-repeat"></i>
-
                                         </a>
-
                                         <a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                             <i class="fa fa-chevron-down"></i>
                                         </a>
+										<!-- Lets Move This To Homepage Settings
                                         <ul id="downloaderSeconds" class="dropdown-menu" style="top: 32px !important">
-
                                             <li data-value="5000"><a>Refresh every 5 seconds</a></li>
                                             <li data-value="10000"><a>Refresh every 10 seconds</a></li>
                                             <li data-value="30000"><a>Refresh every 30 seconds</a></li>
                                             <li data-value="60000"><a>Refresh every 60 seconds</a></li>
-
                                         </ul>
-
+										-->
                                     </div>
-
                                     <h3 class="pull-left"><?php if(NZBGETURL != ""){ echo "NZBGet "; } if(SABNZBDURL != ""){ echo "SABnzbd "; } ?></h3>
-
                                     <ul class="nav nav-tabs pull-right">
-
                                         <li class="active"><a href="#downloadQueue" data-toggle="tab" aria-expanded="true"><?php echo $language->translate("QUEUE");?></a></li>
-
                                         <li class=""><a href="#downloadHistory" data-toggle="tab" aria-expanded="false"><?php echo $language->translate("HISTORY");?></a></li>
-
                                     </ul>
-
                                     <div class="clearfix"></div>
-
                                 </div>
-
                                 <div class="panel-body">
-
                                     <div class="tab-content">
-
                                         <div class="tab-pane fade active in" id="downloadQueue">
-
                                             <div class="table-responsive" style="max-height: 300px">
-
                                                 <table class="table table-striped progress-widget zero-m" style="max-height: 300px">
-
                                                     <thead>
-
                                                         <tr>
-
                                                             <th><?php echo $language->translate("FILE");?></th>
                                                             <th><?php echo $language->translate("STATUS");?></th>
                                                             <th><?php echo $language->translate("CATEGORY");?></th>
                                                             <th><?php echo $language->translate("PROGRESS");?></th>
-
                                                         </tr>
-
                                                     </thead>
-
-                                                    <tbody id="downloaderQueue">                               
-
-                                                    </tbody>
-
+                                                    <tbody class="dl-queue sabnzbd"></tbody>
+                                                    <tbody class="dl-queue nzbget"></tbody>
                                                 </table>
-
                                             </div>
-
                                         </div>
-
                                         <div class="tab-pane fade" id="downloadHistory">
-
                                             <div class="table-responsive" style="max-height: 300px">
-
                                                 <table class="table table-striped progress-widget zero-m" style="max-height: 300px">
-
                                                     <thead>
-
                                                         <tr>
-
-                                                            <th>File</th>
-                                                            <th>Status</th>
-                                                            <th>Category</th>
-                                                            <th>Progress</th>
-
+                                                            <th><?php echo $language->translate("FILE");?></th>
+                                                            <th><?php echo $language->translate("STATUS");?></th>
+                                                            <th><?php echo $language->translate("CATEGORY");?></th>
+                                                            <th><?php echo $language->translate("PROGRESS");?></th>
                                                         </tr>
-
                                                     </thead>
-
-                                                    <tbody id="downloaderHistory">                                      
-
-                                                    </tbody>
-
+                                                    <tbody class="dl-history sabnzbd"></tbody>
+                                                    <tbody class="dl-history nzbget"></tbody>
                                                 </table>
-
                                             </div>
-
                                         </div>
-
                                     </div>
-
                                 </div>
-
                             </div>
                         </div>
-
                     </div>
-
                 </div>
                 <?php } ?>
 				<?php if (qualifyUser(PLEXHOMEAUTH)) { ?>
@@ -365,20 +332,11 @@ endif; ?>
 
             </div>    
         </div>
-        <!--Scripts-->
-        <script src="bower_components/jquery/dist/jquery.min.js"></script>
-        <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
-        <script src="bower_components/moment/min/moment.min.js"></script>
-        <script src="bower_components/jquery.nicescroll/jquery.nicescroll.min.js"></script>
-        <script src="bower_components/slimScroll/jquery.slimscroll.min.js"></script>
-        <script src="bower_components/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.js"></script>
-        <script src="bower_components/jquery.nicescroll/jquery.nicescroll.min.js"></script>
-        <script src="bower_components/cta/dist/cta.min.js"></script>
-        <script src="bower_components/fullcalendar/dist/fullcalendar.js"></script>
-
-        <script src="js/jqueri_ui_custom/jquery-ui.min.js"></script>
-	    <script src="js/jquery.mousewheel.min.js" type="text/javascript"></script>
         <script>
+		function localStorageSupport() {
+			return (('localStorage' in window) && window['localStorage'] !== null)
+		}
+		
         $( document ).ready(function() {
              $('.repeat-btn').click(function(){
                 var refreshBox = $(this).closest('div.content-box');
@@ -409,67 +367,34 @@ endif; ?>
                 mousescrollstep: 60
             });*/
             // check if browser support HTML5 local storage
-            function localStorageSupport() {
-                return (('localStorage' in window) && window['localStorage'] !== null)
-            }
+			
             <?php if((NZBGETURL != "" && qualifyUser(NZBGETHOMEAUTH)) || (SABNZBDURL != "" && qualifyUser(SABNZBDHOMEAUTH))){ ?>
-            var downloaderSeconds = localStorage.getItem("downloaderSeconds");
-            var myInterval = undefined;
-            $("ul").find("[data-value='" + downloaderSeconds + "']").addClass("active");
-            if(  downloaderSeconds === null ) {
-                localStorage.setItem("downloaderSeconds",'60000');
-                var downloaderSeconds = "60000";
-            }
-            $('#downloaderSeconds li').click(function() {
-                $('#downloaderSeconds li').removeClass("active");
-                $(this).addClass("active");
-
-                var newDownloaderSeconds = $(this).attr('data-value');
-                console.log('New Time is ' + newDownloaderSeconds + ' Old Time was ' + downloaderSeconds);
-                if (localStorageSupport) {
-                    localStorage.setItem("downloaderSeconds",newDownloaderSeconds);
-                }
-                if(typeof myInterval != 'undefined'){ clearInterval(myInterval); }
-                refreshDownloader(newDownloaderSeconds);
-            });
-            <?php } ?>
-            <?php if((NZBGETURL != "" && qualifyUser(NZBGETHOMEAUTH))){ ?>
-            $("#downloaderHistory").load("downloader.php?downloader=nzbget&list=history");
-            $("#downloaderQueue").load("downloader.php?downloader=nzbget&list=listgroups");
-            refreshDownloader = function(secs){
-                myInterval = setInterval(function(){
-                    $("#downloaderHistory").load("downloader.php?downloader=nzbget&list=history");
-                    $("#downloaderQueue").load("downloader.php?downloader=nzbget&list=listgroups");
-                }, secs);                
-            }
-
-            refreshDownloader(downloaderSeconds);
-
-            $("#getDownloader").click(function(){
-                $("#downloaderHistory").load("downloader.php?downloader=nzbget&list=history");
-                $("#downloaderQueue").load("downloader.php?downloader=nzbget&list=listgroups");
-                console.log('completed'); 
-            });
-
-            <?php } ?>
-            <?php if((SABNZBDURL != "" && qualifyUser(SABNZBDHOMEAUTH))){ ?>
-            $("#downloaderHistory").load("downloader.php?downloader=sabnzbd&list=history");
-            $("#downloaderQueue").load("downloader.php?downloader=sabnzbd&list=queue");
-            refreshDownloader = function(secs){
-                myInterval = setInterval(function(){
-                    $("#downloaderHistory").load("downloader.php?downloader=sabnzbd&list=history");
-                    $("#downloaderQueue").load("downloader.php?downloader=sabnzbd&list=queue");
-                }, secs);                
-            }
-
-            refreshDownloader(downloaderSeconds);
-
-            $("#getDownloader").click(function(){
-                $("#downloaderHistory").load("downloader.php?downloader=sabnzbd&list=history");
-                $("#downloaderQueue").load("downloader.php?downloader=sabnzbd&list=queue");
-                console.log('completed'); 
-            });
-
+			var queueRefresh = 30000;
+			var historyRefresh = 120000; // This really doesn't need to happen that often
+			
+			var queueLoad = function() {
+				<?php if(SABNZBDURL != "") { echo '$("tbody.dl-queue.sabnzbd").load("ajax.php?a=sabnzbd-update&list=queue");'; } ?>
+				<?php if(NZBGETURL != "") { echo '$("tbody.dl-queue.nzbget").load("ajax.php?a=nzbget-update&list=listgroups");'; } ?>
+			};
+			
+			var historyLoad = function() {
+				<?php if(SABNZBDURL != "") { echo '$("tbody.dl-history.sabnzbd").load("ajax.php?a=sabnzbd-update&list=history");'; } ?>
+				<?php if(NZBGETURL != "") { echo '$("tbody.dl-history.nzbget").load("ajax.php?a=nzbget-update&list=history");'; } ?>
+			};
+			
+			// Initial Loads
+			queueLoad();
+			historyLoad();
+			
+			// Interval Loads
+			var queueInterval = setInterval(queueLoad, queueRefresh);
+			var historyInterval = setInterval(historyLoad, historyRefresh);
+			
+			// Manual Load
+			$("#getDownloader").click(function() {
+				queueLoad();
+				historyLoad();
+			});
             <?php } ?>
         });
         </script>

+ 2 - 0
index.php

@@ -266,6 +266,8 @@ if(file_exists("images/settings2.png")) : $iconRotate = "false"; $settingsIcon =
         <meta name="theme-color" content="#2d89ef">
         <link rel="stylesheet" type="text/css" href="css/addtohomescreen.css">
         <script src="js/addtohomescreen.js"></script>
+		<!--Other-->
+		<script src="js/ajax.js?v=<?php echo INSTALLEDVERSION; ?>"></script>
         <!--[if lt IE 9]>
         <script src="bower_components/html5shiv/dist/html5shiv.min.js"></script>
         <script src="bower_components/respondJs/dest/respond.min.js"></script>

+ 112 - 0
js/ajax.js

@@ -0,0 +1,112 @@
+function ajax_request(method, action, data, callback, options) {
+	var ajax_response_action = function(data, req_code) {
+		if (typeof options === 'object' && options.replacecallback === true && typeof callback === 'function') {
+			callback(data, req_code);
+		} else {
+			// Use just JSON data
+			data = data.responseJSON;
+			
+			// Check if data object is valid
+			if (typeof data === 'object') {				
+				// Check if we are doing notifications
+				if (typeof data.notify === 'object') {
+					if (typeof parent.notify === 'function') {
+						var notifyString = (data.notify.html?data.notify.html:'Ajax Complete!;')
+						var notifyIcon = (data.notify.icon?data.notify.icon:'bullhorn;')
+						var notifyType = (data.notify.type?data.notify.type:'success;')
+						var notifyLength = (data.notify.length?data.notify.length:4000)
+						var notifyLayout = (data.notify.layout?data.notify.layout:'bar')
+						var notifyEffect = (data.notify.effect?data.notify.effect:'slidetop')
+						
+						parent.notify(notifyString, notifyIcon, notifyType, notifyLength, notifyLayout, notifyEffect);
+					} else {
+						console.log(data.notify);
+					}
+				}
+				
+				// Callback
+				if (typeof data.callback === 'string') {
+					eval(data.callback);
+				}
+				
+				// Internal Process Function
+				var scopefunctions = function(scopeObj, data) {
+					// Reload?
+					if (data.reload === true) {
+						scopeObj.location.href = scopeObj.location.href;
+					}
+					
+					// Navigate?
+					if (typeof data.goto === 'string') {
+						if (!/^http(s)?:\/\//i.test(data.goto)) {
+							if (/^\//.test(data.goto)) {
+								data.goto = scopeObj.location.origin + data.goto;
+							} else {
+								var currentLoc = scopeObj.location.pathname.split('/');
+								currentLoc.splice(-1);
+								data.goto = currentLoc.join('/') + '/' + data.goto;
+							}
+						}
+						scopeObj.location.href = data.goto;
+					}
+					
+					// Replace body with
+					if (typeof data.content === 'string') {
+						scopeObj.document.getElementsByTagName('body').innerHTML = data.content;
+					}
+				}
+				
+				// Tab Scope
+				if (typeof data.tab === 'object') {
+					scopefunctions(window, data.tab);
+				}
+				
+				// Page Functions
+				if (typeof data.parent === 'object') {
+					scopefunctions(window.parent, data.parent);
+				}
+			} else {
+				// Dunno what this is
+				console.log(data);
+			}
+			
+			// Custom Callback (in addition to default actions);
+			if (typeof callback !== 'undefined') {
+				if (typeof callback === 'function') {
+					callback(data, req_code);
+				} else {
+					console.log('Specified callback is not valid');
+					console.log(callback);
+				}
+			}
+		}
+	};
+	
+	// Data must be an object
+	if (typeof data !== 'object') { data = {}; }
+	var ajax_settings = {
+		async: true,
+		accepts: 'application/json',
+		cache: false,
+		complete: ajax_response_action,
+		contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
+		crossDomain: false,
+		data: data,
+		dataType: 'json',
+		error: function (xhr, req_code, error) {
+			console.log(xhr);
+			console.log(req_code);
+			console.log(error);
+		},
+		headers: {
+			action: action,
+		},
+		method: method,
+	};
+	
+	var result = $.ajax('ajax.php?a='+action, ajax_settings);
+	
+	console.log(result);
+	
+	return result;
+}

+ 7 - 6
settings.php

@@ -216,7 +216,9 @@ if(SLIMBAR == "true") : $slimBar = "30"; $userSize = "25"; else : $slimBar = "56
 
         <script src="bower_components/smoke/dist/js/smoke.min.js"></script>
         <script src="bower_components/numbered/jquery.numberedtextarea.js"></script>
-
+		
+		<!--Other-->
+		<script src="js/ajax.js?v=<?php echo INSTALLEDVERSION; ?>"></script>
 
         <!--Notification-->
         <script src="js/notifications/notificationFx.js"></script>
@@ -650,7 +652,7 @@ echo buildSettings(
 		'submitAction' => 'update-appearance',
 		'onready' => '$("#editCssButton, #backToThemeButton").click(function(){ $("#appearance_settings_form").toggle(); $("#editCssForm").toggle(); });',
 		'customAfterForm' => '                                     
-<form style="display: none" id="editCssForm" method="POST" action="ajax.php">
+<form style="display: none" id="editCssForm" method="POST" onsubmit="ajax_request(\'POST\', \'editCSS\', {\'css-show\': $(\'#css-show\').val()}); return false;">
 	<button class="btn waves btn-labeled btn-warning btn-sm pull-left text-uppercase waves-effect waves-float" type="button" id="backToThemeButton">
 
 	<span class="btn-label"><i class="fa fa-arrow-left"></i></span>'.translate("GO_BACK").'
@@ -661,7 +663,6 @@ echo buildSettings(
 	<span class="btn-label"><i class="fa fa-floppy-o"></i></span>'.translate("SAVE_CSS").'
 	</button>
 	<br><br>
-	<input type="hidden" name="submit" value="editCSS" /> 
 	<h1>'.translate("EDIT_CUSTOM_CSS").'</h1> 
 	<!--<p>Variables Available<code>$topbar - $topbartext - $bottombar - $sidebar - $hoverbg - $activetabBG - $activetabicon - $activetabtext - $inactiveicon - $inactivetext - $loading - $hovertext</code></p>-->
 	<textarea class="form-control" id="css-show" name="css-show" rows="25" style="background: #000; color: #FFF;">'.(file_exists('./custom.css')?file_get_contents('./custom.css'):'').'</textarea>
@@ -1795,7 +1796,7 @@ echo buildSettings(
                                         <div class="panel-body">
                                             <div class="">
                                                 <p><?php echo $language->translate("DELETE_WARNING");?></p>
-                                                <form id="deletedb" method="post" onsubmit="$.post(\'ajax.php?a=deleteDB\', {}, function(data) { parent.notify(data.html, data.icon, data.type, data.length, data.layout, data.effect); }); return false;">
+                                                <form id="deletedb" method="post" onsubmit="ajax_request('POST', 'deleteDB'); return false;">
                                                     <button class="btn waves btn-labeled btn-danger pull-right text-uppercase waves-effect waves-float" type="submit">
                                                         <span class="btn-label"><i class="fa fa-trash"></i></span><?php echo $language->translate("DELETE_DATABASE");?>
                                                     </button>
@@ -2887,7 +2888,7 @@ echo buildSettings(
             //Simulate Edit Tabs Click 
             $("#open-tabs").trigger("click");
             //Append Delete log to User Logs
-            $("div[class^='DTTT_container']").append('<form style="display: inline; margin-left: 3px;" id="deletelog" method="post" onsubmit="$.post(\'ajax.php?a=deleteLog\', {}, function(data) { parent.notify(data.html, data.icon, data.type, data.length, data.layout, data.effect); }); return false;"><input type="hidden" name="action" value="deleteLog" /><button class="btn waves btn-labeled btn-danger text-uppercase waves-effect waves-float" type="submit"><span class="btn-label"><i class="fa fa-trash"></i></span><?php echo $language->translate("PURGE_LOG");?> </button></form>')
+            $("div[class^='DTTT_container']").append('<form style="display: inline; margin-left: 3px;" id="deletelog" method="post" onsubmit="ajax_request(\'POST\', \'deleteLog\'); return false;"><input type="hidden" name="action" value="deleteLog" /><button class="btn waves btn-labeled btn-danger text-uppercase waves-effect waves-float" type="submit"><span class="btn-label"><i class="fa fa-trash"></i></span><?php echo $language->translate("PURGE_LOG");?> </button></form>')
             $("a[id^='ToolTables_datatable_0'] span").html('<?php echo $language->translate("PRINT");?>')
             //Enable Tooltips
             $('[data-toggle="tooltip"]').tooltip(); 
@@ -2921,7 +2922,7 @@ echo buildSettings(
                         parent.notify("<strong><?php echo $language->translate("NEW_VERSION");?></strong> <?php echo $language->translate("CLICK_INFO");?>","arrow-circle-o-down","warning","50000", "<?=$notifyExplode[0];?>", "<?=$notifyExplode[1];?>");
 
                         $(infoTabNew).html("<br/><h4><strong><?php echo $language->translate("WHATS_NEW");?> " + githubVersion + "</strong></h4><strong><?php echo $language->translate("TITLE");?>: </strong>" + githubName + " <br/><strong><?php echo $language->translate("CHANGES");?>: </strong>" + githubDescription);
-                        $(infoTabDownload).html("<br/><form style=\"display:initial;\" id=\"deletedb\" method=\"post\" onsubmit=\"$.post(\'ajax.php?a=upgradeInstall\', {}, function(data) { parent.notify(data.html, data.icon, data.type, data.length, data.layout, data.effect); }); return false;\"><input type=\"hidden\" name=\"action\" value=\"upgrade\" /><button class=\"btn waves btn-labeled btn-success text-uppercase waves-effect waves-float\" type=\"submit\"><span class=\"btn-label\"><i class=\"fa fa-refresh\"></i></span><?php echo $language->translate("AUTO_UPGRADE");?></button></form> <a href='https://github.com/causefx/Organizr/archive/master.zip' target='_blank' type='button' class='btn waves btn-labeled btn-success text-uppercase waves-effect waves-float'><span class='btn-label'><i class='fa fa-download'></i></span>Organizr v." + githubVersion + "</a>");
+                        $(infoTabDownload).html("<br/><form style=\"display:initial;\" id=\"deletedb\" method=\"post\" onsubmit=\"ajax_request(\'POST\', \'upgradeInstall\'); return false;\"><input type=\"hidden\" name=\"action\" value=\"upgrade\" /><button class=\"btn waves btn-labeled btn-success text-uppercase waves-effect waves-float\" type=\"submit\"><span class=\"btn-label\"><i class=\"fa fa-refresh\"></i></span><?php echo $language->translate("AUTO_UPGRADE");?></button></form> <a href='https://github.com/causefx/Organizr/archive/master.zip' target='_blank' type='button' class='btn waves btn-labeled btn-success text-uppercase waves-effect waves-float'><span class='btn-label'><i class='fa fa-download'></i></span>Organizr v." + githubVersion + "</a>");
                         $( "p[id^='upgrade']" ).toggle();
                     }else if(currentVersion === githubVersion){
                     	console.log("You Are on Current Version");