diff --git a/html/admin-noalyss.php b/html/admin-noalyss.php index 4cb8235d7..d5046f813 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 70f4f9387..fdf3a7e88 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -203,6 +203,12 @@ $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 admin , install a template + "installTemplate"=>"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/do.php b/html/do.php index 67145029f..263514172 100644 --- a/html/do.php +++ b/html/do.php @@ -190,15 +190,19 @@ if ($cn->exist_table('version') == false) } if (DBVERSION < dossier::get_version($cn)) { - echo '

' . _("Attention: la version de base de donnée est supérieure à la version du programme, vous devriez mettre à jour") . '

'; + $a = _("cliquez ici pour mettre à jour "); + $base =NOALYSS_URL."/admin-noalyss.php?action=upgrade&sb=application"; + + echo '

' . + _("Attention: la version de base de donnée est supérieure à la version du programme, vous devriez mettre à jour") , + '' . $a . '

', + ''; } if (DBVERSION > dossier::get_version($cn)) { echo '

' . _("Votre base de données n'est pas à jour") . ' '; $a = _("cliquez ici pour appliquer le patch"); - $base = dirname($_SERVER['REQUEST_URI']); - if ($base == '/') { $base = ''; } - $base .= '/admin-noalyss.php'; + $base =NOALYSS_URL.'/admin-noalyss.php?action=upgrade&sb=database'; echo '' . $a . '

