-- /*******************************************************
-- *
-- * Select DomainID
-- *
-- *******************************************************/
	SELECT @domain_id := id from civicrm_domain;

-- /*******************************************************
-- *
-- * civicrm_mailing_spool
-- *
-- *******************************************************/
CREATE TABLE civicrm_mailing_spool (


     id int(10) unsigned NOT NULL AUTO_INCREMENT  COMMENT '',
     domain_id int(10) unsigned NOT NULL COMMENT 'The ID of the civicrm domain.',
     job_id int(10) unsigned NOT NULL COMMENT 'The ID of the Job .',
     recipient_email text NULL DEFAULT NULL COMMENT 'The email of the receipients this mail is to be sent.',
     headers text NULL DEFAULT NULL COMMENT 'The header information of this mailing .',
     body text NULL DEFAULT NULL COMMENT 'The body of this mailing.', 
     added_at datetime NULL DEFAULT NULL COMMENT 'date on which this job was added.', 
     removed_at datetime NULL DEFAULT NULL COMMENT 'date on which this job was removed.'
,
    PRIMARY KEY ( id )
,      
     CONSTRAINT FK_civicrm_mailing_spool_domain_id FOREIGN KEY (domain_id) REFERENCES civicrm_domain(id)

,    CONSTRAINT FK_civicrm_mailing_spool_job_id FOREIGN KEY (job_id) REFERENCES civicrm_mailing_job(id)

)  ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci  ;


-- /*******************************************************
-- *
-- * Modifying Tables
-- *
-- *******************************************************/

-- /*******************************************************
-- *
-- * civicrm_email
-- *
-- *******************************************************/
	ALTER TABLE civicrm_email 
	    ADD is_bulkmail tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Is this address for bulk mail ?';

-- /*******************************************************
-- *
-- * civicrm_payment_processor_type
-- *
-- *******************************************************/

	ALTER TABLE civicrm_payment_processor_type
	     DROP INDEX UI_name,
	     ADD UNIQUE INDEX UI_name_domain_id( name, domain_id );
  

-- /*******************************************************
-- *
-- * civicrm_domain
-- *
-- *******************************************************/
	ALTER TABLE civicrm_domain 
	    ADD email_name varchar(255) NULL DEFAULT NULL COMMENT 'The default email name that is used in the from address for all outgoing emails',
            ADD email_address varchar(255) NULL DEFAULT NULL COMMENT 'The default email address that is used as the from address for all outgoing emails',
	    DROP contact_name;

    UPDATE `civicrm_domain` SET `email_name`='FIXME';	
    UPDATE `civicrm_domain` SET `email_address`='info@FIXME.ORG';	
    UPDATE `civicrm_domain` SET `email_domain`='FIXME.ORG';
	
-- /*******************************************************
-- *
-- * civicrm_mailing_job
-- *
-- *******************************************************/
	ALTER TABLE civicrm_mailing_job 
	    ADD is_test tinyint(4) DEFAULT 0 COMMENT 'Is this job for a test mail?',
	    DROP is_retry;
        
    UPDATE civicrm_mailing_job
    SET    is_test = 0;
    

-- /*******************************************************
-- *
-- * civicrm_currency
-- *
-- *******************************************************/
	ALTER TABLE civicrm_currency 
	    ADD numeric_code varchar(3) NULL DEFAULT NULL COMMENT 'Numeric currency code',
            ADD full_name varchar(64) NULL DEFAULT NULL COMMENT 'Full currency name';
           
-- /*******************************************************
-- *
-- * civicrm_mailing
-- *
-- *******************************************************/
	ALTER TABLE civicrm_mailing
        ADD resubscribe_id int(10) unsigned NOT NULL,
	ADD msg_template_id int(10) unsigned NULL DEFAULT NULL ,
    	ADD CONSTRAINT FK_civicrm_mailing_msg_template_id FOREIGN KEY (msg_template_id) REFERENCES civicrm_msg_template(id),
    	DROP is_template;

-- /*******************************************************
-- *
-- * civicrm_mailing_component
-- *
-- *******************************************************/
	ALTER TABLE civicrm_mailing_component
	MODIFY component_type enum('Header','Footer','Subscribe','Welcome','Unsubscribe','OptOut','Reply','Resubscribe') NULL DEFAULT NULL;

-- /*******************************************************
-- *
-- * civicrm_group
-- *
-- *******************************************************/
	ALTER TABLE civicrm_group 
	    ADD group_type varchar(128) NULL DEFAULT NULL COMMENT 'FK to group type',
            ADD INDEX index_group_type (group_type);

