Index: openacs-4/packages/ecommerce/www/admin/products/add-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/products/add-2.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/ecommerce/www/admin/products/add-2.tcl 24 Feb 2005 13:33:15 -0000 1.6 +++ openacs-4/packages/ecommerce/www/admin/products/add-2.tcl 27 Apr 2008 01:38:24 -0000 1.7 @@ -132,97 +132,35 @@ # Things to generate: # 1. generate a product_id -# wtem@olywa.net, 2001-03-25 -# we are using ec_product.new pl/sql function now instead of old sequence/insert set product_id [db_nextval acs_object_id_seq] -# 2. generate a directory name (and create the directory) to store pictures -# and other supporting product info - -# let's have dirname 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"}] { - #maybe there aren't 4 letters in the product name - set dirname "$letters_in_product_name$product_id" -} - -# Get the directory where dirname is stored -set subdirectory "[ec_data_directory][ec_product_directory][ec_product_file_directory $product_id]" -# if you get errors here -# it may be because you have not completed your technical setup completely -# namely you need to set -# the EcommerceDataDirectory parameter and ProductDataDirectory parameter -# and create the corresponding directory in the file system -ec_assert_directory $subdirectory - -set full_dirname "$subdirectory/$dirname" -ec_assert_directory $full_dirname - # if an image file has been specified, upload it into the # directory that was just created and make a thumbnail (using # dimensions specified in parameters/whatever.ini) +set thumbnail "" + if { [info exists upload_file] && ![string compare $upload_file ""] == 0 } { - # this takes the upload_file and sticks its contents into a temporary - # file (will be deleted when the thread ends) + # tmp file will be deleted when the thread ends set tmp_filename ${upload_file.tmpfile} - - # so that we'll know if it's a gif or a jpg - set file_extension [file extension $upload_file] - - # copies this temp file into a permanent file - set perm_filename "$full_dirname/product[string tolower $file_extension]" - ns_cp $tmp_filename $perm_filename - - # create thumbnails + # copy image & create thumbnails # thumbnails are all jpg files - # set thumbnail dimensions - set use_both_param_dimensions [parameter::get -parameter ThumbnailSizeOuterlimits] - set thumbnail_width_is_blank [catch {set thumbnail_width [parameter::get -parameter ThumbnailWidth]} ] - set thumbnail_height_is_blank [catch {set thumbnail_height [parameter::get -parameter ThumbnailHeight]} ] - if { $use_both_param_dimensions } { - set convert_dimensions "${thumbnail_width}x${thumbnail_height}>" - } else { - if { $thumbnail_width_is_blank } { - if { $thumbnail_height_is_blank } { - set convert_dimensions "100x10000" - } else { - set convert_dimensions "10000x${thumbnail_height}" - } - } else { - set convert_dimensions "${thumbnail_width}x10000" - } - } + ecommerce::resource::make_product_images \ + -file_extension [file extension $upload_file] \ + -product_id $product_id \ + -product_name $product_name \ + -tmp_filename ${upload_file.tmpfile} - set system_url [parameter::get -package_id [ad_acs_kernel_id] -parameter SystemURL] - set system_name [parameter::get -package_id [ad_acs_kernel_id] -parameter SystemName] - set image_comment "from $system_url $system_name" - - set perm_thumbnail_filename "$full_dirname/product-thumbnail.jpg" - - set convert [ec_convert_path] - if {![string equal "" $convert] && [file exists $convert]} { - if [catch {exec $convert -geometry $convert_dimensions -comment \"$image_comment\" $perm_filename $perm_thumbnail_filename} errmsg ] { - ad_return_complaint 1 " - I am sorry, an error occurred converting the picture. $errmsg - " - } - } else { - ad_return_complaint 1 { - I am sorry, I could not find ImageMagick's convert utility for - image thumbnail creation. Please reconfigure this subsystem before - uploading pictures - } - } } -set linked_thumbnail [ec_linked_thumbnail_if_it_exists $dirname] +set dirname [ecommerce::resource::dirname -product_id $product_id -product_name $product_name] +# TODO: improve, along with admin add product pages +set linked_thumbnail [ecommerce::resource::image_tag -type Thumbnail -product_id $product_id -product_name $product_name] + # Need to let them select template based on category doc_body_append "[ad_admin_header "Add a Product, Continued"] @@ -233,7 +171,7 @@