/
register.php
341 lines (301 loc) · 12.9 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
<?php
/* bootstrap */
require __DIR__.'/./vendor/autoload.php';
require './config.php';
require './classes/boot.php';
require_once './classes/Student.php';
require_once './classes/Faculty.php';
require_once './classes/College.php';
require_once './classes/CaptchaVerify.php';
use Nette\Mail\Message;
use Nette\Mail\SendmailMailer;
use Illuminate\Validation\Factory as ValidatorFactory;
use Symfony\Component\Translation\Translator;
use App\College;
use App\Student;
use App\Faculty;
$post = false;
$error = 0;
const ERROR_DB = 1;
const ERROR_CAPTCHA = 2;
const ERROR_INVALID = 3;
if (isset($_POST['type'])) {
$post = true;
$verify = CaptchaVerify::verify($_POST["g-recaptcha-response"]);
if (!$verify) {
$error = ERROR_CAPTCHA;
}else{
$mail = new Message;
$mail->setFrom("C-SCAN'16 <$mailer_username>")
->addTo($_POST['email'])
->setSubject("C-SCAN'16 Registration");
$mailer = new Nette\Mail\SmtpMailer(array(
'host' => 'smtp.gmail.com',
'username' => $mailer_username,
'password' => $mailer_password,
'secure' => 'ssl',
));
$factory = new ValidatorFactory(new Translator('en'));
$messages = array(
'required' => 'The :attribute field is required.',
'max' => 'Please enter a valid :attribute number.',
'min' => 'Please enter a valid :attribute field.',
'email' => 'Please enter a valid email address.',
'numberic' => 'The :attribute field should consist only of digits.',
'integer' => 'The :attribute field should be selected.',
'digits_between' => 'The :attribute field should be contain minimum of 10 digits.'
);
if ($_POST['type'] == "student") {
$rules = array(
'college' => 'required|integer',
'faculty' => 'required',
'name' => 'required',
'email' => 'required|email',
'phone' => 'required|numeric|digits_between:10,15',
'course'=>'required',
'semester'=>'required',
'gender'=>'required',
'food'=>'required'
);
$validator = $factory->make($_POST, $rules,$messages);
if ($validator->passes()) {
$num = Student::where('college',$_POST['college'])->count();
$_POST['regid'] = $num+1;
if($v=Student::create($_POST)){
$regid = $v->colg->abbr."S".str_pad($_POST['regid'], 3, '0', STR_PAD_LEFT);
$name = $_POST['name'];
$mail->setHTMLBody("Hi $name,<br/>You have successfully registered for C-SCAN 2016. Your registration ID is ".$regid.". The confirmation regarding the same will be done via email on or before 1st February.<br/>For more details and updates, please visit our <a href='http://www.cscan.org.in'>website</a>.<br/><br/>Thank you.<br/><br/>Yours Sincerely,<br/>Organising Team,<br/>C-SCAN 2016.");
$mailer->send($mail);
}else{
$error = ERROR_DB;
}
}else{
$error = ERROR_INVALID;
}
}else if($_POST['type'] == "faculty"){
$rules = array(
'college' => 'required|integer',
'name' => 'required',
'email' => 'required|email',
'phone' => 'required|numeric|digits_between:10,15',
'designation' => 'required',
'interest' => 'required',
'gender'=>'required',
'food'=>'required'
);
$validator = $factory->make($_POST, $rules,$messages);
if ($validator->passes()) {
$num = Faculty::where('college',$_POST['college'])->count();
$_POST['regid'] = $num+1;
if($v = Faculty::create($_POST)){
$regid = $v->colg->abbr."F".str_pad($_POST['regid'], 3, '0', STR_PAD_LEFT);
$name = $_POST['name'];
$mail->setHTMLBody("Hi $name,<br/>You have successfully registered for C-SCAN 2016. Your registration id is ".$regid.". The confirmation regarding the same will be done via email on or before 1st February.<br/>For more details and updates, please visit our <a href='http://www.cscan.org.in'>website</a>.<br/><br/>Thank you.<br/>Yours Sincerely,<br/>Organising Team,<br/>C-SCAN 2016.");
$mailer->send($mail);
}else{
$error = ERROR_DB;
}
}else{
$error = ERROR_INVALID;
}
}
}
}
?>
<?php include_once './header.php'; ?>
<nav class="navsection navbar navbar-default hidden-xs">
<div class="container-fluid">
<nav id="sac-navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="./">Home</a></li>
</ul>
</nav>
</div>
</nav>
<div class="reg" id="reg">
<?php
if(isset($_GET['type'])&&$_GET['type']=="faculty"){
$opt = "?type=faculty";
}else{
$opt = "";
}
if($post){
if($error == 0){
?>
<div class="mesg">
<img src="images/logo.png" />
<h2>You've successfully registered for C-SCAN'16.</h2>
<h3>Your registration id is <?=$regid?>. You'll receive a confirmation mail from us.</h3>
<a class="brochure hashmenu" href="./register.php<?=$opt?>" id="another">Register Another</a>
<a class="brochure hashmenu" href="./index.php">Home</a>
</div>
<?php
}else if($error == ERROR_DB){
?>
<div class="mesg">
<h2>Sorry.Unknown error occured.Please try again</h2>
<a class="brochure hashmenu" href="./register.php<?=$opt?>" id="another">Try Again</a>
</div>
<?php
}else if($error == ERROR_CAPTCHA){
?>
<div class="mesg">
<h2>Registration failed.</h2>
<ul>
<li>Captcha Verification required.</li>
</ul><br>
<a class="brochure hashmenu" href="./register.php$opt" id="another">Try Again</a>
</div>
<?php }else if($error == ERROR_INVALID){
?>
<div class="mesg">
<h2>Registration failed.</h2>
<ul>
<?php
$messages = $validator->messages();
foreach ($messages->all() as $message)
{
echo "<li>".$message."</li>";
}
?>
</ul>
<br/>
<a class="brochure hashmenu" href="./register.php<?=$opt?>" id="another">Try Again</a>
</div>
<?php }
}else{
?>
<div class="wrap">
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<?php
$colleges = College::all();
if(isset($_GET['type'])&&$_GET['type']=="faculty"){ ?>
<form id="facultyform" action="register.php<?=$opt?>" method="POST">
<h2>Faculty Registration</h2>
<div class="form-group">
<select name="college" class="form-control" required>
<option value="" disabled selected>Select College</option>
<?php
foreach ($colleges as $key => $op) {
?>
<option value="<?=$op->id?>"><?=$op->name?></option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Name" required>
</div>
<div class="form-group">
<input type="text" name="designation" class="form-control" placeholder="Designation" required>
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email" required>
</div>
<div class="form-group">
<input type="number" name="phone" class="form-control" placeholder="Phone" required>
</div>
<div class="form-group">
<input type="text" name="interest" class="form-control" placeholder="Area of Interest" required>
</div>
<div class="form-group">
<label>Gender :
<label class="radio-inline">
<input type="radio" name="gender" value="male" checked> Male
</label>
<label class="radio-inline">
<input type="radio" name="gender" value="female"> Female
</label>
</label>
</div>
<div class="form-group">
<label>Food Preference :
<label class="radio-inline">
<input type="radio" name="food" value="veg" checked> Veg
</label>
<label class="radio-inline">
<input type="radio" name="food" value="nonveg"> Non-Veg
</label>
</label>
</div>
<div class="g-recaptcha" data-sitekey="6Lew1BMTAAAAABO4bm79an2x7n7Ix7mQfCGd44S2"></div>
<input type="hidden" name="type" value="faculty" />
<input type="submit" class="fbtn btn btn-default" value="Register" />
</form>
<?php }else{ ?>
<form id="studentform" action="register.php<?=$opt?>" method="POST">
<h2>Student Registration</h2>
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Participant Name" required>
</div>
<div class="form-group">
<select name="college" class="form-control" required>
<option value="" disabled selected>Select Institute</option>
<?php
foreach ($colleges as $key => $op) {
?>
<option value="<?=$op->id?>"><?=$op->name?></option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email" required>
</div>
<div class="form-group">
<input type="number" name="phone" class="form-control" placeholder="Phone" required>
</div>
<div class="form-group">
<select name="course" class="form-control" required>
<option value="" disabled selected>Select Programme</option>
<option value="B.Tech">B.Tech</option>
<option value="M.Tech">M.Tech</option>
<option value="Ph.D">Ph.D</option>
<option value="MCA">MCA</option>
</select>
</div>
<div class="form-group">
<input type="text" name="semester" class="form-control" placeholder="Current Semester" required>
</div>
<div class="form-group">
<input type="text" name="faculty" class="form-control" placeholder="Accompanying Faculty" required>
</div>
<div class="form-group">
<label>Gender :
<label class="radio-inline">
<input type="radio" name="gender" value="male" checked> Male
</label>
<label class="radio-inline">
<input type="radio" name="gender" value="female"> Female
</label>
</label>
</div>
<div class="form-group">
<label>Food Preference :
<label class="radio-inline">
<input type="radio" name="food" value="veg" checked> Veg
</label>
<label class="radio-inline">
<input type="radio" name="food" value="nonveg"> Non-Veg
</label>
</label>
</div>
<div class="g-recaptcha" data-sitekey="6Lew1BMTAAAAABO4bm79an2x7n7Ix7mQfCGd44S2"></div>
<input type="hidden" name="type" value="student" />
<input type="submit" class="fbtn btn btn-default" value="Register" />
</form>
<?php } ?>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<script src='https://www.google.com/recaptcha/api.js'></script>
<div class="footer">
<p> © Creative and Intellectual minds of NIT Calicut </p>
</div>