#!/usr/bin/perl sub said { #&said("comment here"); local($error_content) = @_ ; print "content-type: text/html \n\n"; print "

Information => $error_content \n\n

"; exit; } #require "$ENV{'DOCUMENT_ROOT'}/vm_standard_library/cgi_lib.pl"; require "../cgi_lib.pl"; $mybaseurl = &MyBaseUrl(); $referer = $ENV{'HTTP_REFERER'}; &ReadParse(*in); if ($in{searchPostal}||$in{searchStreet}) { $in{range} = ($in{range})?$in{range}:5; } if ($in{SERVICES_ID} eq "undefined") { $in{SERVICES_ID}==8; } if (!$in{SERVICES_ID}) { $SERVICES_IDNOT = 1 ; } if (!$in{CRITERIA_ID}) { $in{CRITERIA_ID} = 'all' ; } elsif($in{CRITERIA_ID} eq 'null') { $in{CRITERIA_ID} = 'all' ; } #add by akhyar to escape sql variable elsif($in{CRITERIA_ID} =~ /,/){ use DBI(); $dbh = DBI->connect("DBI:mysql:database=mcds_new","root"); my @temp_data = split(',', $in{CRITERIA_ID}); foreach my $val (@temp_data) { $arr_data .= $dbh->quote($val).","; } #my $count = $#temp_data + 1; my $count = length($arr_data); $in{CRITERIA_ID} = substr($arr_data, 0, ($count - 1)); } if ($in{searchProgType} eq "Select Programme Type") { $in{searchProgType}=""; } if ($in{searchSvcSector} eq "Select Service Sector") { $in{searchSvcSector}=""; } &dispatch(); sub dispatch { print<Ministry of Community Development, Youth and Sports EOHTML print< EOHTML ###### DISPATCH HERE ####### if ($SERVICES_IDNOT==1) { print "

Please Define Service Name

