SET @id_table_cmlv = '112';
SET @id_admin = '1';
SET @ip_admin = '162.38.234.1';
SET @id_meta = '';
SET @enrg = '';
#+--------------------------------------------------------------------------------------------------------------------+#
# AJOUT
SET @id_etat_modif = '1';

# Ajout d''une valeur à la liste 58
SET @notes = 'Initialisation de la valeur «4» pour la liste «58».';

SET @id_valeur = '30762';
INSERT INTO tb_coel.coel_meta_historique_ligne (cmhl_ce_table, cmhl_cle_ligne, cmhl_enregistrement, cmhl_date_modification, cmhl_notes, cmhl_ce_modifier_par, cmhl_ce_etat ,cmhl_ip) 
	VALUES	(@id_table_cmlv, @id_valeur, NULL , NOW( ) , @notes, @id_admin, @id_etat_modif, @ip_admin);
SELECT @id_meta := cmhl_id_historique_ligne, cmhl_date_modification FROM tb_coel.coel_meta_historique_ligne WHERE cmhl_ce_table = CONVERT(@id_table_cmlv USING utf8) AND cmhl_cle_ligne = CONVERT(@id_valeur USING utf8) ORDER BY cmhl_date_modification DESC LIMIT 1;
INSERT INTO tb_coel.coel_meta_liste_valeur (cmlv_id_valeur, cmlv_ce_parent, cmlv_ce_projet, cmlv_nom, cmlv_abreviation, cmlv_description, cmlv_ce_meta) 
	VALUES ( @id_valeur, '1061', '1', 'Dactylographié', '4', NULL, @id_meta );
SELECT @enrg := CONCAT('<?xml version="1.0" encoding="UTF-8" ?>\n<resultset>\n',
	'<row>\n', 
	'<cmlv_id_valeur>', cmlv_id_valeur, '</cmlv_id_valeur>\n', 
	'<cmlv_ce_parent>', cmlv_ce_parent, '</cmlv_ce_parent>\n', 
	'<cmlv_ce_projet>', cmlv_ce_projet, '</cmlv_ce_projet>\n',
	'<cmlv_nom>', cmlv_nom, '</cmlv_nom>\n',
	'<cmlv_abreviation>', cmlv_abreviation, '</cmlv_abreviation>\n',
	'<cmlv_description>', IF(cmlv_description IS NOT NULL, cmlv_description, ''), '</cmlv_description>\n',
	'<cmlv_ce_meta>', cmlv_ce_meta, '</cmlv_ce_meta>\n',
	'</row>\n',
	'</resultset>') AS xmldoc 
	FROM tb_coel.coel_meta_liste_valeur
	WHERE cmlv_id_valeur = @id_valeur;
UPDATE tb_coel.coel_meta_historique_ligne SET 
	cmhl_enregistrement = @enrg
	WHERE cmhl_id_historique_ligne = @id_meta;

#+--------------------------------------------------------------------------------------------------------------------+#
# MODIFICATION
SET @id_etat_modif = '2';

# Mise à jour des abréviations de la liste 27 id 1030
SET @notes = 'Remplacement de l''abréviation numérique par un code.';

SET @id_valeur = '2134';
INSERT INTO tb_coel.coel_meta_historique_ligne (cmhl_ce_table, cmhl_cle_ligne, cmhl_enregistrement, cmhl_date_modification, cmhl_notes, cmhl_ce_modifier_par, cmhl_ce_etat ,cmhl_ip) 
	VALUES	(@id_table_cmlv, @id_valeur, NULL , NOW( ) , @notes, @id_admin, @id_etat_modif, @ip_admin);
SELECT @id_meta := cmhl_id_historique_ligne, cmhl_date_modification FROM tb_coel.coel_meta_historique_ligne WHERE cmhl_ce_table = CONVERT(@id_table_cmlv USING utf8) AND cmhl_cle_ligne = CONVERT(@id_valeur USING utf8) ORDER BY cmhl_date_modification DESC LIMIT 1;
UPDATE tb_coel.coel_meta_liste_valeur SET 
	cmlv_abreviation = 'CT', 
	cmlv_ce_meta = @id_meta 
	WHERE cmlv_id_valeur = @id_valeur;
