[ic] Multiple selection form and Mainstreet Communications

interchange-users@icdevgroup.org interchange-users@icdevgroup.org
Thu Sep 19 08:37:02 2002


On Thu, Sep 19, 2002 at 12:47:56AM -0400, Philip S. Hempel wrote:
> I was looking throught the mailing list for information
> on forms. I came across Mr. Millers posting about the
> Maine Lobster site and his form he (I think), created.
> 
> I am not sure if it would be corect to directly mail
> Mr. Miller in relations to this or even if he is still
> around in the IC group.
> I know this is a unusual request for some on the list.
> I really liked what he had done and I know that this is
> way to advanced for me to even begin.
> 
> I was wondering if he would be willing to share the code
> that created this form, if not, would anyone know how to get
> something like this created?


I can't share it easily.  Let's just say that our catalogs are
**highly** system dependant and not at all stock.  :-)  We use
next to no [tags] any more, but do almost everything in straight
perl.  I'd love to share that, but it would be a full time job
just making it presentable and documenting it.  Last thing I
need is someone complaining BOTH the code and documentation suck.

But it's not terribly hard to build that form.  All you are doing
is building your javascript on the fly - once again - we do it
all in perl.  The hardest part is getting quoting to work
and keeping your code legible at the same time.

I've appended the module below; it's not self contained, but it
might give you some ideas.  It's a fairly old module, doesn't
even look like we've touched it in 2 years.  We're much more
averse nowadays to mixing content and presentation, yadda yadda.

Note also that this is mv4.03.  That should not be an issue.

YMMV.



> 
> The posting is at
> 
> http://interchange.redhat.com/pipermail/interchange-users/2001-November/014182.html
> 
> The link is at the bottom of the page.
> 

-- 

Christopher F. Miller, Publisher                               cfm@maine.com
MaineStreet Communications, Inc           208 Portland Road, Gray, ME  04039
1.207.657.5078                                         http://www.maine.com/
Content/site management, online commerce, internet integration, Debian linux


#!/usr/bin/perl
# MV::Giftbasket.pm: MaineStreet perl lib
# rev 2000-04-24, cfm
# in /var/src/vend/Makefile/MS
#

package MV::Giftbasket;

use MS::D qw(d);
use MS::Util;
use MV::MS;
use MV::Opts;

use strict 'vars';

#==========================================
# page

