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

Last change on this file since 18635 was 18635, checked in by cljosse, 12 years ago

[extensions] edit_gmaps compatibility 2.4.4 fix bug on global batch_manager

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