noalyss Version-9
Public Member Functions | Static Public Member Functions | Data Fields
Extension Class Reference

manage the extension, it involves the table extension More...

+ Inheritance diagram for Extension:
+ Collaboration diagram for Extension:

Public Member Functions

 __toString ()
 
 can_request ($p_login)
 return 1 if the user given in parameter can access this extension otherwise returns 0 More...
 
 check_xml (SimpleXMLElement $xml)
 Check that the xml contains all the needed information to change them into a extension, the exception code is 0 if the element is optional. More...
 
 insert_plugin ()
 Insert a plugin into the given profile, by default always insert into EXT. More...
 
 insert_profile_menu ($p_id=1)
 insert into the table profile_menu for the given profile id and depending of the module $p_module More...
 
 remove_from_profile_menu ($p_id)
 
 remove_plugin ()
 
 search ($p_what)
 search a extension, the what is the column (extends_code More...
 
 update_plugin ()
 
 verify ()
 

Static Public Member Functions

static check_plugin_version ($p_plugin_code)
 compare the version of the plugin and the last version , propose to update it if a new version exists More...
 
static check_version ($i, $p_plugin_code=null)
 check the version of the plugin , null stands for one of the standard plugins, it means self::aStandard_plugin @global type $version_noalyss More...
 
static clean (Database $p_cn)
 remove all the standard plugins schema More...
 
static find_extension_code ($a_extension, $access_code)
 find the extension with the me_code = last part of access_code More...
 
static get_version ($xml_file, $plugin_code)
 retrieve the version of the current plugin More...
 
static make_array ($cn)
 make an array of the available plugin for the current user More...
 
static read_definition ($p_file)
 Parse a XML file to complete an array of extension objects, in the plugin.xml file , you can find several plugins sharing some parts. More...
 

Data Fields

const aStandard_plugin
 

Detailed Description

manage the extension, it involves the table extension

Data member

Definition at line 46 of file extension.class.php.

Member Function Documentation

◆ __toString()

Extension::__toString ( )

Definition at line 410 of file extension.class.php.

410 : string
411 {
412 $r = "";
413 $r .= " me_code " . $this->me_code.PHP_EOL;
414 $r .= " me_menu.".$this->me_menu.PHP_EOL;
415 $r .= " version".$this->version.PHP_EOL;
416 $r .= " noalyss_version".$this->noalyss_version.PHP_EOL;
417 $r .= " me_file" . $this->me_file.PHP_EOL;
418 $r .= " me_url" . $this->me_url.PHP_EOL;
419 $r .= " me_description" . $this->me_description.PHP_EOL;
420 $r .= " me_parameter" . $this->me_parameter.PHP_EOL;
421 $r .= " me_javascript" . $this->me_javascript.PHP_EOL;
422 $r .= " me_type" . $this->me_type.PHP_EOL;
423 $r .= " me_descrition_etendue" . $this->me_description_etendue.PHP_EOL;
424 return "Extension $r";
425 }
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r

References $r.

◆ can_request()

Extension::can_request (   $p_login)

return 1 if the user given in parameter can access this extension otherwise returns 0

Parameters
$p_loginthe user login
Returns
1 has access, 0 has no access

Definition at line 85 of file extension.class.php.

86 {
87 $cnt=$this->cn->get_value("select count(*) from menu_ref
88 join profile_menu using (me_code)
89 join profile_user using (p_id)
90 where
91 me_code=$1
92 and user_name=$2", array($this->me_code, $p_login));
93 if ($cnt>0)
94 return 1;
95 return 0;
96 }
$input_from cn
Definition: balance.inc.php:66

References cn.

◆ check_plugin_version()

static Extension::check_plugin_version (   $p_plugin_code)
static

compare the version of the plugin and the last version , propose to update it if a new version exists

Todo:
add a mechanism to check once a day @global User $g_user @global number $version_plugin

Definition at line 277 of file extension.class.php.

278 {
279 global $g_user, $version_plugin;
280 if ($g_user->Admin()==1)
281 {
282 if ( in_array($p_plugin_code, self::aStandard_plugin) && SITE_UPDATE_PLUGIN!="")
283 {
284 $update=@file_get_contents(SITE_UPDATE_PLUGIN);
285 if ($update>$version_plugin)
286 {
287 echo '<div id="version_plugin_div_id" class="inner_box" style="position:absolute;zindex:2;top:5px;left:37.5%;width:25%">';
288 echo '<p class="notice">';
289 echo "Mise à jour disponible des plugins pour NOALYSS, version actuelle : $update votre version $version_plugin";
290 echo '</p>';
291 echo '<p style="text-align:center">'.
292 '<a id="version_plugin_button" class="button" onclick="$(\'version_plugin_div_id\').remove()">'.
293 _('Fermer').
294 "</a></p>";
295 echo '</div>';
296 }
297 }
298 }
299 }
global $g_user
if no group available , then stop

References $g_user.

Referenced by check_version().

◆ check_version()

static Extension::check_version (   $i,
  $p_plugin_code = null 
)
static

check the version of the plugin , null stands for one of the standard plugins, it means self::aStandard_plugin @global type $version_noalyss

Parameters
type$i
type$p_plugin_code
Returns
type

Definition at line 120 of file extension.class.php.

121 {
122 global $version_noalyss;
124 {
125 alert(_('Cette extension ne fonctionne pas sur cette version de NOALYSS'.
126 ' Veuillez mettre votre programme a jour. Version minimum ').$i);
127 return;
128 }
129 Extension::check_plugin_version($p_plugin_code);
130 }
alert($p_msg, $buffer=false)
alert in javascript
Definition: ac_common.php:738
static check_plugin_version($p_plugin_code)
compare the version of the plugin and the last version , propose to update it if a new version exists
global $version_noalyss
Definition: constant.php:26

References $i, $version_noalyss, alert(), and check_plugin_version().

+ Here is the call graph for this function:

◆ check_xml()

Extension::check_xml ( SimpleXMLElement  $xml)

Check that the xml contains all the needed information to change them into a extension, the exception code is 0 if the element is optional.

Check XML.

Parameters
SimpleXMLElement$xml
Exceptions
Exception

Definition at line 308 of file extension.class.php.

309 {
310 try
311 {
312 if (!isset($xml->plugin))
313 throw new Exception(_('Manque plugin'), 1);
314 $nb_plugin=count($xml->plugin);
315
316 for ($i=0; $i<$nb_plugin; $i++)
317 {
318 if (!isset($xml->plugin[$i]->name))
319 throw new Exception(_('Manque nom'), 1);
320 if (!isset($xml->plugin[$i]->description))
321 throw new Exception(_('Manque description'), 0);
322 if (!isset($xml->plugin[$i]->code))
323 throw new Exception(_('Manque code'), 1);
324 if (!isset($xml->plugin[$i]->author))
325 throw new Exception(_('Manque auteur'), 0);
326 if (!isset($xml->plugin[$i]->root))
327 throw new Exception(_('Manque répertoire racine'), 1);
328 if (!isset($xml->plugin[$i]->file))
329 throw new Exception(_('Manque fichier à inclure'), 1);
330 if (!isset($xml->plugin[$i]->version))
331 throw new Exception(_("Manque version de l'extension"), 1);
332
333 if (!isset($xml->plugin[$i]->depend))
334 $xml->plugin[$i]->depend="EXT";
335 if (!isset($xml->plugin[$i]->order))
336 $xml->plugin[$i]->order=9000;
337 }
338 }
339 catch (Exception $ex)
340 {
341 throw $ex;
342 }
343 }
switch($op2) $xml
Definition: ajax_card.php:806
$ex
Definition: balance.inc.php:45
for($e=0;$e< $nb_dirscan;$e++) $nb_plugin

References $ex, $i, $nb_plugin, and $xml.

◆ clean()

static Extension::clean ( Database  $p_cn)
static

remove all the standard plugins schema

Parameters
Database$p_cn

Definition at line 259 of file extension.class.php.

260 {
261 $a_ext=array("tva_belge", "amortissement", "impdol", "coprop", "importbank");
262 for ($i=0; $i<count($a_ext); $i++)
263 {
264 if ($p_cn->exist_schema($a_ext[$i]))
265 {
266 $p_cn->exec_sql("drop schema ".$a_ext[$i]." cascade");
267 }
268 }
269 }
exec_sql($p_string, $p_array=null)
send a sql string to the database

References $i, DatabaseCore\exec_sql(), and DatabaseCore\exist_schema().

+ Here is the call graph for this function:

◆ find_extension_code()

static Extension::find_extension_code (   $a_extension,
  $access_code 
)
static

find the extension with the me_code = last part of access_code

Parameters
$a_extension
$access_codefind the ME_CODE (normally last part )
Returns
the extension or null

Definition at line 398 of file extension.class.php.

398 :Extension|null
399 {
400 $a_me_code=explode("/", $access_code);
401 if (empty($a_me_code ) ) return null;
402 $nb_me_code=count($a_me_code);
403 $me_code=$a_me_code[$nb_me_code-1];
404 foreach ($a_extension as $extension) {
405 if ($extension->me_code==$me_code) return $extension;
406 }
407 return null;
408 }
manage the extension, it involves the table extension

References $access_code, and $me_code.

Referenced by get_version().

◆ get_version()

static Extension::get_version (   $xml_file,
  $plugin_code 
)
static

retrieve the version of the current plugin

Parameters
$xml_filealways DIR."/plugin.xml"
$plugin_codethe plugin or $_REQUEST['ac']
Returns
int version or -1 if not found

Definition at line 433 of file extension.class.php.

433 :int
434 {
435 $aExtension=\Extension::read_definition($xml_file);
436 $extension=self::find_extension_code($aExtension, $plugin_code);
437 if ( empty($plugin_code)) return -1;
438 return $extension->version;
439 }
static find_extension_code($a_extension, $access_code)
find the extension with the me_code = last part of access_code
static read_definition($p_file)
Parse a XML file to complete an array of extension objects, in the plugin.xml file ,...

References find_extension_code(), and read_definition().

+ Here is the call graph for this function:

◆ insert_plugin()

Extension::insert_plugin ( )

Insert a plugin into the given profile, by default always insert into EXT.

Parameters
type$p_idprofile.p_id
Exceptions
Exceptionif duplicate or error db

Definition at line 204 of file extension.class.php.

205 {
206 try
207 {
208 $this->cn->start();
209 $this->verify();
210 // check if duplicate
211 $this->me_code=strtoupper($this->me_code);
212 $count=$this->cn->get_value("select count(*) from menu_ref where me_code=$1", array($this->me_code));
213 if ($count!=0)
214 throw new Exception("Doublon");
215 $this->me_type='PL';
216 $this->insert();
217 $this->cn->commit();
218 }
219 catch (Exception $exc)
220 {
221 echo alert($exc->getMessage());
222 }
223 }
$count

References $count, alert(), cn, and verify().

+ Here is the call graph for this function:

◆ insert_profile_menu()

Extension::insert_profile_menu (   $p_id = 1)

insert into the table profile_menu for the given profile id and depending of the module $p_module

Remarks
type $cn
Parameters
type$p_idprofile.p_id
Exceptions
Exception10 : profile absent , 20 module absent , 30 No parent menu

Definition at line 139 of file extension.class.php.

140 {
141 global $cn;
142 // Module for the plugin
143 $p_module=$this->depend;
144 //profile exists ?
146 if ($profile->p_id!=$p_id)
147 {
148 throw new Exception(_('Profil inexistant'), 10);
149 }
150 // Menu exists
151 \Noalyss\Dbg::echo_var(1,__FILE__.__LINE__. "p_module to find $p_module");
152 $module=new Menu_Ref($cn, $p_module);
153 if ($module->me_code==null)
154 {
155 throw new Exception(_('Module inexistant'), 20);
156 }
157 // Dependency
158 $dep_id=$cn->get_array('select pm_id from profile_menu
159 where
160 p_id=$1
161 and me_code = $2 ', array($p_id, $p_module));
162 // throw an exception if there is no dependency
163 if (empty($dep_id))
164 {
165 throw new Exception(_('Pas de menu ').$p_module, 30);
166 }
167 $nb_dep=count($dep_id);
168
169 // insert at the right location
170 for ($i=0; $i<$nb_dep; $i++)
171 {
172 $profil_menu=new Profile_Menu($cn);
173 $profil_menu->me_code=$this->me_code;
174 $profil_menu->me_code_dep=$p_module;
175 $profil_menu->p_type_display='S';
176 $profil_menu->p_id=$p_id;
177 $profil_menu->pm_id_dep=$dep_id[$i]['pm_id'];
178 $profil_menu->pm_default=0;
179 $profil_menu->p_order=$this->order;
180
181 $cnt=$profil_menu->count(' where pm_id_dep=$3 and p_id=$1 and me_code = $2',
182 array($p_id, $this->me_code, $dep_id[$i]['pm_id']));
183 if ($cnt==0)
184 {
185 $profil_menu->insert();
186 }
187 }
188 }
Menu_Ref let you manage the available menu.
static echo_var($n_level, $msg, $print=true)
Display the value of a var if DEBUGNOALYSS is greater than $n_level, the debugging info has a certain...
Definition: dbg.php:45
Manage the menu of a profile.
Manage the table public.profile.
foreach(array('magic_quotes_gpc', 'magic_quotes_runtime') as $a) $module
Definition: install.php:410

References $cn, $i, $me_code, $module, $nb_dep, $order, $p_id, $profile, and Noalyss\Dbg\echo_var().

+ Here is the call graph for this function:

◆ make_array()

static Extension::make_array (   $cn)
static

make an array of the available plugin for the current user

Returns
an array
See also
ISelect

Definition at line 103 of file extension.class.php.

104 {
105 $sql="select DISTINCT me_code as value, me_menu as label from ".
106 " menu_ref join profile_menu using (me_code)
107 join profile_user using (p_id) where ".
108 " user_name=$1 and me_type='PL' ORDER BY ME_MENU";
109 $a=$cn->get_array($sql, array($_SESSION[SESSION_KEY.'g_user']));
110 return $a;
111 }

References $a, $cn, and $sql.

◆ read_definition()

static Extension::read_definition (   $p_file)
static

Parse a XML file to complete an array of extension objects, in the plugin.xml file , you can find several plugins sharing some parts.

Parameters
string$p_filefilename
Returns
array array of Extension

Definition at line 352 of file extension.class.php.

353 {
354 global $cn;
355 $dom=new DomDocument('1.0');
356 $dom->load($p_file);
357 $xml=simplexml_import_dom($dom);
358 $nb_plugin=count($xml->plugin);
359 $a_extension=array();
360 for ($i=0; $i<$nb_plugin; $i++)
361 {
362
363 $extension=new Extension($cn);
364 try
365 {
366 $extension->check_xml($xml);
367 }
368 catch (Exception $ex)
369 {
370 echo_warning($ex->getMessage());
371 if ($ex->getCode()==1)
372 {
373 continue;
374 }
375 }
376 $extension->me_file=trim($xml->plugin[$i]->root).'/'.trim($xml->plugin[$i]->file);
377 $extension->me_code=trim($xml->plugin[$i]->code);
378 $extension->me_description=(isset($xml->plugin[$i]->description))?trim($xml->plugin[$i]->description):"";
379 $extension->me_description_etendue=(trim($xml->plugin[$i]->author))?trim($xml->plugin[$i]->author):"";
380 $extension->me_type='PL';
381 $extension->me_menu=trim($xml->plugin[$i]->name);
382 $extension->me_parameter='plugin_code='.trim($xml->plugin[$i]->code);
383 $extension->depend=(isset($xml->plugin[$i]->depend))?trim($xml->plugin[$i]->depend):"EXT";
384 $extension->order=(isset($xml->plugin[$i]->order))?trim($xml->plugin[$i]->order):9000;
385 $extension->version=trim($xml->plugin[$i]->version);
386 $extension->noalyss_version=(isset($xml->plugin[$i]->noalyss_version))?trim($xml->plugin[$i]->noalyss_version):8000;
387 $a_extension[]=clone $extension;
388 }
389 return $a_extension;
390 }
echo_warning($p_string)
warns
Definition: ac_common.php:589
$dom
Definition: xml.php:15

References $cn, $dom, $ex, $i, $nb_plugin, $xml, and echo_warning().

Referenced by get_version().

+ Here is the call graph for this function:

◆ remove_from_profile_menu()

Extension::remove_from_profile_menu (   $p_id)

Definition at line 190 of file extension.class.php.

191 {
192 global $cn;
193
194 $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',
195 array($this->me_code, $this->me_file, $p_id));
196 }

References $cn, and $p_id.

◆ remove_plugin()

Extension::remove_plugin ( )

Definition at line 241 of file extension.class.php.

242 {
243 try
244 {
245 $this->cn->start();
246 $this->delete();
247 $this->cn->commit();
248 }
249 catch (Exception $exc)
250 {
251 echo alert($exc->getMessage());
252 }
253 }

References alert(), and cn.

+ Here is the call graph for this function:

◆ search()

Extension::search (   $p_what)

search a extension, the what is the column (extends_code

Definition at line 71 of file extension.class.php.

72 {
73 $this->me_code=strtoupper($p_what);
74 if ($this->load()==false)
75 return null;
76 return 1;
77 }

◆ update_plugin()

Extension::update_plugin ( )

Definition at line 225 of file extension.class.php.

226 {
227 try
228 {
229 $this->cn->start();
230 $this->verify();
231 $this->me_type='PL';
232 $this->update();
233 $this->cn->commit();
234 }
235 catch (Exception $exc)
236 {
237 echo alert($exc->getMessage());
238 }
239 }

References alert(), cn, and verify().

+ Here is the call graph for this function:

◆ verify()

Extension::verify ( )

Definition at line 56 of file extension.class.php.

57 {
58 // Verify that the elt we want to add is correct
59 if (trim($this->me_code)=="")
60 throw new Exception('Le code ne peut pas être vide');
61 if (trim($this->me_menu)=="")
62 throw new Exception('Le nom ne peut pas être vide');
63 if (trim($this->me_file)=="")
64 throw new Exception('Chemin incorrect');
65 if (file_exists(NOALYSS_PLUGIN.'/'.$this->me_file)==false)
66 throw new Exception("$this->me_code $this->me_file".'Extension non trouvée, le chemin est-il correct?');
67 }

Referenced by insert_plugin(), and update_plugin().

Field Documentation

◆ aStandard_plugin

const Extension::aStandard_plugin
Initial value:
=
array('AMORTIS','BACKNOADM','COPRO','IMPCARD',
'IMPORTBANK','INVOICING','LISTING',
'MODOP','RAPAV','SAV',
'TOOLPCMN','TOOLS','TRANSFORM',
'TVA')

Definition at line 49 of file extension.class.php.


The documentation for this class was generated from the following file: