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