#!/usr/local/bin/perl ################################################################## # Architecture.com.au # Awards search script # # Updated and revised # James Norman # Oct 26th, 2005 ################################################################## # use Mysql; use CGI(':standard'); use lib '/usr/data/www/architecture/cgi-bin'; use classes::db; use classes::page; use classes::general; use classes::login; use classes::adabd; use classes::intelsearch_awards; use classes::mylog; # pull from ~www/architecture/awards_new/cgi-bin/ use classes::awards_config; use classes::awards_new; use classes::awards_list; use classes::awards_slideshow; use classes::awards_keyword; use classes::awards_display; ################################################################## $NEXTPAGE = ""; $PREVPAGE = ""; $BACKTOSEARCH = ""; $SLIDESHOW = ""; $TOTALPAGE = ""; $CURRENTPAGE = ""; $FINALAWARDS = ""; $NUMAWARDS = 0; $dbh = db->connect(); my $option = param('option'); # JN 2005-11-14 # check to see if summary script is running and if it is # show a message $is_running = &summary_is_running(); if ($is_running) { my $message = "Sorry, we are currently updating our database. This process should be completed in a few minutes."; &showMain($message); exit(); } # if ($ENV{REMOTE_ADDR} =~ /150\.101\.68/) { # } # else { # print header; # print "Sorry, we are currently experiencing database issues. Please try again in a few hours."; # exit(); # } if ($option eq "" || $option eq "advanced") { &showMain(); exit(); } if ($option eq "search") { &doSearch(); exit(); } if ($option eq "browse" || $option eq "ADABD") { &doBrowse(); exit(); } if ($option eq "showaward") { awards_display->displayAward(); exit(); } if ($option eq "slide") { awards_slideshow->doSlide(); exit(); } if ($option eq "finalslide") { awards_slideshow->doFinalSlide(); exit(); } &invalidOption(); sub showMain () { ########################################################### # showMain - this function displays the main search page # to be used for the awards database # my $output = ""; my $syspage = general->getSystemPage($awards_config::SYSPAGE_MAIN); my $output = page->getOutput($syspage, "yes", "", "", "", "", "yes"); my $message = $_[0]; my $query = "SELECT id FROM major_cat ORDER BY id"; my $sth = awards_new->db_query($query); my $ratio = 0; for (1..$sth->numrows) { my ($section) = $sth->fetchrow; my ($image, $ratio) = awards_new->getFrontImage($section, $ratio); my @path = split '/', $image; $image = $path[$#path]; my $finalimage = "$awards_config::FRONTIMAGEWEB/$section/$image"; my ($entryno, $ext) = split '\.', $image; open (INPUT, "$awards_config::FRONTIMAGEDIR/$section/$entryno.txt"); my $pname = ; my $pracname = ; my $photographer = ; close (INPUT); chop $pname; chop $pracname; chop $photographer; my $altpname = $pname; $altpname =~ s/\"//g; $altpname =~ s/\>|\getSearchYears(); my $years = $year_options; $years =~ s/#FIELD_NAME#/browseyears/g; $output =~ s/#YEARS#/$years/g; my $location = awards_new->getSearchLocation(); $output =~ s/#LOCATION#/$location/g; my $majorcat1 = awards_new->getCategory(1); my $majorcat2 = awards_new->getCategory(2); my $majorcat3 = awards_new->getCategory(3); my $majorcat4 = awards_new->getCategory(4); $output =~ s/#MAJORCAT1#/$majorcat1/g; $output =~ s/#MAJORCAT2#/$majorcat2/g; $output =~ s/#MAJORCAT3#/$majorcat3/g; $output =~ s/#MAJORCAT4#/$majorcat4/g; my $advanced = ""; my $search_link = "Click here for the advanced search"; if ($option eq "advanced") { my $syspage = general->getSystemPage($awards_config::SYSPAGE_ADVANCED); $advanced = page->getOutput($syspage, "yes", "", "", "", "", "yes"); $advanced =~ s/#KEYWORD#/$keyword/g; my @fields = general->getDropDown("fieldsDD"); my $options = awards_new->getOptions($fieldval, $usedesc, @fields); my $field = ""; $advanced =~ s/#FIELD#/$field/g; my $years = $year_options; $years =~ s/#FIELD_NAME#/years/g; $advanced =~ s/#YEARS#/$years/g; $search_link = "Click here for the basic search"; } if ($message ne "") { $search_link .= "

