####################################################################### ## Title: Script to build equipment from database ## ## Author: Shawn Wakefield ## ## Creation Date: 07/30/2001 ## ## Edited Date: ## ## Comment: ## ## Created For: EXW ## ####################################################################### ############### SUB ############### # Build_Equipment subroutine sub Build_Equipment { ######## REQUIRED FILES ########### require "/usr/www/users/cmp101/exw/cgi-bin/db-common.sub" || die "Error loading db-common.sub"; require "/usr/www/users/cmp101/exw/cgi-bin/category-setup-equipment.sub" || die "Error loading category-setup-equipment.sub"; require "/usr/www/users/cmp101/exw/cgi-bin/all-common.sub" || die "Error loading all-common.sub"; ######## INPUT VARIABLES ########## &Init_Common_Vars; $front_include = "front-equip.txt"; # name of front page hw include $equip_include = "equipment.txt"; # name of main hw include $imagesdir = "/images/equipment"; # images dir relative to base $rating_img = "  1  2  3  4  5 "; $opinions_per_page = 8; $menu_includes = ""; $titles_per_listpage = 20; $search_link = "$rooturl/cgi-bin/search-equipment.pl"; $meta_keywords = $keywords . "equipment, synthesizer, cassette deck, video projector, microphone"; $meta_description = $sitename . " equipment information"; $equiprootdir = $rootpath.$equipdir; # main hardware directory for file access $equiprooturl = $rooturl.$equipdir; # main hardware directory for links &Equip_Category_Setup; $num_equip_cat = @equip_cat_title-1; ######## MAIN SCRIPT ############ # get epoch seconds so we can find new software use Time::Local; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # setup current date to put in text box #year needs to have 1900 added $year4 = $year+1900; #month starts at 0 for Jan, so add 1 $mon++; $todays_date = $year4."-".$mon."-".$mday; # connect to mySQL with user and password &Conn_to_DB; # for ($c=1; $c<=$num_equip_cat; $c++) { # $equip_cat_db_var = @equip_cat_dbname[$c]; # $equip_cat_title_var = @equip_cat_title[$c]; # if ($quick_category eq $cat_db_var) { # $category = $cat_db_var; # $equip_cat_title = $equip_cat_title_var; # &Build_Equipment_Cat_Pages; # #} # end if ($cat1 eq $equip_cat_db_var) # } # end for ($c=1; $c<=$num_equip_cat; $c++) #} else { for ($c=1; $c<=$num_equip_cat; $c++) { $category = @equip_cat_dbname[$c]; $equip_cat_title = @equip_cat_title[$c]; &Build_Equipment_Cat_Pages; } # end for ($c=1; $c<=$num_equip_cat; $c++) #} &Build_Equipment_Cat_Pages; if ($quick_build_type !~ /modify/i) { print "front inc.."; &Build_Front_Include; print "includes and indexes.."; # build include for main page $type_tag = "Equipment Devices"; $outfile = "$rootpath$equipdir/$equip_include"; open (OUT_FILE, ">".$outfile) || print "ERROR: *** Cannot open output file: $outfile. ***\n"; # build list of hw into include, no subtype pages $SQL="SELECT * FROM $equip_tbl ORDER BY category ASC, manufacturer ASC, model ASC"; &Print_Device_List; close (OUT_FILE); chmod (0777, "$outfile"); } if (!$quick_build) { # build hardware device pages $SQL="SELECT * FROM $equip_tbl"; print "Building all equip...\n"; &Build_Equip_Pages; } else { # build page for only desired device (update or opinion add) $SQL="SELECT * FROM $equip_tbl WHERE filename = '$quick_filename'"; &Build_Equip_Pages; } # DO NOT disconnect from mySQL or build-hardware.pl fails to connect for the next devicetype ## END of main script ## } # end Build_Equipment subroutine ############### SUB ############### # Build_Equip_Pages subroutine sub Build_Equip_Pages { &Do_SQL; while ($pointer = $sth->fetchrow_hashref){ $filename = $pointer->{'filename'}; $graphic = $pointer->{'graphic'}; $graphicheight = $pointer->{'graphicheight'}; $graphicwidth = $pointer->{'graphicwidth'}; $buylink = $pointer->{'buylink'}; $dateadded = $pointer->{'dateadded'}; $manufacturer = $pointer->{'manufacturer'}; $model = $pointer->{'model'}; $category = $pointer->{'category'}; $description = $pointer->{'description'}; $review = $pointer->{'review'}; $price = $pointer->{'price'}; $available = $pointer->{'available'}; $website = $pointer->{'website'}; $pick = $pointer->{'pick'}; $ID = $pointer->{'ID'}; if ($price eq "") { $price = ""; } else { $price = "Price: $price
"; } if ($available eq "") { $available = ""; } else { $available = "Availability: $available
"; } if ($website ne "") { $website = "http://".$website if (!($website =~ "http:")); $website = "Manufacturer Website: $manufacturer Site
"; } else { $website = ""; } if ($description ne "") { $description = "

