1 | <?php |
---|
2 | //if (!defined(PHPWG_ROOT_PATH)) die('Hacking attempt!'); |
---|
3 | |
---|
4 | global $user, $conf, $template; |
---|
5 | |
---|
6 | // Check Access and exit when user status is not ok |
---|
7 | check_status(ACCESS_ADMINISTRATOR); |
---|
8 | |
---|
9 | $me = get_plugin_data($plugin_id); |
---|
10 | |
---|
11 | load_language('plugin.lang', NBC_ThemeChanger_PATH); |
---|
12 | $page_ThemeChanger_admin = get_admin_plugin_menu_link(__FILE__); |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | $cat=array(); |
---|
17 | $categories = array(); |
---|
18 | |
---|
19 | |
---|
20 | //chargement des catégories |
---|
21 | $query = ' |
---|
22 | SELECT id, name, uppercats, global_rank |
---|
23 | FROM '.CATEGORIES_TABLE.' ; |
---|
24 | '; |
---|
25 | $result = pwg_query($query); |
---|
26 | |
---|
27 | while (($cat = mysql_fetch_array($result)) <> null) |
---|
28 | { |
---|
29 | array_push($categories , array("id" => $cat['id'], |
---|
30 | "name" => $cat['name'], |
---|
31 | "uppercats" =>$cat['uppercats'], |
---|
32 | "longName" => get_cat_display_name_cache($cat['uppercats'], null, false), |
---|
33 | "global_rank" => $cat['global_rank'], |
---|
34 | )); |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | //chargement des thèmes |
---|
39 | $themes = array(); |
---|
40 | foreach (get_pwg_themes() as $pwg_template) |
---|
41 | { |
---|
42 | $selected = $pwg_template; |
---|
43 | array_push($themes, $selected); |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | // Configuration du template |
---|
48 | $template->assign('params', |
---|
49 | array( |
---|
50 | 'U_HOME' => make_index_url(), |
---|
51 | 'F_ACTION' => add_url_params($page_ThemeChanger_admin, array()), |
---|
52 | 'U_ADD_ASSOC' => add_url_params($page_ThemeChanger_admin, array('action' => 'add_assoc')), |
---|
53 | 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=ThemeChanger_admin', |
---|
54 | 'Themes' => $themes, |
---|
55 | 'Categories' => $categories, |
---|
56 | )); |
---|
57 | |
---|
58 | // Mise a jour de la base de donnee |
---|
59 | if (isset($_POST['submit']) and !is_adviser()) |
---|
60 | if ( (isset($_POST['categorychoise']) or isset($_POST['category_id'])) and isset($_POST['template'])) |
---|
61 | { |
---|
62 | $conf_nbc_ThemeChanger = isset($conf['nbc_ThemeChanger']) ? explode(";" , $conf['nbc_ThemeChanger']) : array(); |
---|
63 | $listcategory = array(); |
---|
64 | $newconf_nbc_ThemeChanger = ''; |
---|
65 | //evol $theme = explode("/" , $_POST['template']); |
---|
66 | $theme = $_POST['template']; |
---|
67 | $add_ok = false; |
---|
68 | |
---|
69 | $applysubcategory = isset($_POST['ApplySubCategories']) ? $_POST['ApplySubCategories'] : ''; |
---|
70 | $thecategory = isset($_POST['categorychoise']) ? $_POST['categorychoise'] : ( isset($_POST['category_id']) ? $_POST['category_id'] : ''); |
---|
71 | |
---|
72 | $_POST['categorychoise'] = ''; |
---|
73 | $_POST['category_id'] = ''; |
---|
74 | $_POST['template'] = ''; |
---|
75 | $_GET['action'] = ''; |
---|
76 | $_POST['ApplySubCategories'] = ''; |
---|
77 | |
---|
78 | if ($applysubcategory <> '') { |
---|
79 | foreach ($categories as $icat) { |
---|
80 | $tmp = explode("," , $icat['uppercats']); |
---|
81 | if (in_array ($thecategory, $tmp)) |
---|
82 | array_push($listcategory ,$icat['id']); |
---|
83 | } |
---|
84 | } |
---|
85 | else |
---|
86 | array_push($listcategory ,$thecategory); |
---|
87 | |
---|
88 | foreach ($conf_nbc_ThemeChanger as $Theme_Cat) |
---|
89 | { |
---|
90 | $add_ok = false; |
---|
91 | $element_ThemeChanger = explode("," , $Theme_Cat); |
---|
92 | $i = 0; |
---|
93 | foreach ($listcategory as $thecategory) |
---|
94 | { |
---|
95 | if ($element_ThemeChanger[0] == $thecategory) //MAJ de la nouvelle category déjà présente dans la liste |
---|
96 | { |
---|
97 | //echo ' MAJ: '.$element_ThemeChanger[0]; |
---|
98 | if ($newconf_nbc_ThemeChanger <> '') |
---|
99 | $newconf_nbc_ThemeChanger .= ';'; |
---|
100 | $newconf_nbc_ThemeChanger .= $thecategory.','.$theme; |
---|
101 | $listcategory[$i] = -1; |
---|
102 | $add_ok = true; |
---|
103 | break; |
---|
104 | } |
---|
105 | $i += 1; |
---|
106 | } |
---|
107 | if ($add_ok == false){ |
---|
108 | //récupération des catégories qui n'ont pas été modifié. |
---|
109 | if ($element_ThemeChanger[0] <> '') { |
---|
110 | if ($newconf_nbc_ThemeChanger <> '') |
---|
111 | $newconf_nbc_ThemeChanger .= ';'; |
---|
112 | //echo ' Recup : '.$element_ThemeChanger[0]; |
---|
113 | $newconf_nbc_ThemeChanger .= $element_ThemeChanger[0].','.$element_ThemeChanger[1]; |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | //insertion des nouvelles catégories |
---|
118 | foreach ($listcategory as $thecategory) { |
---|
119 | if ($newconf_nbc_ThemeChanger <> '') |
---|
120 | $newconf_nbc_ThemeChanger .= ';'; |
---|
121 | //echo ' Nouveau: '.$thecategory; |
---|
122 | if ($thecategory <> -1) |
---|
123 | $newconf_nbc_ThemeChanger .= $thecategory.','.$theme; |
---|
124 | } |
---|
125 | |
---|
126 | $conf['nbc_ThemeChanger'] = $newconf_nbc_ThemeChanger; |
---|
127 | |
---|
128 | $query = ' |
---|
129 | UPDATE '.CONFIG_TABLE.' |
---|
130 | SET value="'.$newconf_nbc_ThemeChanger.'" |
---|
131 | WHERE param="nbc_ThemeChanger" |
---|
132 | LIMIT 1'; |
---|
133 | pwg_query($query); |
---|
134 | |
---|
135 | array_push($page['infos'], l10n('nbc_ThemeChanger_save_config')); |
---|
136 | } |
---|
137 | |
---|
138 | $conf_nbc_ThemeChanger = isset($conf['nbc_ThemeChanger']) ? explode(";" , $conf['nbc_ThemeChanger']) : array(); |
---|
139 | |
---|
140 | $catsused = array(); |
---|
141 | $assoc_ThemeChanger = array(); |
---|
142 | |
---|
143 | foreach ($conf_nbc_ThemeChanger as $Theme_Cat) |
---|
144 | { |
---|
145 | $element_ThemeChanger = explode("," , $Theme_Cat); |
---|
146 | |
---|
147 | if ($element_ThemeChanger[0] <> '' and $element_ThemeChanger[1] <> '') |
---|
148 | { |
---|
149 | array_push($catsused, $element_ThemeChanger[0]); |
---|
150 | |
---|
151 | $query = ' |
---|
152 | SELECT uppercats |
---|
153 | FROM '.CATEGORIES_TABLE.' |
---|
154 | WHERE id = \''.$element_ThemeChanger[0].'\' |
---|
155 | ;'; |
---|
156 | |
---|
157 | $result = pwg_query($query); |
---|
158 | $row = mysql_fetch_array($result); |
---|
159 | |
---|
160 | $assoc_ThemeChanger[$element_ThemeChanger[0]] = array( |
---|
161 | 'CATEGORY_NAME' => get_cat_display_name_cache($row['uppercats'], null, false), |
---|
162 | 'TEMPLATE' => $element_ThemeChanger[1], |
---|
163 | ); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | //delete an association |
---|
168 | if ( isset($_GET['action']) and ($_GET['action']=='del_assoc') and isset($_GET['id_cat']) and is_numeric($_GET['id_cat']) and !is_adviser() ) |
---|
169 | { |
---|
170 | $conf_nbc_ThemeChanger = isset($conf['nbc_ThemeChanger']) ? explode(";" , $conf['nbc_ThemeChanger']) : array(); |
---|
171 | |
---|
172 | $newconf_nbc_ThemeChanger = ''; |
---|
173 | |
---|
174 | foreach ($conf_nbc_ThemeChanger as $Theme_Cat) |
---|
175 | { |
---|
176 | $element_ThemeChanger = explode("," , $Theme_Cat); |
---|
177 | |
---|
178 | if ($element_ThemeChanger[0] <> $_GET['id_cat'] and $element_ThemeChanger[0] <> '') |
---|
179 | { |
---|
180 | if ($newconf_nbc_ThemeChanger <> '') |
---|
181 | $newconf_nbc_ThemeChanger .= ';'; |
---|
182 | |
---|
183 | $newconf_nbc_ThemeChanger .= $element_ThemeChanger[0].','.$element_ThemeChanger[1]; |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | $conf['nbc_ThemeChanger'] = $newconf_nbc_ThemeChanger; |
---|
188 | |
---|
189 | $query = ' |
---|
190 | UPDATE '.CONFIG_TABLE.' |
---|
191 | SET value="'.$newconf_nbc_ThemeChanger.'" |
---|
192 | WHERE param="nbc_ThemeChanger" |
---|
193 | LIMIT 1'; |
---|
194 | pwg_query($query); |
---|
195 | |
---|
196 | array_push($page['infos'], l10n('nbc_ThemeChanger_save_config')); |
---|
197 | } |
---|
198 | |
---|
199 | //modify an association |
---|
200 | else if ( isset($_GET['action']) and ($_GET['action']=='mod_assoc') and isset($_GET['id_cat']) and is_numeric($_GET['id_cat']) ) |
---|
201 | { |
---|
202 | $template->assign('formulaire',array( |
---|
203 | 'DESCRIPION' => $lang['modify_assoc'].' : '.$assoc_ThemeChanger[$_GET['id_cat']]['CATEGORY_NAME'], |
---|
204 | 'NAMETOMODIFY' => $assoc_ThemeChanger[$_GET['id_cat']]['CATEGORY_NAME'], |
---|
205 | 'IDTOMODIFY' => $_GET['id_cat'], |
---|
206 | )); |
---|
207 | |
---|
208 | $template->assign('formulaire.categoryfield', array( |
---|
209 | 'NAME' => $assoc_ThemeChanger[$_GET['id_cat']]['CATEGORY_NAME'], |
---|
210 | 'ID' => $_GET['id_cat'], |
---|
211 | )); |
---|
212 | |
---|
213 | $blockname = 'formulaire.template_option'; |
---|
214 | |
---|
215 | foreach (get_pwg_themes() as $pwg_template) |
---|
216 | { |
---|
217 | if ($assoc_ThemeChanger[$_GET['id_cat']]['TEMPLATE'] == $pwg_template) |
---|
218 | { |
---|
219 | $selected = 'selected="selected"'; |
---|
220 | } |
---|
221 | else |
---|
222 | { |
---|
223 | $selected = ''; |
---|
224 | } |
---|
225 | |
---|
226 | $template->assign( |
---|
227 | $blockname, |
---|
228 | array( |
---|
229 | 'VALUE'=> $pwg_template, |
---|
230 | 'CONTENT' => $pwg_template, |
---|
231 | 'SELECTED' => $selected |
---|
232 | )); |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | //add an association |
---|
237 | else if ( isset($_GET['action']) and ($_GET['action']=='add_assoc') ) |
---|
238 | { |
---|
239 | //$template->assign_var('formulaire',array( |
---|
240 | $template->assign( |
---|
241 | 'formulaire', |
---|
242 | array('DESCRIPION' => $lang['add_assoc'], |
---|
243 | ) |
---|
244 | ); |
---|
245 | |
---|
246 | $template->assign('formulaire.categorylist', array()); |
---|
247 | $blockname = 'formulaire.categorylist.parent_option'; |
---|
248 | |
---|
249 | $template->assign($blockname, array()); |
---|
250 | |
---|
251 | |
---|
252 | $query = ' |
---|
253 | SELECT id, name, uppercats, global_rank |
---|
254 | FROM '.CATEGORIES_TABLE.' |
---|
255 | '; |
---|
256 | if (!empty($catsused)) |
---|
257 | { |
---|
258 | $query .= ' |
---|
259 | WHERE id NOT IN ('.implode(',', $catsused).') |
---|
260 | '; |
---|
261 | } |
---|
262 | $query .= ' ;'; |
---|
263 | display_select_cat_wrapper($query, array(), $blockname); |
---|
264 | |
---|
265 | $blockname = 'formulaire.template_option'; |
---|
266 | |
---|
267 | foreach (get_pwg_themes() as $pwg_template) |
---|
268 | { |
---|
269 | $template->assign( |
---|
270 | $blockname, |
---|
271 | array( |
---|
272 | 'VALUE'=> $pwg_template, |
---|
273 | 'CONTENT' => $pwg_template, |
---|
274 | 'SELECTED' => '', |
---|
275 | ) |
---|
276 | ); |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | $conf_nbc_ThemeChanger = isset($conf['nbc_ThemeChanger']) ? explode(";" , $conf['nbc_ThemeChanger']) : array(); |
---|
281 | |
---|
282 | $num = 0; |
---|
283 | $catsused = array(); |
---|
284 | $assoc_ThemeChanger = array(); |
---|
285 | $assoc = array(); |
---|
286 | |
---|
287 | foreach ($conf_nbc_ThemeChanger as $Theme_Cat) |
---|
288 | { |
---|
289 | $element_ThemeChanger = explode("," , $Theme_Cat); |
---|
290 | |
---|
291 | if ($element_ThemeChanger[0] <> '' and $element_ThemeChanger[1] <> '') |
---|
292 | { |
---|
293 | array_push($catsused, $element_ThemeChanger[0]); |
---|
294 | |
---|
295 | $query = ' |
---|
296 | SELECT uppercats |
---|
297 | FROM '.CATEGORIES_TABLE.' |
---|
298 | WHERE id = \''.$element_ThemeChanger[0].'\' |
---|
299 | ;'; |
---|
300 | |
---|
301 | $result = pwg_query($query); |
---|
302 | $row = mysql_fetch_array($result); |
---|
303 | |
---|
304 | array_push($assoc , array( |
---|
305 | 'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1', |
---|
306 | 'CATEGORY_NAME' => get_cat_display_name_cache($row['uppercats'], null, false), |
---|
307 | 'CATEGORY_ID' => $element_ThemeChanger[0], |
---|
308 | 'TEMPLATE' => $element_ThemeChanger[1], |
---|
309 | 'U_MODIFY' => add_url_params($page_ThemeChanger_admin, array( |
---|
310 | 'action' => 'mod_assoc', |
---|
311 | 'id_cat' => $element_ThemeChanger[0], |
---|
312 | )), |
---|
313 | 'U_DELETE' => add_url_params($page_ThemeChanger_admin, array( |
---|
314 | 'action' => 'del_assoc', |
---|
315 | 'id_cat' => $element_ThemeChanger[0], |
---|
316 | )),)); |
---|
317 | |
---|
318 | $assoc_ThemeChanger[$element_ThemeChanger[0]] = array( |
---|
319 | 'CATEGORY_NAME' => get_cat_display_name_cache($row['uppercats'], null, false), |
---|
320 | 'TEMPLATE' => $element_ThemeChanger[1], |
---|
321 | ); |
---|
322 | } |
---|
323 | } |
---|
324 | $template->assign( |
---|
325 | 'assoc',$assoc ); |
---|
326 | |
---|
327 | |
---|
328 | // template initialization |
---|
329 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__).'/nbc_ThemeChanger_admin.tpl')); |
---|
330 | $template->assign_var_from_handle( 'ADMIN_CONTENT', 'plugin_admin_content'); |
---|
331 | |
---|
332 | ?> |
---|