Skip to content

Commit 4d07326

Browse files
committed
Add Place admin page in order to add,edit,delete #62
1 parent ea21ee6 commit 4d07326

2 files changed

Lines changed: 355 additions & 0 deletions

File tree

admin/admin_place.php

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
<?php
2+
/***********************************************
3+
* File : admin_place.php
4+
* Project : piwigo-openstreetmap
5+
* Descr : Create place for reuse
6+
*
7+
* Created : 07.07.2015
8+
*
9+
* Copyright 2013-2015 <xbgmsharp@gmail.com>
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation, either version 3 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
************************************************/
25+
26+
// Check whether we are indeed included by Piwigo.
27+
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
28+
29+
// Check access and exit when user status is not ok
30+
check_status(ACCESS_ADMINISTRATOR);
31+
32+
// Setup plugin Language
33+
load_language('plugin.lang', OSM_PATH);
34+
35+
// Fetch the template.
36+
global $template, $conf, $lang, $prefixeTable;
37+
// Easy access
38+
define('osm_place_table', $prefixeTable.'osm_places');
39+
40+
/* Table to hold osm places details */
41+
$q = 'CREATE TABLE IF NOT EXISTS `'.osm_place_table.'` (
42+
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
43+
`latitude` double(8,6) NOT NULL,
44+
`longitude` double(8,6) NOT NULL,
45+
`name` varchar(255) DEFAULT NULL,
46+
`parentId` mediumint(8),
47+
PRIMARY KEY (id)
48+
) ENGINE=MyISAM DEFAULT CHARSET=utf8
49+
;';
50+
pwg_query($q);
51+
52+
53+
// +-----------------------------------------------------------------------+
54+
// | edit places |
55+
// +-----------------------------------------------------------------------+
56+
57+
if (isset($_POST['edit_submit']) and isset($_POST['edit_list']))
58+
{
59+
$query = '
60+
SELECT name
61+
FROM '.osm_place_table.'
62+
;';
63+
$existing_names = array_from_query($query, 'name');
64+
65+
$current_name_of = array();
66+
$query = '
67+
SELECT id, name, latitude, longitude
68+
FROM '.osm_place_table.'
69+
WHERE id IN ('.$_POST['edit_list'].')
70+
;';
71+
$result = pwg_query($query);
72+
while ($row = pwg_db_fetch_assoc($result))
73+
{
74+
$current_name_of[ $row['id'] ] = $row['name'];
75+
}
76+
77+
$updates = array();
78+
// we must not rename tag with an already existing name
79+
foreach (explode(',', $_POST['edit_list']) as $place_id)
80+
{
81+
$place_name = stripslashes($_POST['place_name-'.$place_id]);
82+
$place_lat = stripslashes($_POST['place_lat-'.$place_id]);
83+
$place_lon = stripslashes($_POST['place_lon-'.$place_id]);
84+
85+
if ($place_name != $current_name_of[$place_id])
86+
{
87+
if (in_array($place_name, $existing_names))
88+
{
89+
$page['errors'][] = l10n('Place "%s" already exists', $place_name);
90+
}
91+
else if (!empty($place_name))
92+
{
93+
$updates[] = array(
94+
'id' => $place_id,
95+
'name' => addslashes($place_name),
96+
'latitude' => $place_lat,
97+
'longitude' => $place_lon,
98+
);
99+
}
100+
}
101+
}
102+
mass_updates(
103+
osm_place_table,
104+
array(
105+
'primary' => array('id'),
106+
'update' => array('name', 'latitude', 'longitude'),
107+
),
108+
$updates
109+
);
110+
}
111+
112+
// +-----------------------------------------------------------------------+
113+
// | delete places |
114+
// +-----------------------------------------------------------------------+
115+
116+
if (isset($_POST['delete']) and isset($_POST['places']))
117+
{
118+
$query = '
119+
SELECT name
120+
FROM '.osm_place_table.'
121+
WHERE id IN ('.implode(',', $_POST['places']).')
122+
;';
123+
$place_names = array_from_query($query, 'name');
124+
125+
$query = '
126+
DELETE
127+
FROM '.osm_place_table.'
128+
WHERE id IN ('.implode(',', $_POST['places']).')
129+
;';
130+
pwg_query($query);
131+
132+
$page['infos'][] = l10n_dec(
133+
'The following place was deleted', 'The %d following places were deleted',
134+
count($place_names)
135+
)
136+
.' : '.implode(', ', $place_names);
137+
}
138+
139+
// +-----------------------------------------------------------------------+
140+
// | add a place |
141+
// +-----------------------------------------------------------------------+
142+
if (isset($_POST['add']) and !empty($_POST['add_place']))
143+
{
144+
$query = "INSERT INTO `".osm_place_table."` (`name`, `latitude`, `longitude`) VALUE ('". $_POST['add_place'] ."', '". $_POST['add_lat'] ."', '". $_POST['add_lon'] ."');";
145+
$result = pwg_query($query);
146+
}
147+
148+
// all places
149+
$query = 'SELECT * FROM `'.osm_place_table.'`;';
150+
$result = pwg_query($query);
151+
$all_places = array();
152+
while ($place = pwg_db_fetch_assoc($result))
153+
{
154+
$all_places[] = $place;
155+
}
156+
157+
// Send value to templates
158+
$template->assign(
159+
array(
160+
'OSM_PATH' => OSM_PATH,
161+
'all_places' => $all_places,
162+
)
163+
);
164+
165+
if (isset($_POST['edit']) and isset($_POST['places']))
166+
{
167+
$list_name = 'EDIT_PLACES_LIST';
168+
if (isset($_POST['duplicate']))
169+
{
170+
$list_name = 'DUPLIC_TAGS_LIST';
171+
}
172+
elseif (isset($_POST['merge']))
173+
{
174+
$list_name = 'MERGE_TAGS_LIST';
175+
}
176+
177+
$template->assign($list_name, implode(',', $_POST['places']));
178+
179+
$query = '
180+
SELECT id, name, latitude, longitude
181+
FROM '.osm_place_table.'
182+
WHERE id IN ('.implode(',', $_POST['places']).')
183+
;';
184+
$result = pwg_query($query);
185+
while ($row = pwg_db_fetch_assoc($result))
186+
{
187+
$template->append(
188+
'places',
189+
array(
190+
'ID' => $row['id'],
191+
'NAME' => $row['name'],
192+
'LATITUDE' => $row['latitude'],
193+
'LONGITUDE' => $row['longitude'],
194+
)
195+
);
196+
}
197+
}
198+
199+
200+
?>

