-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.php
More file actions
138 lines (126 loc) · 4.34 KB
/
Copy pathutil.php
File metadata and controls
138 lines (126 loc) · 4.34 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
<?php
function flashMessage() {
if (isset($_SESSION['error'])) {
echo '<p style="color:red">'.htmlentities($_SESSION['error']).'</p';
unset($_SESSION['error']);
}
if (isset($_SESSION['success'])) {
echo '<p style="color:green">'.htmlentities($_SESSION['success']).'</p';
unset($_SESSION['success']);
}
}
//validate post data
function validateProfile() {
if(strlen($_POST['First_name']) === 0 || strlen($_POST['Last_name']) === 0 ||
($_POST['Email']) === 0 || strlen($_POST['Headline']) === 0
|| strlen($_POST['Summary']) === 0) {
return "All fields are required";
}
elseif(strpos($_POST['Email'], '@') === false) {
return "Email must contain @";
}else{
return true;
}
}
//validate position data
function validatePos() {
for($i=1; $i<=5; $i++) {
if (!isset($_POST['Year'.$i])) continue;
if (!isset($_POST['desc'.$i])) continue;
$year = $_POST['Year'.$i];
$desc = $_POST['desc'.$i];
if(strlen($year) === 0 || strlen($desc) === 0) {
return "position cannot be empty";
}
elseif(!is_numeric($year)) {
return "Year must be numeric";;
}else{
return true;
}
}
}
//validate Education
function validateEdu(){
for ($i = 1; $i <= 3; $i++){
if(!isset($_POST['year'.$i])) continue;
if(!isset($_POST['sch'.$i])) continue;
$year = $_POST['year'.$i];
$school = $_POST['sch'.$i];
if(strlen($year) <= 0 || strlen($school) <= 0) {
return "education field cannot be empty";
}elseif(!is_numeric($year)){
return "Year must numeric";
}else{
return true;
}
}
}
//insert into education
function insertEdu($pdo, $profile_id){
$rank = 1;
for($i = 1; $i <= 3; $i++){
if(!isset($_POST['edu_year'.$i])) continue;
if(!isset($_POST['edu_school'.$i])) continue;
$year = $_POST['edu_year'.$i];
$school = $_POST['edu_school'.$i];
//lookup institution if it is there
$institution_id = false;
$stmt = $pdo->prepare("SELECT institution_id FROM institution WHERE name = :name");
$stmt->execute(array(':name' => $school));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row !== false) {
$institution_id = $row['institution_id'];
}
//if institution is not there insert it
if($institution_id === false){
$stmt = $pdo->prepare("INSERT INTO institution (name) VALUES (:name)");
$stmt->execute(array(':name' => $school));
$institution_id = $pdo->lastInsertId();
}
//insert into education
$stmt = $pdo->prepare("INSERT INTO education (profile_id, institution_id, rank, year)
VALUES (:pid, :intid, :rank, :year)");
$stmt->execute(array(':pid' => $profile_id,
':intid' => $institution_id,
':rank' => $rank,
':year' => $year));
$rank++;
}
}
//insert positions
function insertPos($pdo, $profile_id) {
$rank = 1;
for($i=1; $i<=3; $i++) {
if(!isset($_POST['year'.$i])) continue;
if(!isset($_POST['desc'.$i])) continue;
$year = $_POST['year'.$i];
$desc = $_POST['desc'.$i];
$stmt = $pdo->prepare("INSERT INTO position (profile_id, rank, year,
description) VALUES (:prof, :rank, :year, :desc)");
$stmt->execute(array(':prof' => $profile_id,
':rank' => $rank,
':year' => $year,
':desc' => $desc));
$rank++;
}
}
//load education data
function loadEdu($pdo, $profile_id){
$stmt = $pdo->prepare("SELECT year, name FROM education JOIN institution
ON education.institution_id = institution.institution_id
WHERE profile_id = :poff ORDER BY rank");
$stmt->execute(array(':poff' => $profile_id));
$educations = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $educations;
}
//Load position data
function loadPos($pdo, $profile_id) {
$stmt = $pdo->prepare('SELECT * FROM position WHERE profile_id = :fff
ORDER BY rank');
$stmt->execute(array(':fff' => $profile_id));
$positions = array();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$positions[] = $row;
}
return $positions;
}