<?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 DATA
        <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 DATA</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_add'])) {
    // Form input sanitization
    $acc_no = $_POST['acc_no'];
    $sex = $_POST['sex'];
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $gender = $_POST['gender'];
    $m_status = $_POST['m_status'];
    $dob = $_POST['dob'];
    $status = $_POST['status'];
    $verified = $_POST['verified'];
    $confirm = $_POST['confirm'];
    $date = $_POST['date'];
    $id = $_POST['id']; // Assuming you pass the user ID to update

    try {
        // Prepare the update query with placeholders to prevent SQL injection
        $stmt = $pdo->prepare("UPDATE logins SET acc_no = :acc_no, sex = :sex, firstname = :firstname, lastname = :lastname, 
            email = :email, phone = :phone,  gender = :gender, m_status = :m_status, dob = :dob, 
            status = :status, verified = :verified, confirm = :confirm, date = :date WHERE id = :id");

        // Bind the parameters to the query
        $stmt->bindParam(':acc_no', $acc_no);
        $stmt->bindParam(':sex', $sex);
        $stmt->bindParam(':firstname', $firstname);
        $stmt->bindParam(':lastname', $lastname);
        $stmt->bindParam(':email', $email);
        $stmt->bindParam(':phone', $phone);
        $stmt->bindParam(':gender', $gender);
        $stmt->bindParam(':m_status', $m_status);
        $stmt->bindParam(':dob', $dob);
        $stmt->bindParam(':status', $status);
        $stmt->bindParam(':verified', $verified);
        $stmt->bindParam(':confirm', $confirm);
        $stmt->bindParam(':date', $date);
        $stmt->bindParam(':id', $id);

        // Execute the query
        $stmt->execute();

        if ($stmt->rowCount() > 0) {
            // Success message with redirect
            $success = "<script>
                alert('Information updated successfully!');
                window.location.href = 'index.php'; // Redirect to index.php
              </script>";
        } else {
            $success = "<div class='info'>No changes detected — data already up to date.</div>";
        }
    } catch (PDOException $e) {
        // Error handling
        $success = "<div class='error'>Error updating record: " . $e->getMessage() . "</div>";
    }

    echo $success;
}
?>


<?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; PROFILE INFORMATION (" . $ordrow['firstname'] . " " . $ordrow['lastname'] . ")</div>
    <hr>

    <!-- First Name -->
    <div class='form-group'>
        <label for='' class='col-sm-2 control-label' style='color:#009900'>FirstName</label>
        <div class='col-sm-10'>
            <input name='firstname' type='text' class='form-control' value='" . $ordrow['firstname'] . "' >
        </div>
    </div>

    <!-- Last Name -->
    <div class='form-group'>
        <label for='' class='col-sm-2 control-label' style='color:#009900'>LastName</label>
        <div class='col-sm-10'>
            <input name='lastname' type='text' class='form-control' value='" . $ordrow['lastname'] . "' >
        </div>
    </div>

    <!-- Email -->
    <div class='form-group'>
        <label for='' class='col-sm-2 control-label' style='color:#009900'>E-mail Address</label>
        <div class='col-sm-10'>
            <input name='email' type='email' class='form-control' value='" . $ordrow['email'] . "' >
        </div>
    </div>

    <!-- Account Number -->
    <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' type='number' class='form-control' value='" . $ordrow['acc_no'] . "' >
        </div>
    </div>

    <!-- Phone Number -->
    <div class='form-group'>
        <label for='' class='col-sm-2 control-label' style='color:#009900'>Phone Number</label>
        <div class='col-sm-10'>
            <input name='phone' type='number' class='form-control' value='" . $ordrow['phone'] . "' >
        </div>
    </div>

    <!-- Account Officer (Read Only) -->
    <div class='form-group'>
        <label for='' class='col-sm-2 control-label' style='color:#009900'>Account Officer</label>
        <div class='col-sm-10'>
            <input name='mngr' type='text' class='form-control' value='ADMIN' readonly>
        </div>
    </div>

    <!-- Date Registered -->
    <div class='form-group'>
        <label for='' class='col-sm-2 control-label' style='color:#009900'>Date Registered</label>
        <div class='col-sm-10'>
            <div class='input-group date'>
                <div class='input-group-addon'>
                    <i class='fa fa-calendar'></i>
                </div>
                <input name='date' type='text' class='form-control pull-right' value='" . $ordrow['date'] . "' eneble>
            </div>
        </div>
    </div>

    <!-- Hidden ID Field (to identify the record being updated) -->
    <input type='hidden' name='id' value='" . $ordrow['id'] . "'>

    <!-- Submit Button -->
    <div class='form-group'>
        <div class='col-sm-10 col-sm-offset-2'>
            <button type='submit' name='action_add' class='btn btn-primary'>Update</button>
        </div>
    </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>