1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | if ( isset($_POST['submit']) ) |
---|
5 | $sync_options = array( |
---|
6 | 'simulate' => isset($_POST['simulate']), |
---|
7 | 'use_high' => isset($_POST['use_high']), |
---|
8 | 'cat_id' => isset($_POST['cat_id']) ? (int)$_POST['cat_id'] : 0, |
---|
9 | 'subcats_included' => isset($_POST['subcats_included']), |
---|
10 | ); |
---|
11 | else |
---|
12 | $sync_options = array( |
---|
13 | 'simulate' => true, |
---|
14 | 'use_high' => true, |
---|
15 | 'cat_id' => 0, |
---|
16 | 'subcats_included' => true, |
---|
17 | ); |
---|
18 | |
---|
19 | |
---|
20 | if ( isset($_POST['submit']) ) |
---|
21 | { |
---|
22 | include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); |
---|
23 | include_once( dirname(__FILE__).'/../include/functions_metadata.php' ); |
---|
24 | $where_clauses = array(); |
---|
25 | if ( $sync_options['cat_id']!=0 ) |
---|
26 | { |
---|
27 | $query=' |
---|
28 | SELECT id FROM '.CATEGORIES_TABLE.' |
---|
29 | WHERE '; |
---|
30 | if ( $sync_options['subcats_included']) |
---|
31 | $query .= 'uppercats REGEXP \'(^|,)'.$sync_options['cat_id'].'(,|$)\''; |
---|
32 | else |
---|
33 | $query .= 'id='.$sync_options['cat_id']; |
---|
34 | $cat_ids = array_from_query($query, 'id'); |
---|
35 | |
---|
36 | $query=' |
---|
37 | SELECT id,path,lat,lon,has_high |
---|
38 | FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id |
---|
39 | WHERE category_id IN ('.implode(',', $cat_ids).') |
---|
40 | GROUP BY id'; |
---|
41 | } |
---|
42 | else |
---|
43 | { |
---|
44 | $query=' |
---|
45 | SELECT id,path,lat,lon,has_high |
---|
46 | FROM '.IMAGES_TABLE; |
---|
47 | } |
---|
48 | |
---|
49 | $images = hash_from_query( $query, 'id'); |
---|
50 | $datas = array(); |
---|
51 | $errors = array(); |
---|
52 | foreach ($images as $image) |
---|
53 | { |
---|
54 | $filename = $image['path']; |
---|
55 | if ($sync_options['use_high'] and $image['has_high']=='true') |
---|
56 | $filename = get_high_path($image); |
---|
57 | $exif = @read_exif_data( $filename ); |
---|
58 | if ( empty($exif) ) |
---|
59 | continue; |
---|
60 | $ll = exif_to_lat_lon($exif); |
---|
61 | if (!is_array($ll)) |
---|
62 | { |
---|
63 | if (!empty($ll)) |
---|
64 | $errors[] = $filename. ': '.$ll; |
---|
65 | continue; |
---|
66 | } |
---|
67 | |
---|
68 | $datas[] = array ( |
---|
69 | 'id' => $image['id'], |
---|
70 | 'lat' => $ll[0], |
---|
71 | 'lon' => $ll[1], |
---|
72 | ); |
---|
73 | } |
---|
74 | $template->assign( 'sync_errors', $errors ); |
---|
75 | |
---|
76 | if ( count($datas)>0 and !$sync_options['simulate'] ) |
---|
77 | { |
---|
78 | mass_updates( |
---|
79 | IMAGES_TABLE, |
---|
80 | array( |
---|
81 | 'primary' => array('id'), |
---|
82 | 'update' => array('lat', 'lon') |
---|
83 | ), |
---|
84 | $datas |
---|
85 | ); |
---|
86 | rvm_invalidate_cache(); |
---|
87 | } |
---|
88 | |
---|
89 | $template->assign( |
---|
90 | 'metadata_result', |
---|
91 | array( |
---|
92 | 'NB_ELEMENTS_DONE' => count($datas), |
---|
93 | 'NB_ELEMENTS_CANDIDATES' => count($images), |
---|
94 | 'NB_ERRORS' => count($errors), |
---|
95 | )); |
---|
96 | |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | $query = ' |
---|
101 | SELECT id, |
---|
102 | CONCAT(name, IF(dir IS NULL, " (V)", "") ) AS name, |
---|
103 | uppercats, global_rank |
---|
104 | FROM '.CATEGORIES_TABLE; |
---|
105 | display_select_cat_wrapper($query, |
---|
106 | array( $sync_options['cat_id'] ), |
---|
107 | 'categories', |
---|
108 | false); |
---|
109 | $template->assign( |
---|
110 | array( |
---|
111 | 'SUBCATS_INCLUDED_CHECKED' => $sync_options['subcats_included'] ? 'checked="checked"' : '', |
---|
112 | 'USE_HIGH_CHECKED' => $sync_options['use_high'] ? 'checked="checked"' : '' |
---|
113 | ) |
---|
114 | ); |
---|
115 | |
---|
116 | ?> |
---|