<?php include("../check.php");
$type='home'; if(isset($_GET['p']) && trim($_GET['p'])!=='') { $type=trim($_GET['p']); }
?>
<!DOCTYPE html>
<html>
<head>
    <?php include("common/head.php") ?>
    <script src="../ckeditor1/ckeditor/ckeditor.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body class="fixed-navbar fixed-sidebar">
<?php include("common/header.php") ?>
<?php include("common/aside.php") ?>
<div id="wrapper">
<div class="small-header transition animated fadeIn">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right">
                <ol class="hbreadcrumb breadcrumb">
                    <li><a href="<?=$baseurl; ?>welcome/">Dashboard</a></li>
                </ol>
            </div>
           <?php 
$token_id=rand(1000000000, 9999999999);
if(!isset($_SESSION['token_id']) || $_SESSION['token_id']=='') {  $_SESSION['token_id']=$token_id; }
 if ($_SERVER['REQUEST_METHOD'] == 'POST' && $access=='Yes')
  {
$token=trim($_POST['token']);
   if($token==$_SESSION['token_id'] && $_SESSION['token_id']!=='')
    { $_SESSION['token_id']=$token_id;	
    
$pageData = $getData->runQuery("SELECT * FROM `otherpage` where `page_title`='".$type."' limit 1");
$imgage = '';
$imgage = $pageData[0]['img']; $oldfiles='../../images/pages/'.$pageData[0]['img']['img'];

function uploadFile ($file_field = null, $check_image = false, $random_name = false) 
    {
    $path = '../../images/pages/'; 
    $max_size = 1000000;
    $whitelist_ext = array('jpeg','jpg','png','gif');
    $whitelist_type = array('image/jpeg', 'image/jpg', 'image/png','image/gif');
    $out = array('error'=>null);
    if((!empty($_FILES[$file_field])) && ($_FILES[$file_field]['error'] == 0)) 
    {
        $file_info = pathinfo($_FILES[$file_field]['name']);
        $name = $file_info['filename'];
        $ext = $file_info['extension'];     
       if (!in_array($ext, $whitelist_ext)) { $out['error'][] = "Invalid file Extension"; }
       if (!in_array($_FILES[$file_field]["type"], $whitelist_type)) { $out['error'][] = "Invalid file Type"; }
       if ($_FILES[$file_field]["size"] > $max_size) { $out['error'][] = "File is too big"; }
      if ($random_name) 
       { 
           $tmp = str_replace(array('.',' '), array('',''), microtime()); 
           if (!$tmp || $tmp == '') { $out['error'][] = "File must have a name"; }
           $newname = $tmp.'.'.$ext; 
       } else {  $newname = $name.'.'.$ext;  }
     
     if (count($out['error'])>0) { return $out; } 

     if (move_uploaded_file($_FILES[$file_field]['tmp_name'], $path.$newname)) 
      { $out['filepath'] = $path; $out['filename'] = $newname; return $out; } 
     else { $out['error'][] = "Server Error!"; }

   } 
   else { $out['error'][] = "No file uploaded"; return $out; } 
}

 $file = uploadFile('myimage', true, true); 
 if (is_array($file['error'])) {
  $message = '';
  foreach ($file['error'] as $msg) {
  $message .= $msg.'&nbsp;&nbsp;&nbsp;';    
 } print $msg;
} 
else { $message = ""; $imgage=$file['filename']; }
  $validfile='Yes';
    if(function_exists('finfo_open') && $_FILES['myimage']['size']>0) {
    $filespath='../../images/pages/'.$imgage;
    $mime = finfo_open(FILEINFO_MIME_TYPE);
    $mime_type = finfo_file($mime, $filespath);
    if($mime_type=="image/jpeg" || $mime_type=="image/jpg" || $mime_type=="image/png" || $mime_type=="image/gif") { $validfile='Yes'; unlink($oldfiles);  }
    else { $validfile='No'; echo "<i style='color:red;'>file is not pdf</i>"; unlink($filespath); }
    finfo_close($mime);
    }
    if($validfile=='Yes' || $_FILES['myimage']['size']<1)
     {    
            $title=htmlentities($_POST['title']);
            $metakey=htmlentities($_POST['metakey']);
            $description=htmlentities($_POST['description']);
            $heading=htmlentities($_POST['heading']);
            $data=trim($_POST['data']);
            $title_hindi=htmlentities($_POST['title_hindi']);
            $metakey_hindi=htmlentities($_POST['metakey_hindi']);
            $description_hindi=htmlentities($_POST['description_hindi']);
            $heading_hindi=htmlentities($_POST['heading_hindi']);
            $data_hindi=trim($_POST['data_hindi']);
		   
           $updateData = $db_handle->runQuery("UPDATE `otherpage` SET `title` = '".$title."', `metakey` = '".$metakey."', `description` = '".$description."', `heading` = '".$heading."', `data` = '".$data."', `title_hindi` = '".$title_hindi."', `metakey_hindi` = '".$metakey_hindi."', `description_hindi` = '".$description_hindi."', `heading_hindi` = '".$heading_hindi."', `data_hindi` = '".$data_hindi."', `img` = '".$imgage."' WHERE `page_title` = '".$_GET['p']."' limit 1");
         echo '<em style="color:#0C0;">Record saved successfully...</em>';
     }
  }
} 
$pageData = $getData->runQuery("SELECT * FROM `otherpage` where `page_title`='".$type."' limit 1");
?>
        </div>
    </div>
