get_value('select count(*) from modeledef where ' . 'mod_name=$1 and mod_id !=$2', array(trim($name), $m)) == 0 ) { $cn->exec_sql("update modeledef set mod_name=$1, " . " mod_desc=$2 where mod_id=$3 ", array(trim($name), trim($desc), $m)); } } $sa = "list"; } $cn = new Database(); // 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($_POST["FMOD_DBID"]) . "'"); if ($encoding != 6) { alert(_('Désolé vous devez migrer ce modèle en unicode')); echo ''._('la base de donnée')." " . domaine . 'mod' . $_POST["FMOD_DBID"]." " . _("doit être migrée en unicode").""; echo ' '._("Pour le passer en unicode, faites-en un backup puis restaurez le fichier reçu").''; echo HtmlInput::button_anchor(_('Retour'), 'admin_repo.php?action=dossier_mgt'); return; } $mod_name = sql_string($_POST["FMOD_NAME"]); $mod_desc = sql_string($_POST["FMOD_DESC"]); if ($mod_name != null) { $Res = $cn->exec_sql("insert into modeledef(mod_name,mod_desc) values ('" . $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 "

Base de donnée " . domaine . "dossier" . $_POST['FMOD_DBID'] . " "._("est accèdée, déconnectez-vous en d'abord")."

"; $Res = $cn->exec_sql("delete from modeledef where mod_id=" . $l_id); exit; } } }// if $mod_name != null $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']); } Extension::clean($cn_mod); $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'); // 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"); $Res = $cn_mod->exec_sql("delete from document"); // Remove lob file $Res = $cn_mod->exec_sql("select distinct loid from pg_largeobject except select md_lob from document_modele"); if (Database::num_row($Res) != 0) { $a_lob = Database::fetch_all($Res); //var_dump($a_lob); foreach ($a_lob as $lob) { $cn_mod->lo_unlink($lob['loid']); } } } if (isset($_POST['CARD'])) { $Res = $cn_mod->exec_sql("delete from fiche_detail"); $Res = $cn_mod->exec_sql("delete from fiche"); $Res = $cn_mod->exec_sql("delete from action_gestion"); $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"); // Remove lob file $Res = $cn_mod->exec_sql("select distinct loid from pg_largeobject"); if (Database::num_row($Res) != 0) { $a_lob = Database::fetch_all($Res); foreach ($a_lob as $lob) $cn_mod->lo_unlink($lob['loid']); } } 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"); } } } // Show all available templates require_once NOALYSS_INCLUDE.'/class_sort_table.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 '

'; if ($count == 0) { echo _("Aucun modèle disponible"); } else { echo ''; echo _('Filtre').HtmlInput::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']; printf('' . '' . '' . ''. '' . '' . '' . '' . '' . '', $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'), 'backup.php?action=backup&sa=b&t=m&d=' . $mod['mod_id']) . '
"; }// if count = 0 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")."

"; } ?> get_value("select mod_name from modeledef where mod_id=$1", array($_REQUEST['m'])); if (strlen(trim($name)) == 0) { echo "

$msg inexistant

"; return; } $sql = "drop database " . domaine . "mod" . sql_string($_REQUEST['m']); 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,$_REQUEST['m'] ) . "

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

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

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