sub page {
    my(@A,$CC,%HTML,@OUT,$count,%edit,$opt,@out,$values);
    $opt=$_[0];
    $values=$_[1];

    push @OUT,qq`
[store_referer]

<SCRIPT LANGUAGE='javascript'>
<!--

    function verify() {
	if(document.gift.lobster.selectedIndex > 0) {
	    return true;
	}
	alert("You must select a select a Main Course to go with your giftbasket");
	return false;
    }

//-->
</SCRIPT>
`;

if($values->{Vprocess}=~/delete/) {
    @{$Vend::Session->{carts}{'main'}} = grep { !$_->{mv_mi} } @{$Vend::Session->{carts}{'main'}};
    for(grep /^V.*/, keys %{$Vend::Session->{values}}) {
        delete $Vend::Session->{values}{$_};
    }
    &Vend::Session::put_session();
}

push @OUT,qq`
<SCRIPT LANGUAGE="javascript">
  function startup() {
	window.focus();
	s();
  }
  function w(code) {
      window.open("[area]".split('?')[0]+code+"?"+"[area]".split('?')[1], 'product','width=600,height=450,status=yes,toolbar=yes,resizable=yes,scrollbars=yes');
  }
  function s() {
      total=new Number(0);
      which=new Number(1);
      var i = 0;
      var type,value,code;
      var ary = new Array();
      document.gift.Vinfo.value = '';
      for(i = 0 ; i < document.gift.Vsub.length ; i++ ) {
	  if(document.gift.Vsub[i].selected)
	      which = i+1;
      }
      for(i = 0 ; i < document.gift.elements.length ; i++ ) {
          type = document.gift.elements[i].type;
          if(type == 'select-one') {
	      ary = document.gift.elements[i].options[document.gift.elements[i].selectedIndex].value.split("|");
	      if(ary[0] > 0)
		  document.gift.Vinfo.value += (document.gift.Vinfo.value?'&':'') + 'a=' + ary[0]; 
	      value = parseFloat(ary[which]);
	      if(value) {
		  total += parseFloat(value);
	      }
          }
          if((type == 'checkbox') && document.gift.elements[i].checked) {
	      ary = document.gift.elements[i].value.split("|");
	      document.gift.Vinfo.value += '&a=' + ary[0]; 
              total += parseFloat(ary[which]);
          }

      }
      for(i=0;i<document.gift.total.length;i++) {
	  document.gift.total[i].value = parseInt(total*100)/100;
      }
  }
</SCRIPT>
`;

    for(keys %{$values}) {
	next unless /^V...$/;
	delete $values->{$_};
    }

    {
	my(@out,$query,%v);
	# TODO this needs to not be hardcoded to 50000 sometime soon
	@A=&MV::MS::db_array_query($opt,qq`SELECT product,text FROM products WHERE code='$opt->{item_code}'`);
	for (@A) {
	    ($v{product},$v{text})=@{$_};
	    $HTML{title}=$v{product};
	    push @out,qq`<DIV ALIGN=LEFT>$v{text}</DIV>`;
	}
	$HTML{INS}=join '',@out;
    }

    $values->{LOBSTER_ORDER}=$Vend::Session->{pageCount}+1;

    &Vend::Session::put_session();

    {
	my($query);

	$query=qq`SELECT products.code,products.description,products.product,products.product_sub,aux.base_item,aux.giftbasket,M.category,cc_rel.cc FROM products,aux,cc_rel,cc.master AS M WHERE cc_rel.tbl='products' AND cc_rel.code=products.code AND aux.giftbasket IS NOT NULL AND aux.code=products.code AND products.status>0 AND M.author='$opt->{config}' AND M.cc=cc_rel.cc ORDER BY M.category,products.code`;

	@A=&MV::MS::db_array_query($opt,$query);
    }

    for(grep {$_->{mv_mi}} @{$Vend::Session->{carts}{main}}) {
	$edit{$_->{code}}=1;
    }

    $HTML{SERVINGS}=qq`<SELECT NAME="Vsub" ONCHANGE="s()">\n`;
    $HTML{MAIN_COURSE}=qq`<SELECT NAME="lobster" ONCHANGE="s()"><OPTION VALUE="0|0">Select Main Course\n`;
    $HTML{CONTAINER}=qq`<SELECT NAME="container" ONCHANGE="s()"><OPTION VALUE="0|0">Select Container\n`;
    for (@A) {
	my(%q,%v);
	($v{code},$v{description},$v{product},$v{product_sub},$v{base_item},$v{price},$v{category},$v{cc})=@{$_};
	
	$q{code}=&MS::Util::http_encode($v{code});
	if($v{product}=~/fantasy/i) {
	    $HTML{SERVINGS}.=qq`<OPTION ${\($edit{$v{code}}?' SELECTED':'')} VALUE="$q{code}|$v{price}">$v{product_sub}\n`;
	} elsif($v{product}=~/container/i) {
	    $HTML{CONTAINER}.=qq`<OPTION ${\($edit{$v{code}}?' SELECTED':'')} VALUE="$q{code}|$v{price}">$v{product} $v{product_sub}`;
	} elsif($v{base_item}) {
	    $HTML{MAIN_COURSE}.=qq`<OPTION ${\($edit{$v{code}}?' SELECTED':'')} VALUE="$q{code}|$v{price}">$v{product} $v{product_sub}`;
	} else { 
	    my($CHECKED);
            if($CC!=$v{cc}) {
                $count=0;
                push @out,qq`</TR><TR><TD COLSPAN=$opt->{columns}><TABLE WIDTH="100%"><TR><TD>[page scan/sp=catalog/se=`.
		$v{cc}.
		q`]<?MS_SUBPAGENAME>`.
		$v{category}.
		q`</?MS_SUBPAGENAME></A></TD><TD ALIGN=RIGHT>
TOTAL $&nbsp;<INPUT NAME=total SIZE=6 TYPE=TEXT>
<INPUT TYPE=SUBMIT VALUE="Order Basket">
<INPUT NAME="mv_click" TYPE=SUBMIT VALUE="Delete Basket">
</TD></TR></TABLE></TD></TR><TR>`;
            }
            $CC=$v{cc};
	    unless($count++ % $opt->{columns}) {
		push @out,"</TR><TR>";
	    }
	    $_=qq`<A ONCLICK="w($q{code})" HREF="#$q{code}">$v{product}`;
	    $_.=" - $v{product_sub}" if $v{product_sub};
	    $_.=q`</A>`;

	    $CHECKED=($edit{$v{code}}?' CHECKED':'');
	    push @out,qq`<TD><INPUT OnClick="s()" TYPE=CHECKBOX VALUE="$q{code}|$v{price}"$CHECKED>&nbsp;$_</TD>\n`;
	}
    }
    $HTML{OUT}=join '',@out;
    $HTML{SERVINGS}.=qq`</SELECT>\n`;
    $HTML{MAIN_COURSE}.=qq`</SELECT>\n`;
    $HTML{CONTAINER}.=qq`</SELECT>\n`;
    push @OUT,qq`
<TABLE WIDTH=620><TR>
<TD WIDTH=270 VALIGN=TOP>
<?MS_PAGENAME>$HTML{title}</?MS_PAGENAME>
<?MS_HISTORY>$HTML{history}</?MS_HISTORY>
</TD><TD WIDTH=350 VALIGN=TOP>
[file name='.cache/navbar.cache']
</TD></TR><TR><TD COLSPAN=2>

<FORM NAME=gift ACTION="[process-target]" METHOD=POST ONSUBMIT="return verify();">
<INPUT NAME="mv_orderpage" TYPE=HIDDEN VALUE="basket">
<INPUT NAME="mv_todo" TYPE=HIDDEN VALUE=refresh>
<INPUT NAME="mv_doit" TYPE=HIDDEN VALUE=refresh>
<INPUT NAME="mv_order_profile" TYPE=HIDDEN VALUE=basket>
<INPUT NAME=Vinfo TYPE=HIDDEN VALUE="">
<INPUT NAME="LOBSTER_ORDER" TYPE=HIDDEN VALUE="$values->{LOBSTER_ORDER}">

$HTML{INS}

<TABLE BORDER=1 ALIGN=CENTER CELLSPACING=0 CELLSPADDING=0>
<TR><TD ALIGN=CENTER COLSPAN=2>

$HTML{SERVINGS} 
$HTML{MAIN_COURSE}
$HTML{CONTAINER}

<TR><TD ALIGN=CENTER COLSPAN=2>

<TABLE BORDER=0 CELLSPACING=0>
<TR><TD COLSPAN=6>
</TD></TR><TR>
$HTML{OUT}
</TR>
</TABLE>

</TD></TR><TR><TD ALIGN=CENTER COLSPAN=2>
TOTAL \$&nbsp;<INPUT NAME=total SIZE=6 TYPE=TEXT>
<INPUT TYPE=SUBMIT VALUE="Order Basket">
<INPUT NAME="mv_click" TYPE=SUBMIT VALUE="Delete Basket"></TD></TR>
</TABLE>
</FORM>
</TD></TR></TABLE>

[set Delete Basket]
mv_todo=return
mv_nextpage=giftbasket_flypage
Vprocess=delete
[/set]
`;

return \@OUT;
}


1;

#end