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