Advertisement
Guest User

Untitled

a guest
May 9th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.83 KB | None | 0 0
  1. <?php
  2. if (isset($_POST['grade']))
  3. {
  4.     $grade = $App->entrance_exam_grade();
  5.     if ($grade >= 70)
  6.     {
  7.         $App->entrance_exam_passed($_SERVER['REMOTE_ADDR'], $grade);
  8.         header("Location: /?p=application&route=crew");
  9.     } else {
  10.         $App->entrance_exam_failed($_SERVER['REMOTE_ADDR'], $grade);
  11.         header("Location: /?p=application&route=crew");
  12.     }
  13. }
  14.  
  15. ?>
  16. <div class="top-title-wrapper">
  17.     <div class="container">
  18.         <div class="row">
  19.             <div class="col-md-12 col-sm-12">
  20.                 <div class="page-info">
  21.                     <h1 class="h1-page-title">Entrance Exam: Crew</h1>
  22.                 </div>
  23.             </div>
  24.         </div>
  25.     </div>
  26. </div>
  27. </div><!--.top wrapper end -->
  28.  
  29. <div class="loading-container">
  30.     <div class="spinner">
  31.         <div class="double-bounce1"></div>
  32.         <div class="double-bounce2"></div>
  33.     </div>
  34. </div>
  35.  
  36.  
  37. <div class="content-wrapper hide-until-loading"><div class="body-wrapper">
  38.         <div class="container">
  39.  
  40.             <div class="row">
  41.                 <div class="col-md-12 col-sm-12">
  42.                     <?php
  43.                     if (isset($ee_fail))
  44.                     { ?>
  45.                        <div class="alert alert-danger"><B>You failed the exam.</B> Not to worry, you can still try again. Remember, the test is open book.</div>
  46.                     <?php
  47.                     }
  48.                     ?>
  49.                     <div class="alert alert-info">Prospective crew members are required to pass our basic knowledge exam before being considered for employment. A passing grade is <B>70% or higher</B>, however when reviewing your final application, your overall score is taken into consideration.</div>
  50.                 </div>
  51.             </div>
  52.  
  53.             <div class="row">
  54.  
  55.                 <div class="col-md-8 col-sm-8">
  56.                     <form action="" method="post">
  57.                         <?php
  58.                         $eeq_raw = $App->entrance_exam_question_data();
  59.                         $count = 1;
  60.                         while ($eeq = $eeq_raw->fetch(PDO::FETCH_OBJ)) {
  61.                             echo '<h5 style="margin-top: 20px; margin-bottom: 0;">#' . $count . '. ' . $eeq->content . '</h5>';
  62.                             $eea_raw = $App->entrance_exam_answer_data($eeq->id);
  63.                             while ($eea = $eea_raw->fetch(PDO::FETCH_OBJ)) {
  64.                                 ?>
  65.                                 <label style="display: block">
  66.                                     <input type="radio" name="<?php echo $eeq->id; ?>" value="<?php echo $eea->id; ?>">
  67.                                     <?php echo $eea->content; ?>
  68.                                 </label>
  69.                                 <?php
  70.                             }
  71.                             $count++;
  72.                         }
  73.                         ?>
  74.  
  75.                         <input type="submit" name="grade" value="Submit" class="btn btn-block btn-primary" style="margin-top: 20px;">
  76.                     </form>
  77.                 </div>
  78.                 <div class="col-md-4 col-sm-4">
  79.                     <p>
  80.  
  81.                     </p>
  82.                 </div>
  83.             </div>
  84.  
  85.         </div>
  86.     </div>
  87. </div><!--.content-wrapper end -->
  88.  
  89.  
  90.  
  91.  
  92. <?php
  93. /**
  94.  * (c) 2017 American Virtual Infinite Flight. All Rights Reserved.
  95.  * Developed by Chop Internet, Inc.
  96.  * Contributed to by Chase Morgan
  97.  */
  98.  
  99. class App {
  100.  
  101.     /**
  102.      * Database credentials
  103.      */
  104.  
  105.     private $settings = '';
  106.     private $db_host = '';
  107.     private $db_user = '';
  108.     private $db_pass = '';
  109.     private $db_name = '';
  110.  
  111.     /**
  112.      * Database object
  113.      */
  114.  
  115.     public function dbConn()
  116.     {
  117.         return new PDO('mysql:host=' . $this->db_host . ';dbname=' . $this->db_name, $this->db_user, $this->db_pass);
  118.     }
  119.  
  120.     function __construct()
  121.     {
  122.         $this->settings = new settings();
  123.         $this->db_host = $this->settings->db_host;
  124.         $this->db_user = $this->settings->db_user;
  125.         $this->db_pass = $this->settings->db_pass;
  126.         $this->db_name = $this->settings->db_name;
  127.         $this->db = $this->dbConn();
  128.     }
  129.  
  130.     public function entrance_exam_question_data()
  131.     {
  132.         $stmt = $this->db->prepare("SELECT * FROM ee_question ORDER BY RAND() LIMIT 10");
  133.         $stmt->execute();
  134.         return $stmt;
  135.     }
  136.  
  137.     public function entrance_exam_answer_data($question_id)
  138.     {
  139.         $stmt = $this->db->prepare("SELECT * FROM ee_answer WHERE question_id = :question_id ORDER BY RAND()");
  140.         $stmt->execute(array(':question_id' => $question_id));
  141.         return $stmt;
  142.     }
  143.  
  144.     public function entrance_exam_answer_data_grade($aws_id)
  145.     {
  146.         $stmt = $this->db->prepare("SELECT * FROM ee_answer WHERE id = :aws_id");
  147.         $stmt->execute(array(':aws_id' => $aws_id));
  148.         return $stmt;
  149.     }
  150.  
  151.     public function entrance_exam_grade()
  152.     {
  153.         $correct = 0;
  154.  
  155.         $eeq_r = $this->entrance_exam_question_data();
  156.         while ($eeq = $eeq_r->fetch(PDO::FETCH_OBJ))
  157.         {
  158.             $results = $eeq_r->rowCount();
  159.             $aws_id = $_POST[$eeq->id];
  160.  
  161.             $eea_r = $this->entrance_exam_answer_data_grade($aws_id);
  162.             $eea = $eea_r->fetch(PDO::FETCH_OBJ);
  163.             if ($eea->correct == 1)
  164.             {
  165.                 $correct++;
  166.             }
  167.         }
  168.  
  169.         $prescore = 100 / $results;
  170.         $score = $prescore * $correct;
  171.         return $score;
  172.     }
  173.  
  174.     public function entrance_exam_passed($ip, $score)
  175.     {
  176.         $stmt = $this->db->prepare("DELETE FROM ee_result WHERE ip_address = :ip");
  177.         $stmt->execute(array(':ip' => $ip));
  178.  
  179.         $stmt = $this->db->prepare("INSERT INTO ee_result (ip_address, score, pass) VALUES (:ip, :score, 1)");
  180.         $stmt->execute(array(':ip' => $ip, ':score' => $score));
  181.     }
  182.  
  183.     public function entrance_exam_failed($ip, $score)
  184.     {
  185.         $stmt = $this->db->prepare("INSERT INTO ee_result (ip_address, score, pass) VALUES (:ip, :score, 0)");
  186.         $stmt->execute(array(':ip' => $ip, ':score' => $score));
  187.     }
  188.  
  189.     public function did_entrance_exam_passed($ip)
  190.     {
  191.         $stmt = $this->db->prepare("SELECT COUNT(*) FROM ee_result WHERE ip_address = :ip && pass = 1");
  192.         $stmt->execute(array(':ip' => $ip));
  193.         $count = $stmt->fetchColumn();
  194.         if ($count > 0)
  195.         {
  196.             return true;
  197.         } else {
  198.             return false;
  199.         }
  200.     }
  201.  
  202.     public function did_entrance_exam_failed($ip)
  203.     {
  204.         $stmt = $this->db->prepare("SELECT COUNT(*) FROM ee_result WHERE ip_address = :ip && pass = 0");
  205.         $stmt->execute(array(':ip' => $ip));
  206.         $count = $stmt->fetchColumn();
  207.         if ($count > 0)
  208.         {
  209.             return true;
  210.         } else {
  211.             return false;
  212.         }
  213.     }
  214.  
  215.     public function get_entrance_exam_grade($ip)
  216.     {
  217.         $stmt = $this->db->prepare("SELECT * FROM ee_result WHERE ip_address = :ip");
  218.         $stmt->execute(array(':ip' => $ip));
  219.         return $stmt;
  220.     }
  221.  
  222.     public function country_data()
  223.     {
  224.         $stmt = $this->db->prepare("SELECT * FROM country");
  225.         $stmt->execute();
  226.         return $stmt;
  227.     }
  228.  
  229.     public function generate_password() {
  230.         $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
  231.         $pass = array(); //remember to declare $pass as an array
  232.         $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
  233.         for ($i = 0; $i < 8; $i++) {
  234.             $n = rand(0, $alphaLength);
  235.             $pass[] = $alphabet[$n];
  236.         }
  237.         return implode($pass); //turn the array into a string
  238.     }
  239.  
  240.     public function account_exist($email_address, $ip)
  241.     {
  242.         $stmt = $this->db->prepare("SELECT COUNT(*) FROM account WHERE email_address = :email_address || first_ip = :ip || last_ip = :ip");
  243.         $stmt->execute(array(':email_address' => $email_address, ':ip' => $ip));
  244.         $count = $stmt->fetchColumn();
  245.         if ($count > 0)
  246.         {
  247.             return true;
  248.         } else {
  249.             return false;
  250.         }
  251.     }
  252.  
  253.     public function account_exist_no_email($ip)
  254.     {
  255.         $stmt = $this->db->prepare("SELECT COUNT(*) FROM account WHERE first_ip = :ip || last_ip = :ip");
  256.         $stmt->execute(array(':ip' => $ip));
  257.         $count = $stmt->fetchColumn();
  258.         if ($count > 0)
  259.         {
  260.             return true;
  261.         } else {
  262.             return false;
  263.         }
  264.     }
  265.  
  266.     public function process_app($first_name, $last_name, $middle_name, $date_of_birth, $email_address, $country, $gender, $app_id)
  267.     {
  268.  
  269.         $time = time();
  270.         $stmt = $this->db->prepare("INSERT INTO account (first_name, last_name, middle_name, birthday, email_address, country, gender, hire_date_initial, hire_date_last, first_ip, position) VALUES (:first_name, :last_name, :middle_name, :birthday, :email_address, :country, :gender, :hire_date_initial, :hire_date_last, :first_ip, :my_position)");
  271.         $stmt->execute(array(':first_name' => $first_name, ':last_name' => $last_name, ':middle_name' => $middle_name, ':birthday' => $date_of_birth, ':email_address' => $email_address, ':country' => $country, ':gender' => $gender, ':hire_date_initial' => $time, ':hire_date_last' => $time, ':first_ip' => $_SERVER['REMOTE_ADDR'], ':my_position' => 1));
  272.  
  273.         $email_content = "" . $this->settings->format_string($first_name) . " " . $this->settings->format_string($last_name) . ",<br/><br/> This is an automated notice to inform you that we have received application <B>" . $app_id . "</B>. Our human resources department will review your application usually within 48 hours, and return a decision.<br /><br/>----------<br/>American Virtual Infinite Flight";
  274.         $this->settings->mail_send($email_address, 'Crew Application Status', $email_content);
  275.     }
  276.  
  277.  
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement