/[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.1.1.1 by dpavlin, Tue Apr 8 17:53:46 2003 UTC revision 1.22 by dpavlin, Mon Apr 19 16:33:10 2004 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2  #  #
3    # Dobrica Pavlinusic <dpavlin@rot13.org>
4  use XML::Parser;  #
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;
12    use Carp;
13    use Text::Iconv;
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 $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 62  my $prefix="wopi_"; Line 55  my $prefix="wopi_";
55  # this is usename in database  # this is usename in database
56  my $db_user="dpavlin";  my $db_user="dpavlin";
57    
58  #------------------------------------------------------------------  # This option allows users to fill poll without using invitation URL.
59    # That also means it's unpossible for them to return to exiting poll
60    # because they don't have thair own unique ID. Howver, it enables simple
61    # polls to be conducted by just publishing URL to them.
62    my $without_invitation=0;
63    
64    # This will remove numbers before answers. That enables you to have
65    # answers written like:
66    # 1.1 red
67    # 1.2 black
68    # and users will see just "red" and "black"
69    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  my $html_header.=<<'End_of_header;';  1;
 <html>  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
         <title>proof.anketa</title><link rel="STYLESHEET" type="text/css" href="../stil.css">  
 </head>  
   
 <body background="../beki.gif" bgcolor="White" leftmargin=0 topmargin=0 marginwidth="0" marginheight="0">  
   
 <table width="460" cellspacing="0" cellpadding="0" border="0">  
 <tr>  
     <td colspan="2"><img src="head.php" width=460 height=72 alt="" border="0"><br><br></td>  
 </tr>  
 <tr>  
     <td><img src="../klir.gif" width=20 height=1 alt="" border="0"><br>  
         </td>  
     <td><img src="../klir.gif" width=332 height=1 alt="" border="0"><br>        </td>  
 </tr>  
 <form method=post action="##NEXTPAGE##">  
 <input type=hidden name=a value="<?= $a ?>">  
 <input type=hidden name=id value="<?= $id ?>">  
   
 <tr>  
     <td> </td>  
     <td>  
 End_of_header;  
127    
128  #------------------------------------------------------------------  #------------------------------------------------------------------
129    
130  my $html_separator=<<'End_of_separator;';  sub suck_file {
131  <tr>          my $file = shift || croak "suck_file called without argument";
132      <td></td>          if (! -f $file) {
133      <td bgcolor="#006699"><img src="../klir.gif" width=1 height=1 alt="" border="0"><br></td>                  my $template_file = $file;
134  </tr>                  $template_file =~ s,^.*?/*([^/]+)$,$1,;
135  End_of_separator;                  if (-f $template_file) {
136                            print "WARNING: can't find '$file', copy template '$template_file' ? [Y/n]: ";
137                            my $a = <STDIN>;
138                            chomp $a;
139                            if ($a =~ m/^y/i || $a eq "") {
140                                    open(I,$template_file) || die "FATAL: can't open template file '$template_file': $!";
141                                    open(O,"> $file") || die "FATAL: can't create '$file' from template: $!";
142                                    while(<I>) {
143                                            print O $_;
144                                    }
145                                    close(I);
146                                    close(O);
147                                    print "File '$file' created from template '$template_file'\n";
148                            }
149                    }
150    
151  #------------------------------------------------------------------          }
152    
153  my $html_footer=<<'End_of_footer;';          if (! -f $file) {
154  </td>                  print STDERR "FATAL: please create file $file and then re-run this script!\n";
155  </tr>                  exit 1;
156            }
157  <tr>  
158      <td> </td>          open(H,$file) || die "FATAL: can't open '$file': $!";
159      <td align="right"><br>          my $content;
160  <input type=submit name="update" value="dalje.">&nbsp;&nbsp;          while (<H>) { $content .= $_; } ;
161  <br><br><br>          close(H);
162  </td>          return $content;
163  </tr>  }
164  </table>  
165    $html{'header'}=suck_file($include_files{'header'});
166  </body>  $html{'separator'}=suck_file($include_files{'separator'});
167  </html>  $html{'submit'}=suck_file($include_files{'submit'});
168  End_of_footer;  $html{'footer'}=suck_file($include_files{'footer'});
169    
170  #------------------------------------------------------------------  #------------------------------------------------------------------
171    
172  sub php_header {  sub php_header {
173  my ($page_nr,@sql_update) = @_;  my ($page_nr,@sql_update) = @_;
174  my $out='<?  my $out='<?php
175          include("common.inc");          include_once("common.php");
176          if (isset($update)) {          if (isset($update)) {
177                  $member_id=id_decode($a);                  $member_id=id_decode($a);
178                  ';                  ';
179  $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]);
180  $out.='  $out.='
181                  $sql="update '.$dir.' set '.join(",\n",@sql_update).',                  $sql="update '.$poll.' set '.join(",\n",@sql_update).',
182                          do_stranice=\'$PHP_SELF\'                          do_stranice=\'$PHP_SELF\'
183                          where id=$id";                          where id=$id";
184  #               print "<pre>$sql</pre>";  #               print "<pre>$sql</pre>";
185                  $result=pg_Exec($conn,fix_sql($sql));                  $result=pg_Exec($conn,fix_sql($sql));
186          } elseif($do_stranice != $PHP_SELF) {          } elseif($do_stranice != $PHP_SELF && isset($do_uri) && isset($a)) {
187                  Header("Location: $do_uri?a=$a");                  Header("Location: $do_uri?a=$a");
188                  exit;                  exit;
189          }          }
# Line 146  return $out; Line 194  return $out;
194  #------------------------------------------------------------------  #------------------------------------------------------------------
195    
196  # first, define some constants  # first, define some constants
197  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;  
198    
199  #------------------------------------------------------------------  #------------------------------------------------------------------
200    
201  my $head_php.=<<'End_of_head;';  my $head_php=suck_file("head.php");
   
         Header("Content-type: image/gif");  
         header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past  
         header ("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); // always modified  
         header ("Cache-Control: no-cache, must-revalidate");    // HTTP/1.1  
         header ("Pragma: no-cache");                            // HTTP/1.0  
         $string=implode($argv," ");  
         $im = imagecreatefromgif("head.gif");  
         $red = ImageColorAllocate($im, 255, 0, 0);  
         $black = ImageColorAllocate($im, 0, 0, 0);  
         $px = (imagesx($im)-7.5*strlen($string))/2;  
         if (! isset($pcnt)) {  
                 $pcnt=floor(substr(basename($HTTP_REFERER),0,2)/$max_page*100);  
         }  
         ImageTTFText($im, 6, 0, 10, 65, $black, dirname($PATH_TRANSLATED)."/head.ttf", "Ispunili ste ".sprintf("%02d",$pcnt)."% ankete");  
         $w=80;  
         ImageRectangle($im,149,60,151+$w,66,$black);  
         ImageFilledRectangle($im,150,61,150+floor($pcnt*$w/100),65,$red);  
         ImageGif($im);  
         ImageDestroy($im);  
   
 End_of_head;  
202    
203  #------------------------------------------------------------------  #------------------------------------------------------------------
204    
205  my $html_kraj=<<'End_of_kraj;';  $html{'thanks'}=suck_file($include_files{'thanks'});
 <html>  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">  
         <title>wopi.poll</title><link rel="STYLESHEET" type="text/css" href="../stil.css">  
 </head>  
   
 <body background="../beki.gif" bgcolor="White" leftmargin=0 topmargin=0 marginwidth="0" marginheight="0">  
   
 <table width="460" cellspacing="0" cellpadding="0" border="0">  
 <tr>  
     <td colspan="2"><img src="head.php?pcnt=100" width=460 height=72 alt="" border="0"><br><br></td>  
 </tr>  
 <tr>  
     <td><img src="../klir.gif" width=20 height=1 alt="" border="0"><br>  
         </td>  
     <td><img src="../klir.gif" width=332 height=1 alt="" border="0"><br>        </td>  
 </tr>  
     <td><img src="../klir.gif" width=20 height=1 alt="" border="0"><br>  
         </td>  
     <td><img src="../klir.gif" width=332 height=1 alt="" border="0"><br>        </td>  
 </tr>  
 <tr>  
     <td> </td>  
     <td><br>  
 <p><b>  
 Hvala vam na sudjelovanju u anketi!  
 </b></p>  
 <br><br>  
 Zahvaljujemo se na va¹em vremenu. Nadamo se da æete i vi biti  
 meðu sretnim dobitnicima.  
 <br>  
 <br>  
 Do slijedeæe ankete i nagradne igre srdaèno vas pozdravljamo.  
 <br>  
 <br>Hvala.  
 <br>  
 <br>  
 <a href="http://www.proof.hr"><tt>proof.</tt></a>  
 </td>  
 </tr>  
 <tr>  
     <td></td>  
     <td bgcolor="#006699"><img src="../klir.gif" width=1 height=1 alt="" border="0"><br></td>  
 </tr>  
 <tr>  
     <td align="right" valign="top"></td>  
     <td> </td>  
     <td align="right"><br>  
 <br>  
 </td>  
 </tr>  
 </table>  
   
 </body>  
 </html>  
 End_of_kraj;  
206    
207  #------------------------------------------------------------------  #------------------------------------------------------------------
208    
# Line 353  while (defined($ARGV[0]) and $ARGV[0] =~ Line 213  while (defined($ARGV[0]) and $ARGV[0] =~
213      print $Usage;      print $Usage;
214      exit;      exit;
215    }    }
   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";  
   }  
216  }  # End of option processing  }  # End of option processing
217    
218  my $docfile = shift;  my $xmlfile = shift;
219    
220  die "No docfile provided:\n$Usage" unless defined $docfile;  die "No poll xml file provided!\n$Usage" unless defined $xmlfile;
221    
222  die "Can't read $docfile" unless -r $docfile;  die "Can't read $xmlfile" unless -r $xmlfile;
223    
224  if (defined $dir) {  if (defined $poll) {
225    die "$dir isn't a directory" unless -d $dir;    die "$poll isn't a directory" unless -d $poll;
226  }  }
227  else {  else {
228    $docfile =~ m!([^/.]+)(?:\.[^/.]*)?$!;    $xmlfile =~ m!([^/.]+)(?:\.[^/.]*)?$!;
229    $dir = $1;    $poll = $1;
230    if (-e $dir) {    if (-e $poll) {
231      die "$dir exists but isn't a directory"      die "$poll exists but isn't a directory"
232        unless -d $dir;        unless -d $poll;
233    }    }
234    else {    else {
235      mkdir $dir, 0755;      mkdir $poll, 0755;
236    }    }
237  }  }
238    
239  my $in_slideshow = 0;  my $in_poll = 0;
240  my $after_head = 0;  my $after_head = 0;
241    
242  my $Mode = 0;  my $Mode = 0;
# Line 405  my $Markedup_Text; Line 247  my $Markedup_Text;
247  my $Object;  my $Object;
248  my @Ostack = ();  my @Ostack = ();
249    
250  my $intext = 0;  #my $intext = 0;
251  my $closure;  my $closure;
252  my @closure_stack = ();  my @closure_stack = ();
253    
254  my $style_link = '';  #my $style_link = '';
255    
256  my $index = 'index.html';  #my $index = 'index.html';
257  my @slidetitle;  #my @slidetitle;
258  my $body;  my $body;
259  my $inlist = 0;  #my $inlist = 0;
260    
261  my @Titles;  #my @Titles;
262    
263  my $header;  my $header;
264    
 my $prolog = "<html><head>\n";  
 $prolog .= "<!-- Generated by $0 on " . gmtime() . " GMT -->\n";  
   
265  my $page_number = 0;  my $page_number = 0;
266    
267  my $p = new XML::Parser(ErrorContext => 3,  my $p = new XML::Parser(ErrorContext => 3,
268                          Handlers => {Start => \&starthndl,                          Handlers => {Start => \&starthndl,
269                                       End   => \&endhndl,                                       End   => \&endhndl,
270                                       Char  => \&text});                                       Char  => \&text});
271  $p->parsefile($docfile);  $p->parsefile($xmlfile);
272    
273  #----------------------------------------------------------  #----------------------------------------------------------
274    
# Line 437  $p->parsefile($docfile); Line 276  $p->parsefile($docfile);
276    
277  print "p[$page_nr] ";  print "p[$page_nr] ";
278    
279  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$!";
280  print PAGE php_header($page_nr,@prelast_sql_update);  print PAGE php_header($page_nr,@prelast_sql_update);
281  my $next_fn=sprintf("%02d.php",$page_nr);  my $next_fn=sprintf("%02d.php",$page_nr);
282  $last_page=~s/##NEXTPAGE##/$next_fn/;  $last_page=~s/##NEXTPAGE##/$next_fn/;
# Line 445  print PAGE $last_page; Line 284  print PAGE $last_page;
284  close(PAGE);  close(PAGE);
285    
286  $page_nr++;  $page_nr++;
287  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$!";
288  print PAGE php_header($page_nr,@last_sql_update);  print PAGE php_header($page_nr,@last_sql_update);
289  print PAGE $html_kraj;  print PAGE "$html{'header'} $html{'thanks'} $html{'footer'}";
290  close(PAGE);  close(PAGE);
291    
292  # dump sql structure  # dump sql structure
293    
294  open(SQL,">$dir/$dir.sql") || die "$dir.sql: $!";  open(SQL,">$poll/$poll.sql") || die "$poll.sql: $!";
295    print SQL "drop database ".$prefix.$poll.";\n";
296    print SQL "create database ".$prefix.$poll.";\n";
297    print SQL "\\connect ".$prefix.$poll.";\n";
298  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";
299  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";
300  close(SQL);  close(SQL);
301    
302  # dump common.inc  # dump common.php
303    
304    open(PHP,">$poll/common.php") || die "common.php: $!";
305    $common_php =~ s/##DB##/$poll/g;
306    my $db_name = $prefix.$poll;
307    $common_php =~ s/##DB_NAME##/$db_name/g;
308    $common_php =~ s/##PREFIX##/$prefix/g;
309    $common_php =~ s/##DB_USER##/$db_user/g;
310    $common_php =~ s/##PREFIX##/$prefix/g;
311    my $members_db = $prefix."members";
312    $common_php =~ s/##MEMBERS_DB##/$members_db/g;
313    $common_php =~ s/##WITHOUT_INVITATION##/$without_invitation/g;
314    
315  open(PHP,">$dir/common.inc") || die "common.inc: $!";  print PHP $common_php;
 print PHP '<? $db="'.$dir.'";';  
 print PHP $common_inc;  
 print PHP '?>';  
316  close(PHP);  close(PHP);
317    
318  open(PHP,">$dir/head.php") || die "head.php: $!";  open(PHP,">$poll/head.php") || die "head.php: $!";
319  print PHP '<? $max_page="'.($page_nr+1).'";';  my $max_page = $page_nr - 1;
320    $head_php=~ s/##MAXPAGE##/$max_page/;
321    $head_php=~ s/##TEXT##/Ispunili ste %02d%% ankete/;
322  print PHP $head_php;  print PHP $head_php;
 print PHP '?>';  
323  close(PHP);  close(PHP);
324    
325    # 01.php -> index.php
326    rename "$poll/01.php","$poll/index.php" || die "can't rename '$poll/01.php' to index.php";
327    
328  ################  ################
329  ## End of main  ## End of main
330  ################  ################
331    
332  # return unique name of pitanje  # return unique name of question
333  sub new_pit {  sub new_que {
334          my $out="p".$pitanje_nr.$p_suffix;          my $out=$q_type.( $question_nr{$q_type} || 0 );
335            $out .= "_".$p_suffix if ($p_suffix);
336          $curr_suffix=$p_suffix;          $curr_suffix=$p_suffix;
337          $p_suffix++;          $p_suffix++;
338          return $out;          return $out;
339  }  }
340    
341  # current pitanje  # current question
342  sub curr_pit {  sub curr_que {
343          return "p".$pitanje_nr.$curr_suffix;          return $q_type.( $question_nr{$q_type} || 0 ).$curr_suffix;
344  }  }
345    
346    #----------------------------------------------------------
347    
348  sub starthndl {  sub starthndl {
349    my ($xp, $el, %atts) = @_;          my ($xp, $el, %atts) = @_;
350    
351  #  return unless ($in_slideshow or $el eq 'slideshow');  #       return unless ($in_poll or $el eq 'slideshow');
352    
353    unless ($in_slideshow) {          unless ($in_poll) {
354      $in_slideshow = $xp->depth + 1;                  $in_poll = $xp->depth + 1;
355      return;                  return;
356    }          }
357    
358    if ($Mode) {          if ($Mode) {
359                    if ($Mode eq 'pass') {
360                            $Markedup_Text .= "\n" . $xp->recognized_string;
361                    } elsif ($Mode eq 'object') {
362                            push(@Ostack, $Object);
363    
364      if ($Mode eq 'pass') {                          $Object = {
365        $Markedup_Text .= "\n" . $xp->recognized_string;                                  _Atts     => \%atts,
366      }                                  _Text    => ''
367      elsif ($Mode eq 'object') {                          };
368        push(@Ostack, $Object);                          bless $Object, "Slideobj::$el";
369                    }
370    
371        $Object = {_Atts    => \%atts,                  # skip does nothing
372                   _Text    => ''                  return;
373                  };          }
       bless $Object, "Slideobj::$el";  
     }  
374    
375      # skip does nothing          unless ($after_head) {
376      return;                  if ($el eq 'head') {
377    }                          $after_head = 1;
378                            start_mode($xp, 'object');
379    
380    unless ($after_head) {                          push(@closure_stack, $closure);
381      if ($el eq 'head') {                          $closure = sub {
382        $after_head = 1;                                  my ($xp, $text) = @_;
       start_mode($xp, 'object');  
   
       push(@closure_stack, $closure);  
       $closure =  
         sub {  
           my ($xp, $text) = @_;  
   
           unless (defined $text) {  
               
             $header = $Object;  
           }  
         };  
383    
384        return;                                  unless (defined $text) {
385      }                                          $header = $Object;
386                                    }
387                            };
388                            return;
389                    }
390    
391  #    die "The head element must be the first thing in the slideshow";  #               die "The head element must be the first thing in the slideshow";
392    }          }
393    
394    
395    my $new_closure;          my $new_closure;
396    
397    my $subname = "Slideshow::$el";          my $subname = "Poll::$el";
398    
399    if (defined &$subname) {          if (defined &$subname) {
400      no strict 'refs';                  no strict 'refs';
401    
402      &$subname($xp, $el, \%atts, \$new_closure);                  &$subname($xp, $el, \%atts, \$new_closure);
403    }          } else {
404    else {                  $body .= x($xp->recognized_string);
405      $body .= $xp->recognized_string;                  $new_closure = sub {
406      $new_closure =                          my ($xp, $text) = @_;
407        sub {  
408          my ($xp, $text) = @_;                          if (defined $text) {
409                                            $body .= x($text);
410          if (defined $text) {                          } else {
411            $body .= $text;                                  $body .= x("</$el>");
412          }                          }
413          else {                  };
           $body .= "</$el>";  
414          }          }
       };  
   }  
415    
416    push(@closure_stack, $closure);          push(@closure_stack, $closure);
417    $closure = $new_closure;          $closure = $new_closure;
418  }  # End starthndl  }       # End starthndl
419    
420  sub endhndl {  sub endhndl {
421    my ($xp, $el) = @_;          my ($xp, $el) = @_;
422    
423    return unless $in_slideshow;          return unless $in_poll;
424    
425    my $lev = $xp->depth;          my $lev = $xp->depth;
426    
427    if ($lev == $in_slideshow - 1) {          if ($lev == $in_poll - 1) {
428      $in_slideshow = 0;                  $in_poll = 0;
429      $xp->finish;                  $xp->finish;
430      return;                  return;
431    }          }
432              
433    if ($Mode_level == $lev) {          if ($Mode_level == $lev) {
434                        
435      if ($Mode eq 'pass') {                  if ($Mode eq 'pass') {
436        &$closure($xp, $Markedup_Text)                          &$closure($xp, $Markedup_Text) if (defined $closure);
437          if (defined $closure);                  }
     }  
438    
439      $Mode = $Mode_level = 0;                  $Mode = $Mode_level = 0;
440    }          }
441    
442    if ($Mode) {          if ($Mode) {
443      if ($Mode eq 'pass') {                  if ($Mode eq 'pass') {
444        $Markedup_Text .= "</$el>";                          $Markedup_Text .= "</$el>";
445      }                  } elsif ($Mode eq 'object') {
446      elsif ($Mode eq 'object') {                          my $this = $Object;
447        my $this = $Object;                          if (2 == keys %$this) {
448        if (2 == keys %$this) {                                  $this = $this->{_Text};
449          $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;  
       }  
     }  
450    
451      return;                          $Object = pop(@Ostack);
452    }  
453                            my $slot = $Object->{$el};
454                            if (defined $slot) {
455                                    if (ref($slot) eq 'ARRAY') {
456                                            push(@$slot, $this);
457                                    } else {
458                                            $Object->{$el} = [$slot, $this];
459                                    }
460                            } else {
461                                    $Object->{$el} = $this;
462                            }
463                    }
464    
465    &$closure($xp)                  return;
466      if defined $closure;          }
467    
468    $closure = pop(@closure_stack);          &$closure($xp) if defined $closure;
469    
470            $closure = pop(@closure_stack);
471  }  # End endhndl  }  # End endhndl
472    
473    #----------------------------------------------------------
474    
475  sub text {  sub text {
476    my ($xp, $data) = @_;          my ($xp, $data) = @_;
477    
478    return unless $in_slideshow;          return unless $in_poll;
479    
480    if ($Mode ) {          if ($Mode) {
481    
482      if ($Mode eq 'pass') {                  if ($Mode eq 'pass') {
483        my $safe = sgml_escape($data);                          my $safe = sgml_escape($data);
484    
485        $Text .= $safe;                          $Text .= $safe;
486        $Markedup_Text .= $safe;                          $Markedup_Text .= $safe;
487      }                  } elsif ($Mode eq 'object') {
488      elsif ($Mode eq 'object') {                          $Object->{_Text} .= $data if $data =~ /\S/;
489        $Object->{_Text} .= $data                  }
         if $data =~ /\S/;  
     }  
490    
491      return;                  return;
492    }          }
493    
494    &$closure($xp, sgml_escape($data))          &$closure($xp, sgml_escape($data)) if (defined $closure);
     if (defined $closure);  
495    
496  }  # End text  }  # End text
497    
498  sub start_mode {  sub start_mode {
499    my ($xp, $mode) = @_;          my ($xp, $mode) = @_;
500    
501    if ($mode eq 'pass') {          if ($mode eq 'pass') {
502      $Text = '';                  $Text = '';
503      $Markedup_Text = '';                  $Markedup_Text = '';
504    }          } elsif ($mode eq 'object') {
505    elsif ($mode eq 'object') {                  $Object = {
506      $Object = {_Atts => undef,                          _Atts => undef,
507                 _Text => undef                          _Text => undef
508                };                  };
509    }          }
510    
511    $Mode = $mode;          $Mode = $mode;
512    $Mode_level = $xp->depth;          $Mode_level = $xp->depth;
513  }  # End start_mode  }  # End start_mode
514    
515  sub sgml_escape {  sub sgml_escape {
516    my ($str) = @_;          my ($str) = @_;
517    
518    $str =~ s/\&/\&amp;/g;          $str =~ s/\&/\&amp;/g;
519    $str =~ s/</\&lt;/g;          $str =~ s/</\&lt;/g;
520    $str =~ s/>/\&gt;/g;          $str =~ s/>/\&gt;/g;
521    
522    $str;          $str;
523  }  # End sgml_escape  }  # End sgml_escape
524    
 sub slidename {  
   my ($num) = @_;  
   
   sprintf("slide%03d.html", $num);  
 }  # End slidename  
   
525  ################################################################  ################################################################
526    
527  package Slideshow;  package Poll;
528    
529  sub page {  sub page {
530          package main;          package main;
# Line 701  sub page { Line 539  sub page {
539                          print "p[$page_nr] ";                          print "p[$page_nr] ";
540    
541                          if (defined $last_fn) {                          if (defined $last_fn) {
542                                  # 01.php -> index.php                                  open(PAGE, ">$poll/$last_fn") or die "Couldn't open $last_fn for writing:\n$!";
543                                  $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  
   
   
544                                  my $next_fn=sprintf("%02d.php",$page_nr);                                  my $next_fn=sprintf("%02d.php",$page_nr);
545                                  $last_page=~s/##NEXTPAGE##/$next_fn/;                                  $last_page=~s/##NEXTPAGE##/$next_fn/;
546                                  print PAGE $last_page;                                  print PAGE $last_page;
# Line 738  $sql="insert into '.$dir.' ( http_refere Line 552  $sql="insert into '.$dir.' ( http_refere
552                          @sql_update = ();                          @sql_update = ();
553                    
554                          $last_fn=sprintf("%02d.php",$page_nr);                          $last_fn=sprintf("%02d.php",$page_nr);
555                          $last_page="$html_header $body $html_footer";                          $last_page="$html{'header'} $body $html{'submit'} $html{'footer'}";
556                          # delete vars for next page                          # delete vars for next page
557                          $page_nr++;                          $page_nr++;
558                          $body="";                          $body="";
# Line 751  sub nr { Line 565  sub nr {
565    
566          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
567    
568          $pitanje_tag="";          $question_tag="";
569    
570          $$ncref = sub {          $$ncref = sub {
571                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
572                  if (defined($text)) {                  if (defined($text)) {
573                          $body.=$text;                          $body.=x($text);
574                          chomp $text;                          chomp $text;
575                          $pitanje_tag .= $text;                          $question_tag .= x($text);
576                  } else {                  } else {
577                          $pitanje_nr = $pitanje_tag;                          $question_nr{$q_type} = $question_tag;
578                          $pitanje_nr =~ s/[^0-9a-zA-Z]//g;                          $question_nr{$q_type} =~ s/[^0-9a-zA-Z]//g;
579                          print "$pitanje_nr ";                          print "$question_nr{$q_type} ";
580                  }                  }
581                  $p_suffix="";                  $p_suffix="";
582          };          };
# Line 770  sub nr { Line 584  sub nr {
584    
585    
586  sub hr {  sub hr {
587          $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";  
588  }  }
589    
590  sub pit {  sub que {
591          package main;          package main;
592    
593          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
594    
595          $body.="<p>";          my $nonum = x($attref->{unnumbered});
596            if ($nonum) {
597                    $q_type = $u_db_col;    # unnumbered questions
598            } else {
599                    $q_type = $q_db_col;
600            }
601            
602            $question_nr{$q_type}++;
603    
604            # attribute markup_before override que_before
605            my $markup_before = x($attref->{markup_before});
606            my $markup_after = x($attref->{markup_after});
607    
608            if (defined($markup_before)) {
609                    $body.=$markup_before;
610            } elsif ($html{'que_before'}) {
611                    $body.=$html{'que_before'}
612            }
613    
614          $$ncref = sub {          $$ncref = sub {
615                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
616    
617                  if (defined $text) {                  if (defined $text) {
618                          $body.=$text;                          $body.=x($text);
619                  } else {                  } else {
620                          $body.="</p>";                          if (defined($markup_after)) {
621                                    $body.=$markup_after;
622                            } elsif ($html{'que_after'}) {
623                                    $body.=$html{'que_after'}
624                            }
625                  }                  }
626          }          }
627  }  }
628    
629  sub podpit {  sub subque {
630          package main;          package main;
631    
632          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
633    
634          $body.='<table width="100%" cellspacing="0" cellpadding="2" border="0">';          my $markup_before = x($attref->{markup_before});
635            my $markup_after = x($attref->{markup_after});
636    
637            if (defined($markup_before)) {
638                    $body.=$markup_before;
639            } elsif ($html{'subque_before'}) {
640                    $body.=$html{'subque_before'}
641            }
642    
643          $$ncref = sub {          $$ncref = sub {
644                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
645    
646                  if (defined $text) {                  if (defined $text) {
647                          $body.=$text;                          $body.=x($text);
648                  } else {                  } else {
649                          $body.="</table>";                          if (defined($markup_after)) {
650                                    $body.=$markup_after;
651                            } elsif ($html{'subque_after'}) {
652                                    $body.=$html{'subque_after'}
653                            }
654                  }                  }
655          }          }
656  }  }
657    
658    
659  sub odg {  sub ans {
660          package main;          package main;
661    
662          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
663    
664          $body .= "<p>";          my $markup_before = x($attref->{markup_before});
665            my $markup_after = x($attref->{markup_after});
666    
667            if (defined($markup_before)) {
668                    $body.=$markup_before;
669            } elsif ($html{'ans_before'}) {
670                    $body.=$html{'ans_before'}
671            }
672            
673          $$ncref = sub {          $$ncref = sub {
674                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
675    
676                  if (defined $text) {                  if (defined $text) {
677                          $body .= $text;                          $body .= x($text);
678                  } else {                  } else {
679                          $body .= "</p>";                          if (defined($markup_after)) {
680                                    $body.=$markup_after;
681                            } elsif ($html{'ans_after'}) {
682                                    $body.=$html{'ans_after'}
683                            }
684                  }                  }
685          }          }
686  }  }
# Line 845  sub php { Line 699  sub php {
699                          $text=~s/ le / <= /g;                          $text=~s/ le / <= /g;
700                          $text=~s/ gt / > /g;                          $text=~s/ gt / > /g;
701                          $text=~s/ ge / >= /g;                          $text=~s/ ge / >= /g;
702                          $body.=$text;                          $body.=x($text);
703                  } else {                  } else {
704                          $body.="\n?>\n";                          $body.="\n?>\n";
705                  }                  }
# Line 859  sub dropdown { Line 713  sub dropdown {
713    
714          my @dropdown_data;          my @dropdown_data;
715    
716            my $default_value = x($attref->{default_value}) || 'null';
717            my $default_text = x($attref->{default_text}) || '-';
718    
719          $$ncref = sub {          $$ncref = sub {
720                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
721    
722                  if (defined $text) {                  if (defined $text) {
723                          chomp $text;                          chomp $text;
724                          $text=~s/^\s*//g;                          $text=~s/^\s*//g;
725                          $text=~s/^[\d\.\s]+//g;                          $text=~s/^[\d\.\s]+//g if ($remove_nrs_in_answers);
726                          $text=~s/\s*$//g;                          $text=~s/\s*$//g;
727                          push @dropdown_data,$text if ($text ne "");                          push @dropdown_data,x($text) if ($text ne "");
728                  } else {                  } else {
729                          my $opt;                          my $opt;
730                          my $id=1;                          my $id=1;
731                          my $p=new_pit();                          my $p=new_que();
732                          $body.="<select name=$p >\n";                          $body.="<select name=$p >\n";
733                          $body.="<option value=null>-</option>\n";                          $body.="<option value=\"$default_value\">$default_text</option>\n";
734                          foreach $opt (@dropdown_data) {                          foreach $opt (@dropdown_data) {
735                                  if (defined($opt) && $opt ne "") {                                  if (defined($opt) && $opt ne "") {
736                                          $body.="<option value=$id>$opt</option>\n";                                          $body.="<option value=$id>$opt</option>\n";
# Line 896  sub textbox { Line 753  sub textbox {
753                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
754                  my $size=$attref->{size};                  my $size=$attref->{size};
755                  $size = 25 if (! defined $size || $size == 0);  # default                  $size = 25 if (! defined $size || $size == 0);  # default
756                  my $p=new_pit();                  my $p=new_que();
757                  $body.="<input type=text name=$p size=$size >\n";                  $body.="<input type=text name=$p size=".x($size)." >\n";
758                  push @sql_create,"$p text";                  push @sql_create,"$p text";
759                  push @sql_update,"$p='\$$p'";                  push @sql_update,"$p='\$$p'";
760          }          }
# Line 910  sub radiobuttons_tab { Line 767  sub radiobuttons_tab {
767          $$ncref = sub {          $$ncref = sub {
768                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
769                  if (! defined $text) {                  if (! defined $text) {
770                          my $nr=$attref->{nr};                          my $nr=$attref->{nr} || die "need <radiobuttons_tab nr=\"999\"> for number of buttons";
771                          my $p=new_pit();                          # shownumbers="before|after"
772                            my $shownumbers=lc(x($attref->{shownumbers})) || 'no';
773                            my $showlabels=lc(x($attref->{showlabels})) || 'no';
774                            my $class=lc(x($attref->{class})) || '';
775                            $class=' class="'.$class.'"' if ($class);
776                            my $p=new_que();
777                          for (my $i=1; $i<=$nr; $i++) {                          for (my $i=1; $i<=$nr; $i++) {
778                                  $body.="<td><input type=radio name=$p value=$i></td> ";                                  $body.="<td$class>";
779                                    $body.=$i if ($shownumbers eq "before");
780                                    if ($showlabels eq "before" && $attref->{"label_$i"}) {
781                                            $body.=x($attref->{"label_$i"});
782                                    }
783                                    $body.="<input type=radio name=$p value=$i>";
784                                    $body.=$i if ($shownumbers eq "after");
785                                    $body.="</td> ";
786                          }                          }
787                          push @sql_create,"$p int4";                          push @sql_create,"$p int4";
788                          push @sql_update,"$p=\$$p";                          push @sql_update,"$p=\$$p";
# Line 933  sub radiobuttons { Line 802  sub radiobuttons {
802                  if (defined $text) {                  if (defined $text) {
803                          chomp $text;                          chomp $text;
804                          $text=~s/^\s*//g;                          $text=~s/^\s*//g;
805                          $text=~s/^[\d\.\s]+//g;                          $text=~s/^[\d\.\s]+//g if ($remove_nrs_in_answers);
806                          $text=~s/\s*$//g;                          $text=~s/\s*$//g;
807                          push @radiobuttons_data,$text if ($text ne "");                          push @radiobuttons_data,x($text) if ($text ne "");
808                  } else {                  } else {
809                          my $opt;                          my $opt;
810                          my $p=new_pit();                          my $p=new_que();
811                          my $id=1;                          my $id=1;
812                          foreach $opt (@radiobuttons_data) {                          foreach $opt (@radiobuttons_data) {
813                                  if (defined($opt) && $opt ne "") {                                  if (defined($opt) && $opt ne "") {
# Line 957  sub checkbox { Line 826  sub checkbox {
826    
827          $$ncref = sub {          $$ncref = sub {
828                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
829                  my $p=new_pit();                  my $p=new_que();
830                  $body.="<input type=checkbox name=$p >\n";                  $body.="<input type=checkbox name=$p >\n";
831                  push @sql_create,"$p text";                  push @sql_create,"$p text";
832                  push @sql_update,"$p='\$$p'";                  push @sql_update,"$p='\$$p'";
# Line 978  sub checkboxes { Line 847  sub checkboxes {
847                  if (defined $text) {                  if (defined $text) {
848                          chomp $text;                          chomp $text;
849                          $text=~s/^\s*//g;                          $text=~s/^\s*//g;
850                          $text=~s/^[\d\.\s]+//g;                          $text=~s/^[\d\.\s]+//g if ($remove_nrs_in_answers);
851                          $text=~s/\s*$//g;                          $text=~s/\s*$//g;
852                          push @checkboxes_data,$text if ($text ne "");                          push @checkboxes_data,x($text) if ($text ne "");
853                  } else {                  } else {
854                          my $opt;                          my $opt;
855                          my $base_p=new_pit();                          my $base_p=new_que();
856                          my $id=1;                          my $id=1;
857    
858                          my $before=$attref->{before};                          my $before=$attref->{before};
# Line 999  sub checkboxes { Line 868  sub checkboxes {
868                                  if (defined($opt) && $opt ne "") {                                  if (defined($opt) && $opt ne "") {
869                                          $p=$base_p."_".$id;                                          $p=$base_p."_".$id;
870                                          $id++;                                          $id++;
871                                          $body .= $before if ($before);                                          $body .= x($before) if ($before);
872                                          $body.="<input type=checkbox name=$p>";                                          $body.="<input type=checkbox name=$p>";
873                                          $body .= $middle if ($middle);                                          $body .= x($middle) if ($middle);
874                                          $body .= "$opt" if (! $hide_description);                                          $body .= "$opt" if (! $hide_description);
875                                          $body .= $after if ($after);                                          $body .= x($after) if ($after);
876                                          $body.="\n";                                          $body.="\n";
877    
878                                          push @sql_create,"$p boolean";                                          push @sql_create,"$p boolean";
# Line 1016  sub checkboxes { Line 885  sub checkboxes {
885          }          }
886  }  }
887    
888  #---------------------------------------------------------------  #
889    # insert arbitrary html
890  sub slide {  #
891    package main;  sub html {
892            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;  
   
   my ($xp, $el, $attref, $ncref) = @_;  
   
   if ($dostyle) {  
     $body .= "<span class=\"input\">";  
   }  
   else {  
     $body .= "<b>";  
   }  
   
   $$ncref =  
     sub {  
       my ($xp, $text) = @_;  
   
       if (defined $text) {  
         $body .= $text;  
       }  
       else {  
         if ($dostyle) {  
           $body .= "</span>";  
         }  
         else {  
           $body .= "</b>";  
         }  
       }  
     };  
 }  # End input  
   
 sub group {  
 }  # End group  
893    
894  sub text {          my ($xp, $el, $attref, $ncref) = @_;
   package main;  
895    
896    my ($xp, $el, $attref, $ncref) = @_;          $body.=$html{'html_before'} if ($html{'html_before'});
897    
898    $body .= "<p>\n";          $$ncref = sub {
899                    my ($xp, $text) = @_;
900    
901    $$ncref =                  if (defined $text) {
902      sub {                          $body.=x($text);
903        my ($xp, $text) = @_;                  } elsif ($attref->{include}) {
904                            $body.=suck_file($attref->{include});
905                    } else {
906                            $body.=$html{'html_after'} if ($html{'html_after'});
907                    }
908            }
909    }
910    
911        if (defined $text) {  #
912          $text =~ s/\s+/ /g;  # markup tag can specify any markup which should be applied pre (before)
913          $body .= $text;  # or post (after) any other tag which produces html output
914        }  #
     };  
 }  # End text  
915    
916  sub book {  sub markup {
917    package main;          package main;
918    
919    my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
920    
921    start_mode($xp, 'object');          $$ncref = sub {
922                    my ($xp, $text) = @_;
923    
924    $$ncref =                  my $tag=lc($attref->{tag}) || die 'markup need tag attribute: <markup tag="tag_name" pos="(before|after)">';
925      sub {                  my $pos=lc($attref->{pos}) || die 'markup need pos attribute: <markup tag="tag_name" pos="(before|after)">';
       my ($xp) = @_;  
926    
927        if ($dostyle) {                  return if (! defined $text);
928          $body .= "<span class=\"booktitle\">";                  chomp($text);
929          $body .= sgml_escape($Object->{title});                  if ($text ne "") {
930          $body .= "</span>\n";                          $text =~ s/\&amp;/\&/g;
931        }                          $text =~ s/\&lt;/</g;
932        else {                          $text =~ s/\&gt;/>/g;
933          $body .= "<cite>" . sgml_escape($Object->{title}) . "</cite>\n";                          $text =~ s/^\s+//g;
934        }                          $text =~ s/\s+$//g;
935      };                          $html{$tag.'_'.$pos}=x($text);
936                            print "Using markup $pos $tag: ",x($text),"<--\n";
937                    }
938            }
939  }  }
940    
941  sub aside {  #
942    package main;  # print final instructions and exit
943    #
   my ($xp, $el, $attref, $ncref) = @_;  
   
   if ($dostyle) {  
     $body .= "<span class=\"aside\">[";  
   }  
   else {  
     $body .= "<em>[";  
   }  
     
   
   $$ncref =  
     sub {  
       my ($xp, $text) = @_;  
944    
945        if (defined $text) {  print "\n\nTo create database for poll $poll use:\n\n";
946          $body .= $text;  print "\$ psql template1 < $poll/$poll.sql\n\n";
947        }  print "THIS WILL DISTROY ALL DATA IN EXISTING DATABASE ".$prefix.$poll." !!\n";
       else {  
         if ($dostyle) {  
           $body .= "]</span>\n";  
         }  
         else {  
           $body .= "]</em>";  
         }  
       }  
     };  
 }  
948    
949  sub url {  # read configuration data
950    package main;  sub config {
951            package main;
952            my ($xp, $el, $attref, $ncref) = @_;
953    
954    my ($xp, $el, $attref, $ncref) = @_;          $$ncref = sub {
955                    my ($xp, $text) = @_;
956                    # encoding should be checked first since it also
957                    # initialize iconv for conversion from XML's UTF-8
958                    $html_encoding=$attref->{html_encoding} if ($attref->{html_encoding});
959                    $db_user=x($attref->{db_user});
960                    $prefix=x($attref->{prefix});
961                    $without_invitation=x($attref->{without_invitation}) &&
962                            print "Pool is without need for unique ID (and invitation URLs).\n";
963                    $remove_nrs_in_answers=x($attref->{remove_nrs_in_answers}) &&
964                            print "Numbers before answers will be removed.\n";
965    
966    my $url='';                  # fill in configuration about include files
967                    foreach my $file (qw(header separator submit footer thanks)) {
968                            if ($attref->{$file}) {
969                                    $include_files{$file}=x($attref->{$file});
970                                    print "Using custom $file '$include_files{$file}'\n";
971                                    $html{$file} = suck_file($include_files{$file});
972                            }
973                    }
974                    $q_db_col=x($attref->{q_db_col}) || 'q';
975                    $u_db_col=x($attref->{u_db_col}) || 'u';
976    
   $$ncref =  
     sub {  
       my ($xp, $text) = @_;  
977    
978        if (defined($text)) {          }
         $url .= $text;  
       }  
       else {  
         $body .= "<a href=\"$url\">$url</a>";  
       }  
     }  
979  }  }
980    
981  ## Local Variables: ##  #---------------------------------------------------------------
 ## mode:perl ##  
 ## End: ##  

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.22

  ViewVC Help
Powered by ViewVC 1.1.26