$message
"; } $output =~ s/#ADVANCEDSEARCH#/$advanced/g; $output =~ s/#SEARCH_LINK#/$search_link/g; awards_new->show_page($output); } sub doBrowse () { ############################################################# # doBrowse - this function displays the search results based # on the browse options entered # # REVISED : JN 2005-10-27 # JN 2005-10-28 # JN 2005-11-10 my $style = param('showstyle'); if ($style eq "") { $style = 1; } my $searchid = param('searchid'); if ($searchid eq "") { my ($USERID, $SESSIONID, @rest) = general->getUserCookies(); if ($SESSIONID eq "") { $USERID = ""; } mylog->addLog("PROJBROWSE", $majorcat, $minorcat, $location, $awards, $browseyears, $USERID); my $condition = awards_new->createCondition(); my $query = "SELECT id, entryno FROM awards_summary WHERE image_exists=1$condition"; #if ($ENV{'REMOTE_ADDR'} eq '150.101.68.41') { $query = "q $query"; } $tempsth = $dbh->query($query); if (!(defined $tempsth)) { print "Content-type: text/html\nExpires: Wed, 29 Mar 1995 09:00:00 GMT\n\nError in query : $query\n"; exit(); } $searchid = awards_new->createTemp($tempsth); } else { ## JN 2005-10-26 ## search id is not blank meaning this page was called from a Next or Previous hit! awards_new->updateTemp($searchid); } my $entryno = param('entryno'); if ($entryno ne '' && $option eq 'ADABD') { $G_SEARCH_ID = $searchid; awards_display->displayAward(); exit(); } &showResults($searchid, $style); } sub doSearch () { ############################################################# # doSearch - this function displays the search results based # on the search terms entered # # REVISED : JN 2005-11-09 # JN 2005-11-10 # my $style = param('showstyle'); if ($style eq "") { $style = 1; } my $searchid = param('searchid'); my $keyword = param('keyword'); my $field = param('field'); my $searchterm = $keyword; my $logterm = $keyword; $logterm =~ s/\"//g; $logterm = "\"$logterm\""; my $searchkeyword = $searchterm; $searchkeyword =~ s/\s+or\s*//g; ## JN 2006-03-31 $searchkeyword =~ s/\s+and\s*//g; $searchkeyword =~ s/\s+the\s*//g; #$searchkeyword =~ s/or//g; ## JN 2006-03-31 #$searchkeyword =~ s/and//g; #$searchkeyword =~ s/the//g; $searchkeyword =~ s/\'s//g; $searchkeyword =~ s/\'//g; $searchkeyword =~ s/\&//g; if ($searchid eq "") { my ($USERID, $SESSIONID, @rest) = general->getUserCookies(); if ($SESSIONID eq "") { $USERID = ""; } mylog->addLog("PROJSEARCH", $logterm, $field, $years, $USERID); my $condition = awards_new->createCondition(); my $query = "SELECT id, entryno FROM awards_summary WHERE image_exists=1$condition"; $tempsth = $dbh->query($query); if (!(defined $tempsth)) { print "Content-type: text/html\nExpires: Wed, 29 Mar 1995 09:00:00 GMT\n\nError in query : $query\n"; exit(); } $searchid = awards_new->createTemp($tempsth); } else { ## JN 2005-10-26 ## search id is not blank meaning this page was called from a Next or Previous hit! awards_new->updateTemp($searchid); } #################################################################################################### ## Award search performance boost ... ## JN 2004-11-23 my (@ENTRY_ARRAY) = awards_keyword->findAwardEntries ($searchkeyword, $field); ## JN 2004-11-23 ### now remove all entries from the search file that don't exist in @ENTRY_ARRAY ### as ENTRY_ARRAY is a list of keyword matches! $searchid = awards_keyword->recreateSearch($searchid, \@ENTRY_ARRAY); &showResults($searchid, $style); } sub showResults () { ############################################################# # doBrowse - this function displays the search results based # on the browse options entered # # REVISED : JN 2005-10-27 # JN 2005-10-28 # JN 2005-11-09 my $searchid = $_[0]; my $style = $_[1]; ## default is thumbnail list! if ($style eq '') { $style = $awards_config::STYLE_LIST; } if ($searchid eq '0') { awards_new->no_results_found(); } my $output = ""; my $syspage = general->getSystemPage($awards_config::SYSPAGE_RESULTS); $output = page->getOutput($syspage, "yes", "", "", "", "", "yes"); if ($style eq $awards_config::STYLE_LIST) { $results = awards_list->getListResults($searchid, $style); } elsif ($style eq $awards_config::STYLE_MATRIX) { $results = awards_list->getListResults($searchid, $style); } $SLIDESHOW = awards_new->getSlide($style); $output =~ s/#RESULTS#/$results/g; my $syspage = general->getSystemPage($awards_config::SYSPAGE_HEADER); my $searchbrowse = page->getOutput($syspage, "yes", "", "", "", "", "yes"); $output =~ s/#SEARCHBROWSEHEAD#/$searchbrowse/g; my $syspage = general->getSystemPage($awards_config::SYSPAGE_RAWFORM); my $rawform = page->getOutput($syspage, "yes", "", "", "", "", "yes"); $output =~ s/#RAWFORM#/$rawform/g; my $keyword = param('keyword'); my $field = param('field'); my $years = param('years'); my $majorcat = param('majorcat'); my $minorcat = param('minorcat'); my $locations = param('locations'); my $browseyears = param('browseyears'); my $page = param('displaypage'); my $thisentry = param('entryno'); if ($page eq "") { $page = 1; } $output =~ s/#NATVAL#/$national/g; $national = ($national eq 'on')?'CHECKED':''; $output =~ s/#STATEVAL#/$state/g; $state = ($state eq 'on')?'CHECKED':''; $FINALAWARDS = <
EOF ; if ($NUMAWARDS eq 0) { $NUMAWARDS = 1; } $output =~ s/#OPTION#/$option/g; $output =~ s/#KEYWORD#/$keyword/g; $output =~ s/#FIELD#/$field/g; $output =~ s/#YEARS#/$years/g; $output =~ s/#MAJORCAT#/$majorcat/g; $output =~ s/#MINORCAT#/$minorcat/g; $output =~ s/#LOCATION#/$location/g; $output =~ s/#BROWSEYEARS#/$browseyears/g; $output =~ s/#STYLE#/$style/g; $output =~ s/#NATIONAL#/$national/g; $output =~ s/#STATE#/$state/g; $BACKTOSEARCH = awards_new->getSearch(); $output =~ s/#BACKTOSEARCH#/$BACKTOSEARCH/g; $output =~ s/#AWARDSDD#/$awards/g; $output =~ s/#SEARCHID#/$searchid/g; $output =~ s/#AWARDS#/$FINALAWARDS/g; $output =~ s/#NEXT#/$NEXTPAGE/g; $output =~ s/#SLIDESHOW#/$SLIDESHOW/g; $output =~ s/#PREVIOUS#/$PREVPAGE/g; $output =~ s/#CURRENTPAGE#/$CURRENTPAGE/g; $output =~ s/#TOTALPAGE#/$TOTALPAGE/g; $output =~ s/#MORE#/$MOREPAGES/g; $output =~ s/#PAGE#/$page/g; $output =~ s/#ENTRYNO#/$USE_ENTRYNO/g; awards_new->show_page($output, '', 'Search Results - '); } sub invalidOption() { print "Content-type: text/html\nExpires: Wed, 29 Mar 1995 09:00:00 GMT\n\nPlease enter a valid option\n"; } sub summary_is_running() { ################################################################# # summary_is_running() # # Read the process file to get the process id # Check /proc/ to determine if process is still running # # Return true if process is running, false otherwise # my $PATH = "/usr/data/www/architecture/awards_new/data"; my $PID_FILE = "$PATH/summary.pid"; my $still_running = 0; if (-e($PID_FILE)) { # PID file exists open(INPUT,$PID_FILE); $pid = ; close(INPUT); chop($pid); # check if still running open(INPUT,"/proc/$pid/cmdline"); $cmdline = ; close(INPUT); chop($cmdline); if ($cmdline =~ /summary\.pl/i) { # process is still running! $still_running = 1; } } return $still_running; }