/[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.5 by dpavlin, Thu Apr 24 17:55:17 2003 UTC revision 1.8 by dpavlin, Wed Sep 24 19:55:43 2003 UTC
# Line 19  End_of_Usage; Line 19  End_of_Usage;
19    
20  my @Modes = qw(object pass skip);  my @Modes = qw(object pass skip);
21    
22  my $dir;  my $poll;
23  my $dowarn = 1;  my $dowarn = 1;
24    
25  my $pitanje_nr = 0;             # curr. pitanje  my $pitanje_nr = 0;             # curr. pitanje
# Line 74  my $html_footer=suck_file("footer.html") Line 74  my $html_footer=suck_file("footer.html")
74  sub php_header {  sub php_header {
75  my ($page_nr,@sql_update) = @_;  my ($page_nr,@sql_update) = @_;
76  my $out='<?php  my $out='<?php
77          include("common.php");          include_once("common.php");
78          if (isset($update)) {          if (isset($update)) {
79                  $member_id=id_decode($a);                  $member_id=id_decode($a);
80                  ';                  ';
81  $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]);
82  $out.='  $out.='
83                  $sql="update '.$dir.' set '.join(",\n",@sql_update).',                  $sql="update '.$poll.' set '.join(",\n",@sql_update).',
84                          do_stranice=\'$PHP_SELF\'                          do_stranice=\'$PHP_SELF\'
85                          where id=$id";                          where id=$id";
86  #               print "<pre>$sql</pre>";  #               print "<pre>$sql</pre>";
87                  $result=pg_Exec($conn,fix_sql($sql));                  $result=pg_Exec($conn,fix_sql($sql));
88          } elseif($do_stranice != $PHP_SELF) {          } elseif($do_stranice != $PHP_SELF && isset($do_uri) && isset($a)) {
89                  Header("Location: $do_uri?a=$a");                  Header("Location: $do_uri?a=$a");
90                  exit;                  exit;
91          }          }
# Line 123  die "No poll xml file provided!\n$Usage" Line 123  die "No poll xml file provided!\n$Usage"
123    
124  die "Can't read $xmlfile" unless -r $xmlfile;  die "Can't read $xmlfile" unless -r $xmlfile;
125    
126  if (defined $dir) {  if (defined $poll) {
127    die "$dir isn't a directory" unless -d $dir;    die "$poll isn't a directory" unless -d $poll;
128  }  }
129  else {  else {
130    $xmlfile =~ m!([^/.]+)(?:\.[^/.]*)?$!;    $xmlfile =~ m!([^/.]+)(?:\.[^/.]*)?$!;
131    $dir = $1;    $poll = $1;
132    if (-e $dir) {    if (-e $poll) {
133      die "$dir exists but isn't a directory"      die "$poll exists but isn't a directory"
134        unless -d $dir;        unless -d $poll;
135    }    }
136    else {    else {
137      mkdir $dir, 0755;      mkdir $poll, 0755;
138    }    }
139  }  }
140    
# Line 178  $p->parsefile($xmlfile); Line 178  $p->parsefile($xmlfile);
178    
179  print "p[$page_nr] ";  print "p[$page_nr] ";
180    
181  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$!";
182  print PAGE php_header($page_nr,@prelast_sql_update);  print PAGE php_header($page_nr,@prelast_sql_update);
183  my $next_fn=sprintf("%02d.php",$page_nr);  my $next_fn=sprintf("%02d.php",$page_nr);
184  $last_page=~s/##NEXTPAGE##/$next_fn/;  $last_page=~s/##NEXTPAGE##/$next_fn/;
# Line 186  print PAGE $last_page; Line 186  print PAGE $last_page;
186  close(PAGE);  close(PAGE);
187    
188  $page_nr++;  $page_nr++;
189  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$!";
190  print PAGE php_header($page_nr,@last_sql_update);  print PAGE php_header($page_nr,@last_sql_update);
191  print PAGE "$html_header $html_kraj $html_footer";  print PAGE "$html_header $html_kraj $html_footer";
192  close(PAGE);  close(PAGE);
193    
194  # dump sql structure  # dump sql structure
195    
196  open(SQL,">$dir/$dir.sql") || die "$dir.sql: $!";  open(SQL,">$poll/$poll.sql") || die "$poll.sql: $!";
197    print SQL "drop database ".$prefix.$poll.";\n";
198    print SQL "create database ".$prefix.$poll.";\n";
199    print SQL "\\connect ".$prefix.$poll.";\n";
200  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";
201  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";
202  close(SQL);  close(SQL);
203    
204  # dump common.php  # dump common.php
205    
206  open(PHP,">$dir/common.php") || die "common.php: $!";  open(PHP,">$poll/common.php") || die "common.php: $!";
207  $common_php =~ s/##DB##/$dir/g;  $common_php =~ s/##DB##/$poll/g;
208  my $db_name = $prefix.$dir;  my $db_name = $prefix.$poll;
209  $common_php =~ s/##DB_NAME##/$db_name/g;  $common_php =~ s/##DB_NAME##/$db_name/g;
210  $common_php =~ s/##PREFIX##/$prefix/g;  $common_php =~ s/##PREFIX##/$prefix/g;
211  $common_php =~ s/##DB_USER##/$db_user/g;  $common_php =~ s/##DB_USER##/$db_user/g;
# Line 213  $common_php =~ s/##MEMBERS_DB##/$members Line 216  $common_php =~ s/##MEMBERS_DB##/$members
216  print PHP $common_php;  print PHP $common_php;
217  close(PHP);  close(PHP);
218    
219  open(PHP,">$dir/head.php") || die "head.php: $!";  open(PHP,">$poll/head.php") || die "head.php: $!";
220  my $max_page = $page_nr - 1;  my $max_page = $page_nr - 1;
221  $head_php=~ s/##MAXPAGE##/$max_page/;  $head_php=~ s/##MAXPAGE##/$max_page/;
222  $head_php=~ s/##TEXT##/Ispunili ste %02d%% ankete/;  $head_php=~ s/##TEXT##/Ispunili ste %02d%% ankete/;
# Line 221  print PHP $head_php; Line 224  print PHP $head_php;
224  close(PHP);  close(PHP);
225    
226  # 01.php -> index.php  # 01.php -> index.php
227  rename "$dir/01.php","$dir/index.php" || die "can't rename '$dir/01.php' to index.php";  rename "$poll/01.php","$poll/index.php" || die "can't rename '$poll/01.php' to index.php";
228    
229  ################  ################
230  ## End of main  ## End of main
# Line 229  rename "$dir/01.php","$dir/index.php" || Line 232  rename "$dir/01.php","$dir/index.php" ||
232    
233  # return unique name of pitanje  # return unique name of pitanje
234  sub new_pit {  sub new_pit {
235          my $out="p".$pitanje_nr.$p_suffix;          my $out="p".$pitanje_nr;
236            $out .= "_".$p_suffix if ($p_suffix);
237          $curr_suffix=$p_suffix;          $curr_suffix=$p_suffix;
238          $p_suffix++;          $p_suffix++;
239          return $out;          return $out;
# Line 303  sub starthndl { Line 307  sub starthndl {
307      &$subname($xp, $el, \%atts, \$new_closure);      &$subname($xp, $el, \%atts, \$new_closure);
308    }    }
309    else {    else {
310      $body .= $xp->recognized_string;      $body .= x($xp->recognized_string);
311      $new_closure =      $new_closure =
312        sub {        sub {
313          my ($xp, $text) = @_;          my ($xp, $text) = @_;
314                    
315          if (defined $text) {          if (defined $text) {
316            $body .= $text;            $body .= x($text);
317          }          }
318          else {          else {
319            $body .= "</$el>";            $body .= x("</$el>");
320          }          }
321        };        };
322    }    }
# Line 434  sub sgml_escape { Line 438  sub sgml_escape {
438    $str;    $str;
439  }  # End sgml_escape  }  # End sgml_escape
440    
441    
442  ################################################################  ################################################################
443    
444  package Poll;  package Poll;
# Line 451  sub page { Line 456  sub page {
456                          print "p[$page_nr] ";                          print "p[$page_nr] ";
457    
458                          if (defined $last_fn) {                          if (defined $last_fn) {
459                                  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$!";
460                                  if ($page_nr == 2) {                                  print PAGE php_header($page_nr,@prelast_sql_update);
                                         print PAGE '<?php  
 include("common.php");  
 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  
   
   
461                                  my $next_fn=sprintf("%02d.php",$page_nr);                                  my $next_fn=sprintf("%02d.php",$page_nr);
462                                  $last_page=~s/##NEXTPAGE##/$next_fn/;                                  $last_page=~s/##NEXTPAGE##/$next_fn/;
463                                  print PAGE $last_page;                                  print PAGE $last_page;
# Line 764  sub checkboxes { Line 747  sub checkboxes {
747          }          }
748  }  }
749    
750    print "\n\nTo create database for poll $poll use:\n\n";
751    print "\$ psql template1 < $poll/$poll.sql\n\n";
752    print "THIS WILL DISTROY ALL DATA IN EXISTING DATABASE ".$prefix.$poll." !!\n";
753    
754  # read configuration data  # read configuration data
755  #  #
756  # FIX: write actually this :-)  # FIX: write actually this :-)

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.26