-- /*******************************************************
-- *
-- * civicrm_contribution_page
-- *
-- *******************************************************/
	ALTER TABLE civicrm_contribution_page 
	    MODIFY default_amount_id int(10) unsigned NULL DEFAULT NULL COMMENT 'FK to civicrm_custom_option.';

-- /*******************************************************
-- *
-- * CRM-2260
-- *
-- *******************************************************/

	REPLACE 
  	  civicrm_currency (id, name, symbol, numeric_code, full_name) 
	VALUES
	  (  1, "AUD",  "$", "036", "Australian Dollar"),
	  (  2, "CAD",  "$", "124", "Canadian Dollar"),
	  (  3, "EUR",  "€", "978", "Euro"),
	  (  4, "GBP",  "£", "826", "Pound Sterling"),
	  (  5, "ILS",  "₪", "826", "New Israeli Shekel"),
	  (  6, "INR",  "₨", "356", "Indian Rupee"),
	  (  7, "JPY",  "¥", "392", "Japanese Yen"),
	  (  8, "KRW",  "₩", "410", "South Korean Won"),
	  (  9, "LAK",  "₭", "418", "Lao Kip"),
	  ( 10, "MNT",  "₮", "496", "Mongolian Tugrik"),
 	  ( 11, "NGN",  "₦", "566", "Nigerian Naira"),
	  ( 12, "PLN", "zł", "985", "Polish Złoty"),
	  ( 13, "THB",  "฿", "764", "Thai Baht"),
	  ( 14, "USD",  "$", "840", "US Dollar"),
	  ( 15, "VND",  "₫", "704", "Viet Nam Dong"),
	  ( 16, "ZAR",  "R", "710", "South African Rand"),
	  ( 17, "AED", NULL, "784", "UAE Dirham"),
	  ( 18, "AFN",  "؋", "971", "Afghani"),
	  ( 19, "ALL","Lek", "008", "Albanian Lek"),
	  ( 20, "AMD", NULL, "051", "Armenian Dram"),
	  ( 21, "ANG",  "ƒ", "532", "Netherlands Antillian Guilder"),
	  ( 22, "AOA", NULL, "973", "Angola Kwanza"),
	  ( 23, "ARS",  "$", "032", "Argentine Peso"),
	  ( 24, "AWG",  "ƒ", "533", "Aruban Guilder"),
	  ( 25, "AZN","ман", "944", "Azerbaijanian Manat"),
	  ( 26, "BAM", "KM", "977", "Convertible Marks"),
	  ( 27, "BBD",  "$", "052", "Barbados Dollar"),
	  ( 28, "BDT", NULL, "050", "Bangladeshi Taka"),
  	  ( 29, "BGN", "лв", "975", "Bulgarian Lev"),
	  ( 30, "BHD", NULL, "048", "Bahraini Dinar"),
	  ( 31, "BIF", NULL, "108", "Burundi Franc"),
  	  ( 32, "BMD",  "$", "060", "Bermudian Dollar"),
	  ( 33, "BND",  "$", "096", "Brunei Dollar"),
	  ( 34, "BOB", "$b", "068", "Boliviano"),
	  ( 35, "BOV", NULL, "984", "Bolivian Mvdol"),
	  ( 36, "BRL", "R$", "986", "Brazilian Real"),
	  ( 37, "BSD",  "$", "044", "Bahamian Dollar"),
	  ( 38, "BTN", NULL, "064", "Bhutan Ngultrum"),
	  ( 39, "BWP",  "P", "072", "Botswana Pula"),
	  ( 40, "BYR", "p.", "974", "Belarussian Rouble"),
	  ( 41, "BZD","BZ$", "084", "Belize Dollar"),
	  ( 42, "CDF", NULL, "976", "Franc Congolais"),
	  ( 43, "CHE", NULL, "947", "WIR Euro"),
	  ( 44, "CHF","CHF", "756", "Swiss Franc"),
	  ( 45, "CHW", NULL, "948", "WIR Franc"),
	  ( 46, "CLF", NULL, "990", "Unidades de fomento"),
	  ( 47, "CLP",  "$", "152", "Chilean Peso"),
	  ( 48, "CNY", "å
", "156", "Chinese Yuan Renminbi"),
	  ( 49, "COP",  "$", "170", "Colombian Peso"),
	  ( 50, "COU", NULL, "970", "Unidad de Valor Real"),
	  ( 51, "CRC",  "₡", "188", "Costa Rican Colon"),
	  ( 52, "CSD","Дин.","891", "Serbian Dinar"),
	  ( 53, "CUP",  "₱", "192", "Cuban Peso"),
	  ( 54, "CVE", NULL, "132", "Cape Verde Escudo"),
	  ( 55, "CYP",  "£", "196", "Cyprus Pound"),
	  ( 56, "CZK", "Kč", "203", "Czech Koruna"),
	  ( 57, "DJF", NULL, "262", "Djibouti Franc"),
	  ( 58, "DKK", "kr", "208", "Danish Krone"),
	  ( 59, "DOP","RD$", "214", "Dominican Peso"),
	  ( 60, "DZD", NULL, "012", "Algerian Dinar"),
	  ( 61, "EEK", "kr", "233", "Estonian Kroon"),
	  ( 62, "EGP",  "£", "818", "Egyptian Pound"),
	  ( 63, "ERN", NULL, "232", "Eritrean Nakfa"),
	  ( 64, "ETB", NULL, "230", "Ethiopian Birr"),
	  ( 65, "FJD",  "$", "242", "Fiji Dollar"),
	  ( 66, "FKP",  "£", "238", "Falkland Islands Pound"),
	  ( 67, "GEL", NULL, "981", "Georgian Lari"),
	  ( 68, "GHC",  "¢", "288", "Ghanaian Cedi"),
	  ( 69, "GIP",  "£", "292", "Gibraltar Pound"),
	  ( 70, "GMD", NULL, "270", "Gambian Dalasi"),
	  ( 71, "GNF", NULL, "324", "Guinea Franc"),
	  ( 72, "GTQ",  "Q", "320", "Guatemalan Quetzal"),
	  ( 73, "GWP", NULL, "624", "Guinea-Bissau Peso"),
	  ( 74, "GYD",  "$", "328", "Guyana Dollar"),
	  ( 75, "HKD","HK$", "344", "Hong Kong Dollar"),
	  ( 76, "HNL",  "L", "340", "Honduran Lempira"),
	  ( 77, "HRK", "kn", "191", "Croatian Kuna"),
	  ( 78, "HTG", NULL, "332", "Haitian Gourde"),
	  ( 79, "HUF", "Ft", "348", "Hungarian Forint"),
	  ( 80, "IDR", "Rp", "360", "Indonesian Rupiah"),
	  ( 81, "IQD", NULL, "368", "Iraqi Dinar"),
	  ( 82, "IRR",  "﷼", "364", "Iranian Rial"),
	  ( 83, "ISK", "kr", "352", "Iceland Krona"),
	  ( 84, "JMD", "J$", "388", "Jamaican Dollar"),
	  ( 85, "JOD", NULL, "400", "Jordanian Dinar"),
	  ( 86, "KES", NULL, "404", "Kenyan Shilling"),
	  ( 87, "KGS", "лв", "417", "Kyrgyzstan Som"),
	  ( 88, "KHR",  "៛", "116", "Cambodian Riel"),
	  ( 89, "KMF", NULL, "174", "Comoro Franc"),
	  ( 90, "KPW",  "₩", "408", "North Korean Won"),
	  ( 91, "KWD", NULL, "414", "Kuwaiti Dinar"),
	  ( 92, "KYD",  "$", "136", "Cayman Islands Dollar"),
	  ( 93, "KZT", "лв", "398", "Kazakhstan Tenge"),
	  ( 94, "LBP",  "£", "422", "Lebanese Pound"),
	  ( 95, "LKR",  "₨", "144", "Sri Lanka Rupee"),
	  ( 96, "LRD",  "$", "430", "Liberian Dollar"),
	  ( 97, "LSL", NULL, "426", "Lesotho Loti"),
	  ( 98, "LTL", "Lt", "440", "Lithuanian Litas"),
	  ( 99, "LVL", "Ls", "428", "Latvian Lats"),
	  (100, "LYD", NULL, "434", "Libyan Dinar"),
	  (101, "MAD", NULL, "504", "Moroccan Dirham"),
	  (102, "MDL", NULL, "498", "Moldovan Leu"),
	  (103, "MGA", NULL, "969", "Malagascy Ariary"),
	  (104, "MKD","ден", "807", "Macedonian Denar"),
	  (105, "MMK", NULL, "104", "Myanmar Kyat"),
	  (106, "MOP", NULL, "446", "Macao Pataca"),
	  (107, "MRO", NULL, "478", "Mauritanian Ouguiya"),
	  (108, "MTL", "Lm", "470", "Maltese Lira"),
	  (109, "MUR",  "₨", "480", "Mauritius Rupee"),
	  (110, "MVR", NULL, "462", "Maldive Rufiyaa"),
	  (111, "MWK", NULL, "454", "Malawi Kwacha"),
	  (112, "MXN",  "$", "484", "Mexican Peso"),
	  (113, "MXV", NULL, "979", "Mexican Unidad de Inversion (UID)"),
 	  (114, "MYR", "RM", "458", "Malaysian Ringgit"),
  	  (115, "MZN", "MT", "943", "Mozambique Metical"),
	  (116, "NAD",  "$", "516", "Namibian Dollar"),
	  (117, "NIO", "C$", "558", "Nicaraguan Cordoba Oro"),
	  (118, "NOK", "kr", "578", "Norwegian Krone"),
	  (119, "NPR",  "₨", "524", "Nepalese Rupee"),
	  (120, "NZD",  "$", "554", "New Zealand Dollar"),
	  (121, "OMR",  "﷼", "512", "Rial Omani"),
	  (122, "PAB","B/.", "590", "Panamanian Balboa"),
	  (123, "PEN","S/.", "604", "Peruvian Nuevo Sol"),
	  (124, "PGK", NULL, "598", "Papua New Guinea Kina"),
	  (125, "PHP","Php", "608", "Philippine Peso"),
	  (126, "PKR",  "₨", "586", "Pakistan Rupee"),
	  (127, "PYG", "Gs", "600", "Paraguay Guarani"),
	  (128, "QAR",  "﷼", "634", "Qatari Rial"),
	  (129, "ROL", NULL, "642", "Romanian Old Leu"),
	  (130, "RON","lei", "946", "Romanian New Leu"),
	  (131, "RUB","руб", "643", "Russian Rouble"),
	  (132, "RWF", NULL, "646", "Rwanda Franc"),
	  (133, "SAR",  "﷼", "682", "Saudi Riyal"),
	  (134, "SBD",  "$", "090", "Solomon Islands Dollar"),
	  (135, "SCR",  "₨", "690", "Seychelles Rupee"),
	  (136, "SDD", NULL, "736", "Sudanese Dinar"),
  	  (137, "SEK", "kr", "752", "Swedish Krona"),
	  (138, "SGD",  "$", "702", "Singapore Dollar"),
	  (139, "SHP",  "£", "654", "Saint Helena Pound"),
	  (140, "SIT", NULL, "705", "Slovenian Tolar"),
	  (141, "SKK","SIT", "703", "Slovak Koruna"),
	  (142, "SLL", NULL, "694", "Leone"),
	  (143, "SOS",  "S", "706", "Somali Shilling"),
	  (144, "SRD",  "$", "968", "Surinam Dollar"),
	  (145, "STD", NULL, "678", "São Tome and Principe Dobra"),
	  (146, "SVC",  "$", "222", "El Salvador Colon"),
	  (147, "SYP",  "£", "760", "Syrian Pound"),
	  (148, "SZL", NULL, "748", "Swaziland Lilangeni"),
	  (149, "TJS", NULL, "972", "Tajik Somoni"),
	  (150, "TMM", NULL, "795", "Turkmenistan Manat"),
	  (151, "TND", NULL, "788", "Tunisian Dinar"),
	  (152, "TOP", NULL, "776", "Tongan Pa'anga"),
	  (153, "TRY","YTL", "949", "New Turkish Lira"),
	  (154, "TTD","TT$", "780", "Trinidad and Tobago Dollar"),
	  (155, "TWD","NT$", "901", "New Taiwan Dollar"),
	  (156, "TZS", NULL, "834", "Tanzanian Shilling"),
	  (157, "UAH",  "₴", "980", "Ukrainian Hryvnia"),
	  (158, "UGX", NULL, "800", "Ugandan Shilling"),
	  (159, "USN", NULL, "997", "US Dollar (Next day)"),
	  (160, "USS", NULL, "998", "US Dollar (Same day)"),
	  (161, "UYU", "$U", "858", "Peso Uruguayo"),
	  (162, "UZS", "лв", "860", "Uzbekistan Sum"),
	  (163, "VEB", "Bs", "862", "Venezuela Bolivar"),
	  (164, "VUV", NULL, "548", "Vanuatu Vatu"),
	  (165, "WST", NULL, "882", "Samoan Tala"),
	  (166, "XAF", NULL, "950", "CFA Franc BEAC"),
	  (167, "XAG", NULL, "961", "Silver"),
	  (168, "XAU", NULL, "959", "Gold"),
	  (169, "XBA", NULL, "955", "Bond Markets Units European Composite Unit (EURCO)"),
	  (170, "XBB", NULL, "956", "European Monetary Unit (E.M.U.-6)"),
	  (171, "XBC", NULL, "957", "European Unit of Account 9 (E.U.A.-9)"),
	  (172, "XBD", NULL, "958", "European Unit of Account 17 (E.U.A.-17)"),
	  (173, "XCD",  "$", "951", "East Caribbean Dollar"),
	  (174, "XDR", NULL, "960", "Special Drawing Right"),
	  (175, "XFO", NULL,  NULL, "Gold-Franc"),
	  (176, "XFU", NULL,  NULL, "UIC-Franc"),
	  (177, "XOF", NULL, "952", "CFA Franc BCEAO"),
	  (178, "XPD", NULL, "964", "Palladium"),
	  (179, "XPF", NULL, "953", "CFP Franc"),
	  (180, "XPT", NULL, "962", "Platinum"),
	  (181, "XTS", NULL, "963", "Code for testing purposes"),
	  (182, "XXX", NULL, "999", "No currency involved"),
	  (183, "YER",  "﷼", "886", "Yemeni Rial"),
	  (184, "ZMK", NULL, "894", "Zambian Kwacha"),
	  (185, "ZWD", "Z$", "716", "Zimbabwe Dollar");


-- /*******************************************************
-- *
-- * civicrm_option_group and civicrm_option_value
-- *
-- *******************************************************/

	INSERT INTO `civicrm_option_group` (`domain_id`, `name`, `description`, `is_reserved`, `is_active`) 
	VALUES  
	      (@domain_id, 'group_type', 'Group Type', 0, 1);
	

	SELECT @option_group_id_gType := max(id) from civicrm_option_group where name = 'group_type';

	INSERT INTO 
	   civicrm_option_value (option_group_id, label, value, name, grouping, filter, is_default, weight, description, is_optgroup, is_reserved, is_active) 
	VALUES
	  (@option_group_id_gType, 'Access Control'  , 1, NULL, NULL, 0, NULL, 1, NULL, 0, 1, 1 ),
	  (@option_group_id_gType, 'Mailing List'    , 2, NULL, NULL, 0, NULL, 2, NULL, 0, 1, 1 );


-- /*******************************************************
-- *
-- * civicrm_payment_processor_type (new processor plugins)
-- *
-- *******************************************************/
    INSERT INTO 
        civicrm_payment_processor_type (domain_id, name, title, description, is_active, is_default, user_name_label, password_label, signature_label, subject_label, class_name, url_site_default, url_recur_default, url_button_default, url_site_test_default, url_recur_test_default, url_button_test_default, billing_mode, is_recur )
    VALUES 
        (@domain_id,'PayJunction','PayJunction',NULL,1,0,'User Name','Password',NULL,NULL,'Payment_PayJunction','https://payjunction.com/quick_link',NULL,NULL,'https://payjunction.com/quick_link',NULL,NULL,1,0);


-- /*******************************************************
-- *
-- * civicrm_mailing_component
-- *
-- *******************************************************/

	INSERT IGNORE INTO
      civicrm_mailing_component (domain_id, name, component_type, subject, body_html, body_text, is_default, is_active)
	VALUES
          (@domain_id, 'Resubscribe Message', 'Resubscribe', 'Re-subscribe Confirmation', 'You have been re-subscribed to the following groups: {resubscribe.group}. You can un-subscribe by mailing {action.unsubscribe} or clicking {action.unsubscribeUrl}', 'You have been re-subscribed to the following groups: {resubscribe.group}. You can un-subscribe by mailing {action.unsubscribe} or clicking {action.unsubscribeUrl}', 1, 1);

-- /*******************************************************
-- *
-- * CRM-2349
-- *
-- *******************************************************/
    UPDATE civicrm_state_province SET name = 'Torfaen' WHERE name = 'Torfasn';

-- /*******************************************************
-- *
-- * fix Google Checkout URL
-- *
-- *******************************************************/
    UPDATE civicrm_payment_processor_type SET url_site_test_default = 'https://sandbox.google.com/checkout/' WHERE name = 'Google_Checkout';

