Merge pull request #2452 from totten/lolas-freeform-CRM-14126
[civicrm-core.git] / CRM / Upgrade / 4.5.alpha1.msg_template / civicrm_msg_template.tpl
1 {php}
2 $dir = SMARTY_DIR . '/../../CRM/Upgrade/4.5.alpha1.msg_template/message_templates';
3 $templates = array();
4 foreach (preg_grep('/\.tpl$/', scandir($dir)) as $filename) {
5 $parts = explode('_', basename($filename, '.tpl'));
6 $templates[] = array('type' => array_pop($parts), 'name' => implode('_', $parts), 'filename' => "$dir/$filename");
7 }
8 $this->assign('templates', $templates);
9 {/php}
10
11 {foreach from=$templates item=tpl}
12 {fetch assign=content file=$tpl.filename}
13 SELECT @workflow_id := MAX(id) FROM civicrm_option_value WHERE name = '{$tpl.name}';
14 SELECT @content := msg_{$tpl.type} FROM civicrm_msg_template WHERE workflow_id = @workflow_id AND is_reserved = 1 LIMIT 1;
15 UPDATE civicrm_msg_template SET msg_{$tpl.type} = '{$content|escape:"quotes"}' WHERE workflow_id = @workflow_id AND (is_reserved = 1 OR (is_default = 1 AND msg_{$tpl.type} = @content));
16 {/foreach}
17
18 $ovNames = array(
19 'contribution' => array(
20 'payment_or_refund_notification' => ts('Additional Payment Receipt or Refund Notification', array('escape' => 'sql')),
21 ),
22 );
23
24 $this->assign('ovNames', $ovNames);
25 $this->assign('dir', $dir);
26 {/php}
27
28 {foreach from=$ovNames key=name item=ignore}
29 SELECT @tpl_ogid_{$name} := MAX(id) FROM civicrm_option_group WHERE name = 'msg_tpl_workflow_{$name}';
30 {/foreach}
31
32 INSERT INTO civicrm_option_value
33 (option_group_id, name, {localize field='label'}label{/localize}, value, weight) VALUES
34 {foreach from=$ovNames key=gName item=ovs name=for_groups}
35 {foreach from=$ovs key=vName item=label name=for_values}
36 (@tpl_ogid_{$gName}, '{$vName}', {localize}'{$label}'{/localize}, {$smarty.foreach.for_values.iteration}, {$smarty.foreach.for_values.iteration}) {if $smarty.foreach.for_groups.last and $smarty.foreach.for_values.last};{else},{/if}
37 {/foreach}
38 {/foreach}
39
40 {foreach from=$ovNames key=gName item=ovs}
41 {foreach from=$ovs key=vName item=label}
42 SELECT @tpl_ovid_{$vName} := MAX(id) FROM civicrm_option_value WHERE option_group_id = @tpl_ogid_{$gName} AND name = '{$vName}';
43 {/foreach}
44 {/foreach}
45
46 INSERT INTO civicrm_msg_template
47 (msg_title, msg_subject, msg_text, msg_html, workflow_id, is_default, is_reserved) VALUES
48 {foreach from=$ovNames key=gName item=ovs name=for_groups}
49 {foreach from=$ovs key=vName item=title name=for_values}
50 {fetch assign=subject file="`$smarty.const.SMARTY_DIR`/../../CRM/Upgrade/4.5.alpha1.msg_template/message_templates/`$vName`_subject.tpl"}
51 {fetch assign=text file="`$smarty.const.SMARTY_DIR`/../../CRM/Upgrade/4.5.alpha1.msg_template/message_templates/`$vName`_text.tpl"}
52 {fetch assign=html file="`$smarty.const.SMARTY_DIR`/../../CRM/Upgrade/4.5.alpha1.msg_template/message_templates/`$vName`_html.tpl"}
53 ('{$title}', '{$subject|escape:"quotes"}', '{$text|escape:"quotes"}', '{$html|escape:"quotes"}', @tpl_ovid_{$vName}, 1, 0),
54 ('{$title}', '{$subject|escape:"quotes"}', '{$text|escape:"quotes"}', '{$html|escape:"quotes"}', @tpl_ovid_{$vName}, 0, 1) {if $smarty.foreach.for_groups.last and $smarty.foreach.for_values.last};{else},{/if}
55 {/foreach}
56 {/foreach}