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

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

[extensions] edit_gmaps compatibility 2.4 add batch mode global

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