/[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 by dpavlin, Tue Apr 8 17:53:46 2003 UTC revision 1.16 by dpavlin, Thu Oct 23 22:13:30 2003 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 common;
13    use Carp;
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 $question_nr = 0;            # curr. question
27  my $pitanje_tag = "";           # originalni oblik broja pitanja  my $question_tag = "";          # originalni oblik broja questions
28  my $page_nr = 1;                # prvo pitanje na strani  my $page_nr = 1;                # prvo question na strani
29    
30  my $p_suffix="";                # if more than one box per question  my $p_suffix="";                # if more than one box per question
31    
32  my $curr_suffix="";             # trenutni suffix  my $curr_suffix="";             # trenutni suffix
33    
34  my @stack_pit;                  # stack pitanja (pitanje, suffix)  my @stack_que;                  # stack of questions (question, suffix)
35    
36  my @sql_create = ("id serial",  my @sql_create = ("id serial",
37          "http_referer character varying(500)",          "http_referer character varying(500)",
# Line 62  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    # buffer for suck(_file)ed html files
89    # and additional markup before and after tags
90    my %html = (
91            'hr_before' => "<br></td></tr>",
92            'hr_after' => "<tr><td></td><td><br>",
93            'que_before' => "<p>",
94            'que_after' => "</p>",
95            'subque_before' => '<table width="100%" cellspacing="0" cellpadding="2" border="0">',
96            'subque_after' => "</table>",
97            'ans_before' => "<p>",
98            'ans_after' => "</p>",
99            'html_before' => "<p>",
100            'html_after' => "</p>",
101    
102  my $html_header.=<<'End_of_header;';  );
 <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;  
103    
104  #------------------------------------------------------------------  #------------------------------------------------------------------
105    
106  my $html_separator=<<'End_of_separator;';  sub suck_file {
107  <tr>          my $file = shift || croak "suck_file called without argument";
108      <td></td>          open(H,$file) || die "can't open '$file': $!";
109      <td bgcolor="#006699"><img src="../klir.gif" width=1 height=1 alt="" border="0"><br></td>          my $content;
110  </tr>          while (<H>) { $content .= $_; } ;
111  End_of_separator;          close(H);
112            return $content;
113  #------------------------------------------------------------------  }
114    
115  my $html_footer=<<'End_of_footer;';  $html{'header'}=suck_file($include_files{'header'});
116  </td>  $html{'separator'}=suck_file($include_files{'separator'});
117  </tr>  $html{'submit'}=suck_file($include_files{'submit'});
118    $html{'footer'}=suck_file($include_files{'footer'});
 <tr>  
     <td> </td>  
     <td align="right"><br>  
 <input type=submit name="update" value="dalje.">&nbsp;&nbsp;  
 <br><br><br>  
 </td>  
 </tr>  
 </table>  
   
 </body>  
 </html>  
 End_of_footer;  
119    
120  #------------------------------------------------------------------  #------------------------------------------------------------------
121    
122  sub php_header {  sub php_header {
123  my ($page_nr,@sql_update) = @_;  my ($page_nr,@sql_update) = @_;
124  my $out='<?  my $out='<?php
125          include("common.inc");          include_once("common.php");
126          if (isset($update)) {          if (isset($update)) {
127                  $member_id=id_decode($a);                  $member_id=id_decode($a);
128                  ';                  ';
129  $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]);
130  $out.='  $out.='
131                  $sql="update '.$dir.' set '.join(",\n",@sql_update).',                  $sql="update '.$poll.' set '.join(",\n",@sql_update).',
132                          do_stranice=\'$PHP_SELF\'                          do_stranice=\'$PHP_SELF\'
133                          where id=$id";                          where id=$id";
134  #               print "<pre>$sql</pre>";  #               print "<pre>$sql</pre>";
135                  $result=pg_Exec($conn,fix_sql($sql));                  $result=pg_Exec($conn,fix_sql($sql));
136          } elseif($do_stranice != $PHP_SELF) {          } elseif($do_stranice != $PHP_SELF && isset($do_uri) && isset($a)) {
137                  Header("Location: $do_uri?a=$a");                  Header("Location: $do_uri?a=$a");
138                  exit;                  exit;
139          }          }
# Line 146  return $out; Line 144  return $out;
144  #------------------------------------------------------------------  #------------------------------------------------------------------
145    
146  # first, define some constants  # first, define some constants
147  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;  
148    
149  #------------------------------------------------------------------  #------------------------------------------------------------------
150    
151  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;  
152    
153  #------------------------------------------------------------------  #------------------------------------------------------------------
154    
155  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;  
156    
157  #------------------------------------------------------------------  #------------------------------------------------------------------
158    
# Line 353  while (defined($ARGV[0]) and $ARGV[0] =~ Line 163  while (defined($ARGV[0]) and $ARGV[0] =~
163      print $Usage;      print $Usage;
164      exit;      exit;
165    }    }
   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";  
   }  
166  }  # End of option processing  }  # End of option processing
167    
168  my $docfile = shift;  my $xmlfile = shift;
169    
170  die "No docfile provided:\n$Usage" unless defined $docfile;  die "No poll xml file provided!\n$Usage" unless defined $xmlfile;
171    
172  die "Can't read $docfile" unless -r $docfile;  die "Can't read $xmlfile" unless -r $xmlfile;
173    
174  if (defined $dir) {  if (defined $poll) {
175    die "$dir isn't a directory" unless -d $dir;    die "$poll isn't a directory" unless -d $poll;
176  }  }
177  else {  else {
178    $docfile =~ m!([^/.]+)(?:\.[^/.]*)?$!;    $xmlfile =~ m!([^/.]+)(?:\.[^/.]*)?$!;
179    $dir = $1;    $poll = $1;
180    if (-e $dir) {    if (-e $poll) {
181      die "$dir exists but isn't a directory"      die "$poll exists but isn't a directory"
182        unless -d $dir;        unless -d $poll;
183    }    }
184    else {    else {
185      mkdir $dir, 0755;      mkdir $poll, 0755;
186    }    }
187  }  }
188    
189  my $in_slideshow = 0;  my $in_poll = 0;
190  my $after_head = 0;  my $after_head = 0;
191    
192  my $Mode = 0;  my $Mode = 0;
# Line 405  my $Markedup_Text; Line 197  my $Markedup_Text;
197  my $Object;  my $Object;
198  my @Ostack = ();  my @Ostack = ();
199    
200  my $intext = 0;  #my $intext = 0;
201  my $closure;  my $closure;
202  my @closure_stack = ();  my @closure_stack = ();
203    
204  my $style_link = '';  #my $style_link = '';
205    
206  my $index = 'index.html';  #my $index = 'index.html';
207  my @slidetitle;  #my @slidetitle;
208  my $body;  my $body;
209  my $inlist = 0;  #my $inlist = 0;
210    
211  my @Titles;  #my @Titles;
212    
213  my $header;  my $header;
214    
 my $prolog = "<html><head>\n";  
 $prolog .= "<!-- Generated by $0 on " . gmtime() . " GMT -->\n";  
   
