noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_extension.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS 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  *   NOALYSS 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 NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief the extension class manages the plugins for the security, the access
00024  * the inclusion...
00025  */
00026 /*!\brief manage the extension, it involves the table extension
00027  *
00028  * Data member
00029  * - $cn database connection
00030  * - $variable :
00031  *    -  id (extension.ex_id)
00032  *    -  name (extension.ex_name)
00033  *    - plugin_code (extension.ex_code)
00034  *    - desc (extension.ex_desc)
00035  *    - enable (extension.ex_enable)
00036  *    - filepath (extension.ex_file)
00037  */
00038 require_once 'class_menu_ref_sql.php';
00039 
00040 class Extension extends Menu_Ref_sql
00041 {
00042     public function verify()
00043     {
00044         // Verify that the elt we want to add is correct
00045         if (trim($this->me_code)=="") throw new Exception('Le code ne peut pas être vide');
00046         if (trim($this->me_menu)=="") throw new Exception('Le nom ne peut pas être vide');
00047         if (trim($this->me_file)=="") throw new Exception('Chemin incorrect');
00048         if (file_exists('..'.DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'ext'.DIRECTORY_SEPARATOR.$this->me_file) == false)
00049             throw new Exception ('Extension non trouvée, le chemin est-il correct?');
00050     }
00051     /*!@brief search a extension, the what is the column (extends_code */
00052     function search($p_what)
00053     {
00054                 $this->me_code=strtoupper($p_what);
00055                 if ( $this->load() == -1) return null;
00056                 return 1;
00057     }
00058     /*!\brief return 1 if the user given in parameter can access this extension
00059      * otherwise returns 0
00060      *\param $p_login the user login
00061      *\return 1 has access, 0 has no access
00062      */
00063     function can_request($p_login)
00064     {
00065                 $cnt=$this->cn->get_value("select count(*) from menu_ref
00066                                                                                 join profile_menu using (me_code)
00067                                                                                 join profile_user using (p_id)
00068                                                                                 where
00069                                                                                 me_code=$1
00070                                                                                 and user_name=$2",
00071                                                                 array($this->me_code,$p_login));
00072                 if ( $cnt > 0)        return 1;
00073                 return 0;
00074     }
00075     /*!@brief make an array of the available plugin for the current user
00076      * @return  an array
00077      *@see ISelect
00078      */
00079     static function make_array($cn)
00080     {
00081         $sql="select DISTINCT me_code as value, me_menu as label from ".
00082              " menu_ref join profile_menu using (me_code)
00083                                  join profile_user using (p_id) where ".
00084              " user_name=$1 and me_type='PL' ORDER BY ME_MENU";
00085         $a=$cn->get_array($sql,array($_SESSION['g_user']));
00086         return $a;
00087     }
00088     static function check_version($i)
00089     {
00090         global $version_noalyss;
00091         if ( ! isset ($version_noalyss) || $version_noalyss < $i )
00092         {
00093             alert('Cette extension ne fonctionne pas sur cette version de NOALYSS'.
00094                   ' Veuillez mettre votre programme a jour. Version minimum '.$i);
00095             exit();
00096         }
00097         Extension::check_plugin_version();
00098     }
00099         function insert_plugin()
00100         {
00101                 try
00102                 {
00103                         $this->cn->start();
00104                         $this->verify();
00105                         // check if duplicate
00106                         $this->me_code = strtoupper($this->me_code);
00107                         $count = $this->cn->get_value("select count(*) from menu_ref where me_code=$1", array($this->me_code));
00108                         if ($count != 0)
00109                                 throw new Exception("Doublon");
00110                         $this->me_type = 'PL';
00111                         $this->insert();
00112                         /**
00113                          * insert into default profile
00114                          */
00115                         $this->cn->exec_sql("insert into profile_menu(me_code,me_code_dep,p_type_display,p_id)
00116                                         values ($1,$2,$3,$4)",array($this->me_code,'EXT','S',1));
00117                         $this->cn->commit();
00118                 }
00119                 catch (Exception $exc)
00120                 {
00121                         echo alert($exc->getMessage());
00122                 }
00123         }
00124         function update_plugin()
00125         {
00126                 try
00127                 {
00128                         $this->cn->start();
00129                         $this->verify();
00130                         $this->me_type = 'PL';
00131                         $this->update();
00132                         $this->cn->commit();
00133                 }
00134                 catch (Exception $exc)
00135                 {
00136                         echo alert($exc->getMessage());
00137                 }
00138         }
00139         function remove_plugin()
00140         {
00141                 try
00142                 {
00143                         $this->cn->start();
00144                         $this->delete();
00145                         $this->cn->commit();
00146                 }
00147                 catch (Exception $exc)
00148                 {
00149                         echo alert($exc->getMessage());
00150                 }
00151         }
00152         /**
00153          *remove all the schema from the plugins
00154          * @param Database $p_cn
00155          */
00156         static function clean(Database $p_cn)
00157         {
00158                 $a_ext=array("tva_belge","amortissement","impdol","coprop","importbank");
00159                 for($i=0;$i<count($a_ext);$i++){
00160                         if ($p_cn->exist_schema($a_ext[$i])) {
00161                                 $p_cn->exec_sql("drop schema ".$a_ext[$i]." cascade");
00162                         }
00163                 }
00164         }
00165         static function check_plugin_version()
00166         {
00167             global $g_user,$version_plugin;
00168             if ($g_user->Admin() == 1)
00169             {
00170                 if (SITE_UPDATE_PLUGIN != "")
00171                 {
00172                     $update = @file_get_contents(SITE_UPDATE_PLUGIN);
00173                     if ($update > $version_plugin)
00174                     {
00175                         echo '<div class="inner_box" style="position:absolute;zindex:2;top:5px;left:360px">';
00176                         echo '<p class="notice">';
00177                         echo "Mise à jour disponible des plugins pour NOALYSS, version actuelle : $update votre version $version_plugin";
00178                         echo '</p>';
00179                         echo '</div>';
00180                     }
00181                 }
00182             }
00183         }
00184 }
00185 
 All Data Structures Namespaces Files Functions Variables Enumerations