set pageID PG_4
cw source searchlimit.tcl
cw source mysql.tcl
### deal with related list
if { [info exists cw_args(fromcontent)] } {
set sdb(fromcontent) $cw_args(fromcontent)
set sdb(search_result_list) $sdb(related_result_list)
set sdb(listcriteria) "Related titles in our $sdb(catalog)"
}
### set up search limit
set defaultMax 200
if {![string length $sdb(searchLimit)]} {
set sdb(searchLimit) 20
}
setupSearchLimit $sdb(searchLimit) $sdb(search_result_list) $defaultMax
if { [info exists cw_args(curList)] } {
set curList $cw_args(curList)
if {![string length $curList]} {
set curList 0
}
set sdb(curList) $curList
} elseif { [info exists sdb(curList)] } {
set curList $sdb(curList)
} else {
cw log 2 "Error: Strange thing happens."
set curList 0
}
set results [getListContentsAtIndex $curList]
### set the first, next, prev and last pointers
### the next and prev access functions are coded with guards
### so you won't run off the end or beginning of the list.
### If you run off the end, a -1 is returned instead of an index,
### and you can test for that.
set first 0
set next [getIndexOfNextList $curList]
set prev [getIndexOfPrevList $curList]
set last [expr [getNumberOfLists] - 1]
### displaying the number of rec's found in the search
### Make sure we are using proper grammar for singular/plural
if {[string length $sdb(search_rlen)]} {
set len $sdb(search_rlen)
} else {
set len [llength $sdb(search_result_list)]
}
switch $len {
0 {
set matchTitles "no titles that match your search criteria."
set matchTitles2 "no titles in this category."
}
1 {
set matchTitles "one title matches your search criteria."
set matchTitles2 "one title in this category."
}
default {
set matchTitles "$len titles that match your search criteria."
set matchTitles2 "$len titles in this category."
}
}
### Build the glyphs for new.
##### Deal with the defference between "from contents" and "from search".
switch $sdb(fromcontent) {
0 {
set pageTitle "Search Results List"
set fromString "$sdb(listcriteria)
The catalog contains $matchTitles
"
}
1 {
set pageTitle "Category List"
set fromString "
$sdb(listcriteria)
The catalog contains $matchTitles2
"
}
2 {
set pageTitle "Related Titles List"
set fromString "$sdb(listcriteria)
The catalog contains $matchTitles2
"
}
3 {
set pageTitle "Search Results List"
set fromString "$sdb(listcriteria)
The catalog contains $matchTitles
"
}
default { set fromString "Jump to this page" }
}
cw source $cw_templatePath/templateTop.tcl
puts "
$fromString"
#cw log 2 "sdb(searchCriteriaPairs)=$sdb(searchCriteriaPairs)"
# If there are no results, present a link back to the
# search page or the table of contents page
# and don't try to list results.
set rowsCount 0
if { $len == 0} {
if { $sdb(fromcontent) == 1 } {
puts "Return to the Contents page"
} else {
puts "Return to the Search page
"
}
} else {
puts "
| "
DisplayListPagesMenu $curList head
puts " |
"
MysqlConnectProdDB
set columnList [GetColumnList $cw_product_tablepath]
if {$sdb(fromcontent) == 0} {
## new list style for orderable items
if {[string match Relevance $sdb(SortResult)] && [regexp {(General Media Text)} $sdb(RelevanceBy)]} {
set mdaImg "
"
} else {
set mdaImg ""
}
foreach record $results {
if {[regexp {Match_found_in_} $record]} {
if {[info exists cdb(Show_Relevance_Header)] && [string match Yes $cdb(Show_Relevance_Header)]} {
### 5.3.09 mes: change headers per client
if {[string match "Match_found_in_General_Media_Text" $record]} {
set record "Part of a Set"
}
regsub -all {_} $record { } header
set sdb(RelevanceBy) $header
puts "| $header |
"
}
if {[regexp {(General Media Text)} $header ]} {
set mdaImg "
"
} else {
set mdaImg ""
}
continue
}
set data [MysqlGrokRec $mysqlProdtbl Record_ID $record]
DataStringToArray $data prod $cw_product_tablepath $columnList
if {[regexp -nocase yes $prod(New)]} {
set newImg "
"
} else {
set newImg ""
}
if {[expr $rowsCount % 2] == 0} {
set colorCell " bgcolor=$cdb(color$sdb(catalog_id)Alt)"
} else {
set colorCell ""
}
set pic [GetItemImageString $prod(Picture_File) small {} {} "$prod(Title)"]
set description "$prod(Description)"
set desc_part [TruncateSentence $description 200]
if {[llength $prod(Catalog_Number_Web)] > 3} {
set showList [lrange $prod(Catalog_Number_Web) 0 2]
set ordercodeStr "[join $showList ", "]..."
} else {
set ordercodeStr [join $prod(Catalog_Number_Web) ", "]
}
set ordercode [lindex $prod(Catalog_Number_Web) 0]
set price [lindex $prod(Price_A) 0]
puts "
| $pic |
$prod(Title_Alpha)$newImg $mdaImg $desc_part more>>>
| [join $prod(Media) ", "] | $ordercodeStr
|
| "
incr rowsCount
}
} else {
puts ""
foreach record $results {
set data [MysqlGrokRec $mysqlProdtbl Record_ID $record]
DataStringToArray $data prod $cw_product_tablepath $columnList
puts "- $prod(Title_Alpha)
- "
set description "$prod(Description)"
if { [regexp -nocase {^(Online Activities|Related Web Sites)$} $prod(Record_Type)] } {
## 03/12/03 Cindy: For product that Record_Type is
## "Online Activities" or "Related Web Sites ", don't
## truncate the description.
puts $description
} else {
set desc_part [TruncateSentence $description 200]
puts "$desc_part..."
}
puts "
- "
if { [string length $prod(General_Media_Text)] } {
if { [regexp (\[^\013\]*\013) $prod(General_Media_Text) match]} {
puts "$match."
} else {
puts "$prod(General_Media_Text)."
}
}
set printGrade_Level {}
if { [llength $prod(Grade_Level)] } {
puts "[join $prod(Grade_Level) ", "]. "
}
if { [string length $prod(General_Catalog_Number)] } {
puts "$prod(General_Catalog_Number). "
}
if { [regexp -nocase "Y" $prod(New)] } {
puts "
"
}
if {$sdb(fromcontent) == 3} {
set reSource ""
if {[string length $prod(Sample_Lesson)] } {
append reSource "$prod(Sample_Lesson)
"
}
if {[string length $prod(Video_Preview)] } {
append reSource "$prod(Video_Preview)
"
}
if {[string length $prod(Online_Activity)] } {
append reSource "$prod(Online_Activity)
"
}
if {[string length $prod(Related_Web_Site)] } {
append reSource "$prod(Related_Web_Site)
"
}
if { [string length $reSource] > 5 } {
puts "$reSource"
}
}
puts " "
### end of each result display
}
puts "
"
}
MysqlDisconnect
puts "
"
DisplayListPagesMenu $curList bottom
}
cw source $cw_templatePath/templateBottom.tcl