request("sa", "string", 'list'); if (isset($_POST['upd']) && isset($_POST['m'])) { $name=$http->post('name'); $desc =$http->post('desc'); $mod_id=$http->post("m", 0); if (trim($name) != "" && $mod_id != 0 && isNumber($mod_id)==1) { $cn = new Database(); $cn->exec_sql("update modeledef set mod_name=$1, " . " mod_desc=$2 where mod_id=$3 ", array(trim($name), trim($desc), $mod_id)); } $sa = "list"; } $cn = new Database(); $fmod_dbid=$http->post("FMOD_DBID","number",0); // IF FMOD_NAME is posted then must add a template if (isset($_POST["FMOD_NAME"])) { $encoding = $cn->get_value("select encoding from pg_database where " . " datname='" . domaine . 'dossier' . sql_string($fmod_dbid) . "'"); if ($encoding != 6) { alert(_('Désolé vous devez migrer ce modèle en unicode')); echo ''; printf (_('la base de donnée %smod%s doit être migrée en unicode'),domaine,$fmod_dbid); echo ""; echo ' '._("Pour le passer en unicode, faites-en un backup puis restaurez le fichier reçu").''; echo HtmlInput::button_anchor(_('Retour'), 'admin-noalyss.php?action=dossier_mgt'); return; } $mod_name = $http->post("FMOD_NAME"); $mod_desc = $http->post("FMOD_DESC"); if ($mod_name != null || trim ($mod_name) != "") { $Res = $cn->exec_sql("insert into modeledef(mod_name,mod_desc) values ($1,$2)",array($mod_name,$mod_desc)); // get the mod_id $l_id = $cn->get_current_seq('s_modid'); if ($l_id != 0) { $Sql = sprintf("CREATE DATABASE %sMOD%d encoding='UTF8' TEMPLATE %sDOSSIER%s", domaine, $l_id, domaine, $_POST["FMOD_DBID"]); ob_start(); if ($cn->exec_sql($Sql) == false) { ob_end_clean(); echo "

"; printf(_('Base de donnée %sdossier%d" est accèdée, déconnectez-vous en d\'abord'),domaine,$fmod_dbid); echo "

