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

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

[edit_gmaps] adding support to the altitude.

File size: 15.4 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
17                               
18if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
19
20
21/***********************************************************************************/
22  if (!defined('TOOL_KIT_PATH')) define(  'TOOL_KIT_PATH',   EDIT_RV_PATH."admin/");
23  if (!defined('INCLUDE_PATH')) define(  'INCLUDE_PATH',   TOOL_KIT_PATH.'include/' );                     
24  $Toolkit_Dir =INCLUDE_PATH           ;   
25
26   include $Toolkit_Dir . 'fonctions.php';
27/***********************************************************************************/
28
29 
30$template->concat('TABSHEET_TITLE', ' '.l10n_dec('%d image', '%d images', count($page['cat_elements_id'])).' - '.$page['title']);
31
32
33if ( isset($_POST['submit'])  )
34{
35  $collection = array();
36  if( !isset ($_POST['target']))
37  {
38        $_POST['submit'] == l10n('Submit') ;
39        $_POST['target']='selection';
40        $collection = $_POST['selection'];
41
42  }
43
44  switch ($_POST['target'])
45  {
46    case 'all' :
47      $collection = $page['cat_elements_id'];
48      break;
49    case 'selection' :
50      if (!isset($_POST['selection']) or count($_POST['selection']) == 0)
51        array_push($page['errors'], l10n('Select at least one picture'));
52      else
53        $collection = $_POST['selection'];
54      break;
55  } 
56
57  // test si mise à jour (valider)
58  if ( isset($_POST['submit']) and  $_POST['submit'] == l10n('Submit') )
59    {
60          if ( count($collection)>0 )
61          {
62                $lat = trim($_POST['lat']);
63                $lon = trim($_POST['lon']);
64        $alt = trim($_POST['alt']);
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 ( strlen($alt)==0) 
80             $update_query .= ', alt=NULL';
81          else
82             $update_query .= ', alt=' .$alt ;
83
84
85
86                if (isset($update_query))
87                {
88                  $update_query = '
89                        UPDATE '.IMAGES_TABLE.' SET '.$update_query.'
90                        WHERE id IN ('.implode(',',$collection).')';
91                  pwg_query($update_query);
92                  cl_meta_invalidate_cache();
93                }
94          }
95        }
96}
97
98
99$template->append(
100  'specials',
101  array(
102                $admin_url.get_query_string_diff(array('start','cat')).'&amp;cat=caddie' => l10n('Caddie')
103    ),
104        true
105  );
106
107$query = '
108SELECT id,name,uppercats,global_rank
109  FROM '.CATEGORIES_TABLE.'
110;';
111$result = pwg_query($query);
112$categories = array();
113$selecteds = array();
114if (!empty($result))
115{
116  while ($row = mysql_fetch_assoc($result))
117  {
118    $url = $admin_url.get_query_string_diff(array('start','cat')).'&amp;cat='.$row['id'];
119    if ( $row['id']==$_GET['cat'] ) $selecteds[] = $url;
120    $row['id']=$url;
121    array_push($categories, $row);
122  }
123}
124usort($categories, 'global_rank_compare');
125display_select_categories($categories, $selecteds, 'categories', false);
126
127if (!empty($_GET['display']))
128{
129  if ('all' == $_GET['display'])
130    $page['nb_images'] = count($page['cat_elements_id']);
131  else
132    $page['nb_images'] = intval($_GET['display']);
133}
134else
135  $page['nb_images'] = 20;
136
137if ( !empty($page['cat_elements_id']) )
138{
139  $nav_bar = create_navigation_bar(
140    $admin_url.get_query_string_diff(array('start')),
141    count($page['cat_elements_id']),
142    $page['start'],
143    $page['nb_images']
144    );
145  $template->assign('navbar', $nav_bar);
146}
147
148$images=array();
149if ( !empty($page['cat_elements_id']) )
150{
151  $query='
152SELECT id,tn_ext,name,path,file,lat,lon,alt FROM '.IMAGES_TABLE.'
153  WHERE id IN ('.implode(',',$page['cat_elements_id']).')
154  '.$conf['order_by'].'
155  LIMIT '.$page['start'].', '.$page['nb_images'].'
156;';
157  $result = pwg_query($query);
158  while ( $row=mysql_fetch_assoc($result) )
159    $images[] = $row;
160}
161
162foreach ($images as $image)
163{
164        $tpl_var = array_merge( $image,
165      array(
166        'U_TN' => get_thumbnail_url($image),
167        'TITLE' => get_thumbnail_title($image)
168      )
169    );
170  if ( isset($image['lat']) )
171    $tpl_var['U_MAP'] = cl_make_map_picture_url( array('image_id'=>$image['id'], 'image_file'=>$image['file']) );
172        $template->append('thumbnails', $tpl_var);
173}
174
175$template->assign(
176    array(
177      'U_DISPLAY'=> $admin_url.get_query_string_diff(array('display'))
178    ) 
179  );
180
181//==========================================================
182        if (!defined('EDIT_RV_PATH')) define(  'EDIT_RV_PATH',  EDIT_RV_PATH .'admin/' ); 
183        $path = EDIT_RV_PATH;
184    $plg_data = implode( '', file($path.'main.inc.php') );
185         if (preg_match("|Version: (.*)|", $plg_data, $val))
186          { $EDIT_RV_PATH_plugin['version'] = trim($val[1]);  } 
187            $EDIT_RV_PATH_plugin = array_map('htmlspecialchars', $EDIT_RV_PATH_plugin); 
188            $version= $EDIT_RV_PATH_plugin['version'] ;
189            $icon_path = 'themes/default/icon/help.png';
190            $path_js=  'themes/default/js/' ; 
191
192//==================================================================================
193$match=""; 
194if ( isset($_POST['submit'])   )
195{       
196
197  if ($_POST['submit']==l10n('Submit') )
198   {
199      $_POST['selection']=array(); 
200      $collection =array(); 
201          unset($collection); 
202  }
203 
204
205 if ($_POST['submit']==l10n('reset' ) )
206                {
207                        $_POST['selection']=array();
208                        unset($collection);
209                }
210 
211
212 }
213//=================================================================================
214$src="";
215$template->assign(
216    array(      'EDIT_RV_PATH' => EDIT_RV_PATH,
217                'path_js' => $path_js,
218            'VERSION'=> $version,
219            'EDIT_RV_PATH_ABS' => dirname(__FILE__).'/',
220              ) 
221  );
222  global $lang_info;
223if (date_default_timezone_get()) { $adresse =  date_default_timezone_get()   ;}
224else{
225
226}
227$adresse =  $lang_info['country'];   ;
228$adresse=str_replace("/",", ",$adresse);
229$template->assign( 'coordinates',
230                                                   array('LAT' => '100',
231                                                                                 'LON' => '100',
232                                                                                 'ADRESSE' => $adresse,
233                                                                                 'ZOOM' => 18,
234                                         'ALT' => 0
235                                                                                )
236                                                                        ); 
237                                    $filename ="";
238
239if (isset($_POST['submit']) and $_POST['submit']==l10n('selection' ))
240{
241    if (isset($collection))     
242        {  $lat =1000;
243            foreach ($collection as $id_0)  {
244                        foreach ($images as $image)  {
245                                if (array_search($id_0,$image)) { 
246                                    $_POST['selection'] = $collection ;   
247                     
248                        $infos_gps=  Get_exif_gps( $image['path'],$image) ;   
249                        if( $image['lat'] == ''){ 
250                                $image['lat']=$infos_gps['lat'];
251                                $image['lon']=$infos_gps['lon'];
252                                $image['alt']=$infos_gps['alt'];
253                            }else {
254                                $image['lat']=$infos_gps['lat'];
255                                $image['lon']=$infos_gps['lon'];
256                                $image['alt']=$infos_gps['alt'];
257                            }       
258      $filename=  $image;
259   
260         
261                if ($lat==1000) {
262                            $lat= ($image['lat'] <> '') ? $image['lat'] : '100'  ;
263                                $lon= ($image['lon']  <> '') ? $image['lon'] : '3.0'  ;
264                $alt= ($image['alt']  <> '') ? $image['alt'] : '0'  ;
265                                if($lat != '100') $lat=$image['lat'];
266                                //=====================================================
267                                $template->assign( 'coordinates',
268                                                   array('LAT' =>   $lat  ,
269                                                                                 'LON' =>   $lon  ,
270                                                                                 'ADRESSE' =>  $adresse ,
271                                                                                 'ZOOM' => 4,
272                                         'ALT' =>   $alt ,
273                                                                                )
274                                                                        );
275                                }
276                $lonDMS= dec2dms($lon) ;
277                $latDMS= dec2dms($lat) ;
278                if ($infos_gps['lat']=="")
279                  $icon='icon/minus.png';
280                  else $icon='icon/minus.png';
281
282                            $tpl_var = array_merge( 
283                                    $image,
284                                        array(
285                           'icon' => $icon ,
286                                                   'lat'  =>    $image['lat']    ,
287                                                   'lon' =>     $image['lon']    ,
288                           'alt' =>     $image['alt']    , 
289                           'latDMS' =>    $latDMS[3]     ,
290                           'lonDMS' =>   $lonDMS[3]     ,
291                                                   'adresse' =>  $adresse   ,
292                                                'U_TN' => get_thumbnail_url($image),
293                                                'TITLE' => get_thumbnail_title($image),
294                                                        'U_MAP' => cl_make_map_picture_url(
295                                                                                            array(
296                                                                                                 'image_id'=>$image['id'],
297                                                                                                 'image_file'=>$image['file'],
298                                                                                                 ) 
299
300                                                                                    ),
301                                                                )                                                               
302                                                );
303         
304                                $template->append('Selectthumbnails', $tpl_var);                       
305                        }
306                }       
307        }
308  }
309
310} 
311
312
313 if ( !empty($filename))
314 {
315// document.Envoie.latDMS.value
316        $image= $filename ;
317        $filename= $filename['path'] ;
318        $Val_exif="";
319        $Val_XMP="";   
320          // error_reporting ( 0 );
321  // Hide any unknown EXIF tags
322/*
323 $GLOBALS['HIDE_UNKNOWN_TAGS'] = FALSE;
324   include $Toolkit_Dir . 'Toolkit_Version.php';          // Change: added as of version 1.11
325   include $Toolkit_Dir . 'JPEG.php';                     // Change: Allow this example file to be easily relocatable - as of version 1.11
326   include $Toolkit_Dir . 'JFIF.php';
327   include $Toolkit_Dir . 'PictureInfo.php';
328   include $Toolkit_Dir . 'XMP.php';
329   include $Toolkit_Dir . 'Photoshop_IRB.php';
330   include $Toolkit_Dir . 'EXIF.php';
331 
332        $jpeg_header_data = get_jpeg_header_data($filename );
333     */   
334     if (!empty($infos_gps)) 
335     $Position = $infos_gps ;
336
337     else  $Position =  Get_exif_gps($filename,$image) ;
338
339
340
341     $template->assign( array(
342      'filename_abs' =>   $filename , 
343      'filename' => $filename, 
344     'datas'    =>    array(
345     /*     'Val_JPEG_APP'=> Generate_JPEG_APP_Segment_HTML( $jpeg_header_data ),
346        'Val_intrinsic'=> Interpret_intrinsic_values_to_HTML( get_jpeg_intrinsic_values( $jpeg_header_data ) ),
347        'Val_Comment'=> Interpret_Comment_to_HTML( $jpeg_header_data ),
348        'Val_JFIF'=> Interpret_JFIF_to_HTML( get_JFIF( $jpeg_header_data ), $filename ),
349        'Val_JFXX'=>Interpret_JFXX_to_HTML( get_JFXX( $jpeg_header_data ), $filename ),
350        'Val_App12' => Interpret_App12_Pic_Info_to_HTML( $jpeg_header_data ),         
351        'Val_IRB' => Interpret_IRB_to_HTML( get_Photoshop_IRB( $jpeg_header_data ), $filename ),
352
353        'Val_exif'=>  Interpret_EXIF_to_HTML( get_EXIF_JPEG( $filename ), $filename),
354        'Val_XMP' =>  Interpret_XMP_to_HTML( read_XMP_array_from_text( get_XMP_text( $jpeg_header_data) ) ),
355          */ 
356     //
357         ),
358 'Datadase' =>  ($Position) ,
359          ) );
360}
361
362function Memo_vars($variables)
363{
364                ob_start();
365                echo '<pre>';
366                print_r($variables);
367                echo '</pre>';
368                $m= ob_get_contents();
369
370        ob_end_clean();
371                return $m;
372               
373}
374  //=======================================================================
375function cl_make_map_picture_url($params)
376{
377        global $conf;
378        /*if ( empty($conf['gmaps_api_key']) and $_SERVER['SERVER_ADDR']!='127.0.0.1' )
379                return "";*/
380        $map_url = make_picture_url($params);
381        return add_url_params($map_url, array('map'=>null) );
382}
383$v1=0;
384
385
386function Get_exif_gps($filename,$image)
387{
388 error_reporting ( 1 );
389  $datas = array();
390  $errors = array();
391        //     
392
393     // $Exif_array =    get_EXIF_JPEG( $filename );     
394     //  if ( empty($Exif_array) ) return;
395
396     $exif = @read_exif_data( $filename ); 
397 
398
399      if ( empty($exif) ) return;
400         $exif = array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude', 'GPSAltitudeRef', 'GPSAltitude') ) );
401 
402
403       error_reporting ( 1 );
404       /*
405 if ( count($exif)<4)
406                        return;
407 
408
409     if ( !in_array($exif['GPSLatitudeRef'], array('S', 'N') ) )
410                {
411                        $errors[] = $filename. ': GPSLatitudeRef not S or N';
412                        return;
413                }
414                if ( !in_array($exif['GPSLongitudeRef'], array('W', 'E') ) )
415                {
416                        $errors[] = $filename. ': GPSLongitudeRef not W or E';
417                        return;
418                }
419                if (!is_array($exif['GPSLatitude']) or !is_array($exif['GPSLongitude']) )
420                {
421                        $errors[] = $filename. ': GPSLatitude and GPSLongitude are not arrays';
422                        return;
423                }       
424*/
425
426
427    $lat = $image['lat'] ;         
428    $lon = $image['lon'] ; 
429    $alt=$image['alt'];
430
431if ($lat =="") 
432{ 
433  $lat = Parse_Lat_Lon( $exif['GPSLatitude'] ); 
434  if ( $exif['GPSLatitudeRef']=='S' )$lat = -$lat;
435     $latDMS=$exif['GPSLatitude'][0] . " | " . $exif['GPSLatitude'][1]. " | " . $exif['GPSLatitude'][2] ;
436
437}else{
438
439    if($lat<0)      $exif['GPSLatitudeRef']='S' ;
440        else        $exif['GPSLatitudeRef']='N' ;
441        $latDMS=dec2dms($lat);
442        $exif['GPSLatitude']= $latDMS ;
443}         
444global $errors;
445if (!is_array($exif['GPSLatitude']) or !is_array($exif['GPSLongitude']) )
446                {
447                        $errors[] = $filename. ': GPSLatitude and GPSLongitude are not arrays';
448                        //return;
449                }       
450
451      if ($lon =="") {
452       
453            $lon = parse_lat_lon( $exif['GPSLongitude'] );
454            $lonDMS= $exif['GPSLongitude'][0] . " | " . $exif['GPSLongitude'][1] . " | " . $exif['GPSLongitude'][2] ;
455  if ( $exif['GPSLongitudeRef']=='W' ) $lon = -$lon;
456           }else{
457             if ($lon<0) $exif['GPSLongitudeRef'] ='W' ;
458             else $exif['GPSLongitudeRef'] ='E' ;
459              $lonDMS=dec2dms($lon);
460                 $exif['GPSLongitude']=$lonDMS ;
461           }
462
463           
464
465//=======================================================================         
466           $altref = 0;
467
468if (!is_array($exif['GPSAltitude']) or !is_array($exif['GPSAltitudeRef']) )
469                {
470                         $exif['GPSAltitude']=$alt;
471             $exif['GPSAltitudeRef']=0;
472                }       else {
473                $alt =           $exif['GPSAltitude'];
474            $altref = $exif['GPSAltitudeRef'];
475        }
476 //========================================================================           
477
478                $datas[] = array (
479            ' filename=' => $filename ,
480                        'id' =>    $image['id'] ,
481                        'lat' =>   $lat ,
482                        'lon' =>   $lon ,
483                        'latDMS' =>     $exif['GPSLatitude'][0]['Numerator']  . "/" .
484                            $exif['GPSLatitude'][0]['Denominator'] . " " .   
485                            $exif['GPSLatitude'][1]['Numerator'] . "/" .
486                            $exif['GPSLatitude'][1]['Denominator']. " " .   
487                            $exif['GPSLatitude'][2]['Numerator'] . "/" .
488                            $exif['GPSLatitude'][2]['Denominator'],
489                        'lonDMS' =>     $exif['GPSLongitude'][0]['Numerator']  . "/" .
490                            $exif['GPSLongitude'][0]['Denominator'] . " " .   
491                            $exif['GPSLongitude'][1]['Numerator'] . "/" .
492                            $exif['GPSLongitude'][1]['Denominator']. " " .   
493                            $exif['GPSLongitude'][2]['Numerator'] . "/" .
494                            $exif['GPSLongitude'][2]['Denominator'],
495            'altref' => $exif['GPSAltitudeRef'],
496            'alt' =>   $exif['GPSAltitude'] ,
497
498                        ); 
499
500return $datas[0] ;
501}
502?> 
Note: See TracBrowser for help on using the repository browser.