#!/usr/bin/perl use strict; use vars qw(%c %d %s %w %q %session_cookie %html %data); use Template; use HTML::Entities; use CGI; use FG::Utils; use FG::Listing; use FG::Gift_Detail; use FG::Search; use FG::Cookies; use Data::Dumper; use FG::Calendar; FG::Utils::detect_fg_mobile(\%w); #print "Content-type: text/html\n\n"; #### Define environment variables #### require '/www/findgift.com/cgi-bin/modules/Init_Web_Env.pl'; use constant NUM_CATEGORIES => 48; use constant NUM_GIFTS_PER_ROW => 5; use constant VWO_GIFTS_PER_ROW => 1; use constant PAGE_NUM_FOR_NIF_TAG => 2; $w{'page'}{'base_path'} = 'Home > '; # Do the cookie setting business that was being done in Init_Web_Env.pl # Just copying exactly what was being done in that script. # These variables are used in that process. my $ip = &fetch_visitor_remote_address(); $ip =~ s/[^0-9\.]//g; my $user; my $robot = &check_for_robot_ip($ip); $data{'base_script'} = $ENV{'SCRIPT_NAME'}; $data{'base_script'} =~ s/^\///; $data{'base_script'} =~ s/\/$//; #### Get search variables #### my $path_info = $ENV{'PATH_INFO'}; if (substr($path_info, (length($path_info) - 1), 1) ne '/') { $path_info .= '/'; } $data{'url'} = '/' . $data{'base_script'} . $path_info; my $query_str = $ENV{'QUERY_STRING'}; $data{'page'} = (split /\//, (split /\/p-/, $path_info)[1])[0]; $data{'page'} =~ s/[^0-9]//g; $path_info =~ s/\/p\-[0-9]+\//\//; # If this is a URL that has the page number as part of the extra path info, redirect # to a URL that has it in the query string. &redirect_page_in_url($data{'page'}) if ($data{'page'} > 0); $data{'page_url'} = '/' . $data{'base_script'} . $path_info; #### Define 301 redirects #### my %r301 = ( '/Birthday/Kids/Girls/' => '/Birthday/Girls/', '/Birthday/Kids/Girls/Ages-1-2/' => '/Birthday/Girls/Ages-1-2/', '/Birthday/Kids/Girls/Ages-3-4/' => '/Birthday/Girls/Ages-3-4/', '/Birthday/Kids/Girls/Ages-5-6/' => '/Birthday/Girls/Ages-5-6/', '/Birthday/Kids/Girls/Ages-7-8/' => '/Birthday/Girls/Ages-7-8/', '/Birthday/Kids/Girls/Ages-9-10/' => '/Birthday/Girls/Ages-9-10/', '/Birthday/Tweens/Girls/' => '/Birthday/Girls/Ages-11-12/', '/Birthday/Kids/Boys/' => '/Birthday/Boys/', '/Birthday/Kids/Boys/Ages-1-2/' => '/Birthday/Boys/Ages-1-2/', '/Birthday/Kids/Boys/Ages-3-4/' => '/Birthday/Boys/Ages-3-4/', '/Birthday/Kids/Boys/Ages-5-6/' => '/Birthday/Boys/Ages-5-6/', '/Birthday/Kids/Boys/Ages-7-8/' => '/Birthday/Boys/Ages-7-8/', '/Birthday/Kids/Boys/Ages-9-10/' => '/Birthday/Boys/Ages-9-10/', '/Birthday/Tweens/Boys/' => '/Birthday/Boys/Ages-11-12/', '/Birthday/Teens/Girls/' => '/Birthday/Teen-Girls/', '/Birthday/Teens/Boys/' => '/Birthday/Teen-Boys/', '/Christmas/for-Babies/' => '/Christmas/', '/Christmas/for-Kids/' => '/Christmas/', '/Christmas/for-Teens/' => '/Christmas/', '/Christmas/for-Babies/Baby-Girl/' => '/Christmas/Baby-Girls/', '/Christmas/for-Kids/for-Girls/' => '/Christmas/Girls/', '/Christmas/for-Kids/for-Girls/Ages-1-2/' => '/Christmas/Girls/Ages-1-2/', '/Christmas/for-Kids/for-Girls/Ages-3-4/' => '/Christmas/Girls/Ages-3-4/', '/Christmas/for-Kids/for-Girls/Ages-5-6/' => '/Christmas/Girls/Ages-5-6/', '/Christmas/for-Kids/for-Girls/Ages-7-8/' => '/Christmas/Girls/Ages-7-8/', '/Christmas/for-Kids/for-Girls/Ages-9-10/' => '/Christmas/Girls/Ages-9-10/', '/Christmas/for-Kids/for-Girls/Ages-11-12/' => '/Christmas/Girls/Ages-11-12/', '/Christmas/for-Teens/for-Her/' => '/Christmas/Teen-Girls/', '/Christmas/for-Babies/Baby-Boy/' => '/Christmas/Baby-Boys/', '/Christmas/for-Kids/for-Boys/' => '/Christmas/Boys/', '/Christmas/for-Kids/for-Boys/Ages-1-2/' => '/Christmas/Boys/Ages-1-2/', '/Christmas/for-Kids/for-Boys/Ages-3-4/' => '/Christmas/Boys/Ages-3-4/', '/Christmas/for-Kids/for-Boys/Ages-5-6/' => '/Christmas/Boys/Ages-5-6/', '/Christmas/for-Kids/for-Boys/Ages-7-8/' => '/Christmas/Boys/Ages-7-8/', '/Christmas/for-Kids/for-Boys/Ages-9-10/' => '/Christmas/Boys/Ages-9-10/', '/Christmas/for-Kids/for-Boys/Ages-11-12/' => '/Christmas/Boys/Ages-11-12/', '/Christmas/for-Teens/for-Him/' => '/Christmas/Teen-Boys/', '/Chanukah/for-Babies/' => '/Chanukah/', '/Chanukah/for-Kids/' => '/Chanukah/', '/Chanukah/for-Babies/for-Girls/' => '/Chanukah/Baby-Girls/', '/Chanukah/for-Babies/for-Boys/' => '/Chanukah/Baby-Boys/', '/Chanukah/for-Kids/for-Girls/' => '/Chanukah/Girls/', '/Chanukah/for-Kids/for-Boys/' => '/Chanukah/Boys/', '/Valentines-Day/for-Kids/' => '/Valentines-Day/', '/Valentines-Day/for-Teenagers/' => '/Valentines-Day/', '/Valentines-Day/for-Kids/for-Boys/' => '/Valentines-Day/for-Boys/', '/Valentines-Day/for-Kids/for-Girls/' => '/Valentines-Day/for-Girls/', '/Valentines-Day/for-Teenagers/for-Boyfriend/' => '/Valentines-Day/Teen-Boyfriend/', '/Valentines-Day/for-Teenagers/for-Girlfriend/' => '/Valentines-Day/Teen-Girlfriend/', '/Apparel/Baby-Clothes/' => '/Apparel/', '/Apparel/Kids-Clothes/' => '/Apparel/', '/Apparel/for-Teens/' => '/Apparel/', '/Apparel/Baby-Clothes/for-Baby-Girls/' => '/Apparel/Baby-Girls/', '/Apparel/Kids-Clothes/for-Girls/' => '/Apparel/Girls/', '/Apparel/for-Teens/Teenage-Girls/' => '/Apparel/Teen-Girls/', '/Apparel/Baby-Clothes/for-Baby-Boys/' => '/Apparel/Baby-Boys/', '/Apparel/Kids-Clothes/for-Boys/' => '/Apparel/Boys/', '/Apparel/for-Teens/Teenage-Boys/' => '/Apparel/Teen-Boys/', '/Special-Themes/Gag-Gifts/' => '/Gag-Gifts/', '/Toys/Games/' => '/Leisure/Games/', '/him/fathers-day/' => '/fathers-day/$', '/her/mothers-day/' => '/mothers-day/$', '/her/sisters-day/' => '/sisters-day/$', '/couple/sisters-day/' => '/sisters-day/$', ); # The system thinks these vectors are hex numbers! # explicitly tell it they're not # Vales defined in this hash should not be considered as vectors. my %okay_vectors = ( 'dad' => 1, 'gag' => 1, 'beaded' => 1, 'beef' => 1 ); $data{'price_ids'} = (split /\//, (split /\/prcid-/, $path_info)[1])[0]; $data{'price_ids'} =~ s/[^0-9]//g; $path_info =~ s/\/prcid\-[0-9]+\//\//; my $vector_path = (split /\/gs\//, $path_info)[1]; if ($vector_path ne '') { $data{'vector'} = $vector_path; $data{'vector'} =~ s/[^0-9x\-\/]//g; $data{'non_encoded_vector'} = $data{'vector'}; # Need this to provide 301 Redirect later $data{'vector'} =~ s/\/$//; $data{'vector'} =~ s/\//:/g; $data{'vector'} =~ s/\-/,/g; $data{'found_non_encoded_vector'} = 1; $path_info = (split /\/gs\//, $path_info)[0] . '/'; } else { my $path_string = $path_info; $path_string =~ s/^\///; $path_string =~ s/\/$//; my @path_segments = (split /\//, $path_string); my $vector_path = pop @path_segments; if (($vector_path !~ /[^0-9abcdefgvzx]/) && (!defined($okay_vectors{$vector_path}))) { $data{'vector'} = FG::Search::decode_vector($vector_path); $data{'enc_vector'} = $vector_path; if ($data{'vector'} ne '-1') { $path_info = '/' . (join '/', @path_segments) . '/'; $data{'found_encoded_vector'} = 1; $data{'vector'} = FG::Search::decode_vector($vector_path); } #endif } #endif } #endif $data{'page'} = FG::CGI_IO::pos_int($w{'query'}, 'p') unless ($data{'page'} > 0); $data{'page'} = 1 unless ($data{'page'} > 0); $data{'directory'} = $path_info; if ($r301{$data{'directory'}} ne '') { my $go_to = $s{'com'}{'web'} . '/' . $data{'base_script'}; my $add_vector = 1; if(substr($r301{$data{'directory'}},-1) == '$') { $add_vector = 0; $r301{$data{'directory'}} = substr($r301{$data{'directory'}},0,-1); } $go_to .= $r301{$data{'directory'}}; $go_to .= $data{'enc_vector'} . '/' if ($data{'enc_vector'} ne '' && $add_vector); FG::Utils::redirect_301($go_to); exit(0); } #endif #### Connect to Search DB #### &connect_to_db('schdb'); if ($data{'directory'} eq '' || $data{'directory'} eq '/') { &view_directory_start_page(); } else { &view_directory(); } #### Exit #### exit(0); sub view_directory_start_page { # Okay to set the cookie here because there are no redirects associated with start pages. if ($robot != 1) { my $q = CGI::new(); $user = &set_visit_cookie($q); $w{'user'} = $user; } #### Fetch data #### if ($data{'base_script'} eq 'categories') { &fetch_main_categories_menu_data(1, $data{'base_script'}, 50); } elsif ($data{'base_script'} eq 'express-yourself') { &fetch_main_categories_menu_data(8, $data{'base_script'}, 50); } elsif ($data{'base_script'} eq 'for-who') { &fetch_main_categories_menu_data(6, $data{'base_script'}, 50); } elsif ($data{'base_script'} eq 'gift-types') { &fetch_main_categories_menu_data(5, $data{'base_script'}, 50); } elsif ($data{'base_script'} eq 'occasions') { &fetch_main_categories_menu_data(3, $data{'base_script'}, 50); } my $total_choices = $data{'total_overview_menu'} * 5 + $data{'total_overview_subs'}; my $col_length = int($total_choices / 2 + 1); #if this is for Gift-Types use 3 columns if ($data{'class_ids'} == 5) { $col_length = int($total_choices / 3 + 1); } my $tpl_path = '/www/findgift.com/templates/'.$data{'base_script'}."/"; my $uri = $ENV{'REQUEST_URI'}; my %prod_cookie; $prod_cookie{url} = $uri; FG::Cookies::set_prod_session_cookie(\%prod_cookie, $w{'query'}); FG::Widgets::fetch_html_insert($d{'hndl'}{'fgdb'}, \%d, \%html, 21); my %msp; if ($data{'base_script'} eq 'anniversary-table') { FG::Widgets::fetch_html_insert($d{'hndl'}{'fgdb'}, \%d, \%html, 18); #### Get MSP If Required #### $data{'msps_per_page'} = 14; $data{'page'} = 1; $data{'wiz_id'} = 249; $data{'using_cache'} = 1; $data{'vector'} = 'x:x:x:936:x:x:x:x:x'; my $suffix = '&sctnid=180&p=1&pageid=0&src=10'; FG::MSP::fetch_msp_data($d{'hndl'}{'schdb'}, \%d, \%s, \%c, \%msp, \%data, \$suffix); # Append the page this MSP was displayed on so we can track it if it gets clicked. FG::MSP::append_cpc_url(\%msp, '&from_page=10'); ## Must have at least 3 or show none if ($msp{'num_msps'} < 3 ) { %msp = (); }#endif } if ($msp{'num_msps'} > 0){ #Do we have any MSPs displayed? my %log; $log{'V'} = $data{'vector'}; FG::Logs::log_cpc_msp_views(\%w, \%s, $msp{'logging'}, 3, 10, \%log); #THE LAST TWO: TYPE=3 (MSP) AND SOURCE=10 (Gift Results) }#endif my %header_holiday = (); data_header_holiday(\%header_holiday); my $holidays_arr = FG::Utils::get_holidays(\%d); my $stores_href = _get_stores(); my $vars = { header_holiday => \%header_holiday, header_holiday_link => lc($header_holiday{'link'}), holidays => $holidays_arr, stores => $stores_href, member_name => $w{'member_name'}, data => \%data, col_length => $col_length, html_insert => $html{'html_insert'}{21}, html_insert2 => $html{'html_insert'}{18}, msp => $msp{'d'} }; my $tt = Template->new({ INCLUDE_PATH => $tpl_path, INTERPOLATE => 1, ABSOLUTE => 1, }) || die "$Template::ERROR\n"; $tt->process( $data{'base_script'}."_overview.tt", $vars ) || die $tt->error(), "\n"; #### Log and return #### FG::Logs::log_activity(\%w, \%s, 'View', $data{'page_vars'}{'section_id'}, $data{'page_vars'}{'page_id'}); return 1; } #endsub view_directory_start_page sub view_directory { #require $c{'fg'}{'layout'}{'gift_wizard'}; require $c{'fg'}{'layout'}{'wiz_input'}; # Check if it is a link to guide, top-10, video or hand-crafted on landing pages. my $article = FG::Utils::is_landing_page_guide($data{'directory'}); if( $article->{'landing_page_guide'} ){ _display_landing_page_guide( $article ); } # $d{vwo_test_category_page_redesign} and $d{vwo_test_category_landing_page} cannot be enabled at the same time on same category pages. my %display_landing_page = ( '/occasions/wedding/' => 'wedding', '/holidays/valentines-day/' => 'valentines-day', '/occasions/baptism/' => 'baptism', '/occasions/first-communion/' => 'first_communion', '/occasions/anniversary/' => 'anniversary', '/occasions/confirmation/' => 'confirmation', '/occasions/birthday/' => 'birthday', '/occasions/house-warming/' => 'house_warming', '/holidays/mothers-day/' => 'mothers_day', '/holidays/christmas/' => 'christmas', '/holidays/fathers-day/' => 'fathers_day', ); my %check_landing_page = ( '/occasions/wedding/' => 'wedding', '/occasions/first-communion/' => 'communion', ); my $vwo_check_landing_page; if( $d{vwo_test_category_landing_page} ){ foreach my $active_uri( keys %check_landing_page ){ $vwo_check_landing_page = FG::Utils::is_vwo_active_uri($active_uri); if( $vwo_check_landing_page ){ $data{'vwo_check_landing_page'} = $vwo_check_landing_page; # 1 $data{'landing_page_tpl_path'} = $check_landing_page{$active_uri}; # template name $data{'ver'} = FG::CGI_IO::alpha1($w{'query'}, 'var'); last; } } } my $display_landing_page; foreach my $display_uri( keys %display_landing_page ){ $display_landing_page = FG::Utils::is_vwo_active_uri($display_uri); if( $display_landing_page ){ $data{'landing_page_tpl_path'} = $display_landing_page{$display_uri}; # template name $data{'mobile_pg_url'} = "$s{'com'}{'mobile'}$ENV{'REQUEST_URI'}"; last; } } #### Look for old-style non-encoded vectors and try to re-route them #### if ($data{'found_non_encoded_vector'} == 1) { unless ($data{'non_encoded_vector'} ne '') { # Done to prevent a circular loop FG::Utils::redirect_301($s{'com'}{'web'}); return 1; } my $redirect_vector = FG::Search::encode_vector($data{'non_encoded_vector'}); if ($redirect_vector < 0) { # Needs to find something encodable FG::Utils::redirect_301($s{'com'}{'web'}); return 1; } my $redirect_url = $s{'com'}{'web'} . '/' . $data{'base_script'} . $data{'directory'} . $redirect_vector . '/'; FG::Utils::redirect_301($redirect_url); return 1; } #endif #### Fetch preferences and set defaults #### my %gs_cookie; FG::Cookies::get_gs_cookie(\%gs_cookie, $w{'query'}); my %prefs = %gs_cookie; # Need to do this so we don't overwrite undef preferences with defaults when logging search $prefs{'gpp'} = 24 if ($prefs{'gpp'} eq 'undef'); $prefs{'layout'} = 2 if ($prefs{'layout'} eq 'undef'); $prefs{'search_mode'} = 1 if ($prefs{'search_mode'} eq 'undef'); if ($prefs{'layout'} == 1) { $data{'additional_db_columns'} = 'Credit,Description,Promo,Promo_Expires'; } #### Convert old page numbers coming from old cookie#### if( $prefs{'layout'} == 2 ){ $prefs{'gpp'} = 8 if ($prefs{'gpp'} == 10); $prefs{'gpp'} = 24 if ($prefs{'gpp'} == 25); $prefs{'gpp'} = 48 if ($prefs{'gpp'} == 50); $prefs{'gpp'} = 96 if ($prefs{'gpp'} == 100); } #### Populate rest of data needed for Search.pm #### $data{'gifts_per_page'} = $prefs{'gpp'}; $data{'categories_per_page'} = 50; $data{'msps_per_page'} = 4; $data{'msps_per_row'} = 4; $data{'enable_throttling'} = 1; $data{'secure_images'} = 0; $data{'plink'}{'prefix'} = '/gift-ideas/pid-'; $data{'plink'}{'suffix'} = '/'; $data{'using_encoded_vector'} = 1; $data{'follow_num_levels'} = 2; $data{'use_encoded_menu'} = '/' . $data{'base_script'} . $data{'directory'}; #### Fetch directory information #### my $db_directory = &db_quote_value($data{'directory'}); my $sql = "SELECT * FROM $d{'dir_schema'} WHERE Path LIKE $db_directory"; my $sth = &sql_query($d{'hndl'}{'schdb'}, $sql); my %hash = $sth->FetchHash; # it is possible that the path is not found in the Directory_Schema_7x0 because it is updated to something else. For example: # we updated /categories/patriotic/us-flag/ to /holidays/flag-day/. Look for such urls in the new table, deleted categories. unless( $hash{'Directory_ID'} ){ my $sql2 = "SELECT Class, Deleted_Path, New_Path FROM Deleted_Paths where Deleted_Path=$db_directory"; my $sth2 = &sql_query($d{'hndl'}{'schdb'}, $sql2); my %phash = $sth2->FetchHash; if( $phash{'New_Path'} ){ my $redirect_url = $s{'com'}{'web'} . $phash{'Class'} . $phash{'New_Path'}; my $q = new CGI; print $q->redirect($redirect_url); return 1; } } $data{'directory_id'} = $hash{'Directory_ID'}; $data{'parent_id'} = $hash{'Parent_ID'}; $data{'directory_name'} = $hash{'Long_Label'}; $data{'meta_title'} = $hash{'Meta_Title'}; $data{'meta_description'} = $hash{'Meta_Description'}; $data{'meta_keywords'} = $hash{'Meta_Keywords'}; $data{'base_vector'} = $hash{'Vector'}; $data{'indexable'} = $hash{'Indexable'}; if ($data{'vector'} eq '' && $data{'base_vector'} ne '') { $data{'vector'} = $data{'base_vector'}; my $url_vector = FG::Search::convert_vector_url($data{'base_vector'}); $data{'enc_vector'} = FG::Search::encode_vector($url_vector); #} elsif ($data{'vector'} eq '') { # If no vector supplied, then it needs to be in the DB } elsif ($data{'vector'} eq '' || $data{'vector'} eq '-1' ) { # If no vector supplied, then it needs to be in the DB &error_no_directory_found(); return 1; } #endif #At this point check if any of the orig_cats is deleted. If so replace it with its parent category # if the parent category is not already there in the vector. If parent categry is already there just # remove the deleted category. recreate new encoded vector and redirect to /categories/new_enc_vector. my $redirect_url = _remove_deleted_categories($data{'vector'}); if( $redirect_url ){ my $q = new CGI; print $q->redirect($redirect_url); return 1; } $data{'orig_vector'} = $data{'vector'}; $data{'orig_enc_vector'} = $data{'enc_vector'}; my $vector_str = $data{'vector'}; $vector_str =~ s/[^0-9\,\:]//g; my @vector_arr = split(':',$vector_str); my @orig_cats = split(/,/,$vector_arr[5]); my @orig_prices = split(/,/,$vector_arr[7]); my @new_cats; if( scalar(@orig_cats) > 0 ){ my @sorted_cats; my $base_cats = ""; my $filter_cats = ""; if($data{'base_vector'} ne '' && !$data{'found_encoded_vector'}){ $base_cats = $vector_arr[5]; } else{ my $c = 0; if(scalar (@orig_cats) > 0 ){ @new_cats = FG::Utils::arrange_cats( $d{'hndl'}{'schdb'}, @orig_cats); for my $ref (@new_cats) { # $parent_cats .= @$ref[$#{ $ref }].","; for my $inner (@$ref) { if($c eq 0){ $base_cats .= $inner. ","; } else{ $filter_cats .= $inner. ","; } push(@sorted_cats,$inner); $data{'new_cat_cids'}{$inner} = 1; } $c++; } } $filter_cats =~ s/,$//; $base_cats =~ s/,$//; } $data{'new_cats'}{'base_cats'} = $base_cats; $data{'new_cats'}{'filter_cats'} = $filter_cats; my $cat_ids = join (',',@sorted_cats); $data{'new_category_ids'} = $cat_ids; my @test = split(':' , $data{'vector'}); # $test[5] = $cat_ids; $test[5] = $base_cats; $data{'vector'} = join(':',@test); my $new_enc_vector = FG::Search::convert_vector_url($data{'vector'}); $data{'enc_vector'} = FG::Search::encode_vector($new_enc_vector); } if( scalar(@orig_prices) > 0 ){ my @vector_arr = split(':',$data{'vector'}); $vector_arr[7] = 'x'; $data{'vector'} = join(':',@vector_arr); my $new_enc_vector = FG::Search::convert_vector_url($data{'vector'}); $data{'enc_vector'} = FG::Search::encode_vector($new_enc_vector); } my $new_url; if ($data{'found_encoded_vector'}) { my $new_enc_vector = FG::Search::convert_vector_url($data{'vector'}); $data{'enc_vector'} = FG::Search::encode_vector($new_enc_vector); # 'g0v' corresponds to a vector that is all 'x's. This should go to the top gift ideas page instead. if($data{'enc_vector'} ne 'g0v'){ $new_url = FG::Utils::get_url_from_vector($d{'hndl'}{'schdb'}, $data{'vector'}, $data{'enc_vector'}, $ENV{'SCRIPT_URL'}, $ENV{'QUERY_STRING'}, \@new_cats, \@orig_prices); } else{ if( scalar(@orig_prices) > 0 ){ $new_url = '/services/gift-ideas/#' . $data{'orig_enc_vector'}; } else{ $new_url = '/services/gift-ideas/'; } } } else { $new_url = &check_directory(); } if ($new_url) { print "Status: 301 Moved Permanently\n"; print 'Location: https://www.findgift.com' . "$new_url\n\n"; exit(0); } # Okay to set the visit cookie here. We've made it past any possible redirects. if ($robot != 1) { my $q = CGI::new(); $user = &set_visit_cookie($q); $w{'user'} = $user; } $data{'base_link'} = '/' . $data{'base_script'} . $data{'directory'}; my ($class_id, $section_id, $dynamic) = &get_base_script_info($data{'base_script'}); $data{'section_id'} = $section_id; $data{'page_id'} = $data{'directory_id'}; $data{'num_level'} = FG::Search::compute_num_level($data{'vector'}, $data{'base_vector'}); #### Since we are not getting input from standard CGI variables, then populate input variables from vector #### FG::Search::populate_wiz_input_vars(\%data, $data{'vector'}); $data{'follow_num_levels'} = 1 if ($data{'for_who'} > 0 || $data{'age'} > 0); #### Fetch information for base directory (top level directory for this branch) #### $data{'base_directory'}{'path'} = '/' . (split /\//, $data{'directory'})[1] . '/'; my $db_base_directory = &db_quote_value($data{'base_directory'}{'path'}); $sql = "SELECT Directory_ID, Short_Label, Long_Label, Intersection_IDs, Indexable FROM $d{'dir_schema'} WHERE Path = $db_base_directory"; $sth = &sql_query($d{'hndl'}{'schdb'}, $sql); %hash = $sth->FetchHash; $data{'base_directory'}{'directory_id'} = $hash{'Directory_ID'}; $data{'base_directory'}{'name'} = $hash{'Short_Label'}; $data{'base_directory'}{'meta_name'} = $hash{'Long_Label'}; $data{'ignore_category_ids'} = $hash{'Intersection_IDs'}; $data{'base_indexable'} = $hash{'Indexable'}; $data{'ignore_category_ids'} =~ s/::/,/g; $data{'ignore_category_ids'} =~ s/://g; #### Check to make sure that if this is an encoded directory #### if ($data{'found_non_encoded_vector'} == 1) { my $moved_to = '/' . $data{'base_script'} . $hash{'Path'}; &error_this_page_has_been_moved($moved_to); return 1; } #endif #### Make vector remap hash to use URLs pre-defined in Directory_Schema_7x0 #### my %vector_remap = ( '/x/x/x/x/x/48-181-10547/x/x/x/' => '/Categories/Sports/NBA/', '/x/x/x/x/x/48-178-10545/x/x/x/' => '/Categories/Sports/NFL/', '/x/x/x/x/x/48-180-10548/x/x/x/' => '/Categories/Sports/NHL/', '/x/x/x/x/x/48-179-10546/x/x/x/' => '/Categories/Sports/MLB/', ); my $base_vector_key = FG::Search::convert_vector_url($data{'base_vector'}); $vector_remap{$base_vector_key} = $data{'base_link'}; #analyze here &fetch_parent_remap_urls(\%vector_remap, $data{'parent_id'}, $data{'base_script'}); &fetch_subcategory_remap_urls(\%vector_remap, \%data, $data{'directory_id'}, $data{'base_script'}, $class_id); &fetch_embedded_base_remap_urls(\%vector_remap, \%data); %{$data{'vector_remap'}} = %vector_remap; # Add in the vector remaps #### Fetch gift ideas data #### ###################################################################################################### # if ($data{'directory_id'} == 943) { # START A/B TEST SECTION # # my $test_id = 64; # require $c{'fg'}{'dynamic'}{'ab'}; # $data{'ab_test_version'} = &choose_ab_version($test_id); # &w_log_ab_test($test_id, $data{'ab_test_version'}, $data{'section_id'}, $data{'page_id'}); # if ($data{'ab_test_version'} == 1 || $w{'ip'} eq '96.25.161.248') { # $d{'wiz_products'} = $d{'wiz_products_ab'}; # } # # } #END A/B TEST SECTION ###################################################################################################### my $success = FG::Search::fetch_gift_ideas($d{'hndl'}{'schdb'}, \%d, \%s, \%data, $prefs{'search_mode'}, $gs_cookie{'search_mode'}); unless ($success) { &error_cant_fetch_gift_ideas(); return 1; } #### Fetch and condition menu data #### &fetch_related_items_data(\%data, $data{'directory_id'}); &fetch_cat_page_text(\%data, &sort_vector($data{'vector'})); #### If throttle enabled and new throttle value, then cache new value (only do this for .com search applications, not internal programs) #### if ($data{'enable_throttling'} && $data{'throttle'}{'new_score'} ne '') { my $sql = "INSERT INTO $d{'wiz_throttle'} (Vector, Score, Date) VALUES ('$data{'vector'}', '$data{'throttle'}{'new_score'}', CURRENT_DATE)"; my $sth = &sql_query($d{'hndl'}{'fgdb'}, $sql); } #endif #### Prepare extended logging data #### # MSP needs it as well as logging. my %log; $log{'V'} = $data{'vector'}; $log{'NG'} = $data{'num_gifts'}; $log{'GPP'} = $data{'gifts_per_page'}; $log{'SM'} = $prefs{'search_mode'}; $log{'LY'} = $prefs{'layout'}; $log{'UC'} = $data{'using_cache'}; #### Fetch merchant spotlight data #### my %msp; my $suffix = "&sctnid=$data{'section_id'}&p=$data{'page'}&pageid=$data{'page_id'}&src=10"; FG::MSP::fetch_msp_data($d{'hndl'}{'schdb'}, \%d, \%s, \%c, \%msp, \%data, \$suffix); # Append the page this MSP was displayed on so we can track it if it gets clicked. FG::MSP::append_cpc_url(\%msp, '&from_page=2'); #### Write to last search cookie #### $gs_cookie{'url'} = $w{'url'}; $gs_cookie{'vector'} = $data{'vector'}; $gs_cookie{'page_num'} = $data{'page'}; FG::Cookies::set_gs_cookie(\%gs_cookie, $w{'query'}); #### Fetch other data #### $data{'ajax_vector'} = $data{'enc_vector'}; my (%qa_menu, %pages, %per_page, %prices); FG::Search::fetch_qa_summary_data($d{'hndl'}{'schdb'}, \%c, \%d, \%qa_menu, \%data, '', ''); FG::Widgets::fetch_prices(\%prices, $data{'price_ids'}); FG::Widgets::fetch_per_page_data(\%w, \%per_page, $data{'gifts_per_page'}, $prefs{'layout'}, $data{'ver'}); FG::Widgets::fetch_page_menu_data(\%pages, $data{'page'}, $data{'gifts_per_page'}, $data{'page_url'}, $data{'num_gifts'}, 5, $data{'ver'}); #### Make page #### my (%no_gifts, %store); if ($data{'num_gifts'} == 0) { FG::Search::make_master_undo_menu($d{'hndl'}{'schdb'}, \%d, \%s, \%data, \%prices, \%no_gifts, $data{'vector'}); } # If page number does not exist then redirect to page 1. This happens when user type p= in url. my $page = FG::CGI_IO::pos_int($w{'query'}, 'p'); if( $pages{'starting_gift'} > $pages{'ending_gift'} || ( defined $page && ( $page == 0 || $page == 1 || $display_landing_page ))){ FG::Utils::redirect_to_first_page(); } # if it is one of the display_landing_page go to landing page. if( $display_landing_page ){ _display_landing_page( \%data, \%qa_menu, \%msp, \%no_gifts, \%prices, \%pages, \%per_page, \%prefs, \%store, 1); } elsif( $d{vwo_test_category_landing_page} && $vwo_check_landing_page ){ _check_for_landing_page( \%data, \%qa_menu, \%msp, \%no_gifts, \%prices, \%pages, \%per_page, \%prefs, \%store, 1); &html_gift_search(\%data, \%qa_menu, \%msp, \%no_gifts, \%prices, \%pages, \%per_page, \%prefs, \%store, 1); } elsif( $d{vwo_test_category_page_redesign} ){ _check_page_version(\%data, \%qa_menu, \%msp, \%no_gifts, \%prices, \%pages, \%per_page, \%prefs, \%store ); } else { &_display_results(\%data, \%qa_menu, \%msp, \%no_gifts, \%prices, \%pages, \%per_page, \%prefs, \%store, 1); } #### Log and return #### FG::Logs::log_cpc_gift_views(\%w, \%s, 'Wizard View', $data{'include_set'}, $data{'logging'}{'sids'}, $data{'logging'}{'pids'}, 1, 10, 2, $data{'vector'}, $data{'page'}); FG::Logs::log_cpc_msp_views(\%w, \%s, $msp{'logging'}, 3, 10, \%log, 2); FG::Logs::log_it(\%w, \%s, 'View', $data{'section_id'}, $data{'page_id'}, $data{'page'}, \%log); return 1; } #endsub view_directory #---------------------------------------------------------------------- sub _display_landing_page{ #TODO: Expand this sub when we have more landing pages to display. my ($data, $qa_menu, $msp, $no_gifts, $prices, $pages, $per_page, $prefs, $store) = @_; my $tpl_path = $data{'landing_page_tpl_path'}; my $uri = $ENV{'REQUEST_URI'}; my %cat_cookie; # FG-341: Always set the cookie on any category page for GA event tracking. if( $d{ga_session_tracking_from_cat_page} ){ $cat_cookie{url} = $uri; FG::Cookies::set_cat_session_cookie(\%cat_cookie, $w{'query'}); } #FG-456: cat_content_cookie for vwo my %cat_content_cookie; if( $d{vwo_test_category_page_desc} ){ $cat_content_cookie{content} = 0; FG::Cookies::set_cat_session_cookie(\%cat_content_cookie, $w{'query'}, 'CAT_CONTENT'); } # TODO: These ids are hardcoded in layout/TMP_View_Gift.pl # Get genter, occasion and price values from DB for future. my %gift_wizard_genid = ( 'Recipient' => 0, 'Him' => 301, 'Her' => 316, 'Couple' => 317, 'Family' => 9264, 'per_lover' => 72, 'teen' => 9819, 'kid' => 11192, 'baby' => 602, ); my $tt = Template->new({ INCLUDE_PATH => "/www/findgift.com/templates/$tpl_path/", INTERPOLATE => 1, ABSOLUTE => 1, }) || die "$Template::ERROR\n"; my %header_holiday = (); data_header_holiday(\%header_holiday); # Get occasion id of landing page from vector. This needs to change if we will even have landing pages for categories like "animals"; my @vec = split( ':',$data->{'vector'} ); my $occ_id = $vec[3]; my $arr_events = FG::Calendar::get_calendar_events($d{'hndl'}{'fgdb'}); my $cal_header = FG::Calendar::get_calendar_events_header( $arr_events ) if @$arr_events; my $meta_tags = _get_meta_tags( $data, $qa_menu, $store, $prices ); $w{'page'}{'mtrack'} = $meta_tags->{'keywords'}; my $mtrack = FG::FG_Templates::magnetic_track(\%w); my $holidays_arr = FG::Utils::get_holidays(\%d); my $stores_href = _get_stores(); my $vars = { header_holiday => \%header_holiday, header_holiday_link => lc($header_holiday{'link'}), holidays => $holidays_arr, cal_header => $cal_header, cal_events => $arr_events, meta_tags => $meta_tags, mtrack => $mtrack, css_ver => $d{'css_ver'}, member_name => $w{'member_name'}, stores => $stores_href, landing_page => $tpl_path, mobile_pg_url => $data{'mobile_pg_url'}, occ_id => $occ_id, }; $tt->process( "$tpl_path.tt", $vars ) || die $tt->error(), "\n"; exit(0); } #---------------------------------------------------------------------- sub fetch_main_categories_menu_data { my ($class_ids, $base_script, $selections) = @_; #### Get data for section headers #### &fetch_sections_menu_data(); #### Get total number of sub-categories #### my $sql = "SELECT count(*) AS Sub_Choices FROM $d{'dir_schema'} AS A, $d{'dir_schema'} AS B WHERE A.Directory_ID = B.Parent_ID AND A.Parent_ID = '0' AND A.Class_ID IN ($class_ids) AND A.Status = '1' AND B.Status = '1'"; my $sth = &sql_query($d{'hndl'}{'schdb'}, $sql); my %hash = $sth->FetchHash; $data{'total_overview_subs'} = $hash{'Sub_Choices'}; #### Grab menu data #### $sql = "SELECT Directory_ID, Long_Label, Path FROM $d{'dir_schema'} WHERE Parent_ID = '0' AND Class_ID IN ($class_ids) AND Status = '1' ORDER BY Short_Label LIMIT $selections"; $sth = &sql_query($d{'hndl'}{'schdb'}, $sql); my $i = 0; while (my %hash = $sth->FetchHash) { $data{'overview_menu'}{$i}{'name'} = $hash{'Long_Label'}; $data{'overview_menu'}{$i}{'link'} = '/' . $base_script . $hash{'Path'}; $data{'overview_menu'}{$i}{'link'} = lc($data{'overview_menu'}{$i}{'link'}); my ($sub_categories, $num_sub_categories) = &fetch_sub_categories_menu_data($hash{'Directory_ID'}, $base_script, $i); $i++; } #endwhile $data{'total_overview_menu'} = $i; $data{'class_ids'} = $class_ids; #### Return #### return 1; } #endsub fetch_main_categories_menu_data sub fetch_sections_menu_data { $data{'gift_sections'}{'0'}{'label'} = 'by Occasion'; $data{'gift_sections'}{'0'}{'link'} = '/occasions/'; $data{'gift_sections'}{'1'}{'label'} = 'by Relationship'; $data{'gift_sections'}{'1'}{'link'} = '/for-who/'; $data{'gift_sections'}{'2'}{'label'} = 'by Expresssion'; $data{'gift_sections'}{'2'}{'link'} = '/express-yourself/'; $data{'gift_sections'}{'3'}{'label'} = 'by Type'; $data{'gift_sections'}{'3'}{'link'} = '/gift-types/'; $data{'gift_sections'}{'4'}{'label'} = 'by Holiday'; $data{'gift_sections'}{'4'}{'link'} = '/holidays/'; $data{'gift_sections'}{'5'}{'label'} = 'by Category'; $data{'gift_sections'}{'5'}{'link'} = '/categories/'; $data{'gift_sections'}{'6'}{'label'} = 'Gift Wizard'; $data{'gift_sections'}{'6'}{'link'} = '/Services/Gift-Wizard/'; $data{'num_gift_sections'} = 7; #### Return #### return 1; } #endsub fetch_sections_menu_data sub fetch_sub_categories_menu_data { my ($directory_id, $base_script, $i) = @_; my $sql = "SELECT Directory_ID, Short_Label, Path FROM $d{'dir_schema'} WHERE Parent_ID = '$directory_id' AND Status = '1' ORDER BY `Rank` DESC, Score, Short_Label"; my $sth = &sql_query($d{'hndl'}{'schdb'}, $sql); my $sub_choices = $sth->NumRows; my $j = 0; while (my %hash = $sth->FetchHash) { my $path = '/' . $base_script . $hash{'Path'}; my $sub_category = $hash{'Short_Label'}; $data{'overview_menu'}{$i}{'subs'}{$j}{'name'} = $hash{'Short_Label'}; $data{'overview_menu'}{$i}{'subs'}{$j}{'link'} = '/' . $base_script . $hash{'Path'}; $j++; } #endwhile $data{'overview_menu'}{$i}{'total_subs'} = $j; #### Return #### return 1; } #endsub fetch_sub_categories_menu_data #---------------------------------------------------------------------- sub _get_stores { my %stores; # TODO: for now we are hard coding store ids until we insert them in a table with some rules. my $w_store_arr = FG::Utils::get_stores(\%d, 'women'); $stores{'women'} = FG::Utils::get_store_html(d_ref=>\%d, store_arr=>$w_store_arr, gen_id=>316, cat_id=>9816); my $m_store_arr = FG::Utils::get_stores(\%d, 'men'); $stores{'men'} = FG::Utils::get_store_html(d_ref=>\%d, store_arr=>$m_store_arr, gen_id=>301, cat_id=>9816); my $babies_store_arr = FG::Utils::get_stores(\%d, 'babies'); $stores{'babies'} = FG::Utils::get_store_html(d_ref=>\%d, store_arr=>$babies_store_arr, age_id=>602); my $kids_store_arr = FG::Utils::get_stores(\%d, 'kids'); $stores{'kids'} = FG::Utils::get_store_html(d_ref=>\%d, store_arr=>$kids_store_arr, cat_id=>11192); my $teens_store_arr = FG::Utils::get_stores(\%d, 'teens'); $stores{'teens'} = FG::Utils::get_store_html(d_ref=>\%d, store_arr=>$teens_store_arr, cat_id=>9819); my $couples_store_arr = FG::Utils::get_stores(\%d, 'couples'); $stores{'couples'} = FG::Utils::get_store_html(d_ref=>\%d, store_arr=>$couples_store_arr, gen_id=>317); my $family_store_arr = FG::Utils::get_stores(\%d, 'family'); $stores{'family'} = FG::Utils::get_store_html(d_ref=>\%d, store_arr=>$family_store_arr, gen_id=>9264); my $pets_store_arr = FG::Utils::get_stores(\%d, 'pet'); $stores{'pet'} = FG::Utils::get_store_html(d_ref=>\%d, store_arr=>$pets_store_arr, gen_id=>72); return \%stores; } #---------------------------------------------------------------------- #---------------------------------------------------------------------- # Makes sure that the directory for the URL is correct. This is to # avoid possible duplicate URLs #---------------------------------------------------------------------- sub check_directory { my %directories = ( 'categories' => 1, 'holidays' => 2, 'occasions' => 3, 'anniversary-table' => 4, 'gift-types' => 5, 'for-who' => 6, 'express-yourself' => 8 ); my @stuff = split(/\//, $ENV{'SCRIPT_URL'}); # Get rid of the blank. shift(@stuff); my $dir = shift(@stuff); my $path = '/' . shift(@stuff) . '/'; my $sql = "SELECT Class_ID FROM Directory_Schema_7x0 where Path='$path'"; my $sth = &sql_query($d{'hndl'}{'schdb'}, $sql); my %hash = $sth->FetchHash; my $found_class_id = $directories{$dir}; # Flip the hash so the keys become values and vice versa. my %flipped_directories; map { $flipped_directories{($directories{$_})} = $_ } keys %directories; if ($found_class_id && $found_class_id != $hash{'Class_ID'}) { my $new_path = $flipped_directories{($hash{'Class_ID'})}; my $new_location = "/$new_path" . $path . join('/', @stuff); $new_location =~ s|/+|/|g; if ($ENV{'QUERY_STRING'}) { $new_location .= '?'; $new_location .= $ENV{'QUERY_STRING'}; } return $new_location; } return ''; } sub get_base_script_info { my ($base_script) = @_; my %base_hash = ( 'categories' => '1:110:0', 'holidays' => '2:130:0', 'occasions' => '3:120:0', 'anniversary-table' => '4:180:0', 'gift-types' => '5:170:1', 'for-who' => '6:140:1', 'express-yourself' => '8:150:1'); my ($class_id, $section_id, $dynamic) = split /:/, $base_hash{$base_script}; return ($class_id, $section_id, $dynamic); } #endsub get_base_script_info sub fetch_parent_remap_urls { =pod This routine is used to build the %vector_remap has from the current directory's sub-categories. Doing this will allow us to substitute in these URLs into the dynamic Gift Wizard menu when encountered. =cut my ($remap_ref, $parent_id, $base_script) = @_; my $count = 0; # Recursion protection mechanism in case of circular parent-child loop in Directory_Schema_7x0 while ($parent_id > 0 && $count < 10) { $count++; my $sql = "SELECT Directory_ID, Parent_ID, Path, Vector FROM $d{'dir_schema'} WHERE Directory_ID = '$parent_id' AND Status = '1'"; my $sth = &sql_query($d{'hndl'}{'schdb'}, $sql); if ($sth->NumRows == 0) { # This shouldn't happen, unless child category gets orphaned in Directory_Schema_7x0 $parent_id = 0; next; } my %hash = $sth->FetchHash; my $directory_id = $hash{'Directory_ID'}; my $parent_id = $hash{'Parent_ID'}; # Used for next iteration, should exit at top when Parent_ID is 0 my $url_vector = FG::Search::convert_vector_url($hash{'Vector'}); $$remap_ref{$url_vector} = '/' . $base_script . $hash{'Path'}; } #endwhile $$remap_ref{'/x/x/x/x/x/x/x/x/x/'} = '/Services/Gift-Ideas/'; # Empty vector should go to Top Gift Ideas page return 1; } #endsub fetch_parent_remap_urls sub fetch_subcategory_remap_urls { =pod This routine is used to build the %vector_remap has from the current directory's sub-categories. Doing this will allow us to substitute in these URLs into the dynamic Gift Wizard menu when encountered. =cut my ($remap_ref, $data_ref, $directory_id, $base_script, $class_id) = @_; my $sql = "SELECT Short_Label, Path, Vector FROM $d{'dir_schema'} WHERE Parent_ID = '$directory_id' AND Class_ID = '$class_id' AND Status = '1' ORDER BY `Rank` DESC, Score, Short_Label"; my $sth = &sql_query($d{'hndl'}{'schdb'}, $sql); if ($sth->NumRows == 0) { return 1; } while (my %hash = $sth->FetchHash) { my $url_vector = FG::Search::convert_vector_url($hash{'Vector'}); $$remap_ref{$url_vector} = '/' . $base_script . $hash{'Path'}; } #endwhile return 1; } #endsub fetch_subcategory_remap_urls sub fetch_embedded_base_remap_urls { =pod This routine is used to build the %vector_remap for undo links where the Category_ID being un-done is belongs to the Base URL. Such an event would produce an error (ex. taking Personalized away from /Confirmation/Personalized/enc_vector when other categories selected in conjunction like Pendants -- since we cannot easily decide to go back to the base /Confirmation/enc_vector URL). When we see a situation where a Category_ID is in the Base URL, then we will remap the "undo" vector link to a generic Gift Wizard URL. Doing this will allow us to substitute in these URLs into the dynamic Gift Wizard menu when encountered. =cut my ($remap_ref, $data_ref) = @_; my %base; FG::Search::populate_wiz_input_vars(\%base, $$data_ref{'base_vector'}); FG::Search::format_vector_templates(\%base, $$data_ref{'vector'}); foreach my $base_id (split /,/, $base{'category_ids'}) { my $query_cat_ids = FG::Utils::remove_id_from_list($$data_ref{'category_ids'}, $base_id); my $new_cat_ids = $query_cat_ids; $new_cat_ids =~ s/,/\-/g; if ($new_cat_ids eq '') { $new_cat_ids = 'x'; } my $url_vector = $base{'vtemp'}{'categories'}; $url_vector =~ s/QQQ/$new_cat_ids/; next if ($$remap_ref{$url_vector} ne ''); # Don't remap anything that has already been remapped $$remap_ref{$url_vector} = 'wiz_link'; # Let Search.pm know to use standard Gift Wizard link } #endforeach return 1; } #endsub fetch_embedded_base_remap_urls sub fetch_related_items_data { my ($data_ref, $directory_id) = @_; my $sql = "SELECT Link_Text, Link, Link_Type FROM $d{'dir_links'} WHERE Directory_ID = '$directory_id' AND Status = '1' ORDER BY Link_Type, `Rank` DESC"; my $sth = &sql_query($d{'hndl'}{'schdb'}, $sql); if ($sth->NumRows == 0) { return 1; } my $i = 0; my $j = 0; while (my %hash = $sth->FetchHash) { if ($hash{'Link_Type'} == 1) { $$data_ref{'gifty_links'}{$j}{'text'} = $hash{'Link_Text'}; $$data_ref{'gifty_links'}{$j}{'link'} = $hash{'Link'}; $j++; } else { $$data_ref{'related_links'}{$i}{'text'} = $hash{'Link_Text'}; $$data_ref{'related_links'}{$i}{'link'} = $hash{'Link'}; $i++; } #endif } #endwhile $$data_ref{'num_related_links'} = $i; $$data_ref{'num_gifty_links'} = $j; #### Return #### return 1; } #endsub fetch_related_items_data #---------------------------------------------------------------------- sub sort_vector { my ($vector) = @_; my @fields = split(/:/, $vector); my ($field, $sorted); foreach $field (@fields) { if ($field =~ /,/) { my @subarr = split(',', $field); my @sorted = sort {$a <=> $b} @subarr; my $str = join(',', @sorted); $sorted .= "$str:"; } else { $sorted .= "$field:"; } } $sorted =~ s/:$//; return $sorted; } #---------------------------------------------------------------------- #---------------------------------------------------------------------- sub fetch_cat_page_text { my ($data_ref, $vec) = @_; my ($text, $meta_text); my $sql = qq|SELECT Page_Text, Meta_Text FROM Cat_Page_Text WHERE Vector='$vec'|; my $sth = &sql_query($d{'hndl'}{'schdb'}, $sql); if ($sth && $sth->NumRows) { ($text, $meta_text) = $sth->fetchrow(); $$data_ref{'Cat_Page_Text'} = $text; # Use META description if there's one defined. Otherwise, leave the default. $$data_ref{'meta_description'} = $meta_text if ($meta_text !~ /^\s*$/); } } #---------------------------------------------------------------------- sub _get_meta_tags { my ( $data_ref, $qa_menu, $store, $prices ) = @_; my @sel_ids = split /,/, $$data_ref{'cm'}{'i'}{'sel_order'}{'1'}; my @meta_categories; foreach my $cat_id( @sel_ids ){ push @meta_categories, $$data_ref{'cm'}{'d'}{$cat_id}{'category'}; } my $meta_cats = join ', ', @meta_categories; my %meta; FG::Search::generate_meta_tags( $d{'hndl'}{'fgdb'}, \%meta, $data_ref, $qa_menu, $store, $prices, $meta_cats ); return \%meta; } #---------------------------------------------------------------------- ######################################################################### # # # TEMPLATE FUNCTIONS START HERE # # # ######################################################################### sub _display_results { my ($data_ref, $qa_summary_ref, $msp_ref, $no_gifts_ref, $prices_ref, $pages_ref, $per_page_ref, $pref_ref, $store_ref, $show_trailer, $from_gift_ideas) = @_; my $uri = $ENV{'REQUEST_URI'}; my %cat_cookie; $cat_cookie{url} = $uri; FG::Cookies::set_cat_session_cookie(\%cat_cookie, $w{'query'}); # FG-456: Set category content cookie to check its value for vwoGiftBoxes on product page. # Delete similar to CAT_Session cookie. my $vwo_test_content_text = _is_vwo_test_content_text($data_ref) if( $d{vwo_test_category_page_desc} ); my %cat_content_cookie; $cat_content_cookie{content} = $vwo_test_content_text; FG::Cookies::set_cat_session_cookie(\%cat_content_cookie, $w{'query'}, 'CAT_CONTENT'); &format_store_info($store_ref, $data_ref); &format_related_links($data_ref); #### Make header text #### my $header = 'refine search for...'; if ($$data_ref{'base_directory'}{'name'} ne '') { my $base_dir = "$$data_ref{'base_directory'}{'name'}"; if ($base_dir !~ /gift/i) { $base_dir .= ' Gift Ideas'; } $header = $header . "
$base_dir
"; } #### Make meta tags #### my %meta; FG::Search::generate_meta_tags($d{'hndl'}{'fgdb'}, \%meta, $data_ref, $qa_summary_ref, $store_ref, $prices_ref, $html{'meta_categories'}); #### Add in Gift Message, if there is one #### if ($$data_ref{'cids'}{'11115'} == 1) { &format_qa_summary_last_minute(); } #### Make page #### my $main_catname = $$data_ref{'directory_name'}; $main_catname =~ s/[\'\" ]+//g; # These characters were causing the ads to fail. my @menu_ids = split /,/, $$data_ref{'cm'}{'i'}{'available'}{'1'}; my $max_cat = (scalar @menu_ids) >= NUM_CATEGORIES ? NUM_CATEGORIES : @menu_ids; # my $path = _get_path($data_ref,$cat_header); my $parent_arr = _get_parent_cats($data_ref); my $filters_parent_arr = _get_options_parent_cats($data_ref); my $children = _get_left_children_list($data_ref, $max_cat) unless ($$data_ref{'most_popular'} == 1); my $options = _get_left_options_list($data_ref, $max_cat) unless ($$data_ref{'most_popular'} == 1); my $any_cat_link = _get_any_cat_link($data_ref,$qa_summary_ref); my $msps = format_msps($msp_ref, $vwo_test_content_text) if ($$msp_ref{'num_msps'} > 0); my $right_cat_ad = _get_right_cat_ad($data_ref); my $left_cat_ad = _get_left_cat_ad($data_ref); my $arr_events = FG::Calendar::get_calendar_events($d{'hndl'}{'fgdb'}); my $cal_header = FG::Calendar::get_calendar_events_header( $arr_events ) if @$arr_events; &format_qa_summary($data_ref, $qa_summary_ref); &format_gift_boxes($data_ref, $pref_ref); $$data_ref{'Cat_Page_Text'} = '' if ($$data_ref{'page'} > 1); my %header_holiday = (); data_header_holiday(\%header_holiday); my $holidays_arr = FG::Utils::get_holidays(\%d); my $stores_href = _get_stores(); my $mobile_pg_url = $s{'com'}{'mobile'}.$ENV{'REQUEST_URI'}; $w{'page'}{'mtrack'} = $meta{'keywords'}; my $mtrack = FG::FG_Templates::magnetic_track(\%w); my $tpl_path = '/www/findgift.com/templates/'; my $cat_header = _get_cat_header($data_ref, $store_ref); unless ( $meta{'title'} ){ $meta{'title'} = $cat_header . ' - FindGift.com'; } my $vars = { meta_tags => \%meta, header_holiday => \%header_holiday, header_holiday_link => lc($header_holiday{'link'}), holidays => $holidays_arr, stores => $stores_href, cat_header => "$cat_header", main_catname => $main_catname, member_name => $w{'member_name'}, data => \%data, parent_arr => $parent_arr, filters_parent_arr => $filters_parent_arr, children_arr => $children, filters_children_arr => $options, any_cat_link => $any_cat_link, qa_summary => $html{'qa_summary'}, pages_ref => $pages_ref, per_page_ref => $per_page_ref, pref_ref => $pref_ref, msps => $msps, cal_header => $cal_header, cal_events => $arr_events, no_gifts => $no_gifts_ref, mobile_pg_url => $mobile_pg_url, mtrack => $mtrack, holiday_banner => $s{'com'}{'holiday_banner'}, banner_pg_link => $s{'com'}{'banner_pg_link'}, banner_image_link => $s{'com'}{'banner_image_link'}, }; my $tt = Template->new({ INCLUDE_PATH => $tpl_path, INTERPOLATE => 1, ABSOLUTE => 1, }) || die "$Template::ERROR\n"; $tt->process( "results.tt", $vars ) || die $tt->error(), "\n"; } sub error_no_directory_found{ open(F, '/www/findgift.com/html/error.html'); my @data = ; print "Content-type: text/html\n"; print "Status: 404 Not Found\n\n"; print @data; exit(0); } sub _get_cat_header { my ($data_ref, $store_ref) = @_; my @sel_ids = split /,/, $$data_ref{'cm'}{'i'}{'sel_order'}{'1'}; my ($cat_menu_label, $label, $prefix, $last_cat_name); my ($gender, $for_who, $age, $occasion, $types, $categories, $store, $prices, $sort_by) = split(':', $$data_ref{'vector'}); if ($$data_ref{'store_id'} > 0) { my $company = _get_company_name($data_ref, $store_ref); my $prefix = 'Gifts from '; $cat_menu_label = $prefix . $company; return $cat_menu_label; } elsif ($$data_ref{'most_popular'} == 1) { $cat_menu_label = "Our Most Popular Gift Ideas..."; return $cat_menu_label; } my $has_cats = 0; my $gifts_label = 'Gift Ideas'; if ($categories ne 'x') { my $cat_ids = $categories; my @cat_names; foreach my $cat_id (reverse(split(',', $cat_ids))) { push(@cat_names, $$data_ref{'cm'}{'d'}{$cat_id}{'orig_category'}) if ($$data_ref{'cm'}{'d'}{$cat_id}{'orig_category'} !~ /^adult$/i) } #foreach (@cat_names) { print "cat name:$_
\n"; } $last_cat_name = shift(@cat_names); $label = "$last_cat_name "; $has_cats++; } if ($occasion ne 'x') { $label .= ' - ' if ($last_cat_name); $label .= " $$data_ref{'cm'}{'d'}{$occasion}{'category'}"; $has_cats++; } elsif ($types ne 'x') { $label .= ' - ' if ($last_cat_name); $label .= " $$data_ref{'cm'}{'d'}{$types}{'category'}"; $has_cats++; } my @n_gifts = ($label =~ /gift/gi); my $replacement = (scalar(@n_gifts) >= 1)? ' Ideas' : ' Gift Ideas'; $label .= $replacement; if ($for_who ne 'x') { $label .= ' for your ' . $$data_ref{'cm'}{'d'}{$for_who}{'category'}; #$label =~ s/Gift Ideas/Gifts/ if ($has_cats); my @n_gifts = ($label =~ /gift/gi); my $replacement = (scalar(@n_gifts) <= 1)? 'Gifts' : ''; $label =~ s/Gift Ideas/$replacement/ if ($has_cats); } elsif ($gender ne 'x') { $label .= " for $$data_ref{'cm'}{'d'}{$gender}{'category'}"; my @n_gifts = ($label =~ /gift/gi); my $replacement = (scalar(@n_gifts) <= 1)? 'Gifts' : ''; $label =~ s/Gift Ideas/$replacement/ if ($has_cats); } # Don't have the word "gift" more than once. my @n_gifts = ($label =~ /gift/gi); if (scalar(@n_gifts) > 1) { $label =~ s/Gift Ideas/Ideas/; $label =~ s/Gifts\s+?Ideas/Gift Ideas/; } $cat_menu_label = "$label"; return $cat_menu_label; } sub format_store_info { =pod This routine is used to format the store info box on the Gift Wizard results pages when a store has been chosen. =cut my ($store_ref, $data_ref) = @_; my $store_id = $$data_ref{'store_id'}; my $query_vars = $$data_ref{'wiz_query_vars'}; my $available_categories = $$data_ref{'menu'}{'available_categories'}; my $main_category_str = $$store_ref{'d'}{$store_id}{'main_category'}; my $status = $$store_ref{'d'}{$store_id}{'status'}; unless ($store_id > 0) { return 1; } my $company = $$store_ref{'d'}{$store_id}{'company'}; $company =~ s/\&/&/g; $company =~ s/\"/"/g; #### Add in promo, only if it is a discount and the store is active #### my ($promo); if ($$store_ref{'d'}{$store_id}{'promo_special'} == 1 && $status == 1) { $promo = <$$store_ref{'d'}{$store_id}{'promo'} PROMO if ($$store_ref{'d'}{$store_id}{'promo_expires_med'} ne '') { $promo .= <expires: $$store_ref{'d'}{$store_id}{'promo_expires_med'} PROMO_EXP } #endif } #endif ##### Add in phone number, if present #### my ($phone); if ($$store_ref{'d'}{$store_id}{'phone'} ne '') { $phone .= <$$store_ref{'d'}{$store_id}{'phone'} PHONE } #endif #### Add in a logo, if present #### my $logo; if ($$store_ref{'d'}{$store_id}{'logo'} ne '') { $logo = < LOGO } else { $logo = <$company LOGO } #endif #### Make all stores link #### my $all_stores; if ($query_vars ne '') { my $all_stores_txt; if ($status == 1) { $all_stores_txt = "See gifts like these from all stores"; } else { $all_stores_txt = "See $$data_ref{'all_stores_label'} gifts from all stores"; } $all_stores = <See gifts like these from all stores ALL_STORES } #endif #### Make store info section #### $html{'stores'} = < $logo $promo $phone $all_stores STORE_INFO #### Return #### return 1; } #endsub format_store_info sub format_related_links { my ($data_ref) = @_; if ( ($$data_ref{'num_related_links'} == 0 || $$data_ref{'num_related_links'} eq '') && ($$data_ref{'num_gifty_links'} == 0 || $$data_ref{'num_gifty_links'} eq '') ) { return 1; } #### Format related links #### $html{'related_links'} = ''; #### Format Giftypedia links #### my $class = 'gifty_links'; $class .= ' gifty_links_ie' if ($w{'browser'} =~ /MSIE /); $html{'related_links'} .= "
    " if $$data_ref{'num_gifty_links'}; for (my $i = 0; $i < $$data_ref{'num_gifty_links'}; $i++) { $html{'related_links'} .= <$$data_ref{'gifty_links'}{$i}{'text'} END_LINK } #endfor $i $html{'related_links'} .= '
