source: extensions/edit_gmaps/admin/admin_edit_meta.php @ 12126

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

[extensions] edit_gmaps add functions

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