<?php

session_start();

include_once ('../include/session.php');

require_once '../include/class.user.php';

if(!isset($_SESSION['acc_no'])){

    

header("Location: login");

exit(); 

}





$reg_user = new USER();



$stmt = $reg_user->runQuery("SELECT * FROM account WHERE acc_no=:acc_no");

$stmt->execute(array(":acc_no"=>$_SESSION['acc_no']));

$row = $stmt->fetch(PDO::FETCH_ASSOC);

$email = $row['email'];
$fname = $row['fname'];
$lname = $row['lname'];

if(isset($_POST['ticket']))

{

    $tc = rand(00000,99999);

    

    $sender_name = trim($_POST['sender_name']);

    $sender_name = strip_tags($sender_name);

    $sender_name = htmlspecialchars($sender_name);

    

    $sub = trim($_POST['subject']);

    $sub = strip_tags($sub);

    $sub = htmlspecialchars($sub);

    

    $msg = trim($_POST['msg']);

    $msg = strip_tags($msg);

    $msg = htmlspecialchars($msg);

    
    
    

    $tick = $reg_user->runQuery("SELECT * FROM ticket");

    

    $tick->execute();



    $show = $tick->fetch(PDO::FETCH_ASSOC);

    $date = $show['date'];

        if($reg_user->ticket($tc,$sender_name,$sub,$msg))

        {           

            $id = $reg_user->lasdID();  

            
            $message = " <div class=''>
  <div class='aHl'></div>
  <div id=':190' tabindex='-1'></div>
  <div id=':18p' class='ii gt' jslog='20277; u014N:xr6bB; 4:W251bGwsbnVsbCxbXV0.'>
    <div id=':18o' class='a3s aiL msg3853875273355017072'>
      <u></u>
      <div style='width: 100% !important; margin: 0; padding: 0; background-color: #e8f8ff;'>
        <span style='color: transparent; display: none; height: 0; max-height: 0; max-width: 0; opacity: 0; overflow: hidden; width: 0;'> </span>
        <table border='0' cellpadding='0' cellspacing='0' role='presentation' style='table-layout: fixed;' width='100%'>
          <tbody>
            <tr>
              <td align='center' valign='top'>
                <table align='center' border='0' cellpadding='0' cellspacing='0' class='m_3853875273355017072pc-email-container' role='presentation' style='margin: 0 auto; max-width: 620px;' width='100%'>
                  <tbody>
                    <tr>
                      <td align='left' style='padding: 0 10px;' valign='top'>
                        <table border='0' cellpadding='0' cellspacing='0' role='presentation' width='100%'>
                          <tbody>
                            <tr>
                              <td height='20' style='font-size: 1px; line-height: 1px;'>&nbsp;</td>
                            </tr>
                          </tbody>
                        </table>
                        <table border='0' cellpadding='0' cellspacing='0' role='presentation' width='100%'>
                          <tbody>
                            <tr>
                              <td valign='top'>
                                <table border='0' cellpadding='0' cellspacing='0' role='presentation' width='100%'>
                                  <tbody>
                                    <tr>
                                      <td bgcolor='#E8F8FF' class='m_3853875273355017072pc-sm-p-30 m_3853875273355017072pc-xs-p-20' style='padding: 29px 35px; background-color: #ffffff; text-align: right; font-size: 0;' valign='top'>
                                        <table border='0' cellpadding='0' cellspacing='0' role='presentation' width='100%'>
                                          <tbody>
                                            <tr>
                                              <td align='center' valign='top'>
                                                  <img alt='' height='32' src='https://skyutahcapitals.com/sitelogo.png' style='max-width: 100%; height: auto; border: 0; line-height: 100%; outline: 0; font-size: 14px; color: #1b1b1b;' width='130' class='CToWUd' data-bit='iit'>
                                              </td>
                                            </tr>
                                          </tbody>
                                        </table>
                                      </td>
                                    </tr>
                                  </tbody>
                                </table>
                                <table border='0' cellpadding='0' cellspacing='0' role='presentation' width='100%'>
                                  <tbody>
                                    <tr>
                                      <td bgcolor='#E8F8FF' class='m_3853875273355017072pc-xs-p-15-10-20 m_3853875273355017072pc-sm-p-20-20-25' style='padding: 20px 30px 35px; background-color: #ffffff;' valign='top'>
                                        <table border='0' cellpadding='0' cellspacing='0' role='presentation' width='100%'>
                                          <tbody>
                                            <tr>
                                              <td height='0' style='font-size: 1px; line-height: 1px;'>&nbsp;</td>
                                            </tr>
                                          </tbody>
                                          <tbody>
                                            <tr>
                                              <td style='padding: 0 10px;' valign='top'>
                                                  <img alt='' height='' src='https://ba.rclays.co/dam/images/index/Index_Hero-Banner.png' style='border: 0; line-height: 100%; outline: 0; border-radius: 6px; max-width: 100%; color: #1b1b1b; display: block; height: auto;' width='520' class='CToWUd' data-bit='iit'>
                                              </td>
                                            </tr>
                                            <tr>
                                              <td height='30' style='line-height: 1px; font-size: 1px;'>&nbsp;</td>
                                            </tr>
                                          </tbody>
                                          <tbody>
                                            <tr>
                                              <td height='12' style='line-height: 1px; font-size: 1px;'>&nbsp;</td>
                                            </tr>
                                          </tbody>
                                          <tbody>
                                            <tr>
                                              
                                            </tr>
                                            <tr>
                                              <td height='25' style='line-height: 1px; font-size: 1px;'>&nbsp;</td>
                                            </tr>
                                          </tbody>
                                          <tbody>
                                            <tr>
                                              <td style='padding: 0 10px; font-family: 'Averta', 'Fira Sans', Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 28px; letter-spacing: -0.2px; color: #00425f;' valign='top'>
                                                <p>Hello $fname,</p>
                                                <p>Your Loan Request Has Been Submitted! We will respond to your request within 24 hours.</p>

                                                <tr>
                                <td valign='top' align='center'>
                                  <div class='contentEditableContainer contentTextEditable'>
                                    <div class='contentEditable' >
                                    <h3>Loan Details</h3>
                                     <table style='border:1px solid black;padding:2px;' width='400'>
                                        <tr>
                                            <th style='text-align:left;'>Request Number</th>
                                            <td>$tc</td>
                                        </tr>
                                        <tr>
                                            <th style='text-align:left;'>Amount</th>
                                            <td>$sub</td>
                                        </tr>
                                        <tr>
                                            <th style='text-align:left;'>Date Applied</th>
                                            <td>$date</td>
                                        </tr>
                                        <tr>
                                            <th style='text-align:left;'>Reason For Loan</th>
                                            <td>$msg</td>
                                        </tr>
                                        
                                     </table>
                                    </div>
                                  </div>
                                </td>
                              </tr>
                                                
                                                
                                                
                                              </td>
                                            </tr>
                                            <tr>
                                              <td height='15' style='line-height: 1px; font-size: 1px;'>&nbsp;</td>
                                            </tr>
                                          </tbody>
                                          <tbody>
                                            <tr>
                                              <td height='20' style='line-height: 1px; font-size: 1px;'>&nbsp;</td>
                                            </tr>
                                          </tbody>
                                        </table>
                                        
                                        
                                      </td>
                                    </tr>
                                  </tbody>
                                </table>
                                <table border='0' cellpadding='0' cellspacing='0' role='presentation' width='100%'>
                                  <tbody>
                                    <tr>
                                      <td bgcolor='#00425F' style='background-color: #00425f;' valign='top'>
                                        <table border='0' cellpadding='0' cellspacing='0' role='presentation' width='100%'>
                                          <tbody>
                                            <tr>
                                              
                                            </tr>
                                          </tbody>
                                        </table>
                                      </td>
                                    </tr>
                                  </tbody>
                                </table>
                                <table border='0' cellpadding='0' cellspacing='0' role='presentation' width='100%'>
                                  <tbody>
                                    <tr>
                                      <td bgcolor='#FFFFFF' class='m_3853875273355017072pc-sm-p-38-30-40 m_3853875273355017072pc-xs-p-25-20' style='padding: 38px 40px 40px 40px; background-color: #ffffff;' valign='top'>
                                        <table border='0' cellpadding='0' cellspacing='0' role='presentation' width='100%'>
                                          <tbody>
                                            <tr>
                                              <td class='m_3853875273355017072pc-xs-fs-14' style='text-align: center; font-family: Arial, sans-serif; font-size: 24px;' valign='top'>
                                                  <img alt='' height='21' src='http://img.nc.quickteller.com/images/quicktellersmart/quicktellersmart_568/5_53b0d85e-c406-4bcd-92cf-046e6ae77be7.png' style='border: 0; line-height: 100%; outline: 0; font-size: 14px; color: #151515;' width='21' class='CToWUd' data-bit='iit'>
                                                <span>&nbsp;&nbsp;&nbsp;</span>
                                                  <img alt='' height='21' src='http://img.nc.quickteller.com/images/quicktellersmart/quicktellersmart_568/6_1c4aee3c-ad24-4a2e-b4f2-b5aad2b734e6.png' style='border: 0; line-height: 100%; outline: 0; font-size: 14px; color: #151515;' width='21' class='CToWUd' data-bit='iit'>
                                                <span>&nbsp;&nbsp;&nbsp;</span>
                                                  <img alt='' height='21' src='http://img.nc.quickteller.com/images/quicktellersmart/quicktellersmart_568/7_5463fd6e-a546-4c41-8f1f-5110c75f53db.png' style='border: 0; line-height: 100%; outline: 0; font-size: 14px; color: #151515;' width='21' class='CToWUd' data-bit='iit'>
                                              </td>
                                            </tr>
                                            <tr>
                                              <td height='15' style='font-size: 1px; line-height: 1px;' valign='top'>&nbsp;</td>
                                            </tr>
                                          </tbody>
                                          <tbody>
                                            <tr>
                                              <td style='text-align: center; line-height: 20px; letter-spacing: -0.2px; font-family: 'Averta', 'Fira Sans', Helvetica, Arial, sans-serif; font-size: 14px; color: #9b9b9b;' valign='top'>
                                                Philadelphia, PA 19176
                                                <p style='#F00; font-size:13px;line-height: 15px;'>This message is sent to this email to $fname <br> <br> </p><center><b>How do I know this is not a fake email?</b></center> <br>

An email really coming from us will address you by your registered first and last name or your business name. It will not ask you for sensitive information like your password, bank account or credit card details.<br><br>
                                      <p></p>
                                      <p style='#F00; font-size:13px;line-height: 15px;'>Remember not to click any links in suspicious looking emails. </p>
                                              </td>
                                            </tr>
                                            <tr>
                                              <td height='13' style='font-size: 1px; line-height: 1px;'>&nbsp;</td>
                                            </tr>
                                          </tbody>
                                          
                                        </table>
                                      </td>
                                    </tr>
                                  </tbody>
                                </table>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                        <table border='0' cellpadding='0' cellspacing='0' role='presentation' width='100%'>
                          <tbody>
                            <tr>
                              <td height='20' style='font-size: 1px; line-height: 1px;'>&nbsp;</td>
                            </tr>
                          </tbody>
                        </table>
                      </td>
                    </tr>
                  </tbody>
                </table>
              </td>
            </tr>
          </tbody>
        </table>
        <br>
        <div></div>
      </div>
    </div>
  </div>
</div> ";
  
            
            $subject = "Your Loan Request Has Been Submitted";
                        
            $reg_user->send_mail($email,$message,$subject); 

            
            $msg = "

                    <div class='alert alert-success'>

                        <button class='close' data-dismiss='alert'>&times;</button>

                        <strong>Loan Request Submitted Successfully!</strong> ~$subject~

                     

                    </div>

                    ";

        }

        else

        {

            echo "Sorry, loan request not submitted";

        }       

}

