-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemp_controller.php
More file actions
221 lines (207 loc) · 7.37 KB
/
Copy pathemp_controller.php
File metadata and controls
221 lines (207 loc) · 7.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
session_start();
require_once("includes/db_connect.php");
if (isset($_GET['action'])&& $_GET['action']!='') {
$action=$_GET['action'];
} else {
'';
}
switch ($action) {
case"add":
add_data();
break;
case"login":
emp_login();
break;
case"edit":
edit_data();
break;
case"delete":
delete_data();
break;
}
function add_data()
{
global $connection;
if (isset($_POST['signup'])) {
$name="";
$company_name="";
$wesite_link="";
$phone="";
$email="";
$password="";
$valid=true;
if ($_POST['Name']=="") {
$_SESSION['Name']= "fname field is required";
$valid=false;
header("Location:emp_signup.php");
} elseif (preg_match("/^[a-zA-Z-']*$/", $_POST['Name'])) {
$name=$_POST['Name'];
} else {
$_SESSION['Name']="fname must contains only letters";
$valid=false;
header("Location:emp_signup.php");
}
if ($_POST['Company_name']=="") {
$_SESSION['Company Name']= "fname field is required";
$valid=false;
header("Location:emp_signup.php");
} else {
$company_name=$_POST['Company_name'];
}
if ($_POST['website_link']=="") {
$_SESSION['Share website Link']= "fname field is required";
$valid=false;
header("Location:emp_signup.php");
} else {
$website_link=$_POST['website_link'];
}
if ($_POST['Phone']=="") {
$_SESSION['Phone']="phone field is required";
$valid=false;
} elseif (strlen($_POST['Phone'])==11) {
$phone=$_POST['Phone'];
$sql="SELECT Phone FROM employees WHERE Phone='$phone'";
$res=mysqli_query($connection, $sql);
$row1=mysqli_num_rows($res);
if ($row1>0) {
$_SESSION['Phone']= "This $phone is already exists";
}
} else {
$_SESSION['Phone']="phone must contains 11 integers";
$valid=false;
}
if ($_POST['Email']=="") {
$_SESSION['Email Address']= "email field is required";
$valid=false;
} elseif (filter_var($_POST['Email'], FILTER_VALIDATE_EMAIL)) {
$email=$_POST['Email'];
$sql="SELECT Email FROM employees WHERE Email='$email'";
$data=mysqli_query($connection, $sql);
$row=mysqli_num_rows($data);
if ($row>0) {
$_SESSION['Email Address']= "This $email is already exists";
$valid=false;
}
$email=$_POST['Email'];
$sql="SELECT email FROM job_seekers WHERE email='$email'";
$data=mysqli_query($connection, $sql);
$row=mysqli_num_rows($data);
if ($row>0) {
$_SESSION['Email Address']= "you already signup as jobseeker with this Email $email choose different";
$valid=false;
header("Location:emp_signup.php");
}
} else {
$_SESSION['Email Address']="Enter Valid Email";
$valid=false;
}
if ($_POST['Password']=="") {
$_SESSION['Password']="password field is required";
$valid=false;
} elseif (strlen($_POST['Password'])>4) {
$password=$_POST['Password'];
// echo $password;
} else {
$_SESSION['Password']= "password at least 5 digits";
$valid=false;
}
$logo=$_FILES['logo'];
$logoname=$logo['name'];
move_uploaded_file($logo['tmp_name'], 'images/'.$logoname);
if ($valid) {
$query1="INSERT INTO `employees`( `Name`, `Company_name`,`website_link`,`Phone`,`Email`,`Password`,`Logo`) VALUES('$name','$company_name','$website_link','$phone','$email','$password','$logoname')";
global $connection;
$result= mysqli_query($connection, $query1);
if ($result) {
$_SESSION['successmsg']="signup successfully";
header("location:emp_login.php");
} else {
$_SESSION['errormsg']="data not insert";
header("Location:emp_signup.php");
}
}
}
}
function emp_login()
{
global $connection;
if (isset($_POST['login'])) {
$EmailAddress="";
$Password="";
$valid=true;
if ($_POST['Email']=="") {
$_SESSION['EmailAddress']= "email field is required";
$valid=false;
} elseif (filter_var($_POST['Email'], FILTER_VALIDATE_EMAIL)) {
$EmailAddress=$_POST['Email'];
} else {
$_SESSION['EmailAddressl']="Enter Valid Email";
$valid=false;
}
if ($_POST['Password']=="") {
$_SESSION['Password']="password field is required";
$valid=false;
} elseif (strlen($_POST['Password'])>4) {
$Password=$_POST['Password'];
// echo $password;
} else {
$_SESSION['Password']= "password at least 5 digits";
$valid=false;
}
if ($valid) {
$sql="SELECT e_id,Name FROM employees WHERE Email='$EmailAddress' && Password='$Password'";
$data=mysqli_query($connection, $sql);
$row=mysqli_num_rows($data);
if ($row>0) {
$arr=mysqli_fetch_assoc($data);
$_SESSION['emp_id']=$arr['e_id'];
$_SESSION['emp_name']=$arr['Name'];
header("Location:index.php");
} else {
$_SESSION['errormsg']="password or email wrong";
header("Location:emp_login.php");
}
}
}
}
function edit_data()
{
if (isset($_POST['edit'])) {
$id=$_POST['e_id'];
$name=$_POST['name'];
$company_name=$_POST['company_name'];
$website_link=$_POST['website_link'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$password=$_POST['password'];
$image=$_FILES['logo'];
$query="UPDATE employees SET name='$name',company_name='$company_name',website_link='$website_link',phone='$phone',email='$email',password='$password' WHERE e_id='$id'";
if ($image['name']!="") {
global $connection;
//new upload img name
$imagename=$image['name'];
$sql2="SELECT `Logo` FROM employees WHERE e_id='$id'";
$data2=mysqli_query($connection, $sql2);
$arr=mysqli_fetch_assoc($data2);
//old table img name
$imagename2=$arr['Logo'];
unlink('images/'.$imagename2);
move_uploaded_file($image['tmp_name'], 'images/'.$imagename);
$query="UPDATE employees SET name='$name',company_name='$company_name',website_link='$website_link',phone='$phone',email='$email',password='$password',Logo='$imagename' WHERE e_id='$id'";
}
global $connection;
$result= mysqli_query($connection, $query);
if ($result) {
header("Location:index.php");
$_SESSION['successmsg']="successfully updated";
} else {
header("Location:emp_edit.php");
$_SESSION['errormsg']="not updated";
}
}
}
function delete_data()
{
echo "delete data function";
}