/[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.6 by dpavlin, Thu Apr 24 19:11:45 2003 UTC revision 1.9 by dpavlin, Wed Sep 24 20:35:48 2003 UTC
# Line 53  my $prefix="wopi_"; Line 53  my $prefix="wopi_";
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  #------------------------------------------------------------------  #------------------------------------------------------------------
63    
64  sub suck_file {  sub suck_file {
# Line 83  $out.=' Line 89  $out.='
89                  $sql="update '.$poll.' set '.join(",\n",@sql_update).',                  $sql="update '.$poll.' set '.join(",\n",@sql_update).',
90                          do_stranice=\'$PHP_SELF\'                          do_stranice=\'$PHP_SELF\'
91                          where id=$id";                          where id=$id";
92                  print "<pre>$sql</pre>";  #               print "<pre>$sql</pre>";
93                  $result=pg_Exec($conn,fix_sql($sql));                  $result=pg_Exec($conn,fix_sql($sql));
94          } elseif($do_stranice != $PHP_SELF && isset($do_uri) && isset($a)) {          } elseif($do_stranice != $PHP_SELF && isset($do_uri) && isset($a)) {
95                  Header("Location: $do_uri?a=$a");                  Header("Location: $do_uri?a=$a");
# Line 179  $p->parsefile($xmlfile); Line 185  $p->parsefile($xmlfile);
185  print "p[$page_nr] ";  print "p[$page_nr] ";
186    
187  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();  
 }  
188  print PAGE php_header($page_nr,@prelast_sql_update);  print PAGE php_header($page_nr,@prelast_sql_update);
189  my $next_fn=sprintf("%02d.php",$page_nr);  my $next_fn=sprintf("%02d.php",$page_nr);
190  $last_page=~s/##NEXTPAGE##/$next_fn/;  $last_page=~s/##NEXTPAGE##/$next_fn/;
# Line 197  close(PAGE); Line 200  close(PAGE);
200  # dump sql structure  # dump sql structure
201    
202  open(SQL,">$poll/$poll.sql") || die "$poll.sql: $!";  open(SQL,">$poll/$poll.sql") || die "$poll.sql: $!";
203    print SQL "drop database ".$prefix.$poll.";\n";
204    print SQL "create database ".$prefix.$poll.";\n";
205    print SQL "\\connect ".$prefix.$poll.";\n";
206  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";
207  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";
208  close(SQL);  close(SQL);
# Line 212  $common_php =~ s/##DB_USER##/$db_user/g; Line 218  $common_php =~ s/##DB_USER##/$db_user/g;
218  $common_php =~ s/##PREFIX##/$prefix/g;  $common_php =~ s/##PREFIX##/$prefix/g;
219  my $members_db = $prefix."members";  my $members_db = $prefix."members";
220  $common_php =~ s/##MEMBERS_DB##/$members_db/g;  $common_php =~ s/##MEMBERS_DB##/$members_db/g;
221    $common_php =~ s/##WITHOUT_INVITATION##/$without_invitation/g;
222    
223  print PHP $common_php;  print PHP $common_php;
224  close(PHP);  close(PHP);
# Line 232  rename "$poll/01.php","$poll/index.php" Line 239  rename "$poll/01.php","$poll/index.php"
239    
240  # return unique name of pitanje  # return unique name of pitanje
241  sub new_pit {  sub new_pit {
242          my $out="p".$pitanje_nr.$p_suffix;          my $out="p".$pitanje_nr;
243            $out .= "_".$p_suffix if ($p_suffix);
244          $curr_suffix=$p_suffix;          $curr_suffix=$p_suffix;
245          $p_suffix++;          $p_suffix++;
246          return $out;          return $out;
# Line 438  sub sgml_escape { Line 446  sub sgml_escape {
446  }  # End sgml_escape  }  # End sgml_escape
447    
448    
 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];  
 ?>';  
 }  
   
449  ################################################################  ################################################################
450    
451  package Poll;  package Poll;
# Line 475  sub page { Line 464  sub page {
464    
465                          if (defined $last_fn) {                          if (defined $last_fn) {
466                                  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$!";
467                                  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  
   
   
468                                  my $next_fn=sprintf("%02d.php",$page_nr);                                  my $next_fn=sprintf("%02d.php",$page_nr);
469                                  $last_page=~s/##NEXTPAGE##/$next_fn/;                                  $last_page=~s/##NEXTPAGE##/$next_fn/;
470                                  print PAGE $last_page;                                  print PAGE $last_page;
# Line 771  sub checkboxes { Line 754  sub checkboxes {
754          }          }
755  }  }
756    
757    print "\n\nTo create database for poll $poll use:\n\n";
758    print "\$ psql template1 < $poll/$poll.sql\n\n";
759    print "THIS WILL DISTROY ALL DATA IN EXISTING DATABASE ".$prefix.$poll." !!\n";
760    
761  # read configuration data  # read configuration data
762  #  #
763  # FIX: write actually this :-)  # FIX: write actually this :-)
# Line 782  sub config { Line 769  sub config {
769                  my ($xp, $text) = @_;                  my ($xp, $text) = @_;
770                  $db_user=x($attref->{db_user});                  $db_user=x($attref->{db_user});
771                  $prefix=x($attref->{prefix});                  $prefix=x($attref->{prefix});
772                    $without_invitation=x($attref->{without_invitation});
773          }          }
774  }  }
775    

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.9

  ViewVC Help
Powered by ViewVC 1.1.26