noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
cfgplugin.inc.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   PhpCompta is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 // Copyright (2014) Author Dany De Bontridder <dany@alchimerys.be>
00020 
00021 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00022 require_once 'class_extension.php';
00023 
00024 /**
00025  * @file
00026  * @brief Automatic installation of plugins and activation
00027  */
00028 global $cn;
00029 
00030 /******************************************************************************
00031  * Scan the plugin folder and file in each subfolder a property file and
00032  * store them into an array a_plugin
00033  ******************************************************************************
00034  */
00035 $dirscan=scandir('../include/ext/');
00036 $nb_dirscan=count($dirscan);
00037 $a_plugin=array();
00038 for ($e=0;$e<$nb_dirscan;$e++) {
00039     if ($dirscan[$e] != '.' && $dirscan[$e]!='..' && is_dir('../include/ext/'.$dirscan[$e])) {
00040         $dir_plugin=$dirscan[$e];
00041         if (file_exists('../include/ext/'.$dir_plugin.'/plugin.xml')) {
00042 
00043             $extension=Extension::read_definition('../include/ext/'.$dir_plugin.'/plugin.xml');
00044             for ($i=0;$i<count($extension);$i++)
00045             {
00046                 $a_plugin[]=clone $extension[$i];
00047             }
00048             
00049         }
00050     }
00051 }
00052 $nb_plugin=count($a_plugin);
00053 
00054 /**
00055  * available profiles
00056  */
00057 $a_profile=$cn->get_array('select p_id,p_name from profile where p_id > 0 order by p_name');
00058 $nb_profile=count($a_profile);
00059 /******************************************************************************
00060  * save 
00061  ******************************************************************************/
00062 if ( isset ($_POST['save_plugin'])){
00063     // retrieve array of plugin
00064     $plugin=HtmlInput::default_value_post('plugin', array());
00065     // for each extension
00066     for ($i=0;$i<$nb_plugin;$i++) {
00067         
00068         $code=$a_plugin[$i]->me_code;
00069         // for each profile
00070         for ($e=0;$e<$nb_profile;$e++)
00071         {
00072             $profile=$a_profile[$e]['p_id'];
00073             if ( isset ($plugin[$code][$profile])) {
00074                 // insert or update into db
00075                 $count = $cn->get_value("select count(*) from menu_ref where me_code=$1", array($code));
00076                 if ( $count == 0 ) {
00077                     $a_plugin[$i]->insert();
00078                 }
00079                 $a_plugin[$i]->insert_profile_menu($profile,'EXT');
00080             } else {
00081                 // delete
00082                 $a_plugin[$i]->remove_from_profile_menu ($profile);
00083             }
00084     }
00085     }
00086 }
00087 /******************************************************************************
00088  * Display the Plugin and for each profile were it is installed or not
00089  ******************************************************************************/
00090 
00091 
00092 ?>
00093 <div class="content">
00094     <?php echo _('Nombre de plugins trouvés')." ".$nb_plugin; ?>
00095     <form method="post">
00096     <table class="result">
00097         <tr>
00098             <th><?php echo _('Extension')?></th>
00099             <th><?php echo _('Menu')?></th>
00100             <th><?php echo _('Description')?></th>
00101             <th><?php echo _('Chemin')?></th>
00102             <th><?php echo _('Disponible')?></th>
00103         </tr>
00104         <?php for ($e=0;$e<$nb_plugin;$e++) : 
00105             //-----
00106             $a_profile=$cn->get_array("select distinct
00107                     p_id,p_name,
00108                     (select count(*)  from profile_menu as a where a.p_id=b.p_id and me_code=$1 )+
00109                     (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 
00110                     from profile as b  
00111                     where p_id > 0 
00112                     order by p_name",array($a_plugin[$e]->me_code,$a_plugin[$e]->me_file));
00113 
00114             $class=($e%2==0)?'odd':'even';
00115             ?>
00116         <tr class="<?php echo $class?>">
00117             <td>
00118                 <?php echo h($a_plugin[$e]->me_code); ?>
00119             </td>
00120             <td>
00121                 <?php echo h($a_plugin[$e]->me_menu); ?>
00122             </td>
00123             <td>
00124                 <?php echo h($a_plugin[$e]->me_description); ?>
00125             </td>
00126             <td>
00127                 <?php echo h($a_plugin[$e]->me_file); ?>
00128             </td>
00129             <td>
00130                 <?php 
00131                 
00132                     for ($w=0;$w<$nb_profile;$w++) :
00133                         ?>
00134                     <span style="display:block">
00135                     
00136                     <?php
00137                         $a=new ICheckBox('plugin['.$a_plugin[$e]->me_code.']['.$a_profile[$w]['p_id'].']');
00138                         if ($a_profile[$w]['cnt']>0) $a->selected=true;
00139                         echo $a->input();
00140                         echo $a_profile[$w]['p_name'];
00141                  ?>
00142                     </span>
00143                     <?php
00144                     endfor;
00145                 ?>
00146             </td>
00147         </tr>
00148         
00149         <?php endfor; ?>
00150     </table>
00151         <?php echo HtmlInput::submit('save_plugin', _('Valider')); ?>
00152    </form>
00153 </div>
00154 
 All Data Structures Namespaces Files Functions Variables Enumerations