source: extensions/edit_gmaps/admin/admin_edit.php @ 6769

Last change on this file since 6769 was 6445, checked in by cljosse, 14 years ago

[Edit_gmaps] update for version piwigo 2.1

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