-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.php
More file actions
236 lines (207 loc) · 9.48 KB
/
Copy pathedit.php
File metadata and controls
236 lines (207 loc) · 9.48 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
session_start();
require_once("pdo.php");
require_once("util.php");
?>
<html>
<head>
<title>Kritika Datar</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7"
crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css"
integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r"
crossorigin="anonymous">
<link rel="stylesheet"
href="https://code.jquery.com/ui/1.12.1/themes/ui-lightness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.2.1.js"
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"
integrity="sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30="
crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<?php
if(!isset($_SESSION['name'])){
die("ACCESS DENIED");
return;
}
if(isset($_POST['cancel'])){
header("Location:index.php");
return;
}
if ( isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['email']) && isset($_POST['headline']) && isset($_POST['summary'])) {
// Data validation
$msg = validate();
if(is_string($msg)){
$_SESSION['error'] = $msg;
header("Location: edit.php?profile_id=".$_POST['profile_id']);
return;
}
$str = validateP();
if(is_string($str)){
$_SESSION['error'] = $str;
header("Location: edit.php?profile_id=".$_POST['profile_id']);
return;
}
$pstmt = $pdo->prepare('UPDATE Profile set
first_name= :fn, last_name= :ln, email= :em, headline= :he, summary= :su where profile_id= :pid');
$pstmt->execute(array(':fn' => $_POST['first_name'],
':ln' => $_POST['last_name'],
':em' => $_POST['email'],
':he' => $_POST['headline'],
':su' => $_POST['summary'],
':pid' => $_POST['profile_id']));
$var = $pdo->prepare('DELETE from position where profile_id= :pid');
$var->execute(array(':pid' => $_GET['profile_id']));
$var = $pdo->prepare('DELETE from education where profile_id= :pid');
$var->execute(array(':pid' => $_GET['profile_id']));
$rank = 1;
for($i=1;$i<=9;$i++){
if(isset($_POST['year'.$i])){
$pstmt = $pdo->prepare('INSERT INTO Position (profile_id, rank, year, description) VALUES ( :pid, :rank, :year, :desc)');
$pstmt->execute(array(
':pid' => $_GET['profile_id'],
':rank' => $rank,
':year' => $_POST['year'.$i],
':desc' => $_POST['desc'.$i])
);
}
if(isset($_POST['edu_year'.$i])){
$institution_id = false;
$statement = $pdo->prepare('SELECT institution_id from institution where name =:name');
$statement->execute(array(':name' => $_POST['edu_school'.$i]));
$row = $statement->fetch(PDO::FETCH_ASSOC);
if($row !== false){
$institution_id = $row['institution_id'];
}
else{
$pstmt = $pdo->prepare('INSERT INTO institution(name) VALUES (:name)');
$pstmt->execute(array(':name' => $_POST['edu_school'.$i]));
$institution_id = $pdo->lastInsertId();
}
$pstmt = $pdo->prepare('INSERT INTO education VALUES ( :pid, :institution_id, :rank, :year)');
$pstmt->execute(array(
':pid' => $_GET['profile_id'],
':rank' => $rank,
':year' => $_POST['edu_year'.$i],
':institution_id' => $institution_id)
);
}
$rank++;
}
$_SESSION['success'] = 'Profile updated';
header( 'Location: index.php' ) ;
return;
}
?>
<h1>Editing Profile for <?php echo $_SESSION['name']; ?> </h1>
<?php
// Flash pattern
if ( isset($_SESSION['error']) ) {
echo "<p style='color:red'>".$_SESSION['error']."</p>";
unset($_SESSION['error']);
}
$stmt = $pdo->prepare('SELECT * FROM profile where profile_id= :pi');
$stmt->execute(array( ':pi' => $_GET['profile_id']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
//if ( $stmt->rowCount() == true ) {
?>
<form method='post'>
<input type="text" value="<?php echo $_GET['profile_id'] ?>" name="profile_id" hidden>
<label>First Name: </label><input type="text" name="first_name" size="50" value="<?php echo $row['first_name'] ?>" id="idf_name"><br><br>
<label>Last Name: </label><input type="text" name="last_name" size="50" value="<?php echo $row['last_name'] ?>" id="idl_name"><br><br>
<label>Email: </label><input type="text" name="email" size="50" value="<?php echo $row['email'] ?>" id="idemail"><br><br>
<label>Headline: </label><br><input type="text" name="headline" size="80" value="<?php echo $row['headline'] ?>" id="idheadline"><br><br>
<label>Summary: </label><br><textarea rows="4" cols="50" id="idsummary" name="summary"><?php echo $row['summary'] ?></textarea><br><br>
<label>Education: </label><input type="submit" id="education" value="+">
<div id="educationFields">
<?php
$edupos = 0;
$ps = $pdo->prepare('SELECT * FROM education inner join institution on education.institution_id = institution.institution_id where profile_id= :pi');
$ps->execute(array( ':pi' => $_GET['profile_id']));
if($ps->rowCount() == true){
while($row1 = $ps->fetch(PDO::FETCH_ASSOC)){
$edupos++;
echo "<div id='edu".$edupos."'><p><input type='text' name='edu_year".$edupos."' value='".$row1['year']."'>
<input type='button' value='-' onclick='$(\"#edu".$edupos."\").remove(); return false;'></p>";
echo "<p>School: <input type='text' size='80' class='school' value='".$row1['name']."' name='edu_school".$edupos."'></p></div>";
}
}
?>
</div>
<label>Position: </label><input type="submit" id="position" value="+">
<div id="positionFields">
<?php
$pos = 0;
$ps = $pdo->prepare('SELECT * FROM position where profile_id= :pi');
$ps->execute(array( ':pi' => $_GET['profile_id']));
if($ps->rowCount() == true){
while($row1 = $ps->fetch(PDO::FETCH_ASSOC)){
$pos++;
echo "<div id='posit".$pos."'><p><input type='text' name='year".$pos."' value='".$row1['year']."'>
<input type='button' value='-' onclick='$(\"#posit".$pos."\").remove(); return false;'><br>";
echo "<textarea name='desc".$pos."' rows='5' cols='80'>".$row1['description']."</textarea></p></div>";
}
}
?>
</div>
<input type="submit" name="submit2" value="Save">
<input type="submit" name="cancel" value="Cancel">
</form>
<?php
//}
$pdo = null;
?>
<script>
count= <?=$pos ?> ;
$(document).ready(function(){
window.console && console.log("Document ready called");
$('#position').click(function(event){
event.preventDefault();
if(count>=9){
alert("Maximum positions reached");
return;
}
count++;
window.console && console.log("Adding position "+count);
$('#positionFields').append(
'<div id="posit'+count+'"> \
<p>Year: <input type="text" name="year'+count+'"> \
<input type="button" value="-" onclick="$(\'#posit'+count+'\').remove(); return false;"><br> \
<textarea name="desc'+count+'" rows="5" cols="80"></textarea></p></div>');
});
});
countEdu=0;
$(document).ready(function(){
window.console && console.log("Document ready called");
$('#education').click(function(event){
event.preventDefault();
if(countEdu>=9){
alert("Maximum positions reached");
return;
}
countEdu++;
window.console && console.log("Adding position "+countEdu);
$('#educationFields').append(
'<div id="edu'+countEdu+'"> \
<p>Year: <input type="text" name="edu_year'+countEdu+'"> \
<input type="button" value="-" onclick="$(\'#edu'+countEdu+'\').remove(); return false;"></p> \
<p>School: <input type="text" size="80" class="school" name="edu_school'+countEdu+'"></p></div>');
$('.school').autocomplete({
source: "school.php"
});
});
$('.school').autocomplete({
source: "school.php"
});
});
</script>
</div>
</body>
</html>