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

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

Edit_gmaps Start creation

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