source: extensions/Icons_Set/admin.php @ 14518

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

traduction EN and FR added
all seems good
todo : test tricky .conf.php

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