0.14_07 commit r0_14_07
authorTony Cook <tony@develop-help.com>
Fri, 12 Sep 2003 06:24:33 +0000 (06:24 +0000)
committertony <tony@45cb6cf1-00bc-42d2-bb5a-07f51df49f94>
Fri, 12 Sep 2003 06:24:33 +0000 (06:24 +0000)
20 files changed:
Makefile
schema/bse.sql
site/cgi-bin/bse.cfg
site/cgi-bin/modules/BSE/AdminSiteUsers.pm
site/cgi-bin/modules/BSE/DB/Mysql.pm
site/cgi-bin/modules/BSE/Permissions.pm
site/cgi-bin/modules/BSE/Shop/Util.pm
site/cgi-bin/modules/BSE/UserReg.pm
site/cgi-bin/modules/DevHelp/Formatter.pm
site/cgi-bin/modules/DevHelp/Tags/Iterate.pm
site/cgi-bin/modules/SiteUser.pm
site/cgi-bin/shop.pl
site/docs/bse.pod
site/docs/config.pod
site/templates/admin/users/add.tmpl
site/templates/admin/users/edit.tmpl
site/templates/checkout_base.tmpl
site/templates/checkoutfinal_base.tmpl
t/t050format.t
test.cfg

index dc738b058a4428bc72c2b5d18e01eb730d03e39b..3b42b53ae7a22324c4ecf20df01be11ab009bfdd 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION=0.14_06
+VERSION=0.14_07
 DISTNAME=bse-$(VERSION)
 DISTBUILD=$(DISTNAME)
 DISTTAR=../$(DISTNAME).tar
index 6cca06a9892fbe30938608d160fb4165a53ee19c..047e3bf10415e7175c22f93f11084678ebfc4e08 100644 (file)
@@ -465,6 +465,8 @@ create table site_users (
 
   disabled integer not null default 0,
 
+  flags varchar(80) not null default '',
+
   primary key (id),
   unique (userId)
 );
index 0c5ab8a485cad6f13d1a01f9700eac5e330e1143..774171f43c7a366aae06c8b2f63abf9e83c14b27 100644 (file)
@@ -99,6 +99,10 @@ address1=First address line in configuration
 address2=Second address line in configuration
 address3=Third address line in configuration
 enabled=1
+display_billAddress=Billing Address
+display_name1=First Name
+display_name2=Last Name
+display_address=Address
 
 [level 1]
 template=common/default.tmpl
index 5c0aef1b61e686a5d5ff748c05f62e61378a3385..151df57e5382da5bc70f853d83e4658274e1bb12 100644 (file)
@@ -17,7 +17,7 @@ my %actions =
    add=>1,
   );
 