SELECT @enrg := CONCAT('<?xml version="1.0" encoding="UTF-8" ?>\n<resultset>\n',
	'<row>\n', 
	'<cmlv_id_valeur>', cmlv_id_valeur, '</cmlv_id_valeur>\n', 
	'<cmlv_ce_parent>', cmlv_ce_parent, '</cmlv_ce_parent>\n', 
	'<cmlv_ce_projet>', cmlv_ce_projet, '</cmlv_ce_projet>\n',
	'<cmlv_nom>', cmlv_nom, '</cmlv_nom>\n',
	'<cmlv_abreviation>', cmlv_abreviation, '</cmlv_abreviation>\n',
	'<cmlv_description>', cmlv_description, '</cmlv_description>\n',
	'<cmlv_ce_meta>', cmlv_ce_meta, '</cmlv_ce_meta>\n',
	'</row>\n',
	'</resultset>') AS xmldoc 
	FROM tb_coel.coel_meta_liste_valeur
	WHERE cmlv_id_valeur = @id_valeur;
UPDATE tb_coel.coel_meta_historique_ligne SET 
	cmhl_enregistrement = @enrg
	WHERE cmhl_id_historique_ligne = @id_meta;

SET @id_valeur = '2135';
INSERT INTO tb_coel.coel_meta_historique_ligne (cmhl_ce_table, cmhl_cle_ligne, cmhl_enregistrement, cmhl_date_modification, cmhl_notes, cmhl_ce_modifier_par, cmhl_ce_etat ,cmhl_ip) 
	VALUES	(@id_table_cmlv, @id_valeur, NULL , NOW( ) , @notes, @id_admin, @id_etat_modif, @ip_admin);
SELECT @id_meta := cmhl_id_historique_ligne, cmhl_date_modification FROM tb_coel.coel_meta_historique_ligne WHERE cmhl_ce_table = CONVERT(@id_table_cmlv USING utf8) AND cmhl_cle_ligne = CONVERT(@id_valeur USING utf8) ORDER BY cmhl_date_modification DESC LIMIT 1;
UPDATE tb_coel.coel_meta_liste_valeur SET 
	cmlv_abreviation = 'AU', 
	cmlv_ce_meta = @id_meta 
	WHERE cmlv_id_valeur = @id_valeur;
SELECT @enrg := CONCAT('<?xml version="1.0" encoding="UTF-8" ?>\n<resultset>\n',
	'<row>\n', 
	'<cmlv_id_valeur>', cmlv_id_valeur, '</cmlv_id_valeur>\n', 
	'<cmlv_ce_parent>', cmlv_ce_parent, '</cmlv_ce_parent>\n', 
	'<cmlv_ce_projet>', cmlv_ce_projet, '</cmlv_ce_projet>\n',
	'<cmlv_nom>', cmlv_nom, '</cmlv_nom>\n',
	'<cmlv_abreviation>', cmlv_abreviation, '</cmlv_abreviation>\n',
	'<cmlv_description>', cmlv_description, '</cmlv_description>\n',
	'<cmlv_ce_meta>', cmlv_ce_meta, '</cmlv_ce_meta>\n',
	'</row>\n',
	'</resultset>') AS xmldoc 
	FROM tb_coel.coel_meta_liste_valeur
	WHERE cmlv_id_valeur = @id_valeur;
UPDATE tb_coel.coel_meta_historique_ligne SET 
	cmhl_enregistrement = @enrg
	WHERE cmhl_id_historique_ligne = @id_meta;

SET @id_valeur = '2136';
INSERT INTO tb_coel.coel_meta_historique_ligne (cmhl_ce_table, cmhl_cle_ligne, cmhl_enregistrement, cmhl_date_modification, cmhl_notes, cmhl_ce_modifier_par, cmhl_ce_etat ,cmhl_ip) 
	VALUES	(@id_table_cmlv, @id_valeur, NULL , NOW( ) , @notes, @id_admin, @id_etat_modif, @ip_admin);
SELECT @id_meta := cmhl_id_historique_ligne, cmhl_date_modification FROM tb_coel.coel_meta_historique_ligne WHERE cmhl_ce_table = CONVERT(@id_table_cmlv USING utf8) AND cmhl_cle_ligne = CONVERT(@id_valeur USING utf8) ORDER BY cmhl_date_modification DESC LIMIT 1;
UPDATE tb_coel.coel_meta_liste_valeur SET 
	cmlv_abreviation = 'CO', 
	cmlv_ce_meta = @id_meta 
	WHERE cmlv_id_valeur = @id_valeur;
