<?php
include('extension/connect.php');
include('extension/check-login.php');
include('extension/function.php');
include('extension/rank_check.php');

$admin_data = data_records($con);
$fast_loading = fast_loading($con);
$fastpro_loading = fastpro_loading($con);
$userid = $_SESSION['userid'];
$search = $userid;
$active = 'site_settings';
$status = '';
$status2 = '';
$status3 = '';
$mainte1 = '';
$mainte2 = '';
define('resize_width', 480);
define('resize_height', 480);
?>

<?php
if(isset($_POST['siteupdate'])){
  $webname = mysqli_real_escape_string($con,$_POST['webname']);
  $weburl = mysqli_real_escape_string($con,$_POST['weburl']);
  $maintenance = mysqli_real_escape_string($con,$_POST['maintenance']);
  $mytheme = mysqli_real_escape_string($con,$_POST['themez']);
  $mytxt = mysqli_real_escape_string($con,$_POST['themetext']);
    
    $dirpath = "../assets/images/logo/";
	if(is_dir($dirpath) == false)
	{
		mkdir($dirpath, 0777, true) or die('Error: ');
	}
	
	$images = restructure_array( $_FILES );
    $allowedExts = array("gif", "jpeg", "jpg", "png");
        foreach ( $images as $key => $value)
    		{		
    			$i = $key+1;
    										
    			$image_name = $value['name'];
    			$ext = strtolower(pathinfo($image_name, PATHINFO_EXTENSION));
    			$name = $i*time().'.'.$ext;
    			$image_size = $value["size"] / 1024;
    			$image_flag = true;
    			$max_size = 10000;
    				
    			}
  
    if($webname!='' && $weburl!=''){
            if($image_name=='')
                {
                    $query = mysqli_query($con,"UPDATE admin set title_name='$webname', website='$weburl', maintenance='$maintenance', theme='$mytheme', theme_text='$mytxt'");
                        if($query){
                            $status = '<div class="alert alert-success alert-dismissible" role="alert">
                                            [Site] Update successful
                                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                                <span aria-hidden="true">×</span>
                                            </button>
                                        </div>';
                        }else{
                            $status = '<div class="alert alert-danger alert-dismissible" role="alert">
                                            [Site] Update failure
                                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                                <span aria-hidden="true">×</span>
                                            </button>
                                        </div>';
                    }
            }else{
                    if( in_array($ext, $allowedExts) && $image_size < $max_size )
    				{
    					$image_flag = true;
    				} 
    				else 
    				{
    					$image_flag = false;
    					$status = '<div class="alert alert-danger alert-dismissible" role="alert">
                                    Maybe '.$image_name.' exceeds max '.$max_size.' KB size or incorrect file extension
                                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                        <span aria-hidden="true">×</span>
                                    </button>
                                </div>';
    				} 
    						
    				if( $value["error"] > 0 ){
    					$image_flag = false;
    					$status = '<div class="alert alert-danger alert-dismissible" role="alert">
                                    '.$image_name.' Image contains error - Error Code : '.$value["error"].'
                                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                        <span aria-hidden="true">×</span>
                                    </button>
                                </div>';
    				}
    						
    				if($image_flag)
    				{
    					$pic = mysqli_query($con,"select * from admin");
    					while($rowas = mysqli_fetch_array($pic))
    					{
    						$site_logo = $rowas['logo'];
    						if($site_logo == '')
    						{
    							
    						}else{
    							$path_photo = $dirpath . $site_logo;
    							unlink($path_photo);	
    						}
    					}
    
    					move_uploaded_file($value["tmp_name"], $dirpath.$name);
    								
    					$original = $name;
    					$filename = $dirpath.$name;
    					$resized = $dirpath.$name;
    					if (resizeImage($filename, resize_width, resize_height, $resized))  
    					{  
    					}else{  
    						$status = '<div class="alert alert-danger alert-dismissible" role="alert">
                                    [Site] There was an error resizing your image
                                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                        <span aria-hidden="true">×</span>
                                    </button>
                                </div>';
    					}
    					
        				$query = mysqli_query($con,"UPDATE admin set title_name='$webname', website='$weburl', logo='$original', maintenance='$maintenance', theme='$mytheme', theme_text='$mytxt'");
                            if($query){
                                $status = '<div class="alert alert-success alert-dismissible" role="alert">
                                                [Site] Update successful
                                                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                                    <span aria-hidden="true">×</span>
                                                </button>
                                            </div>';
                            }else{
                                $status = '<div class="alert alert-danger alert-dismissible" role="alert">
                                                [Site] Update failure
                                                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                                    <span aria-hidden="true">×</span>
                                                </button>
                                            </div>';
                        }
    				}
                }
    }
    else{
        $status = "toastr.info('Please fill-out all forms!', 'Error!', {timeOut: 3000})";
    }
}elseif(isset($_POST['privacyupdate'])){
    $privatext = $_POST['privacy']; 
    
    $content = "$privatext";
    $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/updater/privacy","wb");
    $fwrite = fwrite($fp,$content);
    $fclose = fclose($fp);
    
    if($fwrite && $fclose){
        $status2 = '<div class="alert alert-success alert-dismissible" role="alert">
                        [Privacy] Successfully updated
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                    </div>';
    }else{
        $status2 = '<div class="alert alert-danger alert-dismissible" role="alert">
                        [Privacy] Update failed
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                    </div>';
    }
}elseif(isset($_POST['termsupdate'])){
    $termtext = $_POST['terms']; 
    
    $content = "$termtext";
    $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/updater/terms","wb");
    $fwrite = fwrite($fp,$content);
    $fclose = fclose($fp);
    
    if($fwrite && $fclose){
        $status3 = '<div class="alert alert-success alert-dismissible" role="alert">
                        [Terms] Successfully updated
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                    </div>';
    }else{
        $status3 = '<div class="alert alert-danger alert-dismissible" role="alert">
                        [Terms] Update failed
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                    </div>';
    }
}