215  my $page_number = 0;  my $page_number = 0;
216    
217  my $p = new XML::Parser(ErrorContext => 3,  my $p = new XML::Parser(ErrorContext => 3,
218                          Handlers => {Start => \&starthndl,                          Handlers => {Start => \&starthndl,
219                                       End   => \&endhndl,                                       End   => \&endhndl,
220                                       Char  => \&text});                                       Char  => \&text});
221  $p->parsefile($docfile);  $p->parsefile($xmlfile);
222    
223  #----------------------------------------------------------  #----------------------------------------------------------
224    
# Line 437  $p->parsefile($docfile); Line 226  $p->parsefile($docfile);
226    
227  print "p[$page_nr] ";  print "p[$page_nr] ";
228    
229  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$!";
230  print PAGE php_header($page_nr,@prelast_sql_update);  print PAGE php_header($page_nr,@prelast_sql_update);
231  my $next_fn=sprintf("%02d.php",$page_nr);  my $next_fn=sprintf("%02d.php",$page_nr);
232  $last_page=~s/##NEXTPAGE##/$next_fn/;  $last_page=~s/##NEXTPAGE##/$next_fn/;
# Line 445  print PAGE $last_page; Line 234  print PAGE $last_page;
234  close(PAGE);  close(PAGE);
235    
236  $page_nr++;  $page_nr++;
237  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$!";
238  print PAGE php_header($page_nr,@last_sql_update);  print PAGE php_header($page_nr,@last_sql_update);
239  print PAGE $html_kraj;  print PAGE "$html{'header'} $html{'thanks'} $html{'footer'}";
240  close(PAGE);  close(PAGE);
241    
242  # dump sql structure  # dump sql structure
243    
244  open(SQL,">$dir/$dir.sql") || die "$dir.sql: $!";  open(SQL,">$poll/$poll.sql") || die "$poll.sql: $!";
245    print SQL "drop database ".$prefix.$poll.";\n";
246    print SQL "create database ".$prefix.$poll.";\n";
247    print SQL "\\connect ".$prefix.$poll.";\n";
248  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";
249  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";
250  close(SQL);  close(SQL);
251    
252  # dump common.inc  # dump common.php
253    
254  open(PHP,">$dir/common.inc") || die "common.inc: $!";  open(PHP,">$poll/common.php") || die "common.php: $!";
255  print PHP '<? $db="'.$dir.'";';  $common_php =~ s/##DB##/$poll/g;
256  print PHP $common_inc;  my $db_name = $prefix.$poll;
257  print PHP '?>';  $common_php =~ s/##DB_NAME##/$db_name/g;
258    $common_php =~ s/##PREFIX##/$prefix/g;
259    $common_php =~ s/##DB_USER##/$db_user/g;
260    $common_php =~ s/##PREFIX##/$prefix/g;
261    my $members_db = $prefix."members";
262    $common_php =~ s/##MEMBERS_DB##/$members_db/g;
263    $common_php =~ s/##WITHOUT_INVITATION##/$without_invitation/g;
264    
265    print PHP $common_php;
266  close(PHP);  close(PHP);
267    
268  open(PHP,">$dir/head.php") || die "head.php: $!";  open(PHP,">$poll/head.php") || die "head.php: $!";
269  print PHP '<? $max_page="'.($page_nr+1).'";';  my $max_page = $page_nr - 1;
270    $head_php=~ s/##MAXPAGE##/$max_page/;
271    $head_php=~ s/##TEXT##/Ispunili ste %02d%% ankete/;
272  print PHP $head_php;  print PHP $head_php;
 print PHP '?>';  
