use strict;
return sub
{
	my $dbh = shift;

	
	my $moveField = sub
	{
		my ($t1, $t2, $f) = @_;
		
		my $sth = $dbh->prepare("select id, $f from $t1 where $f!=''");
		$sth->execute;
	
		while (my $row = $sth->fetchrow_hashref)
		{
			$dbh->do("update $t2 set $f=? where id=? and ($f='' or $f='0')", undef, $row->{$f}, $row->{id});
		}
	};
	
	for my $f (qw/sitename turboaffid help_url_forum help_url_helpdesk/)
	{
		&$moveField('jin_user', 'jin_merchant_settings', $f);
	}

	for my $f (qw/pg_paypal_email no_admin_mail no_upline_mail/)
	{
		&$moveField('jin_merchant_settings', 'jin_user', $f);
	}
	
	
	
	my $sth = $dbh->prepare("select id, template from jin_template where name='order_thank'");
	$sth->execute;
	
	while (my $row = $sth->fetchrow_hashref)
	{
		for ($row->{template})
		{
		s!<goth\:if\s+var=(?:["']|&quot;)?HasLocalMembership(?:["']|&quot;)?\>(.+?)</goth:if>!<goth:if var=HasMembership>
	<div class="jinOrderSectionTitle">Membership(s)</div>
	<div class="jinOrderSection">#{membership}</div>
</goth:if>!gs;
			s!<goth\:if\s+var=(?:["']|&quot;)?HasRemoteMembership(?:["']|&quot;)?\>(.+?)</goth:if>(?:\r?\n\r?\n)?!!s;
			s!<goth\:if\s+var=(?:["']|&quot;)?HasCMSMembership(?:["']|&quot;)?\>(.+?)</goth:if>(?:\r?\n\r?\n)?!!s;

		s!<goth\:if\s+var=(?:["']|&quot;)?HasRoles(?:["']|&quot;)?\>(.+?)</goth:if>!<goth:if var=HasProgram>
	<div class="jinOrderSectionTitle">Privileges & Programs</div>
	<div class="jinOrderSection">#{program}</div>
</goth:if>!gs;
			s!<goth\:if\s+var=(?:["']|&quot;)?HasAffiliatePrograms(?:["']|&quot;)?\>(.+?)</goth:if>(?:\r?\n\r?\n)?!!s;
			s!<goth\:if\s+var=(?:["']|&quot;)?HasResellingLicenses(?:["']|&quot;)?\>(.+?)</goth:if>(?:\r?\n\r?\n)?!!s;


			s!HasQuestionnaires!HasQuestionnaire!;
			s!#\{questionnaires\}!#{questionnaire}!;
		}
		
		$dbh->do("UPDATE jin_template SET template=".$dbh->quote($row->{template})." WHERE id=$row->{id}");

	}

	return;
};