noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 216/323: Task #1539 : upgrade , install plugi


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 216/323: Task #1539 : upgrade , install plugin , download database template
Date: Wed, 14 Mar 2018 17:38:52 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit b3f7eb085426ce5febb1ee847002d6220dc9bac2
Author: Dany De Bontridder <address@hidden>
Date:   Sun Feb 18 20:51:41 2018 +0100

    Task #1539 : upgrade , install plugin , download database template
---
 html/admin-noalyss.php                             |   1 +
 html/ajax_misc.php                                 |   4 +
 html/index.php                                     |  22 ++-
 html/install.php                                   |  56 ++++---
 html/style-classic7.css                            |   7 +-
 include/admin_repo.inc.php                         |   1 +
 include/ajax/ajax_admin.php                        |  95 +++++++++--
 include/class/dossier.class.php                    | 124 ++++++++++++---
 ...ository.class.php => package_contrib.class.php} |  23 +--
 include/class/package_core.class.php               |  64 ++++++++
 include/class/package_noalyss.class.php            | 117 ++++++++++++++
 ...pository.class.php => package_plugin.class.php} |  52 ++++--
 include/class/package_repository.class.php         | 175 +++++++++++++++++++++
 include/class/package_template.class.php           |  77 +++++++++
 include/class/periode.class.php                    |   4 +-
 include/lib/user_menu.php                          |   2 +-
 include/upgrade-core.php                           |  65 ++++++++
 include/upgrade-plugin.php                         | 133 ++++++++++++++++
 include/upgrade-template.php                       |  66 ++++++++
 include/upgrade.inc.php                            | 134 +++++++---------
 scenario/package_repository.test.php               | 103 ++++++++++++
 21 files changed, 1141 insertions(+), 184 deletions(-)

