/
newcontact3.php
executable file
·258 lines (187 loc) · 9.12 KB
/
newcontact3.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
<?php
require("controllers/LoginController.php");
$login = new LoginController();
$login->verifyLogin();
if ($login->login == 0) {
header("Location: login.php");
}
require("models/Contact.php");
ob_start();
require("phoneEmailAddress.php");
$phoneEmailAddress = ob_get_contents();
ob_end_clean();
require("controllers/PersonController.php");
$updateForm = null;
// http://localhost/contact_v1.1/newcontact.php?id=1&action=update
if( isset($_GET['action']) && $_GET['action'] === 'update' ) {
$action = "update";
$id = (int)$_GET['id'];
$contact = new PersonPDO();
$updateForm = $contact->getPersonById($id);
} else {
$action = "create";
}
$error = NULL;
if( isset($_GET['validate']) && ($_GET['validate'] == "error") ) {
$error = 1;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/styles.css">
<!--<link rel="stylesheet" type="text/css" href="css/main.css"/>-->
<title>Add a New Contact</title>
</head>
<body>
<div class="container" >
<div class="header"><!-- Start Header -->
<?php include("includes/header.php"); ?>
</div><!-- end .header -->
<div class="content">
<div class="row">
<section class="col-xs-12">
<?php if($action === 'update'):?>
<div style="margin-bottom: 9px">
<a href="listcontacts.php">List</a> >> <a href="profile.php?id=<?php echo $id; ?>" >Profile</a> >> <b>Update</b>
</div>
<div style="clear: both"></div>
<?php
$id = NULL;
if( isset($_GET['id']) )
$id = $_GET['id'];
if( isset($_POST['id']) )
$id = $_POST['id'];
$contact = new Contact($id);
$contact->getContactById();
?>
<!-- div 1 Start Avatar -->
<?php require("avatar.php"); ?>
<!-- End Avatar -->
<div style="float: left; width: 200px">
<?php require("name_dob.php"); ?>
</div>
<?php endif; ?>
<?php if($action == "update"): ?>
<h3 style='float: left'>Update Contact</h3>
<span style='float: right'>
<a id="delete" href="controllers/PersonController.php?action=delete&id=<?php echo $id; ?>">delete</a>
</span>
<?php endif; ?>
<?php if($action == "create"): ?>
<h3>Create a New Contact</h3>
<?php endif; ?>
<div style="<?php if($action === 'update') echo "float: right" ?>">
<form action="controllers/PersonController.php?action=<?php
if($action == "update") {
echo "update";
}
if($action == "create") {
echo "create";
}
?>" method="post" name="addContact">
<div class="form-group">
<label class="col-sm-2 control-label" for="lastName">Last<span id="error"><?php if($error == 1) {echo "*";} ?></span></label>
<div class="col-sm-10">
<input name="lastName" type="text" class="form-control" id="lastName" value="<?php if($action == "update") echo $updateForm->last_name; ?>" /><br />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="firstName">First<span id="error"><?php if($error == 1) {echo "*";} ?></span></label>
<div class="col-sm-10">
<input name="firstName" type="text" class="form-control" id="firstName" value="<?php if($action == "update") echo $updateForm->first_name; ?>" /><br />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="middleName">Middle<span id="error"><?php if($error == 1) {echo "*";} ?></span></label>
<div class="col-sm-10">
<input name="middleName" type="text" class="form-control" id="middleName" value="<?php if($action == "update") echo $updateForm->middle_name; ?>" /><br />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="aliasName">Alias<span id="error"><?php if($error == 1) {echo "*";} ?></span></label>
<div class="col-sm-10">
<input name="aliasName" type="text" class="form-control" id="aliasName" value="<?php if($action == "update") echo $updateForm->alias_name; ?>" /><br />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="birthMonth" >DOB</label>
<div class="col-sm-10">
<select name="birthMonth" id="birthMonth" size="1">
<?php if($action == "update"): ?>
<option value="<?php echo $updateForm->birth_month; ?>"><?php echo $contact->getMonthNameByNumber($updateForm->birth_month); ?></option>
<?php endif; ?>
<?php foreach($months as $value => $month): ?>
<option value="<?php echo $value; ?>"><?php echo $month; ?></option>
<?php endforeach; ?>
</select>
<select name="birthDay" id="birthDay" size="1">
<?php if($action == "update"): ?>
<option value="<?php echo $updateForm->birth_day; ?>"><?php echo $updateForm->birth_day; ?></option>
<?php endif; ?>
<option value="0"> </option>
<?php for($i = 1; $i <=31; $i++): ?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php endfor; ?>
</select>
<select name="birthYear" id="year" size="1">
<?php if($action == "update"): ?>
<option value="<?php echo $updateForm->birth_year; ?>"><?php echo $updateForm->birth_year; ?></option>
<?php endif; ?>
<option value="0"> </option>
<?php for ($y = date('Y'); $y >= date('Y') - 110; $y--): ?>
<option value="<?php echo $y; ?>"><?php echo $y; ?></option>
<?php endfor; ?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="note">Notes</label>
<div class="col-sm-10">
<textarea class="form-control" id="note" ><?php
if($action == 'update') {
echo $updateForm->note;
}
?></textarea>
</div>
</div>
<div class="form-block" style="margin-top: 10px; float: right">
<input type="hidden" name="personId" value="<?php echo $updateForm->id ?>" />
<input type="submit" name="addNewContact" value="<?php
if($action == "create") {
echo "Create";
}elseif($action == "update") {
echo "Update";
}
?>"
id="<?php
if($action == "create") {
echo "create";
}elseif($action == "update") {
echo "update";
}
?>"
/>
</div>
<span style="float: left" id="error"><?php if($error == 1) {echo "* All contacts must have at least one name or alias.";} ?></span>
<div style="clear: both"></div>
</form>
</div>
<div style="clear: both"></div>
<?php if($action === 'update') echo "<hr />" . $phoneEmailAddress; ?>
</section>
</div>
</div><!-- end .content -->
<?php
include("includes/footer.php");
?>
</div><!-- end .container -->
<script src="js/jquery-1.12.0.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>