This repository has been archived by the owner on Sep 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
493 lines (431 loc) · 20.2 KB
/
register.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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
<?php
/*
UserCake Version: 1.4
http://usercake.com
Developed by: Adam Davis
*/
require_once("models/config.php");
require_once("libs/recaptchalib.php");
//Prevent the user visiting the logged in page if he/she is already logged in
if(isUserLoggedIn()) { header("Location: account.php"); die(); }
?>
<?php
/*
Below is a very simple example of how to process a new user.
Some simple validation (ideally more is needed).
The first goal is to check for empty / null data, to reduce workload here
we let the user class perform it's own internal checks, just in case they are missed.
*/
//Forms posted
$postback = !empty($_POST);
$v = NULL;
$errors_global = array();
$errors_specific = array();
$warning_messages = array();
$success = false;
if($postback)
{
/*$errors = array();
$email = trim($_POST["email"]);
$username = trim($_POST["username"]);
$password = trim($_POST["password"]);
$confirm_pass = trim($_POST["passwordc"]);*/
// Sanitize inputs
$s = new FormSanitizer();
$s->sanitize($_POST);
// Validate inputs
$v = new Validator($_POST);
foreach ($_POST as $key => $value) {
$v->validate($value, $key);
}
if (!array_key_exists('group_id', $_POST))
$v->set_specific_error('group_id',lang("REQUIRED_FIELD"));
if (!array_key_exists('year', $_POST))
$v->set_specific_error('year',lang("GENERIC_FORM_FIELD_ERROR"));
if (!array_key_exists('signature_deed', $_POST))
$v->set_specific_error('signature_deed', lang("ACCOUNT_SIGNATURE_MISSING", array("το καταστατικό του Συλλόγου Αποφοίτων")));
if (!array_key_exists('signature_privacypolicy', $_POST))
$v->set_specific_error('signature_privacypolicy', lang("ACCOUNT_SIGNATURE_MISSING", array("την πολιτική απορρήτου")));
if (!array_key_exists('signature_termsofuse', $_POST))
$v->set_specific_error('signature_termsofuse', lang("ACCOUNT_SIGNATURE_MISSING", array("τους όρους χρήσης της υπηρεσίας")));
// Perform validation on the CAPTCHA before everything else
$resp = recaptcha_check_answer ($recaptcha_privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$v->set_global_error(lang("CAPTCHA_ERROR"));
}
// If no validation errors present
if(count($v->errors_global) + count($v->errors_specific) == 0)
{
$success = true;
//Construct a user object
$user = new User($_POST['username'], $_POST['password'], $_POST['email']);
//Attempt to add the user to the database, carry out finishing tasks like emailing the user (if required)
if($user->userCakeAddUser())
{
if ($user->mail_failure) {
array_push($warning_messages, lang("ACTIVATION_MAIL_NOT_SENT", array($_POST['username'], $_POST['email'])));
}
// Retrieve the User_ID from the database
$userdetails = fetchUserDetails($user->clean_username);
if (!empty($userdetails)) {
$contact = new Contact(true, $userdetails['User_ID'], $_POST);
$personal = new Personal(true, $userdetails['User_ID'], $_POST);
$status = new Status(true, $userdetails['User_ID'], $_POST);
if ($_POST['group_id'] == 1 || $_POST['group_id'] == 2)
$studies = new Studies_Undergr(true, $userdetails['User_ID'], $_POST);
$inserted = array();
$inserted['contact'] = $contact->insert();
$inserted['personal'] = $personal->insert();
$inserted['status'] = $status->insert();
if ($_POST['group_id'] == 1 || $_POST['group_id'] == 2)
$inserted['studies'] = $studies->insert();
// TODO Failure handling here is non-existent
// Need to better handle the case when database insertion partially fails
$success = true;
foreach ($inserted as $key => $value) {
if ($value == false)
array_push($warning_messages, lang("COULD_NOT_SAVE_IN_DATABASE", array($key)));
}
}
}
}
}
// Form utility functions
function error_exists($key) {
global $postback, $v;
return ($postback && array_key_exists($key, $v->errors_specific));
}
function label($key, $label) {
if (!empty($label)) {
$class = (Validator::$check_required[$key] ? 'required' : 'optional');
echo "<label for=\"$key\" class=\"$class field\">$label:</label>";
}
else
{
echo "<label for=\"$key\" class=\"field\"> </label>";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Εγγραφή μέλους - <?php echo $websiteName; ?></title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="form.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php include 'includes/header-nav.php'; ?>
<div id="wrapper">
<div id="secondary-navi">
<?php include 'includes/secondary-nav.php'; ?>
</div>
<div id="content" >
<div id="main">
<h1>Εγγραφή Νέου Μέλους</h1>
<?php
if($postback)
{
if(!$success)
{
?>
<div id="errors">
<p>Παρακαλούμε διορθώστε τα παρακάτω σφάλματα που εντοπίστηκαν στην υποβολή σας.</p>
<ul>
<?php
foreach ($v->errors_global as $error) {
echo "<li>$error</li>";
}
?>
</ul>
</div>
<?php
} else {
$message = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE1");
if($emailActivation)
{
$message .= "\n\n" . lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE2");
}
?>
<div id="success">
<p><?php echo $message ?></p>
</div>
<a href="http://alumniclub.di.uoa.gr/">Επιστροφή στην Αρχική Σελίδα</a>
<?php
if (count($warning_messages) > 0) {
?>
<div id="warning">
<p>Προσοχή!</p>
<ul>
<?php
foreach ($warning_messages as $warning) {
echo "<li>$warning</li>";
}
?>
</ul>
</div>
<? } } }?>
<?php if (!$success) { ?>
<div id="regbox">
<form name="newUser" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<fieldset id="membertype">
<legend>Τύπος Μέλους</legend>
<p>Παρακαλώ να με εγγράψετε στο Σύλλογο Αποφοίτων του Τμήματος Πληροφορικής και Τηλεπικοινωνιών ως:</p>
<div>
<ol>
<li>
<input type="radio" name="group_id" id="membertype-regular" value="1" <?php if ($postback && $_POST['group_id'] == 1) echo 'checked="checked"';?>/>
<label class="boxradio" for="membertype-regular"><strong>Τακτικό Μέλος</strong>
<span class="foldable">Δηλώνω ότι είμαι απόφοιτος του προπτυχιακού προγράμματος σπουδών του Τμήματος Πληροφορικής και Τηλεπικοινωνιών ΕΚΠΑ και έχω αποκτήσει το πτυχίο μου ή έχω καταθέσει αίτηση ορκομωσίας.</span>
</label>
</li>
<li>
<input type="radio" name="group_id" id="membertype-junior" value="2" <?php if ($postback && $_POST['group_id'] == 2) echo 'checked="checked"';?>/>
<label class="boxradio" for="membertype-junior"><strong>Δόκιμο μέλος</strong>
<span class="foldable">Δηλώνω ότι είμαι εν ενεργεία προπτυχιακός φοιτητής του Τμήματος Πληροφορικής και Τηλεπικοινωνιών ΕΚΠΑ.</span>
</label>
</li>
<li>
<input type="radio" name="group_id" id="membertype-social" value="3" <?php if ($postback && $_POST['group_id'] == 3) echo 'checked="checked"';?>/>
<label class="boxradio" for="membertype-social"><strong>Κοινωνικό Μέλος</strong>
<span class="foldable">Δηλώνω ότι είμαι φοιτητής ή απόφοιτος μεταπτυχιακού προγράμματος σπουδών ή υποψήφιος διδάκτορας του Τμήματος Πληροφορικής και Τηλεπικοινωνιών ΕΚΠΑ ή σπούδασα κατά το παρελθόν στο προπτυχιακό πρόγραμμα σπουδών του Τμήματος Πληροφορικής και Τηλεπικοινωνιών ΕΚΠΑ χωρίς να αποφοιτήσω από αυτό.</span>
</label>
</li>
</ol>
<?php if (error_exists('group_id')) { ?><div class="field_error"><?php echo $v->errors_specific['group_id'];?></div><?php } ?>
<input type="hidden" name="year" value="<?php
// TODO We could use the registration date from the user table instead of a hidden field
echo (time() < $year_change_date ?
date("Y") :
(int)date("Y") + 1
);
?>"/>
</div>
</fieldset>
<fieldset id="account">
<legend>Στοιχεία Λογαριασμού</legend>
<div>
<?php label('username', "Username")?>
<input type="text" name="username" value="<?php if ($postback) echo $_POST['username'];?>"/>
<?php if (error_exists('username')) { ?><div class="field_error"><?php echo $v->errors_specific['username'];?></div><?php } ?>
</div>
<div>
<?php label('password', "Password")?>
<input type="password" name="password" value="<?php if ($postback) echo $_POST['password'];?>"/>
<?php if (error_exists('password')) { ?><div class="field_error"><?php echo $v->errors_specific['password'];?></div><?php } ?>
</div>
<div>
<?php label('password', "Password (επιβεβαίωση)")?>
<input type="password" name="password_c" value="<?php if ($postback) echo $_POST['password_c'];?>"/>
<?php if (error_exists('password_c')) { ?><div class="field_error"><?php echo $v->errors_specific['password_c'];?></div><?php } ?>
</div>
<div>
<?php label('email', "Email")?>
<input type="text" name="email" value="<?php if ($postback) echo $_POST['email'];?>"/>
<?php if (error_exists('email')) { ?><div class="field_error"><?php echo $v->errors_specific['email'];?></div><?php } ?>
</div>
</fieldset>
<fieldset id="personal">
<legend>Προσωπικά Στοιχεία</legend>
<div>
<?php label('lastname', "Επώνυμο")?>
<input type="text" name="lastname" value="<?php if ($postback) echo $_POST['lastname'];?>"/>
<?php if (error_exists('lastname')) { ?><div class="field_error"><?php echo $v->errors_specific['lastname'];?></div><?php } ?>
</div>
<div>
<?php label('firstname', "Όνομα")?>
<input type="text" name="firstname" value="<?php if ($postback) echo $_POST['firstname'];?>"/>
<?php if (error_exists('firstname')) { ?><div class="field_error"><?php echo $v->errors_specific['firstname'];?></div><?php } ?>
</div>
<div>
<?php label('fathersname', "Όνομα Πατέρα")?>
<input type="text" name="fathersname" value="<?php if ($postback) echo $_POST['fathersname'];?>"/>
<?php if (error_exists('fathersname')) { ?><div class="field_error"><?php echo $v->errors_specific['fathersname'];?></div><?php } ?>
</div>
<div>
<?php label('dobdate', "Ημερομηνία Γέννησης")?>
<select name="dobdate">
<option value="0"> </option>
<?php
for ($i = 1; $i <= 31; $i++) {
?>
<option value="<?php echo $i; ?>" <?php if ($postback && $_POST['dobdate'] == $i) echo 'selected="selected"';?>><?php echo $i;?></option>
<?php
}
?>
</select>
<select name="dobmonth">
<?php
$month = array( '', 'Ιανουαρίου', 'Φεβρουαρίου', 'Μαρτίου',
'Απριλίου', 'Μαΐου', 'Ιουνίου',
'Ιουλίου', 'Αυγούστου', 'Σεπτεμβρίου',
'Οκτωβρίου', 'Νοεμβρίου', 'Δεκεμβρίου');
foreach ($month as $i => $mname) {
?>
<option value="<?php echo $i; ?>" <?php if ($postback && $_POST['dobmonth'] == $i) echo 'selected="selected"';?>><?php echo $mname;?></option>
<?php
}
?>
</select>
<select name="dobyear">
<option value="0"> </option>
<?php
$sixteen_years_ago = date("Y") - 16;
for ($i = 1950; $i <= $sixteen_years_ago; $i++) {
?>
<option value="<?php echo $i; ?>" <?php if ($postback && $_POST['dobyear'] == $i) echo 'selected="selected"';?>><?php echo $i;?></option>
<?php
}
?>
</select>
<?php if (error_exists('dobyear')) { ?><div class="field_error"><?php echo $v->errors_specific['dobyear'];?></div><?php } ?>
</div>
</fieldset>
<fieldset id="studies">
<legend>Σπουδές</legend>
<p>Συμπληρώνεται μόνο από τα τακτικά και τα δόκιμα μέλη. Αν εγγράφεστε ως δόκιμο μέλος, επιλέξτε μόνο το έτος εισαγωγής.</p>
<div>
<?php label('entryyear', "Έτος εισαγωγής")?>
<select name="entryyear">
<option value="0">Χωρίς επιλογή</option>
<?php
$thisyear = date("Y");
for ($i = 1986; $i <= $thisyear; $i++) {
?>
<option value="<?php echo $i; ?>" <?php if ($postback && $_POST['entryyear'] == $i) echo 'selected="selected"';?>><?php echo $i;?></option>
<?php
}
?>
</select>
<?php if (error_exists('entryyear')) { ?><div class="field_error"><?php echo $v->errors_specific['entryyear'];?></div><?php } ?>
</div>
<div>
<?php label('graduationyear', "Έτος αποφοίτησης")?>
<select name="graduationyear">
<option value="0">Χωρίς επιλογή</option>
<?php
for ($i = 1990; $i <= $thisyear; $i++) {
?>
<option value="<?php echo $i; ?>" <?php if ($postback && $_POST['graduationyear'] == $i) echo 'selected="selected"';?>><?php echo $i;?></option>
<?php
}
?>
</select>
<?php if (error_exists('graduationyear')) { ?><div class="field_error"><?php echo $v->errors_specific['graduationyear'];?></div><?php } ?>
</div>
</fieldset>
<fieldset id="contact">
<legend>Στοιχεία Επικοινωνίας</legend>
<div>
<?php label('address1', "Διεύθυνση (1η γραμμή)")?>
<input type="text" name="address1" value="<?php if ($postback) echo $_POST['address1'];?>"/><br />
<?php if (error_exists('address1')) { ?><div class="field_error"><?php echo $v->errors_specific['address1'];?></div><?php } ?>
</div>
<div>
<?php label('address2', "Διεύθυνση (2η γραμμή)")?>
<input type="text" name="address2" value="<?php if ($postback) echo $_POST['address2'];?>"/>
<?php if (error_exists('address2')) { ?><div class="field_error"><?php echo $v->errors_specific['address2'];?></div><?php } ?>
</div>
<div>
<?php label('postcode', "Ταχυδρομικός Κώδικας")?>
<input type="text" name="postcode" value="<?php if ($postback) echo $_POST['postcode'];?>" />
<?php if (error_exists('postcode')) { ?><div class="field_error"><?php echo $v->errors_specific['postcode'];?></div><?php } ?>
</div>
<div>
<?php label('city', "Πόλη/περιοχή")?>
<input type="text" name="city" value="<?php if ($postback) echo $_POST['city'];?>" />
<?php if (error_exists('city')) { ?><div class="field_error"><?php echo $v->errors_specific['city'];?></div><?php } ?>
</div>
<div>
<?php label('country', "Χώρα")?>
<select name="country">
<?php
$sql = "SELECT Country_ID, name FROM ".$db_table_prefix."Countries;";
$countries = $db->sql_query($sql);
while ($country = $db->sql_fetchrow($countries)) {
?>
<option value="<?php echo $country['Country_ID']; ?>" <?php if ($postback && $_POST['country'] == $country['Country_ID']) echo 'selected="selected"';?>><?php echo $country['name'];?></option>
<?php
}
?>
</select>
<?php if (error_exists('country')) { ?><div class="field_error"><?php echo $v->errors_specific['country'];?></div><?php } ?>
</div>
<hr />
<div>
<?php label('phone_home', "Τηλέφωνο οικίας")?>
<input type="text" name="phone_home" value="<?php if ($postback) echo $_POST['phone_home'];?>"/>
<?php if (error_exists('phone_home')) { ?><div class="field_error"><?php echo $v->errors_specific['phone_home'];?></div><?php } ?>
</div>
<div>
<?php label('phone_mobile', "Τηλέφωνο κινητό")?>
<input type="text" name="phone_mobile" value="<?php if ($postback) echo $_POST['phone_mobile'];?>"/>
<?php if (error_exists('phone_mobile')) { ?><div class="field_error"><?php echo $v->errors_specific['phone_mobile'];?></div><?php } ?>
</div>
</fieldset>
<fieldset>
<div id="signatures" style="float:left;width:60%;padding:15px 5px;">
<div>
<label>
<input type="checkbox" name="signature_deed" id="signature_deed" <?php if ($postback && array_key_exists('signature_deed', $_POST)) echo 'checked="checked"';?>/>
Έλαβα γνώση και αποδέχομαι <a href="docs/katastatiko.html" class="popup">το καταστατικό του Συλλόγου Αποφοίτων</a>
</label>
<?php if (error_exists('signature_deed')) { ?><div class="field_error"><?php echo $v->errors_specific['signature_deed'];?></div><?php } ?>
</div>
<div>
<label for="signature_termsofuse">
<input type="checkbox" name="signature_termsofuse" id="signature_termsofuse" <?php if ($postback && array_key_exists('signature_termsofuse', $_POST)) echo 'checked="checked"';?>/>
Έλαβα γνώση και αποδέχομαι <a href="docs/termsofuse.html" class="popup">τους όρους χρήσης της υπηρεσίας</a>
</label>
<?php if (error_exists('signature_termsofuse')) { ?><div class="field_error"><?php echo $v->errors_specific['signature_termsofuse'];?></div><?php } ?>
</div>
<div>
<label for="signature_privacypolicy">
<input type="checkbox" name="signature_privacypolicy" id="signature_privacypolicy" <?php if ($postback && array_key_exists('signature_privacypolicy', $_POST)) echo 'checked="checked"';?>/>
Έλαβα γνώση και αποδέχομαι <a href="docs/privacypolicy.html" class="popup">την πολιτική απορρήτου</a>
</label>
<?php if (error_exists('signature_privacypolicy')) { ?><div class="field_error"><?php echo $v->errors_specific['signature_privacypolicy'];?></div><?php } ?>
</div>
</div>
<div id="captchabox" style="padding: 5px; width:320px; height:130px; float:right;">
<?php echo recaptcha_get_html($recaptcha_publickey); ?>
</div>
</fieldset>
<div style="text-align: center">
<input class="button" type="submit" value="Εγγραφή μέλους"/>
</div>
</form>
</div>
<?php } ?>
<div class="clear" style="height:3em;"></div>
</div>
</div>
</div>
<script type="text/javascript">
window.onload = function() {
// check to see that the browser supports the getElementsByTagName method
// if not, exit the loop
if (!document.getElementsByTagName) {
return false;
}
// create an array of objects of each link in the document
var popuplinks = document.getElementsByTagName("a");
// loop through each of these links (anchor tags)
for (var i=0; i < popuplinks.length; i++) {
// if the link has a class of "popup"...
if (popuplinks[i].getAttribute("class") == "popup") {
// add an onclick event on the fly to pass the href attribute
// of the link to our second function, openPopUp
popuplinks[i].onclick = function() {
openPopUp(this.getAttribute("href"));
return false;
}
}
}
}
function openPopUp(linkURL) {
window.open(linkURL,'docs','toolbar=no,menubar=no,status=no,scrollbars=yes,width=600,height=600')
}
</script>
</body>
</html>