Description:
$description
"; } if ($review ne "") { $review = "

EXW Review:
$review
"; } # $buyit = ""; # if ($buylink) { # $buyit = ""; # # } $buyit = ""; if ($buylink) { if ($buylink =~ /(.+)Buy This Item Now!"; $buyit_text =~ s/href/nocolor href/i; $buyit = $buylink . ""; } } else { $buyit = ""; $buyit_text = "Buy This Item Now!"; } if ($pick eq "Yes") { $pick = ""; } else { $pick = ""; } if ($graphicwidth <= 0 || $graphicheight <= 0) { $widthtag = ""; $heighttag = ""; } elsif ($graphicwidth <= 200 && $graphicheight <= 150) { $widthtag = "width=$graphicwidth"; $heighttag = "height=$graphicheight"; } else { if ($graphicwidth >= $graphicheight) { $ratio = 200/$graphicwidth; $graphicwidth = 200; $graphicheight = int($graphicheight*$ratio); } else { $ratio = 150/$graphicheight; $graphicheight = 150; $graphicwidth = int($graphicwidth*$ratio); } $widthtag = "width=$graphicwidth"; $heighttag = "height = $graphicheight"; } $escmodel = $model; $escmodel =~ s/ /%20/g; $graphic = "
Click to View
" if ($graphic ne ""); $top_site_links = "Equipment: "; $title_tag = "Equipment: "; # build user opinion page $opinion_page = 1; $opinion_filename_base = substr($filename, 0, length($filename)-5) . "-uo"; $opinion_filename_first = substr($filename, 0, length($filename)-5) . "-uo1.html"; $submit_opinion_link = "$add_uo_url?prodtype=equipment&prodID=$ID&itemtitle=$model&itemauthor=$manufacturer&itemlink=$equiprooturl/$filename"; $submit_opinion_link =~ s/ /%20/g; $top_uo_links = "
[ Back to Equipment Details   |   Submit Your Opinion ]

\n"; # get user opinions $SQL2 = "SELECT * from $op_tbl WHERE (prodID = '$ID' AND prodtype = 'equipment') ORDER BY dateadded DESC, ID DESC"; &Do_SQL2; $num_records = $sth2->rows; # build opinion page for each device $title = "$manufacturer $model - User Opinions"; $leftmenu = 0; @list_opinions = ""; $existing_opinions = ""; $num_op = 0; $recent_opinions = ""; $opinion_page = 1; while ($pointer2 = $sth2->fetchrow_hashref){ $num_op++; $op_name = $pointer2->{'name'}; $op_email = $pointer2->{'email'}; $op_location = $pointer2->{'location'}; $op_dateadded = $pointer2->{'dateadded'}; $op_title = $pointer2->{'title'}; $op_body = $pointer2->{'body'}; $op_features = $pointer2->{'features'}; $op_usability = $pointer2->{'usability'}; # figure out what page we are on $opinion_page = int($num_op / $opinions_per_page); $opinion_page++ if (($num_op / $opinions_per_page) > $opinion_page); $submitter = "
Submitted by: $op_name"; $submitter = $submitter . "
Email: $op_email" if ($op_email); $submitter = $submitter . "
Location: $op_location" if ($op_location); $submitter = $submitter . "
Date Added: $op_dateadded"; $features_img = ""; $usability_img = ""; $existing_opinions = @list_opinions[$opinion_page]; @list_opinions[$opinion_page] = $existing_opinions . "


\n \n \n \n \n \n
\n $rating_img
\n Features $features_img
\n Usability $usability_img
\n
\n $op_title
\n $op_body
\n $submitter
\n
\n"; if ($num_op <= 3) { $op_body = substr($op_body, 0, 250); $recent_opinions = $recent_opinions . "