SELECT @enrg := CONCAT('<?xml version="1.0" encoding="UTF-8" ?>\n<resultset>\n',
	'<row>\n', 
	'<cmlv_id_valeur>', cmlv_id_valeur, '</cmlv_id_valeur>\n', 
	'<cmlv_ce_parent>', cmlv_ce_parent, '</cmlv_ce_parent>\n', 
	'<cmlv_ce_projet>', cmlv_ce_projet, '</cmlv_ce_projet>\n',
	'<cmlv_nom>', cmlv_nom, '</cmlv_nom>\n',
	'<cmlv_abreviation>', cmlv_abreviation, '</cmlv_abreviation>\n',
	'<cmlv_description>', cmlv_description, '</cmlv_description>\n',
	'<cmlv_ce_meta>', cmlv_ce_meta, '</cmlv_ce_meta>\n',
	'</row>\n',
	'</resultset>') AS xmldoc 
	FROM tb_coel.coel_meta_liste_valeur
	WHERE cmlv_id_valeur = @id_valeur;
UPDATE tb_coel.coel_meta_historique_ligne SET 
	cmhl_enregistrement = @enrg
	WHERE cmhl_id_historique_ligne = @id_meta;

SET @id_valeur = '2137';
INSERT INTO tb_coel.coel_meta_historique_ligne (cmhl_ce_table, cmhl_cle_ligne, cmhl_enregistrement, cmhl_date_modification, cmhl_notes, cmhl_ce_modifier_par, cmhl_ce_etat ,cmhl_ip) 
	VALUES	(@id_table_cmlv, @id_valeur, NULL , NOW( ) , @notes, @id_admin, @id_etat_modif, @ip_admin);
SELECT @id_meta := cmhl_id_historique_ligne, cmhl_date_modification FROM tb_coel.coel_meta_historique_ligne WHERE cmhl_ce_table = CONVERT(@id_table_cmlv USING utf8) AND cmhl_cle_ligne = CONVERT(@id_valeur USING utf8) ORDER BY cmhl_date_modification DESC LIMIT 1;
UPDATE tb_coel.coel_meta_liste_valeur SET 
	cmlv_abreviation = 'DE', 
	cmlv_ce_meta = @id_meta 
	WHERE cmlv_id_valeur = @id_valeur;
SELECT @enrg := CONCAT('<?xml version="1.0" encoding="UTF-8" ?>\n<resultset>\n',
	'<row>\n', 
	'<cmlv_id_valeur>', cmlv_id_valeur, '</cmlv_id_valeur>\n', 
	'<cmlv_ce_parent>', cmlv_ce_parent, '</cmlv_ce_parent>\n', 
	'<cmlv_ce_projet>', cmlv_ce_projet, '</cmlv_ce_projet>\n',
	'<cmlv_nom>', cmlv_nom, '</cmlv_nom>\n',
	'<cmlv_abreviation>', cmlv_abreviation, '</cmlv_abreviation>\n',
	'<cmlv_description>', cmlv_description, '</cmlv_description>\n',
	'<cmlv_ce_meta>', cmlv_ce_meta, '</cmlv_ce_meta>\n',
	'</row>\n',
	'</resultset>') AS xmldoc 
	FROM tb_coel.coel_meta_liste_valeur
	WHERE cmlv_id_valeur = @id_valeur;
UPDATE tb_coel.coel_meta_historique_ligne SET 
	cmhl_enregistrement = @enrg
	WHERE cmhl_id_historique_ligne = @id_meta;

SET @id_valeur = '2138';
INSERT INTO tb_coel.coel_meta_historique_ligne (cmhl_ce_table, cmhl_cle_ligne, cmhl_enregistrement, cmhl_date_modification, cmhl_notes, cmhl_ce_modifier_par, cmhl_ce_etat ,cmhl_ip) 
	VALUES	(@id_table_cmlv, @id_valeur, NULL , NOW( ) , @notes, @id_admin, @id_etat_modif, @ip_admin);
SELECT @id_meta := cmhl_id_historique_ligne, cmhl_date_modification FROM tb_coel.coel_meta_historique_ligne WHERE cmhl_ce_table = CONVERT(@id_table_cmlv USING utf8) AND cmhl_cle_ligne = CONVERT(@id_valeur USING utf8) ORDER BY cmhl_date_modification DESC LIMIT 1;
UPDATE tb_coel.coel_meta_liste_valeur SET 
	cmlv_abreviation = 'HE', 
	cmlv_ce_meta = @id_meta 
	WHERE cmlv_id_valeur = @id_valeur;
