<?php
require_once dirname(__FILE__) . '/../config/config.php';

session_start();

if(!isset($_SESSION['droppy_admin'])) {
    header('Location: login.php');
    exit;
}

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;
}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Droppy - Admin panel">
    <meta name="author" content="Proxibolt">
    <meta name="keyword" content="">

    <title><?php echo $site_name; ?> - Admin Panel</title>

    <link rel="shortcut icon" type="image/png" href="../<?php echo $favicon_path; ?>"/>

    <!-- Bootstrap core CSS -->
    <link href="../src/css/bootstrap/bootstrap.css" rel="stylesheet">
    <!--external css-->
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../src/plugins/lineicons/style.css">   
    
    <!-- Custom styles for this template -->
    <link href="../src/css/admin.css" rel="stylesheet">
    <link href="../src/css/admin-responsive.css" rel="stylesheet">

    <script src="../src/plugins/chart-master/Chart.js"></script>
    <script src="../src/js/admin/sortable.js"></script>
    <script src="../src/js/admin/jquery.js"></script>
	<script src="../src/js/admin/jquery-1.8.3.min.js"></script>
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>
  <section id="container" >
      <!-- **********************************************************************************************************************************************************
      TOP BAR CONTENT & NOTIFICATIONS
      *********************************************************************************************************************************************************** -->
      <!--header start-->
      <header class="header black-bg">
              <div class="sidebar-toggle-box">
                  <div class="fa fa-bars tooltips" data-placement="right" data-original-title="Toggle Navigation"></div>
              </div>
            <!--logo start-->
            <a href="index.php" class="logo"><img src="../<?php echo $logo_path; ?>" style="height: 30px;"></a>
            <!--logo end-->
            <div class="top-menu">
            	<ul class="nav pull-right top-menu">
                    <li><a class="logout" href="action.php?action=logout">Logout</a></li>
            	</ul>
            </div>
        </header>
      <!--header end-->
      
      <!-- **********************************************************************************************************************************************************
      MAIN SIDEBAR MENU
      *********************************************************************************************************************************************************** -->
      <!--sidebar start-->
      <aside>
          <div id="sidebar"  class="nav-collapse ">
              <!-- sidebar menu start-->
              <ul class="sidebar-menu" id="nav-accordion">
                  <li class="mt">
                      <a href="index.php">
                          <i class="fa fa-dashboard"></i>
                          <span>Dashboard</span>
                      </a>
                  </li>

                  <li class="sub-menu">
                      <a href="javascript:;" >
                          <i class="fa fa-cogs"></i>
                          <span>Settings</span>
                      </a>
                      <ul class="sub">
                          <li><a href="?page=settings_general">General settings</a></li>
                          <li><a href="?page=settings_mail">Email settings</a></li>
                          <li><a href="?page=settings_templates">Email templates</a></li>
                          <li><a href="?page=settings_social">Social settings</a></li>
                          <li><a href="?page=settings_lang">Language settings</a></li>
                          <li><a href="?page=settings_termsabout">Terms &amp; About</a></li>
                          <li><a href="?page=settings_ads">Advertising</a></li>
                      </ul>
                  </li>
                  <li class="sub-menu">
                      <a href="?page=uploads">
                          <i class="fa fa-cloud-upload"></i>
                          <span>Uploads</span>
                      </a>
                  </li>
                  <li class="sub-menu">
                      <a href="?page=downloads">
                          <i class="fa fa-cloud-download"></i>
                          <span>Downloads</span>
                      </a>
                  </li>
                  <li class="sub-menu">
                      <a href="?page=users">
                          <i class="fa fa-user"></i>
                          <span>Users</span>
                      </a>
                  </li>
                  <li class="sub-menu">
                      <a href="?page=themes">
                          <i class="fa fa-binoculars"></i>
                          <span>Themes</span>
                      </a>
                  </li>
                  <li class="sub-menu">
                      <a href="?page=plugins">
                          <i class="fa fa-cubes"></i>
                          <span>Plugins</span>
                      </a>
                  </li>
                  <li class="sub-menu">
                      <a href="?page=system">
                          <i class="fa fa-server"></i>
                          <span>System</span>
                      </a>
                  </li>
                  <li class="sub-menu">
                      <a href="?page=log">
                          <i class="fa fa-server"></i>
                          <span>System log</span>
                      </a>
                  </li>
                  <li class="sub-menu">
                      <a href="?page=personal">
                          <i class="fa fa-user"></i>
                          <span>My details</span>
                      </a>
                  </li>
              </ul>
              <!-- sidebar menu end-->
          </div>
      </aside>
      <!--sidebar end-->
      
      <!-- **********************************************************************************************************************************************************
      MAIN CONTENT
      *********************************************************************************************************************************************************** -->
      <!--main content start-->
      <section id="main-content"> 
      <?php
      switch ($_GET['page']) {
          default:
            $size = array();
            $count_disk = $mysqli->query("SELECT * FROM $table_uploads WHERE status='ready'");
            while($row = $count_disk->fetch_assoc()) {
              $size[] = $row['size'];
            }
            $total_size = round(array_sum($size) / 1048576, 2);
      ?>
          <section class="wrapper">

          <div class="row">
            <div class="col-lg-11 main-chart">
              <?php
              if(file_exists("../install.php")) {
                echo '<div class="alert alert-warning" role="alert" style="text-align: center;">Please delete the <b>install.php</b> file from the home directory of Droppy !</div>';
              }
              if(file_exists("../update.php")) {
                echo '<div class="alert alert-danger" role="alert" style="text-align: center;">Please delete the <b>update.php</b> file from the home directory of Droppy !</div>';
              }
              $permission_uploads = substr(sprintf("%o",fileperms("../uploads/")),-4);
              if($permission_uploads != '0777') {
                echo '<div class="alert alert-info" role="alert" style="text-align: center;">Please change the permssion of the <b>uploads</b> directory to 777 (See documentation)</div>';
              }
              $permission_tmp = substr(sprintf("%o",fileperms("../uploads/tmp/")),-4);
              if($permission_tmp != '0777') {
                echo '<div class="alert alert-success" role="alert" style="text-align: center;">Please change the permssion of the <b>uploads/tmp/</b> directory to 777 (See documentation)</div>';
              }
              $permission_updates = substr(sprintf("%o",fileperms("updates/")),-4);
              if($permission_updates != '0777') {
                echo '<div class="alert alert-success" role="alert" style="text-align: center;">Please change the permssion of the <b>admin/updates/</b> directory to 777</div>';
              }
              ?>
            	<div class="row mtbox">
                <?php
                $get_all_uploads = $mysqli->query("SELECT * FROM $table_uploads");
                $get_all_active_uploads = $mysqli->query("SELECT * FROM $table_uploads WHERE status='ready'");
                $get_all_downloads = $mysqli->query("SELECT * FROM $table_downloads");
                $get_all_destroyed = $mysqli->query("SELECT * FROM $table_uploads WHERE status='destroyed'");
                ?>
            		<div class="col-md-2 col-sm-2 col-md-offset-2 box0">
            			<div class="box1">
		  			        <i class="fa fa-cloud-upload fa-5x"></i>
		  			        <h3><?php echo $get_all_uploads->num_rows; ?></h3>
            			</div>
		  			      <p>A total of <?php echo $get_all_uploads->num_rows; ?> uploads have been processed </p>
            		</div>
            		<div class="col-md-2 col-sm-2 box0">
            			<div class="box1">
  					  			<i class="fa fa-cloud fa-5x"></i>
  					  			<h3><?php echo $get_all_active_uploads->num_rows; ?></h3>
            			</div>
					  			<p><?php echo $get_all_active_uploads->num_rows; ?> active files are ready for download.</p>
            		</div>
            		<div class="col-md-2 col-sm-2 box0">
            			<div class="box1">
  					  			<i class="fa fa-cloud-download fa-5x"></i>
  					  			<h3><?php echo $get_all_downloads->num_rows; ?></h3>
                    			</div>
  					  			<p><?php echo $get_all_downloads->num_rows; ?> downloads have been made.</p>
            		</div>
            		<div class="col-md-2 col-sm-2 box0">
            			<div class="box1">
  					  			<i class="fa fa-trash fa-5x"></i>
  					  			<h3><?php echo $get_all_destroyed->num_rows; ?></h3>
                  </div>
  					  		<p><?php echo $get_all_destroyed->num_rows; ?> items have been destroyed</p>
            		</div>                	
            	</div><!-- /row mt -->	
                  
                      
          <div class="row mt">                                      
          	<div class="col-md-4 col-sm-4 mb">
          		<div class="white-panel pn">
          			<div class="white-header">
  			           <h5>MOST DOWNLOADED</h5>
          			</div>
            		<div class="centered" style="padding-top: 20px;">
                <?php
                $get_most_downloaded = $mysqli->query("
                SELECT download_id, COUNT(*) AS magnitude 
                FROM $table_downloads 
                GROUP BY download_id 
                ORDER BY magnitude DESC
                LIMIT 1");
                while($row_downloads = $get_most_downloaded->fetch_assoc()) {
                  $download_id = $row_downloads['download_id'];
									echo '<p><i style="font-wheight: bold;">ID:</i> <a href="' . $site_url . $download_id . '">' . $download_id . '</a></p>';
                  echo '<p><i style="font-wheight: bold;">Downloads:</i>' . $row_downloads['magnitude'] . '</p>';
                }
                ?>
                </div>
          		</div>
          	</div><!-- /col-md-4 -->
            
            <!-- SERVER STATUS PANELS -->
            <div class="col-md-4 mb">
             <div class="white-panel pn">
                <div class="white-header">
                   <h5>DISK STATICS</h5>
                </div>
                <div style="text-align: center; padding-top: 20px;">
                  <i class="fa fa-server fa-5x" style="font-size: 70px;"></i>
                  <?php
                  if($total_size < 1024):
                  ?>
                  <h2><?php echo $total_size; ?> MB used</h2>
                  <?php
                  elseif($total_size > 1024):
                  ?>
                  <h2><?php echo round($total_size / 1000, 2); ?> GB used</h2>
                  <?php
                  endif;
                  ?>
                </div>  
              </div><!-- /white panel -->
            </div><!-- /col-md-4 -->

						<div class="col-md-4 mb">
							<!-- WHITE PANEL - TOP USER -->
							<div class="white-panel pn">
								<div class="white-header">
									<h5>LATEST UPLOAD</h5>
								</div>
								<?php
                $get_latest_upload = $mysqli->query("SELECT * FROM $table_uploads ORDER BY time DESC LIMIT 1");
                while($row = $get_latest_upload->fetch_assoc()) {
                  $upload_id = $row['upload_id'];
                ?>
                <div style="padding-top: 20px; text-align: left;">
                  <p><i style="font-wheight: bold;">ID:</i> <a href="<?php echo $site_url . $upload_id; ?>"><?php echo $upload_id; ?></a></p>
                  <p><i style="font-wheight: bold;">Time:</i> <?php echo date("F j, Y, g:i a", $row['time']); ?></p>
                  <p><i style="font-wheight: bold;">Size:</i> <?php echo round($row['size'] / 1048576, 2); ?> MB</p>
                  <p><i style="font-wheight: bold;">Password:</i> <?php if($row['password'] == 'EMPTY') { echo 'No'; } else { echo 'Yes'; } ?></p>
                  <p><i style="font-wheight: bold;">Deleted:</i> <?php if($row['status'] == 'destroyed') { echo 'Yes'; } else { echo 'No'; } ?></p>
                </div>
                <?php
                }
                ?>
							</div>
						</div><!-- /col-md-4 -->
          </div><!-- /row -->                                				
        </div><!-- /col-lg-9 END SECTION MIDDLE -->
                  
                  
      <!-- **********************************************************************************************************************************************************
      RIGHT SIDEBAR CONTENT
      *********************************************************************************************************************************************************** -->                  
              </div><! --/row -->
          </section>
      </section>
      <?php
      break;
      case 'settings_general':
      ?>
      <section class="wrapper">
        <div class="row mt">
                <div class="col-lg-12">
                    <div class="form-panel" style="overflow:hidden;">
                        <h4 class="mb"><i class="fa fa-angle-right"></i> General Settings</h4>
                        <form class="form-horizontal style-form" method="post" action="action.php" enctype="multipart/form-data">
                          <input type="hidden" name="action" value="settings_general">
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Site name</label>
                                <div class="col-sm-10">
                                    <input type="text" name="site_name" class="form-control" value="<?php echo $site_name; ?>">
                                    <i>Your site name, Eg: Droppy</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Site title</label>
                                <div class="col-sm-10">
                                    <input type="text" name="site_title" class="form-control" value="<?php echo $site_title; ?>">
                                    <i>Your site title, Eg: Droppy - Online file sharing (This will be shown in a browser tab)</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Site description (Search engines)</label>
                                <div class="col-sm-10">
                                    <input type="text" name="site_desc" class="form-control" value="<?php echo $site_desc; ?>">
                                    <i>Description of your website</i>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Name on zip file</label>
                                <div class="col-sm-10">
                                    <input type="text" name="name_on_file" class="form-control" value="<?php echo $name_on_file; ?>">
                                    <i>The name on the downloaded zip files (E.g. <u>droppy</u>-sg785ey.zip or <u>file</u>-82js87w.zip)</i> <p><b>WARNING:</b> By editing this name you won't be able to download old files anymore.</p>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Site url</label>
                                <div class="col-sm-10">
                                    <input type="text" name="site_url" class="form-control" value="<?php echo $site_url; ?>">
                                    <i>The url of your website</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Logo path</label>
                                <div class="col-sm-10">
                                    <input type="text" name="logo_path" class="form-control" value="<?php echo $logo_path; ?>">
                                    <i>Path to your logo image</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Favicon path</label>
                                <div class="col-sm-10">
                                    <input type="text" name="favicon_path" class="form-control" value="<?php echo $favicon_path; ?>">
                                    <i>Path to your favicon image</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Lock site</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="lock_page">
                                        <option value="false" <?php if($lock_page == 'false') { echo 'selected'; } ?>>Disable lock</option>
                                        <option value="both" <?php if($lock_page == 'both') { echo 'selected'; } ?>>Both</option>
                                        <option value="upload" <?php if($lock_page == 'upload') { echo 'selected'; } ?>>Upload page</option>
                                        <option value="download" <?php if($lock_page == 'download') { echo 'selected'; } ?>>Download page</option>
                                    </select>
                                    <i>Select which part of the site you would like to have protected with a password.</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Default share type</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="default_sharetype">
                                        <option value="mail" <?php if($default_sharetype == 'mail') { echo 'selected'; } ?>>E-Mail</option>
                                        <option value="link" <?php if($default_sharetype == 'link') { echo 'selected'; } ?>>Link</option>
                                    </select>
                                    <i>The share type E-Mail or Link on page load</i>
                                    
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Password function enabled</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="password_enabled">
                                        <option value="true" <?php if($password_enabled == 'true') { echo 'selected'; } ?>>Yes</option>
                                        <option value="false" <?php if($password_enabled == 'false') { echo 'selected'; } ?>>No</option>
                                    </select>
                                    <i>Turns the password function on or off</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Destruction default</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="default_destruct">
                                        <option value="yes" <?php if($default_destruct == 'yes') { echo 'selected'; } ?>>Yes</option>
                                        <option value="no" <?php if($default_destruct == 'no') { echo 'selected'; } ?>>No</option>
                                    </select>
                                    <i>The destruction option in the upload settings section will automaticly select Yes or No</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Default email to</label>
                                <div class="col-sm-10">
                                    <input type="text" name="default_email_to" class="form-control" value="<?php echo $default_email_to; ?>">
                                    <i>Default email where all uploads need to be send to (Leave empty to let users choose their own recipients)</i>
                                </div>
                            </div>
                            <div class="form-group" id="backgrounds">
                                <label class="col-sm-2 col-sm-2 control-label">Background images/videos</label>
                                <div class="col-sm-10">
                                    <p style="color: red;">IMPORTANT: Files with the same name will be ignored, try changing the file name when it already exists on the server.<br> When the upload fails try to give the <span style="color:black">src/images/backgrounds/</span> directory the 777 permissions or contact Proxibolt Support.</p>
                                    <p>Background images should be JPG and PNG, you can also upload a video but you are only able to select .MP4 videos (Due to browser limitations)</p>
                                    <?php
                                    $get_backgrounds = $mysqli->query("SELECT * FROM $table_backgrounds");
                                    if($get_backgrounds->num_rows == 0) :
                                    ?>
                                    <b>Select file:</b>(only images) <input type="file" name="background[]" accept="image/*,video/mp4">
                                    <input type="text" name="background_url[]" class="form-control" placeholder="Background href (Leave empty for nothing)"><hr>
                                    <div id="extraBG"></div>
                                    <?php
                                    else :
                                    ?>
                                    <div id="extraBG">
                                    <?php
                                    while($rows = $get_backgrounds->fetch_assoc()){
                                      echo '<div style="padding-top: 30px;"><input type="text" name="background[]" class="form-control" value="' . $rows['src'] . '" disabled><br>';
                                      echo '<input type="text" name="background_url[]" class="form-control" value="' . $rows['url'] . '" disabled>
                                      <div style="float: right; padding-right: 5px;"><a href="action.php?action=rm_bg&id=' . $rows['id'] . '" class="btn btn-danger btn-sm">Delete</a></div><br></div>';
                                    }
                                    ?>
                                    </div>
                                    <?php
                                    endif;
                                    ?>
                                    <div style="float: right; padding-right: 5px; padding-top: 20px; clear: both;">
                                      <button type="button" onclick="add_bg_section()" class="btn btn-primary btn-sm">Add background input</button>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Slide timer</label>
                                <div class="col-sm-10">
                                    <input type="text" name="bg_timer" class="form-control" value="<?php echo $bg_timer; ?>">
                                    <i>The time between every background image (Seconds) input 0 to disable this function</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Language</label>
                                <div class="col-sm-10">
                                    <input type="text" name="lang" class="form-control" value="<?php echo $language; ?>">
                                    <i>Only language file name not path !</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Expire time</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="expire">
                                        <option value="0" <?php if($expire == '0') { echo 'selected'; } ?>>Disable</option>
                                        <optgroup label="Hours">
                                          <option value="3600" <?php if($expire == '3600') { echo 'selected'; } ?>>1 Hour</option>
                                          <option value="10800" <?php if($expire == '10800') { echo 'selected'; } ?>>3 Hours</option>
                                          <option value="18000" <?php if($expire == '18000') { echo 'selected'; } ?>>5 Hours</option>
                                          <option value="28800" <?php if($expire == '28800') { echo 'selected'; } ?>>8 Hours</option>
                                          <option value="36000" <?php if($expire == '36000') { echo 'selected'; } ?>>10 Hours</option>
                                          <option value="43200" <?php if($expire == '43200') { echo 'selected'; } ?>>12 Hours</option>
                                          <option value="50400" <?php if($expire == '50400') { echo 'selected'; } ?>>14 Hours</option>
                                          <option value="57600" <?php if($expire == '57600') { echo 'selected'; } ?>>16 Hours</option>
                                          <option value="64800" <?php if($expire == '64800') { echo 'selected'; } ?>>18 Hours</option>
                                          <option value="72000" <?php if($expire == '72000') { echo 'selected'; } ?>>20 Hours</option>
                                          <option value="79200" <?php if($expire == '79200') { echo 'selected'; } ?>>22 Hours</option>
                                        </optgroup>
                                        <optgroup label="Days">
                                          <option value="86400" <?php if($expire == '86400') { echo 'selected'; } ?>>1 Day</option>
                                          <option value="172800" <?php if($expire == '172800') { echo 'selected'; } ?>>2 Days</option>
                                          <option value="259200" <?php if($expire == '259200') { echo 'selected'; } ?>>3 Days</option>
                                          <option value="345600" <?php if($expire == '345600') { echo 'selected'; } ?>>4 Days</option>
                                          <option value="432000" <?php if($expire == '432000') { echo 'selected'; } ?>>5 Days</option>
                                          <option value="518400" <?php if($expire == '518400') { echo 'selected'; } ?>>6 Days</option>
                                        </optgroup>
                                        <optgroup label="Weeks">
                                          <option value="604800" <?php if($expire == '604800') { echo 'selected'; } ?>>1 Week</option>
                                          <option value="1209600" <?php if($expire == '1209600') { echo 'selected'; } ?>>2 Weeks</option>
                                          <option value="1814400" <?php if($expire == '1814400') { echo 'selected'; } ?>>3 Weeks</option>
                                        </optgroup>
                                        <optgroup label="Months">
                                          <option value="2592000" <?php if($expire == '2592000') { echo 'selected'; } ?>>1 Month</option>
                                          <option value="5184000" <?php if($expire == '5184000') { echo 'selected'; } ?>>2 Months</option>
                                          <option value="7776000" <?php if($expire == '7776000') { echo 'selected'; } ?>>3 Months</option>
                                          <option value="10368000" <?php if($expire == '10368000') { echo 'selected'; } ?>>4 Months</option>
                                          <option value="12960000" <?php if($expire == '12960000') { echo 'selected'; } ?>>5 Months</option>
                                          <option value="15552000" <?php if($expire == '15552000') { echo 'selected'; } ?>>6 Months</option>
                                          <option value="18144000" <?php if($expire == '18144000') { echo 'selected'; } ?>>7 Months</option>
                                          <option value="20736000" <?php if($expire == '20736000') { echo 'selected'; } ?>>8 Months</option>
                                          <option value="23328000" <?php if($expire == '23328000') { echo 'selected'; } ?>>9 Months</option>
                                          <option value="25920000" <?php if($expire == '25920000') { echo 'selected'; } ?>>10 Months</option>
                                          <option value="28512000" <?php if($expire == '28512000') { echo 'selected'; } ?>>11 Months</option>
                                          <option value="31104000" <?php if($expire == '31104000') { echo 'selected'; } ?>>12 Months</option>
                                        </optgroup>
                                    </select>
                                    <p><i>Time till a file gets destroyed</i></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Max selected files</label>
                                <div class="col-sm-10">
                                    <input type="number" name="max_select" class="form-control" value="<?php echo $max_upload_files; ?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Max upload size <b>(MB)</b></label>
                                <div class="col-sm-10">
                                    <input type="number" name="max_upload" class="form-control" value="<?php echo $max_size; ?>">
                                    <i>Maximum upload size in MB</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Max file reports</label>
                                <div class="col-sm-10">
                                    <input type="number" name="max_file_reports" class="form-control" value="<?php echo $max_file_reports; ?>">
                                    <i>Amount of reports it takes before a file gets destroyed (Set 0 to disable)</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Encrypt files (<a href="https://proxibolt.zendesk.com/hc/en-us/articles/115001511049" target="_blank" style="color: blue;">More info</a>)</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="encrypt_files">
                                        <option value="1" <?php if($encrypt_files == '1') { echo 'selected'; } ?>>Enabled</option>
                                        <option value="0" <?php if($encrypt_files == '0') { echo 'selected'; } ?>>Disabled</option>
                                    </select>
                                    <i><span style="color: red;">IMPORTANT !</span> you will need to have the PHP module " mcrypt " installed on your server. Files that are already on the server will be kept uncrypted only<br> new uploaded files will be encrypted, the uncrypted files will still be available for download. More information about the encryption feature can be found in </i><a href="https://proxibolt.zendesk.com/hc/en-us/articles/115001511049" target="_blank" style="color: blue;">this article</a>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Blocked file types</label>
                                <div class="col-sm-10">
                                    <textarea class="form-control" name="blocked_types" style="width: 100%; height: 100px;"><?php echo $disallowed_types; ?></textarea>
                                    <i>Choose which file type(s) have to be blocked. (Split values with  a comma ',' and without any space between them, All file types can be found <a href="http://www.iana.org/assignments/media-types/media-types.xhtml">here</a>)</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Upload directory</label>
                                <div class="col-sm-10">
                                    <input type="text" name="upload_dir" class="form-control" value="<?php echo $upload_dir; ?>">
                                    <i>Do not forget to add a "/" at the end</i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Analytics code</label>
                                <div class="col-sm-10">
                                    <textarea name="analytics" class="form-control" style="width: 100%; height: 200px;"><?php echo $analytics_code; ?></textarea>
                                </div>
                            </div>
                            <div style="float: right; padding-right: 5px;">
                              <button type="submit" class="btn btn-success" ><i class="fa fa-floppy-o"></i> Save</button>
                            </div>
                      </form>
                  </div>
              </div><!-- col-lg-12-->       
          </div><!-- /row -->
      </section>
      <?php
      break;
      case 'settings_mail':
      ?>
      <section class="wrapper">
        <div class="row mt">
                <div class="col-lg-12">
                    <div class="form-panel" style="overflow:hidden ;">
                        <h4 class="mb"><i class="fa fa-angle-right"></i> E-Mail Settings</h4>
                        <form class="form-horizontal style-form" method="post" action="action.php">
                          <input type="hidden" name="action" value="settings_mail">
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Email from (Name)</label>
                                <div class="col-sm-10">
                                    <input type="text" name="email_from_name" class="form-control" value="<?php echo $email_from_name; ?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Email from (E-Mail)</label>
                                <div class="col-sm-10">
                                    <input type="email" name="email_from_email" class="form-control" value="<?php echo $email_from_email; ?>">
                                </div>
                            </div>                       
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Email Server</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="email_server" id="email_server" onchange="emailServer()">
                                        <option value="<?php echo $email_server; ?>" selected style="display:none;"><?php echo $email_server; ?></option>
                                        <option value="LOCAL">Local</option>
                                        <option value="SMTP">SMTP</option>
                                    </select>
                                </div>
                            </div>
                            <div id="smtpSection" <?php if($email_server == 'LOCAL') { echo 'style="display: none;"'; } ?>>                           
                              <div class="form-group">
                                  <label class="col-sm-2 col-sm-2 control-label">SMTP Host</label>
                                  <div class="col-sm-10">
                                      <input type="text" name="smtp_host" class="form-control" value="<?php echo $smtp_host; ?>">
                                  </div>
                              </div>
                              <div class="form-group">
                                  <label class="col-sm-2 col-sm-2 control-label">SMTP Auth</label>
                                  <div class="col-sm-10">
                                      <select class="form-control" name="smtp_auth">
                                          <option value="true" <?php if($smtp_auth == 'true') { echo 'selected'; } ?>>On</option>
                                          <option value="false" <?php if($smtp_auth == 'false') { echo 'selected'; } ?>>Off</option>
                                      </select>
                                  </div>
                              </div>
                              <div class="form-group">
                                  <label class="col-sm-2 col-sm-2 control-label">SMTP Port</label>
                                  <div class="col-sm-10">
                                      <input type="text" name="smtp_port" class="form-control" value="<?php echo $smtp_port; ?>">
                                  </div>
                              </div>
                              <div class="form-group">
                                  <label class="col-sm-2 col-sm-2 control-label">SMTP Secure</label>
                                  <div class="col-sm-10">
                                      <select class="form-control" name="smtp_secure">
                                          <option value="tls" <?php if($smtp_secure == 'tls') { echo 'selected'; } ?>>TLS</option>
                                          <option value="ssl" <?php if($smtp_secure == 'ssl') { echo 'selected'; } ?>>SSL</option>
                                          <option value="none" <?php if($smtp_secure == 'none') { echo 'selected'; } ?>>NONE</option>
                                      </select>
                                  </div>
                              </div>
                              <div class="form-group">
                                  <label class="col-sm-2 col-sm-2 control-label">SMTP Username</label>
                                  <div class="col-sm-10">
                                      <input type="text" name="smtp_username" class="form-control" value="<?php echo $smtp_username; ?>">
                                  </div>
                              </div>
                              <div class="form-group">
                                  <label class="col-sm-2 col-sm-2 control-label">SMTP Password</label>
                                  <div class="col-sm-10">
                                      <input type="password" name="smtp_password" class="form-control" placeholder="SMTP Password (Leave empty if you do not want to change it)">
                                  </div>
                              </div>
                            </div>
                            <div id="localSection" <?php if($email_server == 'SMTP') { echo 'style="display: none;"'; } ?>>
                              <div class="form-group">
                                <h4 style="text-align: center;">You have selected "Local server" there are no more options when Local server has been selected</h4>
                              </div>
                            </div>
                            <div style="float: right; padding-right: 5px;">
                              <button type="submit" class="btn btn-success" ><i class="fa fa-floppy-o"></i> Save</button>
                            </div>
                      </form>
                  </div>
              </div><!-- col-lg-12-->       
          </div><!-- /row -->
      </section>
      <?php
      break;
      case 'settings_templates':
      ?>
      <section class="wrapper">
        <div class="row mt">
                <div class="col-lg-12">
                    <div class="form-panel" style="overflow:hidden;">
                        <div style="float: left;">
                          <h4 class="mb"><i class="fa fa-angle-right"></i> E-Mail Templates</h4>
                        </div>
                        <?php
                        if(isset($_GET['lang'])) :
                          $temp_lang = mysqli_real_escape_string($mysqli, $_GET['lang']);

                          $select_receiver = $mysqli->query("SELECT * FROM $table_templates WHERE type='receiver' AND lang='$temp_lang'");
                          while($row = $select_receiver->fetch_assoc()) {
                            $temp_receiver_admin = $row['msg'];
                          }
                          $select_sender= $mysqli->query("SELECT * FROM $table_templates WHERE type='sender' AND lang='$temp_lang'");
                          while($row = $select_sender->fetch_assoc()) {
                            $temp_sender_admin = $row['msg'];
                          }
                          $select_destroyed = $mysqli->query("SELECT * FROM $table_templates WHERE type='destroyed' AND lang='$temp_lang'");
                          while($row = $select_destroyed->fetch_assoc()) {
                            $temp_destroyed_admin = $row['msg'];
                          }
                          $select_downloaded = $mysqli->query("SELECT * FROM $table_templates WHERE type='downloaded' AND lang='$temp_lang'");
                          while($row = $select_downloaded->fetch_assoc()) {
                              $temp_downloaded_admin = $row['msg'];
                          }

                          //Subject settings
                          $select_receiver_subject = $mysqli->query("SELECT * FROM $table_templates WHERE type='receiver_subject' AND lang='$temp_lang'");
                          while($row = $select_receiver_subject->fetch_assoc()) {
                            $receiver_subject_admin = $row['msg'];
                          }
                          $select_sender_subject = $mysqli->query("SELECT * FROM $table_templates WHERE type='sender_subject' AND lang='$temp_lang'");
                          while($row = $select_sender_subject->fetch_assoc()) {
                            $sender_subject_admin = $row['msg'];
                          }
                          $select_destroyed_subject = $mysqli->query("SELECT * FROM $table_templates WHERE type='destroyed_subject' AND lang='$temp_lang'");
                          while($row = $select_destroyed_subject->fetch_assoc()) {
                            $destroyed_subject_admin = $row['msg'];
                          }
                          $select_downloaded_subject = $mysqli->query("SELECT * FROM $table_templates WHERE type='downloaded_subject' AND lang='$temp_lang'");
                          while($row = $select_downloaded_subject->fetch_assoc()) {
                              $downloaded_subject_admin = $row['msg'];
                          }
                        ?>
                        <script>
                        function langSelector() 
                        {
                          var selectedLang = document.getElementById('langSelector').value;
                          window.location.href = "index.php?page=settings_templates&lang="+selectedLang;
                        }
                        </script>
                        <div style="float: right;">
                          <select id="langSelector" onchange="langSelector()">
                            <option selected="true" disabled="disabled">-- Select language --</option>
                            <?php
                            $get_languages = $mysqli->query("SELECT * FROM $table_language");
                            while($row = $get_languages->fetch_assoc()) 
                            {
                              echo '<option value="' . $row['path'] . '">' . $row['name'] . '</option>';
                            }
                            ?>
                          </select>
                        </div>
                        <form class="form-horizontal style-form" method="post" action="action.php" style="margin-top: 80px;">
                            <input type="hidden" name="action" value="settings_template">
                            <input type="hidden" name="lang" value="<?php echo $temp_lang; ?>">
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">E-Mail - Receivers</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="receiver_subject" placeholder="Receiver email subject" value="<?php echo $receiver_subject_admin; ?>"><br>
                                    <textarea name="temp_receiver" class="form-control" style="width: 100%; height: 200px;"><?php echo $temp_receiver_admin; ?></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">E-Mail - Sender</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="sender_subject" placeholder="Sender email subject" value="<?php echo $sender_subject_admin; ?>"><br>
                                    <textarea name="temp_sender" class="form-control" style="width: 100%; height: 200px;"><?php echo $temp_sender_admin; ?></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">E-Mail - Destroyed</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="destroyed_subject" placeholder="Receiver email subject" value="<?php echo $destroyed_subject_admin; ?>"><br>
                                    <textarea name="temp_destroyed" class="form-control" style="width: 100%; height: 200px;"><?php echo $temp_destroyed_admin; ?></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">E-Mail - Downloaded</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="downloaded_subject" placeholder="Downloaded email subject" value="<?php echo $downloaded_subject_admin; ?>"><br>
                                    <textarea name="temp_downloaded" class="form-control" style="width: 100%; height: 200px;"><?php echo $temp_downloaded_admin; ?></textarea>
                                </div>
                            </div>
                            <div style="float: right; padding-right: 5px;">             
                              <button type="submit" class="btn btn-success" ><i class="fa fa-floppy-o"></i> Save</button>
                            </div>
                      </form>
                      <?php

                      else:
                      ?>
                      <script>
                      function langSelector() 
                      {
                        var selectedLang = document.getElementById('langSelector').value;
                        window.location.href = "index.php?page=settings_templates&lang="+selectedLang;
                      }
                      </script>
                      <div class="form-group" style="margin-top: 80px;">
                        <select id="langSelector" onchange="langSelector()" class="form-control">
                          <option selected="true" disabled="disabled">-- Select language --</option>
                          <?php
                          $get_languages = $mysqli->query("SELECT * FROM $table_language");
                          while($row = $get_languages->fetch_assoc()) 
                          {
                            echo '<option value="' . $row['path'] . '">' . $row['name'] . '</option>';
                          }
                          ?>
                        </select>
                        <p><i>Go to this page <a href="index.php?page=settings_lang"><span class="label label-info">here</span></a> if you would like to add more language options.</i></p>
                      </div>
                      <?php
                      endif;
                      ?>
                  </div>
              </div><!-- col-lg-12-->       
          </div><!-- /row -->
      </section>
      <?php
      break;
      case 'settings_ads':
      ?>
      <section class="wrapper">
        <div class="row mt">
                <div class="col-lg-12">
                    <div class="form-panel" style="overflow:hidden;">
                        <h4 class="mb"><i class="fa fa-angle-right"></i> Advertisement</h4>
                        <form class="form-horizontal style-form" method="post" action="action.php">
                          <input type="hidden" name="action" value="settings_ads">
                          <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">Advertisement in menu enabled</label>
                            <div class="col-sm-10">
                              <select class="form-control" name="ad_1_enabled">
                                <option value="true" <?php if($ad_1_enabled == 'true') { echo 'selected'; } ?>>Yes</option>
                                <option value="false" <?php if($ad_1_enabled == 'false') { echo 'selected'; } ?>>No</option>
                              </select>
                            </div>
                          </div>
                          <div class="form-group">
                              <label class="col-sm-2 col-sm-2 control-label">Advertisement in menu code</label>
                              <div class="col-sm-10">
                                  <textarea name="ad_1_code" class="form-control" style="width: 100%; height: 300px;"><?php echo $ad_1_code; ?></textarea>
                                  <p><i>Advertisement code, if you are using adsense do not forget to include the javascript tags</i></p>
                              </div>
                          </div>
                          <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">Advertisement on upload/download enabled</label>
                            <div class="col-sm-10">
                              <select class="form-control" name="ad_2_enabled">
                                <option value="true" <?php if($ad_2_enabled == 'true') { echo 'selected'; } ?>>Yes</option>
                                <option value="false" <?php if($ad_2_enabled == 'false') { echo 'selected'; } ?>>No</option>
                              </select>
                            </div>
                          </div>
                          <div class="form-group">
                              <label class="col-sm-2 col-sm-2 control-label">Advertisement on upload/download code</label>
                              <div class="col-sm-10">
                                  <textarea name="ad_2_code" class="form-control" style="width: 100%; height: 300px;"><?php echo $ad_2_code; ?></textarea>
                                  <p><i>Advertisement code, if you are using adsense do not forget to include the javascript tags</i></p>
                              </div>
                          </div>
                          <div style="float: right; padding-right: 5px;">             
                            <button type="submit" class="btn btn-success" ><i class="fa fa-floppy-o"></i> Save</button>
                          </div>
                      </form>
                  </div>
              </div><!-- col-lg-12-->       
          </div><!-- /row -->
      </section>
      <?php
      break;
      case 'settings_social' :
      ?>
      <section class="wrapper">
        <div class="row mt">
                <div class="col-lg-12">
                    <div class="form-panel" style="overflow:hidden;">
                        <h4 class="mb"><i class="fa fa-angle-right"></i> Social settings</h4>
                        <form class="form-horizontal style-form" method="post" action="action.php">
                          <input type="hidden" name="action" value="settings_social">
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Facebook</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="facebook" placeholder="Facebook url" value="<?php echo $social_facebook; ?>">
                                    <p><i>Leave empty to disable it</i></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Twitter</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="twitter" placeholder="Twitter plus url" value="<?php echo $social_twitter; ?>">
                                    <p><i>Leave empty to disable it</i></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Google plus</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="google" placeholder="Google plus url" value="<?php echo $social_google; ?>">
                                    <p><i>Leave empty to disable it</i></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Instagram</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="instagram" placeholder="Instagram url" value="<?php echo $social_instagram; ?>">
                                    <p><i>Leave empty to disable it</i></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">GitHub</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="github" placeholder="GitHub url" value="<?php echo $social_github; ?>">
                                    <p><i>Leave empty to disable it</i></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Tumblr</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="tumblr" placeholder="Tumblr url" value="<?php echo $social_tumblr; ?>">
                                    <p><i>Leave empty to disable it</i></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Pinterest</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="pinterest" placeholder="Pinterest url" value="<?php echo $social_pinterest; ?>">
                                    <p><i>Leave empty to disable it</i></p>
                                </div>
                            </div>
                            <div style="float: right; padding-right: 5px;">             
                              <button type="submit" class="btn btn-success" ><i class="fa fa-floppy-o"></i> Save</button>
                            </div>
                      </form>
                  </div>
              </div><!-- col-lg-12-->       
          </div><!-- /row -->
      </section>
      <?php
      break;
      case 'settings_termsabout':
      ?>
      <section class="wrapper">
        <div class="row mt">
                <div class="col-lg-12">
                    <div class="form-panel" style="overflow:hidden;">
                        <h4 class="mb"><i class="fa fa-angle-right"></i> Terms &amp; About</h4>
                        <form class="form-horizontal style-form" method="post" action="action.php">
                          <input type="hidden" name="action" value="settings_termsabout">
                            <div class="form-group">
                              <label class="col-sm-2 col-sm-2 control-label">User needs to accept terms</label>
                              <div class="col-sm-10">
                                <select class="form-control" name="accept_terms">
                                  <option value="yes" <?php if($accept_terms_enabled == 'yes') { echo 'selected'; } ?>>Yes</option>
                                  <option value="no" <?php if($accept_terms_enabled == 'no') { echo 'selected'; } ?>>No</option>
                                </select>
                              </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Terms</label>
                                <div class="col-sm-10">
                                    <textarea class="form-control" name="terms" style="width: 100%; height: 300px;"><?php echo $terms_text; ?></textarea>
                                    <p><i>You can use HTML to style the text</i></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">About</label>
                                <div class="col-sm-10">
                                    <textarea class="form-control" name="about" style="width: 100%; height: 300px;"><?php echo $about_text; ?></textarea>
                                    <p><i>You can use HTML to style the text</i></p>
                                </div>
                            </div>
                            <div style="float: right; padding-right: 5px;">             
                              <button type="submit" class="btn btn-success" ><i class="fa fa-floppy-o"></i> Save</button>
                            </div>
                      </form>
                  </div>
              </div><!-- col-lg-12-->       
          </div><!-- /row -->
      </section>
      <?php
      break;
      case 'settings_lang':
      ?>
      <section class="wrapper">
            <h3><i class="fa fa-angle-right"></i> Supported languages</h3>
          <div class="row mt">
            <div class="col-lg-12">
                      <div class="content-panel">
                          <section id="unseen" style="overflow:auto;">
                            <table class="table table-bordered table-striped table-condensed sortable">
                              <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Name</th>
                                    <th>Path</th>
                                    <th>Action</th>
                                </tr>
                              </thead>
                              <tbody>
                              <?php
                                $get_lang = $mysqli->query("SELECT * FROM $table_language");

                                //Echo table content
                                while($row = $get_lang->fetch_assoc()) {
                                  echo '<tr>';
                                  echo '<td>' . $row['id'] . '</td>';
                                  echo '<td>' . $row['name'] . '</td>';
                                  echo '<td>' . $row['path'] . '</td>';
                                  echo '<td><a href="action.php?action=rm_lang&lang=' . $row['id'] . '"><li class="fa fa-trash"></li> Remove</a></td>';
                                  echo '</tr>';
                                }
                              ?>                          
                            </tbody>
                        </table>
                        <p><i>Language files are located in the directory <code>/config/language/</code>, new language files need to be added there.</i></p>
                        <form action="action.php" method="POST">
                          <input type="hidden" name="action" value="add_lang">
                          <div style="padding-top: 20px;">
                            <div style="float: left; padding-left: 10px; width: 250px;">
                              <input type="text" class="form-control input-sm" name="name" placeholder="Name">
                            </div>
                            <div style="float: left; padding-left: 6px; width: 250px;">
                              <input type="text" class="form-control input-sm" name="path" placeholder="Path (Only filename)">
                            </div>
                            <div style="float: left; padding-left: 6px; width: 100px;">
                              <input type="submit" class="btn btn-success btn-sm" value="Add">
                            </div>
                          </div>
                        </form>
                      </section>
                  </div><!-- /content-panel -->
               </div><!-- /col-lg-4 -->
        </div><!-- /row -->
      <?php
      break;
      case 'plugin_settings':
      ?>
      <section class="wrapper">
        <div class="row mt">
          <div class="col-lg-12">
            <?php 
            $plugin_id = $_GET['id'];

            $get_plugin = $mysqli->query("SELECT * FROM $table_plugins WHERE id='$plugin_id'");
            while($plugin = $get_plugin->fetch_assoc()) {
              include dirname(__FILE__) . '/../plugins/' . $plugin['path'] . 'plugin_settings.php';
            }
            ?>            
          </div><!-- col-lg-12-->       
        </div><!-- /row -->
      </section>
      <?php
      break;
      case 'system':
      $latest_version = get_proxibolt_api('http://api.proxibolt.com/versions/droppy/v.html');
      ?>
      <section class="wrapper">
        <?php
        $get_settings = $mysqli->query("SELECT * FROM $table_settings");
        while($system = $get_settings->fetch_assoc()) {
        ?>
        <div class="row mt">
          <div class="col-lg-12">
            <div class="form-panel" style="overflow:hidden;">
              <h4 class="mb"><i class="fa fa-server"></i> System</h4>
              <li class="list-group-item"><span class="pull-right"><?php echo $system['version']; ?></span>Current version</li>
              <li class="list-group-item"><span class="pull-right"><?php if($latest_version == '') { echo '<span class="label label-danger">Not connected</span>'; } else { echo $latest_version; } ?></span>Latest version</li>
              <li class="list-group-item"><span class="pull-right"><?php echo phpversion(); ?></span>PHP Version</li>
              <li class="list-group-item"><span class="pull-right"><?php echo $system['site_url']; ?></span>Website URL</li>
              <li class="list-group-item"><span class="pull-right"><?php echo $_SERVER['SERVER_ADDR']; ?></span>Server IP</li>
              <li class="list-group-item"><span class="pull-right"><?php if(function_exists('curl_version') != '') { echo 'Enabled'; } else { echo 'Disabled (Need to install)'; } ?></span>CURL</li>
            </div>
            <script>
              function updateClick() {
                document.getElementById('updateDiv').style.display = "none";
                document.getElementById('updatingDiv').style.display = "block";
              }
            </script>
            <div class="form-panel" style="overflow:hidden;" id="updateDiv">
              <h4 class="mb"><i class="fa fa-server"></i> Auto-Update</h4>
              <?php
              if(function_exists('curl_version') != '') :
                if($system['version'] == $latest_version || $system['version'] > $latest_version) :
                ?>
                <p><b>Awesome !</b> You are using the latest version available.</p>
                <p>Signup <span class="label label-info"><a href="https://newsletter.proxibolt.com" target="_blank" style="color: #FFF;">here</a></span> and get notified when there is a new update available.
                <?php
                else:
                ?>
                <form action="action.php" method="POST">
                  <input type="hidden" name="action" value="update">
                  <?php
                  $update_msg = get_proxibolt_api('http://api.proxibolt.com/messages/droppy/msg.html');

                  if($_GET['e'] == 'purchase') {
                    echo '<div class="alert alert-danger" role="alert">The purchase code is not found on the system of Envato, are you sure you have entered it correctly ?</div>';
                  }
                  elseif($_GET['e'] == 'ip') {
                    echo '<div class="alert alert-danger" role="alert">Droppy and this purchase code are already in use on another IP address, if you would like to use Droppy on two (or more) systems you will need to purchase another license <a href="http://codecanyon.net/item/droppy-online-file-sharing/10575317">here</a></div>';
                    echo '<div class="alert alert-warning" role="alert">If you would like to transfer Droppy over to another IP address you will need to contact us <a href="http://support.proxibolt.com">here</a>.</div>';
                  }
                  elseif($_GET['e'] == 'failed') {
                    echo '<div class="alert alert-danger" role="alert">The update failed, please try again. Please contact us <a href="http://support.proxibolt.com">here</a> if this problem keeps happening</div>';
                  }
                  if($update_msg != 'NON' && $update_msg != '') {
                    echo '<div class="alert alert-info" role="alert">' . $update_msg . '</div>';
                  }
                  ?>
                  <p style="padding-left: 15px;">Your version of Droppy is outdated and needs to be updated, please enter your purchase code below and Droppy will do the rest for you.</p><br>
                  <div class="form-group">
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="purchase_code" placeholder="Your purchase code" value="<?php echo $purchase_code; ?>" required>
                        <p><i>Don't know where to find your purchase code ? Please give a look to this article: <a href="https://help.market.envato.com/hc/en-us/articles/202822600-Where-Can-I-Find-my-Purchase-Code-">here</a></i></p>
                    </div>
                  </div>
                  <div style="float: right; padding-right: 5px;">             
                    <button type="submit" class="btn btn-success" onclick="updateClick();"><i class="fa fa-wrench"></i> Update</button>
                  </div>
                </form>
                <?php
                endif;
              endif;
              ?>
            </div>
            <div class="form-panel" style="overflow:hidden; display: none;" id="updatingDiv">
              <div style="padding-top: 25px;">
                <p style="text-align:center;"><i class="fa fa-spinner fa-pulse fa-3x"></i><br><br>
                Updating your system, please be patient.</p>
              </div>
            </div>
            <div class="form-panel" style="overflow:hidden;" id="manualUpdate">
              <h4 class="mb"><i class="fa fa-server"></i> Manual update</h4>
              <form action="action.php" method="POST">
                <input type="hidden" name="action" value="update_manually">
                <p>You can manually download the latest version to your desktop with the form below, this can be used if your system is unable to update automaticly.</p><br>
                <div class="form-group">
                  <div class="col-sm-10">
                      <input type="text" class="form-control" name="purchase_code" placeholder="Your purchase code" value="<?php echo $purchase_code; ?>" required>
                      <p><i>Don't know where to find your purchase code ? Please give a look to this article: <a href="https://help.market.envato.com/hc/en-us/articles/202822600-Where-Can-I-Find-my-Purchase-Code-">here</a></i></p>
                  </div>
                </div>
                <div style="float: right; margin-top:-13px;">             
                  <button type="submit" class="btn btn-success"><i class="fa fa-download"></i> Download</button>
                </div>
              </form>
            </div>
            <div class="form-panel" style="overflow:hidden;">
              <h4 class="mb"><i class="fa fa-server"></i> Last 5 updates</h4>
              <table class="table table-bordered table-striped table-condensed sortable">
                <thead>
                  <tr>
                    <th>ID</th>
                    <th>Version</th>
                    <th>Date installed</th>
                  </tr>
                </thead>
                <tbody>
                <?php
                  $get_lang = $mysqli->query("SELECT * FROM $table_updates ORDER BY id DESC LIMIT 5");

                  //Echo table content
                  while($row = $get_lang->fetch_assoc()) {
                    echo '<tr>';
                    echo '<td>' . $row['id'] . '</td>';
                    echo '<td>' . $row['version'] . '</td>';
                    echo '<td>' . $row['date'] . '</td>';
                    echo '</tr>';
                  }
                ?>                          
                </tbody>
              </table>
            </div>
          </div><!-- col-lg-12-->       
        </div><!-- /row -->
        <?php
        }
        ?>
      </section>
      <?php
      break;
      case 'plugins':
      ?>
      <section class="wrapper">
        <div class="row mt">
                <div class="col-lg-12">
                    <div class="form-panel" style="overflow:hidden ;">
                        <h4 class="mb"><i class="fa fa-angle-right"></i> Installed plugins</h4>
                        <?php
                        $get_plugins = $mysqli->query("SELECT * FROM $table_plugins");
                        if($get_plugins->num_rows == 0) :
                        ?>
                          <p>No plugins found</p>
                        <?php
                        else:
                        ?>
                        <table class="table table-bordered table-striped table-condensed sortable">
                          <thead>
                            <tr>
                                <th>Name</th>
                                <th>Path</th>
                                <th>Status</th>
                                <th>Version</th>
                                <th>Actions</th>  
                                <th>#</th>                             
                            </tr>
                          </thead>
                          <tbody>
                            <?php 
                            while($plugin = $get_plugins->fetch_assoc()) {
                              echo '<tr>';
                              echo '<td>' . $plugin['name'] . '</td>';
                              echo '<td>' . $plugin['path'] . '</td>';
                              echo '<td>' . $plugin['status'] . '</td>';
                              echo '<td>' . $plugin['version'] . '</td>';
                              if($plugin['status'] == 'ready') {
                                echo '<td><a href="action.php?action=suspend_plugin&plugin_id=' . $plugin['id'] . '"><i class="fa fa-toggle-off"></i> Suspend</a> | <a href="index.php?page=plugin_settings&id=' . $plugin['id'] . '"><i class="fa fa-cogs"></i> Settings</a> | <a href="index.php?page=update_plugin&id=' . $plugin['id'] . '"><i class="fa fa-wrench"></i> Update</a></td>';
                              }
                              else
                              {
                                echo '<td><a href="action.php?action=activate_plugin&plugin_id=' . $plugin['id'] . '"><i class="fa fa-toggle-on"></i> Activate</a> | <a href="index.php?page=plugin_settings&id=' . $plugin['id'] . '"><i class="fa fa-cogs"></i> Settings</a> | <a href="index.php?page=update_plugin&id=' . $plugin['id'] . '"><i class="fa fa-wrench"></i> Update</a></td>';
                              }
                              echo '<td><a href="action.php?action=delete_plugin&plugin_id=' . $plugin['id'] . '"><i class="fa fa-trash-o"></i> Delete</a></td>';
                              echo '</tr>';
                            }
                            ?>
                          </tbody>
                        </table>
                        <?php
                        endif;
                        ?>
                    </div>
                    <div class="form-panel" style="overflow:hidden ;">
                        <h4 class="mb"><i class="fa fa-angle-right"></i> Install new plugin</h4>
                        <form class="form-horizontal style-form" method="POST" action="action.php" enctype="multipart/form-data">
                          <input type="hidden" name="action" value="install_plugin">
                           <div class="form-group">
                              <label class="col-sm-2 col-sm-2 control-label">Select plugin zip file (See documentation)</label>
                              <div class="col-sm-10">
                                  <input type="file" name="file" required="required" accept="application/zip">
                              </div>
                          </div>
                          <div style="float: right; padding-right: 5px;">
                            <button type="submit" class="btn btn-success" ><i class="fa fa-bolt"></i> Install</button>
                          </div>
                      </form>
                  </div>
              </div><!-- col-lg-12-->       
          </div><!-- /row -->
      </section>
      <?php
      break;
      case 'update_plugin':
      ?>
      <section class="wrapper">
        <div class="row mt">
                <div class="col-lg-12">
                    <div class="form-panel" style="overflow:hidden ;">
                        <h4 class="mb"><i class="fa fa-angle-right"></i> Update plugin</h4>
                        <form class="form-horizontal style-form" method="POST" action="action.php" enctype="multipart/form-data">
                            <input type="hidden" name="action" value="update_plugin">
                            <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
                           <div class="form-group">
                              <label class="col-sm-2 col-sm-2 control-label">Select the updated plugin zip file from CodeCanyon</label>
                              <div class="col-sm-10">
                                  <input type="file" name="file" required="required" accept="application/zip">
                              </div>
                          </div>
                          <div style="float: right; padding-right: 5px;">
                            <button type="submit" class="btn btn-success" ><i class="fa fa-bolt"></i> Update</button>
                          </div>
                      </form>
                  </div>
              </div><!-- col-lg-12-->       
          </div><!-- /row -->
      </section>
      <?php
      break;
      case 'themes':
      ?>
      <section class="wrapper">
        <div class="row mt">
                <div class="col-lg-12">
                    <div class="form-panel" style="overflow:hidden ;">
                        <h4 class="mb"><i class="fa fa-angle-right"></i> Installed themes</h4>
                        <?php
                        $get_themes = $mysqli->query("SELECT * FROM $table_themes");
                        if($get_themes->num_rows == 0) :
                        ?>
                          <p><b>WARNING !</b> No themes have been found, your home page is now unavailable</p>
                        <?php
                        else:
                        ?>
                        <table class="table table-bordered table-striped table-condensed sortable">
                          <thead>
                            <tr>
                                <th>Name</th>
                                <th>Path</th>
                                <th>Status</th>
                                <th>Actions</th>  
                                <th>#</th>                             
                            </tr>
                          </thead>
                          <tbody>
                            <?php 
                            while($theme = $get_themes->fetch_assoc()) {
                              echo '<tr>';
                              echo '<td>' . $theme['name'] . ' (<a href="../resources/themes/' . $theme['path'] . 'theme_preview.png" target="_blank">Preview</a>)</td>';
                              echo '<td>' . $theme['path'] . '</td>';
                              if($theme['status'] == 'ready') {
                                echo '<td><span class="label label-info">In use</span></td>';
                              }
                              else
                              {
                                echo '<td><span class="label label-default">Not set</span></td>';
                              }
                              if($theme['status'] == 'ready') {
                                echo '<td><a href="action.php?action=suspend_theme&theme_id=' . $theme['id'] . '"><i class="fa fa-toggle-off"></i> Suspend</a></td>';
                              }
                              else
                              {
                                echo '<td><a href="action.php?action=activate_theme&theme_id=' . $theme['id'] . '"><i class="fa fa-toggle-on"></i> Activate</a></td>';
                              }
                              echo '<td><a href="action.php?action=delete_theme&theme_id=' . $theme['id'] . '"><i class="fa fa-trash-o"></i> Remove</a></td>';
                              echo '</tr>';
                            }
                            ?>
                          </tbody>
                        </table>
                        <?php
                        endif;
                        ?>
                    </div>
                    <div class="form-panel" style="overflow:hidden ;">
                        <h4 class="mb"><i class="fa fa-angle-right"></i> Install new theme</h4>
                        <form class="form-horizontal style-form" method="POST" action="action.php" enctype="multipart/form-data">
                          <input type="hidden" name="action" value="add_theme">
                           <div class="form-group">
                              <div>
                                <label class="col-sm-2 col-sm-2 control-label">Theme name</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" name="name" required="required" placeholder="The name of the theme">
                                </div>
                              </div>
                              <div style="margin-top: 50px;">
                                <label class="col-sm-2 col-sm-2 control-label">Theme directory path (directory that is located in the "resources/themes/" directory)</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" name="directory" required="required" placeholder="The path to the theme (Path from the themes/ directory)">
                                    <p><em>Do not forget the "/" (backslash) on the end.</em></p>
                                </div>
                                
                              </div>
                          </div>
                          <div style="float: right; padding-right: 5px;">
                            <button type="submit" class="btn btn-success" ><i class="fa fa-bolt"></i> Add theme</button>
                          </div>
                      </form>
                  </div>
              </div><!-- col-lg-12-->       
          </div><!-- /row -->
      </section>
      <?php
      break;
      case 'uploads':
      $get_files = $mysqli->query("SELECT * FROM $table_uploads");
      $count_uploads = $get_files->num_rows;
      ?>
      <section class="wrapper">
            <h3><i class="fa fa-angle-right"></i> Uploads
            <div style="float: right;"><button type="button" data-toggle="modal" data-target="#modalCleardb" class="btn btn-danger"><li class="fa fa-trash"></li> Clear DB</a></div></h3>
          <div class="row mt">
            <div class="col-lg-12">
                      <?php
                      if($_GET['msg'] == 'dbcleared') {
                        echo '<div class="alert alert-success" role="alert">Database has been cleared !</div>';
                      } 
                      if($_GET['msg'] == 'destroyed') {
                        echo '<div class="alert alert-success" role="alert">Upload has been destroyed</div>';
                      }
                      ?>
                      <div class="content-panel">
                          <section id="unseen" style="overflow:auto;">
                          <?php
                          if($count_uploads == 0) :
                          ?>
                          <h4>No uploads have been found</h4>
                          <?php
                          else:
                          ?>
                            <table class="table table-bordered table-striped table-condensed sortable">
                              <thead>
                                <tr>
                                    <th>Flag</th>
                                    <th>ID</th>
                                    <th>Owner</th>
                                    <th>Upload date</th>
                                    <th>Files count</th>
                                    <th>Total downloads</th>                              
                                    <th>Status</th>
                                    <th>Share type</th>
                                    <th>Password</th>
                                    <th class="numeric">Size (MB)</th>
                                    <th>IP</th>
                                    <th>Destruct</th>
                                    <th>Action</th>
                                </tr>
                              </thead>
                              <tbody>
                              <?php
                                //Get table page
                                $rows_per_page = 20;
                                if(isset($_GET['table'])) {
                                  $table_page = $_GET['table'];
                                }
                                else
                                {
                                  $table_page = 0;
                                }                              
                                $current_table = $table_page * $rows_per_page;

                                if($_GET['view'] == 'ALL') {
                                  $get_uploads = $mysqli->query("SELECT * FROM $table_uploads ORDER BY time"); 
                                }
                                else
                                {
                                  $get_uploads = $mysqli->query("SELECT * FROM $table_uploads ORDER BY time DESC LIMIT $current_table, $rows_per_page"); 
                                }

                                //Echo table content
                                while($row = $get_uploads->fetch_assoc()) {
                                  $upload_unique = $row['upload_id'];
                                  $get_total_downloads = $mysqli->query("SELECT * FROM $table_downloads WHERE download_id='$upload_unique'");
                                  $total_downloads = $get_total_downloads->num_rows;
                                  echo '<tr>';
                                  if($row['flag'] != '' || $row['flag'] == 'yes') {
                                    echo '<td><a onclick="rmFlag(\'' . $row['upload_id'] . '\')" alt="Remove flag" id="flag_' . $row['upload_id'] . '"><i class="fa fa-flag"></i></a></td>';
                                  }
                                  else
                                  {
                                    echo '<td></td>';
                                  }                          
                                  echo '<td><a href="../' . $row['upload_id'] . '&a=' . $row['secret_code'] . '" target="_blank">' . $row['upload_id'] . '</a></td>';
                                  if(empty($row['email_from'])) {
                                    echo '<td>Link (No Email)</td>';
                                  }
                                  else
                                  {
                                    echo '<td>' . $row['email_from'] . '</td>';
                                  }
                                  echo '<td>' . date("F j, Y, g:i a", $row['time']) . '</td>';
                                  echo '<td class="numeric">' . $row['count'] . '</td>';
                                  echo '<td>' . $total_downloads . '</td>';
                                  if($row['status'] == 'ready') {
                                    echo '<td ><i class="fa fa-check"></i> Ready</td>';
                                  }
                                  if($row['status'] == 'destroyed') {
                                    echo '<td><i class="fa fa-times"></i> Destroyed</td>';
                                  }
                                  if($row['status'] == 'processing') {
                                    echo '<td><i class="fa fa-refresh"></i> Processing</td>';
                                  }
                                  if($row['share'] == 'mail') {
                                    echo '<td>Email</td>';
                                  }
                                  if($row['share'] == 'link') {
                                    echo '<td>Link</td>';
                                  }
                                  if($row['password'] == 'EMPTY') {
                                    echo '<td>No</td>';
                                  }
                                  else
                                  {
                                    echo '<td>Yes</td>';
                                  }
                                  echo '<td>' . (($row['size'] < 1048576)? round($row['size'] / 1024, 2) . ' KB' : round($row['size'] / 1048576, 2) . ' MB').'</td>';
                                  echo '<td>' . $row['ip'] . '</td>';
                                  if($row['destruct'] == 'YES') {
                                    echo '<td>Yes</td>';
                                  }
                                  elseif($row['destruct'] == 'NO') {
                                    echo '<td>No</td>';
                                  }
                                  if($row['status'] == 'ready') {
                                    if(isset($amazon_plugin) && $amazon_plugin == 'true') {
                                      $thispage = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
                                      echo '<td><a href="../plugins/' . basename($amazon_dir) . '/action.php?action=delete&id=' . $row['upload_id'] . '&return=' . $thispage . '"><i class="fa fa-trash"></i> Destroy</a></td>';
                                    }
                                    elseif(isset($ftp_plugin) && $ftp_plugin == 'true') {
                                      $thispage = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
                                      echo '<td><a href="../plugins/' . basename($ftp_dir) . '/action.php?action=delete&id=' . $row['upload_id'] . '&return=' . $thispage . '"><i class="fa fa-trash"></i> Destroy</a></td>';
                                    }
                                    else
                                    {
                                      echo '<td><a href="action.php?action=delete_upload&id=' . $row['upload_id'] . '"><i class="fa fa-trash"></i> Destroy</a></td>';
                                    }
                                  }
                                  if($row['status'] == 'destroyed') {
                                    echo '<td></td>';
                                  }
                                  echo '</tr>';
                                }
                              ?>                          
                            </tbody>
                        </table>
                        <?php
                        if($_GET['view'] != 'ALL'):
                        //Pagination script
                        $get_all = $mysqli->query("SELECT * FROM $table_uploads");
                        $count_rows = $get_all->num_rows;
                        $total_pages = round($count_rows / $rows_per_page);
                        $page_up = $table_page + 1;
                        $page_down = $table_page - 1;
                        ?>
                        <div style="float: right; padding-right: 10px;">
                        <?php
                        if($table_page > 0):
                        ?>
                          <a href="?page=uploads&table=<?php echo $page_down; ?>" class="btn btn-danger"><i class="fa fa-arrow-left"></i> Prev</a>
                        <?php
                        endif;
                        if($total_pages > $table_page + 1) :
                        ?>
                          <a href="?page=uploads&table=<?php echo $page_up; ?>" class="btn btn-success">Next <i class="fa fa-arrow-right"></i></a>
                        <?php
                        endif;
                        ?>
                        </div>
                        <div style="float: left; padding-left: 10px;">
                          <a href="index.php?page=uploads&view=ALL" class="btn btn-success">View all</a>
                        </div>
                        <?php
                        endif;
                        endif;
                        ?>
                      </section>
                  </div><!-- /content-panel -->
               </div><!-- /col-lg-4 -->     
        </div><!-- /row -->
      </section><! --/wrapper -->
      <?php
      break;
      case 'downloads':
      $get_downloads = $mysqli->query("SELECT * FROM $table_downloads");
      $count_downloads = $get_downloads->num_rows;
      ?>
      <section class="wrapper">
            <h3><i class="fa fa-angle-right"></i> Downloads
            <div style="float: right;"><button type="button" data-toggle="modal" data-target="#modalCleardb" class="btn btn-danger"><li class="fa fa-trash"></li> Clear DB</a></div></h3>
          <div class="row mt">
            <div class="col-lg-12">
                      <?php
                      if($_GET['msg'] == 'dbcleared') {
                        echo '<div class="alert alert-success" role="alert">Database has been cleared !</div>';
                      } 
                      if($_GET['msg'] == 'destroyed') {
                        echo '<div class="alert alert-success" role="alert">Upload has been destroyed</div>';
                      }
                      ?>
                      <div class="content-panel">
                          <section id="unseen" style="overflow:auto;">
                          <?php
                          if($count_downloads == 0) :
                          ?>
                          <h4>No downloads have been found</h4>
                          <?php
                          else:
                          ?>
                            <table class="table table-bordered table-striped table-condensed sortable">
                              <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Time</th>
                                    <th>Download email</th>
                                    <th>IP</th>
                                </tr>
                              </thead>
                              <tbody>
                              <?php
                                //Get table page
                                $rows_per_page = 20;
                                if(isset($_GET['table'])) {
                                  $table_page = $_GET['table'];
                                }
                                else
                                {
                                  $table_page = 0;
                                }                              
                                $current_table = $table_page * $rows_per_page;
                                if($_GET['view'] == 'ALL') {
                                  $get_uploads = $mysqli->query("SELECT * FROM $table_downloads ORDER BY time"); 
                                }
                                else
                                {
                                  $get_uploads = $mysqli->query("SELECT * FROM $table_downloads ORDER BY time DESC LIMIT $current_table, $rows_per_page"); 
                                }
                                //Echo table content
                                while($row = $get_uploads->fetch_assoc()) {
                                  echo '<tr>';                                
                                  echo '<td><a href="../' . $row['download_id'] . '" target="_blank">' . $row['download_id'] . '</a></td>';
                                  echo '<td>' . date("F j, Y, g:i a", $row['time']) . '</td>';
                                  echo '<td>' . $row['email'] . '</td>';
                                  echo '<td>' . $row['ip'] . '</td>';
                                  echo '</tr>';
                                }
                              ?>                          
                            </tbody>
                        </table>
                        <?php
                        if($_GET['view'] != 'ALL'):
                          //Pagination script
                          $get_all = $mysqli->query("SELECT * FROM $table_downloads");
                          $count_rows = $get_all->num_rows;
                          $total_pages = round($count_rows / $rows_per_page);
                          $page_up = $table_page + 1;
                          $page_down = $table_page - 1;
                          ?>
                          <div style="float: right; padding-right: 10px;">
                          <?php
                          if($table_page > 0):
                          ?>
                            <a href="?page=downloads&table=<?php echo $page_down; ?>" class="btn btn-danger"><i class="fa fa-arrow-left"></i> Prev</a>
                          <?php
                          endif;
                          if($total_pages > $table_page + 1) :
                          ?>
                            <a href="?page=downloads&table=<?php echo $page_up; ?>" class="btn btn-success">Next <i class="fa fa-arrow-right"></i></a>
                          <?php
                          endif;
                          ?>
                          </div>
                          <div style="float: left; padding-left: 10px;">
                            <a href="index.php?page=downloads&view=ALL" class="btn btn-success">View all</a>
                          </div>
                          <?php
                          endif;
                        endif;
                        ?>
                      </section>
                  </div><!-- /content-panel -->
               </div><!-- /col-lg-4 -->     
        </div><!-- /row -->
      </section><! --/wrapper -->
      <?php
      break;
      case 'pages':
      $get_pages = $mysqli->query("SELECT * FROM $table_pages");
      $count_pages = $get_pages->num_rows;
      ?>
      <section class="wrapper">
            <h3><i class="fa fa-angle-right"></i> Pages
          <div class="row mt">
            <div class="col-lg-12">
                      <div class="content-panel">
                          <section id="unseen" style="overflow:auto; font-size: 14px;">
                          <?php
                          if($count_pages == 0) :
                          ?>
                          <h4>No pages have been found</h4>
                          <?php
                          else:
                          ?>
                            <table class="table table-bordered table-striped table-condensed sortable">
                              <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Type</th>
                                    <th>Title</th>
                                    <th>Parent</th>
                                    <th>Path</th>
                                    <th>#</th>
                                </tr>
                              </thead>
                              <tbody>
                              <?php
                                //Get table page
                                $get_pages = $mysqli->query("SELECT * FROM $table_pages"); 
                                //Echo table content
                                while($row = $get_pages->fetch_assoc()) {
                                  echo '<tr>';                                
                                  echo '<td>' . $row['id'] . '</td>';
                                  echo '<td>' . $row['type'] . '</td>';
                                  echo '<td>' . $row['title'] . '</td>';
                                  echo '<td>' . $row['parent'] . '</td>';
                                  echo '<td>' . $row['path'] . '</td>';
                                  echo '<td><a href="action.php?action=delete_page&id=' . $row['id'] . '">Delete</a></td>';
                                  echo '</tr>';
                                }
                              ?>                          
                            </tbody>
                        </table>
                        <?php
                        endif;
                        ?>
                      </section>
                  </div><!-- /content-panel -->
               </div><!-- /col-lg-4 -->     
        </div><!-- /row -->
      </section><! --/wrapper -->
      <?php
      break;
      case 'personal':
      ?>
      <section class="wrapper">
        <div class="row mt">
                <div class="col-lg-12">
                    <div class="form-panel" style="overflow:hidden;">
                        <h4 class="mb"><i class="fa fa-angle-right"></i> Social settings</h4>
                        <form class="form-horizontal style-form" method="post" action="action.php">
                          <input type="hidden" name="action" value="settings_personal">
                           <div class="form-group">
                              <label class="col-sm-2 col-sm-2 control-label">Login email</label>
                              <div class="col-sm-10">
                                  <input type="email" class="form-control" name="email" placeholder="Admin email" value="<?php echo $_SESSION['droppy_admin']; ?>">
                                  <p><i>Admin login email</i></p>
                              </div>
                          </div>
                          <div class="form-group">
                              <label class="col-sm-2 col-sm-2 control-label">Login password</label>
                              <div class="col-sm-10">
                                  <input type="password" class="form-control" name="password" placeholder="Password">
                                  <p><i>Admin login password (Leave empty to keep the same)</i></p>
                              </div>
                          </div>
                          <div style="float: right; padding-right: 5px;">             
                            <button type="submit" class="btn btn-success" ><i class="fa fa-floppy-o"></i> Save</button>
                          </div>
                      </form>
                  </div>
              </div><!-- col-lg-12-->       
          </div><!-- /row -->
      </section>
      <?php
      break;
      case 'users':
      $get_users = $mysqli->query("SELECT * FROM $table_users");
      $count_users = $get_users->num_rows;
      ?>
      <section class="wrapper">
            <h3><i class="fa fa-angle-right"></i> Users
            <div style="float: right;"><button type="button" data-toggle="modal" data-target="#modalAddUser" class="btn btn-success"><li class="fa fa-plus-o"></li> Add user</a></div></h3>
            <div class="row mt">
               <div class="col-lg-12">
                      <?php
                      if($_GET['user'] == 'exists') :
                      ?>
                      <div class="alert alert-danger" role="alert">User already exists</div>
                      <?php
                      endif;
                      ?>
                      <div class="content-panel">
                          <section id="unseen" style="overflow:auto; font-size: 18px;">
                          <?php
                          if($count_users == 0) :
                          ?>
                          <h4>No users have been found in the database</h4>
                          <?php
                          else:
                          ?>
                            <table class="table table-bordered table-striped table-condensed">
                              <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>E-Mail</th>
                                    <th>Action</th>
                                </tr>
                              </thead>
                              <tbody>
                              <?php
                                //Get table page
                                $rows_per_page = 20;
                                if(isset($_GET['table'])) {
                                  $table_page = $_GET['table'];
                                }
                                else
                                {
                                  $table_page = 0;
                                }                              
                                $current_table = $table_page * $rows_per_page;

                                $get_users_table = $mysqli->query("SELECT * FROM $table_users ORDER BY id DESC LIMIT $current_table, $rows_per_page"); 

                                //Echo table content
                                while($row = $get_users_table->fetch_assoc()) {
                                  echo '<tr>';                                
                                  echo '<td>' . $row['id'] . '</td>';
                                  echo '<td>' . $row['email'] . '</td>';
                                  echo '<td><a href="action.php?action=delete_user&id=' . $row['id'] . '">Delete</a> | <a href="#" data-toggle="modal" data-target="#modalEditUser_' . $row['id'] . '">Edit</a></td>';
                                  echo '</tr>';
                                }
                              ?>                          
                            </tbody>
                        </table>
                        <?php
                        //Pagination script
                        $get_all = $mysqli->query("SELECT * FROM $table_users");
                        $count_rows = $get_all->num_rows;
                        $total_pages = round($count_rows / $rows_per_page);
                        $page_up = $table_page + 1;
                        $page_down = $table_page - 1;
                        ?>
                        <div style="float: right; padding-right: 10px;">
                        <?php
                        if($table_page > 0):
                        ?>
                          <a href="?page=users&table=<?php echo $page_down; ?>" class="btn btn-danger"><i class="fa fa-arrow-left"></i> Prev</a>
                        <?php
                        endif;
                        if($total_pages > $table_page + 1) :
                        ?>
                          <a href="?page=users&table=<?php echo $page_up; ?>" class="btn btn-success">Next <i class="fa fa-arrow-right"></i></a>
                        <?php
                        endif;
                        ?>
                        </div>
                        <?php
                        endif;
                        ?>
                      </section>
                  </div><!-- /content-panel -->
               </div><!-- /col-lg-4 -->     
        </div><!-- /row -->
      </section><! --/wrapper -->
      <?php
      while($row = $get_users->fetch_assoc()) {
        echo '<div class="modal fade" id="modalEditUser_' . $row['id'] . '" tabindex="-1" role="dialog" aria-labelledby="modalEditUser_' . $row['id'] . 'Label" aria-hidden="true">
                <div class="modal-dialog">
                  <div class="modal-content">
                    <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                      <h4 class="modal-title" id="modalEditUser_' . $row['id'] . 'Label">Edit user: ' . $row['email'] . '</h4>
                    </div>
                    <div class="modal-body">
                    <form method="post" action="action.php">
                      <input type="hidden" name="action" value="edit_user">
                      <input type="hidden" name="id" value="' . $row['id'] . '">
                      <div class="form-group">
                        <input type="text" class="form-control" name="email" placeholder="E-Mail" value="' . $row['email'] . '"><br>
                      </div>
                      <div class="form-group">
                        <input type="password" class="form-control" name="password" placeholder="password" ><br>
                      </div>
                      <input type="submit" class="btn btn-success" value="Edit user">
                    </form>
                    </div>
                    <div class="modal-footer">
                      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                  </div>
                </div>
              </div>';
      }
      break;
      case 'log':
      ?>
      <section class="wrapper">
        <div class="row mt">
              <div class="col-lg-12">
                <div id="logarea" style="width: 100%;">
                <?php
                $get_log = $mysqli->query("SELECT * FROM $table_log ORDER BY time DESC");
                if($get_log->num_rows == 0) {
                  echo 'No data';
                }
                else
                {
                  while($row = $get_log->fetch_assoc()) {
                    echo '<p><span style="color: red;">[' . date("Y-m-d H:i:s", $row['time']) . ']</span> ' . $row['msg'] . '</p>';
                  }
                }
                ?>
                </div>
              </div><!-- col-lg-12-->       
          </div><!-- /row -->
      </section>
      <?php
      break;
      }
      ?>
      <!--main content end-->
  </section>

<div class="modal fade" id="modalCleardb" tabindex="-1" role="dialog" aria-labelledby="modalCleardbLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="modalCleardbLabel">Clear database</h4>
      </div>
      <div class="modal-body" style="text-align: center;">
        <li class="fa fa-exclamation-triangle fa-5x"></li>
        <p style="padding-top: 10px;">Are you sure you want to delete all the data from your database ? This will include Upload, files and Download data.</p>
        <p><b>Warning !</b> This will not delete any uploaded files on your server</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <a type="button" href="action.php?action=cleardb" class="btn btn-primary">Clear DB</a>
      </div>
    </div>
  </div>
</div>
<div class="modal fade" id="modalAddUser" tabindex="-1" role="dialog" aria-labelledby="modalAddUserLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="modalAddUserLabel">Add user</h4>
      </div>
      <form id="createUser" action="action.php" method="POST">
        <input type="hidden" name="action" value="create_user">
        <div class="modal-body">
          <div id="userError"></div>
          <div class="form-group">
            <input type="text" class="form-control" name="email" placeholder="E-Mail">
          </div>
          <div class="form-group">
            <input type="password" class="form-control" name="password" placeholder="Password">
          </div>
          <button type="submit" class="btn btn-success" id="submitAddUser">Add user</button>
        </div>
      </form>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

<!-- js placed at the end of the document so the pages load faster -->
<script src="../src/js/admin/bootstrap.min.js"></script>
<script class="include" type="text/javascript" src="../src/js/admin/jquery.dcjqaccordion.2.7.js"></script>
<script src="../src/js/admin/jquery.scrollTo.min.js"></script>
<script src="../src/js/admin/jquery.nicescroll.js" type="text/javascript"></script>
<script src="../src/js/admin/jquery.sparkline.js"></script>


<!--common script for all pages-->
<script src="../src/js/admin/common-scripts.js"></script>

<!--script for this page-->
<script src="../src/js/admin/sparkline-chart.js"></script>    
<script src="../src/js/admin/zabuto_calendar.js"></script>	

<script type="application/javascript">
    $(document).ready(function () {
        $("#date-popover").popover({html: true, trigger: "manual"});
        $("#date-popover").hide();
        $("#date-popover").click(function (e) {
            $(this).hide();
        });
    
        $("#my-calendar").zabuto_calendar({
            action: function () {
                return myDateFunction(this.id, false);
            },
            action_nav: function () {
                return myNavFunction(this.id);
            },
            ajax: {
                url: "show_data.php?action=1",
                modal: true
            },
            legend: [
                {type: "text", label: "Special event", badge: "00"},
                {type: "block", label: "Regular event", }
            ]
        });
    });
    
    function emailServer() {
      var X = document.getElementById("email_server").value;
      if(X == 'LOCAL') {
        document.getElementById('smtpSection').style.display = "none";
        document.getElementById('localSection').style.display = "block";
      }
      if(X == 'SMTP') {
        document.getElementById('smtpSection').style.display = "block";
        document.getElementById('localSection').style.display = "none";
      }
    }
    
    function myNavFunction(id) {
        $("#date-popover").hide();
        var nav = $("#" + id).data("navigation");
        var to = $("#" + id).data("to");
        console.log('nav ' + nav + ' to: ' + to.month + '/' + to.year);
    }

    function add_bg_section() {
      var newdiv = document.createElement('div');
      newdiv.innerHTML = '<div style="padding-top: 30px;"><b>Select file:</b>(only images) <input type="file" name="background[]" accept="image/*,video/mp4"><br><input type="text" name="background_url[]" class="form-control" placeholder="Background href (Leave empty for nothing)"></div>';
      document.getElementById('extraBG').appendChild(newdiv);
    }

    function rmFlag(id) {
      var dataString = 'action=rmflag&id='+id;
      $.ajax({
        type: "POST",
        url: 'action.php',
        data: dataString,
        cache: false,
        success: function(){}
      });
      document.getElementById('flag_'+id+'').remove();
    }
</script>
  
  </body>
</html>
