Update of /cvs/scoop/scoop/struct/patch-files/current
In directory sodium.sabren.com:/tmp/cvs-serv9158/struct/patch-files/current

Modified Files:
	README 
Added Files:
	patch-06-UserPrefs3.sql script-06-post.pl 
Log Message:
A few more bugfixes to userprefs stuff. Caching issues, validation tweaks, 
and fixing a bug with pref reset. See the SBM, bugs 118, 119, 120, and 121.

--janra



Index: README
===================================================================
RCS file: /cvs/scoop/scoop/struct/patch-files/current/README,v
retrieving revision 1.96
retrieving revision 1.97
diff -C2 -d -r1.96 -r1.97
*** README	17 Aug 2004 19:03:42 -0000	1.96
--- README	27 Aug 2004 22:32:52 -0000	1.97
***************
*** 35,38 ****
--- 35,43 ----
  	Bugfixes and small feature additions for the above userprefs patch.
  
+ Aug 27 13:30 patch-06-UserPrefs3.sql
+ 	More bugfixes: fixed a caching issue and added the ability to use a box
+ 	for validation instead of a regex, if desired. If you want both, put
+ 	the regex in the box.
+ 
  Any problems, email scoop-help at lists.kuro5hin.org (don't forget to join!)
  join here: http://lists.kuro5hin.org/mailman/listinfo/scoop-help

--- NEW FILE: script-06-post.pl ---
#!/usr/bin/perl

use strict;
use Getopt::Std;
use DBI;

my $args = &get_args();

my $db_user = $args->{u};
my $db_pass = $args->{p};
my $db_port = $args->{o};
my $db_name = $args->{d};
my $db_host = $args->{h};

my $QUIET = $args->{q} || 0;

my $dsn = "DBI:mysql:database=$db_name:host=$db_host:port=$db_port";
my $dbh = DBI->connect($dsn, $db_user, $db_pass);

my ($query, $sth, $rv);
my $default;
$|++;

my $block;
$block = &grab_block($dbh,'edit_prefs');
$block =~ s/Regular expression/Box or regular expression/;
$block =~ s/Perl regexp - but you must escape pipes/either a perl regex (pipes escaped) or BOX,boxname[,args]/;
&update_block($dbh,'edit_prefs',$block);


# utility functions follow from here

sub delete_var {
	my ($dbh, $id) = @_;
	my $query = "DELETE FROM vars WHERE name=" . $dbh->quote($id);
	my $sth = $dbh->prepare($query);
	$sth->execute;
	$sth->finish;
}

sub grab_var {
	my ($dbh, $id) = @_;
	my $query = "SELECT value FROM vars WHERE name = " . $dbh->quote($id);
	my $sth = $dbh->prepare($query);
	$sth->execute;
	my ($contents) = $sth->fetchrow_array;
	$sth->finish;
	return $contents;
}

sub update_var {
	my ($dbh, $id, $contents) = @_;
	my $query = "UPDATE vars SET value = ? WHERE name = ?";
	my $sth = $dbh->prepare($query);
	$sth->execute($contents, $id);
	$sth->finish;
}

sub grab_block {
	my ($dbh, $bid) = @_;
	my $query = "SELECT block FROM blocks WHERE bid = " . $dbh->quote($bid);
	my $sth = $dbh->prepare($query);
	$sth->execute;
	my ($contents) = $sth->fetchrow_array;
	$sth->finish;
	return $contents;
}

sub update_block {
	my ($dbh, $bid, $contents) = @_;
	my $query = "UPDATE blocks SET block = ? WHERE bid = ?";
	my $sth = $dbh->prepare($query);
	$sth->execute($contents, $bid);
	$sth->finish;
}

sub grab_box {
	my ($dbh, $box) = @_;
	my $query = "SELECT content FROM box WHERE boxid = " . $dbh->quote($box);
	my $sth = $dbh->prepare($query);
	$sth->execute;
	my ($contents) = $sth->fetchrow_array;
	$sth->finish;
	return $contents;
}

sub update_box {
	my ($dbh, $box, $contents) = @_;
	my $query = "UPDATE box SET content = ? WHERE boxid = ?";
	my $sth = $dbh->prepare($query);
	$sth->execute($contents, $box);
	$sth->finish;
}

sub mesg {
	print @_ unless $QUIET;
}

sub get_args {
    my %info;
    my @neededargs;

    getopts("u:p:d:h:o:vqD", \%info);

    # now first generate an array of hashrefs that tell us what we
    # still need to get
    foreach my $arg ( qw( u p d h o ) ) {
        next if ( $info{$arg} and $info{$arg} ne '' );

        if( $arg eq 'u' ) {
            push( @neededargs, {arg     => 'u',
                                q       => 'db username? ',
                                default => 'nobody'} );
        } elsif( $arg eq 'p' ) {
            push( @neededargs, {arg     => 'p',
                                q       => 'db password? ',
                                default => 'password'} );
        } elsif( $arg eq 'd' ) {
            push( @neededargs, {arg     => 'd',
                                q       => 'db name? ',
                                default => 'scoop'} );
        } elsif( $arg eq 'h' ) {
            push( @neededargs, {arg     => 'h',
                                q       => 'db hostname? ',
                                default => 'localhost'} );
        } elsif( $arg eq 'o' ) {
            push( @neededargs, {arg     => 'o',
                                q       => 'db port? ',
                                default => '3306'} );
        }
    }

    foreach my $h ( @neededargs ) {
        my $answer = '';

        print "$h->{q}"."[$h->{default}] ";
        chomp( $answer = <STDIN> );

        $answer = $h->{default} unless( $answer && $answer ne '' );

        $info{ $h->{arg} } = $answer;
    }

    return \%info;
}

--- NEW FILE: patch-06-UserPrefs3.sql ---
INSERT INTO box (boxid,title,content,description,template,user_choose) VALUES ('startpage_validation','','if ( $S->{SECTION_DATA}->{$ARGS[1]} || $ARGS[1] eq \'__main__\' || $ARGS[1] eq \'__all__\' ) {\n  return '';\n} else {\n  return "Start Page not valid<BR>";\n}','validates the start page pref','empty_box','0');
UPDATE pref_items set regex='BOX,startpage_validation' WHERE prefname='start_page';