<?php
    require("functions/functions.php");
	require_once('functions/backup_restore.class.php'); 
	
	// CSRF Protection
	require 'functions/CSRF_Protect.php';
	$csrf = new CSRF_Protect();
	
	// Error Reporting Active
	ini_set('display_errors', 1);
	ini_set('display_startup_errors', 1);
	error_reporting(E_ALL);
	
    if(empty($_SESSION['user'])) 
    {
        header("Location: index.php");
        die("Redirecting to index.php"); 
    }
	
	echo language();
	
	function curPageURL() {
	 $pageURL = 'http';
	 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
	 $pageURL .= "://";
	 if ($_SERVER["SERVER_PORT"] != "80") {
	  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
	 } else {
	  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
	 }
	 return $pageURL;
	}
	
	//Fun��o para devolver current page
	function curPageName() {
	 return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
	}
	$active = curPageName();
	
	//IMPORT - EXPORT Options
    $newImport = new backup_restore($host,$dbname,$username,$password);

    if(isset($_GET['process'])){
        $process = $_GET['process'];
        if($process == 'backup'){
            $message = $newImport -> backup ();   
        }else if($process == 'restore'){
            $message = $newImport -> restore (); 
            @unlink('assets/backup/'.$dbname.'_'.date('Y-m-d').'_'.time().'.sql');
            
        }
    }
    if(isset($_POST['submit'])){        
        $dbname = ''.$dbname.'-'.date('Y-m-d').'.sql';
        $target_path = 'assets/backup/';
        move_uploaded_file($_FILES["file"]["tmp_name"], $target_path . '/' . $dbname);    
        $message = 'Successfully uploaded. You can now <a href=dashboard.php?process=restore>restore</a> the database!';
    }

			
?>
<!DOCTYPE html>
<html lang="<?php echo langName(); ?>">
<head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title> Admin Panel </title>
	<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
    <!-- Bootstrap Core CSS -->
    <link href="assets/css/bootstrap.css" rel="stylesheet">
	<!-- DateTimePicker CSS -->
	<link href="assets/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
	
	
	<link rel="stylesheet" type="text/css" href="assets/css/sweetalert.css">
    <!-- Custom CSS -->
    <link href="assets/css/styles.css" rel="stylesheet">
	<!-- DataTables CSS -->
    <link href="assets/css/dataTables.bootstrap.css" rel="stylesheet">
    <!-- Custom Fonts -->
    <link href="assets/css/font-awesome.min.css" rel="stylesheet" type="text/css">
	<link href="assets/css/bootstrap-colorpicker.css" rel="stylesheet" type="text/css">
	<link href="assets/css/bootstrap-toggle.css" rel="stylesheet">
	

	<link rel="shortcut icon" href="../assets/img/favicon.png">

	<!-- jQuery -->
    <script src="assets/js/jquery.min.js"></script>
	<script src="assets/js/colorpicker-color.js"></script>
	<script src="assets/js/bootstrap-colorpicker.js"></script>
	<!-- SweetAlert CSS -->
	<script src="assets/js/sweetalert.min.js"></script> 
	<script src="assets/js/jquery.vide.js"></script>

    <link href="assets/css/style.css" rel="stylesheet">
	<script src="assets/js/dygraph.js"></script>
 
	<link href="https://fonts.googleapis.com/css?family=Noto+Sans+HK:100,300,400,500,700,900&display=swap" rel="stylesheet"> 

	<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">



	<?php if ($active == "about.php") echo "
	
		<!-- include summernote css/js-->
		<link href='http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.4/summernote.css' rel='stylesheet'>
		<script src='http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.4/summernote.js'></script>
	
	" ?>

	<?php if ($active == "new_category.php") echo "
	
		<!-- include summernote css/js-->
		<link href='http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.4/summernote.css' rel='stylesheet'>
		<script src='http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.4/summernote.js'></script>
	
	" ?>

	<?php if ($active == "edit_categoty.php") echo "
	
		<!-- include summernote css/js-->
		<link href='http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.4/summernote.css' rel='stylesheet'>
		<script src='http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.4/summernote.js'></script>
	
	" ?>
	
	<style>
        .copyright p {
            color: #0373b0;
            font-family: Roboto !important;
            font-size: 15px;
            text-align: center;
        }
        .ck p { min-height : 70px ; }
    </style>
    <script src="https://cdn.ckeditor.com/ckeditor5/11.0.1/classic/ckeditor.js"></script>	
</head>
<body <?php if ($active == "map.php") echo "onLoad='initialize()'" ?>>
 
    <div id="wrapper">	
        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">		
            <!-- Brand and toggle get grouped for better mobile display -->
			<div class="topbar">			
				<div class="navbar-header">
					<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
						<span class="sr-only">Toggle navigation</span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</button>
					 <a href="dashboard.php" class="navbar-brand"><img src="../assets/images/logo.jpg" style="float: left; height: 43px; margin-right: 20px; margin-top: -9px;"> 
					  Center for Systems Biology and Molecular Medicine </a>
				</div>				
				<!-- Top Menu Items -->
				 <ul id="info" class="nav navbar-right">				 
					<!-- Button trigger modal -->
					<a href="admin.php" class="btn btn-success"><i class="fa fa-user" aria-hidden="true"></i>  <?php echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); ?></a>					 
					</button>	
					<a href="pass.php" class="btn btn-success"><i class="fa fa-user" aria-hidden="true"></i>  Change User Password</a>				
					<a href="logout.php" class="btn btn-warning"><i class="fa fa-close" aria-hidden="true"></i> <?php echo lang('LOG_OUT');?></a>
				</ul>				
			</div>