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


	my $sth = $dbh->prepare("select id, welcomem_ids from jin_affprog where welcomem_ids!='' and email_welcome=''");
	$sth->execute;
	
	while (my $row = $sth->fetchrow_hashref)
	{
		my $sth1 = $dbh->prepare("select id, subject, message from jin_welcomemail where id=?");
		$sth1->execute((split ",", $row->{welcomem_ids})[0]);
		
		my $row1 = $sth1->fetchrow_hashref;
	
		$dbh->do("update jin_affprog set email_welcome=? where id=?", undef, "Subject: $row1->{subject}\n\n$row1->{message}", $row->{id});
	}
	
	$sth = $dbh->prepare("select id, welcomem_ids from jin_package where welcomem_ids!='' and email_welcome=''");
	$sth->execute;
	
	while (my $row = $sth->fetchrow_hashref)
	{
		my $sth1 = $dbh->prepare("select id, subject, message from jin_welcomemail where id=?");
		$sth1->execute((split ",", $row->{welcomem_ids})[0]);
		
		my $row1 = $sth1->fetchrow_hashref;
	
		$dbh->do("update jin_package set email_welcome=? where id=?", undef, "Subject: $row1->{subject}\n\n$row1->{message}", $row->{id});
	}
	
	$sth = $dbh->prepare("select id, welcomem_ma2cust_ids from jin_user_settings where welcomem_ma2cust_ids!='' and email_ma2cust=''");
	$sth->execute;
	
	while (my $row = $sth->fetchrow_hashref)
	{
		my $sth1 = $dbh->prepare("select id, subject, message from jin_welcomemail where id=?");
		$sth1->execute((split ",", $row->{welcomem_ma2cust_ids})[0]);
		
		my $row1 = $sth1->fetchrow_hashref;
	
		$dbh->do("update jin_user_settings set email_ma2cust=? where id=?", undef, "Subject: $row1->{subject}\n\n$row1->{message}", $row->{id});
	}
	
	$sth = $dbh->prepare("select id, welcomem_me2refered_ids from jin_user_settings where welcomem_me2refered_ids!='' and email_me2refered=''");
	$sth->execute;
	
	while (my $row = $sth->fetchrow_hashref)
	{
		my $sth1 = $dbh->prepare("select id, subject, message from jin_welcomemail where id=?");
		$sth1->execute((split ",", $row->{welcomem_me2refered_ids})[0]);
		
		my $row1 = $sth1->fetchrow_hashref;
	
		$dbh->do("update jin_user_settings set email_me2refered=? where id=?", undef, "Subject: $row1->{subject}\n\n$row1->{message}", $row->{id});
	}
	
	

	my $sth = $dbh->prepare("select id, owner_id from jin_cmsmem where email_access=''");
	$sth->execute;
	
	while (my $row = $sth->fetchrow_hashref)
	{
		my $sth1 = $dbh->prepare("select id, owner_id, access_cmsmem from jin_embedded_email where owner_id=?");
		$sth1->execute($row->{owner_id});
		
		my $row1 = $sth1->fetchrow_hashref;
		
		$dbh->do("update jin_cmsmem set email_access=? where id=?", undef, $row1->{access_cmsmem}, $row->{id});
	}
	
	$sth = $dbh->prepare("select id, owner_id from jin_lmem where email_access=''");
	$sth->execute;
	
	while (my $row = $sth->fetchrow_hashref)
	{
		my $sth1 = $dbh->prepare("select id, owner_id, access_lmem from jin_embedded_email where owner_id=?");
		$sth1->execute($row->{owner_id});
		
		my $row1 = $sth1->fetchrow_hashref;
		
		$dbh->do("update jin_lmem set email_access=? where id=?", undef, $row1->{access_lmem}, $row->{id});
	}
	
	$sth = $dbh->prepare("select id, owner_id from jin_rmem where email_access=''");
	$sth->execute;
	
	while (my $row = $sth->fetchrow_hashref)
	{
		my $sth1 = $dbh->prepare("select id, owner_id, access_rmem from jin_embedded_email where owner_id=?");
		$sth1->execute($row->{owner_id});
		
		my $row1 = $sth1->fetchrow_hashref;
		
		$dbh->do("update jin_rmem set email_access=? where id=?", undef, $row1->{access_rmem}, $row->{id});
	}

	
	my $sth = $dbh->prepare("select id, plugin, cfgtext from jin_ext_script where cfgtext!='' and plugin='ExtScriptInvisionPB' or plugin='ExtScriptPhpBB' or plugin='ExtScriptSMF' or plugin='ExtScriptVBulletin'");
	$sth->execute;
	
	while (my $row = $sth->fetchrow_hashref)
	{
		$dbh->do("update jin_ext_script set cfgtext=? where id=?", undef, join(':', map { split('=', $_, 2) } grep { length($_) && ! /^\#/ } split(/\r?\n/, $row->{cfgtext})), $row->{id});
	}


	my $sth = $dbh->prepare("select id, owner_id from jin_coupon where email_cust=''");
	$sth->execute;
	
	while (my $row = $sth->fetchrow_hashref)
	{
		my $sth1 = $dbh->prepare("select id, owner_id, coupon_cust from jin_embedded_email where owner_id=?");
		$sth1->execute($row->{owner_id});
		
		my $row1 = $sth1->fetchrow_hashref;
		
		$dbh->do("update jin_coupon set email_cust=? where id=?", undef, $row1->{coupon_cust}, $row->{id});
	}
	

	$sth = $dbh->prepare("select id, owner_id from jin_coupon where email_aff=''");
	$sth->execute;
	
	while (my $row = $sth->fetchrow_hashref)
	{
		my $sth1 = $dbh->prepare("select id, owner_id, coupon_aff from jin_embedded_email where owner_id=?");
		$sth1->execute($row->{owner_id});
		
		my $row1 = $sth1->fetchrow_hashref;
		
		$dbh->do("update jin_coupon set email_aff=? where id=?", undef, $row1->{coupon_aff}, $row->{id});
	}
	
	
	$sth = $dbh->prepare("select currency from jin_sys_cfg");
	$sth->execute;
	my $row = $sth->fetchrow_hashref;
	my $currency = $row ? $row->{currency} : 'USD';
	
	$dbh->do("update jin_user_settings set currency=? where currency=''", undef, $currency);
	
};