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