# file: search.web # Copyright (c) 1996-2013 Cuesta Technologies, LLC # All rights reserved. # This document contains confidential and/or proprietary information # beloging to Cuesta Technologies, LLC. # Package: tat # # Purpose: # # Requires: # set pageID PG_12 ################## copied from cdw for email friend page ################ set quickSearch {} set URL_search_field {} set URL_search_value {} set URL_search_string "" ########################################################## redo_form_values set recordedFields {Title Keywords Description Category Subcategory Special_Categories} ## reset the browser search if user do advanced search. if {[info exists cw_val(Search)] || [info exists cw_val(Select)]} { set sdb(Category) "" set sdb(Subcategory) "" set sdb(Grade) "" set sdb(lmTitle) Categories } cw source $cw_templatePath/templateSetup.tcl if {[info exists cw_args(CategoryBrowse)] || [info exists cw_args(SubcategoryBrowse)] || [info exists cw_args(GradeBrowse)] } { if {[string length $sdb(Category)]} { set cw_val(Category) $sdb(Category) set cw_vals(Category) [list $sdb(Category)] } if {[string length $sdb(Subcategory)]} { set cw_val(Subcategory) $sdb(Subcategory) set cw_vals(Subcategory) [list $sdb(Subcategory)] } if {[string length $sdb(Grade)]} { set cw_val(Grade_Begin_Code) $sdb(Grade) set cw_vals(Grade_Begin_Code) $sdb(Grade) set cw_val(Grade_End_Code) $sdb(Grade) set cw_vals(Grade_End_Code) $sdb(Grade) } } if {[info exists cw_args(SpecialCategories)]} { foreach pair $sdb(searchCriteriaPairs) { set field [lindex $pair 0] regsub $field $pair {} value cw log 2 "pair=$pair; $field=$value" if {[string match Special_Categories $field]} { if {[string match GSA $cw_args(SpecialCategories)]} { set cw_val($field) GSA set cw_vals($field) GSA } } else { set cw_val($field) $value set cw_vals($field) $value } } if {[string match GSA $cw_args(SpecialCategories)] && ![info exists cw_val(Special_Categories)]} { set cw_val(Special_Categories) GSA set cw_vals(Special_Categories) GSA } } if {[info exists cw_val] || ([info exists cw_args(where)] && [string match template $cw_args(where)])} { cw_val_trimSpace set listcriteria "" ## List of fileds that need to do tlob search (word And word) set tlobFieldList "" ## List of fileds that are mult fileds. set multFieldList {Category Subcategory Special_Categories} ## extra query string for some special search pass to MySQLRecordSearch proc. set appendQueryString "" set sdb(search_result_list) "" set sdb(searchcriteria) "" set sdb(searchCriteriaPairs) "" set omitlist {Title Grade_Begin_Code Grade_End_Code} set results {} ### check the input data and do complain ### marked_complain Title isonechar "Please enter more than one character for Title/Description/Keyword search." if {![info exists cw_args(where)]} { ### check if the search criteria is input if come from search page set input 0 set searchStep1 "" foreach var $recordedFields { if {[info exists cw_val($var)] && [string length $cw_val($var)]} { incr input if {[info exists cw_val(Select)]} { if {[lsearch $multFieldList $var] > -1} { foreach item $cw_vals($var) { append searchStep1 "" } } else { append searchStep1 "" } } else { lappend URL_search_field $var if {[lsearch $multFieldList $var] > -1} { cw log 2 "multFieldList: $var" lappend URL_search_value [make_percent $cw_vals($var)] } else { cw log 2 "Single Field $var" lappend URL_search_value [sub_percent $cw_val($var)] } } cw log 2 "URL_search_field=$URL_search_field" cw log 2 "URL_search_value=$URL_search_value" #cw log 2 "var is $var; incr the input: $input" } } ## Begin of check range fields. if {[info exists cw_val(Grade_Begin_Code)] && [info exists cw_val(Grade_End_Code)]} { if {[string compare [lindex $cdb(Grade_Range_Number) 0] $cw_val(Grade_Begin_Code)] || [string compare [lindex $cdb(Grade_Range_Number) end] $cw_val(Grade_End_Code)]} { incr input set checkgrade yes append searchStep1 "" } if {$cw_vals(Grade_Begin_Code) > $cw_vals(Grade_End_Code)} { set mark(grade) 1 lappend complaints "Please specify a valid grade range (from was greater than to)." } } if {[info exists cw_val(Select)]} { ## User select a Category and click "Select Subcategories" button. marked_complain Category isblank "Please select at lease one Category item for Subcategories search." } cw log 2 "input=$input" if { $input == 0 } { lappend complaints "Please enter some search criteria." } } else { ### come from quick search form. if {![info exists cw_val(quicksearch)] || ![string length $cw_val(quicksearch)] } { cw log 2 "NO INPUT FROM QUICK SEARCH" lappend complaints "Please enter some search criteria." } } if {[llength $complaints] == 0 } { set psearchableList [GetSearchableList $cw_tablepath $omitlist] foreach item $psearchableList { lappend sdb(searchCriteriaPairs) "$item $cw_vals($item)" cw log 2 "sdb(searchCriteriaPairs)=$sdb(searchCriteriaPairs)" } set substitutepairs { {Category {}} {Subcategory {}} } ### Generate search criteria #cw log 2 "multFieldList:$multFieldList" set listcriteria [GetSearchCriteria $psearchableList $substitutepairs] if {[info exists cw_args(where)] && [string match template $cw_args(where)]} { ## Generate special query string for Title, Keywords, ## ISBN Item_Number fields. set searchList {Title Keywords} append listcriteria "
   Keyword: $cw_val(quicksearch)" } else { ## create product search list based on product_table.t and cw_vals. if {[info exists cw_val(Title)] && [string length $cw_val(Title)]} { append listcriteria "
   Title/Description/Keyword: $cw_val(Title)" } } MysqlCleancw_val set morethanpairs {} set lessthanpairs {} ## Step 1: Connect to the mysql server MysqlConnectProdDB #cw log 2 "tlobFieldList=$tlobFieldList" if {[info exists cw_args(where)] && [string match template $cw_args(where)]} { set sdb(GSAOnly) No ### Do search for template quick search form. ### Search for Title, Description and Configuration_Text cw stats QUICKSEARCH $cw_val(quicksearch) lappend sdb(searchCriteriaPairs) "Title $cw_val(quicksearch)" cw log 2 "quick search: $cw_val(quicksearch)" set titleORList {} foreach item $searchList { if {[llength $cw_val(quicksearch)] == 1 } { lappend titleORList "$item LIKE '% $cw_val(quicksearch) %' OR $item LIKE '$cw_val(quicksearch)%' OR $item LIKE '%$cw_val(quicksearch)'" #lappend titleORList "$item REGEXP ' $cw_val(quicksearch) ' OR $item REGEXP '^$cw_val(quicksearch)' OR $item REGEXP '$cw_val(quicksearch)$'" } else { lappend titleORList [CreateOrderedTlobSearchQuery $item $cw_val(quicksearch)] } lappend URL_search_field $item lappend URL_search_value [sub_percent $cw_val(quicksearch)] } set titleString "([join $titleORList " OR "])" set appendQueryString [SetAppendQueryString $appendQueryString $titleString] set results [MysqlRecordSearch $mysqlProductTable $psearchableList Record_ID "Title" {} {} $morethanpairs $lessthanpairs $appendQueryString] cw log 2 "quick search:sdb(MYSQLqueryString): $sdb(MYSQLqueryString)" } else { ### Do search if come from search page if {[info exists checkgrade]} { lappend sdb(searchCriteriaPairs) "Grade_Begin_Code $cw_val(Grade_Begin_Code)" lappend sdb(searchCriteriaPairs) "Grade_End_Code $cw_val(Grade_End_Code)" set gradebegin [mapelement $cw_vals(Grade_Begin_Code) $cdb(Grade_Range_Number) $cdb(Grade_Range)] set gradeend [mapelement $cw_vals(Grade_End_Code) $cdb(Grade_Range_Number) $cdb(Grade_Range)] cw stats PF-GRADE_BEGIN $gradebegin cw stats PF-GRADE_END $gradeend ##Grade_Begin_Code >= $cw_val(Grade_End_Code) ##Grade_End_Code >= $cw_val(Grade_Start_Code) lappend morethanpairs {Grade_End_Code Grade_Begin_Code } lappend lessthanpairs {Grade_Begin_Code Grade_End_Code} lappend psearchableList Grade_Begin_Code Grade_End_Code append listcriteria "
   Grade Level: $gradebegin" if {$cw_val(Grade_End_Code) != $cw_val(Grade_Begin_Code)} { append listcriteria " - $gradeend" } lappend URL_search_field Grade_Begin_Code lappend URL_search_value $cw_val(Grade_Begin_Code) lappend URL_search_field Grade_End_Code lappend URL_search_value $cw_val(Grade_End_Code) } if {[info exists cw_val(Select)]} { ## User select a Category and click "Select Subcategories" button. foreach cate $cw_vals(Category) { set code [GetItemCode $cate] set cateVal [sub_underline $cate] #set subCate($cateVal) [MysqlGetRelatedFieldValues $mysqlProductTable Category $cate Subcategory mult] #cw log 2 "code=$code, cateVal=$cateVal" set subCate($cateVal) $cdb(${code}Subcategory) #cw log 2 "subCate($cateVal)=$subCate($cateVal)" set subCateShow($cateVal) $cdb(${code}SubcategoryShow) #cw log 2 "subCateShow($cateVal)=$subCateShow($cateVal)" } } else { cw stats SEARCHPAGE search if {[info exists cw_val(Special_Categories)] && [string match GSA $cw_val(Special_Categories)]} { set sdb(GSAOnly) Yes } else { set sdb(GSAOnly) No } if {[info exists cw_val(Title)] && [string length $cw_val(Title)]} { lappend sdb(searchCriteriaPairs) "Title $cw_val(Title)" ## Generate special query string for Title field. set searchList {Title Description Keywords} set titleORList {} foreach item $searchList { if {[llength $cw_val(Title)] == 1} { #lappend titleORList "$item REGEXP ' $cw_val(Title) ' OR $item REGEXP '^$cw_val(Title)' OR $item REGEXP '$cw_val(Title)$'" lappend titleORList "$item LIKE '% $cw_val(Title) %' OR $item LIKE '$cw_val(Title) %' OR $item LIKE '% $cw_val(Title)'" } else { lappend titleORList [CreateOrderedTlobSearchQuery $item $cw_val(Title)] } } lappend URL_search_field $item lappend URL_search_value [sub_percent $cw_val(Title)] set titleString "([join $titleORList " OR "])" set appendQueryString [SetAppendQueryString $appendQueryString $titleString] } #cw log 2 "appendQueryString=$appendQueryString" ## do MysqlRecordSearch set results [MysqlRecordSearch $mysqlProductTable $psearchableList Record_ID "Title" {} {} $morethanpairs $lessthanpairs $appendQueryString] cw log 2 "sdb(MYSQLqueryString): $sdb(MYSQLqueryString)" } } ## generate Category and Subcategory search criteria. remove the code. if {[info exists cw_vals(Category)]} { append listcriteria "
   Category: " set tmpList {} foreach itm $cw_vals(Category) { set vle [GetItemValue $itm] lappend tmpList $vle } append listcriteria [join $tmpList " or "] } if {[info exists cw_vals(Subcategory)]} { append listcriteria "
   Subcategory: " set tmpList {} foreach itm $cw_vals(Subcategory) { set vle [GetItemValue $itm] lappend tmpList $vle } append listcriteria [join $tmpList " or "] } ##Added the HTML end tags to search criteria append listcriteria [GetSearchCriteriaEnd] ## Disconnect the mysql server MysqlDisconnect set sdb(searchcriteria) $listcriteria if {![info exists cw_val(Select)]} { ############################################# #### copied from cdw for email friend page ##### ### Create the URL that can duplicate the search if {[info exists cw_args(where)] && [string match template $cw_args(where)]} { set URL_search_string "$cw_pageURL/search$webPgExtn?s@0+where@template+&quicksearch=[sub_percent $cw_val(quicksearch)]" } else { set URL_search_string $cw_pageURL/search$webPgExtn?s@0+& foreach field $URL_search_field { set values [mapelement $field $URL_search_field $URL_search_value] if {[lsearch $multFieldList $field]> -1} { set mult_value "" foreach item $values { append mult_value "[sub_percent $item]," } set len [string length $mult_value] set values [string range $mult_value 0 [expr $len - 2]] } else { set values [sub_percent $values] } append URL_search_string $field=$values& } } set len [string length $URL_search_string] cw log 2 "1.URL: $URL_search_string" ### 11.17.16 mes: truncating URL_search_string causes link in emailpage.web ### to not work # set URL_search_string [string range $URL_search_string 0 [expr $len - 2]] cw log 2 "2.URL: $URL_search_string" set sdb(URL_search_string) $URL_search_string ### /end of creat URL string ################################################## set sdb(resultType) search_result_list set sdb(search_result_list) $results DoStats $recordedFields set resNum [llength $results] cw log 2 "resNum=$resNum" if {$resNum == 0} { set noresult 1 } elseif {$resNum ==1} { cw redirect product$webPgExtn$nocache+record@$sdb(search_result_list)+frompage@search force } else { if {[info exists cw_val(List_Limit)]} { set sdb(listLimit) $cw_val(List_Limit) cw log 2 "sdb(listLimit)====$sdb(listLimit)" } else { set sdb(listLimit) [lindex $cdb(resultLimitList) 1] } if {![string length $sdb(listShowType)]} { set sdb(listShowType) list } set sdb(sort) "" cw log 2 "sdb(listShowType)=$sdb(listShowType)" cw redirect $sdb(listShowType)$webPgExtn$nocache+curList@0+frompage@search force } } } } cw source $cw_templatePath/templateTop.tcl ######################## # Add your own code here ######################## if {[info exists cw_args(prod)] && [string match no $cw_args(prod)]} { puts "That product is no longer available. Please use the search page to find products that meet your needs." } if {[info exists noresult] && [string match 1 $noresult]} { puts "$sdb(searchcriteria)
