-
Notifications
You must be signed in to change notification settings - Fork 5
/
tracktrees.php
186 lines (167 loc) · 5.09 KB
/
tracktrees.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
<?php
include './includes/dbc.php';
page_protect();
//print_r($HTTP_POST_VARS);
$speciesId=($_POST['species_id']);
$getlocationname= $_SESSION['treelocID'];
//echo $_POST['treelocationname'];
//echo $getlocationname;
if($_POST['Submit'] == 'Submit')
{ foreach($_POST as $key => $value)
{
$data[$key] = filter($value);
}
$dfw_fieldname="";
$dfw_value="";
$dos_fieldname="";
$dos_value="";
if($_POST[distance_from_water]!="")
{
$dfw_fieldname="distance_from_water,";
$dfw_value="'$_POST[distance_from_water]',";
}
if($_POST[degree_of_slope]!="")
{
$dos_fieldname="degree_of_slope,";
$dos_value="'$_POST[degree_of_slope]',";
}
$sql1 = "INSERT INTO trees
(tree_desc,is_fertilised,
is_watered,species_id,tree_location_id,location_type,".$dfw_fieldname.$dos_fieldname." aspect)
VALUES
('$_POST[tree_desc]',
'$_POST[is_fertilised]',
'$_POST[is_watered]',
'$speciesId',
'$_SESSION[treelocID]',
'$_POST[location_type]',".
$dfw_value.$dos_value."
'$_POST[aspect]'
)";
mysql_query($sql1,$link)or die("Insertion Failed:" .mysql_error());
//echo "ID of last inserted record is: " . mysql_insert_id();
$tree_id = mysql_insert_id();
//echo "$tree_id";
$sql2 = "INSERT INTO user_tree_table
(tree_id,tree_nickname,user_id)
VALUES
('$tree_id',
'".addslashes($_POST[tree_nickname])."',
'$_SESSION[user_id]'
)";
mysql_query($sql2,$link) or die("Insertion Failed2:" .mysql_error());
//echo "tree damage".$_POST[tree_damage];
$sql3 = "INSERT INTO tree_measurement
(tree_id,user_id,date_of_measurement,";
if($_POST[tree_girth]!="")
{
$sql3 .= "tree_girth,";
}
if($_POST[tree_height]!="")
{
$sql3 .= "tree_height,";
}
$sql3 .= "tree_damage,other_notes)
VALUES
('$tree_id',
'$_SESSION[user_id]',
now(),";
if($_POST[tree_girth]!="")
{
$sql3 .= "'".addslashes($_POST[tree_girth])."',";
}
if($_POST[tree_height]!="")
{
$sql3 .= "'".addslashes($_POST[tree_height])."',";
}
$sql3 .= " '".addslashes($_POST[tree_damage])."',
'".addslashes($_POST[other_notes])."'
)";
mysql_query($sql3,$link) or die("Insertion Failed3:" .mysql_error());
//echo "Done id: ".$row.". <br />";
}
//after insertion unset the session for treelocation
unset($_SESSION['treelocation']);
?>
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<title>SeasonWatch</title>
<?php
include ("contribheader_head.php");
?>
</head>
<body>
<link rel="stylesheet" href="blueprint/screen.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="blueprint/print.css" type="text/css" media="print">
<link rel="stylesheet" href="blueprint/plugins/fancy-type/screen.css" type="text/css" media="screen, projection">
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<link rel="stylesheet" href="css/styles_new.css" type="text/css">
<?php
include ("contribheader_body.php");
?>
<div class="container first_image" style="-moz-border-radius-bottomleft: 10px; -moz-border-radius-bottomright: 10px;">
<table>
<tbody>
<tr>
<td/>
</tr>
</tbody>
</table>
<div>
<hr/>
</div>
<table id="table1" class="tablesorter" cellspacing="0" cellpadding="3" style="width: 500px; margin-left: auto; margin-right: 50%;">
<colgroup>
<col style="width: 150px;"/>
<col style="width: 3500px;"/>
<col style="width: 350px;"/>
<col style="width: 400px;"/>
</colgroup>
<thead>
<tr>
<th class="header">Tree Nickname</th>
<th class="header">Primary Name</th>
<th class="header">Scientific name</th>
<th class="header">Family</th>
<th class="header">Tree Location</th>
</tr>
</thead>
<tbody>
<?php
print "<tr class='delboxtr'>";
print "<tr>";
$tree_nickname=$_POST['tree_nickname'];
echo "<td>" . $tree_nickname . "</td>";
$species_scientific_nameID=$_POST['species_id'];
$query1 = mysql_query("SELECT * FROM Species_master WHERE species_id=$species_scientific_nameID");
while($row_settings = mysql_fetch_array($query1))
{
echo "<td>" . $row_settings['species_primary_common_name'] . "</td>";
echo "<td>" . $row_settings['species_scientific_name'] . "</td>";
echo "<td>" . $row_settings['family'] . "</td>";
}
$query = mysql_query("SELECT * FROM location_master WHERE tree_location_id='$_SESSION[treelocID]'");
while($row = mysql_fetch_array($query))
{
$getlocationname = $row['location_name'];
}
echo "<td>" . $getlocationname . "</td>";
print "</tr>";
echo "</tbody></table>";
mysql_close($link);
?>
<html>
<p align="center">
<input type=reset value="Add a new tree" class=buttonstyle onclick="javascript:window.location.href='addtree_options.php';">
<input type=reset value="Edit tree details" class=buttonstyle onclick="javascript:window.location.href='listtree.php';">
</p>
</div>
</div>
<div class="container bottom">
</div>
</body>
</html>