function restructure_array(array $images)
{
	$result = array();

	foreach ($images as $key => $value) {
		foreach ($value as $k => $val) {
			for ($i = 0; $i < count($val); $i++) {
				$result[$i][$k] = $val[$i];
			}
		}
	}

	return $result;
}

function resizeImage($filename, $max_width, $max_height, $newfilename="", $withSampling=true)   
{   
   $width = 0;  
   $height = 0;  
  
   $newwidth = 0;  
   $newheight = 0;  
  
	// If no new filename was specified then use the original filename  
	if($newfilename == "")   
	{  
		$newfilename = $filename;   
	}  
      
	// Get original sizes   
	list($width, $height) = getimagesize($filename);   
      
	if($width > $height)  
	{  
		// We're dealing with max_width  
		if($width > $max_width)  
		{  
			$newwidth = $width * ($max_width / $width);  
			$newheight = $height * ($max_width / $width);  
		}else{  
			// No need to resize  
			$newwidth = $width;  
			$newheight = $height;  
		}  
	}else{  
		// Deal with max_height  
		if($height > $max_height)  
		{  
			$newwidth = $width * ($max_height / $height);  
			$newheight = $height * ($max_height / $height);  
		}else{  
			// No need to resize  
			$newwidth = $width;  
			$newheight = $height;  
		}  
	}  
  
	// Create a new image object   
	$thumb = imagecreatetruecolor($newwidth, $newheight);   
	imagealphablending($thumb, false);
	imagesavealpha($thumb, true);
	
	// Load the original based on it's extension  
	$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));  
  
	if($ext=='jpg' || $ext=='jpeg'){  
		$source = imagecreatefromjpeg($filename);   
	}elseif($ext=='gif'){  
		$source = imagecreatefromgif($filename);
		imagealphablending($source, true);		
	}elseif($ext=='png'){   
		$source = imagecreatefrompng($filename); 
		imagealphablending($source, true);		
	}else{  
		// Fail because we only do JPG, JPEG, GIF and PNG  
		return FALSE;  
	}  
      
	// Resize the image with sampling if specified  
	if($withSampling)   
	{  
		imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);   
	}else{     
		imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);   
	}  
          
	$imageQuality = 100;       
	// Save the new image   
	if($ext=='jpg' || $ext=='jpeg'){  
		return imagejpeg($thumb, $newfilename);   
	}elseif($ext=='gif'){  
      return imagegif($thumb, $newfilename);   
	}elseif($ext=='png'){  
		$scaleQuality = round(($imageQuality/100) * 9);
		$invertScaleQuality = 9 - $scaleQuality;
		return imagepng($thumb, $newfilename);   
	}
	imagedestroy($thumb);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="keywords" content="<?php include('extension/title.php'); ?>" />
  <meta name="description" content="<?php include('extension/title.php'); ?> - VPN Panel System" />
  <meta name="author" content="<?php include('extension/title.php'); ?>" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title><?php include('extension/title.php'); ?> | Site Settings</title>

  <!-- Favicon -->
  <link rel="shortcut icon" href="<?php include('extension/logo.php'); ?>" />
  
  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="/assets/plugins/fontawesome-free/css/all.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <!-- Bootstrap Color Picker -->
  <link rel="stylesheet" href="/assets/plugins/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css">
  <!-- summernote -->
  <link rel="stylesheet" href="/assets/plugins/summernote/summernote-bs4.min.css">
  <!-- Tempusdominus Bootstrap 4 -->
  <link rel="stylesheet" href="/assets/plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
  <!-- iCheck -->
  <link rel="stylesheet" href="/assets/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <!-- JQVMap -->
  <link rel="stylesheet" href="/assets/plugins/jqvmap/jqvmap.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="/assets/dist/css/adminlte.min.css">
  <!-- overlayScrollbars -->
  <link rel="stylesheet" href="/assets/plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
  <!-- Daterange picker -->
  <link rel="stylesheet" href="/assets/plugins/daterangepicker/daterangepicker.css">
  <!-- summernote -->
  <link rel="stylesheet" href="/assets/plugins/summernote/summernote-bs4.min.css">
