Index: openacs-4/packages/ecommerce/www/admin/products/list.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/list.tcl,v
diff -u -r1.5 -r1.6
--- openacs-4/packages/ecommerce/www/admin/products/list.tcl 9 Mar 2004 00:59:51 -0000 1.5
+++ openacs-4/packages/ecommerce/www/admin/products/list.tcl 14 Aug 2008 10:53:42 -0000 1.6
@@ -1,14 +1,19 @@
# www/[ec_url_concat [ec_url] /admin]/products/list.tcl
ad_page_contract {
- Lists a class of products, ordered to the user's taste.
+ Lists a class of products, ordered to the user's taste.
- @author Philip Greenspun (philg@mit.edu)
- @creation-date July 18, 1999
- @cvs-id $Id$
- @author ported by Jerry Asher (jerry@theashergroup.com)
+ @param how_many How many products to display on the page
+ @param start_row Where to begin from
+
+ @author Philip Greenspun (philg@mit.edu)
+ @creation-date July 18, 1999
+ @cvs-id $Id$
+ @author ported by Jerry Asher (jerry@theashergroup.com)
} {
- category_id:integer,notnull,optional
- order_by:optional
+ category_id:integer,notnull,optional
+ order_by:optional
+ {how_many:naturalnum {[ad_parameter -package_id [ec_id] ProductsToDisplayPerPage ecommerce]}}
+ {start_row:naturalnum "0"}
}
ad_require_permission [ad_conn package_id] admin
@@ -27,51 +32,89 @@
if { ![info exists order_by] || [empty_string_p $order_by] || $order_by == "name"} {
set order_by_clause "order by upper(product_name)"
- set ordering_options "sales | name | age | comments"
+ set ordering_options "sales | name | age | comments | last modified"
} elseif { $order_by == "sales" } {
set order_by_clause "order by n_items_ordered desc"
- set ordering_options "sales | name | age | comments"
+ set ordering_options "sales | name | age | comments | last modified"
} elseif { $order_by == "comments" } {
set order_by_clause "order by n_comments desc"
- set ordering_options "sales | name | age | comments"
+ set ordering_options "sales | name | age | comments | last modified"
+} elseif { $order_by == "last_edit_date" } {
+ set order_by_clause "order by last_modified desc"
+ set ordering_options "sales | name | age | comments | last modified"
} else {
# must be age
set order_by_clause "order by available_date desc"
- set ordering_options "sales | name | age | comments"
+ set ordering_options "sales | name | age | comments | last modified"
}
-doc_body_append "[ad_admin_header $title]
+set header " order by $ordering_options"
+set context [list [list index Products] $title]
-
$title
-[ad_context_bar [list "../" "Ecommerce([ec_system_name])"] [list "index.tcl" "Products"] $title]
-
+set list_items ""
-order by $ordering_options
+set have_how_many_more_p f
+set count $start_row
-
-"
+if {[info exists category_id]} {
+ db_1row product_select_count_for_category "
+ select count(product_id) as product_count
+ from ec_category_product_map map
+ where map.category_id = :category_id
+ "
+} else {
+ db_1row product_select_count_all "
+ select count(product_id) as product_count
+ from ec_products
+ "
+}
-set list_items ""
+db_foreach product_select "SELECT ep.product_id, ep.product_name, ep.available_date, ep.last_modified, count(distinct eir.item_id) as n_items_ordered, count(distinct epc.comment_id) as n_comments FROM ec_products ep, ec_items_reportable eir, ec_product_comments epc WHERE ep.product_id = eir.product_id(+) AND ep.product_id = epc.product_id(+) GROUP BY ep.product_id, ep.product_name, ep.available_date, ep.last_modified $category_exclusion_clause $order_by_clause" {
-db_foreach product_select "SELECT ep.product_id, ep.product_name, ep.available_date, count(distinct eir.item_id) as n_items_ordered, count(distinct epc.comment_id) as n_comments FROM ec_products ep, ec_items_reportable eir, ec_product_comments epc WHERE ep.product_id = eir.product_id(+) AND ep.product_id = epc.product_id(+) GROUP BY ep.product_id, ep.product_name, ep.available_date $category_exclusion_clause $order_by_clause" {
append list_items "- $product_name
-(available since [util_AnsiDatetoPrettyDate $available_date]; $n_items_ordered sold"
+ (available since [util_AnsiDatetoPrettyDate $available_date]; $n_items_ordered sold"
if { $n_comments > 0 } {
- append list_items "; $n_comments customer reviews"
+ append list_items "; $n_comments customer reviews"
}
- append list_items ")\n"
-
+ append list_items ")
"
+ incr count
}
+if { $product_count > [expr $start_row + (2 * $how_many)] } {
+ # We know there are at least how_many more items to display
+ # next time
+ set have_how_many_more_p t
+} else {
+ set have_how_many_more_p f
+}
if { [empty_string_p $list_items] } {
- doc_body_append "No products found.\n"
+ set list_items "No products found.
"
} else {
- doc_body_append $list_items
+ set list_items ""
}
-doc_body_append "
+if { $start_row >= $how_many } {
+ set prev_link "Previous $how_many"
+} else {
+ set prev_link ""
+}
-[ad_admin_footer]
-"
+if { $have_how_many_more_p == "t" } {
+ set next_link "Next $how_many"
+} else {
+ set number_of_remaining_products [expr $product_count - $start_row - $how_many]
+ if { $number_of_remaining_products > 0 } {
+ set next_link "Next $number_of_remaining_products"
+ } else {
+ set next_link ""
+ }
+}
+
+if { [empty_string_p $next_link] || [empty_string_p $prev_link] } {
+ set separator ""
+} else {
+ set separator "|"
+}
+