diff --git a/apps/maarch_entreprise/js/angularFunctions.js b/apps/maarch_entreprise/js/angularFunctions.js
index f9740d3033db9c7c2a32c5cdb51891449bdb220e..3bd27e5cb3d39ae5834d61482449c7c779f8dd02 100755
--- a/apps/maarch_entreprise/js/angularFunctions.js
+++ b/apps/maarch_entreprise/js/angularFunctions.js
@@ -132,24 +132,6 @@ if (Prototype.BrowserFeatures.ElementExtensions) {
     disablePrototypeJS('hide', pluginsToDisable);
 }
 
-function duplicateTemplate(id) {
-    var r = confirm("Voulez-vous vraiment dupliquer le modèle ?");
-
-    if (r) {
-        $j.ajax({
-            url      : '../../rest/templates/' + id + '/duplicate',
-            type     : 'POST',
-            dataType : 'json',
-            data: {},
-            success: function(answer) {
-                location.href = "index.php?page=templates_management_controler&mode=up&module=templates&id=" + answer.id + "&start=0&order=asc&order_field=&what=";
-            }, error: function(err) {
-                alert("Une erreur s'est produite");
-            }
-        });
-    }
-}
-
 function setAttachmentInSignatureBook(id, isVersion) {
     $j.ajax({
         url      : '../../rest/attachments/' + id + '/inSignatureBook',
diff --git a/modules/templates/addTemplateBase.php b/modules/templates/addTemplateBase.php
deleted file mode 100644
index 8f4a74f4a5cfbff31031a43974b40b33674dc378..0000000000000000000000000000000000000000
--- a/modules/templates/addTemplateBase.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php 
-require 'modules/templates/class/templates_controler.php';
-$templatesControler = new templates_controler();
-if (!in_array($_REQUEST['fileMimeType'],array('application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.ms-excel','application/vnd.ms-powerpoint','application/vnd.openxmlformats-officedocument.presentationml‌​.slideshow','application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.presentation','application/vnd.oasis.opendocument.spreadsheet'))) {
-    echo "{\"status\":1,\"error_txt\":\""._EXTENSION_NOT_ALLOWED."\"}";
-    exit();
-}
-if (isset($_REQUEST['fileContent'])) {
-    $filename = htmlentities($_REQUEST['fileName'], ENT_NOQUOTES, 'UTF-8');
-    
-    $filename = preg_replace('#&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $filename);
-    $filename = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $filename); // pour les ligatures e.g. '&oelig;'
-    $filename = preg_replace('#[^\w]+#', '_', $filename); // supprime les autres caractères
-    $fileContent = base64_decode($_REQUEST['fileContent']);
-
-    if ($_REQUEST['saveTemplateBase'] == "yes") {
-
-        if (is_dir('custom/' . $_SESSION['custom_override_id'] . '/modules/templates/templates/styles')) {
-            $dir = 'custom/' . $_SESSION['custom_override_id'] . '/modules/templates/templates/styles';
-        } else {
-            $dir = 'modules/templates/templates/styles/';
-        }
-    
-        $fileNameOnTmp = $filename . '.' . strtolower(
-            $templatesControler->extractFileExt($_REQUEST['fileName'])
-            );
-        $filePathOnTmp = $dir . DIRECTORY_SEPARATOR . $fileNameOnTmp;
-        $inF = fopen($filePathOnTmp, 'w');
-        fwrite($inF, $fileContent);
-        fclose($inF);
-    }
-    
-    $fileNameOnTmp ='cm_tmp_file_' . $_SESSION['user']['UserId'] . '_' . rand() . '.' . strtolower(
-        $templatesControler->extractFileExt($_REQUEST['fileName'])
-        );
-    $filePathOnTmp = $_SESSION['config']['tmppath'] . DIRECTORY_SEPARATOR . $fileNameOnTmp;
-    $inF = fopen($filePathOnTmp, 'w');
-    fwrite($inF, $fileContent);
-    fclose($inF);
-    $_SESSION['m_admin']['templates']['current_style'] = $filePathOnTmp;
-    $_SESSION['m_admin']['templates']['template_style'] = $filename;
-    echo "{\"status\" : 0}";
-} else {
-    echo "{\"status\" : 1}";
-}
-exit;
diff --git a/modules/templates/change_template_style.php b/modules/templates/change_template_style.php
deleted file mode 100755
index 2cd11e60a45038c556f59d775002a594662795ff..0000000000000000000000000000000000000000
--- a/modules/templates/change_template_style.php
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php 
-if (isset($_REQUEST['template_style']) && !empty($_REQUEST['template_style'])) {
-    for (
-        $cptStyle = 0;
-        $cptStyle < count($_SESSION['m_admin']['templatesStyles']);
-        $cptStyle ++
-    ) {
-        if (
-            $_SESSION['m_admin']['templatesStyles'][$cptStyle]['fileExt'] 
-            . ': ' . $_SESSION['m_admin']['templatesStyles'][$cptStyle]['fileName']
-            == $_REQUEST['template_style']
-        ) {
-            $_SESSION['m_admin']['templates']['current_style'] 
-                = $_SESSION['m_admin']['templatesStyles'][$cptStyle]['filePath'];
-            $_SESSION['m_admin']['templates']['template_style'] = $_REQUEST['template_style'];
-        }
-    }
-    
-    echo "{status : 0, " . $_SESSION['m_admin']['templates']['current_style'] . "}";
-    exit();
-} else {
-    echo "{status : 1}";
-}
-exit;
diff --git a/modules/templates/choose_template.php b/modules/templates/choose_template.php
deleted file mode 100755
index 121fe270ad333d15515e34c9fb54b318f9f816a2..0000000000000000000000000000000000000000
--- a/modules/templates/choose_template.php
+++ /dev/null
@@ -1,132 +0,0 @@
-<?php
-
-/*
-*   Copyright 2008-2012 Maarch
-*
-*   This file is part of Maarch Framework.
-*
-*   Maarch Framework 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 3 of the License, or
-*   (at your option) any later version.
-*
-*   Maarch Framework 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 Maarch Framework.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/**
-* File : choose_template.php
-*
-* Pop up to choose a document template for an answer in the process
-*
-* @since 10/2007
-* @license GPL
-* @author  Claire Figueras  <dev@maarch.org>
-*/
-$core_tools = new core_tools();
-$core_tools->test_user();
-$core_tools->load_lang();
-require_once 'modules/templates/templates_tables_definition.php';
-
-if (isset($_REQUEST['template']) && !empty($_REQUEST['template'])) {
-    require_once('core/class/class_security.php');
-    $sec = new security();
-    $objectTable = $sec->retrieve_table_from_coll($_REQUEST['coll_id']);
-    require_once('modules/templates/class/templates_controler.php');
-    $templates_controler = new templates_controler();
-    $template = $templates_controler->get($_REQUEST['template']);
-    if ($template->template_type == 'HTML') {
-        header(
-            'location: ' . $_SESSION['config']['businessappurl'] 
-            . 'index.php?display=true&module=templates&page=generate_attachment_html&mode=add&template=' 
-            . $_REQUEST['template'] . '&res_id=' . $_REQUEST['res_id'] 
-            . '&coll_id=' . $_REQUEST['coll_id']
-        );
-    } else {
-         header(
-            'location: ' . $_SESSION['config']['coreurl']
-            . 'modules/content_management/applet_launcher.php?objectType=attachmentFromTemplate' 
-            . '&objectId=' . $_REQUEST['template'] . '&objectTable=' . $objectTable
-            . '&resMaster=' . $_REQUEST['res_id']
-        );
-    }
-    exit();
-}
-
-$db = new Database();
-
-$stmt = $db->query(
-    "select * from " 
-    . _TEMPLATES_TABLE_NAME . " t, " 
-    . _TEMPLATES_ASSOCIATION_TABLE_NAME . " ta where "
-    . "t.template_id = ta.template_id and ta.value_field = ? ", array($_REQUEST['entity'])
-);
-
-
-$templates = array();
-
-while($res = $stmt->fetchObject())
-{
-    array_push(
-        $templates, array(
-            'ID' => $res->template_id, 
-            'LABEL' => $res->template_label,
-            'TYPE' => $res->template_type,
-        )
-    );
-}
-
-$core_tools->load_html();
-$time = $core_tools->get_session_time_expire();
-//here we building the header
-$core_tools->load_header(_CHOOSE_TEMPLATE, true, false);
-
-?>
-<body id="pop_up"  onload="setTimeout(window.close, <?php echo $time;?>*60*1000);">
-<h2 class="tit"><?php echo _CHOOSE_TEMPLATE;?> </h2>
-<div align="center"><b><?php functions::xecho($erreur);?></b></div>
-<form enctype="multipart/form-data" method="post" name="attachment" action="<?php 
-    echo $_SESSION['config']['businessappurl'];
-    ?>index.php?display=true&module=templates&page=choose_template">
-    <input type="hidden" name="display"  value="true" />
-    <input type="hidden" name="module"  value="templates" />
-    <input type="hidden" name="page"  value="choose_template" />
-    <input type="hidden" name="res_id" id="res_id" value="<?php 
-        functions::xecho($_REQUEST['res_id']);
-        ?>" />
-    <input type="hidden" name="coll_id" id="coll_id" value="<?php 
-        functions::xecho($_REQUEST['coll_id']);
-        ?>" />
-    <p><label><?php echo _PLEASE_SELECT_TEMPLATE;?> :</label></p>
-    <br/>
-    <p>
-        <select name="template" id="template" style="width:150px" onchange="this.form.submit();">
-            <option value=""></option>
-            <?php
-                for ($i=0;$i<count($templates);$i++) {
-                    ?>
-                        <option value="<?php 
-                            functions::xecho($templates[$i]['ID']);
-                            ?>"><?php 
-                            functions::xecho($templates[$i]['TYPE'] . ' : ' 
-                            . $templates[$i]['LABEL']);
-                        ?></option>
-                    <?php
-                }
-            ?>
-        </select>
-    </p>
-    <br/>
-    <p class="buttons">
-    <input type="button" value="<?php 
-        echo _CANCEL;
-        ?>" name="cancel" class="button"  onclick="self.close();"/>
-</form>
-<?php $core_tools->load_js();?>
-</body>
-</html>
diff --git a/modules/templates/generate_attachment_html.php b/modules/templates/generate_attachment_html.php
deleted file mode 100755
index 6d9e7099d0e583f1fb4556ea2bf51d5ea5298528..0000000000000000000000000000000000000000
--- a/modules/templates/generate_attachment_html.php
+++ /dev/null
@@ -1,183 +0,0 @@
-<?php
-/*
-*   Copyright 2008-2015 Maarch
-*
-*   This file is part of Maarch Framework.
-*
-*   Maarch Framework 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 3 of the License, or
-*   (at your option) any later version.
-*
-*   Maarch Framework 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 Maarch Framework.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/**
- * File : generate_attachment_html.php.
- *
- * Form to generate an attachment to a mail with an existing template
- *
- * @since 10/2007
- *
- * @license GPL
- * @author  Claire Figueras <dev@maarch.org>
- * @author  Laurent Giovannoni <dev@maarch.org>
- */
-//require_once('modules/templates/class/class_modules_tools.php');
-require_once 'modules/templates/class/templates_controler.php';
-require_once 'modules/templates/templates_tables_definition.php';
-require_once 'core/class/class_security.php';
-$core_tools = new core_tools();
-$core_tools->test_user();
-$core_tools->load_lang();
-$db = new Database();
-$templates_controler = new templates_controler();
-$answer = array();
-$answer['TITLE'] = '';
-$answer['CONTENT'] = '';
-$answer['TEMPLATE_ID'] = '';
-$id = '';
-$res_id = '';
-$coll_id = '';
-
-$func = new functions();
-
-if (isset($_REQUEST['coll_id']) && !empty($_REQUEST['coll_id'])) {
-    $coll_id = $_REQUEST['coll_id'];
-}
-if (isset($_REQUEST['res_id']) && !empty($_REQUEST['res_id'])) {
-    $res_id = $_REQUEST['res_id'];
-}
-if (isset($_REQUEST['mode']) && !empty($_REQUEST['mode'])) {
-    $mode = $_REQUEST['mode'];
-} else {
-    $mode = '';
-    $_SESSION['error'] .= _NO_MODE_DEFINED.'.<br/>';
-}
-if (isset($_GET['template']) && !empty($_GET['template'])) {
-    $answer['TEMPLATE_ID'] = trim($_GET['template']);
-}
-if (isset($_GET['id']) && !empty($_GET['id'])) {
-    $id = trim($_GET['id']);
-    $stmt = $db->query('select title from '
-        .$_SESSION['tablename']['attach_res_attachments']
-        .' where res_id = ? ', array($id));
-    $res = $stmt->fetchObject();
-    $answer['TITLE'] = $func->show_string($res->title);
-}
-if (!empty($answer['TEMPLATE_ID']) && $mode == 'add') {
-    $template = $templates_controler->get($answer['TEMPLATE_ID']);
-
-    if ($template->template_id == '') {
-        $_SESSION['error'] .= _TEMPLATE.' '._UNKNOWN.'<br/>';
-    } else {
-        $line = $stmt->fetchObject();
-        $answer['TEMPLATE_ID'] = $template->template_id;
-        $answer['MODEL_LABEL'] = $func->show_string($template->template_label);
-        $answer['TITLE'] = $_SESSION['courrier']['res_id'].'_'
-            .$answer['MODEL_LABEL'].'_'.date('dmY');
-
-        $sec = new security();
-        $res_view = $sec->retrieve_view_from_coll_id($coll_id);
-        $params = array(
-            'res_id' => $res_id,
-            'coll_id' => $coll_id,
-            'res_view' => $res_view,
-        );
-
-        $answer['CONTENT'] = $templates_controler->merge($template->template_id, $params, 'content');
-    }
-} elseif (!empty($id) && $mode == 'up') {
-    $stmt = $db->query('select title, res_id, path, docserver_id, filename from '
-        .$_SESSION['tablename']['attach_res_attachments'].' where res_id = ? ', array($id));
-
-    if ($stmt->rowCount() < 1) {
-        $_SESSION['error'] .= _FILE.' '._UNKNOWN.'.<br/>';
-    } else {
-        $line = $stmt->fetchObject();
-        $docserver = $line->docserver_id;
-        $path = $line->path;
-        $filename = $line->filename;
-        $answer['TITLE'] = $func->show_string($line->title);
-        $stmt = $db->query('select path_template from '.$_SESSION['tablename']['docservers']
-            .' where docserver_id = ?', array($docserver));
-        $line_doc = $stmt->fetchObject();
-        $docserver = $line_doc->path_template;
-        $file = $docserver.$path.strtolower($filename);
-        $file = str_replace('#', DIRECTORY_SEPARATOR, $file);
-        $myfile = fopen($file, 'r');
-        $data = fread($myfile, filesize($file));
-        fclose($myfile);
-        $answer['CONTENT'] = $func->show_string($data);
-    }
-} else {
-    $_SESSION['error'] .= _TEMPLATE_OR_ANSWER_ERROR.'.<br/>';
-}
-$core_tools->load_html();
-$time = $core_tools->get_session_time_expire();
-//here we building the header
-if ($_REQUEST['mode'] == 'add') {
-    $title = _GENERATE_ANSWER.' : '.$answer['TITLE'];
-} elseif ($_REQUEST['mode'] == 'up') {
-    $title = _ANSWER.' : '.$answer['TITLE'];
-} else {
-    $title = _GENERATE_ANSWER;
-}
-$core_tools->load_header($title, true, false);
-?>
-<body onload="moveTo(0,0);resizeTo(screen.width, screen.height);setTimeout(window.close, <?php 
-    echo $time; ?>*60*1000);">
-<?php
-$_SESSION['mode_editor'] = false;
-$height = '400';
-include 'modules/templates/load_editor.php'; ?>
-<div class="error"><?php functions::xecho($_SESSION['error']); $_SESSION['error'] = ''; ?></div>
-<div align="center">
-    <form name="frmtemplate" id="frmtemplate" method="post" action="<?php 
-        echo $_SESSION['config']['businessappurl'];
-        ?>index.php?display=true&module=templates&page=manage_generated_attachment&mode=<?php 
-        echo $mode; ?>">
-    <input type="hidden" name="display" value="true" />
-    <input type="hidden" name="module" value="templates" />
-    <input type="hidden" name="page" value="manage_generated_attachment" />
-    <?php
-    if ($mode == 'up') {
-        ?>
-        <input type="hidden" name="id" id="id" value="<?php functions::xecho($id); ?>" />
-        <?php
-    }
-    ?>
-    <input type="hidden" name="res_id" id="res_id" value="<?php 
-        functions::xecho($res_id); ?>" />
-    <input type="hidden" name="coll_id" id="coll_id" value="<?php 
-        functions::xecho($coll_id); ?>" />
-    <input type="hidden" name="template_id" id="template_id" value="<?php 
-        functions::xecho($answer['TEMPLATE_ID']); ?>" />
-    <input type="hidden" name="template_label" id="template_label" value="<?php 
-        functions::xecho($answer['MODEL_LABEL']); ?>" />
-     <textarea name="template_content" style="width:100%" rows="50">
-        <?php functions::xecho($answer['CONTENT']); ?>
-    </textarea>
-    <br/>
-    <p>
-        <label><?php echo _ANSWER_TITLE; ?> :</label>
-        <input type="text" name="answer_title" id="answer_title" value="<?php 
-            functions::xecho($answer['TITLE']); ?>" style="width: 250px;" />
-    </p>
-    <p>
-    <input type="submit" name="submit" id="submit" value="<?php 
-        echo _VALIDATE; ?>" class="button"/>
-    <input type="button" name="cancel" id="cancel" value="<?php 
-        echo _CANCEL;?>" class="button" onclick="window.close();" />
-    </p>
-    </form>
-</div>
-<?php $core_tools->load_js();?>
-</body>
-</html>
diff --git a/modules/templates/js/functions.js b/modules/templates/js/functions.js
index ae99d402b17237a0bc732e14accd7bf30fce4f56..0ea0ba1e280bcf2a61f37a5a49785ead5b1739f7 100755
--- a/modules/templates/js/functions.js
+++ b/modules/templates/js/functions.js
@@ -12,79 +12,6 @@ function show_templates(show)
     }
 }
 
-function show_special_form(elem_to_view, elem_to_hide1)
-{
-    var elem_1 = window.document.getElementById(elem_to_view);
-    var elem_2 = window.document.getElementById(elem_to_hide1);
-    if (elem_1 != null) {
-        elem_1.style.display = "block";
-    }
-    if (elem_2 != null) {
-        elem_2.style.display = "none";
-    }
-}
-
-function show_special_form_3_elements(elem_to_view, elem_to_hide1, elem_to_hide2)
-{
-    var elem_0 = window.document.getElementById(elem_to_view);
-    var elem_1 = window.document.getElementById(elem_to_hide1);
-    var elem_2 = window.document.getElementById(elem_to_hide2);
-    if (elem_0 != null) {
-        elem_0.style.display = "block";
-    }
-    if (elem_1 != null) {
-        elem_1.style.display = "none";
-    }
-    if (elem_2 != null) {
-        elem_2.style.display = "none";
-    }
-}
-
-function changeStyle(style_id, path_to_script) 
-{
-    //window.alert(path_to_script);
-    new Ajax.Request(path_to_script,
-    {
-        method:'post',
-        parameters: {template_style: style_id.value},
-        onSuccess: function(answer){
-            eval("response = "+answer.responseText)
-        },
-        onFailure: function() {
-            $('modal').innerHTML = '<div class="error"><?php echo _SERVER_ERROR;?></div>'+form_txt;
-            form.query_name.value = this.name;
-        }
-    });
-}
-
-function setradiobutton(target)
-{
-    $j("#html,#office,#txt,#span_html,#span_office,#span_txt").css({"display":"inline"});
-    $j("#template_attachment_type_tr").hide();
-
-    if(target=="notes") {
-        $j("#html,#span_html,#office,#span_office").hide();
-        $j("#txt").click();
-    }else if(target=="sendmail") {
-        $j("#office,#span_office").hide();
-        $j("#html").click();
-    } else if(target=="notifications") {
-        $j("#txt,#span_txt,#office,#span_office").hide();
-        $j("#html").click();
-    } else if (target=="attachments"){
-        $j("#txt,#span_txt,#html,#span_html").hide();
-        $j("#office").click();
-        $j("#template_attachment_type_tr").css({"display":"inline"});
-    } else if(target=="doctypes") {
-        $j("#txt,#span_txt,#office,#span_office").hide();
-        $j("#html").click();
-    }
-
-    if (target != "attachments") {
-    	$j("#template_attachment_type").selectedIndex="0";
-    }
-}
-
 function select_template(path_to_script, attachment_type)
 {
     
@@ -129,43 +56,3 @@ function select_template(path_to_script, attachment_type)
         }
     });
 }
