-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.php
313 lines (301 loc) · 8.11 KB
/
common.php
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<?php
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
/*
class Pdf extends Dompdf{
public function __construct(){
parent::__construct();
}
}
*/
class Db
{
public static function db_connect()
{
$host="localhost";
$db="parallel";
$username="root";
$pass="";
$dbh = null;
$dbh = new PDO("mysql:host=$host;dbname=$db", $username, $pass, array(
PDO::ATTR_PERSISTENT => true
));
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;
}
public static function db_conn()
{
$DBServer = "localhost";
$DBUser = "root";
$DBPass = "";
$DBName = "parallel";
$conn = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
if ($conn->connect_error) {
trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
}
return $conn;
}
}
class ApiData
{
public static function getData($method, $filter)
{
try
{
$wsdl = "https://webapp.placementpartner.com/ws/clients/?wsdl";
$username = 'parallel';
$password = 'parallel';
$client = new SoapClient($wsdl, array('cache_wsdl' => WSDL_CACHE_NONE) );
$session_id = $client->login($username, $password);
$php_filter = array(
//echo $filter;
);
return $client->$method($session_id, $php_filter);
}
catch(Exception $e)
{
//echo $message = $e->getMessage();
echo 'Error getting data, check your connection';
return 'error found';
}
}
public static function updateApiData($dbh, $vacancies)
{
try
{
for($x = 0; $x < count($vacancies); $x++){
if(empty(DB::select('select * from vacancies where vacancy_ref = :id', ['id' => $vacancies[$x]->vacancy_ref]))){
DB::insert('insert into vacancies (company_ref,vacancy_ref,job_title,salary_max,start_date,expiry_date)
values (?, ?,?, ?,?, ?)',
[$vacancies[$x]->company_ref,$vacancies[$x]->vacancy_ref,$vacancies[$x]->job_title,$vacancies[$x]->salary_max,$vacancies[$x]->start_date,$vacancies[$x]->expiry_date]);
}
}
return True;
}
catch(Exception $e)
{
//echo $message = $e->getMessage();
echo 'Error updating vacancy data, check your connection';
return 'error found';
}
}
}
class Clicks
{
public static function addClicks($dbh,$vacancy_ref)
{
try
{
$v=preg_split("#/#", $vacancy_ref);
$query = "insert into click_records(vacancy_ref) values(:VACANCY_REF)";
$sth = $dbh->prepare($query);
$sth->bindParam(':VACANCY_REF', $v[0], PDO::PARAM_STR);
$sth->execute();
return True;
}
catch(PDOException $e)
{
//echo $message = $e->getMessage();
echo 'Error adding click data, check your connection';
return 'error found';
}
}
public static function getClick($dbh, $ref)
{
try
{
$v=preg_split("#/#", $ref);
//$query = "SELECT click_date,count(vacancy_ref) as clicks FROM click_records where company_ref=:USR_ID group by click_date";
$query = "SELECT click_date,count(vacancy_ref) as clicks FROM click_records where company_ref=:USR_ID group by click_date";
$sth = $dbh->prepare($query);
$sth->bindParam(':USR_ID', $userid, PDO::PARAM_STR);
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
return $row;
}
catch(PDOException $e)
{
//echo $message = $e->getMessage();
echo 'Error getting click data, check your connection';
return 'error found';
}
}
public static function getClicks2($dbh, $ref)
{
try
{
$v=preg_split("#/#", $ref);
$query = "SELECT count(vacancy_ref) as clicks FROM click_records where vacancy_ref=:USR_ID";
$sth = $dbh->prepare($query);
$sth->bindParam(':USR_ID', $v[0], PDO::PARAM_STR);
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
return $row;
}
catch(PDOException $e)
{
echo 'Error getting data click2 , check your connection';
return 'error found';
}
}
}
class ExportData
{
public static function makePdf($dbh, $userid)
{
try
{
//$query = "SELECT click_date,count(vacancy_ref) as clicks FROM click_records where company_ref=:USR_ID group by click_date";
$query = "SELECT click_date,count(vacancy_ref) as clicks FROM click_records GROUP BY click_date";
$sth = $dbh->prepare($query);
//$sth->bindParam(':USR_ID', $userid, PDO::PARAM_STR);
$sth->execute();
return $sth->fetchAll();
}
catch(PDOException $e)
{
echo 'Error in make pdf, check your connection';
return 'error found';
}
}
public static function makeExcel($dbh, $userid)
{
try
{
$data=[];
$select =$dbh->query("SELECT company_ref,vacancy_ref,job_title,salary_max,start_date,expiry_date FROM vacancies");
while ( $aRow = $select->fetch_assoc() )
{
foreach($aRow as $fieldname => $fieldvalue) {
$row[$fieldname] = $fieldvalue;
}
array_push($data,$row);
}
return $data;
}
catch(PDOException $e)
{
echo 'Error in make excel, check your connection';
return 'error found';
}
}
}
class Register
{
public static function userValidate($dbh, $name,$email,$password,$password_confirmation)
{
try
{ $errors=[];
$flag=true;
$query = "select email from users where email='$email'";
$sth = $dbh->prepare($query);
$sth->execute();
$result = $sth->fetch();
if(!empty($result['email'])){
array_push($errors,'User email '.$result['email'].' already exist');
$flag=false;
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
array_push($errors,'$email is not a valid email address');
$flag=false;
}
if($password !=$password_confirmation){
array_push($errors,'Passwords not the same');
$flag=false;
}
if($flag==true){
return "passed";;
}else{
return $errors;
}
}
catch(Exception $e)
{
echo 'Error in validate, check your connection';
return 'error found';
}
}
public static function userRegister($dbh, $name,$email,$password)
{
try
{
$password=password_hash($password, PASSWORD_DEFAULT);
$query="insert into users(name,email, password) values(:NAME, :EMAIL, :PASSWORD)";
$sth = $dbh->prepare($query);
$sth->bindParam(':NAME', $name, PDO::PARAM_STR);
$sth->bindParam(':EMAIL', $email, PDO::PARAM_STR);
$sth->bindParam(':PASSWORD', $password, PDO::PARAM_STR);
$sth->execute();
return true;
}
catch(Exception $e)
{
echo 'Error in register, check your connection';
return 'error found';
}
}
}
class Login
{
public static function checkLogin($dbh, $username, $password)
{
try
{
$query = "SELECT * from users WHERE email =:EMAIL";
$sth = $dbh->prepare($query);
$sth->bindParam(':EMAIL', $username, PDO::PARAM_STR);
$sth->execute();
$row = $sth->fetch();
//return $row;
if (password_verify($password, $row['password']))
{
return $row['name'];
}else{
return false;
}
}
catch(PDOException $e)
{
echo 'Error in login check your connection';
return 'error found';
}
}
public static function checkLogin1($dbh, $username, $password)
{
$password = md5($password);
try
{
$query = "SELECT * FROM user WHERE (EMAIL=:EMAIL OR PHONE=:EMAIL) AND PASSWORD=:PASSWORD";
$sth = $dbh->prepare($query);
$sth->bindParam(':EMAIL', $username, PDO::PARAM_STR);
$sth->bindParam(':PASSWORD', $password, PDO::PARAM_STR);
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
return $row;
}
catch(PDOException $e)
{
echo 'Error in login1, check your connection';
return 'error found';
}
}
public static function updatePassword($dbh, $username, $password)
{
$password = md5($password);
try
{
$query = "update user set password=:PASSWORD WHERE (EMAIL=:EMAIL) AND STATUS = 1";
$sth = $dbh->prepare($query);
$sth->bindParam(':EMAIL', $username, PDO::PARAM_STR);
$sth->bindParam(':PASSWORD', $password, PDO::PARAM_STR);
$sth->execute();
return True;
}
catch(PDOException $e)
{
echo 'Error in update password, check your connection';
return 'error found';
}
}
}
?>