--- make_poll.pl 2003/04/08 17:53:46 1.1.1.1 +++ make_poll.pl 2003/04/24 16:43:09 1.3 @@ -1,9 +1,19 @@ #!/usr/bin/perl -w # +use strict; + use XML::Parser; +use Text::Iconv; -use strict; +# output charset +my $charset='ISO-8859-2'; + +Text::Iconv->raise_error(0); # Conversion errors raise exceptions +my $from_utf8 = Text::Iconv->new('UTF8', $charset); +sub x { + return $from_utf8->convert($_[0]); +} $|=1; @@ -64,67 +74,26 @@ #------------------------------------------------------------------ -my $html_header.=<<'End_of_header;'; - - - - proof.anketa - - - - - - - - - - - - - - - - - - - - - - -End_of_separator; - -#------------------------------------------------------------------ +sub suck_file { + my $file = shift @_; + open(H,$file) || die "can't open '$file': $!"; + my $content; + while () { $content .= $_; } ; + close(H); + return $content; +} -my $html_footer=<<'End_of_footer;'; - - - - - - - -



-

-End_of_header; - -#------------------------------------------------------------------ - -my $html_separator=<<'End_of_separator;'; -


-   -


-
- - - -End_of_footer; +my $html_header=suck_file("header.html"); +my $html_separator=suck_file("separator.html"); +my $html_next=suck_file("next.html"); +my $html_footer=suck_file("footer.html"); #------------------------------------------------------------------ sub php_header { my ($page_nr,@sql_update) = @_; -my $out=' 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; +my $common_php = suck_file("common.php"); #------------------------------------------------------------------ -my $head_php.=<<'End_of_head;'; - - 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; +my $head_php=suck_file("head.php"); #------------------------------------------------------------------ -my $html_kraj=<<'End_of_kraj;'; - - - - wopi.poll - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



-


-


-

-Hvala vam na sudjelovanju u anketi! -

-

-Zahvaljujemo se na vašem vremenu. Nadamo se da ćete i vi biti -među sretnim dobitnicima. -
-
-Do slijedeće ankete i nagradne igre srdačno vas pozdravljamo. -
-
Hvala. -
-
-proof. -


-
-
- - - -End_of_kraj; +my $html_kraj=suck_file("thanks.html"); #------------------------------------------------------------------ @@ -447,7 +228,7 @@ $page_nr++; open(PAGE, ">$dir/$next_fn") or die "Couldn't open $next_fn for writing:\n$!"; print PAGE php_header($page_nr,@last_sql_update); -print PAGE $html_kraj; +print PAGE "$html_header $html_kraj $html_footer"; close(PAGE); # dump sql structure @@ -457,18 +238,26 @@ print SQL "create table $dir (do_stranice text default null, ",join(",\n",@sql_create),");\n"; close(SQL); -# dump common.inc +# dump common.php + +open(PHP,">$dir/common.php") || die "common.php: $!"; +$common_php =~ s/##DB##/$dir/g; +my $db_name = $prefix.$dir; +$common_php =~ s/##DB_NAME##/$db_name/g; +$common_php =~ s/##PREFIX##/$prefix/g; +$common_php =~ s/##DB_USER##/$db_user/g; +$common_php =~ s/##PREFIX##/$prefix/g; +my $members_db = $prefix."members"; +$common_php =~ s/##MEMBERS_DB##/$members_db/g; -open(PHP,">$dir/common.inc") || die "common.inc: $!"; -print PHP ''; +print PHP $common_php; close(PHP); open(PHP,">$dir/head.php") || die "head.php: $!"; -print PHP ''; close(PHP); ################ @@ -705,8 +494,8 @@ $last_fn="index.php" if ($last_fn eq "01.php"); open(PAGE, ">$dir/$last_fn") or die "Couldn't open $last_fn for writing:\n$!"; if ($page_nr == 2) { - print PAGE '"; } @@ -805,7 +594,7 @@ my ($xp, $text) = @_; if (defined $text) { - $body.=$text; + $body.=x($text); } else { $body.=""; } @@ -824,7 +613,7 @@ my ($xp, $text) = @_; if (defined $text) { - $body .= $text; + $body .= x($text); } else { $body .= "

