#!/usr/bin/perl use CGI qw(:all); # get paths my($i); $PWD = __FILE__; $i = rindex($PWD, '/'); if ($i != -1) { $SCRIPT = substr($PWD, $i+1); $PWD = substr($PWD, 0, $i); } else { $SCRIPT = $PWD; $PWD = "."; } use File::Basename; # load configuration parameters require $PWD."/config.ph"; require $DIR{modules}."WWW.pm"; require $DIR{modules}."LDB.pm"; require $DIR{modules}."List.pm"; my($www) = new WWW(); my($db) = "macrojp"; my($ldb) = new LDB($db, undef, $www); $www->setObject("ishopper", "db", $db); my($page) = $www->param("page"); my($item) = $www->param("item"); if ($item) { $www->setObject("email", "item", $item); } $page =~ s/\\//g; # get page content according to page or use default my($content); &getpdf(); if ($page) { $www->setObject("object", "page", $page); my($htmlpath) = $page; if ($htmlpath =~ /email/){ &email; $htmlpath = $www->param("imail_confirm"); } # page requested ($page), display it $content = $www->parseFile($DIR{objects}.$htmlpath.".html"); } else { # no specific page(!$page) requested, display index default $www->setObject("object", "home", 'Y'); &getNews(); $content = $www->parseFile($DIR{objects}."default.html"); } # assign values to app object for use by template $www->setObject("app", "content", $content); # Build Javascript Menu of products and assign to object for use by template #&buildjs(); # get site template and parse my($template) = $www->parseFile($DIR{templates}."index.html"); # print magic header print $www->header(-charset=>'euc-jp'); # print parsed template print $template; exit; # SUB FUNCTIONS ############### sub email { # locks $LOCK{'SH'} = 1; $LOCK{'EX'} = 2; $LOCK{'NB'} = 4; $LOCK{'UN'} = 8; # validate my(@input) = $www->param(); $www->validate(\@input); # get base url my($base, $pos); $base = $ENV{'HTTP_REFERER'}; $pos = rindex($base, "/"); if ($pos != -1) { $base = substr($base, 0, $pos); } # check path my($path) = $www->param("Submit"); if ($path eq "Place Order" || $path eq "Place Request"){ my($key); foreach $key (@input) { if ($key =~ /^cgi_/ || $key =~ /^imail_/) { next; } my($value) = $www->param($key); if ($key =~ /.*_file$/ && $value) { $value = time()."_".$value; my($new_key) = substr($key, 0, length($key)-length("_file")); my($file) = $DIR{htdocs}."/".$www->param("imail_upload")."/".$value; rename($in->{$new_key}, $file) || $www->die("Can't move: ".$www->param($new_key)." to ".$file.": $!"); $value = $base."/".$in->{imail_upload}."/".$value; } $www->setObject("email", $key, $value); } my($total) = $www->param("shipping") + $www->param("subtotal"); $www->setObject("iapp", "total", "$total"); $www->setObject("email", "total", "$total"); $www->setObject("iapp", "imail_sender", $www->param("imail_sender")); $www->setObject("email", "imail_sender", $www->param("imail_sender")); $www->setObject("email", "stamp", scalar(localtime(time))); # archive my($archive) = $www->param("imail_archive"); if ($archive) { open(FILE, ">>$DIR{data}/$archive/data.txt"); # write lock unless (flock(FILE, $LOCK{'EX'} | $LOCK{'NB'})) { unless(flock(FILE, $LOCK{'EX'})) { $www->die("Can't lock database for writing: $!"); } } my($data) = $www->getObject("email"); foreach $key (keys %$data) { print FILE $key.":\t".$data->{$key}."\n"; } print FILE "\n"; close(FILE); } # special instructions my($email) = $www->parseFile($DIR{templates}.$www->param("imail_template")); $www->sendmail($www->param("imail_sender"), $www->param("imail_recipient"), $www->param("imail_subject"), $email, $www->param("imail_app")); $www->setObject("object", "title", "Confirmation"); } # endif path is place order if ($path eq "Fax or Mail"){ my($key); foreach $key (@input) { if ($key =~ /^cgi_/ || $key =~ /^imail_/) { next; } $www->setObject("iapp", "imail_sender", $www->param("imail_sender")); my($value) = $www->param($key); $www->setObject("iapp", $key, $value); } my($total) = $www->param("shipping") + $www->param("subtotal"); $www->setObject("iapp", "total", "$total"); my($page) = $www->parseFile($DIR{templates}."printpage.html"); # print magic header print $www->header(-charset=>'euc-jp'); # print parsed template print $page; exit; } # end if fax or mail } # end sub email # # getNews # displaysNewsHeadlines # sub getNews { my($sh, $record); # get layout objects my($layout) = $www->loadObjectFiles($DIR{objects}."/headlines_home"); my($sql) = qq{ SELECT *, DATE_FORMAT(date, '%m/%d/%y') AS d, DATE_FORMAT(date, '%M %Y') AS d2 FROM News WHERE home = 'Y' ORDER BY date DESC LIMIT 4 }; $sh = $ldb->getRecords($sql); while ($record = $ldb->getMoreRecords($sh)) { # update counter $count++; $record->{index} = $count; # build body $www->setObject("data", $record); $layout->{tmp} .= $www->parseString($layout->{body}); } if ($layout->{tmp}) { $www->setObject("list", "headlines", $www->parseString($layout->{header}). $layout->{tmp}. $www->parseString($layout->{footer})); } else { $www->setObject("list", "headlines", $www->parseString($layout->{empty})); } } sub getpdf { # db stuff my($sh, $record, $sh2, $record2); # build sql my($sql2) = qq{ SELECT * FROM catalogpdf }; $sh2 = $ldb->getRecord($sql2); my($catalog) = $sh2->{pdf}; $www->setObject("pdf", "catalog", $catalog); } # end getpdf sub buildjs { $num = 40; my($array) = qq~prod = new MakeArray(~.$num.qq~)\n~; # db stuff my($sh, $record, $sh2, $record2); # build sql my($sql2) = qq{ SELECT * FROM type ORDER BY type }; my($i,$name,$prev, $count); $sh2 = $ldb->getRecords($sql2); while ($record2 = $ldb->getMoreRecords($sh2)) { # update counter $count++; $i = $record2->{id}; $name = $record2->{type}; $array .= qq~prod[~.$count.qq~] = "/cgi-bin/content/ishopper/ishopper.cgi?mode=list_type&type=~.$i; $array .= qq~"\n~; $select .= qq~