"; $Res = $cn->exec_sql("delete from modeledef where mod_id=$1",array($l_id)); exit; } } }// if $mod_name != null else { alert(_('Le nom est vide')); return; } $cn_mod = new Database($l_id, 'mod'); // Clean some tables $Res = $cn_mod->exec_sql("select distinct jr_pj from jrn where jr_pj is not null "); if (Database::num_row($Res) != 0) { $a_lob = Database::fetch_all($Res); for ($i = 0; $i < count($a_lob); $i++) $cn_mod->lo_unlink($a_lob[$i]['jr_pj']); } $Res = $cn_mod->exec_sql("truncate table centralized"); $Res = $cn_mod->exec_sql("truncate table jrn cascade"); $Res = $cn_mod->exec_sql("delete from del_jrn"); $Res = $cn_mod->exec_sql("delete from del_jrnx"); $Res = $cn_mod->exec_sql("truncate table jrnx cascade "); $Res = $cn_mod->exec_sql("truncate table todo_list cascade "); $Res = $cn_mod->exec_sql("delete from del_action"); $Res = $cn_mod->exec_sql("delete from profile_user"); $Res = $cn_mod->exec_sql("delete from jnt_letter"); $Res = $cn_mod->exec_sql('delete from operation_analytique'); // Delete info from USERS $Res = $cn_mod->exec_sql('delete from user_sec_act'); $Res = $cn_mod->exec_sql('delete from user_sec_action_profile'); $Res = $cn_mod->exec_sql('delete from user_local_pref'); $Res = $cn_mod->exec_sql('delete from user_sec_jrn'); $Res = $cn_mod->exec_sql('delete from bookmark'); // Reset the closed periode $Res = $cn_mod->exec_sql("update parm_periode set p_closed='f'"); $Res = $cn_mod->exec_sql('delete from jrn_periode'); $Res = $cn_mod->exec_sql(' insert into jrn_periode(p_id,jrn_def_id,status) ' . ' select p_id,jrn_def_id,\'OP\' ' . ' from ' . ' parm_periode cross join jrn_def'); // Reset Sequence $a_seq = array('s_jrn', 's_jrn_op', 's_centralized', 's_stock_goods', 's_internal'); foreach ($a_seq as $seq) { $sql = sprintf("select setval('%s',1,false)", $seq); $Res = $cn_mod->exec_sql($sql); } $sql = "select jrn_def_id from jrn_def "; $Res = $cn_mod->exec_sql($sql); $Max = Database::num_row($Res); for ($seq = 0; $seq < $Max; $seq++) { $row = Database::fetch_array($Res, $seq); /* if seq doesn't exist create it */ if ($cn_mod->exist_sequence('s_jrn_' . $row['jrn_def_id']) == false) { $cn_mod->create_sequence('s_jrn_' . $row['jrn_def_id']); } $sql = sprintf("select setval('s_jrn_%d',1,false)", $row['jrn_def_id']); $cn_mod->exec_sql($sql); $sql = sprintf("select setval('s_jrn_pj%d',1,false)", $row['jrn_def_id']); $cn_mod->exec_sql($sql); $sql = sprintf("select setval('jnt_letter_jl_id_seq',1,false)"); $cn_mod->exec_sql($sql); } //--- // Cleaning Follow_Up //-- if (isset($_POST['DOC'])) { $Res = $cn_mod->exec_sql("delete from action_gestion_related"); $Res = $cn_mod->exec_sql("delete from action_gestion_comment"); $Res = $cn_mod->exec_sql("delete from action_gestion_related"); $Res = $cn_mod->exec_sql("delete from action_person"); $Res = $cn_mod->exec_sql("delete from action_gestion"); $Res = $cn_mod->exec_sql("delete from tags"); $Res = $cn_mod->exec_sql("delete from action_tags"); $Res = $cn_mod->exec_sql("delete from document"); // reset sequences for Follow-up $a_seq=$cn_mod->get_array(" select sequence_name " . " from information_schema.sequences " . "where sequence_name like 'seq_doc_type%'" ); $n_seq=count($a_seq); for ($i = 0;$i < $n_seq;$i++) { $cn_mod->alter_seq($a_seq[$i]['sequence_name'], 1); } } if (isset($_POST['CARD'])) { // it is necessary to remove the plugin amortissement due to a // Foreign key without cascading $a_schema=$cn_mod->get_array(" select nspname from pg_namespace where nspname not like 'pg_%' and nspname in ('amortissement') "); $nb_schema=count($a_schema); for ($i=0;$i < $nb_schema;$i++) { $cn_mod->exec_sql(" drop schema ".$a_schema[$i]['nspname']." cascade"); } $Res = $cn_mod->exec_sql("delete from action_gestion"); $Res = $cn_mod->exec_sql("delete from fiche_detail"); $Res = $cn_mod->exec_sql("delete from fiche"); $Res = $cn_mod->exec_sql("delete from document"); $Res = $cn_mod->exec_sql("delete from document_modele"); $Res = $cn_mod->exec_sql("delete from op_predef"); } if (isset($_POST['CANAL'])) { $Res = $cn_mod->exec_sql('delete from poste_analytique'); $Res = $cn_mod->exec_sql('delete from plan_analytique'); } if ( isset ($_POST['PLUGIN'])) { $a_schema=$cn_mod->get_array(" select nspname from pg_namespace where nspname not like 'pg_%' and nspname not in ('information_schema','public','comptaproc') "); $nb_schema=count($a_schema); for ($i=0;$i < $nb_schema;$i++) { $cn_mod->exec_sql(" drop schema ".$a_schema[$i]['nspname']." cascade"); } } // Clean orphan log $cn_mod->clean_orphan_lob(); } // Show all available templates require_once NOALYSS_INCLUDE.'/lib/sort_table.class.php'; $url=$_SERVER['PHP_SELF']."?sa=list&action=".$_REQUEST['action']; $header=new Sort_Table(); $header->add(_("id"),$url," order by mod_id asc"," order by mod_id desc","ia","id"); $header->add(_("Nom"),$url," order by mod_name asc"," order by mod_name desc","na","nd"); $header->add(_("Description"),$url," order by mod_desc asc"," order by mod_desc desc","da","dd"); $ord=(isset($_REQUEST['ord']))?$_REQUEST['ord']:'na'; $sql_order=$header->get_sql_order($ord); $Res = $cn->exec_sql("select mod_id,mod_name,mod_desc from modeledef $sql_order"); $count = Database::num_row($Res); echo '
'; echo "

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

