Ver código fonte

DB Changes, Upgrade Changes, More AJAX, More Stuff, ... I hope this works >.>

Cerothen 9 anos atrás
pai
commit
31d2055944
5 arquivos alterados com 447 adições e 562 exclusões
  1. 1 0
      .gitignore
  2. 23 23
      ajax.php
  3. 323 11
      functions.php
  4. 98 524
      settings.php
  5. 2 4
      user.php

+ 1 - 0
.gitignore

@@ -61,5 +61,6 @@ config/config.bak.php
 config/users/
 config/users
 config/users.db
+config/users.bak.db
 
 

+ 23 - 23
ajax.php

@@ -25,30 +25,37 @@ switch ($_SERVER['REQUEST_METHOD']) {
 	case 'GET':
 		switch ($action) {
 			case 'emby-image':
+				qualifyUser(EMBYHOMEAUTH, true);
 				getEmbyImage();
 				break;
 			case 'plex-image':
+				qualifyUser(PLEXHOMEAUTH, true);
 				getPlexImage();
 				break;
 			case 'emby-streams':
+				qualifyUser(EMBYHOMEAUTH, true);
 				echo getEmbyStreams(12);
 				break;
 			case 'plex-streams':
+				qualifyUser(PLEXHOMEAUTH, true);
 				echo getPlexStreams(12);
 				break;
 			case 'emby-recent':
+				qualifyUser(EMBYHOMEAUTH, true);
 				echo getEmbyRecent($_GET['type'], 12);
 				break;
 			case 'plex-recent':
+				qualifyUser(PLEXHOMEAUTH, true);
 				echo getPlexRecent($_GET['type'], 12);
 				break;
 			case 'sabnzbd-update':
+				qualifyUser(NZBGETHOMEAUTH, true);
 				
 				break;
 			case 'nzbget-update':
+				qualifyUser(NZBGETHOMEAUTH, true);
 				
 				break;
-			
 			default:
 				debug_out('Unsupported Action!',1);
 		}
@@ -64,33 +71,26 @@ switch ($_SERVER['REQUEST_METHOD']) {
 				removeFiles('images/'.(isset($_POST['file'])?$_POST['file']:''));
 				break;
 			case 'update-config':
-				header('Content-Type: application/json');
-				$notifyExplode = explode("-", NOTIFYEFFECT);
-				if (updateConfig($_POST)) {
-					$msg = array(
-						'html' => '<strong>'.translate("SETTINGS_SAVED").'</strong>',
-						'icon' => 'floppy-o',
-						'type' => 'success',
-						'length' => '5000',
-						'layout' => $notifyExplode[0],
-						'effect' => $notifyExplode[1],
-					);
-				} else {
-					$msg = array(
-						'html' => '<strong>'.translate("SETTINGS__NOT_SAVED").'</strong>',
-						'icon' => 'floppy-o',
-						'type' => 'failed',
-						'length' => '5000',
-						'layout' => $notifyExplode[0],
-						'effect' => $notifyExplode[1],
-					);
-				}
-				echo json_encode($msg);
+				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>';
 				break;
+			case 'update-appearance':
+				sendNotification(updateDBOptions($_POST));
+				break;
+			case 'deleteDB':
+				deleteDatabase();
+				echo json_encode(array('result' => 'success'));
+				break;
+			case 'upgradeInstall':
+				upgradeInstall();
+				echo json_encode(array('result' => 'success'));
+				break;
+			case 'deleteLog':
+				sendNotification(unlink(FAIL_LOG));
+				break;
 			default:
 				debug_out('Unsupported Action!',1);
 		}

+ 323 - 11
functions.php

@@ -917,6 +917,7 @@ function upgradeCheck() {
 		unlink('homepageSettings.ini.php');
 		unset($databaseData);
 		unset($homepageConfig);
+		$effectiveVersion = '1.31';
 	}
 	
 	// Upgrade to 1.32
@@ -953,10 +954,12 @@ function upgradeCheck() {
 		} else {
 			debug_out('Couldn\'t create updated configuration.' ,1);
 		}
+		$effectiveVersion = '1.32';
 	}
 	
 	// Upgrade to 1.33
 	$config = loadConfig();
+	if (isset($effectiveVersion)) { $config['CONFIG_VERSION'] = $effectiveVersion; }
 	if (isset($config['database_Location']) && (!isset($config['CONFIG_VERSION']) || $config['CONFIG_VERSION'] < '1.33')) {
 		// Fix User Directory
 		$config['user_home'] = $config['database_Location'].'users/';
@@ -973,11 +976,16 @@ function upgradeCheck() {
 			$config['embyURL'] = $config['authBackendHost'];
 		}
 		
+		// Upgrade database to latest version
+		updateSQLiteDB();
+		
 		// Update Version and Commit
 		$config['CONFIG_VERSION'] = '1.33';
 		$createConfigSuccess = createConfig($config);
+		
+		$effectiveVersion = $config['CONFIG_VERSION'];
+		unset($config);
 	}
-	unset($config);
 	
 	return true;
 }
@@ -1063,9 +1071,11 @@ function qualifyUser($type, $errOnFail = false) {
 		} else {
 			$authorized = true;
 		}
