53 |
# this is usename in database |
# this is usename in database |
54 |
my $db_user="dpavlin"; |
my $db_user="dpavlin"; |
55 |
|
|
56 |
|
# This option allows users to fill poll without using invitation URL. |
57 |
|
# That also means it's unpossible for them to return to exiting poll |
58 |
|
# because they don't have thair own unique ID. Howver, it enables simple |
59 |
|
# polls to be conducted by just publishing URL to them. |
60 |
|
my $without_invitation=0; |
61 |
|
|
62 |
|
# This will remove numbers before answers. That enables you to have |
63 |
|
# answers written like: |
64 |
|
# 1.1 red |
65 |
|
# 1.2 black |
66 |
|
# and users will see just "red" and "black" |
67 |
|
my $remove_nrs_in_answers=0; |
68 |
|
|
69 |
#------------------------------------------------------------------ |
#------------------------------------------------------------------ |
70 |
|
|
71 |
sub suck_file { |
sub suck_file { |
96 |
$sql="update '.$poll.' set '.join(",\n",@sql_update).', |
$sql="update '.$poll.' set '.join(",\n",@sql_update).', |
97 |
do_stranice=\'$PHP_SELF\' |
do_stranice=\'$PHP_SELF\' |
98 |
where id=$id"; |
where id=$id"; |
99 |
print "<pre>$sql</pre>"; |
# print "<pre>$sql</pre>"; |
100 |
$result=pg_Exec($conn,fix_sql($sql)); |
$result=pg_Exec($conn,fix_sql($sql)); |
101 |
} elseif($do_stranice != $PHP_SELF && isset($do_uri) && isset($a)) { |
} elseif($do_stranice != $PHP_SELF && isset($do_uri) && isset($a)) { |
102 |
Header("Location: $do_uri?a=$a"); |
Header("Location: $do_uri?a=$a"); |
192 |
print "p[$page_nr] "; |
print "p[$page_nr] "; |
193 |
|
|
194 |
open(PAGE, ">$poll/$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$!"; |
|
if ($page_nr <= 2) { |
|
|
print PAGE php_new_poll(); |
|
|
} |
|
195 |
print PAGE php_header($page_nr,@prelast_sql_update); |
print PAGE php_header($page_nr,@prelast_sql_update); |
196 |
my $next_fn=sprintf("%02d.php",$page_nr); |
my $next_fn=sprintf("%02d.php",$page_nr); |
197 |
$last_page=~s/##NEXTPAGE##/$next_fn/; |
$last_page=~s/##NEXTPAGE##/$next_fn/; |
207 |
# dump sql structure |
# dump sql structure |
208 |
|
|
209 |
open(SQL,">$poll/$poll.sql") || die "$poll.sql: $!"; |
open(SQL,">$poll/$poll.sql") || die "$poll.sql: $!"; |
210 |
|
print SQL "drop database ".$prefix.$poll.";\n"; |
211 |
|
print SQL "create database ".$prefix.$poll.";\n"; |
212 |
|
print SQL "\\connect ".$prefix.$poll.";\n"; |
213 |
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"; |
214 |
print SQL "create table $poll (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"; |
215 |
close(SQL); |
close(SQL); |
225 |
$common_php =~ s/##PREFIX##/$prefix/g; |
$common_php =~ s/##PREFIX##/$prefix/g; |
226 |
my $members_db = $prefix."members"; |
my $members_db = $prefix."members"; |
227 |
$common_php =~ s/##MEMBERS_DB##/$members_db/g; |
$common_php =~ s/##MEMBERS_DB##/$members_db/g; |
228 |
|
$common_php =~ s/##WITHOUT_INVITATION##/$without_invitation/g; |
229 |
|
|
230 |
print PHP $common_php; |
print PHP $common_php; |
231 |
close(PHP); |
close(PHP); |
246 |
|
|
247 |
# return unique name of pitanje |
# return unique name of pitanje |
248 |
sub new_pit { |
sub new_pit { |
249 |
my $out="p".$pitanje_nr.$p_suffix; |
my $out="p".$pitanje_nr; |
250 |
|
$out .= "_".$p_suffix if ($p_suffix); |
251 |
$curr_suffix=$p_suffix; |
$curr_suffix=$p_suffix; |
252 |
$p_suffix++; |
$p_suffix++; |
253 |
return $out; |
return $out; |
453 |
} # End sgml_escape |
} # End sgml_escape |
454 |
|
|
455 |
|
|
|
sub php_new_poll { |
|
|
return '<?php |
|
|
include_once("common.php"); |
|
|
if (isset($do_stranice) && $do_stranice !="") { |
|
|
Header("Location: $do_uri?a=$a"); |
|
|
exit; |
|
|
} |
|
|
$member_id=id_decode($a); |
|
|
$sql="insert into '.$poll.' ( 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 '.$poll.' where oid=$lastoid")); |
|
|
$row=pg_fetch_row($result,0); |
|
|
$id=$row[0]; |
|
|
?>'; |
|
|
} |
|
|
|
|
456 |
################################################################ |
################################################################ |
457 |
|
|
458 |
package Poll; |
package Poll; |
471 |
|
|
472 |
if (defined $last_fn) { |
if (defined $last_fn) { |
473 |
open(PAGE, ">$poll/$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$!"; |
474 |
if ($page_nr < 2) { |
print PAGE php_header($page_nr,@prelast_sql_update); |
|
print PAGE php_new_poll(); |
|
|
} else { |
|
|
print PAGE php_header($page_nr,@prelast_sql_update); |
|
|
} # last_sql_update |
|
|
|
|
|
|
|
475 |
my $next_fn=sprintf("%02d.php",$page_nr); |
my $next_fn=sprintf("%02d.php",$page_nr); |
476 |
$last_page=~s/##NEXTPAGE##/$next_fn/; |
$last_page=~s/##NEXTPAGE##/$next_fn/; |
477 |
print PAGE $last_page; |
print PAGE $last_page; |
604 |
|
|
605 |
my @dropdown_data; |
my @dropdown_data; |
606 |
|
|
607 |
|
my $default_value = x($attref->{default_value}) || 'null'; |
608 |
|
my $default_text = x($attref->{default_text}) || '-'; |
609 |
|
|
610 |
$$ncref = sub { |
$$ncref = sub { |
611 |
my ($xp, $text) = @_; |
my ($xp, $text) = @_; |
612 |
|
|
613 |
if (defined $text) { |
if (defined $text) { |
614 |
chomp $text; |
chomp $text; |
615 |
$text=~s/^\s*//g; |
$text=~s/^\s*//g; |
616 |
$text=~s/^[\d\.\s]+//g; |
$text=~s/^[\d\.\s]+//g if ($remove_nrs_in_answers); |
617 |
$text=~s/\s*$//g; |
$text=~s/\s*$//g; |
618 |
push @dropdown_data,x($text) if ($text ne ""); |
push @dropdown_data,x($text) if ($text ne ""); |
619 |
} else { |
} else { |
621 |
my $id=1; |
my $id=1; |
622 |
my $p=new_pit(); |
my $p=new_pit(); |
623 |
$body.="<select name=$p >\n"; |
$body.="<select name=$p >\n"; |
624 |
$body.="<option value=null>-</option>\n"; |
$body.="<option value=\"$default_value\">$default_text</option>\n"; |
625 |
foreach $opt (@dropdown_data) { |
foreach $opt (@dropdown_data) { |
626 |
if (defined($opt) && $opt ne "") { |
if (defined($opt) && $opt ne "") { |
627 |
$body.="<option value=$id>$opt</option>\n"; |
$body.="<option value=$id>$opt</option>\n"; |
681 |
if (defined $text) { |
if (defined $text) { |
682 |
chomp $text; |
chomp $text; |
683 |
$text=~s/^\s*//g; |
$text=~s/^\s*//g; |
684 |
$text=~s/^[\d\.\s]+//g; |
$text=~s/^[\d\.\s]+//g if ($remove_nrs_in_answers); |
685 |
$text=~s/\s*$//g; |
$text=~s/\s*$//g; |
686 |
push @radiobuttons_data,x($text) if ($text ne ""); |
push @radiobuttons_data,x($text) if ($text ne ""); |
687 |
} else { |
} else { |
726 |
if (defined $text) { |
if (defined $text) { |
727 |
chomp $text; |
chomp $text; |
728 |
$text=~s/^\s*//g; |
$text=~s/^\s*//g; |
729 |
$text=~s/^[\d\.\s]+//g; |
$text=~s/^[\d\.\s]+//g if ($remove_nrs_in_answers); |
730 |
$text=~s/\s*$//g; |
$text=~s/\s*$//g; |
731 |
push @checkboxes_data,x($text) if ($text ne ""); |
push @checkboxes_data,x($text) if ($text ne ""); |
732 |
} else { |
} else { |
764 |
} |
} |
765 |
} |
} |
766 |
|
|
767 |
|
print "\n\nTo create database for poll $poll use:\n\n"; |
768 |
|
print "\$ psql template1 < $poll/$poll.sql\n\n"; |
769 |
|
print "THIS WILL DISTROY ALL DATA IN EXISTING DATABASE ".$prefix.$poll." !!\n"; |
770 |
|
|
771 |
# read configuration data |
# read configuration data |
772 |
# |
# |
773 |
# FIX: write actually this :-) |
# FIX: write actually this :-) |
779 |
my ($xp, $text) = @_; |
my ($xp, $text) = @_; |
780 |
$db_user=x($attref->{db_user}); |
$db_user=x($attref->{db_user}); |
781 |
$prefix=x($attref->{prefix}); |
$prefix=x($attref->{prefix}); |
782 |
|
$without_invitation=x($attref->{without_invitation}) && |
783 |
|
print "Pool is without need for unique ID (and invitation URLs).\n"; |
784 |
|
$remove_nrs_in_answers=x($attref->{$remove_nrs_in_answers}) && |
785 |
|
print "Numbers before answers will be removed.\n"; |
786 |
} |
} |
787 |
} |
} |
788 |
|
|