Index: openacs-4/packages/ecommerce/www/admin/products/upload-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/upload-2.tcl,v diff -u -N -r1.9 -r1.10 --- openacs-4/packages/ecommerce/www/admin/products/upload-2.tcl 30 Apr 2008 11:38:11 -0000 1.9 +++ openacs-4/packages/ecommerce/www/admin/products/upload-2.tcl 16 Aug 2008 05:12:52 -0000 1.10 @@ -19,34 +19,25 @@ set peeraddr [ns_conn peeraddr] # Grab package_id as context_id - set context_id [ad_conn package_id] -doc_body_append "[ad_admin_header "Uploading Products"] +set serious_errors 0 -

Uploading Products

+set title "Uploading Products" +set context [list [list index Products] $title] -[ad_context_bar [list "../" "Ecommerce([ec_system_name])"] [list "index.tcl" "Products"] "Uploading Products"] - -
- -
-" - # Get the name of the transfered data file - set unix_file_name ${csv_file.tmpfile} # Check that the file is readable. - if { ![file readable $unix_file_name] } { - doc_body_append "Cannot read file $unix_file_name" - return + append error_message "Cannot read file ${unix_file_name}. " + set serious_errors 1 } # Check that delimiter is one character, if used if { [string length $delimiter] != 1 && [string eq $file_type "delim"]} { - doc_body_append "Delimiter is not one character long." - return + append error_message "Delimiter is not one character long." + set serious_errors 1 } # Accept only field names that exist in the ec_product table and are @@ -59,27 +50,22 @@ # Check each entry in the datafile for the following required fields. # These fields are required so that we can check if a product already # in the products table and should be update rather than created. - set required_field_names {sku product_name} # Initialize each legal field name as the datafile might not mention # each and every one of them. - foreach legal_field_name $legal_field_names { set $legal_field_name "" } # Start reading. # use file_type to determine which proc to delimit data - set datafilefp [open $unix_file_name] set count 0 -set errors 0 +set errors $serious_errors set success_count 0 +set doc_body "" -# Continue reading the file till the end but stop when an error -# occured. - # read line, depending on file type if {[string eq $file_type "csv"]} { set line_status [ns_getcsv $datafilefp elements] @@ -92,21 +78,20 @@ set line_status -1 } +# Continue reading the file till the end but stop when an error occured. while { $line_status != -1 && !$errors} { incr count if { $count == 1 } { # First row, grab the field names and their number. - set field_names $elements set number_of_fields [llength $elements] # Check the field names against the list of legal names - foreach field_name $field_names { if {[lsearch -exact $legal_field_names $field_name] == -1} { incr errors - doc_body_append "

FAILURE! $field_name is not an allowed field name.

" + append doc_body "

FAILURE! $field_name is not an allowed field name.

" } } } else { @@ -162,7 +147,6 @@ # We found a product_id for the given sku, let's # update the product. - if { [catch {db_dml product_update " update ec_products set user_id = :user_id, @@ -187,20 +171,18 @@ template_id = :template_id where product_id = :product_id; "} errmsg] } { - doc_body_append "

FAILURE! Product update of $product_name failed with error:<\p>

$errmsg

" + append doc_body "

FAILURE! Product update of $product_name failed with error:<\p>

$errmsg

" } else { - doc_body_append "

Updated $product_name

" + append doc_body "

Updated $product_name

" } } else { # Generate a product_id - set product_id [db_nextval acs_object_id_seq] # Dirname will be the first four letters (lowercase) # of the product_name followed by the product_id (for # uniqueness) - regsub -all {[^a-zA-Z]} $product_name "" letters_in_product_name set letters_in_product_name [string tolower $letters_in_product_name] if [catch {set dirname "[string range $letters_in_product_name 0 3]$product_id"}] { @@ -238,16 +220,14 @@ :size_list, :peeraddr )"} errmsg] } { - doc_body_append "FAILURE! Product creation of $product_name failed with error:<\p>

$errmsg

" + append doc_body "FAILURE! Product creation of $product_name failed with error:<\p>

$errmsg

" } else { - doc_body_append "

Created $product_name

" + append doc_body "

Created $product_name

" # we have to also write a row into ec_custom_product_field_values # for consistency with add*.tcl (added 1999-08-08, inadvertently removed 20020504) - - if { [catch {db_dml custom_product_field_insert "insert into ec_custom_product_field_values (product_id, last_modified, last_modifying_user, modified_ip_address) values (:product_id, now(), :user_id, :peeraddr)" } errmsg] } { - doc_body_append "FAILURE! Insert into ec_custom_product_field_values failed for product_id=$product_id with error: $errmsg
\n" + append doc_body "FAILURE! Insert into ec_custom_product_field_values failed for product_id=$product_id with error: $errmsg
\n" } } } @@ -265,13 +245,10 @@ template_id = :template_id where product_id = :product_id; "} errmsg] } { - doc_body_append "FAILURE! Product update of new product $product_name failed with error:<\p>

$errmsg

" + append doc_body "FAILURE! Product update of new product $product_name failed with error:<\p>

$errmsg

" } - } - # Product line is completed, increase counter - incr success_count } @@ -289,7 +266,6 @@ set line_status -1 } - } if { $success_count == 1 } { @@ -298,9 +274,7 @@ set product_string "products" } -doc_body_append "
+set total_lines "[ec_decode $count "0" "0" [expr $count -1]]" -

Successfully loaded $success_count $product_string out of [ec_decode $count "0" "0" [expr $count -1]]. -[ad_admin_footer] -" +