\n $op_title
\n $op_body...more

\n Submitted by: $op_name

\n"; }# end if ($num_op <= 2) } # end while ($pointer = $sth2->fetchrow_hashref) # check if any opinions found if ($recent_opinions eq "") { $recent_opinions = "

Be the first to add your opinion about this product
Click HERE Now!

\n"; @list_opinions[1] = $recent_opinions; } else { $recent_opinions = $recent_opinions . "
\n"; } # end if ($recent_opinions eq "") $bottom_hr = ""; $nextprev = ""; $headercount = ""; $stopcount = 0; $startcount = 0; for ($p=1; $p<=$opinion_page; $p++) { if ($num_op >= 1) { $bottom_hr = "
"; $startcount = ($p - 1) * $opinions_per_page + 1; $stopcount = $p * $opinions_per_page; # build next & prev buttons if ($p > 1) { $prevpage = $p - 1; $nextprev = "<< First "; $nextprev = $nextprev."| Prev  ||"; } else { $nextprev = "<< First "; $nextprev = $nextprev."| Prev ||"; } if ($p < ($num_op / $opinions_per_page)) { $lastpage = int($num_op / $opinions_per_page); $lastpage++ if (($num_op/$opinions_per_page) > $lastpage); $nextpage = $p + 1; $nextprev = $nextprev." Next |"; $nextprev = $nextprev." Last >>"; } else { $nextprev = $nextprev." Next |"; $nextprev = $nextprev." Last >>"; } # build headers/footers, then print body $stopcount = $num_op if ($stopcount > $num_op); $headercount = " \n \n \n \n \n
Total: $num_op Opinions   Displaying: $startcount - $stopcount$nextprev
\n"; } # build individual software user opinion page $outfile = "$equiprootdir/$opinion_filename_base$p.html"; open (OUT_FILE, ">". $outfile) || print "ERROR: *** Cannot open $outfile ***
\n"; &Print_Page_Top_File; print OUT_FILE "

$title

\n"; print OUT_FILE < @list_opinions[$p] $bottom_hr $headercount
$top_uo_links
HTML &Print_Page_Bottom_File; } # end for $opinion_page = 0; if ($num_op > 0) { $display_count = 3; $display_count = $num_op if ($num_op <= 3); $show_tag = "Total: $num_op Opinions  -   Displaying: $display_count of $num_op"; $see_all = " See All $num_op Opinions"; $read_more = "Read More..."; } else { $show_tag = " "; $see_all = " "; $read_more = " "; } # end of printing opinions list page $title = "$manufacturer $model"; $top_site_links = $top_site_links.$title; $title_tag = $title_tag.$title; $outfile = "$equiprootdir/$filename"; open (OUT_FILE, ">".$outfile) || print "ERROR: *** Cannot open output file: $outfile. ***\n"; &Print_Page_Top_File; # prints top of table print OUT_FILE <

 
$pick
$buyit

$title

Manufacturer: $manufacturer
Model: $model
$price $available $website
$graphic

$description $review

$buyit_text


Search All Equipment

User Opinions:

$show_tag$read_more
$recent_opinions
 Add Your Opinion $see_all

Give Your Opinion


Compare
Looking to purchase more equipment? Compare equipment here!

Already own this piece of equipment? Add your review here!

$menu_includes
HTML &Print_Page_Bottom_File; # end of printing main record page } # end while ($pointer = $sth->fetchrow_hashref) } # end of Build_Equip_Pages ############### SUB ############### # Print_Device_List subroutine sub Print_Device_List { $rowcolor = "#EEEEEE"; $headerbar = " \n \n \n \n \n
ProductManufacturerPriceAvailability
\n"; $devices = ""; &Do_SQL; $oldcat = ""; while ($pointer = $sth->fetchrow_hashref){ $filename = $pointer->{'filename'}; $model = $pointer->{'model'}; $manufacturer = $pointer->{'manufacturer'}; $price = $pointer->{'price'}; $price = " " if (!$price); $category = $pointer->{'category'}; $available = $pointer->{'available'}; $available = " " if (!$available); if ($category ne $oldcat) { $category_title = $category; for ($c=1; $c<=$num_equip_cat; $c++) { $cat_db_var = @equip_cat_dbname[$c]; $cat_title_var = @equip_cat_title[$c]; if ($category eq $cat_db_var) { $category_title = $cat_title_var; } # end if ($cat1 eq $cat_db_var) } # end for ($c=1; $c<=$num_equip_cat; $c++) $devices = $devices . " \n \n
 $category_title
