<?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>
        SECURITY 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'>SECURITY DATA</a></li>
              
   
               
<li><a href='#tab_7' class='btn btn-warning' data-toggle='tab'>LOGIN</a></li>
               
               
             
           
              
              </ul>
              
         
            
            
            
          <div class='tab-content'>
            
            
     




            
         <?php
require_once '../config.php'; // Include your PDO connection

// Handle form submission


if (isset($_POST['action_sec'])) {
    $pin = $_POST['pin'] ?? '';
    $password = $_POST['password'] ?? '';
    $cpassword = $_POST['password'] ?? '';
    $pint_status = $_POST['pint_status'] ?? '';
    $id = $_POST['id'] ?? 0;

    if (is_numeric($id)) {
        // Hash the password before storing it
        $hashedPassword = password_hash($password, PASSWORD_BCRYPT);

        // Prepare and execute the SQL statement
        $stmt = $pdo->prepare("UPDATE logins SET pin = :pin, password = :password, cpassword = :cpassword, pint_status = :pint_status WHERE id = :id");
        $stmt->execute([
            ':pin' => $pin,
            ':password' => $hashedPassword, // Use the hashed password
            ':cpassword' => $cpassword,
            ':pint_status' => $pint_status,
            ':id' => $id
        ]);

        if ($stmt->rowCount() > 0) {
            // Success message
            $success = "<div class='success'>Security info updated successfully.</div>";
            // Add JavaScript for the popup alert and redirect
            echo "<script>
                    alert('Security info updated successfully.');
                    window.location.href = 'index.php'; // Change this to the page you want to redirect to
                  </script>";
        } else {
            $success = "<div class='info'>No changes detected — data already up to date.</div>";
        }
    } else {
        $success = "<div class='error'>Invalid ID provided.</div>";
    }

    echo $success;
}


// Fetch and display the user info
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) {
        ?>
        <div class='tab-pane fade in active' id='tab_1'>
            <hr>
            <div class='form-group'>
                <form class='form-horizontal' method='post' enctype='multipart/form-data' action=''>
                    <input type='hidden' name='id' value='<?= htmlspecialchars($ordrow['id']) ?>'>

                    <div class='alert-danger'>
                        &nbsp; ACCOUNT NAME (<?= htmlspecialchars($ordrow['firstname'] . ' ' . $ordrow['lastname']) ?>)
                    </div>
                    <hr>

                    <div class='form-group'>
                        <label class='col-sm-2 control-label' style='color:#009900'>Password</label>
                        <div class='col-sm-10'>
                            <input type='text' name='password' class='form-control' value='<?= htmlspecialchars($ordrow['cpassword']) ?>'>
                        </div>
                    </div>

                    <div class='form-group'>
                        <label class='col-sm-2 control-label' style='color:#009900'>Transaction Pin</label>
                        <div class='col-sm-10'>
                            <input name='pin' type='text' class='form-control' value='<?= htmlspecialchars($ordrow['pin']) ?>'>
                        </div>
                    </div>

                    <div class='form-group'>
                        <label class='col-sm-2 control-label' style='color:#009900'>OTP CODE</label>
                        <div class='col-sm-10'>
                            <input type='text' class='form-control' value='<?= htmlspecialchars($ordrow['pint']) ?>' readonly>
                        </div>
                    </div>

                    <div class='form-group'>
                        <label class='col-sm-2 control-label' style='color:#009900'>Activate OTP</label>
                        <div class='col-sm-10'>
    <select name='pint_status' class='form-control' style='height: 50px;'>
        <option value='1' <?= $ordrow['pint_status'] == 1 ? "selected" : "" ?>>ON</option>
        <option value='0' <?= $ordrow['pint_status'] == 0 ? "selected" : "" ?>>OFF</option>
    </select>
</div>

                    </div>

                    <center>
                        <button type='submit' class='btn btn-info btn-flat' name='action_sec'>
                            <i class='fa fa-save'></i>&nbsp;Update Security
                        </button>
                    </center>
                </form>
            </div>
        </div>
        <?php
    } else {
        echo "<div class='error'>User not found.</div>";
    }
} else {
    echo "<div class='error'>Invalid or missing user ID.</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>