Revision 296 (by ahitrov, 2013/03/26 17:59:01) Promosite (anthill) project source
<%args>

	$voting	=> undef
	$quest	=> undef
	$filled	=> undef

</%args>
<%init>
  return	unless ref $voting;

  my $CP = 'UTF8';
  my $to = $voting->email;
  my $error;
  my $errstr;
  my $testresult;


  $testresult = 1;
  foreach ( 1 .. $quest->{question_amount} ) {
	my $index = 'r'.$_;
	if ( !exists $ARGS{$index} ) {
		$testresult = 0;
	} elsif ( exists $ARGS{$index} && $ARGS{$index} != $quest->{questions}->[$_-1]->{right} ) {
		$testresult = 0;
	}
  }

  if ( $testresult ) {
	$CP = 'ISO'		if Convert::Cyrillic::cstocs('ISO', 'UTF8', $filled) eq 'Ответить';
	$CP = 'KOI8'		if Convert::Cyrillic::cstocs('KOI8', 'UTF8', $filled) eq 'Ответить';
	$CP = 'WIN'		if Convert::Cyrillic::cstocs('WIN', 'UTF8', $filled) eq 'Ответить';
	my $name = Convert::Cyrillic::cstocs($CP, 'UTF8', $ARGS{freefield_1});
	my $body = "Пользователь $name правильно ответил на вопросы.<br>\n";
	$body .= "Переданы данные:<br>\n";
	foreach my $j ( 1 .. $quest->{freefields_amount} ) {
		$body .= "  ".$quest->{freefields}->[$j-1].":\t".$ARGS{"freefield_".$j}."<br>\n";
	}
	$body .= "-----------------------------------<br>\n";
	$body .= "Робот ".$request->{project_profile}->name;
	my %email;
	$email{subject} = 'Анкета на конкурс '.$request->{project};
	$email{from_name} = Convert::Cyrillic::cstocs($CP, 'UTF8', $name);
	$email{to_name} = 'Жюри';
	$email{body} = $body;
	$email{from} = 'admin@rambler-co.ru';
	$email{to} = $to;

#	$voting->res(int($voting->res)+1);
#	$voting->store;

	warn 'Все зашибись!!!';
	unless ($error) {
		$m->comp ('/subs/sendmail.msn', email => \%email);
	}
  } else {
	warn 'Не пролезло';
  }
</%init>