-
Notifications
You must be signed in to change notification settings - Fork 3
/
GeocodeSetup.php
285 lines (238 loc) · 10.2 KB
/
GeocodeSetup.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
<?php
/* $Id: GeocodeSetup.php 4625 2011-07-06 09:30:42Z daintree $*/
include('includes/session.inc');
$title = _('Geocode Maintenance');
include('includes/header.inc');
if (isset($_GET['SelectedParam'])){
$SelectedParam = $_GET['SelectedParam'];
} elseif(isset($_POST['SelectedParam'])){
$SelectedParam = $_POST['SelectedParam'];
}
if (isset($Errors)) {
unset($Errors);
}
$Errors = array();
$InputError = 0;
if (isset($_POST['submit'])) {
//initialise no input errors assumed initially before we test
$i=1;
/* actions to take once the user has clicked the submit button
ie the page has called itself with some user input */
//first off validate inputs are sensible
$sql="SELECT count(geocodeid)
FROM geocode_param WHERE geocodeid='".$_POST['GeoCodeID']."'";
$result=DB_query($sql, $db);
$myrow=DB_fetch_row($result);
if ($myrow[0]!=0 and !isset($SelectedParam)) {
$InputError = 1;
prnMsg( _('That geocode ID already exists in the database'),'error');
$Errors[$i] = 'GeoCodeID';
$i++;
}
$msg='';
if (isset($SelectedParam) and $InputError !=1) {
/*SelectedParam could also exist if submit had not been clicked this code would not run in this case cos submit is false of course see the delete code below*/
if (isset($_POST['GeoCode_Key']) and isset($_POST['GeoCode_Key']) ){
$sql = "UPDATE geocode_param SET
geocode_key='" . $_POST['GeoCode_Key'] . "',
center_long='" . $_POST['Center_Long'] . "',
center_lat='" . $_POST['Center_Lat'] . "',
map_height='" . $_POST['Map_Height'] . "',
map_width='" . $_POST['Map_Width'] . "',
map_host='" . $_POST['Map_Host'] . "'
WHERE geocodeid = '" . $SelectedParam . "'";
}
$msg = _('The geocode status record has been updated');
} else if ($InputError !=1) {
/*Selected Param is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new status code form */
if (isset($_POST['GeoCode_Key']) and $_POST['GeoCode_Key']>0){
$sql = "INSERT INTO geocode_param (geocodeid,
geocode_key,
center_long,
center_lat,
map_height,
map_width,
map_host)
VALUES ('',
'" . $_POST['GeoCode_Key'] . "',
'" . $_POST['Center_Long'] . "',
'" . $_POST['Center_Lat'] . "',
'" . $_POST['Map_Height'] . "',
'" . $_POST['Map_Width'] . "',
'" . $_POST['Map_Host'] . "')";
} else {
$sql = "INSERT INTO geocode_param (geocodeid,
geocode_key,
center_long,
center_lat,
map_height,
map_width,
map_host)
VALUES ('" . $_POST['GeoCodeID'] . "',
'" . $_POST['GeoCode_Key'] . "',
'" . $_POST['Center_Long'] . "',
'" . $_POST['Center_Lat'] . "',
'" . $_POST['Map_Height'] . "',
'" . $_POST['Map_Width'] . "',
'" . $_POST['Map_Host'] . "')";
}
$msg = _('A new geocode status record has been inserted');
unset ($SelectedParam);
unset ($_POST['GeoCode_Key']);
}
//run the SQL from either of the above possibilites
$result = DB_query($sql,$db);
if ($msg != '') {
prnMsg($msg,'success');
}
} elseif (isset($_GET['delete'])) {
//the link to delete a selected record was clicked instead of the submit button
$sql = "DELETE FROM geocode_param WHERE geocodeid = '" . $_GET['delete'] . "' LIMIT 1";
$result = DB_query($sql,$db);
prnMsg( _('Geocode deleted'), 'success' );
//end if status code used in customer or supplier accounts
unset ($_GET['delete']);
unset ($SelectedParam);
}
if (!isset($SelectedParam)) {
/* It could still be the second time the page has been run and a record has been selected for modification - SelectedParam will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters
then none of the above are true and the list of status codes will be displayed with
links to delete or edit each. These will call the same page again and allow update/input
or deletion of the records*/
$sql = "SELECT geocodeid,
geocode_key,
center_long,
center_lat,
map_height,
map_width,
map_host
FROM geocode_param";
$result = DB_query($sql, $db);
echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/maintenance.png" title="' . _('Geocode Setup') . '" alt="" />'.
_('Setup configuration for Geocoding of Customers and Suppliers') .'</p>';
echo '<div class="page_help_text">'. _('Get a google API key at ') .
'<a href="http://code.google.com/apis/maps/signup.html" target="_blank"> http://code.google.com/apis/maps/signup.html</a></div>';
echo '<br /><div class="page_help_text">'. _('Find the lat/long for your map center point at ') .
'<a href="http://www.batchgeocode.com/lookup/" target="_blank">http://www.batchgeocode.com/lookup/</a></div><br />';
prnMsg(_('Set the maps centre point using the Center Longitude and Center Latitude. Set the maps screen size using the height and width in pixels (px)'),'info');
echo '</div><br />';
echo '<table class="selection">';
echo '<tr>
<th>'. _('Geocode ID') .'</th>
<th>'. _('Geocode Key') .'</th>
<th>'. _('Center Longitude') . '</th>
<th>'. _('Center Latitude') . '</th>
<th>'. _('Map height (px)') . '</th>
<th>'. _('Map width (px)') . '</th>
<th>'. _('Map host') . '</th>
</tr>';
$k=0; //row colour counter
while ($myrow=DB_fetch_row($result)) {
if ($k==1){
echo '<tr class="EvenTableRows">';
$k=0;
} else {
echo '<tr class="OddTableRows">';
$k=1;
}
printf('<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href="%s?SelectedParam=%s">' . _('Edit') . '</a></td>
<td><a href="%s?SelectedParam=%s&delete=%s">'. _('Delete') .'</a></td>
</tr>',
$myrow[0],
$myrow[1],
$myrow[2],
$myrow[3],
$myrow[4],
$myrow[5],
$myrow[6],
htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'),
$myrow[0],
htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'),
$myrow[0],
$myrow[0]);
} //END WHILE LIST LOOP
echo '</table>';
} //end of ifs and buts!
if (isset($SelectedParam)) {
echo '<div class="centre"><br /><a href="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">' . _('Show Defined Geocode Param Codes') . '</a><br /></div>';
}
if (!isset($_GET['delete'])) {
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
if (isset($SelectedParam) and ($InputError!=1)) {
//editing an existing status code
$sql = "SELECT geocodeid,
geocode_key,
center_long,
center_lat,
map_height,
map_width,
map_host
FROM geocode_param
WHERE geocodeid='" . $SelectedParam . "'";
$result = DB_query($sql, $db);
$myrow = DB_fetch_array($result);
$_POST['GeoCodeID'] = $myrow['geocodeid'];
$_POST['GeoCode_Key'] = $myrow['geocode_key'];
$_POST['Center_Long'] = $myrow['center_long'];
$_POST['Center_Lat'] = $myrow['center_lat'];
$_POST['Map_Height'] = $myrow['map_height'];
$_POST['Map_Width'] = $myrow['map_width'];
$_POST['Map_Host'] = $myrow['map_host'];
echo '<input type="hidden" name="SelectedParam" value="' . $SelectedParam . '" />';
echo '<input type="hidden" name="GeoCodeID" value="' . $_POST['GeoCodeID'] . '" />';
echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/maintenance.png" title="' . _('Geocode Setup') . '" alt="" />'. _('Setup configuration for Geocoding of Customers and Suppliers') .'</p>';
echo '<table class="selection">
<tr>
<td>'. _('Geocode Code') .':</td>
<td>' . $_POST['GeoCodeID'] . '</td>
</tr>';
} else { //end of if $SelectedParam only do the else when a new record is being entered
if (!isset($_POST['GeoCodeID'])) {
$_POST['GeoCodeID'] = '';
$_POST['GeoCode_Key'] = '';
$_POST['Center_Long'] = '';
$_POST['Center_Lat'] = '';
$_POST['Map_Height'] = '';
$_POST['Map_Width'] = '';
$_POST['Map_Host'] = '';
}
echo '<table class="selection">';
}
if (!isset($_POST['GeoCode_Key'])) {
$_POST['GeoCode_Key'] = '';
}
echo '<br /><tr>
<td>'. _('Geocode Key') .':</td>
<td><input ' . (in_array('GeoCode_Key',$Errors) ? 'class="inputerror"' : '' ) . ' tabindex="2" type="text" name="GeoCode_Key" value="'. $_POST['GeoCode_Key'] .'" size="28" maxlength="300" />
</td></tr>
<tr><td>'. _('Geocode Center Long') . '</td>
<td><input tabindex="3" type="text" name="Center_Long" value="'. $_POST['Center_Long'] .'" size="28" maxlength="300" /></td></tr>
<tr><td>'. _('Geocode Center Lat') . '</td>
<td><input tabindex="4" type="text" name="Center_Lat" value="'. $_POST['Center_Lat'] .'" size="28" maxlength="300" /></td></tr>
<tr><td>'. _('Geocode Map Height') . '</td>
<td><input tabindex="5" type="text" name="Map_Height" value="'. $_POST['Map_Height'] .'" size="28" maxlength="300" /></td></tr>
<tr><td>'. _('Geocode Map Width') . '</td>
<td><input tabindex="6" type="text" name="Map_Width" value="'. $_POST['Map_Width'] .'" size="28" maxlength="300" /></td></tr>
<tr><td>'. _('Geocode Host') . '</td>
<td><input tabindex="7" type="text" name="Map_Host" value="'. $_POST['Map_Host'] .'" size="20" maxlength="300" /></td></tr>
</table>
<br />
<div class="centre"><button tabindex="4" type="submit" name="submit">' . _('Enter Information') . '</button></div>
<br />
</form>';
echo '<div class="page_help_text">' . _('When ready, click on the link below to run the GeoCode process. This will Geocode all Branches and Suppliers. This may take some time. Errors will be returned to the screen.') . '</p>';
echo '<p>' . _('Suppliers and Customer Branches are geocoded when being entered/updated. You can rerun the geocode process from this screen at any time.') . '</p></div><br />';
echo '<div class="centre"><a href="' . $rootpath . '/geocode.php">' . _('Run GeoCode process (may take a long time)') . '</a></p><br />';
echo '<a href="' . $rootpath . '/geo_displaymap_customers.php">' . _('Display Map of Customer Branches') . '</a><br />';
echo '<a href="' . $rootpath . '/geo_displaymap_suppliers.php">' . _('Display Map of Suppliers') . '</a></div>';
} //end if record deleted no point displaying form to add record
include('includes/footer.inc');
?>