"; } @@ -845,7 +634,7 @@ $text=~s/ le / <= /g; $text=~s/ gt / > /g; $text=~s/ ge / >= /g; - $body.=$text; + $body.=x($text); } else { $body.="\n?>\n"; } @@ -867,7 +656,7 @@ $text=~s/^\s*//g; $text=~s/^[\d\.\s]+//g; $text=~s/\s*$//g; - push @dropdown_data,$text if ($text ne ""); + push @dropdown_data,x($text) if ($text ne ""); } else { my $opt; my $id=1; @@ -897,7 +686,7 @@ my $size=$attref->{size}; $size = 25 if (! defined $size || $size == 0); # default my $p=new_pit(); - $body.="\n"; + $body.="\n"; push @sql_create,"$p text"; push @sql_update,"$p='\$$p'"; } @@ -935,7 +724,7 @@ $text=~s/^\s*//g; $text=~s/^[\d\.\s]+//g; $text=~s/\s*$//g; - push @radiobuttons_data,$text if ($text ne ""); + push @radiobuttons_data,x($text) if ($text ne ""); } else { my $opt; my $p=new_pit(); @@ -980,7 +769,7 @@ $text=~s/^\s*//g; $text=~s/^[\d\.\s]+//g; $text=~s/\s*$//g; - push @checkboxes_data,$text if ($text ne ""); + push @checkboxes_data,x($text) if ($text ne ""); } else { my $opt; my $base_p=new_pit(); @@ -999,11 +788,11 @@ if (defined($opt) && $opt ne "") { $p=$base_p."_".$id; $id++; - $body .= $before if ($before); + $body .= x($before) if ($before); $body.=""; - $body .= $middle if ($middle); + $body .= x($middle) if ($middle); $body .= "$opt" if (! $hide_description); - $body .= $after if ($after); + $body .= x($after) if ($after); $body.="\n"; push @sql_create,"$p boolean"; @@ -1017,482 +806,3 @@ } #--------------------------------------------------------------- - -sub slide { - package main; - - my ($xp, $el, $attref, $ncref) = @_; - - my $prev = $page_number ? slidename($page_number) : $index; - $page_number++; - my $fn = slidename($page_number); - my $next = slidename($page_number + 1); - - open(SLIDE, ">$dir/$fn") or die "Couldn't open $fn for writing:\n$!"; - - print SLIDE $prolog; - - undef @slidetitle; - $body = ''; - $inlist = 0; - - $$ncref = - sub { - my ($xp, $text) = @_; - - if (defined $text) { - #ignore text at slide toplevel - } - else { - $Titles[$page_number] = $slidetitle[0]; - - print SLIDE "$slidetitle[0]\n"; - print SLIDE $style_link; - print SLIDE "\n"; - - if ($dostyle) { - print SLIDE "\n"; - } - else { - print SLIDE "\n"; - } - - my $navbar = "\n"; - $navbar .= "\n"; - $navbar .= "\n"; - $navbar .= "\n"; - $navbar .= "
PreviousIndexNext
\n"; - - print SLIDE "$navbar
\n"; - if ($dostyle) { - print SLIDE "\n"; - print SLIDE "

$slidetitle[1]

\n"; - } - else { - print SLIDE "
\n"; - print SLIDE "\n"; - print SLIDE ""; - print SLIDE "

"; - print SLIDE "$slidetitle[1]"; - print SLIDE "

\n"; - print SLIDE "
\n"; - print SLIDE "
\n"; - print SLIDE "\n"; - } - print SLIDE $body; - - if ($inlist) { - print SLIDE "\n\n"; - } - - unless ($dostyle) { - print SLIDE "\n\n"; - print SLIDE "\n
\n"; - } - - print SLIDE "\n
\n$navbar"; - print SLIDE "\n\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\n"; - $inlist = 0; - } - - unless ($inlist) { - $body .= "\n