SELECT @enrg := CONCAT('<?xml version="1.0" encoding="UTF-8" ?>\n<resultset>\n',
	'<row>\n', 
	'<cmlv_id_valeur>', cmlv_id_valeur, '</cmlv_id_valeur>\n', 
	'<cmlv_ce_parent>', cmlv_ce_parent, '</cmlv_ce_parent>\n', 
	'<cmlv_ce_projet>', cmlv_ce_projet, '</cmlv_ce_projet>\n',
	'<cmlv_nom>', cmlv_nom, '</cmlv_nom>\n',
	'<cmlv_abreviation>', cmlv_abreviation, '</cmlv_abreviation>\n',
	'<cmlv_description>', cmlv_description, '</cmlv_description>\n',
	'<cmlv_ce_meta>', cmlv_ce_meta, '</cmlv_ce_meta>\n',
	'</row>\n',
	'</resultset>') AS xmldoc 
	FROM tb_coel.coel_meta_liste_valeur
	WHERE cmlv_id_valeur = @id_valeur;
UPDATE tb_coel.coel_meta_historique_ligne SET 
	cmhl_enregistrement = @enrg
	WHERE cmhl_id_historique_ligne = @id_meta;


#Correction bogue  FS#535 - [Collection] - Fautes de frappes
SET @notes = 'Correction syntaxe du nom.';

SET @id_valeur = '2295';
INSERT INTO tb_coel.coel_meta_historique_ligne (cmhl_ce_table, cmhl_cle_ligne, cmhl_enregistrement, cmhl_date_modification, cmhl_notes, cmhl_ce_modifier_par, cmhl_ce_etat ,cmhl_ip) 
	VALUES	(@id_table_cmlv, @id_valeur, NULL , NOW( ) , @notes, @id_admin, @id_etat_modif, @ip_admin);
SELECT @id_meta := cmhl_id_historique_ligne, cmhl_date_modification FROM tb_coel.coel_meta_historique_ligne WHERE cmhl_ce_table = CONVERT(@id_table_cmlv USING utf8) AND cmhl_cle_ligne = CONVERT(@id_valeur USING utf8) ORDER BY cmhl_date_modification DESC LIMIT 1;
UPDATE tb_coel.coel_meta_liste_valeur SET 
	cmlv_nom = 'Papier adhésif type scotch',  
	cmlv_ce_meta = @id_meta 
	WHERE cmlv_id_valeur = @id_valeur;
SELECT @enrg := CONCAT('<?xml version="1.0" encoding="UTF-8" ?>\n<resultset>\n',
	'<row>\n', 
	'<cmlv_id_valeur>', cmlv_id_valeur, '</cmlv_id_valeur>\n', 
	'<cmlv_ce_parent>', cmlv_ce_parent, '</cmlv_ce_parent>\n', 
	'<cmlv_ce_projet>', cmlv_ce_projet, '</cmlv_ce_projet>\n',
	'<cmlv_nom>', cmlv_nom, '</cmlv_nom>\n',
	'<cmlv_abreviation>', cmlv_abreviation, '</cmlv_abreviation>\n',
	'<cmlv_description>', cmlv_description, '</cmlv_description>\n',
	'<cmlv_ce_meta>', cmlv_ce_meta, '</cmlv_ce_meta>\n',
	'</row>\n',
	'</resultset>') AS xmldoc 
	FROM tb_coel.coel_meta_liste_valeur
	WHERE cmlv_id_valeur = @id_valeur;
UPDATE tb_coel.coel_meta_historique_ligne SET 
	cmhl_enregistrement = @enrg
	WHERE cmhl_id_historique_ligne = @id_meta;

SET @id_valeur = '2247';
INSERT INTO tb_coel.coel_meta_historique_ligne (cmhl_ce_table, cmhl_cle_ligne, cmhl_enregistrement, cmhl_date_modification, cmhl_notes, cmhl_ce_modifier_par, cmhl_ce_etat ,cmhl_ip) 
	VALUES	(@id_table_cmlv, @id_valeur, NULL , NOW( ) , @notes, @id_admin, @id_etat_modif, @ip_admin);