273  close(PHP);  close(PHP);
274    
275    # 01.php -> index.php
276    rename "$poll/01.php","$poll/index.php" || die "can't rename '$poll/01.php' to index.php";
277    
278  ################  ################
279  ## End of main  ## End of main
280  ################  ################
281    
282  # return unique name of pitanje  # return unique name of question
283  sub new_pit {  sub new_que {
284          my $out="p".$pitanje_nr.$p_suffix;          my $out="p".$question_nr;
285            $out .= "_".$p_suffix if ($p_suffix);
286          $curr_suffix=$p_suffix;          $curr_suffix=$p_suffix;
287          $p_suffix++;          $p_suffix++;
288          return $out;          return $out;
289  }  }
290    
291  # current pitanje  # current question
292  sub curr_pit {  sub curr_que {
293          return "p".$pitanje_nr.$curr_suffix;          return "p".$question_nr.$curr_suffix;
294  }  }
295    
296    #----------------------------------------------------------
297    
298  sub starthndl {  sub starthndl {
299    my ($xp, $el, %atts) = @_;          my ($xp, $el, %atts) = @_;
300    
301  #  return unless ($in_slideshow or $el eq 'slideshow');  #       return unless ($in_poll or $el eq 'slideshow');
302    
303    unless ($in_slideshow) {          unless ($in_poll) {
304      $in_slideshow = $xp->depth + 1;                  $in_poll = $xp->depth + 1;
305      return;                  return;
306    }          }
307    
308    if ($Mode) {          if ($Mode) {
309                    if ($Mode eq 'pass') {
310                            $Markedup_Text .= "\n" . $xp->recognized_string;
311                    } elsif ($Mode eq 'object') {
312                            push(@Ostack, $Object);
313    
314      if ($Mode eq 'pass') {                          $Object = {
315        $Markedup_Text .= "\n" . $xp->recognized_string;                                  _Atts     => \%atts,
316      }                                  _Text    => ''
317      elsif ($Mode eq 'object') {                          };
318        push(@Ostack, $Object);                          bless $Object, "Slideobj::$el";
319                    }
320    
321        $Object = {_Atts    => \%atts,                  # skip does nothing
322                   _Text    => ''                  return;
323                  };          }
       bless $Object, "Slideobj::$el";  
     }  
324    
325      # skip does nothing          unless ($after_head) {
326      return;                  if ($el eq 'head') {
327    }                          $after_head = 1;
328                            start_mode($xp, 'object');
329    
330    unless ($after_head) {                          push(@closure_stack, $closure);
331      if ($el eq 'head') {                          $closure = sub {
332        $after_head = 1;                                  my ($xp, $text) = @_;
       start_mode($xp, 'object');  
   
       push(@closure_stack, $closure);  
       $closure =  
         sub {  
           my ($xp, $text) = @_;  
   
           unless (defined $text) {  
               
             $header = $Object;  
           }  
         };  
333    
334        return;                                  unless (defined $text) {
335      }                                          $header = $Object;
336                                    }
337                            };
338                            return;
339                    }
340    
341  #    die "The head element must be the first thing in the slideshow";  #               die "The head element must be the first thing in the slideshow";
342    }          }
343    
344    
345    my $new_closure;          my $new_closure;
346    
347    my $subname = "Slideshow::$el";          my $subname = "Poll::$el";
348    
349    if (defined &$subname) {          if (defined &$subname) {
350      no strict 'refs';                  no strict 'refs';
351    
352      &$subname($xp, $el, \%atts, \$new_closure);                  &$subname($xp, $el, \%atts, \$new_closure);
353    }          } else {
354    else {                  $body .= x($xp->recognized_string);
355      $body .= $xp->recognized_string;                  $new_closure = sub {
356      $new_closure =                          my ($xp, $text) = @_;
357        sub {  
358          my ($xp, $text) = @_;                          if (defined $text) {
359                                            $body .= x($text);
360          if (defined $text) {                          } else {
361            $body .= $text;                                  $body .= x("</$el>");
362          }                          }
363          else {                  };
           $body .= "</$el>";  
364          }          }
       };  
   }  
365    
366    push(@closure_stack, $closure);          push(@closure_stack, $closure);
367    $closure = $new_closure;          $closure = $new_closure;
368  }  # End starthndl  }       # End starthndl
369    
370  sub endhndl {  sub endhndl {
371    my ($xp, $el) = @_;          my ($xp, $el) = @_;
372    
373    return unless $in_slideshow;          return unless $in_poll;
374    
375    my $lev = $xp->depth;          my $lev = $xp->depth;
376    
377    if ($lev == $in_slideshow - 1) {          if ($lev == $in_poll - 1) {
378      $in_slideshow = 0;                  $in_poll = 0;
379      $xp->finish;                  $xp->finish;
380      return;                  return;
381    }          }
382              
383    if ($Mode_level == $lev) {          if ($Mode_level == $lev) {
384                        
385      if ($Mode eq 'pass') {                  if ($Mode eq 'pass') {
386        &$closure($xp, $Markedup_Text)                          &$closure($xp, $Markedup_Text) if (defined $closure);
387          if (defined $closure);                  }
     }  
388    
389      $Mode = $Mode_level = 0;                  $Mode = $Mode_level = 0;
390    }          }
391    
392    if ($Mode) {          if ($Mode) {
393      if ($Mode eq 'pass') {                  if ($Mode eq 'pass') {
394        $Markedup_Text .= "</$el>";                          $Markedup_Text .= "</$el>";
395      }                  } elsif ($Mode eq 'object') {
396      elsif ($Mode eq 'object') {                          my $this = $Object;
397        my $this = $Object;                          if (2 == keys %$this) {
398        if (2 == keys %$this) {                                  $this = $this->{_Text};
399          $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;  
       }  
     }  
400    
401      return;                          $Object = pop(@Ostack);
   }  
402    
403    &$closure($xp)                          my $slot = $Object->{$el};
404      if defined $closure;                          if (defined $slot) {
405                                    if (ref($slot) eq 'ARRAY') {
406                                            push(@$slot, $this);
407                                    } else {
408                                            $Object->{$el} = [$slot, $this];
409                                    }
410                            } else {
411                                    $Object->{$el} = $this;
412                            }
413                    }
414    
415                    return;
416            }
417    
418            &$closure($xp) if defined $closure;
419    
420    $closure = pop(@closure_stack);          $closure = pop(@closure_stack);
421  }  # End endhndl  }  # End endhndl
422    
423    #----------------------------------------------------------
424    
425  sub text {  sub text {
426    my ($xp, $data) = @_;          my ($xp, $data) = @_;
427    
428    return unless $in_slideshow;          return unless $in_poll;
429    
430    if ($Mode ) {          if ($Mode) {
431    
432      if ($Mode eq 'pass') {                  if ($Mode eq 'pass') {
433        my $safe = sgml_escape($data);                          my $safe = sgml_escape($data);
434    
435        $Text .= $safe;                          $Text .= $safe;
436        $Markedup_Text .= $safe;                          $Markedup_Text .= $safe;
437      }                  } elsif ($Mode eq 'object') {
438      elsif ($Mode eq 'object') {                          $Object->{_Text} .= $data if $data =~ /\S/;
439        $Object->{_Text} .= $data                  }
         if $data =~ /\S/;  
     }  
440    
441      return;                  return;
442    }          }
443    
444    &$closure($xp, sgml_escape($data))          &$closure($xp, sgml_escape($data)) if (defined $closure);
     if (defined $closure);  
445    
446  }  # End text  }  # End text
447    
448  sub start_mode {  sub start_mode {
449    my ($xp, $mode) = @_;          my ($xp, $mode) = @_;
450    
451    if ($mode eq 'pass') {          if ($mode eq 'pass') {
452      $Text = '';                  $Text = '';
453      $Markedup_Text = '';                  $Markedup_Text = '';
454    }          } elsif ($mode eq 'object') {
455    elsif ($mode eq 'object') {                  $Object = {
456      $Object = {_Atts => undef,                          _Atts => undef,
457                 _Text => undef                          _Text => undef
458                };                  };
459    }          }
460    
461    $Mode = $mode;          $Mode = $mode;
462    $Mode_level = $xp->depth;          $Mode_level = $xp->depth;
463  }  # End start_mode  }  # End start_mode
464    
465  sub sgml_escape {  sub sgml_escape {
466    my ($str) = @_;          my ($str) = @_;
467    
468    $str =~ s/\&/\&amp;/g;          $str =~ s/\&/\&amp;/g;
469    $str =~ s/</\&lt;/g;          $str =~ s/</\&lt;/g;
470    $str =~ s/>/\&gt;/g;          $str =~ s/>/\&gt;/g;
471    
472    $str;          $str;
473  }  # End sgml_escape  }  # End sgml_escape
474    
 sub slidename {  
   my ($num) = @_;  
   
   sprintf("slide%03d.html", $num);  
 }  # End slidename  
   
475  ################################################################  ################################################################
476    
477  package Slideshow;  package Poll;
478    
479  sub page {  sub page {
480          package main;          package main;
# Line 701  sub page { Line 489  sub page {
489                          print "p[$page_nr] ";                          print "p[$page_nr] ";
490    
491                          if (defined $last_fn) {                          if (defined $last_fn) {
492                                  # 01.php -> index.php                                  open(PAGE, ">$poll/$last_fn") or die "Couldn't open $last_fn for writing:\n$!";
493                                  $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  
   
   
494                                  my $next_fn=sprintf("%02d.php",$page_nr);                                  my $next_fn=sprintf("%02d.php",$page_nr);
495                                  $last_page=~s/##NEXTPAGE##/$next_fn/;                                  $last_page=~s/##NEXTPAGE##/$next_fn/;
496                                  print PAGE $last_page;                                  print PAGE $last_page;
# Line 738  $sql="insert into '.$dir.' ( http_refere Line 502  $sql="insert into '.$dir.' ( http_refere
502                          @sql_update = ();                          @sql_update = ();
503                    
504                          $last_fn=sprintf("%02d.php",$page_nr);                          $last_fn=sprintf("%02d.php",$page_nr);
505                          $last_page="$html_header $body $html_footer";                          $last_page="$html{'header'} $body $html{'submit'} $html{'footer'}";
506                          # delete vars for next page                          # delete vars for next page
507                          $page_nr++;                          $page_nr++;
508                          $body="";                          $body="";
# Line 751  sub nr { Line 515  sub nr {
515    
516          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
517    
518          $pitanje_tag="";          $question_tag="";
519    
520          $$ncref = sub {          $$ncref = sub {
521                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
522                  if (defined($text)) {                  if (defined($text)) {
523                          $body.=$text;                          $body.=x($text);
524                          chomp $text;                          chomp $text;
525                          $pitanje_tag .= $text;                          $question_tag .= x($text);
526                  } else {                  } else {
527                          $pitanje_nr = $pitanje_tag;                          $question_nr = $question_tag;
528                          $pitanje_nr =~ s/[^0-9a-zA-Z]//g;                          $question_nr =~ s/[^0-9a-zA-Z]//g;
529                          print "$pitanje_nr ";                          print "$question_nr ";
530                  }                  }
531                  $p_suffix="";                  $p_suffix="";
532          };          };
# Line 770  sub nr { Line 534  sub nr {
534    
535    
536  sub hr {  sub hr {
537          $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";  
538  }  }
539    
540  sub pit {  sub que {
541          package main;          package main;
542    
543          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
544    
545          $body.="<p>";          $body.=$html{'que_before'} if ($html{'que_before'});
546    
547          $$ncref = sub {          $$ncref = sub {
548                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
549    
550                  if (defined $text) {                  if (defined $text) {
551                          $body.=$text;                          $body.=x($text);
552                  } else {                  } else {
553                          $body.="</p>";                          $body.=$html{'que_after'} if ($html{'que_after'});
554                  }                  }
555          }          }
556  }  }
557    
558  sub podpit {  sub subque {
559          package main;          package main;
560    
561          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
562    
563          $body.='<table width="100%" cellspacing="0" cellpadding="2" border="0">';          $body.=$html{'subque_before'} if ($html{'subque_before'});
564    
565          $$ncref = sub {          $$ncref = sub {
566                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
567    
568                  if (defined $text) {                  if (defined $text) {
569                          $body.=$text;                          $body.=x($text);
570                  } else {                  } else {
571                          $body.="</table>";                          $body.=$html{'subque_after'} if ($html{'subque_after'});
572                  }                  }
573          }          }
574  }  }
575    
576    
577  sub odg {  sub ans {
578          package main;          package main;
579    
580          my ($xp, $el, $attref, $ncref) = @_;          my ($xp, $el, $attref, $ncref) = @_;
581    
582          $body .= "<p>";          $body.=$html{'ans_before'} if ($html{'ans_before'});
583            
584          $$ncref = sub {          $$ncref = sub {
585                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
586    
587                  if (defined $text) {                  if (defined $text) {
588                          $body .= $text;                          $body .= x($text);
589                  } else {                  } else {
590                          $body .= "</p>";                          $body.=$html{'ans_after'} if ($html{'ans_after'});
591                  }                  }
592          }          }
593  }  }
# Line 845  sub php { Line 606  sub php {
606                          $text=~s/ le / <= /g;                          $text=~s/ le / <= /g;
607                          $text=~s/ gt / > /g;                          $text=~s/ gt / > /g;
608                          $text=~s/ ge / >= /g;                          $text=~s/ ge / >= /g;
609                          $body.=$text;                          $body.=x($text);
610                  } else {                  } else {
611                          $body.="\n?>\n";                          $body.="\n?>\n";
612                  }                  }
# Line 859  sub dropdown { Line 620  sub dropdown {
620    
621          my @dropdown_data;          my @dropdown_data;
622    
623            my $default_value = x($attref->{default_value}) || 'null';
624            my $default_text = x($attref->{default_text}) || '-';
625    
626          $$ncref = sub {          $$ncref = sub {
627                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
628    
629                  if (defined $text) {                  if (defined $text) {
630                          chomp $text;                          chomp $text;
631                          $text=~s/^\s*//g;                          $text=~s/^\s*//g;
632                          $text=~s/^[\d\.\s]+//g;                          $text=~s/^[\d\.\s]+//g if ($remove_nrs_in_answers);
633                          $text=~s/\s*$//g;                          $text=~s/\s*$//g;
634                          push @dropdown_data,$text if ($text ne "");                          push @dropdown_data,x($text) if ($text ne "");
635                  } else {                  } else {
636                          my $opt;                          my $opt;
637                          my $id=1;                          my $id=1;
638                          my $p=new_pit();                          my $p=new_que();
639                          $body.="<select name=$p >\n";                          $body.="<select name=$p >\n";
640                          $body.="<option value=null>-</option>\n";                          $body.="<option value=\"$default_value\">$default_text</option>\n";
641                          foreach $opt (@dropdown_data) {                          foreach $opt (@dropdown_data) {
642                                  if (defined($opt) && $opt ne "") {                                  if (defined($opt) && $opt ne "") {
643                                          $body.="<option value=$id>$opt</option>\n";                                          $body.="<option value=$id>$opt</option>\n";
# Line 896  sub textbox { Line 660  sub textbox {
660                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
661                  my $size=$attref->{size};                  my $size=$attref->{size};
662                  $size = 25 if (! defined $size || $size == 0);  # default                  $size = 25 if (! defined $size || $size == 0);  # default
663                  my $p=new_pit();                  my $p=new_que();
664                  $body.="<input type=text name=$p size=$size >\n";                  $body.="<input type=text name=$p size=".x($size)." >\n";
665                  push @sql_create,"$p text";                  push @sql_create,"$p text";
666                  push @sql_update,"$p='\$$p'";                  push @sql_update,"$p='\$$p'";
667          }          }
# Line 911  sub radiobuttons_tab { Line 675  sub radiobuttons_tab {
675                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
676                  if (! defined $text) {                  if (! defined $text) {
677                          my $nr=$attref->{nr};                          my $nr=$attref->{nr};
678                          my $p=new_pit();                          my $p=new_que();
679                          for (my $i=1; $i<=$nr; $i++) {                          for (my $i=1; $i<=$nr; $i++) {
680                                  $body.="<td><input type=radio name=$p value=$i></td> ";                                  $body.="<td><input type=radio name=$p value=$i></td> ";
681                          }                          }
# Line 933  sub radiobuttons { Line 697  sub radiobuttons {
697                  if (defined $text) {                  if (defined $text) {
698                          chomp $text;                          chomp $text;
699                          $text=~s/^\s*//g;                          $text=~s/^\s*//g;
700                          $text=~s/^[\d\.\s]+//g;                          $text=~s/^[\d\.\s]+//g if ($remove_nrs_in_answers);
701                          $text=~s/\s*$//g;                          $text=~s/\s*$//g;
702                          push @radiobuttons_data,$text if ($text ne "");                          push @radiobuttons_data,x($text) if ($text ne "");
703                  } else {                  } else {
704                          my $opt;                          my $opt;
705                          my $p=new_pit();                          my $p=new_que();
706                          my $id=1;                          my $id=1;
707                          foreach $opt (@radiobuttons_data) {                          foreach $opt (@radiobuttons_data) {
708                                  if (defined($opt) && $opt ne "") {                                  if (defined($opt) && $opt ne "") {
# Line 957  sub checkbox { Line 721  sub checkbox {
721    
722          $$ncref = sub {          $$ncref = sub {
723                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
724                  my $p=new_pit();                  my $p=new_que();
725                  $body.="<input type=checkbox name=$p >\n";                  $body.="<input type=checkbox name=$p >\n";
726                  push @sql_create,"$p text";                  push @sql_create,"$p text";
727                  push @sql_update,"$p='\$$p'";                  push @sql_update,"$p='\$$p'";
# Line 978  sub checkboxes { Line 742  sub checkboxes {
742                  if (defined $text) {                  if (defined $text) {
743                          chomp $text;                          chomp $text;
744                          $text=~s/^\s*//g;                          $text=~s/^\s*//g;
745                          $text=~s/^[\d\.\s]+//g;                          $text=~s/^[\d\.\s]+//g if ($remove_nrs_in_answers);
746                          $text=~s/\s*$//g;                          $text=~s/\s*$//g;
747                          push @checkboxes_data,$text if ($text ne "");                          push @checkboxes_data,x($text) if ($text ne "");
748                  } else {                  } else {
749                          my $opt;                          my $opt;
750                          my $base_p=new_pit();                          my $base_p=new_que();
751                          my $id=1;                          my $id=1;
752    
753                          my $before=$attref->{before};                          my $before=$attref->{before};
# Line 999  sub checkboxes { Line 763  sub checkboxes {
763                                  if (defined($opt) && $opt ne "") {                                  if (defined($opt) && $opt ne "") {
764                                          $p=$base_p."_".$id;                                          $p=$base_p."_".$id;
765                                          $id++;                                          $id++;
766                                          $body .= $before if ($before);                                          $body .= x($before) if ($before);
767                                          $body.="<input type=checkbox name=$p>";                                          $body.="<input type=checkbox name=$p>";
768                                          $body .= $middle if ($middle);                                          $body .= x($middle) if ($middle);
769                                          $body .= "$opt" if (! $hide_description);                                          $body .= "$opt" if (! $hide_description);
770                                          $body .= $after if ($after);                                          $body .= x($after) if ($after);
771                                          $body.="\n";                                          $body.="\n";
772    
773                                          push @sql_create,"$p boolean";                                          push @sql_create,"$p boolean";
# Line 1016  sub checkboxes { Line 780  sub checkboxes {
780          }          }
781  }  }
782    
783  #---------------------------------------------------------------  #
784    # insert arbitrary html
785  sub slide {  #
786    package main;  sub html {
787            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  
788    
789  sub group {          my ($xp, $el, $attref, $ncref) = @_;
 }  # End group  
790    
791  sub text {          $body.=$html{'html_before'} if ($html{'html_before'});
   package main;  
792    
793    my ($xp, $el, $attref, $ncref) = @_;          $$ncref = sub {
794                    my ($xp, $text) = @_;
795    
796    $body .= "<p>\n";                  if (defined $text) {
797                            $body.=x($text);
798                    } elsif ($attref->{include}) {
799                            $body.=suck_file($attref->{include});
800                    } else {
801                            $body.=$html{'html_after'} if ($html{'html_after'});
802                    }
803            }
804    }
805    
806    $$ncref =  #
807      sub {  # markup tag can specify any markup which should be applied pre (before)
808        my ($xp, $text) = @_;  # or post (after) any other tag which produces html output
809    #
810    
811        if (defined $text) {  sub markup {
812          $text =~ s/\s+/ /g;          package main;
         $body .= $text;  
       }  
     };  
 }  # End text  
813    
814  sub book {          my ($xp, $el, $attref, $ncref) = @_;
   package main;  
815    
816    my ($xp, $el, $attref, $ncref) = @_;          $$ncref = sub {
817                    my ($xp, $text) = @_;
818    
819    start_mode($xp, 'object');                  my $tag=lc($attref->{tag}) || die 'markup need tag attribute: <markup tag="tag_name" pos="(before|after)">';
820                    my $pos=lc($attref->{pos}) || die 'markup need pos attribute: <markup tag="tag_name" pos="(before|after)">';
821    
822    $$ncref =                  return if (! defined $text);
823      sub {                  chomp($text);
824        my ($xp) = @_;                  if ($text ne "") {
825                            $text =~ s/\&amp;/\&/g;
826        if ($dostyle) {                          $text =~ s/\&lt;/</g;
827          $body .= "<span class=\"booktitle\">";                          $text =~ s/\&gt;/>/g;
828          $body .= sgml_escape($Object->{title});                          $text =~ s/^\s+//g;
829          $body .= "</span>\n";                          $text =~ s/\s+$//g;
830        }                          $html{$tag.'_'.$pos}=x($text);
831        else {                          print "Using markup $pos $tag: ",x($text),"<--\n";
832          $body .= "<cite>" . sgml_escape($Object->{title}) . "</cite>\n";                  }
833        }          }
     };  
834  }  }
835    
836  sub aside {  #
837    package main;  # print final instructions and exit
838    #
   my ($xp, $el, $attref, $ncref) = @_;  
   
   if ($dostyle) {  
     $body .= "<span class=\"aside\">[";  
   }  
   else {  
     $body .= "<em>[";  
   }  
     
839    
840    $$ncref =  print "\n\nTo create database for poll $poll use:\n\n";
841      sub {  print "\$ psql template1 < $poll/$poll.sql\n\n";
842        my ($xp, $text) = @_;  print "THIS WILL DISTROY ALL DATA IN EXISTING DATABASE ".$prefix.$poll." !!\n";
   
       if (defined $text) {  
         $body .= $text;  
       }  
       else {  
         if ($dostyle) {  
           $body .= "]</span>\n";  
         }  
         else {  
           $body .= "]</em>";  
         }  
       }  
     };  
 }  
843    
844  sub url {  # read configuration data
845    package main;  sub config {
846            package main;
847            my ($xp, $el, $attref, $ncref) = @_;
848    
849    my ($xp, $el, $attref, $ncref) = @_;          $$ncref = sub {
850                    my ($xp, $text) = @_;
851                    $db_user=x($attref->{db_user});
852                    $prefix=x($attref->{prefix});
853                    $without_invitation=x($attref->{without_invitation}) &&
854                            print "Pool is without need for unique ID (and invitation URLs).\n";
855                    $remove_nrs_in_answers=x($attref->{remove_nrs_in_answers}) &&
856                            print "Numbers before answers will be removed.\n";
857    
858    my $url='';                  # fill in configuration about include files
859                    foreach my $file (qw(header separator submit footer thanks)) {
860                            if ($attref->{$file}) {
861                                    $include_files{$file}=x($attref->{$file});
862                                    print "Using custom $file '$include_files{$file}'\n";
863                                    $html{$file} = suck_file($include_files{$file});
864                            }
865                    }
866    
867    $$ncref =          }
     sub {  
       my ($xp, $text) = @_;  
   
       if (defined($text)) {  
         $url .= $text;  
       }  
       else {  
         $body .= "<a href=\"$url\">$url</a>";  
       }  
     }  
868  }  }
869    
870  ## Local Variables: ##  #---------------------------------------------------------------
 ## mode:perl ##  
 ## End: ##  

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.26