noalyss Version-9
cfgplugin.inc.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS isfree software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS isdistributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19// Copyright (2014) Author Dany De Bontridder <dany@alchimerys.be>
20
21if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
22
23/**
24 * @file
25 * @brief Automatic installation of plugins and activation
26 */
27global $cn;
28global $http;
29
30/******************************************************************************
31 * Scan the plugin folder and file in each subfolder a property file and
32 * store them into an array a_plugin
33 ******************************************************************************
34 */
35$dirscan=scandir(NOALYSS_PLUGIN);
37$a_plugin=array();
38for ($e=0;$e<$nb_dirscan;$e++) {
39 if ($dirscan[$e] != '.' && $dirscan[$e]!='..' && is_dir(NOALYSS_PLUGIN.'/'.$dirscan[$e])) {
40 $dir_plugin=$dirscan[$e];
41 if (file_exists(NOALYSS_PLUGIN.'/'.$dir_plugin.'/plugin.xml')) {
42
43 $extension=Extension::read_definition(NOALYSS_PLUGIN.'/'.$dir_plugin.'/plugin.xml');
44 for ($i=0;$i<count($extension);$i++)
45 {
46 $a_plugin[]=clone $extension[$i];
47 }
48
49 }
50 }
51}
53
54/**
55 * available profiles
56 */
57$a_profile=$cn->get_array('select p_id,p_name from profile where p_id > 0 order by p_name');
59/******************************************************************************
60 * save
61 ******************************************************************************/
62if ( isset ($_POST['save_plugin'])){
63 // retrieve array of plugin
64 $plugin=$http->post('plugin', "string",array());
65 // for each extension
66 for ($i=0;$i<$nb_plugin;$i++) {
67
68 $code=$a_plugin[$i]->me_code;
69 // for each profile
70 for ($e=0;$e<$nb_profile;$e++)
71 {
72 $profile=$a_profile[$e]['p_id'];
73 if ( isset ($plugin[$code][$profile])) {
74 // insert or update into db
75 $count = $cn->get_value("select count(*) from menu_ref where me_code=$1", array($code));
76 if ( $count == 0 ) {
77 $a_plugin[$i]->insert();
78 }
79 try
80 {
81 $a_plugin[$i]->insert_profile_menu($profile);
82 }
83 catch (Exception $exc)
84 {
85 record_log($exc->getMessage()." trace:".$exc->getTraceAsString());
86 $profile_name=$cn->get_value('select profile.p_name from profile where p_id=$1'
87 ,array($profile));
88 echo '<p class="notice">';
89 echo "code $code"," profile $profile_name ",$exc->getMessage();
90 echo '</p>';
91 }
92
93 } else {
94 // delete
95 $a_plugin[$i]->remove_from_profile_menu ($profile);
96 }
97 }
98 }
99}
100/******************************************************************************
101 * Display the Plugin and for each profile were it is installed or not
102 ******************************************************************************/
103
104
105?>
106<div class="content">
107 <?php echo _('Nombre de plugins trouvés')." ".$nb_plugin; ?>
108 <form method="post">
109 <?php echo _('Filtre');echo " ";echo HtmlInput::filter_table("plugin_install_tb", '0,1,2,3', 1);?>
110 <table id="plugin_install_tb" class="result">
111 <tr>
112 <th><?php echo _('Extension')?></th>
113 <th><?php echo _('Menu')?></th>
114 <th><?php echo _('Description')?></th>
115 <th><?php echo _('Chemin')?></th>
116 <th><?php echo _('Disponible')?></th>
117 </tr>
118 <?php for ($e=0;$e<$nb_plugin;$e++) :
119 //-----
120 $a_profile=$cn->get_array("select distinct
121 p_id,p_name,
122 (select count(*) from profile_menu as a where a.p_id=b.p_id and me_code=$1 )+
123 (select count(*) from menu_ref as c join profile_menu as d on (d.me_code=c.me_code) where d.p_id=b.p_id and me_file=$2 ) as cnt
124 from profile as b
125 where p_id > 0
126 order by p_name",array($a_plugin[$e]->me_code,$a_plugin[$e]->me_file));
127
128 $class=($e%2==0)?'odd':'even';
129 ?>
130 <tr class="<?php echo $class?>">
131 <td>
132 <?php echo h($a_plugin[$e]->me_code); ?>
133 </td>
134 <td>
135 <?php echo h($a_plugin[$e]->me_menu); ?>
136 </td>
137 <td>
138 <?php echo h($a_plugin[$e]->me_description);?>
139 <span style="display:block">
140 <?php
141 printf(_("Installé par défaut dans %s"),$a_plugin[$e]->depend);
142 ?>
143 </span>
144 </td>
145 <td>
146 <?php echo h($a_plugin[$e]->me_file); ?>
147 </td>
148 <td>
149 <?php
150
151 for ($w=0;$w<$nb_profile;$w++) :
152 ?>
153 <span style="display:block">
154
155 <?php
156 $a=new ICheckBox('plugin['.$a_plugin[$e]->me_code.']['.$a_profile[$w]['p_id'].']');
157 if ($a_profile[$w]['cnt']>0) $a->selected=true;
158 echo $a->input();
159 echo $a_profile[$w]['p_name'];
160 ?>
161 </span>
162 <?php
163 endfor;
164 ?>
165 </td>
166 </tr>
167
168 <?php endfor; ?>
169 </table>
170 <?php echo HtmlInput::submit('save_plugin', _('Valider')); ?>
171 </form>
172</div>
173
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
span($p_string, $p_extra='')
Definition: ac_common.php:43
tr($p_string, $p_extra='')
Definition: ac_common.php:88
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
h( $row[ 'oa_description'])
$code
$opd_description style
foreach($array as $idx=> $m) $w
$dirscan
$class
$nb_dirscan
global $http
global $cn
$a_profile
available profiles
$a_plugin
$nb_profile
for($e=0;$e< $nb_dirscan;$e++) $nb_plugin
static read_definition($p_file)
Parse a XML file to complete an array of extension objects, in the plugin.xml file ,...
static filter_table($p_table_id, $p_col, $start_row)
filter the rows in a table and keep the colored row in alternance
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
Html Input.
$all table
$_POST['ac']
Definition: do.php:310
$count
endfor