# This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;

-- ---------------------------------------------------------------------
-- Mail templates for FedEx
-- ---------------------------------------------------------------------

-- First, delete existing entries
SET @var := 0;
SELECT @var := `id` FROM `message` WHERE name="mail_fedex";
DELETE FROM `message` WHERE `id`=@var;
-- Try if ON DELETE constraint isn't set
DELETE FROM `message_i18n` WHERE `id`=@var;

-- Then add new entries
SELECT @max := MAX(`id`) FROM `message`;
SET @max := @max+1;
-- insert message
INSERT INTO `message` (`id`, `name`, `secured`) VALUES
(@max,
'mail_fedex',
'0'
);

-- and template fr_FR
INSERT INTO `message_i18n` (`id`, `locale`, `title`, `subject`, `text_message`, `html_message`) VALUES
(@max,
 'en_US',
 'FedEx shipping message',
 'Your order {$order_ref} has been shipped',
 '{loop type="customer" name="customer.order" current="false" id="$customer_id" backend_context="1"}Dear {$FIRSTNAME} {$LASTNAME},\r\n\r\n{/loop}Thank you for your order {$order_ref} you placed on our online store {config key="store_name"} on {format_date date=$order_date output="date"}.\r\n\r\nYour order has been shipped on {format_date date=$update_date}.\r\nPlease check the FedEx website for tracking your parcel using this link : {$tracking_url}{$package}\r\n\r\nFeel free to contact us for any further information,\r\n\r\nBest Regards.',
 '<p>{loop type="customer" name="customer.order" current="false" id="$customer_id" backend_context="1"}Dear {$FIRSTNAME} {$LASTNAME},</p>{/loop}\r\n<p>Thank you for your order {$order_ref} you placed on our online store {config key="store_name"} on {format_date date=$order_date output="date"}.</p><p>Your order has been shipped on {format_date date=$update_date}.Please check the FedEx website for tracking your parcel using this link : <a href={$tracking_url}{$package}>{$tracking_url}{$package}</a></p><p>Feel free to contact us for any further information,</p><p>Best Regards.</p>'
 ),
(@max,
 'fr_FR',
 'Message d''expédition de FedEx',
 'Suivi FedEx commande : {$order_ref}',
 '{loop type="customer" name="customer.order" current="false" id="$customer_id" backend_context="1"}\r\nCher/chère {$LASTNAME} {$FIRSTNAME},\r\n{/loop}\r\n\r\nNous vous remercions de votre commande {$order_ref} effectuée sur notre site {config key="store_name"} le {format_date date=$order_date output="date"}.\r\n\r\nVotre colis a quitté nos entrepôts pour être pris en charge par FedEx le {format_date date=$update_date output="date"}.\r\nVous pouvez le suivre en ligne sur le site officiel de FedEx via ce lien : {$tracking_url}{$package}\r\n\r\nNous restons à votre disposition pour toute information complémentaire.\r\n\r\nCordialement\r\n',
 '<p>{loop type="customer" name="customer.order" current="false" id="$customer_id" backend_context="1"}\r\nCher/chère {$LASTNAME} {$FIRSTNAME},</p>{/loop}\r\n<p>Nous vous remercions de votre commande {$order_ref} effectuée sur notre site {config key="store_name"} le {format_date date=$order_date output="date"}.</p><br><p>Votre colis a quitté nos entrepôts pour être pris en charge par FedEx le {format_date date=$update_date output="date"}.Vous pouvez le suivre en ligne sur le site officiel de FedEx via ce lien : <a href={$tracking_url}{$package}>{$tracking_url}{$package}</a></p><p>Nous restons à votre disposition pour toute information complémentaire.</p><p>Cordialement</p>'
);

# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;
