/[wopi]/make_poll.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /make_poll.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.17 by dpavlin, Sat Nov 8 01:08:44 2003 UTC revision 1.21 by dpavlin, Tue Apr 13 15:11:58 2004 UTC
# Line 9  Line 9 
9  use strict;  use strict;
10    
11  use XML::Parser;  use XML::Parser;
 use common;  
12  use Carp;  use Carp;
13    use Text::Iconv;
14    
15  $|=1;  $|=1;
16    
# Line 108  my $q_db_col = "q"; Line 108  my $q_db_col = "q";
108  # for unnumbered questions  # for unnumbered questions
109  my $u_db_col = "u";  my $u_db_col = "u";
110    
111    # output encoding for files, probably defined in header.html also
112    my $html_encoding="ISO-8859-2";
113    
114    Text::Iconv->raise_error(1);    # Conversion errors raise exceptions
115    my $iconv;
116    
117    # convert UTF8 (as from XML file) to 8-bit encoding
118    sub x {
119            if (! $iconv) {
120                    $iconv = Text::Iconv->new('UTF8', $html_encoding);
121                    print "output encoding is $html_encoding\n";
122            }
123            return $iconv->convert($_[0]);
124    }
125    
126    1;
127    
128  #------------------------------------------------------------------  #------------------------------------------------------------------
129    
# Line 556  sub que { Line 572  sub que {
572          } else {          } else {
573                  $q_type = $q_db_col;                  $q_type = $q_db_col;
574          }          }
575            
576          $question_nr{$q_type}++;          $question_nr{$q_type}++;
577    
578          $body.=$html{'que_before'} if ($html{'que_before'});          # attribute markup_before override que_before
579            my $markup_before = x($attref->{markup_before});
580            my $markup_after = x($attref->{markup_after});
581    
582            if (defined($markup_before)) {
583                    $body.=$markup_before;
584            } elsif ($html{'que_before'}) {
585                    $body.=$html{'que_before'}
586            }
587    
588          $$ncref = sub {          $$ncref = sub {
589                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
# Line 567  sub que { Line 591  sub que {
591                  if (defined $text) {                  if (defined $text) {
592                          $body.=x($text);                          $body.=x($text);
593                  } else {                  } else {
594                          $body.=$html{'que_after'} if ($html{'que_after'});                          if (defined($markup_after)) {
595                                    $body.=$markup_after;
596                            } elsif ($html{'que_after'}) {
597                                    $body.=$html{'que_after'}
598                            }
599                  }                  }
600          }          }
601  }  }
# Line 577  sub subque { Line 605  sub subque {
605    
606          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
607    
608          $body.=$html{'subque_before'} if ($html{'subque_before'});          my $markup_before = x($attref->{markup_before});
609            my $markup_after = x($attref->{markup_after});
610    
611            if (defined($markup_before)) {
612                    $body.=$markup_before;
613            } elsif ($html{'subque_before'}) {
614                    $body.=$html{'subque_before'}
615            }
616    
617          $$ncref = sub {          $$ncref = sub {
618                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
# Line 585  sub subque { Line 620  sub subque {
620                  if (defined $text) {                  if (defined $text) {
621                          $body.=x($text);                          $body.=x($text);
622                  } else {                  } else {
623                          $body.=$html{'subque_after'} if ($html{'subque_after'});                          if (defined($markup_after)) {
624                                    $body.=$markup_after;
625                            } elsif ($html{'subque_after'}) {
626                                    $body.=$html{'subque_after'}
627                            }
628                  }                  }
629          }          }
630  }  }
# Line 596  sub ans { Line 635  sub ans {
635    
636          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
637    
638          $body.=$html{'ans_before'} if ($html{'ans_before'});          my $markup_before = x($attref->{markup_before});
639            my $markup_after = x($attref->{markup_after});
640    
641            if (defined($markup_before)) {
642                    $body.=$markup_before;
643            } elsif ($html{'ans_before'}) {
644                    $body.=$html{'ans_before'}
645            }
646                    
647          $$ncref = sub {          $$ncref = sub {
648                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
# Line 604  sub ans { Line 650  sub ans {
650                  if (defined $text) {                  if (defined $text) {
651                          $body .= x($text);                          $body .= x($text);
652                  } else {                  } else {
653                          $body.=$html{'ans_after'} if ($html{'ans_after'});                          if (defined($markup_after)) {
654                                    $body.=$markup_after;
655                            } elsif ($html{'ans_after'}) {
656                                    $body.=$html{'ans_after'}
657                            }
658                  }                  }
659          }          }
660  }  }
# Line 694  sub radiobuttons_tab { Line 744  sub radiobuttons_tab {
744                          my $nr=$attref->{nr} || die "need <radiobuttons_tab nr=\"999\"> for number of buttons";                          my $nr=$attref->{nr} || die "need <radiobuttons_tab nr=\"999\"> for number of buttons";
745                          # shownumbers="before|after"                          # shownumbers="before|after"
746                          my $shownumbers=lc(x($attref->{shownumbers})) || 'no';                          my $shownumbers=lc(x($attref->{shownumbers})) || 'no';
747                            my $showlabels=lc(x($attref->{showlabels})) || 'no';
748                            my $class=lc(x($attref->{class})) || '';
749                            $class=' class="'.$class.'"' if ($class);
750                          my $p=new_que();                          my $p=new_que();
751                          for (my $i=1; $i<=$nr; $i++) {                          for (my $i=1; $i<=$nr; $i++) {
752                                  $body.="<td>";                                  $body.="<td$class>";
753                                  $body.=$i if ($shownumbers eq "before");                                  $body.=$i if ($shownumbers eq "before");
754                                    if ($showlabels eq "before" && $attref->{"label_$i"}) {
755                                            $body.=x($attref->{"label_$i"});
756                                    }
757                                  $body.="<input type=radio name=$p value=$i>";                                  $body.="<input type=radio name=$p value=$i>";
758                                  $body.=$i if ($shownumbers eq "after");                                  $body.=$i if ($shownumbers eq "after");
759                                  $body.="</td> ";                                  $body.="</td> ";
# Line 871  sub config { Line 927  sub config {
927    
928          $$ncref = sub {          $$ncref = sub {
929                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
930                    # encoding should be checked first since it also
931                    # initialize iconv for conversion from XML's UTF-8
932                    $html_encoding=$attref->{html_encoding} if ($attref->{html_encoding});
933                  $db_user=x($attref->{db_user});                  $db_user=x($attref->{db_user});
934                  $prefix=x($attref->{prefix});                  $prefix=x($attref->{prefix});
935                  $without_invitation=x($attref->{without_invitation}) &&                  $without_invitation=x($attref->{without_invitation}) &&
# Line 889  sub config { Line 948  sub config {
948                  $q_db_col=x($attref->{q_db_col}) || 'q';                  $q_db_col=x($attref->{q_db_col}) || 'q';
949                  $u_db_col=x($attref->{u_db_col}) || 'u';                  $u_db_col=x($attref->{u_db_col}) || 'u';
950    
951    
952          }          }
953  }  }
954    

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.26