-
-function addTemplateBase(file)
-{
-    // if (confirm('En cliquant sur ok, le modèle sera ajouté dans la liste des natures de modèle.')) {
-    //     saveTemplateBase = "yes";
-    // }else{
-        saveTemplateBase = "no";
-    // }
-    var reader = new FileReader();
-    reader.readAsDataURL(file.files[0]);
-    reader.onload = function () {
-      base64File = reader.result.replace(/^[^,]*,/, '');
-      $j.ajax({
-        url: 'index.php?display=true&module=templates&page=addTemplateBase',
-        type: 'POST',
-        dataType: 'JSON',
-        data: {
-            fileName: file.files[0].name,
-            fileMimeType : file.files[0].type,
-            fileContent: base64File,
-            saveTemplateBase : saveTemplateBase,
-        },
-        success: function (response) {
-            if (response.status == 0) {
-                $j('#template_style').hide();
-                $j('#addTemplate').val(file.files[0].name);
-                $j('#addTemplate').show();
-                $j('#templateEditTr').hide();
-            } else {
-                alert(response.error_txt);
-            }
-        },
-        error: function (error) {
-            console.log(error);
-            alert(error);
-        }
-
-    });
-    };
-}
\ No newline at end of file
diff --git a/modules/templates/manage_generated_attachment.php b/modules/templates/manage_generated_attachment.php
deleted file mode 100755
index c410c563c6536cd0fc7ff7e0459302f5f34396d2..0000000000000000000000000000000000000000
--- a/modules/templates/manage_generated_attachment.php
+++ /dev/null
@@ -1,192 +0,0 @@
-<?php
-/**
-* File : manage_generated_attachment.php
-*
-* Result of the generate answer form
-*
-* @package Maarch LetterBox 2.3
-* @version 1.0
-* @since 10/2007
-* @license GPL
-* @author  Claire Figueras  <dev@maarch.org>
-*/
-
-/*require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_request.php");
-require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_resource.php");
-require_once "core/class/class_security.php";
-
-$core_tools = new core_tools();
-$core_tools->test_user();
-$core_tools->load_lang();
-$func = new functions();
-if (empty($_REQUEST['mode']) || !isset($_REQUEST['mode'])) {
-    $_SESSION['error'] .= _NO_MODE_DEFINED.'.<br/>';
-    header("location: ".$_SESSION['config']['businessappurl']."index.php?display=true&module=templates&page=generate_attachment_html&template=".$_REQUEST['template_id']);
-    exit;
-} else {
-    $conn = new Database();
-    if (empty($_REQUEST['template_content']) || !isset($_REQUEST['template_content'])) {
-        $_SESSION['error'] .= _NO_CONTENT.'.<br/>';
-        if ($_REQUEST['mode'] == 'add') {
-            header("location: ".$_SESSION['config']['businessappurl']."index.php?display=true&module=templates&page=generate_attachment_html&template=".$_REQUEST['template_id']."&mode=".$_REQUEST['mode']);
-        } else {
-            header("location: ".$_SESSION['config']['businessappurl']."index.php?display=true&module=templates&page=generate_attachment_html&id=".$_REQUEST['id']."&mode=".$_REQUEST['mode']);
-        }
-        exit;
-    } else {
-        if ($_REQUEST['mode'] == "add") {
-            if (empty($_REQUEST['answer_title']) || !isset($_REQUEST['answer_title'])) {
-                $_REQUEST['answer_title'] = $_SESSION['courrier']['res_id']."_".$_REQUEST['template_label'].date("dmY");
-            }
-            $_REQUEST['answer_title'] = str_replace("\\", "", $_REQUEST['answer_title']);
-            $_REQUEST['answer_title'] = str_replace("/", "", $_REQUEST['answer_title']);
-            $_REQUEST['answer_title'] = str_replace("..", "", $_REQUEST['answer_title']);
-            $path_tmp = $_SESSION['config']['tmppath'].DIRECTORY_SEPARATOR.$_REQUEST['answer_title'].".maarch";
-            $myfile = fopen($path_tmp, "w");
-            if (!$myfile) {
-                $_SESSION['error'] .= _FILE_OPEN_ERROR.'.<br/>';
-                header("location: ".$_SESSION['config']['businessappurl']."index.php?display=true&module=templates&page=generate_attachment_html&template=".$_REQUEST['template_id']);
-                exit;
-            }
-            fwrite($myfile, $_REQUEST['template_content']);
-            fclose($myfile);            
-            //DOCSERVER
-            if (!isset($_SESSION['collection_id_choice']) 
-                || empty($_SESSION['collection_id_choice'])
-            ) {
-                $_SESSION['collection_id_choice'] 
-                    = $_SESSION['user']['collections'][0];
-            }
-            $tmpPath = $path_tmp;
-            $fileSize = filesize($tmpPath);
-            require_once('core' . DIRECTORY_SEPARATOR . 'class' 
-                . DIRECTORY_SEPARATOR . 'docservers_controler.php');
-            $docserverControler = new docservers_controler();
-            $fileInfos = array(
-                "tmpDir"      => $_SESSION['config']['tmppath'],
-                "size"        => $fileSize,
-                "format"      => 'maarch',
-                "tmpFileName" => $_REQUEST['answer_title'] . '.maarch',
-            );
-            $storeResult = array();
-            $storeResult = $docserverControler->storeResourceOnDocserver(
-                $_SESSION['collection_id_choice'], $fileInfos
-            );
-            if (isset($storeResult['error']) && $storeResult['error'] <> "") {
-                $_SESSION['error'] = $storeResult['error'];
-                
-            } else {
-                $pathTemplate = $storeResult['path_template'];
-                $destinationDir = $storeResult['destination_dir'];
-                $docserverId = $storeResult['docserver_id'];
-                $fileDestinationName = $storeResult['file_destination_name'];
-            }
-            //INDEXING
-            $res_attach = new resource();
-            $_SESSION['data'] = array();
-            array_push($_SESSION['data'], array('column' => "typist", 'value' => $_SESSION['user']['UserId'], 'type' => "string"));
-            array_push($_SESSION['data'], array('column' => "format", 'value' => 'maarch', 'type' => "string"));
-            array_push($_SESSION['data'], array('column' => "docserver_id", 'value' => $docserverId, 'type' => "string"));
-            array_push($_SESSION['data'], array('column' => "status", 'value' => 'NEW', 'type' => "string"));
-            array_push($_SESSION['data'], array('column' => "offset_doc", 'value' => ' ', 'type' => "string"));
-            array_push($_SESSION['data'], array('column' => "logical_adr", 'value' => ' ', 'type' => "string"));
-            array_push($_SESSION['data'], array('column' => "title", 'value' => $_REQUEST['answer_title'], 'type' => "string"));
-            array_push($_SESSION['data'], array('column' => "coll_id", 'value' => $_SESSION['collection_id_choice'], 'type' => "string"));
-            array_push($_SESSION['data'], array('column' => "res_id_master", 'value' => $_SESSION['doc_id'], 'type' => "integer"));
-            array_push($_SESSION['data'], array('column' => "type_id", 'value' => 0, 'type' => "int"));
-            $id = $res_attach->load_into_db(
-                $_SESSION['tablename']['attach_res_attachments'],
-                $destinationDir,
-                $fileDestinationName,
-                $pathTemplate,
-                $docserverId,
-                $_SESSION['data'],
-                $_SESSION['config']['databasetype']
-            );
-            if ($id == false) {
-                $_SESSION['error'] = $res_attach->get_error();
-                header("location: ".$_SESSION['config']['businessappurl']."index.php?display=true&module=templates&page=generate_attachment_html&template=".$_REQUEST['template_id']."&mode=".$_REQUEST['mode']);
-                exit();
-            } else {
-                if ($_SESSION['history']['attachadd'] == "true") {
-                    require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_history.php");
-                    $hist = new history();
-                    //$_SESSION['error'] = _NEW_ATTACH_ADDED;
-                    $hist->add($_SESSION['tablename']['attach_res_attachments'], $id, "ADD", 'attachadd', _NEW_ATTACH_ADDED." (".$_REQUEST['answer_title'].") ", $_SESSION['config']['databasetype'],'attachments');
-                    $sec = new security();
-                    $view = $sec->retrieve_view_from_coll_id($_SESSION['collection_id_choice']);
-                    $hist->add($view, $_SESSION['doc_id'], "ADD", 'attachadd', ucfirst(_DOC_NUM) . $id . ' ' . _NEW_ATTACH_ADDED . ' ' . _TO_MASTER_DOCUMENT . $_SESSION['doc_id'], $_SESSION['config']['databasetype'], 'apps');
-                }
-            }
-            if (empty($_SESSION['error']) || $_SESSION['error'] == _NEW_ATTACH_ADDED) {
-                ?>
-                <script type="text/javascript">
-                    var eleframe1 =  window.opener.top.document.getElementById('list_attach');
-                    eleframe1.src = '<?php echo $_SESSION['config']['businessappurl'];?>index.php?display=true&module=attachments&page=frame_list_attachments';
-                    window.top.close();
-                </script>
-                <?php
-                exit();
-            }
-        } else {
-            //mode = up 
-            if (empty($_REQUEST['id']) || !isset($_REQUEST['id'])) {
-                $_SESSION['error'] .= _ANSWER_OPEN_ERROR.'.<br/>';
-                header("location: ".$_SESSION['config']['businessappurl']."index.php?display=true&module=templates&page=generate_attachment_html&template=".$_REQUEST['template_id']);
-                exit;
-            } else {
-                $stmt = $conn->query("select docserver_id, path, filename from ".$_SESSION['tablename']['attach_res_attachments']." where res_id = ? ", 
-									array($_REQUEST['id'])
-						);
-                if ($stmt->rowCount() == 0) {
-                    $_SESSION['error'] = _NO_DOC_OR_NO_RIGHTS."...";
-                    ?>
-                    <script  type="text/javascript">
-                        var eleframe1 =  window.opener.top.frames['process_frame'].document.getElementById('list_attach');
-                        eleframe1.src = '<?php echo $_SESSION['config']['businessappurl'];?>index.php?display=true&module=attachments&page=frame_list_attachments';
-                        window.top.close();
-                    </script>
-                    <?php
-                    exit;
-                } else {
-                    $line = $stmt->fetchObject();
-                    $docserver = $line->docserver_id;
-                    $path = $line->path;
-                    $filename = $line->filename;
-                    $stmt = $conn->query("select path_template from ".$_SESSION['tablename']['docservers']." where docserver_id = ? ", 
-									array($docserver)
-								);
-                    $line_doc = $stmt->fetchObject();
-                    $docserver = $line_doc->path_template;
-                    $file = $docserver.$path.strtolower($filename);
-                    $file = str_replace("#",DIRECTORY_SEPARATOR,$file);
-                    $myfile = fopen($file, "w");
-                    if (!$myfile) {
-                        $_SESSION['error'] .= _FILE_OPEN_ERROR.'.<br/>';
-                        header("location: ".$_SESSION['config']['businessappurl']."index.php?display=true&module=templates&page=generate_attachment_html&id=".$_REQUEST['id']);
-                        exit;
-                    }
-                    fwrite($myfile, $_REQUEST['template_content']);
-                    fclose($myfile);
-                    $stmt = $conn->query("update ".$_SESSION['tablename']['attach_res_attachments']." set title = ? where res_id = ? ", 
-									array($_REQUEST['answer_title'], $_REQUEST['id'])
-									);
-                    if ($_SESSION['history']['attachup'] == "true") {
-                        require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_history.php");
-                        $hist = new history();
-                        $hist->add($_SESSION['tablename']['attach_res_attachments'], $_SESSION['courrier']['res_id'],"UP", 'attachup', _ANSWER_UPDATED."  (".$_SESSION['courrier']['res_id'].")", $_SESSION['config']['databasetype'],'attachments');
-
-                    }
-                    ?>
-                    <script  type="text/javascript">
-                        var eleframe1 =  window.opener.top.document.getElementById('list_attach');
-                        eleframe1.src = '<?php echo $_SESSION['config']['businessappurl'];?>index.php?display=true&module=attachments&page=frame_list_attachments';
-                        window.top.close();
-                    </script>
-                    <?php
-                    exit();
-                }
-            }
-        }
-    }
-}*/
diff --git a/modules/templates/templates_list_by_label.php b/modules/templates/templates_list_by_label.php
deleted file mode 100755
index 2c65d56030d94b80a5f0e06c578a4e8d098b2bbc..0000000000000000000000000000000000000000
--- a/modules/templates/templates_list_by_label.php
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-
-/*
-*   Copyright 2008-2012 Maarch
-*
-*   This file is part of Maarch Framework.
-*
-*   Maarch Framework 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 3 of the License, or
-*   (at your option) any later version.
-*
-*   Maarch Framework 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 Maarch Framework.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/**
-* @brief List of templates for autocompletion
-*
-*
-* @file
-* @author  Laurent Giovannoni <dev@maarch.org>
-* @date $date$
-* @version $Revision$
-* @ingroup templates
-*/
-require_once 'modules/templates/templates_tables_definition.php';
-require_once 'core/admin_tools.php';
-$db = new Database();
-if ($_SESSION['config']['databasetype'] == 'POSTGRESQL') {
-	
-    $stmt = $db->query("select template_label as tag from " 
-               . _TEMPLATES_TABLE_NAME . " where template_label ilike ? order by template_label", 
-               array('%' . $_REQUEST['what'].'%')
-            );
-} else {
-    $stmt = $db->query("select template_label as tag from " 
-               . _TEMPLATES_TABLE_NAME . " where template_label like ? order by template_label",
-               array($_REQUEST['what'] . '%')
-            );
-}
-At_showAjaxList($stmt, $_REQUEST['what']);
diff --git a/modules/templates/templates_management.php b/modules/templates/templates_management.php
deleted file mode 100755
index 2413aa16ef11c1d4cb435e77aebead04f5b05ef7..0000000000000000000000000000000000000000
--- a/modules/templates/templates_management.php
+++ /dev/null
@@ -1,420 +0,0 @@
-<?php
-/* View */
-$func = new functions();
-if ($mode == 'list') {
-    $listShow = new list_show();
-    $listShow->admin_list(
-        $templates_list['tab'],
-        count($templates_list['tab']),
-        $templates_list['title'],
-        'template_id',
-        'templates_management_controler&mode=list',
-        'templates', 'template_id',
-        true,
-        $templates_list['page_name_up'],
-        '',
-        '',
-        $templates_list['page_name_del'],
-        $templates_list['page_name_add'],
-        $templates_list['label_add'],
-        false,
-        false,
-        _ALL_TEMPLATES,
-        _TEMPLATES,
-        'file-alt',
-        true,
-        true,
-        false,
-        true,
-        $templates_list['what'],
-        true,
-        $templates_list['autoCompletionArray']
-    );
-} elseif ($mode == 'up' || $mode == 'add') {
-    $height = '400';
-    include 'modules/templates/load_editor.php'; ?>
-    <h1><i class="fa fa-file-alt fa-2x"></i>
-        <?php
-        if ($mode == 'add') {
-            echo _TEMPLATE_ADDITION;
-        } elseif ($mode == 'up') {
-            echo _TEMPLATE_UPDATE;
-        } ?>
-    </h1>
-    <div id="inner_content" class="clearfix" align="center">
-        <br/><br/>
-        <?php
-        if ($state == false) {
-            echo '<br /><br />'._THE_TEMPLATE.' '._UNKOWN
-                .'<br /><br /><br /><br />';
-        } else {
-            ?>
-            <div class="error" id="divError" name="divError"></div>
-            <div class="block">
-            <form id="adminform" method="post" class="forms" style="width: 620px;" action="<?php
-                echo $_SESSION['config']['businessappurl']
-                .'index.php?display=true&page=templates_management_controler&module=templates&mode='
-                .$mode; ?>">
-                <input type="hidden" name="display" value="true" />
-                <input type="hidden" name="module" value="templates" />
-                <input type="hidden" name="page" value="templates_management_controler" />
-                <input type="hidden" name="mode" id="mode" value="<?php functions::xecho($mode); ?>" />
-                <input type="hidden" name="order" id="order" value="<?php
-                    if (isset($_REQUEST['order'])) {
-                        functions::xecho($_REQUEST['order']);
-                    } ?>" />
-                <input type="hidden" name="order_field" id="order_field" value="<?php
-                    if (isset($_REQUEST['order_field'])) {
-                        functions::xecho($_REQUEST['order_field']);
-                    } ?>" />
-                <input type="hidden" name="what" id="what" value="<?php
-                    if (isset($_REQUEST['what'])) {
-                        functions::xecho($_REQUEST['what']);
-                    } ?>" />
-                <input type="hidden" name="start" id="start" value="<?php
-                    if (isset($_REQUEST['start'])) {
-                        functions::xecho($_REQUEST['start']);
-                    } ?>" />
-                <?php
-                if (
-                    $mode == 'up'
-                    && $_SESSION['m_admin']['templates']['template_type'] == 'OFFICE'
-                ) {
-                    ?>
-                    <input type="hidden" name="template_path" id="template_path" value="<?php
-                        echo $_SESSION['m_admin']['templates']['template_path']; ?>" />
-                    <input type="hidden" name="template_file_name" id="template_file_name" value="<?php
-                        echo $_SESSION['m_admin']['templates']['template_file_name']; ?>" />
-                    <?php
-                }
-            if ($mode == 'up') {
-                ?>
-                    <p>
-                        <label for="id"><?php echo _TEMPLATE_ID; ?> : </label>
-                        <input name="id" type="text" id="id" value="<?php
-                            if (isset($_SESSION['m_admin']['templates']['template_id'])) {
-                                echo functions::xecho($func->show_str($_SESSION['m_admin']['templates']['template_id']));
-                            } ?>" readonly='readonly' class='readonly'/>
-                    </p>
-                    <?php
-            } ?>
-                <p>
-                    <label for="template_label"><?php echo _TEMPLATE_LABEL; ?> : </label>
-                    <input name="template_label" type="text" id="template_label" value="<?php
-                        if (isset($_SESSION['m_admin']['templates']['template_label'])) {
-                            functions::xecho($func->show_str($_SESSION['m_admin']['templates']['template_label']));
-                        } ?>" />
-                </p>
-                <p>
-                    <label for="template_comment"><?php echo _TEMPLATE_COMMENT; ?> : </label>
-                    <textarea name="template_comment" type="text"  id="template_comment" value="<?php
-                        if (isset($_SESSION['m_admin']['templates']['template_comment'])) {
-                            functions::xecho($func->show_str($_SESSION['m_admin']['templates']['template_comment']));
-                        } ?>" /><?php
-                        if (isset($_SESSION['m_admin']['templates']['template_comment'])) {
-                            functions::xecho($_SESSION['m_admin']['templates']['template_comment']);
-                        } ?></textarea>
-                </p>
-                <p>
-                    <label for="template_target"><?php echo _TEMPLATE_TARGET; ?> : </label>
-                    <select name="template_target" id="template_target" onchange="setradiobutton(this.options[this.selectedIndex].value);">
-                        <option value="" ><?php echo _NO_TARGET; ?></option>
-                        <?php
-                        for (
-                            $cptTarget = 0;
-                            $cptTarget < count($_SESSION['m_admin']['templatesTargets']);
-                            ++$cptTarget
-                        ) {
-                            ?>
-                            <option value="<?php functions::xecho($_SESSION['m_admin']['templatesTargets'][$cptTarget]['id']); ?>" <?php
-                            if (isset($_SESSION['m_admin']['templates']['template_target'])
-                                && $_SESSION['m_admin']['templates']['template_target'] == $_SESSION['m_admin']['templatesTargets'][$cptTarget]['id']
-                            ) {
-                                echo 'selected="selected"';
-                            } ?> ><?php
-                                functions::xecho($_SESSION['m_admin']['templatesTargets'][$cptTarget]['label']); ?></option><?php
-                        } ?>
-                    </select>
-                </p>
-                <div id="template_attachment_type_tr" style="display:none">
-                <p>
-                    <label for="template_attachment_type"><?php echo _ATTACHMENT_TYPES; ?> : </label>
-                    <select name="template_attachment_type" id="template_attachment_type">
-                        <option value="all" ><?php echo _ALL_ATTACHMENT_TYPES; ?></option>
-                        <?php
-                            foreach (array_keys($_SESSION['attachment_types']) as $attachmentType) {
-                                ?><option value="<?php functions::xecho($attachmentType); ?>" <?php
-
-                                if (isset($_SESSION['m_admin']['templates']['template_attachment_type'])
-                                    &&
-                                    $_SESSION['m_admin']['templates']['template_attachment_type'] == $attachmentType
-                                ) {
-                                    echo 'selected="selected"';
-                                } ?> >
-                                    <?php functions::xecho($_SESSION['attachment_types'][$attachmentType]); ?>
-                                </option>
-                            <?php
-                            } ?>
-                    </select>
-                </p>
-                </div>
-                <p>
-                    <label><?php echo _TEMPLATE_TYPE; ?> :</label>
-                    <input type="radio" name="template_type" value="OFFICE" id="office"
-                        onClick="javascript:show_special_form_3_elements('office_div', 'html_div', 'txt_div');" <?php
-                        echo $checkedOFFICE; ?>/> <span id="span_office"><?php echo _OFFICE; ?></span>
-                    <input type="radio" name="template_type" value="HTML" id="html"
-                        onClick="javascript:show_special_form_3_elements('html_div', 'office_div', 'txt_div');" <?php
-                        echo $checkedHTML; ?>/> <span id="span_html"><?php echo _HTML; ?></span>
-                    <input type="radio" name="template_type" value="TXT" id="txt"
-                        onClick="javascript:show_special_form_3_elements('txt_div', 'html_div', 'office_div');" <?php
-                        echo $checkedTXT; ?>/> <span id="span_txt"><?php echo _TXT; ?></span>
-                </p>
-                <script>setradiobutton($j("#template_target").val());</script>
-                <p>
-                    <label for="template_datasource"><?php echo _TEMPLATE_DATASOURCE; ?> : </label>
-                    <select name="template_datasource" id="template_datasource">
-                        <option value="" ><?php echo _NO_DATASOURCE; ?></option>
-                        <?php
-                        for (
-                            $cptDatasource = 0;
-                            $cptDatasource < count($_SESSION['m_admin']['templatesDatasources']);
-                            ++$cptDatasource
-                        ) {
-                            ?>
-                            <option value="<?php functions::xecho($_SESSION['m_admin']['templatesDatasources'][$cptDatasource]['id']); ?>" <?php
-                            if (isset($_SESSION['m_admin']['templates']['template_datasource'])
-                                && $_SESSION['m_admin']['templates']['template_datasource'] == $_SESSION['m_admin']['templatesDatasources'][$cptDatasource]['id']
-                            ) {
-                                echo 'selected="selected"';
-                            } ?> ><?php
-                                functions::xecho($_SESSION['m_admin']['templatesDatasources'][$cptDatasource]['label']); ?></option><?php
-                        } ?>
-                    </select>
-                </p>
-                <div id="html_div" name="html_div">
-                    <p>
-                        <label for="template_content">
-                            <?php echo _TEMPLATE_CONTENT; ?> HTML :
-                        </label><br/><br/>
-                        <textarea name="template_content" style="width:100%" rows="15" cols="60" id="template_content" value="<?php
-                            if (isset($_SESSION['m_admin']['templates']['template_content'])) {
-                                echo $func->show_str($_SESSION['m_admin']['templates']['template_content']);
-                            } ?>" /><?php
-                            if (isset($_SESSION['m_admin']['templates']['template_content'])) {
-                                functions::xecho($_SESSION['m_admin']['templates']['template_content']);
-                            } ?></textarea>
-                    </p>
-                </div>
-                <div id="office_div" name="office_div">
-                    <p>
-                        <?php 
-                        echo '<label for="template_style">'._TEMPLATE_STYLE.' : ';
-            if ($mode == 'add') {
-                echo '<i id="template_style_icon" class="fa fa-paperclip fa-lg" title="'._LOADED_FILE.'" onclick="$j(\'#templateEditTr\').hide();$j(\'#addTemplateFile\').click();$(\'template_style_icon\').setStyle({color: \'#135F7F\'});$(\'template_style_icon2\').setStyle({color: \'#666\'});"></i> <i id="template_style_icon2" class="fa fa-file-alt fa-lg" title="'._GENERATED_FILE.'" onclick="$j(\'#templateEditTr\').show();$j(\'#template_style\').show();$j(\'#addTemplate\').hide();$(\'template_style_icon\').setStyle({color: \'#666\'});$(\'template_style_icon2\').setStyle({color: \'#135F7F\'});" style="color:#135F7F"></i>';
-            }
-            echo '</label>';
-            if ($mode == 'up') {
-                ?>
-                            <input name="template_style" type="text" id="template_style" value="<?php
-                                if (isset($_SESSION['m_admin']['templates']['template_style'])) {
-                                    functions::xecho($func->show_str($_SESSION['m_admin']['templates']['template_style']));
-                                } ?>" readonly='readonly' class='readonly' />
-                            <?php
-            } else {
-                ?>
-                            <input class="button" name="addTemplate" id="addTemplate" onclick="$j('#addTemplateFile').click();" style="display:none;" value="+" title="Importer une nature de modèle" type="button"/>
-                            <input id="addTemplateFile" type="file" onchange="addTemplateBase(this);" style="display:none;" accept="application/msword,application/vnd.openxmlformats-officedocument.wordprocessing‌​ml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml‌​.slideshow,application/vnd.oasis.opendocument.text,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.spreadsheet"/>
-                            <select name="template_style" id="template_style" onChange="javascript:changeStyle($('template_style'), '<?php
-                                echo $_SESSION['config']['businessappurl'].'index.php?display=false&module=templates&page=change_template_style'; ?>');">
-                                <?php
-                                // if user don't choose a style
-                                if (!isset($_SESSION['m_admin']['templates']['current_style'])) {
-                                    $_SESSION['m_admin']['templates']['current_style']
-                                        = $_SESSION['m_admin']['templatesStyles'][0]['filePath'];
-                                }
-                for (
-                                    $cptStyle = 0;
-                                    $cptStyle < count($_SESSION['m_admin']['templatesStyles']);
-                                    ++$cptStyle
-                                ) {
-                    ?>
-                                    <option value="<?php
-                                        functions::xecho($_SESSION['m_admin']['templatesStyles'][$cptStyle]['fileExt']);
-                    echo ': ';
-                    functions::xecho($_SESSION['m_admin']['templatesStyles'][$cptStyle]['fileName']); ?>" <?php
-                                    if (isset($_SESSION['m_admin']['templates']['template_style'])
-                                        && $_SESSION['m_admin']['templates']['template_style'] == $_SESSION['m_admin']['templatesStyles'][$cptStyle]['fileName']
-                                    ) {
-                                        echo 'selected="selected"';
-                                    } ?>><?php
-                                        functions::xecho($_SESSION['m_admin']['templatesStyles'][$cptStyle]['fileExt']);
-                    echo ': ';
-                    functions::xecho($_SESSION['m_admin']['templatesStyles'][$cptStyle]['fileName']); ?></option>
-                                    <?php
-                } ?>
-                            </select>
-                            <?php
-            } ?>
-                    </p>
-                    <?php
-                    if ($mode == 'add') {
-                        $objectType = 'templateStyle';
-                    } else {
-                        $objectType = 'template';
-                        $objectId = $_SESSION['m_admin']['templates']['template_id'];
-                    }
-            $objectTable = _TEMPLATES_TABLE_NAME; ?>
-                    <p>
-                        <span id="templateEditTr">
-                            <label><?php echo _EDIT_TEMPLATE; ?> :</label>
-                  
-                                <?php
-                                $strAction .= 'showAppletLauncher(this,\''.$objectId.'\',\''.$objectTable.'\',\''.$objectType.'\',\'template\', \'100px\', \'500px\');$(\'add\').value=\'Edition en cours ...\';editingDoc(\''.$_SESSION['user']['UserId'].'\');$(\'add\').disabled=\'disabled\';$(\'add\').style.opacity=\'0.5\';'; ?>
-                                <a href="#" onClick="<?php functions::xecho($strAction); ?>">
-                                
-                                    <i class="fa fa-pencil-alt fa-2x"></i>
-                                <?php echo _EDIT_TEMPLATE; ?>
-                            </a>
-                        </span>
-                        <?php if ($mode == 'up') {
-                                    ?>
-                        <a href="#" onclick="$j('#addTemplateFile').click();$('template_style_icon').setStyle({color: '#135F7F'})" style="margin-left:15px">
-                            <i id="template_style_icon" class="fa fa-paperclip fa-2x"></i> Importer un fichier
-                        </a>
-                        <input class="button" name="addTemplate" id="addTemplate" onclick="$j('#addTemplateFile').click();" style="display:none;margin-left:15px" value="+" type="button"/>
-                        <input id="addTemplateFile" type="file" onchange="addTemplateBase(this);" style="display:none;" accept="application/msword,application/vnd.openxmlformats-officedocument.wordprocessing‌​ml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml‌​.slideshow,application/vnd.oasis.opendocument.text,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.spreadsheet"/>
-                        <?php
-                                } ?>   
-                    </p>
-                </div>
-                <div id="txt_div" name="txt_div">
-                    <p>
-                        <label for="template_content_txt">
-                            <?php echo _TEMPLATE_CONTENT; ?> TXT :
-                        </label><br/><br/>
-                        <textarea name="template_content_txt" style="width:100%" rows="15" cols="60" id="template_content_txt" value="<?php
-                            if (isset($_SESSION['m_admin']['templates']['template_content'])) {
-                                functions::xecho($func->show_str($_SESSION['m_admin']['templates']['template_content']));
-                            } ?>" /><?php
-                            if (isset($_SESSION['m_admin']['templates']['template_content'])) {
-                                functions::xecho($_SESSION['m_admin']['templates']['template_content']);
-                            } ?></textarea>
-                    </p>
-                </div>
-                    <table align="center" width="100%" id="template_entities" >
-                    <tr>
-                        <td colspan="3"><?php echo _CHOOSE_ENTITY_TEMPLATE; ?> :</td>
-                    </tr>
-                    <tr>
-                        <td width="40%" align="center">
-                            <select name="entitieslist[]" id="entitieslist" size="7"
-                            ondblclick='moveclick($(entitieslist), $(entities_chosen));' multiple="multiple" >
-                            <?php
-                            for ($i = 0; $i < count($_SESSION['m_admin']['templatesEntitiesOrg']); ++$i) {
-                                $state_entity = false;
-                                for ($j = 0; $j < count($_SESSION['m_admin']['templatesEntities']['destination']); ++$j) {
-                                    if (
-                                        $_SESSION['m_admin']['templatesEntitiesOrg'][$i]->entity_id
-                                        == $_SESSION['m_admin']['templatesEntities']['destination'][$j]
-                                    ) {
-                                        $state_entity = true;
-                                    }
-                                }
-                                if ($state_entity == false) {
-                                    ?>
-                                    <option value="<?php
-                                        functions::xecho($_SESSION['m_admin']['templatesEntitiesOrg'][$i]->entity_id); ?>"><?php
-                                        functions::xecho($_SESSION['m_admin']['templatesEntitiesOrg'][$i]->entity_label); ?></option>
-                                    <?php
-                                }
-                            } ?>
-                            </select>
-                            <br/>
-                            <!--<em><a href='javascript:selectall($(entitieslist));'><?php
-                                echo _SELECT_ALL; ?></a></em>-->
-                        </td>
-                        <td width="20%" align="center">
-                            <input type="button" class="button" value="<?php
-
-                                ?> &gt;&gt;" onclick='Move($(entitieslist), $(entities_chosen));' />
-                            <br />
-                            <br />
-                            <input type="button" class="button" value="&lt;&lt; <?php
-
-                                ?>" onclick='Move($(entities_chosen), $(entitieslist));' />
-                        </td>
-                        <td width="40%" align="center">
-                            <select name="entities_chosen[]" id="entities_chosen" size="7"
-                            ondblclick='moveclick($(entities_chosen), $(entitieslist));' multiple="multiple">
-                            <?php
-                            for ($i = 0; $i < count($_SESSION['m_admin']['templatesEntitiesOrg']); ++$i) {
-                                $state_entity = false;
-                                for ($j = 0; $j < count($_SESSION['m_admin']['templatesEntities']['destination']); ++$j) {
-                                    if (
-                                        $_SESSION['m_admin']['templatesEntitiesOrg'][$i]->entity_id
-                                        == $_SESSION['m_admin']['templatesEntities']['destination'][$j]
-                                    ) {
-                                        $state_entity = true;
-                                    }
-                                }
-                                if ($state_entity == true) {
-                                    ?>
-                                    <option value="<?php
-                                        functions::xecho($_SESSION['m_admin']['templatesEntitiesOrg'][$i]->entity_id); ?>" selected="selected" ><?php
-                                        functions::xecho($_SESSION['m_admin']['templatesEntitiesOrg'][$i]->entity_label); ?></option>
-                                    <?php
-                                }
-                            } ?>
-                            </select>
-                            <br/>
-                            <!--<em><a href="javascript:selectall($(entities_chosen));" >
-                            <?php echo _SELECT_ALL; ?></a></em>-->
-                        </td>
-                    </tr>
-                </table>
-                <br/>
-                <p class="buttons">
-                    <?php
-                    if ($mode == 'up') {
-                        ?>
-                        <input class="button" type="button" id="duplicateTemplateButton" onclick="duplicateTemplate(<?php functions::xecho($_SESSION['m_admin']['templates']['template_id']); ?>)" value="Dupliquer" />
-                        <input class="button" type="submit" name="submit" id="add" onclick="selectall($('entities_chosen'));" value="<?php
-                            echo _MODIFY; ?>" />
-                        <?php
-                    } elseif ($mode == 'add') {
-                        ?>
-                        <input type="submit" class="button"  name="submit" id="add" onclick="selectall($('entities_chosen'));" value="<?php
-                            echo _ADD; ?>" />
-                        <?php
-                    } ?>
-                    <input type="button" class="button"  name="cancel" value="<?php
-                        echo _CANCEL; ?>" onclick="javascript:window.location.href='<?php
-                        echo $_SESSION['config']['businessappurl']; ?>index.php?page=templates_management_controler&amp;module=templates&amp;mode=list';"/>
-                </p>
-            </form>
-            </div>
-            <?php
-            if ($_SESSION['m_admin']['templates']['template_type'] == 'HTML') {
-                ?>
-                <script>
-                    show_special_form_3_elements('html_div', 'txt_div', 'office_div');
-                </script>
-                <?php
-            } elseif ($_SESSION['m_admin']['templates']['template_type'] == 'TXT') {
-                ?>
-                <script>
-                    show_special_form_3_elements('txt_div', 'office_div', 'html_div');
-                </script>
-                <?php
-            } else {
-                ?>
-                <script>
-                    show_special_form_3_elements('office_div', 'html_div', 'txt_div');
-                </script>
-                <?php
-            }
-        } ?>
-    </div>
-    <?php
-}
diff --git a/modules/templates/templates_management_controler.php b/modules/templates/templates_management_controler.php
deleted file mode 100755
index 0384e54c941ed76e679e2fba000f40483b661ea0..0000000000000000000000000000000000000000
--- a/modules/templates/templates_management_controler.php
+++ /dev/null
@@ -1,461 +0,0 @@
-<?php
-
-/*
-*   Copyright 2008-2012 Maarch
-*
-*   This file is part of Maarch Framework.
-*
-*   Maarch Framework 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 3 of the License, or
-*   (at your option) any later version.
-*
-*   Maarch Framework 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 Maarch Framework.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/**
-* @brief  Contains the template Object (herits of the BaseObject class)
-* 
-* 
-* @file
-* @author Laurent Giovannoni
-* @date $date$
-* @version $Revision$
-* @ingroup templates
-*/
-
-$sessionName = 'templates';
-$pageName = 'templates_management_controler';
-$tableName = 'templates';
-$idName = 'template_id';
-
-$mode = 'add';
-
-$core = new core_tools();
-$core->load_lang();
-
-$core->test_admin('admin_templates', 'templates');
-
-if (isset($_REQUEST['mode']) && !empty($_REQUEST['mode'])) {
-    $mode = $_REQUEST['mode'];
-} else {
-    $mode = 'list'; 
-}
-
-try{
-	
-    require_once('modules/templates/class/templates_controler.php');
-    require_once('core/class/class_request.php');
-    require_once('core/admin_tools.php');
-    if ($mode == 'list') {
-        require_once('modules/templates/lang/fr.php');
-        require_once(
-            'apps/' . $_SESSION['config']['app_id'] 
-            . '/class/class_list_show.php'
-        );
-    }
-} catch (Exception $e) {
-    functions::xecho($e->getMessage());
-}
-
-if (isset($_REQUEST['submit'])) {
-    // Action to do with db
-    validate_cs_submit($mode);
-} else {
-    // Display to do
-    if (isset($_REQUEST['id']) && !empty($_REQUEST['id']))
-        $template_id = $_REQUEST['id'];
-    $state = true;
-    switch ($mode) {
-        case 'up' :
-            $state = display_up($template_id); 
-            location_bar_management($mode);
-            break;
-        case 'add' :
-            display_add(); 
-            location_bar_management($mode);
-            break;
-        case 'del' :
-            display_del($template_id); 
-            break;
-        case 'list' :
-            $templates_list = display_list(); 
-            location_bar_management($mode);
-            break;
-        case 'allow' :
-            display_enable($template_id); 
-            location_bar_management($mode);
-        case 'ban' :
-            display_disable($template_id); 
-            location_bar_management($mode);
-    }
-    $checkedOFFICE = '';
-    $checkedHTML = '';
-    if (
-        $_SESSION['m_admin']['templates']['template_type'] == '' 
-        || $_SESSION['m_admin']['templates']['template_type'] == 'OFFICE'
-    ) {
-        $checkedOFFICE = 'checked="checked"';
-    } elseif ($_SESSION['m_admin']['templates']['template_type'] == 'HTML') {
-        $checkedHTML = 'checked="checked"';
-    } elseif ($_SESSION['m_admin']['templates']['template_type'] == 'TXT') {
-        $checkedTXT = 'checked="checked"';
-    }
-    include('templates_management.php');
-}
-
-/**
- * Initialize session variables
- */
-function init_session()
-{
-    $_SESSION['m_admin']['templates'] = array();
-    $_SESSION['m_admin']['templatesStyles'] = array();
-    $_SESSION['m_admin']['templatesTargets'] = array();
-    $_SESSION['m_admin']['templatesDatasources'] = array();
-    $_SESSION['m_admin']['templatesEntities'] = array();
-    $_SESSION['m_admin']['templatesEntitiesOrg'] = array();
-    $_SESSION['m_admin']['templatesEntitiesSelected'] = array();
-}
-
-/**
- * Management of the location bar  
- */
-function location_bar_management($mode)
-{
-    $pageName = 'templates_management_controler';
-    
-    $page_labels = array(
-        'add' => _ADDITION, 
-        'up' => _MODIFICATION, 
-        'list' => _TEMPLATES_LIST
-    );
-    $page_ids = array(
-        'add' => 'template_add', 
-        'up' => 'template_up', 
-        'list' => 'templates_list'
-    );
-
-    $init = false;
-    if (isset($_REQUEST['reinit']) && $_REQUEST['reinit'] == 'true') 
-        $init = true;
-
-    $level = '';
-    if (
-        isset($_REQUEST['level']) 
-        && ($_REQUEST['level'] == 2 
-        || $_REQUEST['level'] == 3 
-        || $_REQUEST['level'] == 4 
-        || $_REQUEST['level'] == 1)
-    ) {
-        $level = $_REQUEST['level'];
-    }
-    $page_path = $_SESSION['config']['businessappurl'] . 'index.php?page=' 
-        . $pageName . '&module=templates&mode=' . $mode;
-    $page_label = $page_labels[$mode];
-    $page_id = $page_ids[$mode];
-    $ct=new core_tools();
-    $ct->manage_location_bar($page_path, $page_label, $page_id, $init, $level);
-
-}
-
-/**
- * Validate a submit (add or up),
- * up to saving object
- */
-function validate_cs_submit($mode)
-{
-    $pageName = 'templates_management_controler';
-    $templatesControler = new templates_controler();
-    $status = array();
-    $status['order'] = $_REQUEST['order'];
-    $status['order_field'] = $_REQUEST['order_field'];
-    $status['what'] = $_REQUEST['what'];
-    $status['start'] = $_REQUEST['start'];
-    $templates = new templates();
-    if (isset($_REQUEST['id'])) $templates->template_id = $_REQUEST['id'];
-    if (isset($_REQUEST['template_label'])) $templates->template_label 
-        = $_REQUEST['template_label'];
-    if (isset($_REQUEST['template_comment'])) $templates->template_comment 
-        = $_REQUEST['template_comment'];
-    if (isset($_REQUEST['template_style'])) $templates->template_style 
-        = $_REQUEST['template_style'];
-    if (isset($_REQUEST['template_datasource'])) $templates->template_datasource 
-        = $_REQUEST['template_datasource'];
-    if (isset($_REQUEST['template_target'])) {
-        $templates->template_target = $_REQUEST['template_target'];
-        if ($_REQUEST['template_target'] == "") {
-        	$templates->template_attachment_type = "all";
-        } else {
-        	$templates->template_attachment_type = $_REQUEST['template_attachment_type'];        	
-        }
-    }
-    if (isset($_REQUEST['template_type'])) {
-        $templates->template_type = $_REQUEST['template_type'];
-        if ($templates->template_type == 'HTML') {
-            if (isset($_REQUEST['template_content'])) {
-                $templates->template_content = $_REQUEST['template_content'];
-            }
-        } elseif ($templates->template_type == 'TXT') {
-            if (isset($_REQUEST['template_content_txt'])) $templates->template_content 
-                = $_REQUEST['template_content_txt'];
-        }
-    }
-    $_SESSION['m_admin']['templatesEntitiesSelected'] = array();
-    for ($i=0;$i<count($_REQUEST['entities_chosen']); $i++) {
-        array_push(
-            $_SESSION['m_admin']['templatesEntitiesSelected'], 
-            $_REQUEST['entities_chosen'][$i]
-        );
-    }
-    $control = array();
-    $control = $templatesControler->save($templates, $mode);
-    if (!empty($control['error']) && $control['error'] <> 1) {
-        // Error management depending of mode
-        $_SESSION['error'] = str_replace('#', '<br />', $control['error']);
-        At_putInSession('status', $status);
-        At_putInSession('templates', $templates->getArray());
-        switch ($mode) {
-            case 'up':
-                if (!empty($_REQUEST['id'])) {
-                    header('location: ' . $_SESSION['config']['businessappurl'] 
-                        . 'index.php?page=' . $pageName . '&mode=up&id=' 
-                        . $_REQUEST['id'] . '&module=templates'
-                    );
-                } else {
-                    header('location: ' . $_SESSION['config']['businessappurl'] 
-                        . 'index.php?page=' . $pageName . '&mode=list&module=templates&order=' 
-                        . $status['order'] . '&order_field=' . $status['order_field'] 
-                        . '&start=' . $status['start'] . '&what=' . $status['what']
-                    );
-                }
-                exit;
-            case 'add':
-                header('location: ' . $_SESSION['config']['businessappurl'] 
-                    . 'index.php?page=' . $pageName 
-                    . '&mode=add&module=templates'
-                );
-                exit;
-        }
-    } else {
-        if ($mode == 'add')
-            $_SESSION['info'] = _TEMPLATE_ADDED;
-         else
-            $_SESSION['info'] = _TEMPLATE_UPDATED;
-        unset($_SESSION['m_admin']);
-        header('location: ' . $_SESSION['config']['businessappurl'] 
-            . 'index.php?page=' . $pageName . '&mode=list&module=templates&order=' 
-            . $status['order'] . '&order_field=' . $status['order_field'] 
-            . '&start=' . $status['start'] . '&what=' . $status['what']
-        );
-    }
-}
-
-/**
- * Initialize session parameters for update display
- * @param Long $template_id
- */
-function display_up($templateId)
-{
-    init_session();
-    $state = true;
-    $templatesControler = new templates_controler();
-    $stylesArray = array();
-    if (is_dir('custom/' . $_SESSION['custom_override_id'] . '/modules/templates/templates/styles')) {
-       $dir = 'custom/' . $_SESSION['custom_override_id'] . '/modules/templates/templates/styles/';
-    } else {
-        $dir = 'modules/templates/templates/styles/';
-    }
-    $stylesArray = $templatesControler->getTemplatesStyles(
-        $dir, 
-        $stylesArray
-    );
-    $xmlfile = 'modules/templates/xml/datasources.xml';
-    $xmlfileCustom = $_SESSION['config']['corepath'] 
-    . 'custom/' . $_SESSION['custom_override_id'] . '/' . $xmlfile;
-     if (file_exists($xmlfileCustom)) {
-        $xmlfile = $xmlfileCustom;
-    }
-    $datasourcesArray = array();
-    $datasourcesArray = $templatesControler->getTemplatesDatasources($xmlfile);
-    $targetsArray = array();
-    $targetsArray = $templatesControler->getTemplatesTargets();
-    $templates = $templatesControler->get($templateId);
-    /*echo '<pre>';
-    print_r($stylesArray);
-    echo '</pre>';*/
-    $entities = $templatesControler->getAllItemsLinkedToModel($templateId);
-    require_once 'modules/entities/class/EntityControler.php';
-    $entityControler = new EntityControler();
-    $entitiesOrg = $entityControler->getAllEntities();
-    /*echo '<pre>';
-    print_r($entities);
-    echo '</pre>';*/
-    if (empty($templates)) {
-        $state = false; 
-    } else {
-        At_putInSession('templates', $templates->getArray());
-        At_putInSession('templatesStyles', $stylesArray);
-        At_putInSession('templatesTargets', $targetsArray);
-        At_putInSession('templatesDatasources', $datasourcesArray);
-        At_putInSession('templatesEntities', $entities);
-        At_putInSession('templatesEntitiesOrg', $entitiesOrg);
-    }
-    return $state;
-}
-
-/**
- * Initialize session parameters for add display with given docserver
- */
-function display_add()
-{
-    $sessionName = 'templates';
-    if (!isset($_SESSION['m_admin'][$sessionName])) {
-        init_session();
-    }
-    $templatesControler = new templates_controler();
-    $stylesArray = array();
-    //echo 'custom/' . $_SESSION['custom_override_id'] . '/modules/templates/templates/styles';exit;
-    if (is_dir('custom/' . $_SESSION['custom_override_id'] . '/modules/templates/templates/styles')) {
-       $dir = 'custom/' . $_SESSION['custom_override_id'] . '/modules/templates/templates/styles/';
-    } else {
-        $dir = 'modules/templates/templates/styles/';
-    }
-    $stylesArray = $templatesControler->getTemplatesStyles(
-        $dir, 
-        $stylesArray
-    );
-    $xmlfile = 'modules/templates/xml/datasources.xml';
-    $xmlfileCustom = $_SESSION['config']['corepath'] 
-    . 'custom/' . $_SESSION['custom_override_id'] . '/' . $xmlfile;
-     if (file_exists($xmlfileCustom)) {
-        $xmlfile = $xmlfileCustom;
-    }
-    $datasourcesArray = array();
-    $datasourcesArray = $templatesControler->getTemplatesDatasources($xmlfile);
-    $targetsArray = array();
-    $targetsArray = $templatesControler->getTemplatesTargets();
-    require_once 'modules/entities/class/EntityControler.php';
-    $entityControler = new EntityControler();
-    $entitiesOrg = $entityControler->getAllEntities();
-    At_putInSession('templatesStyles', $stylesArray);
-    At_putInSession('templatesTargets', $targetsArray);
-    At_putInSession('templatesDatasources', $datasourcesArray);
-    At_putInSession('templatesEntitiesOrg', $entitiesOrg);
-}
-
-/**
- * Initialize session parameters for list display
- */
-function display_list()
-{
-    $pageName = 'templates_management_controler';
-    $idName = 'template_id';
-    
-    $_SESSION['m_admin'] = array();
-    
-    init_session();
-    
-    $select[_TEMPLATES_TABLE_NAME] = array();
-    array_push(
-        $select[_TEMPLATES_TABLE_NAME], 
-        $idName, 
-        'template_label', 
-        'template_comment',
-        'template_type'
-    );
-    $what = '';
-    $where ='';
-    $arrayPDO = array();
-    if (isset($_REQUEST['what']) && !empty($_REQUEST['what'])) {
-        $func = new functions();
-        $what = $_REQUEST['what'];
-        if ($_SESSION['config']['databasetype'] == 'POSTGRESQL') {
-            $where = "template_label ilike ? ";
-        } else {
-            $where = "template_label like ? ";
-        }
-        $arrayPDO = array_merge($arrayPDO, array(strtoupper($what)."%"));
-    }
-
-    // Checking order and order_field values
-    $order = 'asc';
-    if (isset($_REQUEST['order']) && !empty($_REQUEST['order'])) {
-        $order = trim($_REQUEST['order']);
-    }
-    $field = $idName;
-    if (isset($_REQUEST['order_field']) && !empty($_REQUEST['order_field'])) {
-        $field = trim($_REQUEST['order_field']);
-    }
-    $listShow = new list_show();
-    $orderstr = $listShow->define_order($order, $field);
-    $request = new request();
-    $tab = $request->PDOselect($select,$where,$arrayPDO,$orderstr,$_SESSION['config']['databasetype']);
-    for ($i=0;$i<count($tab);$i++) {
-        foreach($tab[$i] as &$item) {
-            switch ($item['column']) {
-                case $idName:
-                    At_formatItem($item, _TEMPLATE_ID,'10','left','left','bottom',true); break;
-                case 'template_label':
-                    At_formatItem($item, _TEMPLATE_LABEL,'30','left','left','bottom',true); break;
-                case 'template_comment':
-                    At_formatItem($item, _TEMPLATE_COMMENT,'40','left','left','bottom',true); break;
-                case 'template_type':
-                    At_formatItem($item, _TEMPLATE_TYPE,'10','left','left','bottom',true); break;
-            }
-        }    
-    }
-     
-    $result = array();
-    $result['tab']=$tab;
-    $result['what']=$what;
-    $result['page_name'] = $pageName.'&mode=list';
-    $result['page_name_up'] = $pageName.'&mode=up';
-    $result['page_name_del'] = $pageName.'&mode=del';
-    $result['page_name_add'] = $pageName.'&mode=add';
-    $result['label_add'] = _TEMPLATE_ADDITION;
-    $_SESSION['m_admin']['init'] = true;
-    $result['title'] = _TEMPLATES_LIST . ' : ' . count($tab) . ' ' . _TEMPLATES;
-    $result['autoCompletionArray'] = array();
-    $result['autoCompletionArray']['list_script_url'] 
-        = $_SESSION['config']['businessappurl'] . 'index.php?display=true'
-            . '&module=templates&page=templates_list_by_label';
-    $result['autoCompletionArray']['number_to_begin'] = 1;
-    return $result;
-}
-
-/**
- * Delete given docserver if exists and initialize session parameters
- * @param string $template_id
- */
-function display_del($template_id)
-{
-    $templatesControler = new templates_controler();
-    $templates = $templatesControler->get($template_id);
-    if (isset($templates)) {
-        // Deletion
-        $control = array();
-        $control = $templatesControler->delete($templates);
-        if (!empty($control['error']) && $control['error'] <> 1) {
-            $_SESSION['error'] = str_replace('#', '<br />', $control['error']);
-        } else {
-            $_SESSION['info'] = _TEMPLATE_DELETED . ' ' . $template_id;
-        }
-        $pageName = 'templates_management_controler';
-        ?>
-        <script type='text/javascript'>window.top.location='<?php 
-            echo $_SESSION['config']['businessappurl'] . 'index.php?page=' 
-                . $pageName . '&mode=list&module=templates';?>';</script>
-        <?php
-        exit;
-    } else {
-        // Error management
-        $_SESSION['error'] = _TEMPLATE . ' ' . _UNKNOWN;
-    }
-}
diff --git a/modules/templates/xml/IVS/requests_definitions.xml b/modules/templates/xml/IVS/requests_definitions.xml
index 0f3877e7a8ccfc5d9c8450e3a991e0ed1fe37c3a..6ddb1460cb7f5e4626ecca39f4ef2386370a241e 100755
--- a/modules/templates/xml/IVS/requests_definitions.xml
+++ b/modules/templates/xml/IVS/requests_definitions.xml
@@ -32,21 +32,6 @@
         <parameter name="module" value="templates"/>
         <parameter name="display" value="true"/>
     </requestDefinition>
