[3893] | 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 | |
---|
| 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 | |
---|
| 64 | $newconf_nbc_ThemeChanger = ''; |
---|
| 65 | $theme = explode("/" , $_POST['template']); |
---|
| 66 | $add_ok = false; |
---|
| 67 | |
---|
| 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 | |
---|
| 75 | foreach ($conf_nbc_ThemeChanger as $Theme_Cat) |
---|
| 76 | { |
---|
| 77 | $element_ThemeChanger = explode("," , $Theme_Cat); |
---|
| 78 | |
---|
| 79 | if ($newconf_nbc_ThemeChanger <> '') |
---|
| 80 | $newconf_nbc_ThemeChanger .= ';'; |
---|
| 81 | |
---|
| 82 | if ($element_ThemeChanger[0] == $thecategory) |
---|
| 83 | { |
---|
| 84 | $newconf_nbc_ThemeChanger .= $thecategory.','.$theme[0].','.$theme[1]; |
---|
| 85 | $add_ok = true; |
---|
| 86 | } |
---|
| 87 | else if ($element_ThemeChanger[0] <> '') |
---|
| 88 | { |
---|
| 89 | $newconf_nbc_ThemeChanger .= $element_ThemeChanger[0].','.$element_ThemeChanger[1].','.$element_ThemeChanger[2]; |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | if ($add_ok == false) |
---|
| 94 | { |
---|
| 95 | if ($newconf_nbc_ThemeChanger <> '') |
---|
| 96 | $newconf_nbc_ThemeChanger .= ';'; |
---|
| 97 | |
---|
| 98 | $newconf_nbc_ThemeChanger .= $thecategory.','.$theme[0].','.$theme[1]; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | $conf['nbc_ThemeChanger'] = $newconf_nbc_ThemeChanger; |
---|
| 102 | |
---|
| 103 | $query = ' |
---|
| 104 | UPDATE '.CONFIG_TABLE.' |
---|
| 105 | SET value="'.$newconf_nbc_ThemeChanger.'" |
---|
| 106 | WHERE param="nbc_ThemeChanger" |
---|
| 107 | LIMIT 1'; |
---|
| 108 | pwg_query($query); |
---|
| 109 | |
---|
| 110 | array_push($page['infos'], l10n('nbc_ThemeChanger_save_config')); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | $conf_nbc_ThemeChanger = isset($conf['nbc_ThemeChanger']) ? explode(";" , $conf['nbc_ThemeChanger']) : array(); |
---|
| 116 | |
---|
| 117 | $catsused = array(); |
---|
| 118 | $assoc_ThemeChanger = array(); |
---|
| 119 | |
---|
| 120 | foreach ($conf_nbc_ThemeChanger as $Theme_Cat) |
---|
| 121 | { |
---|
| 122 | $element_ThemeChanger = explode("," , $Theme_Cat); |
---|
| 123 | |
---|
| 124 | if ($element_ThemeChanger[0] <> '' and $element_ThemeChanger[1] <> '' and $element_ThemeChanger[2] <> '') |
---|
| 125 | { |
---|
| 126 | array_push($catsused, $element_ThemeChanger[0]); |
---|
| 127 | |
---|
| 128 | $query = ' |
---|
| 129 | SELECT uppercats |
---|
| 130 | FROM '.CATEGORIES_TABLE.' |
---|
| 131 | WHERE id = \''.$element_ThemeChanger[0].'\' |
---|
| 132 | ;'; |
---|
| 133 | |
---|
| 134 | $result = pwg_query($query); |
---|
| 135 | $row = mysql_fetch_array($result); |
---|
| 136 | |
---|
| 137 | $assoc_ThemeChanger[$element_ThemeChanger[0]] = array( |
---|
| 138 | 'CATEGORY_NAME' => get_cat_display_name_cache($row['uppercats'], null, false), |
---|
| 139 | 'TEMPLATE' => $element_ThemeChanger[1].'/'.$element_ThemeChanger[2], |
---|
| 140 | ); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | //delete an association |
---|
| 148 | if ( isset($_GET['action']) and ($_GET['action']=='del_assoc') and isset($_GET['id_cat']) and is_numeric($_GET['id_cat']) and !is_adviser() ) |
---|
| 149 | { |
---|
| 150 | $conf_nbc_ThemeChanger = isset($conf['nbc_ThemeChanger']) ? explode(";" , $conf['nbc_ThemeChanger']) : array(); |
---|
| 151 | |
---|
| 152 | $newconf_nbc_ThemeChanger = ''; |
---|
| 153 | |
---|
| 154 | foreach ($conf_nbc_ThemeChanger as $Theme_Cat) |
---|
| 155 | { |
---|
| 156 | $element_ThemeChanger = explode("," , $Theme_Cat); |
---|
| 157 | |
---|
| 158 | if ($element_ThemeChanger[0] <> $_GET['id_cat'] and $element_ThemeChanger[0] <> '') |
---|
| 159 | { |
---|
| 160 | if ($newconf_nbc_ThemeChanger <> '') |
---|
| 161 | $newconf_nbc_ThemeChanger .= ';'; |
---|
| 162 | |
---|
| 163 | $newconf_nbc_ThemeChanger .= $element_ThemeChanger[0].','.$element_ThemeChanger[1].','.$element_ThemeChanger[2]; |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | $conf['nbc_ThemeChanger'] = $newconf_nbc_ThemeChanger; |
---|
| 168 | |
---|
| 169 | $query = ' |
---|
| 170 | UPDATE '.CONFIG_TABLE.' |
---|
| 171 | SET value="'.$newconf_nbc_ThemeChanger.'" |
---|
| 172 | WHERE param="nbc_ThemeChanger" |
---|
| 173 | LIMIT 1'; |
---|
| 174 | pwg_query($query); |
---|
| 175 | |
---|
| 176 | array_push($page['infos'], l10n('nbc_ThemeChanger_save_config')); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | //modify an association |
---|
| 180 | else if ( isset($_GET['action']) and ($_GET['action']=='mod_assoc') and isset($_GET['id_cat']) and is_numeric($_GET['id_cat']) ) |
---|
| 181 | { |
---|
| 182 | $template->assign('formulaire',array( |
---|
| 183 | 'DESCRIPION' => $lang['modify_assoc'].' : '.$assoc_ThemeChanger[$_GET['id_cat']]['CATEGORY_NAME'], |
---|
| 184 | 'NAMETOMODIFY' => $assoc_ThemeChanger[$_GET['id_cat']]['CATEGORY_NAME'], |
---|
| 185 | 'IDTOMODIFY' => $_GET['id_cat'], |
---|
| 186 | )); |
---|
| 187 | |
---|
| 188 | $template->assign('formulaire.categoryfield', array( |
---|
| 189 | 'NAME' => $assoc_ThemeChanger[$_GET['id_cat']]['CATEGORY_NAME'], |
---|
| 190 | 'ID' => $_GET['id_cat'], |
---|
| 191 | )); |
---|
| 192 | |
---|
| 193 | $blockname = 'formulaire.template_option'; |
---|
| 194 | |
---|
| 195 | foreach (get_pwg_themes() as $pwg_template) |
---|
| 196 | { |
---|
| 197 | if ($assoc_ThemeChanger[$_GET['id_cat']]['TEMPLATE'] == $pwg_template) |
---|
| 198 | { |
---|
| 199 | $selected = 'selected="selected"'; |
---|
| 200 | } |
---|
| 201 | else |
---|
| 202 | { |
---|
| 203 | $selected = ''; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | $template->assign( |
---|
| 207 | $blockname, |
---|
| 208 | array( |
---|
| 209 | 'VALUE'=> $pwg_template, |
---|
| 210 | 'CONTENT' => $pwg_template, |
---|
| 211 | 'SELECTED' => $selected |
---|
| 212 | )); |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | //add an association |
---|
| 217 | else if ( isset($_GET['action']) and ($_GET['action']=='add_assoc') ) |
---|
| 218 | { |
---|
| 219 | //$template->assign_var('formulaire',array( |
---|
| 220 | $template->assign( |
---|
| 221 | 'formulaire', |
---|
| 222 | array('DESCRIPION' => $lang['add_assoc'], |
---|
| 223 | ) |
---|
| 224 | ); |
---|
| 225 | |
---|
| 226 | $template->assign('formulaire.categorylist', array()); |
---|
| 227 | $blockname = 'formulaire.categorylist.parent_option'; |
---|
| 228 | |
---|
| 229 | $template->assign($blockname, array()); |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | $query = ' |
---|
| 233 | SELECT id, name, uppercats, global_rank |
---|
| 234 | FROM '.CATEGORIES_TABLE.' |
---|
| 235 | '; |
---|
| 236 | if (!empty($catsused)) |
---|
| 237 | { |
---|
| 238 | $query .= ' |
---|
| 239 | WHERE id NOT IN ('.implode(',', $catsused).') |
---|
| 240 | '; |
---|
| 241 | } |
---|
| 242 | $query .= ' ;'; |
---|
| 243 | display_select_cat_wrapper($query, array(), $blockname); |
---|
| 244 | |
---|
| 245 | $blockname = 'formulaire.template_option'; |
---|
| 246 | |
---|
| 247 | foreach (get_pwg_themes() as $pwg_template) |
---|
| 248 | { |
---|
| 249 | $template->assign( |
---|
| 250 | $blockname, |
---|
| 251 | array( |
---|
| 252 | 'VALUE'=> $pwg_template, |
---|
| 253 | 'CONTENT' => $pwg_template, |
---|
| 254 | 'SELECTED' => '', |
---|
| 255 | ) |
---|
| 256 | ); |
---|
| 257 | } |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | $conf_nbc_ThemeChanger = isset($conf['nbc_ThemeChanger']) ? explode(";" , $conf['nbc_ThemeChanger']) : array(); |
---|
| 261 | |
---|
| 262 | $num = 0; |
---|
| 263 | $catsused = array(); |
---|
| 264 | $assoc_ThemeChanger = array(); |
---|
| 265 | $assoc = array(); |
---|
| 266 | |
---|
| 267 | foreach ($conf_nbc_ThemeChanger as $Theme_Cat) |
---|
| 268 | { |
---|
| 269 | $element_ThemeChanger = explode("," , $Theme_Cat); |
---|
| 270 | |
---|
| 271 | if ($element_ThemeChanger[0] <> '' and $element_ThemeChanger[1] <> '' and $element_ThemeChanger[2] <> '') |
---|
| 272 | { |
---|
| 273 | array_push($catsused, $element_ThemeChanger[0]); |
---|
| 274 | |
---|
| 275 | $query = ' |
---|
| 276 | SELECT uppercats |
---|
| 277 | FROM '.CATEGORIES_TABLE.' |
---|
| 278 | WHERE id = \''.$element_ThemeChanger[0].'\' |
---|
| 279 | ;'; |
---|
| 280 | |
---|
| 281 | $result = pwg_query($query); |
---|
| 282 | $row = mysql_fetch_array($result); |
---|
| 283 | |
---|
| 284 | array_push($assoc , array( |
---|
| 285 | 'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1', |
---|
| 286 | 'CATEGORY_NAME' => get_cat_display_name_cache($row['uppercats'], null, false), |
---|
| 287 | 'CATEGORY_ID' => $element_ThemeChanger[0], |
---|
| 288 | 'TEMPLATE' => $element_ThemeChanger[1].'/'.$element_ThemeChanger[2], |
---|
| 289 | 'U_MODIFY' => add_url_params($page_ThemeChanger_admin, array( |
---|
| 290 | 'action' => 'mod_assoc', |
---|
| 291 | 'id_cat' => $element_ThemeChanger[0], |
---|
| 292 | )), |
---|
| 293 | 'U_DELETE' => add_url_params($page_ThemeChanger_admin, array( |
---|
| 294 | 'action' => 'del_assoc', |
---|
| 295 | 'id_cat' => $element_ThemeChanger[0], |
---|
| 296 | )),)); |
---|
| 297 | |
---|
| 298 | $assoc_ThemeChanger[$element_ThemeChanger[0]] = array( |
---|
| 299 | 'CATEGORY_NAME' => get_cat_display_name_cache($row['uppercats'], null, false), |
---|
| 300 | 'TEMPLATE' => $element_ThemeChanger[1].'/'.$element_ThemeChanger[2], |
---|
| 301 | ); |
---|
| 302 | } |
---|
| 303 | } |
---|
| 304 | $template->assign( |
---|
| 305 | 'assoc',$assoc ); |
---|
| 306 | |
---|
| 307 | |
---|
| 308 | // template initialization |
---|
| 309 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__).'/nbc_ThemeChanger_admin.tpl')); |
---|
| 310 | $template->assign_var_from_handle( 'ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 311 | |
---|
| 312 | ?> |
---|