-	} elseif (is_string($type)) {
+	} elseif (is_string($type) || is_array($type)) {
 		if ($type !== 'false') {
-			$type = explode('|',$type);
+			if (!is_array($type)) {
+				$type = explode('|',$type);
+			}
 			$authorized = ($GLOBALS['USER']->authenticated && in_array($GLOBALS['USER']->role,$type));
 		} else {
 			$authorized = true;
@@ -1075,8 +1085,14 @@ function qualifyUser($type, $errOnFail = false) {
 	}
 	
 	if (!$authorized && $errOnFail) {
-		header('Location: error.php?error=401');
-		echo '<script>window.location.href = \''.dirname($_SERVER['SCRIPT_NAME']).'/error.php?error=401\'</script>';
+		if ($GLOBALS['USER']->authenticated) {
+			header('Location: error.php?error=401');
+			echo '<script>window.location.href = \''.dirname($_SERVER['SCRIPT_NAME']).'/error.php?error=401\'</script>';
+		} else {
+			header('Location: error.php?error=999');
+			echo '<script>window.location.href = \''.dirname($_SERVER['SCRIPT_NAME']).'/error.php?error=999\'</script>';
+		}
+
 		debug_out('Not Authorized' ,1);
 	} else {
 		return $authorized;
@@ -1142,7 +1158,11 @@ function buildSettings($array) {
 			<div class="email-inner-section">
 				<div class="small-box fade in" id="'.$pageID.'_frame">
 					<div class="col-lg-12">
+						'.(isset($array['customBeforeForm'])?$array['customBeforeForm']:'').'
 						<form class="content-form" name="'.$pageID.'" id="'.$pageID.'_form" onsubmit="return false;">
+							<button type="submit" class="btn waves btn-labeled btn-success btn btn-sm pull-right text-uppercase waves-effect waves-float">
+							<span class="btn-label"><i class="fa fa-floppy-o"></i></span>Save
+							</button>
 							'.$fields.($tabContent?'
 							<div class="tabbable tabs-with-bg" id="'.$pageID.'_tabs">
 								<ul class="nav nav-tabs apps">
@@ -1153,10 +1173,8 @@ function buildSettings($array) {
 									'.implode('', $tabContent).'
 								</div>
 							</div>':'').'
-							<button type="submit" class="btn waves btn-labeled btn-success btn btn-sm pull-right text-uppercase waves-effect waves-float">
-								<span class="btn-label"><i class="fa fa-floppy-o"></i></span>Save
-							</button>
 						</form>
+						'.(isset($array['customAfterForm'])?$array['customAfterForm']:'').'
 					</div>
 				</div>
 			</div>
@@ -1188,7 +1206,7 @@ function buildSettings($array) {
 				});
 				if (hasVals) {
 					console.log(newVals);
-					$.post(\'ajax.php?a=update-config\', newVals, function(data) {
+					$.post(\'ajax.php?a='.(isset($array['submitAction'])?$array['submitAction']:'update-config').'\', newVals, function(data) {
 						console.log(data);
 						$(\'#'.$pageID.'_form\').find(\'[data-changed=true]\').removeAttr(\'data-changed\');
 						parent.notify(data.html, data.icon, data.type, data.length, data.layout, data.effect);
@@ -1223,7 +1241,7 @@ function buildField($params, $sizeSm = 12, $sizeMd = 12, $sizeLg = 12) {
 	
 	// Tags
 	$tags = array();
-	foreach(array('placeholder','style','disabled','readonly','pattern','min','max','required','onkeypress','onchange','onfocus','onleave') as $value) {
+	foreach(array('placeholder','style','disabled','readonly','pattern','min','max','required','onkeypress','onchange','onfocus','onleave','href') as $value) {
 		$tags[] = (isset($params[$value])?$value.'="'.$params[$value].'"':'');
 	}
 	
@@ -1273,7 +1291,10 @@ function buildField($params, $sizeSm = 12, $sizeMd = 12, $sizeLg = 12) {
 			break;
 		case 'button':
 			$labelOut = '';
-			$field = '<button id="'.$id.'" type="button" class="btn waves btn-labeled btn-success btn btn-sm text-uppercase waves-effect waves-float'.$class.'"><span class="btn-label"><i class="fa fa-flask" '.implode(' ',$tags).'></i></span>'.$label.'</button>';
+			$icon = (isset($params['icon'])?$params['icon']:'flask');
+			$bType = (isset($params['buttonType'])?$params['buttonType']:'success');
+			$bDropdown = (isset($params['buttonDrop'])?$params['buttonDrop']:'');
+			$field = ($bDropdown?'<div class="btn-group">':'').'<button id="'.$id.'" type="button" class="btn waves btn-labeled btn-'.$bType.' btn-sm text-uppercase waves-effect waves-float'.$class.''.($bDropdown?' dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"':'"').' '.implode(' ',$tags).'><span class="btn-label"><i class="fa fa-'.$icon.'"></i></span>'.$label.'</button>'.($bDropdown?$bDropdown.'</div>':'');
 			break;
 		case 'space':
 			$labelOut = '';
@@ -1331,6 +1352,297 @@ function timezoneOptions() {
 	return $output;
 }
 
+// Build Database
+function createSQLiteDB() {
+	if (!is_file(DATABASE_LOCATION.'users.db')) {
+		if (!isset($GLOBALS['file_db'])) {
+			$GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
+			$GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+		}
+		
+		// Create Users
+		$users = $GLOBALS['file_db']->query('CREATE TABLE `users` (
+			`id`	INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
+			`username`	TEXT UNIQUE,
+			`password`	TEXT,
+			`email`	TEXT,
+			`token`	TEXT,
+			`role`	TEXT,
+			`active`	TEXT,
+			`last`	TEXT,
+			`auth_service`	TEXT DEFAULT \'internal\'
+		);');
+		
+		// Create Tabs
+		$tabs = $GLOBALS['file_db']->query('CREATE TABLE `tabs` (
+			`id`	INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
+			`users_id`	INTEGER,
+			`name`	TEXT,
+			`url`	TEXT,
+			`defaultz`	TEXT,
+			`active`	TEXT,
+			`user`	TEXT,
+			`guest`	TEXT,
+			`icon`	TEXT,
+			`iconurl`	TEXT,
+			`window`	TEXT
+		);');
+		
+		// Create Options
+		$options = $GLOBALS['file_db']->query('CREATE TABLE `options` (
+			`id`	INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
+			`users_id`	INTEGER UNIQUE,
+			`title`	TEXT UNIQUE,
+			`topbar`	TEXT,
+			`bottombar`	TEXT,
+			`sidebar`	TEXT,
+			`hoverbg`	TEXT,
+			`topbartext`	TEXT,
+			`activetabBG`	TEXT,
+			`activetabicon`	TEXT,
+			`activetabtext`	TEXT,
+			`inactiveicon`	TEXT,
+			`inactivetext`	TEXT,
+			`loading`	TEXT,
+			`hovertext`	TEXT
+		);');
+		
+		return $users && $tabs && $options;
+	} else {
+		return false;
+	}
+}
+
+// Upgrade Database
+function updateSQLiteDB() {
+	if (!isset($GLOBALS['file_db'])) {
+		$GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
+		$GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+	}
+	
+	// Cache current DB
+	$cache = array();
+	foreach($GLOBALS['file_db']->query('SELECT name FROM sqlite_master WHERE type="table";') as $table) {
+		foreach($GLOBALS['file_db']->query('SELECT * FROM '.$table['name'].';') as $key => $row) {
+			foreach($row as $k => $v) {
+				if (is_string($k)) {
+					$cache[$table['name']][$key][$k] = $v;
+				}
+			}
+		}
+	}
+	
+	// Remove Current Database
+	$pathDigest = pathinfo(DATABASE_LOCATION.'users.db');
+	if (file_exists(DATABASE_LOCATION.'users.db')) {
+		rename(DATABASE_LOCATION.'users.db', $pathDigest['dirname'].'/'.$pathDigest['filename'].'.bak.db');
+	}
+    $GLOBALS['file_db'] = null;
+	
+	// Create New Database
+	$success = createSQLiteDB();
+	
+	// Restore Items
+	if ($success) {
+		foreach($cache as $table => $tableData) {
+			if ($tableData) {
+				$queryBase = 'INSERT INTO '.$table.' (`'.implode('`,`',array_keys(current($tableData))).'`) values ';
+				$insertValues = array();
+				reset($tableData);
+				foreach($tableData as $key => $value) {
+					$insertValues[] = '('.implode(',',array_map(function($d) { 
+						return (isset($d)?"'".addslashes($d)."'":'null');
+					}, $value)).')';
+				}
+				$GLOBALS['file_db']->query($queryBase.implode(',',$insertValues).';');
+			}
+		}
+		return true;
+	} else {
+		
+		return false;
+	}
+}
+
+// Commit colours to database
+function updateDBOptions($values) {
+	if (!isset($GLOBALS['file_db'])) {
+		$GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
+		$GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+	}
+	
+	// Commit new values to database
+	$GLOBALS['file_db']->exec('UPDATE options SET '.implode(',',array_map(function($d, $k) { 
+		return '`'.$k.'` = '.(isset($d)?"'".addslashes($d)."'":'null');
+	}, $values, array_keys($values))).';'); // WHERE user_id = '';
+	
+	return true;
+}
+
+// Send AJAX notification
+function sendNotification($success, $message = false) {
+	header('Content-Type: application/json');
+	$notifyExplode = explode("-", NOTIFYEFFECT);
+	if ($success) {
+		$msg = array(
+			'html' => '<strong>'.translate("SETTINGS_SAVED").'</strong>'.($message?'<br>'.$message:''),
+			'icon' => 'floppy-o',
+			'type' => 'success',
+			'length' => '5000',
+			'layout' => $notifyExplode[0],
+			'effect' => $notifyExplode[1],
+		);
+	} else {
+		$msg = array(
+			'html' => '<strong>'.translate("SETTINGS_NOT_SAVED").'</strong>'.($message?'<br>'.$message:''),
+			'icon' => 'floppy-o',
+			'type' => 'failed',
+			'length' => '5000',
+			'layout' => $notifyExplode[0],
+			'effect' => $notifyExplode[1],
+		);
+	}
+	echo json_encode($msg);
+	die();
+}
+
+// Load colours from the database
+function loadAppearance() {
+	if (!isset($GLOBALS['file_db'])) {
+		$GLOBALS['file_db'] = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
+		$GLOBALS['file_db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+	}
+	
+	// Defaults
+	$defaults = array(
+		'title' => 'Organizr',
+		'topbartext' => '#66D9EF',
+		'topbar' => '#333333',
+		'bottombar' => '#333333',
+		'sidebar' => '#393939',
+		'hoverbg' => '#AD80FD',
+		'activetabBG' => '#F92671',
+		'activetabicon' => '#FFFFFF',
+		'activetabtext' => '#FFFFFF',
+		'inactiveicon' => '#66D9EF',
+		'inactivetext' => '#66D9EF',
+		'loading' => '#66D9EF',
+		'hovertext' => '#000000',
+	);
+	
+	// Database Lookup
+	$options = $GLOBALS['file_db']->query('SELECT * FROM options');
+	
+	// Replace defaults with filled options
+	foreach($options as $row) {
+		foreach($defaults as $key => $value) {
+			if (isset($row[$key]) && $row[$key]) {
+				$defaults[$key] = $row[$key];
+			}
+		}
+	}
+	
+	// Return the Results
+	return $defaults;
+}
+
+// Delete Database
+function deleteDatabase() {
+    unset($_COOKIE['Organizr']);
+    setcookie('Organizr', '', time() - 3600, '/');
+    unset($_COOKIE['OrganizrU']);
+    setcookie('OrganizrU', '', time() - 3600, '/');
+	
+    $GLOBALS['file_db'] = null;
+
+    unlink(DATABASE_LOCATION.'users.db'); 
+	
+    foreach(glob(substr_replace($userdirpath, "", -1).'/*') as $file) {
+        if(is_dir($file)) {
+            rmdir($file); 
+        } elseif (!is_dir($file)) {
+            unlink($file);
+        }
+	}
+
+    rmdir($userdirpath);
+	
+	return true;
+}
+
+// Upgrade the installation
+function upgradeInstall() {
+    function downloadFile($url, $path){
+        $folderPath = "upgrade/";
+        if(!mkdir($folderPath)) : echo "can't make dir"; endif;
+        $newfname = $folderPath . $path;
+        $file = fopen ($url, 'rb');
+        if ($file) {
+            $newf = fopen ($newfname, 'wb');
+            if ($newf) {
+                while(!feof($file)) {
+                    fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
+                }
+            }
+        }
+
+        if ($file) {
+            fclose($file);
+        }
+
+        if ($newf) {
+            fclose($newf);
+        }
+    }
+
+    function unzipFile($zipFile){
+        $zip = new ZipArchive;
+        $extractPath = "upgrade/";
+        if($zip->open($extractPath . $zipFile) != "true"){
+            echo "Error :- Unable to open the Zip File";
+        }
+
+        /* Extract Zip File */
+        $zip->extractTo($extractPath);
+        $zip->close();
+    }
+
+    // Function to remove folders and files 
+    function rrmdir($dir) {
+        if (is_dir($dir)) {
+            $files = scandir($dir);
+            foreach ($files as $file)
+                if ($file != "." && $file != "..") rrmdir("$dir/$file");
+            rmdir($dir);
+        }
+        else if (file_exists($dir)) unlink($dir);
+    }
+
+    // Function to Copy folders and files       
+    function rcopy($src, $dst) {
+        if (is_dir ( $src )) {
+            if (!file_exists($dst)) : mkdir ( $dst ); endif;
+            $files = scandir ( $src );
+            foreach ( $files as $file )
+                if ($file != "." && $file != "..")
+                    rcopy ( "$src/$file", "$dst/$file" );
+        } else if (file_exists ( $src ))
+            copy ( $src, $dst );
+    }
+
+    $url = "https://github.com/causefx/Organizr/archive/master.zip";
+    $file = "upgrade.zip";
+    $source = __DIR__ . "/upgrade/Organizr-master/";
+    $cleanup = __DIR__ . "/upgrade/";
+    $destination = __DIR__ . "/";
+    downloadFile($url, $file);
+    unzipFile($file);
+    rcopy($source, $destination);
+    rrmdir($cleanup);
+	
+	return true;
+}
+
 // ==============
 
 function clean($strin) {

+ 98 - 524
settings.php

@@ -12,280 +12,44 @@ $databaseConfig = configLazy('config/config.php');
 require_once("user.php");
 $USER = new User("registration_callback");
 
+// Create Database Connection
+$file_db = new PDO('sqlite:'.DATABASE_LOCATION.'users.db');
+$file_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 
-
-
-$data = false;
-
+// Some PHP config stuff
 ini_set("display_errors", 1);
 ini_set("error_reporting", E_ALL | E_STRICT);
 
-if(!$USER->authenticated) :
+// Confirm Access
+qualifyUser('admin', true);
 
-    header( 'Location: error.php?error=999' );
-
-elseif($USER->authenticated && $USER->role !== "admin") :
-
-    header( 'Location: error.php?error=401' );
-
-endif;
-
-$dbfile = DATABASE_LOCATION.'users.db';
-$databaseLocation = "databaseLocation.ini.php";
-$homepageSettings = "homepageSettings.ini.php";
-$userdirpath = USER_HOME;
-$userdirpath = substr_replace($userdirpath, "", -1);
-
-$file_db = new PDO("sqlite:" . $dbfile);
-$file_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-
-$getUsers = $file_db->query('SELECT * FROM users');
+// Load User List
 $gotUsers = $file_db->query('SELECT * FROM users');
 
-$dbTab = $file_db->query('SELECT name FROM sqlite_master WHERE type="table" AND name="tabs"');
-$dbOptions = $file_db->query('SELECT name FROM sqlite_master WHERE type="table" AND name="options"');
-
-$tabSetup = "Yes";
-$hasOptions = "No";
-
-foreach($dbTab as $row) :
-
-    if (in_array("tabs", $row)) :
-        $tabSetup = "No";
-    endif;
-
-endforeach;
-
-foreach($dbOptions as $row) :
-
-    if (in_array("options", $row)) :
-        $hasOptions = "Yes";
-    endif;
-
-endforeach;
-
-if($hasOptions == "No") :
-
-    $title = "Organizr";
-    $topbar = "#333333"; 
-    $topbartext = "#66D9EF";
-    $bottombar = "#333333";
-    $sidebar = "#393939";
-    $hoverbg = "#AD80FD";
-    $activetabBG = "#F92671";
-    $activetabicon = "#FFFFFF";
-    $activetabtext = "#FFFFFF";
-    $inactiveicon = "#66D9EF";
-    $inactivetext = "#66D9EF";
-    $loading = "#66D9EF";
-    $hovertext = "#000000";
-
-endif;
+// Load Colours/Appearance
+foreach(loadAppearance() as $key => $value) {
+	$$key = $value;
+}
 
-if($tabSetup == "No") :
 
-    $result = $file_db->query('SELECT * FROM tabs');
-endif;
 
-if($hasOptions == "Yes") :
 
-    $resulto = $file_db->query('SELECT * FROM options');
-endif;
 
-if($hasOptions == "Yes") : 
-    foreach($resulto as $row) : 
-
-        $title = isset($row['title']) ? $row['title'] : "Organizr";
-        $topbartext = isset($row['topbartext']) ? $row['topbartext'] : "#66D9EF";
-        $topbar = isset($row['topbar']) ? $row['topbar'] : "#333333";
-        $bottombar = isset($row['bottombar']) ? $row['bottombar'] : "#333333";
-        $sidebar = isset($row['sidebar']) ? $row['sidebar'] : "#393939";
-        $hoverbg = isset($row['hoverbg']) ? $row['hoverbg'] : "#AD80FD";
-        $activetabBG = isset($row['activetabBG']) ? $row['activetabBG'] : "#F92671";
-        $activetabicon = isset($row['activetabicon']) ? $row['activetabicon'] : "#FFFFFF";
-        $activetabtext = isset($row['activetabtext']) ? $row['activetabtext'] : "#FFFFFF";
-        $inactiveicon = isset($row['inactiveicon']) ? $row['inactiveicon'] : "#66D9EF";
-        $inactivetext = isset($row['inactivetext']) ? $row['inactivetext'] : "#66D9EF";
-        $loading = isset($row['loading']) ? $row['loading'] : "#66D9EF";
-        $hovertext = isset($row['hovertext']) ? $row['hovertext'] : "#000000";
 
-    endforeach;
 
-endif;
 
 $action = "";
 if(isset($_POST['action'])) :
-
     $action = $_POST['action'];
 endif;
 
-if($action == "deleteDB") : 
-    unset($_COOKIE['Organizr']);
-    setcookie('Organizr', '', time() - 3600, '/');
-    unset($_COOKIE['OrganizrU']);
-    setcookie('OrganizrU', '', time() - 3600, '/');
-
-    $file_db = null;
-
-    unlink($dbfile); 
-
-    foreach(glob($userdirpath . '/*') as $file) : 
-
-        if(is_dir($file)) :
-
-            rmdir($file); 
-
-        elseif(!is_dir($file)) :
-
-            unlink($file);
-
-        endif;
-
-    endforeach; 
-
-    rmdir($userdirpath);
-
-   echo "<script>window.parent.location.reload();</script>";
-
-endif;
-
-if($action == "deleteLog") : 
-    unlink(FAIL_LOG); 
-
-   echo "<script type='text/javascript'>window.location.replace('settings.php');</script>";
-
-endif;
-
-if($action == "upgrade") : 
-    function downloadFile($url, $path){
-
-        $folderPath = "upgrade/";
-
-        if(!mkdir($folderPath)) : echo "can't make dir"; endif;
-
-        $newfname = $folderPath . $path;
-
-        $file = fopen ($url, 'rb');
-
-        if ($file) {
-
-            $newf = fopen ($newfname, 'wb');
-
-            if ($newf) {
-
-                while(!feof($file)) {
-
-                    fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
-
-                }
-
-            }
-
-        }
-
-        if ($file) {
-
-            fclose($file);
-
-        }
-
-        if ($newf) {
-
-            fclose($newf);
-
-        }
-
-    }
-
-    function unzipFile($zipFile){
-
-        $zip = new ZipArchive;
-
-        $extractPath = "upgrade/";
-
-        if($zip->open($extractPath . $zipFile) != "true"){
-
-            echo "Error :- Unable to open the Zip File";
-        }
-
-        /* Extract Zip File */
-        $zip->extractTo($extractPath);
-        $zip->close();
-
-    }
-
-    // Function to remove folders and files 
-    function rrmdir($dir) {
-
-        if (is_dir($dir)) {
-
-            $files = scandir($dir);
-
-            foreach ($files as $file)
-
-                if ($file != "." && $file != "..") rrmdir("$dir/$file");
-
-            rmdir($dir);
-
-        }
-
-        else if (file_exists($dir)) unlink($dir);
-
-    }
-
-    // Function to Copy folders and files       
-    function rcopy($src, $dst) {
-
-        if (is_dir ( $src )) {
-
-            if (!file_exists($dst)) : mkdir ( $dst ); endif;
-
-            $files = scandir ( $src );
-
-            foreach ( $files as $file )
-
-                if ($file != "." && $file != "..")
-
-                    rcopy ( "$src/$file", "$dst/$file" );
-
-        } else if (file_exists ( $src ))
-
-            copy ( $src, $dst );
-
-    }
-
-    $url = "https://github.com/causefx/Organizr/archive/master.zip";
-
-    $file = "upgrade.zip";
-
-    $source = __DIR__ . "/upgrade/Organizr-master/";
-
-    $cleanup = __DIR__ . "/upgrade/";
-
-    $destination = __DIR__ . "/";
-
-    downloadFile($url, $file);
-    unzipFile($file);
-
-    rcopy($source, $destination);
-    rrmdir($cleanup);
-
-    echo "<script>top.location.href = 'index.php#upgrade';</script>";
-
-endif;
 if(!isset($_POST['op'])) :
 
     $_POST['op'] = "";
 endif; 
 
 if($action == "addTabz") :
-    if($tabSetup == "No") :
-
-        $file_db->exec("DELETE FROM tabs");
-    endif;
-    if($tabSetup == "Yes") :
-        $file_db->exec("CREATE TABLE tabs (name TEXT UNIQUE, url TEXT, defaultz TEXT, active TEXT, user TEXT, guest TEXT, icon TEXT, iconurl TEXT, window TEXT)");
-    endif;
+	$file_db->exec("DELETE FROM tabs");
 
     $addTabName = array();
     $addTabUrl = array();
@@ -382,49 +146,6 @@ if($action == "addTabz") :
     endforeach;
 endif;
 
-if($action == "addOptionz") :
-    if($hasOptions == "Yes") :
-        $file_db->exec("DELETE FROM options");
-    endif;
-    if($hasOptions == "No") :
-
-        $file_db->exec("CREATE TABLE options (title TEXT UNIQUE, topbar TEXT, bottombar TEXT, sidebar TEXT, hoverbg TEXT, topbartext TEXT, activetabBG TEXT, activetabicon TEXT, activetabtext TEXT, inactiveicon TEXT, inactivetext TEXT, loading TEXT, hovertext TEXT)");
-    endif;
-    $title = $_POST['title'];
-    $topbartext = $_POST['topbartext'];
-    $topbar = $_POST['topbar'];
-    $bottombar = $_POST['bottombar'];
-    $sidebar = $_POST['sidebar'];
-    $hoverbg = $_POST['hoverbg'];
-    $hovertext = $_POST['hovertext'];
-    $activetabBG = $_POST['activetabBG'];
-    $activetabicon = $_POST['activetabicon'];
-    $activetabtext = $_POST['activetabtext'];
-    $inactiveicon = $_POST['inactiveicon'];
-    $inactivetext = $_POST['inactivetext'];
-    $loading = $_POST['loading'];
-
-    $insert = "INSERT INTO options (title, topbartext, topbar, bottombar, sidebar, hoverbg, activetabBG, activetabicon, activetabtext, inactiveicon, inactivetext, loading, hovertext) 
-                VALUES (:title, :topbartext, :topbar, :bottombar, :sidebar, :hoverbg, :activetabBG, :activetabicon , :activetabtext , :inactiveicon, :inactivetext, :loading, :hovertext)";
-    $stmt = $file_db->prepare($insert);
-    $stmt->bindParam(':title', $title);
-    $stmt->bindParam(':topbartext', $topbartext);
-    $stmt->bindParam(':topbar', $topbar);
-    $stmt->bindParam(':bottombar', $bottombar);
-    $stmt->bindParam(':sidebar', $sidebar);
-    $stmt->bindParam(':hoverbg', $hoverbg);
-    $stmt->bindParam(':activetabBG', $activetabBG);
-    $stmt->bindParam(':activetabicon', $activetabicon);
-    $stmt->bindParam(':activetabtext', $activetabtext);
-    $stmt->bindParam(':inactiveicon', $inactiveicon);
-    $stmt->bindParam(':inactivetext', $inactivetext);
-    $stmt->bindParam(':loading', $loading);
-    $stmt->bindParam(':hovertext', $hovertext);
-
-    $stmt->execute();
-
-endif;
-
 if(SLIMBAR == "true") : $slimBar = "30"; $userSize = "25"; else : $slimBar = "56"; $userSize = "40"; endif;
 ?>
 
@@ -762,9 +483,9 @@ endif; ?>
 
                                                 <ul class="list-group ui-sortable">
 
-                                                    <?php if($tabSetup == "No") : $tabNum = 1; 
-
-                                                    foreach($result as $row) : 
+                                                    <?php  
+													$tabNum = 1;
+                                                    foreach($file_db->query('SELECT * FROM tabs') as $row) {
 
                                                     if($row['defaultz'] == "true") : $default = "checked"; else : $default = ""; endif;
                                                     if($row['active'] == "true") : $activez = "checked"; else : $activez = ""; endif;
@@ -895,7 +616,7 @@ endif; ?>
                                                         </tab>
 
                                                     </li>
-                                                    <?php $tabNum ++; endforeach; endif;?>
+                                                    <?php $tabNum ++; }?>
 
                                                 </ul>
 
@@ -921,14 +642,61 @@ endif; ?>
 
                 <div class="email-content color-box white-bg">
 <?php
-
 // Build Colour Settings
-/*
 echo buildSettings(
 	array(
-		'title' => 'Homepage Settings',
-		'id' => 'homepage_settings',
+		'title' => 'Appearance Settings',
+		'id' => 'appearance_settings',
+		'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">
+	<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").'
+	</button>
+
+	<button class="btn waves btn-labeled btn-success btn-sm pull-right text-uppercase waves-effect waves-float" type="submit">
+
+	<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>
+</form>',
 		'fields' => array(
+			array(
+				array(
+					'type' => 'button',
+					'labelTranslate' => 'CHOOSE_THEME',
+					'icon' => 'css3',
+					'id' => 'themeSelector',
+					'buttonType' => 'dark',
+					'buttonDrop' => '
+<ul class="dropdown-menu gray-bg">
+	<li class="chooseTheme" id="plexTheme" style="border: 1px #FFFFFF; border-style: groove; background: #000000; border-radius: 5px; margin: 5px;"><a style="color: #E49F0C !important;" href="#">Plex<span><img class="themeImage" src="images/themes/plex.png"></span></a></li>
+	<li class="chooseTheme" id="newPlexTheme" style="border: 1px #E5A00D; border-style: groove; background: #282A2D; border-radius: 5px; margin: 5px;"><a style="color: #E5A00D !important;" href="#">New Plex<span><img class="themeImage" src="images/themes/newplex.png"></span></a></li>
+	<li class="chooseTheme" id="embyTheme" style="border: 1px #FFFFFF; border-style: groove; background: #212121; border-radius: 5px; margin: 5px;"><a style="color: #52B54B !important;" href="#">Emby<span><img class="themeImage" src="images/themes/emby.png"></span></a></li>
+	<li class="chooseTheme" id="bookTheme" style="border: 1px #FFFFFF; border-style: groove; background: #3B5998; border-radius: 5px; margin: 5px;"><a style="color: #FFFFFF !important;" href="#">Facebook<span><img class="themeImage" src="images/themes/facebook.png"></span></a></li>
+	<li class="chooseTheme" id="spaTheme" style="border: 1px #66BBAE; border-style: groove; background: #66BBAE; border-radius: 5px; margin: 5px;"><a style="color: #5B391E !important;" href="#">Spa<span><img class="themeImage" src="images/themes/spa.png"></span></a></li>
+	<li class="chooseTheme" id="darklyTheme" style="border: 1px #464545; border-style: groove; background: #375A7F; border-radius: 5px; margin: 5px;"><a style="color: #FFFFFF !important;" href="#">Darkly<span><img class="themeImage" src="images/themes/darkly.png"></span></a></li>
+	<li class="chooseTheme" id="slateTheme" style="border: 1px #58C0DE; border-style: groove; background: #272B30; border-radius: 5px; margin: 5px;"><a style="color: #C8C8C8 !important;" href="#">Slate<span><img class="themeImage" src="images/themes/slate.png"></span></a></li>
+	<li class="chooseTheme" id="monokaiTheme" style="border: 1px #AD80FD; border-style: groove; background: #333333; border-radius: 5px; margin: 5px;"><a style="color: #66D9EF !important;" href="#">Monokai<span><img class="themeImage" src="images/themes/monokai.png"></span></a></li>
+	<li class="chooseTheme" id="thejokerTheme" style="border: 1px #CCC6CC; border-style: groove; background: #000000; border-radius: 5px; margin: 5px;"><a style="color: #CCCCCC !important;" href="#">The Joker<span><img class="themeImage" src="images/themes/joker.png"></span></a></li>
+	<li class="chooseTheme" id="redTheme" style="border: 1px #eb6363; border-style: groove; background: #eb6363; border-radius: 5px; margin: 5px;"><a style="color: #FFFFFF !important;" href="#">Original Red<span><img class="themeImage" src="images/themes/original.png"></span></a></li>
+</ul>
+					',
+				),
+				array(
+					'type' => 'button',
+					'labelTranslate' => 'EDIT_CUSTOM_CSS',
+					'icon' => 'css3',
+					'buttonType' => 'primary',
+					'id' => 'editCssButton',
+				),
+			),
 			array(
 				'type' => 'header',
 				'labelTranslate' => 'TITLE',
@@ -938,7 +706,8 @@ echo buildSettings(
 					'type' => 'text',
 					'format' => 'colour',
 					'labelTranslate' => 'TITLE',
-					'name' => 'colour_',
+					'name' => 'title',
+					'id' => 'title',
 					'value' => $title,
 				),
 				array(
@@ -946,7 +715,8 @@ echo buildSettings(
 					'format' => 'colour',
 					'class' => 'jscolor {hash:true}',
 					'labelTranslate' => 'TITLE_TEXT',
-					'name' => 'colour_',
+					'name' => 'topbartext',
+					'id' => 'topbartext',
 					'value' => $topbartext,
 				),
 				array(
@@ -954,7 +724,8 @@ echo buildSettings(
 					'format' => 'colour',
 					'class' => 'jscolor {hash:true}',
 					'labelTranslate' => 'LOADING_COLOR',
-					'name' => 'colour_',
+					'name' => 'loading',
+					'id' => 'loading',
 					'value' => $loading,
 				),
 			),
@@ -968,7 +739,8 @@ echo buildSettings(
 					'format' => 'colour',
 					'class' => 'jscolor {hash:true}',
 					'labelTranslate' => 'TOP_BAR',
-					'name' => 'colour_',
+					'name' => 'topbar',
+					'id' => 'topbar',
 					'value' => $topbar,
 				),
 				array(
@@ -976,7 +748,8 @@ echo buildSettings(
 					'format' => 'colour',
 					'class' => 'jscolor {hash:true}',
 					'labelTranslate' => 'BOTTOM_BAR',
-					'name' => 'colour_',
+					'name' => 'bottombar',
+					'id' => 'bottombar',
 					'value' => $bottombar,
 				),
 				array(
@@ -984,7 +757,8 @@ echo buildSettings(
 					'format' => 'colour',
 					'class' => 'jscolor {hash:true}',
 					'labelTranslate' => 'SIDE_BAR',
-					'name' => 'colour_',
+					'name' => 'sidebar',
+					'id' => 'sidebar',
 					'value' => $sidebar,
 				),
 			),
@@ -994,7 +768,8 @@ echo buildSettings(
 					'format' => 'colour',
 					'class' => 'jscolor {hash:true}',
 					'labelTranslate' => 'HOVER_BG',
-					'name' => 'colour_',
+					'name' => 'hoverbg',
+					'id' => 'hoverbg',
 					'value' => $hoverbg,
 				),
 				array(
@@ -1002,7 +777,8 @@ echo buildSettings(
 					'format' => 'colour',
 					'class' => 'jscolor {hash:true}',
 					'labelTranslate' => 'HOVER_TEXT',
-					'name' => 'colour_',
+					'name' => 'hovertext',
+					'id' => 'hovertext',
 					'value' => $hovertext,
 				),
 			),
@@ -1016,7 +792,8 @@ echo buildSettings(
 					'format' => 'colour',
 					'class' => 'jscolor {hash:true}',
 					'labelTranslate' => 'ACTIVE_TAB_BG',
-					'name' => 'colour_',
+					'name' => 'activetabBG',
+					'id' => 'activetabBG',
 					'value' => $activetabBG,
 				),
 				array(
@@ -1024,7 +801,8 @@ echo buildSettings(
 					'format' => 'colour',
 					'class' => 'jscolor {hash:true}',
 					'labelTranslate' => 'ACTIVE_TAB_ICON',
-					'name' => 'colour_',
+					'name' => 'activetabicon',
+					'id' => 'activetabicon',
 					'value' => $activetabicon,
 				),
 				array(
@@ -1032,7 +810,8 @@ echo buildSettings(
 					'format' => 'colour',
 					'class' => 'jscolor {hash:true}',
 					'labelTranslate' => 'ACTIVE_TAB_TEXT',
-					'name' => 'colour_',
+					'name' => 'activetabtext',
+					'id' => 'activetabtext',
 					'value' => $activetabtext,
 				),
 			),
@@ -1046,7 +825,8 @@ echo buildSettings(
 					'format' => 'colour',
 					'class' => 'jscolor {hash:true}',
 					'labelTranslate' => 'INACTIVE_ICON',
-					'name' => 'colour_',
+					'name' => 'inactiveicon',
+					'id' => 'inactiveicon',
 					'value' => $inactiveicon,
 				),
 				array(
@@ -1054,211 +834,15 @@ echo buildSettings(
 					'format' => 'colour',
 					'class' => 'jscolor {hash:true}',
 					'labelTranslate' => 'INACTIVE_TEXT',
-					'name' => 'colour_',
+					'name' => 'inactivetext',
+					'id' => 'inactivetext',
 					'value' => $inactivetext,
 				),
 			),
 		),
 	)
 );
-*/
-?>				
-                    <div class="email-body">
-                        <div class="email-header gray-bg">
-                            <button type="button" class="btn btn-danger btn-sm waves close-button"><i class="fa fa-close"></i></button>
-                            <h1>Color Settings</h1>
-                        </div>
-                        <div class="email-inner small-box">
-                            <div class="email-inner-section">
-                                <div class="small-box fade in" id="customedit">
-
-                                    <form id="add_optionz" method="post">
-                                        <input type="hidden" name="action" value="addOptionz" />
-                                        <div class="btn-group">
-                                            <button type="button" class="btn btn-dark dropdown-toggle btn-sm" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
-                                            <?php echo $language->translate("CHOOSE_THEME");?>  <span class="caret"></span>
-                                            </button>
-                                            <ul class="dropdown-menu gray-bg">
-                                                <li class="chooseTheme" id="plexTheme" style="border: 1px #FFFFFF; border-style: groove; background: #000000; border-radius: 5px; margin: 5px;"><a style="color: #E49F0C !important;" href="#">Plex<span><img class="themeImage" src="images/themes/plex.png"></span></a></li>
-                                                <li class="chooseTheme" id="newPlexTheme" style="border: 1px #E5A00D; border-style: groove; background: #282A2D; border-radius: 5px; margin: 5px;"><a style="color: #E5A00D !important;" href="#">New Plex<span><img class="themeImage" src="images/themes/newplex.png"></span></a></li>
-                                                <li class="chooseTheme" id="embyTheme" style="border: 1px #FFFFFF; border-style: groove; background: #212121; border-radius: 5px; margin: 5px;"><a style="color: #52B54B !important;" href="#">Emby<span><img class="themeImage" src="images/themes/emby.png"></span></a></li>
-                                                <li class="chooseTheme" id="bookTheme" style="border: 1px #FFFFFF; border-style: groove; background: #3B5998; border-radius: 5px; margin: 5px;"><a style="color: #FFFFFF !important;" href="#">Facebook<span><img class="themeImage" src="images/themes/facebook.png"></span></a></li>
-                                                <li class="chooseTheme" id="spaTheme" style="border: 1px #66BBAE; border-style: groove; background: #66BBAE; border-radius: 5px; margin: 5px;"><a style="color: #5B391E !important;" href="#">Spa<span><img class="themeImage" src="images/themes/spa.png"></span></a></li>
-                                                <li class="chooseTheme" id="darklyTheme" style="border: 1px #464545; border-style: groove; background: #375A7F; border-radius: 5px; margin: 5px;"><a style="color: #FFFFFF !important;" href="#">Darkly<span><img class="themeImage" src="images/themes/darkly.png"></span></a></li>
-                                                <li class="chooseTheme" id="slateTheme" style="border: 1px #58C0DE; border-style: groove; background: #272B30; border-radius: 5px; margin: 5px;"><a style="color: #C8C8C8 !important;" href="#">Slate<span><img class="themeImage" src="images/themes/slate.png"></span></a></li>
-                                                <li class="chooseTheme" id="monokaiTheme" style="border: 1px #AD80FD; border-style: groove; background: #333333; border-radius: 5px; margin: 5px;"><a style="color: #66D9EF !important;" href="#">Monokai<span><img class="themeImage" src="images/themes/monokai.png"></span></a></li>
-                                                <li class="chooseTheme" id="thejokerTheme" style="border: 1px #CCC6CC; border-style: groove; background: #000000; border-radius: 5px; margin: 5px;"><a style="color: #CCCCCC !important;" href="#">The Joker<span><img class="themeImage" src="images/themes/joker.png"></span></a></li>
-                                                <li class="chooseTheme" id="redTheme" style="border: 1px #eb6363; border-style: groove; background: #eb6363; border-radius: 5px; margin: 5px;"><a style="color: #FFFFFF !important;" href="#">Original Red<span><img class="themeImage" src="images/themes/original.png"></span></a></li>
-                                            </ul>
-                                        </div>
-                                        <button id="editCssButton" class="btn waves btn-labeled btn-primary btn-sm text-uppercase waves-effect waves-float" type="button">
-                                                <span class="btn-label"><i class="fa fa-css3"></i></span><?php echo $language->translate("EDIT_CUSTOM_CSS");?>
-                                        </button>
-                                        <button class="btn waves btn-labeled btn-success btn-sm pull-right text-uppercase waves-effect waves-float" type="submit">
-                                                <span class="btn-label"><i class="fa fa-floppy-o"></i></span><?php echo $language->translate("SAVE_OPTIONS");?>
-                                        </button>
-
-                                        <div class="big-box grids">
-
-                                            <div class="row show-grids col-lg-12">
-
-                                                <h4><strong><?php echo $language->translate("TITLE");?></strong></h4>
-
-                                                <div class="col-md-4 gray-bg">
-
-                                                    <center><?php echo $language->translate("TITLE");?></center>
-
-                                                    <input name="title" class="form-control gray" value="<?=$title;?>" placeholder="Organizr">
-
-                                                </div>
-
-                                                <div class="col-md-4 gray-bg">
-
-                                                    <center><?php echo $language->translate("TITLE_TEXT");?></center>
-
-                                                    <input name="topbartext" id="topbartext" class="form-control jscolor {hash:true}" value="<?=$topbartext;?>">
-
-                                                </div>
-                                                <div class="col-md-4 gray-bg">
-
-                                                    <center><?php echo $language->translate("LOADING_COLOR");?></center>
-
-                                                    <input name="loading" id="loading" class="form-control jscolor {hash:true}" value="<?=$loading;?>">
-
-                                                </div>
-
-                                            </div>
-
-                                            <div class="row show-grids col-lg-12">
-
-                                                <h4><strong><?php echo $language->translate("NAVIGATION_BARS");?></strong></h4>
-
-                                                <div class="col-md-4 gray-bg">
-
-                                                    <center><?php echo $language->translate("TOP_BAR");?></center>
-
-                                                    <input name="topbar" id="topbar" class="form-control jscolor {hash:true}" value="<?=$topbar;?>">
-
-                                                </div>
-
-                                                <div class="col-md-4 gray-bg">
-
-                                                    <center><?php echo $language->translate("BOTTOM_BAR");?></center>
-
-                                                    <input name="bottombar" id="bottombar" class="form-control jscolor {hash:true}" value="<?=$bottombar;?>">
-
-                                                </div>
-
-                                                <div class="clearfix visible-xs-block"></div>
-
-                                                <div class="col-md-4 gray-bg">
-
-                                                    <center><?php echo $language->translate("SIDE_BAR");?></center>
-
-                                                    <input name="sidebar" id="sidebar" class="form-control jscolor {hash:true}" value="<?=$sidebar;?>">
-
-                                                </div>
-                                            </div>
-                                            <div class="row show-grids col-lg-12">
-
-                                                <div class="col-md-6 gray-bg">
-
-                                                    <center><?php echo $language->translate("HOVER_BG");?></center>
-
-                                                    <input name="hoverbg" id="hoverbg" class="form-control jscolor {hash:true}" value="<?=$hoverbg;?>">
-
-                                                </div>
-                                                <div class="col-md-6 gray-bg">
-
-                                                    <center><?php echo $language->translate("HOVER_TEXT");?></center>
-
-                                                    <input name="hovertext" id="hovertext" class="form-control jscolor {hash:true}" value="<?=$hovertext;?>">
-
-                                                </div>
-
-                                            </div>
-
-                                            <div class="row show-grids col-lg-12">
-
-                                                <h4><strong><?php echo $language->translate("ACTIVE_TAB");?></strong></h4>
-
-                                                <div class="col-md-4 gray-bg">
-
-                                                    <center><?php echo $language->translate("ACTIVE_TAB_BG");?></center>
-
-                                                    <input name="activetabBG" id="activetabBG" class="form-control jscolor {hash:true}" value=<?=$activetabBG;?>"">
-
-                                                </div>
-
-                                                <div class="col-md-4 gray-bg">
-
-                                                    <center><?php echo $language->translate("ACTIVE_TAB_ICON");?></center>
-
-                                                    <input name="activetabicon" id="activetabicon" class="form-control jscolor {hash:true}" value="<?=$activetabicon;?>">
-
-                                                </div>
-
-                                                <div class="col-md-4 gray-bg">
-
-                                                    <center><?php echo $language->translate("ACTIVE_TAB_TEXT");?></center>
-
-                                                    <input name="activetabtext" id="activetabtext" class="form-control jscolor {hash:true}" value="<?=$activetabtext;?>">
-
-                                                </div>
-
-                                            </div>
-
-                                            <div class="row show-grids col-lg-12">
-
-                                                <h4><strong><?php echo $language->translate("INACTIVE_TAB");?></strong></h4>
-
-                                                <div class="col-md-6 gray-bg">
-
-                                                    <center><?php echo $language->translate("INACTIVE_ICON");?></center>
-
-                                                    <input name="inactiveicon" id="inactiveicon" class="form-control jscolor {hash:true}" value="<?=$inactiveicon;?>">
-
-                                                </div>
-
-                                                <div class="col-md-6 gray-bg">
-
-                                                    <center><?php echo $language->translate("INACTIVE_TEXT");?></center>
-
-                                                    <input name="inactivetext" id="inactivetext" class="form-control jscolor {hash:true}" value="<?=$inactivetext;?>">
-
-                                                </div>
-
-                                            </div>
-
-                                        </div>
-                                    </form>
-                                     <form style="display: none" id="editCssForm" method="POST" action="ajax.php">
-                                         <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><?php echo $language->translate("GO_BACK");?>
-                                        </button>
-                                         
-                                         <button class="btn waves btn-labeled btn-success btn-sm pull-right text-uppercase waves-effect waves-float" type="submit">
-
-                                            <span class="btn-label"><i class="fa fa-floppy-o"></i></span><?php echo $language->translate("SAVE_CSS");?>
-                                        </button>
-                                        <br><br>
-                                        <input type="hidden" name="submit" value="editCSS" /> 
-                                        <h1><?php echo $language->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;">
-<?php if(CUSTOMCSS == "true") :
-$template_file = "custom.css";
-$file_handle = fopen($template_file, "rb");
-echo fread($file_handle, filesize($template_file));
-fclose($file_handle);
-endif;?></textarea>
-                                    </form>
-                                </div>
-                            </div>
-
-                        </div>
-                    </div>
+?>
                 </div>
                 <div class="email-content homepage-box white-bg">
 <?php
@@ -2213,8 +1797,7 @@ echo buildSettings(
                                         <div class="panel-body">
                                             <div class="">
                                                 <p><?php echo $language->translate("DELETE_WARNING");?></p>
-                                                <form id="deletedb" method="post">
-                                                    <input type="hidden" name="action" value="deleteDB" />
+                                                <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;">
                                                     <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>
@@ -2780,16 +2363,6 @@ echo buildSettings(
 
                 $( "#deleteDiv" ).toggle();
             });
-            $("#editCssButton").click(function(){
-
-                $( "#add_optionz" ).toggle();
-                $( "#editCssForm" ).toggle();
-            });
-            $("#backToThemeButton").click(function(){
-
-                $( "#add_optionz" ).toggle();
-                $( "#editCssForm" ).toggle();
-            });
             $(".deleteUser").click(function(){
 
                 var parent_id = $(this).parent().attr('id');
@@ -2912,6 +2485,7 @@ echo buildSettings(
                 definedElement.focus();
                 definedElement.value = elementColor;
                 definedElement.style.backgroundColor = elementColor;
+				$(definedElement).trigger('change');
             }
 
             $('#plexTheme').on('click touchstart', function(){
@@ -3315,7 +2889,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"><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="$.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>')
             $("a[id^='ToolTables_datatable_0'] span").html('<?php echo $language->translate("PRINT");?>')
             //Enable Tooltips
             $('[data-toggle="tooltip"]').tooltip(); 
@@ -3349,7 +2923,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\"><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=\"$.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>");
                         $( "p[id^='upgrade']" ).toggle();
                     }else if(currentVersion === githubVersion){
                     	console.log("You Are on Current Version");

+ 2 - 4
user.php

@@ -165,10 +165,8 @@
 		function rebuild_database($dbfile)
 		{
 			$this->info("creating/rebuilding database as ".$dbfile);
-			$this->database->beginTransaction();
-			$create = "CREATE TABLE users (username TEXT UNIQUE, password TEXT, email TEXT UNIQUE, token TEXT, role TEXT, active TEXT, last TEXT);";
-			$this->database->exec($create);
-			$this->database->commit();
+			createSQLiteDB();
+			$this->database = new PDO("sqlite:" . $dbfile);
 		}
 		// process a page request
 		function process(&$registration_callback=false)