Index: openacs-4/packages/ams/sql/postgresql/ams-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/sql/postgresql/ams-drop.sql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/sql/postgresql/ams-drop.sql 20 Oct 2004 21:40:04 -0000 1.1 +++ openacs-4/packages/ams/sql/postgresql/ams-drop.sql 21 Oct 2004 01:53:46 -0000 1.2 @@ -37,6 +37,14 @@ drop view ams_object_revisionsi; drop table ams_object_revisions cascade; drop table ams_objects cascade; + + + + +select acs_object__delete(address_id) from ams_attribute_values where address_id is not null; +select acs_object__delete(number_id) from ams_attribute_values where number_id is not null; + + drop table ams_attribute_values cascade; drop table ams_option_map cascade; drop table ams_option_map_ids cascade; Index: openacs-4/packages/ams/sql/postgresql/ams-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/sql/postgresql/ams-package-create.sql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/sql/postgresql/ams-package-create.sql 20 Oct 2004 21:40:03 -0000 1.1 +++ openacs-4/packages/ams/sql/postgresql/ams-package-create.sql 21 Oct 2004 01:53:46 -0000 1.2 @@ -632,6 +632,8 @@ ------ Postal Address -------------------------------------------------------------------- +-- postal_type needs to be entered here at the end... this is a hack + create or replace function ams_attribute__postal_address_string (integer) returns varchar as ' declare @@ -646,8 +648,7 @@ CASE WHEN region is not null THEN region ELSE '''' END || ''} {'' || CASE WHEN postal_code is not null THEN postal_code ELSE '''' END || ''} {'' || CASE WHEN country_code is not null THEN country_code::varchar ELSE '''' END || ''} {'' || - CASE WHEN additional_text is not null THEN additional_text ELSE '''' END || ''} {'' || - CASE WHEN postal_type is not null THEN postal_type ELSE '''' END || ''}'' + CASE WHEN additional_text is not null THEN additional_text ELSE '''' END || ''} {}'' from postal_addresses where address_id = p_address_id; else Index: openacs-4/packages/ams/tcl/address-widget-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/address-widget-procs.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/tcl/address-widget-procs.tcl 20 Oct 2004 21:40:03 -0000 1.1 +++ openacs-4/packages/ams/tcl/address-widget-procs.tcl 21 Oct 2004 01:53:49 -0000 1.2 @@ -102,7 +102,10 @@ } if { $country_code == "US" } { # this should check a cached list - if { ![db_0or1row validate_state {} ] } { + # this proc cannot for some reason go in the postgresql file... + if { ![db_0or1row validate_state { + select 1 from us_states where abbrev = upper(:region) or state_name = upper(:region) +} ] } { if { [exists_and_not_null message_temp] } { append message " " } append message "\"$region\" [_ ams.is_not_a_valid_US_state]." } Index: openacs-4/packages/ams/tcl/ams-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/ams-procs-postgresql.xql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/tcl/ams-procs-postgresql.xql 20 Oct 2004 21:40:03 -0000 1.1 +++ openacs-4/packages/ams/tcl/ams-procs-postgresql.xql 21 Oct 2004 01:53:49 -0000 1.2 @@ -1,6 +1,15 @@ + + + select ams_attribute_id, required_p + from ams_list_attribute_map + where list_id = :list_id + order by sort_order + + + select ams_object_id(:object_id) @@ -248,7 +257,7 @@ - + select ams_attribute_id from ams_list_attribute_map @@ -271,7 +280,7 @@ select list_id from ams_lists - where short_name = :short_name + where short_name = :list_name and package_key = :package_key and object_type = :object_type Index: openacs-4/packages/ams/tcl/ams-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/ams-procs.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/tcl/ams-procs.tcl 20 Oct 2004 21:40:02 -0000 1.1 +++ openacs-4/packages/ams/tcl/ams-procs.tcl 21 Oct 2004 01:53:49 -0000 1.2 @@ -206,6 +206,81 @@ } +namespace eval ams::ad_form {} + +ad_proc -public ams::ad_form::save { form_name package_key object_type list_name object_id } { + this code saves attributes input in a form +} { + + set list_id [ams::list::get_list_id $package_key $object_type $list_name] + + ams::object::attribute::values -array oldvalues $object_id + set ams_attribute_ids [ams::list::ams_attribute_ids $list_id] + foreach ams_attribute_id $ams_attribute_ids { + set storage_type [ams::attribute::storage_type $ams_attribute_id] + set attribute_name [ams::attribute::name $ams_attribute_id] + set attribute_value [template::element::get_value $form_name $attribute_name] + if { $storage_type == "ams_options" } { + set attribute_value [template::element::get_values $form_name $attribute_name] + } + + ns_log Debug "Form $form_name: Attribute $attribute_name: $attribute_value" + + if { [info exists oldvalues($ams_attribute_id)] } { + if { $attribute_value != $oldvalues($ams_attribute_id) } { + lappend variables $ams_attribute_id $attribute_value + } + } else { + if { [exists_and_not_null attribute_value] } { + lappend variables $ams_attribute_id $attribute_value + } + } + } + if { [exists_and_not_null variables] } { + ns_log Notice "$object_id changed vars: $variables" +# ams_attributes_save $object_id $variables + db_transaction { + ams::object::attribute::values_flush $object_id + set revision_id [ams::object::revision::new $object_id] + set ams_object_id [ams_object_id $object_id] + foreach { ams_attribute_id attribute_value } $variables { + ams::attribute::value::superseed $revision_id $ams_attribute_id $ams_object_id + if { [exists_and_not_null attribute_value] } { + ams::attribute::value::new $revision_id $ams_attribute_id $attribute_value + } + } + } + } + ams::object::attribute::values $object_id + return 1 +} + +ad_proc -public ams::ad_form::elements { + {-key ""} + package_key + object_type + list_name +} { + this code saves retrieves ad_form elements +} { + set list_id [ams::list::get_list_id $package_key $object_type $list_name] + + set element_list "" + if { [exists_and_not_null key] } { + lappend element_list "$key\:key" + } + db_foreach select_elements {} { + if { $required_p } { + lappend element_list [ams::attribute::widget -required $ams_attribute_id] + } else { + lappend element_list [ams::attribute::widget $ams_attribute_id] + } + } + return $element_list +} + + + namespace eval ams::option {} @@ -803,7 +878,7 @@ set ${object_id}($ams_attribute_id) $attribute_value } foreach object_id_from_list $object_ids { - util_memoize_seed [list ams::object::attribute::values_not_cached $object_id_from_list] [array get ${object_id}] + util_memoize_seed [list ams::object::attribute::values_not_cached $object_id_from_list] [array get ${object_id_from_list}] } } } @@ -852,7 +927,7 @@ @see ams::list::ams_attribute_ids @see ams::list::ams_attribute_ids_flush } { - return [db_list ams_attribute_name {}] + return [db_list ams_attribute_ids {}] } ad_proc -private ams::list::ams_attribute_ids { list_id } { @@ -893,7 +968,11 @@ } -ad_proc -private ams::list::get_list_id { short_name package_key object_type } { +ad_proc -private ams::list::get_list_id { + package_key + object_type + list_name +} { return the list_id for the given parameters Index: openacs-4/packages/ams/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/index.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/index.tcl 20 Oct 2004 21:40:04 -0000 1.1 +++ openacs-4/packages/ams/www/index.tcl 21 Oct 2004 01:53:50 -0000 1.2 @@ -8,162 +8,49 @@ } { } -ad_proc -public ams_ad_form_save { - {-name} - {-list_id} - {-object_id} -} { - this code saves attributes input in a form -} { - ams::object::attribute::values -array oldvalues $object_id - set ams_attribute_ids [ams::list::ams_attribute_ids $list_id] - foreach ams_attribute_id $ams_attribute_ids { - set storage_type [ams::attribute::storage_type $ams_attribute_id] - set attribute_name [ams::attribute::name $ams_attribute_id] - set attribute_value [template::element::get_value $name $attribute_name] - if { $storage_type == "ams_options" } { - set attribute_value [template::element::get_values $name $attribute_name] - } - if { [info exists oldvalues($ams_attribute_id)] } { - if { $attribute_value != $oldvalues($ams_attribute_id) } { - lappend variables $ams_attribute_id $attribute_value - } - } else { - if { [exists_and_not_null attribute_value] } { - lappend variables $ams_attribute_id $attribute_value - } - } - } - if { [exists_and_not_null variables] } { - ns_log Notice "$object_id changed vars: $variables" -# ams_attributes_save $object_id $variables - } - db_transaction { - ams::object::attribute::values_flush $object_id - set revision_id [ams::object::revision::new $object_id] - set ams_object_id [ams_object_id $object_id] - ams::attribute::value::superseed $revision_id $ams_attribute_id $ams_object_id - foreach { ams_attribute_id attribute_value } $variables { - if { [exists_and_not_null attribute_value] } { - ams::attribute::value::new $revision_id $ams_attribute_id $attribute_value - } - } - } - ams::object::attribute::values $object_id - return 1 -} +set title "Attribute Management System" +set context {} -ad_proc -public ams_attributes_save { - object_id - attribute_value_list -} { - this code saves attributes input in a form -} { - db_transaction { - set revision_id [ams::object::revision::new $object_id] - set ams_object_id [ams_object_id $object_id] - foreach attribute_id_value $attribute_value_list { - # TODO find those that need to be updated (since its cached) and put them in attribute_values_to_update - set ams_attribute_id [lindex $attribute_id_value 0] - set new_attribute_value [lindex $attribute_id_value 1] - set old_attribute_value [ams::attribute::value $object_id $ams_attribute_id] - ns_log Notice "AMS: $ams_attribute_id , old: $old_attribute_value , new: $new_attribute_value" - if { [string compare $old_attribute_value $new_attribute_value] != "0" } { -# ams::attribute::value::superseed $revision_id $ams_attribute_id $ams_object_id - } else { - if { [exists_and_not_null new_attribute_value] } { - ams::attribute::value::new $revision_id $ams_attribute_id $attribute_value - } - } - } - } - ams::object::attribute::values_flush $object_id - ams::object::attribute::values $object_id -} +# YOU NEED TO SPECIFY A VALID OBJECT_ID +#set object_id "2864" +# Once done comment out the error line +#ad_return_error "You need to specify and valid object id in the packages/ams/www/index.tcl file" "Once done comment out this line." +set package_key "ams" +set object_type "ams_list" +set list_name "ams_list_demo" +set list_name_pretty "The Fields used to Add/Edit a Contact Person" +ams::define_list $list_name $list_name_pretty $package_key $object_type { + {first_names textbox {First Name(s)} {First Names} required} + {middle_names textbox {Middle Name(s)} {Middle Names}} + {last_name textbox {Last Name} {Last Names} required} + {email email {Email Address} {Email Addresses}} + {url url {Website} {Websites}} + {home_address address {Home Address} {Home Addresses}} + {organization_address address {Organization Address} {Organization Addresses}} + } +set object_id [db_string get_list_id { + select list_id + from ams_lists + where short_name = :list_name + and package_key = :package_key + and object_type = :object_type +}] - - - - - - - - - - - - - - - - - - - - - - - - -ad_proc -private ams_form { - {-name} - {-key} - {-list_id} - {-return_message} - {-return_url} -} { -} { - - ad_form \ - -name $name \ - -form [ams::ad_form::elements_from_list_id -key $key $list_id] \ - -edit_request { - ams::object::attribute::values -names -varenv $object_id - } -validate { - } -on_submit { - ams_ad_form_save -name $name -list_id $list_id -object_id $object_id - } -after_submit { - if { [exists_and_not_null $message] } { - ad_returnredirect $message $return_url - } else { - ad_returnredirect $return_url - } - } -} - - -set object_id 1931 - - -set title "Attribute Management System" -set context {} - ad_form -name entry \ - -form [ams::ad_form::elements_from_list_id -key object_id 1935] - -ad_form -extend -name entry \ - -new_request { - } -edit_request { + -form [ams::ad_form::elements -key object_id $package_key $object_type $list_name] \ + -edit_request { ams::object::attribute::values -names -varenv $object_id - } -validate { } -on_submit { - ams_ad_form_save -name entry -list_id 1935 -object_id $object_id + ams::ad_form::save entry $package_key $object_type $list_name $object_id } -after_submit { if { ![exists_and_not_null return_url] } { set return_url "./" } -# ad_returnredirect -message "[acs_object_name $object_id] Updated" $return_url -# ad_script_abort -# set attr_list [ams_ad_form_save -name entry -list_id 1935 -object_id $object_id] - } -#ams::object::attributes::flush $object_id -#set attr_list "" set attr_list [ams::object::attribute::values -names $object_id] -#set attr_list $fred(last_name) ad_return_template