-    <requestDefinition method="POST" path="/apps/maarch_entreprise/index.php" validationRule="admin_change_templates" >
-        <parameter name="page" value="change_template_style"/>
-        <parameter name="module" value="templates"/>
-        <parameter name="display" value="false"/>
-    </requestDefinition>
-    <requestDefinition method="POST" path="/apps/maarch_entreprise/index.php" validationRule="template_list" >
-        <parameter name="page" value="templates_list_by_label"/>
-        <parameter name="module" value="templates"/>
-        <parameter name="display" value="false"/>
-    </requestDefinition>
-    <requestDefinition method="POST" path="/apps/maarch_entreprise/index.php" validationRule="generate_attachment_html" >
-        <parameter name="page" value="generate_attachment_html"/>
-        <parameter name="module" value="templates"/>
-        <parameter name="display" value="false"/>
-    </requestDefinition>
     <requestDefinition method="POST" path="/apps/maarch_entreprise/index.php" validationRule="param_templates_doctypes" >
         <parameter name="page" value="param_templates_doctypes"/>
         <parameter name="module" value="templates"/>
diff --git a/modules/templates/xml/IVS/validation_rules.xml b/modules/templates/xml/IVS/validation_rules.xml
index c473684725777e84316108b23cd9c038b7911e1d..b8168f52aec43479cacae1840db6443205680e98 100755
--- a/modules/templates/xml/IVS/validation_rules.xml
+++ b/modules/templates/xml/IVS/validation_rules.xml
@@ -49,14 +49,7 @@
     	<parameter name="template_id" type="document_id" />
     	<parameter name="module" type="identifier" />
     </validationRule>
