diff --git a/apps/maarch_entreprise/actions/index_mlb.php b/apps/maarch_entreprise/actions/index_mlb.php index c19b5958cf1748da4df6792ec5a7ad40cecf8200..b806f39d8e659c8776204abf8023b2b809eed2bd 100755 --- a/apps/maarch_entreprise/actions/index_mlb.php +++ b/apps/maarch_entreprise/actions/index_mlb.php @@ -224,11 +224,6 @@ function get_form_txt($values, $pathManageAction, $actionId, $table, $module, $c $frmStr .= '<div style="display:table;width:100%;">'; $frmStr .= '<div style="display:table-cell;vertical-align:middle;">'; - $frmStr .= '<select id="indexing_models_select" data-placeholder="'._USE_MODEL_MAILING.'" onchange="loadIndexingModel(\''.$actionId.'\');"><option value="none"></option>'; - while ($resIndexingModels = $stmt->fetchObject()) { - $frmStr .= '<option value="'.$resIndexingModels->id.'">'.$resIndexingModels->label.'</option>'; - } - $frmStr .= '</select>'; $frmStr .= '</div>'; $frmStr .= '<div style="display:table-cell;text-align:right;vertical-align:middle;width: 12%;">'; $frmStr .= '<a style="cursor:pointer;"><i id="action1_indexingmodels" class="fa fa-plus fa-2x" onclick="saveIndexingModel();"></i></a> <a id="delete_indexingmodels" style="cursor:pointer;"><i id="action2_indexingmodels" style="visibility:hidden;" class="fa fa-trash-alt fa-2x" onclick="delIndexingModel();"></i></a>'; diff --git a/apps/maarch_entreprise/actions/validate_mail.php b/apps/maarch_entreprise/actions/validate_mail.php index 2ce8019768f29270d2076dbd631bdc29a96ae266..adf595f4126d2f81f321eb59cbb092dbd2876dce 100755 --- a/apps/maarch_entreprise/actions/validate_mail.php +++ b/apps/maarch_entreprise/actions/validate_mail.php @@ -311,11 +311,6 @@ function get_form_txt($values, $path_manage_action, $id_action, $table, $module, $frm_str .= '<div style="display:table;width:100%;">'; $frm_str .= '<div style="display:table-cell;vertical-align:middle;">'; - $frm_str .= '<select id="indexing_models_select" data-placeholder="'._USE_MODEL_MAILING.'" onchange="loadIndexingModel();"><option value="none"></option>'; - while ($resIndexingModels = $stmt->fetchObject()) { - $frm_str .= '<option value="'.$resIndexingModels->id.'">'.$resIndexingModels->label.'</option>'; - } - $frm_str .= '</select>'; $frm_str .= '</div>'; $frm_str .= '<div style="display:table-cell;text-align:right;vertical-align:middle;width: 12%;">'; $frm_str .= '<a style="cursor:pointer;"><i id="action1_indexingmodels" class="fa fa-plus fa-2x" onclick="saveIndexingModel();"></i></a> <a style="cursor:pointer;"><i class="fa fa-trash-alt fa-2x" onclick="delIndexingModel();"></i></a>'; diff --git a/apps/maarch_entreprise/ajaxIndexingModel.php b/apps/maarch_entreprise/ajaxIndexingModel.php deleted file mode 100755 index 0953a12b441384ee713a0e7fc2800947da3aa4a6..0000000000000000000000000000000000000000 --- a/apps/maarch_entreprise/ajaxIndexingModel.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php -/** -* Copyright Maarch since 2008 under licence GPLv3. -* See LICENCE.txt file at the root folder for more details. -* This file is part of Maarch software. - -* -* @brief ajaxIndexingModel -* -* @author dev <dev@maarch.org> -* @ingroup apps -*/ -$db = new Database(); -$mode = $_REQUEST['mode']; - -if ($mode == 'up') { - $id = $_REQUEST['id']; - $content = $_REQUEST['content']; - $stmt = $db->query( - 'UPDATE indexingModels SET fields_content = ? WHERE id = ?', [$content, $id]); - $result_txt = 'Modèle modifié'; -} elseif ($mode == 'del') { - $id = $_REQUEST['id']; - - $stmt = $db->query( - 'DELETE FROM indexingModels WHERE id = ?', [$id] - ); - $result_txt = 'Modèle supprimé'; -} elseif ($mode == 'get') { - $id = $_REQUEST['id']; - - $stmt = $db->query( - 'select fields_content FROM indexingModels WHERE id=?', [$id] - ); - - $res = $stmt->fetchObject(); - $result_txt = $res->fields_content; -} else { - $label = $_REQUEST['label']; - $content = $_REQUEST['content']; - $mode = $_REQUEST['mode']; - - $stmt = $db->query( - 'INSERT INTO indexingModels (label, fields_content) VALUES(?,?)', [$label, $content] - ); - $id = $db->lastInsertId('indexingmodels_id_seq'); - - $stmt = $db->query( - 'select id,label FROM indexingModels WHERE id=?', [$id] - ); - - $res = $stmt->fetchObject(); - $result = json_encode($res); - - $result_txt = 'Modèle ajouté'; -} - -$return = [ - "status" => 0, - "result" => $result, - "result_txt" => $result_txt -]; - -echo json_encode($return); -exit(); diff --git a/apps/maarch_entreprise/js/indexing.js b/apps/maarch_entreprise/js/indexing.js index 65d2cc8c82ed29588c9c1b6d1b56022df3c78f41..88319d5a028d3652f355f159e7abe1b0e83bec5f 100755 --- a/apps/maarch_entreprise/js/indexing.js +++ b/apps/maarch_entreprise/js/indexing.js @@ -1805,214 +1805,6 @@ function loadInfoContactSenderRecipient(){ return pathScript; } -function loadIndexingModel(actionId) { - if ($j('#complementary_fields').css('display') == 'none') { - new Effect.toggle('complementary_fields', 'blind', {delay:0.2}); - whatIsTheDivStatus('complementary_fields', 'divStatus_complementary_fields'); - } - if ($j('#indexing_models_select').val() != 'none') { - $j('#action2_indexingmodels').css('visibility','visible'); - $j('#action1_indexingmodels').removeClass('fa-plus'); - $j('#action1_indexingmodels').addClass('fa-edit'); - - $j.ajax({ - url : 'index.php?display=true&page=ajaxIndexingModel', - type : 'POST', - dataType : 'JSON', - data: { - mode : 'get', - id: $j('#indexing_models_select').val() - }, - success : function(response){ - if (response.status == 0) { - var content = JSON.parse(response.result_txt); - - $j.each(content, function( index, value ) { - if ($j('#'+index).length) { - if (index == 'destination' && $j('#'+index+' option[value="'+value+'"]').is(':disabled')) { - //do nothing - } else { - $j('#'+index).val(value); - } - $j('#category_id').change(); - - if ($j('#'+index).is('select') && index != 'thesaurus') { - if (index == 'type_id') { - change_doctype(value, 'index.php?display=true&dir=indexing_searching&page=change_doctype', 'Type de document non valide', - actionId, 'index.php?display=true&page=get_content_js', 'table-row'); - } else { - $j('#'+index).change(); - } - $j('#'+index).trigger("chosen:updated"); - } else if (index == 'thesaurus') { - $j.each(value, function( ind, thes ) { - add_thes(thes.id,thes.label); - }); - } - } - }); - } - }, - error : function(error){ - alert('ERROR!'); - } - - }); - } else { - $j('#action2_indexingmodels').css('visibility','hidden'); - $j('#action1_indexingmodels').removeClass('fa-edit'); - $j('#action1_indexingmodels').addClass('fa-plus'); - $j('#category_id').val(''); - $j('#category_id').change(); - $j('#category_id').trigger("chosen:updated"); - $j('#type_id').val(''); - $j('#priority').val(''); - $j('#priority').change(); - $j('#priority').trigger("chosen:updated"); - $j('#nature_id').val(''); - $j('#nature_id').change(); - $j('#nature_id').trigger("chosen:updated"); - $j('#subject').val(''); - $j('#destination').val(''); - $j('#destination').change(); - $j('#destination').trigger("chosen:updated"); - $j('#folder').val(''); - $j('#folder').change(); - $j('#folder').trigger("chosen:updated"); - $j('#thesaurus').val(''); - $j('#thesaurus').trigger("chosen:updated"); - } -} - -function saveIndexingModel() { - - if ($j('#indexing_models_select').val() == 'none') { - var label_fields =[] - if ($j('[for=category_id]').length) { - label_fields.push($j('[for=category_id]').filter(function() { return $j(this).css("display") != "none" }).text()); - } - if ($j('[for=type_id]').length) { - label_fields.push($j('[for=type_id]').filter(function() { return $j(this).css("display") != "none" }).text()); - - } - if ($j('[for=priority]').length) { - label_fields.push($j('[for=priority]').filter(function() { return $j(this).css("display") != "none" }).text()); - - } - if ($j('[for=nature_id]').length) { - label_fields.push($j('[for=nature_id]').filter(function() { return $j(this).css("display") != "none" }).text()); - - } - if ($j('[for=subject]').length) { - label_fields.push($j('[for=subject]').filter(function() { return $j(this).css("display") != "none" }).text()); - - } - if ($j('[for=destination]').length) { - label_fields.push($j('[for=destination]').filter(function() { return $j(this).css("display") != "none" }).text()); - - } - if ($j('[for=folder]').length) { - label_fields.push($j('[for=folder]').filter(function() { return $j(this).css("display") != "none" }).text()); - - } - if ($j('[for=thesaurus]').length) { - label_fields.push($j('[for=thesaurus]').filter(function() { return $j(this).css("display") != "none" }).text()); - } - - var label = prompt("Nom du modèle:\nChamps concernés : "+label_fields.join(', '), ""); - mode = 'add'; - } else { - mode = 'up'; - } - - - if (label || $j('#indexing_models_select').val() != 'none') { - var obj = {}; - if ($j('#category_id').val() != '') { - obj['category_id'] = $j('#category_id').val(); - } - if ($j('#type_id').val() != '') { - obj['type_id'] = $j('#type_id').val(); - } - if ($j('#priority').val() != '') { - obj['priority'] = $j('#priority').val(); - } - if ($j('#nature_id').val() != '') { - obj['nature_id'] = $j('#nature_id').val(); - } - if ($j('#subject').val() != '') { - obj['subject'] = $j('#subject').val(); - } - if ($j('#destination').val() != '') { - obj['destination'] = $j('#destination').val(); - } - if ($j('#thesaurus').length) { - obj['thesaurus'] = []; - $j("#thesaurus > option").each(function() { - $tmp = { - "id" : this.value, - "label" : this.text - } - obj['thesaurus'].push($tmp); - }); - } - $j.ajax({ - url : 'index.php?display=true&page=ajaxIndexingModel', - type : 'POST', - dataType : 'JSON', - data: { - id : $j('#indexing_models_select').val(), - mode : mode, - label: label, - content: JSON.stringify(obj) - }, - success : function(response){ - if (response.status == 0) { - //alert(response.result_txt); - if (mode == 'add') { - var res_content = JSON.parse(response.result); - $j('#indexing_models_select').append('<option value="'+res_content.id+'">'+res_content.label+'</option>'); - $j('#indexing_models_select').val(res_content.id); - $j('#indexing_models_select').trigger("chosen:updated"); - } - } - }, - error : function(error){ - alert('ERROR!'); - } - - }); - } - -} - -function delIndexingModel() { - - if (confirm("Supprimer le modèle ?")) { - $j.ajax({ - url : 'index.php?display=true&page=ajaxIndexingModel', - type : 'POST', - dataType : 'JSON', - data: { - mode : 'del', - id: $j('#indexing_models_select').val(), - }, - success : function(response){ - if (response.status == 0) { - //alert(response.result_txt); - $j('#indexing_models_select option:selected').remove(); - $j('#indexing_models_select option:selected').change(); - $j('#indexing_models_select').trigger("chosen:updated"); - } - }, - error : function(error){ - alert('ERROR!'); - } - - }); - } -} - function initSenderRecipientAutocomplete(inputId, mode, alternateVersion, cardId) { var route = ''; if (mode == 'contactsUsers') { diff --git a/migration/19.12/1912-postScript.sql b/migration/19.12/1912-postScript.sql index 08f5cb0a33e1586b37926d135d006c7a46568433..df427841edf80d822f4d632075c921ade2fba8a3 100644 --- a/migration/19.12/1912-postScript.sql +++ b/migration/19.12/1912-postScript.sql @@ -17,3 +17,4 @@ DROP TABLE IF EXISTS folder_tmp; ALTER TABLE res_letterbox DROP COLUMN IF EXISTS folders_system_id; DROP TABLE IF EXISTS groupbasket_status; +DROP TABLE IF EXISTS indexingmodels; diff --git a/migration/19.12/1912.sql b/migration/19.12/1912.sql index b11e875ed8c365727d5c73574a52e3535421cc8a..578496f8bbb781d7f8885cf406791cdc3327f156 100644 --- a/migration/19.12/1912.sql +++ b/migration/19.12/1912.sql @@ -152,7 +152,7 @@ CREATE TABLE indexing_models_fields identifier text NOT NULL, mandatory BOOLEAN NOT NULL, default_value json, - unit text, + unit text NOT NULL, CONSTRAINT indexing_models_fields_pkey PRIMARY KEY (id) ) WITH (OIDS=FALSE); diff --git a/migration/19.12/migrateOldIndexingModels.php b/migration/19.12/migrateOldIndexingModels.php new file mode 100644 index 0000000000000000000000000000000000000000..876d42dd5405b8b9778fe890ddeddc9d3d45bb95 --- /dev/null +++ b/migration/19.12/migrateOldIndexingModels.php @@ -0,0 +1,66 @@ +<?php + +require '../../vendor/autoload.php'; + +chdir('../..'); + +$customs = scandir('custom'); + +foreach ($customs as $custom) { + if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') { + continue; + } + + \SrcCore\models\DatabasePDO::reset(); + new \SrcCore\models\DatabasePDO(['customId' => $custom]); + + + $oldIndexingModels = \SrcCore\models\DatabaseModel::select([ + 'select' => ['*'], + 'table' => ['indexingmodels'] + ]); + + $superadmin = \User\models\UserModel::getByLogin(['select' => ['id'], 'login' => 'superadmin']); + if (empty($superadmin)) { + $firstMan = \User\models\UserModel::get(['select' => ['id'], 'orderBy' => ['id'], 'limit' => 1]); + $masterOwnerId = $firstMan[0]['id']; + } else { + $masterOwnerId = $superadmin['id']; + } + + $migrated = 0; + foreach ($oldIndexingModels as $oldIndexingModel) { + $fieldContent = json_decode($oldIndexingModel['fields_content'], true); + if (empty($fieldContent['category_id'])) { + continue; + } + + $modelId = \IndexingModel\models\IndexingModelModel::create([ + 'label' => $oldIndexingModel['label'], + 'category' => $fieldContent['category_id'], + 'default' => 'false', + 'owner' => $masterOwnerId, + 'private' => 'false' + ]); + + foreach ($fieldContent as $key => $field) { + if (in_array($key, ['type_id', 'priority', 'subject', 'destination'])) { + if ($key == 'type_id') { + $identifier = 'doctype'; + } else { + $identifier = $key; + } + \IndexingModel\models\IndexingModelFieldModel::create([ + 'model_id' => $modelId, + 'identifier' => $identifier, + 'mandatory' => 'false', + 'default_value' => json_encode($field), + 'unit' => 'mail' + ]); + } + } + ++$migrated; + } + + printf("Migration ancien modèles d'indexation (CUSTOM {$custom}) : " . $migrated . " modèle utilisé(s) et migré(s).\n"); +} diff --git a/sql/structure.sql b/sql/structure.sql index 63b82709e05a4e10660d66cdc76f6b8d11f1a44a..0429071a2b5d0d1be3c8665eaa344aa930f46a7e 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -1761,18 +1761,6 @@ CREATE TABLE convert_stack ) WITH (OIDS=FALSE); -DROP TABLE IF EXISTS indexingmodels; -CREATE TABLE indexingmodels -( - id serial NOT NULL, - label character varying(255) NOT NULL, - fields_content text NOT NULL, - CONSTRAINT indexingmodels_pkey PRIMARY KEY (id) -) -WITH ( - OIDS=FALSE -); - CREATE TABLE password_rules ( id serial,