</head>
<body class="hold-transition sidebar-mini layout-fixed">
<?php
    $dns_status = mysqli_query($con,"select status from dns");
    $dns_count = mysqli_num_rows($dns_status);
    
    if($dns_count == 0){
        $dns_bg = 'red-bg';
    }else{
        $dns_bg = 'green-bg';
    }
?>
<div class="wrapper">

  <!-- Preloader -->
  <div class="preloader flex-column justify-content-center align-items-center">
    <img class="animation__shake" src="<?php include('extension/logo.php'); ?>" alt="Preloader" height="60" width="60">
  </div>

  <?php include('extension/topnav.php'); ?>
  
  <?php include('extension/sidenav.php'); ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0">Site Settings</h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#" style="color: <?php include('extension/theme.php'); ?>;">Home</a></li>
              <li class="breadcrumb-item active">Site Settings</li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->
    
    <section class="content">
        
      <div class="container-fluid">
        
        <div class="row">
          <!-- left column -->
          <div class="col-md-6">
            <!-- jquery validation -->
            <?php
            $query = mysqli_query($con,"select * from users where user_name='$userid'");
            $result = mysqli_fetch_array($query);
            ?>
            <div class="card card-primary">
              <div class="card-header" style="color: <?php include('extension/theme_text.php'); ?>; background-color: <?php include('extension/theme.php'); ?>;">
                <h3 class="card-title">Site Settings</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form method="post" enctype="multipart/form-data">
                
                <?php
                    $query = mysqli_query($con,"select * from admin");
                    $result = mysqli_fetch_array($query);
                        
                    $web_name = $result['title_name'];
                    $web_url = $result['website'];
                    $mainte = $result['maintenance'];
                    $themez = $result['theme'];
                    $themeztext = $result['theme_text'];
                        
                    if($mainte == '0'){
                        $mainte1 = 'selected';
                        $mainte2 = '';
                    }else{
                        $mainte2 = 'selected';
                        $mainte1 = '';
                    }
                ?>  
                  
                <div class="card-body">
                  <?php echo $status; ?>
                  <div class="form-group">
                      <label for="images">Logo</label>
                      <div class="custom-file">
                        <input type="file" class="custom-file-input" id="images" name="images[]">
                        <label class="custom-file-label" for="images">Choose file</label>
                      </div>
                  </div>  
                  <div class="form-group">
                    <label for="webname">Website Name</label>
                    <input name="webname" value="<?php echo $web_name; ?>" type="text" class="form-control" id="webname" placeholder="Enter update name" required>
                  </div>
                  
                  <div class="form-group">
                    <label for="weburl">Website URL</label>
                    <input name="weburl" value="<?php echo $web_url; ?>" type="text" class="form-control" id="weburl" placeholder="Enter update name" required>
                  </div>
                  
                  <div class="form-group">
                    <label for="maintenance">Maintenance</label>
                      <select name="maintenance" class="custom-select form-control" id="maintenance">
                        <option value="0" <?php echo $mainte1; ?>>Inactive</option>
                        <option value="1" <?php echo $mainte2; ?>>Active</option>
                      </select>
                  </div>
                  
                  <div class="form-group">
                    <label for="hostname">Theme Color</label>
                    <input type="text" value="<?php echo $themez; ?>" name="themez" class="form-control my-colorpicker1 colorpicker-element" data-colorpicker-id="1" data-original-title="" title="" aria-describedby="popover292981">
                  </div>
                  
                  <div class="form-group">
                    <label for="hostname">Text Color</label>
                    <input type="text" value="<?php echo $themeztext; ?>" name="themetext" class="form-control my-colorpicker1 colorpicker-element" data-colorpicker-id="1" data-original-title="" title="" aria-describedby="popover292981">
                  </div>
                  
                </div>
                <!-- /.card-body -->
                <div class="card-footer">
                  <button type="submit" name="siteupdate" class="btn" style="color: <?php include('extension/theme_text.php'); ?>; background-color: <?php include('extension/theme.php'); ?>;">Submit</button>
                </div>
              </form>
            </div>
            <!-- /.card -->
            </div>
          <!--/.col (left) -->
          <!-- right column -->
          <div class="col-md-6">
            <!-- jquery validation -->
            <div class="card card-primary">
              <div class="card-header" style="color: <?php include('extension/theme_text.php'); ?>; background-color: <?php include('extension/theme.php'); ?>;">
                <h3 class="card-title">Privacy Policy</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form method="post">
                
                <?php
                    $file = '../updater/privacy';
                    $myfile = fopen($file, "r") or die("Unable to open file!");
                    $privacy = fread($myfile,filesize($file));
                    fwrite($myfile, $privacy);
                    fclose($myfile);
                ?>
                  
                <div class="card-body">
                  <?php echo $status2; ?>
                  <div class="form-group">
                      <textarea id="privacy" name="privacy"><?php echo $privacy; ?></textarea>
                  </div>  
                </div>
                <!-- /.card-body -->
                <div class="card-footer">
                  <button type="submit" name="privacyupdate" class="btn" style="color: <?php include('extension/theme_text.php'); ?>; background-color: <?php include('extension/theme.php'); ?>;">Submit</button>
                </div>
              </form>
            </div>
            <!-- /.card -->
            <div class="card card-primary">
              <div class="card-header" style="color: <?php include('extension/theme_text.php'); ?>; background-color: <?php include('extension/theme.php'); ?>;">
                <h3 class="card-title">Terms & Conditions</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form method="post">
                
                <?php
                    $file = '../updater/terms';
                    $myfile = fopen($file, "r") or die("Unable to open file!");
                    $terms = fread($myfile,filesize($file));
                    fwrite($myfile, $terms);
                    fclose($myfile);
                ?>
                  
                <div class="card-body">
                  <?php echo $status3; ?>
                  <div class="form-group">
                      <textarea id="terms" name="terms"><?php echo $terms; ?></textarea>
                  </div>  
                </div>
                <!-- /.card-body -->
                <div class="card-footer">
                  <button type="submit" name="termsupdate" class="btn" style="color: <?php include('extension/theme_text.php'); ?>; background-color: <?php include('extension/theme.php'); ?>;">Submit</button>
                </div>
              </form>
            </div>
            </div>
          </div>
        </div>
        <!-- /.row -->
        
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <?php include('extension/footer.php'); ?>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="/assets/plugins/jquery/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="/assets/plugins/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
  $.widget.bridge('uibutton', $.ui.button)
