1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | if (!defined('EDIT_RV_ROOT')) |
---|
5 | define( 'EDIT_RV_ROOT', PHPWG_PLUGINS_PATH.'edit_gmaps/admin/' ); |
---|
6 | |
---|
7 | global $lang; |
---|
8 | load_language('lang', dirname(__FILE__).'/../'); |
---|
9 | $admin_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
10 | if (file_exists ( 'themes/default/js/jquery.packed.js')) |
---|
11 | { |
---|
12 | //version 2.1 |
---|
13 | |
---|
14 | $icon_path = 'themes/default/icon/help.png'; |
---|
15 | $path_js= 'themes/default/js/' ; |
---|
16 | |
---|
17 | } |
---|
18 | else |
---|
19 | { |
---|
20 | // version < 1.9 |
---|
21 | $path_js= "template-common/lib/"; |
---|
22 | $icon_path = "admin/template/goto/theme/clear/icon/help.png"; |
---|
23 | } |
---|
24 | $sql="SELECT * |
---|
25 | FROM `".$prefixeTable."plugins` |
---|
26 | WHERE `id` LIKE 'edit_gmaps' |
---|
27 | "; |
---|
28 | $result = @pwg_query($sql); |
---|
29 | if ($result) { |
---|
30 | $versions = mysql_fetch_array($result,MYSQL_ASSOC); |
---|
31 | } |
---|
32 | $version= $versions['version']; |
---|
33 | |
---|
34 | if ( !isset($_GET['cat']) ) |
---|
35 | $_GET['cat'] = 'caddie'; |
---|
36 | $_GET['mode'] = 'map'; |
---|
37 | include (PHPWG_ROOT_PATH.'admin/element_set.php'); |
---|
38 | |
---|
39 | |
---|
40 | $template->concat('TABSHEET_TITLE', ' '.l10n_dec('%d element', '%d elements', count($page['cat_elements_id'])).' - '.$page['title']); |
---|
41 | |
---|
42 | |
---|
43 | $template->assign( |
---|
44 | array( |
---|
45 | 'EDIT_RV_ROOT' => EDIT_RV_ROOT) |
---|
46 | ); |
---|
47 | |
---|
48 | |
---|
49 | if ( isset($_POST['submit']) and !is_adviser() ) |
---|
50 | { |
---|
51 | |
---|
52 | |
---|
53 | $collection = array(); |
---|
54 | $_POST['target']=isset($_POST['target']) ? $_POST['target']: "" ; |
---|
55 | switch ($_POST['target']) |
---|
56 | { |
---|
57 | case 'all' : |
---|
58 | $collection = $page['cat_elements_id']; |
---|
59 | break; |
---|
60 | case 'selection' : |
---|
61 | if (!isset($_POST['selection']) or count($_POST['selection']) == 0) |
---|
62 | array_push($page['errors'], l10n('Select at least one picture')); |
---|
63 | else |
---|
64 | $collection = $_POST['selection']; |
---|
65 | break; |
---|
66 | } |
---|
67 | //=========================================================================== |
---|
68 | $match=""; |
---|
69 | |
---|
70 | if ( count($collection)>0 ) |
---|
71 | { |
---|
72 | |
---|
73 | $lat = trim($_POST['lat']); |
---|
74 | $lon = trim($_POST['lon']); |
---|
75 | |
---|
76 | if ( strlen($lat)>0 and strlen($lon)>0 ) |
---|
77 | { |
---|
78 | if ( (double)$lat<=90 and (double)$lat>=-90 |
---|
79 | and (double)$lon<=180 and (double)$lat>=-180 ) |
---|
80 | $update_query = 'lat='.$lat.', lon='.$lon; |
---|
81 | else |
---|
82 | $page['errors'][] = 'Invalid lat or lon value'; |
---|
83 | } |
---|
84 | elseif ( strlen($lat)==0 and strlen($lon)==0 ) |
---|
85 | $update_query = 'lat=NULL, lon=NULL'; |
---|
86 | else |
---|
87 | $page['errors'][] = 'Both lat/lon must be empty or not empty'; |
---|
88 | |
---|
89 | if ($_POST['submit']=='Valider' ) |
---|
90 | { |
---|
91 | if (isset($update_query)) |
---|
92 | { |
---|
93 | $update_query = ' |
---|
94 | UPDATE '.IMAGES_TABLE.' SET '.$update_query.' |
---|
95 | WHERE id IN ('.implode(',',$collection).')'; |
---|
96 | pwg_query($update_query); |
---|
97 | rvm_invalidate_cache(); |
---|
98 | } |
---|
99 | $_POST['selection']=array(); |
---|
100 | unset($collection); |
---|
101 | |
---|
102 | } |
---|
103 | } |
---|
104 | //=========================================================================== |
---|
105 | |
---|
106 | if ($_POST['submit']==l10n('reset' ) ) |
---|
107 | { |
---|
108 | $_POST['selection']=array(); |
---|
109 | unset($collection); |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | if ($_POST['submit']==l10n('search_title' )) |
---|
115 | { |
---|
116 | |
---|
117 | $match = $_POST['match'] ; |
---|
118 | |
---|
119 | |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | $template->append( |
---|
124 | 'specials', |
---|
125 | array( |
---|
126 | $admin_url.get_query_string_diff(array('start','cat')).'&cat=caddie' => l10n('Caddie') |
---|
127 | ), |
---|
128 | true |
---|
129 | ); |
---|
130 | |
---|
131 | $query = ' |
---|
132 | SELECT id,name,uppercats,global_rank |
---|
133 | FROM '.CATEGORIES_TABLE.' |
---|
134 | ;'; |
---|
135 | $result = pwg_query($query); |
---|
136 | $categories = array(); |
---|
137 | $selecteds = array(); |
---|
138 | if (!empty($result)) |
---|
139 | { |
---|
140 | while ($row = mysql_fetch_assoc($result)) |
---|
141 | { |
---|
142 | $url = $admin_url.get_query_string_diff(array('start','cat')).'&cat='.$row['id']; |
---|
143 | if ( $row['id']==$_GET['cat'] ) $selecteds[] = $url; |
---|
144 | $row['id']=$url; |
---|
145 | array_push($categories, $row); |
---|
146 | } |
---|
147 | } |
---|
148 | usort($categories, 'global_rank_compare'); |
---|
149 | display_select_categories($categories, $selecteds, 'categories', false); |
---|
150 | |
---|
151 | if (!empty($_GET['display'])) |
---|
152 | { |
---|
153 | if ('all' == $_GET['display']) |
---|
154 | $page['nb_images'] = count($page['cat_elements_id']); |
---|
155 | else |
---|
156 | $page['nb_images'] = intval($_GET['display']); |
---|
157 | } |
---|
158 | else |
---|
159 | $page['nb_images'] = 20; |
---|
160 | |
---|
161 | if ( !empty($page['cat_elements_id']) ) |
---|
162 | { |
---|
163 | $nav_bar = create_navigation_bar( |
---|
164 | $admin_url.get_query_string_diff(array('start')), |
---|
165 | count($page['cat_elements_id']), |
---|
166 | $page['start'], |
---|
167 | $page['nb_images'] |
---|
168 | ); |
---|
169 | $template->assign('NAV_BAR', $nav_bar); |
---|
170 | } |
---|
171 | |
---|
172 | $images=array(); |
---|
173 | if ( !empty($page['cat_elements_id']) ) |
---|
174 | { |
---|
175 | $query=' |
---|
176 | SELECT id,tn_ext,name,path,file,lat,lon FROM '.IMAGES_TABLE.' |
---|
177 | WHERE id IN ('.implode(',',$page['cat_elements_id']).') |
---|
178 | '.$conf['order_by'].' |
---|
179 | LIMIT '.$page['start'].', '.$page['nb_images'].' |
---|
180 | ;'; |
---|
181 | $result = pwg_query($query); |
---|
182 | while ( $row=mysql_fetch_assoc($result) ) |
---|
183 | $images[] = $row; |
---|
184 | } |
---|
185 | //================================================================================= |
---|
186 | foreach ($images as $image) |
---|
187 | { |
---|
188 | $tpl_var = array_merge( $image, |
---|
189 | array( |
---|
190 | 'U_TN' => get_thumbnail_url($image), |
---|
191 | 'TITLE' => get_thumbnail_title($image) |
---|
192 | ) |
---|
193 | ); |
---|
194 | |
---|
195 | if ( isset($image['lat']) ) |
---|
196 | $tpl_var['U_MAP'] = rvm_make_map_picture_url( array('image_id'=>$image['id'], 'image_file'=>$image['file']) ); |
---|
197 | $template->append('thumbnails', $tpl_var); |
---|
198 | } |
---|
199 | |
---|
200 | //=================================================================================== |
---|
201 | $template->assign( |
---|
202 | array( 'path_js' => $path_js, |
---|
203 | 'U_DISPLAY'=> $admin_url.get_query_string_diff(array('display')), |
---|
204 | 'VERSION'=> $version, |
---|
205 | ) |
---|
206 | ); |
---|
207 | //================================================================================== |
---|
208 | $template->assign( |
---|
209 | array( |
---|
210 | 'GMAPS_API_KEY' => $conf['gmaps_api_key'], |
---|
211 | ) |
---|
212 | ); |
---|
213 | //================================================================================== |
---|
214 | $src=""; |
---|
215 | |
---|
216 | if (isset($collection)) |
---|
217 | { |
---|
218 | $lat =1000; |
---|
219 | |
---|
220 | if ($match<>"" && $match<>"/" ) |
---|
221 | { |
---|
222 | $match=str_replace(" ","+",$match); |
---|
223 | $src="http://maps.google.com/maps/geo?q=".$match."&output=xml&sensor=true_or_false&key=".$conf['gmaps_api_key']; |
---|
224 | //json,kml,xml,csv |
---|
225 | |
---|
226 | $location = file_get_contents($src); |
---|
227 | $location = explode("coordinates>",$location ); |
---|
228 | $location = explode(",",$location[1]); |
---|
229 | $lat=$location[1]; |
---|
230 | $lon=$location[0]; |
---|
231 | |
---|
232 | $template->assign( array('lat' => $lat , |
---|
233 | 'lon' => $lon ,)); |
---|
234 | $template->assign( 'coordinates', |
---|
235 | array('LAT' => $lat, |
---|
236 | 'LON' => $lon, |
---|
237 | ) |
---|
238 | ); |
---|
239 | } |
---|
240 | |
---|
241 | foreach ($collection as $id_0) { |
---|
242 | foreach ($images as $image) { |
---|
243 | |
---|
244 | if (array_search($id_0,$image)) { |
---|
245 | if ($lat==1000) { |
---|
246 | $lat= ($image['lat'] <> '') ? $image['lat'] : '100' ; |
---|
247 | $lon= ($image['lon'] <> '') ? $image['lon'] : '3.0' ; |
---|
248 | |
---|
249 | $template->assign( array('zoom' => 4,'lat' => $lat , 'lon' => $lon , ) ); |
---|
250 | $template->assign( 'coordinates', |
---|
251 | array('LAT' => $lat, |
---|
252 | 'LON' => $lon, |
---|
253 | ) |
---|
254 | ); |
---|
255 | |
---|
256 | } |
---|
257 | |
---|
258 | $tpl_var = array_merge( |
---|
259 | $image, |
---|
260 | array( |
---|
261 | 'src' => $src , |
---|
262 | 'match' => $_POST['match'] , |
---|
263 | 'check' => $_POST['submit'] , |
---|
264 | 'U_TN' => get_thumbnail_url($image), |
---|
265 | 'TITLE' => get_thumbnail_title($image), |
---|
266 | 'U_MAP' => rvm_make_map_picture_url( |
---|
267 | array( |
---|
268 | 'image_id'=>$image['id'], |
---|
269 | 'image_file'=>$image['file'], |
---|
270 | ) |
---|
271 | |
---|
272 | ), |
---|
273 | ) |
---|
274 | ); |
---|
275 | |
---|
276 | $template->append('Selectthumbnails', $tpl_var); |
---|
277 | |
---|
278 | } |
---|
279 | } |
---|
280 | } |
---|
281 | |
---|
282 | |
---|
283 | } |
---|
284 | if (isset($_POST['submit']) ) |
---|
285 | { if ($_POST['submit']==l10n('Submit') ) |
---|
286 | { |
---|
287 | $_POST['selection']=array(); |
---|
288 | $collection =array(); |
---|
289 | } |
---|
290 | } |
---|
291 | //======================================================================= |
---|
292 | |
---|
293 | ?> |
---|