1 | <?php |
---|
2 | |
---|
3 | include_once (NBC_ThemeChanger_PATH.'include/functions_ThemeChanger.inc.php'); |
---|
4 | |
---|
5 | global $user, $conf, $template; |
---|
6 | |
---|
7 | $__BEBUG = 0; |
---|
8 | |
---|
9 | // Check Access and exit when user status is not ok |
---|
10 | check_status(ACCESS_ADMINISTRATOR); |
---|
11 | |
---|
12 | $me = get_plugin_data($plugin_id); |
---|
13 | load_language('plugin.lang', NBC_ThemeChanger_PATH); |
---|
14 | $page_ThemeChanger_admin = get_admin_plugin_menu_link(__FILE__); |
---|
15 | |
---|
16 | |
---|
17 | //chargement des catégories |
---|
18 | $categories = my_get_pwg_categories(); |
---|
19 | |
---|
20 | |
---|
21 | //chargement des thèmes |
---|
22 | $themes = my_get_pwg_themes(); |
---|
23 | if ($__BEBUG) |
---|
24 | { |
---|
25 | echo '0 '.$themes[0]['id'] .':'. $themes[0]['name'] .'<br>'; |
---|
26 | echo '0 '.$themes[1]['id'] .':'. $themes[1]['name'] .'<br>'; |
---|
27 | echo '0 '.$themes[2]['id'] .':'. $themes[2]['name'] .'<br>'; |
---|
28 | echo '0 '.$themes[3]['id'] .':'. $themes[3]['name'] .'<br>'; |
---|
29 | } |
---|
30 | |
---|
31 | // Configuration du template |
---|
32 | $template->assign('params', |
---|
33 | array( |
---|
34 | 'U_HOME' => make_index_url(), |
---|
35 | 'F_ACTION' => add_url_params($page_ThemeChanger_admin, array()), |
---|
36 | 'U_ADD_ASSOC' => add_url_params($page_ThemeChanger_admin, array('action' => 'add_assoc')), |
---|
37 | 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=ThemeChanger', |
---|
38 | 'Themes' => $themes, |
---|
39 | 'Categories' => $categories, |
---|
40 | 'page_banner' => $conf['page_banner'], |
---|
41 | 'gallery_title' => $conf['gallery_title'] |
---|
42 | )); |
---|
43 | |
---|
44 | // Configuration du formulaire |
---|
45 | $template->assign('formulaire',array( |
---|
46 | 'DESCRIPION' => $lang['add_assoc'], |
---|
47 | )); |
---|
48 | |
---|
49 | //Recupération options du plugin |
---|
50 | $conf_nbc_ThemeChanger = isset($conf['nbc_ThemeChanger']) ? explode(";" , $conf['nbc_ThemeChanger']) : array(); |
---|
51 | |
---|
52 | |
---|
53 | // Mise a jour des paramètres du plugin |
---|
54 | if (isset($_POST['submit']) and !is_adviser()) |
---|
55 | if ( (isset($_POST['categorychoise']) or isset($_POST['category_id'])) and isset($_POST['template'])) |
---|
56 | { |
---|
57 | |
---|
58 | $listcategory = array(); |
---|
59 | $newconf_nbc_ThemeChanger = ''; |
---|
60 | $add_ok = false; |
---|
61 | //recupération des variables |
---|
62 | $theme = $_POST['template']; |
---|
63 | $applysubcategory = isset($_POST['ApplySubCategories']) ? $_POST['ApplySubCategories'] : ''; |
---|
64 | $thecategory = isset($_POST['categorychoise']) ? $_POST['categorychoise'] : ( isset($_POST['category_id']) ? $_POST['category_id'] : ''); |
---|
65 | |
---|
66 | $_POST['categorychoise'] = ''; |
---|
67 | $_POST['category_id'] = ''; |
---|
68 | $_POST['template'] = ''; |
---|
69 | $_GET['action'] = ''; |
---|
70 | $_POST['ApplySubCategories'] = ''; |
---|
71 | |
---|
72 | if ($applysubcategory <> '') { |
---|
73 | foreach ($categories as $icat) { |
---|
74 | $tmp = explode("," , $icat['uppercats']); |
---|
75 | if (in_array ($thecategory, $tmp)) |
---|
76 | array_push($listcategory ,$icat['id']); |
---|
77 | } |
---|
78 | } |
---|
79 | else |
---|
80 | array_push($listcategory ,$thecategory); |
---|
81 | |
---|
82 | foreach ($conf_nbc_ThemeChanger as $Theme_Cat) |
---|
83 | { |
---|
84 | $add_ok = false; |
---|
85 | $element_ThemeChanger = explode("," , $Theme_Cat); |
---|
86 | $i = 0; |
---|
87 | foreach ($listcategory as $thecategory) |
---|
88 | { |
---|
89 | if ($element_ThemeChanger[0] == $thecategory) //MAJ de la nouvelle category déjà présente dans la liste |
---|
90 | { |
---|
91 | //echo ' MAJ: '.$element_ThemeChanger[0]; |
---|
92 | if ($newconf_nbc_ThemeChanger <> '') |
---|
93 | $newconf_nbc_ThemeChanger .= ';'; |
---|
94 | $newconf_nbc_ThemeChanger .= $thecategory.','.$theme; |
---|
95 | $listcategory[$i] = -1; |
---|
96 | $add_ok = true; |
---|
97 | break; |
---|
98 | } |
---|
99 | $i += 1; |
---|
100 | } |
---|
101 | if ($add_ok == false){ |
---|
102 | //récupération des catégories qui n'ont pas été modifié. |
---|
103 | if ($element_ThemeChanger[0] <> '') { |
---|
104 | if ($newconf_nbc_ThemeChanger <> '') |
---|
105 | $newconf_nbc_ThemeChanger .= ';'; |
---|
106 | //echo ' Recup : '.$element_ThemeChanger[0]; |
---|
107 | if ($element_ThemeChanger[1]) |
---|
108 | $newconf_nbc_ThemeChanger .= $element_ThemeChanger[0].','.$element_ThemeChanger[1]; |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|
112 | //insertion des nouvelles catégories |
---|
113 | foreach ($listcategory as $thecategory) { |
---|
114 | if ($newconf_nbc_ThemeChanger <> '') |
---|
115 | $newconf_nbc_ThemeChanger .= ';'; |
---|
116 | //echo ' Nouveau: '.$thecategory; |
---|
117 | if ($thecategory <> -1) |
---|
118 | $newconf_nbc_ThemeChanger .= $thecategory.','.$theme; |
---|
119 | } |
---|
120 | |
---|
121 | $conf['nbc_ThemeChanger'] = $newconf_nbc_ThemeChanger; |
---|
122 | |
---|
123 | $query = ' |
---|
124 | UPDATE '.CONFIG_TABLE.' |
---|
125 | SET value="'.$newconf_nbc_ThemeChanger.'" |
---|
126 | WHERE param="nbc_ThemeChanger" |
---|
127 | LIMIT 1'; |
---|
128 | pwg_query($query); |
---|
129 | |
---|
130 | array_push($page['infos'], l10n('nbc_ThemeChanger_save_config')); |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | //delete an association |
---|
135 | if ( isset($_GET['action']) and ($_GET['action']=='del_assoc') and isset($_GET['id_cat']) and is_numeric($_GET['id_cat']) and !is_adviser() ) |
---|
136 | { |
---|
137 | |
---|
138 | $newconf_nbc_ThemeChanger = ''; |
---|
139 | |
---|
140 | foreach ($conf_nbc_ThemeChanger as $Theme_Cat) |
---|
141 | { |
---|
142 | $element_ThemeChanger = explode("," , $Theme_Cat); |
---|
143 | |
---|
144 | if ($element_ThemeChanger[0] <> $_GET['id_cat'] and $element_ThemeChanger[0] <> '') |
---|
145 | { |
---|
146 | if ($newconf_nbc_ThemeChanger <> '') |
---|
147 | $newconf_nbc_ThemeChanger .= ';'; |
---|
148 | |
---|
149 | $newconf_nbc_ThemeChanger .= $element_ThemeChanger[0].','.$element_ThemeChanger[1]; |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | $conf['nbc_ThemeChanger'] = $newconf_nbc_ThemeChanger; |
---|
154 | |
---|
155 | $query = ' |
---|
156 | UPDATE '.CONFIG_TABLE.' |
---|
157 | SET value="'.$newconf_nbc_ThemeChanger.'" |
---|
158 | WHERE param="nbc_ThemeChanger" |
---|
159 | LIMIT 1'; |
---|
160 | pwg_query($query); |
---|
161 | |
---|
162 | array_push($page['infos'], l10n('nbc_ThemeChanger_save_config')); |
---|
163 | } |
---|
164 | |
---|
165 | //modify an association |
---|
166 | else if ( isset($_GET['action']) and ($_GET['action']=='mod_assoc') and isset($_GET['id_cat']) and is_numeric($_GET['id_cat']) and isset($_GET['id_theme']) ) |
---|
167 | { |
---|
168 | $template->assign('formulaire',array( |
---|
169 | 'DESCRIPION' => $lang['modify_assoc'].' : '.get_long_categorie_name($_GET['id_cat']), |
---|
170 | 'THEMETOMODIFY' => $_GET['id_theme'], |
---|
171 | 'NAMETOMODIFY' => get_long_categorie_name($_GET['id_cat']), |
---|
172 | 'IDTOMODIFY' => $_GET['id_cat'], |
---|
173 | )); |
---|
174 | } |
---|
175 | |
---|
176 | //add an association |
---|
177 | else if ( isset($_GET['action']) and ($_GET['action']=='add_assoc') ) |
---|
178 | { |
---|
179 | $template->assign('formulaire', array( |
---|
180 | 'DESCRIPION' => $lang['add_assoc'], |
---|
181 | )); |
---|
182 | } |
---|
183 | |
---|
184 | |
---|
185 | //needed to relaod the good configuration after delete |
---|
186 | $conf_nbc_ThemeChanger = isset($conf['nbc_ThemeChanger']) ? explode(";" , $conf['nbc_ThemeChanger']) : array(); |
---|
187 | |
---|
188 | //$num = 0; |
---|
189 | $catsused = array(); |
---|
190 | $assoc = array(); |
---|
191 | |
---|
192 | //reconstruction du tableau d'association. |
---|
193 | foreach ($conf_nbc_ThemeChanger as $Theme_Cat) |
---|
194 | { |
---|
195 | $element_ThemeChanger = explode("," , $Theme_Cat); |
---|
196 | |
---|
197 | if ($element_ThemeChanger[0] <> '' and $element_ThemeChanger[1] <> '') |
---|
198 | { |
---|
199 | array_push($catsused, $element_ThemeChanger[0]); |
---|
200 | |
---|
201 | $query = ' |
---|
202 | SELECT uppercats |
---|
203 | FROM '.CATEGORIES_TABLE.' |
---|
204 | WHERE id = \''.$element_ThemeChanger[0].'\' |
---|
205 | ;'; |
---|
206 | |
---|
207 | $result = pwg_query($query); |
---|
208 | $row = mysql_fetch_array($result); |
---|
209 | |
---|
210 | array_push($assoc , array( |
---|
211 | //'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1', |
---|
212 | 'CATEGORY_NAME' => get_cat_display_name_cache($row['uppercats'], null, false), |
---|
213 | 'CATEGORY_ID' => $element_ThemeChanger[0], |
---|
214 | 'TEMPLATE' => $element_ThemeChanger[1], |
---|
215 | 'STATUS' => my_get_pwg_theme_status($element_ThemeChanger[1]), |
---|
216 | 'U_MODIFY' => add_url_params($page_ThemeChanger_admin, array( |
---|
217 | 'action' => 'mod_assoc', |
---|
218 | 'id_cat' => $element_ThemeChanger[0], |
---|
219 | 'id_theme' => $element_ThemeChanger[1], |
---|
220 | )), |
---|
221 | 'U_DELETE' => add_url_params($page_ThemeChanger_admin, array( |
---|
222 | 'action' => 'del_assoc', |
---|
223 | 'id_cat' => $element_ThemeChanger[0], |
---|
224 | )), |
---|
225 | )); |
---|
226 | } |
---|
227 | } |
---|
228 | $template->assign('assoc',$assoc ); |
---|
229 | |
---|
230 | |
---|
231 | // template initialization |
---|
232 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__).'/nbc_ThemeChanger_admin.tpl')); |
---|
233 | $template->assign_var_from_handle( 'ADMIN_CONTENT', 'plugin_admin_content'); |
---|
234 | |
---|
235 | ?> |
---|