"; if ($sa == 'list') { echo '

'; echo HtmlInput::button(_('Ajouter'),_('Ajouter un modèle')," onclick=\$('folder_add_id').show()"); echo '

'; echo "

" . _("Si vous voulez récupérer toutes les adaptations d'un dossier " . " dans un autre dossier, vous pouvez en faire un modèle." . " Seules les fiches, la structure des journaux, les périodes,... seront reprises " . "et aucune donnée du dossier sur lequel le dossier est basé. Les données contenues dans les extensions ne sont pas effacées") . "

"; echo h2(_("Modèles locaux")); if ($count == 0) { echo _("Aucun modèle disponible"); } else { echo ''; echo _('Filtre').Icon_Action::infobulle(23); echo HtmlInput::filter_table("t_modele", "0,1,2","1"); echo ''; echo ''; echo "". "" . "" . "" . "" . "" . "" . ""; for ($i = 0; $i < $count; $i++) { $mod = Database::fetch_array($Res, $i); $class = ($i % 2 == 0) ? "odd" : "even"; $str_name=domaine.'mod'.$mod['mod_id']; $valid=true; $exist=true; $mod_status=""; if ( $cn->exist_database($str_name) == 0 ) { $exist=false; $mod_status=_('Inexistant'); } if ( $exist ) { $mod_cn=new Database($mod['mod_id'],'mod'); if ( $mod_cn->exist_table("version")==0) { $valid=false; $mod_status=_('Invalide'); } } printf('' . '' . '' . ''. td($mod_status). '' . '' . '' . '' . '' . '', $mod['mod_id'], $mod['mod_name'], $mod['mod_desc']); }// for echo "
".$header->get_header(0)."".$header->get_header(1)."".$header->get_header(2).""._('Nom base de données')."
%d %s %s '.$str_name.' ' . HtmlInput::anchor(_('Effacer'), '?action=modele_mgt&sa=del&m=' . $mod['mod_id']," onclick = \"modele_drop('{$mod['mod_id']}') \"") . '' . HtmlInput::anchor(_('Modifie'), '?action=modele_mgt&sa=mod&m=' . $mod['mod_id']," onclick = \"modele_modify('{$mod['mod_id']}') \"") . '' . HtmlInput::anchor(_('Backup'), '?action=backup&sa=b&t=m&d=' . $mod['mod_id']) . '
"; }// if count = 0 echo h2(_("Modèles disponibles dans le dépôt")); require NOALYSS_INCLUDE . "/upgrade-template.php"; } ?> request('m', "number"); } catch (Exception $e) { echo _('Donnée invalide'); return; } $cn = new Database(); $msg = "dossier"; $name = $cn->get_value("select mod_name from modeledef where mod_id=$1", array($mod_id)); if (strlen(trim($name)) == 0) { echo "

$msg inexistant

"; return; } // Before dropping database check that database exist if ( $cn->exist_database(domaine.'mod'.$mod_id) == 1) { $sql = "drop database " . domaine . "mod" . sql_string($mod_id); ob_start(); if ($cn->exec_sql($sql) == false) { ob_end_clean(); echo "

"; printf (_("Base de donnée %s mod %s est accèdée, déconnectez-vous d'abord"),domaine,$mod_id ) . "

"; exit; } ob_flush(); } $sql = "delete from modeledef where mod_id=$1"; $cn->exec_sql($sql, array($mod_id)); print '

'; printf (_("Le modèle %s est effacé")."

",$name ); echo HtmlInput::button_anchor(_('Retour'), '?action=modele_mgt'); } echo '
'; ?>