<?php require ("header.php")?>


      
      
    
      
      
      
      
      
      
      
      
      
       <?php
session_start();
if(isset($_SESSION['SESS_ADMINLOGGEDIN']) == FALSE) {
    header("Location: " . $config_basedir."access");
}
require_once("../config.php");

?>
      

  
      
                <?php


    $id = $_GET['id'];
   
 
 
 ?>
 
 
 
 


 
  <div class='page-wrapper'>
           
            <div class='page-breadcrumb'>
                <div class='row'>
                    <div class='col-12 d-flex no-block align-items-center'>
                       
                       
                    </div>
                </div>
            </div>
           
            <div class='container-fluid'>
               
                <div class='row'>
                    <div class='col-12'>
                        <div class='card'>
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
 
     <!-- Content Wrapper. Contains page content -->
      <div class='content-wrapper'>
      
        <!-- Main content -->
        <section class='content'>

          <div class='row'>
            <!-- /.col -->
            <div class='col-md-12'>
              <div class='nav-tabs-custom'>
                <ul class='nav nav-tabs'>
                    <li class='active'>
                          <a href='index.php' class='rowtab'><strong>HOME</strong></a>
                          
                          </li>
<a href='list_customers.php'  class='btn btn-primary' value='log in'>CUSTOMERS List</a>
                   
                   </li>
                </ul>
                <div class='tab-content'>
                  <div class='active tab-pane' id='activity'>
                    <!-- Post -->
                    <div class='post'>
      
      
          
    <section class='content-header'>
      <h1>
        USER's ADDRESS
        <small>Customer's panel</small>
      </h1>
      <ol class='breadcrumb'>
        <li><a href='index.php'><i class='fa fa-dashboard'></i> Home</a></li>
        <li class='active'> <a href='list_customers.php'>CUSTOMERS List</a></li>
        <li class='active'>Add</li>
      </ol>
    </section>
	
	
    <section class='content'>
	<div class='row'>	
		
	 <section class='content'>
     

				
				<div class='box box-success'>
            <div class='box-body'>
              <div class='table-responsive'>
             <div class='box-body'>

			 <!--<div class='col-md-14'>-->
           <div class='container'>
             <ul class='nav nav-tabs'>
              
    <li class='active'><a href='#tab_1' data-toggle='tab'>USER's ADDRESS</a></li>
              
   
               
<li><a href='#tab_7' class='btn btn-warning' data-toggle='tab'>LOGIN</a></li>
               
               
             
           
              
              </ul>
              
         
            
            
            
          <div class='tab-content'>
            
            
     

<?php
if (isset($_POST['action'])) {
    // Validate and sanitize inputs
    $country = $_POST['country'] ?? '';
    $state = $_POST['state'] ?? '';
    $city = $_POST['city'] ?? '';
    // $p_code = $_POST['p_code'] ?? '';  // If needed
    $address = $_POST['address'] ?? '';
    $id = $_POST['id'] ?? 0;  // Assuming you have an ID passed

    if (is_numeric($id)) {
        try {
            // Prepare PDO statement for update
            $stmt = $pdo->prepare("UPDATE logins SET address = :address, city = :city, state = :state WHERE id = :id");
            $stmt->execute([
                ':address' => $address,
                ':city' => $city,
                ':state' => $state,
                ':id' => $id
            ]);

            // Check if any row was updated
            if ($stmt->rowCount() > 0) {
                // If rows were updated, show success message and redirect
                echo "<script>alert('Security Information updated successfully.'); window.location.href = 'index.php';</script>";
            } else {
                // If no rows were updated (meaning data didn't change), show info message and redirect
                echo "<script>alert('No changes detected — data already up to date.'); window.location.href = 'index.php';</script>";
            }
        } catch (PDOException $e) {
            // Handle any error
            echo "<script>alert('Error updating information: " . $e->getMessage() . "'); window.location.href = 'index.php';</script>";
        }
    } else {
        // Invalid ID error
        echo "<script>alert('Invalid ID provided.'); window.location.href = 'index.php';</script>";
    }
}
?>




