use strict;

return sub
{
	my $dbh = shift;

	{
		my $sth = $dbh->prepare("select id from jin_helpticket where thread_id=0 and ticket_code=''");
		$sth->execute;

		my $sth1 = $dbh->prepare("update jin_helpticket set ticket_code=? where id=? or thread_id=?");

		my %codes;
		
		while (my $row = $sth->fetchrow_hashref)
		{
			my $code = '';
			
			while (! $code || $codes{$code})
			{
				$code =
					join('', map { chr(ord('A') + int(rand(26))) } 1..3) .
					'-' .
					join('', map { int(rand(10)) } 1..6);
			}
			
			$codes{$code} = 1;

			$sth1->execute($code, $row->{id}, $row->{id});
		}
	}

	return;
};