</div>
<div class="content animate-panel">
<div>
    <div class="row">
        <div class="col-lg-12">
            <div class="hpanel">
                <div class="panel-heading">
                    <div class="panel-tools">
                        <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                        <a class="closebox"><i class="fa fa-times"></i></a>
                    </div>
                   <?php print $pageData[0]['heading']; ?>
                </div>
                <div class="panel-body">
                <?php 
                $token_id=rand(1000000000, 9999999999); $_SESSION['token_id']=$token_id;
			    foreach($pageData as $key => $value)
	            {
			   ?>
                <form action="<?php echo $_SERVER['PHP_SELF'];?>?p=<?php echo $type; ?>" method="POST" enctype="multipart/form-data" class="form-horizontal">
                		<input type="hidden" name="token" id="token" value="<?php print $token_id; ?>">

                        <div class="text-center m-b-md" id="wizardControl">

                            <a class="btn btn-primary" href="#step1" data-toggle="tab">English</a>
                            <a class="btn btn-default" href="#step2" data-toggle="tab">Hindi</a>

                        </div>

                        <div class="tab-content">
                        	
							<div id="step1" class="tab-pane active">
                                    <div class="form-group col-lg-12">
                                        <label>English Title</label>
                                        <input type="text" value="<?php print $value['title']; ?>" id="" class="form-control" name="title" placeholder="Enter English Title">
                                    </div>
                                    <div class="form-group col-lg-12">
                                        <label>English Metakey</label>
                                        <input type="text" value="<?php print $value['metakey']; ?>" id="" class="form-control" name="metakey" placeholder="Enter English Metakey">
                                    </div>
                                    <div class="form-group col-lg-12">
                                        <label>English Description</label>
                                        <input type="text" value="<?php print $value['description']; ?>" id="" class="form-control" name="description" placeholder="Enter English Description">
                                    </div>
                                    <div class="form-group col-lg-12">
                                        <label>English Heading</label>
                                        <input type="text" value="<?php print $value['heading']; ?>" id="" class="form-control" name="heading" placeholder="Enter English Description">
                                    </div>
                                    <div class="form-group col-lg-12">
                                        <label>English Page Data</label>
                                        <textarea class="ckeditor" id="editor1" rows="8" id="details" name="data" style="max-width:100%;"><?php print $value['data']; ?></textarea>
                                    </div>
                                    <div class="form-group col-lg-12">
                                    <?php $filename='../../images/pages/'.$pageData[0]['img'];
                                  if($pageData[0]['img']!=='') {print '<img src="'.$filename.'" class="img-responsive" id="img" style="width:350px; margin:15px;">';
                                  echo '<i class="fa fa-trash" style="font-size:30px;color:red;margin-left:35%;" aria-hidden="true" id="delete-img"></i>';
                                  }
                                  ?>

                                <br>
                                <label class="col-sm-2 control-label">Image Upload</label>
                                  <div class="col-sm-8"><input type="file" name="myimage" id="myimage" class="form-control" >image size: max 500kb</div>
                                    </div>
                            </div>


                        	<div id="step2" class="tab-pane">
                                    <div class="form-group col-lg-12">
                                        <label>Hindi Title</label>
                                        <input type="text" value="<?php print $value['data_hindi']; ?>" class="form-control" name="title_hindi" placeholder="Enter Hindi Title">
                                    </div>
                                    <div class="form-group col-lg-12">
                                        <label>Hindi Metakey</label>
                                        <input type="text" value="<?php print $value['data_hindi']; ?>"  class="form-control" name="metakey_hindi" placeholder="Enter Hindi Metakey">
                                    </div>
                                    <div class="form-group col-lg-12">
                                        <label>Hindi Description</label>
                                        <input type="text" value="<?php print $value['data_hindi']; ?>"  class="form-control" name="description_hindi" placeholder="Enter HIndi Description">
                                    </div>
                                    <div class="form-group col-lg-12">
                                        <label>Hindi Heading</label>
                                        <input type="text" value="<?php print $value['data_hindi']; ?>"  class="form-control" name="heading_hindi" placeholder="Enter Hindi Heading" >
                                    </div>
                                    <div class="form-group col-lg-12">
                                        <label>Hindi Page Data</label>
                                        <textarea class="ckeditor" id="editor1" rows="8" id="details" name="data_hindi" style="max-width:100%;"><?php print $value['data_hindi']; ?></textarea>
                                    </div>
                            </div>
                            

                     		<div class="form-group">
                          <div class="col-sm-8 col-sm-offset-2">
                              <button class="btn btn-primary" id="submitbtn" type="submit">Save Changes</button>
                              <button class="btn btn-deafult" type="button" onClick="window.location.reload()">Refresh</button>
                          </div>
                      </div>
							
                        </div>
                    </form>
                 <?php 
			   }
			 ?>
                </div>
            </div>
        </div>
        
    </div>


