source: extensions/edit_gmaps/admin/admin_edit.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: 16.8 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
7if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
8
9/***********************************************************************************/
10if (!defined('TOOL_KIT_PATH')) define(  'TOOL_KIT_PATH',   EDIT_CL_PATH."admin/");
11if (!defined('INCLUDE_PATH')) define(  'INCLUDE_PATH',   TOOL_KIT_PATH.'include/' );
12
13$Toolkit_Dir =INCLUDE_PATH           ;
14
15include $Toolkit_Dir . 'fonctions.php';
16//==========================================================
17if (!defined('EDIT_CL_PATH')) define(  'EDIT_CL_PATH',  EDIT_CL_PATH .'admin/' );
18$path = EDIT_CL_PATH;
19$plg_data = implode( '', file($path.'main.inc.php') );
20if (preg_match("|Version: (.*)|", $plg_data, $val)) { 
21  $EDIT_CL_PATH_plugin['version'] = trim($val[1]); 
22}
23$EDIT_CL_PATH_plugin = array_map('htmlspecialchars', $EDIT_CL_PATH_plugin);
24$version= $EDIT_CL_PATH_plugin['version'] ;
25$icon_path = 'themes/default/icon/help.png';
26$path_js=  'themes/default/js/' ;
27/****************************************************************/
28$info_message="" ;
29$erreur_message=""; 
30/****************************************************************/
31if ( !isset($_GET['cat']) )   $_GET['cat'] = 'caddie';
32$_GET['mode'] = 'map';
33    if (PHPWG_VERSION < 2.2 ) {
34      include (PHPWG_ROOT_PATH.'admin/element_set.php');
35    } else {
36      if (!isset($page['title'])) $page['title']="";
37      include (PHPWG_ROOT_PATH.'admin/batch_manager.php');
38    $template->concat('TABSHEET_TITLE', ' '.l10n_dec('%d image', '%d images', count($page['cat_elements_id'])).' - '.$page['title']);
39  }
40//===============================================================
41$collection = array(); 
42if(!isset($_POST['target'])) $_POST['target']="";
43
44  switch ($_POST['target']){
45    case 'all' :
46      $collection = $page['cat_elements_id'];
47    break;
48    case 'selection' :
49      if (!isset($_POST['selection']) or count($_POST['selection']) == 0)
50        array_push($page['errors'], l10n('Select at least one photo'));
51      else
52        $collection = $_POST['selection'];
53    break;
54  }
55if (isset($_POST['selection'])){}
56//===============================================================       
57  $images=array();   
58if (!empty($_GET['display']))
59{
60  if ('all' == $_GET['display'])
61    $page['nb_images'] = count($page['cat_elements_id']);
62  else
63    $page['nb_images'] = intval($_GET['display']);
64}
65else
66  $page['nb_images'] = 20;
67
68if ( !empty($page['cat_elements_id']) )
69{
70  $query='
71SELECT id,tn_ext,name,path,file,lat,lon,alt FROM '.IMAGES_TABLE.'
72  WHERE id IN ('.implode(',',$page['cat_elements_id']).')
73  '.$conf['order_by'].'
74  LIMIT '.$page['start'].', '.   $page['nb_images'] .'
75;';
76  $result = pwg_query($query);
77  while ( $row=mysql_fetch_assoc($result) )
78    $images[] = $row;
79}
80//===============================================================
81global $lang_info;
82if (date_default_timezone_get()) {
83  $adresse =  date_default_timezone_get()   ;
84}else{
85
86}
87$adresse =  $lang_info['country'];   ;
88$adresse=str_replace("/",", ",$adresse);
89 
90if (count($collection)>0 )
91//=============================================================
92  if (isset($_POST['update']) && $_POST['update']==l10n('update_exif')){
93  /************* Mise à jour des meta données ***************/
94    // error_reporting ( 0 );
95    // Hide any unknown EXIF tags   
96    $GLOBALS['HIDE_UNKNOWN_TAGS'] = FALSE;
97    include $Toolkit_Dir.'Toolkit_Version.php';   // Change: added as of version 1.11
98      // Include the required files for reading and writing Photoshop File Info
99    include  $Toolkit_Dir.'JPEG.php';
100    include  $Toolkit_Dir.'XMP.php';
101    include  $Toolkit_Dir.'Photoshop_IRB.php';
102    include  $Toolkit_Dir.'EXIF.php';
103    include  $Toolkit_Dir.'GPS_File_Info.php';
104
105    $GLOBALS['HTTP_POST_VARS']=$_POST ;
106    // Copy all of the HTML Posted variables into an array
107    $new_ps_file_info_array = $GLOBALS['HTTP_POST_VARS'];
108
109    // Some characters are escaped with backslashes in HTML Posted variable
110    // Cycle through each of the HTML Posted variables, and strip out the slashes '
111
112    foreach( $new_ps_file_info_array as $var_key => $var_val ){
113      if ($var_key !="selection")
114          $new_ps_file_info_array[ $var_key ] = stripslashes( $var_val );
115    }
116   
117      $init_info =true;
118      $first_image="";   
119      $_POST['submit']="";
120
121      foreach ($collection as $id_0){
122          foreach ($images as $image) { 
123            if (array_search($id_0,$image)) {   
124              //=================================================================
125              // Donnée base de donnée
126              //=================================================================
127         //     $info_message .= "<div style='border:2px solid red'>$id_0 Image:" . cl_edit_functions::Memo_vars($image)."</div>" ;
128               
129              //=================================================================
130              // Meta donnée
131              //=================================================================
132                $infos_gps  = array();
133                $infos_gps  = cl_edit_controler::Get_exif_gps( $image['path'],$image,false) ;
134                if($image['lat']=='' || $image['lon']==''){ 
135                    $image['lat']=$infos_gps['lat'];
136                    $image['lon']=$infos_gps['lon'];
137                    $image['alt']=$infos_gps['alt'];
138                }     
139
140                if($image['lat']!=''){
141                      $new_ps_file_info_array=  base_to_meta($image);
142                  }
143
144                $new_ps_file_info_array['filename'] =  $image['path'];
145                $new_ps_file_info_array['selection'] = explode(";",$new_ps_file_info_array['filename']);
146   //   
147          if( $image['lat']=="" ){
148              $image['lat']=  $new_ps_file_info_array['lat'] ;
149              $image['lon']=  $new_ps_file_info_array['lon'] ;
150              $image['alt']=  $new_ps_file_info_array['alt'] ; 
151          }
152        if($_POST['update']==l10n('update_exif')) unset($_POST['submit']);
153        if(1) {
154 
155           if(  cl_edit_controler::add_meta_gps($new_ps_file_info_array,$image)){
156             
157                $exif = @read_exif_data( $image['path']);
158                 $infos_gps  = cl_edit_controler::Get_exif_gps( $image['path'],$image,false) ;
159                $info_message .= $image['path'] . " : " . $image['file'] . " : ok<BR />";
160                }else{
161
162                }
163           }
164        }else{
165         
166        } // fin search
167      }   // fin id_0
168    }     // fin collection     
169    $_POST['update'] ="ok";
170  }
171
172if ( isset($_POST['submit'])  ) {
173  /******** Mise à jour base de données *****/
174   if (   $_POST['submit'] == l10n('update_database') ){
175    if ( count($collection)>0 ){
176        $lat = trim($_POST['lat']);
177        $lon = trim($_POST['lon']);
178        $alt = trim($_POST['alt']);
179        //===============================================================
180       if($lat !="") cl_edit_controler::add_data_base($collection,$lat,$lon,$alt) ;
181        $_POST['submit'] = l10n('Submit') ;
182            foreach ($collection as $id_0){
183          foreach ($images as $image) { 
184            if (array_search($id_0,$image)) { 
185              $image['lat'] =    $lat ;
186              $image['lon']= $lon  ;
187              $image['alt'] =$alt  ;
188           }
189          }
190        } 
191      }
192    }
193 }
194/**************************************/
195
196$specials_selected = null;
197foreach( array('caddie'=>'Caddie', 'recent'=>'Recent photos') as $k => $v){
198    $link = $admin_url.get_query_string_diff(array('start','cat')).'&amp;cat='.$k;
199    $template->append(
200        'specials',
201        array(
202            $link => l10n($v),
203            ),
204        true
205        );
206    if ($k == $_GET['cat']) $specials_selected = $link;
207}
208
209
210$template->assign('specials_selected', $specials_selected);
211/****************************************/
212$query = '
213SELECT id,name,uppercats,global_rank
214  FROM '.CATEGORIES_TABLE.'
215;';
216$result = pwg_query($query);
217$categories = array();
218$selecteds = array();
219if (!empty($result)){
220  while ($row = mysql_fetch_assoc($result))  {
221    $url = $admin_url.get_query_string_diff(array('start','cat')).'&amp;cat='.$row['id'];
222    if ( $row['id']==$_GET['cat'] ) $selecteds[] = $url;
223    $row['id']=$url;
224    array_push($categories, $row);
225  }
226}
227usort($categories, 'global_rank_compare');
228display_select_categories($categories, $selecteds, 'categories', false);
229
230
231if ( !empty($page['cat_elements_id']) ){
232  $nav_bar = create_navigation_bar(
233    $admin_url.get_query_string_diff(array('start')),
234    count($page['cat_elements_id']),
235    $page['start'],
236    $page['nb_images']
237    );
238  $template->assign('navbar', $nav_bar);
239}
240//========================================================================
241  $v_exif="";
242foreach ($images as $image){ 
243 
244    $infos_gps  = array();
245    $infos_gps  =  cl_edit_controler::Get_exif_gps( $image['path'],$image,false) ;
246    $v_exif=$infos_gps['is_exif']?true:false ;   
247    $v_db=false  ; 
248    $v_db=$image['lat']!=0 && $image['lon']!=0;
249
250    if(  $infos_gps['lat'] !=0  || $infos_gps['lon'] !=0 ) { 
251   
252      $new= ( !isset($image['lat'])? true: $image['lat']!=$infos_gps['lat'] ) ;
253      $image['lat']=$infos_gps['lat'];
254      $image['lon']=$infos_gps['lon'];
255      $image['alt']=$infos_gps['alt'];
256      $sel_img= array($image['id']);
257      if ($new) cl_edit_controler::add_data_base( $sel_img,$image['lat'],$image['lon'],$image['alt']) ;             
258   }         
259   //=================================================
260   $tpl_var = array_merge( $image,
261      array(
262        'U_EXIF' => $v_exif,
263        'U_DB' => $v_db,
264        'U_TN' => get_thumbnail_url($image),
265        'TITLE' => get_thumbnail_title($image)
266      ) );
267
268  if ( isset($image['lat']) ){
269    $tpl_var['U_MAP'] = cl_make_map_picture_url( 
270    array('image_id'=>$image['id'],
271          'image_file'=>$image['file']) );
272         } 
273           
274    $template->append('thumbnails', $tpl_var);
275}
276
277
278$template->assign(
279    array(
280      'U_DISPLAY'=> $admin_url.get_query_string_diff(array('display'))
281    )
282  );
283
284
285//==================================================================================
286$match="";
287if ( isset($_POST['submit'])   ) {
288  if ($_POST['submit']==l10n('Submit') ) {
289    $_POST['selection']=array();
290    $collection =array();
291    unset($collection);
292  }
293  if ($_POST['submit']==l10n('reset' ) ) {
294    $_POST['selection']=array();
295    unset($collection);
296  }
297}
298//=================================================================================
299$src="";
300$template->assign(
301    array(  'EDIT_CL_PATH' => EDIT_CL_PATH,
302            'path_js' => $path_js,
303            'VERSION'=> $version,
304            'EDIT_CL_PATH_ABS' => dirname(__FILE__).'/',
305          )
306  );
307 
308$template->assign( 'coordinates',
309                    array(  'FILE' => '',
310                            'LAT' => '100',
311                            'LON' => '100',
312                            'ADRESSE' => $adresse,
313                            'ZOOM' => 18,
314                            'ALT' => 0
315                        )
316                    );
317//======================================================================
318if (isset($_POST['submit']) and $_POST['submit']==l10n('selection' )){
319  if (isset($collection)) {
320    $init_info =true;
321    $first_image=""; 
322    $_POST['selection'] = $collection ;
323    foreach ($collection as $id_0)  {
324        foreach ($images as $image) {
325            if (array_search($id_0,$image)) {   
326              $infos_gps  = array();   
327              if($image['lat']=='' || $image['lon']==''){    }
328              $infos_gps  =array();
329              $infos_gps  =  cl_edit_controler::Get_exif_gps( $image['path'],$image,false) ;
330              if(isset($infos_gps['lat']) && $infos_gps['is_exif']){       
331                $image['lat']=$infos_gps['lat'];
332                $image['lon']=$infos_gps['lon'];
333                $image['alt']=$infos_gps['alt'];
334              }                   
335              if ( $init_info && $image['lat'] <> '' ) {
336                $init_info = false ;
337                $lat = ($image['lat'] <> '') ? $image['lat'] : '100'  ;
338                $lon = ($image['lon']  <> '') ? $image['lon'] : '3.0'  ;
339                $alt = ($image['alt']  <> '') ? $image['alt'] : '0'  ;
340                     
341                //=====================================================
342                $template->assign( 'coordinates',
343                        array(
344                            'FILE' => $image['path'],
345                            'LAT' =>   $lat  ,
346                            'LON' =>   $lon  ,
347                            'ADRESSE' =>  $adresse ,
348                            'ZOOM' => 4,
349                            'ALT' =>  $alt ,
350                              )
351                          );                             
352              }
353              //=====================================================
354                    $lon=$image['lon'];
355                    $lat=$image['lat'];
356                    if($infos_gps['is_exif']) {                                       
357                     $info_message .='EXIF';
358                    }
359                    $lonDMS= dec2dms($lon) ;
360                    $latDMS= dec2dms($lat) ;
361
362                        $v_db=false  ; 
363    $v_db=$lon!=0 && $lat!=0;
364
365                $tpl_var = array_merge(
366                        $image,
367                        array(
368                  'filename' =>  $image['path'],
369                  'exif' => '"'.$infos_gps['is_exif'].'"' ,
370                  'lat'  =>    $image['lat']    ,
371                  'lon' =>     $image['lon']    ,
372                  'alt' =>     $image['alt']    ,
373                  'latDMS' =>    $latDMS[3]     ,
374                  'lonDMS' =>   $lonDMS[3]     ,
375                  'adresse' =>  $adresse   ,
376                  'U_TN' => get_thumbnail_url($image),
377                  'TITLE' => get_thumbnail_title($image),
378                  'U_EXIF' =>  $infos_gps['is_exif'] ,
379                  'U_BD' =>  $v_db ,
380                  'U_MAP' => cl_make_map_picture_url(
381                                                array(
382                                                      'image_id'=>$image['id'],
383                                                      'image_file'=>$image['file'],
384                                                      )
385                                                    ),
386                                  )
387                            );
388          $template->append('Selectthumbnails', $tpl_var);
389        }
390      }
391    }
392  }
393}
394
395//============================================================
396 if ( !empty($first_image)) { 
397   $erreur_message .= cl_edit_functions::Memo_Vars($first_image);
398   
399   if (isset($_POST['update'])) {
400          // document.Envoie.latDMS.value
401          $image= first_image ;
402          $filename=$image['path'] ;
403          $Val_exif="";
404          $Val_XMP="";
405   /*  */
406     if (!empty($infos_gps))
407         $Position = $infos_gps ;
408     else  $Position =  cl_edit_controler::Get_exif_gps($filename,$image,false) ;
409
410      $jpeg_header_data = get_jpeg_header_data($filename );
411      $template->assign( array(
412      'filename_abs' =>   $filename ,
413      'filename' => $filename,
414      'datas'    =>    array(
415/*       
416        'Val_JPEG_APP'=> Generate_JPEG_APP_Segment_HTML( $jpeg_header_data ),
417        'Val_intrinsic'=> Interpret_intrinsic_values_to_HTML( get_jpeg_intrinsic_values( $jpeg_header_data ) ),
418        'Val_Comment'=> Interpret_Comment_to_HTML( $jpeg_header_data ),
419        'Val_JFIF'=> Interpret_JFIF_to_HTML( get_JFIF( $jpeg_header_data ), $filename ),
420        'Val_JFXX'=>Interpret_JFXX_to_HTML( get_JFXX( $jpeg_header_data ), $filename ),
421        'Val_App12' => Interpret_App12_Pic_Info_to_HTML( $jpeg_header_data ),
422        'Val_IRB' => Interpret_IRB_to_HTML( get_Photoshop_IRB( $jpeg_header_data ), $filename ),
423
424        'Val_exif'=>  Interpret_EXIF_to_HTML( get_EXIF_JPEG( $filename ), $filename),
425        'Val_XMP' =>  Interpret_XMP_to_HTML( read_XMP_array_from_text( get_XMP_text( $jpeg_header_data) ) ),
426          */
427     //
428         ),
429          'Datadase' =>  ($Position) ,
430          ) );
431  }
432}
433
434
435  //=======================================================================
436function cl_make_map_picture_url($params)
437{
438    global $conf;
439    /*if ( empty($conf['gmaps_api_key']) and $_SERVER['SERVER_ADDR']!='127.0.0.1' )
440        return "";*/
441    $map_url = make_picture_url($params);
442    return add_url_params($map_url, array('map'=>null) );
443}
444$v1=0;
445
446
447
448
449if ($info_message!="")
450$template->assign('infos',$info_message);
451if ($erreur_message!="")
452$template->assign('errors',$erreur_message);
453
454
455?>
Note: See TracBrowser for help on using the repository browser.