<?php
//Getting config file
require_once dirname(__FILE__) . '/../config/config.php';
require_once dirname(__FILE__) . '/../src/plugins/class.phpmailer.php';
require_once dirname(__FILE__) . '/../src/plugins/class.smtp.php';

ob_start();

function recursiveRemoveDirectory($directory)
{
    foreach(glob("{$directory}/*") as $file)
    {
        if(is_dir($file)) { 
            recursiveRemoveDirectory($file);
        } else {
            unlink($file);
        }
    }
    rmdir($directory);
}
function get_proxibolt_api( $url )
{
    $user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';

    $options = array(

        CURLOPT_CUSTOMREQUEST  =>"GET",        //set request type post or get
        CURLOPT_POST           =>false,        //set to GET
        CURLOPT_USERAGENT      => $user_agent, //set user agent
        CURLOPT_RETURNTRANSFER => true,     // return web page
        CURLOPT_HEADER         => false,    // don't return headers
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
        CURLOPT_ENCODING       => "",       // handle all encodings
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
        CURLOPT_TIMEOUT        => 120,      // timeout on response
        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
    );

    $ch      = curl_init( $url );
    curl_setopt_array( $ch, $options );
    $content = curl_exec( $ch );
    $header  = curl_getinfo( $ch );
    curl_close( $ch );

    return $content;
}