</div>

</div>

    
    

    <?php include("common/footer.php") ?>

</div>

<script src="vendor/jquery/dist/jquery.min.js"></script>
<script src="vendor/jquery-ui/jquery-ui.min.js"></script>
<script src="vendor/slimScroll/jquery.slimscroll.min.js"></script>
<script src="vendor/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="vendor/metisMenu/dist/metisMenu.min.js"></script>
<script src="vendor/iCheck/icheck.min.js"></script>
<script src="vendor/sparkline/index.js"></script>
<script src="vendor/sweetalert/lib/sweet-alert.min.js"></script>

  <script>
    $(document).ready(function(){
      $("#delete-img").click(function(){
        var confirm = window.confirm("Are you sure?");
        if(confirm == true)
        {
          $.ajax({
            type : "POST",
            url : "delete-img.php",
            data : {
              path : $("#img").attr('src')
            },
            success : function(response)
            {
              $("#img").fadeOut();
              $("#delete-img").fadeOut();
            }
          });
        }
      });

      // $("#submitbtn").click(function()
      //   {
      //     $.ajax({
      //       type : "POST",
      //       url : "delete-img.php",
      //       data : {
      //         path : $("#img").attr('src')
      //       },
      //       success : function(response)
      //       {
      //         alert(response);
      //       }
      //     });
      //   });
    });
  </script>

<script>

$(function(){

    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
        $('a[data-toggle="tab"]').removeClass('btn-primary');
        $('a[data-toggle="tab"]').addClass('btn-default');
        $(this).removeClass('btn-default');
        $(this).addClass('btn-primary');
    })

    $('.next').click(function(){
        var nextId = $(this).parents('.tab-pane').next().attr("id");
        $('[href=#'+nextId+']').tab('show');
    })

    $('.prev').click(function(){
        var prevId = $(this).parents('.tab-pane').prev().attr("id");
        $('[href=#'+prevId+']').tab('show');
    })

    $('.submitWizard').click(function(){

        var approve = $(".approveCheck").is(':checked');
        if(approve) {
            // Got to step 1
            $('[href=#step1]').tab('show');

            // Serialize data to post method
            var datastring = $("#simpleForm").serialize();

            // Show notification
            swal({
                title: "Thank you!",
                text: "You approved our example form!",
                type: "success"
            });
//            Example code for post form
//            $.ajax({
//                type: "POST",
//                url: "your_link.php",
//                data: datastring,
//                success: function(data) {
//                    // Notification
//                }
//            });
        } else {
            // Show notification
            swal({
                title: "Error!",
                text: "You have to approve form checkbox.",
                type: "error"
            });
        }
    })
});
</script>

</body>

</html>