Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-package-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-package-drop.sql,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-package-drop.sql 16 Jul 2003 04:52:31 -0000 1.1 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-package-drop.sql 27 Jul 2003 00:46:16 -0000 1.2 @@ -5,4 +5,22 @@ -- @cvs-id $Id$ -- +create function inline_0 () returns integer as ' +declare + v_rec record; +begin + + -- delete all ads + + FOR v_rec IN SELECT ad_id FROM cr_ca_ads LOOP + SELET ca_ad__delete(v_rec.ad_id); + SELECT select content_item__delete(v_rec.ad_id); + END LOOP; + + return 0; +end; +' language 'plpgsql'; + +SELECT inline_0(); +DROP FUNCTION inline_0(); drop function ca_ad__delete (integer); Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-create.sql,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-create.sql 24 Jul 2003 00:11:03 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-create.sql 27 Jul 2003 00:46:16 -0000 1.3 @@ -75,9 +75,10 @@ not null, html_options varchar(400), -- - -- RBM: If this is not null, use the form builder's -help_text. + -- RBM: extra fomr builder options like help, help_text, etc. + -- We give the admin a nice UI to abstract this. -- - help_text text, + extra_options text, select_options text, validate text, optional_p char(1) Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-package-create.sql,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-package-create.sql 24 Jul 2003 00:11:03 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-package-create.sql 27 Jul 2003 00:46:16 -0000 1.3 @@ -186,7 +186,7 @@ select define_function_args('ca_attributes__register_widget','attribute_id,widget,label,keyword_id,html_options,extra_options,select_options,validate,optional_p,enabled_p'); -create or replace function ca_attributes__register_widget (integer,varchar,varchar,integer,varchar,text,varchar,varchar,boolean,boolean) +create or replace function ca_attributes__register_widget (integer,varchar,varchar,integer,varchar,text,varchar,varchar,char,char) returns integer as ' declare p_attribute_id alias for $1; Index: openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs-postgresql.xql,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs-postgresql.xql 25 Jul 2003 23:53:19 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs-postgresql.xql 27 Jul 2003 00:46:16 -0000 1.3 @@ -223,89 +223,43 @@ - + - create function ca_inline_0 () - returns integer as ' - declare - v_attribute_id ca_attributes.attribute_id%TYPE; - begin - v_attribute_id := ca_attributes__create_attribute ( - ''ca_ad'', -- content_type - ''type'', -- attribute_name - ''integer'', -- datatype - ''Type'', -- pretty_name - ''Types'', -- pretty_plural - null, -- sort_order - ''0'', -- default_value - ''type_specific'', -- storage - ''cr_ca_ads'', -- table_name - ''integer'', -- column_spec - null -- package_id + SELECT ca_attributes__create_attribute ( + 'ca_ad', -- content_type + :attribute_name, -- attribute_name + :datatype, -- datatype + :pretty_name, -- pretty_name + :pretty_plural, -- pretty_plural + null, -- sort_order + :default_value, -- default_value + 'type_specific', -- storage + 'cr_ca_ads', -- table_name + :column_spec, -- column_spec + null -- package_id ); - PERFORM ca_attributes__register_widget ( - v_attribute_id, -- attribute_name - ''radio'', -- widget - ''Type'', -- label - :main_keyword_id, -- keyword_id - null, -- html_options - null, -- extra_options - ''{{"For Sale" 0} {"Wanted to Buy" 1}}'', -- select_options - ''{type {![string equal $value 0] && ![string equal $value 1]} {"Invalid option selected, please select For Sale or Wanted to Buy"}}'', -- validate - ''f'', -- optional_p - ''t'' -- enabled_p - ); - - v_attribute_id := ca_attributes__create_attribute ( - ''ca_ad'', -- content_type - ''expires_on'', -- attribute_name - ''date'', -- datatype - ''Expiry Date'', -- pretty_name - ''Expiry Dates'', -- pretty_plural - null, -- sort_order - null, -- default_value - ''type_specific'', -- storage - ''cr_ca_ads'', -- table_name - ''timestamp'', -- column_spec - null -- package_id - ); - - PERFORM ca_attributes__register_widget ( - v_attribute_id, -- attribute_name - ''date'', -- widget - ''Ad expires on'', -- label - :main_keyword_id, -- keyword_id - null, -- html_options - '' -format "MONTH DD YYYY" -help'' -- extra_options - null, -- select_options - null, -- validate - ''t'', -- optional_p - ''t'' -- enabled_p - ); - - return NULL; - end; - ' language 'plpgsql'; - - + - SELECT ca_inline_0(); + SELECT ca_attributes__register_widget ( + :attribute_id, -- attribute_name + :widget , -- widget + :pretty_name, -- label + :main_keyword_id, -- keyword_id + :html_options, -- html_options + :extra_options, -- extra_options + :select_options, -- select_options + :validate, -- validate + :optional_p, -- optional_p + :enabled_p -- enabled_p + ); - - - - - DROP FUNCTION ca_inline_0(); - - - - + Index: openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl,v diff -u -r1.8 -r1.9 --- openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl 25 Jul 2003 23:53:19 -0000 1.8 +++ openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl 27 Jul 2003 00:46:16 -0000 1.9 @@ -72,19 +72,52 @@ } { set main_keyword_id [classified-ads::main_keyword_exists_p] set attributes [list type expires_on] - set attributes_query [join attributes ","] - set count [db_1row count_attributes {}] + foreach attrib $attributes { + set count [db_1row count_attributes {}] - if { $count != [llength $attributes] } { - # - # Site-wide attributes have not been created. Create them. - # + if { $count != 1 } { + # + # This site-wide attribute has not been created. Create them. + # - db_transaction { - db_exec_plsql create_function {} - db_exec_plsql run_function {} - db_exec_plsql drop_function {} + db_transaction { + switch $attrib { + "type" { + set attribute_name "type" + set datatype "integer" + set pretty_name "Type" + set pretty_plural "Types" + set default_value 0 + set column_spec "integer" + set widget "radio" + set html_options "" + set extra_options "" + set select_options "{{\"For Sale\" 0} {\"Wanted to Buy\" 1}}" + set validate "" + set optional_p "f" + set enabled_p "t" + } + "expires_on" { + set attribute_name "expires_on" + set datatype "date" + set pretty_name "Expires On" + set pretty_plural "Expires On" + set default_value "" + set column_spec "timestamp" + set widget "date" + set html_options "" + set extra_options " -format \"MONTH DD YYYY\" -help" + set select_options "" + set validate "" + set optional_p "t" + set enabled_p "t" + } + } + + set attribute_id [db_exec_plsql create_attribute {}] + db_exec_plsql register_widget {} + } } return 1 Index: openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.xql,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.xql 25 Jul 2003 23:53:19 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.xql 27 Jul 2003 00:46:16 -0000 1.3 @@ -118,7 +118,7 @@ SELECT COUNT(*) FROM acs_attributes WHERE object_type = 'ca_ad' - AND attribute_name IN ( $attributes_query ) + AND attribute_name = :attrib