-	
-	<validationRule name="generate_attachment_html" extends="standardForm" mode="error">
-    	<parameter name="coll_id" type="collection_list" />
-    	<parameter name="res_id" type="identifier" />
-    	<parameter name="module" type="identifier" />
-    </validationRule>
-    
-    <validationRule name="param_templates_doctypes" extends="standardForm" mode="error">
+	<validationRule name="param_templates_doctypes" extends="standardForm" mode="error">
     	<parameter name="templates" type="identifier" />
     	<parameter name="e_file" type="YN" />
     	<parameter name="module" type="identifier" />
diff --git a/sql/140_to_151.sql b/sql/140_to_151.sql
new file mode 100644
index 0000000000000000000000000000000000000000..c4a8266d64cecac843ad9ac628cbd7b2d8da7dd9
--- /dev/null
+++ b/sql/140_to_151.sql
@@ -0,0 +1,819 @@
+-- *************************************************************************--
+--                                                                          --
+--                                                                          --
+--        THIS SCRIPT IS USE TO PASS FROM MAARCH 1.4 TO MAARCH 1.5.1        --
+--                                                                          --
+--                                                                          --
+-- *************************************************************************--
+
+
+-- ************************************************************************* --
+--                               ALL VIEWS DROP                              --
+-- ************************************************************************* --
+
+DROP VIEW IF EXISTS view_postindexing;
+DROP VIEW IF EXISTS res_view_letterbox;
+DROP VIEW IF EXISTS res_view_business;
+DROP VIEW IF EXISTS res_view;
+DROP VIEW IF EXISTS view_contacts;
+DROP VIEW IF EXISTS res_view_attachments;
+
+-- ************************************************************************* --
+--                               MULTICONTACTS                               --
+-- ************************************************************************* --
+
+-- multicontacts
+DROP TABLE IF EXISTS contacts_res;
+CREATE TABLE contacts_res
+(
+  coll_id character varying(32) NOT NULL,
+  res_id bigint NOT NULL,
+  contact_id character varying(128) NOT NULL,
+  address_id bigint NOT NULL
+);
+
+-- ************************************************************************* --
+--                          NEW CONTACTS MANAGEMENTS                         --
+-- ************************************************************************* --
+
+-- Contact types
+DROP TABLE IF EXISTS contact_types;
+DROP SEQUENCE IF EXISTS contact_types_id_seq;
+
+CREATE SEQUENCE contact_types_id_seq
+  INCREMENT 1
+  MINVALUE 1
+  MAXVALUE 9223372036854775807
+  START 100
+  CACHE 1;
+
+CREATE TABLE contact_types 
+(
+    id bigint NOT NULL DEFAULT nextval('contact_types_id_seq'::regclass),
+    label character varying(255) NOT NULL,
+    can_add_contact character varying(1) NOT NULL DEFAULT 'Y'::character varying,
+    contact_target character varying(50),
+    CONSTRAINT contact_types_pkey PRIMARY KEY  (id)
+) WITH (OIDS=FALSE);
+
+-- Contacts v2
+DROP TABLE IF EXISTS contacts_v2;
+DROP SEQUENCE IF EXISTS contact_v2_id_seq;
+
+CREATE SEQUENCE contact_v2_id_seq
+  INCREMENT 1
+  MINVALUE 14
+  MAXVALUE 9223372036854775807
+  START 200
+  CACHE 1;
+
+CREATE TABLE contacts_v2 
+(
+    contact_id bigint NOT NULL DEFAULT nextval('contact_v2_id_seq'::regclass),
+    contact_type bigint NOT NULL,
+    is_corporate_person character(1) DEFAULT 'Y'::bpchar,
+    society character varying(255),
+    society_short character varying(32),
+    firstname character varying(255),
+    lastname character varying(255),
+    title character varying(255),
+    function character varying(255),
+    other_data text,
+    user_id character varying(255) NOT NULL,
+    entity_id character varying(32) NOT NULL,
+    creation_date timestamp without time zone NOT NULL,
+    update_date timestamp without time zone,
+    enabled character varying(1) NOT NULL DEFAULT 'Y'::bpchar,
+    CONSTRAINT contacts_v2_pkey PRIMARY KEY  (contact_id)
+) WITH (OIDS=FALSE);
+
+-- Contact purposes
+DROP TABLE IF EXISTS contact_purposes;
+DROP SEQUENCE IF EXISTS contact_purposes_id_seq;
+
+CREATE SEQUENCE contact_purposes_id_seq
+  INCREMENT 1
+  MINVALUE 1
+  MAXVALUE 9223372036854775807
+  START 100
+  CACHE 1;
+
+CREATE TABLE contact_purposes 
+(
+    id bigint NOT NULL DEFAULT nextval('contact_purposes_id_seq'::regclass),
+    label character varying(255) NOT NULL,
+    CONSTRAINT contact_purposes_pkey PRIMARY KEY  (id)
+) WITH (OIDS=FALSE);
+
+-- Contact addresses
+DROP TABLE IF EXISTS contact_addresses;
+DROP SEQUENCE IF EXISTS contact_addresses_id_seq;
+
+CREATE SEQUENCE contact_addresses_id_seq
+  INCREMENT 1
+  MINVALUE 1
+  MAXVALUE 9223372036854775807
+  START 100
+  CACHE 1;
+
+CREATE TABLE contact_addresses 
+(
+    id bigint NOT NULL DEFAULT nextval('contact_addresses_id_seq'::regclass),
+    contact_id bigint NOT NULL,
+    contact_purpose_id bigint DEFAULT 1,
+    departement character varying(255),
+    firstname character varying(255),
+    lastname character varying(255),
+    title character varying(255),
+    function character varying(255),
+    occupancy character varying(1024),
+    address_num character varying(32)  ,
+    address_street character varying(255),
+    address_complement character varying(255),
+    address_town character varying(255),
+    address_postal_code character varying(255),
+    address_country character varying(255),
+    phone character varying(20),
+    email character varying(255),
+    website character varying(255),
+    salutation_header character varying(255),
+    salutation_footer character varying(255),
+    other_data character varying(255),
+    user_id character varying(255) NOT NULL,
+    entity_id character varying(32) NOT NULL,
+    is_private character(1) NOT NULL DEFAULT 'N'::bpchar,
+    enabled character varying(1) NOT NULL DEFAULT 'Y'::bpchar,
+    CONSTRAINT contact_addresses_pkey PRIMARY KEY  (id)
+) WITH (OIDS=FALSE);
+
+
+-- ************************************************************************* --
+--                               ACTIONS IN RELATION WITH CATEGORIES         --
+-- ************************************************************************* --
+
+
+-- actions / category
+ALTER TABLE actions DROP COLUMN IF EXISTS category_id; 
+--ALTER TABLE actions ADD category_id character varying(255);
+
+DROP TABLE IF EXISTS actions_categories;
+CREATE TABLE actions_categories
+(
+  action_id bigint NOT NULL,
+  category_id character varying(255) NOT NULL,
+  CONSTRAINT actions_categories_pkey PRIMARY KEY (action_id,category_id)
+);
+
+-- ************************************************************************* --
+--                  RELATION BETWEEN USERS AND BASKETS OF SECONDARY PROFILES --
+-- ************************************************************************* --
+
+DROP TABLE IF EXISTS user_baskets_secondary;
+DROP SEQUENCE IF EXISTS user_baskets_secondary_seq;
+CREATE SEQUENCE user_baskets_secondary_seq
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 9223372036854775807
+START 1
+CACHE 1;
+
+CREATE TABLE user_baskets_secondary
+(
+  system_id bigint NOT NULL DEFAULT nextval('user_baskets_secondary_seq'::regclass),
+  user_id character varying(128) NOT NULL,
+  group_id character varying(32) NOT NULL,
+  basket_id character varying(32) NOT NULL,
+  CONSTRAINT user_baskets_secondary_pkey PRIMARY KEY (system_id)
+);
+
+-- ************************************************************************* --
+--                                VIEWED MAIL                                --
+-- ************************************************************************* --
+
+DROP TABLE IF EXISTS res_mark_as_read;
+CREATE TABLE res_mark_as_read
+(
+  coll_id character varying(32),
+  res_id bigint,
+  user_id character varying(32),
+  basket_id character varying(32)
+);
+
+-- ************************************************************************* --
+--                               NEW COLUMNS IN EXTENSIONS TABLE             --
+-- ************************************************************************* --
+
+ALTER TABLE mlb_coll_ext DROP COLUMN IF EXISTS address_id;
+ALTER TABLE mlb_coll_ext ADD address_id bigint;
+
+ALTER TABLE business_coll_ext DROP COLUMN IF EXISTS address_id;
+ALTER TABLE business_coll_ext ADD address_id bigint;
+
+
+-- ************************************************************************* --
+--                               NEW COLUMNS INTO TABLES                     --
+-- ************************************************************************* --
+
+ALTER TABLE templates DROP COLUMN IF EXISTS template_target; 
+ALTER TABLE templates ADD template_target character varying(255);
+
+ALTER TABLE entities DROP COLUMN IF EXISTS entity_path;
+ALTER TABLE entities ADD entity_path character varying(2048);
+
+ALTER TABLE entities DROP COLUMN IF EXISTS ldap_id;
+ALTER TABLE entities ADD ldap_id character varying(255);
+
+ALTER TABLE baskets DROP COLUMN IF EXISTS basket_order;
+ALTER TABLE baskets ADD basket_order integer;
+
+ALTER TABLE mlb_coll_ext DROP COLUMN IF EXISTS is_multicontacts; 
+ALTER TABLE mlb_coll_ext ADD is_multicontacts character(1);
+
+ALTER TABLE res_x DROP COLUMN IF EXISTS reference_number; 
+ALTER TABLE res_x ADD reference_number character varying(255) DEFAULT NULL::character varying;
+
+ALTER TABLE res_x DROP COLUMN IF EXISTS locker_user_id; 
+ALTER TABLE res_x ADD locker_user_id character varying(255) DEFAULT NULL::character varying;
+
+ALTER TABLE res_x DROP COLUMN IF EXISTS locker_time; 
+ALTER TABLE res_x ADD locker_time timestamp without time zone;
+
+ALTER TABLE res_letterbox DROP COLUMN IF EXISTS reference_number; 
+ALTER TABLE res_letterbox ADD reference_number character varying(255) DEFAULT NULL::character varying;
+
+ALTER TABLE res_letterbox DROP COLUMN IF EXISTS locker_user_id; 
+ALTER TABLE res_letterbox ADD locker_user_id character varying(255) DEFAULT NULL::character varying;
+
+ALTER TABLE res_letterbox DROP COLUMN IF EXISTS locker_time; 
+ALTER TABLE res_letterbox ADD locker_time timestamp without time zone;
+
+ALTER TABLE res_business DROP COLUMN IF EXISTS reference_number; 
+ALTER TABLE res_business ADD reference_number character varying(255) DEFAULT NULL::character varying;
+
+ALTER TABLE res_business DROP COLUMN IF EXISTS locker_user_id; 
+ALTER TABLE res_business ADD locker_user_id character varying(255) DEFAULT NULL::character varying;
+
+ALTER TABLE res_business DROP COLUMN IF EXISTS locker_time; 
+ALTER TABLE res_business ADD locker_time timestamp without time zone;
+
+ALTER TABLE lc_stack DROP COLUMN IF EXISTS work_batch;
+ALTER TABLE lc_stack ADD COLUMN work_batch bigint;
+
+ALTER TABLE lc_stack DROP COLUMN IF EXISTS regex;
+ALTER TABLE lc_stack ADD COLUMN regex character varying(32);
+
+ALTER TABLE res_letterbox DROP COLUMN IF EXISTS confidentiality; 
+ALTER TABLE res_letterbox ADD confidentiality character(1);
+
+ALTER TABLE listinstance DROP COLUMN IF EXISTS process_comment;
+ALTER TABLE listinstance ADD process_comment character varying(255);
+
+ALTER TABLE listinstance DROP COLUMN IF EXISTS process_date;
+ALTER TABLE listinstance ADD process_date timestamp without time zone;
+
+ALTER TABLE listmodels DROP COLUMN IF EXISTS title;
+ALTER TABLE listmodels ADD COLUMN title varchar(255);
+
+ALTER TABLE sendmail DROP COLUMN IF EXISTS sender_email;
+ALTER TABLE sendmail ADD COLUMN sender_email varchar(255);
+
+-- ALTER TABLE listmodels DROP COLUMN IF EXISTS description;
+-- ALTER TABLE listmodels ADD COLUMN description varchar(255);
+
+ALTER TABLE listmodels DROP COLUMN IF EXISTS process_comment;
+ALTER TABLE listmodels ADD COLUMN process_comment varchar(255);
+
+DROP TABLE IF EXISTS listinstance_history;
+DROP SEQUENCE IF EXISTS listinstance_history_id_seq;
+CREATE SEQUENCE listinstance_history_id_seq
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 9223372036854775807
+START 1
+CACHE 1;
+
+CREATE TABLE listinstance_history
+(
+listinstance_history_id bigint NOT NULL DEFAULT nextval('listinstance_history_id_seq'::regclass),
+coll_id character varying(50) NOT NULL,
+res_id bigint NOT NULL,
+updated_by_user character varying(128) NOT NULL,
+updated_date timestamp without time zone NOT NULL,
+CONSTRAINT listinstance_history_pkey PRIMARY KEY (listinstance_history_id)
+)
+WITH ( OIDS=FALSE );
+
+DROP TABLE IF EXISTS listinstance_history_details;
+DROP SEQUENCE IF EXISTS listinstance_history_details_id_seq;
+CREATE SEQUENCE listinstance_history_details_id_seq
+INCREMENT 1
+MINVALUE 1
+MAXVALUE 9223372036854775807
+START 1
+CACHE 1;
+
+CREATE TABLE listinstance_history_details
+(
+listinstance_history_details_id bigint NOT NULL DEFAULT nextval('listinstance_history_details_id_seq'::regclass),
+listinstance_history_id bigint NOT NULL,
+coll_id character varying(50) NOT NULL,
+res_id bigint NOT NULL,
+listinstance_type character varying(50) DEFAULT 'DOC'::character varying,
+sequence bigint NOT NULL,
+item_id character varying(128) NOT NULL,
+item_type character varying(255) NOT NULL,
+item_mode character varying(50) NOT NULL,
+added_by_user character varying(128) NOT NULL,
+added_by_entity character varying(50) NOT NULL,
+visible character varying(1) NOT NULL DEFAULT 'Y'::bpchar,
+viewed bigint,
+difflist_type character varying(50),
+process_date timestamp without time zone,
+process_comment character varying(255),
+CONSTRAINT listinstance_history_details_pkey PRIMARY KEY (listinstance_history_details_id)
+) WITH ( OIDS=FALSE );
+
+ -- nouvelle gestion des pj
+ALTER TABLE res_attachments DROP COLUMN IF EXISTS attachment_type; 
+ALTER TABLE res_attachments ADD attachment_type character varying(255) DEFAULT NULL::character varying;
+
+ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_contact_id; 
+ALTER TABLE res_attachments ADD dest_contact_id bigint;
+
+ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_address_id; 
+ALTER TABLE res_attachments ADD dest_address_id bigint;
+
+ALTER TABLE res_attachments DROP COLUMN IF EXISTS updated_by; 
+ALTER TABLE res_attachments ADD updated_by character varying(128) DEFAULT NULL::character varying;
+
+ALTER TABLE res_attachments DROP COLUMN IF EXISTS is_multicontacts; 
+ALTER TABLE res_attachments ADD is_multicontacts character(1);
+
+ALTER TABLE res_attachments DROP COLUMN IF EXISTS is_multi_docservers; 
+ALTER TABLE res_attachments ADD is_multi_docservers character(1) NOT NULL DEFAULT 'N'::bpchar;
+
+ALTER TABLE templates DROP COLUMN IF EXISTS template_attachment_type; 
+ALTER TABLE templates ADD template_attachment_type character varying(255) DEFAULT NULL::character varying;
+
+ALTER TABLE users DROP COLUMN IF EXISTS thumbprint;
+ALTER TABLE users ADD thumbprint text;
+
+ALTER TABLE users DROP COLUMN IF EXISTS signature_path;
+ALTER TABLE users ADD signature_path character varying(255) DEFAULT NULL::character varying;
+
+ALTER TABLE users DROP COLUMN IF EXISTS signature_file_name;
+ALTER TABLE users ADD signature_file_name character varying(255) DEFAULT NULL::character varying;
+
+ALTER TABLE users DROP COLUMN IF EXISTS initials;
+ALTER TABLE users ADD COLUMN initials character varying(32);
+
+DELETE FROM status WHERE id = 'A_TRA';
+INSERT INTO status (id, label_status, is_system) VALUES ('A_TRA', 'A traiter', 'N');
+
+DELETE FROM status WHERE id = 'TRA';
+INSERT INTO status (id, label_status, is_system) VALUES ('TRA', 'Traité', 'N');
+
+DELETE FROM status WHERE id = 'OBS';
+INSERT INTO status (id, label_status, is_system) VALUES ('OBS', 'Obsolète', 'N');
+
+UPDATE status SET img_filename = 'fm-letter-status-inprogress' WHERE id = 'COU'; 
+UPDATE status SET img_filename = 'fm-letter-del' WHERE id = 'DEL'; 
+UPDATE status SET img_filename = 'fm-letter-status-end' WHERE id = 'END'; 
+UPDATE status SET img_filename = 'fm-letter-status-new' WHERE id = 'NEW'; 
+UPDATE status SET img_filename = 'fm-letter-status-rejected' WHERE id = 'RET'; 
+UPDATE status SET img_filename = 'fm-file-fingerprint' WHERE id = 'SIG'; 
+UPDATE status SET img_filename = 'fm-letter-status-rejected' WHERE id = 'UNS'; 
+UPDATE status SET img_filename = 'fm-letter-status-aval' WHERE id = 'VAL'; 
+UPDATE status SET img_filename = 'fm-letter-status-attr' WHERE id = 'INIT'; 
+UPDATE status SET img_filename = 'fm-letter-status-aval' WHERE id = 'VIS';
+
+-- tumbnails
+ALTER TABLE res_letterbox DROP COLUMN IF EXISTS tnl_path;
+ALTER TABLE res_letterbox DROP COLUMN IF EXISTS tnl_filename;
+ALTER TABLE res_letterbox ADD tnl_path character varying(255) DEFAULT NULL::character varying;
+ALTER TABLE res_letterbox ADD tnl_filename character varying(255) DEFAULT NULL::character varying;
+ALTER TABLE res_business DROP COLUMN IF EXISTS tnl_path;
+ALTER TABLE res_business DROP COLUMN IF EXISTS tnl_filename;
+ALTER TABLE res_business ADD tnl_path character varying(255) DEFAULT NULL::character varying;
+ALTER TABLE res_business ADD tnl_filename character varying(255) DEFAULT NULL::character varying;
+ALTER TABLE res_x DROP COLUMN IF EXISTS tnl_path;
+ALTER TABLE res_x DROP COLUMN IF EXISTS tnl_filename;
+ALTER TABLE res_x ADD tnl_path character varying(255) DEFAULT NULL::character varying;
+ALTER TABLE res_x ADD tnl_filename character varying(255) DEFAULT NULL::character varying;
+
+DROP TABLE IF EXISTS res_version_attachments;
+DROP SEQUENCE IF EXISTS res_id_version_attachments_seq;
+
+CREATE SEQUENCE res_id_version_attachments_seq
+  INCREMENT 1
+  MINVALUE 1
+  MAXVALUE 9223372036854775807
+  START 100
+  CACHE 1;
+
+CREATE TABLE res_version_attachments
+(
+  res_id bigint NOT NULL DEFAULT nextval('res_id_version_attachments_seq'::regclass),
+  title character varying(255) DEFAULT NULL::character varying,
+  subject text,
+  description text,
+  publisher character varying(255) DEFAULT NULL::character varying,
+  contributor character varying(255) DEFAULT NULL::character varying,
+  type_id bigint NOT NULL,
+  format character varying(50) NOT NULL,
+  typist character varying(128) NOT NULL,
+  creation_date timestamp without time zone NOT NULL,
+  fulltext_result character varying(10) DEFAULT NULL::character varying,
+  ocr_result character varying(10) DEFAULT NULL::character varying,
+  converter_result character varying(10) DEFAULT NULL::character varying,
+  author character varying(255) DEFAULT NULL::character varying,
+  author_name text,
+  identifier character varying(255) DEFAULT NULL::character varying,
+  source character varying(255) DEFAULT NULL::character varying,
+  doc_language character varying(50) DEFAULT NULL::character varying,
+  relation bigint,
+  coverage character varying(255) DEFAULT NULL::character varying,
+  doc_date timestamp without time zone,
+  docserver_id character varying(32) NOT NULL,
+  folders_system_id bigint,
+  arbox_id character varying(32) DEFAULT NULL::character varying,
+  path character varying(255) DEFAULT NULL::character varying,
+  filename character varying(255) DEFAULT NULL::character varying,
+  offset_doc character varying(255) DEFAULT NULL::character varying,
+  logical_adr character varying(255) DEFAULT NULL::character varying,
+  fingerprint character varying(255) DEFAULT NULL::character varying,
+  filesize bigint,
+  is_paper character(1) DEFAULT NULL::bpchar,
+  page_count integer,
+  scan_date timestamp without time zone,
+  scan_user character varying(50) DEFAULT NULL::character varying,
+  scan_location character varying(255) DEFAULT NULL::character varying,
+  scan_wkstation character varying(255) DEFAULT NULL::character varying,
+  scan_batch character varying(50) DEFAULT NULL::character varying,
+  burn_batch character varying(50) DEFAULT NULL::character varying,
+  scan_postmark character varying(50) DEFAULT NULL::character varying,
+  envelop_id bigint,
+  status character varying(10) NOT NULL,
+  destination character varying(50) DEFAULT NULL::character varying,
+  approver character varying(50) DEFAULT NULL::character varying,
+  validation_date timestamp without time zone,
+  work_batch bigint,
+  origin character varying(50) DEFAULT NULL::character varying,
+  is_ingoing character(1) DEFAULT NULL::bpchar,
+  priority smallint,
+  arbatch_id bigint,
+  policy_id character varying(32),
+  cycle_id character varying(32),
+  is_multi_docservers character(1) NOT NULL DEFAULT 'N'::bpchar,
+  is_frozen character(1) NOT NULL DEFAULT 'N'::bpchar,
+  custom_t1 text,
+  custom_n1 bigint,
+  custom_f1 numeric,
+  custom_d1 timestamp without time zone,
+  custom_t2 character varying(255) DEFAULT NULL::character varying,
+  custom_n2 bigint,
+  custom_f2 numeric,
+  custom_d2 timestamp without time zone,
+  custom_t3 character varying(255) DEFAULT NULL::character varying,
+  custom_n3 bigint,
+  custom_f3 numeric,
+  custom_d3 timestamp without time zone,
+  custom_t4 character varying(255) DEFAULT NULL::character varying,
+  custom_n4 bigint,
+  custom_f4 numeric,
+  custom_d4 timestamp without time zone,
+  custom_t5 character varying(255) DEFAULT NULL::character varying,
+  custom_n5 bigint,
+  custom_f5 numeric,
+  custom_d5 timestamp without time zone,
+  custom_t6 character varying(255) DEFAULT NULL::character varying,
+  custom_d6 timestamp without time zone,
+  custom_t7 character varying(255) DEFAULT NULL::character varying,
+  custom_d7 timestamp without time zone,
+  custom_t8 character varying(255) DEFAULT NULL::character varying,
+  custom_d8 timestamp without time zone,
+  custom_t9 character varying(255) DEFAULT NULL::character varying,
+  custom_d9 timestamp without time zone,
+  custom_t10 character varying(255) DEFAULT NULL::character varying,
+  custom_d10 timestamp without time zone,
+  custom_t11 character varying(255) DEFAULT NULL::character varying,
+  custom_t12 character varying(255) DEFAULT NULL::character varying,
+  custom_t13 character varying(255) DEFAULT NULL::character varying,
+  custom_t14 character varying(255) DEFAULT NULL::character varying,
+  custom_t15 character varying(255) DEFAULT NULL::character varying,
+  tablename character varying(32) DEFAULT 'res_version_attachments'::character varying,
+  initiator character varying(50) DEFAULT NULL::character varying,
+  dest_user character varying(128) DEFAULT NULL::character varying,
+  video_batch integer,
+  video_time integer,
+  video_user character varying(128) DEFAULT NULL::character varying,
+  video_date timestamp without time zone,
+  cycle_date timestamp without time zone,
+  coll_id character varying(32) NOT NULL,
+  attachment_type character varying(255) DEFAULT NULL::character varying,
+  dest_contact_id bigint,
+  dest_address_id bigint,
+  updated_by character varying(128) DEFAULT NULL::character varying,
+  is_multicontacts character(1),
+  res_id_master bigint,
+  attachment_id_master bigint,
+  CONSTRAINT res_version_attachments_pkey PRIMARY KEY (res_id)
+)
+WITH (
+  OIDS=FALSE
+);
+
+
+-- ************************************************************************* --
+--                               RECREATE VIEWS                              --
+-- ************************************************************************* --
+
+
+-- view for letterbox
+CREATE VIEW res_view_letterbox AS
+    SELECT r.tablename, r.is_multi_docservers, r.res_id, r.type_id, r.policy_id, r.cycle_id, 
+    d.description AS type_label, d.doctypes_first_level_id,
+    dfl.doctypes_first_level_label, dfl.css_style as doctype_first_level_style,
+    d.doctypes_second_level_id, dsl.doctypes_second_level_label,
+    dsl.css_style as doctype_second_level_style, r.format, r.typist,
+    r.creation_date, r.relation, r.docserver_id, r.folders_system_id,
+    f.folder_id, f.destination as folder_destination, f.is_frozen as folder_is_frozen, r.path, r.filename, r.fingerprint, r.offset_doc, r.filesize,
+    r.status, r.work_batch, r.arbatch_id, r.arbox_id, r.page_count, r.is_paper,
+    r.doc_date, r.scan_date, r.scan_user, r.scan_location, r.scan_wkstation,
+    r.scan_batch, r.doc_language, r.description, r.source, r.author, r.reference_number,
+    r.custom_t1 AS doc_custom_t1, r.custom_t2 AS doc_custom_t2,
+    r.custom_t3 AS doc_custom_t3, r.custom_t4 AS doc_custom_t4,
+    r.custom_t5 AS doc_custom_t5, r.custom_t6 AS doc_custom_t6,
+    r.custom_t7 AS doc_custom_t7, r.custom_t8 AS doc_custom_t8,
+    r.custom_t9 AS doc_custom_t9, r.custom_t10 AS doc_custom_t10,
+    r.custom_t11 AS doc_custom_t11, r.custom_t12 AS doc_custom_t12,
+    r.custom_t13 AS doc_custom_t13, r.custom_t14 AS doc_custom_t14,
+    r.custom_t15 AS doc_custom_t15, r.custom_d1 AS doc_custom_d1,
+    r.custom_d2 AS doc_custom_d2, r.custom_d3 AS doc_custom_d3,
+    r.custom_d4 AS doc_custom_d4, r.custom_d5 AS doc_custom_d5,
+    r.custom_d6 AS doc_custom_d6, r.custom_d7 AS doc_custom_d7,
+    r.custom_d8 AS doc_custom_d8, r.custom_d9 AS doc_custom_d9,
+    r.custom_d10 AS doc_custom_d10, r.custom_n1 AS doc_custom_n1,
+    r.custom_n2 AS doc_custom_n2, r.custom_n3 AS doc_custom_n3,
+    r.custom_n4 AS doc_custom_n4, r.custom_n5 AS doc_custom_n5,
+    r.custom_f1 AS doc_custom_f1, r.custom_f2 AS doc_custom_f2,
+    r.custom_f3 AS doc_custom_f3, r.custom_f4 AS doc_custom_f4,
+    r.custom_f5 AS doc_custom_f5, f.foldertype_id, ft.foldertype_label,
+    f.custom_t1 AS fold_custom_t1, f.custom_t2 AS fold_custom_t2,
+    f.custom_t3 AS fold_custom_t3, f.custom_t4 AS fold_custom_t4,
+    f.custom_t5 AS fold_custom_t5, f.custom_t6 AS fold_custom_t6,
+    f.custom_t7 AS fold_custom_t7, f.custom_t8 AS fold_custom_t8,
+    f.custom_t9 AS fold_custom_t9, f.custom_t10 AS fold_custom_t10,
+    f.custom_t11 AS fold_custom_t11, f.custom_t12 AS fold_custom_t12,
+    f.custom_t13 AS fold_custom_t13, f.custom_t14 AS fold_custom_t14,
+    f.custom_t15 AS fold_custom_t15, f.custom_d1 AS fold_custom_d1,
+    f.custom_d2 AS fold_custom_d2, f.custom_d3 AS fold_custom_d3,
+    f.custom_d4 AS fold_custom_d4, f.custom_d5 AS fold_custom_d5,
+    f.custom_d6 AS fold_custom_d6, f.custom_d7 AS fold_custom_d7,
+    f.custom_d8 AS fold_custom_d8, f.custom_d9 AS fold_custom_d9,
+    f.custom_d10 AS fold_custom_d10, f.custom_n1 AS fold_custom_n1,
+    f.custom_n2 AS fold_custom_n2, f.custom_n3 AS fold_custom_n3,
+    f.custom_n4 AS fold_custom_n4, f.custom_n5 AS fold_custom_n5,
+    f.custom_f1 AS fold_custom_f1, f.custom_f2 AS fold_custom_f2,
+    f.custom_f3 AS fold_custom_f3, f.custom_f4 AS fold_custom_f4,
+    f.custom_f5 AS fold_custom_f5, f.is_complete AS fold_complete,
+    f.status AS fold_status, f.subject AS fold_subject,
+    f.parent_id AS fold_parent_id, f.folder_level, f.folder_name,
+    f.creation_date AS fold_creation_date, r.initiator, r.destination,
+    r.dest_user, r.confidentiality, mlb.category_id, mlb.exp_contact_id, mlb.exp_user_id,
+    mlb.dest_user_id, mlb.dest_contact_id, mlb.address_id, mlb.nature_id, mlb.alt_identifier,
+    mlb.admission_date, mlb.answer_type_bitmask, mlb.other_answer_desc,
+    mlb.process_limit_date, mlb.closing_date, mlb.alarm1_date, mlb.alarm2_date,
+    mlb.flag_notif, mlb.flag_alarm1, mlb.flag_alarm2, mlb.is_multicontacts, r.video_user, r.video_time,
+    r.video_batch, r.subject, r.identifier, r.title, r.priority, mlb.process_notes,
+	r.locker_user_id, r.locker_time,
+    ca.case_id, ca.case_label, ca.case_description, en.entity_label, en.entity_type AS entityType,
+    cont.contact_id AS contact_id,
+    cont.firstname AS contact_firstname, cont.lastname AS contact_lastname,
+    cont.society AS contact_society, u.lastname AS user_lastname,
+    u.firstname AS user_firstname, list.item_id AS dest_user_from_listinstance, list.viewed, 
+    r.is_frozen as res_is_frozen, COALESCE(att.count_attachment, 0::bigint) AS count_attachment 
+    FROM doctypes d, doctypes_first_level dfl, doctypes_second_level dsl,
+    (((((((((((ar_batch a RIGHT JOIN res_letterbox r ON ((r.arbatch_id = a.arbatch_id)))
+    LEFT JOIN (SELECT res_attachments.res_id_master, count(res_attachments.res_id_master) AS count_attachment
+        FROM res_attachments WHERE res_attachments.status <> 'DEL' GROUP BY res_attachments.res_id_master) att ON (r.res_id = att.res_id_master))
+    LEFT JOIN entities en ON (((r.destination)::text = (en.entity_id)::text)))
+    LEFT JOIN folders f ON ((r.folders_system_id = f.folders_system_id)))
+    LEFT JOIN cases_res cr ON ((r.res_id = cr.res_id)))
+    LEFT JOIN mlb_coll_ext mlb ON ((mlb.res_id = r.res_id)))
+    LEFT JOIN foldertypes ft ON (((f.foldertype_id = ft.foldertype_id)
+        AND ((f.status)::text <> 'DEL'::text))))
+    LEFT JOIN cases ca ON ((cr.case_id = ca.case_id)))
+    LEFT JOIN contacts_v2 cont ON (((mlb.exp_contact_id = cont.contact_id)
+        OR (mlb.dest_contact_id = cont.contact_id))))
+    LEFT JOIN users u ON ((((mlb.exp_user_id)::text = (u.user_id)::text)
+        OR ((mlb.dest_user_id)::text = (u.user_id)::text))))
+    LEFT JOIN listinstance list ON (((r.res_id = list.res_id)
+        AND ((list.item_mode)::text = 'dest'::text))))
+    WHERE (((r.type_id = d.type_id) AND
+    (d.doctypes_first_level_id = dfl.doctypes_first_level_id))
+    AND (d.doctypes_second_level_id = dsl.doctypes_second_level_id));
+
+-- view for business
+CREATE VIEW res_view_business AS
+    SELECT r.tablename, r.is_multi_docservers, r.res_id, r.type_id,
+    d.description AS type_label, d.doctypes_first_level_id,
+    d.doctypes_second_level_id, dfl.doctypes_first_level_label, 
+    dfl.css_style as doctype_first_level_style,
+    dsl.doctypes_second_level_label,
+    dsl.css_style as doctype_second_level_style, r.format, r.typist,
+    r.creation_date, r.relation, r.docserver_id, r.folders_system_id,
+    f.folder_id, f.is_frozen as folder_is_frozen, r.path, r.filename, 
+    r.fingerprint, r.offset_doc, r.filesize,
+    r.status, r.work_batch, r.arbatch_id, r.arbox_id, r.page_count, r.is_paper,
+    r.doc_date, r.scan_date, r.scan_user, r.scan_location, r.scan_wkstation,
+    r.scan_batch, r.doc_language, r.description, r.source, r.author, r.reference_number,
+    r.custom_t1 AS doc_custom_t1, r.custom_t2 AS doc_custom_t2,
+    r.custom_t3 AS doc_custom_t3, r.custom_t4 AS doc_custom_t4,
+    r.custom_t5 AS doc_custom_t5, r.custom_t6 AS doc_custom_t6,
+    r.custom_t7 AS doc_custom_t7, r.custom_t8 AS doc_custom_t8,
+    r.custom_t9 AS doc_custom_t9, r.custom_t10 AS doc_custom_t10,
+    r.custom_t11 AS doc_custom_t11, r.custom_t12 AS doc_custom_t12,
+    r.custom_t13 AS doc_custom_t13, r.custom_t14 AS doc_custom_t14,
+    r.custom_t15 AS doc_custom_t15, r.custom_d1 AS doc_custom_d1,
+    r.custom_d2 AS doc_custom_d2, r.custom_d3 AS doc_custom_d3,
+    r.custom_d4 AS doc_custom_d4, r.custom_d5 AS doc_custom_d5,
+    r.custom_d6 AS doc_custom_d6, r.custom_d7 AS doc_custom_d7,
+    r.custom_d8 AS doc_custom_d8, r.custom_d9 AS doc_custom_d9,
+    r.custom_d10 AS doc_custom_d10, r.custom_n1 AS doc_custom_n1,
+    r.custom_n2 AS doc_custom_n2, r.custom_n3 AS doc_custom_n3,
+    r.custom_n4 AS doc_custom_n4, r.custom_n5 AS doc_custom_n5,
+    r.custom_f1 AS doc_custom_f1, r.custom_f2 AS doc_custom_f2,
+    r.custom_f3 AS doc_custom_f3, r.custom_f4 AS doc_custom_f4,
+    r.custom_f5 AS doc_custom_f5, f.foldertype_id,
+    f.custom_t1 AS fold_custom_t1, f.custom_t2 AS fold_custom_t2,
+    f.custom_t3 AS fold_custom_t3, f.custom_t4 AS fold_custom_t4,
+    f.custom_t5 AS fold_custom_t5, f.custom_t6 AS fold_custom_t6,
+    f.custom_t7 AS fold_custom_t7, f.custom_t8 AS fold_custom_t8,
+    f.custom_t9 AS fold_custom_t9, f.custom_t10 AS fold_custom_t10,
+    f.custom_t11 AS fold_custom_t11, f.custom_t12 AS fold_custom_t12,
+    f.custom_t13 AS fold_custom_t13, f.custom_t14 AS fold_custom_t14,
+    f.custom_t15 AS fold_custom_t15, f.custom_d1 AS fold_custom_d1,
+    f.custom_d2 AS fold_custom_d2, f.custom_d3 AS fold_custom_d3,
+    f.custom_d4 AS fold_custom_d4, f.custom_d5 AS fold_custom_d5,
+    f.custom_d6 AS fold_custom_d6, f.custom_d7 AS fold_custom_d7,
+    f.custom_d8 AS fold_custom_d8, f.custom_d9 AS fold_custom_d9,
+    f.custom_d10 AS fold_custom_d10, f.custom_n1 AS fold_custom_n1,
+    f.custom_n2 AS fold_custom_n2, f.custom_n3 AS fold_custom_n3,
+    f.custom_n4 AS fold_custom_n4, f.custom_n5 AS fold_custom_n5,
+    f.custom_f1 AS fold_custom_f1, f.custom_f2 AS fold_custom_f2,
+    f.custom_f3 AS fold_custom_f3, f.custom_f4 AS fold_custom_f4,
+    f.custom_f5 AS fold_custom_f5, f.is_complete AS fold_complete,
+    f.status AS fold_status, f.subject AS fold_subject,
+    f.parent_id AS fold_parent_id, f.folder_level, f.folder_name,
+    f.creation_date AS fold_creation_date, r.initiator, r.destination,
+    r.dest_user, busi.category_id, busi.contact_id, busi.address_id, busi.currency,
+	r.locker_user_id, r.locker_time,	
+    busi.net_sum, busi.tax_sum, busi.total_sum, 
+    busi.process_limit_date, busi.closing_date, busi.alarm1_date, busi.alarm2_date,
+    busi.flag_notif, busi.flag_alarm1, busi.flag_alarm2, r.video_user, r.video_time,
+    r.video_batch, r.subject, r.identifier, r.title, r.priority,
+    en.entity_label,
+    cont.firstname AS contact_firstname, cont.lastname AS contact_lastname,
+    cont.society AS contact_society, list.item_id AS dest_user_from_listinstance,  list.viewed, 
+    r.is_frozen as res_is_frozen, COALESCE(att.count_attachment, 0::bigint) AS count_attachment 
+    FROM doctypes d, doctypes_first_level dfl, doctypes_second_level dsl, res_business r
+    LEFT JOIN (SELECT res_attachments.res_id_master, coll_id, count(res_attachments.res_id_master) AS count_attachment
+        FROM res_attachments WHERE res_attachments.status <> 'DEL' GROUP BY res_attachments.res_id_master, coll_id) att ON (r.res_id = att.res_id_master and att.coll_id = 'business_coll')
+    LEFT JOIN entities en ON ((r.destination)::text = (en.entity_id)::text)
+    LEFT JOIN folders f ON ((r.folders_system_id = f.folders_system_id))
+    LEFT JOIN business_coll_ext busi ON (busi.res_id = r.res_id)
+    LEFT JOIN contacts_v2 cont ON (busi.contact_id = cont.contact_id)
+    LEFT JOIN listinstance list ON ((r.res_id = list.res_id)
+        AND ((list.item_mode)::text = 'dest'::text))
+    WHERE r.type_id = d.type_id 
+    AND d.doctypes_first_level_id = dfl.doctypes_first_level_id
+    AND d.doctypes_second_level_id = dsl.doctypes_second_level_id;
+
+
+CREATE VIEW res_view AS
+ SELECT r.tablename, r.is_multi_docservers, r.res_id, r.title, r.subject, r.page_count, r.identifier, r.doc_date, r.type_id,
+ d.description AS type_label, d.doctypes_first_level_id, dfl.doctypes_first_level_label, dfl.css_style as doctype_first_level_style,
+ d.doctypes_second_level_id, dsl.doctypes_second_level_label, dsl.css_style as doctype_second_level_style,
+ r.format, r.typist, r.creation_date, r.relation, r.docserver_id,
+ r.folders_system_id, r.path, r.filename, r.fingerprint, r.offset_doc, r.filesize, r.status,
+ r.work_batch, r.arbatch_id, r.arbox_id,  r.is_paper, r.scan_date, r.scan_user,r.scan_location,r.scan_wkstation,
+ r.scan_batch,r.doc_language,r.description,r.source,r.initiator,r.destination,r.dest_user,r.policy_id,r.cycle_id,r.cycle_date,
+ r.custom_t1 AS doc_custom_t1, r.custom_t2 AS doc_custom_t2, r.custom_t3 AS doc_custom_t3,
+ r.custom_t4 AS doc_custom_t4, r.custom_t5 AS doc_custom_t5, r.custom_t6 AS doc_custom_t6,
+ r.custom_t7 AS doc_custom_t7, r.custom_t8 AS doc_custom_t8, r.custom_t9 AS doc_custom_t9,
+ r.custom_t10 AS doc_custom_t10, r.custom_t11 AS doc_custom_t11, r.custom_t12 AS doc_custom_t12,
+ r.custom_t13 AS doc_custom_t13, r.custom_t14 AS doc_custom_t14, r.custom_t15 AS doc_custom_t15,
+ r.custom_d1 AS doc_custom_d1, r.custom_d2 AS doc_custom_d2, r.custom_d3 AS doc_custom_d3,
+ r.custom_d4 AS doc_custom_d4, r.custom_d5 AS doc_custom_d5, r.custom_d6 AS doc_custom_d6,
+ r.custom_d7 AS doc_custom_d7, r.custom_d8 AS doc_custom_d8, r.custom_d9 AS doc_custom_d9,
+ r.custom_d10 AS doc_custom_d10, r.custom_n1 AS doc_custom_n1, r.custom_n2 AS doc_custom_n2,
+ r.custom_n3 AS doc_custom_n3, r.custom_n4 AS doc_custom_n4, r.custom_n5 AS doc_custom_n5,
+ r.custom_f1 AS doc_custom_f1, r.custom_f2 AS doc_custom_f2, r.custom_f3 AS doc_custom_f3,
+ r.custom_f4 AS doc_custom_f4, r.custom_f5 AS doc_custom_f5, r.is_frozen as res_is_frozen,  
+ r.reference_number, r.locker_user_id, r.locker_time
+   FROM  doctypes d, doctypes_first_level dfl, doctypes_second_level dsl, res_x r
+   WHERE r.type_id = d.type_id
+   AND d.doctypes_first_level_id = dfl.doctypes_first_level_id
+   AND d.doctypes_second_level_id = dsl.doctypes_second_level_id;
+
+
+--view for postindexing
+CREATE VIEW view_postindexing AS
+SELECT res_view_letterbox.video_user, (users.firstname::text || ' '::text) || users.lastname::text AS user_name, res_view_letterbox.video_batch, res_view_letterbox.video_time, count(res_view_letterbox.res_id) AS count_documents, res_view_letterbox.folders_system_id, (folders.folder_id::text || ' / '::text) || folders.folder_name::text AS folder_full_label, folders.video_status
+FROM res_view_letterbox
+LEFT JOIN users ON res_view_letterbox.video_user::text = users.user_id::text
+LEFT JOIN folders ON folders.folders_system_id = res_view_letterbox.folders_system_id
+WHERE res_view_letterbox.video_batch IS NOT NULL
+GROUP BY res_view_letterbox.video_user, (users.firstname::text || ' '::text) || users.lastname::text, res_view_letterbox.video_batch, res_view_letterbox.video_time, res_view_letterbox.folders_system_id, (folders.folder_id::text || ' / '::text) || folders.folder_name::text, folders.video_status;
+
+
+--view for contacts_v2
+CREATE VIEW view_contacts AS 
+ SELECT c.contact_id, c.contact_type, c.is_corporate_person, c.society, c.society_short, c.firstname AS contact_firstname
+, c.lastname AS contact_lastname, c.title AS contact_title, c.function AS contact_function, c.other_data AS contact_other_data
+, c.user_id AS contact_user_id, c.entity_id AS contact_entity_id, c.creation_date, c.update_date, c.enabled AS contact_enabled, ca.id AS ca_id
+, ca.contact_purpose_id, ca.departement, ca.firstname, ca.lastname, ca.title, ca.function, ca.occupancy
+, ca.address_num, ca.address_street, ca.address_complement, ca.address_town, ca.address_postal_code, ca.address_country
+, ca.phone, ca.email, ca.website, ca.salutation_header, ca.salutation_footer, ca.other_data, ca.user_id, ca.entity_id, ca.is_private, ca.enabled
+, cp.label as contact_purpose_label, ct.label as contact_type_label
+   FROM contacts_v2 c
+   RIGHT JOIN contact_addresses ca ON c.contact_id = ca.contact_id
+   LEFT JOIN contact_purposes cp ON ca.contact_purpose_id = cp.id
+   LEFT JOIN contact_types ct ON c.contact_type = ct.id;
+
+-- view for attachments
+CREATE VIEW res_view_attachments AS
+  SELECT '0' as res_id, res_id as res_id_version, title, subject, description, publisher, contributor, type_id, format, typist,
+  creation_date, fulltext_result, ocr_result, author, author_name, identifier, source,
+  doc_language, relation, coverage, doc_date, docserver_id, folders_system_id, arbox_id, path,
+  filename, offset_doc, logical_adr, fingerprint, filesize, is_paper, page_count,
+  scan_date, scan_user, scan_location, scan_wkstation, scan_batch, burn_batch, scan_postmark,
+  envelop_id, status, destination, approver, validation_date, work_batch, origin, is_ingoing, priority, initiator, dest_user,
+  coll_id, dest_contact_id, dest_address_id, updated_by, is_multicontacts, is_multi_docservers, res_id_master, attachment_type, attachment_id_master
+  FROM res_version_attachments
+  UNION ALL
+  SELECT res_id, '0' as res_id_version, title, subject, description, publisher, contributor, type_id, format, typist,
+  creation_date, fulltext_result, ocr_result, author, author_name, identifier, source,
+  doc_language, relation, coverage, doc_date, docserver_id, folders_system_id, arbox_id, path,
+  filename, offset_doc, logical_adr, fingerprint, filesize, is_paper, page_count,
+  scan_date, scan_user, scan_location, scan_wkstation, scan_batch, burn_batch, scan_postmark,
+  envelop_id, status, destination, approver, validation_date, work_batch, origin, is_ingoing, priority, initiator, dest_user,
+  coll_id, dest_contact_id, dest_address_id, updated_by, is_multicontacts, is_multi_docservers, res_id_master, attachment_type, '0'
+  FROM res_attachments;
+
+   
+
+-- ************************************************************************* --
+--                               DATABASE VERSION                            --
+-- ************************************************************************* --
+
+
+
+UPDATE parameters SET param_value_int = 151 where id='database_version';
+
+
+
+-- ************************************************************************* --
+--                               DATA MIGRATION                              --
+-- ************************************************************************* --
+
+-- confidentiality
+UPDATE res_letterbox SET confidentiality = 'N';
+
+-- contacts_v2
+INSERT INTO contacts_v2 (contact_id, contact_type, is_corporate_person, society, society_short,firstname,lastname,title,function,other_data,user_id,entity_id,creation_date,update_date,enabled)
+SELECT contact_id, '1', is_corporate_person, society, '', firstname, lastname, title,function, other_data,'superadmin','',CURRENT_DATE,CURRENT_DATE,enabled FROM contacts;
+
+INSERT INTO contact_addresses (contact_id, contact_purpose_id, departement,firstname,lastname,title,function,occupancy,address_num,address_street, address_complement, address_town, address_postal_code,address_country,phone,email,website,salutation_header,salutation_footer,other_data,user_id,entity_id,is_private, enabled)
+SELECT contact_id,'1','','','','','','',address_num,address_street,address_complement,address_town,address_postal_code,address_country,phone,email,'','','','','superadmin','',is_private,enabled from contacts;
+
+INSERT INTO contact_purposes (id,label) VALUES ('1','Adresse Principale');
+
+INSERT INTO contact_types (id,label,can_add_contact,contact_target) VALUES ('1','Courriers', 'Y', 'both');
+
+UPDATE mlb_coll_ext m SET address_id = adr.id FROM contact_addresses adr WHERE m.exp_contact_id = adr.contact_id OR m.dest_contact_id = adr.contact_id;
+
+-- attachments
+UPDATE res_attachments SET relation = 1, attachment_type='response_project';
+
+
+-- templates
+UPDATE templates SET template_target = 'attachments', template_attachment_type = 'response_project';
+
+UPDATE templates SET template_target = 'notifications', template_attachment_type = NULL WHERE lower(template_label) LIKE '%notification%';
+
+-- listmodels
+UPDATE listmodels SET title=description, description='';
+
+-- passwords SHA512
+UPDATE users SET password = '65d1d802c2c5e7e9035c5cef3cfc0902b6d0b591bfa85977055290736bbfcdd7e19cb7cfc9f980d0c815bbf7fe329a4efd8da880515ba520b22c0aa3a96514cc', change_password = 'Y' WHERE user_id != 'superadmin';
+UPDATE users SET password = '964a5502faec7a27f63ab5f7bddbe1bd8a685616a90ffcba633b5ad404569bd8fed4693cc00474a4881f636f3831a3e5a36bda049c568a89cfe54b1285b0c13e' WHERE user_id = 'superadmin';
+
+-- Docservers for thumbnails
+INSERT INTO docserver_types (docserver_type_id, docserver_type_label, enabled, is_container, container_max_number, is_compressed, compression_mode, is_meta, meta_template, is_logged, log_template, is_signed, fingerprint_mode) VALUES ('TNL', 'Thumbnails', 'Y', 'N', 0, 'N', 'NONE', 'N', 'NONE', 'N', 'NONE', 'Y', 'NONE');
+INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, enabled, size_limit_number, actual_size_number, path_template, ext_docserver_info, chain_before, chain_after, creation_date, closing_date, coll_id, priority_number, docserver_location_id, adr_priority_number) VALUES ('TNL', 'TNL', 'Server for thumbnails of documents', 'N', 'Y', 50000000000, 0, '/opt/maarch/docservers/thumbnails_mlb/', NULL, NULL, NULL, '2015-03-16 14:47:49.197164', NULL, 'letterbox_coll', 11, 'NANTERRE', 3);
+
+--Add service associate_folder by default
+INSERT INTO usergroups_services(group_id,service_id)
+SELECT group_id,'associate_folder' from usergroups;
diff --git a/sql/150_to_151.sql b/sql/150_to_151.sql
deleted file mode 100755
index 473268771254284acd4c4537dd58f24a95364142..0000000000000000000000000000000000000000
--- a/sql/150_to_151.sql
+++ /dev/null
@@ -1,317 +0,0 @@
--- *************************************************************************--
---                                                                          --
---                                                                          --
---        THIS SCRIPT IS USE TO PASS FROM MAARCH 1.5 TO MAARCH 1.5.1        --
---                                                                          --
---                                                                          --
--- *************************************************************************--
-
-
--- ************************************************************************* --
---                               ALL VIEWS DROP                              --
--- ************************************************************************* --
-
-DROP VIEW IF EXISTS view_postindexing;
-DROP VIEW IF EXISTS res_view_letterbox;
-DROP VIEW IF EXISTS res_view_business;
-DROP VIEW IF EXISTS res_view;
-DROP VIEW IF EXISTS view_contacts;
-DROP VIEW IF EXISTS res_view_attachments;
-
-
-ALTER TABLE contact_types DROP COLUMN IF EXISTS can_add_contact;
-ALTER TABLE contact_types DROP COLUMN IF EXISTS contact_target;
-ALTER TABLE contact_types ADD COLUMN can_add_contact character varying(1) NOT NULL DEFAULT 'Y'::character varying, 
-ADD COLUMN contact_target character varying(50);
-
--- ************************************************************************* --
---                                VIEWED MAIL                                --
--- ************************************************************************* --
-
-DROP TABLE IF EXISTS res_mark_as_read;
-CREATE TABLE res_mark_as_read
-(
-  coll_id character varying(32),
-  res_id bigint,
-  user_id character varying(32),
-  basket_id character varying(32)
-);
-
-
-ALTER TABLE entities DROP COLUMN IF EXISTS ldap_id;
-ALTER TABLE entities ADD ldap_id character varying(255);
-
-ALTER TABLE baskets DROP COLUMN IF EXISTS basket_order;
-ALTER TABLE baskets ADD basket_order integer;
-
-ALTER TABLE sendmail DROP COLUMN IF EXISTS sender_email;
-ALTER TABLE sendmail ADD COLUMN sender_email varchar(255);
-
-ALTER TABLE users DROP COLUMN IF EXISTS initials;
-ALTER TABLE users ADD COLUMN initials character varying(32);
-
-
--- ************************************************************************* --
---                               RECREATE VIEWS                              --
--- ************************************************************************* --
-
--- view for letterbox
-CREATE VIEW res_view_letterbox AS
-    SELECT r.tablename, r.is_multi_docservers, r.res_id, r.type_id, r.policy_id, r.cycle_id, 
-    d.description AS type_label, d.doctypes_first_level_id,
-    dfl.doctypes_first_level_label, dfl.css_style as doctype_first_level_style,
-    d.doctypes_second_level_id, dsl.doctypes_second_level_label,
-    dsl.css_style as doctype_second_level_style, r.format, r.typist,
-    r.creation_date, r.relation, r.docserver_id, r.folders_system_id,
-    f.folder_id, f.destination as folder_destination, f.is_frozen as folder_is_frozen, r.path, r.filename, r.fingerprint, r.offset_doc, r.filesize,
-    r.status, r.work_batch, r.arbatch_id, r.arbox_id, r.page_count, r.is_paper,
-    r.doc_date, r.scan_date, r.scan_user, r.scan_location, r.scan_wkstation,
-    r.scan_batch, r.doc_language, r.description, r.source, r.author, r.reference_number,
-    r.custom_t1 AS doc_custom_t1, r.custom_t2 AS doc_custom_t2,
-    r.custom_t3 AS doc_custom_t3, r.custom_t4 AS doc_custom_t4,
-    r.custom_t5 AS doc_custom_t5, r.custom_t6 AS doc_custom_t6,
-    r.custom_t7 AS doc_custom_t7, r.custom_t8 AS doc_custom_t8,
-    r.custom_t9 AS doc_custom_t9, r.custom_t10 AS doc_custom_t10,
-    r.custom_t11 AS doc_custom_t11, r.custom_t12 AS doc_custom_t12,
-    r.custom_t13 AS doc_custom_t13, r.custom_t14 AS doc_custom_t14,
-    r.custom_t15 AS doc_custom_t15, r.custom_d1 AS doc_custom_d1,
-    r.custom_d2 AS doc_custom_d2, r.custom_d3 AS doc_custom_d3,
-    r.custom_d4 AS doc_custom_d4, r.custom_d5 AS doc_custom_d5,
-    r.custom_d6 AS doc_custom_d6, r.custom_d7 AS doc_custom_d7,
-    r.custom_d8 AS doc_custom_d8, r.custom_d9 AS doc_custom_d9,
-    r.custom_d10 AS doc_custom_d10, r.custom_n1 AS doc_custom_n1,
-    r.custom_n2 AS doc_custom_n2, r.custom_n3 AS doc_custom_n3,
-    r.custom_n4 AS doc_custom_n4, r.custom_n5 AS doc_custom_n5,
-    r.custom_f1 AS doc_custom_f1, r.custom_f2 AS doc_custom_f2,
-    r.custom_f3 AS doc_custom_f3, r.custom_f4 AS doc_custom_f4,
-    r.custom_f5 AS doc_custom_f5, f.foldertype_id, ft.foldertype_label,
-    f.custom_t1 AS fold_custom_t1, f.custom_t2 AS fold_custom_t2,
-    f.custom_t3 AS fold_custom_t3, f.custom_t4 AS fold_custom_t4,
-    f.custom_t5 AS fold_custom_t5, f.custom_t6 AS fold_custom_t6,
-    f.custom_t7 AS fold_custom_t7, f.custom_t8 AS fold_custom_t8,
-    f.custom_t9 AS fold_custom_t9, f.custom_t10 AS fold_custom_t10,
-    f.custom_t11 AS fold_custom_t11, f.custom_t12 AS fold_custom_t12,
-    f.custom_t13 AS fold_custom_t13, f.custom_t14 AS fold_custom_t14,
-    f.custom_t15 AS fold_custom_t15, f.custom_d1 AS fold_custom_d1,
-    f.custom_d2 AS fold_custom_d2, f.custom_d3 AS fold_custom_d3,
-    f.custom_d4 AS fold_custom_d4, f.custom_d5 AS fold_custom_d5,
-    f.custom_d6 AS fold_custom_d6, f.custom_d7 AS fold_custom_d7,
-    f.custom_d8 AS fold_custom_d8, f.custom_d9 AS fold_custom_d9,
-    f.custom_d10 AS fold_custom_d10, f.custom_n1 AS fold_custom_n1,
-    f.custom_n2 AS fold_custom_n2, f.custom_n3 AS fold_custom_n3,
-    f.custom_n4 AS fold_custom_n4, f.custom_n5 AS fold_custom_n5,
-    f.custom_f1 AS fold_custom_f1, f.custom_f2 AS fold_custom_f2,
-    f.custom_f3 AS fold_custom_f3, f.custom_f4 AS fold_custom_f4,
-    f.custom_f5 AS fold_custom_f5, f.is_complete AS fold_complete,
-    f.status AS fold_status, f.subject AS fold_subject,
-    f.parent_id AS fold_parent_id, f.folder_level, f.folder_name,
-    f.creation_date AS fold_creation_date, r.initiator, r.destination,
-    r.dest_user, r.confidentiality, mlb.category_id, mlb.exp_contact_id, mlb.exp_user_id,
-    mlb.dest_user_id, mlb.dest_contact_id, mlb.address_id, mlb.nature_id, mlb.alt_identifier,
-    mlb.admission_date, mlb.answer_type_bitmask, mlb.other_answer_desc,
-    mlb.process_limit_date, mlb.closing_date, mlb.alarm1_date, mlb.alarm2_date,
-    mlb.flag_notif, mlb.flag_alarm1, mlb.flag_alarm2, mlb.is_multicontacts, r.video_user, r.video_time,
-    r.video_batch, r.subject, r.identifier, r.title, r.priority, mlb.process_notes,
-	r.locker_user_id, r.locker_time,
-    ca.case_id, ca.case_label, ca.case_description, en.entity_label, en.entity_type AS entityType,
-    cont.contact_id AS contact_id,
-    cont.firstname AS contact_firstname, cont.lastname AS contact_lastname,
-    cont.society AS contact_society, u.lastname AS user_lastname,
-    u.firstname AS user_firstname, list.item_id AS dest_user_from_listinstance, list.viewed, 
-    r.is_frozen as res_is_frozen, COALESCE(att.count_attachment, 0::bigint) AS count_attachment 
-    FROM doctypes d, doctypes_first_level dfl, doctypes_second_level dsl,
-    (((((((((((ar_batch a RIGHT JOIN res_letterbox r ON ((r.arbatch_id = a.arbatch_id)))
-    LEFT JOIN (SELECT res_attachments.res_id_master, count(res_attachments.res_id_master) AS count_attachment
-        FROM res_attachments WHERE res_attachments.status <> 'DEL' GROUP BY res_attachments.res_id_master) att ON (r.res_id = att.res_id_master))
-    LEFT JOIN entities en ON (((r.destination)::text = (en.entity_id)::text)))
-    LEFT JOIN folders f ON ((r.folders_system_id = f.folders_system_id)))
-    LEFT JOIN cases_res cr ON ((r.res_id = cr.res_id)))
-    LEFT JOIN mlb_coll_ext mlb ON ((mlb.res_id = r.res_id)))
-    LEFT JOIN foldertypes ft ON (((f.foldertype_id = ft.foldertype_id)
-        AND ((f.status)::text <> 'DEL'::text))))
-    LEFT JOIN cases ca ON ((cr.case_id = ca.case_id)))
-    LEFT JOIN contacts_v2 cont ON (((mlb.exp_contact_id = cont.contact_id)
-        OR (mlb.dest_contact_id = cont.contact_id))))
-    LEFT JOIN users u ON ((((mlb.exp_user_id)::text = (u.user_id)::text)
-        OR ((mlb.dest_user_id)::text = (u.user_id)::text))))
-    LEFT JOIN listinstance list ON (((r.res_id = list.res_id)
-        AND ((list.item_mode)::text = 'dest'::text))))
-    WHERE (((r.type_id = d.type_id) AND
-    (d.doctypes_first_level_id = dfl.doctypes_first_level_id))
-    AND (d.doctypes_second_level_id = dsl.doctypes_second_level_id));
-
--- view for business
-CREATE VIEW res_view_business AS
-    SELECT r.tablename, r.is_multi_docservers, r.res_id, r.type_id,
-    d.description AS type_label, d.doctypes_first_level_id,
-    d.doctypes_second_level_id, dfl.doctypes_first_level_label, 
-    dfl.css_style as doctype_first_level_style,
-    dsl.doctypes_second_level_label,
-    dsl.css_style as doctype_second_level_style, r.format, r.typist,
-    r.creation_date, r.relation, r.docserver_id, r.folders_system_id,
-    f.folder_id, f.is_frozen as folder_is_frozen, r.path, r.filename, 
-    r.fingerprint, r.offset_doc, r.filesize,
-    r.status, r.work_batch, r.arbatch_id, r.arbox_id, r.page_count, r.is_paper,
-    r.doc_date, r.scan_date, r.scan_user, r.scan_location, r.scan_wkstation,
-    r.scan_batch, r.doc_language, r.description, r.source, r.author, r.reference_number,
-    r.custom_t1 AS doc_custom_t1, r.custom_t2 AS doc_custom_t2,
-    r.custom_t3 AS doc_custom_t3, r.custom_t4 AS doc_custom_t4,
-    r.custom_t5 AS doc_custom_t5, r.custom_t6 AS doc_custom_t6,
-    r.custom_t7 AS doc_custom_t7, r.custom_t8 AS doc_custom_t8,
-    r.custom_t9 AS doc_custom_t9, r.custom_t10 AS doc_custom_t10,
-    r.custom_t11 AS doc_custom_t11, r.custom_t12 AS doc_custom_t12,
-    r.custom_t13 AS doc_custom_t13, r.custom_t14 AS doc_custom_t14,
-    r.custom_t15 AS doc_custom_t15, r.custom_d1 AS doc_custom_d1,
-    r.custom_d2 AS doc_custom_d2, r.custom_d3 AS doc_custom_d3,
-    r.custom_d4 AS doc_custom_d4, r.custom_d5 AS doc_custom_d5,
-    r.custom_d6 AS doc_custom_d6, r.custom_d7 AS doc_custom_d7,
-    r.custom_d8 AS doc_custom_d8, r.custom_d9 AS doc_custom_d9,
-    r.custom_d10 AS doc_custom_d10, r.custom_n1 AS doc_custom_n1,
-    r.custom_n2 AS doc_custom_n2, r.custom_n3 AS doc_custom_n3,
-    r.custom_n4 AS doc_custom_n4, r.custom_n5 AS doc_custom_n5,
-    r.custom_f1 AS doc_custom_f1, r.custom_f2 AS doc_custom_f2,
-    r.custom_f3 AS doc_custom_f3, r.custom_f4 AS doc_custom_f4,
-    r.custom_f5 AS doc_custom_f5, f.foldertype_id,
-    f.custom_t1 AS fold_custom_t1, f.custom_t2 AS fold_custom_t2,
-    f.custom_t3 AS fold_custom_t3, f.custom_t4 AS fold_custom_t4,
-    f.custom_t5 AS fold_custom_t5, f.custom_t6 AS fold_custom_t6,
-    f.custom_t7 AS fold_custom_t7, f.custom_t8 AS fold_custom_t8,
-    f.custom_t9 AS fold_custom_t9, f.custom_t10 AS fold_custom_t10,
-    f.custom_t11 AS fold_custom_t11, f.custom_t12 AS fold_custom_t12,
-    f.custom_t13 AS fold_custom_t13, f.custom_t14 AS fold_custom_t14,
-    f.custom_t15 AS fold_custom_t15, f.custom_d1 AS fold_custom_d1,
-    f.custom_d2 AS fold_custom_d2, f.custom_d3 AS fold_custom_d3,
-    f.custom_d4 AS fold_custom_d4, f.custom_d5 AS fold_custom_d5,
-    f.custom_d6 AS fold_custom_d6, f.custom_d7 AS fold_custom_d7,
-    f.custom_d8 AS fold_custom_d8, f.custom_d9 AS fold_custom_d9,
-    f.custom_d10 AS fold_custom_d10, f.custom_n1 AS fold_custom_n1,
-    f.custom_n2 AS fold_custom_n2, f.custom_n3 AS fold_custom_n3,
-    f.custom_n4 AS fold_custom_n4, f.custom_n5 AS fold_custom_n5,
-    f.custom_f1 AS fold_custom_f1, f.custom_f2 AS fold_custom_f2,
-    f.custom_f3 AS fold_custom_f3, f.custom_f4 AS fold_custom_f4,
-    f.custom_f5 AS fold_custom_f5, f.is_complete AS fold_complete,
-    f.status AS fold_status, f.subject AS fold_subject,
-    f.parent_id AS fold_parent_id, f.folder_level, f.folder_name,
-    f.creation_date AS fold_creation_date, r.initiator, r.destination,
-    r.dest_user, busi.category_id, busi.contact_id, busi.address_id, busi.currency,
-	r.locker_user_id, r.locker_time,	
-    busi.net_sum, busi.tax_sum, busi.total_sum, 
-    busi.process_limit_date, busi.closing_date, busi.alarm1_date, busi.alarm2_date,
-    busi.flag_notif, busi.flag_alarm1, busi.flag_alarm2, r.video_user, r.video_time,
-    r.video_batch, r.subject, r.identifier, r.title, r.priority,
-    en.entity_label,
-    cont.firstname AS contact_firstname, cont.lastname AS contact_lastname,
-    cont.society AS contact_society, list.item_id AS dest_user_from_listinstance,  list.viewed, 
-    r.is_frozen as res_is_frozen, COALESCE(att.count_attachment, 0::bigint) AS count_attachment 
-    FROM doctypes d, doctypes_first_level dfl, doctypes_second_level dsl, res_business r
-    LEFT JOIN (SELECT res_attachments.res_id_master, coll_id, count(res_attachments.res_id_master) AS count_attachment
-        FROM res_attachments WHERE res_attachments.status <> 'DEL' GROUP BY res_attachments.res_id_master, coll_id) att ON (r.res_id = att.res_id_master and att.coll_id = 'business_coll')
-    LEFT JOIN entities en ON ((r.destination)::text = (en.entity_id)::text)
-    LEFT JOIN folders f ON ((r.folders_system_id = f.folders_system_id))
-    LEFT JOIN business_coll_ext busi ON (busi.res_id = r.res_id)
-    LEFT JOIN contacts_v2 cont ON (busi.contact_id = cont.contact_id)
-    LEFT JOIN listinstance list ON ((r.res_id = list.res_id)
-        AND ((list.item_mode)::text = 'dest'::text))
-    WHERE r.type_id = d.type_id 
-    AND d.doctypes_first_level_id = dfl.doctypes_first_level_id
-    AND d.doctypes_second_level_id = dsl.doctypes_second_level_id;
-
-
-CREATE VIEW res_view AS
- SELECT r.tablename, r.is_multi_docservers, r.res_id, r.title, r.subject, r.page_count, r.identifier, r.doc_date, r.type_id,
- d.description AS type_label, d.doctypes_first_level_id, dfl.doctypes_first_level_label, dfl.css_style as doctype_first_level_style,
- d.doctypes_second_level_id, dsl.doctypes_second_level_label, dsl.css_style as doctype_second_level_style,
- r.format, r.typist, r.creation_date, r.relation, r.docserver_id,
- r.folders_system_id, r.path, r.filename, r.fingerprint, r.offset_doc, r.filesize, r.status,
- r.work_batch, r.arbatch_id, r.arbox_id,  r.is_paper, r.scan_date, r.scan_user,r.scan_location,r.scan_wkstation,
- r.scan_batch,r.doc_language,r.description,r.source,r.initiator,r.destination,r.dest_user,r.policy_id,r.cycle_id,r.cycle_date,
- r.custom_t1 AS doc_custom_t1, r.custom_t2 AS doc_custom_t2, r.custom_t3 AS doc_custom_t3,
- r.custom_t4 AS doc_custom_t4, r.custom_t5 AS doc_custom_t5, r.custom_t6 AS doc_custom_t6,
- r.custom_t7 AS doc_custom_t7, r.custom_t8 AS doc_custom_t8, r.custom_t9 AS doc_custom_t9,
- r.custom_t10 AS doc_custom_t10, r.custom_t11 AS doc_custom_t11, r.custom_t12 AS doc_custom_t12,
- r.custom_t13 AS doc_custom_t13, r.custom_t14 AS doc_custom_t14, r.custom_t15 AS doc_custom_t15,
- r.custom_d1 AS doc_custom_d1, r.custom_d2 AS doc_custom_d2, r.custom_d3 AS doc_custom_d3,
- r.custom_d4 AS doc_custom_d4, r.custom_d5 AS doc_custom_d5, r.custom_d6 AS doc_custom_d6,
- r.custom_d7 AS doc_custom_d7, r.custom_d8 AS doc_custom_d8, r.custom_d9 AS doc_custom_d9,
- r.custom_d10 AS doc_custom_d10, r.custom_n1 AS doc_custom_n1, r.custom_n2 AS doc_custom_n2,
- r.custom_n3 AS doc_custom_n3, r.custom_n4 AS doc_custom_n4, r.custom_n5 AS doc_custom_n5,
- r.custom_f1 AS doc_custom_f1, r.custom_f2 AS doc_custom_f2, r.custom_f3 AS doc_custom_f3,
- r.custom_f4 AS doc_custom_f4, r.custom_f5 AS doc_custom_f5, r.is_frozen as res_is_frozen,  
- r.reference_number, r.locker_user_id, r.locker_time
-   FROM  doctypes d, doctypes_first_level dfl, doctypes_second_level dsl, res_x r
-   WHERE r.type_id = d.type_id
-   AND d.doctypes_first_level_id = dfl.doctypes_first_level_id
-   AND d.doctypes_second_level_id = dsl.doctypes_second_level_id;
-
-
---view for postindexing
-CREATE VIEW view_postindexing AS
-SELECT res_view_letterbox.video_user, (users.firstname::text || ' '::text) || users.lastname::text AS user_name, res_view_letterbox.video_batch, res_view_letterbox.video_time, count(res_view_letterbox.res_id) AS count_documents, res_view_letterbox.folders_system_id, (folders.folder_id::text || ' / '::text) || folders.folder_name::text AS folder_full_label, folders.video_status
-FROM res_view_letterbox
-LEFT JOIN users ON res_view_letterbox.video_user::text = users.user_id::text
-LEFT JOIN folders ON folders.folders_system_id = res_view_letterbox.folders_system_id
-WHERE res_view_letterbox.video_batch IS NOT NULL
-GROUP BY res_view_letterbox.video_user, (users.firstname::text || ' '::text) || users.lastname::text, res_view_letterbox.video_batch, res_view_letterbox.video_time, res_view_letterbox.folders_system_id, (folders.folder_id::text || ' / '::text) || folders.folder_name::text, folders.video_status;
-
-
---view for contacts_v2
-CREATE VIEW view_contacts AS 
- SELECT c.contact_id, c.contact_type, c.is_corporate_person, c.society, c.society_short, c.firstname AS contact_firstname
-, c.lastname AS contact_lastname, c.title AS contact_title, c.function AS contact_function, c.other_data AS contact_other_data
-, c.user_id AS contact_user_id, c.entity_id AS contact_entity_id, c.creation_date, c.update_date, c.enabled AS contact_enabled, ca.id AS ca_id
-, ca.contact_purpose_id, ca.departement, ca.firstname, ca.lastname, ca.title, ca.function, ca.occupancy
-, ca.address_num, ca.address_street, ca.address_complement, ca.address_town, ca.address_postal_code, ca.address_country
-, ca.phone, ca.email, ca.website, ca.salutation_header, ca.salutation_footer, ca.other_data, ca.user_id, ca.entity_id, ca.is_private, ca.enabled
-, cp.label as contact_purpose_label, ct.label as contact_type_label
-   FROM contacts_v2 c
-   RIGHT JOIN contact_addresses ca ON c.contact_id = ca.contact_id
-   LEFT JOIN contact_purposes cp ON ca.contact_purpose_id = cp.id
-   LEFT JOIN contact_types ct ON c.contact_type = ct.id;
-
--- view for attachments
-CREATE VIEW res_view_attachments AS
-  SELECT '0' as res_id, res_id as res_id_version, title, subject, description, publisher, contributor, type_id, format, typist,
-  creation_date, fulltext_result, ocr_result, author, author_name, identifier, source,
-  doc_language, relation, coverage, doc_date, docserver_id, folders_system_id, arbox_id, path,
-  filename, offset_doc, logical_adr, fingerprint, filesize, is_paper, page_count,
-  scan_date, scan_user, scan_location, scan_wkstation, scan_batch, burn_batch, scan_postmark,
-  envelop_id, status, destination, approver, validation_date, work_batch, origin, is_ingoing, priority, initiator, dest_user,
-  coll_id, dest_contact_id, dest_address_id, updated_by, is_multicontacts, is_multi_docservers, res_id_master, attachment_type, attachment_id_master
-  FROM res_version_attachments
-  UNION ALL
-  SELECT res_id, '0' as res_id_version, title, subject, description, publisher, contributor, type_id, format, typist,
-  creation_date, fulltext_result, ocr_result, author, author_name, identifier, source,
-  doc_language, relation, coverage, doc_date, docserver_id, folders_system_id, arbox_id, path,
-  filename, offset_doc, logical_adr, fingerprint, filesize, is_paper, page_count,
-  scan_date, scan_user, scan_location, scan_wkstation, scan_batch, burn_batch, scan_postmark,
-  envelop_id, status, destination, approver, validation_date, work_batch, origin, is_ingoing, priority, initiator, dest_user,
-  coll_id, dest_contact_id, dest_address_id, updated_by, is_multicontacts, is_multi_docservers, res_id_master, attachment_type, '0'
-  FROM res_attachments;
-
-   
-
-
--- ************************************************************************* --
---                               DATABASE VERSION                            --
--- ************************************************************************* --
-
-
-
-UPDATE parameters SET param_value_int = 151 where id='database_version';
-
-
-UPDATE contact_types set can_add_contact = 'Y' where id = '1';
-UPDATE contact_types set contact_target = 'both' where id = '1';
-
-
--- passwords SHA512
-UPDATE users SET password = '65d1d802c2c5e7e9035c5cef3cfc0902b6d0b591bfa85977055290736bbfcdd7e19cb7cfc9f980d0c815bbf7fe329a4efd8da880515ba520b22c0aa3a96514cc', change_password = 'Y' WHERE user_id != 'superadmin';
-UPDATE users SET password = '964a5502faec7a27f63ab5f7bddbe1bd8a685616a90ffcba633b5ad404569bd8fed4693cc00474a4881f636f3831a3e5a36bda049c568a89cfe54b1285b0c13e' WHERE user_id = 'superadmin';
-
--- Docservers for thumbnails
-INSERT INTO docserver_types (docserver_type_id, docserver_type_label, enabled, is_container, container_max_number, is_compressed, compression_mode, is_meta, meta_template, is_logged, log_template, is_signed, fingerprint_mode) VALUES ('TNL', 'Thumbnails', 'Y', 'N', 0, 'N', 'NONE', 'N', 'NONE', 'N', 'NONE', 'Y', 'NONE');
-INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readonly, enabled, size_limit_number, actual_size_number, path_template, ext_docserver_info, chain_before, chain_after, creation_date, closing_date, coll_id, priority_number, docserver_location_id, adr_priority_number) VALUES ('TNL', 'TNL', 'Server for thumbnails of documents', 'N', 'Y', 50000000000, 0, '/opt/maarch/docservers/thumbnails_mlb/', NULL, NULL, NULL, '2015-03-16 14:47:49.197164', NULL, 'letterbox_coll', 11, 'NANTERRE', 3);
-
---Add service associate_folder by default
-INSERT INTO usergroups_services(group_id,service_id)
-SELECT group_id,'associate_folder' from usergroups;
\ No newline at end of file
diff --git a/sql/151.sql b/sql/151.sql
old mode 100755
new mode 100644
index c4a8266d64cecac843ad9ac628cbd7b2d8da7dd9..473268771254284acd4c4537dd58f24a95364142
--- a/sql/151.sql
+++ b/sql/151.sql
@@ -1,7 +1,7 @@
 -- *************************************************************************--
 --                                                                          --
 --                                                                          --
