1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | /* |
---|
5 | * Add verso link on picture page |
---|
6 | */ |
---|
7 | function Back2Front_picture_content($content, $image) |
---|
8 | { |
---|
9 | global $template, $conf; |
---|
10 | |
---|
11 | /* search for a verso picture */ |
---|
12 | $query = " |
---|
13 | SELECT |
---|
14 | i.id, |
---|
15 | i.path, |
---|
16 | i.has_high |
---|
17 | FROM ".IMAGES_TABLE." as i |
---|
18 | INNER JOIN ".B2F_TABLE." as v |
---|
19 | ON i.id = v.verso_id |
---|
20 | WHERE |
---|
21 | v.image_id = ".$image['id']." |
---|
22 | ;"; |
---|
23 | $result = pwg_query($query); |
---|
24 | |
---|
25 | if (pwg_db_num_rows($result)) |
---|
26 | { |
---|
27 | $verso = pwg_db_fetch_assoc($result); |
---|
28 | |
---|
29 | /* websize picture */ |
---|
30 | $template->assign('VERSO_URL', $verso['path']); |
---|
31 | |
---|
32 | /* admin link */ |
---|
33 | if (is_admin()) |
---|
34 | { |
---|
35 | $template->assign('VERSO_U_ADMIN', get_root_url().'admin.php?page=picture_modify&cat_id=&image_id='.$verso['id']); |
---|
36 | $template->set_filename('B2F_admin_button', dirname(__FILE__).'/template/admin_button.tpl'); |
---|
37 | $template->concat('PLUGIN_PICTURE_ACTIONS', $template->parse('B2F_admin_button', true)); |
---|
38 | } |
---|
39 | |
---|
40 | /* high picture */ |
---|
41 | if ($verso['has_high']) |
---|
42 | { |
---|
43 | $template->assign('VERSO_HD', get_high_url($verso)); |
---|
44 | } |
---|
45 | |
---|
46 | /* template & output */ |
---|
47 | $template->set_filenames(array('B2F_picture_content' => dirname(__FILE__).'/template/picture_content.tpl') ); |
---|
48 | $template->assign('B2F_PATH', B2F_PATH); |
---|
49 | |
---|
50 | return $content . $template->parse('B2F_picture_content', true); |
---|
51 | } |
---|
52 | else |
---|
53 | { |
---|
54 | return $content; |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | /* |
---|
60 | * Add field on picture modify page |
---|
61 | */ |
---|
62 | function Back2Front_picture_modify() |
---|
63 | { |
---|
64 | global $page, $template; |
---|
65 | |
---|
66 | if ($page['page'] == 'picture_modify') |
---|
67 | { |
---|
68 | /* change values */ |
---|
69 | if (isset($_POST['b2f_submit'])) |
---|
70 | { |
---|
71 | /* picture is verso */ |
---|
72 | if (isset($_POST['b2f_is_verso'])) |
---|
73 | { |
---|
74 | /* frontside exists */ |
---|
75 | if (picture_exists($_POST['b2f_front_id'])) |
---|
76 | { |
---|
77 | $query = " |
---|
78 | INSERT INTO ".B2F_TABLE." |
---|
79 | VALUES(".$_POST['b2f_front_id'].", ".$_GET['image_id'].", ".$_POST['b2f_old_level'].") |
---|
80 | ON DUPLICATE KEY UPDATE image_id = ".$_POST['b2f_front_id'].", old_level = ".$_POST['b2f_old_level']." |
---|
81 | ;"; |
---|
82 | pwg_query($query); |
---|
83 | |
---|
84 | $query = " |
---|
85 | UPDATE ".IMAGES_TABLE." |
---|
86 | SET level = 99 |
---|
87 | WHERE id = ".$_GET['image_id']." |
---|
88 | ;"; |
---|
89 | pwg_query($query); |
---|
90 | |
---|
91 | $template->assign(array( |
---|
92 | 'B2F_IS_VERSO' => 'checked="checked"', |
---|
93 | 'B2F_FRONT_ID' => $_POST['b2f_front_id'], |
---|
94 | 'B2F_OLD_LEVEL' => $_POST['b2f_old_level'], |
---|
95 | )); |
---|
96 | } |
---|
97 | else |
---|
98 | { |
---|
99 | $template->assign('errors', l10n('Unknown id for frontside picture')); |
---|
100 | } |
---|
101 | } |
---|
102 | /* picture isn't verso */ |
---|
103 | else |
---|
104 | { |
---|
105 | $query = " |
---|
106 | DELETE FROM ".B2F_TABLE." |
---|
107 | WHERE verso_id = ".$_GET['image_id']." |
---|
108 | ;"; |
---|
109 | pwg_query($query); |
---|
110 | |
---|
111 | $query = " |
---|
112 | UPDATE ".IMAGES_TABLE." |
---|
113 | SET level = ".$_POST['b2f_old_level']." |
---|
114 | WHERE id = ".$_GET['image_id']." |
---|
115 | ;"; |
---|
116 | pwg_query($query); |
---|
117 | |
---|
118 | $template->assign(array( |
---|
119 | 'level_options_selected' => array($_POST['b2f_old_level']), |
---|
120 | )); |
---|
121 | } |
---|
122 | } |
---|
123 | /* get saved values */ |
---|
124 | else |
---|
125 | { |
---|
126 | /* is the pisture a verso ? */ |
---|
127 | $query = " |
---|
128 | SELECT image_id, old_level |
---|
129 | FROM ".B2F_TABLE." |
---|
130 | WHERE verso_id = ".$_GET['image_id']." |
---|
131 | ;"; |
---|
132 | $result = pwg_query($query); |
---|
133 | |
---|
134 | if (pwg_db_num_rows($result)) |
---|
135 | { |
---|
136 | $item = pwg_db_fetch_assoc($result); |
---|
137 | $template->assign(array( |
---|
138 | 'B2F_IS_VERSO' => 'checked="checked"', |
---|
139 | 'B2F_FRONT_ID' => $item['image_id'], |
---|
140 | 'B2F_OLD_LEVEL' => $item['old_level'], |
---|
141 | )); |
---|
142 | } |
---|
143 | /* is the picture a front ? */ |
---|
144 | else |
---|
145 | { |
---|
146 | $query = " |
---|
147 | SELECT verso_id |
---|
148 | FROM ".B2F_TABLE." |
---|
149 | WHERE image_id = ".$_GET['image_id']." |
---|
150 | ;"; |
---|
151 | $result = pwg_query($query); |
---|
152 | |
---|
153 | if (pwg_db_num_rows($result)) |
---|
154 | { |
---|
155 | include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); |
---|
156 | |
---|
157 | $item = pwg_db_fetch_assoc($result); |
---|
158 | $query = " |
---|
159 | SELECT id, name, file |
---|
160 | FROM ".IMAGES_TABLE." |
---|
161 | WHERE id = ".$item['verso_id']." |
---|
162 | ;"; |
---|
163 | $item = pwg_db_fetch_assoc(pwg_query($query)); |
---|
164 | |
---|
165 | $template->assign(array( |
---|
166 | 'B2F_VERSO_ID' => $item['id'], |
---|
167 | 'B2F_VERSO_URL' => get_root_url().'admin.php?page=picture_modify&cat_id=&image_id='.$item['id'], |
---|
168 | 'B2F_VERSO_NAME' => get_image_name($item['name'], $item['file']), |
---|
169 | )); |
---|
170 | } |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | $template->set_filename('B2F_picture_modify', dirname(__FILE__).'/template/picture_modify.tpl'); |
---|
175 | $template->concat('ADMIN_CONTENT', $template->parse('B2F_picture_modify', true)); |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | function picture_exists($id) |
---|
180 | { |
---|
181 | if (!preg_match('#([0-9]{1,})#', $id) OR $id == '0') return false; |
---|
182 | |
---|
183 | $query = "SELECT id FROM ".IMAGES_TABLE." WHERE id = ".$id.";"; |
---|
184 | $result = pwg_query($query); |
---|
185 | |
---|
186 | if (pwg_db_num_rows($result)) return true; |
---|
187 | else return false; |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | $versos = null; // needs to be declared outside any function for the array_filter callback ?! |
---|
192 | /* |
---|
193 | * Change/remove navigation thumbnails |
---|
194 | */ |
---|
195 | function Back2Front_items() |
---|
196 | { |
---|
197 | global $template, $page, $versos; |
---|
198 | |
---|
199 | /* search all verso ids */ |
---|
200 | $query = " |
---|
201 | SELECT verso_id as id |
---|
202 | FROM ".B2F_TABLE." |
---|
203 | ;"; |
---|
204 | $versos = array_values(array_from_query($query, 'id')); |
---|
205 | |
---|
206 | /* output */ |
---|
207 | function remove_versos($item) |
---|
208 | { |
---|
209 | global $versos; |
---|
210 | return !in_array($item, $versos); |
---|
211 | } |
---|
212 | $page['items'] = array_values(array_filter($page['items'], 'remove_versos')); |
---|
213 | } |
---|
214 | |
---|
215 | ?> |
---|