forked from OlivierCrn/CV_TEK
-
Notifications
You must be signed in to change notification settings - Fork 1
/
function.php
259 lines (235 loc) · 10.7 KB
/
function.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
<?php
//FUNCTIONS
//--FUNCTION THAT SUPRESSES ACCENTS
function removeAccents($str) {
$a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ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', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o', 'Α', 'α', 'Ε', 'ε', 'Ο', 'ο', 'Ω', 'ω', 'Ι', 'ι', 'ι', 'ι', 'Υ', 'υ', 'υ', 'υ', 'Η', 'η');
return str_replace($a, $b, $str);
}
//--FONCTION THAT CLEANS THE INPUT
function cleanInput($str) {
//if the users types spaces by mistakes
$str=trim($str);
//if the user types in accents, this removes it
$str=removeAccents($str);
//if the user types in small letters it turns them into capitals
$str=strtoupper($str);
return $str;
}
// FUNCTION FOR THE CANDIDATES DISPLAY WHETHER STANDARD OR SORTED (THE SEARCH FUNCTION DOES NOT CALL ON THIS FUNCTION)
function affichage($candidats)
{
print PHP_EOL;
print PHP_EOL;
foreach($candidats as $key => $value)
{
foreach($value as $key1 => $value1)
{
if($key1 == "SKILLS")
{
print($key1.":") .PHP_EOL;
for($i = 0; $i < count($value1); $i++)
{
print($value1[$i]." | ");
}
}
else
{
print($key1);
print(": ");
print($value1);
print(" ") .PHP_EOL;
}
}
print PHP_EOL;
print PHP_EOL;
print PHP_EOL;
}
}
//--FUNCTION THAT EXTRACT THE CSV FILE
function csv_to_array($filename='hrdata.csv', $delimiter=';')
{
$nul= "NULL";
if(!file_exists($filename) || !is_readable($filename)) //Check if the file exist and is readable
{
return FALSE;
}
$candidats = array();
if (($handle = fopen($filename, 'r')) !== FALSE) // Open the file
{
$firstline=true;
while (($information = fgetcsv($handle, 1000, $delimiter)) !== FALSE) // Allows the program to go through all the csv file until the end.
{
if ($firstline==false) {
$temp=array();
$temps=array();
$temp["ID"]= $information[0];
$temp["LASTNAME"] = strtoupper(removeAccents($information[1]));
$temp["FIRSTNAME"] = strtoupper(removeAccents($information[2]));
$temp["AGE"] = age($information[4]);
$temp["BIRTHDATE"] = trim($information[4]);
$temp["ADRESS1"] = strtoupper(removeAccents($information[5]));
$temp["ADRESS2"]= strtoupper(removeAccents($information[6]));
$temp["POSTCODE"]=strtoupper(removeAccents($information[7]));
$temp["TOWN"]=strtoupper(removeAccents($information[8]));
$temp["MOBILE"] = trim($information[9]);
$temp["PHONE"] =trim($information[10]);
$temp["MAIL"] = strtoupper(removeAccents($information[11]));
$temp["PROFILE"] = strtoupper(removeAccents($information[12]));
$count_skills=0;
for($i=0; $i<10; $i++) // Set all "skills" in the same array
{
if ($information[$i+13] !=$nul)
{
$count_skills++;
$temps[]=strtoupper(removeAccents($information[$i+13]));
}
}
$temp["SKILLS"] = $temps;
$temp["WEBSITE"] = strtoupper(removeAccents($information[23]));
if ($count_skills>=5 && $temp["LASTNAME"]!=$nul && $temp["FIRSTNAME"]!=$nul && $temp["BIRTHDATE"]!=$nul && $temp["MOBILE"]!=$nul && $temp["MAIL"]!=$nul && $temp["PROFILE"]!=$nul)
{
$candidats[] = $temp; //Set the $temp values at the last line of $candidats before cycle through until done.
}
} else {
$firstline=false;
}
}
fclose($handle);
}
print_r($candidats);
return $candidats;
}
//--FUNCTION THAT CALCULATES THE AGE BASED ON THE BIRTHDATE INPUT
function age ($DOB)
{
$DOB = str_replace("/", "-", $DOB); // replaces / by - so it's readable in PHP
$today = date("d-m-Y");
$cal = strtotime($today) - strtotime($DOB); //turns the date into a readable string for the program
$age = intval($cal/(60*60*24*365.25)); //intval rounds up the age then the years difference ($cal) is divided by the seconds, minutes, hours and days - days are 365.25 to take in the leap years-
return $age;
}
function write ($candidats)
{
$temp = "";
$delimiter = ";";
$today = date("d-m-Y");
rename('hrdata.csv' , 'hrdata'.$today.'.csv'); // to add today's date to the file name so it can be saved in a new file.
$handle = fopen('hrdata.csv', 'w');
$headers= array();
$headers[]="ID";
$headers[]="LASTNAME";
$headers[]="FIRSTNAME";
$headers[]="AGE";
$headers[]="BIRTHDATE";
$headers[]="ADRESS1";
$headers[]="ADRESS2";
$headers[]="POSTCODE";
$headers[]="TOWN";
$headers[]="MOBILE";
$headers[]="PHONE";
$headers[]="MAIL";
$headers[]="PROFILE";
for($i = 0; $i < 10 ; $i++ )
{
$headers[13+$i]="SKILLS ".$i;
}
$headers[] = "WEBSITE";
fputcsv($handle , $headers , $delimiter);
foreach($candidats as $key => $value)
{
// The program checks if it's the first line to insert keys.
foreach($value as $key1 => $value1)
{
if(empty($value1))
{
$value[$key1] = "NULL";
}
}
$temp=array();
$temp["ID"]= $value["ID"];
$temp["LASTNAME"] = $value["LASTNAME"];
$temp["FIRSTNAME"] = $value["FIRSTNAME"];
$temp["AGE"] = $value["AGE"];
$temp["BIRTHDATE"] = $value["BIRTHDATE"];
$temp["ADRESS1"] = $value["ADRESS1"];
$temp["ADRESS2"]= $value["ADRESS2"];
$temp["POSTCODE"]=$value["POSTCODE"];
$temp["TOWN"]=$value["TOWN"];
$temp["MOBILE"] = $value["MOBILE"];
$temp["PHONE"] =$value["PHONE"];
$temp["MAIL"] = $value["MAIL"];
$temp["PROFILE"] =$value["PROFILE"];
// The program divides the array "SKILLS" into 10 keys to become writable in csv file.
for($i = 0; $i < 10; $i++)
{
if(empty($value["SKILLS"][$i]))
{
$temp["SKILL $i"] = "Null";
}
else
{
$temp["SKILLS $i"] = $value["SKILLS"][$i];
}
}
$temp["WEBSITE"] = $value["WEBSITE"];
$value = $temp;
fputcsv($handle , $value , $delimiter);
}
fclose($handle);
return;
}
function open_cv($candidats, $traduction)
{
print($traduction["ADD19"]);
$cv = "";
$YesNo = readline();
$YesNo = strtoupper($YesNo);
if($YesNo[0] == "Y")
{
$cv = readline($traduction["ADD20"]);
if (file_exists(realpath('faits/'.$cv .'.pdf')))
{
exec(realpath('faits/'.$cv .'.pdf')); // opens a file with the appropriate software
}
else if (file_exists(realpath('faits/'.$cv .'.docx')))
{
exec(realpath('faits/'.$cv .'.docx'));
} else
{
print($traduction["ADD21"]);
}
} else if ($YesNo != "Y" && $YesNo != "N")
{
print "ADD26";
$YesNo = readline();
$YesNo = strtoupper($YesNo);
open_cv($candidats, $traduction) ;
}
print($traduction["ADD22"]);
$YesNo = readline();
$YesNo = strtoupper($YesNo);
if($YesNo[0] == "Y")
{
if(empty($cv))
{
$cv = readline($traduction["ADD20"]);
}
exec('"C:/Program Files (x86)/Mozilla Firefox/firefox.exe" "'.$candidats[$cv]["WEBSITE"] .'"');
}
}
function fullcheckdate($DOB)
{
$day = substr($DOB, 0, 2);
$day = intval($day);
$month = substr($DOB, 3, 2);
$month = intval($month);
$year = substr($DOB, 6, 4);
$year = intval($year);
if($year < 1920)
{
$year = -12.3;
}
return checkdate($month, $day, $year);
}
?>