//Check if post is set
if(isset($_POST)) {
	$action = $_POST['action'];

	//Check if user is logged in
	if((!isset($_SESSION['droppy_admin']) && $action != 'login')) {
		header('Location: login.php?e=noadmin');
		exit();
	}

	switch ($action) {
		case 'login':
			$email = mysqli_real_escape_string($mysqli, $_POST['email']);
			$password = md5(mysqli_real_escape_string($mysqli, $_POST['password']));

	        if(empty($_POST['validate_id'])) {
	            $result = $mysqli->query("SELECT * FROM $table_accounts WHERE email='$email' and password='$password'");
	            $count = $result->num_rows;
	            if ($count == 1) {
	                $_SESSION['droppy_admin'] = $email;
	                header('Location: index.php');
	            } else {
	                header('Location: login.php?e=wrong');
	            }
	        }
	        else
	        {
	            header('Location: login.php');
	        }
		break;
		case 'settings_personal':
			$email = mysqli_real_escape_string($mysqli, $_POST['email']);
			$password = md5(mysqli_real_escape_string($mysqli, $_POST['password']));

			if(empty($_POST['password'])) {
				$mysqli->query("UPDATE $table_accounts SET email='$email'");
			}
			else
			{
				$mysqli->query("UPDATE $table_accounts SET email='$email', password='$password'");
			}
			header('Location: action.php?action=logout');
		break;
		case 'settings_general':
			$site_name_new 			= mysqli_real_escape_string($mysqli, $_POST['site_name']);
			$site_title_new 		= mysqli_real_escape_string($mysqli, $_POST['site_title']);
			$site_desc_new			= mysqli_real_escape_string($mysqli, $_POST['site_desc']);
			$expire_new 			= mysqli_real_escape_string($mysqli, $_POST['expire']);
			$logo_path_new			= mysqli_real_escape_string($mysqli, $_POST['logo_path']);
			$favicon_path_new 		= mysqli_real_escape_string($mysqli, $_POST['favicon_path']);
			$lang_new 				= mysqli_real_escape_string($mysqli, $_POST['lang']);
			$max_upload 			= mysqli_real_escape_string($mysqli, $_POST['max_upload']);
			$upload_dir_new 		= mysqli_real_escape_string($mysqli, $_POST['upload_dir']);
			$bg_timer_new 			= mysqli_real_escape_string($mysqli, $_POST['bg_timer']);
			$disallowed_types_new 	= mysqli_real_escape_string($mysqli, $_POST['blocked_types']);
			$site_url_new 			= mysqli_real_escape_string($mysqli, $_POST['site_url']);
			$new_max_reports 		= mysqli_real_escape_string($mysqli, $_POST['max_file_reports']);
			$new_lock_page 			= mysqli_real_escape_string($mysqli, $_POST['lock_page']);
			$new_default_destruct 	= mysqli_real_escape_string($mysqli, $_POST['default_destruct']);
			$new_default_sharetype 	= mysqli_real_escape_string($mysqli, $_POST['default_sharetype']);
			$new_password_enabled 	= mysqli_real_escape_string($mysqli, $_POST['password_enabled']);
			$new_analytics_code 	= mysqli_real_escape_string($mysqli, $_POST['analytics']);
			$new_max_files 			= mysqli_real_escape_string($mysqli, $_POST['max_select']);
			$new_default_email_to 	= mysqli_real_escape_string($mysqli, $_POST['default_email_to']);
			$new_name_on_file 		= mysqli_real_escape_string($mysqli, $_POST['name_on_file']);
			$new_encrypt_files      = mysqli_real_escape_string($mysqli, $_POST['encrypt_files']);
			if($new_max_files == 0) {
				$new_max_files = '';
			}

			//$max_files_new = mysqli_real_escape_string($mysqli, $_POST['max_files']);
			$mysqli->query("UPDATE $table_settings SET site_name='$site_name_new', site_title='$site_title_new', site_desc='$site_desc_new', site_url='$site_url_new', lock_page='$new_lock_page', name_on_file='$new_name_on_file', max_size='$max_upload', max_files='$new_max_files', max_file_reports='$new_max_reports', blocked_types='$disallowed_types_new', expire='$expire_new', upload_dir='$upload_dir_new', favicon_path='$favicon_path_new', logo_path='$logo_path_new', language='$lang_new', bg_timer='$bg_timer_new', default_destruct='$new_default_destruct', default_sharetype='$new_default_sharetype', default_email_to='$new_default_email_to', password_enabled='$new_password_enabled', analytics='$new_analytics_code', encrypt_files='$new_encrypt_files'");

	        $upload_path = 'src/images/backgrounds/';

	        $total = count($_FILES['background']['name']);

	        for($count = 0; $count < $total; $count++) {
	            $full_path = $upload_path . $_FILES['background']['name'][$count];

	            if(!file_exists(dirname(__FILE__) . '/../' . $full_path)) {
	                if (move_uploaded_file($_FILES['background']["tmp_name"][$count], dirname(__FILE__) . '/../' . $full_path)) {
	                    $search_background = $mysqli->query("SELECT * FROM $table_backgrounds WHERE src='$full_path'");
	                    if ($search_background->num_rows == 0) {
	                        if (empty($_POST['background_url'][$count])) {
	                            $mysqli->query("INSERT INTO $table_backgrounds (src, url) VALUES ('$full_path', '')");
	                        } else {
	                            $url = $_POST['background_url'][$count];
	                            $mysqli->query("INSERT INTO $table_backgrounds (src, url) VALUES ('$full_path', '$url')");
	                        }
	                    }
	                }
	            }
	            else
	            {
	                //Skip
	            }
	        }

			header('Location: index.php?page=settings_general&change=OK');
		break;
		case 'settings_mail':
			$email_from_name_n = mysqli_real_escape_string($mysqli, $_POST['email_from_name']);
			$email_from_email_n = mysqli_real_escape_string($mysqli, $_POST['email_from_email']);
			$email_server_n = mysqli_real_escape_string($mysqli, $_POST['email_server']);
			$email_to_name_n = mysqli_real_escape_string($mysqli, $_POST['email_to_name']); 
			$smtp_host_n = mysqli_real_escape_string($mysqli, $_POST['smtp_host']);
			$smtp_auth_n = mysqli_real_escape_string($mysqli, $_POST['smtp_auth']);
			$smtp_port_n = mysqli_real_escape_string($mysqli, $_POST['smtp_port']);
			$smtp_secure_n = mysqli_real_escape_string($mysqli, $_POST['smtp_secure']);
			$smtp_username_n = mysqli_real_escape_string($mysqli, $_POST['smtp_username']);

			if(empty($_POST['smtp_password'])) {
				$smtp_password_n = $smtp_password;
			}
			else
			{
				$smtp_password_n = mysqli_real_escape_string($mysqli, $_POST['smtp_password']);
			}

			$mysqli->query("UPDATE $table_settings SET email_from_name='$email_from_name_n', email_from_email='$email_from_email_n', email_to_name='$email_to_name_n', email_server='$email_server_n', smtp_host='$smtp_host_n', smtp_auth='$smtp_auth_n', smtp_port='$smtp_port_n', smtp_secure='$smtp_secure_n', smtp_username='$smtp_username_n', smtp_password='$smtp_password_n'");
			header('Location: index.php?page=settings_mail&change=OK');
		break;
		case 'settings_template':
			$receiver 				= mysqli_real_escape_string($mysqli, $_POST['temp_receiver']);
			$sender 				= mysqli_real_escape_string($mysqli, $_POST['temp_sender']);
			$destroyed 				= mysqli_real_escape_string($mysqli, $_POST['temp_destroyed']);
			$downloaded 			= mysqli_real_escape_string($mysqli, $_POST['temp_downloaded']);
			$subject_receiver		= mysqli_real_escape_string($mysqli, $_POST['receiver_subject']);
			$subject_sender 		= mysqli_real_escape_string($mysqli, $_POST['sender_subject']);
			$subject_destroyed 		= mysqli_real_escape_string($mysqli, $_POST['destroyed_subject']);
			$subject_downloaded 	= mysqli_real_escape_string($mysqli, $_POST['downloaded_subject']);

			$language 				= mysqli_real_escape_string($mysqli, $_POST['lang']);

			$check_language = $mysqli->query("SELECT * FROM $table_templates WHERE lang='$language'");
			if($check_language->num_rows > 0) {
				$mysqli->query("UPDATE $table_templates SET msg='$receiver' WHERE type='receiver' AND lang='$language'");
				$mysqli->query("UPDATE $table_templates SET msg='$sender' WHERE type='sender' AND lang='$language'");
				$mysqli->query("UPDATE $table_templates SET msg='$destroyed' WHERE type='destroyed' AND lang='$language'");
				$mysqli->query("UPDATE $table_templates SET msg='$downloaded' WHERE type='downloaded' AND lang='$language'");
				$mysqli->query("UPDATE $table_templates SET msg='$subject_receiver' WHERE type='receiver_subject' AND lang='$language'");
				$mysqli->query("UPDATE $table_templates SET msg='$subject_sender' WHERE type='sender_subject' AND lang='$language'");
				$mysqli->query("UPDATE $table_templates SET msg='$subject_destroyed' WHERE type='destroyed_subject' AND lang='$language'");
				$mysqli->query("UPDATE $table_templates SET msg='$subject_downloaded' WHERE type='downloaded_subject' AND lang='$language'");
			}
			else
			{
				$mysqli->query("INSERT INTO `$table_templates` (`type`, `msg`, `lang`) VALUES
							('receiver', '$receiver', '$language'),
							('sender', '$sender', '$language'),
							('destroyed', '$destroyed', '$language'),
							('downloaded', '$downloaded', '$language'),
							('receiver_subject', '$subject_receiver', '$language'),
							('sender_subject', '$subject_sender', '$language'),
							('destroyed_subject', '$subject_destroyed', '$language'),
							('downloaded_subject', '$subject_downloaded', '$language');");
			}

			header('Location: index.php?page=settings_templates&lang='.$language.'&change=OK');
		break;
		case 'settings_social' :
			$social_facebook_new = mysqli_real_escape_string($mysqli, $_POST['facebook']);
			$social_twitter_new = mysqli_real_escape_string($mysqli, $_POST['twitter']);
			$social_google_new = mysqli_real_escape_string($mysqli, $_POST['google']);
			$social_instagram_new = mysqli_real_escape_string($mysqli, $_POST['instagram']);
			$social_github_new = mysqli_real_escape_string($mysqli, $_POST['github']);
			$social_tumblr_new = mysqli_real_escape_string($mysqli, $_POST['tumblr']);
			$social_pinterest_new = mysqli_real_escape_string($mysqli, $_POST['pinterest']);

			$mysqli->query("UPDATE $table_social SET facebook='$social_facebook_new', twitter='$social_twitter_new', google='$social_google_new', instagram='$social_instagram_new', github='$social_github_new', tumblr='$social_tumblr_new', pinterest='$social_pinterest_new'");
			header('Location: index.php?page=settings_social&change=OK');
		break;
		case 'settings_termsabout':
			$new_terms 			= mysqli_real_escape_string($mysqli, $_POST['terms']);
			$new_terms_enabled 	= mysqli_real_escape_string($mysqli, $_POST['accept_terms']);
			$new_about 			= mysqli_real_escape_string($mysqli, $_POST['about']);

			$mysqli->query("UPDATE $table_settings SET accept_terms='$new_terms_enabled', terms_text='$new_terms', about_text='$new_about'");
			header('Location: index.php?page=settings_termsabout&change=OK');
		break;
		case 'settings_ads':
			$new_ad_1_code = mysqli_real_escape_string($mysqli, $_POST['ad_1_code']);
			$new_ad_1_enabled = mysqli_real_escape_string($mysqli, $_POST['ad_1_enabled']);
			$new_ad_2_code = mysqli_real_escape_string($mysqli, $_POST['ad_2_code']);
			$new_ad_2_enabled = mysqli_real_escape_string($mysqli, $_POST['ad_2_enabled']);

			$mysqli->query("UPDATE $table_settings SET ad_1_enabled='$new_ad_1_enabled', ad_1_code='$new_ad_1_code', ad_2_enabled='$new_ad_2_enabled', ad_2_code='$new_ad_2_code'");
			header('Location: index.php?page=settings_ads&change=OK');
		break;
		case 'rmflag':
			$id = $_POST['id'];
			$mysqli->query("UPDATE $table_uploads SET flag='' WHERE upload_id='$id'");
		break;
		case 'add_lang':
			$name = mysqli_real_escape_string($mysqli, $_POST['name']);
			$path = mysqli_real_escape_string($mysqli, $_POST['path']);

			$get_lang = $mysqli->query("SELECT * FROM $table_language WHERE name='$name' OR path='$path'");
			if($get_lang->num_rows > 0) 
			{
				header('Location: index.php?page=settings_lang');
			}
			else
			{
				$mysqli->query("INSERT INTO $table_language (name,path) VALUES ('$name','$path')");
				header('Location: index.php?page=settings_lang');
			}
		break;
		case 'create_user':
			$email = mysqli_real_escape_string($mysqli, $_POST['email']);
			$pass = md5(mysqli_real_escape_string($mysqli, $_POST['password']));
			$check_user = $mysqli->query("SELECT * FROM $table_users WHERE email='$email'");
			if($check_user->num_rows > 0) {
				header('Location: index.php?page=users&user=exists');
			}
			else
			{
				$mysqli->query("INSERT INTO $table_users (email, password) VALUES ('$email','$pass')");
				header('Location: index.php?page=users');
			}
		break;
		case 'edit_user':
			$email = mysqli_real_escape_string($mysqli, $_POST['email']);
			$pass = md5(mysqli_real_escape_string($mysqli, $_POST['password']));
			$id = mysqli_real_escape_string($mysqli, $_POST['id']);
			if(empty($_POST['password'])) {
				$mysqli->query("UPDATE $table_users SET email='$email' WHERE id='$id'");
				header('Location: index.php?page=users');
			}
			else
			{
				$mysqli->query("UPDATE $table_users SET email='$email', password='$pass' WHERE id='$id'");
				header('Location: index.php?page=users');
			}
		break;
		case 'install_plugin':
			$uploaddir = dirname(__FILE__) . '/../plugins/';
			$uploadfile = $uploaddir . basename($_FILES['file']['name']);

			if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
				$zip = new ZipArchive;
				$res = $zip->open($uploadfile);
				if ($res === TRUE) {
				  // extract it to the path we determined above
				  $zip->extractTo($uploaddir);
				  $zip->close();
				  if(unlink($uploadfile)) {
				  	header('Location: ../plugins/' . pathinfo($_FILES['file']['name'], PATHINFO_FILENAME) . '/install.php');
				  }
				  else
				  {
				  	header('Location: index.php?page=plugins&upload=failed_deleting');
				  }
				} else {
				  header('Location: index.php?page=plugins&upload=failed_unzip');
				}
			} else {
			   	header('Location: index.php?page=plugins&upload=failed_upload');
			}
		break;
		case 'update_plugin':
			$uploaddir = dirname(__FILE__) . '/../plugins/';
			$uploadfile = $uploaddir . basename($_FILES['file']['name']);
			$id = $_POST['id'];

			if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
				$zip = new ZipArchive;
				$res = $zip->open($uploadfile);
				if ($res === TRUE) {
				  // extract it to the path we determined above
				  $zip->extractTo($uploaddir);
				  $zip->close();
				  if(unlink($uploadfile)) {
				  	header('Location: ../plugins/' . pathinfo($_FILES['file']['name'], PATHINFO_FILENAME) . '/update.php?id=' . $id);
				  }
				  else
				  {
				  	header('Location: index.php?page=plugins&upload=failed');
				  }
				} else {
				  header('Location: index.php?page=plugins&upload=failed');
				}
			} else {
			   	header('Location: index.php?page=plugins&upload=failed');
			}
		break;
		case 'add_theme':
			$theme_name = mysqli_real_escape_string($mysqli, $_POST['name']);
			$theme_directory = mysqli_real_escape_string($mysqli, $_POST['directory']);

			$mysqli->query("INSERT INTO $table_themes (name,path,status) VALUES ('$theme_name','$theme_directory','stopped')");
			header('Location: index.php?page=themes');
		break;
		case 'update':
			function post_to_url($url, $data) {
			    $fields = '';
			    foreach ($data as $key => $value) {
			        $fields .= $key . '=' . $value . '&';
			    }
			    rtrim($fields, '&');

			    $post = curl_init();

			    curl_setopt($post, CURLOPT_URL, $url);
			    curl_setopt($post, CURLOPT_POST, count($data));
			    curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
			    curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);

			    $result = curl_exec($post);

			    curl_close($post);
			    return $result;
			}

			function getRemoteIPAddress() {
			    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
			        return $_SERVER['HTTP_CLIENT_IP'];

			    } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 
			        return $_SERVER['HTTP_X_FORWARDED_FOR'];
			    }
			    return $_SERVER['REMOTE_ADDR'];
			}

			$data = array(
			    "purchase_code" => $_POST['purchase_code'],
			    "ip" => $_SERVER['SERVER_ADDR'],
			    "version" => getRemoteIPAddress()
			);

			$surl = 'http://api.proxibolt.com/verify/droppy/verify.php';
			$res = post_to_url($surl, $data);

			if($res == 'invalid_ip') {
				header('Location: index.php?page=system&e=ip');
			}
			elseif($res == 'invalid_purchase') {
				header('Location: index.php?page=system&e=purchase');
			}
			else
			{
			    $file = fopen(dirname(__FILE__) . '/updates/update_' . get_proxibolt_api('http://api.proxibolt.com/versions/droppy/v.html') . '.zip', 'w');
				// cURL
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL,$res);
				// set cURL options
				curl_setopt($ch, CURLOPT_FAILONERROR, true);
				curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
				// set file handler option
				curl_setopt($ch, CURLOPT_FILE, $file);
				// execute cURL
				curl_exec($ch);
				// close cURL
				curl_close($ch);
				// close file
				fclose($file);

			    $zip = new ZipArchive;
				$res = $zip->open(dirname(__FILE__) . '/updates/update_' . get_proxibolt_api('http://api.proxibolt.com/versions/droppy/v.html') . '.zip');
				if ($res === TRUE) {
				  // extract it to the path we determined above
				  $zip->extractTo(dirname(__FILE__) . '/../');
				  $zip->close();
				  header('Location: ../update.php');
				} else {
				  header('Location: index.php?page=system&e=failed&p=zip');
				}
			}
		break;
		case 'update_manually':
			function post_to_url($url, $data) {
			    $fields = '';
			    foreach ($data as $key => $value) {
			        $fields .= $key . '=' . $value . '&';
			    }
			    rtrim($fields, '&');

			    $post = curl_init();

			    curl_setopt($post, CURLOPT_URL, $url);
			    curl_setopt($post, CURLOPT_POST, count($data));
			    curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
			    curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);

			    $result = curl_exec($post);

			    curl_close($post);
			    return $result;
			}

			function getRemoteIPAddress() {
			    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
			        return $_SERVER['HTTP_CLIENT_IP'];

			    } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 
			        return $_SERVER['HTTP_X_FORWARDED_FOR'];
			    }
			    return $_SERVER['REMOTE_ADDR'];
			}

			$post_code = $_POST['purchase_code'];

			$data = array(
			    "purchase_code" => $post_code,
			    "ip" => $_SERVER['SERVER_ADDR'],
			    "version" => getRemoteIPAddress()
			);

			$surl = 'http://api.proxibolt.com/verify/droppy/verify.php';
			$res = post_to_url($surl, $data);

			if($res == 'invalid_ip') {
				header('Location: index.php?page=system&e=ip');
			}
			elseif($res == 'invalid_purchase') {
				header('Location: index.php?page=system&e=purchase');
			}
			else
			{
				$mysqli->query("UPDATE $table_settings SET purchase_code='$post_code'");
			    $file_name = 'update_' . get_proxibolt_api('http://api.proxibolt.com/versions/droppy/v.html') . '.zip';

			    /*header("Content-Type: application/zip");
				header("Content-Transfer-Encoding: Binary");
				header("Content-disposition: attachment; filename=\"$file_name\""); 
				
				ob_clean();

				readfile($res);*/
				header('Location: ' . $res);
			}
		break;
	}
	switch ($_GET['action']) {
		case 'delete_page':
			$id = $_GET['id'];
			$mysqli->query("DELETE FROM $table_pages WHERE id='$id'");

			header("Location: index.php?page=pages");
		break;
		case 'delete_user':
			$id = $_GET['id'];
			$mysqli->query("DELETE FROM $table_users WHERE id='$id'");

			header("Location: index.php?page=users");
		break;
		case 'rm_lang':
			$id = mysqli_real_escape_string($mysqli, $_GET['lang']);

			$mysqli->query("DELETE FROM $table_language WHERE id='$id'");
			header('Location: index.php?page=settings_lang');
		break;
		case 'reset':
			$a = mysqli_real_escape_string($mysqli, $_GET['a']);
			$b = mysqli_real_escape_string($mysqli, $_GET['b']);

			$search_account = $mysqli->query("SELECT * FROM $table_accounts WHERE password='$a' AND email='$b'");
			if($search_account->num_rows == 1) {
				$_SESSION['droppy_admin'] = $a;
				header('Location: index.php?page=personal');
			}
			else
			{
				header('Location: login.php');
			}
		break;
		case 'logout':
			session_destroy();
			header('Location: login.php');
		break;
		case 'delete_upload':
			$id = $_GET['id'];

            require_once dirname(__FILE__) . '/../resources/class/upload.class.php';

            $upload = new Upload();
            $delete = $upload->delete($id);

            if($delete) {
                header('Location: index.php?page=uploads&msg=destroyed');
            }
            else
            {
                header('Location: index.php?page=uploads&msg=error');
            }
		break;
		case 'cleardb':
			$mysqli->query("TRUNCATE TABLE $table_uploads");
			$mysqli->query("TRUNCATE TABLE $table_downloads");
			$mysqli->query("TRUNCATE TABLE $table_files");
			$mysqli->query("TRUNCATE TABLE $table_log");

			header('Location: index.php?page=uploads&msg=dbcleared');
		break;
		case 'rm_bg':
			$id = $_GET['id'];

	        $get_background = $mysqli->query("SELECT * FROM $table_backgrounds WHERE id='$id'");
	        while($row = $get_background->fetch_assoc()) {
	            if(file_exists(dirname(__FILE__) . '/../' . $row['src'])) {
	                unlink(dirname(__FILE__) . '/../' . $row['src']);
	            }
	        }
			$mysqli->query("DELETE FROM $table_backgrounds WHERE id='$id'");

			header('Location: index.php?page=settings_general#backgrounds');
		break;
		case 'suspend_plugin':
			$plugin_id = $_GET['plugin_id'];

			$mysqli->query("UPDATE $table_plugins SET status='stopped' WHERE id='$plugin_id'");

			header('Location: index.php?page=plugins&plugin=suspended');
		break;
		case 'activate_plugin':
			$plugin_id = $_GET['plugin_id'];

			$mysqli->query("UPDATE $table_plugins SET status='ready' WHERE id='$plugin_id'");

			header('Location: index.php?page=plugins&plugin=activated');
		break;
		case 'delete_plugin':
			$plugin_id = $_GET['plugin_id'];

			$mysqli->query("DELETE FROM $table_plugins WHERE id='$plugin_id'");

			header('Location: index.php?page=plugins&plugin=deleted');
		break;
		case 'suspend_theme':
			$theme_id = $_GET['theme_id'];

			$mysqli->query("UPDATE $table_themes SET status='stopped' WHERE id='$theme_id'");

			header('Location: index.php?page=themes&plugin=suspended');
		break;
		case 'activate_theme':
			$theme_id = $_GET['theme_id'];

			$mysqli->query("UPDATE $table_themes SET status='stopped'");
			$mysqli->query("UPDATE $table_themes SET status='ready' WHERE id='$theme_id'");

			header('Location: index.php?page=themes&plugin=activated');
		break;
		case 'delete_theme':
			$theme_id = $_GET['theme_id'];

			$mysqli->query("DELETE FROM $table_themes WHERE id='$theme_id'");

			header('Location: index.php?page=themes&plugin=deleted');
		break;
	}
}
?>