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

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

[edit_gmaps] compatibility with piwigo 2.2

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