\n"; $oldcat = $category; } $devices = $devices . " \n \n \n \n \n
$model$manufacturer$price$available
\n"; # alternate grey and white bar if ($rowcolor eq "#EEEEEE") { $rowcolor = "#FFFFFF"; } else { $rowcolor = "#EEEEEE"; } } # end while # prints list of devices print OUT_FILE < $type_tagSearch Equipment $headerbar $devices $headerbar

$hwtype_links

If you don't see your product, let us know, and we will add it!
HTML } # end Print_Device_List subroutine ############### SUB ############### # Build_Front_Include subroutine sub Build_Front_Include { # builds include for front page spotlight $outfile = "$rootpath/skin/$front_include"; open (OUT_FILE, ">". $outfile) || print "ERROR: *** Cannot open $outfile ***
\n"; print OUT_FILE <

Product Focus

HTML $SQL="SELECT * FROM $equip_tbl WHERE available='Now' AND CHARACTER_LENGTH(graphic)>3"; &Do_SQL; $num_records = $sth->rows; $start_num = int rand($num_records - 1); $print_num = 1; $curr_num = 0; # SELECT statement to get records from specified table &Do_SQL; $rowcolor = "#FFFFFF"; while ($pointer = $sth->fetchrow_hashref) { $curr_num++; if ($curr_num > $start_num) { last if ($curr_num > $start_num + $print_num); $filename = $pointer->{'filename'}; $graphic = $pointer->{'graphic'}; $graphicheight = $pointer->{'graphicheight'}; $graphicwidth = $pointer->{'graphicwidth'}; $manufacturer = $pointer->{'manufacturer'}; $model = $pointer->{'model'}; $website = $pointer->{'website'}; if ($website ne "") { $website = "http://".$website if (!($website =~ "http:")); $manufacturer = "$manufacturer"; } if ($graphicwidth <= 0 || $graphicheight <= 0) { $widthtag = ""; $heighttag = ""; } elsif ($graphicwidth <= 100 && $graphicheight <= 100) { $widthtag = "width=$graphicwidth"; $heighttag = "height=$graphicheight"; } else { if ($graphicwidth >= $graphicheight) { $ratio = 100/$graphicwidth; $graphicwidth = 100; $graphicheight = int($graphicheight*$ratio); } else { $ratio = 100/$graphicheight; $graphicheight = 100; $graphicwidth = int($graphicwidth*$ratio); } $widthtag = "width=$graphicwidth"; $heighttag = "height = $graphicheight"; } $graphic = "" if ($graphic ne ""); $filename = $pointer->{'filename'}; $filename_uo = substr($filename, 0, length($filename)-5) . "-uo1.html"; $filename = $filename."-datesort-1.html" if (!($filename =~ /html/)); print OUT_FILE <$graphic
$model