There are no items that meet your selected criteria. Please try again.

" } puts "

" ## Select Subcategory if {[info exists cw_val(Select)] && ![llength $complaints]} { puts "$sdb(searchcriteria)
Back to Advanced Search

Select Subcategories to refine your search:

" if {[info exists searchStep1]} { cw log 2 "searchStep1=$searchStep1" puts $searchStep1 } set cateList [array names subCate] set cateList [lsort $cateList] set flag 0 foreach cateVal $cateList { set cate [unsub_underline $cateVal] set code [GetItemCode $cate] set value [GetItemValue $cate] puts "" if {[llength $subCate($cateVal)]} { incr flag puts "" #cw_checkboxes2 Subcategory $subCate($cateVal) 2 {} {} {} {} {} h {} "nowrap" cw_checkboxes2 Subcategory $subCateShow($cateVal) 3 {} {} {} {} $subCate($cateVal) h {} "nowrap" puts "" } } puts "
$value
 
" if {$flag} { puts "" } else { puts "There are no Subcategory items for the Category you selected.
" } } else { #### search form #### puts "
Limit Search Results To  " cw_popup List_Limit $cdb(resultLimitList) puts "  Items Per Page
" ### 6.20.13 mes: client does not want to show GSA checkbox to non-gsa user if {[IsGSAcustomer]} { puts "" } puts "
Title/Description/Keyword:  " complain_mark Title * cw_text Title {} 30 puts "
Grade/Age Levels: From: " complain_mark grade * if {![info exists cw_vals(Grade_Begin_Code)] || [llength $cw_vals(Grade_Begin_Code)] == 0} { set gradebegin "[lindex $cdb(Grade_Range_Number) 0]" } else { set gradebegin $cw_vals(Grade_Begin_Code) } cw_popupE Grade_Begin_Code $cdb(Grade_Range) {} {} {} {} $gradebegin {} $cdb(Grade_Range_Number) puts " To: " complain_mark grade * if {![info exists cw_vals(Grade_End_Code)] || [llength $cw_vals(Grade_End_Code)] == 0} { set gradeend [lindex $cdb(Grade_Range_Number) end] } else { set gradeend $cw_vals(Grade_End_Code) } cw_popupE Grade_End_Code $cdb(Grade_Range) {} {} {} {} $gradeend {} $cdb(Grade_Range_Number) puts "
(Your search will include all grades/ages if you do not change the beginning or ending level.)
 
" cw_single_checkbox Special_Categories {   GSA products only} {} GSA puts "
" #cw_checkboxes2 Category $cdb(Category) 2 {} {} {} {} {} v {} "nowrap" cw_checkboxes2 Category $cdb(CategoryShow) 3 {} {} {} {} $cdb(Category) v {} "nowrap" puts "
Category: (Your search will include all categories if you do not select one.)
   
" } puts "" cw source $cw_templatePath/templateBottom.tcl