1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Psli-BingMaps |
---|
4 | Author: psli |
---|
5 | */ |
---|
6 | |
---|
7 | // Chech whether we are indeed included by Piwigo. |
---|
8 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
9 | |
---|
10 | //******* Fetch global data ******* |
---|
11 | global $template, $conf, $page, $debug; |
---|
12 | |
---|
13 | // Include class files for map, pin and zone |
---|
14 | include_once(PSLI_BINGMAPS_CLASS_MAP_PHP); |
---|
15 | |
---|
16 | //******* Select map to display ******* |
---|
17 | $class_map = new Psli_Map(); |
---|
18 | $addjs = ""; |
---|
19 | if (isset($_POST['open'])) |
---|
20 | { |
---|
21 | if ((isset($_POST['mapSelected'])) && ($_POST['mapSelected'] != 0)) |
---|
22 | $class_map->open($_POST['mapSelected']); |
---|
23 | else |
---|
24 | array_push($page['errors'], l10n('You need to select a map')); |
---|
25 | } |
---|
26 | else |
---|
27 | { |
---|
28 | if ((isset($_POST['hiddenmap'])) && ($_POST['hiddenmap'] != "")) |
---|
29 | $class_map->open($_POST['hiddenmap']); |
---|
30 | else |
---|
31 | { |
---|
32 | $query = 'SELECT id FROM '.PSLI_MAPS_TABLE.' ORDER BY id LIMIT 1;'; |
---|
33 | $result = pwg_query($query); |
---|
34 | if (pwg_db_num_rows($result) > 0) |
---|
35 | { |
---|
36 | $row = pwg_db_fetch_assoc($result); |
---|
37 | $class_map->open($row['id']); |
---|
38 | } |
---|
39 | } |
---|
40 | } |
---|
41 | if ($class_map->isOpened()) |
---|
42 | $display = 'block'; |
---|
43 | else |
---|
44 | $display = 'none'; |
---|
45 | |
---|
46 | /************************************************************************************/ |
---|
47 | /* Submit - Delete map **************************************************************/ |
---|
48 | if (isset($_POST['delete'])) |
---|
49 | { |
---|
50 | if (isset($_POST['deleteCheck'])) |
---|
51 | { |
---|
52 | if ((isset($_POST['mapSelected'])) && ($_POST['mapSelected'] != 0)) |
---|
53 | { |
---|
54 | $class_map->delete(); |
---|
55 | $class_map = new Psli_Map(); |
---|
56 | $display = 'none'; |
---|
57 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
58 | } |
---|
59 | else |
---|
60 | array_push($page['errors'], l10n('You need to select a map')); |
---|
61 | } |
---|
62 | else |
---|
63 | array_push($page['errors'], l10n('You need to confirm deletion')); |
---|
64 | } |
---|
65 | /************************************************************************************/ |
---|
66 | |
---|
67 | /************************************************************************************/ |
---|
68 | /* Submit - Create a new map ********************************************************/ |
---|
69 | if (isset($_POST['create'])) |
---|
70 | { |
---|
71 | $class_map = new Psli_Map(); |
---|
72 | $class_map->create(); |
---|
73 | $display = 'block'; |
---|
74 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
75 | } |
---|
76 | /************************************************************************************/ |
---|
77 | |
---|
78 | /************************************************************************************/ |
---|
79 | /* Submit - Update in map data ******************************************************/ |
---|
80 | if (isset ($_POST['save'])) |
---|
81 | { |
---|
82 | $class_map->setLatitude($_POST['lat']); |
---|
83 | $class_map->setLongitude($_POST['lon']); |
---|
84 | $class_map->setTitle($_POST['title']); |
---|
85 | $class_map->setZoom($_POST['zoom']); |
---|
86 | $class_map->setCategory($_POST['categorySelected']); |
---|
87 | |
---|
88 | $class_map->save(); |
---|
89 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
90 | } |
---|
91 | /************************************************************************************/ |
---|
92 | |
---|
93 | //******* Load zone and pin for this map ******* |
---|
94 | if ($class_map->isOpened()) |
---|
95 | { |
---|
96 | $query_entities = ' |
---|
97 | SELECT e.id id, lat, lon, zoomMin, zoomMax, action, id_action, title, type |
---|
98 | FROM '.PSLI_ENTITIES_TABLE.' e left join '.PSLI_ENTITIES_MAPS_TABLE.' j ON e.id = j.id_entity |
---|
99 | WHERE j.id_map = '.$class_map->getId().';'; |
---|
100 | $result_entities = pwg_query($query_entities); |
---|
101 | |
---|
102 | // Is there any entities ? |
---|
103 | if (pwg_db_num_rows($result_entities) > 0) |
---|
104 | { |
---|
105 | $desc_data = ""; |
---|
106 | $desc_function_mouse_over = ""; |
---|
107 | $desc_function_click = ""; |
---|
108 | |
---|
109 | // For each sub category |
---|
110 | while ($entity = pwg_db_fetch_assoc($result_entities)) |
---|
111 | { |
---|
112 | if ($entity['id_action'] != 0) |
---|
113 | { |
---|
114 | if ($entity['type'] == 2) |
---|
115 | { |
---|
116 | $query_datapoint = ' |
---|
117 | SELECT lat, lon |
---|
118 | FROM '.PSLI_DATAPOINT_TABLE.' |
---|
119 | WHERE id_entity = '.$entity['id'].' ORDER BY id;'; |
---|
120 | $result_datapoint = pwg_query($query_datapoint); |
---|
121 | if (pwg_db_num_rows($result_datapoint) > 0) |
---|
122 | { |
---|
123 | $desc_data .= 'var psli_t_Vertices'.$entity['id'].' = new Array();'."\n"; |
---|
124 | while ($row = pwg_db_fetch_assoc($result_datapoint)) |
---|
125 | { |
---|
126 | $desc_data .= 'psli_t_Vertices'.$entity['id'].'.push(new Microsoft.Maps.Location('.$row['lat'].','.$row['lon'].'));'."\n"; |
---|
127 | } |
---|
128 | $desc_data .= ' |
---|
129 | var psli_t_Child'.$entity['id'].' = new Microsoft.Maps.Polygon(psli_t_Vertices'.$entity['id'].',{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor});'."\n"; |
---|
130 | } |
---|
131 | } |
---|
132 | else |
---|
133 | { |
---|
134 | $desc_data .= ' |
---|
135 | var psli_t_Child'.$entity['id'].' = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location('.$entity['lat'].','.$entity['lon'].'));'."\n"; |
---|
136 | } |
---|
137 | |
---|
138 | $desc_data .= ' |
---|
139 | Microsoft.Maps.Events.addHandler(psli_t_Child'.$entity['id'].', "click", psli_MapsClick_'.$entity['id'].');'."\n"; |
---|
140 | switch ($entity['action']) |
---|
141 | { |
---|
142 | case 1: |
---|
143 | $desc_function_click .= ' |
---|
144 | function psli_MapsClick_'.$entity['id'].' (e) { |
---|
145 | psli_g_Map.setView({zoom:'.$entity['id_action'].', center: new Microsoft.Maps.Location('.$entity['lat'].', '.$entity['lon'].')}); |
---|
146 | }'."\n"; |
---|
147 | break; |
---|
148 | case 2: |
---|
149 | $desc_function_click .= ' |
---|
150 | function psli_MapsClick_'.$entity['id'].' (e) { |
---|
151 | alert ("'.l10n('Open this category').' '.$entity['title'].'"); |
---|
152 | }'."\n"; |
---|
153 | break; |
---|
154 | case 3: |
---|
155 | $desc_function_click .= ' |
---|
156 | function psli_MapsClick_'.$entity['id'].' (e) { |
---|
157 | alert ("'.l10n('Open this picture').' '.$entity['title'].'"); |
---|
158 | }'."\n"; |
---|
159 | break; |
---|
160 | } |
---|
161 | for ($i = $entity['zoomMin']; $i <= $entity['zoomMax']; $i++) |
---|
162 | { |
---|
163 | $desc_data .= 'psli_g_ZoomEntity['.($i - 1).'].push(psli_t_Child'.$entity['id'].');'."\n"; |
---|
164 | } |
---|
165 | } |
---|
166 | } |
---|
167 | $addjs .= $desc_data; |
---|
168 | $addjs .= $desc_function_mouse_over; |
---|
169 | $addjs .= $desc_function_click; |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | //******* Get Bing Map Key ******* |
---|
174 | $query = ' |
---|
175 | SELECT value |
---|
176 | FROM '.CONFIG_TABLE.' |
---|
177 | WHERE param = "'.PSLI_CONF_KEY.'";'; |
---|
178 | $result = pwg_query($query); |
---|
179 | $row = pwg_db_fetch_assoc($result); |
---|
180 | $bing_map_key = $row['value']; |
---|
181 | |
---|
182 | //******* Send configuration data to template ******* |
---|
183 | generateCategoryList($class_map->getCategory(), $class_map->isOpened(), 'category_select', l10n('Not assign to a category')); |
---|
184 | $class_map->generateMapsList($template, "map_select"); |
---|
185 | $class_map->assignData($template, "LAT", "LON", "ZOOM", "TITLE", "HIDDENMAP"); |
---|
186 | |
---|
187 | //******* Assign data to template ******* |
---|
188 | $template->assign( |
---|
189 | array( |
---|
190 | 'KEY' => $bing_map_key, |
---|
191 | 'JSPATH' => PSLI_BINGMAPS_JS_MAP, |
---|
192 | 'DISPLAY' => $display, |
---|
193 | 'ADDJS' => $addjs, |
---|
194 | ) |
---|
195 | ); |
---|
196 | |
---|
197 | //******* Assign the template contents to ADMIN_CONTENT ******* |
---|
198 | $template->set_filenames(array('plugin_admin_content' => PSLI_BINGMAPS_ADMIN_MAP_TPL)); |
---|
199 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
200 | ?> |
---|