Index: openacs-4/packages/ams/www/attribute-options-update.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/attribute-options-update.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/ams/www/attribute-options-update.tcl 28 May 2005 15:37:27 -0000 1.3 +++ openacs-4/packages/ams/www/attribute-options-update.tcl 7 Jun 2005 07:44:14 -0000 1.4 @@ -1,50 +1,58 @@ ad_page_contract { - Update sort order @author Matthew Geddert openacs@geddert.com @creation-date 2004-07-28 @cvs-id $Id$ - - } { option:array sort_key:array attribute_id:integer,notnull } -# first we check to see if there are new options. -# if yes we add them + +# first we check to see if there are new options. if yes we add them + foreach option_key [list new1 new2 new3] { set option_string [string trim $option(${option_key})] - if { [exists_and_not_null option_string] } { - set option_id [ams::option::new -attribute_id $attribute_id -option $option_string] + if {[exists_and_not_null option_string]} { + + # Replace the pretty_name and pretty_plural with the message key, so it is inserted correctly in the database + set option_string [lang::util::convert_to_i18n -text $option_string -prefix "ams_option"] + + set option_id [ams::option::new \ + -attribute_id $attribute_id \ + -option $option_string] set sort_key(${option_id}) $sort_key(${option_key}) } } -# now that all the options are in the database we get the "old" sort order -# if not value for sort_key is provided we will keep the same order as before -set option_ids [db_list get_option_ids { select option_id from ams_option_types where attribute_id = :attribute_id order by sort_order }] +# now that all the options are in the database we get the "old" sort +# order if not value for sort_key is provided we will keep the same +# order as before -# first we get the highest sort_order so variables without a sort_order can be given one +set option_ids [db_list get_option_ids {select option_id from ams_option_types where attribute_id = :attribute_id order by sort_order}] + +# first we get the highest sort_order so variables without a +# sort_order can be given one + set highest_sort 0 foreach option_id $option_ids { - if { $sort_key(${option_id}) > $highest_sort } { + if {$sort_key(${option_id}) > $highest_sort} { set highest_sort $sort_key(${option_id}) - } + } } - db_transaction { foreach option_id $option_ids { set sort_order $sort_key(${option_id}) incr highest_sort - db_dml update_sort_order { update ams_option_types set sort_order = :highest_sort where sort_order = :sort_order and attribute_id = :attribute_id } - if { ![exists_and_not_null sort_order] } { + db_dml update_sort_order {update ams_option_types set sort_order = :highest_sort where sort_order = :sort_order and attribute_id = :attribute_id} + if {![exists_and_not_null sort_order]} { incr highest_sort 1 - set sort_order $highest_sort + set sort_order $highest_sort } - db_dml update_sort_order { update ams_option_types set sort_order = :sort_order where option_id = :option_id } + db_dml update_sort_order {update ams_option_types set sort_order = :sort_order where option_id = :option_id} } } -ad_returnredirect -message "[_ ams.Options_Updated]" "attribute?[export_vars -url {attribute_id}]" +ad_returnredirect -message "[_ ams.Options_Updated]" "attribute?[export_vars \ +-url {attribute_id}]"