1 | <?php |
---|
2 | /***************************************************************************/ |
---|
3 | class set_plugins_controler { |
---|
4 | //============================================================================= |
---|
5 | function set_plugins_admin_menu($menu) { |
---|
6 | array_push( |
---|
7 | $menu, |
---|
8 | array( |
---|
9 | 'NAME' => 'Set_plugins', |
---|
10 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__)).'/admin.php' |
---|
11 | ) |
---|
12 | ); |
---|
13 | return $menu; |
---|
14 | } |
---|
15 | //============================================================================ |
---|
16 | function set_plugins_add() { |
---|
17 | global $user, $template, $val,$page,$conf; |
---|
18 | if (!isset($page['body_id'])) return; |
---|
19 | if (!isset($page['body_id'])) return; |
---|
20 | switch($page['body_id']){ |
---|
21 | case 'theAdminPage': |
---|
22 | switch($page['page']){ |
---|
23 | case 'plugins_list': |
---|
24 | if(!isset($template)) return ; |
---|
25 | set_plugins_controler::Affiche_set_plugins(); |
---|
26 | break; |
---|
27 | case 'plugins': |
---|
28 | if (!isset($page['tab'])) return; |
---|
29 | if ($page['tab']!="installed") return ; |
---|
30 | set_plugins_controler::Affiche_set_plugins(); |
---|
31 | break; |
---|
32 | } |
---|
33 | } |
---|
34 | } |
---|
35 | //============================================================================ |
---|
36 | function cl_affiche_messages_admin() |
---|
37 | { |
---|
38 | global $template,$page, $template, $pwg_loaded_plugins,$infos_message,$erreur_message,$infos_warning; |
---|
39 | if ( (isset($_GET['page']) AND $_GET['page'] == 'plugins_list') ) { |
---|
40 | if ($infos_message != "") { |
---|
41 | array_push($page['infos'], $infos_message); |
---|
42 | $infos_message=""; |
---|
43 | } |
---|
44 | if ($erreur_message != "") { |
---|
45 | array_push($page['errors'], $erreur_message); |
---|
46 | $erreur_message=""; |
---|
47 | } |
---|
48 | if ($infos_warning!= "") { |
---|
49 | array_push($page['warnings'], $infos_warning); |
---|
50 | $infos_warning= ""; |
---|
51 | } |
---|
52 | if (count($page['errors']) != 0){ |
---|
53 | $template->assign('errors', $page['errors']); |
---|
54 | } |
---|
55 | if (count($page['infos']) != 0){ |
---|
56 | $template->assign('infos', $page['infos']); |
---|
57 | } |
---|
58 | if (count($page['warnings']) != 0){ |
---|
59 | $template->assign('warnings', $page['warnings']); |
---|
60 | } |
---|
61 | } |
---|
62 | } |
---|
63 | //========================================================================================== |
---|
64 | function set_var($key,$defaut){ |
---|
65 | global $set_plugins_parametres; |
---|
66 | global $infos_message; |
---|
67 | |
---|
68 | if(isset($set_plugins_parametres) && isset($set_plugins_parametres[$key])) |
---|
69 | $ret=$set_plugins_parametres[$key]; |
---|
70 | |
---|
71 | $ret= (isset($ret))?$ret:$defaut; |
---|
72 | $ret=isset($_POST[$key])?$_POST[$key]:$ret; |
---|
73 | return $ret ; |
---|
74 | } |
---|
75 | //================================================================ |
---|
76 | function save_config(){ |
---|
77 | global $list_visible, $state,$liste,$nb,$page,$conf ; |
---|
78 | global $infos_message,$infos_warning,$erreur_message ; |
---|
79 | $config=array(); |
---|
80 | $config = array( |
---|
81 | 'list_visible' => $list_visible, |
---|
82 | 'state' => $state, |
---|
83 | 'list'=>$liste, |
---|
84 | 'nb' =>$nb |
---|
85 | ); |
---|
86 | // $infos_warning .="save_config" . set_plugins_controler::memo_var($conf['set_plugins'] ); |
---|
87 | $conf['set_plugins']= (serialize($config)); |
---|
88 | conf_update_param('set_plugins', $conf['set_plugins']); |
---|
89 | |
---|
90 | |
---|
91 | } |
---|
92 | //================================================================= |
---|
93 | function memo_var($variables){ |
---|
94 | ob_start(); |
---|
95 | echo '<pre>'; |
---|
96 | print_r($variables); |
---|
97 | echo '</pre>'; |
---|
98 | $m= ob_get_contents(); |
---|
99 | ob_end_clean(); |
---|
100 | return $m; |
---|
101 | } |
---|
102 | //=================================================================== |
---|
103 | function Affiche_set_plugins(){ |
---|
104 | include_once(SET_PLUGINS_PATH."include/constants.php"); |
---|
105 | include(SET_PLUGINS_PATH.'include/affiche.php'); |
---|
106 | $all_tpl_vars = $template->get_template_vars('plugins'); |
---|
107 | if(!$all_tpl_vars) return; |
---|
108 | if( $set=="true" ){ |
---|
109 | $state=""; |
---|
110 | if(isset($_POST['unset_plugins']) ) |
---|
111 | $state='inactive'; |
---|
112 | elseif(isset($_POST['set_plugins']) ) |
---|
113 | $state='active'; |
---|
114 | if($state!=""){ |
---|
115 | if($state=="inactive") |
---|
116 | $sens ="DESC"; |
---|
117 | else |
---|
118 | $sens="ASC"; |
---|
119 | //============================ |
---|
120 | $query = 'SELECT * |
---|
121 | FROM ' . PLUGINS_TABLE . ' |
---|
122 | WHERE `state` NOT LIKE "'.$state. '" AND id!="' . "set_plugins" . '" |
---|
123 | ORDER BY `id` '.$sens.' |
---|
124 | LIMIT '.$nb.' |
---|
125 | '; |
---|
126 | $result = pwg_query($query); |
---|
127 | //======= mise à jour ========= |
---|
128 | if($result){ |
---|
129 | $query = ' |
---|
130 | UPDATE '.PLUGINS_TABLE.' |
---|
131 | SET state="'.$state.'" |
---|
132 | WHERE `state` NOT LIKE "'.$state. '" AND id!="' . "set_plugins" . '" |
---|
133 | ORDER BY `id` '.$sens.' |
---|
134 | LIMIT '.$nb.';'; |
---|
135 | pwg_query($query); |
---|
136 | } |
---|
137 | //===================================== |
---|
138 | if(isset($result) && $result==true){ |
---|
139 | $liste= array_unique($liste); |
---|
140 | if(!array_search($add_plugins, $liste)){ |
---|
141 | array_push($liste, $add_plugins ); |
---|
142 | } |
---|
143 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
144 | $url = $row['id'] ; |
---|
145 | array_push($liste, $url); |
---|
146 | } |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | }else if (isset($_POST['init_plugins'])){ |
---|
151 | $liste = array(); |
---|
152 | $state="active"; |
---|
153 | $query = 'SELECT * |
---|
154 | FROM ' . PLUGINS_TABLE . ' |
---|
155 | WHERE `state` LIKE "active" AND id!="' . "set_plugins" . '" |
---|
156 | '; |
---|
157 | $result = pwg_query($query); |
---|
158 | if(isset($result) && $result==true){ |
---|
159 | $liste_plugins = array(); |
---|
160 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
161 | $url = $row['id'] ; |
---|
162 | //array_push($liste_plugins, array('plugin' => $url ) ); |
---|
163 | array_push($liste, $url ); |
---|
164 | } |
---|
165 | } |
---|
166 | $nb=count($liste_plugins); |
---|
167 | } |
---|
168 | if(isset($result) && $result==true){ |
---|
169 | $redirect_url = get_root_url().'admin.php?page='.$_GET['page']; |
---|
170 | //$infos_message .="-----> Mise à jour : " . $nb."<br />"; |
---|
171 | //$infos_message .="Liste Avant: " . set_plugins_controler::memo_var($liste); |
---|
172 | set_plugins_controler::save_config(); |
---|
173 | |
---|
174 | $_POST['set']=""; |
---|
175 | $set=""; |
---|
176 | include(SET_PLUGINS_PATH.'include/affiche.php'); |
---|
177 | |
---|
178 | // redirect($redirect_url); |
---|
179 | } |
---|
180 | // |
---|
181 | |
---|
182 | |
---|
183 | } |
---|
184 | $template->set_filenames( |
---|
185 | array( 'cl_plugin' => dirname(__FILE__).'/admin.tpl' ) |
---|
186 | ); |
---|
187 | |
---|
188 | //=========================================================== |
---|
189 | $header_1='<div id="titrePage"> |
---|
190 | <h2>'.l10n("set_plugins").l10n("Version").": ".$cl_set_plugins_plugin['version'] .'</h2> |
---|
191 | </div>'; |
---|
192 | $bpplus=$header_1.$template->parse('cl_plugin', true); |
---|
193 | $template-> assign('ADMIN_CONTENT',$bpplus); |
---|
194 | $bpplus=$template->parse('plugins', true); |
---|
195 | $template-> concat('ADMIN_CONTENT',$bpplus); |
---|
196 | |
---|
197 | } |
---|
198 | |
---|
199 | |
---|
200 | }// fin classe |
---|
201 | ?> |
---|