#!/usr/bin/perl # ---------------------------------------------------------------------- # view.mp: The page that allows us to view a particular category of # classified ads. We pass parameters in the path-info string. First # is the category, then the status, and then the state, if applicable. # # We could also do a search if we've got a doSearch action passed in. # # $RCSfile: view,v $ # $Id: view,v 1.6 2007/09/14 01:33:02 ravyn Exp $ # # copyright 2007 and beyond, DeadBunny Enterprises, Inc. # all rights reserved. # ---------------------------------------------------------------------- use strict; no strict 'refs'; use String::Strip; do "../../perl-bin/dbugsite.rc"; do "../../perl-bin/initialize.rc"; do "../../perl-bin/functions/classified-crud.pl"; do "../../perl-bin/functions/classified-functions.pl"; my ($query, $dbh, $dbInfo, $dConfig, %dH) = nonmember_init(); my @classifiedList; if (! defined $dH{'iIsCommercial'}) { $dH{'iIsCommercial'} = -1; } $dH{'fMinPrice'} += 0; $dH{'iWhichOrder'} = ($dH{'iWhichOrder'}+0) % 2; $dH{'iResultsPerPage'} += 0; $dH{'iResultsPerPage'} = 10 if (($dH{'iResultsPerPage'} < 10) || ($dH{'iResultsPerPage'} > 100)); if ($dH{'szAction'} eq 'doSearchByAdNumber') { my $theAd = retrieveClassified($dbh, $dH{'iClassifiedID'}+0); if ($theAd->{iClassifiedID} > 0) { if (($theAd->{iIsActive} == 1) || ($dH{'iMyUserIsAdmin'} == 1)) { print $query->redirect("/classifieds/viewAd/$theAd->{iClassifiedID}"); $dbh->commit; exit; } } } elsif ($dH{'szAction'} eq 'doSearch') { $dH{'iStart'} += 0; $dH{'iIsCommercial'} += 0; StripLTSpace($dH{'szSearchUsername'}); if ($dH{'szSearchUsername'} ne '') { $dH{'iUserID'} = $dbh->selectrow_array("SELECT iUserID FROM tblUser WHERE szUsername='$dH{'szSearchUsername'}' AND iAccessLevel > 0"); $dH{'iUserID'} = -1 if (! ($dH{'iUserID'} > 0)); } my @keywords = $query->param('szKeyword'); $dH{'szKeyword'} = join(' ', @keywords); @classifiedList = findClassifieds($dbh, 600, ! $dH{'iUserIsAdmin'}, $dH{'iCategoryID'}, $dH{'iForSaleWanted'}, $dH{'szStateCode'}, $dH{'fMinPrice'}, $dH{'fMaxPrice'}, $dH{'szManufacturer'}, $dH{'iIsCommercial'}, $dH{'szKeyword'}, $dH{'iUserID'}, $dH{'iWhichOrder'}); } else { if (substr($ENV{'PATH_INFO'}, 0, 1) eq '/') { substr($ENV{'PATH_INFO'}, 0, 1) = ''; } ($dH{'iCategoryID'}, $dH{'iForSaleWanted'}, $dH{'iStart'}, $dH{'szExtra'}) = split (/\//, $ENV{'PATH_INFO'}); %dH = site::fromString ($dH{'szExtra'}, {%dH}, 'szStateCode', 'fMinPrice', 'fMaxPrice', 'szManufacturer', 'iIsCommercial', 'iUserID', 'szKeyword', 'iResultsPerPage', 'iWhichOrder'); $dH{'iCategoryID'} =~ s/\D//gi; $dH{'iCategoryID'} += 0; if ($dH{'iForSaleWanted'} eq 'ForSale') { $dH{'iForSaleWanted'} = 0; } elsif ($dH{'iForSaleWanted'} eq 'Wanted') { $dH{'iForSaleWanted'} = 1; } else { $dH{'iForSaleWanted'} = -1; } $dH{'iStart'} += 0; @classifiedList = findClassifieds($dbh, 600, ! $dH{'iUserIsAdmin'}, $dH{'iCategoryID'}, $dH{'iForSaleWanted'}, $dH{'szStateCode'}, $dH{'fMinPrice'}, $dH{'fMaxPrice'}, $dH{'szManufacturer'}, $dH{'iIsCommercial'}, $dH{'szKeyword'}, $dH{'iUserID'}, $dH{'iWhichOrder'}); } if ($#classifiedList == -1) { my $error = 'No+ads+were+found+matching+your+search+criteria.'; print $query->redirect("/classifieds/search.mp?szErrorMessage=$error"); $dbh->disconnect; exit; } $dH{'iNumListings'} = $#classifiedList+1; $dH{'iEnd'} = $dH{'iStart'} + $dH{'iResultsPerPage'}; $dH{'iEnd'} = $dH{'iNumListings'} if ($dH{'iEnd'} > $dH{'iNumListings'}); $dH{'iShowStart'} = $dH{'iStart'} + 1; for (my $i=$dH{'iStart'}; $i<$dH{'iStart'}+$dH{'iResultsPerPage'}; $i++) { if ($classifiedList[$i]->{iClassifiedID} > 0) { my $foo = formatClassifiedSummary ($classifiedList[$i], $dH{'iMyUserID'}, $dH{'iUserIsAdmin'}); $dH{'szResults'} .= dbAccess::parseDBPage ($dbh, $dbInfo, %{$foo}); } } $dH{'szFileName'} = 'classifieds/browse-template.html'; # ---- format the criteria space ---- # $dH{'szCategoryName'} = ($dH{'iCategoryID'} <= 0) ? 'All' : $dbh->selectrow_array("SELECT szCategoryName FROM tblClassifiedCategory WHERE iCategoryID=$dH{'iCategoryID'}"); if ($dH{'szCategoryName'} eq 'All') { $dH{'szCategoryNameNoSpaces'} = '*'; } else{ $dH{'szCategoryNameNoSpaces'} = $dH{'szCategoryName'}; $dH{'szCategoryNameNoSpaces'} =~ s/\W/\_/gi; $dH{'szCategoryNameNoSpaces'} .= "_" . $dH{'iCategoryID'}; } $dH{'szStateName'} = (length($dH{'szStateCode'}) != 2) ? 'All' : $dbh->selectrow_array("SELECT szStateName FROM tblState WHERE szStateCode='$dH{'szStateCode'}'"); $dH{'szManufacturerShow'} = ($dH{'szManufacturer'} eq '') ? 'Any' : $dH{'szManufacturer'}; $dH{'szAdType'} = ($dH{'iIsCommercial'} == -1 ) ? 'Any' : $site::adType[$dH{'iIsCommercial'}]; $dH{'szForSaleWanted'} = ($dH{'iForSaleWanted'} == -1) ? 'All' : $site::adStatus[$dH{'iForSaleWanted'}]; my $maxShow = ($dH{'fMaxPrice'} eq '') ? ' no limit ' : "\$ $dH{'fMaxPrice'}"; $dH{'szPriceRange'} = "\$$dH{'fMinPrice'} to $maxShow"; # ---- format the next/previous links ---- # $dH{'iPrevStart'} = $dH{'iStart'} - $dH{'iResultsPerPage'}; $dH{'iNextStart'} = $dH{'iStart'} + $dH{'iResultsPerPage'}; if ($dH{'iPrevStart'} < 0) { $dH{'szPrevStatement'} = 'At first page'; $dH{'szPrevDisabled'} = " onClick='return false;' "; $dH{'iPrevStart'} = 0; } else { $dH{'szPrevStatement'} = 'Previous page'; } if ($dH{'iNextStart'} > $#classifiedList) { $dH{'szNextStatement'} = 'At last page'; $dH{'szNextDisabled'} = " onClick='return false;' "; $dH{'iNextStart'} = $#classifiedList; } else { $dH{'szNextStatement'} = 'Next page'; } $dH{'szExtra'} = site::toString({%dH}, '', 'szStateCode', 'fMinPrice', 'fMaxPrice', 'szManufacturer', 'iIsCommercial', 'iUserID', 'szKeyword', 'iResultsPerPage', 'iWhichOrder'); $dH{'szScript'} = 'view'; my $data = dbAccess::parseDBPage($dbh, $dbInfo, %dH); $dbh->commit; $dbh->disconnect; print $query->header ('text/html'); print $data; exit;