'; } diff --git a/html/index.css b/html/index.css index 1bdcd3893..e2b10178e 100644 --- a/html/index.css +++ b/html/index.css @@ -62,20 +62,6 @@ background-repeat: repeat-x repeat-y; #logo_id { width:19%; } - - -#recover_box { - - display: none; - position: absolute; - top: 40%; - z-index: 1; - border: 2px solid blue; - width: 30%; - margin-left: 25%; - background-color: whitesmoke; - -} @media only screen and (max-width : 360px) { #alternate_browser { display : none; @@ -87,6 +73,32 @@ background-repeat: repeat-x repeat-y; width:auto; left:0px; + } + #login_frm { + position:absolute; + left:15%; + top:50%; + } + .input_text { + width:8em; + } + #recover_link { + position:absolute; + margin-bottom:30px; + width: 100%; + } + +} + #alternate_browser { + display : none; + } + #logo_id { + position:absolute; + z-index:-1; + height:45%; + width:auto; + left:0px; + } #login_frm { position:absolute; @@ -155,18 +167,48 @@ background-repeat: repeat-x repeat-y; z-index:-1; position:absolute; width:19%; - left:15%; - top:10%; + left:7%; + top:9%; } #login_frm { position:absolute; - left:29%; + left:15%; top:15%; } .input_text { width: 24em; width: 24rem; } + #recover_link { + position:absolute; + margin-top:397px; + left:539px; + background-color: white; +} +} +@media only screen and (min-width : 1100px) { + #alternate_browser { + position:absolute; + bottom: 0px; + left:0px; + z-index: -1; + } + #logo_id { + z-index:-1; + position:absolute; + width:19%; + left:8%; + top:19.5%; + } + #login_frm { + position:absolute; + left:25%; + top:30%; + } + .input_text { + width: 24em; + width: 24rem; + } #recover_link { position:absolute; top:397px; diff --git a/html/index.php b/html/index.php index 4d112d387..f4f5c18d1 100644 --- a/html/index.php +++ b/html/index.php @@ -132,12 +132,14 @@ * */ + if ( ! file_exists('..'.DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'config.inc.php')) { header("Location: install.php",true, 307); exit(0); } + echo ' NOALYSS @@ -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 c770c844a..3aa9be0c0 100644 --- a/html/install.php +++ b/html/install.php @@ -319,73 +319,33 @@ echo "
  • "; echo "
  • "; } +//--------------------------------------------------------------------------------------- +// Check php modules +//--------------------------------------------------------------------------------------- $module=get_loaded_extensions(); -echo "
  • "; $str_error_message=_('Vous devez installer ou activer l\'extension').' %s '; -if ( in_array('mbstring',$module) == false ){ - echo 'module mbstring '.$failed; - echo '', - sprintf($str_error_message, "mbstring"), - ' '; - $flag_php++; -} else echo 'module mbstring '.$succeed; -echo "
  • "; -echo "
  • "; -if ( in_array('pgsql',$module) == false ) -{ - echo 'module PGSQL '.$failed; - echo '', - sprintf($str_error_message, "psql"), - ' '; - $flag_php++; -} else echo 'module PGSQL '.$succeed; -echo "
  • "; +$a_need_module=array("mbstring","pgsql","bcmath","gettext","zip","gd","dom","xml","SimpleXML","xmlwriter","xmlreader"); -echo "
  • "; -if ( in_array('bcmath',$module) == false ) -{ - echo 'module BCMATH ok '.$failed; - echo '', - sprintf($str_error_message, "bcmath"), - ' '; - $flag_php++; -} else echo 'module BCMATH '.$succeed; -echo "
  • "; +$nb_need_module=count($a_need_module); -echo "
  • "; -if (in_array('gettext',$module) == false ) +for ($m=0;$m<$nb_need_module;$m++) { - echo 'module GETTEXT '.$failed; - echo '', - sprintf($str_error_message, "gettext"), - ' '; - $flag_php++; -} else echo 'module GETTEXT '.$succeed; -echo "
  • "; - -echo "
  • "; -if ( in_array('zip',$module) == false ) -{ - echo 'module ZIP '.$failed; - echo '', - sprintf($str_error_message, "zip"), - ' '; - $flag_php++; -} else echo 'module ZIP '.$succeed; -echo "
  • "; -echo "
  • "; -if ( in_array('gd',$module) == false ) -{ - echo 'module GD '.$failed; - echo '', - sprintf($str_error_message, "gd"), - ' '; - $flag_php++; -} else echo 'module GD '.$succeed; -echo "
  • "; - + + echo "
  • "; + if ( in_array($a_need_module[$m],$module) == false ){ + echo 'module '.$a_need_module[$m].$failed; + echo '', + sprintf($str_error_message, $a_need_module[$m]), + ' '; + $flag_php++; + } else echo 'module '.$a_need_module[$m].$succeed; + echo "
  • "; +} +//--------------------------------------------------------------------------------------- +// Max_execution_time , can be overriden +//--------------------------------------------------------------------------------------- if ( ini_get("max_execution_time") < 60 ) { echo "
  • "; echo _('Avertissement').' : '.$failed; @@ -505,13 +465,19 @@ if ( ! isset($_POST['go']) ) { 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 ) { @@ -531,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(); @@ -544,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(); @@ -575,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(); } @@ -631,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 '

    '._('Important').'

    '; echo '

    '._('Utilisateur administrateur'),' ',NOALYSS_ADMINISTRATOR,'

    '; @@ -644,9 +622,9 @@ echo "

    "; printf (" VOUS DEVEZ EFFACER CE FICHIER %s",__FILE__); echo "

    "; - echo "

    "._("Tout est installé")." ". $succeed; + echo "

    "._("Tout est installé")." ". $succeed; ?>

    - +

    \ No newline at end of file diff --git a/html/style-classic7.css b/html/style-classic7.css index 8bcd8c5bc..1e8f7f196 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/html/user_login.php b/html/user_login.php index 8eec383c0..81e6b41bf 100644 --- a/html/user_login.php +++ b/html/user_login.php @@ -68,7 +68,7 @@ $hi=new HttpInput(); if ( $ac->exist_table('version') == false) { echo '

    '._("Base de donnée invalide").'

    '; - $base=dirname($_SERVER['REQUEST_URI']); + echo ''._("Retour").''; exit(); } @@ -78,27 +78,30 @@ if ( $version < DBVERSIONREPO ) { echo '

    '._("Votre base de données n'est pas à jour").' '; $a=_("cliquez ici pour appliquer le patch"); - $base = dirname($_SERVER['REQUEST_URI']); - if ($base == '/') { $base = ''; } - $base .= '/admin-noalyss.php'; + $base =NOALYSS_URL.'/admin-noalyss.php'; echo ''.$a.'

    '; } if ( $User->Admin() == 1) { - if (SITE_UPDATE !="") { - $update=@file_get_contents(SITE_UPDATE); + if (SITE_UPDATE !="") { + $update=@file_get_contents(SITE_UPDATE); if ($update > $version_noalyss ) { - echo '
    '; - echo '

    '; - printf ( "Mise à jour disponible de NOALYSS version actuelle : %s votre version %s ",$update,$version_noalyss); - echo '

    '; - echo '

    '. - _('Fermer'). - "

    "; - echo '
    '; - } - } + echo '
    '; + echo '

    '; + printf ( "Mise à jour disponible de NOALYSS version actuelle : %s votre version %s ",$update,$version_noalyss); + + // Link to admin_repo : upgrade application + $base =NOALYSS_URL."/admin-noalyss.php?action=upgrade&sb=application"; + + echo '' . _("Cliquez ici pour mettre à jour") . ''; + echo '

    '; + echo '

    '. + _('Fermer'). + "

    "; + echo '
    '; + } + } } include_once NOALYSS_INCLUDE."/lib/user_menu.php"; @@ -144,12 +147,11 @@ if ( $User->admin == 0 || (defined("MULTI")&& MULTI == 0 ) ) if ( $folder != null && count($folder) == 1 ) { - redirect('do.php?gDossier='.$folder[0]['dos_id']); + redirect(NOALYSS_URL.'/do.php?gDossier='.$folder[0]['dos_id']); exit(); } } - $result=""; $result.=""; $result.=''; diff --git a/include/admin_repo.inc.php b/include/admin_repo.inc.php index a5aedd0f0..b0b1d9f92 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"; @@ -46,7 +47,7 @@ if ($User->admin != 1) echo _("Vous n'êtes pas administateur"); echo ""; $reconnect=http_build_query(array("reconnect"=>1,"backurl"=>"admin-noalyss.php?action=upgrade")); - echo ''; + echo ''; echo _("Connectez-vous comme administrateur"); echo ''; html_page_stop(); @@ -59,7 +60,7 @@ if ( $action== 'backup') { require_once NOALYSS_INCLUDE."/backup.inc.php"; exit(); } -html_page_start(); +html_page_start($_SESSION['g_theme']); load_all_script(); echo '

    '._('Administration').'

    '; echo '
    '; @@ -191,19 +192,16 @@ hr {width: 600px; background-color: #cccccc; border: 0px; height: 1px; color: #0 echo $html->saveHTML(); } +//------------------------------------------------------------------------------ +// Upgrade +//------------------------------------------------------------------------------ if ( $action == "upgrade" ) { -?> -
    - - - - -
    diff --git a/include/ajax/ajax_admin.php b/include/ajax/ajax_admin.php index 47ffdc01d..70856bd5c 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'); ?> + return false">

    - + - + onkeyup="filter_table(this, 'folder_display_tb', '1,2,3', 0)" > +

    @@ -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').' :
    '; echo $wDesc->input('desc', $dos->get_parameter('desc')); echo '
    '; - - 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(' install.php', 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/ajax/ajax_periode.php b/include/ajax/ajax_periode.php index 05cd807c8..6dd49386a 100644 --- a/include/ajax/ajax_periode.php +++ b/include/ajax/ajax_periode.php @@ -279,9 +279,11 @@ switch ($act) $a_answer['content']=ob_get_clean(); $a_answer['status']="OK"; $a_answer['p_id']=$p_id; + $a_answer['status']="OK"; } catch (Exception $e) { + $a_answer['status']="NOK"; $a_answer['content']=$e->getMessage(); } break; diff --git a/include/audit_log.php b/include/audit_log.php index a9a93f0b9..c18a42135 100644 --- a/include/audit_log.php +++ b/include/audit_log.php @@ -17,14 +17,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// Copyright Author Dany De Bontridder danydb@aevalys.eu +// Copyright Author Dany De Bontridder danydb@noalyss.eu /*!\file * \brief let you see the list of the connexion */ if ( !defined ('ALLOWED')) die('Forbidden'); ?> -
    +
    Liste limitée aux 100 dernières connexions "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 ''; } - /*!\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 "

    "._("Mise à jour de la base de données principale")."

    "; + $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 "

    "._("Mise à jour dossiers")."

    "; + + for ($e=0; $e<$MaxDossier; $e++) + { + $db_row=Database::fetch_array($Resdossier, $e); + $name=$rep->format_name($db_row['dos_id'], 'dos'); + echo "

    Patching ".$db_row['dos_name'].'

    '; + 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 "

    "._("Mise à jour modèles")."

    "; + + for ($e=0; $e<$MaxDossier; $e++) + { + $db_row=Database::fetch_array($Resdossier, $e); + $name=$rep->format_name($db_row['mod_id'], 'mod'); + echo "

    Patching ".$db_row['mod_name']."

    "; + 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/extension.class.php b/include/class/extension.class.php index 781318938..86e29a814 100644 --- a/include/class/extension.class.php +++ b/include/class/extension.class.php @@ -1,4 +1,5 @@ me_code)=="") throw new Exception('Le code ne peut pas être vide'); - if (trim($this->me_menu)=="") throw new Exception('Le nom ne peut pas être vide'); - if (trim($this->me_file)=="") throw new Exception('Chemin incorrect'); - if (file_exists(NOALYSS_PLUGIN.'/'.$this->me_file) == false) - throw new Exception ('Extension non trouvée, le chemin est-il correct?'); + if (trim($this->me_code)=="") + throw new Exception('Le code ne peut pas être vide'); + if (trim($this->me_menu)=="") + throw new Exception('Le nom ne peut pas être vide'); + if (trim($this->me_file)=="") + throw new Exception('Chemin incorrect'); + if (file_exists(NOALYSS_PLUGIN.'/'.$this->me_file)==false) + throw new Exception('Extension non trouvée, le chemin est-il correct?'); } - /*!@brief search a extension, the what is the column (extends_code */ + + /* !@brief search a extension, the what is the column (extends_code */ + function search($p_what) { - $this->me_code=strtoupper($p_what); - if ( $this->load() == -1) return null; - return 1; + $this->me_code=strtoupper($p_what); + if ($this->load()==-1) + return null; + return 1; } - /*!\brief return 1 if the user given in parameter can access this extension + + /* !\brief return 1 if the user given in parameter can access this extension * otherwise returns 0 - *\param $p_login the user login - *\return 1 has access, 0 has no access + * \param $p_login the user login + * \return 1 has access, 0 has no access */ + function can_request($p_login) { - $cnt=$this->cn->get_value("select count(*) from menu_ref - join profile_menu using (me_code) - join profile_user using (p_id) - where - me_code=$1 - and user_name=$2", - array($this->me_code,$p_login)); - if ( $cnt > 0) return 1; - return 0; + $cnt=$this->cn->get_value("select count(*) from menu_ref + join profile_menu using (me_code) + join profile_user using (p_id) + where + me_code=$1 + and user_name=$2", array($this->me_code, $p_login)); + if ($cnt>0) + return 1; + return 0; } - /*!@brief make an array of the available plugin for the current user + + /* !@brief make an array of the available plugin for the current user * @return an array - *@see ISelect + * @see ISelect */ + static function make_array($cn) { $sql="select DISTINCT me_code as value, me_menu as label from ". - " menu_ref join profile_menu using (me_code) + " menu_ref join profile_menu using (me_code) join profile_user using (p_id) where ". - " user_name=$1 and me_type='PL' ORDER BY ME_MENU"; - $a=$cn->get_array($sql,array($_SESSION['g_user'])); + " user_name=$1 and me_type='PL' ORDER BY ME_MENU"; + $a=$cn->get_array($sql, array($_SESSION['g_user'])); return $a; } + static function check_version($i) { global $version_noalyss; - if ( ! isset ($version_noalyss) || $version_noalyss < $i ) + if (!isset($version_noalyss)||$version_noalyss<$i) { alert(_('Cette extension ne fonctionne pas sur cette version de NOALYSS'. - ' Veuillez mettre votre programme a jour. Version minimum ').$i); + ' Veuillez mettre votre programme a jour. Version minimum ').$i); return; } Extension::check_plugin_version(); } + /** * insert into the table profile_menu for the given profile id and depending * of the module $p_module @@ -112,28 +126,31 @@ class Extension extends Menu_Ref_sql // Module for the plugin $p_module=$this->depend; //profile exists ? - $profile=new Profile_sql($cn,$p_id); - if ( $profile->p_id != $p_id) { - throw new Exception(_('Profil inexistant'),10); + $profile=new Profile_sql($cn, $p_id); + if ($profile->p_id!=$p_id) + { + throw new Exception(_('Profil inexistant'), 10); } // Menu exists - $module=new Menu_Ref($cn,$p_module); - if ($module->me_code==null) { - throw new Exception(_('Module inexistant'),20); + $module=new Menu_Ref($cn, $p_module); + if ($module->me_code==null) + { + throw new Exception(_('Module inexistant'), 20); } // Dependency $dep_id=$cn->get_array('select pm_id from profile_menu where p_id=$1 - and me_code = $2 ',array($p_id,$p_module)); + and me_code = $2 ', array($p_id, $p_module)); // throw an exception if there is no dependency - if (empty($dep_id)) { - throw new Exception(_('Pas de menu ').$p_module,30); + if (empty($dep_id)) + { + throw new Exception(_('Pas de menu ').$p_module, 30); } $nb_dep=count($dep_id); - + // insert at the right location - for ($i=0;$i<$nb_dep;$i++) + for ($i=0; $i<$nb_dep; $i++) { $profil_menu=new Profile_Menu($cn); $profil_menu->me_code=$this->me_code; @@ -144,178 +161,203 @@ class Extension extends Menu_Ref_sql $profil_menu->pm_default=0; $profil_menu->p_order=$this->order; - $cnt=$profil_menu->count(' where pm_id_dep=$3 and p_id=$1 and me_code = $2',array($p_id,$this->me_code,$dep_id[$i]['pm_id'])); - if ( $cnt==0) { + $cnt=$profil_menu->count(' where pm_id_dep=$3 and p_id=$1 and me_code = $2', + array($p_id, $this->me_code, $dep_id[$i]['pm_id'])); + if ($cnt==0) + { $profil_menu->insert(); } } - - } + function remove_from_profile_menu($p_id) { global $cn; - - $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)); - + + $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)); } + /** * Insert a plugin into the given profile, by default always insert into EXT * * @param type $p_id profile.p_id * @throws Exception if duplicate or error db */ - function insert_plugin() - { - try - { - $this->cn->start(); - $this->verify(); - // check if duplicate - $this->me_code = strtoupper($this->me_code); - $count = $this->cn->get_value("select count(*) from menu_ref where me_code=$1", array($this->me_code)); - if ($count != 0) - throw new Exception("Doublon"); - $this->me_type = 'PL'; - $this->insert(); - $this->cn->commit(); - } - catch (Exception $exc) - { - echo alert($exc->getMessage()); - } - } - function update_plugin() - { - try - { - $this->cn->start(); - $this->verify(); - $this->me_type = 'PL'; - $this->update(); - $this->cn->commit(); - } - catch (Exception $exc) - { - echo alert($exc->getMessage()); - } - } - function remove_plugin() - { - try - { - $this->cn->start(); - $this->delete(); - $this->cn->commit(); - } - catch (Exception $exc) - { - echo alert($exc->getMessage()); - } - } - /** - *remove all the schema from the plugins - * @param Database $p_cn - */ - static function clean(Database $p_cn) - { - $a_ext=array("tva_belge","amortissement","impdol","coprop","importbank"); - for($i=0;$iexist_schema($a_ext[$i])) { - $p_cn->exec_sql("drop schema ".$a_ext[$i]." cascade"); - } - } - } - static function check_plugin_version() + function insert_plugin() + { + try { - global $g_user,$version_plugin; - if ($g_user->Admin() == 1) - { - if (SITE_UPDATE_PLUGIN != "") - { - $update = @file_get_contents(SITE_UPDATE_PLUGIN); - if ($update > $version_plugin) - { - echo '
    '; - echo '

    '; - echo "Mise à jour disponible des plugins pour NOALYSS, version actuelle : $update votre version $version_plugin"; - echo '

    '; - echo '

    '. - ''. - _('Fermer'). - "

    "; - echo '
    '; - } - } - } + $this->cn->start(); + $this->verify(); + // check if duplicate + $this->me_code=strtoupper($this->me_code); + $count=$this->cn->get_value("select count(*) from menu_ref where me_code=$1", array($this->me_code)); + if ($count!=0) + throw new Exception("Doublon"); + $this->me_type='PL'; + $this->insert(); + $this->cn->commit(); } - /** - * 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 - * @brief Check XML. - * @param SimpleXMLElement $xml - * @throws Exception - */ - function check_xml(SimpleXMLElement $xml) + catch (Exception $exc) { - try { - if ( !isset ($xml->plugin)) throw new Exception(_('Manque plugin'),1); - $nb_plugin=count($xml->plugin); - - for ($i=0;$i<$nb_plugin;$i++) - { - if ( !isset ($xml->plugin[$i]->name)) throw new Exception(_('Manque nom'),1); - if ( !isset ($xml->plugin[$i]->description)) throw new Exception(_('Manque description'),0); - if ( !isset ($xml->plugin[$i]->code)) throw new Exception(_('Manque code'),1); - if ( !isset ($xml->plugin[$i]->author)) throw new Exception(_('Manque auteur'),0); - if ( !isset ($xml->plugin[$i]->root)) throw new Exception(_('Manque répertoire racine'),1); - if ( !isset ($xml->plugin[$i]->file)) throw new Exception(_('Manque fichier à inclure'),1); - if ( !isset ($xml->plugin[$i]->depend)) $xml->plugin[$i]->depend="EXT"; - if ( !isset ($xml->plugin[$i]->order)) $xml->plugin[$i]->order=9000; - } - } catch (Exception $ex) { - throw $ex; - } + echo alert($exc->getMessage()); } - /** - * Parse a XML file to complete an array of extension objects - * @brief Create extension from XML. - * @param type $p_file filename - * @return array of Extension - */ - static function read_definition($p_file) - { - global $cn; - $dom=new DomDocument('1.0'); - $dom->load($p_file); - $xml=simplexml_import_dom($dom); - $nb_plugin=count($xml->plugin); - $a_extension=array(); - for ($i=0;$i<$nb_plugin;$i++) - { - - $extension=new Extension($cn); - try { - $extension->check_xml($xml); - } catch (Exception $ex) { - echo_warning($e->getMessage()); - if ( $ex->getCode()==1) { - continue; - } - - } - $extension->me_file=trim($xml->plugin[$i]->root).'/'.trim($xml->plugin[$i]->file); - $extension->me_code=trim($xml->plugin[$i]->code); - $extension->me_description=(isset ($xml->plugin[$i]->description))?trim($xml->plugin[$i]->description):""; - $extension->me_description_etendue=(trim($xml->plugin[$i]->author))?trim($xml->plugin[$i]->author):""; - $extension->me_type='PL'; - $extension->me_menu=trim($xml->plugin[$i]->name); - $extension->me_parameter='plugin_code='.trim($xml->plugin[$i]->code); - $extension->depend=(isset($xml->plugin[$i]->depend))?trim($xml->plugin[$i]->depend):""; - $extension->order=(isset($xml->plugin[$i]->order))?trim($xml->plugin[$i]->order):9000; - $a_extension[]=clone $extension; - } - return $a_extension; - } -} + } + function update_plugin() + { + try + { + $this->cn->start(); + $this->verify(); + $this->me_type='PL'; + $this->update(); + $this->cn->commit(); + } + catch (Exception $exc) + { + echo alert($exc->getMessage()); + } + } + + function remove_plugin() + { + try + { + $this->cn->start(); + $this->delete(); + $this->cn->commit(); + } + catch (Exception $exc) + { + echo alert($exc->getMessage()); + } + } + + /** + * remove all the schema from the plugins + * @param Database $p_cn + */ + static function clean(Database $p_cn) + { + $a_ext=array("tva_belge", "amortissement", "impdol", "coprop", "importbank"); + for ($i=0; $iexist_schema($a_ext[$i])) + { + $p_cn->exec_sql("drop schema ".$a_ext[$i]." cascade"); + } + } + } + + static function check_plugin_version() + { + global $g_user, $version_plugin; + if ($g_user->Admin()==1) + { + if (SITE_UPDATE_PLUGIN!="") + { + $update=@file_get_contents(SITE_UPDATE_PLUGIN); + if ($update>$version_plugin) + { + echo '
    '; + echo '

    '; + echo "Mise à jour disponible des plugins pour NOALYSS, version actuelle : $update votre version $version_plugin"; + echo '

    '; + echo '

    '. + ''. + _('Fermer'). + "

    "; + echo '
    '; + } + } + } + } + + /** + * 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 + * @brief Check XML. + * @param SimpleXMLElement $xml + * @throws Exception + */ + function check_xml(SimpleXMLElement $xml) + { + try + { + if (!isset($xml->plugin)) + throw new Exception(_('Manque plugin'), 1); + $nb_plugin=count($xml->plugin); + + for ($i=0; $i<$nb_plugin; $i++) + { + if (!isset($xml->plugin[$i]->name)) + throw new Exception(_('Manque nom'), 1); + if (!isset($xml->plugin[$i]->description)) + throw new Exception(_('Manque description'), 0); + if (!isset($xml->plugin[$i]->code)) + throw new Exception(_('Manque code'), 1); + if (!isset($xml->plugin[$i]->author)) + throw new Exception(_('Manque auteur'), 0); + if (!isset($xml->plugin[$i]->root)) + throw new Exception(_('Manque répertoire racine'), 1); + if (!isset($xml->plugin[$i]->file)) + throw new Exception(_('Manque fichier à inclure'), 1); + if (!isset($xml->plugin[$i]->depend)) + $xml->plugin[$i]->depend="EXT"; + if (!isset($xml->plugin[$i]->order)) + $xml->plugin[$i]->order=9000; + } + } + catch (Exception $ex) + { + throw $ex; + } + } + + /** + * Parse a XML file to complete an array of extension objects + * @brief Create extension from XML. + * @param string $p_file filename + * @return array array of Extension + */ + static function read_definition($p_file) + { + global $cn; + $dom=new DomDocument('1.0'); + $dom->load($p_file); + $xml=simplexml_import_dom($dom); + $nb_plugin=count($xml->plugin); + $a_extension=array(); + for ($i=0; $i<$nb_plugin; $i++) + { + + $extension=new Extension($cn); + try + { + $extension->check_xml($xml); + } + catch (Exception $ex) + { + echo_warning($e->getMessage()); + if ($ex->getCode()==1) + { + continue; + } + } + $extension->me_file=trim($xml->plugin[$i]->root).'/'.trim($xml->plugin[$i]->file); + $extension->me_code=trim($xml->plugin[$i]->code); + $extension->me_description=(isset($xml->plugin[$i]->description))?trim($xml->plugin[$i]->description):""; + $extension->me_description_etendue=(trim($xml->plugin[$i]->author))?trim($xml->plugin[$i]->author):""; + $extension->me_type='PL'; + $extension->me_menu=trim($xml->plugin[$i]->name); + $extension->me_parameter='plugin_code='.trim($xml->plugin[$i]->code); + $extension->depend=(isset($xml->plugin[$i]->depend))?trim($xml->plugin[$i]->depend):""; + $extension->order=(isset($xml->plugin[$i]->order))?trim($xml->plugin[$i]->order):9000; + $a_extension[]=clone $extension; + } + return $a_extension; + } + +} diff --git a/include/class/package_contrib.class.php b/include/class/package_contrib.class.php new file mode 100644 index 000000000..19196398a --- /dev/null +++ b/include/class/package_contrib.class.php @@ -0,0 +1,25 @@ + + +/** + * @file + * @brief + */ diff --git a/include/class/package_core.class.php b/include/class/package_core.class.php new file mode 100644 index 000000000..44b8787af --- /dev/null +++ b/include/class/package_core.class.php @@ -0,0 +1,64 @@ + +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 000000000..d33fde657 --- /dev/null +++ b/include/class/package_noalyss.class.php @@ -0,0 +1,117 @@ + + +/** + * @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_plugin.class.php b/include/class/package_plugin.class.php new file mode 100644 index 000000000..046bfdd21 --- /dev/null +++ b/include/class/package_plugin.class.php @@ -0,0 +1,66 @@ + + +/** + * @file + * @brief + */ +require_once NOALYSS_INCLUDE."/class/package_noalyss.class.php"; + +/** + * @class + * @brief + */ +class Package_Plugin extends Package_Noalyss +{ + + 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); + } + } + + /** + * Check the NOALYSS_PLUGIN is writeable + */ + public function can_install() + { + if (is_writable(NOALYSS_PLUGIN)) + { + return TRUE; ; + } + return FALSE; + } + + +} diff --git a/include/class/package_repository.class.php b/include/class/package_repository.class.php new file mode 100644 index 000000000..d78af3aba --- /dev/null +++ b/include/class/package_repository.class.php @@ -0,0 +1,175 @@ + + +/** + * @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 "
    ";
    +                    echo $this->content->core->description;
    +                    echo "
    "; + + 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 000000000..caa5666d4 --- /dev/null +++ b/include/class/package_template.class.php @@ -0,0 +1,77 @@ + + + +/** + * @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 8e4a64c08..4ff4dfc9d 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) @@ -264,15 +264,14 @@ class Periode $Res=$this->cn->exec_sql("insert into jrn_periode (jrn_def_id,p_id,status) ". "select jrn_def_id,$p_id,'OP' from jrn_def"); $this->cn->commit(); + return $p_id; } catch (Exception $e) { record_log($e->getTraceAsString()); $this->cn->rollback(); throw $e; - return 1; } - return 0; } /* !\brief load data from database @@ -478,10 +477,7 @@ class Periode $date_start=sprintf('01.%02d.%d', $month, $year); $date_end=$this->cn->get_value("select to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '1 day','DD.MM.YYYY')", array($date_start)); - if ($this->insert($date_start, $date_end, $p_exercice)!=0) - { - throw new Exception('Erreur insertion période'); - } + $this->insert($date_start, $date_end, $p_exercice); } $month++; if ($month == 13 ) diff --git a/include/constant.php b/include/constant.php index 31b88012f..afa6e050f 100644 --- a/include/constant.php +++ b/include/constant.php @@ -103,7 +103,9 @@ if ( !defined("SITE_UPDATE")) define ("SITE_UPDATE",'http://www.noalyss.eu/last_version.txt'); if ( !defined("SITE_UPDATE_PLUGIN")) define ("SITE_UPDATE_PLUGIN",'http://www.noalyss.eu/plugin_last_version.txt'); - +if ( !defined ("NOALYSS_PACKAGE_REPOSITORY")) { + define ("NOALYSS_PACKAGE_REPOSITORY","https://package.noalyss.eu/"); +} // If you don't want that the system information is accessible if ( ! defined ("SYSINFO_DISPLAY")) { define ("SYSINFO_DISPLAY",TRUE); @@ -311,3 +313,13 @@ define ('EXC_PARAM_TYPE',1006); define ('EXC_DUPLICATE',1200); define ("UNPINDG",""); define ("PINDG",""); + +// Url of NOALYSS (http://...) +// +if ( ! defined ("NOALYSS_URL")) { + $base=$_SERVER['REQUEST_SCHEME'].'://'. + $_SERVER['HTTP_HOST']. + ":".$_SERVER['SERVER_PORT']. + dirname($_SERVER['PHP_SELF']); + define ("NOALYSS_URL",$base); +} \ No newline at end of file diff --git a/include/dossier.inc.php b/include/dossier.inc.php index 4b0865185..25d865934 100644 --- a/include/dossier.inc.php +++ b/include/dossier.inc.php @@ -45,7 +45,7 @@ if ( isset ($_POST['upd']) && isNumber($dossier_id) == 1 && $dossier_id != -1) $dos->set_parameter("max_email", $max_email); $dos->save(); } -echo '
    '; +echo '
    '; /* * check and add an new folder */ diff --git a/include/lib/user_menu.php b/include/lib/user_menu.php index b37d630c4..b3dc5fa2c 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), @@ -145,7 +145,7 @@ function MenuAdmin() ); } - $menu=ShowItem($item,'H',"mtitle","mtitle",$def,' style="width:80%;margin-left:10%" '); + $menu=ShowItem($item,'H',"mtitle","mtitle",$def); return $menu; } diff --git a/include/modele.inc.php b/include/modele.inc.php index aa8002a04..5998b636b 100644 --- a/include/modele.inc.php +++ b/include/modele.inc.php @@ -254,7 +254,7 @@ $Res = $cn->exec_sql("select mod_id,mod_name,mod_desc from modeledef $sql_order"); $count = Database::num_row($Res); -echo '
    '; +echo '
    '; echo "

    "._('Modèles')."

    "; if ($sa == 'list') { diff --git a/include/restore.inc.php b/include/restore.inc.php index 941cfc180..2dd3e0489 100644 --- a/include/restore.inc.php +++ b/include/restore.inc.php @@ -72,7 +72,7 @@ if ( isset ($_REQUEST['sa'] )) // Restore a folder (dossier) if ( $_REQUEST['t']=='d') { - echo '
    '; + echo '
    '; $cn=new Database(); $id=$cn->get_next_seq('dossier_id'); diff --git a/include/upgrade-core.php b/include/upgrade-core.php new file mode 100644 index 000000000..529bf86ed --- /dev/null +++ b/include/upgrade-core.php @@ -0,0 +1,65 @@ + + +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 '

    '; +echo $xml->core->description; +echo '

    '; + +if ( $xml->core->version < NOALYSS_VERSION) { + echo '

    '; + echo _("Votre version est à jour"); + echo '

    '; + return; +} + +$js="onclick='UpgradeCore()'"; + +echo HtmlInput::button("upgrade",_("Mise à jour de votre système"),$js); +?> +
    + +
    + \ No newline at end of file diff --git a/include/upgrade-plugin.php b/include/upgrade-plugin.php new file mode 100644 index 000000000..a1d78cd88 --- /dev/null +++ b/include/upgrade-plugin.php @@ -0,0 +1,133 @@ + + +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); +?> + +
    + + + + + + + + + + + + + + + + + +
    + + + + + + + + + Installé ou mettre à jour ??? +
    + name; ?> + + description; ?> + + author; ?> + + code; ?> + version [version; ?>] + + + 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))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); + } + ?> +
    + + \ No newline at end of file diff --git a/include/upgrade-template.php b/include/upgrade-template.php new file mode 100644 index 000000000..93732055a --- /dev/null +++ b/include/upgrade-template.php @@ -0,0 +1,66 @@ + + +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 ""; +echo tr( + th(_("Nom")).th(_("Description")).th(_("Mise à jour")) +); +for ($i=0; $i<$nb_template; $i++) +{ + echo ''; + echo td($a_template[$i]->name); + echo td($a_template[$i]->description); + echo td($a_template[$i]->date_update); + echo ''; + echo ''; +} +echo "
    '; + $js=sprintf("onclick=\"install_template('%s')\"", trim($a_template[$i]->code)); + echo HtmlInput::button("installTemplate", "Installation modèle", $js); + echo '
    "; +?> + \ No newline at end of file diff --git a/include/upgrade.inc.php b/include/upgrade.inc.php index 8c73434d5..ce2a28d7d 100644 --- a/include/upgrade.inc.php +++ b/include/upgrade.inc.php @@ -1,5 +1,4 @@ - -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é'));} -get("sb", "string","none"); -if ($sb === "upg_all" && (!defined('MULTI')||(defined('MULTI')&&MULTI==1))) + +$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 ''; + +$sc=$http->get("sc", "string", "none"); + +//----------------------------------------------------------------------------- +// Upgrade Databases (Folder, Template , Account ) +//----------------------------------------------------------------------------- +if ($sb=="database") { - echo '
    '; - /* If multi folders */ - $Resdossier=$rep->exec_sql("select dos_id, dos_name from ac_dossier"); - $MaxDossier=$rep->size($Resdossier); - - //---------------------------------------------------------------------- - // Upgrade the account_repository - //---------------------------------------------------------------------- - echo "

    "._("Mise à jour de la base de données principale")."

    "; - $cn=new Database(); - if (DEBUG==false) - ob_start(); - $MaxVersion=DBVERSIONREPO-1; - for ($i=4; $i<=$MaxVersion; $i++) + ?> +
    + + + + +
    + + get_version()<=$i) - { - $cn->execute_script(NOALYSS_INCLUDE.'/sql/patch/ac-upgrade'.$i.'.sql'); - } + echo '
    '; + + Dossier::upgrade(); + + echo '
    '; + return; } - //---------------------------------------------------------------------- - // Upgrade the folders - //---------------------------------------------------------------------- - echo "

    "._("Mise à jour dossiers")."

    "; - - for ($e=0; $e<$MaxDossier; $e++) - { - $db_row=Database::fetch_array($Resdossier, $e); - $name=$rep->format_name($db_row['dos_id'], 'dos'); - echo "

    Patching ".$db_row['dos_name'].'

    '; - 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 "

    "._("Mise à jour modèles")."

    "; - - for ($e=0; $e<$MaxDossier; $e++) - { - $db_row=Database::fetch_array($Resdossier, $e); - $name=$rep->format_name($db_row['mod_id'], 'mod'); - echo "

    Patching ".$db_row['mod_name']."

    "; - 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"); - } - } - } +// 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/include/user.inc.php b/include/user.inc.php index 1d1c97aa9..3148f2f55 100644 --- a/include/user.inc.php +++ b/include/user.inc.php @@ -29,7 +29,7 @@ if ( !defined ('ALLOWED')) die('Forbidden'); require_once NOALYSS_INCLUDE.'/lib/sort_table.class.php'; require_once NOALYSS_INCLUDE.'/lib/http_input.class.php'; $http=new HttpInput(); -echo '
    '; +echo '
    '; /******************************************************/ // Add user /******************************************************/ diff --git a/scenario/package_repository.test.php b/scenario/package_repository.test.php new file mode 100644 index 000000000..5c14014b5 --- /dev/null +++ b/scenario/package_repository.test.php @@ -0,0 +1,103 @@ + +//@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 "
      "; + for ( $i=0;$i < $nb_plugin;$i++) + { + echo "
    1. "; + echo $a_plugin[$i]->name; + echo "- - - - - - "; + echo $a_plugin[$i]->path; + echo "- - - - - - "; + echo $a_plugin[$i]->author; + echo "- - - - - - "; + echo $a_plugin[$i]->code; + echo "
    2. "; + if (trim($a_plugin[$i]->code)=="AMORTIS") + { + $a_coprop=$a_plugin[$i]; + var_dump($a_coprop); + } + } + echo "
    "; + + // 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 "
      "; + for ( $i=0;$i < $nb_template;$i++) + { + echo "
    1. "; + echo $a_template[$i]->name; + echo "- - - - - - "; + echo $a_template[$i]->description; + echo "- - - - - - "; + echo $a_template[$i]->path; + echo "
    2. "; + } + echo "
    "; + + 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