| 1 | <?php |
|---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
|---|
| 3 | global $lang; |
|---|
| 4 | load_language('lang', dirname(__FILE__).'/../'); |
|---|
| 5 | $admin_url = PHPWG_ROOT_PATH.'admin.php'; |
|---|
| 6 | |
|---|
| 7 | $sql="SELECT * |
|---|
| 8 | FROM `".$prefixeTable."plugins` |
|---|
| 9 | WHERE `id` LIKE 'edit_gmaps' |
|---|
| 10 | "; |
|---|
| 11 | $result = @pwg_query($sql); |
|---|
| 12 | if ($result) { |
|---|
| 13 | $versions = mysql_fetch_array($result,MYSQL_ASSOC); |
|---|
| 14 | } |
|---|
| 15 | $version= $versions['version']; |
|---|
| 16 | |
|---|
| 17 | if ( !isset($_GET['cat']) ) |
|---|
| 18 | $_GET['cat'] = 'caddie'; |
|---|
| 19 | $_GET['mode'] = 'map'; |
|---|
| 20 | include (PHPWG_ROOT_PATH.'admin/element_set.php'); |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | $template->concat('TABSHEET_TITLE', ' '.l10n_dec('%d element', '%d elements', count($page['cat_elements_id'])).' - '.$page['title']); |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | if ( isset($_POST['submit']) and !is_adviser() ) |
|---|
| 27 | { |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | $collection = array(); |
|---|
| 31 | $_POST['target']=isset($_POST['target']) ? $_POST['target']: "" ; |
|---|
| 32 | switch ($_POST['target']) |
|---|
| 33 | { |
|---|
| 34 | case 'all' : |
|---|
| 35 | $collection = $page['cat_elements_id']; |
|---|
| 36 | break; |
|---|
| 37 | case 'selection' : |
|---|
| 38 | if (!isset($_POST['selection']) or count($_POST['selection']) == 0) |
|---|
| 39 | array_push($page['errors'], l10n('Select at least one picture')); |
|---|
| 40 | else |
|---|
| 41 | $collection = $_POST['selection']; |
|---|
| 42 | break; |
|---|
| 43 | } |
|---|
| 44 | //=========================================================================== |
|---|
| 45 | $match=""; |
|---|
| 46 | |
|---|
| 47 | if ( count($collection)>0 ) |
|---|
| 48 | { |
|---|
| 49 | |
|---|
| 50 | $lat = trim($_POST['lat']); |
|---|
| 51 | $lon = trim($_POST['lon']); |
|---|
| 52 | |
|---|
| 53 | if ( strlen($lat)>0 and strlen($lon)>0 ) |
|---|
| 54 | { |
|---|
| 55 | if ( (double)$lat<=90 and (double)$lat>=-90 |
|---|
| 56 | and (double)$lon<=180 and (double)$lat>=-180 ) |
|---|
| 57 | $update_query = 'lat='.$lat.', lon='.$lon; |
|---|
| 58 | else |
|---|
| 59 | $page['errors'][] = 'Invalid lat or lon value'; |
|---|
| 60 | } |
|---|
| 61 | elseif ( strlen($lat)==0 and strlen($lon)==0 ) |
|---|
| 62 | $update_query = 'lat=NULL, lon=NULL'; |
|---|
| 63 | else |
|---|
| 64 | $page['errors'][] = 'Both lat/lon must be empty or not empty'; |
|---|
| 65 | |
|---|
| 66 | if ($_POST['submit']=='Valider' ) |
|---|
| 67 | { |
|---|
| 68 | if (isset($update_query)) |
|---|
| 69 | { |
|---|
| 70 | $update_query = ' |
|---|
| 71 | UPDATE '.IMAGES_TABLE.' SET '.$update_query.' |
|---|
| 72 | WHERE id IN ('.implode(',',$collection).')'; |
|---|
| 73 | pwg_query($update_query); |
|---|
| 74 | rvm_invalidate_cache(); |
|---|
| 75 | } |
|---|
| 76 | $_POST['selection']=array(); |
|---|
| 77 | unset($collection); |
|---|
| 78 | |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | //=========================================================================== |
|---|
| 82 | |
|---|
| 83 | if ($_POST['submit']==l10n('reset' ) ) |
|---|
| 84 | { |
|---|
| 85 | $_POST['selection']=array(); |
|---|
| 86 | unset($collection); |
|---|
| 87 | } |
|---|
| 88 | if ($_POST['submit']==l10n('search_title' )) |
|---|
| 89 | { |
|---|
| 90 | $match = $_POST['match'] ; |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | $template->append( |
|---|
| 97 | 'specials', |
|---|
| 98 | array( |
|---|
| 99 | $admin_url.get_query_string_diff(array('start','cat')).'&cat=caddie' => l10n('Caddie') |
|---|
| 100 | ), |
|---|
| 101 | true |
|---|
| 102 | ); |
|---|
| 103 | |
|---|
| 104 | $query = ' |
|---|
| 105 | SELECT id,name,uppercats,global_rank |
|---|
| 106 | FROM '.CATEGORIES_TABLE.' |
|---|
| 107 | ;'; |
|---|
| 108 | $result = pwg_query($query); |
|---|
| 109 | $categories = array(); |
|---|
| 110 | $selecteds = array(); |
|---|
| 111 | if (!empty($result)) |
|---|
| 112 | { |
|---|
| 113 | while ($row = mysql_fetch_assoc($result)) |
|---|
| 114 | { |
|---|
| 115 | $url = $admin_url.get_query_string_diff(array('start','cat')).'&cat='.$row['id']; |
|---|
| 116 | if ( $row['id']==$_GET['cat'] ) $selecteds[] = $url; |
|---|
| 117 | $row['id']=$url; |
|---|
| 118 | array_push($categories, $row); |
|---|
| 119 | } |
|---|
| 120 | } |
|---|
| 121 | usort($categories, 'global_rank_compare'); |
|---|
| 122 | display_select_categories($categories, $selecteds, 'categories', false); |
|---|
| 123 | |
|---|
| 124 | if (!empty($_GET['display'])) |
|---|
| 125 | { |
|---|
| 126 | if ('all' == $_GET['display']) |
|---|
| 127 | $page['nb_images'] = count($page['cat_elements_id']); |
|---|
| 128 | else |
|---|
| 129 | $page['nb_images'] = intval($_GET['display']); |
|---|
| 130 | } |
|---|
| 131 | else |
|---|
| 132 | $page['nb_images'] = 20; |
|---|
| 133 | |
|---|
| 134 | if ( !empty($page['cat_elements_id']) ) |
|---|
| 135 | { |
|---|
| 136 | $nav_bar = create_navigation_bar( |
|---|
| 137 | $admin_url.get_query_string_diff(array('start')), |
|---|
| 138 | count($page['cat_elements_id']), |
|---|
| 139 | $page['start'], |
|---|
| 140 | $page['nb_images'] |
|---|
| 141 | ); |
|---|
| 142 | $template->assign('NAV_BAR', $nav_bar); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | $images=array(); |
|---|
| 146 | if ( !empty($page['cat_elements_id']) ) |
|---|
| 147 | { |
|---|
| 148 | $query=' |
|---|
| 149 | SELECT id,tn_ext,name,path,file,lat,lon FROM '.IMAGES_TABLE.' |
|---|
| 150 | WHERE id IN ('.implode(',',$page['cat_elements_id']).') |
|---|
| 151 | '.$conf['order_by'].' |
|---|
| 152 | LIMIT '.$page['start'].', '.$page['nb_images'].' |
|---|
| 153 | ;'; |
|---|
| 154 | $result = pwg_query($query); |
|---|
| 155 | while ( $row=mysql_fetch_assoc($result) ) |
|---|
| 156 | $images[] = $row; |
|---|
| 157 | } |
|---|
| 158 | //================================================================================= |
|---|
| 159 | foreach ($images as $image) |
|---|
| 160 | { |
|---|
| 161 | $tpl_var = array_merge( $image, |
|---|
| 162 | array( |
|---|
| 163 | 'U_TN' => get_thumbnail_url($image), |
|---|
| 164 | 'TITLE' => get_thumbnail_title($image) |
|---|
| 165 | ) |
|---|
| 166 | ); |
|---|
| 167 | |
|---|
| 168 | if ( isset($image['lat']) ) |
|---|
| 169 | $tpl_var['U_MAP'] = rvm_make_map_picture_url( array('image_id'=>$image['id'], 'image_file'=>$image['file']) ); |
|---|
| 170 | $template->append('thumbnails', $tpl_var); |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | //=================================================================================== |
|---|
| 174 | $template->assign( |
|---|
| 175 | array( |
|---|
| 176 | 'U_DISPLAY'=> $admin_url.get_query_string_diff(array('display')), |
|---|
| 177 | 'VERSION'=> $version, |
|---|
| 178 | ) |
|---|
| 179 | ); |
|---|
| 180 | //================================================================================== |
|---|
| 181 | $template->assign( |
|---|
| 182 | array( |
|---|
| 183 | 'GMAPS_API_KEY' => $conf['gmaps_api_key'], |
|---|
| 184 | ) |
|---|
| 185 | ); |
|---|
| 186 | //================================================================================== |
|---|
| 187 | $src=""; |
|---|
| 188 | |
|---|
| 189 | if (isset($collection)) |
|---|
| 190 | { |
|---|
| 191 | $lat =1000; |
|---|
| 192 | |
|---|
| 193 | if ($match<>"" && $match<>"/" ) |
|---|
| 194 | { |
|---|
| 195 | $match=str_replace(" ","+",$match); |
|---|
| 196 | |
|---|
| 197 | $src="http://maps.google.com/maps/geo?q=".$match."&output=xml&sensor=true_or_false&key=".$conf['gmaps_api_key']; |
|---|
| 198 | //json,kml,xml,csv |
|---|
| 199 | |
|---|
| 200 | $location = file_get_contents($src); |
|---|
| 201 | $location = explode("coordinates>",$location ); |
|---|
| 202 | $location = explode(",",$location[1]); |
|---|
| 203 | $lat=$location[1]; |
|---|
| 204 | $lon=$location[0]; |
|---|
| 205 | $template->assign( array('lat' => $lat , |
|---|
| 206 | 'lon' => $lon ,)); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | foreach ($collection as $id_0) { |
|---|
| 210 | foreach ($images as $image) { |
|---|
| 211 | |
|---|
| 212 | if (array_search($id_0,$image)) { |
|---|
| 213 | if ($lat==1000) { |
|---|
| 214 | $lat= ($image['lat'] <> '') ? $image['lat'] : '49.0' ; |
|---|
| 215 | $lon= ($image['lon'] <> '') ? $image['lon'] : '3.0' ; |
|---|
| 216 | $template->assign( array('lat' => $lat , |
|---|
| 217 | 'lon' => $lon , |
|---|
| 218 | ) |
|---|
| 219 | ); |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | $tpl_var = array_merge( |
|---|
| 223 | $image, |
|---|
| 224 | array( |
|---|
| 225 | 'src' => $src , |
|---|
| 226 | 'match' => $_POST['match'] , |
|---|
| 227 | 'check' => $_POST['submit'] , |
|---|
| 228 | 'U_TN' => get_thumbnail_url($image), |
|---|
| 229 | 'TITLE' => get_thumbnail_title($image), |
|---|
| 230 | 'U_MAP' => rvm_make_map_picture_url( |
|---|
| 231 | array( |
|---|
| 232 | 'image_id'=>$image['id'], |
|---|
| 233 | 'image_file'=>$image['file'], |
|---|
| 234 | ) |
|---|
| 235 | |
|---|
| 236 | ), |
|---|
| 237 | ) |
|---|
| 238 | ); |
|---|
| 239 | |
|---|
| 240 | $template->append('Selectthumbnails', $tpl_var); |
|---|
| 241 | |
|---|
| 242 | } |
|---|
| 243 | } |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | } |
|---|
| 248 | if (isset($_POST['submit']) ) |
|---|
| 249 | { if ($_POST['submit']==l10n('Submit') ) |
|---|
| 250 | { |
|---|
| 251 | $_POST['selection']=array(); |
|---|
| 252 | $collection =array(); |
|---|
| 253 | } |
|---|
| 254 | } |
|---|
| 255 | //======================================================================= |
|---|
| 256 | |
|---|
| 257 | ?> |
|---|