<?php
    session_start();
    include "../../db.php";
    date_default_timezone_set('Asia/Kolkata');
    $currentTime = date('jS  F Y');

    if ( !isset($_SESSION['uid']) && !isset($_SESSION['uref']) && !isset($_SESSION['utype']) ) {
        header("Location: logout.php");
        exit();
    }
    if ( $_SESSION['utype'] != 'master_admin' && $_SESSION['uref'] != 'fssdf4543frts' ) {
        header("Location: logout.php");
        exit();
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Admin Panel</title>

  
    <link href="css/sb-admin-2.min.css" rel="stylesheet">
    <link href="css/all.min.css" rel="stylesheet" type="text/css">
	<link rel="stylesheet" href="vendor/croppie/croppie.css" />


    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.easing.min.js"></script>
    <script src="js/sb-admin-2.min.js"></script>
    <script src="vendor/croppie/croppie.js"></script>
    <script src="js/custom.js"></script>

    <script src="vendor/ckeditor.js"></script>

    <style>
        .custom-file-label::after {
            height: 8.25rem;
            padding-top: 50px;
        }
        .custom-file-label-edit::after{
            height: 2.25rem;
            padding-top: 5px;
        }
        #uploadimageModal .modal-dialog{
            max-width: 100% !important;
        }
    </style>
</head>
<body >

 <?php include "includes/topbar.php"; ?>


    <div id="wr apper">

        <div id="con tent-wrapper" class="d-flex flex-column">

            <div id="cont ent">

               
                <div class="container-fluid px-0">

                    <div class="card shadow mb-4">
                        <div class="card-body">
 <?php
                                if ( isset($_GET["edit_id"]) ) {
                                    $edit_run = mysqli_query($con, "SELECT * FROM ad WHERE aid = '$_GET[edit_id]'");
                                    $edit_row = mysqli_fetch_assoc($edit_run);
                                    ?>
                        
						
						
                            <h1 class="h3 mb-2 text-gray-800 text-center "><a href="admin_lvl2.php?see_id=<?php echo $edit_row["aid"]; ?>"><?php echo $edit_row["aname"]; ?> </h1>
                       </a>     <hr>

                           
                                    <form class="user" method="post" enctype="multipart/form-data">
                                        <h4 class="mb-3 badge badge-secondary"> <?php echo $edit_row["aname"]; ?></h4>
                                     
										
                                     
										<div class="">
											
											<div  class="form-group row" >
											<div class="col-sm-2 mb-1 mb-sm-0"></div>
										
						<div class="col-sm-8 mb-1 mb-sm-0">
						
                          <div id="logox_wrapper">
                                               <?php echo $edit_row["hpicurl"]; ?>      
                                                </div>          
						 <label>Header pic url : </label>
                         <textarea   name="content" id="content" class="form-control ckeditor" ><?php echo $edit_row["hpicurl"]; ?>
                         </textarea>


										  </div>
								</div>	
								
							
							




                                <div  class="form-group row" >
											<div class="col-sm-2 mb-1 mb-sm-0"></div>
											<div class="col-sm-8 mb-1 mb-sm-0">
                                            <label>Description: </label>
                                                <input type="text" class="form-control form-control-sm mb-2" id="apoint" value="<?php echo $edit_row["adist"]; ?>"  name="adist" > 
 <label>Point: </label>
                                                <input type="text" class="form-control form-control-sm mb-2" id="apoint" value="<?php echo $edit_row["apoint"]; ?>"  name="apoint" >
                                          
						</div>
						
								</div>




									
										<div  class="form-group row" >
											<div class="col-sm-3 mb-1 mb-sm-0"></div>
						<button type="submit" class="btn btn-success btn-user m-2" name="edit_users">					
					  
                                            <i class="far fa-image"></i> Update Organization Profile
                                        </button>
                                        <a href="admin_lvl2.php" class="btn btn-warning btn-user m-2"> <i class="fas fa-ban"></i> Cancel </a>
								</div>	
										
										
                                    </div> 
                                        
                                    </form>
									 	
                                   
                                    <?php
                                
								
								}
                            ?>

                            <hr>

                         
                        </div>
                    </div>

                </div>

            </div>

            <?php include "includes/footer.php"; ?>

        </div>

    </div>



<script>
     CKEDITOR.replace( 'content', {
        height: 200,
        filebrowserUploadUrl: "upload.php"
    });



   
</script>

   



</body>
</html>


<?php
 
 
 


    if(isset($_POST['edit_users'])){ 
	
	
	
        $hpicurl = $_POST["content"];
		$adist = $_POST["adist"];
		 $apoint = $_POST["apoint"];
        
       
  		
        {
            $up_sql = "UPDATE ad SET hpicurl = '$hpicurl',adist = '$adist',apoint = '$apoint' ";
   
  
        $up_sql .= " WHERE aid = '$_GET[edit_id]'";
		 if(mysqli_query($con, $up_sql)){

       
            ?>
            <script>
                alert("Data Updated Successfully");
                window.location = 'ad.php?edit_id=<?php echo $aid; ?>';
            </script>

        
               
                <?php
            }
            else{
                ?>
                <script>
                    alert('OOPS !!!!');
                    setTimeout(() => {
                        window.location = 'ad.php?edit_id=<?php echo $uid; ?>';
                    }, 1200);
                </script>
                <?php
            }
        
            ?>
          
			
			
            <?php
        }
    }

?>