10 |
|
|
11 |
use XML::Parser; |
use XML::Parser; |
12 |
use common; |
use common; |
13 |
|
use Carp; |
14 |
|
|
15 |
$|=1; |
$|=1; |
16 |
|
|
23 |
my $poll; |
my $poll; |
24 |
my $dowarn = 1; |
my $dowarn = 1; |
25 |
|
|
26 |
my $pitanje_nr = 0; # curr. pitanje |
my $q_type = "q"; # q=question, u=unnumbered question |
27 |
my $pitanje_tag = ""; # originalni oblik broja pitanja |
my %question_nr; # curr. question numbers |
28 |
my $page_nr = 1; # prvo pitanje na strani |
my $question_tag = ""; # originalni oblik broja questions |
29 |
|
my $page_nr = 1; # prvo question na strani |
30 |
|
|
31 |
my $p_suffix=""; # if more than one box per question |
my $p_suffix=""; # if more than one box per question |
32 |
|
|
33 |
my $curr_suffix=""; # trenutni suffix |
my $curr_suffix=""; # trenutni suffix |
34 |
|
|
35 |
my @stack_pit; # stack pitanja (pitanje, suffix) |
my @stack_que; # stack of questions (question, suffix) |
36 |
|
|
37 |
my @sql_create = ("id serial", |
my @sql_create = ("id serial", |
38 |
"http_referer character varying(500)", |
"http_referer character varying(500)", |
68 |
# and users will see just "red" and "black" |
# and users will see just "red" and "black" |
69 |
my $remove_nrs_in_answers=0; |
my $remove_nrs_in_answers=0; |
70 |
|
|
71 |
|
# This defines files which will be included in various places to produce |
72 |
|
# design. You could desing them using your faviourite html editor (vim :-) |
73 |
|
# and then split them into separate files |
74 |
|
|
75 |
|
my %include_files = ( |
76 |
|
# this file is included at top of each paAge |
77 |
|
'header' => "header.html", |
78 |
|
# this file is used to separate questions |
79 |
|
'separator' => "separator.html", |
80 |
|
# this file is used to show "submit" button, which under multi-page |
81 |
|
# polls will also bring next page |
82 |
|
'submit' => "next.html", |
83 |
|
# this file is included at bottom of each page |
84 |
|
'footer' => "footer.html", |
85 |
|
# this file will be showen after poll is completed |
86 |
|
'thanks' => "thanks.html" |
87 |
|
); |
88 |
|
|
89 |
|
# buffer for suck(_file)ed html files |
90 |
|
# and additional markup before and after tags |
91 |
|
my %html = ( |
92 |
|
'hr_before' => "<br></td></tr>", |
93 |
|
'hr_after' => "<tr><td></td><td><br>", |
94 |
|
'que_before' => "<p>", |
95 |
|
'que_after' => "</p>", |
96 |
|
'subque_before' => '<table width="100%" cellspacing="0" cellpadding="2" border="0">', |
97 |
|
'subque_after' => "</table>", |
98 |
|
'ans_before' => "<p>", |
99 |
|
'ans_after' => "</p>", |
100 |
|
'html_before' => "<p>", |
101 |
|
'html_after' => "</p>", |
102 |
|
|
103 |
|
); |
104 |
|
|
105 |
|
# name of database colums |
106 |
|
# for questions |
107 |
|
my $q_db_col = "q"; |
108 |
|
# for unnumbered questions |
109 |
|
my $u_db_col = "u"; |
110 |
|
|
111 |
|
|
112 |
#------------------------------------------------------------------ |
#------------------------------------------------------------------ |
113 |
|
|
114 |
sub suck_file { |
sub suck_file { |
115 |
my $file = shift @_; |
my $file = shift || croak "suck_file called without argument"; |
116 |
open(H,$file) || die "can't open '$file': $!"; |
open(H,$file) || die "can't open '$file': $!"; |
117 |
my $content; |
my $content; |
118 |
while (<H>) { $content .= $_; } ; |
while (<H>) { $content .= $_; } ; |
120 |
return $content; |
return $content; |
121 |
} |
} |
122 |
|
|
123 |
my $html_header=suck_file("header.html"); |
$html{'header'}=suck_file($include_files{'header'}); |
124 |
my $html_separator=suck_file("separator.html"); |
$html{'separator'}=suck_file($include_files{'separator'}); |
125 |
my $html_next=suck_file("next.html"); |
$html{'submit'}=suck_file($include_files{'submit'}); |
126 |
my $html_footer=suck_file("footer.html"); |
$html{'footer'}=suck_file($include_files{'footer'}); |
127 |
|
|
128 |
#------------------------------------------------------------------ |
#------------------------------------------------------------------ |
129 |
|
|
160 |
|
|
161 |
#------------------------------------------------------------------ |
#------------------------------------------------------------------ |
162 |
|
|
163 |
my $html_kraj=suck_file("thanks.html"); |
$html{'thanks'}=suck_file($include_files{'thanks'}); |
164 |
|
|
165 |
#------------------------------------------------------------------ |
#------------------------------------------------------------------ |
166 |
|
|
244 |
$page_nr++; |
$page_nr++; |
245 |
open(PAGE, ">$poll/$next_fn") or die "Couldn't open $next_fn for writing:\n$!"; |
open(PAGE, ">$poll/$next_fn") or die "Couldn't open $next_fn for writing:\n$!"; |
246 |
print PAGE php_header($page_nr,@last_sql_update); |
print PAGE php_header($page_nr,@last_sql_update); |
247 |
print PAGE "$html_header $html_kraj $html_footer"; |
print PAGE "$html{'header'} $html{'thanks'} $html{'footer'}"; |
248 |
close(PAGE); |
close(PAGE); |
249 |
|
|
250 |
# dump sql structure |
# dump sql structure |
287 |
## End of main |
## End of main |
288 |
################ |
################ |
289 |
|
|
290 |
# return unique name of pitanje |
# return unique name of question |
291 |
sub new_pit { |
sub new_que { |
292 |
my $out="p".$pitanje_nr; |
my $out=$q_type.( $question_nr{$q_type} || 0 ); |
293 |
$out .= "_".$p_suffix if ($p_suffix); |
$out .= "_".$p_suffix if ($p_suffix); |
294 |
$curr_suffix=$p_suffix; |
$curr_suffix=$p_suffix; |
295 |
$p_suffix++; |
$p_suffix++; |
296 |
return $out; |
return $out; |
297 |
} |
} |
298 |
|
|
299 |
# current pitanje |
# current question |
300 |
sub curr_pit { |
sub curr_que { |
301 |
return "p".$pitanje_nr.$curr_suffix; |
return $q_type.( $question_nr{$q_type} || 0 ).$curr_suffix; |
302 |
} |
} |
303 |
|
|
304 |
#---------------------------------------------------------- |
#---------------------------------------------------------- |
305 |
|
|
306 |
sub starthndl { |
sub starthndl { |
307 |
my ($xp, $el, %atts) = @_; |
my ($xp, $el, %atts) = @_; |
308 |
|
|
309 |
# return unless ($in_poll or $el eq 'slideshow'); |
# return unless ($in_poll or $el eq 'slideshow'); |
310 |
|
|
311 |
unless ($in_poll) { |
unless ($in_poll) { |
312 |
$in_poll = $xp->depth + 1; |
$in_poll = $xp->depth + 1; |
313 |
return; |
return; |
314 |
} |
} |
315 |
|
|
316 |
|
if ($Mode) { |
317 |
|
if ($Mode eq 'pass') { |
318 |
|
$Markedup_Text .= "\n" . $xp->recognized_string; |
319 |
|
} elsif ($Mode eq 'object') { |
320 |
|
push(@Ostack, $Object); |
321 |
|
|
322 |
|
$Object = { |
323 |
|
_Atts => \%atts, |
324 |
|
_Text => '' |
325 |
|
}; |
326 |
|
bless $Object, "Slideobj::$el"; |
327 |
|
} |
328 |
|
|
329 |
if ($Mode) { |
# skip does nothing |
330 |
|
return; |
331 |
|
} |
332 |
|
|
333 |
if ($Mode eq 'pass') { |
unless ($after_head) { |
334 |
$Markedup_Text .= "\n" . $xp->recognized_string; |
if ($el eq 'head') { |
335 |
} |
$after_head = 1; |
336 |
elsif ($Mode eq 'object') { |
start_mode($xp, 'object'); |
|
push(@Ostack, $Object); |
|
337 |
|
|
338 |
$Object = {_Atts => \%atts, |
push(@closure_stack, $closure); |
339 |
_Text => '' |
$closure = sub { |
340 |
}; |
my ($xp, $text) = @_; |
|
bless $Object, "Slideobj::$el"; |
|
|
} |
|
341 |
|
|
342 |
# skip does nothing |
unless (defined $text) { |
343 |
return; |
$header = $Object; |
344 |
} |
} |
345 |
|
}; |
346 |
|
return; |
347 |
|
} |
348 |
|
|
349 |
unless ($after_head) { |
# die "The head element must be the first thing in the slideshow"; |
350 |
if ($el eq 'head') { |
} |
|
$after_head = 1; |
|
|
start_mode($xp, 'object'); |
|
|
|
|
|
push(@closure_stack, $closure); |
|
|
$closure = |
|
|
sub { |
|
|
my ($xp, $text) = @_; |
|
|
|
|
|
unless (defined $text) { |
|
|
|
|
|
$header = $Object; |
|
|
} |
|
|
}; |
|
351 |
|
|
|
return; |
|
|
} |
|
352 |
|
|
353 |
# die "The head element must be the first thing in the slideshow"; |
my $new_closure; |
|
} |
|
354 |
|
|
355 |
|
my $subname = "Poll::$el"; |
356 |
|
|
357 |
my $new_closure; |
if (defined &$subname) { |
358 |
|
no strict 'refs'; |
359 |
|
|
360 |
my $subname = "Poll::$el"; |
&$subname($xp, $el, \%atts, \$new_closure); |
361 |
|
} else { |
362 |
|
$body .= x($xp->recognized_string); |
363 |
|
$new_closure = sub { |
364 |
|
my ($xp, $text) = @_; |
365 |
|
|
366 |
if (defined &$subname) { |
if (defined $text) { |
367 |
no strict 'refs'; |
$body .= x($text); |
368 |
|
} else { |
369 |
&$subname($xp, $el, \%atts, \$new_closure); |
$body .= x("</$el>"); |
370 |
} |
} |
371 |
else { |
}; |
|
$body .= x($xp->recognized_string); |
|
|
$new_closure = |
|
|
sub { |
|
|
my ($xp, $text) = @_; |
|
|
|
|
|
if (defined $text) { |
|
|
$body .= x($text); |
|
|
} |
|
|
else { |
|
|
$body .= x("</$el>"); |
|
372 |
} |
} |
|
}; |
|
|
} |
|
373 |
|
|
374 |
push(@closure_stack, $closure); |
push(@closure_stack, $closure); |
375 |
$closure = $new_closure; |
$closure = $new_closure; |
376 |
} # End starthndl |
} # End starthndl |
377 |
|
|
378 |
sub endhndl { |
sub endhndl { |
379 |
my ($xp, $el) = @_; |
my ($xp, $el) = @_; |
380 |
|
|
381 |
return unless $in_poll; |
return unless $in_poll; |
382 |
|
|
383 |
my $lev = $xp->depth; |
my $lev = $xp->depth; |
384 |
|
|
385 |
if ($lev == $in_poll - 1) { |
if ($lev == $in_poll - 1) { |
386 |
$in_poll = 0; |
$in_poll = 0; |
387 |
$xp->finish; |
$xp->finish; |
388 |
return; |
return; |
389 |
} |
} |
390 |
|
|
391 |
if ($Mode_level == $lev) { |
if ($Mode_level == $lev) { |
392 |
|
|
393 |
if ($Mode eq 'pass') { |
if ($Mode eq 'pass') { |
394 |
&$closure($xp, $Markedup_Text) |
&$closure($xp, $Markedup_Text) if (defined $closure); |
395 |
if (defined $closure); |
} |
|
} |
|
396 |
|
|
397 |
$Mode = $Mode_level = 0; |
$Mode = $Mode_level = 0; |
398 |
} |
} |
399 |
|
|
400 |
if ($Mode) { |
if ($Mode) { |
401 |
if ($Mode eq 'pass') { |
if ($Mode eq 'pass') { |
402 |
$Markedup_Text .= "</$el>"; |
$Markedup_Text .= "</$el>"; |
403 |
} |
} elsif ($Mode eq 'object') { |
404 |
elsif ($Mode eq 'object') { |
my $this = $Object; |
405 |
my $this = $Object; |
if (2 == keys %$this) { |
406 |
if (2 == keys %$this) { |
$this = $this->{_Text}; |
407 |
$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; |
|
|
} |
|
|
} |
|
408 |
|
|
409 |
return; |
$Object = pop(@Ostack); |
410 |
} |
|
411 |
|
my $slot = $Object->{$el}; |
412 |
|
if (defined $slot) { |
413 |
|
if (ref($slot) eq 'ARRAY') { |
414 |
|
push(@$slot, $this); |
415 |
|
} else { |
416 |
|
$Object->{$el} = [$slot, $this]; |
417 |
|
} |
418 |
|
} else { |
419 |
|
$Object->{$el} = $this; |
420 |
|
} |
421 |
|
} |
422 |
|
|
423 |
|
return; |
424 |
|
} |
425 |
|
|
426 |
&$closure($xp) |
&$closure($xp) if defined $closure; |
|
if defined $closure; |
|
427 |
|
|
428 |
$closure = pop(@closure_stack); |
$closure = pop(@closure_stack); |
429 |
} # End endhndl |
} # End endhndl |
430 |
|
|
431 |
#---------------------------------------------------------- |
#---------------------------------------------------------- |
432 |
|
|
433 |
sub text { |
sub text { |
434 |
my ($xp, $data) = @_; |
my ($xp, $data) = @_; |
435 |
|
|
436 |
return unless $in_poll; |
return unless $in_poll; |
437 |
|
|
438 |
if ($Mode ) { |
if ($Mode) { |
439 |
|
|
440 |
if ($Mode eq 'pass') { |
if ($Mode eq 'pass') { |
441 |
my $safe = sgml_escape($data); |
my $safe = sgml_escape($data); |
442 |
|
|
443 |
$Text .= $safe; |
$Text .= $safe; |
444 |
$Markedup_Text .= $safe; |
$Markedup_Text .= $safe; |
445 |
} |
} elsif ($Mode eq 'object') { |
446 |
elsif ($Mode eq 'object') { |
$Object->{_Text} .= $data if $data =~ /\S/; |
447 |
$Object->{_Text} .= $data |
} |
|
if $data =~ /\S/; |
|
|
} |
|
448 |
|
|
449 |
return; |
return; |
450 |
} |
} |
451 |
|
|
452 |
&$closure($xp, sgml_escape($data)) |
&$closure($xp, sgml_escape($data)) if (defined $closure); |
|
if (defined $closure); |
|
453 |
|
|
454 |
} # End text |
} # End text |
455 |
|
|
456 |
sub start_mode { |
sub start_mode { |
457 |
my ($xp, $mode) = @_; |
my ($xp, $mode) = @_; |
458 |
|
|
459 |
if ($mode eq 'pass') { |
if ($mode eq 'pass') { |
460 |
$Text = ''; |
$Text = ''; |
461 |
$Markedup_Text = ''; |
$Markedup_Text = ''; |
462 |
} |
} elsif ($mode eq 'object') { |
463 |
elsif ($mode eq 'object') { |
$Object = { |
464 |
$Object = {_Atts => undef, |
_Atts => undef, |
465 |
_Text => undef |
_Text => undef |
466 |
}; |
}; |
467 |
} |
} |
468 |
|
|
469 |
$Mode = $mode; |
$Mode = $mode; |
470 |
$Mode_level = $xp->depth; |
$Mode_level = $xp->depth; |
471 |
} # End start_mode |
} # End start_mode |
472 |
|
|
473 |
sub sgml_escape { |
sub sgml_escape { |
474 |
my ($str) = @_; |
my ($str) = @_; |
475 |
|
|
476 |
$str =~ s/\&/\&/g; |
$str =~ s/\&/\&/g; |
477 |
$str =~ s/</\</g; |
$str =~ s/</\</g; |
478 |
$str =~ s/>/\>/g; |
$str =~ s/>/\>/g; |
479 |
|
|
480 |
$str; |
$str; |
481 |
} # End sgml_escape |
} # End sgml_escape |
482 |
|
|
|
|
|
483 |
################################################################ |
################################################################ |
484 |
|
|
485 |
package Poll; |
package Poll; |
510 |
@sql_update = (); |
@sql_update = (); |
511 |
|
|
512 |
$last_fn=sprintf("%02d.php",$page_nr); |
$last_fn=sprintf("%02d.php",$page_nr); |
513 |
$last_page="$html_header $body $html_next $html_footer"; |
$last_page="$html{'header'} $body $html{'submit'} $html{'footer'}"; |
514 |
# delete vars for next page |
# delete vars for next page |
515 |
$page_nr++; |
$page_nr++; |
516 |
$body=""; |
$body=""; |
523 |
|
|
524 |
my ($xp, $el, $attref, $ncref) = @_; |
my ($xp, $el, $attref, $ncref) = @_; |
525 |
|
|
526 |
$pitanje_tag=""; |
$question_tag=""; |
527 |
|
|
528 |
$$ncref = sub { |
$$ncref = sub { |
529 |
my ($xp, $text) = @_; |
my ($xp, $text) = @_; |
530 |
if (defined($text)) { |
if (defined($text)) { |
531 |
$body.=x($text); |
$body.=x($text); |
532 |
chomp $text; |
chomp $text; |
533 |
$pitanje_tag .= x($text); |
$question_tag .= x($text); |
534 |
} else { |
} else { |
535 |
$pitanje_nr = $pitanje_tag; |
$question_nr{$q_type} = $question_tag; |
536 |
$pitanje_nr =~ s/[^0-9a-zA-Z]//g; |
$question_nr{$q_type} =~ s/[^0-9a-zA-Z]//g; |
537 |
print "$pitanje_nr "; |
print "$question_nr{$q_type} "; |
538 |
} |
} |
539 |
$p_suffix=""; |
$p_suffix=""; |
540 |
}; |
}; |
542 |
|
|
543 |
|
|
544 |
sub hr { |
sub hr { |
545 |
$body .= "<br></td></tr>$html_separator<tr><td></td><td><br>"; |
$body .= $html{'hr_before'}.$html{'separator'}.$html{'hr_after'}; |
546 |
} |
} |
547 |
|
|
548 |
sub br { |
sub que { |
|
$body .= "<br>\n"; |
|
|
} |
|
|
|
|
|
sub pit { |
|
549 |
package main; |
package main; |
550 |
|
|
551 |
my ($xp, $el, $attref, $ncref) = @_; |
my ($xp, $el, $attref, $ncref) = @_; |
552 |
|
|
553 |
$body.="<p>"; |
my $nonum = x($attref->{unnumbered}); |
554 |
|
if ($nonum) { |
555 |
|
$q_type = $u_db_col; # unnumbered questions |
556 |
|
} else { |
557 |
|
$q_type = $q_db_col; |
558 |
|
} |
559 |
|
|
560 |
|
$question_nr{$q_type}++; |
561 |
|
|
562 |
|
$body.=$html{'que_before'} if ($html{'que_before'}); |
563 |
|
|
564 |
$$ncref = sub { |
$$ncref = sub { |
565 |
my ($xp, $text) = @_; |
my ($xp, $text) = @_; |
567 |
if (defined $text) { |
if (defined $text) { |
568 |
$body.=x($text); |
$body.=x($text); |
569 |
} else { |
} else { |
570 |
$body.="</p>"; |
$body.=$html{'que_after'} if ($html{'que_after'}); |
571 |
} |
} |
572 |
} |
} |
573 |
} |
} |
574 |
|
|
575 |
sub podpit { |
sub subque { |
576 |
package main; |
package main; |
577 |
|
|
578 |
my ($xp, $el, $attref, $ncref) = @_; |
my ($xp, $el, $attref, $ncref) = @_; |
579 |
|
|
580 |
$body.='<table width="100%" cellspacing="0" cellpadding="2" border="0">'; |
$body.=$html{'subque_before'} if ($html{'subque_before'}); |
581 |
|
|
582 |
$$ncref = sub { |
$$ncref = sub { |
583 |
my ($xp, $text) = @_; |
my ($xp, $text) = @_; |
584 |
|
|
585 |
if (defined $text) { |
if (defined $text) { |
586 |
$body.=x($text); |
$body.=x($text); |
587 |
} else { |
} else { |
588 |
$body.="</table>"; |
$body.=$html{'subque_after'} if ($html{'subque_after'}); |
589 |
} |
} |
590 |
} |
} |
591 |
} |
} |
592 |
|
|
593 |
|
|
594 |
sub odg { |
sub ans { |
595 |
package main; |
package main; |
596 |
|
|
597 |
my ($xp, $el, $attref, $ncref) = @_; |
my ($xp, $el, $attref, $ncref) = @_; |
598 |
|
|
599 |
$body .= "<p>"; |
$body.=$html{'ans_before'} if ($html{'ans_before'}); |
600 |
|
|
601 |
$$ncref = sub { |
$$ncref = sub { |
602 |
my ($xp, $text) = @_; |
my ($xp, $text) = @_; |
603 |
|
|
604 |
if (defined $text) { |
if (defined $text) { |
605 |
$body .= x($text); |
$body .= x($text); |
606 |
} else { |
} else { |
607 |
$body .= "</p>"; |
$body.=$html{'ans_after'} if ($html{'ans_after'}); |
608 |
} |
} |
609 |
} |
} |
610 |
} |
} |
637 |
|
|
638 |
my @dropdown_data; |
my @dropdown_data; |
639 |
|
|
640 |
|
my $default_value = x($attref->{default_value}) || 'null'; |
641 |
|
my $default_text = x($attref->{default_text}) || '-'; |
642 |
|
|
643 |
$$ncref = sub { |
$$ncref = sub { |
644 |
my ($xp, $text) = @_; |
my ($xp, $text) = @_; |
645 |
|
|
652 |
} else { |
} else { |
653 |
my $opt; |
my $opt; |
654 |
my $id=1; |
my $id=1; |
655 |
my $p=new_pit(); |
my $p=new_que(); |
656 |
$body.="<select name=$p >\n"; |
$body.="<select name=$p >\n"; |
657 |
$body.="<option value=null>-</option>\n"; |
$body.="<option value=\"$default_value\">$default_text</option>\n"; |
658 |
foreach $opt (@dropdown_data) { |
foreach $opt (@dropdown_data) { |
659 |
if (defined($opt) && $opt ne "") { |
if (defined($opt) && $opt ne "") { |
660 |
$body.="<option value=$id>$opt</option>\n"; |
$body.="<option value=$id>$opt</option>\n"; |
677 |
my ($xp, $text) = @_; |
my ($xp, $text) = @_; |
678 |
my $size=$attref->{size}; |
my $size=$attref->{size}; |
679 |
$size = 25 if (! defined $size || $size == 0); # default |
$size = 25 if (! defined $size || $size == 0); # default |
680 |
my $p=new_pit(); |
my $p=new_que(); |
681 |
$body.="<input type=text name=$p size=".x($size)." >\n"; |
$body.="<input type=text name=$p size=".x($size)." >\n"; |
682 |
push @sql_create,"$p text"; |
push @sql_create,"$p text"; |
683 |
push @sql_update,"$p='\$$p'"; |
push @sql_update,"$p='\$$p'"; |
691 |
$$ncref = sub { |
$$ncref = sub { |
692 |
my ($xp, $text) = @_; |
my ($xp, $text) = @_; |
693 |
if (! defined $text) { |
if (! defined $text) { |
694 |
my $nr=$attref->{nr}; |
my $nr=$attref->{nr} || die "need <radiobuttons_tab nr=\"999\"> for number of buttons"; |
695 |
my $p=new_pit(); |
# shownumbers="before|after" |
696 |
|
my $shownumbers=lc(x($attref->{shownumbers})) || 'no'; |
697 |
|
my $p=new_que(); |
698 |
for (my $i=1; $i<=$nr; $i++) { |
for (my $i=1; $i<=$nr; $i++) { |
699 |
$body.="<td><input type=radio name=$p value=$i></td> "; |
$body.="<td>"; |
700 |
|
$body.=$i if ($shownumbers eq "before"); |
701 |
|
$body.="<input type=radio name=$p value=$i>"; |
702 |
|
$body.=$i if ($shownumbers eq "after"); |
703 |
|
$body.="</td> "; |
704 |
} |
} |
705 |
push @sql_create,"$p int4"; |
push @sql_create,"$p int4"; |
706 |
push @sql_update,"$p=\$$p"; |
push @sql_update,"$p=\$$p"; |
725 |
push @radiobuttons_data,x($text) if ($text ne ""); |
push @radiobuttons_data,x($text) if ($text ne ""); |
726 |
} else { |
} else { |
727 |
my $opt; |
my $opt; |
728 |
my $p=new_pit(); |
my $p=new_que(); |
729 |
my $id=1; |
my $id=1; |
730 |
foreach $opt (@radiobuttons_data) { |
foreach $opt (@radiobuttons_data) { |
731 |
if (defined($opt) && $opt ne "") { |
if (defined($opt) && $opt ne "") { |
744 |
|
|
745 |
$$ncref = sub { |
$$ncref = sub { |
746 |
my ($xp, $text) = @_; |
my ($xp, $text) = @_; |
747 |
my $p=new_pit(); |
my $p=new_que(); |
748 |
$body.="<input type=checkbox name=$p >\n"; |
$body.="<input type=checkbox name=$p >\n"; |
749 |
push @sql_create,"$p text"; |
push @sql_create,"$p text"; |
750 |
push @sql_update,"$p='\$$p'"; |
push @sql_update,"$p='\$$p'"; |
770 |
push @checkboxes_data,x($text) if ($text ne ""); |
push @checkboxes_data,x($text) if ($text ne ""); |
771 |
} else { |
} else { |
772 |
my $opt; |
my $opt; |
773 |
my $base_p=new_pit(); |
my $base_p=new_que(); |
774 |
my $id=1; |
my $id=1; |
775 |
|
|
776 |
my $before=$attref->{before}; |
my $before=$attref->{before}; |
803 |
} |
} |
804 |
} |
} |
805 |
|
|
806 |
|
# |
807 |
|
# insert arbitrary html |
808 |
|
# |
809 |
|
sub html { |
810 |
|
package main; |
811 |
|
|
812 |
|
my ($xp, $el, $attref, $ncref) = @_; |
813 |
|
|
814 |
|
$body.=$html{'html_before'} if ($html{'html_before'}); |
815 |
|
|
816 |
|
$$ncref = sub { |
817 |
|
my ($xp, $text) = @_; |
818 |
|
|
819 |
|
if (defined $text) { |
820 |
|
$body.=x($text); |
821 |
|
} elsif ($attref->{include}) { |
822 |
|
$body.=suck_file($attref->{include}); |
823 |
|
} else { |
824 |
|
$body.=$html{'html_after'} if ($html{'html_after'}); |
825 |
|
} |
826 |
|
} |
827 |
|
} |
828 |
|
|
829 |
|
# |
830 |
|
# markup tag can specify any markup which should be applied pre (before) |
831 |
|
# or post (after) any other tag which produces html output |
832 |
|
# |
833 |
|
|
834 |
|
sub markup { |
835 |
|
package main; |
836 |
|
|
837 |
|
my ($xp, $el, $attref, $ncref) = @_; |
838 |
|
|
839 |
|
$$ncref = sub { |
840 |
|
my ($xp, $text) = @_; |
841 |
|
|
842 |
|
my $tag=lc($attref->{tag}) || die 'markup need tag attribute: <markup tag="tag_name" pos="(before|after)">'; |
843 |
|
my $pos=lc($attref->{pos}) || die 'markup need pos attribute: <markup tag="tag_name" pos="(before|after)">'; |
844 |
|
|
845 |
|
return if (! defined $text); |
846 |
|
chomp($text); |
847 |
|
if ($text ne "") { |
848 |
|
$text =~ s/\&/\&/g; |
849 |
|
$text =~ s/\</</g; |
850 |
|
$text =~ s/\>/>/g; |
851 |
|
$text =~ s/^\s+//g; |
852 |
|
$text =~ s/\s+$//g; |
853 |
|
$html{$tag.'_'.$pos}=x($text); |
854 |
|
print "Using markup $pos $tag: ",x($text),"<--\n"; |
855 |
|
} |
856 |
|
} |
857 |
|
} |
858 |
|
|
859 |
|
# |
860 |
|
# print final instructions and exit |
861 |
|
# |
862 |
|
|
863 |
print "\n\nTo create database for poll $poll use:\n\n"; |
print "\n\nTo create database for poll $poll use:\n\n"; |
864 |
print "\$ psql template1 < $poll/$poll.sql\n\n"; |
print "\$ psql template1 < $poll/$poll.sql\n\n"; |
865 |
print "THIS WILL DISTROY ALL DATA IN EXISTING DATABASE ".$prefix.$poll." !!\n"; |
print "THIS WILL DISTROY ALL DATA IN EXISTING DATABASE ".$prefix.$poll." !!\n"; |
866 |
|
|
867 |
# read configuration data |
# read configuration data |
|
# |
|
|
# FIX: write actually this :-) |
|
868 |
sub config { |
sub config { |
869 |
package main; |
package main; |
870 |
my ($xp, $el, $attref, $ncref) = @_; |
my ($xp, $el, $attref, $ncref) = @_; |
875 |
$prefix=x($attref->{prefix}); |
$prefix=x($attref->{prefix}); |
876 |
$without_invitation=x($attref->{without_invitation}) && |
$without_invitation=x($attref->{without_invitation}) && |
877 |
print "Pool is without need for unique ID (and invitation URLs).\n"; |
print "Pool is without need for unique ID (and invitation URLs).\n"; |
878 |
$remove_nrs_in_answers=x($attref->{$remove_nrs_in_answers}) && |
$remove_nrs_in_answers=x($attref->{remove_nrs_in_answers}) && |
879 |
print "Numbers before answers will be removed.\n"; |
print "Numbers before answers will be removed.\n"; |
880 |
|
|
881 |
|
# fill in configuration about include files |
882 |
|
foreach my $file (qw(header separator submit footer thanks)) { |
883 |
|
if ($attref->{$file}) { |
884 |
|
$include_files{$file}=x($attref->{$file}); |
885 |
|
print "Using custom $file '$include_files{$file}'\n"; |
886 |
|
$html{$file} = suck_file($include_files{$file}); |
887 |
|
} |
888 |
|
} |
889 |
|
$q_db_col=x($attref->{q_db_col}) || 'q'; |
890 |
|
$u_db_col=x($attref->{u_db_col}) || 'u'; |
891 |
|
|
892 |
} |
} |
893 |
} |
} |
894 |
|
|