admin/admin_place.tpl

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{html_head}
2+
<link rel="stylesheet" href="{$OSM_PATH}fontello/css/osm.css" />
3+
{/html_head}
4+
5+
{html_style}
6+
.showInfo { text-indent:5px; }
7+
{/html_style}
8+
9+
Create place to allow reuse of location.
10+
<br/><br/>
11+
Refer to the <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/wiki" target="_blanck">plugin documentation</a> for additional information. Create an <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/issues" target="_blanck">issue</a> for support, or feedback, or feature request.
12+
13+
{footer_script require='jquery'}
14+
jQuery('.showInfo').tipTip({
15+
'delay' : 0,
16+
'fadeIn' : 200,
17+
'fadeOut' : 200,
18+
'maxWidth':'300px',
19+
'keepAlive':true,
20+
'activation':'click'
21+
});
22+
23+
function displayDeletionWarnings() {
24+
jQuery(".warningDeletion").show();
25+
jQuery("input[name=destination_tag]:checked").parent("label").children(".warningDeletion").hide();
26+
}
27+
28+
displayDeletionWarnings();
29+
30+
jQuery("#mergeTags label").click(function() {
31+
displayDeletionWarnings();
32+
});
33+
34+
jQuery("input[name=merge]").click(function() {
35+
if (jQuery("ul.tagSelection input[type=checkbox]:checked").length < 2) {
36+
alert("{'Select at least two places for merging'|@translate}");
37+
return false;
38+
}
39+
});
40+
41+
$("#searchInput").on("keydown", function(e) {
42+
var $this = $(this),
43+
timer = $this.data("timer");
44+
45+
if (timer) {
46+
clearTimeout(timer);
47+
}
48+
49+
$this.data("timer", setTimeout(function() {
50+
var val = $this.val();
51+
if (!val) {
52+
$(".tagSelection>li").show();
53+
$("#filterIcon").css("visibility","hidden");
54+
}
55+
else {
56+
$("#filterIcon").css("visibility","visible");
57+
var regex = new RegExp( val.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"), "i" );
58+
$(".tagSelection>li").each(function() {
59+
var $li = $(this),
60+
text = $.trim( $("label", $li).text() );
61+
$li.toggle(regex.test(text));
62+
});
63+
}
64+
65+
}, 300) );
66+
67+
if (e.keyCode == 13) { // Enter
68+
e.preventDefault();
69+
}
70+
});
71+
{/footer_script}
72+
73+
<form action="" method="post" id="update">
74+
{if isset($EDIT_PLACES_LIST)}
75+
<fieldset>
76+
<legend>{'Edit places'|@translate}</legend>
77+
<input type="hidden" name="edit_list" value="{$EDIT_PLACES_LIST}">
78+
<table class="table2">
79+
<tr class="throw">
80+
<th>{'Current'|@translate}</th>
81+
<th>{'New'|@translate}</th>
82+
</tr>
83+
{foreach from=$places item=place}
84+
<tr>
85+
<td style="border-top: 1px dashed #005E89;">{$place.NAME}</td>
86+
<td style="border-top: 1px dashed #005E89;"><input type="text" name="place_name-{$place.ID}" value="{$place.NAME}" size="50"></td>
87+
<tr>
88+
</tr>
89+
<td>{$place.LATITUDE}</td>
90+
<td><input type="text" name="place_lat-{$place.ID}" value="{$place.LATITUDE}" size="40"></td>
91+
<tr>
92+
</tr>
93+
<td>{$place.LONGITUDE}</td>
94+
<td><input type="text" name="place_lon-{$place.ID}" value="{$place.LONGITUDE}" size="40"></td>
95+
</tr>
96+
{/foreach}
97+
</table>
98+
99+
<p>
100+
<input type="submit" name="edit_submit" value="{'Submit'|@translate}">
101+
<input type="submit" name="edit_cancel" value="{'Cancel'|@translate}">
102+
</p>
103+
</fieldset>
104+
{/if}
105+
106+
<fieldset>
107+
<legend>{'Add a place'|@translate}</legend>
108+
<ul>
109+
<li>
110+
<label>{'New place'|@translate} : </label>
111+
<input type="text" name="add_place" size="50" require="" placeholder="Home">
112+
</li>
113+
<li>
114+
<label>{'Latitude'|@translate} : </label>
115+
<input type="text" name="add_lat" size="40" require="" placeholder="48.858">
116+
</li>
117+
<li>
118+
<label>{'Longitude'|@translate} : </label>
119+
<input type="text" name="add_lon" size="40" require="" placeholder="2.2942">
120+
</li>
121+
</ul>
122+
123+
<p><input class="submit" type="submit" name="add" value="{'Submit'|@translate}"></p>
124+
</fieldset>
125+
126+
<fieldset>
127+
<legend>{'Place selection'|@translate}</legend>
128+
129+
{if count($all_places)}
130+
<div><label><span class="icon-filter" style="visibility:hidden" id="filterIcon"></span>{'Search'|@translate}: <input id="searchInput" type="text" size="12"></label></div>
131+
{/if}
132+
133+
<ul class="tagSelection">
134+
{foreach from=$all_places item=place}
135+
<li>
136+
{capture name='showInfo'}{strip}
137+
<b>{$place.name}</b><br>
138+
{/strip}{/capture}
139+
<a class="icon-info-circled-1 showInfo" title="{$smarty.capture.showInfo|@htmlspecialchars}"></a>
140+
<label>
141+
<input type="checkbox" name="places[]" value="{$place.id}"> {$place.name}
142+
</label>
143+
</li>
144+
{/foreach}
145+
</ul>
146+
147+
<p>
148+
<input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
149+
<input type="submit" name="edit" value="{'Edit selected places'|@translate}">
150+
<input type="submit" name="duplicate" value="{'Duplicate selected places'|@translate}">
151+
<input type="submit" name="delete" value="{'Delete selected places'|@translate}" onclick="return confirm('{'Are you sure?'|@translate}');">
152+
</p>
153+
</fieldset>
154+
155+
</form>

0 commit comments

Comments
 (0)