Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-10-02-11-18-44
[civicrm-core.git] / CRM / Upgrade / 4.2.alpha1.msg_template / civicrm_msg_template.tpl
1 {php}
2 $dir = SMARTY_DIR . '/../../CRM/Upgrade/4.2.alpha1.msg_template/message_templates';
3
4 $ovNames = array(
5 'contribution' => array(
6 'contribution_recurring_cancelled' => ts('Contributions - Recurring Cancellation Notification', array('escape' => 'sql')),
7 'contribution_recurring_billing' => ts('Contributions - Recurring Billing Updates', array('escape' => 'sql')),
8 'contribution_recurring_edit' => ts('Contributions - Recurring Updates', array('escape' => 'sql')),
9 ),
10 'membership' => array(
11 'membership_autorenew_cancelled' => ts('Memberships - Auto-renew Cancellation Notification', array('escape' => 'sql')),
12 'membership_autorenew_billing' => ts('Memberships - Auto-renew Billing Updates', array('escape' => 'sql')),
13 ),
14 );
15
16 $ignoreTemplate = array_merge(array_keys($ovNames['contribution']), array_keys($ovNames['membership']));
17
18 $this->assign('ovNames', $ovNames);
19 $this->assign('dir', $dir);
20 $templates = array();
21 foreach (preg_grep('/\.tpl$/', scandir($dir)) as $filename) {
22 $parts = explode('_', basename($filename, '.tpl'));
23 $type = array_pop($parts);
24 $name = implode('_', $parts);
25 if (!in_array($name,$ignoreTemplate)) {
26 $templates[] = array('type' => $type, 'name' => $name, 'filename' => "$dir/$filename");
27 }
28 }
29 $this->assign('templates', $templates);
30 {/php}
31
32 {foreach from=$templates item=tpl}
33 {fetch assign=content file=$tpl.filename}
34 SELECT @workflow_id := MAX(id) FROM civicrm_option_value WHERE name = '{$tpl.name}';
35 SELECT @content := msg_{$tpl.type} FROM civicrm_msg_template WHERE workflow_id = @workflow_id AND is_reserved = 1 LIMIT 1;
36 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));
37 {/foreach}
38
39 {foreach from=$ovNames key=name item=ignore}
40 SELECT @tpl_ogid_{$name} := MAX(id) FROM civicrm_option_group WHERE name = 'msg_tpl_workflow_{$name}';
41 {/foreach}
42
43 INSERT INTO civicrm_option_value
44 (option_group_id, name, {localize field='label'}label{/localize}, value, weight) VALUES
45 {foreach from=$ovNames key=gName item=ovs name=for_groups}
46 {foreach from=$ovs key=vName item=label name=for_values}
47 (@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}
48 {/foreach}
49 {/foreach}
50
51 {foreach from=$ovNames key=gName item=ovs}
52 {foreach from=$ovs key=vName item=label}
53 SELECT @tpl_ovid_{$vName} := MAX(id) FROM civicrm_option_value WHERE option_group_id = @tpl_ogid_{$gName} AND name = '{$vName}';
54 {/foreach}
55 {/foreach}
56
57 INSERT INTO civicrm_msg_template
58 (msg_title, msg_subject, msg_text, msg_html, workflow_id, is_default, is_reserved) VALUES
59 {foreach from=$ovNames key=gName item=ovs name=for_groups}
60 {foreach from=$ovs key=vName item=title name=for_values}
61 {fetch assign=subject file="`$smarty.const.SMARTY_DIR`/../../CRM/Upgrade/4.2.alpha1.msg_template/message_templates/`$vName`_subject.tpl"}
62 {fetch assign=text file="`$smarty.const.SMARTY_DIR`/../../CRM/Upgrade/4.2.alpha1.msg_template/message_templates/`$vName`_text.tpl"}
63 {fetch assign=html file="`$smarty.const.SMARTY_DIR`/../../CRM/Upgrade/4.2.alpha1.msg_template/message_templates/`$vName`_html.tpl"}
64 ('{$title}', '{$subject|escape:"quotes"}', '{$text|escape:"quotes"}', '{$html|escape:"quotes"}', @tpl_ovid_{$vName}, 1, 0),
65 ('{$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}
66 {/foreach}
67 {/foreach}