SELECT @id_meta := cmhl_id_historique_ligne, cmhl_date_modification FROM tb_coel.coel_meta_historique_ligne WHERE cmhl_ce_table = CONVERT(@id_table_cmlv USING utf8) AND cmhl_cle_ligne = CONVERT(@id_valeur USING utf8) ORDER BY cmhl_date_modification DESC LIMIT 1;
UPDATE tb_coel.coel_meta_liste_valeur SET 
	cmlv_nom = 'Gymnospermes (Conifère)',  
	cmlv_ce_meta = @id_meta 
	WHERE cmlv_id_valeur = @id_valeur;
SELECT @enrg := CONCAT('<?xml version="1.0" encoding="UTF-8" ?>\n<resultset>\n',
	'<row>\n', 
	'<cmlv_id_valeur>', cmlv_id_valeur, '</cmlv_id_valeur>\n', 
	'<cmlv_ce_parent>', cmlv_ce_parent, '</cmlv_ce_parent>\n', 
	'<cmlv_ce_projet>', cmlv_ce_projet, '</cmlv_ce_projet>\n',
	'<cmlv_nom>', cmlv_nom, '</cmlv_nom>\n',
	'<cmlv_abreviation>', cmlv_abreviation, '</cmlv_abreviation>\n',
	'<cmlv_description>', cmlv_description, '</cmlv_description>\n',
	'<cmlv_ce_meta>', cmlv_ce_meta, '</cmlv_ce_meta>\n',
	'</row>\n',
	'</resultset>') AS xmldoc 
	FROM tb_coel.coel_meta_liste_valeur
	WHERE cmlv_id_valeur = @id_valeur;
UPDATE tb_coel.coel_meta_historique_ligne SET 
	cmhl_enregistrement = @enrg
	WHERE cmhl_id_historique_ligne = @id_meta;

SET @id_valeur = '2248';
INSERT INTO tb_coel.coel_meta_historique_ligne (cmhl_ce_table, cmhl_cle_ligne, cmhl_enregistrement, cmhl_date_modification, cmhl_notes, cmhl_ce_modifier_par, cmhl_ce_etat ,cmhl_ip) 
	VALUES	(@id_table_cmlv, @id_valeur, NULL , NOW( ) , @notes, @id_admin, @id_etat_modif, @ip_admin);
SELECT @id_meta := cmhl_id_historique_ligne, cmhl_date_modification FROM tb_coel.coel_meta_historique_ligne WHERE cmhl_ce_table = CONVERT(@id_table_cmlv USING utf8) AND cmhl_cle_ligne = CONVERT(@id_valeur USING utf8) ORDER BY cmhl_date_modification DESC LIMIT 1;
UPDATE tb_coel.coel_meta_liste_valeur SET 
	cmlv_nom = 'Angiospermes (plantes à fleur)',  
	cmlv_ce_meta = @id_meta 
	WHERE cmlv_id_valeur = @id_valeur;
SELECT @enrg := CONCAT('<?xml version="1.0" encoding="UTF-8" ?>\n<resultset>\n',
	'<row>\n', 
	'<cmlv_id_valeur>', cmlv_id_valeur, '</cmlv_id_valeur>\n', 
	'<cmlv_ce_parent>', cmlv_ce_parent, '</cmlv_ce_parent>\n', 
	'<cmlv_ce_projet>', cmlv_ce_projet, '</cmlv_ce_projet>\n',
	'<cmlv_nom>', cmlv_nom, '</cmlv_nom>\n',
	'<cmlv_abreviation>', cmlv_abreviation, '</cmlv_abreviation>\n',
	'<cmlv_description>', cmlv_description, '</cmlv_description>\n',
	'<cmlv_ce_meta>', cmlv_ce_meta, '</cmlv_ce_meta>\n',
	'</row>\n',
	'</resultset>') AS xmldoc 
	FROM tb_coel.coel_meta_liste_valeur
	WHERE cmlv_id_valeur = @id_valeur;
UPDATE tb_coel.coel_meta_historique_ligne SET 
	cmhl_enregistrement = @enrg
	WHERE cmhl_id_historique_ligne = @id_meta;

# Correction bogue FS#645 - [BD] Nettoyage de CollectionACommentaire 
DELETE FROM tb_coel.coel_collection_a_commentaire 
	WHERE ccac_id_collection NOT IN (SELECT cc_id_collection FROM tb_coel.coel_collection);