-my @donttouch = qw(id userId password email confirmed confirmSecret waitingForConfirmation);
+my @donttouch = qw(id userId password email confirmed confirmSecret waitingForConfirmation flags); # flags is saved separately
 my %donttouch = map { $_, $_ } @donttouch;
 
 sub dispatch {
@@ -39,6 +39,17 @@ sub dispatch {
   $class->$method($req);
 }
 
+sub flags {
+  my ($cfg) = @_;
+
+  my %flags = $cfg->entriesCS('site user flags');
+
+  my @valid = grep /^\w+$/, keys %flags;
+
+  return map +{ id => $_, desc => $flags{$_} },
+    sort { lc($flags{$a}) cmp lc($flags{$b}) } @valid;
+}
+
 sub req_list {
   my ($class, $req, $msg) = @_;
   
@@ -83,6 +94,21 @@ sub tag_if_required {
   return $cfg->entryBool('site users', "require_$args", 0);
 }
 
+sub iter_flags {
+  my ($cfg) = @_;
+
+  flags($cfg);
+}
+
+sub tag_if_flag_set {
+  my ($flags, $arg, $acts, $funcname, $templater) = @_;
+
+  my @args = DevHelp::Tags->get_parms($arg, $acts, $templater);
+  @args or return;
+
+  return index($flags, $args[0]) >= 0;
+}
+
 sub req_edit {
   my ($class, $req, $msg, $errors) = @_;
 
@@ -93,6 +119,8 @@ sub req_edit {
   my $siteuser = SiteUsers->getByPkey($id)
     or return $class->req_list($req, "No such site user found");
 
+  my $it = BSE::Util::Iterate->new;
+
   $errors ||= {};
   if ($msg) {
     $msg = escape_html($msg);
@@ -122,6 +150,8 @@ sub req_edit {
      siteuser => [ \&tag_hash, $siteuser ],
      error_img => [ \&tag_error_img, $req->cfg, $errors ],
      ifRequired => [ \&tag_if_required, $req->cfg ],
+     $it->make_iterator([ \&iter_flags, $req->cfg], 'flag', 'flags'),
+     ifFlagSet => [ \&tag_if_flag_set, $siteuser->{flags} ],
     );  
 
   my $template = 'admin/users/edit';
@@ -242,6 +272,11 @@ sub req_save {
     }
   }
 
+  my @flags = flags($cfg);
+  my %flags = map { $_->{id} => 1 } @flags;
+  $user->{flags} = join('', grep exists $flags{$_}, $cgi->param('flags'))
+    if $cgi->param('saveFlags');
+
   $user->{textOnlyMail} = 0 
     if $cgi->param('saveTextOnlyMail') && !defined $cgi->param('textOnlyMail');
   $user->{keepAddress} = 0 
@@ -445,6 +480,9 @@ sub req_add {
     use BSE::Util::Secure qw/make_secret/;
     $user{password} = make_secret($cfg);
   }
+  my @flags = flags($cfg);
+  my %flags = map { $_->{id} => 1 } @flags;
+  $user{flags} = join('', grep exists $flags{$_}, $cgi->param('flags'));
 
   my $user;
   eval {
index 5f6d435cb1edc409d7beb179bb1e25c4b0a691ff..45173ad8bfd94083baf63b217ff88123e8635b46 100644 (file)
@@ -113,8 +113,8 @@ SQL
    'select * from site_users where userId = ?',
    getSiteUserByPkey =>
    'select * from site_users where id = ?',
-   addSiteUser => 'insert site_users values(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
-   replaceSiteUser => 'replace site_users values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
+   addSiteUser => 'insert site_users values(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
+   replaceSiteUser => 'replace site_users values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
    'SiteUsers.removeSubscriptions'=>
    'delete from subscribed_users where userId = ?',
    'SiteUsers.removeSub'=>
index 1d1a4a213067695cec56d9386f2bd202f0d05a3b..07d73ce946ba3e909e7590e0135ce9fdebb76553 100644 (file)
@@ -89,9 +89,11 @@ sub check_logon {
 
   return 1 if $req->user;
 
+  my $server_auth_admin = $cfg->entry('basic', 'server_auth', 0);
+
   my $user;
   require BSE::TB::AdminUsers;
-  if ($ENV{REMOTE_USER}) {
+  if ($server_auth_admin && $ENV{REMOTE_USER}) {
     ($user) = BSE::TB::AdminUsers->getBy(logon => $ENV{REMOTE_USER});
   }
   if ($req->session->{adminuserid}) {
index 49ab8321710814d66616ac193c96dd7e1d0c1282..87a3a313be091e4861e2d4b5a63d46367eac6dfe 100644 (file)
@@ -338,7 +338,7 @@ sub payment_types {
           id => 0, 
           name => 'CC', 
           desc => 'Credit Card',
-          require => [ qw/cardNumber cardExpiry/ ],
+          require => [ qw/cardNumber cardExpiry cardHolder cardType/ ],
          },
      1 => { 
           id => 1, 
index 02149c4568f2d4f66457c7f416090c698116c92c..39b013984c9b793c3522c2814e445e5790ea6bdb 100644 (file)
@@ -16,7 +16,7 @@ use Util;
 use constant MAX_UNACKED_CONF_MSGS => 3;
 use constant MIN_UNACKED_CONF_GAP => 2 * 24 * 60 * 60;
 
-my @donttouch = qw(id userId password email confirmed confirmSecret waitingForConfirmation disabled);
+my @donttouch = qw(id userId password email confirmed confirmSecret waitingForConfirmation disabled flags);
 my %donttouch = map { $_, $_ } @donttouch;
 
 sub user_tags {
index ac142a4ab77ea06eaa859a29cd82c916683765ae..d181db9bf091a41dd0f40599a6b53ad2b34c02f0 100644 (file)
@@ -197,6 +197,8 @@ sub format {
          and next TRY;
        $part =~ s#image\[([^\]\[]+)\]# $self->image($1) #ige
            and next TRY;
+       $part =~ s#class\[([^\]\[\|]+)\|([^\]\[]+)\]#<span class="$1">$2</span>#ig
+          and next TRY;
        last;
       }
       $part =~ s!(\n([ \r]*\n)*)!$1 eq "\n" ? "<br />\n" : "</p>\n<p>"!eg;
index 821f6c4f2a679885042afa1b45eac646558817e5..c708a5250620fd0c85d74f4bf3d9bcbbe9eab0c1 100644 (file)
@@ -190,6 +190,23 @@ sub _iter_number {
   1+$$rindex;
 }
 
+sub _iter_count {
+  my ($self, $rdata, $code, $loaded, $nocache, 
+      $args, $acts, $name, $templater) = @_;
+
+  if (!$$loaded && !@$rdata && $code || $args || $nocache) {
+    my ($sub, @args) = $code;
+
+    if (ref $code eq 'ARRAY') {
+      ($sub, @args) = @$code;
+    }
+    @$rdata = $sub->(@args, $args, $acts, $name, $templater);
+    ++$$loaded unless $args;
+  }
+
+  scalar(@$rdata);
+}
+
 sub make_iterator {
   my ($self, $code, $single, $plural, $rdata, $rindex, $nocache) = @_;
 
index 22d2c8bf29a561a7c3ff1ff33beb4f62f1f3f59f..6f3ab78b000bc3e861839181afd7dad00c8a467c 100644 (file)
@@ -18,7 +18,7 @@ sub columns {
             prompt otherPrompt profession otherProfession previousLogon
             billFirstName billLastName billStreet billSuburb billState 
             billPostCode billCountry instructions billTelephone billFacsimile 
-            billEmail adminNotes disabled/;
+            billEmail adminNotes disabled flags/;
 }
 
 sub removeSubscriptions {
index 168f4688fd908bb09d22c229b550fd8152a0d7a9..1d8cf44382af8cc45a6574a18fa2b21c77e029d7 100755 (executable)
@@ -638,8 +638,9 @@ sub purchase {
   push @required, @{$pay_types{$paymentType}{require}};
 
   for my $field (@required) {
+    my $display = $cfg->entry('shop', "display_$field", $field);
     defined(param($field)) && length(param($field))
-      or return checkout("Field $field is required", 1);
+      or return checkout("Field $display is required", 1);
   }
   defined(param('email')) && param('email') =~ /.\@./
     or return checkout("Please enter a valid email address", 1);
index 9244802d8c98f323c0ff1ab1790093f5d5c44081..d41fca2c383d8718106c04984aafd6e2a4233480 100644 (file)
@@ -10,6 +10,57 @@ Maybe I'll add some other bits here.
 
 =head1 CHANGES
 
+=head2 0.14_07
+
+You will need to run upgrade_mysql.pl for this release.
+
+=over
+
+=item *
+
+checkoutfinal_base.tmpl now uses the new <:if Payment I<name>:> tags,
+and includes a payments customization shim.
+
+=item *
+
+shop.pl now uses [shop].display_I<field-name> to convert stored field
+names into display names for error messages.
+
+=item *
+
+cardType and cardHolder fields are now required fields for credit card
+payments
+
+=item *
+
+admin access control now requires that a configuration option to be
+set before it will accept admin user authentication information from
+the server (typically basic authentication.)
+
+=item *
+
+the class[I<classname>|I<text>] tag was lost when integrating the
+common tag handling code, added it back in (#284)
+
+=item *
+
+you can now define custom flags for site users, the flag value is a
+single letter or digit, case-sensitive.  Add an entry like:
+
+   I<letter-or-digit>=I<description>
+
+to the [site user flags] section of the config file.  For example:
+
+   a=Access to private area of the site
+   b=Accept orders on account
+
+You can check this on templates where the user is visible with the
+<:if Match:> tag:
+
+  <:ifMatch [siteuser flags] "b":>Accept orders on account<:or:><:eif:>
+
+=back
+
 =head2 0.14_06
 
 =over
index 3cf7461a857c056ba6e76284adb99b2c08d892b7..74db5f78a17a4b74e0d90a2cea57ecb0710bcdc4 100644 (file)
@@ -174,6 +174,12 @@ without modifying the name of the HTML file.  Default: False.
 If this is true then the user/group/permissions database is used to
 control access to the system.  Default: False.
 
+=item server_auth
+
+Set this to non-zero to enable authentication via server
+authentication (usually Basic Authentication.)  You should normally
+set this if you set htusers below.  Default: 0 (disabled)
+
 =item htusers
 
 This should be the path to a file to be updated with the list of users
@@ -503,6 +509,11 @@ unencrypted.
 If true, then the order is email to to_email, possibly with credit
 card information included.  Default: $SHOP_EMAIL_ORDER.
 
+=item display_I<field>
+
+Used to translate the stored order field name into a presentation name
+suitable for error messages.
+
 =back
 
 =head2 [fields]
index 57dfff7d385bcc1f7d5f874f2fd36091d43c5c3b..561c4d16d06fb44ee4712d1403723424cf006973 100644 (file)
             </td>
             <td bgcolor="#FFFFFF" valign="top"><:help editsiteuser adminNotes:>  <:error_img adminNotes:></td>
           </tr>
+<:if Flags:>
+          <tr> 
+            <th bgcolor="#FFFFFF" align="left" valign="top">Flags: </th>
+            <td bgcolor="#FFFFFF"> 
+           <:iterator begin flags:>
+           <input type="checkbox" name="flags" value="<:flag id:>" /> <:flag desc:>
+           <:iterator separator flags:>
+           <br />
+           <:iterator end flags:>
+            </td>
+            <td bgcolor="#FFFFFF" valign="top"><:help editsiteuser flags:>  <:error_img adminNotes:></td>
+          </tr>
+<:or Flags:><:eif Flags:>
           <tr> 
             <td bgcolor="#FFFFFF" colspan="3" align="right"> 
               <input type="submit" name="a_add" value="  Add User  " />
index da0f27efd63a6e6b1c940f31f6dfb4db928fbb3b..06c519322388351ef6c4fb11a7bc74a37882427d 100644 (file)
             </td>
             <td bgcolor="#FFFFFF" valign="top"><:help editsiteuser adminNotes:>  <:error_img adminNotes:></td>
           </tr>
+<:if Flags:>
+          <tr> 
+            <th bgcolor="#FFFFFF" align="left" valign="top">Flags: </th>
+            <td bgcolor="#FFFFFF"> <input type="hidden" name="saveFlags" value="1" />
+           <:iterator begin flags:>
+           <input type="checkbox" name="flags" value="<:flag id:>" <:ifFlagSet [flag id]:>checked="checked" <:or:><:eif:>/> <:flag desc:>
+           <:iterator separator flags:>
+           <br />
+           <:iterator end flags:>
+            </td>
+            <td bgcolor="#FFFFFF" valign="top"><:help editsiteuser flags:>  <:error_img adminNotes:></td>
+          </tr>
+<:or Flags:><:eif Flags:>
 <:if UserCan siteuser_changepw:>
 <:if Cfg "site users" nopassword:><:or Cfg:>
           <tr> 
index e2a23eabeed0429a6f562319a8a9614681804b52..07fbbedbfbf29bd174051f1375caf8ed32798f8d 100644 (file)
@@ -269,6 +269,24 @@ function BSE_validateForm {
         <input type="Text" name="billCountry" size=20 value="<:old billCountry:>">
         *</font></td>
     </tr>
+    <tr> 
+      <td> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> Email:</font></td>
+      <td> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
+        <input type="Text" name="billEmail" size=20 value="<:old billEmail:>">
+        *</font></td>
+    </tr>
+    <tr> 
+      <td> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> Telephone:</font></td>
+      <td> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
+        <input type="Text" name="billTelephone" size=20 value="<:old billTelephone:>">
+        *</font></td>
+    </tr>
+    <tr> 
+      <td> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> Facsimile:</font></td>
+      <td> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
+        <input type="Text" name="billFacsimile" size=20 value="<:old billFacsimile:>">
+        *</font></td>
+    </tr>
   </table>
   <p>&nbsp; </p>
  <:or Cgi:>
index 81a7042879010eba70716bc82452281cf16f2207..6fec7741a58ecfd2f82b05367829fed2b198db2e 100644 (file)
 <p> The <:siteName:> store is run on a secure encrypted server, your details are 
   safe with us.<br>
 </p>
-<:if CCPayment:><:or CCPayment:><:eif CCPayment:>
-<:if ChequePayment:>
+<:if Payment CC:><:or Payment:><:eif Payment:>
+<:if Payment Cheque:>
 <p>Please send your cheque to:</p>
 <ul><:cfg shop address1 |h:><br>
 <:cfg shop address2 |h:><br>
 <:cfg shop address3 |h:></ul>
-<:or ChequePayment:><:eif ChequePayment:>
-<:if CallMePayment:>
+<:or Payment:><:eif Payment:>
+<:if Payment CallMe:>
 <p>We will call you to arrange payment.</p>
-<:or CallMePayment:><:eif CallMePayment:>
-
+<:or Payment:><:eif Payment:>
+<:include custom/checkout_final_payments.include optional:>
 </font> 
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
   <tr> 
index a8bee6bd8c7c05a31ce38f7c2a4be7056cfd6923..497477b5782c38c422a7292dcfd1d07acae18e53 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -w
 use strict;
-use Test::More tests => 36;
+use Test::More tests => 37;
 
 sub format_test($$$;$);
 
@@ -137,6 +137,8 @@ OUT
 <table width="80" height="10" border="0" bgcolor="#FF0000" cellpadding="0" cellspacing="0"><tr><td><img src="/images/trans_pixel.gif" width="1" height="1" alt="" /></td></tr></table>
 OUT
   format_test 'image[foo]', '', 'image';
+
+  format_test 'class[xxx|yyy]', '<span class="xxx">yyy</span>', 'class';
 }
 
 sub format_test ($$$;$) {
index b8810005da2f3c27d3350c7c1a4d35ad66e6fe77..88505f38b4cec9283bb1df50d67f239077bfe82c 100644 (file)
--- a/test.cfg
+++ b/test.cfg
@@ -60,3 +60,6 @@ payment type required.11=facsimile
 
 dealer.bsb=999999
 dealer.accountno=77777777
+shop.display_facsimile=Fax Number
+site user flags.a=Access to private pages
+tandb custom.siteuser_include_flag=a