diff --git a/html/admin-noalyss.php b/html/admin-noalyss.php
index 4cb8235..d5046f8 100644
--- a/html/admin-noalyss.php
+++ b/html/admin-noalyss.php
@@ -29,6 +29,7 @@ if (file_exists("../include/config.inc.php") ) {
      * installed
      */
     define ('ALLOWED',1);
+    define ('ALLOWED_ADMIN',1);
     require_once '../include/constant.php';
     require_once NOALYSS_INCLUDE.'/admin_repo.inc.php';
 } else {
diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index 70f4f93..5da6df5 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -203,6 +203,10 @@ $path = array(
     "modele_drop"=>"ajax_admin",
   // From admin, display the information of a template you can modify
     "modele_modify"=>"ajax_admin",
+    // From admin , upgrade Noalyss
+    "upgradeCore"=>"ajax_admin",
+    // From admin , upgrade or install plugin
+    "upgradePlugin"=>"ajax_admin",
   // From dashboard, display detail about last operation     
     "action_show"=>"ajax_gestion",
   // From dashboard, display form for a new event    
diff --git a/html/index.php b/html/index.php
index 716ffdb..828b682 100644
--- a/html/index.php
+++ b/html/index.php
@@ -132,12 +132,14 @@
  * </ul>
  */
 
+
 if ( ! 
file_exists('..'.DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'config.inc.php'))
 {
     header("Location: install.php",true, 307);
     exit(0);
 }
 
+
 echo '<!doctype html><HTML>
 <head>
 <TITLE> NOALYSS </TITLE>
@@ -153,11 +155,21 @@ require_once '../include/constant.php';
 require_once '../include/config.inc.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 if (file_exists("install.php")&& ! DEBUG ) {
-    /*
-     * This file shouldn't exist
-     */
-    echo _("Le fichier ".__DIR__."/install.php est encore présent, vous devez 
l'effacer avant d'utiliser NOALYSS");
-    return;
+    // At the end of the installation procedure , the install file must be 
removed
+    if (isset($_GET['remove_install'])) {
+        if (is_writable(__DIR__."/install.php") ) {
+            unlink(__DIR__."/install.php");
+        }
+    }
+    // if removed failed then
+    if (file_exists("install.php") )
+    {
+        /*
+        * This file shouldn't exist
+        */
+       echo _("Le fichier ".__DIR__."/install.php est encore présent, vous 
devez l'effacer avant d'utiliser NOALYSS");
+       return;
+    }
 }
 if ( strlen(domaine) > 0 )
 {
diff --git a/html/install.php b/html/install.php
index bb6f519..3aa9be0 100644
--- a/html/install.php
+++ b/html/install.php
@@ -465,13 +465,19 @@ if ( ! isset($_POST['go']) ) {
 </span>
 <?php
 }
-if ( ! isset($_POST['go']) )
-       exit();
+if (!isset($_POST['go']))
+{
+    exit();
+}
 // Check if account_repository exists
-if (!defined("MULTI") || (defined("MULTI") && MULTI == 1))
-        $account = $cn->count_sql("select * from pg_database where 
datname=lower('" . domaine . "account_repository')");
+if (!defined("MULTI")||(defined("MULTI")&&MULTI==1))
+{
+    $account=$cn->count_sql("select * from pg_database where 
datname=lower('".domaine."account_repository')");
+}
 else
-        $account=1;
+{
+    $account=1;
+}
 
 // Create the account_repository
 if ($account == 0 ) {
@@ -491,11 +497,17 @@ if ($account == 0 ) {
 
   $cn->commit($cn);
 
- if ( ! DEBUG) ob_end_clean();
+  if (!DEBUG)
+    {
+        ob_end_clean();
+    }
 
-  echo _("Creation of Modele 1");
-  if ( ! DEBUG) ob_start();
-  $cn->exec_sql("create database ".domaine."mod1 encoding='utf8'");
+    echo _("Creation of Modele 1");
+  if (!DEBUG)
+    {
+        ob_start();
+    }
+    $cn->exec_sql("create database ".domaine."mod1 encoding='utf8'");
 
   $cn=new Database(1,'mod');
   $cn->start();
@@ -504,9 +516,12 @@ if ($account == 0 ) {
   $cn->execute_script(NOALYSS_INCLUDE.'/sql/mod1/constraint.sql');
   $cn->commit();
 
-  if ( ! DEBUG) ob_end_clean();
+  if (!DEBUG)
+    {
+        ob_end_clean();
+    }
 
-  echo _("Creation of Modele 2");
+    echo _("Creation of Modele 2");
   $cn->exec_sql("create database ".domaine."mod2 encoding='utf8'");
   $cn=new Database(2,'mod');
   $cn->start();
@@ -535,8 +550,8 @@ if  (defined("MULTI") && MULTI == 0)
        $db = new Database();
        if ($db->exist_table("repo_version") == false) 
        {
-            if ( ! DEBUG) { ob_start();  }
-            $db->execute_script(NOALYSS_INCLUDE.'/sql/mono/mono.sql');
+                        if ( ! DEBUG) { ob_start();  }
+                        
$db->execute_script(NOALYSS_INCLUDE.'/sql/mono/mono.sql');
                      
             if ( ! DEBUG) ob_end_clean();
        }
@@ -591,12 +606,15 @@ if  (defined("MULTI") && MULTI == 0)
  * If multi folders
  */
 define ('ALLOWED',1);
+define ('ALLOWED_ADMIN',1);
+
 $_GET['sb']="upg_all";
 $rep=new Database();
-if (defined (NOALYSS_ADMINISTRATOR) )
-        $rep->exec_sql("update ac_users set use_login=$1 where use_id=1",
-              array(strtolower(NOALYSS_ADMINISTRATOR)));
-require NOALYSS_INCLUDE."/upgrade.inc.php";
+if (defined(NOALYSS_ADMINISTRATOR))
+{
+    $rep->exec_sql("update ac_users set use_login=$1 where use_id=1", 
array(strtolower(NOALYSS_ADMINISTRATOR)));
+}
+ Dossier::upgrade();
 echo '<h1>'._('Important').'</h1>';
 echo '<p>'._('Utilisateur administrateur'),' ',NOALYSS_ADMINISTRATOR,'</p>';
         
@@ -604,9 +622,9 @@ echo "<h2 class=\"warning\">";
 printf (" VOUS DEVEZ EFFACER CE FICHIER %s",__FILE__);
 echo "</h2>";
 
- echo "<p class=\"info\">"._("Tout est install&eacute;")." ". $succeed;
+ echo "<p class=\"info\">"._("Tout est installé")." ". $succeed;
 ?>
 </p>
 <p style="text-align: center">
-<A style="display:inline;margin:10px;padding:10px;" class="button" 
HREF="index.php"><?php echo _('Connectez-vous à NOALYSS')?></A>
+<A style="display:inline;margin:10px;padding:10px;" class="button" 
HREF="index.php?remove_install"><?php echo _("Essai effacement install.php et 
se connecter à NOALYSS")?></A>
 </p>
\ No newline at end of file
diff --git a/html/style-classic7.css b/html/style-classic7.css
index 8bcd8c5..1e8f7f1 100644
--- a/html/style-classic7.css
+++ b/html/style-classic7.css
@@ -305,9 +305,9 @@ td.cell{
 }
 td.selectedcell{
     
-  border-radius:15px;
-   -moz-border-radius: 15px;
-   -webkit-border-radius: 15px;
+  border-radius:19px;
+   -moz-border-radius: 19px;
+   -webkit-border-radius: 19px;
     font-weight: bold;
     color:#FFFFFF;
     width:250px;
@@ -315,6 +315,7 @@ td.selectedcell{
     background: #b8c6df; /* Old browsers */
     border-top-right-radius: 0px;
     border-bottom-left-radius: 0px;
+    border-bottom-right-radius: 0px;
 }
 .menu2 td.mtitle ,.menu2 td.selectedcell{
     border-radius: 0px;
diff --git a/include/admin_repo.inc.php b/include/admin_repo.inc.php
index 353617b..b0b1d9f 100644
--- a/include/admin_repo.inc.php
+++ b/include/admin_repo.inc.php
@@ -22,6 +22,7 @@
  *        templates... Accessible only by the administrator
  */
 if ( ! defined ('ALLOWED')) { die (_('Non autorisé'));}
+if ( ! defined ('ALLOWED_ADMIN')) { die (_('Non autorisé'));}
 
 include_once NOALYSS_INCLUDE."/class/user.class.php";
 require_once NOALYSS_INCLUDE."/lib/user_common.php";
diff --git a/include/ajax/ajax_admin.php b/include/ajax/ajax_admin.php
index 47ffdc0..70856bd 100644
--- a/include/ajax/ajax_admin.php
+++ b/include/ajax/ajax_admin.php
@@ -31,10 +31,11 @@ if ($g_user->Admin()==0)
 {
     die();
 }
+session_write_close();
 set_language();
 require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
 $http=new HttpInput();
-
+$op=$http->request("op");
 // From admin, grant  the access to a folder to an
 // user
 if ($op=='folder_add') // operation
@@ -50,7 +51,7 @@ if ($op=='folder_add') // operation
         $dossiercn=new Database($dossier_id);
         // By default new user has the profile 1 (admin) and ledger's security
         // + action's security are disabled
-        $user=new User($dossiercn,$user_id);
+        $user=new User($dossiercn, $user_id);
         $user->set_status_security_action(0);
         $user->set_status_security_ledger(0);
         $user->save_profile(1);
@@ -70,7 +71,7 @@ if ($op=='folder_add') // operation
         return;
     }
 
-        
+
     //----------------------------------------------------------------
     // Answer in XML
     header('Content-type: text/xml; charset=UTF-8');
@@ -131,20 +132,20 @@ if ($op=='folder_display') // operation
     try
     {
         $user_id=$http->get("p_user", "number"); // get variable
-        $p_filter=$http->get('p_filter', "string",'');
+        $p_filter=$http->get('p_filter', "string", '');
         ob_start();
         $user=new User($cn, $user_id);
         $a_dossier=Dossier::show_dossier('X', $user->id, $p_filter, 
MAX_FOLDER_TO_SHOW);
         echo HtmlInput::title_box(_("Liste dossier"), 'folder_list_div');
         ?>
         <form method="get" onsubmit="folder_display('<?php echo $user_id ?>');
-                        return false">
+                return false">
             <p style="text-align: center">
                 <?php echo _('Recherche'); ?>
-                
+
                 <input type="text" id="database_filter_input" 
class="input_text" autofocus="true" autocomplete="off" nohistory 
autocomplete="false" value="<?php echo $p_filter ?>" 
-                       onkeyup="filter_table(this, 
'folder_display_tb','1,2,3',0)"  >
-                <input type="button" class="smallbutton" 
onclick="$('database_filter_input').value='';filter_table($('database_filter_input'),
 'folder_display_tb','1,2,3',0);" value="X">
+                       onkeyup="filter_table(this, 'folder_display_tb', 
'1,2,3', 0)"  >
+                <input type="button" class="smallbutton" 
onclick="$('database_filter_input').value = 
'';filter_table($('database_filter_input'), 'folder_display_tb', '1,2,3', 0);" 
value="X">
                 <input type="submit" class="smallbutton" value="<?php echo 
_('Rechercher') ?>">
             </p>
         </form>    
@@ -159,8 +160,6 @@ if ($op=='folder_display') // operation
         require NOALYSS_TEMPLATE.'/folder_display.php';
         $content=ob_get_clean();
         $status='OK';
-
-        
     }
     catch (Exception $exc)
     {
@@ -195,14 +194,13 @@ if (in_array($op, array('modele_drop', 'modele_modify', 
'folder_modify', 'folder
         $dossier=$http->get('p_dossier', "number");
         $content=_('Erreur paramètre');
         $status="NOK";
-        
     }
     catch (Exception $exc)
     {
         error_log($exc->getTraceAsString());
         $content=_('Erreur paramètre');
         $status="NOK";
-          //----------------------------------------------------------------
+        //----------------------------------------------------------------
         // Answer in XML
         header('Content-type: text/xml; charset=UTF-8');
         $dom=new DOMDocument('1.0', 'UTF-8');
@@ -215,7 +213,6 @@ if (in_array($op, array('modele_drop', 'modele_modify', 
'folder_modify', 'folder
         $dom->appendChild($root);
         echo $dom->saveXML();
         exit();
-
     }
 
     // Modify the description or the name of folder
@@ -237,8 +234,8 @@ if (in_array($op, array('modele_drop', 'modele_modify', 
'folder_modify', 'folder
         echo _('Description').' : <br>';
         echo $wDesc->input('desc', $dos->get_parameter('desc'));
         echo '<br>';
-        
-        echo _('Max. email / jour (-1 = illimité)')    ;
+
+        echo _('Max. email / jour (-1 = illimité)');
         $max_email_input=new INum('max_email');
         $max_email_input->value=$dos->get_parameter('max_email');
         $max_email_input->prec=0;
@@ -341,4 +338,72 @@ if (in_array($op, array('modele_drop', 'modele_modify', 
'folder_modify', 'folder
     echo $dom->saveXML();
     exit();
 }
+//------------------------------------------------------------------
+// Upgrade Core
+//------------------------------------------------------------------
+if ($op=='upgradeCore')
+{
+    require_once NOALYSS_INCLUDE.'/lib/progress_bar.class.php';
+    require_once NOALYSS_INCLUDE.'/class/package_repository.class.php';
+    $task_id=$http->request("task_id");
+    $progress=new Progress_Bar($task_id);
+    $progress->set_value(2);
+    $repo=new Package_Repository();
+    $core=$repo->make_object("core", " ");
+    $progress->set_value(5);
+    $core->download();
+    $progress->set_value(55);
+    if (!DEBUG)
+    {
+        $core->install();
+    }
+    $progress->set_value(100);
+
+    $url=sprintf('<a href="%s"> install.php</a>', NOALYSS_URL."/install.php");
+    printf(_("Afin de terminer l'installation aller sur %s , à la fin de la 
procédure , demandez à effacer le fichier install.php"),
+            $url);
+}
+//---------------------------------------------------------------------------------------------------------
+// Upgrade or install plugin
+//---------------------------------------------------------------------------------------------------------
+if ($op=='upgradePlugin')
+{
+    require_once NOALYSS_INCLUDE.'/lib/progress_bar.class.php';
+    require_once NOALYSS_INCLUDE.'/class/package_repository.class.php';
+    $task_id=$http->request("task_id");
+    $code=$http->post("code_plugin");
+    $progress=new Progress_Bar($task_id);
+    $progress->set_value(2);
+    $repo=new Package_Repository();
+    $plugin=$repo->make_object("plugin", $code);
+    $progress->set_value(5);
+    $plugin->download();
+    $progress->set_value(55);
+    if (!DEBUG)
+    {
+        $plugin->install();
+    }
+    $progress->set_value(100);
+}
+//------------------------------------------------------------------------------------------------------------------
+// Install template
+//------------------------------------------------------------------------------------------------------------------
+if ($op=="installTemplate")
+{
+    require_once NOALYSS_INCLUDE.'/lib/progress_bar.class.php';
+    require_once NOALYSS_INCLUDE.'/class/package_repository.class.php';
+    $task_id=$http->request("task_id");
+    $name=$http->post("code");
+    $progress=new Progress_Bar($task_id);
+    $progress->set_value(2);
+    $package_repository=new Package_Repository();
+    $progress->set_value(4);
+    $template=$package_repository->make_object("template", $name);
+    $progress->set_value(30);
+    $template->download();
+    $progress->set_value(70);
+    $template->install();
+    $progress->set_value(100);
+    echo _("Modèle installé ");
+}
 ?>        
\ No newline at end of file
diff --git a/include/class/dossier.class.php b/include/class/dossier.class.php
index 4108a8a..5eea06b 100644
--- a/include/class/dossier.class.php
+++ b/include/class/dossier.class.php
@@ -20,13 +20,13 @@
 
 // Copyright Author Dany De Bontridder address@hidden
 
-/*!\file
+/* !\file
  * \brief the class for the dossier, everywhere we need to know to
  * which folder we are connected, because we can't use $_SESSION, we
  * need to pass the dossier_id via a _GET or a POST variable
  */
 
-/*! \brief manage the current dossier, everywhere we need to know to
+/* ! \brief manage the current dossier, everywhere we need to know to
  * which folder we are connected, because we can't use $_SESSION, we
  * need to pass the dossier_id via a _GET or a POST variable
  *  private static $variable=array("id"=>"dos_id",
@@ -52,7 +52,7 @@ class Dossier
         $this->dos_id=$p_id;
     }
 
-    /*!\brief return the $_REQUEST['gDossier'] after a check */
+    /* !\brief return the $_REQUEST['gDossier'] after a check */
 
     static function id()
     {
@@ -78,11 +78,11 @@ class Dossier
         if ($p_type=="A")
         {
             $l_sql="select *, 'W' as priv_priv "
-                    . "from ac_dossier "
-                    . "where "
-                    . "dos_name ~* $2 "
-                    . "or dos_description ~* $2 "
-                    . "ORDER BY dos_name $str_limit  ";
+                    ."from ac_dossier "
+                    ."where "
+                    ."dos_name ~* $2 "
+                    ."or dos_description ~* $2 "
+                    ."ORDER BY dos_name $str_limit  ";
             $a_row=$cn->get_array($l_sql, $p_text);
             return $a_row;
         }
@@ -127,7 +127,7 @@ class Dossier
         return $nb_folder;
     }
 
-    /*!
+    /* !
      * \brief Return all the users
      * as an array
      */
@@ -157,11 +157,11 @@ class Dossier
             $sql
             ";
 
-        $res=$this->cn->get_array($sql,array(NOALYSS_ADMINISTRATOR));
+        $res=$this->cn->get_array($sql, array(NOALYSS_ADMINISTRATOR));
         return $res;
     }
 
-    /*!\brief check if gDossier is set */
+    /* !\brief check if gDossier is set */
 
     static function check()
     {
@@ -177,7 +177,7 @@ class Dossier
             exit('gDossier Invalide : '.$id);
     }
 
-    /*!
+    /* !
      * \brief return a string to put to gDossier into a GET 
      */
 
@@ -187,7 +187,7 @@ class Dossier
         return "gDossier=".$_REQUEST['gDossier'];
     }
 
-    /*!\brief return a string to set gDossier into a FORM */
+    /* !\brief return a string to set gDossier into a FORM */
 
     static function hidden()
     {
@@ -195,7 +195,7 @@ class Dossier
         return '<input type="hidden" id="gDossier" name="gDossier" 
value="'.$_REQUEST['gDossier'].'">';
     }
 
-    /*!\brief retrieve the name of the current dossier */
+    /* !\brief retrieve the name of the current dossier */
 
     static function name($id=0)
     {
@@ -203,8 +203,7 @@ class Dossier
 
         $cn=new Database();
         $id=($id==0)?$_REQUEST['gDossier']:$id;
-        $name=$cn->get_value("select dos_name from ac_dossier where dos_id=$1",
-                array($_REQUEST['gDossier']));
+        $name=$cn->get_value("select dos_name from ac_dossier where 
dos_id=$1", array($_REQUEST['gDossier']));
         return $name;
     }
 
@@ -246,18 +245,16 @@ class Dossier
             return;
 
         if ($this->cn->get_value("select count(*) from ac_dossier "
-                . " where dos_name=$1 and dos_id<>$2",
-                        array($this->dos_name, $this->dos_id))!=0)
+                        ." where dos_name=$1 and dos_id<>$2", 
array($this->dos_name, $this->dos_id))!=0)
             return;
 
         $sql="update ac_dossier set dos_name=$1,dos_description=$2 
,dos_email=$3".
                 " where dos_id = $4";
         $res=$this->cn->exec_sql(
-                $sql,
-                array(trim($this->dos_name),
-                      trim($this->dos_description),
-                      $this->dos_email,
-                      $this->dos_id)
+                $sql, array(trim($this->dos_name),
+            trim($this->dos_description),
+            $this->dos_email,
+            $this->dos_id)
         );
     }
 
@@ -300,7 +297,7 @@ class Dossier
      */
     static function synchro_admin($p_id)
     {
-        // connect to target
+// connect to target
         $cn=new Database($p_id);
 
         if (!$cn->exist_table("profile_menu"))
@@ -308,7 +305,7 @@ class Dossier
             echo_warning("Dossier invalide");
             return;
         }
-        // connect to repo
+// connect to repo
         $repo=new Database();
 
         $a_admin=$repo->get_array("select use_login from ac_users where
@@ -327,11 +324,86 @@ class Dossier
         }
         catch (Exception $e)
         {
-            
+
             echo_warning($e->getMessage());
             record_log($e->getTraceAsString());
             $cn->rollback();
         }
     }
 
+    static function upgrade()
+    {
+        $rep=new Database();
+        /* If multi folders */
+        $Resdossier=$rep->exec_sql("select dos_id, dos_name from ac_dossier");
+        $MaxDossier=$rep->size($Resdossier);
+
+        
//----------------------------------------------------------------------
+        // Upgrade the account_repository
+        
//----------------------------------------------------------------------
+        echo "<h2>"._("Mise à jour de la base de données principale")."</h2>";
+        $cn=new Database();
+        if (DEBUG==false)
+            ob_start();
+        $MaxVersion=DBVERSIONREPO-1;
+        for ($i=4; $i<=$MaxVersion; $i++)
+        {
+            if ($cn->get_version()<=$i)
+            {
+                
$cn->execute_script(NOALYSS_INCLUDE.'/sql/patch/ac-upgrade'.$i.'.sql');
+            }
+        }
+
+        
//----------------------------------------------------------------------
+        // Upgrade the folders
+        
//----------------------------------------------------------------------
+        echo "<h2>"._("Mise à jour dossiers")."</h2>";
+
+        for ($e=0; $e<$MaxDossier; $e++)
+        {
+            $db_row=Database::fetch_array($Resdossier, $e);
+            $name=$rep->format_name($db_row['dos_id'], 'dos');
+            echo "<h3>Patching ".$db_row['dos_name'].'</h3>';
+            echo _('Base de données')." ".$name;
+
+            if ($rep->exist_database($name)>0)
+            {
+                $db=new Database($db_row['dos_id'], 'dos');
+                $db->apply_patch($db_row['dos_name']);
+                Dossier::synchro_admin($db_row['dos_id']);
+                User::remove_inexistant_user($db_row['dos_id']);
+                $db->clean_orphan_lob();
+            }
+            else
+            {
+                echo_warning(_("Dossier inexistant")." $name");
+            }
+        }
+
+        
//----------------------------------------------------------------------
+        // Upgrade the template
+        
//----------------------------------------------------------------------
+        $Resdossier=$rep->exec_sql("select mod_id, mod_name from modeledef");
+        $MaxDossier=$rep->size();
+        echo "<h2>"._("Mise à jour modèles")."</h2>";
+
+        for ($e=0; $e<$MaxDossier; $e++)
+        {
+            $db_row=Database::fetch_array($Resdossier, $e);
+            $name=$rep->format_name($db_row['mod_id'], 'mod');
+            echo "<h3>Patching ".$db_row['mod_name']."</h3>";
+            echo _('Base de données')." ".$name;
+            if ($rep->exist_database($name)>0)
+            {
+                $db=new Database($db_row['mod_id'], 'mod');
+                $db->apply_patch($db_row['mod_name']);
+                $db->clean_orphan_lob();
+            }
+            else
+            {
+                echo_warning(_("Modèle inexistant")." $name");
+            }
+        }
+    }
+
 }
diff --git a/include/class/Package_Repository.class.php 
b/include/class/package_contrib.class.php
similarity index 69%
copy from include/class/Package_Repository.class.php
copy to include/class/package_contrib.class.php
index af84b72..1919639 100644
--- a/include/class/Package_Repository.class.php
+++ b/include/class/package_contrib.class.php
@@ -21,26 +21,5 @@
 
 /**
  * @file
- * @brief contains the class Package_Repository
+ * @brief 
  */
-class Package_Repository
-{
-    private $content;
-    function __construct()
-    {
-        $this->address@hidden(NOALYSS_PACKAGE."/web.xml");
-    }
-    function get_noalyss_info()
-    {
-        
-    }
-    function get_plugin_info()
-    {
-        
-    }
-    function get_template_info()
-    {
-        
-    }
-    
-}
\ No newline at end of file
diff --git a/include/class/package_core.class.php 
b/include/class/package_core.class.php
new file mode 100644
index 0000000..44b8787
--- /dev/null
+++ b/include/class/package_core.class.php
@@ -0,0 +1,64 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2018) Author Dany De Bontridder <address@hidden>
+require_once NOALYSS_INCLUDE.'/class/package_noalyss.class.php';
+
+/**
+ * @file
+ * @brief Class Package Core to install the core , if possible
+ */
+class Package_Core extends Package_Noalyss
+{
+
+    /**
+     * @brief check if it is possible to install
+     *  Are the folder html and include writeable ?
+     */
+    public function can_install()
+    {
+        
+    }
+
+    /**
+     * Unzip the file and overwrite current implementation, the databases and 
modele are not upgraded.
+     *It must be done after.
+     *  In this package the install is given and must be delete manually 
+     * @throws Exception 1 : cannot extract content of the zip , 2: cannot 
open zip file 
+     */
+    public function install()
+    {
+        $zip=new ZipArchive ();
+        // open the file
+        if ($zip->open(NOALYSS_HOME."/tmp/".$this->get_file()))
+        {
+            // try to unzip and overwrite current 
+            if (!$zip->extractTo(NOALYSS_HOME."/../"))
+            {
+                throw new Exception(_("Echec mis à jour"), 1);
+            }
+        }
+        else
+        {
+            throw new Exception(_("Ce n'est pas un fichier valide"), 2);
+        }
+        
+    }
+
+}
diff --git a/include/class/package_noalyss.class.php 
b/include/class/package_noalyss.class.php
new file mode 100644
index 0000000..d33fde6
--- /dev/null
+++ b/include/class/package_noalyss.class.php
@@ -0,0 +1,117 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2018) Author Dany De Bontridder <address@hidden>
+
+/**
+ * @file
+ * @brief package noalyss is the mother class of the class to install and 
download package
+ */
+abstract class Package_Noalyss
+{
+
+    private $file;
+    private $path;
+    private $name;
+    private $description;
+
+    function __construct($name, $description, $full_path)
+    {
+        $this->file=basename(trim($full_path));
+        $this->path=dirname(trim($full_path));
+
+        $this->description=$description;
+        $this->name=$name;
+    }
+
+    public function get_path()
+    {
+        return $this->path;
+    }
+
+    public function set_path($path)
+    {
+        $this->path=$path;
+        return $this;
+    }
+
+    public function get_file()
+    {
+        return $this->file;
+    }
+
+    public function get_name()
+    {
+        return $this->name;
+    }
+
+    public function get_description()
+    {
+        return $this->description;
+    }
+
+    public function set_file($file)
+    {
+        $this->file=$file;
+        return $this;
+    }
+
+    public function set_name($name)
+    {
+        $this->name=$name;
+        return $this;
+    }
+
+    public function set_description($description)
+    {
+        $this->description=$description;
+        return $this;
+    }
+
+    /**
+     * check that NOALYSS_HOME exists and is writable
+     */
+    function can_download()
+    {
+        $download_dir=NOALYSS_HOME."/tmp";
+        if (is_dir($download_dir)&&is_writable($download_dir))
+        {
+            return TRUE;
+        }
+        return FALSE;
+    }
+
+    function download()
+    {
+        // If install is writable then download 
+        if ( $this->can_download() )
+        {
+            $full=$this->get_path()."/".$this->get_file();
+            $file = file_get_contents(NOALYSS_PACKAGE_REPOSITORY."/".$full);
+            $fh_file=fopen(NOALYSS_HOME."/tmp/".$this->get_file(),"w+");
+            
+            fwrite($fh_file, $file);
+             fclose($fh_file);
+        }
+    }
+
+    abstract function install();
+    
+    abstract function can_install();
+}
diff --git a/include/class/Package_Repository.class.php 
b/include/class/package_plugin.class.php
similarity index 51%
rename from include/class/Package_Repository.class.php
rename to include/class/package_plugin.class.php
index af84b72..046bfdd 100644
--- a/include/class/Package_Repository.class.php
+++ b/include/class/package_plugin.class.php
@@ -21,26 +21,46 @@
 
 /**
  * @file
- * @brief contains the class Package_Repository
+ * @brief 
  */
-class Package_Repository
+require_once NOALYSS_INCLUDE."/class/package_noalyss.class.php";
+
+/**
+ * @class
+ * @brief
+ */
+class Package_Plugin extends Package_Noalyss
 {
-    private $content;
-    function __construct()
-    {
-        $this->address@hidden(NOALYSS_PACKAGE."/web.xml");
-    }
-    function get_noalyss_info()
-    {
-        
-    }
-    function get_plugin_info()
+
+    public function install()
     {
-        
+        $zip=new ZipArchive ();
+        // open the file
+        if ($zip->open(NOALYSS_HOME."/tmp/".$this->get_file()))
+        {
+            // try to unzip and overwrite current 
+            if (!$zip->extractTo(NOALYSS_PLUGIN))
+            {
+                throw new Exception(_("Echec installation plugin "), 1);
+            }
+        }
+        else
+        {
+            throw new Exception(_("Ce n'est pas un fichier valide"), 2);
+        }
     }
-    function get_template_info()
+
+    /**
+     * Check the NOALYSS_PLUGIN is writeable
+     */
+    public function can_install()
     {
-        
+        if (is_writable(NOALYSS_PLUGIN))
+        {
+            return TRUE; ;
+        }
+        return FALSE;
     }
     
-}
\ No newline at end of file
+
+}
diff --git a/include/class/package_repository.class.php 
b/include/class/package_repository.class.php
new file mode 100644
index 0000000..d78af3a
--- /dev/null
+++ b/include/class/package_repository.class.php
@@ -0,0 +1,175 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2018) Author Dany De Bontridder <address@hidden>
+
+/**
+ * @file
+ * @brief contains the class Package_Repository
+ */
+require_once NOALYSS_INCLUDE.'/class/package_core.class.php';
+require_once NOALYSS_INCLUDE.'/class/package_plugin.class.php';
+require_once NOALYSS_INCLUDE.'/class/package_template.class.php';
+require_once NOALYSS_INCLUDE.'/class/package_contrib.class.php';
+
+/**
+ * @brief connect to NOALYSS_PACKAGE and fetch the file web.xml , it displays
+ * content of this file , build the appropriate object for installing
+ */
+class Package_Repository
+{
+
+    private $content;
+
+    /**
+     * @see package_repository.test.php
+     */
+    function __construct()
+    {
+        $content=file_get_contents(NOALYSS_PACKAGE_REPOSITORY."/web.xml");
+
+        $this->content=simplexml_load_string($content);
+    }
+
+    public function getContent()
+    {
+        return $this->content;
+    }
+
+    /**
+     * check that NOALYSS_HOME exists and is writable
+     */
+    function can_download()
+    {
+        $download_dir=NOALYSS_HOME."/tmp";
+        if (is_dir($download_dir)&&is_writable($download_dir))
+        {
+            return TRUE;
+        }
+        return FALSE;
+    }
+
+    /**
+     * Get info for Noalyss code : version #, announce, path to the last
+     * version
+     */
+    function display_noalyss_info()
+    {
+        global $g_user;
+        switch ($g_user->lang)
+        {
+            case 'fr_FR.utf8':
+                    echo "<pre>";
+                    echo $this->content->core->description;
+                    echo "</pre>";
+                
+                break;
+            case 'en_US.utf8':
+                break;
+            case 'nl_NL.utf8':
+                break;
+        }
+    }
+
+    /**
+     * return a SimpleXMLElement of the plugin thanks its code, it returns 
NULL if no plugin is found
+     * @param string $p_code  code of the plugin
+     * @return SimpleXMLElement or NULL if not found
+     */
+    function find_plugin($p_code)
+    {
+        $a_plugin=$this->content->xpath('//plugins/plugin');
+        $nb_plugin=count($a_plugin);
+        for ($i=0; $i<$nb_plugin; $i++)
+        {
+            if (trim($a_plugin[$i]->code)==$p_code)
+            {
+                return $a_plugin[$i];
+            }
+        }
+        return NULL;
+    }
+    
+
+    /**
+     * return a SimpleXMLElement of the db template thanks its code, it 
returns NULL if no template is found
+     * @param string $p_code  code of the template
+     * @return SimpleXMLElement or NULL if not found
+     */
+    function find_template($p_code)
+    {
+        $a_template=$this->content->xpath('//database_template/dbtemplate');
+        $nb_template=count($a_template);
+        for ($i=0; $i<$nb_template; $i++)
+        {
+            if (trim($a_template[$i]->code)==$p_code)
+            {
+                return $a_template[$i];
+            }
+        }
+        return NULL;
+    }
+    
+    function make_object($p_type, $p_id)
+    {
+        switch ($p_type)
+        {
+            case "core":
+                // Create an object to download & install the core
+                $obj=new Package_Core("Noalyss", "Core", 
$this->content->core->path);
+                return $obj;
+                break;
+            case 'template':
+            // create an object to download & install the template
+                $db=$this->find_template($p_id);
+                if ($db == NULL ) {
+                    throw new Exception(_("Modèle non trouvé"),1002);
+                }
+                $obj=new 
Package_Template($db->name,$db->description,$db->path);
+                return $obj;
+            case 'plugin':
+                // create an object to download & install a plugin
+                $plugin = $this->find_plugin($p_id);
+                if ($plugin==NULL)
+                {
+                    throw new Exception(_("Extension non trouvée"), 1001);
+                }
+                $obj=new 
Package_Plugin($plugin->name,$plugin->description,$plugin->path);
+                return $obj;
+                break;
+            case 'contrib':
+            //create an object to download & install a contrib
+            default:
+                break;
+        }
+    }
+    /**
+     * Read xml file from the package
+     * @param string $p_file
+     * @return SimpleXMLElement
+     */
+    public function read_package_xml($p_file)
+    {
+        $dom=new DomDocument('1.0');
+        $dom->load($p_file);
+        $xml=simplexml_import_dom($dom);
+        return $xml;
+    }
+
+}
diff --git a/include/class/package_template.class.php 
b/include/class/package_template.class.php
new file mode 100644
index 0000000..caa5666
--- /dev/null
+++ b/include/class/package_template.class.php
@@ -0,0 +1,77 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2018) Author Dany De Bontridder <address@hidden>
+
+
+/**
+ * @file
+ * @brief 
+ */
+require_once NOALYSS_INCLUDE."/class/package_noalyss.class.php";
+
+/**
+ * @brief
+ * 
+ */
+class Package_Template extends Package_Noalyss
+{
+
+    public function can_install()
+    {
+        return TRUE;
+    }
+    
+    /**
+     * Install the template
+     */
+    public function install()
+    {
+        // make temp dir
+        $tmp=NOALYSS_HOME."/tmp/";
+        $tmpdir=$tmp."db-".microtime(TRUE);
+        mkdir($tmpdir);
+
+        // unzip Archive file 
+        $db=new ZipArchive;
+        $db->open($tmp."/".$this->get_file());
+        $db->extractTo($tmpdir);
+
+
+        // create database
+        $cn=new Database();
+        $seq=$cn->get_value("select nextval('s_modid')");
+
+        $sql=sprintf(" create database %smod%d encoding='utf8'", domaine, 
$seq);
+        $cn->exec_sql($sql);
+        
+        $newdb=new Database($seq, 'mod');
+
+        // Execute SQL Script
+        $newdb->execute_script($tmpdir.'/schema.sql');
+        $newdb->execute_script($tmpdir.'/data.sql');
+        $newdb->execute_script($tmpdir.'/constraint.sql');
+        
+        // Register into account_repository, we add the seq number for 
avoiding duplicate
+        $description = sprintf(_("Installé le %s"),date("d-m-Y h:i:s"));
+        $cn->exec_sql(" insert into modeledef (mod_id,mod_name,mod_desc) 
values ($1,$2,$3)",
+                [$seq,$seq."-".$this->get_name(),$this->get_description()." 
".$description]);
+    }
+
+}
diff --git a/include/class/periode.class.php b/include/class/periode.class.php
index 1b6b45e..0ca7725 100644
--- a/include/class/periode.class.php
+++ b/include/class/periode.class.php
@@ -218,7 +218,7 @@ class Periode
      * @param date $p_date_end
      * @param int $p_exercice
      * @return int p_id of the new periode
-     * @exception Exception 10 Invalide date or exercice
+     * @exception Exception 10 Invalide date or exercice, 20 overlapping 
periode
      */
     function insert($p_date_start, $p_date_end, $p_exercice)
     {
@@ -248,7 +248,7 @@ class Periode
                 ",[$p_date_end]);
             if ( $overlap_start > 0 || $overlap_end > 0)
             {
-                throw new Exception (_("Période chevauchant une autre"));
+                throw new Exception (_("Période chevauchant une autre"),20);
             }
             $p_id=$this->cn->get_next_seq('s_periode');
             $sql=" insert into 
parm_periode(p_id,p_start,p_end,p_closed,p_exercice)
diff --git a/include/lib/user_menu.php b/include/lib/user_menu.php
index f38b032..b3dc5fa 100644
--- a/include/lib/user_menu.php
+++ b/include/lib/user_menu.php
@@ -118,7 +118,7 @@ function MenuAdmin()
                  
array("admin-noalyss.php?action=dossier_mgt",_("Dossiers"),_('Gestion des 
dossiers'),1),
                  
array("admin-noalyss.php?action=modele_mgt",_("Modèles"),_('Gestion des 
modèles'),2),
                  
array("admin-noalyss.php?action=restore",_("Restaure"),_("Restaure une base de 
données"),3),
-                 array("admin-noalyss.php?action=upgrade",_("Mise à 
jour"),_("Mise à jour du système et des bases de données"),5),
+                 
array("admin-noalyss.php?action=upgrade",_("Installation"),_("Installation Mise 
à jour du système et des bases de données"),5),
                  
array("admin-noalyss.php?action=audit_log",_("Audit"),_("Utilisateurs qui se 
sont connectés"),4),
                  array("admin-noalyss.php?action=info",_("Information 
système"),('Information à propos de votre installation'),6),
                  array("login.php",_("Accueil"),"",7),
diff --git a/include/upgrade-core.php b/include/upgrade-core.php
new file mode 100644
index 0000000..529bf86
--- /dev/null
+++ b/include/upgrade-core.php
@@ -0,0 +1,65 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2018) Author Dany De Bontridder <address@hidden>
+
+if (!defined('ALLOWED'))     die('Appel direct ne sont pas permis');
+if ( ! defined ('ALLOWED_ADMIN')) { die (_('Non autorisé'));}
+
+
+require_once NOALYSS_INCLUDE.'/class/package_repository.class.php';
+/**
+ * @file
+ * @brief 
+ */
+printf (_(" La version de votre installaiton est %s "),NOALYSS_VERSION);
+
+$core=new Package_Repository();
+$xml=$core->getContent();
+printf(h1(_("Version %s du %s")),$xml->core->version,$xml->core->date);
+echo '<p>';
+echo $xml->core->description;
+echo '</p>';
+
+if ( $xml->core->version < NOALYSS_VERSION) {
+    echo '<p>';
+    echo _("Votre version est à jour");
+    echo '</p>';
+    return;
+}
+
+$js="onclick='UpgradeCore()'";
+
+echo HtmlInput::button("upgrade",_("Mise à jour de votre système"),$js);
+?>
+<div id="info_admin">
+    
+</div>
+<script>
+    function UpgradeCore()
+    {
+        progress_bar_start('upgradeCore');
+        new Ajax.Updater("info_admin","ajax_misc.php",{
+                method:'POST',
+                parameters:{op:"upgradeCore",gDossier:0,task_id:'upgradeCore'
+                }
+            }
+            );
+    }
+ </script>
\ No newline at end of file
diff --git a/include/upgrade-plugin.php b/include/upgrade-plugin.php
new file mode 100644
index 0000000..a1d78cd
--- /dev/null
+++ b/include/upgrade-plugin.php
@@ -0,0 +1,133 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2018) Author Dany De Bontridder <address@hidden>
+
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+if (!defined('ALLOWED_ADMIN'))
+{
+    die(_('Non autorisé'));
+}
+
+
+require_once NOALYSS_INCLUDE.'/class/package_repository.class.php';
+require_once NOALYSS_INCLUDE.'/class/extension.class.php';
+
+/**
+ * @file
+ * @brief Install new plugin
+ */
+$package_repository=new Package_Repository();
+$xml=$package_repository->getContent();
+
+$a_plugin=$xml->xpath('//plugins/plugin');
+$nb_plugin=count($a_plugin);
+?>
+
+<table>
+    <tr>
+        <th>
+            <?= _("Nom") ?>
+        </th>
+        <th>
+            <?= _("Description") ?>
+        </th>
+        <th>
+            <?= _("Auteur") ?>
+        </th>
+        <th>
+            <?= _("Code") ?>
+        </th>
+        <th>
+            Installé ou mettre à jour ???
+        </th>
+
+    </tr>
+    <?php
+    for ($i=0; $i<$nb_plugin; $i++)
+    {
+        ?>
+        <tr>
+            <td>
+                <?= $a_plugin[$i]->name; ?>
+            </td>
+            <td>
+                <?= $a_plugin[$i]->description; ?>
+            </td>
+            <td>
+                <?= $a_plugin[$i]->author; ?>
+            </td>
+            <td>
+                <?= $a_plugin[$i]->code; ?>
+                version [<?= $a_plugin[$i]->version; ?>]
+            </td>
+            <td id="result<?=trim($a_plugin[$i]->code)?>">
+
+                <?php
+                //is installed
+                if 
(is_file(NOALYSS_PLUGIN."/".trim($a_plugin[$i]->root)."/plugin.xml"))
+                {
+                    // plugin is installed take the version and compare with 
remote one
+                    
$xml_plugin=$package_repository->read_package_xml(NOALYSS_PLUGIN."/".trim($a_plugin[$i]->root)."/plugin.xml");
+                    if (count($xml_plugin->plugin)>1)
+                    {
+                        echo _("MultiModule");
+                    }
+                    // Compute js to install or upgrade
+                    $js=sprintf("onclick=\"upgradePlugin('%s')\"", 
trim($a_plugin[$i]->code));
+                    // Check if new version is available
+                    if 
(floatval(trim($xml_plugin->plugin->version))<floatval(trim($a_plugin[$i]->version)))
+                    {
+                        printf (_("Nouvelle version disponible %s , votre 
version %s"),
+                                floatval(trim($a_plugin[$i]->version)),
+                                trim($xml_plugin->plugin->version));
+                        echo HtmlInput::button("upgrade", _("Mise à jour"), 
$js);
+                    }
+                    else
+                    {
+                        echo _("Dernière version installée");
+                    }
+                }
+                else
+                {
+                    // It is not installed , propose to install it
+                    echo _("Non installée");
+                    echo HtmlInput::button("upgrade", _("Installation"), $js);
+                }
+                ?>
+            </td>
+        </tr>
+        <?php
+    }
+    ?>
+</table>
+
+<script>
+    function upgradePlugin(p_code) {
+        var task_id="<?=uniqid()?>";
+       progress_bar_start(task_id);
+        new Ajax.Updater(
+            "result"+p_code,
+            "ajax_misc.php" ,
+        {
+            method:'POST',
+            
parameters:{gDossier:0,op:'upgradePlugin',code_plugin:p_code,"task_id":task_id}
+        });
+    }
+</script>
\ No newline at end of file
diff --git a/include/upgrade-template.php b/include/upgrade-template.php
new file mode 100644
index 0000000..7bde312
--- /dev/null
+++ b/include/upgrade-template.php
@@ -0,0 +1,66 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2018) Author Dany De Bontridder <address@hidden>
+
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+if (!defined('ALLOWED_ADMIN'))
+{
+    die(_('Non autorisé'));
+}
+require_once NOALYSS_INCLUDE.'/class/package_repository.class.php';
+require_once NOALYSS_INCLUDE.'/class/extension.class.php';
+
+
+$package_repository=new Package_Repository();
+$xml=$package_repository->getContent();
+
+
+$a_template=$xml->xpath('//database_template/dbtemplate');
+$nb_template=count($a_template);
+echo "<table>";
+echo tr(
+        th(_("Nom")).th(_("Description")).th(_("Mise à jour"))
+);
+for ($i=0; $i<$nb_template; $i++)
+{
+    echo '<tr>';
+    echo td($a_template[$i]->name);
+    echo td($a_template[$i]->description);
+    echo td($a_template[$i]->date_update);
+    echo '<td id="template'.trim($a_template[$i]->code).'" >';
+    $js=sprintf("onclick=\"install_template('%s')\"", 
trim($a_template[$i]->code));
+    echo HtmlInput::button("installTemplate", "Installation modèle", $js);
+    echo '</td>';
+    echo '</tr>';
+}
+echo "</table>";
+?>
+<script>
+    function install_template(p_code)
+    {
+        var task_id = "<?= uniqid() ?>";
+        /* progress_bar_start(task_id)*/
+        new Ajax.Updater("installTemplate" + p_code, "ajax_misc.php", {
+                method:"POST",
+                parameters:{op:"installTemplate", gDossier:0, code:p_code}
+        }
+        );
+    }
+</script>
\ No newline at end of file
diff --git a/include/upgrade.inc.php b/include/upgrade.inc.php
index 8c73434..ce2a28d 100644
--- a/include/upgrade.inc.php
+++ b/include/upgrade.inc.php
@@ -1,5 +1,4 @@
 <?php
-
 /*
  *   This file is part of NOALYSS.
  *
@@ -18,93 +17,78 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 // Copyright (2014) Author Dany De Bontridder <address@hidden>
-
-if (!defined('ALLOWED'))
-    die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
 /**
  * @file
  * @brief Upgrade all the database : the central repository , the templates and
  * the folder
  * @param $rep db connection to central repository
  */
-?>
+if (!defined('ALLOWED'))     die('Appel direct ne sont pas permis');
+if ( ! defined ('ALLOWED_ADMIN')) { die (_('Non autorisé'));}
 
-<?php
+require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
 $http=new HttpInput();
-$sb= $http->get("sb", "string","none");
-if ($sb === "upg_all" && (!defined('MULTI')||(defined('MULTI')&&MULTI==1)))
-{
-    echo '<div class="content">';
-    /* If multi folders */
-    $Resdossier=$rep->exec_sql("select dos_id, dos_name from ac_dossier");
-    $MaxDossier=$rep->size($Resdossier);
-    
-    //----------------------------------------------------------------------
-    // Upgrade the account_repository
-    //----------------------------------------------------------------------
-    echo "<h2>"._("Mise à jour de la base de données principale")."</h2>";
-    $cn=new Database();
-    if (DEBUG==false)
-        ob_start();
-    $MaxVersion=DBVERSIONREPO-1;
-    for ($i=4; $i<=$MaxVersion; $i++)
-    {
-        if ($cn->get_version()<=$i)
-        {
-            
$cn->execute_script(NOALYSS_INCLUDE.'/sql/patch/ac-upgrade'.$i.'.sql');
-        }
-    }
-    //----------------------------------------------------------------------
-    // Upgrade the folders
-    //----------------------------------------------------------------------
-    echo "<h2>"._("Mise à jour dossiers")."</h2>";
 
-    for ($e=0; $e<$MaxDossier; $e++)
-    {
-        $db_row=Database::fetch_array($Resdossier, $e);
-        $name=$rep->format_name($db_row['dos_id'], 'dos');
-        echo "<h3>Patching ".$db_row['dos_name'].'</h3>';
-        echo _('Base de données')." ".$name;
+$menu=array(
+    ["?action=upgrade&sb=database", _("Base de données"), _("Met à jour toutes 
les dossiers et modèles"), 'database'],
+    ["?action=upgrade&sb=application", _("Application"), _("Installe la 
dernière version de Noalyss"), 'application'],
+    ["?action=upgrade&sb=plugin", _("Extension"), _("Installe ou met à jour 
les extensions"), "plugin"],
+    ["?action=upgrade&sb=template", _("Modèle"), _("Installe des modèles"), 
"template"]
+);
+$sb=$http->request("sb", "string", "application");
+echo '<div class="menu2">';
+echo ShowItem($menu, "H", "mtitle", "mtitle", $sb);
+echo '</div>';
 
-        if ($rep->exist_database($name)>0)
-        {
-            $db=new Database($db_row['dos_id'], 'dos');
-            $db->apply_patch($db_row['dos_name']);
-            Dossier::synchro_admin($db_row['dos_id']);
-            User::remove_inexistant_user($db_row['dos_id']);
-            $db->clean_orphan_lob();
-        }
-        else
-        {
-            echo_warning(_("Dossier inexistant")." $name");
-        }
-    }
+$sc=$http->get("sc", "string", "none");
 
-    //----------------------------------------------------------------------
-    // Upgrade the template
-    //----------------------------------------------------------------------
-    $Resdossier=$rep->exec_sql("select mod_id, mod_name from modeledef");
-    $MaxDossier=$rep->size();
-    echo "<h2>"._("Mise à jour modèles")."</h2>";
+//-----------------------------------------------------------------------------
+// Upgrade Databases (Folder, Template , Account )
+//-----------------------------------------------------------------------------
+if ($sb=="database")
+{
+    ?>
+    <form method="get" id="frm_upg_all" onsubmit="return 
confirm_box('frm_upg_all', '<?php echo _('Confirmez') ?>')">
+        <input type="hidden" name="sb" value="database">
+        <input type="hidden" name="sc" value="upg_all">
+        <input type="hidden" name="action" value="upgrade">
+        <input type="submit" class="button" name="submit_upg_all" 
id="submit_upg_all" value="<?php echo _('Tout mettre à jour') ?>">
+    </form>
 
-    for ($e=0; $e<$MaxDossier; $e++)
+    <?php
+    if ($sc==="upg_all"&&(!defined('MULTI')||(defined('MULTI')&&MULTI==1)))
     {
-        $db_row=Database::fetch_array($Resdossier, $e);
-        $name=$rep->format_name($db_row['mod_id'], 'mod');
-        echo "<h3>Patching ".$db_row['mod_name']."</h3>";
-        echo _('Base de données')." ".$name;
-        if ($rep->exist_database($name)>0)
-        {
-            $db=new Database($db_row['mod_id'], 'mod');
-            $db->apply_patch($db_row['mod_name']);
-            $db->clean_orphan_lob();
-        }
-        else
-        {
-            echo_warning(_("Modèle inexistant")." $name");
-        }
-    }
+        echo '<div class="content">';
+
+        Dossier::upgrade();
 
+        echo '</div>';
+        return;
+    }
+}
+// Import the file with the package
+//------------------------------------------------------------------------------
+// Upgrade Main application, show all the info from the NOALYSS_PACKAGE site
+//------------------------------------------------------------------------------
+if ($sb=="application")
+{
+    require NOALYSS_INCLUDE."/upgrade-core.php";
+}
+//------------------------------------------------------------------------------
+// Install or Upgrade Extension, show all the info from the NOALYSS_PACKAGE 
site
+//------------------------------------------------------------------------------
+if ($sb=="plugin")
+{
+    require NOALYSS_INCLUDE."/upgrade-plugin.php";
+    
+}
+//-------------------------------------------------------------------------------------------------------------------------------
+// Install template
+//-------------------------------------------------------------------------------------------------------------------------------
+if ( $sb == 'template')
+{
+    require NOALYSS_INCLUDE."/upgrade-template.php";
+    
 }
+
 ?>
diff --git a/scenario/package_repository.test.php 
b/scenario/package_repository.test.php
new file mode 100644
index 0000000..5c14014
--- /dev/null
+++ b/scenario/package_repository.test.php
@@ -0,0 +1,103 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2018) Author Dany De Bontridder <address@hidden>
+//@description:Test class Package_Repository
+$_GET=array ();
+$_POST=array ();
+$_POST['gDossier']=$gDossierLogInput;
+$_GET['gDossier']=$gDossierLogInput;
+ $_REQUEST=array_merge($_GET,$_POST);
+ 
+ require_once NOALYSS_INCLUDE.'/class/package_repository.class.php';
+ 
+ $package_repository=new Package_Repository();
+ $package_repository->display_noalyss_info();
+ 
+ echo $package_repository->can_download();
+ 
+ $xml=$package_repository->getContent();
+ 
+ $a_plugin=$xml->xpath('//plugins/plugin');
+ $nb_plugin=count($a_plugin);
+ $a_coprop="";
+ echo "<ol>";
+ for ( $i=0;$i < $nb_plugin;$i++)
+ {
+     echo "<li>";
+     echo $a_plugin[$i]->name;
+     echo "- - - - - - ";
+     echo $a_plugin[$i]->path;
+     echo "- - - - - - ";
+     echo $a_plugin[$i]->author;
+     echo "- - - - - - ";
+     echo $a_plugin[$i]->code;
+     echo "</li>";
+     if (trim($a_plugin[$i]->code)=="AMORTIS")
+    {
+        $a_coprop=$a_plugin[$i];
+        var_dump($a_coprop);
+    }
+ }
+ echo "</ol>";
+ 
+ // find a specific plugin
+$spec_plugin=$xml->xpath("//plugins/plugin[code='AMORTIS']");
+var_dump($spec_plugin);
+ 
+
+
+ $a_noalyss=$xml->xpath("//core");
+ 
+echo "description core ".$a_noalyss[0]->description;
+ 
+// Download fake core 
+echo h1(_("Download core"));
+$core=$package_repository->make_object("core", "");
+$core->download();
+
+//download fake plugin
+echo h1("Plugin : download and install ");
+$plugin=$package_repository->make_object("plugin","COPRO");
+$plugin->download();
+echo h2("Install in noalyss/include/ext/copro-fake");
+$plugin->install();
+
+
+echo h1("Available template");
+ $a_template=$xml->xpath('//database_template/dbtemplate');
+ $nb_template=count($a_template);
+ echo "<ol>";
+ for ( $i=0;$i < $nb_template;$i++)
+ {
+     echo "<li>";
+     echo $a_template[$i]->name;
+     echo "- - - - - - ";
+     echo $a_template[$i]->description;
+     echo "- - - - - - ";
+     echo $a_template[$i]->path;
+     echo "</li>";
+ }
+ echo "</ol>";
+
+ echo h1("Create new database");
+$template=$package_repository->make_object("template", "mod1");
+$template->download();
+$template->install();
+echo h2( $template->get_name()." est installé");
\ No newline at end of file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]