---        THIS SCRIPT IS USE TO PASS FROM MAARCH 1.4 TO MAARCH 1.5.1        --
+--        THIS SCRIPT IS USE TO PASS FROM MAARCH 1.5 TO MAARCH 1.5.1        --
 --                                                                          --
 --                                                                          --
 -- *************************************************************************--
@@ -18,173 +18,11 @@ DROP VIEW IF EXISTS res_view;
 DROP VIEW IF EXISTS view_contacts;
 DROP VIEW IF EXISTS res_view_attachments;
 
--- ************************************************************************* --
---                               MULTICONTACTS                               --
--- ************************************************************************* --
-
--- multicontacts
-DROP TABLE IF EXISTS contacts_res;
-CREATE TABLE contacts_res
-(
-  coll_id character varying(32) NOT NULL,
-  res_id bigint NOT NULL,
-  contact_id character varying(128) NOT NULL,
-  address_id bigint NOT NULL
-);
-
--- ************************************************************************* --
---                          NEW CONTACTS MANAGEMENTS                         --
--- ************************************************************************* --
-
--- Contact types
-DROP TABLE IF EXISTS contact_types;
-DROP SEQUENCE IF EXISTS contact_types_id_seq;
-
-CREATE SEQUENCE contact_types_id_seq
-  INCREMENT 1
-  MINVALUE 1
-  MAXVALUE 9223372036854775807
-  START 100
-  CACHE 1;
-
-CREATE TABLE contact_types 
-(
-    id bigint NOT NULL DEFAULT nextval('contact_types_id_seq'::regclass),
-    label character varying(255) NOT NULL,
-    can_add_contact character varying(1) NOT NULL DEFAULT 'Y'::character varying,
-    contact_target character varying(50),
-    CONSTRAINT contact_types_pkey PRIMARY KEY  (id)
-) WITH (OIDS=FALSE);
-
--- Contacts v2
-DROP TABLE IF EXISTS contacts_v2;
-DROP SEQUENCE IF EXISTS contact_v2_id_seq;
-
-CREATE SEQUENCE contact_v2_id_seq
-  INCREMENT 1
-  MINVALUE 14
-  MAXVALUE 9223372036854775807
-  START 200
-  CACHE 1;
-
-CREATE TABLE contacts_v2 
-(
-    contact_id bigint NOT NULL DEFAULT nextval('contact_v2_id_seq'::regclass),
-    contact_type bigint NOT NULL,
-    is_corporate_person character(1) DEFAULT 'Y'::bpchar,
-    society character varying(255),
-    society_short character varying(32),
-    firstname character varying(255),
-    lastname character varying(255),
-    title character varying(255),
-    function character varying(255),
-    other_data text,
-    user_id character varying(255) NOT NULL,
-    entity_id character varying(32) NOT NULL,
-    creation_date timestamp without time zone NOT NULL,
-    update_date timestamp without time zone,
-    enabled character varying(1) NOT NULL DEFAULT 'Y'::bpchar,
-    CONSTRAINT contacts_v2_pkey PRIMARY KEY  (contact_id)
-) WITH (OIDS=FALSE);
-
--- Contact purposes
-DROP TABLE IF EXISTS contact_purposes;
-DROP SEQUENCE IF EXISTS contact_purposes_id_seq;
-
-CREATE SEQUENCE contact_purposes_id_seq
-  INCREMENT 1
-  MINVALUE 1
-  MAXVALUE 9223372036854775807
-  START 100
-  CACHE 1;
-
-CREATE TABLE contact_purposes 
-(
-    id bigint NOT NULL DEFAULT nextval('contact_purposes_id_seq'::regclass),
-    label character varying(255) NOT NULL,
-    CONSTRAINT contact_purposes_pkey PRIMARY KEY  (id)
-) WITH (OIDS=FALSE);
-
--- Contact addresses
-DROP TABLE IF EXISTS contact_addresses;
-DROP SEQUENCE IF EXISTS contact_addresses_id_seq;
-
-CREATE SEQUENCE contact_addresses_id_seq
-  INCREMENT 1
-  MINVALUE 1
-  MAXVALUE 9223372036854775807
-  START 100
-  CACHE 1;
-
-CREATE TABLE contact_addresses 
-(
-    id bigint NOT NULL DEFAULT nextval('contact_addresses_id_seq'::regclass),
-    contact_id bigint NOT NULL,
-    contact_purpose_id bigint DEFAULT 1,
-    departement character varying(255),
-    firstname character varying(255),
-    lastname character varying(255),
-    title character varying(255),
-    function character varying(255),
-    occupancy character varying(1024),
-    address_num character varying(32)  ,
-    address_street character varying(255),
-    address_complement character varying(255),
-    address_town character varying(255),
-    address_postal_code character varying(255),
-    address_country character varying(255),
-    phone character varying(20),
-    email character varying(255),
-    website character varying(255),
-    salutation_header character varying(255),
-    salutation_footer character varying(255),
-    other_data character varying(255),
-    user_id character varying(255) NOT NULL,
-    entity_id character varying(32) NOT NULL,
-    is_private character(1) NOT NULL DEFAULT 'N'::bpchar,
-    enabled character varying(1) NOT NULL DEFAULT 'Y'::bpchar,
-    CONSTRAINT contact_addresses_pkey PRIMARY KEY  (id)
-) WITH (OIDS=FALSE);
-
-
--- ************************************************************************* --
---                               ACTIONS IN RELATION WITH CATEGORIES         --
--- ************************************************************************* --
-
 
