/[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.9 by dpavlin, Wed Sep 24 20:35:48 2003 UTC revision 1.14 by dpavlin, Tue Oct 21 16:55:06 2003 UTC
# Line 10  use strict; Line 10  use strict;
10    
11  use XML::Parser;  use XML::Parser;
12  use common;  use common;
13    use Carp;
14    
15  $|=1;  $|=1;
16    
# Line 59  my $db_user="dpavlin"; Line 60  my $db_user="dpavlin";
60  # polls to be conducted by just publishing URL to them.  # polls to be conducted by just publishing URL to them.
61  my $without_invitation=0;  my $without_invitation=0;
62    
63    # This will remove numbers before answers. That enables you to have
64    # answers written like:
65    # 1.1 red
66    # 1.2 black
67    # and users will see just "red" and "black"
68    my $remove_nrs_in_answers=0;
69    
70    # This defines files which will be included in various places to produce
71    # design. You could desing them using your faviourite html editor (vim :-)
72    # and then split them into separate files
73    
74    my %include_files = (
75    # this file is included at top of each paAge
76            'header' => "header.html",
77    # this file is used to separate questions
78            'separator' => "separator.html",
79    # this file is used to show "submit" button, which under multi-page
80    # polls will also bring next page
81            'submit' => "next.html",
82    # this file is included at bottom of each page
83            'footer' => "footer.html",
84    # this file will be showen after poll is completed
85            'thanks' => "thanks.html"
86    );
87    
88    my %html;       # buffer for suck(_file)ed html files
89    
90  #------------------------------------------------------------------  #------------------------------------------------------------------
91    
92  sub suck_file {  sub suck_file {
93          my $file = shift @_;          my $file = shift || croak "suck_file called without argument";
94          open(H,$file) || die "can't open '$file': $!";          open(H,$file) || die "can't open '$file': $!";
95          my $content;          my $content;
96          while (<H>) { $content .= $_; } ;          while (<H>) { $content .= $_; } ;
# Line 70  sub suck_file { Line 98  sub suck_file {
98          return $content;          return $content;
99  }  }
100    
101  my $html_header=suck_file("header.html");  $html{'header'}=suck_file($include_files{'header'});
102  my $html_separator=suck_file("separator.html");  $html{'separator'}=suck_file($include_files{'separator'});
103  my $html_next=suck_file("next.html");  $html{'submit'}=suck_file($include_files{'submit'});
104  my $html_footer=suck_file("footer.html");  $html{'footer'}=suck_file($include_files{'footer'});
105    
106  #------------------------------------------------------------------  #------------------------------------------------------------------
107    
# Line 110  my $head_php=suck_file("head.php"); Line 138  my $head_php=suck_file("head.php");
138    
139  #------------------------------------------------------------------  #------------------------------------------------------------------
140    
141  my $html_kraj=suck_file("thanks.html");  $html{'kraj'}=suck_file($include_files{'thanks'});
142    
143  #------------------------------------------------------------------  #------------------------------------------------------------------
144    
# Line 194  close(PAGE); Line 222  close(PAGE);
222  $page_nr++;  $page_nr++;
223  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$!";
224  print PAGE php_header($page_nr,@last_sql_update);  print PAGE php_header($page_nr,@last_sql_update);
225  print PAGE "$html_header $html_kraj $html_footer";  print PAGE "$html{'header'} $html{'kraj'} $html{'footer'}";
226  close(PAGE);  close(PAGE);
227    
228  # dump sql structure  # dump sql structure
# Line 476  sub page { Line 504  sub page {
504                          @sql_update = ();                          @sql_update = ();
505                    
506                          $last_fn=sprintf("%02d.php",$page_nr);                          $last_fn=sprintf("%02d.php",$page_nr);
507                          $last_page="$html_header $body $html_next $html_footer";                          $last_page="$html{'header'} $body $html{'submit'} $html{'footer'}";
508                          # delete vars for next page                          # delete vars for next page
509                          $page_nr++;                          $page_nr++;
510                          $body="";                          $body="";
# Line 508  sub nr { Line 536  sub nr {
536    
537    
538  sub hr {  sub hr {
539          $body .= "<br></td></tr>$html_separator<tr><td></td><td><br>";          $body .= "<br></td></tr>$html{'separator'}<tr><td></td><td><br>";
540  }  }
541    
542  sub br {  sub br {
# Line 597  sub dropdown { Line 625  sub dropdown {
625    
626          my @dropdown_data;          my @dropdown_data;
627    
628            my $default_value = x($attref->{default_value}) || 'null';
629            my $default_text = x($attref->{default_text}) || '-';
630    
631          $$ncref = sub {          $$ncref = sub {
632                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
633    
634                  if (defined $text) {                  if (defined $text) {
635                          chomp $text;                          chomp $text;
636                          $text=~s/^\s*//g;                          $text=~s/^\s*//g;
637                          $text=~s/^[\d\.\s]+//g;                          $text=~s/^[\d\.\s]+//g if ($remove_nrs_in_answers);
638                          $text=~s/\s*$//g;                          $text=~s/\s*$//g;
639                          push @dropdown_data,x($text) if ($text ne "");                          push @dropdown_data,x($text) if ($text ne "");
640                  } else {                  } else {
# Line 611  sub dropdown { Line 642  sub dropdown {
642                          my $id=1;                          my $id=1;
643                          my $p=new_pit();                          my $p=new_pit();
644                          $body.="<select name=$p >\n";                          $body.="<select name=$p >\n";
645                          $body.="<option value=null>-</option>\n";                          $body.="<option value=\"$default_value\">$default_text</option>\n";
646                          foreach $opt (@dropdown_data) {                          foreach $opt (@dropdown_data) {
647                                  if (defined($opt) && $opt ne "") {                                  if (defined($opt) && $opt ne "") {
648                                          $body.="<option value=$id>$opt</option>\n";                                          $body.="<option value=$id>$opt</option>\n";
# Line 671  sub radiobuttons { Line 702  sub radiobuttons {
702                  if (defined $text) {                  if (defined $text) {
703                          chomp $text;                          chomp $text;
704                          $text=~s/^\s*//g;                          $text=~s/^\s*//g;
705                          $text=~s/^[\d\.\s]+//g;                          $text=~s/^[\d\.\s]+//g if ($remove_nrs_in_answers);
706                          $text=~s/\s*$//g;                          $text=~s/\s*$//g;
707                          push @radiobuttons_data,x($text) if ($text ne "");                          push @radiobuttons_data,x($text) if ($text ne "");
708                  } else {                  } else {
# Line 716  sub checkboxes { Line 747  sub checkboxes {
747                  if (defined $text) {                  if (defined $text) {
748                          chomp $text;                          chomp $text;
749                          $text=~s/^\s*//g;                          $text=~s/^\s*//g;
750                          $text=~s/^[\d\.\s]+//g;                          $text=~s/^[\d\.\s]+//g if ($remove_nrs_in_answers);
751                          $text=~s/\s*$//g;                          $text=~s/\s*$//g;
752                          push @checkboxes_data,x($text) if ($text ne "");                          push @checkboxes_data,x($text) if ($text ne "");
753                  } else {                  } else {
# Line 754  sub checkboxes { Line 785  sub checkboxes {
785          }          }
786  }  }
787    
788    sub html {
789            package main;
790    
791            my ($xp, $el, $attref, $ncref) = @_;
792    
793            $body.="<p>";
794    
795            $$ncref = sub {
796                    my ($xp, $text) = @_;
797    
798                    if (defined $text) {
799                            $body.=x($text);
800                    } elsif ($attref->{include}) {
801                            $body.=suck_file($attref->{include});
802                    } else {
803                            $body.="</p>";
804                    }
805            }
806    }
807    
808  print "\n\nTo create database for poll $poll use:\n\n";  print "\n\nTo create database for poll $poll use:\n\n";
809  print "\$ psql template1 < $poll/$poll.sql\n\n";  print "\$ psql template1 < $poll/$poll.sql\n\n";
810  print "THIS WILL DISTROY ALL DATA IN EXISTING DATABASE ".$prefix.$poll." !!\n";  print "THIS WILL DISTROY ALL DATA IN EXISTING DATABASE ".$prefix.$poll." !!\n";
# Line 769  sub config { Line 820  sub config {
820                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
821                  $db_user=x($attref->{db_user});                  $db_user=x($attref->{db_user});
822                  $prefix=x($attref->{prefix});                  $prefix=x($attref->{prefix});
823                  $without_invitation=x($attref->{without_invitation});                  $without_invitation=x($attref->{without_invitation}) &&
824                            print "Pool is without need for unique ID (and invitation URLs).\n";
825                    $remove_nrs_in_answers=x($attref->{$remove_nrs_in_answers}) &&
826                            print "Numbers before answers will be removed.\n";
827    
828                    foreach my $file (qw(header separator submit footer thanks)) {
829                            if ($attref->{$file}) {
830                                    $include_files{$file}=x($attref->{$file});
831                                    print "Using custom $file '$include_files{$file}'\n";
832                                    $html{$file} = suck_file($include_files{$file});
833                            }
834                    }
835          }          }
836  }  }
837    

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.26