-
Notifications
You must be signed in to change notification settings - Fork 0
/
addobs.php
executable file
·526 lines (487 loc) · 16.8 KB
/
addobs.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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<?php
session_start();
header("Cache-control: private"); // IE 6 Fix
if(($_POST[cmd] == "statechanged") || ($_POST['cmd']=="locselected")){
foreach($_POST as $key=>$value){
$_SESSION[$key]=$value;
}
}
include("banner.html");
if (empty($_POST) && (empty($_GET) || $_GET['last'] = 1)) {
unset($_SESSION['other_name']);
unset($_SESSION['obstart']);
unset($_SESSION['other_notes']);
}
$dcity = "";
$ddist = "";
$dlat = "";
$dlong = "";
if ($_GET['last'] == 1 || $_POST['last'] == 1) {
$last = 1;
$sighting = 'last';
$ucsighting = 'Last';
} else {
$last = 0;
$sighting = 'first';
$ucsighting = 'First';
}
?>
<html>
<head>
<title>MigrantWatch -- Level 1 Online Form</title>
<link rel="shortcut icon" href="favicon.ico">
<link href="CalendarControl.css" rel="stylesheet" type="text/css">
<link rel=stylesheet href="style.css" type="text/css">
<script src="CalendarControl.js" language="javascript"></script>
<script src="jquery.js" language="javascript"></script>
<script src="jquery.autocomplete.js" language="javascript"></script>
<script src="jquery.bgiframe.min.js" language="javascript"></script>
<link href="jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="date.js" language="javascript"></script>
<script language="JavaScript" type="text/javascript">
function appendNewInput()
{
var tbl = $('#catTable');
var lastRow = $('#catTable tr').length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var newElement =
"<tr>"
+ "<td>" + iteration + "</td>"
+ "<td>"
+ "<input type='text' id='obdate_" + iteration + "' name='obdate[]' value='' readonly>"
+ "<input type='button' id='obdate_but_" + iteration + "' value='Choose' onclick='showCalendarControl(obdate_" + iteration + ");' /> *</td>"
+ "<td>"
+ "<input type='text' id='species_" + iteration +"' name='species[]' size='25'>"
+ "<input type ='hidden' id='species_id_" + iteration +"' name='species_id[]'></td>"
+ "<td>"
+ "<select id= 'ob_type_" + iteration + "' name='ob_type[]'>"
+ "<option value='first'>First</option>"
+ "<option value='last'>Last</option>"
+ "</select>"
+ "</td>" +
"</tr>";
$('#catTable').append(newElement);
$("#species_" + iteration).autocomplete("autocomplete.php", {
width: 260,
selectFirst: false
});
$("#species_" + iteration).result(function(event, data, formatted) {
if (data)
$("#species_id_" + iteration).val(data[1]);
});
}
$().ready(function() {
$('#species_1').autocomplete("autocomplete.php", {
width: 260,
selectFirst: false
});
$("#species_1").result(function(event, data, formatted) {
if (data)
$("#species_id_1").val(data[1]);
});
});
function validate() {
var now = new Date();
var tbl = $('#catTable');
var lastRow = $('#catTable tr').length - 1;
for(var i = 1; i <= lastRow; i++) {
if ($('#species_' + i).val() != '' || (i == 1)) {
if ($('#obdate_' + i).val() == '') {
alert('Please enter date of observation for the entry no. ' + i);
$('#obdate_' + i).focus();
return false;
}
}
if ($('#obdate_' + i).val() != '' || (i == 1)) {
var obdate = $('#obdate_' + i).val();
if ($('#species_' + i).val() == '') {
alert('Please enter the species for the for the entry no. ' + i);
$('#species_' + i).focus();
return false;
}
if (compareDates(obdate,"dd-MM-yyyy",formatDate(now,"dd-MM-yyyy"),"dd-MM-yyyy") == 1) {
alert("The observation date cannot be a future date.");
return false;
}
}
}
}
</script>
<script language=javascript>
function isEmpty(s)
{ return ((s == null) || (s.length == 0))
}
// BOI, followed by one or more whitespace characters, followed by EOI.
var reWhitespace = /^\s+$/
// BOI, followed by one or more characters, followed by @,
// followed by one or more characters, followed by .,
// followed by one or more characters, followed by EOI.
var reEmail = /^.+\@.+\..+$/
var defaultEmptyOK = false
// Returns true if string s is empty or
// whitespace characters only.
function isWhitespace (s)
{ // Is s empty?
return (isEmpty(s) || reWhitespace.test(s));
}
function displaytr(opt){
if(opt==1)
document.getElementById("loctr").style.display = "block";
else
document.getElementById("loctr").style.display = "none";
}
function stateChanged(){
document.frm_level1.cmd.value = "statechanged";
document.frm_level1.action = "level1.php";
document.frm_level1.submit();
}
function locSelected(){
document.frm_level1.cmd.value = "locselected";
document.frm_level1.action = "level1.php";
document.frm_level1.submit();
}
function addLocation(){
if(isWhitespace(document.frm_level1.nlname.value)){
alert("Please enter location name.");
return;
}
if (document.frm_level1.nlstate.value == -1){
alert("Please select a state for new location");
return;
}
document.frm_level1.cmd.value = "newlocation";
document.frm_level1.action="process_level1.php";
document.frm_level1.submit();
}
function validate(){
if(document.frm_level1.location.value == -1){
alert("Please select a location for the Observations.");
return false;
}
if (document.frm_level1.obstart.value == "") {
alert("Please enter Observation <?php echo ($last == 1) ? 'End' : 'Start'; ?> date.");
return false;
}
if (document.frm_level1.often.value == ""){
alert("Please select How often you look for birds at this location?");
return false;
}
var now = new Date();
var flag = false;
var invalidDate = false;
var el, i = 0, oForm = document.frm_level1;
var obstart = document.frm_level1.obstart.value;
while (el = oForm.elements[i++]){
if ((el.type == 'text') && (el.name.indexOf('dt') != -1)){
if (el.value != ""){
flag = true;
if((compareDates(el.value,"dd-MM-yyyy",formatDate(now,"dd-MM-yyyy"),"dd-MM-yyyy") == 1) || (compareDates(obstart,"dd-MM-yyyy",el.value,"dd-MM-yyyy") == 1)) {
invalidDate = true;
}
}
}
}
if (!flag){
alert("Please enter <?php echo $sighting; ?> sighting date for atleast one Species.");
return false;
}
if (invalidDate){
alert("One of the sighting dates is either before Observation <?php echo ($last == 1) ? 'End' : 'Start'; ?> Date or in future. Please check.");
return false;
}
return true;
}
</script>
</head>
<body>
<a name="Top"></a>
<?php
//include("banner.html");
include("./db.php");
if (!isset($_SESSION['userid']))
die("No Session. Fatal Error...<br><a href='login.php'>Login Here</a>");
?>
<form name=frm_level1 action=process_level1.php method=POST>
<input type="hidden" name="last" value="<?php echo $last ?>"/>
<table border=0 width=580 cellpadding=2 cellspacing=1>
<tr><td colspan=2>
</td></tr>
<tr>
<td colspan=2 style="font-weight:bold;">
Form for reporting <?php echo $ucsighting; ?> Dates
</td></tr>
<tr>
<td bgcolor="dedede" colspan=2><b>Reported By</b></td>
</tr>
<tr>
<td width=40% align=right>Name :</td>
<td><b><?php print($_SESSION['username']); ?></b></td>
</tr>
<tr>
<td align=right>
If you are reporting sightings on behalf of someone else, please
give that person's name :
</td>
<td><input type=text name="other_name" value="<?php print $_SESSION[other_name]; ?>" style="width:150px"></tr>
</tr>
<tr>
<td valign=top bgcolor="dedede" colspan=2>
<b>Location of Observations</b>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align=right>Select State or Union Territory </td>
<td>
<SELECT name=state width=150 onchange="javascript:stateChanged();">
<option value=-1>--Select State--</option>
<?php
$result = mysql_query("SELECT state_id, state FROM migwatch_states order by state");
$state = $_POST['state'];
if (!$state)
$state = $_GET['state'];
if($result){
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
print "<option value=".$row{'state_id'};
if (($row{'state_id'} == $state) || ($_SESSION[state] == $row{'state_id'}))
print " selected ";
print ">".$row{'state'}."</option>\n";
}
}
?>
</select>
</td>
</tr>
<tr>
<td align=right>Select Location</td>
<td>
<select name=location width=150 onchange="javascript:locSelected();">
<option value=-1> - Select A Location - </option>
<?php
if(($_POST['cmd'] == "statechanged") || ($state != "") || ($_POST['cmd']=="locselected")) {
$result = mysql_query("SELECT location_id, location_name, city, district, latitude, longitude FROM migwatch_locations WHERE state_id=".$state." ORDER BY location_name");
if($result){
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
print "<option value=".$row{'location_id'};
if (($_GET['loc'] == $row{'location_id'}) || ($_SESSION[location] == $row{'location_id'}) || ($_POST['location'] == $row{'location_id'}))
print " selected ";
print ">".$row{'location_name'}." - ".$row{'city'}."</option>\n";
}
}
}
?>
</select> *
</td>
</tr>
<?php
if(($_POST['cmd']=="locselected") && (isset($_SESSION['location']))) {
$result = mysql_query("SELECT city, district, latitude, longitude FROM migwatch_locations WHERE location_id=".$_SESSION['location']);
if($result){
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$dcity = $row{'city'};
$ddist = $row{'district'};
$dlat = $row{'latitude'};
$dlong = $row{'longitude'};
}
}
}
?>
<tr>
<td align=right>City/Town:</td>
<td><?php print $dcity; ?></td>
</tr>
<tr>
<td align=right>District:</td>
<td><?php print $ddist; ?></td>
</tr>
<tr>
<td align=right>Latitude:</td>
<td><?php print $dlat; ?></td>
</tr>
<tr>
<td align=right>Longitude:</td>
<td><?php print $dlong; ?></td>
</tr>
<tr><td colspan=2><a href="javascript:displaytr(1);">Add New Location</a></td>
</tr>
<tr>
<td colspan=2>
<table width="100%" style="border-style:solid;border-width:1px; display:none" align='center' id="loctr">
<tr>
<td width=20%>Location Name:</td>
<td><input type=text name=nlname style="width:250px;"/>
(eg. Okhla Bird Sanctuary)
</td>
</tr>
<tr>
<td>City/Town:</td>
<td><input type=text name=nlcity style="width:250px;"/></td>
</tr>
<tr>
<td>District:</td>
<td><input type=text name=nldist style="width:250px;"/></td>
</tr>
<tr>
<td>State:</td>
<td>
<SELECT name=nlstate style="width:250">
<option value=-1>--Select State--</option>
<?php
$result = mysql_query("SELECT state_id, state FROM migwatch_states order by state");
if($result){
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
print "<option value=".$row{'state_id'};
print ">".$row{'state'}."</option>\n";
}
}
?>
</select>
</td>
</tr>
<tr>
<td>Latitude:</td>
<td><input type=text name=nllat style="width:250px;"/> (If known)</td>
</tr>
<tr>
<td>Longitude:</td>
<td><input type=text name=nllong style="width:250px;"/> (If known)
</td>
</tr>
<tr>
<td colspan=2>
If you don't know the geographical coordinates,
please describe the location in detail (eg, distance and direction
from the nearest town)
</td>
</tr>
<tr>
<td colspan=2>
<textarea name=nladditional rows=5 cols=40></textarea>
</td>
</tr>
<tr>
<td colspan=2>
<input type=button value="Add" class=buttonstyle onclick="addLocation();" />
<input type=button value="Hide" class=buttonstyle onclick="javascript:displaytr(0);"/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="dedede" colspan=2><b>Observation Details</b></td>
</tr>
<tr>
<td align=right><?php echo ($last == 1) ? 'End' : 'Start'; ?> of Observations:</td>
<td>
<input type=text name=obstart value="<?php print $_SESSION[obstart]; ?>" readonly><input type=button value="Choose" onclick="showCalendarControl(obstart);" /> *
<br>
(Date when you <?php echo ($last == 1) ? 'stopped' : 'started'; ?> observing at this location after 1st Aug 2007)
</td>
</tr>
<tr>
<td align=right>
How often do you look for birds at this location?
</td>
<td>
<select name="often">
<option value="" >Select</option>
<option value="Daily" <?php print($_SESSION[often]=="Daily" ? " selected " : "") ?>>Daily</option>
<option value="Weekly" <?php print($_SESSION[often]=="Weekly" ? " selected " : "") ?>>Weekly</option>
<option value="Fortnightly" <?php print($_SESSION[often]=="Fortnightly" ? " selected " : "") ?>>Fortnightly</option>
<option value="Monthly" <?php print($_SESSION[often]=="Monthly" ? " selected " : "") ?>>Monthly</option>
<option value="Irregular" <?php print($_SESSION[often]=="Irregular" ? " selected " : "") ?>>Irregular</option>
<option value="First visit" <?php print($_SESSION[often]=="First visit" ? " selected " : "") ?>>This is my first visit</option>
</select> *
</td>
</tr>
<tr>
<td align=left colspan='2'>* <?php echo $ucsighting; ?> Dates of Sighting for:<br>(dd-mm-yyyy)</td>
</tr>
<tr>
<td colspan='2'>
<table id='catTable'>
<tbody>
<tr>
<td>No.</td>
<td>Date</td>
<td>Species</td>
<td>Type</td>
</tr>
<?php
for($i = 1; $i <= $rowCount; $i++) {
$j = $i - 1;
?>
<tr id='cloneme'>
<td>1</td>
<td>
<input type='text' id='obdate_<?php echo $i; ?>' name='obdate[]' value='<?php if(isset($lastData['obdate'][$j])) echo $lastData['obdate'][$j]; ?>' readonly><input type='button' id='obdate_but_<?php echo $i; ?>' value="Choose" onclick="showCalendarControl(obdate_<?php echo $i; ?>);" /> *</td>
<td>
<input type='text' id='species_<?php echo $i; ?>' name='species[]' size='25' value='<?php if (isset($lastData['species'][$j])) echo $lastData['species'][$j]; ?>'>
<input type ='hidden' id='species_id_<?php echo $i; ?>' name='species_id[]' value='<?php if (isset($lastData['species_id'][$j])) echo $lastData['species_id'][$j]; ?>'></td>
<td>
<select id= 'ob_type_<?php echo $i ?>' name='ob_type[]'>
<option value='first' <?php if (isset($lastData['obtype'][$j]) && $lastData['obtype'][$j] == 'first') echo 'selected' ?>>First</option>
<option value='last' <?php if (isset($lastData['obtype'][$j]) && $lastData['obtype'][$j] == 'last') echo 'selected' ?>>Last</option>
</select>
</td>
</tr>
<?php
}
?>
</table>
</td>
<td width='232px'>
<table width='232px' cellpadding=2 cellspacing=1 style="border-width:1px;border-style:solid;">
<?php
if($result && $table2rows > 0){
$i = 1;
while ($i <= $table2rows){
$row = mysql_fetch_array($result, MYSQL_ASSOC);
print "<tr bgcolor=".($i++ % 2 == 0 ? "#dedede" : "#FFFFFF")."><td width=40% align=right>";
print $row{'common_name'};
print "</td><td>";
print "<input name=dt".$row{'species_id'}." type=text readonly value='".$_SESSION["dt".$row{species_id}]."'>";
print "<input name=spname".$row{'species_id'}." type=hidden value='".$row{'common_name'}."' />";
print "<input type=button value='Choose' onclick='showCalendarControl(dt".$row{'species_id'}.")' />";
print "</td></tr>\n";
}
}
?>
</table>
</td>
</tr>
<tr>
<td align=right>Other Notes:</td>
<td><textarea name="other_notes" class="editbox" rows="4" cols=40 ><?php print $_SESSION[other_notes]; ?></textarea>
<br>(eg, habitat, numbers of individuals seen, etc)
</td>
</tr>
<tr>
<td colspan=2>
<br><input type=submit value= "Submit Data" class=buttonstyle onclick="return validate();">
<input type=button value="Go Back to Main Page" class=buttonstyle onclick="javascript:window.location.href='main.php';" />
<input type=hidden name=cmd value="level1"/>
</td>
</tr>
<tr><td colspan=2> </td></tr>
<tr>
<td colspan=2>
<li> <b>Asterisks (*) indicate required fields.</b>
<li>A message with the information you submit
will be sent to your email address. Please check this carefully
and tell us about any errors.
</td>
</tr>
</table>
</form>
</body>
</html>
<!-----------------------------------------------------
Written by: Suresh V [verditer at gmail.com]
For: National Center for Biological Sciences, Bangalore
http://ncbs.res.in
In Love of Birds.
------------------------------------------------------->