--- actions / category
-ALTER TABLE actions DROP COLUMN IF EXISTS category_id; 
---ALTER TABLE actions ADD category_id character varying(255);
-
-DROP TABLE IF EXISTS actions_categories;
-CREATE TABLE actions_categories
-(
-  action_id bigint NOT NULL,
-  category_id character varying(255) NOT NULL,
-  CONSTRAINT actions_categories_pkey PRIMARY KEY (action_id,category_id)
-);
-
--- ************************************************************************* --
---                  RELATION BETWEEN USERS AND BASKETS OF SECONDARY PROFILES --
--- ************************************************************************* --
-
-DROP TABLE IF EXISTS user_baskets_secondary;
-DROP SEQUENCE IF EXISTS user_baskets_secondary_seq;
-CREATE SEQUENCE user_baskets_secondary_seq
-INCREMENT 1
-MINVALUE 1
-MAXVALUE 9223372036854775807
-START 1
-CACHE 1;
-
-CREATE TABLE user_baskets_secondary
-(
-  system_id bigint NOT NULL DEFAULT nextval('user_baskets_secondary_seq'::regclass),
-  user_id character varying(128) NOT NULL,
-  group_id character varying(32) NOT NULL,
-  basket_id character varying(32) NOT NULL,
-  CONSTRAINT user_baskets_secondary_pkey PRIMARY KEY (system_id)
-);
+ALTER TABLE contact_types DROP COLUMN IF EXISTS can_add_contact;
+ALTER TABLE contact_types DROP COLUMN IF EXISTS contact_target;
+ALTER TABLE contact_types ADD COLUMN can_add_contact character varying(1) NOT NULL DEFAULT 'Y'::character varying, 
+ADD COLUMN contact_target character varying(50);
 
 -- ************************************************************************* --
 --                                VIEWED MAIL                                --
