/[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.12 by dpavlin, Sat Oct 11 15:47:33 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;
12  use common;  use Carp;
13    use Text::Iconv;
14    
15  $|=1;  $|=1;
16    
# Line 22  my @Modes = qw(object pass skip); Line 23  my @Modes = qw(object pass skip);
23  my $poll;  my $poll;
24  my $dowarn = 1;  my $dowarn = 1;
25    
26  my $pitanje_nr = 0;             # curr. pitanje  my $q_type = "q";               # q=question, u=unnumbered question
27  my $pitanje_tag = "";           # originalni oblik broja pitanja  my %question_nr;                # curr. question numbers
28  my $page_nr = 1;                # prvo pitanje na strani  my $question_tag = "";          # originalni oblik broja questions
29    my $page_nr = 1;                # prvo question na strani
30    
31  my $p_suffix="";                # if more than one box per question  my $p_suffix="";                # if more than one box per question
32    
33  my $curr_suffix="";             # trenutni suffix  my $curr_suffix="";             # trenutni suffix
34    
35  my @stack_pit;                  # stack pitanja (pitanje, suffix)  my @stack_que;                  # stack of questions (question, suffix)
36    
37  my @sql_create = ("id serial",  my @sql_create = ("id serial",
38          "http_referer character varying(500)",          "http_referer character varying(500)",
# Line 66  my $without_invitation=0; Line 68  my $without_invitation=0;
68  # and users will see just "red" and "black"  # and users will see just "red" and "black"
69  my $remove_nrs_in_answers=0;  my $remove_nrs_in_answers=0;
70    
71    # This defines files which will be included in various places to produce
72    # design. You could desing them using your faviourite html editor (vim :-)
73    # and then split them into separate files
74    
75    my %include_files = (
76    # this file is included at top of each paAge
77            'header' => "header.html",
78    # this file is used to separate questions
79            'separator' => "separator.html",
80    # this file is used to show "submit" button, which under multi-page
81    # polls will also bring next page
82            'submit' => "next.html",
83    # this file is included at bottom of each page
84            'footer' => "footer.html",
85    # this file will be showen after poll is completed
86            'thanks' => "thanks.html"
87    );
88    
89    # buffer for suck(_file)ed html files
90    # and additional markup before and after tags
91    my %html = (
92            'hr_before' => "<br></td></tr>",
93            'hr_after' => "<tr><td></td><td><br>",
94            'que_before' => "<p>",
95            'que_after' => "</p>",
96            'subque_before' => '<table width="100%" cellspacing="0" cellpadding="2" border="0">',
97            'subque_after' => "</table>",
98            'ans_before' => "<p>",
99            'ans_after' => "</p>",
100            'html_before' => "<p>",
101            'html_after' => "</p>",
102    
103    );
104    
105    # name of database colums
106    # for questions
107    my $q_db_col = "q";
108    # for unnumbered questions
109    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    
130  sub suck_file {  sub suck_file {
131          my $file = shift @_;          my $file = shift || croak "suck_file called without argument";
132          open(H,$file) || die "can't open '$file': $!";          open(H,$file) || die "can't open '$file': $!";
133          my $content;          my $content;
134          while (<H>) { $content .= $_; } ;          while (<H>) { $content .= $_; } ;
# Line 77  sub suck_file { Line 136  sub suck_file {
136          return $content;          return $content;
137  }  }
138    
139  my $html_header=suck_file("header.html");  $html{'header'}=suck_file($include_files{'header'});
140  my $html_separator=suck_file("separator.html");  $html{'separator'}=suck_file($include_files{'separator'});
141  my $html_next=suck_file("next.html");  $html{'submit'}=suck_file($include_files{'submit'});
142  my $html_footer=suck_file("footer.html");  $html{'footer'}=suck_file($include_files{'footer'});
143    
144  #------------------------------------------------------------------  #------------------------------------------------------------------
145    
# Line 117  my $head_php=suck_file("head.php"); Line 176  my $head_php=suck_file("head.php");
176    
177  #------------------------------------------------------------------  #------------------------------------------------------------------
178    
179  my $html_kraj=suck_file("thanks.html");  $html{'thanks'}=suck_file($include_files{'thanks'});
180    
181  #------------------------------------------------------------------  #------------------------------------------------------------------
182    
# Line 201  close(PAGE); Line 260  close(PAGE);
260  $page_nr++;  $page_nr++;
261  open(PAGE, ">$poll/$next_fn") or die "Couldn't open $next_fn for writing:\n$!";  open(PAGE, ">$poll/$next_fn") or die "Couldn't open $next_fn for writing:\n$!";
262  print PAGE php_header($page_nr,@last_sql_update);  print PAGE php_header($page_nr,@last_sql_update);
263  print PAGE "$html_header $html_kraj $html_footer";  print PAGE "$html{'header'} $html{'thanks'} $html{'footer'}";
264  close(PAGE);  close(PAGE);
265    
266  # dump sql structure  # dump sql structure
# Line 244  rename "$poll/01.php","$poll/index.php" Line 303  rename "$poll/01.php","$poll/index.php"
303  ## End of main  ## End of main
304  ################  ################
305    
306  # return unique name of pitanje  # return unique name of question
307  sub new_pit {  sub new_que {
308          my $out="p".$pitanje_nr;          my $out=$q_type.( $question_nr{$q_type} || 0 );
309          $out .= "_".$p_suffix if ($p_suffix);          $out .= "_".$p_suffix if ($p_suffix);
310          $curr_suffix=$p_suffix;          $curr_suffix=$p_suffix;
311          $p_suffix++;          $p_suffix++;
312          return $out;          return $out;
313  }  }
314    
315  # current pitanje  # current question
316  sub curr_pit {  sub curr_que {
317          return "p".$pitanje_nr.$curr_suffix;          return $q_type.( $question_nr{$q_type} || 0 ).$curr_suffix;
318  }  }
319    
320  #----------------------------------------------------------  #----------------------------------------------------------
321    
322  sub starthndl {  sub starthndl {
323    my ($xp, $el, %atts) = @_;          my ($xp, $el, %atts) = @_;
324    
325  #  return unless ($in_poll or $el eq 'slideshow');  #       return unless ($in_poll or $el eq 'slideshow');
326    
327    unless ($in_poll) {          unless ($in_poll) {
328      $in_poll = $xp->depth + 1;                  $in_poll = $xp->depth + 1;
329      return;                  return;
330    }          }
331    
332    if ($Mode) {          if ($Mode) {
333                    if ($Mode eq 'pass') {
334                            $Markedup_Text .= "\n" . $xp->recognized_string;
335                    } elsif ($Mode eq 'object') {
336                            push(@Ostack, $Object);
337    
338                            $Object = {
339                                    _Atts     => \%atts,
340                                    _Text    => ''
341                            };
342                            bless $Object, "Slideobj::$el";
343                    }
344    
345      if ($Mode eq 'pass') {                  # skip does nothing
346        $Markedup_Text .= "\n" . $xp->recognized_string;                  return;
347      }          }
     elsif ($Mode eq 'object') {  
       push(@Ostack, $Object);  
348    
349        $Object = {_Atts    => \%atts,          unless ($after_head) {
350                   _Text    => ''                  if ($el eq 'head') {
351                  };                          $after_head = 1;
352        bless $Object, "Slideobj::$el";                          start_mode($xp, 'object');
     }  
353    
354      # skip does nothing                          push(@closure_stack, $closure);
355      return;                          $closure = sub {
356    }                                  my ($xp, $text) = @_;
357    
358    unless ($after_head) {                                  unless (defined $text) {
359      if ($el eq 'head') {                                          $header = $Object;
360        $after_head = 1;                                  }
361        start_mode($xp, 'object');                          };
362                            return;
363        push(@closure_stack, $closure);                  }
       $closure =  
         sub {  
           my ($xp, $text) = @_;  
   
           unless (defined $text) {  
               
             $header = $Object;  
           }  
         };  
364    
365        return;  #               die "The head element must be the first thing in the slideshow";
366      }          }
367    
 #    die "The head element must be the first thing in the slideshow";  
   }  
368    
369            my $new_closure;
370    
371    my $new_closure;          my $subname = "Poll::$el";
372    
373    my $subname = "Poll::$el";          if (defined &$subname) {
374                    no strict 'refs';
375    
376    if (defined &$subname) {                  &$subname($xp, $el, \%atts, \$new_closure);
377      no strict 'refs';          } else {
378                    $body .= x($xp->recognized_string);
379                    $new_closure = sub {
380                            my ($xp, $text) = @_;
381    
382      &$subname($xp, $el, \%atts, \$new_closure);                          if (defined $text) {
383    }                                  $body .= x($text);
384    else {                          } else {
385      $body .= x($xp->recognized_string);                                  $body .= x("</$el>");
386      $new_closure =                          }
387        sub {                  };
         my ($xp, $text) = @_;  
           
         if (defined $text) {  
           $body .= x($text);  
         }  
         else {  
           $body .= x("</$el>");  
388          }          }
       };  
   }  
389    
390    push(@closure_stack, $closure);          push(@closure_stack, $closure);
391    $closure = $new_closure;          $closure = $new_closure;
392  }  # End starthndl  }       # End starthndl
393    
394  sub endhndl {  sub endhndl {
395    my ($xp, $el) = @_;          my ($xp, $el) = @_;
396    
397    return unless $in_poll;          return unless $in_poll;
398    
399    my $lev = $xp->depth;          my $lev = $xp->depth;
400    
401    if ($lev == $in_poll - 1) {          if ($lev == $in_poll - 1) {
402      $in_poll = 0;                  $in_poll = 0;
403      $xp->finish;                  $xp->finish;
404      return;                  return;
405    }          }
406              
407    if ($Mode_level == $lev) {          if ($Mode_level == $lev) {
408                        
409      if ($Mode eq 'pass') {                  if ($Mode eq 'pass') {
410        &$closure($xp, $Markedup_Text)                          &$closure($xp, $Markedup_Text) if (defined $closure);
411          if (defined $closure);                  }
     }  
412    
413      $Mode = $Mode_level = 0;                  $Mode = $Mode_level = 0;
414    }          }
415    
416    if ($Mode) {          if ($Mode) {
417      if ($Mode eq 'pass') {                  if ($Mode eq 'pass') {
418        $Markedup_Text .= "</$el>";                          $Markedup_Text .= "</$el>";
419      }                  } elsif ($Mode eq 'object') {
420      elsif ($Mode eq 'object') {                          my $this = $Object;
421        my $this = $Object;                          if (2 == keys %$this) {
422        if (2 == keys %$this) {                                  $this = $this->{_Text};
423          $this = $this->{_Text};                          }
       }  
   
       $Object = pop(@Ostack);  
   
       my $slot = $Object->{$el};  
       if (defined $slot) {  
         if (ref($slot) eq 'ARRAY') {  
           push(@$slot, $this);  
         }  
         else {  
           $Object->{$el} = [$slot, $this];  
         }  
       }  
       else {  
         $Object->{$el} = $this;  
       }  
     }  
424    
425      return;                          $Object = pop(@Ostack);
   }  
426    
427    &$closure($xp)                          my $slot = $Object->{$el};
428      if defined $closure;                          if (defined $slot) {
429                                    if (ref($slot) eq 'ARRAY') {
430                                            push(@$slot, $this);
431                                    } else {
432                                            $Object->{$el} = [$slot, $this];
433                                    }
434                            } else {
435                                    $Object->{$el} = $this;
436                            }
437                    }
438    
439                    return;
440            }
441    
442            &$closure($xp) if defined $closure;
443    
444    $closure = pop(@closure_stack);          $closure = pop(@closure_stack);
445  }  # End endhndl  }  # End endhndl
446    
447  #----------------------------------------------------------  #----------------------------------------------------------
448    
449  sub text {  sub text {
450    my ($xp, $data) = @_;          my ($xp, $data) = @_;
451    
452    return unless $in_poll;          return unless $in_poll;
453    
454    if ($Mode ) {          if ($Mode) {
455    
456      if ($Mode eq 'pass') {                  if ($Mode eq 'pass') {
457        my $safe = sgml_escape($data);                          my $safe = sgml_escape($data);
458    
459        $Text .= $safe;                          $Text .= $safe;
460        $Markedup_Text .= $safe;                          $Markedup_Text .= $safe;
461      }                  } elsif ($Mode eq 'object') {
462      elsif ($Mode eq 'object') {                          $Object->{_Text} .= $data if $data =~ /\S/;
463        $Object->{_Text} .= $data                  }
         if $data =~ /\S/;  
     }  
464    
465      return;                  return;
466    }          }
467    
468    &$closure($xp, sgml_escape($data))          &$closure($xp, sgml_escape($data)) if (defined $closure);
     if (defined $closure);  
469    
470  }  # End text  }  # End text
471    
472  sub start_mode {  sub start_mode {
473    my ($xp, $mode) = @_;          my ($xp, $mode) = @_;
474    
475    if ($mode eq 'pass') {          if ($mode eq 'pass') {
476      $Text = '';                  $Text = '';
477      $Markedup_Text = '';                  $Markedup_Text = '';
478    }          } elsif ($mode eq 'object') {
479    elsif ($mode eq 'object') {                  $Object = {
480      $Object = {_Atts => undef,                          _Atts => undef,
481                 _Text => undef                          _Text => undef
482                };                  };
483    }          }
484    
485    $Mode = $mode;          $Mode = $mode;
486    $Mode_level = $xp->depth;          $Mode_level = $xp->depth;
487  }  # End start_mode  }  # End start_mode
488    
489  sub sgml_escape {  sub sgml_escape {
490    my ($str) = @_;          my ($str) = @_;
491    
492    $str =~ s/\&/\&amp;/g;          $str =~ s/\&/\&amp;/g;
493    $str =~ s/</\&lt;/g;          $str =~ s/</\&lt;/g;
494    $str =~ s/>/\&gt;/g;          $str =~ s/>/\&gt;/g;
495    
496    $str;          $str;
497  }  # End sgml_escape  }  # End sgml_escape
498    
   
499  ################################################################  ################################################################
500    
501  package Poll;  package Poll;
# Line 483  sub page { Line 526  sub page {
526                          @sql_update = ();                          @sql_update = ();
527                    
528                          $last_fn=sprintf("%02d.php",$page_nr);                          $last_fn=sprintf("%02d.php",$page_nr);
529                          $last_page="$html_header $body $html_next $html_footer";                          $last_page="$html{'header'} $body $html{'submit'} $html{'footer'}";
530                          # delete vars for next page                          # delete vars for next page
531                          $page_nr++;                          $page_nr++;
532                          $body="";                          $body="";
# Line 496  sub nr { Line 539  sub nr {
539    
540          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
541    
542          $pitanje_tag="";          $question_tag="";
543    
544          $$ncref = sub {          $$ncref = sub {
545                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
546                  if (defined($text)) {                  if (defined($text)) {
547                          $body.=x($text);                          $body.=x($text);
548                          chomp $text;                          chomp $text;
549                          $pitanje_tag .= x($text);                          $question_tag .= x($text);
550                  } else {                  } else {
551                          $pitanje_nr = $pitanje_tag;                          $question_nr{$q_type} = $question_tag;
552                          $pitanje_nr =~ s/[^0-9a-zA-Z]//g;                          $question_nr{$q_type} =~ s/[^0-9a-zA-Z]//g;
553                          print "$pitanje_nr ";                          print "$question_nr{$q_type} ";
554                  }                  }
555                  $p_suffix="";                  $p_suffix="";
556          };          };
# Line 515  sub nr { Line 558  sub nr {
558    
559    
560  sub hr {  sub hr {
561          $body .= "<br></td></tr>$html_separator<tr><td></td><td><br>";          $body .= $html{'hr_before'}.$html{'separator'}.$html{'hr_after'};
 }  
   
 sub br {  
         $body .= "<br>\n";  
562  }  }
563    
564  sub pit {  sub que {
565          package main;          package main;
566    
567          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
568    
569          $body.="<p>";          my $nonum = x($attref->{unnumbered});
570            if ($nonum) {
571                    $q_type = $u_db_col;    # unnumbered questions
572            } else {
573                    $q_type = $q_db_col;
574            }
575            
576            $question_nr{$q_type}++;
577    
578            # 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 535  sub pit { Line 591  sub pit {
591                  if (defined $text) {                  if (defined $text) {
592                          $body.=x($text);                          $body.=x($text);
593                  } else {                  } else {
594                          $body.="</p>";                          if (defined($markup_after)) {
595                                    $body.=$markup_after;
596                            } elsif ($html{'que_after'}) {
597                                    $body.=$html{'que_after'}
598                            }
599                  }                  }
600          }          }
601  }  }
602    
603  sub podpit {  sub subque {
604          package main;          package main;
605    
606          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
607    
608          $body.='<table width="100%" cellspacing="0" cellpadding="2" border="0">';          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) = @_;
619    
620                  if (defined $text) {                  if (defined $text) {
621                          $body.=x($text);                          $body.=x($text);
622                  } else {                  } else {
623                          $body.="</table>";                          if (defined($markup_after)) {
624                                    $body.=$markup_after;
625                            } elsif ($html{'subque_after'}) {
626                                    $body.=$html{'subque_after'}
627                            }
628                  }                  }
629          }          }
630  }  }
631    
632    
633  sub odg {  sub ans {
634          package main;          package main;
635    
636          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
637    
638          $body .= "<p>";          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) = @_;
649    
650                  if (defined $text) {                  if (defined $text) {
651                          $body .= x($text);                          $body .= x($text);
652                  } else {                  } else {
653                          $body .= "</p>";                          if (defined($markup_after)) {
654                                    $body.=$markup_after;
655                            } elsif ($html{'ans_after'}) {
656                                    $body.=$html{'ans_after'}
657                            }
658                  }                  }
659          }          }
660  }  }
# Line 619  sub dropdown { Line 702  sub dropdown {
702                  } else {                  } else {
703                          my $opt;                          my $opt;
704                          my $id=1;                          my $id=1;
705                          my $p=new_pit();                          my $p=new_que();
706                          $body.="<select name=$p >\n";                          $body.="<select name=$p >\n";
707                          $body.="<option value=\"$default_value\">$default_text</option>\n";                          $body.="<option value=\"$default_value\">$default_text</option>\n";
708                          foreach $opt (@dropdown_data) {                          foreach $opt (@dropdown_data) {
# Line 644  sub textbox { Line 727  sub textbox {
727                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
728                  my $size=$attref->{size};                  my $size=$attref->{size};
729                  $size = 25 if (! defined $size || $size == 0);  # default                  $size = 25 if (! defined $size || $size == 0);  # default
730                  my $p=new_pit();                  my $p=new_que();
731                  $body.="<input type=text name=$p size=".x($size)." >\n";                  $body.="<input type=text name=$p size=".x($size)." >\n";
732                  push @sql_create,"$p text";                  push @sql_create,"$p text";
733                  push @sql_update,"$p='\$$p'";                  push @sql_update,"$p='\$$p'";
# Line 658  sub radiobuttons_tab { Line 741  sub radiobuttons_tab {
741          $$ncref = sub {          $$ncref = sub {
742                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
743                  if (! defined $text) {                  if (! defined $text) {
744                          my $nr=$attref->{nr};                          my $nr=$attref->{nr} || die "need <radiobuttons_tab nr=\"999\"> for number of buttons";
745                          my $p=new_pit();                          # shownumbers="before|after"
746                            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();
751                          for (my $i=1; $i<=$nr; $i++) {                          for (my $i=1; $i<=$nr; $i++) {
752                                  $body.="<td><input type=radio name=$p value=$i></td> ";                                  $body.="<td$class>";
753                                    $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>";
758                                    $body.=$i if ($shownumbers eq "after");
759                                    $body.="</td> ";
760                          }                          }
761                          push @sql_create,"$p int4";                          push @sql_create,"$p int4";
762                          push @sql_update,"$p=\$$p";                          push @sql_update,"$p=\$$p";
# Line 686  sub radiobuttons { Line 781  sub radiobuttons {
781                          push @radiobuttons_data,x($text) if ($text ne "");                          push @radiobuttons_data,x($text) if ($text ne "");
782                  } else {                  } else {
783                          my $opt;                          my $opt;
784                          my $p=new_pit();                          my $p=new_que();
785                          my $id=1;                          my $id=1;
786                          foreach $opt (@radiobuttons_data) {                          foreach $opt (@radiobuttons_data) {
787                                  if (defined($opt) && $opt ne "") {                                  if (defined($opt) && $opt ne "") {
# Line 705  sub checkbox { Line 800  sub checkbox {
800    
801          $$ncref = sub {          $$ncref = sub {
802                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
803                  my $p=new_pit();                  my $p=new_que();
804                  $body.="<input type=checkbox name=$p >\n";                  $body.="<input type=checkbox name=$p >\n";
805                  push @sql_create,"$p text";                  push @sql_create,"$p text";
806                  push @sql_update,"$p='\$$p'";                  push @sql_update,"$p='\$$p'";
# Line 731  sub checkboxes { Line 826  sub checkboxes {
826                          push @checkboxes_data,x($text) if ($text ne "");                          push @checkboxes_data,x($text) if ($text ne "");
827                  } else {                  } else {
828                          my $opt;                          my $opt;
829                          my $base_p=new_pit();                          my $base_p=new_que();
830                          my $id=1;                          my $id=1;
831    
832                          my $before=$attref->{before};                          my $before=$attref->{before};
# Line 764  sub checkboxes { Line 859  sub checkboxes {
859          }          }
860  }  }
861    
862    #
863    # insert arbitrary html
864    #
865    sub html {
866            package main;
867    
868            my ($xp, $el, $attref, $ncref) = @_;
869    
870            $body.=$html{'html_before'} if ($html{'html_before'});
871    
872            $$ncref = sub {
873                    my ($xp, $text) = @_;
874    
875                    if (defined $text) {
876                            $body.=x($text);
877                    } elsif ($attref->{include}) {
878                            $body.=suck_file($attref->{include});
879                    } else {
880                            $body.=$html{'html_after'} if ($html{'html_after'});
881                    }
882            }
883    }
884    
885    #
886    # markup tag can specify any markup which should be applied pre (before)
887    # or post (after) any other tag which produces html output
888    #
889    
890    sub markup {
891            package main;
892    
893            my ($xp, $el, $attref, $ncref) = @_;
894    
895            $$ncref = sub {
896                    my ($xp, $text) = @_;
897    
898                    my $tag=lc($attref->{tag}) || die 'markup need tag attribute: <markup tag="tag_name" pos="(before|after)">';
899                    my $pos=lc($attref->{pos}) || die 'markup need pos attribute: <markup tag="tag_name" pos="(before|after)">';
900    
901                    return if (! defined $text);
902                    chomp($text);
903                    if ($text ne "") {
904                            $text =~ s/\&amp;/\&/g;
905                            $text =~ s/\&lt;/</g;
906                            $text =~ s/\&gt;/>/g;
907                            $text =~ s/^\s+//g;
908                            $text =~ s/\s+$//g;
909                            $html{$tag.'_'.$pos}=x($text);
910                            print "Using markup $pos $tag: ",x($text),"<--\n";
911                    }
912            }
913    }
914    
915    #
916    # print final instructions and exit
917    #
918    
919  print "\n\nTo create database for poll $poll use:\n\n";  print "\n\nTo create database for poll $poll use:\n\n";
920  print "\$ psql template1 < $poll/$poll.sql\n\n";  print "\$ psql template1 < $poll/$poll.sql\n\n";
921  print "THIS WILL DISTROY ALL DATA IN EXISTING DATABASE ".$prefix.$poll." !!\n";  print "THIS WILL DISTROY ALL DATA IN EXISTING DATABASE ".$prefix.$poll." !!\n";
922    
923  # read configuration data  # read configuration data
 #  
 # FIX: write actually this :-)  
924  sub config {  sub config {
925          package main;          package main;
926          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
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}) &&
936                          print "Pool is without need for unique ID (and invitation URLs).\n";                          print "Pool is without need for unique ID (and invitation URLs).\n";
937                  $remove_nrs_in_answers=x($attref->{$remove_nrs_in_answers}) &&                  $remove_nrs_in_answers=x($attref->{remove_nrs_in_answers}) &&
938                          print "Numbers before answers will be removed.\n";                          print "Numbers before answers will be removed.\n";
939    
940                    # fill in configuration about include files
941                    foreach my $file (qw(header separator submit footer thanks)) {
942                            if ($attref->{$file}) {
943                                    $include_files{$file}=x($attref->{$file});
944                                    print "Using custom $file '$include_files{$file}'\n";
945                                    $html{$file} = suck_file($include_files{$file});
946                            }
947                    }
948                    $q_db_col=x($attref->{q_db_col}) || 'q';
949                    $u_db_col=x($attref->{u_db_col}) || 'u';
950    
951    
952          }          }
953  }  }
954    

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

  ViewVC Help
Powered by ViewVC 1.1.26