' if $$data_ref{'num_gifty_links'}; #### Return #### return 1; } #endsub format_related_links sub format_qa_summary_last_minute { $html{'gifts_message'} = < Last Minute Gifts:
These gifts might be deliverable by the next day if ordered by mid-afternoon.
See individual retailer\'s website for specifics and limitations.  Delivery deadlines vary by time zone & retailer, and may exclude weekends & holidays.
LM } #endsub format_qa_summary_last_minute sub _get_company_name { my ($data_ref,$store_ref) = @_; my $company = $$store_ref{'d'}{$$data_ref{'store_id'}}{'company'}; # Get the company name from the list of gifts. The variable we were getting it from before isn't always populated. my @gift_nums = keys(%{$$data_ref{'gifts'}}); $company ||= $$data_ref{'gifts'}{$gift_nums[0]}{'company'}; # Okay, we've tried everything that's already populated. Get the name from the database as a last resort. $company ||= &company_name_from_db($$data_ref{'store_id'}); $company =~ s/\&/&/g; $company =~ s/\"/"/g; return $company; } sub _get_parent_cats { my ($data_ref) = @_; #### Define variables and hash keys to be used later #### my @sel_ids = split /,/, $$data_ref{'new_cats'}{'base_cats'}; #### Build already selected list #### my @parent_arr; my @cat_ids; for (my $i = 0; $i < scalar(@sel_ids); $i++) { my %parent_hash; my $cat_id = $sel_ids[$i]; push(@cat_ids,$cat_id); $parent_hash{url} = lc(get_cat_link(\@cat_ids,$data_ref)) ; $parent_hash{cat_id} = $cat_id; $parent_hash{category} = $$data_ref{'cm'}{'d'}{$cat_id}{'category'}; #$parent_hash{url} = "javascript:parent.location='$$data_ref{'cm'}{'d'}{$cat_id}{'undo_link'}'"; push @parent_arr, \%parent_hash if ($parent_hash{cat_id} && $parent_hash{category} && $parent_hash{url}); } return \@parent_arr; } sub get_cat_link { my ($cat_ids,$data_ref) = @_; my $vector_str = $data{'orig_vector'}; my @vector_arr = split(':',$vector_str); my @filter_cats; if($$data_ref{'new_cats'}{'filter_cats'} ne ''){ my @filter_cats = split(/,/,$$data_ref{'new_cats'}{'filter_cats'}); push(@$cat_ids,@filter_cats); } sort @$cat_ids; $vector_arr[5] = join(',',@$cat_ids); my $new_vec = join(':',@vector_arr); my $sql = "SELECT Path FROM Directory_Schema_7x0 WHERE Vector = '$new_vec' AND Status = '1'"; my $sth = &sql_query($d{'hndl'}{'schdb'}, $sql); if ($sth->NumRows == 1) { # We have an SE friendly link my %hash = $sth->FetchHash; return '/'.$$data_ref{'base_script'}. lc($hash{'Path'}); } else{ my $new_enc_vec = FG::Search::convert_vector_url($new_vec); $new_enc_vec = FG::Search::encode_vector($new_enc_vec); return '/'.$$data_ref{'base_script'}.$$data_ref{'directory'}.$new_enc_vec.'/'; } } sub _get_options_parent_cats { my ($data_ref) = @_; #### Define variables and hash keys to be used later #### my @sel_ids = split /,/, $$data_ref{'new_cats'}{'filter_cats'}; #### Build already selected list #### my @parent_arr; if (scalar(@sel_ids) > 0 && $$data_ref{'menu'}{'disable_dynamic'} != 1) { my @test = split(':' , $$data_ref{'vector'}); my @cat_ids = split(',',$$data_ref{'new_category_ids'}); for (my $i = 0; $i < scalar(@sel_ids); $i++) { my $add_vector = ""; my %parent_hash; my $cat_id = $sel_ids[$i]; if(scalar(@sel_ids) eq 1){ $parent_hash{url} = '/'.$data{'base_script'}.'/'; } else{ $parent_hash{url} = ""; foreach(@cat_ids){ if($_ ne $cat_id){ $add_vector .= $_ .","; } } } $test[5] = $add_vector; my $decoded_vector = join(':',@test); my $new_enc_vector = FG::Search::convert_vector_url($decoded_vector); $new_enc_vector = FG::Search::encode_vector($new_enc_vector); $parent_hash{vector} = $new_enc_vector; $parent_hash{cat_id} = $cat_id; $parent_hash{category} = $$data_ref{'cm'}{'d'}{$cat_id}{'category'}; push @parent_arr, \%parent_hash if ($parent_hash{cat_id} && $parent_hash{category}); } } #endif if(scalar(@parent_arr) > 0 ){ $$data_ref{'new_settings'}{'filters_base_cat'} = $parent_arr[-1]{'cat_id'}; } else { $$data_ref{'new_settings'}{'filters_base_cat'} = "" } return \@parent_arr; } sub _get_left_children_list{ my ($data_ref,$max_cat) = @_; my @menu_ids = split /,/, $$data_ref{'cm'}{'i'}{'available'}{'1'}; unless( scalar(@menu_ids) ){ return; } my @cat_arr; my @parents = split(',' , $data{'new_cats'}{'base_cats'}); my $base_id = $parents[$#parents]; for (my $i = 0; $i < $max_cat; $i++){ my %cat_hash; my $cat_id = $menu_ids[$i]; if(!($base_id) || $$data_ref{'cm'}{'d'}{$cat_id}{'parent_id'} eq $base_id || $$data_ref{'cm'}{'d'}{$cat_id}{'parent_id'} eq $$data_ref{'directory_id'} ){ $cat_hash{category} = $$data_ref{'cm'}{'d'}{$cat_id}{'category'}; $cat_hash{url} = lc($$data_ref{'cm'}{'d'}{$cat_id}{'link'}); $cat_hash{title} = $$data_ref{'cm'}{'d'}{$cat_id}{'add_reltag'}; push (@cat_arr, \%cat_hash); } } return \@cat_arr; } sub _get_left_options_list{ my ($data_ref,$max_cat) = @_; my @menu_ids = split /,/, $$data_ref{'cm'}{'i'}{'available'}{'1'}; unless( scalar(@menu_ids) ){ return; } my @cat_arr; my $base_id = 0; my @parents = split(',' , $data{'new_cats'}{'base_cats'}); if(scalar(@parents) > 0){ $base_id = $parents[$#parents]; } for (my $i = 0; $i < $max_cat; $i++){ my %cat_hash; my $cat_id = $menu_ids[$i]; if($base_id ne 0 && $$data_ref{'cm'}{'d'}{$cat_id}{'parent_id'} ne $base_id && $$data_ref{'cm'}{'d'}{$cat_id}{'parent_id'} ne $$data_ref{'directory_id'} ){ $cat_hash{category} = $$data_ref{'cm'}{'d'}{$cat_id}{'category'}; $cat_hash{url} = lc($$data_ref{'cm'}{'d'}{$cat_id}{'link'}); $cat_hash{title} = $$data_ref{'cm'}{'d'}{$cat_id}{'add_reltag'}; $cat_hash{vector} = substr $$data_ref{'cm'}{'d'}{$cat_id}{'add_enc_vector'},0,-1; push (@cat_arr, \%cat_hash); } } return \@cat_arr; } sub _get_any_cat_link { my ($data_ref, $qa_sum_ref) = @_; # if any sub category is selected along with filters. return $$data_ref{'cm'}{'d'}{'any_cat_link'} if( $$data_ref{'cm'}{'d'}{'any_cat_link'} ); #no sub category is selected but check if any flter is selected. my @config_keys = (8, 6, 7, 3, 5, 99); foreach my $filter (@config_keys){ if( $$qa_sum_ref{$filter}{'category_id'} > 0 ){ return $ENV{'REQUEST_URI'}; } } # no sub category is selected and no filters are selected. For example /categories/animals. return '/services/gift-ideas/'; # No filters are selected, therefore any_category link should go to /Services/Gift-Ideas. #my $uri = $ENV{'REQUEST_URI'}; #$uri =~ m!(^/categories/.+?/).*!; #return '/services/gift-ideas/' if $1; # return $ENV{'REQUEST_URI'}; # ($$data_ref{'cm'}{'d'}{'any_cat_link'}) ? return $$data_ref{'cm'}{'d'}{'any_cat_link'} : return $ENV{'REQUEST_URI'}; } sub format_gift_boxes{ my ($data_ref,$pref_ref) = @_; $$data_ref{'url_encoded_vector'} = FG::Utils::url_encode($$data_ref{'vector'}); for (my $i = 0; $i < $$data_ref{'num_shown'}; $i++) { $$data_ref{'gifts'}{$i}{'name'} =~ s/\"/"/g; $$data_ref{'gifts'}{$i}{'name'} = ( length($$data_ref{'gifts'}{$i}{'name'}) > 102 ? substr($$data_ref{'gifts'}{$i}{'name'},0,102) : $$data_ref{'gifts'}{$i}{'name'} ); if ($$data_ref{'gifts'}{$i}{'image_m'} ne '') { $$data_ref{'gifts'}{$i}{'image_cdn_src'} = FG::Utils::add_cdn_img_path($$data_ref{'gifts'}{$i}{'image_m'}); } elsif ($$data_ref{'gifts'}{$i}{'image_s'} ne '') { my $src = $$data_ref{'gifts'}{$i}{'image_s'}; $$data_ref{'gifts'}{$i}{'image_s_cdn_src'} = FG::Utils::add_cdn_img_path($$data_ref{'gifts'}{$i}{'image_s'}); } } return 1; } sub format_msps{ my ($msp_ref, $vwo_test_content_text) = @_; my @msp_ids = split(/\,/, $msp_ref->{'i'}{'sort_rank'}); my $editor_image= $s{'net'}{'webs'}; my $live_image = $s{'com'}{'images'}; my $msps; unless( @msp_ids ){ return 1; } my @my_msps; foreach my $msp_id( @msp_ids ){ my %new_msps; $new_msps{'headline'} = $$msp_ref{'d'}{$msp_id}{'headline'}; $new_msps{'enc_headline'} = _html_encode_entities($new_msps{'headline'}); $new_msps{'description'} = $$msp_ref{'d'}{$msp_id}{'description'}; $new_msps{'display_url'} = $$msp_ref{'d'}{$msp_id}{'display_url'}; $new_msps{'url'} = $$msp_ref{'d'}{$msp_id}{'cpc_url'}; $new_msps{'image'} = $$msp_ref{'d'}{$msp_id}{'image'}; $new_msps{'headline'} =~ s/'/\\'/g; $new_msps{'headline'} =~ s/"/"/g; next unless( $new_msps{'headline'} && $new_msps{'description'} && $new_msps{'display_url'} ); if( $new_msps{'image'} && $new_msps{'image'} =~ /\_PEND/ ){ # Image is a pending image so fetch from local machine! $new_msps{'image'} = "$editor_image/Graphics/MSP/" . $new_msps{'image'}; } elsif( $new_msps{'image'} ){ $new_msps{'image'} = "$live_image/Graphics/MSP/".$new_msps{'image'}; } else{ $new_msps{'image'}= "$live_image/Graphics/fg/Registry/no_product.gif"; } $new_msps{'image'} = FG::Utils::add_cdn_img_path($new_msps{'image'}); push( @my_msps , \%new_msps ); } return \@my_msps; } sub format_qa_summary { my ($data_ref, $qa_sum_ref, $html_key) = @_; my $mask = $$qa_sum_ref{'mask'}; $mask = 0 if ($$data_ref{'most_popular'} == 1); # Don't mask any inputs for most popular search my $binary_mask = FG::Utils::dec2bin($mask, 6); my @config_keys = (8, 6, 7, 3, 5, 99); my %config = ( 8 => { html_key => 'menu_genid', label => 'RECIPIENT', id => 'recipient', default => 'All', }, 6 => { html_key => 'menu_whoid', label => 'RELATIONSHIP', id => 'relationship', default => 'Any', }, 7 => { html_key => 'menu_ageid', label => 'AGE', id => 'age', default => 'All', }, 3 => { html_key => 'menu_occid', label => 'OCCASION', id => 'occasion', default => 'Any', }, 5 => { html_key => 'menu_typids', label => 'GIFT TYPE', id => 'gift_type', default => 'Any', }, 99 => { html_key => 'menu_prcids', label => 'PRICE RANGE', id => 'price_range', default => 'Any', }, ); #### Make summary #### $html{'qa_summary'} = < HEAD my $prior_summary = 0; for (my $i = 0; $i < scalar(@config_keys); $i++) { my $class = $config_keys[$i]; my $category = $$qa_sum_ref{$class}{'category'}; $category =~ s/^a //; # Turn "a Girl" into "Girl" for summary menu display purposes my $html_key = $config{$class}->{'html_key'}; next if (substr($binary_mask,$i,1) eq '1' && $$qa_sum_ref{$class}{'category_id'} eq ''); if ($html{$html_key} ne '') { # Put in overlay menu if present $html{'qa_summary'} .= <$html{$html_key} QA_2 if ($$qa_sum_ref{$class}{'category_id'} > 0) { $html{'qa_summary'} .= qq|
$config{$class}->{'label'}
|; $html{'qa_summary'} .= qq|
$category
|; } else { $html{'qa_summary'} .= qq|
$category
|; $html{'qa_summary'} .= qq|
« $config{$class}->{'default'}
|; } } elsif ($$qa_sum_ref{$class}{'category_id'} > 0) { # Menu has data specified, show it $html{'qa_summary'} .= <$config{$class}->{'label'}
$category
QA_2 } else { $html{'qa_summary'} .= <$category
« $config{$class}->{'default'}
QA_2 } #endif $prior_summary = 1; } #endfor $i $html{'qa_summary'} .= ''; $html{'qa_summary'} = '' if ($prior_summary == 0); # Blank out this menu if nothing to see return 1; } #endsub format_qa_summary sub _html_encode_entities{ my ($data) = @_; # escape single quotes. Double escape because it is in perl. #$data =~ s/'/\\'/g; #$data =~ s/"/\"/g; use HTML::Entities; HTML::Entities::encode_entities($data); # HTML::Entities double escape dobule quotes so it has to be dealt explicitly. $data =~ s/&quot;/"/g; return $data; } sub _get_right_cat_ad { my ($data_ref) = @_; my $main_catname = $$data_ref{'directory_name'}; $main_catname =~ s/[\'\" ]+//g; # These characters were causing the ads to fail. my $right_cat_ad = <
RIGHT_AD return $right_cat_ad; } sub _get_left_cat_ad { my ($data_ref) = @_; my $main_catname = $$data_ref{'directory_name'}; $main_catname =~ s/[\'\" ]+//g; # These characters were causing the ads to fail. my $left_cat_ad = <
LEFT_AD return $left_cat_ad; } #---------------------------------------------------------------------- sub company_name_from_db { my ($store_id) = @_; my $sql = qq|select Company from Shops_7x0 where Store_ID=$store_id|; my $sth = &sql_query($d{'hndl'}{'fgdb'}, $sql); my %hash = $sth->FetchHash if ($sth); return $hash{'Company'}; } #---------------------------------------------------------------------- sub redirect_page_in_url { my ($pageno) = @_; my $new_url = $ENV{'SCRIPT_URL'}; $new_url =~ s/p-$pageno//g; $new_url =~ s|[/]+|/|g; my $qs = $ENV{'QUERY_STRING'}; $qs .= '&' if ($qs); $qs .= "p=$pageno"; print "Status: 301 Moved Permanently\n"; print 'Location: https://www.findgift.com' . $new_url . '?' . $qs; print "\n\n"; exit(0); } #---------------------------------------------------------------------- sub _display_landing_page_guide{ print "Content-type: text/html\n\n"; my($input) = @_; my $landing_page_guide = $input->{'landing_page_guide'}; my $occasion = $input->{'occasion'}; # url has mothers-day whereas folder is templates/mothers_day. $occasion =~ s/-/_/g; my $tt = Template->new({ INCLUDE_PATH => "/www/findgift.com/templates/$occasion", INTERPOLATE => 1, ABSOLUTE => 1, }) || die "$Template::ERROR\n"; my %header_holiday = (); data_header_holiday(\%header_holiday); my $arr_events = FG::Calendar::get_calendar_events($d{'hndl'}{'fgdb'}); my $cal_header = FG::Calendar::get_calendar_events_header( $arr_events ) if @$arr_events; my $holidays_arr = FG::Utils::get_holidays(\%d); my $vars = { header_holiday => \%header_holiday, header_holiday_link => lc($header_holiday{'link'}), holidays => $holidays_arr, cal_header => $cal_header, cal_events => $arr_events, css_ver => $d{'css_ver'}, member_name => $w{'member_name'}, landing_page => $occasion, }; my $tpl = $landing_page_guide . ".tt"; $tt->process( $tpl, $vars ) || die $tt->error(), "\n"; exit(0); } #---------------------------------------------------------------------- sub _remove_deleted_categories { my($vector) = @_; return if $vector < 0; my $redirect_url; my @vec_arr = split(':', $vector); # return if it is holiday or occasion like christmas and birthday. return if $vec_arr[5] eq 'x'; my @cat_arr = split(',',$vec_arr[5]); # All deleted ids are leaf categories, they have no children so it will be the last one in the array to check. my $del_cat = $cat_arr[$#cat_arr]; my $sql = "SELECT Parent_ID,Status FROM Gift_Category_List_7x0 WHERE category_id = $del_cat"; my $sth = &sql_query($d{'hndl'}{'schdb'}, $sql); my %hash = $sth->FetchHash; if( $hash{'Status'} == 99 ){ my $parent_del_cat = $cat_arr[-2]; if( $parent_del_cat == $hash{'Parent_ID'} ){ # parent is there in the vector, just remove del_cat from vector pop(@cat_arr); } else { # replace deleted id with parent id $cat_arr[$#cat_arr] = $hash{'Parent_ID'}; } my $cat_ids = join(',', @cat_arr); $vec_arr[5] = $cat_ids; my $new_vector = join(':', @vec_arr); my $new_enc_vector_url = FG::Search::convert_vector_url($new_vector); my $new_enc_vector = FG::Search::encode_vector($new_enc_vector_url); $redirect_url = $s{'com'}{'web'} . '/categories/' . $new_enc_vector; } return $redirect_url; } #----------------------------------------------------------------------