HTML } } print OUT_FILE <
Device Summary
Manufacturer:$manufacturer
HTML close (OUT_FILE); chmod (0777, "$outfile"); } # end Build_Front_Include subroutine ############### SUB ############### # Build_Equipment_Cat_Pages subroutine sub Build_Equipment_Cat_Pages { $catbase = "$category"; $title_heading = "Equipment - $equip_cat_title"; $title_tag = "Equipment: $equip_cat_title:"; $SQLbase="SELECT * FROM $equip_tbl "; $SQL = $SQLbase . " WHERE category='$category' ORDER BY model ASC"; $listfile_base = "$rootpath$equipdir/$catbase-model"; $listfile_baseurl = "$rooturl$equipdir/$catbase-model"; &Build_Equipment_List_Pages; $SQL = $SQLbase . " WHERE category='$category' ORDER BY manufacturer ASC, model ASC"; $listfile_base = "$rootpath$equipdir/$catbase-manufacturer"; $listfile_baseurl = "$rooturl$equipdir/$catbase-manufacturer"; &Build_Equipment_List_Pages; $SQL = $SQLbase . " WHERE category='$category' ORDER BY price DESC, model ASC"; $listfile_base = "$rootpath$equipdir/$catbase-price"; $listfile_baseurl = "$rooturl$equipdir/$catbase-price"; &Build_Equipment_List_Pages; } # end Build_Cat_Pages subroutine ############### SUB ############### # Build_Equipment_List_Pages subroutine sub Build_Equipment_List_Pages { $headerbar = " \n \n \n \n \n \n \n
Sort by: ModelManufacturerPricePick
\n"; # clear/setup variables for new category $recordcount = 0; $rowcolor = "#EEEEEE"; $list_pagenum = 1; @list_titles = ""; $existing_titles = ""; &Do_SQL; while ($pointer = $sth->fetchrow_hashref){ # figure out what page we are on $list_pagenum = int($recordcount / $titles_per_listpage) + 1; $recordcount++; $filename = $pointer->{'filename'}; $graphic = $pointer->{'graphic'}; $graphicheight = $pointer->{'graphicheight'}; $graphicwidth = $pointer->{'graphicwidth'}; $buylink = $pointer->{'buylink'}; $dateadded = $pointer->{'dateadded'}; $manufacturer = $pointer->{'manufacturer'}; $model = $pointer->{'model'}; $category = $pointer->{'category'}; $description = $pointer->{'description'}; $review = $pointer->{'review'}; $price = $pointer->{'price'}; $available = $pointer->{'available'}; $website = $pointer->{'website'}; $pick = $pointer->{'pick'}; $ID = $pointer->{'ID'}; $esctitle = $title; $esctitle =~ s/ /%20/g; $esctitle =~ s/&/%26/g; if ($pick eq "Yes") { $pick = ""; } else { $pick = " "; } # fix description - XX chars long $shortdesc = ""; # strip tags out to keep description compact $description =~ s/<([^>]|\n)*>//g; # take out html tags $shortdesc = substr ($description, 0, 100) . "....more" if ($description ne ""); $shortdesc = "
$shortdesc \n" if ($description ne ""); # build line for each record $existing_titles = @list_titles[$list_pagenum]; $existing_titles = @list_titles[$list_pagenum]; @list_titles[$list_pagenum] = $existing_titles . " \n \n \n \n \n \n \n \n
$model\n $shortdesc $pubtag $booktag $manufacturer$price$pick
\n"; # alternate grey and white bar if ($rowcolor eq "#EEEEEE") { $rowcolor = "#FFFFFF"; } else { $rowcolor = "#EEEEEE"; } } # End of while # fix variables if no records were found if ($recordcount == 0) { $startcount = 0; $headercount = " \n \n \n \n \n
Found: 0
\n"; } # end if ($recordcount == 0) if (@list_titles[1] eq "") { @list_titles[1] = " \n \n \n \n

No records were found.

\n"; } # end if (@list_titles[1] eq "") $nextprev = ""; for ($p=1; $p<=$list_pagenum; $p++) { if ($recordcount >= 1) { $startcount = ($p - 1) * $titles_per_listpage + 1; $stopcount = $p * $titles_per_listpage; # build next & prev buttons if ($p > 1) { $prevpage = $p - 1; $nextprev = "<< First "; $nextprev = $nextprev."| Prev  ||"; } else { $nextprev = "<< First "; $nextprev = $nextprev."| Prev ||"; } if ($p < ($recordcount / $titles_per_listpage)) { $lastpage = int($recordcount / $titles_per_listpage); $lastpage++ if (($recordcount/$titles_per_listpage) > $lastpage); $nextpage = $p + 1; $nextprev = $nextprev." Next |"; $nextprev = $nextprev." Last >>"; } else { $nextprev = $nextprev." Next |"; $nextprev = $nextprev." Last >>"; } # build headers/footers, then print body $stopcount = $recordcount if ($stopcount > $recordcount); $headercount = " \n \n \n \n \n \n
Total: $recordcount   Displaying: $startcount - $stopcountSearch Equipment$nextprev
\n"; } # build individual software user opinion page $outfile = $listfile_base . $p . ".html"; open (OUT_FILE, ">". $outfile) || print "ERROR: *** Cannot open $outfile ***
\n"; flock(OUT_FILE, 2); # lock exclusive # all vars are set, build this category page $leftmenu = ""; $title_tag = "$title_tag $equip_cat_title"; $top_site_links = "Equipment: $equip_cat_title"; &Print_Page_Top_File; print OUT_FILE <$title_heading $headercount $headerbar @list_titles[$p] $headerbar $headercount HTMLEND $print_additional_info = "no"; &Print_Page_Bottom_File; } # end for ($p=1; $p<=$list_pagenum; $p++) } # end Build_Album_List_Pages subroutine 1; # required