"; } else { if ( $in{index} || $in{zone} || $in{searchName} || $in{searchPostal} || $in{searchNo} || $in{searchStreet} || $in{streetname} || $in{CRITERIA_ID} || $in{CENTRE_ID} || $in{Centre_Id}) { if ($in{index}) { if ($in{index} == 7) { &drawmap() ; } if ($in{index} == 22) { ¢recode() ; } if ($in{index} == 8) { &nearby_amenity_finded() ; } }else{ if ($in{searchName}) { &search_by_name() ; } elsif ($in{searchPostal}) { &postalcode_search(); } elsif ($in{searchNo} || $in{searchStreet}) { &search_streetname() ; } elsif ($in{streetname}) { if (($in{SERVICES_ID}==8) || ($in{SERVICES_ID}==7)||($in{SERVICES_ID}==4)||($in{SERVICES_ID}==9)) { &search_nearby_street_directory() ; }else{ &search_nearby_street() ; } } elsif ($in{CENTRE_ID}) { &getMapById() ; } elsif ($in{zone} || $in{Centre_Id}) { $in{zone} = uc($in{zone}); if ($in{SERVICES_ID}==2) { $in{fsczone}=$in{zone}; &searchzonefsc() ; } else { &findnearregion() ; } ##Return Back all variebles with no address input }elsif(((!$in{searchStreet})||(!$in{searchPostal}))&&(($in{SERVICES_ID}==2)||($in{SERVICES_ID}==4))){ &search_for_services(); ################Search by VWO without street and postal########## }elsif((($in{SERVICES_ID}==7)&&(!$in{zone}))||(($in{SERVICES_ID}==7)&&(!$in{searchPostalcode}))||(($in{SERVICES_ID}==7)&&(!$in{searchNo}))){ &search_VWO(); ############################################################### } } } } ###### DISPATCH HERE ####### print<
EOHTML } sub find_for_adroit { local($ServiceName,$ServiceId,$CriteriaId); $ServiceName = $in{SERVICES_ID} ; $ServiceId = $SERVICES_ID ; $CriteriaId = $in{CRITERIA_ID} ; if ($ServiceId==1 && (lc($CriteriaId) ne 'all')) { # FOR DDC and Not All $finalsql="select TB_MS_CENTRELIST_CSS.CENTRE_ID,TB_MS_CENTRELIST_CSS.CRITERIA_ID from TB_MS_CENTRELIST_CSS,TB_MS_CENTRES_CSS where (TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID) AND ((TB_MS_CENTRELIST_CSS.SERVICES_ID = $ServiceId) AND (TB_MS_CENTRELIST_CSS.CRITERIA_ID IN ($CriteriaId))) order by TB_MS_CENTRES_CSS.CENTRE_NAME"; use DBI(); $dbh = DBI->connect("DBI:mysql:database=mcds_new","root"); $sth = $dbh->prepare("$finalsql"); $sth->execute; while ($ref=$sth->fetchrow_hashref()) { $DDCID = $ref->{'CENTRE_ID'} ; $DataDDC{$DDCID} .= $ref->{'CRITERIA_ID'}.","; } $sth->finish; $dbh->disconnect(); foreach $variable (keys %DataDDC) { substr($DataDDC{$variable},-1) = "" ; if (getCriteria($in{CRITERIA_ID},$DataDDC{$variable})) { $centre_ids .= "$variable," ; } } if (!$centre_ids) { $centre_ids = 'noresult'; } else { substr($centre_ids,-1) = "" ; } } else { if (lc($CriteriaId) eq 'all') { $SqlCondition = sprintf("TB_MS_CENTRELIST_CSS.SERVICES_ID = %s",$dbh->quote($ServiceId)) ; } else { $SqlCondition = sprintf("(TB_MS_CENTRELIST_CSS.SERVICES_ID = $ServiceId) AND (TB_MS_CENTRELIST_CSS.CRITERIA_ID IN ($CriteriaId))",$dbh->quote($ServiceId)) ; } if ($ServiceId==2||$ServiceId==6) { $finalsql=sprintf("select CENTRE_ID from TB_MS_CENTRES_CSS where SERVICES_ID=$s order by CENTRE_NAME",$dbh->quote($ServiceId)); } else { $finalsql="select TB_MS_CENTRELIST_CSS.CENTRE_ID from TB_MS_CENTRELIST_CSS,TB_MS_CENTRES_CSS where (TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID) AND ($SqlCondition) AND TB_MS_CENTRES_CSS.STATUS='O' group by TB_MS_CENTRELIST_CSS.CENTRE_ID order by TB_MS_CENTRES_CSS.CENTRE_NAME"; } use DBI(); $dbh = DBI->connect("DBI:mysql:database=mcds_new","root"); $sth = $dbh->prepare("$finalsql"); $sth->execute; $rows=0; while ($ref=$sth->fetchrow_hashref()) { if ($rows==0) { $centre_ids = $ref->{'CENTRE_ID'} ; } else { $centre_ids .= ',' . $ref->{'CENTRE_ID'} ; } $rows++; } $sth->finish; $dbh->disconnect(); if ($rows<=0) { $centre_ids = 'noresult'; } } #print"$finalsql"; &SendCentresIdList($ServiceId,$CriteriaId,$centre_ids) ; } sub getMapById { $in{CENTRE_ID} = uc($in{CENTRE_ID}); local($getmap) = 'NO' ; use DBI(); $dbh = DBI->connect("DBI:mysql:database=mcds_new","root"); $query=sprintf("select * FROM TB_MS_CENTRES_CSS where CENTRE_ID=%s",$dbh->quote($in{CENTRE_ID})); $sth = $dbh->prepare($query); $sth->execute; while ($ref=$sth->fetchrow_hashref()) { $in{index}=7; $in{x}=$ref->{'X_ADDR'}; $in{y}=$ref->{'Y_ADDR'}; $in{d1}=$ref->{'ADDRESS'}; $in{d2}=$ref->{'TELEPHONE_NUMBER'}; $in{d3}=$ref->{'FAX_NUMBER'}; $in{d5}=$ref->{'EMAIL'}; $in{d4}=$ref->{'WEBSITE_URL'}; $in{hour}=$ref->{'OPERATING_HOURS'}; $in{CenterName}=$ref->{'CENTRE_NAME'}; $in{postal}=$ref->{'POSTAL_CODE'}; $in{detail}="yes"; $in{level} = 7 ; &drawmap() ; $getmap = 'OK' ; } # print"$in{CentreName} and $in{d1} and $in{d2} and $in{d3}"; $sth->finish; $dbh->disconnect(); if ($getmap ne 'OK') { print "

Sorry There Is No Result For
Services : $in{SERVICES_ID}
Centre Id : $in{CENTRE_ID}

" ; } } sub SendCentresIdList { local($Service_Id,$Criteria_Id,$Centre_Id,$mapurl,$formurl) = @_ ; $Service_Id = ($Service_Id)?$Service_Id:$SERVICES_ID; $Criteria_Id = ($Criteria_Id)?$Criteria_Id:$in{CRITERIA_ID}; if ($Service_Id == 2 ||$Service_Id == 6) { $Criteria_Id = 'null'; } if (!$formurl) { # For Posting Other Search Except Zone Search $formurl = 'http://app.mcys.gov.sg/web/serv_newdss_main_result_alpha.asp' ; #$formurl = 'http://app-stg.mcys.gov.sg/web/serv_newdss_main_result_alpha.asp' ; } $Centre_Id = uc($Centre_Id); if ($mapurl) { local($mapinputurl) = qq{}; } @count = split(",",$Centre_Id) ; my $counter = @count ; &emptyjs(); print< $mapinputurl EOF } sub SendCentresIdFSCList { local($Service_Id,$Criteria_Id,$FSC_IN,$Centre_Id,$CENTRE_NAME) = @_ ; if (!$formurl) { $formurl = 'http://app.mcys.gov.sg/web/serv_newdss_main_result_alpha.asp' ; #$formurl = 'http://app-stg.mcys.gov.sg/web/serv_newdss_main_result_alpha.asp' ; } $Centre_Id = uc($Centre_Id); if ($mapurl) { local($mapinputurl) = qq{}; } if (($CENTRE_ID eq "F00035")|| ($in{CRITERIA_ID} eq 'all')) {$CENTRE_ID="F00018"; } @count = split(",",$Centre_Id) ; my $counter = @count+$FSC_IN; &emptyjs(); if ($in{searchPostal}) { if ($in{CRITERIA_ID} eq "all") { $return_varb=qq{ }; $testrev=qq{1 SERVICES_ID=$Service_Id&CRITERIA_ID=null&searchPostal=$in{searchPostal}&SORT_BY=$in{SORT_BY}&CENTRE_ID=$Centre_Id}; }else{ $return_varb=qq{ }; $testrev=qq{2 SERVICES_ID=$Service_Id&CRITERIA_ID=$Criteria_Id&searchPostal=$in{searchPostal}&SORT_BY=$in{SORT_BY}&FSC_IN=$FSC_IN&CENTRE_ID=$Centre_Id}; } }elsif(($in{searchNo})&&($in{searchStreet})){ if ($in{CRITERIA_ID} eq "all") { $return_varb=qq{ }; $testrev=qq{3 SERVICES_ID=$Service_Id&CRITERIA_ID=null&searchNo=$in{searchNo}&&searchStreet=$in{searchStreet}&SORT_BY=$in{SORT_BY}&CENTRE_ID=$Centre_Id}; }else{ $return_varb=qq{ }; $testrev=qq{4 SERVICES_ID=$Service_Id&CRITERIA_ID=$Criteria_Id&searchNo=$in{searchNo}&&searchStreet=$in{searchStreet}&SORT_BY=$in{SORT_BY}&FSC_IN=$FSC_IN&CENTRE_ID=$Centre_Id}; } }else{ $return_varb=qq{ }; $testrev=qq{5 SERVICES_ID=2&CRITERIA_ID=$Criteria_Id&SORT_BY=$in{SORT_BY}&CENTRE_ID=$Centre_Id}; } print< $return_varb
EOF } ##########return variable for Directory Search################################ sub SendCentresIdListForAllSearch { ## change services_id to 8 local($Service_Id,$Criteria_Id,$CCC,$CDC,$DSS,$ECS,$FSC,$SCS,$VWO,$CENTRE_NAME) = @_ ; ################################################################################# $Service_Id = ($Service_Id)?$Service_Id:$SERVICES_ID; $Criteria_Id = ($Criteria_Id)?$Criteria_Id:$in{CRITERIA_ID}; if (!$formurl) { $formurl = 'http://app.mcys.gov.sg/web/serv_newdss_main_result_alpha.asp' ; #$formurl = 'http://app-stg.mcys.gov.sg/web/serv_newdss_main_result_alpha.asp' ; } if ($mapurl) { local($mapinputurl) = qq{}; } if ($CCC) {substr($CCC,-1) = "" ;$CCCID=qq{};}else{$CCCID="";} if($CDC) {substr($CDC,-1) = "" ;$CDCID=qq{};}else{$CDCID="";} if($DSS) {substr($DSS,-1) = "" ;$DSSID=qq{};}else{$DSSID="";} if($ECS) {substr($ECS,-1) = "" ;$ECSID =qq{};}else{$ECSID="";} if($FSC) {$FSCID=qq{};}else{$FSCID="";} if($SCS) {substr($SCS,-1) = "" ;$SCSID=qq{};}else{$SCSID='';} if($VWO) {substr($VWO,-1) = "" ;$VWOID=qq{};}else{$VWOID="";} &emptyjs(); if ($in{searchPostal}) { $address=qq{ }; }elsif($in{searchNo}&&$in{searchStreet}) { $address=qq{ }; }elsif($in{zone}){ $address=qq{ }; }else{ $address=""; } @count = split(",",$Centre_Id) ; my $counter = @count ; print< $address$CCCID$CDCID$DSSID$ECSID$FSCID$SCSID$VWOID EOF } ##########return variable for VWO################################ sub SendCentresIdListForVWO { ## change services_id to 8 local($Service_Id,$Centre_Id) = @_ ; ################################################################################# if (!$formurl) { $formurl = 'http://app.mcys.gov.sg/web/serv_newdss_main_result_alpha.asp' ; #$formurl = 'http://app-stg.mcys.gov.sg/web/serv_newdss_main_result_alpha.asp' ; } if ($mapurl) { local($mapinputurl) = qq{}; } &emptyjs(); if ($in{searchPostal}) { $address=qq{ }; }elsif($in{searchNo}&&$in{searchStreet}) { $address=qq{ }; }elsif($in{zone}){ $address=qq{ }; }else{ $address=qq{ }; } #print"klist : $Centre_Id"; @count = split(",",$Centre_Id) ; my $counter = @count ; print< $address EOF } sub printlistnum_with_rows { local ($start, $rows, $per_page, $link) = @_; local ($string,$end); $end = ($start+$per_page < $rows)? $start+$per_page: $rows; $string = sprintf qq{
Search Results %d to %d of $rows.
Page :}, $start+1, $end; local($i,$j); $j = 1; if (($i=$start-$per_page)>=0) { $string .= qq{ <<}; } for ($i=0; $i<$rows && $j<11; $i+=$per_page) { if ($i == $start) { $string .= qq{ $j}; } else { $string .= qq{ $j}; } $j++; } if ($i<$rows) { $string .= qq{ (too many matches)}; } if (($i=$start+$per_page)<((--$j)*$per_page)) { $string .= qq{ >>}; } $string .= qq{
\n}; print "
$string
" ; } sub printlistnum_with_rows_2 { local ($start, $rows, $per_page, $link) = @_; local ($string,$end); $end = ($start+$per_page < $rows)? $start+$per_page: $rows; $string = sprintf qq{
Search Results %d to %d of $rows.
Page :}, $start+1, $end; local($i,$j); $j = 1; if (($i=$start-$per_page)>=0) { $string .= qq{ <<}; } for ($i=0; $i<$rows && $j<11; $i+=$per_page) { if ($i == $start) { $string .= qq{ $j}; } else { $string .= qq{ $j}; } $j++; } if ($i<$rows) { $string .= qq{ (too many matches)}; } if (($i=$start+$per_page)<((--$j)*$per_page)) { $string .= qq{ >>}; } $string .= qq{
\n}; return $string; } ################################################################################################### # # FUNCTION: percent_escape # # DESCRIPTION: Replace special characters # # PARAMETERS: String to be processed # # RETURNED: Processed string # # REVISION HISTORY: 19/10/2000 # ################################################################################################### sub unescape { local($toencode) = @_; $toencode=~s/%23/"#"/eg; $toencode=~s/%28/"("/eg; $toencode=~s/%29/")"/eg; $toencode=~s/%27/"'"/eg; $toencode=~s/%26/"&"/eg; $toencode=~s/%20/" "/eg; #$toencode=~s/%2F/"/"/eg; return $toencode; } sub break_line { local($toencode) = @_; $toencode=~s/\(/"
("/eg; return $toencode; } ################################################################################################### # # FUNCTION: escape # # DESCRIPTION: Replace special characters # # PARAMETERS: String to be processed # # RETURNED: Processed string # # REVISION HISTORY: 19/10/2000 # ################################################################################################### sub escape { local($toencode) = @_; #$toencode=~s/(\s)/sprintf("_%x",ord($1))/eg; $toencode=~s/#/"%23"/eg; $toencode=~s/\(/"%28 "/eg; $toencode=~s/\)/"%29"/eg; $toencode=~s/\'/"%27"/eg; $toencode=~s/&/"%26"/eg; $toencode=~s/ /"%20"/eg; #$toencode=~s/\//"%2F"/eg; return $toencode; } sub space_escape { local($toencode) = @_; $toencode=~s/%20/"+"/eg; $toencode=~s/ /"+"/eg; $toencode=~s/%2520/"+" /eg; return $toencode; } sub plus_escape { local($toencode) = @_; $toencode=~s/\+/" "/eg; return $toencode; } sub unplus_escape { local($toencode) = @_; $toencode=~s/\+/" "/eg; return $toencode; } sub set_boundary { local($long, $lat, $level) = @_; local($scale, $long_min, $long_max, $lat_max, $image_x, $lm_delta); if ($level < 3) { $scale = exp((2-$level)*log(2)); $long_min = $global_long_min; $long_max = $global_long_max; $lat_max = $global_lat_max; $image_x = 919; } elsif ($level == 3) { $scale = 1; # $long_min = $global_long_min; # $long_max = $global_long_max; # $lat_max = $global_lat_max; # $image_x = 3803; $long_min = 1976; $long_max = 57959; $lat_max = 51191; $image_x = 2533; } else { $scale = exp((7-$level)*log(2)); # $long_min = 26468; # $long_max = 29988; # $lat_max = 33448; # $image_x = 3240; $long_min = 3072; $long_max = 56897.75; $lat_max = 51191; $image_x = 49680; } $map_scale = ($long_max-$long_min)/$image_x*$scale; $lm_deltaX = $map_sizeX /2 * $map_scale; $lm_deltaY = $map_sizeY /2 * $map_scale; $lm_long_min = $long - $lm_deltaY; $lm_long_max = $long + $lm_deltaY; $lm_lat_min = $lat - $lm_deltaX; $lm_lat_max = $lat + $lm_deltaX; } sub printfooter { print "" ; print qq{
Terms and conditions of use. All rights reserved.
©2011 "Streetdirectory.com" is the trademark right of
Streetdirectory Pte Ltd ( a JobsDB company). Company Reg No. 200811860N.
Streetdirectory.com, the Number 1 Singapore Travel Guide & Singapore Food Guide
}; } sub drawmap { if ($in{CenterName}) { $judul = &break_line($in{CenterName}) ; $judul = unescape($judul) ; $in{d1} = &unescape($in{d1}) ; $in{d2} = &unescape($in{d2}) ; $in{d3} = &unescape($in{d3}) ; $in{d4} = &unescape($in{d4}) ; $in{d5} = &unescape($in{d5}) ; $in{d6} = &unescape($in{d6}) ; $in{hour} = &unescape($in{hour}) ; print< $judul
EOHTML if ($in{detail}) { print "
" ; if ($in{d1}) { print "$in{d1}
" ; } if ($in{d2}) { print "Tel: $in{d2}  " ; } if ($in{d3}) { print " Fax: $in{d3}
" ; } else { print "
" ; } if ($in{d4} ne " ") { print "Website: $in{d4}
" ; }else{print ""} if ($in{d5} ne " ") { print "Email: $in{d5}
" ; } if ($in{d6}) { print "$in{d6}
" ; } if ($in{hour} eq " ") {print "" }else{print "Operating Hour: $in{hour}
" }; if ($in{SERVICES_ID} eq 'CCC') { print "More Details" ; } } $in{d1} = &escape($in{d1}) ; $in{d2} = &escape($in{d2}) ; $in{d3} = &escape($in{d3}) ; $in{d4} = &escape($in{d4}) ; $in{d5} = &escape($in{d5}) ; $in{d6} = &escape($in{d6}) ; $in{hour} = &escape($in{hour}) ; print< EOHTML } $in{CenterName} = escape($in{CenterName}) ; &scriptloadmap(); print< $javascript
EOHTML print "  NEARBY AMENITY SEARCH :"; print "" ; &nearby_amenity() ; print ""; &printfooter() ; } ######### NEARBY AMENITY ############### sub nearby_amenity { print<
Search Nearby Amenity Within Range  
EOHTML } sub nearby_amenity_finded { local ($dbh, $sth, $new, $query, $count, $row, $link, $results, $result_string); $distsqbound = 1000000*$in{range}*$in{range}; $start = ($in{start})? $in{start}*1: 0; $per_page = 10; use DBI(); $dbh = DBI->connect("DBI:mysql:database=vm_singapore_new","root"); if ($in{nearby_amenity} eq "MRT") { $nearby_type=51; }elsif($in{nearby_amenity} eq "Community Club"){ $nearby_type=14; }elsif($in{nearby_amenity} eq "Hospital"){ $nearby_type=41; }elsif($in{nearby_amenity} eq "Educational Institution"){ $nearby_type="20,21,22,23,24,25,26,92"; }elsif($in{nearby_amenity} eq "Community Centre"){ $nearby_type=14; }elsif($in{nearby_amenity} eq "Bus Interchange"){ $nearby_type=4; } $query = qq{ SELECT *,POW(x_addr-$in{x},2)+POW(y_addr-$in{y},2) AS distsq FROM sg_full WHERE place_category_id IN ($nearby_type) AND ( POW(x_addr-$in{x},2)+POW(y_addr-$in{y},2) <=$distsqbound ) ORDER BY distsq }; $sth = $dbh->prepare($query); $rows = $sth->execute; $sth->finish; if ($rows!=0) { $query = qq{ SELECT * ,POW(x_addr-$in{x},2)+POW(y_addr-$in{y},2) AS distsq FROM sg_full WHERE place_category_id IN ($nearby_type) AND ( POW(x_addr-$in{x},2)+POW(y_addr-$in{y},2) <=$distsqbound ) ORDER BY distsq limit $start, $per_page }; #print $query; $sth = $dbh->prepare($query); $sth->execute; $index = $start; while (my $ref=$sth->fetchrow_hashref()) { # ($type, $landmarkname) = split(': ',$ref->{'place_name'}); $x = $ref->{'x_addr'}; $y = $ref->{'y_addr'}; $index++; $script .= &getscript($x,$y,$index); $results .= &save_amenity_result($ref->{'distsq'}, $index, "$ref->{'place_name'}", $x, $y); push @xylist, "$x,$y"; } $sth->finish; $xylist = join (',',@xylist); $link = sprintf "index=8&x=$in{x}&y=$in{y}&SERVICES_ID=$in{SERVICES_ID}&$multilist&range=$in{range}&nearby_amenity=$in{nearby_amenity}" ; $linklist = &printlistnum_with_rows_2($start,$rows,$per_page,$link) ; &scriptnearby(); $result_string = qq{ $scriptnearby
$linklist $results }; print "
Click here to go back.\n"; &result_wrapup_without_ad("Nearby $in{nearby_amenity} (Within $in{range} km)", $result_string); } else { $result_string = qq{
}; print "$result_string" ; print "
Click here to go back.\n"; # &printfooter() ; } $dbh->disconnect(); } sub save_amenity_result { local($distsq, $index, $name, $x, $y) = @_; local($string); $dist= sqrt($distsq)*0.001; $dist_format = sprintf ("%5.2f", $dist); $string = sprintf qq{ }, &percent_escape($name); return $string; } sub percent_escape { local($toencode) = @_; $toencode=~s/(\s)/sprintf("%%%x",ord($1))/eg; $toencode=~s/#/"%23"/eg; $toencode=~s/&/"%26"/eg; $toencode=~s/\)/"%29"/eg; $toencode=~s/\'/"%27"/eg; $toencode=~s/&/"%26"/eg; $toencode=~s/ /"%20"/eg; #$toencode=~s/\//"%2F"/eg; return $toencode; } sub result_wrapup_without_ad { local($title, $result_string,) = @_; print < EOF print <" ; print "
No Result for Nearby $in{nearby_amenity} (Within $in{range} km)
  $index. $name
 
 
Distance $dist_format km
$title
" ; &printlistnum_with_rows($start,$rows,$per_page,$link) ; print "
" ; print "Click here to go back.\n

"; print "
" ; &printfooter() ; undef $result_string; } ## ## ## ## ## ## ## ## ## ## MCDS START HERE ## ## ## ## ## ## ## ## ## ## #### ZONE SEARCH ############################################################################################################################ sub regionmap { my ($AREAFILE) = @_ ; open(INFILE, $AREAFILE); # determine region vertices and town name. while () { chop; @vertices = split(/,/,$_); $town = shift(@vertices); if ($town eq $in{zone}) { last;} } close(INFILE); my $length = @vertices; push(@vertices,@vertices[0,1]); $polyxylist = join(',', @vertices); $x_min = 9999999; $x_max = 0; $y_min = 9999999; $y_max = 0; $x_ave = 0; $y_ave = 0; for (my $i=0; $i<$length-1; $i+=2) { $x = $vertices[$i]; $y = $vertices[$i+1]; $x_ave= $x_ave + $x; $y_ave= $y_ave + $y; if ($x<$x_min) { $x_min = $x; } if ($x>$x_max) { $x_max = $x; } if ($y<$y_min) { $y_min = $y; } if ($y>$y_max) { $y_max = $y; } } $x_ave = ($x_ave/$length) * 2; $y_ave = ($y_ave/$length) * 2; $in{x}= int($x_ave); $in{y}= int($y_ave); $level = 7; while ($level>0) { &set_boundary($in{x}, $in{y}, $level); last if ( $x_min>$lm_long_min && $x_max<$lm_long_max && $y_min>$lm_lat_min && $y_max<$lm_lat_max ); if ($level!=5) { $level--; } else { $level -= 2; } } use MD5; use constant SECRET => 'kd93kld093lklmlsde'; $tmpfilename = MD5->hexhash(localtime); open(TMPOUTPUT, ">/tmp/$tmpfilename"); print TMPOUTPUT "custom_line,4,blue,$polyxylist,\n"; close(TMPOUTPUT); } sub searchzonefsc { use DBI(); $dbh = DBI->connect("DBI:mysql:database=mcds_new","root"); $query=sprintf("select null from TB_MS_FSC_ZONE where FSC_ZONE_ID=%s",$dbh->quote($in{fsczone})); $sth = $dbh->prepare($query); $rows = $sth->execute; $sth->finish; if ($rows>0) { $query=sprintf("select CENTRE_ID from TB_MS_FSC_ZONE where FSC_ZONE_ID=%s",$dbh->quote($in{fsczone})); $sth = $dbh->prepare($query); $sth->execute; while (my $ref=$sth->fetchrow_hashref()) { $CENTRE_ID = $ref->{'CENTRE_ID'}; $IDs .= $CENTRE_ID . ","; } if ($IDs) { substr($IDs,-1) = "" ; $FSC=$IDs; }#end if if($in{Centre_Id}){ $FSC = $in{Centre_Id}; } if ($in{SERVICES_ID} ==8) { $in{FSC}=$FSC; }else{ #print" fsc $FSC"; &SendCentresIdList($in{SERVICES_ID},$in{CRITERIA_ID},$FSC,"","http://app.mcys.gov.sg/web/serv_newdss_main_result_region.asp") ; #&SendCentresIdList($in{SERVICES_ID},$in{CRITERIA_ID},$FSC,"","http://app-stg.mcys.gov.sg/web/serv_newdss_main_result_region.asp") ; } } else{ &SendCentresIdList($in{SERVICES_ID},$in{CRITERIA_ID},"0","","http://app.mcys.gov.sg/web/serv_newdss_main_result_region.asp") ; #&SendCentresIdList($in{SERVICES_ID},$in{CRITERIA_ID},$FSC,"noresult") ; } #print"$query
"; #print" fsc $FSC";exit; # if ($in{SERVICES_ID} ==8) { # $in{FSC}=$FSC; # }else{ # #print" fsc $FSC"; # &SendCentresIdList($in{SERVICES_ID},$in{CRITERIA_ID},$FSC,"","http://app.mcys.gov.sg/web/serv_newdss_main_result_region.asp") ; # } $dbh->disconnect(); } ################################## ## ZONE DIRECTORY SEARCH ######### ################################# sub searchzonedirectory{ local (@vertices) = @_; &searchzonefsc(); use DBI(); $dbh = DBI->connect("DBI:mysql:database=mcds_new","root"); $query="select null FROM TB_MS_CENTRES_CSS where SERVICES_ID !=2"; $sth = $dbh->prepare($query); $rows = $sth->execute; $sth->finish; if ($rows>0) { $query="SELECT X_ADDR,Y_ADDR,CENTRE_ID,SERVICES_ID from TB_MS_CENTRES_CSS where SERVICES_ID !=2"; $sth = $dbh->prepare($query); $sth->execute; #print" rows = $rows print $query"; while (my $ref=$sth->fetchrow_hashref()) { $x=$ref->{'X_ADDR'}; $y=$ref->{'Y_ADDR'}; $CENTRE_ID = $ref->{'CENTRE_ID'}; $SERVICES_ID=$ref->{'SERVICES_ID'}; if ($SERVICES_ID==6) { if ($in{cdczone} == 88) { $CDC="CD0001,"; }elsif($in{cdczone} == 89){ $CDC="CD0002,"; }elsif($in{cdczone} == 87){ $CDC="CD0003,"; }elsif($in{cdczone} == 90){ $CDC="CD0004,"; }elsif($in{cdczone} == 86){ $CDC="CD0005,"; } } if (!&in_polygon($x,$y,@vertices) && ($SERVICES_ID !=6)) { if ($SERVICES_ID==4) {$CCC .= $CENTRE_ID . ",";} if($SERVICES_ID==1){$DSS .= $CENTRE_ID . ",";} if($SERVICES_ID==5){$ESC .= $CENTRE_ID . ",";} if($SERVICES_ID==3){$SCS .= $CENTRE_ID . ",";} if($SERVICES_ID==7){$VWO .= $CENTRE_ID . ",";} } }# end of while #print"$query
CCC $CCC
CDD $CDC
DSS $DSS
ECC $ESC
FSC $in{FSC}
SCC $SCS
VWO $VWO"; if ($CENTRES_IDS) { substr($CENTRES_IDS,-1) = "" ; $centrelist=$CENTRES_IDS; }#end if &SendCentresIdListForAllSearch(8,"1,2,3,4,5,6,7,8",$CCC,$CDC,$DSS,$ESC,$FSC,$SCS,$VWO,$CENTRE_NAME); #print"$query
ccc= $CCC
cdc= $CDC
DSS= $DSS
ECC= $ESC
FSC= $in{FSC}
SCS= $SCS
VWO = $VWO
"; }else{ &SendCentresIdListForAllSearch(8,"1,2,3,4,5,6,7,8","no result"); }#end if $sth->finish; $dbh->disconnect(); } ################################### ### Find Near Region Care Centre### ################################### sub DGPzonename{ ($in{fsczone},$regions,$in{cdczone}) = split(',',$in{zone}); if ($regions==58) {$in{zone}="ANG MO KIO";} elsif ($regions==52) {$in{zone}="BEDOK";} elsif ($regions==37) {$in{zone}="BISHAN";} elsif ($regions==72) {$in{zone}="BOON LAY";} elsif ($regions==73) {$in{zone}="BUKIT BATOK";} elsif ($regions==38) {$in{zone}="BUKIT MERAH";} elsif ($regions==74) {$in{zone}="BUKIT PANJANG";} elsif ($regions==39) {$in{zone}="BUKIT TIMAH";} elsif ($regions==48) {$in{zone}="CENTRAL WATER CATCHMENT";} elsif ($regions==53) {$in{zone}="CHANGI";} elsif ($regions==54) {$in{zone}="CHANGI BAY";} elsif ($regions==75) {$in{zone}="CHOA CHU KANG";} elsif ($regions==76) {$in{zone}="CLEMENTI";} elsif ($regions==43) {$in{zone}="GEYLANG";} elsif ($regions==59) {$in{zone}="HOUGANG";} elsif ($regions==78) {$in{zone}="JURONG EAST";} elsif ($regions==72) {$in{zone}="JURONG WEST";} elsif ($regions==41) {$in{zone}="KALLANG";} elsif ($regions==65) {$in{zone}="LIM CHU KANG";} elsif ($regions==48) {$in{zone}="MANDAI";} elsif ($regions==49) {$in{zone}="MARINA SOUTH";} elsif ($regions==43) {$in{zone}="MARINE PARADE";} elsif ($regions==46) {$in{zone}="ORCHARD";} elsif ($regions==64) {$in{zone}="NORTH EASTERN ISLANDS";} elsif ($regions==45) {$in{zone}="NOVENA";} elsif ($regions==55) {$in{zone}="PASIR RIS";} elsif ($regions==56) {$in{zone}="PAYA LEBAR";} elsif ($regions==80) {$in{zone}="PIONEER";} elsif ($regions==61) {$in{zone}="PUNGGOL";} elsif ($regions==47) {$in{zone}="QUEENSTOWN";} elsif ($regions==62) {$in{zone}="SELETAR";} elsif ($regions==76) {$in{zone}="SEMBAWANG";} elsif ($regions==60) {$in{zone}="SENGKANG";} elsif ($regions==85) {$in{zone}="SOUTHERN ISLANDS";} elsif ($regions==59) {$in{zone}="SERANGOON";} elsif ($regions==71) {$in{zone}="SIMPANG";} elsif ($regions==69) {$in{zone}="SUNGEI KADUT";} elsif ($regions==57) {$in{zone}="TAMPINES";} elsif ($regions==39) {$in{zone}="TANGLIN";} elsif ($regions==79) {$in{zone}="TENGAH";} elsif ($regions==51) {$in{zone}="TOA PAYOH";} elsif ($regions==81) {$in{zone}="TUAS";} elsif ($regions==82) {$in{zone}="WESTERN ISLANDS";} elsif ($regions==83) {$in{zone}="WESTERN WATER CATCHMENT";} elsif ($regions==70) {$in{zone}="WOODLANDS";} elsif ($regions==71) {$in{zone}="YISHUN";} elsif ($regions==46) {$in{zone}="ORCHARD";} } sub findnearregion { local ($distsqbound,$start,$xyarr); $distsqbound = 1000000*9; $start = ($in{start})? $in{start}: 0; &DGPzonename(); my $AREAFILE = "area.data"; open(INFILE, $AREAFILE); # determine region vertices and town name. while () { chop; @vertices = split(/,/,$_); $town = shift(@vertices); if ($town eq $in{zone}) {last;} } close(INFILE); # print "region = $town; >>> sudah ok " ; # process into polygon xylist. my $length = @vertices; # repeat first vertices at the end. push(@vertices,@vertices[0,1]); $polyxylist = join(',', @vertices); $x_min = 9999999; $x_max = 0; $y_min = 9999999; $y_max = 0; $x_ave = 0; $y_ave = 0; for (my $i=0; $i<$length-1; $i+=2) { $x = $vertices[$i]; $y = $vertices[$i+1]; $x_ave= $x_ave + $x; $y_ave= $y_ave + $y; if ($x<$x_min) { $x_min = $x; } if ($x>$x_max) { $x_max = $x; } if ($y<$y_min) { $y_min = $y; } if ($y>$y_max) { $y_max = $y; } } $x_ave = ($x_ave/$length) * 2; $y_ave = ($y_ave/$length) * 2; $in{x}= int($x_ave); $in{y}= int($y_ave); $level = 7; while ($level>0) { &set_boundary($in{x}, $in{y}, $level); last if ( $x_min>$lm_long_min && $x_max<$lm_long_max && $y_min>$lm_lat_min && $y_max<$lm_lat_max ); if ($level!=5) { $level--; } else { $level -= 2; } } use MD5; use constant SECRET => 'kd93kld093lklmlsde'; $tmpfilename = MD5->hexhash(localtime); open(TMPOUTPUT, ">/tmp/$tmpfilename"); print TMPOUTPUT "custom_line,4,blue,$polyxylist,\n"; close(TMPOUTPUT); if ($in{SERVICES_ID}==8) { &searchzonedirectory(@vertices) ; }else{ &find_nearby_center_byregion(@vertices); } } sub in_polygon { $testx = shift(@_); $testy = shift(@_); @vertices = @_; my $length = @vertices; # default 1 indicate out of region. my $out =1; $j = $length - 2; for (my $i=0; $i<$length-1; $i+=2) { if ( (($vertices[$i+1]<=$testy) && ($testy<$vertices[$j+1])) || (($vertices[$j+1]<=$testy) && ($testy<$vertices[$i+1]))) { # $compare_x = ($vertices[$j]-$vertices[$i])*($testy-$vertices[$i+1])/($vertices[$j]-$vertices[$i+1])+$vertices[$i]; if ($testx < ($vertices[$j]-$vertices[$i])*($testy-$vertices[$i+1])/($vertices[$j+1]-$vertices[$i+1])+$vertices[$i]) { $out = 1 - $out; } } $j = $i; } return $out; } sub find_nearby_center_byregion { local (@vertices) = @_; use DBI(); $dbh = DBI->connect("DBI:mysql:database=mcds_new","root"); $query=sprintf("select CENTRE_ID,X_ADDR,Y_ADDR from TB_MS_CENTRES_CSS where SERVICES_ID=%s group by CENTRE_ID",$dbh->quote($in{SERVICES_ID})); $sth = $dbh->prepare($query); #print "$query"; $sth->execute; while (my $ref=$sth->fetchrow_hashref()) { $x=$ref->{'X_ADDR'}; $y=$ref->{'Y_ADDR'}; if (!&in_polygon($x,$y,@vertices)) { $CENTRE_IDS .= $ref->{'CENTRE_ID'}.","; } }#end while $sth->finish; if ($CENTRE_IDS) { substr($CENTRE_IDS,-1) = "" ; $centrelist=$CENTRE_IDS; }#end if if ($centrelist) { $rows=1; } if ($rows>0) { &SendCentresIdList($in{SERVICES_ID},"null",$centrelist,"","http://app.mcys.gov.sg/web/serv_newdss_main_result_region.asp") ; #&SendCentresIdList($in{SERVICES_ID},"null",$centrelist,"","http://app-stg.mcys.gov.sg/web/serv_newdss_main_result_region.asp") ; $dbh->disconnect(); }else{ &SendCentresIdList($in{SERVICES_ID},$CriteriaId,"noresult") ; } } #### ZONE SEARCH ############################################################################################################################ sub findfsc { #print $searchpostal;exit; my $AREAFILE = "area_fsc_2010.data"; open(INFILE, $AREAFILE); @id_fsc = (); # determine region vertices and town name. while () { chop; @vertices = split(/,/,$_); #print @vertices; $id_fscs = shift(@vertices); if (!&in_polygon($x_fsc,$y_fsc,@vertices)) {push(@id_fsc, $id_fscs);} } close(INFILE); my $length = @vertices; # repeat first vertices at the end. push(@vertices,@vertices[0,1]); $polyxylist = join(',', @vertices); $x_min = 9999999; $x_max = 0; $y_min = 9999999; $y_max = 0; $x_ave = 0; $y_ave = 0; for (my $i=0; $i<$length-1; $i+=2) { $x = $vertices[$i]; $y = $vertices[$i+1]; $x_ave= $x_ave + $x; $y_ave= $y_ave + $y; if ($x<$x_min) { $x_min = $x; } if ($x>$x_max) { $x_max = $x; } if ($y<$y_min) { $y_min = $y; } if ($y>$y_max) { $y_max = $y; } } $x_ave = ($x_ave/$length) * 2; $y_ave = ($y_ave/$length) * 2; $in{x}= int($x_ave); $in{y}= int($y_ave); $level = 3; #while ($level>0) { &set_boundary($in{x}, $in{y}, $level); # last if ( $x_min>$lm_long_min && $x_max<$lm_long_max && $y_min>$lm_lat_min && $y_max<$lm_lat_max ); # if ($level!=5) { # $level--; # } else { # $level -= 2; # } #} use MD5; use constant SECRET => 'kd93kld093lklmlsde'; $tmpfilename = MD5->hexhash(localtime); open(TMPOUTPUT, ">/tmp/$tmpfilename"); print TMPOUTPUT "custom_line,4,blue,$polyxylist,\n"; close(TMPOUTPUT); } sub findfscname { if ($no_fsc == 1) { $boundary_name = "Ang Mo Kio" } if ($no_fsc == 2) { $boundary_name = "Cheng San" } if ($no_fsc == 3) { $boundary_name = "Asian Women's Welfare Association" } if ($no_fsc == 4) { $boundary_name = "Bukit HO" } if ($no_fsc == 5) { $boundary_name = "Queenstown" } if ($no_fsc == 6) { $boundary_name = "Toa Payoh" } if ($no_fsc == 7) { $boundary_name = "Woodlands" } if ($no_fsc == 8) { $boundary_name = "Covenant" } if ($no_fsc == 9) { $boundary_name = "Bukit Batok" } if ($no_fsc == 10) { $boundary_name = "Kampong Kapor" } if ($no_fsc == 11) { $boundary_name = "Jurong West" } if ($no_fsc == 12) { $boundary_name = "Jurong East" } if ($no_fsc == 13) { $boundary_name = "Macpherson Moral" } if ($no_fsc == 14) { $boundary_name = "Pasir RIS" } if ($no_fsc == 15) { $boundary_name = "Rotary" } if ($no_fsc == 16) { $boundary_name = "Serangoon Moral" } if ($no_fsc == 17) { $boundary_name = "Sinda FSC" } if ($no_fsc == 18) { $boundary_name = "Yishun" } if ($no_fsc == 19) { $boundary_name = "Tampines" } if ($no_fsc == 20) { $boundary_name = "Tanjong Pagar" } if ($no_fsc == 21) { $boundary_name = "Trans Center Bedok" } if ($no_fsc == 22) { $boundary_name = "YWMA-MENDAKI" } if ($no_fsc == 23) { $boundary_name = "Moral FSC (Bedok North)" } if ($no_fsc == 24) { $boundary_name = "Daybreak" } if ($no_fsc == 25) { $boundary_name = "Reach" } if ($no_fsc == 26) { $boundary_name = "Choa Chu Kang" } if ($no_fsc == 27) { $boundary_name = "SBL Vision" } if ($no_fsc == 28) { $boundary_name = "Hougang Seng Hong" } if ($no_fsc == 29) { $boundary_name = "Trans Center" } if ($no_fsc == 30) { $boundary_name = "Marine Parade" } if ($no_fsc == 31) { $boundary_name = "Woodlands II" } if ($no_fsc == 32) { $boundary_name = "Boonlay" } if ($no_fsc == 33) { $boundary_name = "Sembawang" } if ($no_fsc == 34) { $boundary_name = "Sengkang" } if ($no_fsc == 35) { $boundary_name = "Muhammadiyah-MENDAKI" } } ##################################################################### # ***************************POSTAL CODE SEARCH********************* ##################################################################### sub postalcode_search{ local ($dbh, $sth, $query, $count, $row, $xxx); $distsqbound = 1000000*$in{range}*$in{range}; $searchpostal = $in{searchPostal}; #### Find x,y from Postal Code first use DBI(); $dbh = DBI->connect("DBI:mysql:database=vm_singapore_new","root"); #$sql="SELECT sg_address.address_id,sg_place.place_id, sg_place.place_name,sg_place.is_main_building,sg_place.former_place_name,sg_address.block,sg_address.streetname,sg_address.former_streetname,sg_address.postal,sg_link.x_addr,sg_link.y_addr,sg_link.link_id FROM vm_singapore_new.sg_address INNER JOIN vm_singapore_new.sg_link ON sg_address.address_id = sg_link.address_id INNER JOIN vm_singapore_new.sg_place ON sg_place.place_id = sg_link.place_id WHERE (sg_place.is_main_building = -1 OR sg_place.is_main_building =1) AND postal='$searchpostal'"; $sql=sprintf("SELECT address_id,place_id, place_name,is_main_building,former_place_name,block,streetname,former_streetname,postal,x_addr,y_addr,link_id FROM vm_singapore_new.sg_full WHERE (is_main_building = -1 OR is_main_building =1) AND postal=%s",$dbh->quote($searchpostal)); #print $sql; $sth = $dbh->prepare($sql); $sth->execute; my $ref=$sth->fetchrow_hashref(); $in{px_addr}= $ref->{'x_addr'}; $in{py_addr}= $ref->{'y_addr'}; $sth->finish; $dbh->disconnect(); #### Search nearby from postal code #### If Postal code exists if ($in{px_addr}) { if (($in{SERVICES_ID}==8)||($in{SERVICES_ID}==7)||($in{SERVICES_ID}==4)||($in{SERVICES_ID}==9)) { &search4789() ; }else{ &search1235() ; } }else { #&SendCentresIdList($ServiceId,$CriteriaId,"Invalid") ; &SendCentresIdList($in{SERVICES_ID},$services_id_new,"noresult",$CENTRE_NAME) ; } } sub search4789 { local ($dbh, $sth, $query, $count, $row, $xxx); $px_addr=$in{px_addr}; $py_addr=$in{py_addr}; $distsqbound = 1000000*$in{range}*$in{range}; &checkcriteria22(); $xxx = 0; $dbh = DBI->connect("DBI:mysql:database=mcds_new","root"); if($in{SERVICES_ID} == 4){ if($in{searchFood} eq "Select Menu"){ $in{searchFood} = "";} if($in{searchService} eq "Select Service"){ $in{searchService} = "";} } if ($in{SERVICES_ID} == 7) { if (($in{searchSvcSector}) and ($in{searchProgType}) ){ $query="select null from TB_MS_CENTRES_CSS where POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) <= $distsqbound and SERVICES_ID=7 AND PROG_TYPE='$in{searchProgType}' and SECTOR_CODE='$in{searchSvcSector}' group by CENTRE_ID"; }elsif($in{searchProgType}){ $query="select null from TB_MS_CENTRES_CSS where POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) <= $distsqbound and SERVICES_ID=7 AND PROG_TYPE='$in{searchProgType}' group by CENTRE_ID"; }elsif($in{searchSvcSector}){ $query="select null from TB_MS_CENTRES_CSS where POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) <= $distsqbound and SERVICES_ID=7 AND SECTOR_CODE='$in{searchSvcSector}' group by CENTRE_ID"; }else{ $query="select null from TB_MS_CENTRES_CSS where POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) <= $distsqbound and SERVICES_ID=7 group by CENTRE_ID"; } }elsif($in{SERVICES_ID} == 9){ $query="select null from TB_MS_CENTRES_CSS where POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) <= $distsqbound and SERVICES_ID=9 group by CENTRE_ID"; }elsif($in{SERVICES_ID}==4){ if ($in{CRITERIA_ID} eq "all") {$criteria_id="";}else{$criteria_id = $in{CRITERIA_ID};} if (($in{searchFood}) and ($in{searchService}) and ($criteria_id)) { $query="select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD='$in{searchService}' AND TB_MS_CENTRELIST_CSS.CRITERIA_ID='$in{searchFood}' and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD AND TB_MS_CENTRELIST_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID"; }elsif(($in{searchFood}) and ($in{searchService})){ $query="select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD='$in{searchService}' AND TB_MS_CENTRELIST_CSS.CRITERIA_ID='$in{searchFood}' and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD and TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID"; }elsif(($in{searchFood}) and ($criteria_id)){ $query="select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_MS_CENTRELIST_CSS.CRITERIA_ID='$in{searchFood}' and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD and TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID"; }elsif(($in{searchService}) and ($criteria_id)){ $query="select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD='$in{searchService}' and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID"; }elsif(($in{searchFood})){ $query="select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_MS_CENTRELIST_CSS.CRITERIA_ID='$in{searchFood}' and TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID"; }elsif(($in{searchService})){ $query="select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD='$in{searchService}' and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID"; }elsif(($criteria_id)){ $query="select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID;"; }else{ $query="select count(*) FROM TB_MS_CENTRES_CSS where POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound AND SERVICES_ID=4"; } }else{ #this is for search where SERVICES_ID=8 if (($in{CRITERIA_ID} eq "All")|| ($in{CRITERIA_ID} eq "all")){ $query="select null from TB_MS_CENTRES_CSS,TB_MS_SERVICES where POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound AND TB_MS_CENTRES_CSS.SERVICES_ID=TB_MS_SERVICES.SERVICES_ID"; }else{ $query="select null from TB_MS_CENTRES_CSS,TB_MS_SERVICES where POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound AND TB_MS_CENTRES_CSS.SERVICES_ID IN ($in{CRITERIA_ID}) AND TB_MS_CENTRES_CSS.SERVICES_ID=TB_MS_SERVICES.SERVICES_ID"; } } $sth = $dbh->prepare($query); $rows = $sth->execute; $sth->finish; # print"$query"; if ($rows>0) { if ($in{SERVICES_ID} == 7) { if (($in{searchSvcSector}) and ($in{searchProgType}) ){ $query="select CENTRE_ID,SERVICES_ID,POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) as distance from TB_MS_CENTRES_CSS where POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) <= $distsqbound and SERVICES_ID=7 AND PROG_TYPE='$in{searchProgType}' and SECTOR_CODE='$in{searchSvcSector}' group by CENTRE_ID order by distance"; }elsif($in{searchProgType}){ $query="select CENTRE_ID,SERVICES_ID,POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) as distance from TB_MS_CENTRES_CSS where POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) <= $distsqbound and SERVICES_ID=7 AND PROG_TYPE='$in{searchProgType}' group by CENTRE_ID order by distance"; }elsif($in{searchSvcSector}){ $query="select CENTRE_ID,SERVICES_ID,POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) as distance from TB_MS_CENTRES_CSS where POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) <= $distsqbound and SERVICES_ID=7 AND SECTOR_CODE='$in{searchSvcSector}' group by CENTRE_ID order by distance"; }else{ $query="select CENTRE_ID,SERVICES_ID,POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) as distance from TB_MS_CENTRES_CSS where POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) <= $distsqbound and SERVICES_ID=7 group by CENTRE_ID order by distance"; } }elsif($in{SERVICES_ID} == 9){ $query="select CENTRE_ID,SERVICES_ID,POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) as distance from TB_MS_CENTRES_CSS where POW(X_ADDR-$px_addr,2)+POW(Y_ADDR-$py_addr,2) <= $distsqbound and SERVICES_ID=9 group by CENTRE_ID order by distance"; }elsif($in{SERVICES_ID}==4){ if ($in{CRITERIA_ID} eq "all") {$criteria_id="";}else{$criteria_id = $in{CRITERIA_ID};} if (($in{searchFood}) and ($in{searchService}) and ($criteria_id)) { $query="select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT,TB_MS_CENTRELIST_CSS.CRITERIA_ID,POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) as distance FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD='$in{searchService}' AND TB_MS_CENTRELIST_CSS.CRITERIA_ID='$in{searchFood}' and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD AND TB_MS_CENTRELIST_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID order by distance"; }elsif(($in{searchFood}) and ($in{searchService})){ $query="select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT,TB_MS_CENTRELIST_CSS.CRITERIA_ID,POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) as distance FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD='$in{searchService}' AND TB_MS_CENTRELIST_CSS.CRITERIA_ID='$in{searchFood}' and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD and TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID order by distance"; }elsif(($in{searchFood}) and ($criteria_id)){ $query="select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT,TB_MS_CENTRELIST_CSS.CRITERIA_ID,POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) as distance FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_MS_CENTRELIST_CSS.CRITERIA_ID='$in{searchFood}' and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD and TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID order by distance"; }elsif(($in{searchService}) and ($criteria_id)){ $query="select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT,TB_MS_CENTRELIST_CSS.CRITERIA_ID,POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) as distance FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD='$in{searchService}' and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID order by distance"; }elsif(($in{searchFood})){ $query="select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT,TB_MS_CENTRELIST_CSS.CRITERIA_ID,POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) as distance FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_MS_CENTRELIST_CSS.CRITERIA_ID='$in{searchFood}' and TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID order by distance"; }elsif(($in{searchService})){ $query="select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT,POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) as distance FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD='$in{searchService}' and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID order by distance"; }elsif(($criteria_id)){ $query="select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT,POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) as distance FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID order by distance"; }else{ $query="select CENTRE_ID,CENTRE_NAME AS CENTRE_NAME,POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) as distance FROM TB_MS_CENTRES_CSS where POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound AND SERVICES_ID=4 order by distance"; } }else{ if ($in{CRITERIA_ID} eq "All") { $query="select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.SERVICES_ID,TB_MS_SERVICES.SERVICE_NAME,POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) as distance from TB_MS_CENTRES_CSS,TB_MS_SERVICES where POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound AND TB_MS_CENTRES_CSS.SERVICES_ID=TB_MS_SERVICES.SERVICES_ID ORDER by TB_MS_SERVICES.SERVICE_NAME,distance asc"; }else{ $query="select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.SERVICES_ID,TB_MS_SERVICES.SERVICE_NAME,POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) as distance from TB_MS_CENTRES_CSS,TB_MS_SERVICES where POW(TB_MS_CENTRES_CSS.X_ADDR-$px_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$py_addr,2) <= $distsqbound AND TB_MS_CENTRES_CSS.SERVICES_ID IN ($in{CRITERIA_ID}) AND TB_MS_CENTRES_CSS.SERVICES_ID=TB_MS_SERVICES.SERVICES_ID ORDER by TB_MS_SERVICES.SERVICE_NAME,distance asc"; } } #print "$query"; $sth = $dbh->prepare($query); $sth->execute; #print"row=$rows"; $rowcol = $rows; while (my $ref=$sth->fetchrow_hashref()) { if (($in{SERVICES_ID}==7)||($in{SERVICES_ID}==4)||($in{SERVICES_ID}==9)){ $CENTRE_IDS .= $ref->{'CENTRE_ID'}.","; }else{ $SERVICES_ID=$ref->{'SERVICES_ID'}; if ($SERVICES_ID==4) {$CCC .= $ref->{'CENTRE_ID'} . ",";} if($SERVICES_ID==6){$CDC .= $ref->{'CENTRE_ID'} . ",";} if($SERVICES_ID==1){$DSS .= $ref->{'CENTRE_ID'} . ",";} if($SERVICES_ID==5){$ECS .= $ref->{'CENTRE_ID'} . ",";} if($SERVICES_ID==2){#$FSC .= $ref->{'CENTRE_ID'} . ",";} $FSC .= $ref->{'CENTRE_ID'}; if($rowcol > 1){$FSC .= ",";} } if($SERVICES_ID==3){$SCS .= $ref->{'CENTRE_ID'} . ",";} if($SERVICES_ID==7){$VWO .= $ref->{'CENTRE_ID'} . ",";} } $rowcol--; #$CENTRE_NAME .=$ref->{'CENTRE_ID'}." ". $ref->{'SERVICE_NAME'}." (".sqrt($ref->{'distance'})*0.001." km) (".$SERVICES_ID.")
"; } if ($CENTRE_IDS) { substr($CENTRE_IDS,-1) = "" ; $centrelist=$CENTRE_IDS; }#end if #print"$FSC"; #if($FSC) {$FSCID=qq{};}else{$FSCID="";} #print"$FSCID"; $sth->finish; $dbh->disconnect(); if ($in{SERVICES_ID} == 7) { &SendCentresIdListForVWO($in{SERVICES_ID},$centrelist,$CENTRE_NAME) ; }elsif($in{SERVICES_ID}==4) { if ($in{CRITERIA_ID} eq "all") { &SendCentresIdList("4","null",$centrelist) ; }else{ &SendCentresIdList("4",$in{CRITERIA_ID},$centrelist) ; } }elsif($in{SERVICES_ID} == 9){ &SendCentresIdList("9","null",$centrelist) ; }else{ &SendCentresIdListForAllSearch($in{SERVICES_ID},$in{CRITERIA_ID},$CCC,$CDC,$DSS,$ECS,$FSC,$SCS,$VWO,$CENTRE_NAME) ; } }else{ &SendCentresIdList($in{SERVICES_ID},$in{CRITERIA_ID},"noresult",$CENTRE_NAME) ; }#end rows } sub search1235 { local ($dbh, $sth, $query, $count, $row, $xxx); $x_addr=$in{px_addr}*1; $y_addr=$in{py_addr}*1; $distsqbound = 1000000*$in{range}*$in{range}; use DBI(); $dbh = DBI->connect("DBI:mysql:database=mcds_new","root"); if ($in{SERVICES_ID}==2) { if ($in{CRITERIA_ID}) { $x_fsc = $x_addr ; $y_fsc = $y_addr ; &findfsc(); #print "x= $x_fsc and y = $y_fsc and id = @id_fsc"; #exit(); $_ = $in{CRITERIA_ID}; s/\bAll,\b//i; s/\b,All,\b//i; $in{CRITERIA_ID} = $_; if ($in{CRITERIA_ID} eq 'all') { $query=sprintf("SELECT null FROM TB_MS_CENTRES_CSS,TB_MS_FSC_ZONE WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$x_fsc,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$y_fsc,2) <= 25000000 and TB_MS_CENTRES_CSS.SERVICES_ID=2 AND TB_MS_FSC_ZONE.FSC_ZONE_ID=%s",,$dbh->quote(@id_fsc[0])); }else{ $query="SELECT null FROM TB_MS_CENTRELIST_CSS,TB_MS_CENTRES_CSS,TB_MS_FSC_ZONE WHERE TB_MS_CENTRELIST_CSS.CENTRE_ID=TB_MS_CENTRES_CSS.CENTRE_ID AND TB_MS_CENTRELIST_CSS.CENTRE_ID=TB_MS_FSC_ZONE.CENTRE_ID AND TB_MS_CENTRELIST_CSS.CRITERIA_ID IN ($in{CRITERIA_ID}) AND POW(TB_MS_CENTRES_CSS.X_ADDR-$x_fsc,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$y_fsc,2) <= 25000000 AND TB_MS_CENTRELIST_CSS.SERVICES_ID=2 GROUP BY TB_MS_CENTRELIST_CSS.CENTRE_ID"; } #$query="SELECT TB_MS_CENTRELIST_CSS.CENTRE_ID,TB_MS_CENTRELIST_CSS.CRITERIA_ID,TB_MS_FSC_ZONE.FSC_ZONE_ID,TB_MS_CENTRES_CSS.* FROM TB_MS_CENTRELIST_CSS,TB_MS_CENTRES_CSS,TB_MS_FSC_ZONE WHERE TB_MS_CENTRELIST_CSS.CENTRE_ID=TB_MS_CENTRES_CSS.CENTRE_ID AND TB_MS_CENTRELIST_CSS.CENTRE_ID=TB_MS_FSC_ZONE.CENTRE_ID AND TB_MS_CENTRELIST_CSS.CRITERIA_ID IN ($in{CRITERIA_ID}) GROUP BY TB_MS_CENTRELIST_CSS.CENTRE_ID"; #print $query; $sth = $dbh->prepare($query); $rows = $sth->execute; $sth->finish; if ($in{SORT_BY} eq "proximity") { $sort_by="ORDER BY distance"; }elsif(($in{SORT_BY} eq "max")&&($in{CRITERIA_ID} eq "all")){ $sort_by="ORDER BY distance"; }elsif($in{SORT_BY} eq "max"){ $sort_by="ORDER BY COUNT_CRITERIA DESC"; } if ($rows>=1) { if ($in{CRITERIA_ID} eq 'all') { for ($i=0; $iquote($id_fsc)); }else{ $query3=sprintf("SELECT TB_MS_CENTRES_CSS.CENTRE_ID,POW(TB_MS_CENTRES_CSS.X_ADDR-$x_fsc,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$y_fsc,2) as distance FROM TB_MS_CENTRES_CSS,TB_MS_FSC_ZONE WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$x_fsc,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$y_fsc,2) <= 25000000 AND TB_MS_CENTRES_CSS.SERVICES_ID=2 AND TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_FSC_ZONE.CENTRE_ID AND TB_MS_FSC_ZONE.FSC_ZONE_ID=%s $sort_by",$dbh->quote($id_fsc)); } #$query2="SELECT TB_MS_CENTRES_CSS.CENTRE_ID,POW(TB_MS_CENTRES_CSS.X_ADDR-$x_fsc,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$y_fsc,2) as distance FROM TB_MS_CENTRES_CSS,TB_MS_FSC_ZONE WHERE POW(TB_MS_CENTRES_CSS.X_ADDR-$x_fsc,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$y_fsc,2) <= 25000000 AND TB_MS_CENTRES_CSS.SERVICES_ID=2 AND TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_FSC_ZONE.CENTRE_ID $sort_by"; #print "
".$query3."
"; #exit(); $sth = $dbh->prepare($query3); $sth->execute; $FSC_IN=0; while(my $ref=$sth->fetchrow_hashref()){ $CENTRES_ID=$ref->{'CENTRE_ID'}; $CENTRE_NAME .=$ref->{'CENTRE_ID'}." ".$ref->{'CENTRE_NAME'}."(".sqrt($ref->{'distance'})*0.001." km) and Services match".$ref->{'COUNT_CRITERIA'}.", ZONE=".$ref->{'FSC_ZONE_ID'}."
";#." $x_fsc and ".$ref->{'Y_ADDR'}." = $y_fsc
"; if ($ref->{'FSC_ZONE_ID'}==$id_fsc){ $FSC_INS .=$CENTRES_ID.","; }else { $CENTRES_IDS .=$CENTRES_ID.","; } }# end of while #print "
fsc=".$FSC_INS."
"; #print "
centre id=".$CENTRES_IDS; } }else{ $query2="SELECT count(TB_MS_CENTRELIST_CSS.CRITERIA_ID) as COUNT_CRITERIA,POW(TB_MS_CENTRES_CSS.X_ADDR-$x_fsc,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$y_fsc,2) as distance,TB_MS_CENTRES_CSS.X_ADDR,TB_MS_CENTRES_CSS.Y_ADDR,TB_MS_CENTRELIST_CSS.CRITERIA_ID,TB_MS_CENTRELIST_CSS.CENTRE_ID,TB_MS_CENTRELIST_CSS.CRITERIA_ID,TB_MS_FSC_ZONE.FSC_ZONE_ID FROM TB_MS_CENTRELIST_CSS,TB_MS_CENTRES_CSS,TB_MS_FSC_ZONE WHERE TB_MS_CENTRELIST_CSS.CENTRE_ID=TB_MS_CENTRES_CSS.CENTRE_ID AND TB_MS_CENTRELIST_CSS.CENTRE_ID=TB_MS_FSC_ZONE.CENTRE_ID AND TB_MS_CENTRELIST_CSS.CRITERIA_ID IN ($in{CRITERIA_ID}) AND POW(TB_MS_CENTRES_CSS.X_ADDR-$x_fsc,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$y_fsc,2) <= 25000000 AND TB_MS_CENTRELIST_CSS.SERVICES_ID=2 GROUP BY TB_MS_CENTRELIST_CSS.CENTRE_ID $sort_by "; $sth = $dbh->prepare($query2); $sth->execute; $FSC_IN=0; while(my $ref=$sth->fetchrow_hashref()){ $CENTRES_ID=$ref->{'CENTRE_ID'}; $CENTRE_NAME .=$ref->{'CENTRE_ID'}." ".$ref->{'CENTRE_NAME'}."(".sqrt($ref->{'distance'})*0.001." km) and Services match".$ref->{'COUNT_CRITERIA'}.", ZONE=".$ref->{'FSC_ZONE_ID'}."
";#." $x_fsc and ".$ref->{'Y_ADDR'}." = $y_fsc
"; if ($ref->{'FSC_ZONE_ID'}==$id_fsc){ $FSC_INS .=$CENTRES_ID.","; }else { $CENTRES_IDS .=$CENTRES_ID.","; } }# end of while #print "
2fsc=".$FSC_INS."
"; #print "
2centre id=".$CENTRES_IDS; } #print "
$query2"; if ($CENTRES_IDS) { substr($CENTRES_IDS,-1) = "" ; $CENTRES_IDS=$CENTRES_IDS; } if ($FSC_INS) { substr($FSC_INS,-1) = "" ; $FSC_INS=$FSC_INS; } if ($FSC_INS ne "0") { &SendCentresIdFSCList($in{SERVICES_ID},$in{CRITERIA_ID},$FSC_INS,$CENTRES_IDS,$CENTRE_NAME) ; }else{ &SendCentresIdFSCList($in{SERVICES_ID},$in{CRITERIA_ID},"0",$CENTRES_IDS,$CENTRE_NAME) ; } }else { &SendCentresIdFSCList($in{SERVICES_ID},$in{CRITERIA_ID},"0") ; } $sth->finish; }#END CRITERIA }elsif(($in{SERVICES_ID}==5) || ($in{SERVICES_ID}==1) || ($in{SERVICES_ID}==3)){ $ServiceId=$in{SERVICES_ID}; $CriteriaId=$in{CRITERIA_ID}; if ($in{CRITERIA_ID} eq 'all') { $query=sprintf("SELECT null FROM TB_MS_CENTRES_CSS,TB_MS_CENTRELIST_CSS,TB_MS_CRITERIA WHERE (POW(TB_MS_CENTRES_CSS.X_ADDR-$x_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$y_addr,2) <= $distsqbound AND (TB_MS_CRITERIA.CRITERIA_ID = TB_MS_CENTRELIST_CSS.CRITERIA_ID) AND (TB_MS_CENTRELIST_CSS.CENTRE_ID = TB_MS_CENTRES_CSS.CENTRE_ID) AND (TB_MS_CENTRES_CSS.SERVICES_ID=%s)) group by TB_MS_CENTRES_CSS.CENTRE_ID",$dbh->quote($ServiceId)); }else{ $query=sprintf("SELECT null FROM TB_MS_CENTRES_CSS,TB_MS_CENTRELIST_CSS,TB_MS_CRITERIA WHERE (POW(TB_MS_CENTRES_CSS.X_ADDR-$x_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$y_addr,2) <= $distsqbound AND (TB_MS_CRITERIA.CRITERIA_ID = TB_MS_CENTRELIST_CSS.CRITERIA_ID) AND (TB_MS_CENTRELIST_CSS.CENTRE_ID = TB_MS_CENTRES_CSS.CENTRE_ID) AND (TB_MS_CENTRES_CSS.SERVICES_ID=%s) AND TB_MS_CRITERIA.CRITERIA_ID IN ($CriteriaId)) group by TB_MS_CENTRES_CSS.CENTRE_ID",$dbh->quote($ServiceId)); } #print "$query
"; $sth = $dbh->prepare($query); $rows = $sth->execute; if ($rows>=1) { if ($in{CRITERIA_ID} eq 'all') { $query=sprintf("SELECT TB_MS_CENTRES_CSS.CENTRE_ID FROM TB_MS_CENTRES_CSS,TB_MS_CENTRELIST_CSS,TB_MS_CRITERIA WHERE (POW(TB_MS_CENTRES_CSS.X_ADDR-$x_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$y_addr,2) <= $distsqbound AND (TB_MS_CRITERIA.CRITERIA_ID = TB_MS_CENTRELIST_CSS.CRITERIA_ID) AND (TB_MS_CENTRELIST_CSS.CENTRE_ID = TB_MS_CENTRES_CSS.CENTRE_ID) AND (TB_MS_CENTRES_CSS.SERVICES_ID=%s)) group by TB_MS_CENTRES_CSS.CENTRE_ID",$dbh->quote($ServiceId)); }else{ $query=spirntf("SELECT TB_MS_CENTRES_CSS.CENTRE_ID FROM TB_MS_CENTRES_CSS,TB_MS_CENTRELIST_CSS,TB_MS_CRITERIA WHERE (POW(TB_MS_CENTRES_CSS.X_ADDR-$x_addr,2)+POW(TB_MS_CENTRES_CSS.Y_ADDR-$y_addr,2) <= $distsqbound AND (TB_MS_CRITERIA.CRITERIA_ID = TB_MS_CENTRELIST_CSS.CRITERIA_ID) AND (TB_MS_CENTRELIST_CSS.CENTRE_ID = TB_MS_CENTRES_CSS.CENTRE_ID) AND (TB_MS_CENTRES_CSS.SERVICES_ID=%s) AND TB_MS_CRITERIA.CRITERIA_ID IN ($CriteriaId)) group by TB_MS_CENTRES_CSS.CENTRE_ID",$dbh->quote($ServiceId)); } $sth = $dbh->prepare($query); $sth->execute; while(my $ref=$sth->fetchrow_hashref()){ $CENTRES_ID= $ref->{'CENTRE_ID'}; $CENTRES_IDS .=$CENTRES_ID.","; }#end of while if ($CENTRES_IDS) { substr($CENTRES_IDS,-1) = "" ; $centrelist=$CENTRES_IDS; } $sth->finish; #rint"$query"; &SendCentresIdList($ServiceId,$CriteriaId,$CENTRES_IDS) ; }else{#if rows=0 &SendCentresIdList($ServiceId,$CriteriaId,"noresult") ; } #print"$query $rows
$centrelist"; $sth->finish; }#end SERVICES_ID $dbh->disconnect(); } #End postal_code ##################################################################### # ***************************VWO SEARCH************************** #***************** Search for VWO without Street and Postalcode***** #################################################################### sub search_VWO{ local ($dbh, $sth, $query, $count, $rows); use DBI(); $dbh = DBI->connect("DBI:mysql:database=mcds_new","root"); if (($in{searchSvcSector}) and ($in{searchProgType}) ){ $query=sprintf("select null from TB_MS_CENTRES_CSS where SERVICES_ID=7 AND PROG_TYPE=%s and SECTOR_CODE=%s group by CENTRE_ID",$dbh->quote($in{searchProgType}),$dbh->quote($in{searchSvcSector})); }elsif($in{searchProgType}){ $query=sprintf("select null from TB_MS_CENTRES_CSS where SERVICES_ID=7 AND PROG_TYPE=%s group by CENTRE_ID",$dbh->quote($in{searchProgType})); }elsif($in{searchSvcSector}){ $query=sprintf("select null from TB_MS_CENTRES_CSS where SERVICES_ID=7 AND SECTOR_CODE=%s group by CENTRE_ID",$dbh->quote($in{searchSvcSector})); }else{ $query="select null from TB_MS_CENTRES_CSS where SERVICES_ID=7 group by CENTRE_ID"; } $sth = $dbh->prepare($query); $rows=$sth->execute; #rint"$query"; $sth->finish; if ($rows>1) { if (($in{searchSvcSector}) and ($in{searchProgType}) ){ $query=sprintf("select CENTRE_ID,SERVICES_ID from TB_MS_CENTRES_CSS where SERVICES_ID=7 AND PROG_TYPE=%s and SECTOR_CODE=%s group by CENTRE_ID order by CENTRE_NAME",$dbh->quote($in{searchProgType}),$dbh->quote($in{searchSvcSector})); }elsif($in{searchProgType}){ $query=sprintf("select CENTRE_ID,SERVICES_ID from TB_MS_CENTRES_CSS where SERVICES_ID=7 AND PROG_TYPE=%s group by CENTRE_ID order by CENTRE_NAME",$dbh->quote($in{searchProgType})); }elsif($in{searchSvcSector}){ $query=sprintf("select CENTRE_ID,SERVICES_ID from TB_MS_CENTRES_CSS where SERVICES_ID=7 AND SECTOR_CODE=%s group by CENTRE_ID order by CENTRE_NAME",$dbh->quote($in{searchSvcSector})); }else{ $query="select CENTRE_ID,SERVICES_ID from TB_MS_CENTRES_CSS where SERVICES_ID=7 group by CENTRE_ID order by CENTRE_NAME"; } $sth = $dbh->prepare($query); $sth->execute; while (my $ref=$sth->fetchrow_hashref()) { $CENTRES_ID= $ref->{'CENTRE_ID'}; $CENTRES_IDS .=$CENTRES_ID.","; }#end of while if ($CENTRES_IDS) { substr($CENTRES_IDS,-1) = "" ; $centrelist=$CENTRES_IDS; } $sth->finish; &SendCentresIdListForVWO("7",$centrelist,$CENTRE_NAME) ; #rint"$query"; }else{ &SendCentresIdListForVWO("7","noresult",$CENTRE_NAME) ; }### Endif $rows $dbh->disconnect(); } ################################################################## # ***************************FSC SEARCH************************** #***************** Selects programmes only and do a search***** #################################################################### sub search_for_services { local ($dbh, $sth, $query, $count, $row, $xxx); &checkcriteria22(); #### Find centre ID that match services inputed use DBI(); $dbh = DBI->connect("DBI:mysql:database=mcds_new","root"); if ($in{SERVICES_ID} eq "FSC") { $query="SELECT count(*) FROM TB_MS_CENTRELIST_CSS,TB_MS_CENTRES_CSS WHERE TB_MS_CENTRELIST_CSS.CRITERIA_ID IN ($in{CRITERIA_ID}) AND TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID group by TB_MS_CENTRES_CSS.CENTRE_ID"; }else{ if ($in{CRITERIA_ID} eq "all") { $criteria_id=""; } if (($in{searchFood}) and ($in{searchService}) and ($criteria_id)) { $query=sprintf("select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD=%s AND TB_MS_CENTRELIST_CSS.CRITERIA_ID=%s and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD AND TB_MS_CENTRELIST_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID",$dbh->quote($in{searchService}),$dbh->quote($in{searchFood})); }elsif(($in{searchFood}) and ($in{searchService})){ $query=sprintf("select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD=%s AND TB_MS_CENTRELIST_CSS.CRITERIA_ID=%s and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD and TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID",$dbh->quote($in{searchService}),$dbh->quote($in{searchFood})); }elsif(($in{searchFood}) and ($criteria_id)){ $query=sprintf("select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE TB_MS_CENTRELIST_CSS.CRITERIA_ID=%s and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD and TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID",$dbh->quote($in{searchFood})); }elsif(($in{searchService}) and ($criteria_id)){ $query=sprintf("select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD=%s and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID",$dbh->quote($in{searchService})); }elsif(($in{searchFood})){ $query=sprintf("select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE TB_MS_CENTRELIST_CSS.CRITERIA_ID=%s and TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID",$dbh->quote($in{searchFood})); }elsif(($in{searchService})){ $query=sprintf("select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL WHERE TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD=%s and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID",$dbh->quote($in{searchService})); }elsif(($criteria_id)){ $query="select count(*) FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL WHERE TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID;"; }else{ $query="select count(*) FROM TB_MS_CENTRES_CSS WHERE SERVICES_ID=4"; } } $sth = $dbh->prepare($query); $rows=$sth->execute; $sth->finish; if ($rows>0) { if ($in{SERVICES_ID} eq "FSC") { $query="SELECT TB_MS_CENTRELIST_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME FROM TB_MS_CENTRELIST_CSS,TB_MS_CENTRES_CSS WHERE TB_MS_CENTRELIST_CSS.CRITERIA_ID IN ($in{CRITERIA_ID}) AND TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID group by TB_MS_CENTRES_CSS.CENTRE_ID ORDER BY CENTRE_NAME ASC"; }else{ if ($in{CRITERIA_ID} eq "all") { $criteria_id=""; } if (($in{searchFood}) and ($in{searchService}) and ($criteria_id)) { $query=sprintf("select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT,TB_MS_CENTRELIST_CSS.CRITERIA_ID FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD=%s AND TB_MS_CENTRELIST_CSS.CRITERIA_ID=%s and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD AND TB_MS_CENTRELIST_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID ORDER BY CENTRE_NAME ASC",$dbh->quote($in{searchService}),$dbh->quote($in{searchFood})); }elsif(($in{searchFood}) and ($in{searchService})){ $query=sprintf("select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT,TB_MS_CENTRELIST_CSS.CRITERIA_ID FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD=%s AND TB_MS_CENTRELIST_CSS.CRITERIA_ID=%s and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD and TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID ORDER BY CENTRE_NAME ASC",$dbh->quote($in{searchService}),$dbh->quote($in{searchFood})); }elsif(($in{searchFood}) and ($criteria_id)){ $query=sprintf("select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT,TB_MS_CENTRELIST_CSS.CRITERIA_ID FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE TB_MS_CENTRELIST_CSS.CRITERIA_ID=%s and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD and TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID ORDER BY CENTRE_NAME ASC",$dbh->quote($in{searchFood})); }elsif(($in{searchService}) and ($criteria_id)){ $query=sprintf("select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT,TB_MS_CENTRELIST_CSS.CRITERIA_ID FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD=%s and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID ORDER BY CENTRE_NAME ASC",$dbh->quote($in{searchService})); }elsif(($in{searchFood})){ $query=sprintf("select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT,TB_MS_CENTRELIST_CSS.CRITERIA_ID FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL,TB_MS_CENTRELIST_CSS WHERE TB_MS_CENTRELIST_CSS.CRITERIA_ID=%s and TB_MS_CENTRES_CSS.CENTRE_ID=TB_MS_CENTRELIST_CSS.CENTRE_ID GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID ORDER BY CENTRE_NAME ASC",$dbh->quote($in{searchFood})); }elsif(($in{searchService})){ $query=sprintf("select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL WHERE TB_CHILDCARE_FEE_DTL.SERVICE_TYPE_CD=%s and TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID ORDER BY CENTRE_NAME ASC",$dbh->quote($in{searchService})); }elsif(($criteria_id)){ $query="select TB_MS_CENTRES_CSS.CENTRE_ID,TB_MS_CENTRES_CSS.CENTRE_NAME AS CENTRE_NAME,TB_CHILDCARE_FEE_DTL.FEE_AMT FROM TB_MS_CENTRES_CSS,TB_CHILDCARE_FEE_DTL WHERE TB_MS_CENTRES_CSS.CENTRE_ID=TB_CHILDCARE_FEE_DTL.CENTRE_CD $rangeprice GROUP BY TB_MS_CENTRES_CSS.CENTRE_ID ORDER BY CENTRE_NAME ASC"; }else{ $query="select CENTRE_ID,CENTRE_NAME AS CENTRE_NAME FROM TB_MS_CENTRES_CSS WHERE SERVICES_ID=4 ORDER BY CENTRE_NAME ASC"; } } $sth = $dbh->prepare($query); $sth->execute; while (my $ref=$sth->fetchrow_hashref()) { $CENTRES_ID= $ref->{'CENTRE_ID'}; $CENTRE_NAME= $ref->{'CENTRE_NAME'}; $CENTRES_IDS .=$CENTRES_ID.","; #print"$CENTRE_NAME
"; }#end of while if ($CENTRES_IDS) { substr($CENTRES_IDS,-1) = "" ; $centrelist=$CENTRES_IDS; } $sth->finish; $dbh->disconnect(); if ($in{SERVICES_ID}==2) { &SendCentresIdFSCList(2,$in{CRITERIA_ID},"0",$centrelist,$CENTRE_NAME) ; }else{ if (($in{SERVICES_ID}==4) && ($in{CRITERIA_ID} eq "all")) { $in{CRITERIA_ID}="null"; } &SendCentresIdList("4",$in{CRITERIA_ID},$centrelist) ; } &printfooter(); }else{ &SendCentresIdList(8,$services_id_new,"noresult",$CENTRE_NAME) ; &printfooter(); }### Endif $rows } sub checkcriteria22{ if ($in{CRITERIA_ID}==22) { $rangeprice="and TB_CHILDCARE_FEE_DTL.FEE_AMT BETWEEN 100 AND 199"; }elsif($in{CRITERIA_ID}==23){ $rangeprice="and TB_CHILDCARE_FEE_DTL.FEE_AMT BETWEEN 200 AND 299"; }elsif($in{CRITERIA_ID}==30){ $rangeprice="and TB_CHILDCARE_FEE_DTL.FEE_AMT BETWEEN 300 AND 399"; }elsif($in{CRITERIA_ID}==31){ $rangeprice="and TB_CHILDCARE_FEE_DTL.FEE_AMT BETWEEN 400 AND 499"; }elsif($in{CRITERIA_ID}==32){ $rangeprice="and TB_CHILDCARE_FEE_DTL.FEE_AMT BETWEEN 500 AND 599"; }elsif($in{CRITERIA_ID}==33){ $rangeprice="and TB_CHILDCARE_FEE_DTL.FEE_AMT BETWEEN 600 AND 699"; }elsif($in{CRITERIA_ID}==34){ $rangeprice="and TB_CHILDCARE_FEE_DTL.FEE_AMT BETWEEN 700 AND 799"; }elsif($in{CRITERIA_ID}==35){ $rangeprice="and TB_CHILDCARE_FEE_DTL.FEE_AMT BETWEEN 800 AND 899"; }elsif($in{CRITERIA_ID}==36){ $rangeprice="and TB_CHILDCARE_FEE_DTL.FEE_AMT BETWEEN 900 AND 1000"; }else{ $rangeprice="and TB_CHILDCARE_FEE_DTL.FEE_AMT >1000"; } } #### POSTAL ############################################################################################################################ #### STREET SEARCH ############################################################################################################################ sub search_streetname { use DBI(); $dbh = DBI->connect("DBI:mysql:database=vm_singapore_new","root"); $in{blockno} = $in{searchNo} ; $in{roadname} = $in{searchStreet} ; $_ = $in{roadname}; s/\bave\b/avenue/i; s/\brd\b/road/i; s/\bst\b/street/i; $in{roadname} = $_; $_ = $in{blockno}; s/\bblk\b//i; s/\bblock\b//i; s/\bno\b//i; s/ //i; $in{blockno} = $_; $LimitSearch = "50" ; #if ($in{SERVICES_ID} eq 'FSC') { # $LimitSearch = "1" ; #} my $roadname1=&substitute_quote($in{roadname}); $roadname1=~s/^\s+//; $roadname1=~s/\s+$//; $roadname1=~s/\s{2,}/ /g; if ($in{blockno}) { $sqlquery = sprintf(qq{ SELECT sg_full.x_addr, sg_full.y_addr from vm_singapore_new.sg_full where (is_main_building = -1 OR is_main_building =1) AND block=%s and (streetname like %s) group by SUBSTRING(postal, 1, 2), streetname limit 0,$LimitSearch }, $dbh->quote($in{blockno}), $dbh->quote("%".$roadname1."%") ); #SELECT sg_link.x_addr, sg_link.y_addr #FROM vm_singapore_new.sg_address INNER JOIN vm_singapore_new.sg_link ON sg_address.address_id = sg_link.address_id #INNER JOIN vm_singapore_new.sg_place ON sg_place.place_id = sg_link.place_id #WHERE #(sg_place.is_main_building = -1 OR sg_place.is_main_building =1) AND block='$in{blockno}' and (sg_address.streetname like '%$roadname1%' or sg_address.streetname like '%$roadname1%') group by SUBSTRING(sg_address.postal, 1, 2), streetname limit 0,$LimitSearch } else { $sqlquery = sprintf(qq{ SELECT sg_full.x_addr, sg_full.y_addr from sg_full where (is_main_building = -1 OR is_main_building =1) AND (streetname like %s) group by SUBSTRING(postal, 1, 2), streetname limit 0,$LimitSearch }, $dbh->quote("%".$roadname1."%") ); #SELECT sg_link.x_addr, sg_link.y_addr #FROM vm_singapore_new.sg_address INNER JOIN vm_singapore_new.sg_link ON sg_address.address_id = sg_link.address_id #INNER JOIN vm_singapore_new.sg_place ON sg_place.place_id = sg_link.place_id #WHERE #(sg_place.is_main_building = -1 OR sg_place.is_main_building =1) AND (sg_address.streetname like '%$roadname1 %' or sg_address.streetname like '%$roadname1%') group by SUBSTRING(sg_address.postal, 1, 2), streetname limit 0,$LimitSearch } #print"
here $sqlquery"; $sth = $dbh->prepare($sqlquery); $sth->execute; my $ref=$sth->fetchrow_hashref(); $in{px_addr}= $ref->{'x_addr'}; $in{py_addr}= $ref->{'y_addr'}; $sth->finish; $dbh->disconnect(); #print"$count and $sqlquery"; if ($in{px_addr}) { if (($in{SERVICES_ID}==8) || ($in{SERVICES_ID}==7) ||($in{SERVICES_ID}==4)||($in{SERVICES_ID}==9)){ &search4789() ; }else{ &search1235() ; } } else { #&SendCentresIdList($ServiceId,$CriteriaId,"no-$in{roadname}$blocknok") ; &SendCentresIdList($ServiceId,$CriteriaId,"Invalid") ; } } sub substitute_quote { local ($_) = @_; s/\'/\\\'/g; $_; } #######################################to Call Javascript################################################## #GET looping icon/xylist sub getscript{ local($x,$y,$index)=@_; $java=sprintf qq{ MapAPI.addOverlay(new MapIcon(new Vertex($x,$y),$index)); }; return $java; } #print draw map java script sub scriptloadmap{ $javascript=sprintf qq{ }; return $javascript; } ##print zone java script sub scriptzone{ $scriptzone=sprintf qq{ };} ### Print Nearby java script sub scriptnearby{ $iconhere=qq{ var iconno = "http://$ENV{'HTTP_HOST'}/data/icons/star11.gif"; var icon = new MapMarker(new Vertex($in{x},$in{y}), {icon:new Icon({iconSize:new Size(70 ,24),image:iconno})}); MapAPI.addOverlay(icon); }; $scriptnearby=sprintf qq{ }; } ###Print Empty Java script sub emptyjs{ print qq{ }; }