/[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.2 by dpavlin, Tue Apr 22 18:46:04 2003 UTC revision 1.14 by dpavlin, Tue Oct 21 16:55:06 2003 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2  #  #
3    # Dobrica Pavlinusic <dpavlin@rot13.org>
4    #
5    # Originally made for proof. during April 2001; later released under GPL v2
6    #
7    # 2003-04-dd general cleanup in preparation of release
8    
9  use strict;  use strict;
10    
11  use XML::Parser;  use XML::Parser;
12  use Text::Iconv;  use common;
13    use Carp;
 # output charset  
 my $charset='ISO-8859-2';  
   
 Text::Iconv->raise_error(0);    # Conversion errors raise exceptions  
 my $from_utf8 = Text::Iconv->new('UTF8', $charset);  
 sub x {  
         return $from_utf8->convert($_[0]);  
 }  
14    
15  $|=1;  $|=1;
16    
17  my $Usage =<<'End_of_Usage;';  my $Usage =<<'End_of_Usage;';
18  slides [-h] [-d dir] [-mode mode] slide-doc  I will write usage information here. I promise!
   
 Convert a slideshow document into html, with a separate html document  
 for each slide and an index to all of them.  
   
         -h      Print this message and exit  
   
         -w      warn about unrecognized tags  
   
         -d      Use dir as directory into which to write html pages. Defaults  
                 to basename of supplied doc file.  
   
         -mode   Output mode. Choices are html, html-style. Default is  
                 html-style.  
   
19  End_of_Usage;  End_of_Usage;
20    
21  my @Modes = qw(object pass skip);  my @Modes = qw(object pass skip);
22    
23  my $dir;  my $poll;
24  my $dowarn = 1;  my $dowarn = 1;
 my $dostyle = 0;  
25    
26  my $pitanje_nr = 0;             # curr. pitanje  my $pitanje_nr = 0;             # curr. pitanje
27  my $pitanje_tag = "";           # originalni oblik broja pitanja  my $pitanje_tag = "";           # originalni oblik broja pitanja
# Line 72  my $prefix="wopi_"; Line 54  my $prefix="wopi_";
54  # this is usename in database  # this is usename in database
55  my $db_user="dpavlin";  my $db_user="dpavlin";
56    
57    # This option allows users to fill poll without using invitation URL.
58    # That also means it's unpossible for them to return to exiting poll
59    # because they don't have thair own unique ID. Howver, it enables simple
60    # polls to be conducted by just publishing URL to them.
61    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 83  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_footer=suck_file("footer.html");  $html{'submit'}=suck_file($include_files{'submit'});
104    $html{'footer'}=suck_file($include_files{'footer'});
105    
106  #------------------------------------------------------------------  #------------------------------------------------------------------
107    
108  sub php_header {  sub php_header {
109  my ($page_nr,@sql_update) = @_;  my ($page_nr,@sql_update) = @_;
110  my $out='<?  my $out='<?php
111          include("common.inc");          include_once("common.php");
112          if (isset($update)) {          if (isset($update)) {
113                  $member_id=id_decode($a);                  $member_id=id_decode($a);
114                  ';                  ';
115  $out.=$php_addon[$page_nr-2] if (defined $php_addon[$page_nr-2]);  $out.=$php_addon[$page_nr-2] if (defined $php_addon[$page_nr-2]);
116  $out.='  $out.='
117                  $sql="update '.$dir.' set '.join(",\n",@sql_update).',                  $sql="update '.$poll.' set '.join(",\n",@sql_update).',
118                          do_stranice=\'$PHP_SELF\'                          do_stranice=\'$PHP_SELF\'
119                          where id=$id";                          where id=$id";
120  #               print "<pre>$sql</pre>";  #               print "<pre>$sql</pre>";
121                  $result=pg_Exec($conn,fix_sql($sql));                  $result=pg_Exec($conn,fix_sql($sql));
122          } elseif($do_stranice != $PHP_SELF) {          } elseif($do_stranice != $PHP_SELF && isset($do_uri) && isset($a)) {
123                  Header("Location: $do_uri?a=$a");                  Header("Location: $do_uri?a=$a");
124                  exit;                  exit;
125          }          }
# Line 114  return $out; Line 130  return $out;
130  #------------------------------------------------------------------  #------------------------------------------------------------------
131    
132  # first, define some constants  # first, define some constants
133  my $common_inc='  my $common_php = suck_file("common.php");
 $PREFIX="'.$prefix.'";  
 $DB_USER="'.$db_user.'";  
 $MEMBERS_DB="'.$prefix.'_members";  
 ';  
   
 # then append rest of text  
   
 $common_inc.=<<'End_of_common;';  
   
 $conn = pg_connect("dbname=$PREFIX$db user=$DB_USER");  
 $result=pg_Exec($conn,"set datestyle = 'german'");  
   
 set_magic_quotes_runtime(1);  
   
 // return number of true answers  
   
 function fix_checkboxes($var,$nr) {  
         for($i=1; $i<=$nr; $i++) {  
                 if (isset($GLOBALS[$var."_".$i])) {  
                         $GLOBALS[$var."_".$i]="true";  
                         $nr++;  
                 } else {  
                         $GLOBALS[$var."_".$i]="false";  
                 }  
         }  
         return $nr;  
   
 }  
   
 function checked($var) {  
         if ($var == "true" || $var == "t") return 1;  
         return 0;  
 }  
   
 function id_encode($id) {  
         return md5($id).strtr($id,"1234567890","abcdef1234");  
 }  
   
 function id_decode($eid) {  
         $id=substr(strtr($eid,"abcdef1234","1234567890"),32);  
         if (md5($id) == substr($eid,0,32)) {  
                 return $id;  
         } else {  
                 return 0;  
         }  
 }  
   
 function fix_sql($sql) {  
         $sql=ereg_replace(",([ \t\n\r]*),",",null\\1,",$sql);  
         $sql=ereg_replace(",([ \t\n\r]*),",",null\\1,",$sql);  
         $sql=ereg_replace(",([ \t\n\r]*),",",null\\1,",$sql);  
         $sql=ereg_replace("=([ \t\n\r,]+)","=null\\1",$sql);  
         $sql=ereg_replace("=([ \t\n\r,]*)$","=null\\1",$sql);  
         return $sql;  
 }  
   
 function get_answer($p) {  
         global $conn,$id,$db;  
         $result = pg_Exec ($conn,"select $p from $db where id=$id");  
         if ($result && pg_numrows($result) > 0) {  
                 $row=pg_fetch_row($result,0);  
                 if (isset($row[0]) && $row[0] != "") {  
                         $GLOBALS[$p]=$row[0];  
                         return $row[0];  
                 }  
         }  
         $GLOBALS[$p]=0;  
         return 0;  
 }  
   
 function get_answers($p) {  
         global $conn,$id,$db;  
         $result = pg_Exec ($conn,"select $p from $db where id=$id");  
         if ($result && pg_numrows($result) > 0) {  
                 $row=pg_fetch_array($result,0);  
                 $pit=split(",",$p);  
                 while(list($key,$val) = each($row)) {  
                         $GLOBALS[$key]=$val;  
                 }  
         }  
 }  
 function get_member($pitanja,$uvjet) {  
         global $member_id;  
         $p_conn = pg_connect("dbname=$MEMBERS_DB user=$DB_USER");  
         if ($uvjet == "") $uvjet="true";  
         $result=pg_Exec($p_conn,"select id,$pitanja from member  
                 where $uvjet and id = $member_id");  
         $numrows=pg_numrows($result);  
         if ($numrows) {  
                 $row=pg_fetch_array($result,0);  
                 $pit=split(",",$pitanja);  
                 while(list($key,$val) = each($row)) {  
                         $GLOBALS["member_".$key]=$val;  
                 }  
         }  
 }  
   
 if (isset($a) && !isset($id) && !isset($pid)) {  
         global $conn,$db,$do_stranice;  
         $pid=id_decode($a);  
         $result = pg_Exec ($conn,"select id,do_stranice from $db where member_id=$pid");  
         if ($result && pg_numrows($result) > 0) {  
                 $row=pg_fetch_array($result,0);  
                 $id=$row[id];  
                 $do_stranice=$row[do_stranice];  
                 $do_uri="http://".$SERVER_NAME.":".$SERVER_PORT.$row[do_stranice];  
         }  
 }  
   
 End_of_common;  
134    
135  #------------------------------------------------------------------  #------------------------------------------------------------------
136    
# Line 232  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 243  while (defined($ARGV[0]) and $ARGV[0] =~ Line 149  while (defined($ARGV[0]) and $ARGV[0] =~
149      print $Usage;      print $Usage;
150      exit;      exit;
151    }    }
   elsif ($opt eq '-d') {  
     $dir = shift;  
   }  
   elsif ($opt eq '-w') {  
     $dowarn = 1;  
   }  
   elsif ($opt eq '-mode') {  
     my $marg = shift;  
     if ($marg eq 'html') {  
       $dostyle = 0;  
     }  
     else {  
       die "Unrecognized mode: $marg\n$Usage";  
     }  
   }  
   else {  
     die "Unrecognized option: $opt\n$Usage";  
   }  
152  }  # End of option processing  }  # End of option processing
153    
154  my $docfile = shift;  my $xmlfile = shift;
155    
156  die "No docfile provided:\n$Usage" unless defined $docfile;  die "No poll xml file provided!\n$Usage" unless defined $xmlfile;
157    
158  die "Can't read $docfile" unless -r $docfile;  die "Can't read $xmlfile" unless -r $xmlfile;
159    
160  if (defined $dir) {  if (defined $poll) {
161    die "$dir isn't a directory" unless -d $dir;    die "$poll isn't a directory" unless -d $poll;
162  }  }
163  else {  else {
164    $docfile =~ m!([^/.]+)(?:\.[^/.]*)?$!;    $xmlfile =~ m!([^/.]+)(?:\.[^/.]*)?$!;
165    $dir = $1;    $poll = $1;
166    if (-e $dir) {    if (-e $poll) {
167      die "$dir exists but isn't a directory"      die "$poll exists but isn't a directory"
168        unless -d $dir;        unless -d $poll;
169    }    }
170    else {    else {
171      mkdir $dir, 0755;      mkdir $poll, 0755;
172    }    }
173  }  }
174    
175  my $in_slideshow = 0;  my $in_poll = 0;
176  my $after_head = 0;  my $after_head = 0;
177    
178  my $Mode = 0;  my $Mode = 0;
# Line 295  my $Markedup_Text; Line 183  my $Markedup_Text;
183  my $Object;  my $Object;
184  my @Ostack = ();  my @Ostack = ();
185    
186  my $intext = 0;  #my $intext = 0;
187  my $closure;  my $closure;
188  my @closure_stack = ();  my @closure_stack = ();
189    
190  my $style_link = '';  #my $style_link = '';
191    
192  my $index = 'index.html';  #my $index = 'index.html';
193  my @slidetitle;  #my @slidetitle;
194  my $body;  my $body;
195  my $inlist = 0;  #my $inlist = 0;
196    
197  my @Titles;  #my @Titles;
198    
199  my $header;  my $header;
200    
 my $prolog = "<html><head>\n";  
 $prolog .= "<!-- Generated by $0 on " . gmtime() . " GMT -->\n";  
   
201  my $page_number = 0;  my $page_number = 0;
202    
203  my $p = new XML::Parser(ErrorContext => 3,  my $p = new XML::Parser(ErrorContext => 3,
204                          Handlers => {Start => \&starthndl,                          Handlers => {Start => \&starthndl,
205                                       End   => \&endhndl,                                       End   => \&endhndl,
206                                       Char  => \&text});                                       Char  => \&text});
207  $p->parsefile($docfile);  $p->parsefile($xmlfile);
208    
209  #----------------------------------------------------------  #----------------------------------------------------------
210    
# Line 327  $p->parsefile($docfile); Line 212  $p->parsefile($docfile);
212    
213  print "p[$page_nr] ";  print "p[$page_nr] ";
214    
215  open(PAGE, ">$dir/$last_fn") or die "Couldn't open $last_fn for writing:\n$!";  open(PAGE, ">$poll/$last_fn") or die "Couldn't open $last_fn for writing:\n$!";
216  print PAGE php_header($page_nr,@prelast_sql_update);  print PAGE php_header($page_nr,@prelast_sql_update);
217  my $next_fn=sprintf("%02d.php",$page_nr);  my $next_fn=sprintf("%02d.php",$page_nr);
218  $last_page=~s/##NEXTPAGE##/$next_fn/;  $last_page=~s/##NEXTPAGE##/$next_fn/;
# Line 335  print PAGE $last_page; Line 220  print PAGE $last_page;
220  close(PAGE);  close(PAGE);
221    
222  $page_nr++;  $page_nr++;
223  open(PAGE, ">$dir/$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
229    
230  open(SQL,">$dir/$dir.sql") || die "$dir.sql: $!";  open(SQL,">$poll/$poll.sql") || die "$poll.sql: $!";
231    print SQL "drop database ".$prefix.$poll.";\n";
232    print SQL "create database ".$prefix.$poll.";\n";
233    print SQL "\\connect ".$prefix.$poll.";\n";
234  print SQL "create table poslani ( member_id int4 not null, unesen timestamp default now() );\n";  print SQL "create table poslani ( member_id int4 not null, unesen timestamp default now() );\n";
235  print SQL "create table $dir (do_stranice text default null, ",join(",\n",@sql_create),");\n";  print SQL "create table $poll (do_stranice text default null, ",join(",\n",@sql_create),");\n";
236  close(SQL);  close(SQL);
237    
238  # dump common.inc  # dump common.php
239    
240    open(PHP,">$poll/common.php") || die "common.php: $!";
241    $common_php =~ s/##DB##/$poll/g;
242    my $db_name = $prefix.$poll;
243    $common_php =~ s/##DB_NAME##/$db_name/g;
244    $common_php =~ s/##PREFIX##/$prefix/g;
245    $common_php =~ s/##DB_USER##/$db_user/g;
246    $common_php =~ s/##PREFIX##/$prefix/g;
247    my $members_db = $prefix."members";
248    $common_php =~ s/##MEMBERS_DB##/$members_db/g;
249    $common_php =~ s/##WITHOUT_INVITATION##/$without_invitation/g;
250    
251  open(PHP,">$dir/common.inc") || die "common.inc: $!";  print PHP $common_php;
 print PHP '<? $db="'.$dir.'";';  
 print PHP $common_inc;  
 print PHP '?>';  
252  close(PHP);  close(PHP);
253    
254  open(PHP,">$dir/head.php") || die "head.php: $!";  open(PHP,">$poll/head.php") || die "head.php: $!";
255  my $max_page = $page_nr + 1;  my $max_page = $page_nr - 1;
256  $head_php=~ s/##MAXPAGE##/$max_page/;  $head_php=~ s/##MAXPAGE##/$max_page/;
257  $head_php=~ s/##TEXT##/Ispunili ste %02d%% ankete/;  $head_php=~ s/##TEXT##/Ispunili ste %02d%% ankete/;
258  print PHP $head_php;  print PHP $head_php;
259  close(PHP);  close(PHP);
260    
261    # 01.php -> index.php
262    rename "$poll/01.php","$poll/index.php" || die "can't rename '$poll/01.php' to index.php";
263    
264  ################  ################
265  ## End of main  ## End of main
266  ################  ################
267    
268  # return unique name of pitanje  # return unique name of pitanje
269  sub new_pit {  sub new_pit {
270          my $out="p".$pitanje_nr.$p_suffix;          my $out="p".$pitanje_nr;
271            $out .= "_".$p_suffix if ($p_suffix);
272          $curr_suffix=$p_suffix;          $curr_suffix=$p_suffix;
273          $p_suffix++;          $p_suffix++;
274          return $out;          return $out;
# Line 379  sub curr_pit { Line 279  sub curr_pit {
279          return "p".$pitanje_nr.$curr_suffix;          return "p".$pitanje_nr.$curr_suffix;
280  }  }
281    
282    #----------------------------------------------------------
283    
284  sub starthndl {  sub starthndl {
285    my ($xp, $el, %atts) = @_;    my ($xp, $el, %atts) = @_;
286    
287  #  return unless ($in_slideshow or $el eq 'slideshow');  #  return unless ($in_poll or $el eq 'slideshow');
288    
289    unless ($in_slideshow) {    unless ($in_poll) {
290      $in_slideshow = $xp->depth + 1;      $in_poll = $xp->depth + 1;
291      return;      return;
292    }    }
293    
# Line 432  sub starthndl { Line 334  sub starthndl {
334    
335    my $new_closure;    my $new_closure;
336    
337    my $subname = "Slideshow::$el";    my $subname = "Poll::$el";
338    
339    if (defined &$subname) {    if (defined &$subname) {
340      no strict 'refs';      no strict 'refs';
# Line 440  sub starthndl { Line 342  sub starthndl {
342      &$subname($xp, $el, \%atts, \$new_closure);      &$subname($xp, $el, \%atts, \$new_closure);
343    }    }
344    else {    else {
345      $body .= $xp->recognized_string;      $body .= x($xp->recognized_string);
346      $new_closure =      $new_closure =
347        sub {        sub {
348          my ($xp, $text) = @_;          my ($xp, $text) = @_;
349                    
350          if (defined $text) {          if (defined $text) {
351            $body .= $text;            $body .= x($text);
352          }          }
353          else {          else {
354            $body .= "</$el>";            $body .= x("</$el>");
355          }          }
356        };        };
357    }    }
# Line 461  sub starthndl { Line 363  sub starthndl {
363  sub endhndl {  sub endhndl {
364    my ($xp, $el) = @_;    my ($xp, $el) = @_;
365    
366    return unless $in_slideshow;    return unless $in_poll;
367    
368    my $lev = $xp->depth;    my $lev = $xp->depth;
369    
370    if ($lev == $in_slideshow - 1) {    if ($lev == $in_poll - 1) {
371      $in_slideshow = 0;      $in_poll = 0;
372      $xp->finish;      $xp->finish;
373      return;      return;
374    }    }
# Line 516  sub endhndl { Line 418  sub endhndl {
418    $closure = pop(@closure_stack);    $closure = pop(@closure_stack);
419  }  # End endhndl  }  # End endhndl
420    
421    #----------------------------------------------------------
422    
423  sub text {  sub text {
424    my ($xp, $data) = @_;    my ($xp, $data) = @_;
425    
426    return unless $in_slideshow;    return unless $in_poll;
427    
428    if ($Mode ) {    if ($Mode ) {
429    
# Line 569  sub sgml_escape { Line 473  sub sgml_escape {
473    $str;    $str;
474  }  # End sgml_escape  }  # End sgml_escape
475    
 sub slidename {  
   my ($num) = @_;  
   
   sprintf("slide%03d.html", $num);  
 }  # End slidename  
476    
477  ################################################################  ################################################################
478    
479  package Slideshow;  package Poll;
480    
481  sub page {  sub page {
482          package main;          package main;
# Line 592  sub page { Line 491  sub page {
491                          print "p[$page_nr] ";                          print "p[$page_nr] ";
492    
493                          if (defined $last_fn) {                          if (defined $last_fn) {
494                                  # 01.php -> index.php                                  open(PAGE, ">$poll/$last_fn") or die "Couldn't open $last_fn for writing:\n$!";
495                                  $last_fn="index.php" if ($last_fn eq "01.php");                                  print PAGE php_header($page_nr,@prelast_sql_update);
                                 open(PAGE, ">$dir/$last_fn") or die "Couldn't open $last_fn for writing:\n$!";  
                                 if ($page_nr == 2) {  
                                         print PAGE '<?  
 include("common.inc");  
 if (isset($do_stranice) && $do_stranice !="") {  
         Header("Location: $do_uri?a=$a");  
         exit;  
 }  
 $member_id=id_decode($a);  
 $sql="insert into '.$dir.' ( http_referer,remote_addr,user_agent, member_id ) values (\'$HTTP_REFERER\',\'$REMOTE_ADDR\',\'$HTTP_USER_AGENT\',$member_id)";  
   
 #       print "<pre>$sql</pre>";  
         $result=pg_Exec($conn,fix_sql($sql));  
         $lastoid=pg_getlastoid($result);  
         $result = pg_Exec($conn,fix_sql("select id from '.$dir.' where oid=$lastoid"));  
         $row=pg_fetch_row($result,0);  
         $id=$row[0];  
 ?>';  
   
                                 } else {  
                                         print PAGE php_header($page_nr,@prelast_sql_update);  
                                 } # last_sql_update  
   
   
496                                  my $next_fn=sprintf("%02d.php",$page_nr);                                  my $next_fn=sprintf("%02d.php",$page_nr);
497                                  $last_page=~s/##NEXTPAGE##/$next_fn/;                                  $last_page=~s/##NEXTPAGE##/$next_fn/;
498                                  print PAGE $last_page;                                  print PAGE $last_page;
# Line 629  $sql="insert into '.$dir.' ( http_refere Line 504  $sql="insert into '.$dir.' ( http_refere
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_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 647  sub nr { Line 522  sub nr {
522          $$ncref = sub {          $$ncref = sub {
523                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
524                  if (defined($text)) {                  if (defined($text)) {
525                          $body.=$text;                          $body.=x($text);
526                          chomp $text;                          chomp $text;
527                          $pitanje_tag .= $text;                          $pitanje_tag .= x($text);
528                  } else {                  } else {
529                          $pitanje_nr = $pitanje_tag;                          $pitanje_nr = $pitanje_tag;
530                          $pitanje_nr =~ s/[^0-9a-zA-Z]//g;                          $pitanje_nr =~ s/[^0-9a-zA-Z]//g;
# Line 661  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 750  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 764  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 824  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 869  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 907  sub checkboxes { Line 785  sub checkboxes {
785          }          }
786  }  }
787    
788  #---------------------------------------------------------------  sub html {
789            package main;
 sub slide {  
   package main;  
   
   my ($xp, $el, $attref, $ncref) = @_;  
   
   my $prev = $page_number ? slidename($page_number) : $index;  
   $page_number++;  
   my $fn = slidename($page_number);  
   my $next = slidename($page_number + 1);  
   
   open(SLIDE, ">$dir/$fn") or die "Couldn't open $fn for writing:\n$!";  
   
   print SLIDE $prolog;  
   
   undef @slidetitle;  
   $body = '';  
   $inlist = 0;  
   
   $$ncref =  
     sub {  
       my ($xp, $text) = @_;  
   
       if (defined $text) {  
         #ignore text at slide toplevel  
       }  
       else {  
         $Titles[$page_number] =  $slidetitle[0];  
   
         print SLIDE "<title>$slidetitle[0]</title>\n";  
         print SLIDE $style_link;  
         print SLIDE "</head>\n";  
   
         if ($dostyle) {  
           print SLIDE "<body>\n";  
         }  
         else {  
           print SLIDE "<body background=\"back.gif\">\n";  
         }  
         
         my $navbar = "<table class=\"navbar\" width=\"100%\"><tr>\n";  
         $navbar .= "<td align=\"left\"><a href=\"$prev\">Previous</td>\n";  
         $navbar .= "<td align=\"left\"><a href=\"$index\">Index</td>\n";  
         $navbar .= "<td align=\"right\"><a href=\"$next\">Next</td>\n";  
         $navbar .= "</table>\n";  
   
         print SLIDE "$navbar<hr>\n";  
         if ($dostyle) {  
           print SLIDE "<img class=\"logo\" src=\"logo.gif\">\n";  
           print SLIDE "<h1 class=\"title\">$slidetitle[1]</h1>\n";  
         }  
         else {  
           print SLIDE "<table width=\"100%\"><tr><td>\n";  
           print SLIDE "<img src=\"logo.gif\">\n";  
           print SLIDE "<td align=\"left\">";  
           print SLIDE "<h1>";  
           print SLIDE "<font size=\"7\" color=\"maroon\">$slidetitle[1]";  
           print SLIDE "</font></h1>\n";  
           print SLIDE "<tr><td colspan=\"2\">\n";  
           print SLIDE "<table width=\"80%\"><tr><td>\n";  
           print SLIDE "<font size=\"+2\">\n";  
         }  
         print SLIDE $body;  
   
         if ($inlist) {  
           print SLIDE "\n</$inlist>\n";  
         }  
   
         unless ($dostyle) {  
           print SLIDE "\n</font>\n";  
           print SLIDE "\n</table></table>\n";  
         }  
   
         print SLIDE "\n<hr>\n$navbar";  
         print SLIDE "</body>\n</html>\n";  
         close(SLIDE);  
       }  
     };  
 }  # End slide  
   
 sub title {  
   package main;  
   
   my ($xp, $el, $attref, $ncref) = @_;  
   
   if ($xp->current_element eq 'slide') {  
     start_mode($xp, 'pass');  
   
     $$ncref =  
       sub {  
         $slidetitle[0] = $Text;  
         $slidetitle[1] = $Markedup_Text;  
       };  
   }  
 }  # End title  
   
 sub point {  
   package main;  
   
   my ($xp, $el, $attref, $ncref) = @_;  
   
   if ($inlist and $inlist ne 'ul') {  
     $body .= "\n</$inlist>\n";  
     $inlist = 0;  
   }  
   
   unless ($inlist) {  
     $body .= "\n<ul>\n";  
   }  
   
   $inlist = 0;  
   
   if ($dostyle) {  
     $body .= "\n<li><div class=\"point\">";  
   }  
   else {  
     $body .= "\n<li>";  
   }  
   
   $$ncref =  
     sub {  
       my ($xp, $text) = @_;  
   
       if (defined $text) {  
         $text =~ s/\s+/ /g;  
         $body .= $text;  
       }  
       else {  
         if ($dostyle) {  
           $body .= "</div></li>";  
         }  
         $body .= "\n</$inlist>\n"  
           if $inlist;  
         $inlist = 'ul';  
       }  
     };  
   
 }  # End point  
   
 sub item {  
   package main;  
   
   my ($xp, $el, $attref, $ncref) = @_;  
   
   if ($inlist and $inlist ne 'ul') {  
     $body .= "\n</$inlist>\n";  
     $inlist = 0;  
   }  
   
   unless ($inlist) {  
     $body .= "\n<ul>\n";  
   }  
   
   $inlist = 0;  
   
   if ($dostyle) {  
     $body .= "\n<li><div class=\"item\">";  
   }  
   else {  
     $body .= "\n<li><font face=\"monospace\">";  
   }  
   
   $$ncref =  
     sub {  
       my ($xp, $text) = @_;  
   
       if (defined $text) {  
         $text =~ s/\s+/ /g;  
         $body .= $text;  
       }  
       else {  
         if ($dostyle) {  
           $body .= "</div></li>";  
         }  
         else {  
           $body .= "</font>";  
         }  
         $body .= "\n</$inlist>\n"  
           if $inlist;  
         $inlist = 'ul';  
       }  
     };  
 }  # End item  
   
 sub def {  
   package main;  
   
   my ($xp, $el, $attref, $ncref) = @_;  
   
   if ($inlist and $inlist ne 'dl') {  
     $body .= "\n</$inlist>\n";  
     $inlist = 0;  
   }  
   
   unless ($inlist) {  
     $body .= "\n<dl>\n";  
   }  
   
   $inlist = 0;  
   
   if ($dostyle) {  
     $body .= "<dt><span class=\"defterm\">";  
     $body .=  $attref->{term} ."</span></dt>\n";  
     $body .= "<dd><div class=\"def\">\n";  
   }  
   else {  
     $body .= "<dt><font face=\"monospace\" color=\"maroon\" style=\"bold\">";  
     $body .= $attref->{term} . "</font></dt>\n";  
     $body .= "<dd>";  
   }  
   
   $$ncref =  
     sub {  
       my ($xp, $text) = @_;  
   
       if (defined $text) {  
         $text =~ s/\s+/ /g;  
         $body .= $text;  
       }  
       else {  
         if ($dostyle) {  
           $body .= "</div></dd>\n";  
         }  
         $body .= "\n</$inlist>\n"  
           if $inlist;  
         $inlist = 'dl';  
       }  
     };  
 }  # End def  
   
 sub eg {  
   package main;  
   
   my ($xp, $el, $attref, $ncref) = @_;  
   
   if ($dostyle) {  
     $body .= "<div class=\"eg\"><pre>";  
   }  
   else {  
     $body .= "<table bgcolor=\"tan\" width=\"70%\"><tr><td>\n";  
     $body .= "<font size=\"+1\"><pre>";  
   }  
   
   $$ncref =  
     sub {  
       my ($xp, $text) = @_;  
   
       if (defined $text) {  
         $body .= $text;  
       }  
       else {  
         if ($dostyle) {  
           $body .= "</pre></div>\n";  
         }  
         else {  
           $body .= "</pre></font></td></tr></table>\n"  
         }  
       }  
     };  
 }  # End eg  
   
 sub key {  
   package main;  
   
   my ($xp, $el, $attref, $ncref) = @_;  
   
   if ($dostyle) {  
     $body .= "<span class=\"key\">";  
   }  
   else {  
     $body .= "<font face=\"monospace\" color=\"navy\">";  
   }  
   
   $$ncref =  
     sub {  
       my ($xp, $text) = @_;  
   
       if (defined $text) {  
         $body .= $text;  
       }  
       else {  
         if ($dostyle) {  
           $body .= "</span>";  
         }  
         else {  
           $body .= "</font>";  
         }  
       }  
     };  
 }  # End key  
   
 sub abstract {  
   package main;  
   
   my ($xp, $el, $attref, $ncref) = @_;  
   
   if ($dostyle) {  
     $body .= "<span class=\"abstract\">";  
   }  
   else {  
     $body .= "<font color=\"green\">";  
   }  
   
   $$ncref =  
     sub {  
       my ($xp, $text) = @_;  
   
       if (defined $text) {  
         $body .= $text;  
       }  
       else {  
         if ($dostyle) {  
           $body .= "</span>";  
         }  
         else {  
           $body .= "</font>";  
         }  
       }  
     };  
 }  # End abstract  
   
 sub screen {  
   package main;  
   
   my ($xp, $el, $attref, $ncref) = @_;  
   
   if ($dostyle) {  
     $body .= "<pre class=\"screen\">\n";  
   }  
   else {  
     $body .= "<table bgcolor=\"white\" border=\"1\" width=\"70%\"><tr><td>\n";  
     $body .= "<font size=\"+1\"><pre>";  
   }  
   
   $$ncref =  
     sub {  
       my ($xp, $text) = @_;  
   
       if (defined $text) {  
         $body .= $text;  
       }  
       else {  
         if ($dostyle) {  
           $body .= "</pre>\n";  
         }  
         else {  
           $body .= "</pre></td></tr></table>\n";  
         }  
       }  
     };  
 }  # End screen  
   
 sub input {  
   package main;  
790    
791    my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
792    
793    if ($dostyle) {          $body.="<p>";
     $body .= "<span class=\"input\">";  
   }  
   else {  
     $body .= "<b>";  
   }  
794    
795    $$ncref =          $$ncref = sub {
796      sub {                  my ($xp, $text) = @_;
       my ($xp, $text) = @_;  
797    
798        if (defined $text) {                  if (defined $text) {
799          $body .= $text;                          $body.=x($text);
800        }                  } elsif ($attref->{include}) {
801        else {                          $body.=suck_file($attref->{include});
802          if ($dostyle) {                  } else {
803            $body .= "</span>";                          $body.="</p>";
804          }                  }
         else {  
           $body .= "</b>";  
805          }          }
       }  
     };  
 }  # End input  
   
 sub group {  
 }  # End group  
   
 sub text {  
   package main;  
   
   my ($xp, $el, $attref, $ncref) = @_;  
   
   $body .= "<p>\n";  
   
   $$ncref =  
     sub {  
       my ($xp, $text) = @_;  
   
       if (defined $text) {  
         $text =~ s/\s+/ /g;  
         $body .= $text;  
       }  
     };  
 }  # End text  
   
 sub book {  
   package main;  
   
   my ($xp, $el, $attref, $ncref) = @_;  
   
   start_mode($xp, 'object');  
   
   $$ncref =  
     sub {  
       my ($xp) = @_;  
   
       if ($dostyle) {  
         $body .= "<span class=\"booktitle\">";  
         $body .= sgml_escape($Object->{title});  
         $body .= "</span>\n";  
       }  
       else {  
         $body .= "<cite>" . sgml_escape($Object->{title}) . "</cite>\n";  
       }  
     };  
806  }  }
807    
808  sub aside {  print "\n\nTo create database for poll $poll use:\n\n";
809    package main;  print "\$ psql template1 < $poll/$poll.sql\n\n";
810    print "THIS WILL DISTROY ALL DATA IN EXISTING DATABASE ".$prefix.$poll." !!\n";
   my ($xp, $el, $attref, $ncref) = @_;  
811    
812    if ($dostyle) {  # read configuration data
813      $body .= "<span class=\"aside\">[";  #
814    }  # FIX: write actually this :-)
815    else {  sub config {
816      $body .= "<em>[";          package main;
817    }          my ($xp, $el, $attref, $ncref) = @_;
     
818    
819    $$ncref =          $$ncref = sub {
820      sub {                  my ($xp, $text) = @_;
821        my ($xp, $text) = @_;                  $db_user=x($attref->{db_user});
822                    $prefix=x($attref->{prefix});
823                    $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        if (defined $text) {                  foreach my $file (qw(header separator submit footer thanks)) {
829          $body .= $text;                          if ($attref->{$file}) {
830        }                                  $include_files{$file}=x($attref->{$file});
831        else {                                  print "Using custom $file '$include_files{$file}'\n";
832          if ($dostyle) {                                  $html{$file} = suck_file($include_files{$file});
833            $body .= "]</span>\n";                          }
834          }                  }
         else {  
           $body .= "]</em>";  
835          }          }
       }  
     };  
836  }  }
837    
838  sub url {  #---------------------------------------------------------------
   package main;  
   
   my ($xp, $el, $attref, $ncref) = @_;  
   
   my $url='';  
   
   $$ncref =  
     sub {  
       my ($xp, $text) = @_;  
   
       if (defined($text)) {  
         $url .= $text;  
       }  
       else {  
         $body .= "<a href=\"$url\">$url</a>";  
       }  
     }  
 }  
   
 ## Local Variables: ##  
 ## mode:perl ##  
 ## End: ##  

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

  ViewVC Help
Powered by ViewVC 1.1.26