About Organizr
Submit Issue or Request View On Github Chat With Us
Delete Database
Only do this if an upgrade requires it. This will delete your database so there is no going back and you will need to set everything back up, including user accouts.
authenticated) :
die("Why you trying to access this without logging in?!?!");
elseif($USER->authenticated && $USER->role !== "admin") :
die("C'mon man! I give you access to my stuff and now you're trying to get in the back door?");
endif;
function printArray($arrayName){
foreach ( $arrayName as $item ) :
echo $item . "
";
endforeach;
}
$dbfile = DATABASE_LOCATION . constant('User::DATABASE_NAME') . ".db";
$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');
$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 = "#eb6363";
$topbartext = "#FFFFFF";
$bottombar = "#eb6363";
$sidebar = "#000000";
$hoverbg = "#eb6363";
$activetabBG = "#eb6363";
$activetabicon = "#FFFFFF";
$activetabtext = "#FFFFFF";
$inactiveicon = "#FFFFFF";
$inactivetext = "#FFFFFF";
endif;
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 = $row['title'];
$topbartext = $row['topbartext'];
$topbar = $row['topbar'];
$bottombar = $row['bottombar'];
$sidebar = $row['sidebar'];
$hoverbg = $row['hoverbg'];
$activetabBG = $row['activetabBG'];
$activetabicon = $row['activetabicon'];
$activetabtext = $row['activetabtext'];
$inactiveicon = $row['inactiveicon'];
$inactivetext = $row['inactivetext'];
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 "";
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 "";
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;
$addTabName = array();
$addTabUrl = array();
$addTabIcon = array();
$addTabIconUrl = array();
$addTabDefault = array();
$addTabActive = array();
$addTabUser = array();
$addTabGuest = array();
$addTabWindow = array();
$buildArray = array();
foreach ($_POST as $key => $value) :
$trueKey = explode('-', $key);
if ($value == "on") :
$value = "true";
endif;
if($trueKey[0] == "name"):
array_push($addTabName, $value);
endif;
if($trueKey[0] == "url"):
array_push($addTabUrl, $value);
endif;
if($trueKey[0] == "icon"):
array_push($addTabIcon, $value);
endif;
if($trueKey[0] == "iconurl"):
array_push($addTabIconUrl, $value);
endif;
if($trueKey[0] == "default"):
array_push($addTabDefault, $value);
endif;
if($trueKey[0] == "active"):
array_push($addTabActive, $value);
endif;
if($trueKey[0] == "user"):
array_push($addTabUser, $value);
endif;
if($trueKey[0] == "guest"):
array_push($addTabGuest, $value);
endif;
if($trueKey[0] == "window"):
array_push($addTabWindow, $value);
endif;
endforeach;
$tabArray = 0;
if(count($addTabName) > 0) :
foreach(range(1,count($addTabName)) as $index) :
if(!isset($addTabDefault[$tabArray])) :
$tabDefault = "false";
else :
$tabDefault = $addTabDefault[$tabArray];
endif;
$buildArray[] = array('name' => $addTabName[$tabArray],
'url' => $addTabUrl[$tabArray],
'defaultz' => $tabDefault,
'active' => $addTabActive[$tabArray],
'user' => $addTabUser[$tabArray],
'guest' => $addTabGuest[$tabArray],
'icon' => $addTabIcon[$tabArray],
'window' => $addTabWindow[$tabArray],
'iconurl' => $addTabIconUrl[$tabArray]);
$tabArray++;
endforeach;
endif;
$insert = "INSERT INTO tabs (name, url, defaultz, active, user, guest, icon, iconurl, window)
VALUES (:name, :url, :defaultz, :active, :user, :guest, :icon, :iconurl, :window)";
$stmt = $file_db->prepare($insert);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':url', $url);
$stmt->bindParam(':defaultz', $defaultz);
$stmt->bindParam(':active', $active);
$stmt->bindParam(':user', $user);
$stmt->bindParam(':guest', $guest);
$stmt->bindParam(':icon', $icon);
$stmt->bindParam(':iconurl', $iconurl);
$stmt->bindParam(':window', $window);
foreach ($buildArray as $t) :
$name = $t['name'];
$url = $t['url'];
$defaultz = $t['defaultz'];
$active = $t['active'];
$user = $t['user'];
$guest = $t['guest'];
$icon = $t['icon'];
$iconurl = $t['iconurl'];
$window = $t['window'];
$stmt->execute();
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)");
endif;
$title = $_POST['title'];
$topbartext = $_POST['topbartext'];
$topbar = $_POST['topbar'];
$bottombar = $_POST['bottombar'];
$sidebar = $_POST['sidebar'];
$hoverbg = $_POST['hoverbg'];
$activetabBG = $_POST['activetabBG'];
$activetabicon = $_POST['activetabicon'];
$activetabtext = $_POST['activetabtext'];
$inactiveicon = $_POST['inactiveicon'];
$inactivetext = $_POST['inactivetext'];
$insert = "INSERT INTO options (title, topbartext, topbar, bottombar, sidebar, hoverbg, activetabBG, activetabicon, activetabtext, inactiveicon, inactivetext)
VALUES (:title, :topbartext, :topbar, :bottombar, :sidebar, :hoverbg, :activetabBG, :activetabicon , :activetabtext , :inactiveicon, :inactivetext)";
$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->execute();
endif;
?>
Submit Issue or Request View On Github Chat With Us
Only do this if an upgrade requires it. This will delete your database so there is no going back and you will need to set everything back up, including user accouts.