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