<?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>
        MAIL USER
        <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'>MAIL USER</a></li>
              
   
               
<li><a href='#tab_7' class='btn btn-warning' data-toggle='tab'>LOGIN</a></li>
               
               
             
           
              
              </ul>
              
         
            
            
            
          <div class='tab-content'>
            
            
     
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

// Load PHPMailer classes
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
require 'PHPMailer/Exception.php';

// Get website settings from database
$stmt = $pdo->query("SELECT * FROM settings ORDER BY id DESC LIMIT 1");
$row = $stmt->fetch(PDO::FETCH_ASSOC);

if ($row) {
    $cphone   = $row['phone'];
    $curl     = $row['url'];
    $cdomain  = $row['domain'];
    $cname    = $row['domain_name'];
    $cpass    = $row['password'];
    $cemail   = $row['email2'];         // Sender's email address
    $cright   = $row['copyright'];
    $chost    = $row['contact_email'];  // SMTP Host
    $cport    = $row['service1'];       // SMTP Port
    $ctitle   = $row['title'];
}

if (isset($_POST['action_email'])) {
    // Sanitize and validate inputs
   
   
    $id = $_POST['id'] ?? 0;
    $email = $_POST['email'] ?? '';
    $name = $_POST['name'] ?? '';
    $phone = $_POST['phone'] ?? '';
    $msg = $_POST['msg'] ?? '';
    $title = $_POST['title'] ?? '';
    $status = $_POST['status'] ?? '';
    $date = $_POST['date'] ?? '';

    // Validate ID and sanitize further if needed
    if (is_numeric($id)) {
        try {
            // Insert the message into the database using PDO
            $stmt = $pdo->prepare("INSERT INTO message (log_id, email, name, phone, msg, title, status, date) VALUES (:id, :email, :name, :phone, :msg, :title, 1, :date)");
            $stmt->execute([
                ':id' => $id,
                ':email' => $email,
                ':name' => $name,
                ':phone' => $phone,
                ':msg' => $msg,
                ':title' => $title,
                ':date' => $date
            ]);

            // Send email to the admin
            $mail = new PHPMailer(true);
            try {
                // Server settings
                $mail->isSMTP();
            $mail->Host = $chost;
            $mail->SMTPAuth = true;
            $mail->Username = $cemail;
            $mail->Password = $cpass;
            $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
            $mail->Port = $cport;

                // Recipients
                $mail->setFrom($email, $name);
                $mail->addAddress($cemail); // Admin's email address

                // Content
                $mail->isHTML(true);
                $mail->Subject = 'MESSAGE DELIVERED TO (' . $name . ')';
                $mail->Body    = "
                    <p>Your message has been delivered to the contact details below:</p>
                    <p>NAME: $name<br>
                    PHONE: $phone<br>
                    EMAIL: $email<br>
                    MESSAGE: $msg</p>
                ";

                $mail->send();
            } catch (Exception $e) {
                echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
            }

            // Send email to the user
            try {
                $mail->clearAddresses();
                $mail->addAddress($email); // User's email address
                $mail->Subject = 'MESSAGE FROM ADMIN';
                $mail->Body    = "
                    <p>You have a new message from $cname.</p>
                    <p>TITLE: $title<br>
                    PHONE: $cphone<br>
                    EMAIL: $cemail<br>
                    MESSAGE: $msg</p>
                ";

                $mail->send();
            } catch (Exception $e) {
                echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
            }

            // Success message
            echo "<script>alert('Message sent successfully.'); window.location.href = 'index.php';</script>";

        } catch (PDOException $e) {
            // Handle database insertion errors
            echo "<script>alert('Error: " . $e->getMessage() . "'); window.location.href = 'index.php';</script>";
        }
    } else {
        echo "<script>alert('Invalid ID.'); 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' action='' method='post'>
                                <div class='card-body'>
                                    
                                    
                                 
                                 <input type='hidden' class='form-control' name='id' value='" . $ordrow['id'] . "'readonly>
                                    
                                    
                                    
                                    <div class='form-group row'>
                                        <label for='firstname' class='col-sm-3 text-right control-label col-form-label'> Name</label>
                                        <div class='col-sm-9'>
                                            <input type='text' class='form-control' name='name' value='" . $ordrow['firstname'] . " " . $ordrow['lastname'] . "'  readonly>
                                        </div>
                                    </div>
                                    
                                    
                                    <div class='form-group row'>
                                        <label for='lname' class='col-sm-3 text-right control-label col-form-label'>Email</label>
                                        <div class='col-sm-9'>
                                            <input type='email' class='form-control' name='email' value='" . $ordrow['email'] . "'   readonly>
                                        </div>
                                    </div>
                                    
                                    
                                    
                                    <div class='form-group row'>
                                        <label for='phone' class='col-sm-3 text-right control-label col-form-label'>Mobile Number</label>
                                        <div class='col-sm-9'>
                                            <input type='text' class='form-control' name='phone' value='" . $ordrow['phone'] . "'  readonly>
                                        </div>
                                    </div>
                                   
                                    
                                    <div class='form-group row'>
                                        <label for='cono1' class='col-sm-3 text-right control-label col-form-label'>Title</label>
                                        <div class='col-sm-9'>
                                            <input type='text' class='form-control' name='title' placeholder=''>
                                        </div>
                                    </div>
                                    
                                    
                                    <div class='form-group row'>
                                        <label for='cono1' class='col-sm-3 text-right control-label col-form-label'>Message</label>
                                        <div class='col-sm-9'>
                                            <textarea type='text' name='msg' id='editor1' class='form-control'></textarea>
                                            
   
                                        </div>
                                    </div>
                                </div>";
}
}
?>


 <input type="hidden" class="form-control" name="date" id="details"  value="<?php
echo(date("jS F Y g.iA"));
?>"  readonly/><br>
            
<div class="col-md-12">
<div class="form-group app-label">
  <label for="edit_personal_email" class="control-label">Ticket ID</label>
                   <?php
$ticket_id = rand(10000000000000,100000000000000);
?>
 <input name="ticket_id" type="number" class="form-control"  value="<?php echo $ticket_id; ?>"readonly>  
 </div></div>
 <div class='border-top'>
                                    <div class='card-body'>
                                        <button type='submit' name='action_email' class='btn btn-primary'>Submit</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>