· 7 years ago · Oct 25, 2018, 02:54 AM
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <title>WDG - Application Process</title>
5 <meta charset="utf-8" />
6 <meta name="description" content="Web Developers Group" />
7 <meta name="keywords" content="Web developer jobs" />
8 <meta name="author" content="Deniz Sumer" />
9 <!-- References to external fonts ' -->
10 <link href="https://fonts.googleapis.com/css?family=Audiowide" rel="stylesheet" />
11 <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" />
12 <link rel="stylesheet" type="text/css" href="styles/style.css" />
13</head>
14
15<body>
16 <?php include("header.inc");?>
17 <?php include("menu.inc");?>
18 <section id="page_section">
19
20 <?php
21 //function to check postcode integrity
22 function check_post_code($postcode, $state)
23 {
24 $result = false; //assumes false
25 if($state == "vic" && ($postcode[0] == "3" || $postcode[0] == "8")) $result = true;
26 if($state == "nsw" && ($postcode[0] == "1" || $postcode[0] == "2")) $result = true;
27 if($state == "qld" && ($postcode[0] == "4" || $postcode[0] == "9")) $result = true;
28 if($state == "nt" && $postcode[0] == "0") $result = true;
29 if($state == "wa" && $postcode[0] == "6") $result = true;
30 if($state == "sa" && $postcode[0] == "5") $result = true;
31 if($state == "tas" && $postcode[0] == "7") $result = true;
32 if($state == "act" && $postcode[0] == "0") $result = true;
33 return $result;
34 }
35
36 //function to clean input
37 function sanitise_input($data)
38 {
39 //sanitising (cleaning) user input data
40 $data = trim($data); //removing leading or trailing spaces
41 $data = stripslashes($data); //removing backslashes in front of quotes
42 $data = htmlspecialchars($data); //converting HTML tags to plain text
43 return $data;
44 }
45
46 //checks if process was triggered by a form submit, if not display an error message
47 if(isset($_POST["refNo"]))
48 {
49 //assigning variables
50 $refNo = $_POST["refNo"];
51 //PERSONAL DETAILS
52 if(isset($_POST["firstName"])) $firstName = $_POST["firstName"];
53 if(isset($_POST["familyName"])) $familyName = $_POST["familyName"];
54 if(isset($_POST["dob"])) $dob = $_POST["dob"];
55 if(isset($_POST["gender"])){$gender = $_POST["gender"];}
56 else{$gender = "no_gender";}
57 //address and communication details
58 if(isset($_POST["address"])){$address = $_POST["address"];}
59 if(isset($_POST["suburb"])){$suburb = $_POST["suburb"];}
60 $state = $_POST["state"];
61 if(isset($_POST["postcode"])){$postcode = $_POST["postcode"];}
62 if(isset($_POST["email"])){$email = $_POST["email"];}
63 if(isset($_POST["phone"])){$phone = $_POST["phone"];}
64 //web language skills
65 if((isset($_POST["html"]))) {$html = 1;} else {$html = 0;}
66 if((isset($_POST["css"]))) {$css = 1;} else {$css = 0;}
67 if((isset($_POST["js"]))) {$js = 1;} else {$js = 0;}
68 if((isset($_POST["php"]))) {$php = 1;} else {$php = 0;}
69 if((isset($_POST["jquery"]))) {$jquery = 1;} else {$jquery = 0;}
70 //other skills
71 if((isset($_POST["otherSkills"]))) {$otherSkills = $_POST["otherSkills"];}
72
73 //sanitising inputs
74 $firstName = sanitise_input($firstName);
75 $familyName = sanitise_input($familyName);
76 $dob = sanitise_input($dob);
77 $gender = sanitise_input($gender);
78 $address = sanitise_input($address);
79 $suburb = sanitise_input($suburb);
80 $postcode = sanitise_input($postcode);
81 $email = sanitise_input($email);
82 $phone = sanitise_input($phone);
83 $otherSkills = sanitise_input($otherSkills);
84
85 //check data input
86 $errMsg = "";
87 //checking job reference number - not empty & exactly 5 alphanumeric chars
88 if($refNo == ""){$errMsg .= "<p>You must enter job reference number.</p>";}
89 else if(!preg_match("/^[a-zA-Z0-9]{5}/", $refNo)){$errMsg .= "<p>Job reference number must be 5 alphanumeric characters.</p>";}
90 //checking firstname - not empty & exactly 40 alpha chars
91 if($firstName == ""){$errMsg .= "<p>You must enter your first name.</p>";}
92 else if(!preg_match("/^[a-zA-Z]{1,20}/", $firstName)){$errMsg .= "<p>Your name must only contain up to 20 alpha characters.</p>";}
93 //checking last name - last name is not empty and contains only alpha characters or a hyphen
94 if($familyName == ""){$errMsg .= "<p>You must enter your last name.</p>";}
95 else if(!preg_match("/^[a-zA-Z]+[a-zA-Z-]+[a-zA-Z]{1,20}/", $familyName)){$errMsg .= "<p>Your last name must only contain up to 20 alpha characters and hypens.</p>";}
96 //checking dob - dd/mm/yyyy format
97 if($dob == ""){$errMsg .= "<p>You must enter your date of birth.</p>";}
98 else if(!preg_match("/^[0-9]{2}[\/]{1}[0-9]{2}[\/]{1}[0-9]{4}$/", $dob)){$errMsg .= "<p>Your date of birth must in dd/mm/yyyy format.</p>";}
99 //checking age - between 15 and 80
100 $age = date_diff(date_create($dob), date_create('today'))->y;
101 if($age <= 15) {$errMsg .= "<p>Your age must be 15 or more.</p>";}
102 else if ($age >= 80) {$errMsg .= "<p>Your age must be 80 or less.</p>";}
103 //checking gender
104 if(strcmp("no_gender", $gender) == 0) {$errMsg .= "<p>You must enter your gender.</p>";}
105 //checking street address - max 40 chars
106 if($address == ""){$errMsg .= "<p>You must enter your street address.</p>";}
107 else if(!preg_match("/^[a-zA-Z0-9-_.]{1,40}/", $address)){$errMsg .= "<p>Street address must be maximum 40 characters long.</p>";}
108 //checking suburb/town - max 40 chars
109 if($suburb == ""){$errMsg .= "<p>You must enter your suburb/town.</p>";}
110 else if(!preg_match("/^[a-zA-Z0-9-_.]{1,40}/", $suburb)){$errMsg .= "<p>Suburb/town must be maximum 40 characters long.</p>";}
111 //no need to check state - it is optionbox with default NSW
112 $state = $state;
113 //checking postcode - exactly 4 digits and state integrity
114 if($postcode == ""){$errMsg .= "<p>You must enter your post code.</p>";}
115 else if(!preg_match("/^[0-9]{4}/", $postcode)){$errMsg .= "<p>Postcode must be 4 digits.</p>";}
116 else if(!check_post_code($postcode, $state)){$errMsg .= "<p>Your state and postcode must match.</p>";}
117 //checking email address - valid format
118 if($email == ""){$errMsg .= "<p>You must enter your e-mail.</p>";}
119 else if(!preg_match("/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,3}/", $email)){$errMsg .= "<p>You must enter a valid email address.</p>";}
120 //checking phone number - 8 to 12 digits
121 if($phone == ""){$errMsg .= "<p>You must enter your phone number.</p>";}
122 else if(!preg_match("/^[0-9]{8,12}/", $phone)){$errMsg .= "<p>Phone number must be 8 to 12 digits</p>";}
123 //checking other skills - not empty if check box selected
124 if($html || $css || $js || $php || $jquery){
125 if($otherSkills == ""){$errMsg .= "<p>You must enter some other skills.</p>";}
126 }
127
128 //echo error message if any
129 if($errMsg != "")
130 {
131 echo "<h4>Please check errors in application form : </h4>
132 <section class='error'>
133 $errMsg
134 </section>
135 <h4>Click <a href=apply.php>here</a> to go back the form.</h4>";
136 }
137 //if everything is okay, process to database
138 else
139 {
140 //connect to database
141 require_once ("settings.php");
142 $conn = @mysqli_connect($host,$user,$pwd,$sql_db);
143 //checks if connection successful
144 if(!$conn)
145 {
146 //shows error message
147 echo "<p class=\"wrong\">We are sorry, we are having technical problems right now.<br />
148 Plase try again later to apply. (Error Code: 511)</p>";
149 } else {
150 //if connection successful
151 $sql_table = "EOI";
152 //convert date to sql format add status
153 $dob_sql = substr($dob,6,4)."-".substr($dob,3,2)."-".substr($dob,0,2);
154 $status = "New";
155 //check table exists or not
156 $exist_query = "SELECT * FROM $sql_table";
157 $table_exist = mysqli_query($conn, $exist_query);
158 //add table if not exist
159 if(!$table_exist)
160 {
161 $add_table_query = "CREATE TABLE $sql_table (EOInumber INT(6) PRIMARY KEY AUTO_INCREMENT,JobRefNo VARCHAR(5),FirstName VARCHAR(40),LastName VARCHAR(40),DoB DATE,Gender VARCHAR(6),StreetAddr VARCHAR(40),SubTown VARCHAR(40),State VARCHAR(3),PostCode INT(6),Email VARCHAR(40),Phone VARCHAR(12),SkillHTML BIT,SkillCSS BIT,SkillJS BIT,SkillPHP BIT,SkillJQ BIT,SkillOther VARCHAR(180),Status VARCHAR(7))";
162
163 $add_table = mysqli_query($conn, $add_table_query);
164 $set_autonumber_query = "ALTER TABLE EOI AUTO_INCREMENT=10000";
165 $autonumbering = mysqli_query($conn, $set_autonumber_query);
166 if(!$autonumbering || !$autonumbering)
167 {
168 echo "<p class=\"wrong\">We are sorry, we are having technical problems right now.<br />
169 Plase try again later to apply. (Error Code: 611)</p>";
170 }
171 }
172
173 //insert query
174 $insert_query = "INSERT INTO $sql_table (JobRefNo, FirstName, LastName, DoB, Gender, StreetAddr, SubTown, State, PostCode, Email, Phone, SkillHTML, SkillCSS, SkillJS, SkillPHP, SkillJQ, SkillOther, Status) VALUES ('$refNo', '$firstName', '$familyName', DATE('$dob_sql'), '$gender', '$address', '$suburb', '$state', $postcode, '$email', '$phone', $html, $css, $js, $php, $jquery, '$otherSkills', '$status')";
175 $is_inserted = mysqli_query($conn, $insert_query);
176 if(!$is_inserted)
177 {
178 //display error if not successful
179 echo "<p class=\"wrong\">We are sorry, we are having technical problems right now.<br />
180 Plase try again later to apply. (Error Code: 711)</p>";
181 } else {
182 //get EOI number
183 $EOInumber_query = "SELECT LAST_INSERT_ID()";
184 $get_EOI = mysqli_query($conn, $EOInumber_query);
185 $EOInumber = mysqli_fetch_assoc($get_EOI)["LAST_INSERT_ID()"];
186 //display successfull message
187 echo "<p><h3>Dear $firstName,</h3><br />
188 We appriciate for your interest.<br />
189 We have received your application and you will be contacted soon.<br />
190 Your application number is :
191 <h3>$EOInumber</h3>
192 If you are intrested, please feel free to apply other jobs on the Job page.<br />
193 Wish you a good day without bugs.</p>
194 <p></p>
195 <p>Click <a href=jobs.php>here</a> to go back Jobs page.</p>";
196
197
198 }
199 }
200 mysqli_close($conn);
201 }
202 }
203
204 else
205 {
206 //Redirect to form, if process not triggered by a form submit
207 header("location: apply.php");
208 }
209 ?>
210
211</section>
212<?php include("footer.inc");?>
213</body>
214</html>