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

Last change on this file since 8960 was 8960, checked in by cljosse, 13 years ago

[edit_gmaps] compatibility with piwigo 2.2 (Add element_set.php)

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';
6
7
8
9if ( !isset($_GET['cat']) )   $_GET['cat'] = 'caddie';
10$_GET['mode'] = 'map';
11if (PHPWG_VERSION < 2.2 ) 
12 include (PHPWG_ROOT_PATH.'admin/element_set.php');
13else 
14include (dirname(__FILE__).'\element_set.php');
15
16$template->concat('TABSHEET_TITLE', ' '.l10n_dec('%d image', '%d images', count($page['cat_elements_id'])).' - '.$page['title']);
17if ( isset($_POST['submit']) and !is_adviser() )
18{
19  $collection = array();
20  if( !isset ($_POST['target']))
21  {
22  $_POST['submit'] == l10n('Submit') ;
23  $_POST['target']='selection';
24    $collection = $_POST['selection'];
25
26  }
27
28  switch ($_POST['target'])
29  {
30    case 'all' :
31      $collection = $page['cat_elements_id'];
32      break;
33    case 'selection' :
34      if (!isset($_POST['selection']) or count($_POST['selection']) == 0)
35        array_push($page['errors'], l10n('Select at least one picture'));
36      else
37        $collection = $_POST['selection'];
38      break;
39  }
40 
41
42  // test si mise à jour (valider)
43  if ( isset($_POST['submit']) and  $_POST['submit'] == l10n('Submit') )
44    {
45          if ( count($collection)>0 )
46          {
47                $lat = trim($_POST['lat']);
48                $lon = trim($_POST['lon']);
49
50                if ( strlen($lat)>0 and strlen($lon)>0 )
51                {
52                  if ( (double)$lat<=90 and (double)$lat>=-90
53                          and (double)$lon<=180 and (double)$lat>=-180 )
54                        $update_query = 'lat='.$lat.', lon='.$lon;
55                  else
56                        $page['errors'][] = 'Invalid lat or lon value';
57                }
58                elseif ( strlen($lat)==0 and strlen($lon)==0 )
59                  $update_query = 'lat=NULL, lon=NULL';
60                else
61                  $page['errors'][] = 'Both lat/lon must be empty or not empty';
62
63                if (isset($update_query))
64                {
65                  $update_query = '
66                        UPDATE '.IMAGES_TABLE.' SET '.$update_query.'
67                        WHERE id IN ('.implode(',',$collection).')';
68                  pwg_query($update_query);
69                  clm_invalidate_cache();
70                }
71          }
72        }
73}
74
75
76$template->append(
77  'specials',
78  array(
79                $admin_url.get_query_string_diff(array('start','cat')).'&amp;cat=caddie' => l10n('Caddie')
80    ),
81        true
82  );
83
84$query = '
85SELECT id,name,uppercats,global_rank
86  FROM '.CATEGORIES_TABLE.'
87;';
88$result = pwg_query($query);
89$categories = array();
90$selecteds = array();
91if (!empty($result))
92{
93  while ($row = mysql_fetch_assoc($result))
94  {
95    $url = $admin_url.get_query_string_diff(array('start','cat')).'&amp;cat='.$row['id'];
96    if ( $row['id']==$_GET['cat'] ) $selecteds[] = $url;
97    $row['id']=$url;
98    array_push($categories, $row);
99  }
100}
101usort($categories, 'global_rank_compare');
102display_select_categories($categories, $selecteds, 'categories', false);
103
104if (!empty($_GET['display']))
105{
106  if ('all' == $_GET['display'])
107    $page['nb_images'] = count($page['cat_elements_id']);
108  else
109    $page['nb_images'] = intval($_GET['display']);
110}
111else
112  $page['nb_images'] = 20;
113
114if ( !empty($page['cat_elements_id']) )
115{
116  $nav_bar = create_navigation_bar(
117    $admin_url.get_query_string_diff(array('start')),
118    count($page['cat_elements_id']),
119    $page['start'],
120    $page['nb_images']
121    );
122  $template->assign('navbar', $nav_bar);
123}
124
125$images=array();
126if ( !empty($page['cat_elements_id']) )
127{
128  $query='
129SELECT id,tn_ext,name,path,file,lat,lon FROM '.IMAGES_TABLE.'
130  WHERE id IN ('.implode(',',$page['cat_elements_id']).')
131  '.$conf['order_by'].'
132  LIMIT '.$page['start'].', '.$page['nb_images'].'
133;';
134  $result = pwg_query($query);
135  while ( $row=mysql_fetch_assoc($result) )
136    $images[] = $row;
137}
138
139foreach ($images as $image)
140{
141        $tpl_var = array_merge( $image,
142      array(
143        'U_TN' => get_thumbnail_url($image),
144        'TITLE' => get_thumbnail_title($image)
145      )
146    );
147  if ( isset($image['lat']) )
148    $tpl_var['U_MAP'] = cl_make_map_picture_url( array('image_id'=>$image['id'], 'image_file'=>$image['file']) );
149        $template->append('thumbnails', $tpl_var);
150}
151
152$template->assign(
153    array(
154      'U_DISPLAY'=> $admin_url.get_query_string_diff(array('display'))
155    ) 
156  );
157
158//==========================================================
159        if (!defined('EDIT_RV_ROOT')) define(  'EDIT_RV_ROOT',  PHPWG_PLUGINS_PATH.'edit_gmaps/admin/' ); 
160        $path = EDIT_RV_PATH;
161    $plg_data = implode( '', file($path.'main.inc.php') );
162         if (preg_match("|Version: (.*)|", $plg_data, $val))
163          { $edit_rv_plugin['version'] = trim($val[1]);  } 
164    $edit_rv_plugin = array_map('htmlspecialchars', $edit_rv_plugin); 
165        $version= $edit_rv_plugin['version'] ;
166        $icon_path = 'themes/default/icon/help.png';
167        $path_js=  'themes/default/js/' ; 
168
169//==================================================================================
170$match=""; 
171if ( isset($_POST['submit']) and !is_adviser() )
172{       
173
174  if ($_POST['submit']==l10n('Submit') )
175   {
176      $_POST['selection']=array(); 
177      $collection =array(); 
178          unset($collection); 
179  }
180 
181
182 if ($_POST['submit']==l10n('reset' ) )
183                {
184                        $_POST['selection']=array();
185                        unset($collection);
186                }
187 
188
189 }
190//=================================================================================
191$src="";
192$template->assign(
193    array(      'EDIT_RV_ROOT' => EDIT_RV_ROOT,
194                'path_js' => $path_js,
195            'VERSION'=> $version,
196            'EDIT_RV_ROOT_ABS' => dirname(__FILE__).'/',
197              ) 
198  );
199  global $lang_info;
200if (date_default_timezone_get()) { $adresse =  date_default_timezone_get()   ;}
201else{
202
203}
204$adresse =  $lang_info['country'];   ;
205$adresse=str_replace("/",", ",$adresse);
206$template->assign( 'coordinates',
207                                                   array('LAT' => '100',
208                                                                                 'LON' => '100',
209                                                                                 'ADRESSE' => $adresse,
210                                                                                 'ZOOM' => 18,
211                                                                                )
212                                                                        );
213if (isset($_POST['submit']) and $_POST['submit']==l10n('selection' ))
214{
215
216if (isset($collection)) 
217{   
218    $lat =1000;
219  foreach ($collection as $id_0)  {
220                foreach ($images as $image)  {
221                        if (array_search($id_0,$image)) { 
222                          $_POST['selection'] = $collection ;
223
224                          if ($lat==1000) {
225                            $lat1= ($image['lat'] <> '') ? $image['lat'] : '100'  ;
226                                $lon1= ($image['lon']  <> '') ? $image['lon'] : '3.0'  ;
227                                if($lat1 != '100') $lat=$image['lat'];
228                               
229                                $template->assign( 'coordinates',
230                                                   array('LAT' =>   $lat1  ,
231                                                                                 'LON' =>   $lon1  ,
232                                                                                 'ADRESSE' =>  $adresse ,
233                                                                                 'ZOOM' => 4,
234                                                                                )
235                                                                        );
236
237                                }
238
239                         $tpl_var = array_merge( 
240                                    $image,
241                                        array(
242                                                   'lat'  =>   $image['lat']    ,
243                                                   'lon' =>  $image['lon']    ,
244                                                   'adresse' =>  $adresse   ,
245                                                'U_TN' => get_thumbnail_url($image),
246                                                'TITLE' => get_thumbnail_title($image),
247                                                        'U_MAP' => cl_make_map_picture_url(
248                                                                                            array(
249                                                                                                 'image_id'=>$image['id'],
250                                                                                                 'image_file'=>$image['file'],
251                                                                                                 ) 
252
253                                                                                    ),
254                                                                )                                                               
255                                                );
256         
257                                $template->append('Selectthumbnails', $tpl_var);                       
258                        }
259                }       
260        }
261  }
262}
263
264  //=======================================================================
265function cl_make_map_picture_url($params)
266{
267        global $conf;
268        /*if ( empty($conf['gmaps_api_key']) and $_SERVER['SERVER_ADDR']!='127.0.0.1' )
269                return "";*/
270        $map_url = make_picture_url($params);
271        return add_url_params($map_url, array('map'=>null) );
272}
273?>
Note: See TracBrowser for help on using the repository browser.