Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 require_once 'class_menu_ref_sql.php';
00039 include_once 'class_profile_sql.php';
00040 require_once 'class_menu_ref.php';
00041 require_once 'class_profile_menu.php';
00042
00043 class Extension extends Menu_Ref_sql
00044 {
00045 public function verify()
00046 {
00047
00048 if (trim($this->me_code)=="") throw new Exception('Le code ne peut pas être vide');
00049 if (trim($this->me_menu)=="") throw new Exception('Le nom ne peut pas être vide');
00050 if (trim($this->me_file)=="") throw new Exception('Chemin incorrect');
00051 if (file_exists('..'.DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'ext'.DIRECTORY_SEPARATOR.$this->me_file) == false)
00052 throw new Exception ('Extension non trouvée, le chemin est-il correct?');
00053 }
00054
00055 function search($p_what)
00056 {
00057 $this->me_code=strtoupper($p_what);
00058 if ( $this->load() == -1) return null;
00059 return 1;
00060 }
00061
00062
00063
00064
00065
00066 function can_request($p_login)
00067 {
00068 $cnt=$this->cn->get_value("select count(*) from menu_ref
00069 join profile_menu using (me_code)
00070 join profile_user using (p_id)
00071 where
00072 me_code=$1
00073 and user_name=$2",
00074 array($this->me_code,$p_login));
00075 if ( $cnt > 0) return 1;
00076 return 0;
00077 }
00078
00079
00080
00081
00082 static function make_array($cn)
00083 {
00084 $sql="select DISTINCT me_code as value, me_menu as label from ".
00085 " menu_ref join profile_menu using (me_code)
00086 join profile_user using (p_id) where ".
00087 " user_name=$1 and me_type='PL' ORDER BY ME_MENU";
00088 $a=$cn->get_array($sql,array($_SESSION['g_user']));
00089 return $a;
00090 }
00091 static function check_version($i)
00092 {
00093 global $version_noalyss;
00094 if ( ! isset ($version_noalyss) || $version_noalyss < $i )
00095 {
00096 alert('Cette extension ne fonctionne pas sur cette version de NOALYSS'.
00097 ' Veuillez mettre votre programme a jour. Version minimum '.$i);
00098 return;
00099 }
00100 Extension::check_plugin_version();
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110 function insert_profile_menu($p_id=1,$p_module='EXT')
00111 {
00112 global $cn;
00113
00114 $profile=new Profile_sql($cn,$p_id);
00115 if ( $profile->p_id != $p_id) {
00116 throw new Exception(_('Profil inexistant'),10);
00117 }
00118
00119 $module=new Menu_Ref($cn,$p_module);
00120 if ($module->me_code==null) {
00121 throw new Exception(_('Module inexistant'),20);
00122 }
00123
00124 $profil_menu=new Profile_Menu($cn);
00125 $profil_menu->me_code=$this->me_code;
00126 $profil_menu->me_code_dep=$p_module;
00127 $profil_menu->p_type_display='S';
00128 $profil_menu->p_id=$p_id;
00129 $cnt=$profil_menu->count(' where p_id=$1 and me_code = $2',array($p_id,$this->me_code));
00130 if ( $cnt==0) {
00131 $profil_menu->insert();
00132 }
00133
00134
00135 }
00136 function remove_from_profile_menu($p_id)
00137 {
00138 global $cn;
00139
00140 $cn->exec_sql('delete from profile_menu where (me_code = $1 or me_code in (select me_code from menu_ref where me_file=$2)) and p_id=$3',array($this->me_code,$this->me_file,$p_id));
00141
00142 }
00143
00144
00145
00146
00147
00148
00149 function insert_plugin()
00150 {
00151 try
00152 {
00153 $this->cn->start();
00154 $this->verify();
00155
00156 $this->me_code = strtoupper($this->me_code);
00157 $count = $this->cn->get_value("select count(*) from menu_ref where me_code=$1", array($this->me_code));
00158 if ($count != 0)
00159 throw new Exception("Doublon");
00160 $this->me_type = 'PL';
00161 $this->insert();
00162 $this->cn->commit();
00163 }
00164 catch (Exception $exc)
00165 {
00166 echo alert($exc->getMessage());
00167 }
00168 }
00169 function update_plugin()
00170 {
00171 try
00172 {
00173 $this->cn->start();
00174 $this->verify();
00175 $this->me_type = 'PL';
00176 $this->update();
00177 $this->cn->commit();
00178 }
00179 catch (Exception $exc)
00180 {
00181 echo alert($exc->getMessage());
00182 }
00183 }
00184 function remove_plugin()
00185 {
00186 try
00187 {
00188 $this->cn->start();
00189 $this->delete();
00190 $this->cn->commit();
00191 }
00192 catch (Exception $exc)
00193 {
00194 echo alert($exc->getMessage());
00195 }
00196 }
00197
00198
00199
00200
00201 static function clean(Database $p_cn)
00202 {
00203 $a_ext=array("tva_belge","amortissement","impdol","coprop","importbank");
00204 for($i=0;$i<count($a_ext);$i++){
00205 if ($p_cn->exist_schema($a_ext[$i])) {
00206 $p_cn->exec_sql("drop schema ".$a_ext[$i]." cascade");
00207 }
00208 }
00209 }
00210 static function check_plugin_version()
00211 {
00212 global $g_user,$version_plugin;
00213 if ($g_user->Admin() == 1)
00214 {
00215 if (SITE_UPDATE_PLUGIN != "")
00216 {
00217 $update = @file_get_contents(SITE_UPDATE_PLUGIN);
00218 if ($update > $version_plugin)
00219 {
00220 echo '<div class="inner_box" style="position:absolute;zindex:2;top:5px;left:360px">';
00221 echo '<p class="notice">';
00222 echo "Mise à jour disponible des plugins pour NOALYSS, version actuelle : $update votre version $version_plugin";
00223 echo '</p>';
00224 echo '</div>';
00225 }
00226 }
00227 }
00228 }
00229
00230
00231
00232
00233
00234
00235
00236 function check_xml(SimpleXMLElement $xml)
00237 {
00238 try {
00239 if ( !isset ($xml->plugin)) throw new Exception(_('Manque plugin'),1);
00240 $nb_plugin=count($xml->plugin);
00241
00242 for ($i=0;$i<$nb_plugin;$i++)
00243 {
00244 if ( !isset ($xml->plugin[$i]->name)) throw new Exception(_('Manque nom'),1);
00245 if ( !isset ($xml->plugin[$i]->description)) throw new Exception(_('Manque description'),0);
00246 if ( !isset ($xml->plugin[$i]->code)) throw new Exception(_('Manque code'),1);
00247 if ( !isset ($xml->plugin[$i]->author)) throw new Exception(_('Manque auteur'),0);
00248 if ( !isset ($xml->plugin[$i]->root)) throw new Exception(_('Manque répertoire racine'),1);
00249 if ( !isset ($xml->plugin[$i]->file)) throw new Exception(_('Manque fichier à inclure'),1);
00250 }
00251 } catch (Exception $ex) {
00252 throw $ex;
00253 }
00254 }
00255
00256
00257
00258
00259
00260
00261 static function read_definition($p_file)
00262 {
00263 global $cn;
00264 $dom=new DomDocument('1.0');
00265 $dom->load($p_file);
00266 $xml=simplexml_import_dom($dom);
00267 $nb_plugin=count($xml->plugin);
00268 $a_extension=array();
00269 for ($i=0;$i<$nb_plugin;$i++)
00270 {
00271
00272 $extension=new Extension($cn);
00273 try {
00274 $extension->check_xml($xml);
00275 } catch (Exception $ex) {
00276 echo_warning($e->getMessage());
00277 if ( $ex->getCode()==1) {
00278 continue;
00279 }
00280
00281 }
00282 $extension->me_file=trim($xml->plugin[$i]->root).'/'.trim($xml->plugin[$i]->file);
00283 $extension->me_code=trim($xml->plugin[$i]->code);
00284 $extension->me_description=(isset ($xml->plugin[$i]->description))?$xml->plugin[$i]->description:"";
00285 $extension->me_description_etendue=($xml->plugin[$i]->author)?$xml->plugin[$i]->author:"";
00286 $extension->me_type='PL';
00287 $extension->me_menu=$xml->plugin[$i]->name;
00288 $extension->me_parameter='plugin_code='.trim($xml->plugin[$i]->code);
00289 $a_extension[]=clone $extension;
00290 }
00291 return $a_extension;
00292 }
00293 }
00294