source: extensions/Icons_Set/admin.php @ 10330

Last change on this file since 10330 was 10330, checked in by flop25, 13 years ago

plugin functional !
todo : localization

File size: 7.4 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5global $template, $conf, $user;
6
7load_language('plugin.lang', ICONSET_PATH);
8$page['infos'] = array();
9
10// +-------------------------------------------------------+
11// |                  envoi de la config                   |
12// +-------------------------------------------------------+
13if (isset($_POST['envoi_config']) and $_POST['envoi_config']=='iconset')
14{
15        check_pwg_token();
16        $conf_iconset = @unserialize($conf['iconset']);//pwg_db_real_escape_string(serialize($conf_iconset))
17        $conf_themes=$conf_iconset['themes'];
18        $conf_icons=$conf_iconset['icons'];
19        $conf_icons=$conf_iconset['icons'];
20        $error_update='';
21        $update_ok='';
22        foreach ($conf_themes as $theme_id => $iconset) // theme supprimé
23        {
24                if (isset($_POST[$theme_id]) and isset($conf_themes[$theme_id]) and $conf_themes[$theme_id]!=$_POST[$theme_id] and in_array($_POST[$theme_id], $conf_icons))
25                {
26                        $conf_themes[$theme_id]=$_POST[$theme_id];
27                        $update_ok.=$theme_id.' / ';
28                }
29                elseif (empty($_POST[$theme_id]) and $conf_themes[$theme_id]!=$_POST[$theme_id])
30                {
31                        $conf_themes[$theme_id]='';
32                        $update_ok.=$theme_id.' / ';
33                }
34                elseif (!isset($_POST[$theme_id]) or !isset($conf_themes[$theme_id]) or (!in_array($_POST[$theme_id], $conf_icons) and !empty($_POST[$theme_id])) )
35                {
36                        $error_update.=$theme_id.' / ';
37                }
38        }
39        $conf['iconset']=array(
40                'themes'=>$conf_themes,
41                'icons'=>$conf_icons
42                );
43  $query = '
44    UPDATE '.CONFIG_TABLE.'
45    SET value="'.pwg_db_real_escape_string(serialize($conf['iconset'])).'"
46    WHERE param="iconset"
47    LIMIT 1';
48  pwg_query($query);
49        if (!empty($error_update)) {    array_push($page['infos'], l10n('iconset_error_update').$error_update );         }
50        if (!empty($update_ok)) {       array_push($page['infos'], l10n('iconset_update_ok').$update_ok );       }
51        load_conf_from_db();
52}
53
54// +-------------------------------------------------------+
55// |            liste les icones dispo                     |
56// +-------------------------------------------------------+
57
58// RQ : un set d'icone = chemin vers le *.conf.php ; on associe (ou pas) un fichier *.conf.php par thème
59
60function get_list_iconconf_path ($dir) {
61        static $list_iconconf_path=array();
62        $dh = opendir ($dir);
63        while (($file = readdir ($dh)) !== false ) {
64                if ($file !== '.' && $file !== '..') {
65                        $path =$dir.'/'.$file;
66                        if (is_dir ($path)) { 
67                                get_list_iconconf_path ($path);
68                        }
69                        else
70                        {
71                                $page = explode('.', $file);
72                                $nb = count($page);
73                                $nom_fichier = $page[0];
74                                for ($i = 1; $i < $nb-1; $i++){
75                                 $nom_fichier .= '.'.$page[$i];
76                                }
77                                if(isset($page[1])){
78                                 $ext_fichier = $page[$nb-2].'.'.$page[$nb-1];
79                                }
80                                else {
81                                 $ext_fichier = '';
82                                }
83                       
84                                if($ext_fichier == 'conf.php') { //On ne prend que les .conf.php
85                                        $path = str_replace("./plugins/Icons_Set/icons/", "", $path);
86                                        $list_iconconf_path[]=$path;
87                                }
88                        }
89                }
90        }
91        closedir ($dh);
92        return $list_iconconf_path;
93}       
94// +-------------------------------------------------------+
95// |          Vérifie l'intégrité de la config             |
96// +-------------------------------------------------------+
97function check_config()
98{
99        global $conf, $prefixeTable, $page;
100        $conf_iconset = @unserialize($conf['iconset']);//pwg_db_real_escape_string(serialize($conf_iconset))
101        include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
102        $themes = new themes();
103        $all_icons=get_list_iconconf_path ('./plugins/Icons_Set/icons');
104        if ( !isset($conf_iconset) or empty($conf_iconset) or !is_array($conf_iconset) )
105        {
106                $conf['iconset']=array(
107                'themes'=>array(),
108                'icons'=>array()
109                );
110        }
111        $themes->sort_fs_themes();
112        $conf_themes=$conf_iconset['themes'];
113        $conf_icons=$conf_iconset['icons'];
114        $list_theme_id=array();
115        $info_new_theme='';
116        $info_new_icon='';
117        $info_deleted_theme='';
118        $info_deleted_icon='';
119        foreach ($themes->fs_themes as $theme_id => $fs_theme)
120        {
121    if  ((isset($fs_theme['activable']) and !$fs_theme['activable']) or $theme_id == 'default' )
122                {
123                        continue;
124                }
125                if (!array_key_exists($fs_theme['id'], $conf_themes)) // theme ajouté
126                {
127                        $info_new_theme.=$theme_id.'<br>';
128                        $conf_themes[$theme_id]=''; // RAZ
129                }
130                if (!empty($conf_themes[$theme_id]) and !in_array($conf_themes[$theme_id], $all_icons))  //  association thème/icon supprimée
131                {
132                        $info_deleted_icon.=$conf_themes[$theme_id].'<br>';
133                        $conf_themes[$theme_id]=''; // RAZ
134                }
135                $list_theme_id[]=$theme_id;
136        }
137        foreach ($conf_themes as $theme_id => $iconset) // theme supprimé
138        {
139                if (!in_array($theme_id, $list_theme_id))
140                {
141                        $info_deleted_theme.=$theme_id.'<br>';
142                        unset($conf_themes[$theme_id]);// suppression de sa config
143                }
144        }
145        foreach ($all_icons as $iconset) // icones ajoutées
146        {
147                if (!in_array($iconset, $conf_icons))
148                {
149                        $info_new_icon.=$iconset.'<br>';
150                }
151        }
152        $conf['iconset']=array(
153                'themes'=>$conf_themes,
154                'icons'=>$all_icons
155                );
156  $query = '
157    UPDATE '.CONFIG_TABLE.'
158    SET value="'.pwg_db_real_escape_string(serialize($conf['iconset'])).'"
159    WHERE param="iconset"
160    LIMIT 1';
161  pwg_query($query);
162        load_conf_from_db();
163        if (!empty($info_new_theme)) {  array_push($page['infos'], l10n('iconset_info_new_theme').$info_new_theme );     }
164        if (!empty($info_new_icon)) {   array_push($page['infos'], l10n('iconset_info_new_icon').$info_new_icon );       }
165        if (!empty($info_deleted_theme)) {      array_push($page['infos'], l10n('iconset_info_deleted_theme').$info_deleted_theme );     }
166        if (!empty($info_deleted_icon)) {       array_push($page['infos'], l10n('iconset_info_deleted_icon').$info_deleted_icon );       }
167}
168
169// +-------------------------------------------------------+
170// |                début réel                             |
171// +-------------------------------------------------------+
172
173if (!isset($_POST['envoi_config']))// on économise du temps
174{
175        check_config();
176        load_conf_from_db();
177}
178$conf_iconset = @unserialize($conf['iconset']);//pwg_db_real_escape_string(serialize($conf_iconset))
179$conf_themes=$conf_iconset['themes'];
180$conf_icons=$conf_iconset['icons'];
181include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
182$themes = new themes();
183$themes->sort_fs_themes();
184$all_themes=array();
185
186// affichage des themes
187foreach ($conf_themes as $theme_id => $iconset)
188{
189        $all_themes[$theme_id]=array(
190        'name'=>$themes->fs_themes[$theme_id]['name'],
191        'id'=>$themes->fs_themes[$theme_id]['id'],
192        'screenshot'=>$themes->fs_themes[$theme_id]['screenshot'],
193        'icon'=>$iconset,
194        );
195}
196
197$all_icons=array();
198$values=array();
199$output=array();
200$template->func_combine_css(array(
201        'path' => 'themes/default/iconset.css',
202        ),
203        $smarty
204);
205
206// affichage des icônes
207foreach ($conf_icons as $iconset)
208{
209        @include_once('icons/'.$iconset);
210        $all_icons[]=array(
211        'path'=>$iconset,
212  'name' => $iconsetconf['name'],
213  'id' => $iconsetconf['id'],
214  'icon_file' => $iconsetconf['icon_file'],
215  'css_file' => $iconsetconf['css_file'],
216  'css_file_admin' => $iconsetconf['css_file_admin'],
217        );
218        $values[]=$iconset;
219        $output[]=$iconsetconf['name'];
220        $template->func_combine_css(array(
221                'path' => $iconsetconf['css_file_admin'],
222                ),
223                $smarty
224        );
225}
226$template->assign(array(
227  'all_themes' => $all_themes,
228  'all_icons' => $all_icons,
229  'values' => $values,
230  'output' => $output,
231));
232
233$template->assign(array(
234  'PWG_TOKEN' => get_pwg_token()
235));
236
237$template->func_combine_css(array(
238        'path' => 'plugins/'.ICONSET_DIR.'/template/admin.css',
239        ),
240        $smarty
241);
242
243$template->set_filename('plugin_admin_content', dirname(__FILE__) .'/template/admin.tpl');
244$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
245
246?>
Note: See TracBrowser for help on using the repository browser.