@@ -199,26 +37,6 @@ CREATE TABLE res_mark_as_read
   basket_id character varying(32)
 );
 
--- ************************************************************************* --
---                               NEW COLUMNS IN EXTENSIONS TABLE             --
--- ************************************************************************* --
-
-ALTER TABLE mlb_coll_ext DROP COLUMN IF EXISTS address_id;
-ALTER TABLE mlb_coll_ext ADD address_id bigint;
-
-ALTER TABLE business_coll_ext DROP COLUMN IF EXISTS address_id;
-ALTER TABLE business_coll_ext ADD address_id bigint;
-
-
--- ************************************************************************* --
---                               NEW COLUMNS INTO TABLES                     --
--- ************************************************************************* --
-
-ALTER TABLE templates DROP COLUMN IF EXISTS template_target; 
-ALTER TABLE templates ADD template_target character varying(255);
-
-ALTER TABLE entities DROP COLUMN IF EXISTS entity_path;
-ALTER TABLE entities ADD entity_path character varying(2048);
 
 ALTER TABLE entities DROP COLUMN IF EXISTS ldap_id;
 ALTER TABLE entities ADD ldap_id character varying(255);
@@ -226,309 +44,17 @@ ALTER TABLE entities ADD ldap_id character varying(255);
 ALTER TABLE baskets DROP COLUMN IF EXISTS basket_order;
 ALTER TABLE baskets ADD basket_order integer;
 