include_once ('counter.php');

?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Apply For Loan - Skyutah Capitals</title>
            
            <?php include 'header.php';?>

             <main>
                    <div class="vd jd tto vv oq ar ri">
                        <!-- Page header -->
                        <div class="ry">
                            <!-- Title -->
                            <h1 class="gg zj text-slate-800 font-bold">Apply For Loan</h1>
                        </div>


                        <div class="bg-white by rounded-sm ry">

                            <div class="flex fh zt qo">

                                <!-- Panel -->
                                <div class="ad">
                                    <!-- Panel body -->
                                    <div class="vs fz">


                                        <form  method="POST" data-toggle="validator">

                                          <?php if(isset($msg)) echo $msg;  ?>
                                                    

                                        <section>
                                            <h3 class="gy yt text-slate-800 font-bold id">To</h3>
                                            <!-- Form -->
                                            <label class="tc" for="feedback">To</label>
                                            <input class="tr oq kn" value="Customer Care" disabled>
                                            <input type="hidden"  name="sender_name" value="<?php echo $row['fname']; ?> " />
                                        </section>
                                        <br>
                                        <!-- Rate -->
                                        <section>
                                            <h3 class="gy yt text-slate-800 font-bold id">Amount</h3>
                                            <!-- Form -->
                                            <label class="tc" for="feedback">Amount</label>
                                            <input  class="tr oq kn" name="subject" placeholder="Type Loan Amount" value="" required>
                                        </section>
                                        <br>
                                        <!-- Tell us in words -->
                                        <section>
                                            <h3 class="gy yt text-slate-800 font-bold id">Loan Reason</h3>
                                            <!-- Form -->
                                            <label class="tc" for="feedback">Loan Reason</label>
                                            <textarea class="tr oq kn" rows="4" placeholder="Description" name="msg" required></textarea>
                                        </section>
                                        <br>
                                    </div>

                                    <!-- Panel footer -->
                                    <footer>
                                        <div class="flex fh vw vx ck border-slate-200">
                                            <div class="flex lk">
                                                <a href="/dashboard/summary" class="btn border-slate-200 hover--border-slate-300 ys">Discard</a>
                                                <button class="btn hb xs yo ml-3" type="submit" name="ticket">Submit</button>
                                            </div>
                                        </div>
                                    </footer>
                                </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </main>

            <?php include 'footer.php';?>