</script>
<!-- jQuery -->
<script src="/assets/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="/assets/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- bs-custom-file-input -->
<script src="/assets/plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
<!-- Select2 -->
<script src="/assets/plugins/select2/js/select2.full.min.js"></script>
<!-- Bootstrap4 Duallistbox -->
<script src="/assets/plugins/bootstrap4-duallistbox/jquery.bootstrap-duallistbox.min.js"></script>
<!-- Summernote -->
<script src="/assets/plugins/summernote/summernote-bs4.min.js"></script>
<!-- InputMask -->
<script src="/assets/plugins/moment/moment.min.js"></script>
<script src="/assets/plugins/inputmask/jquery.inputmask.min.js"></script>
<!-- date-range-picker -->
<script src="/assets/plugins/daterangepicker/daterangepicker.js"></script>
<!-- bootstrap color picker -->
<script src="/assets/plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="/assets/plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Bootstrap Switch -->
<script src="/assets/plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<!-- BS-Stepper -->
<script src="/assets/plugins/bs-stepper/js/bs-stepper.min.js"></script>
<!-- dropzonejs -->
<script src="/assets/plugins/dropzone/min/dropzone.min.js"></script>
<!-- AdminLTE App -->
<script src="/assets/dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="/assets/dist/js/demo.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="/assets/dist/js/pages/dashboard.js"></script>
<script src="/assets/alertifyjs/alertify.js"></script>
<script>
  $(function () {
    //Initialize Select2 Elements
    $('.select2').select2()

    //Initialize Select2 Elements
    $('.select2bs4').select2({
      theme: 'bootstrap4'
    })

    //Datemask dd/mm/yyyy
    $('#datemask').inputmask('dd/mm/yyyy', { 'placeholder': 'dd/mm/yyyy' })
    //Datemask2 mm/dd/yyyy
    $('#datemask2').inputmask('mm/dd/yyyy', { 'placeholder': 'mm/dd/yyyy' })
    //Money Euro
    $('[data-mask]').inputmask()

    //Date picker
    $('#reservationdate').datetimepicker({
        format: 'L'
    });

    //Date and time picker
    $('#reservationdatetime').datetimepicker({ icons: { time: 'far fa-clock' } });

    //Date range picker
    $('#reservation').daterangepicker()
    //Date range picker with time picker
    $('#reservationtime').daterangepicker({
      timePicker: true,
      timePickerIncrement: 30,
      locale: {
        format: 'MM/DD/YYYY hh:mm A'
      }
    })
    //Date range as a button
    $('#daterange-btn').daterangepicker(
      {
        ranges   : {
          'Today'       : [moment(), moment()],
          'Yesterday'   : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
          'Last 7 Days' : [moment().subtract(6, 'days'), moment()],
          'Last 30 Days': [moment().subtract(29, 'days'), moment()],
          'This Month'  : [moment().startOf('month'), moment().endOf('month')],
          'Last Month'  : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        },
        startDate: moment().subtract(29, 'days'),
        endDate  : moment()
      },
      function (start, end) {
        $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'))
      }
    )

    //Timepicker
    $('#timepicker').datetimepicker({
      format: 'LT'
    })

    //Bootstrap Duallistbox
    $('.duallistbox').bootstrapDualListbox()

    //Colorpicker
    $('.my-colorpicker1').colorpicker()
    //color picker with addon
    $('.my-colorpicker2').colorpicker()

    $('.my-colorpicker2').on('colorpickerChange', function(event) {
      $('.my-colorpicker2 .fa-square').css('color', event.color.toString());
    })

    $("input[data-bootstrap-switch]").each(function(){
      $(this).bootstrapSwitch('state', $(this).prop('checked'));
    })

  })
  // BS-Stepper Init
  document.addEventListener('DOMContentLoaded', function () {
    window.stepper = new Stepper(document.querySelector('.bs-stepper'))
  })

  // DropzoneJS Demo Code Start
  Dropzone.autoDiscover = false

  // Get the template HTML and remove it from the doumenthe template HTML and remove it from the doument
  var previewNode = document.querySelector("#template")
  previewNode.id = ""
  var previewTemplate = previewNode.parentNode.innerHTML
  previewNode.parentNode.removeChild(previewNode)

  var myDropzone = new Dropzone(document.body, { // Make the whole body a dropzone
    url: "/target-url", // Set the url
    thumbnailWidth: 80,
    thumbnailHeight: 80,
    parallelUploads: 20,
    previewTemplate: previewTemplate,
    autoQueue: false, // Make sure the files aren't queued until manually added
    previewsContainer: "#previews", // Define the container to display the previews
    clickable: ".fileinput-button" // Define the element that should be used as click trigger to select files.
  })

  myDropzone.on("addedfile", function(file) {
    // Hookup the start button
    file.previewElement.querySelector(".start").onclick = function() { myDropzone.enqueueFile(file) }
  })

  // Update the total progress bar
  myDropzone.on("totaluploadprogress", function(progress) {
    document.querySelector("#total-progress .progress-bar").style.width = progress + "%"
  })

  myDropzone.on("sending", function(file) {
    // Show the total progress bar when upload starts
    document.querySelector("#total-progress").style.opacity = "1"
    // And disable the start button
    file.previewElement.querySelector(".start").setAttribute("disabled", "disabled")
  })

  // Hide the total progress bar when nothing's uploading anymore
  myDropzone.on("queuecomplete", function(progress) {
    document.querySelector("#total-progress").style.opacity = "0"
  })

  // Setup the buttons for all transfers
  // The "add files" button doesn't need to be setup because the config
  // `clickable` has already been specified.
  document.querySelector("#actions .start").onclick = function() {
    myDropzone.enqueueFiles(myDropzone.getFilesWithStatus(Dropzone.ADDED))
  }
  document.querySelector("#actions .cancel").onclick = function() {
    myDropzone.removeAllFiles(true)
  }
  // DropzoneJS Demo Code End
</script>

<script>
  $(function () {
    // Summernote
    $('#privacy').summernote({
        height: 100
    })
    
    // Summernote
    $('#terms').summernote({
        height: 100
    })

    // CodeMirror
    CodeMirror.fromTextArea(document.getElementById("codeMirrorDemo"), {
      mode: "htmlmixed",
      theme: "monokai"
    });
  })
</script>
</body>
</html>