<?php
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
    $id = (int) $_GET['id'];

    $stmt = $pdo->prepare("SELECT * FROM logins WHERE id = :id");
    $stmt->bindParam(':id', $id, PDO::PARAM_INT);
    $stmt->execute();
    $ordrow = $stmt->fetch(PDO::FETCH_ASSOC);

    if ($ordrow) {

            echo" <form class='form-horizontal' method='post' enctype='multipart/form-data' action=''>
			
			
			
			<div class='alert-danger'>&nbsp; ADDRESS INFORMATION (" . $ordrow['firstname'] . " " . $ordrow['lastname'] . ")</div>
<hr>
	   
          	
                  		
                  		 <div class='form-group'>
                  	<label for='' class='col-sm-2 control-label' style='color:#009900'>Address</label>
                  	<div class='col-sm-10'>
					<textarea name='address'  class='form-control' rows='4' cols='80' >" . $ordrow['address'] . "</textarea>
           			 </div>
          	</div> 
          	
          	
          
			
			<div class='form-group'>
                  <label for='' class='col-sm-2 control-label' style='color:#009900'>City</label>
                  <div class='col-sm-10'>
                  <input name='city' type='text' class='form-control' value='" . $ordrow['city'] . "' >
                  </div>
                  </div>
			
			 <div class='form-group'>
                  <label for='' class='col-sm-2 control-label' style='color:#009900'>State</label>
                  <div class='col-sm-10'>
                  <input name='state' type='text' class='form-control' value='" . $ordrow['state'] . "' >
                  </div>
                  </div>
				  
				  <div class='form-group'>
                  <label for='' class='col-sm-2 control-label' style='color:#009900'>IP</label>
                  <div class='col-sm-10'>
                  <input name='id' type='text' class='form-control' value='" . $ordrow['id'] . "' readonly>
                  </div>
                  </div>
                  
               
               
              <center>
                  
                    <button type='submit' class='btn btn-info btn-flat' name='action'><i class='fa fa-save'>&nbsp;Update Address</i></button>
              </center>

              </div>
			 
			  </form>";
}
}
?>
 

            </div>
        </div>
       
 
              
       <hr>
       
       
       
         
       

              
              
                  </div> 
     
     
     
     
     
              
              
              
              
                  </div>
                  
           
              
              
              
              
              
              <?php
// Assuming you are using PDO for database connection
// Modify this code as necessary based on your PDO setup
try {
    // Prepare and execute the query using PDO
    $stmt = $pdo->prepare("SELECT * FROM logins WHERE id = :id");
    $stmt->bindParam(':id', $id, PDO::PARAM_INT);
    $stmt->execute();
    $ordrow = $stmt->fetch(PDO::FETCH_ASSOC);

    if ($ordrow) {
        echo "
        <div class='tab-pane fade' id='tab_7'>       
            <form method='POST' action='../connx/login.php' role='form'>
                <div class='form-group'>
                    <label for='' class='col-sm-2 control-label' style='color:#009900'>Account No. </label>
                    <div class='col-sm-10'>
                        <input name='acc_no' class='form-control' value='" . htmlspecialchars($ordrow['acc_no']) . "' readonly/>
                    </div>
                </div> 
                <br><br>
                
                <div class='form-group'>
                    <label for='' class='col-sm-2 control-label' style='color:#009900'>Password</label>
                    <div class='col-sm-10'>
                        <input name='password' type='password' class='form-control' placeholder='Enter your password' />
                    </div>
                </div>
                
                <center>
                    <button type='submit' name='action' value='Login' class='btn btn-success my-4'>Sign in</button> 
                </center>
            </form>
        </div>";
    } else {
        echo "Account not found.";
    }
} catch (PDOException $e) {
    echo "Error: " . $e->getMessage();
}
?>

              <!-- /.tab-pane -->
                  
					
					
				
				
				</div>
				

              </div>
			 

	
</div>	
</div>
</div></div>	
</div>
</div></div>	
</div>
</div></div>	
</div>
</div></div>	
</div>
</div>	
</div>		</section>
        
        
        
        
        
        
        
        
        
        
                    </div><!-- /.post -->

                
                  </div>
                  <!-- /.tab-pane -->
                  
                  
                  
                  

                  <!-- /.tab-pane -->
                </div><!-- /.tab-content -->
              </div><!-- /.nav-tabs-custom -->
            </div><!-- /.col -->
          </div><!-- /.row -->

        </section><!-- /.content -->
      </div>
                </div>
               
            </div>
            
           <?php require ("footer.php")?>
           
           <script>
function myFunction() {
  window.print(); }
</script>