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

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

[extensions] edit_gmaps compatibility 2.4

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