<%@ LANGUAGE = PerlScript %><% use Win32::ADO; use Win32::ASP qw(:strict); use Win32::ASP qw/SetCookie/; use strict; $Response->End(); $Response->{Buffer} = 1; use constant adCmdStoredProc => 0x0004; use constant adInteger => 3; use constant adVarChar => 200; use constant adParamOutput => 0x0002; use constant adParamInput => 0x0001; use constant adOpenForwardOnly => 0; use constant adOpenDynamic => 2; use constant adOpenStatic => 3; use constant adLockOptimistic => 3; my $RecurseLevel = 0; $Response->{Buffer} = 1; ### Read Application Variables ### my $mySQL = $Application->Contents('Connection'); my $COLORProductHeader = $Application->Contents('COLORProductHeader'); my $COLORCategoryHeader = $Application->Contents('COLORCategoryHeader'); my $MyConn = $Server->CreateObject("ADODB.Connection"); $MyConn->Open($mySQL); ### Constants ### use constant COLS => 2; ### Number of category columns ### use constant PAGESIZE => 10; ### Number of items per page ### ### my $action = GetFormValue("action"); my $key = GetFormValue("key"); &PullCat if ($action eq 'grabcat'); &GetItem if ($key > 0); &ShowCats; %> <% sub PullCat { ########################################################## ### Display List of Categories within current Category ### ########################################################## my ($catid, $page) = (GetFormValue('category'), GetFormValue('page')); my ($catPath, $catPage, $catLinks, @subcatList); my $ReturnID = $catid; if (($catid < 1) || ($page < 1)) { &ShowCats; exit; } ### Load Product List Recordset ### my $Rset = $Server->CreateObject("ADODB.Recordset"); $Rset->{'CursorLocation'} = 3; ### Client-side Cursor ### $Rset->Open("SELECT ProductsTable.* FROM Categories INNER JOIN (ProductsTable INNER JOIN ProductCategories ON ProductsTable.ProductID = ProductCategories.ProductID) ON Categories.CategoryID = ProductCategories.CategoryID WHERE Categories.CategoryID = $catid ORDER BY ProductCategories.Position, ProductsTable.ProductName ", $MyConn, 3, 1); $Rset->{'PageSize'} = PAGESIZE; $Rset->{'AbsolutePage'} = $page; my $Rstart = $Rset->{'AbsolutePosition'}; my $Rstop = $Rset->{'AbsolutePosition'} + ($Rset->{'PageSize'} - 1); my $Rtotal = $Rset->{RecordCount}; if ($Rstop > $Rtotal) { $Rstop = $Rtotal; } ### Find originating record to search path ### my $RS = $MyConn->Execute("SELECT * FROM Categories WHERE CategoryID = $catid"); if (!$RS) { $RS->Close; &ShowCats; exit; } my ($mainDescript, $mainPic, $mainCode, $mainLink) = ($RS->Fields("Description")->value, $RS->Fields("PictureFile")->value, $RS->Fields("HTMLCode")->value, $RS->Fields("DescriptionLink")->value ); my ($mainID) = $catid; undef($mainLink) if (length($mainLink) < 1); $mainDescript =~ s/\b(\w)/\U$1/g; $catid = $RS->Fields("ParentCategory")->value; $catPath = " : $mainDescript"; my $infLoop = 0; my $companyName = $mainDescript; while ($catid > 0) { $RS->Close; $RS = $MyConn->Execute("SELECT * FROM Categories WHERE CategoryID = $catid"); if ($RS) { my ($descript, $parent) = ($RS->Fields("Description")->value, $RS->Fields("ParentCategory")->value ); $descript =~ s/\b(\w)/\U$1/g; my $tlink = sprintf("action=grabcat&page=1&category=%d", $Server->URLEncode($catid)); $catPath = sprintf(" : %s%s", $tlink, $descript, $catPath); $companyName = $descript; ### Keeps last description which should be company name if ($catid == $parent) { $catid = 0; } else { $catid = $parent; } } else { $catid = 0; } if ($infLoop++ > 50) { $catid = 0; } ### Break from infinite loops } $RS->Close; $catPath = "All Categories" . $catPath; ### Compile a list of available sub-categories ### $RS = $MyConn->Execute("SELECT * FROM Categories WHERE ParentCategory = $mainID ORDER BY Description"); while(!$RS->EOF) { my ($catid, $descript) = ( $RS->Fields("CategoryID")->value, $RS->Fields("Description")->value ); $descript =~ s/\b(\w)/\U$1/g; if (($catid > 0) && (length($descript) > 0)) { push(@subcatList, sprintf("
  • %s", $catid, $descript)); } $RS->MoveNext; } $RS->Close; if ($mainDescript eq $companyName) { &HTMLHeader(sprintf("%s: All Categories - Page %d", $mainDescript, $page)); } else { &HTMLHeader(sprintf("%s: %s - Page %d", $companyName, $mainDescript, $page)); } %> '; } else { $catPage .= sprintf("\n", ($page - 1), $mainID); } my $totpages = int((($page * PAGESIZE) + ($Rtotal - $Rstop)) / PAGESIZE); $totpages++ if (($Rtotal - $Rstop) > 0); $catPage .= sprintf("", $page, $totpages); if ($Rstop < $Rtotal) { $catPage .= sprintf("\n", ($page + 1), $mainID); } else { $catPage .= ''; } ### Construct Quick Page line ### if (($Rtotal / PAGESIZE) > 3) { $catLinks = ''; for (my $ii = 1; $ii <= (int($Rtotal / PAGESIZE)+1); $ii++) { if ($ii == $page) { $catLinks .= "$ii "; next; } $catLinks .= sprintf("%d ", $ii, $mainID, $ii); } $catLinks = '- ' . $catLinks . ' -'; } ### List products on page X ### if (($Rstart < 0) && ($Rstop < 1)) { if ($#subcatList < 0) { print "
    No products listed.
    Come back soon.
    \n"; } } else { #Get X number of products for this page# for (my $ii = $Rstart; $ii <= $Rstop; $ii++) { my ($ProductID, $ProductCode, $ProductName, $PictureFile, $UnitPrice, $MSRP, $Orientation, $Notes) = ( $Rset->Fields('ProductID')->value, $Rset->Fields('ProductCode')->value, $Rset->Fields('ProductName')->value, $Rset->Fields('PictureFile')->value, $Rset->Fields('UnitPrice')->value, $Rset->Fields('MSRP')->value, $Rset->Fields('Orientation')->value, $Rset->Fields('Notes')->value ); $Orientation =~ s/ +$//g; if (length($Orientation) < 1) { $Orientation = 'T'; $Orientation =~ s/ +$//g; } #Select Additional Pics# my $AddLink; my $AddRS = $MyConn->Execute("SELECT * FROM AdditionalPics WHERE ProductID = $ProductID"); if (!$AddRS->EOF) { $AddLink = "images.asp?ProductID=$ProductID&page=$page&Category=$ReturnID"; } else { undef($AddLink); } $AddRS->Close(); print "\n"; ##Determine Orientation## if ($Orientation eq 'T') { #Orientation is TOP# %>
    <% print "
    \n"; ## if (length($mainPic) > 1) { print "\n"; print "\n"; print "\n"; print "
    \n"; print "\n"; print "
    $mainDescript
    \n"; print "
    \n
    \n"; } else { print "$mainDescript\n"; print "
    \n
    \n"; } %>
    <% if (length($mainCode) > 1) { ### A long description was provided, print it ### print "
    \n"; print "
    \n
    \n"; } print "$catPath\n"; print "

    \n"; ### List sub-categories if they exist ### if ($#subcatList >= 0) { print "

    \n"; print "\n"; print "\n"; print "\n"; print "
    \n"; print "
      \n"; for (my $ii = 0; $ii <= (int($#subcatList / 2)); $ii++) { print $subcatList[$ii] . "\n"; } print "
    \n"; print "
      \n"; for (my $ii = (int($#subcatList / 2)+1); $ii <= $#subcatList; $ii++) { print $subcatList[$ii] . "\n"; } print "
    \n"; print "

    \n"; } ### Construct page selection line ### $catPage = ''; if ($page < 2) { $catPage .= '

      << PREVIOUSPage %d of %dNEXT >>  
    <% #Write out Picture if it exists# #Determine if Additional pics exist# $Response->Write(" ") if ($AddLink); if (length($PictureFile) > 1) { $Response->Write("\n"); } else { $Response->Write("Click here for Picture(s)\n") if ($AddLink); } $Response->Write("\n") if ($AddLink); %>
    <% print "$ProductName
    \n"; print "\U$ProductCode
    \n"; $Response->Write(sprintf("Our Price: \$%1.2f", $UnitPrice)); if ($MSRP > 0.01) { $Response->Write(sprintf("\n
    Sugg. Retail Price: \$%1.2f

    ", $MSRP)); } else { $Response->Write("

    \n"); } # Print out a description if available # if (length($Notes) > 1) { $Response->Write("
    $Notes\n
    "); } %>

    <% } #End TOP Orientation# if ($Orientation eq 'L') { #Orientation is Left# %>
    <% #Write out Picture if it exists# #Determine if Additional pics exist# $Response->Write(" ") if ($AddLink); if (length($PictureFile) > 1) { $Response->Write("\n"); } else { $Response->Write("Click here for Picture(s)\n") if ($AddLink); } $Response->Write("\n") if ($AddLink); %> <% print "$ProductName
    \n"; print "\U$ProductCode
    \n"; $Response->Write(sprintf("Our Price: \$%1.2f", $UnitPrice)); if ($MSRP > 0.01) { $Response->Write(sprintf("\n
    Sugg. Retail Price: \$%1.2f

    ", $MSRP)); } else { $Response->Write("

    \n"); } # Print out a description if available # if (length($Notes) > 1) { $Response->Write("
    $Notes\n
    "); } %>

    <% } #End LEFT Orientation# if ($Orientation eq 'R') { #Orientation is Right# %>
    <% print "$ProductName
    \n"; print "\U$ProductCode
    \n"; $Response->Write(sprintf("Our Price: \$%1.2f", $UnitPrice)); if ($MSRP > 0.01) { $Response->Write(sprintf("\n
    Sugg. Retail Price: \$%1.2f

    ", $MSRP)); } else { $Response->Write("

    \n"); } # Print out a description if available # if (length($Notes) > 1) { $Response->Write("
    $Notes\n
    "); } %>

    <% #Write out Picture if it exists# #Determine if Additional pics exist# $Response->Write(" ") if ($AddLink); if (length($PictureFile) > 1) { $Response->Write("\n"); } else { $Response->Write("Click here for Picture(s)\n") if ($AddLink); } $Response->Write("\n") if ($AddLink); %>
    <% } #End RIGHT Orientation# ### Check for Drop Downs ### my $rsDrops = $MyConn->Execute("SELECT * FROM DropDowns WHERE ProductID = $ProductID ORDER BY DropPriority"); if (!$rsDrops->EOF) { my $dNum = 1; print "
    \n"; while (!$rsDrops->EOF) { my ($DropID,$Descript,$SD) = ($rsDrops->Fields('DropID')->value, $rsDrops->Fields('Description')->value, $rsDrops->Fields('SelectionRequired')->value); print "\n"; $dNum++; $rsDrops->MoveNext; } print "

    "; print ""; } elsif ($rsDrops->EOF) { print "\n"; } print "


    \n"; $Rset->MoveNext; } } $Rset->Close; %>

    <%= $catPage %> <%= ($catLinks) ? "\n\n" : '' %>
    $catLinks

    <% &HTMLFooter; $MyConn->Close; $Response->End; exit; } %> <% sub ShowCats { ###################################### ### Display List of Top Categories ### ###################################### my $ii = 0; my $RS = $MyConn->Execute("SELECT DISTINCT Categories.CategoryID, Categories.Description FROM Categories WHERE Categories.ParentCategory < 1 AND Len(Description) > 1 ORDER BY Categories.Description"); if(!$RS) { my $Errors = $MyConn->Errors(); print "Errors:\n"; foreach my $error (keys %$Errors) { $Response->write($error->{Description}."\n"); } die; } &HTMLHeader(); %>


    Product Categories

    <% while(!$RS->EOF) { my($catid,$descript) = ( $RS->Fields('CategoryID')->value, $RS->Fields('Description')->value ); $descript =~ s/\b(\w)/\U$1/g; if (!($ii % COLS)) { $Response->write("\n"); } my $tlink = sprintf("action=grabcat&page=1&category=%d", $Server->URLEncode($catid)); $Response->write(sprintf(" \n", $tlink, $descript)); $ii++; if (!($ii % COLS)) { $Response->write(""); } $RS->MoveNext; } if (($ii % COLS)) { $Response->write("\n "); } $RS->Close; %>
    %s






    <% &HTMLFooter; $MyConn->Close; $Response->End; exit; } sub HTMLHeader { # Does header file exist my $HeaderFile = $Application->Contents('HTMLHeader'); my $FullPath = $Application->Contents('FullPath'); my $HeaderPath = "$FullPath\\$HeaderFile"; my $FSYS = $Server->CreateObject("Scripting.FileSystemObject"); if ($FSYS->FileExists($HeaderPath)) { my $HTMLFile = $FSYS->OpenTextFile($HeaderPath); my $AllFile = $HTMLFile->ReadAll(); $Response->Write("$AllFile\n"); $FSYS->Close(); } else { my $subtitle = shift; my $title = $Application->{'SiteTitle'}; if (length($subtitle) > 0) { $title .= ": $subtitle"; } %> <%= $title %> <% } ## } sub HTMLFooter { # Does Footer file exist my $FooterFile = $Application->Contents('HTMLFooter'); my $FullPath = $Application->Contents('FullPath'); my $FooterPath = "$FullPath\\$FooterFile"; my $FSYS = $Server->CreateObject("Scripting.FileSystemObject"); if ($FSYS->FileExists($FooterPath)) { my $HTMLFile = $FSYS->OpenTextFile($FooterPath); my $AllFile = $HTMLFile->ReadAll(); $Response->Write("$AllFile\n"); $FSYS->Close(); } else { %> <% } %>

    HOME

    E-Mail: <%=$Application->Contents('Email')%>

    <%=$Application->Contents('Copyright')%>
    Produced by 1st Internet Resources

    <% } %> <% sub GetItem { &HTMLHeader; %>
    <% my $Rset = $Server->CreateObject("ADODB.Recordset"); $Rset->{'CursorLocation'} = 3; ### Client-side Cursor ### $Rset->Open("SELECT ProductsTable.* FROM ProductsTable WHERE ProductsTable.ProductID = $key ORDER BY ProductsTable.WebOrdering, ProductsTable.ProductName, ProductsTable.ProductCode", $MyConn, 3, 1); my ($ProductID, $ProductCode, $ProductName, $PictureFile, $UnitPrice, $MSRP, $Orientation, $Notes) = ( $Rset->Fields('ProductID')->value, $Rset->Fields('ProductCode')->value, $Rset->Fields('ProductName')->value, $Rset->Fields('PictureFile')->value, $Rset->Fields('UnitPrice')->value, $Rset->Fields('MSRP')->value, $Rset->Fields('Orientation')->value, $Rset->Fields('Notes')->value ); $Orientation =~ s/ +$//g; if (length($Orientation) < 1) { $Orientation = 'T'; $Orientation =~ s/ +$//g; } #Select Additional Pics# my $AddLink; my $AddRS = $MyConn->Execute("SELECT * FROM AdditionalPics WHERE ProductID = $ProductID"); if (!$AddRS->EOF) { $AddLink = "images.asp?ProductID=$ProductID"; } else { undef($AddLink); } $AddRS->Close(); print "\n"; ##Determine Orientation## if ($Orientation eq 'T') { #Orientation is TOP# %>
    <% #Write out Picture if it exists# #Determine if Additional pics exist# $Response->Write(" ") if ($AddLink); if (length($PictureFile) > 1) { $Response->Write("\n"); } else { $Response->Write("Click here for Picture(s)\n") if ($AddLink); } $Response->Write("\n") if ($AddLink); %>
    <% print "$ProductName
    \n"; print "\U$ProductCode
    \n"; $Response->Write(sprintf("Our Price: \$%1.2f", $UnitPrice)); if ($MSRP > 0.01) { $Response->Write(sprintf("\n
    Sugg. Retail Price: \$%1.2f

    ", $MSRP)); } else { $Response->Write("

    \n"); } # Print out a description if available # if (length($Notes) > 1) { $Response->Write("
    $Notes\n
    "); } %>

    <% } #End TOP Orientation# if ($Orientation eq 'L') { #Orientation is Left# %>
    <% #Write out Picture if it exists# #Determine if Additional pics exist# $Response->Write(" ") if ($AddLink); if (length($PictureFile) > 1) { $Response->Write("\n"); } else { $Response->Write("Click here for Picture(s)\n") if ($AddLink); } $Response->Write("\n") if ($AddLink); %> <% print "$ProductName
    \n"; print "\U$ProductCode
    \n"; $Response->Write(sprintf("Our Price: \$%1.2f", $UnitPrice)); if ($MSRP > 0.01) { $Response->Write(sprintf("\n
    Sugg. Retail Price: \$%1.2f

    ", $MSRP)); } else { $Response->Write("

    \n"); } # Print out a description if available # if (length($Notes) > 1) { $Response->Write("
    $Notes\n
    "); } %>

    <% } #End LEFT Orientation# if ($Orientation eq 'R') { #Orientation is Right# %>
    <% print "$ProductName
    \n"; print "\U$ProductCode
    \n"; $Response->Write(sprintf("Our Price: \$%1.2f", $UnitPrice)); if ($MSRP > 0.01) { $Response->Write(sprintf("\n
    Sugg. Retail Price: \$%1.2f

    ", $MSRP)); } else { $Response->Write("

    \n"); } # Print out a description if available # if (length($Notes) > 1) { $Response->Write("
    $Notes\n
    "); } %>

    <% #Write out Picture if it exists# #Determine if Additional pics exist# $Response->Write(" ") if ($AddLink); if (length($PictureFile) > 1) { $Response->Write("\n"); } else { $Response->Write("Click here for Picture(s)\n") if ($AddLink); } $Response->Write("\n") if ($AddLink); %>
    <% } #End RIGHT Orientation# ### Check for Drop Downs ### my $rsDrops = $MyConn->Execute("SELECT * FROM DropDowns WHERE ProductID = $ProductID ORDER BY DropPriority"); if (!$rsDrops->EOF) { my $dNum = 1; print "
    \n"; while (!$rsDrops->EOF) { my ($DropID,$Descript,$SD) = ($rsDrops->Fields('DropID')->value, $rsDrops->Fields('Description')->value, $rsDrops->Fields('SelectionRequired')->value); print "\n"; $dNum++; $rsDrops->MoveNext; } print "

    "; print ""; } elsif ($rsDrops->EOF) { print "\n"; } print "


    \n"; $Rset->Close; %>

    <% &HTMLFooter; $Response->End; exit; } %>