-ALTER TABLE mlb_coll_ext DROP COLUMN IF EXISTS is_multicontacts; 
-ALTER TABLE mlb_coll_ext ADD is_multicontacts character(1);
-
-ALTER TABLE res_x DROP COLUMN IF EXISTS reference_number; 
-ALTER TABLE res_x ADD reference_number character varying(255) DEFAULT NULL::character varying;
-
-ALTER TABLE res_x DROP COLUMN IF EXISTS locker_user_id; 
-ALTER TABLE res_x ADD locker_user_id character varying(255) DEFAULT NULL::character varying;
-
-ALTER TABLE res_x DROP COLUMN IF EXISTS locker_time; 
-ALTER TABLE res_x ADD locker_time timestamp without time zone;
-
-ALTER TABLE res_letterbox DROP COLUMN IF EXISTS reference_number; 
-ALTER TABLE res_letterbox ADD reference_number character varying(255) DEFAULT NULL::character varying;
-
-ALTER TABLE res_letterbox DROP COLUMN IF EXISTS locker_user_id; 
-ALTER TABLE res_letterbox ADD locker_user_id character varying(255) DEFAULT NULL::character varying;
-
-ALTER TABLE res_letterbox DROP COLUMN IF EXISTS locker_time; 
-ALTER TABLE res_letterbox ADD locker_time timestamp without time zone;
-
-ALTER TABLE res_business DROP COLUMN IF EXISTS reference_number; 
-ALTER TABLE res_business ADD reference_number character varying(255) DEFAULT NULL::character varying;
-
-ALTER TABLE res_business DROP COLUMN IF EXISTS locker_user_id; 
-ALTER TABLE res_business ADD locker_user_id character varying(255) DEFAULT NULL::character varying;
-
-ALTER TABLE res_business DROP COLUMN IF EXISTS locker_time; 
-ALTER TABLE res_business ADD locker_time timestamp without time zone;
-
-ALTER TABLE lc_stack DROP COLUMN IF EXISTS work_batch;
-ALTER TABLE lc_stack ADD COLUMN work_batch bigint;
-
-ALTER TABLE lc_stack DROP COLUMN IF EXISTS regex;
-ALTER TABLE lc_stack ADD COLUMN regex character varying(32);
-
-ALTER TABLE res_letterbox DROP COLUMN IF EXISTS confidentiality; 
-ALTER TABLE res_letterbox ADD confidentiality character(1);
-
-ALTER TABLE listinstance DROP COLUMN IF EXISTS process_comment;
-ALTER TABLE listinstance ADD process_comment character varying(255);
-
-ALTER TABLE listinstance DROP COLUMN IF EXISTS process_date;
-ALTER TABLE listinstance ADD process_date timestamp without time zone;
-
-ALTER TABLE listmodels DROP COLUMN IF EXISTS title;
-ALTER TABLE listmodels ADD COLUMN title varchar(255);
-
 ALTER TABLE sendmail DROP COLUMN IF EXISTS sender_email;
 ALTER TABLE sendmail ADD COLUMN sender_email varchar(255);
 
--- ALTER TABLE listmodels DROP COLUMN IF EXISTS description;
--- ALTER TABLE listmodels ADD COLUMN description varchar(255);
-
-ALTER TABLE listmodels DROP COLUMN IF EXISTS process_comment;
-ALTER TABLE listmodels ADD COLUMN process_comment varchar(255);
-
-DROP TABLE IF EXISTS listinstance_history;
-DROP SEQUENCE IF EXISTS listinstance_history_id_seq;
-CREATE SEQUENCE listinstance_history_id_seq
-INCREMENT 1
-MINVALUE 1
-MAXVALUE 9223372036854775807
-START 1
-CACHE 1;
-
-CREATE TABLE listinstance_history
-(
-listinstance_history_id bigint NOT NULL DEFAULT nextval('listinstance_history_id_seq'::regclass),
-coll_id character varying(50) NOT NULL,
-res_id bigint NOT NULL,
-updated_by_user character varying(128) NOT NULL,
-updated_date timestamp without time zone NOT NULL,
-CONSTRAINT listinstance_history_pkey PRIMARY KEY (listinstance_history_id)
-)
-WITH ( OIDS=FALSE );
-
-DROP TABLE IF EXISTS listinstance_history_details;
-DROP SEQUENCE IF EXISTS listinstance_history_details_id_seq;
-CREATE SEQUENCE listinstance_history_details_id_seq
-INCREMENT 1
-MINVALUE 1
-MAXVALUE 9223372036854775807
-START 1
-CACHE 1;
-
-CREATE TABLE listinstance_history_details
-(
-listinstance_history_details_id bigint NOT NULL DEFAULT nextval('listinstance_history_details_id_seq'::regclass),
-listinstance_history_id bigint NOT NULL,
-coll_id character varying(50) NOT NULL,
-res_id bigint NOT NULL,
-listinstance_type character varying(50) DEFAULT 'DOC'::character varying,
-sequence bigint NOT NULL,
-item_id character varying(128) NOT NULL,
-item_type character varying(255) NOT NULL,
-item_mode character varying(50) NOT NULL,
-added_by_user character varying(128) NOT NULL,
-added_by_entity character varying(50) NOT NULL,
-visible character varying(1) NOT NULL DEFAULT 'Y'::bpchar,
-viewed bigint,
-difflist_type character varying(50),
-process_date timestamp without time zone,
-process_comment character varying(255),
-CONSTRAINT listinstance_history_details_pkey PRIMARY KEY (listinstance_history_details_id)
-) WITH ( OIDS=FALSE );
-
- -- nouvelle gestion des pj
-ALTER TABLE res_attachments DROP COLUMN IF EXISTS attachment_type; 
-ALTER TABLE res_attachments ADD attachment_type character varying(255) DEFAULT NULL::character varying;
-
-ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_contact_id; 
-ALTER TABLE res_attachments ADD dest_contact_id bigint;
-
-ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_address_id; 
-ALTER TABLE res_attachments ADD dest_address_id bigint;
-
-ALTER TABLE res_attachments DROP COLUMN IF EXISTS updated_by; 
-ALTER TABLE res_attachments ADD updated_by character varying(128) DEFAULT NULL::character varying;
-
-ALTER TABLE res_attachments DROP COLUMN IF EXISTS is_multicontacts; 
-ALTER TABLE res_attachments ADD is_multicontacts character(1);
-
-ALTER TABLE res_attachments DROP COLUMN IF EXISTS is_multi_docservers; 
-ALTER TABLE res_attachments ADD is_multi_docservers character(1) NOT NULL DEFAULT 'N'::bpchar;
-
-ALTER TABLE templates DROP COLUMN IF EXISTS template_attachment_type; 
-ALTER TABLE templates ADD template_attachment_type character varying(255) DEFAULT NULL::character varying;
-
-ALTER TABLE users DROP COLUMN IF EXISTS thumbprint;
-ALTER TABLE users ADD thumbprint text;
-
-ALTER TABLE users DROP COLUMN IF EXISTS signature_path;
-ALTER TABLE users ADD signature_path character varying(255) DEFAULT NULL::character varying;
-
-ALTER TABLE users DROP COLUMN IF EXISTS signature_file_name;
-ALTER TABLE users ADD signature_file_name character varying(255) DEFAULT NULL::character varying;
-
 ALTER TABLE users DROP COLUMN IF EXISTS initials;
 ALTER TABLE users ADD COLUMN initials character varying(32);
 
-DELETE FROM status WHERE id = 'A_TRA';
-INSERT INTO status (id, label_status, is_system) VALUES ('A_TRA', 'A traiter', 'N');
-
-DELETE FROM status WHERE id = 'TRA';
-INSERT INTO status (id, label_status, is_system) VALUES ('TRA', 'Traité', 'N');
-
-DELETE FROM status WHERE id = 'OBS';
-INSERT INTO status (id, label_status, is_system) VALUES ('OBS', 'Obsolète', 'N');
-
-UPDATE status SET img_filename = 'fm-letter-status-inprogress' WHERE id = 'COU'; 
-UPDATE status SET img_filename = 'fm-letter-del' WHERE id = 'DEL'; 
-UPDATE status SET img_filename = 'fm-letter-status-end' WHERE id = 'END'; 
-UPDATE status SET img_filename = 'fm-letter-status-new' WHERE id = 'NEW'; 
-UPDATE status SET img_filename = 'fm-letter-status-rejected' WHERE id = 'RET'; 
-UPDATE status SET img_filename = 'fm-file-fingerprint' WHERE id = 'SIG'; 
-UPDATE status SET img_filename = 'fm-letter-status-rejected' WHERE id = 'UNS'; 
-UPDATE status SET img_filename = 'fm-letter-status-aval' WHERE id = 'VAL'; 
-UPDATE status SET img_filename = 'fm-letter-status-attr' WHERE id = 'INIT'; 
-UPDATE status SET img_filename = 'fm-letter-status-aval' WHERE id = 'VIS';
-
--- tumbnails
-ALTER TABLE res_letterbox DROP COLUMN IF EXISTS tnl_path;
-ALTER TABLE res_letterbox DROP COLUMN IF EXISTS tnl_filename;
-ALTER TABLE res_letterbox ADD tnl_path character varying(255) DEFAULT NULL::character varying;
-ALTER TABLE res_letterbox ADD tnl_filename character varying(255) DEFAULT NULL::character varying;
-ALTER TABLE res_business DROP COLUMN IF EXISTS tnl_path;
-ALTER TABLE res_business DROP COLUMN IF EXISTS tnl_filename;
-ALTER TABLE res_business ADD tnl_path character varying(255) DEFAULT NULL::character varying;
-ALTER TABLE res_business ADD tnl_filename character varying(255) DEFAULT NULL::character varying;
-ALTER TABLE res_x DROP COLUMN IF EXISTS tnl_path;
-ALTER TABLE res_x DROP COLUMN IF EXISTS tnl_filename;
-ALTER TABLE res_x ADD tnl_path character varying(255) DEFAULT NULL::character varying;
-ALTER TABLE res_x ADD tnl_filename character varying(255) DEFAULT NULL::character varying;
-
-DROP TABLE IF EXISTS res_version_attachments;
-DROP SEQUENCE IF EXISTS res_id_version_attachments_seq;
-
-CREATE SEQUENCE res_id_version_attachments_seq
-  INCREMENT 1
-  MINVALUE 1
-  MAXVALUE 9223372036854775807
-  START 100
-  CACHE 1;
-
-CREATE TABLE res_version_attachments
-(
-  res_id bigint NOT NULL DEFAULT nextval('res_id_version_attachments_seq'::regclass),
-  title character varying(255) DEFAULT NULL::character varying,
-  subject text,
-  description text,
-  publisher character varying(255) DEFAULT NULL::character varying,
-  contributor character varying(255) DEFAULT NULL::character varying,
-  type_id bigint NOT NULL,
-  format character varying(50) NOT NULL,
-  typist character varying(128) NOT NULL,
-  creation_date timestamp without time zone NOT NULL,
-  fulltext_result character varying(10) DEFAULT NULL::character varying,
-  ocr_result character varying(10) DEFAULT NULL::character varying,
-  converter_result character varying(10) DEFAULT NULL::character varying,
-  author character varying(255) DEFAULT NULL::character varying,
-  author_name text,
-  identifier character varying(255) DEFAULT NULL::character varying,
-  source character varying(255) DEFAULT NULL::character varying,
-  doc_language character varying(50) DEFAULT NULL::character varying,
-  relation bigint,
-  coverage character varying(255) DEFAULT NULL::character varying,
-  doc_date timestamp without time zone,
-  docserver_id character varying(32) NOT NULL,
-  folders_system_id bigint,
-  arbox_id character varying(32) DEFAULT NULL::character varying,
-  path character varying(255) DEFAULT NULL::character varying,
-  filename character varying(255) DEFAULT NULL::character varying,
-  offset_doc character varying(255) DEFAULT NULL::character varying,
-  logical_adr character varying(255) DEFAULT NULL::character varying,
-  fingerprint character varying(255) DEFAULT NULL::character varying,
-  filesize bigint,
-  is_paper character(1) DEFAULT NULL::bpchar,
-  page_count integer,
-  scan_date timestamp without time zone,
-  scan_user character varying(50) DEFAULT NULL::character varying,
-  scan_location character varying(255) DEFAULT NULL::character varying,
-  scan_wkstation character varying(255) DEFAULT NULL::character varying,
-  scan_batch character varying(50) DEFAULT NULL::character varying,
-  burn_batch character varying(50) DEFAULT NULL::character varying,
-  scan_postmark character varying(50) DEFAULT NULL::character varying,
-  envelop_id bigint,
-  status character varying(10) NOT NULL,
-  destination character varying(50) DEFAULT NULL::character varying,
-  approver character varying(50) DEFAULT NULL::character varying,
-  validation_date timestamp without time zone,
-  work_batch bigint,
-  origin character varying(50) DEFAULT NULL::character varying,
-  is_ingoing character(1) DEFAULT NULL::bpchar,
-  priority smallint,
-  arbatch_id bigint,
-  policy_id character varying(32),
-  cycle_id character varying(32),
-  is_multi_docservers character(1) NOT NULL DEFAULT 'N'::bpchar,
-  is_frozen character(1) NOT NULL DEFAULT 'N'::bpchar,
-  custom_t1 text,
-  custom_n1 bigint,
-  custom_f1 numeric,
-  custom_d1 timestamp without time zone,
-  custom_t2 character varying(255) DEFAULT NULL::character varying,
-  custom_n2 bigint,
-  custom_f2 numeric,
-  custom_d2 timestamp without time zone,
-  custom_t3 character varying(255) DEFAULT NULL::character varying,
-  custom_n3 bigint,
-  custom_f3 numeric,
-  custom_d3 timestamp without time zone,
-  custom_t4 character varying(255) DEFAULT NULL::character varying,
-  custom_n4 bigint,
-  custom_f4 numeric,
-  custom_d4 timestamp without time zone,
-  custom_t5 character varying(255) DEFAULT NULL::character varying,
-  custom_n5 bigint,
-  custom_f5 numeric,
-  custom_d5 timestamp without time zone,
-  custom_t6 character varying(255) DEFAULT NULL::character varying,
-  custom_d6 timestamp without time zone,
-  custom_t7 character varying(255) DEFAULT NULL::character varying,
-  custom_d7 timestamp without time zone,
-  custom_t8 character varying(255) DEFAULT NULL::character varying,
-  custom_d8 timestamp without time zone,
-  custom_t9 character varying(255) DEFAULT NULL::character varying,
-  custom_d9 timestamp without time zone,
-  custom_t10 character varying(255) DEFAULT NULL::character varying,
-  custom_d10 timestamp without time zone,
-  custom_t11 character varying(255) DEFAULT NULL::character varying,
-  custom_t12 character varying(255) DEFAULT NULL::character varying,
-  custom_t13 character varying(255) DEFAULT NULL::character varying,
-  custom_t14 character varying(255) DEFAULT NULL::character varying,
-  custom_t15 character varying(255) DEFAULT NULL::character varying,
-  tablename character varying(32) DEFAULT 'res_version_attachments'::character varying,
-  initiator character varying(50) DEFAULT NULL::character varying,
-  dest_user character varying(128) DEFAULT NULL::character varying,
-  video_batch integer,
-  video_time integer,
-  video_user character varying(128) DEFAULT NULL::character varying,
-  video_date timestamp without time zone,
-  cycle_date timestamp without time zone,
-  coll_id character varying(32) NOT NULL,
-  attachment_type character varying(255) DEFAULT NULL::character varying,
-  dest_contact_id bigint,
-  dest_address_id bigint,
-  updated_by character varying(128) DEFAULT NULL::character varying,
-  is_multicontacts character(1),
-  res_id_master bigint,
-  attachment_id_master bigint,
-  CONSTRAINT res_version_attachments_pkey PRIMARY KEY (res_id)
-)
-WITH (
-  OIDS=FALSE
-);
-
 
 -- ************************************************************************* --
 --                               RECREATE VIEWS                              --
 -- ************************************************************************* --
 
-
 -- view for letterbox
 CREATE VIEW res_view_letterbox AS
     SELECT r.tablename, r.is_multi_docservers, r.res_id, r.type_id, r.policy_id, r.cycle_id, 
@@ -764,6 +290,7 @@ CREATE VIEW res_view_attachments AS
 
    
 
+
 -- ************************************************************************* --
 --                               DATABASE VERSION                            --
 -- ************************************************************************* --
@@ -773,38 +300,9 @@ CREATE VIEW res_view_attachments AS
 UPDATE parameters SET param_value_int = 151 where id='database_version';
 
 
+UPDATE contact_types set can_add_contact = 'Y' where id = '1';
+UPDATE contact_types set contact_target = 'both' where id = '1';
 
--- ************************************************************************* --
---                               DATA MIGRATION                              --
--- ************************************************************************* --
-
--- confidentiality
-UPDATE res_letterbox SET confidentiality = 'N';
-
--- contacts_v2
-INSERT INTO contacts_v2 (contact_id, contact_type, is_corporate_person, society, society_short,firstname,lastname,title,function,other_data,user_id,entity_id,creation_date,update_date,enabled)
-SELECT contact_id, '1', is_corporate_person, society, '', firstname, lastname, title,function, other_data,'superadmin','',CURRENT_DATE,CURRENT_DATE,enabled FROM contacts;
-
-INSERT INTO contact_addresses (contact_id, contact_purpose_id, departement,firstname,lastname,title,function,occupancy,address_num,address_street, address_complement, address_town, address_postal_code,address_country,phone,email,website,salutation_header,salutation_footer,other_data,user_id,entity_id,is_private, enabled)
-SELECT contact_id,'1','','','','','','',address_num,address_street,address_complement,address_town,address_postal_code,address_country,phone,email,'','','','','superadmin','',is_private,enabled from contacts;
-
-INSERT INTO contact_purposes (id,label) VALUES ('1','Adresse Principale');
-
-INSERT INTO contact_types (id,label,can_add_contact,contact_target) VALUES ('1','Courriers', 'Y', 'both');
-
-UPDATE mlb_coll_ext m SET address_id = adr.id FROM contact_addresses adr WHERE m.exp_contact_id = adr.contact_id OR m.dest_contact_id = adr.contact_id;
-
--- attachments
-UPDATE res_attachments SET relation = 1, attachment_type='response_project';
-
-
--- templates
-UPDATE templates SET template_target = 'attachments', template_attachment_type = 'response_project';
-
-UPDATE templates SET template_target = 'notifications', template_attachment_type = NULL WHERE lower(template_label) LIKE '%notification%';
-
--- listmodels
-UPDATE listmodels SET title=description, description='';
 
 -- passwords SHA512
 UPDATE users SET password = '65d1d802c2c5e7e9035c5cef3cfc0902b6d0b591bfa85977055290736bbfcdd7e19cb7cfc9f980d0c815bbf7fe329a4efd8da880515ba520b22c0aa3a96514cc', change_password = 'Y' WHERE user_id != 'superadmin';
@@ -816,4 +314,4 @@ INSERT INTO docservers (docserver_id, docserver_type_id, device_label, is_readon
 
 --Add service associate_folder by default
 INSERT INTO usergroups_services(group_id,service_id)
-SELECT group_id,'associate_folder' from usergroups;
+SELECT group_id,'associate_folder' from usergroups;
\ No newline at end of file