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 | $add_js = ""; |
---|
14 | |
---|
15 | // Include class files for map, pin and zone |
---|
16 | include_once(PSLI_BINGMAPS_CLASS_PIN_PHP); |
---|
17 | |
---|
18 | //******* Get Bing Map Key ******* |
---|
19 | $query = ' |
---|
20 | SELECT value |
---|
21 | FROM '.CONFIG_TABLE.' |
---|
22 | WHERE param = "'.PSLI_CONF_KEY.'";'; |
---|
23 | $result = pwg_query($query); |
---|
24 | $row = pwg_db_fetch_assoc($result); |
---|
25 | $bing_map_key = $row['value']; |
---|
26 | |
---|
27 | //******* Select entity to display ******* |
---|
28 | $class_pin = new Psli_Pin(); |
---|
29 | if (isset($_POST['open'])) |
---|
30 | { |
---|
31 | if ((isset($_POST['pinSelected'])) && ($_POST['pinSelected'] != 0)) |
---|
32 | $class_pin->open($_POST['pinSelected']); |
---|
33 | else |
---|
34 | array_push($page['errors'], l10n('You need to select a pin')); |
---|
35 | } |
---|
36 | else |
---|
37 | { |
---|
38 | if ((isset($_POST['hiddenpin'])) && ($_POST['hiddenpin'] != "")) |
---|
39 | $class_pin->open($_POST['hiddenpin']); |
---|
40 | } |
---|
41 | if ($class_pin->isOpened()) |
---|
42 | $display = 'block'; |
---|
43 | else |
---|
44 | $display = 'none'; |
---|
45 | |
---|
46 | |
---|
47 | /************************************************************************************/ |
---|
48 | /* Submit - Delete pin **************************************************************/ |
---|
49 | if (isset($_POST['delete'])) |
---|
50 | { |
---|
51 | if (isset($_POST['deleteCheck'])) |
---|
52 | { |
---|
53 | if ((isset($_POST['pinSelected'])) && ($_POST['pinSelected'] != 0)) |
---|
54 | { |
---|
55 | $class_pin->open($_POST['pinSelected']); |
---|
56 | $class_pin->delete(); |
---|
57 | $class_pin = new Psli_Pin(); |
---|
58 | $display = 'none'; |
---|
59 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
60 | } |
---|
61 | else |
---|
62 | array_push($page['errors'], l10n('You need to select a pin')); |
---|
63 | } |
---|
64 | else |
---|
65 | array_push($page['errors'], l10n('You need to confirm deletion')); |
---|
66 | } |
---|
67 | /************************************************************************************/ |
---|
68 | |
---|
69 | /************************************************************************************/ |
---|
70 | /* Submit - Update a pin ************************************************************/ |
---|
71 | if (isset($_POST['save'])) |
---|
72 | { |
---|
73 | $class_pin->setLatitude($_POST['lat']); |
---|
74 | $class_pin->setLongitude($_POST['lon']); |
---|
75 | $class_pin->setTitle($_POST['title']); |
---|
76 | $class_pin->setZoomMin($_POST['zoommin']); |
---|
77 | $class_pin->setZoomMax($_POST['zoommax']); |
---|
78 | |
---|
79 | $class_pin->clearMaps(); |
---|
80 | if (isset ($_POST['associatedmap'])) |
---|
81 | for ($i = 0; $i < count($_POST['associatedmap']); $i++) |
---|
82 | $class_pin->addMap($_POST['associatedmap'][$i]); |
---|
83 | |
---|
84 | switch ($_POST['actionselect']) |
---|
85 | { |
---|
86 | case 2: |
---|
87 | $class_pin->setAction(2, $_POST['actionalbumselect']); |
---|
88 | break; |
---|
89 | case 3: |
---|
90 | $class_pin->setAction(3, $_POST['actionpictureid']); |
---|
91 | break; |
---|
92 | } |
---|
93 | $class_pin->save(); |
---|
94 | $display = 'block'; |
---|
95 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
96 | } |
---|
97 | /************************************************************************************/ |
---|
98 | |
---|
99 | /************************************************************************************/ |
---|
100 | /* Submit - Create a new pin ********************************************************/ |
---|
101 | if (isset($_POST['create'])) |
---|
102 | { |
---|
103 | $class_pin = new Psli_Pin(); |
---|
104 | $class_pin->create(); |
---|
105 | $display = 'block'; |
---|
106 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
107 | } |
---|
108 | /************************************************************************************/ |
---|
109 | |
---|
110 | |
---|
111 | //******* Get pin selected data ******* |
---|
112 | if ($class_pin->isOpened()) |
---|
113 | { |
---|
114 | $add_js .= "\npsli_ShowPin();"; |
---|
115 | switch ($class_pin->getAction()) |
---|
116 | { |
---|
117 | case 2: |
---|
118 | $add_js .= "\ndocument.getElementById(\"actionselect\").selectedIndex = 0;"; |
---|
119 | $add_js .= "\ndocument.getElementById(\"actionalbumselect\").selectedItem = ".($class_pin->getActionId()).";"; |
---|
120 | $add_js .= "\ndocument.getElementById(\"ActionAlbum\").style.display = 'block';"; |
---|
121 | $add_js .= "\ndocument.getElementById(\"ActionPicture\").style.display = 'none';"; |
---|
122 | break; |
---|
123 | case 3: |
---|
124 | $add_js .= "\ndocument.getElementById(\"actionselect\").selectedIndex = 1;"; |
---|
125 | $add_js .= "\ndocument.getElementById(\"ActionAlbum\").style.display = 'none';"; |
---|
126 | $add_js .= "\ndocument.getElementById(\"ActionPicture\").style.display = 'block';"; |
---|
127 | break; |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | //******* Generate map list ******* |
---|
132 | $query = " |
---|
133 | SELECT id, title |
---|
134 | FROM ".PSLI_MAPS_TABLE." |
---|
135 | ORDER BY title;"; |
---|
136 | $result = pwg_query($query); |
---|
137 | $associatedmap = ""; |
---|
138 | while ($row = pwg_db_fetch_assoc($result)) |
---|
139 | { |
---|
140 | $status = ""; |
---|
141 | if ($class_pin->isMapAssociated($row['id'])) |
---|
142 | $status = "CHECKED"; |
---|
143 | $associatedmap .= '<tr><td><input type="checkbox" name="associatedmap[]" value="'.$row['id'].'" style="margin-right:10px;" '.$status.' />'.$row['title'].'</td></tr>'; |
---|
144 | } |
---|
145 | |
---|
146 | //******* Generate category list for pin action ******* |
---|
147 | if ($class_pin->getAction() == 2) |
---|
148 | generateCategoryList($class_pin->getActionId(), true, 'actionalbum_select', l10n('Not assign to a category')); |
---|
149 | else |
---|
150 | generateCategoryList(0, false, 'actionalbum_select', l10n('Not assign to a category')); |
---|
151 | |
---|
152 | //******* Send configuration data to template ******* |
---|
153 | $class_pin->assignData($template, "LAT", "LON", "ZOOMMIN", "ZOOMMAX", "TITLE", "ACTIONPICTURE", "HIDDENPIN"); |
---|
154 | $class_pin->generatePinList($template, "pin_select"); |
---|
155 | |
---|
156 | //******* Assign data to template ******* |
---|
157 | $template->assign( |
---|
158 | array( |
---|
159 | 'KEY' => $bing_map_key, |
---|
160 | 'JSPATH' => PSLI_BINGMAPS_JS_PIN, |
---|
161 | 'DISPLAY' => $display, |
---|
162 | 'ADDJS' => $add_js, |
---|
163 | 'ASSOCIATEDMAP' => $associatedmap, |
---|
164 | 'ACTIONPICTURE' => $class_pin->getActionId() |
---|
165 | ) |
---|
166 | ); |
---|
167 | |
---|
168 | //******* Assign the template contents to ADMIN_CONTENT ******* |
---|
169 | $template->set_filenames(array('plugin_admin_content' => PSLI_BINGMAPS_ADMIN_PIN_TPL)); |
---|
170 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
171 | ?> |
---|