[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); |
---|
| 14 | $page_ThemeChanger_admin = get_admin_plugin_menu_link(__FILE__); |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | //chargement des catégories |
---|
[6573] | 18 | $categories = my_get_pwg_categories(); |
---|
| 19 | |
---|
[3954] | 20 | |
---|
| 21 | //chargement des thèmes |
---|
[6573] | 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 | } |
---|
[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()), |
---|
| 36 | 'U_ADD_ASSOC' => add_url_params($page_ThemeChanger_admin, array('action' => 'add_assoc')), |
---|
[6573] | 37 | 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=ThemeChanger', |
---|
[3954] | 38 | 'Themes' => $themes, |
---|
| 39 | 'Categories' => $categories, |
---|
[6573] | 40 | 'page_banner' => $conf['page_banner'], |
---|
| 41 | 'gallery_title' => $conf['gallery_title'] |
---|
[3954] | 42 | )); |
---|
| 43 | |
---|
[6573] | 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 |
---|
[3954] | 54 | if (isset($_POST['submit']) and !is_adviser()) |
---|
| 55 | if ( (isset($_POST['categorychoise']) or isset($_POST['category_id'])) and isset($_POST['template'])) |
---|
[6573] | 56 | { |
---|
| 57 | |
---|
[3954] | 58 | $listcategory = array(); |
---|
| 59 | $newconf_nbc_ThemeChanger = ''; |
---|
[6573] | 60 | $add_ok = false; |
---|
| 61 | //recupération des variables |
---|
[6552] | 62 | $theme = $_POST['template']; |
---|
[3954] | 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 .= ';'; |
---|
[6552] | 94 | $newconf_nbc_ThemeChanger .= $thecategory.','.$theme; |
---|
[3954] | 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]; |
---|
[6552] | 107 | $newconf_nbc_ThemeChanger .= $element_ThemeChanger[0].','.$element_ThemeChanger[1]; |
---|
[3954] | 108 | } |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | //insertion des nouvelles catégories |
---|
| 112 | foreach ($listcategory as $thecategory) { |
---|
| 113 | if ($newconf_nbc_ThemeChanger <> '') |
---|
| 114 | $newconf_nbc_ThemeChanger .= ';'; |
---|
| 115 | //echo ' Nouveau: '.$thecategory; |
---|
| 116 | if ($thecategory <> -1) |
---|
[6552] | 117 | $newconf_nbc_ThemeChanger .= $thecategory.','.$theme; |
---|
[3954] | 118 | } |
---|
| 119 | |
---|
| 120 | $conf['nbc_ThemeChanger'] = $newconf_nbc_ThemeChanger; |
---|
| 121 | |
---|
| 122 | $query = ' |
---|
| 123 | UPDATE '.CONFIG_TABLE.' |
---|
| 124 | SET value="'.$newconf_nbc_ThemeChanger.'" |
---|
| 125 | WHERE param="nbc_ThemeChanger" |
---|
| 126 | LIMIT 1'; |
---|
| 127 | pwg_query($query); |
---|
| 128 | |
---|
| 129 | array_push($page['infos'], l10n('nbc_ThemeChanger_save_config')); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | //delete an association |
---|
| 134 | if ( isset($_GET['action']) and ($_GET['action']=='del_assoc') and isset($_GET['id_cat']) and is_numeric($_GET['id_cat']) and !is_adviser() ) |
---|
| 135 | { |
---|
| 136 | |
---|
[6573] | 137 | $newconf_nbc_ThemeChanger = ''; |
---|
[3954] | 138 | |
---|
| 139 | foreach ($conf_nbc_ThemeChanger as $Theme_Cat) |
---|
| 140 | { |
---|
| 141 | $element_ThemeChanger = explode("," , $Theme_Cat); |
---|
| 142 | |
---|
| 143 | if ($element_ThemeChanger[0] <> $_GET['id_cat'] and $element_ThemeChanger[0] <> '') |
---|
| 144 | { |
---|
| 145 | if ($newconf_nbc_ThemeChanger <> '') |
---|
| 146 | $newconf_nbc_ThemeChanger .= ';'; |
---|
| 147 | |
---|
[6552] | 148 | $newconf_nbc_ThemeChanger .= $element_ThemeChanger[0].','.$element_ThemeChanger[1]; |
---|
[3954] | 149 | } |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | $conf['nbc_ThemeChanger'] = $newconf_nbc_ThemeChanger; |
---|
| 153 | |
---|
| 154 | $query = ' |
---|
| 155 | UPDATE '.CONFIG_TABLE.' |
---|
| 156 | SET value="'.$newconf_nbc_ThemeChanger.'" |
---|
| 157 | WHERE param="nbc_ThemeChanger" |
---|
| 158 | LIMIT 1'; |
---|
| 159 | pwg_query($query); |
---|
| 160 | |
---|
| 161 | array_push($page['infos'], l10n('nbc_ThemeChanger_save_config')); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | //modify an association |
---|
[6573] | 165 | 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']) ) |
---|
[3954] | 166 | { |
---|
| 167 | $template->assign('formulaire',array( |
---|
[6573] | 168 | 'DESCRIPION' => $lang['modify_assoc'].' : '.get_long_categorie_name($_GET['id_cat']), |
---|
| 169 | 'THEMETOMODIFY' => $_GET['id_theme'], |
---|
| 170 | 'NAMETOMODIFY' => get_long_categorie_name($_GET['id_cat']), |
---|
[3954] | 171 | 'IDTOMODIFY' => $_GET['id_cat'], |
---|
| 172 | )); |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | //add an association |
---|
| 176 | else if ( isset($_GET['action']) and ($_GET['action']=='add_assoc') ) |
---|
| 177 | { |
---|
[6573] | 178 | $template->assign('formulaire', array( |
---|
| 179 | 'DESCRIPION' => $lang['add_assoc'], |
---|
| 180 | )); |
---|
| 181 | } |
---|
[3954] | 182 | |
---|
| 183 | |
---|
[6573] | 184 | //needed to relaod the good configuration after delete |
---|
[3954] | 185 | $conf_nbc_ThemeChanger = isset($conf['nbc_ThemeChanger']) ? explode(";" , $conf['nbc_ThemeChanger']) : array(); |
---|
| 186 | |
---|
[6642] | 187 | //$num = 0; |
---|
[3954] | 188 | $catsused = array(); |
---|
| 189 | $assoc = array(); |
---|
| 190 | |
---|
[6573] | 191 | //reconstruction du tableau d'association. |
---|
[3954] | 192 | foreach ($conf_nbc_ThemeChanger as $Theme_Cat) |
---|
| 193 | { |
---|
| 194 | $element_ThemeChanger = explode("," , $Theme_Cat); |
---|
| 195 | |
---|
[6552] | 196 | if ($element_ThemeChanger[0] <> '' and $element_ThemeChanger[1] <> '') |
---|
[3954] | 197 | { |
---|
| 198 | array_push($catsused, $element_ThemeChanger[0]); |
---|
| 199 | |
---|
| 200 | $query = ' |
---|
| 201 | SELECT uppercats |
---|
| 202 | FROM '.CATEGORIES_TABLE.' |
---|
| 203 | WHERE id = \''.$element_ThemeChanger[0].'\' |
---|
| 204 | ;'; |
---|
| 205 | |
---|
| 206 | $result = pwg_query($query); |
---|
| 207 | $row = mysql_fetch_array($result); |
---|
| 208 | |
---|
| 209 | array_push($assoc , array( |
---|
[6642] | 210 | //'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1', |
---|
[6573] | 211 | 'CATEGORY_NAME' => get_cat_display_name_cache($row['uppercats'], null, false), |
---|
| 212 | 'CATEGORY_ID' => $element_ThemeChanger[0], |
---|
[6642] | 213 | 'TEMPLATE' => $element_ThemeChanger[1], |
---|
[3954] | 214 | 'U_MODIFY' => add_url_params($page_ThemeChanger_admin, array( |
---|
[6573] | 215 | 'action' => 'mod_assoc', |
---|
| 216 | 'id_cat' => $element_ThemeChanger[0], |
---|
| 217 | 'id_theme' => $element_ThemeChanger[1], |
---|
| 218 | )), |
---|
| 219 | 'U_DELETE' => add_url_params($page_ThemeChanger_admin, array( |
---|
| 220 | 'action' => 'del_assoc', |
---|
| 221 | 'id_cat' => $element_ThemeChanger[0], |
---|
| 222 | )), |
---|
| 223 | )); |
---|
[3954] | 224 | } |
---|
| 225 | } |
---|
[6573] | 226 | $template->assign('assoc',$assoc ); |
---|
[3954] | 227 | |
---|
| 228 | |
---|
| 229 | // template initialization |
---|
| 230 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__).'/nbc_ThemeChanger_admin.tpl')); |
---|
| 231 | $template->assign_var_from_handle( 'ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 232 | |
---|
[3893] | 233 | ?> |
---|