<?php
   require_once("header.php");
   require_once("menu.php");
   
   $_SESSION['error'] = '';
  
   if(isset($_REQUEST['edit']))
   {
       $site_config_id = base64_decode($_REQUEST['edit']);
       $ex = $obj->get_site_configuration_id($site_config_id);
       $row = mysqli_fetch_array($ex);
   }	
   
   if(isset($_POST['update']))
   {
    $site_config['id'] = $_POST['id'];
    $site_config['about_text'] = $_POST['about_text'];
    $site_config['get_in_touch_text'] = $_POST['get_in_touch_text'];
    $site_config['get_in_touch_email'] = $_POST['get_in_touch_email'];
    $site_config['address'] = $_POST['address'];
    $site_config['contact_no'] = $_POST['contact_no'];
    $site_config['contact_no2'] = $_POST['contact_no2'];
    $site_config['email_id'] = $_POST['email_id'];
    $site_config['contact_inquiry_mail_id'] = $_POST['contact_inquiry_mail_id'];
    $site_config['subscribe_email_id'] = $_POST['subscribe_email_id'];
    $site_config['website'] = $_POST['website'];
    $site_config['map_code'] = $_POST['map_code'];
    $site_config['facebook'] = $_POST['facebook'];
	  $site_config['twitter'] = $_POST['twitter'];
    $site_config['youtube'] = $_POST['youtube'];
    $site_config['instagram'] = $_POST['instagram'];
    $site_config['linkedin'] = $_POST['linkedin'];
    $site_config['pinterest'] = $_POST['pinterest'];
	  $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/header/';
        
        if(!empty($_FILES['header_logo']['name']))
        {   
            unlink($_POST['old_img']);
            $tempname = $_FILES['header_logo']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['header_logo']['name'];
            move_uploaded_file($tempname,$upload_name);
            $site_config['header_logo'] = $server_url."/".$upload_name;
        }
		else
      {
        $site_config['header_logo'] = $_POST['old_img'];
      }
      if(!empty($_FILES['fevicon']['name']))
        {   
            unlink($_POST['fevicon1']);
            $tempname = $_FILES['fevicon']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['fevicon']['name'];
            move_uploaded_file($tempname,$upload_name);
            $site_config['fevicon'] = $server_url."/".$upload_name;
        }
    else
      {
        $site_config['fevicon'] = $_POST['fevicon1'];
      }
      if(!empty($_FILES['header_banner']['name']))
        {   
            unlink($_POST['header_banner1']);
            $tempname = $_FILES['header_banner']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['header_banner']['name'];
            move_uploaded_file($tempname,$upload_name);
            $site_config['header_banner'] = $server_url."/".$upload_name;
        }
    else
      {
        $site_config['header_banner'] = $_POST['header_banner1'];
      }

      $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
      $upload_dir = '../uploads/footer/';
        
        if(!empty($_FILES['footer_logo']['name']))
        {   
            unlink($_POST['old_img2']);
            $tempname = $_FILES['footer_logo']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['footer_logo']['name'];
            move_uploaded_file($tempname,$upload_name);
            $site_config['footer_logo'] = $server_url."/".$upload_name;
        }
    else
      {
        $site_config['footer_logo'] = $_POST['old_img2'];
      }
		
		$site_config['newsletter'] = $_POST['newsletter'];
    $site_config['how_can_text'] = $_POST['how_can_text'];
	  $site_config['copy_right'] = $_POST['copy_right'];

    $row = $obj->update_site_configuration($site_config);
   if($row){
   echo '<script>window.location="site_configuration.php"</script>';
   }
   
   
   }
                           
   if(isset($_POST['submit']))
   {
    $site_config['about_text'] = $_POST['about_text'];
    $site_config['get_in_touch_text'] = $_POST['get_in_touch_text'];
    $site_config['get_in_touch_email'] = $_POST['get_in_touch_email'];
    $site_config['address'] = $_POST['address'];
    $site_config['contact_no'] = $_POST['contact_no'];
    $site_config['contact_no2'] = $_POST['contact_no2'];
    $site_config['email_id'] = $_POST['email_id'];
    $site_config['contact_inquiry_mail_id'] = $_POST['contact_inquiry_mail_id'];
    $site_config['subscribe_email_id'] = $_POST['subscribe_email_id'];
    $site_config['website'] = $_POST['website'];
    $site_config['map_code'] = $_POST['map_code'];
    $site_config['facebook'] = $_POST['facebook'];
	$site_config['twitter'] = $_POST['twitter'];
    $site_config['youtube'] = $_POST['youtube'];
      $site_config['instagram'] = $_POST['instagram'];
    $site_config['linkedin'] = $_POST['linkedin'];
    $site_config['pinterest'] = $_POST['pinterest'];
	  
    $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/header/';
        
        if(!empty($_FILES['header_logo']))
        {            
            $tempname = $_FILES['header_logo']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['header_logo']['name'];
            move_uploaded_file($tempname,$upload_name);
            $site_config['header_logo'] = $server_url."/".$upload_name;
        }
        if(!empty($_FILES['fevicon']))
        {            
            $tempname = $_FILES['fevicon']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['fevicon']['name'];
            move_uploaded_file($tempname,$upload_name);
            $site_config['fevicon'] = $server_url."/".$upload_name;
        }
		
		$server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
		$upload_dir = '../uploads/header/';


       if(!empty($_FILES['header_banner']))
        {            
            $tempname = $_FILES['header_banner']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['header_banner']['name'];
            move_uploaded_file($tempname,$upload_name);
            $site_config['header_banner'] = $server_url."/".$upload_name;
        }
    

    $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/footer/';
        
        if(!empty($_FILES['footer_logo']))
        {            
            $tempname = $_FILES['footer_logo']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['footer_logo']['name'];
            move_uploaded_file($tempname,$upload_name);
            $site_config['footer_logo'] = $server_url."/".$upload_name;
        }
    
    $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/footer/';
        
   $site_config['newsletter'] = $_POST['newsletter']; 
   $site_config['how_can_text'] = $_POST['how_can_text']; 
	 $site_config['copy_right'] = $_POST['copy_right'];
  
    $row = $obj->add_site_configuration($site_config);
   if($row){
   echo '<script>window.location="site_configuration.php"</script>';
   }
   }
   ?>  
