Index: openacs-4/packages/invoices/www/offer-ae.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-ae.tcl,v diff -u -r1.14 -r1.15 --- openacs-4/packages/invoices/www/offer-ae.tcl 16 Dec 2005 09:02:33 -0000 1.14 +++ openacs-4/packages/invoices/www/offer-ae.tcl 27 Dec 2005 16:39:35 -0000 1.15 @@ -18,6 +18,7 @@ {item_price:array,optional} {item_rebate:array,optional} {offer_item_id:array,optional} + {delete_files:optional,multiple} {__new_p 0} {mode edit} {accept:optional} @@ -55,6 +56,7 @@ if {![info exists offer_id] || $__new_p} { set page_title "[_ invoices.iv_offer_Add2]" set _offer_id 0 + set files "" set list_id [iv::price_list::get_list_id -organization_id $organization_id] if {[empty_string_p $list_id]} { set currency [parameter::get -parameter "DefaultCurrency" -default "EUR" -package_id $package_id] @@ -64,6 +66,11 @@ } } else { db_1row get_organization_and_currencies {} + set files {} + db_foreach get_files {} { + lappend files [list "$file_name ($file_length bytes)" $file_id] + } + set cur_vat_percent [format "%.1f" $cur_vat_percent] if {$mode == "edit"} { db_1row check_invoices {} @@ -118,7 +125,7 @@ set list_id [iv::price_list::get_list_id -organization_id $organization_id] db_multirow pricelist all_prices {} -ad_form -name iv_offer_form -action offer-ae -mode $mode -has_submit $has_submit -has_edit $has_edit -export {organization_id return_url} -form { +ad_form -name iv_offer_form -action offer-ae -mode $mode -has_submit $has_submit -has_edit $has_edit -export {organization_id return_url} -html {enctype multipart/form-data} -form { {offer_id:key} {organization_namex:text(inform) {label "[_ invoices.iv_offer_organization]"} {value "$organization_name"}} {title:text {label "[_ invoices.iv_offer_Title]"} {html {size 80 maxlength 1000}} {help_text "[_ invoices.iv_offer_Title_help]"}} @@ -212,9 +219,30 @@ {amount_sum:float,optional {label "[_ invoices.iv_offer_amount_sum]"} {html {size 10 maxlength 10 disabled t}} {help_text "[_ invoices.iv_offer_amount_sum_help]"} {after_html $currency}} {amount_total:float,optional {label "[_ invoices.iv_offer_amount_total]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_offer_amount_total_help]"} {after_html $currency}} } -} + # let user delete uploaded files + if {[exists_and_not_null files]} { + ad_form -extend -name iv_offer_form -form { + {delete_files:integer(checkbox),multiple,optional {label "[_ invoices.iv_offer_file_delete]"} {help_text "[_ invoices.iv_offer_file_delete_help]"} {options $files}} + } + } + # let user upload a file + ad_form -extend -name iv_offer_form -form { + {upload_file:file,optional {label "[_ invoices.iv_offer_file]"} {help_text "[_ invoices.iv_offer_file_help]"}} + } + +} else { + # we are just displaying an offer + + # display uploaded files + if {[exists_and_not_null files]} { + ad_form -extend -name iv_offer_form -form { + {delete_files:integer(checkbox),multiple,optional {label "[_ invoices.iv_offer_file_view]"} {help_text "[_ invoices.iv_offer_file_view_help]"} {options $files}} + } + } +} + if {$_offer_id} { # edit or display existing offer set i 0 @@ -552,11 +580,11 @@ set item(rebate) $item_rebate($i) set item(page_count) $item_pages($i) set item(file_count) $item_files($i) - set title_cat $item_title_cat($i) # generate item title from categories if empty title - if {[empty_string_p $item(title)]} { + if {[empty_string_p $item(title)] && [exists_and_not_null item_title_cat($i)]} { # if only single category + set title_cat $item_title_cat($i) if {[llength $title_cat] == 1} { set item(title) "#invoices.iv_offer_item_title_cat_1# ([category::get_name [lindex $title_cat 0]])" } @@ -633,7 +661,7 @@ category::map_object -object_id $new_item_rev_id $item(category) } - set offer_id [pm::project::get_project_item_id -project_id $new_offer_rev_id] + set offer_id [content::revision::item_id -revision_id $new_offer_rev_id] } } -edit_data { db_transaction { @@ -700,20 +728,48 @@ } } } -after_submit { + # upload new file + if {![empty_string_p $upload_file]} { + set filename [lindex $upload_file 0] + set tmp_filename [lindex $upload_file 1] + set file_mimetype [lindex $upload_file 2] + set n_bytes [file size $tmp_filename] + + if { $n_bytes > 0 } { + cr_import_content -title $filename $offer_id $tmp_filename $n_bytes $file_mimetype $filename + } + } + + # delete files + if {[info exists delete_files]} { + foreach file_id $delete_files { + db_exec_plsql delete_file {} + + set path "[cr_fs_path][cr_create_content_file_path $file_id ""]" + foreach revision [glob -directory $path "*"] { + ns_unlink $revision + } + ns_rmdir $path + } + } + + # link offer to project if {[exists_and_not_null project_id]} { catch { application_data_link::new -this_object_id $offer_id -target_object_id $project_id set _project_id $project_id } } + # set acceptance date if necessary if {[exists_and_not_null _project_id]} { set status [pm::project::get_status_description -project_item_id $_project_id] if {$status == "#acs-kernel.common_Open#"} { db_dml set_accepted_date {} } } + # set project deadline if {![empty_string_p $finish_date]} { db_dml set_finish_date {}