<div id="layoutSidenav_content">
<main class="mt-4">
   <div class="container-fluid">
      <div class="card mb-4">
         <div class="card-header">
            <i class="fas fa-check-square mr-1"></i>Site configuration
            <a href="site_configuration.php" class="btn btn-primary btn-sm float-right">Back</a>
         </div>
         <div class="card-body">
            <p class="text-danger"><?php echo $_SESSION['error'];?></p>
            <form method="post" enctype="multipart/form-data">
               <input type="hidden" name="id" value="<?php echo $site_config_id;?>">
                
               <h5 class="siteconfi">About Us Section</h5>
               <div class="form-group">
                  <label>About us Text</label>
                  <textarea id="w3review" name="about_text" rows="4" cols="50" class="form-control"><?php echo $row['about_text'];?>
                  </textarea>
               </div>
			   <h5 class="siteconfi">Get In Touch Section</h5>
			    <div class="form-group">
                  <label>Get In Touch Text</label>
                  <textarea id="w3review" name="get_in_touch_text" rows="4" cols="50" class="form-control"><?php echo $row['get_in_touch_text'];?>
                  </textarea>
               </div>
			   <div class="form-group">
                  <label>Email Id</label>
                  <input type="text" class="form-control" name="get_in_touch_email" value="<?php echo $row['get_in_touch_email'];?>">
               </div>
			   
			    <h5 class="siteconfi">Contact Us Section</h5>
               <div class="form-group">
                  <label>Address</label>
                  <textarea id="w3review" name="address" rows="4" cols="50" class="form-control"><?php echo $row['address'];?>
                  </textarea>
               </div>
			   <div class="form-group">
                  <label>Contact No</label>
                  <input type="text" class="form-control" name="contact_no" value="<?php echo $row['contact_no'];?>">
               </div>
               <div class="form-group">
                  <label>Contact No</label>
                  <input type="text" class="form-control" name="contact_no2" value="<?php echo $row['contact_no2'];?>">
               </div>
               <div class="form-group">
                  <label>Email Id</label>
                  <input type="text" class="form-control" name="email_id" value="<?php echo $row['email_id'];?>">
               </div>
                <h5 class="siteconfi">Inquiry Mail Id Section</h5>
                <div class="form-group">
                  <label>Contact Inquiry Email Id</label>
                  <input type="text" class="form-control" name="contact_inquiry_mail_id" value="<?php echo $row['contact_inquiry_mail_id'];?>">
               </div>
                                    
               <div class="form-group">
                  <label>Subscription Request Email Id</label>
                  <input type="text" class="form-control" name="subscribe_email_id" value="<?php echo $row['subscribe_email_id'];?>">
               </div>
              
               <div class="form-group">
                  <label>Website</label>
                  <input type="text" class="form-control" name="website" value="<?php echo $row['website'];?>">
               </div>
			   <div class="form-group">
                  <label>Google Map Iframe Code</label>
                  <textarea id="w3review" name="map_code" rows="4" cols="50" class="form-control"><?php echo $row['map_code'];?>
                  </textarea>
               </div>
			   
               <h5 class="siteconfi">Social Links</h5>
               <div class="form-group">
                  <label>Facebook link</label>
                  <input type="text" class="form-control" name="facebook" value="<?php echo $row['facebook'];?>">
               </div>
               
               <div class="form-group">
                  <label>Twitter link</label>
                  <input type="text" class="form-control" name="twitter" value="<?php echo $row['twitter'];?>">
               </div>
               <div class="form-group">
                  <label>Youtube link</label>
                  <input type="text" class="form-control" name="youtube" value="<?php echo $row['youtube'];?>">
               </div>
               <div class="form-group">
                  <label>Instagram</label>
                  <input type="text" class="form-control" name="instagram" value="<?php echo $row['instagram'];?>">
               </div>
               <div class="form-group">
                  <label>linkedIn</label>
                  <input type="text" class="form-control" name="linkedin" value="<?php echo $row['linkedin'];?>">
               </div>
                <div class="form-group">
                  <label>Pinterest</label>
                  <input type="text" class="form-control" name="pinterest" value="<?php echo $row['pinterest'];?>">
               </div>
			          
                <h5 class="siteconfi">Header Section</h5>
			               <div class="form-group">
                        <label>Header Logo</label><br>
						            <img src="<?php echo $row['header_logo'];?>" style="width:100px;">
                        <input type="hidden" name="old_img" value="<?php echo $row['header_logo'];?>">
                        <input type="file"  name="header_logo" value="<?php echo $row['header_logo'];?>" >
                     </div>
                       <div class="form-group">
                        <label>Favicon</label><br>
                        <img src="<?php echo $row['fevicon'];?>" style="width:100px;">
                        <input type="hidden" name="fevicon1" value="<?php echo $row['fevicon'];?>">
                        <input type="file"  name="fevicon" value="<?php echo $row['fevicon'];?>" >
                     </div>


                     <h5 class="siteconfi">Banner Section</h5>
                     <div class="form-group">
                        <label>Banner Section</label><br>
                        <img src="<?php echo $row['header_banner'];?>" style="width:100px;">
                        <input type="hidden" name="header_banner1" value="<?php echo $row['header_banner'];?>">
                        <input type="file"  name="header_banner" value="<?php echo $row['header_banner'];?>" >
                     </div>

                      <h5 class="siteconfi">Footer Section</h5>
                     <div class="form-group slider_logo">
                        <label>White Logo</label><br>
                        <img src="<?php echo $row['footer_logo'];?>" style="width:100px;">
                        <input type="hidden" name="old_img2" value="<?php echo $row['footer_logo'];?>">
                        <input type="file"  name="footer_logo" value="<?php echo $row['footer_logo'];?>" >
                     </div>
                  <h5 class="siteconfi">News Letter</h5>
                  <div class="form-group">
                  <label>News Letter</label>
                  <input type="text" class="form-control" name="newsletter" value="<?php echo $row['newsletter'];?>">
                 </div>

                  <!-- <h5 class="siteconfi">How Can We Help Text</h5>
                  <div class="form-group">
                  <label>How Can We Help Text</label>
                  <input type="text" class="form-control" name="how_can_text" value="<?php //echo $row['how_can_text'];?>">
                 </div> -->
					 
					 
			   <h5 class="siteconfi">Copy Right Section</h5>
               <div class="form-group">
                  <label>Copy Right Text</label>
                  <textarea class="form-control" name="copy_right" value=""><?php echo $row['copy_right'];?></textarea>
               </div>
               <?php if(isset($_REQUEST['edit']))
                  { ?> 
               <button type="submit" class="btn btn-primary" name="update">Update</button>
               <?php } 
                  else
                  { ?>
               <button type="submit" class="btn btn-primary" name="submit">Submit</button>
               <?php } ?>
            </form>
         </div>
      </div>
   </div>
</main>
<script>
   var url ="site_configuration.php";
</script>
<?php require_once("footer.php");?>