Index: openacs-4/contrib/packages/classified-ads/classified-ads.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/classified-ads.info,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/classified-ads.info 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,120 @@ + + + + + Classified Ads + Classified Ads + f + f + + + + oracle + postgresql + + Deds Castillo + Classified Ads Package + Infiniteinfo + This package implements a generic classified ads module using the content repository. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-create.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,67 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: ads-create.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +create function inline_0 () +returns integer as' +declare + v_attribute_id ca_attributes.attribute_id%TYPE; +begin + +-- create the content type + PERFORM content_type__create_type ( + ''ca_ad'', -- object_type + ''content_revision'', -- supertype + ''Classified Ad'', -- pretty_name + ''Classified Ads'', -- pretty_plural + ''cr_ca_ads'', -- table_name + ''ad_id'', -- id_column + ''ca_ads__name'' -- name_method + ); + +-- create the attributes + + 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 + ''text'', -- widget + ''Ad expires on'', -- label + null, -- html_options + null, -- select_options + null, -- validate + ''t'' -- optional_p + ); + +-- register mime_types + PERFORM content_type__register_mime_type ( + ''ca_ad'', -- content_type + ''text/plain'' -- mime_type + ); + + PERFORM content_type__register_mime_type ( + ''ca_ad'', -- content_type + ''text/html'' -- mime_type + ); + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0(); + Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-drop.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,54 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: ads-drop.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +-- DEDS: FIXME - drop ads +create function inline_0 () +returns integer as ' +declare + v_rec record; +begin + + +-- unregister the mime types + PERFORM content_type__unregister_mime_type ( + ''ca_ad'', -- content_type + ''text/html'' -- mime_type + ); + + PERFORM content_type__unregister_mime_type ( + ''ca_ad'', -- content_type + ''text/plain'' -- mime_type + ); + +-- drop the attributes + for v_rec in select attribute_id,attribute_name + from acs_attributes + where object_type = ''ca_ad'' + LOOP + PERFORM ca_attributes__unregister_widget ( + v_rec.attribute_id + ); + + PERFORM ca_attributes__drop_attribute ( + ''ca_ad'', + v_rec.attribute_name + ); + end LOOP; + +-- delete the content_type + PERFORM content_type__drop_type ( + ''ca_ad'', -- object_type + ''t'', -- drop children? + ''t'' -- drop table? + ); + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0 (); + Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-package-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-package-create.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,40 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: ads-package-create.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +select define_function_args('ca_ad__delete','ad_id'); + +create or replace function ca_ad__delete (integer) +returns integer as ' +declare + p_ad_id alias for $1; + rec record; +begin + +-- delete any associated generic attribute values + delete from ca_attribute_values + where object_id = p_ad_id; + +-- set our latest and live revisions to null + update cr_items + set live_revision = null, + latest_revision = null + where item_id = p_ad_id; + +-- delete entry from the ads table + for rec in + select revision_id + from cr_revisions + where item_id = p_ad_id + + LOOP + delete from cr_ca_ads + where ad_id = rec.revision_id; + end LOOP; + + return 0; +end; +' language 'plpgsql'; 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/ads-package-drop.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,8 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: ads-package-drop.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-create.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,102 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: attributes-create.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +-- create the table +create table ca_attributes ( + attribute_id integer + constraint ca_attributes_fk + references acs_attributes + constraint ca_attributes_nn + not null + constraint cr_ca_attributes_pk + primary key, + package_id integer + constraint ca_attributes_package_id_fk + references acs_objects, + sitewide_p char(1) + default 'f' + constraint ca_attributes_sitewide_p_nn + not null + constraint ca_attributes_sitewide_p_ck + check (sitewide_p in ('t','f')), + constraint ca_attributes_un + unique(attribute_id,package_id) +); + + +create table ca_attribute_values ( + object_id integer + constraint cav_object_id_fk + references acs_objects + constraint cav_object_id_nn + not null, + attribute_id integer + constraint ca_attribute_values_fk + references ca_attributes + constraint ca_attributes_values_nn + not null, + attr_value text, + constraint ca_attribute_values_un + unique(object_id,attribute_id) +); + + +create table ca_attribute_widgets ( + widget varchar(100) + constraint constraint_ca_widgets_pk + primary key +); + +create table ca_attribute_widget_values ( + attribute_id integer + constraint ca_attribute_widget_values_pk + primary key + constraint ca_attribute_widget_values_fk + references acs_attributes, + widget varchar(100) + constraint ca_awv_widget_fk + references ca_attribute_widgets + constraint ca_awv_widget_nn + not null, + label varchar(200), + html_options varchar(400), + select_options text, + validate text, + optional_p char(1) + default 'f' + constraint ca_awv_optional_p_nn + not null + constraint ca_awv_optional_p_ck + check (optional_p in ('t','f')), + enabled_p char(1) + default 't' + constraint ca_awv_enabled_p_nn + not null + constraint ca_awv_enabled_p_ck + check (enabled_p in ('t','f')) +); + + + +create function inline_0 () +returns integer as' +begin + + insert into ca_attribute_widgets (widget) values (''checkbox''); + insert into ca_attribute_widgets (widget) values (''date''); + insert into ca_attribute_widgets (widget) values (''hidden''); + insert into ca_attribute_widgets (widget) values (''multiselect''); + insert into ca_attribute_widgets (widget) values (''radio''); + insert into ca_attribute_widgets (widget) values (''select''); + insert into ca_attribute_widgets (widget) values (''text''); + insert into ca_attribute_widgets (widget) values (''textarea''); + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0(); Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-drop.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,11 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: attributes-drop.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +drop table ca_attribute_values; +drop table ca_attributes; +drop table ca_attribute_widget_values; +drop table ca_attribute_widgets; 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-package-create.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,270 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: attributes-package-create.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +select define_function_args('ca_attributes__create_attribute','content_type,attribute_name,datatype,pretty_name,pretty_plural,sort_order,default_value,storage,table_name,column_spec,package_id'); + +create or replace function ca_attributes__create_attribute (varchar,varchar,varchar,varchar,varchar,integer,varchar,varchar,varchar,varchar,integer) +returns integer as ' +declare + p_content_type alias for $1; + p_attribute_name alias for $2; + p_datatype alias for $3; + p_pretty_name alias for $4; + p_pretty_plural alias for $5; + p_sort_order alias for $6; + p_default_value alias for $7; + p_storage alias for $8; + p_table_name alias for $9; + p_column_spec alias for $10; + p_package_id alias for $11; + v_attribute_id acs_attributes.attribute_id%TYPE; + v_sort_order acs_attributes.sort_order%TYPE; + v_sitewide_p ca_attributes.sitewide_p%TYPE; + v_column_exists boolean; +begin + +-- if storage is type_specific then we should always have a column_spec +-- if table_name is provided as well then we assume that the user +-- wants to use a combo of acs_attributes and table_name and not cr + + if p_storage = ''type_specific'' and + p_column_spec is null then + + raise EXCEPTION ''-20000: Type_specific attributes require a colum_spec parameter''; + + end if; + + if p_sort_order is null then + select coalesce(max(sort_order), 0)+1 into v_sort_order + from acs_attributes + where object_type = p_content_type; + else + v_sort_order = p_sort_order; + end if; + + if p_storage = ''generic'' then + + v_attribute_id := acs_attribute__create_attribute ( + p_content_type, -- content_type + p_attribute_name, -- attribute_name + p_datatype, -- datatype + p_pretty_name, -- pretty_name + p_pretty_plural, -- pretty_plural + null, -- table_name + null, -- column_name + p_default_value, -- default_value + 1, -- min_n_values + 1, -- max_n_values + v_sort_order, -- sort_order + ''generic'', -- storage + ''f'' -- static_p + ); + + else if p_storage = ''type_specific'' then + if p_table_name is null then + +-- table_name is null. so the user probably wants to use cr. + + v_attribute_id := content_type__create_attribute ( + p_content_type, -- content_type + p_attribute_name, -- attribute_name + p_datatype, -- datatype + p_pretty_name, -- pretty_name + p_pretty_plural, -- pretty_plural + v_sort_order, -- sort_order + p_default_value, -- default_value + p_column_spec -- column_spec + ); + + else + +-- user passed in a table_name. since acs_attributes do not +-- create columns automagically, we steal stuff from cr +-- to add the column before calling create_attribute + + select count(*) > 0 into v_column_exists + from pg_class c, pg_attribute a + where c.relname::varchar = p_table_name + and c.oid = a.attrelid + and a.attname = lower(p_attribute_name); + + if NOT v_column_exists then + execute ''alter table '' || p_table_name || '' add '' || + p_attribute_name || '' '' + || p_column_spec; + end if; + + v_attribute_id := acs_attribute__create_attribute ( + p_content_type, -- content_type + p_attribute_name, -- attribute_name + p_datatype, -- datatype + p_pretty_name, -- pretty_name + p_pretty_plural, -- pretty_plural + null, -- table_name + null, -- column_name + p_default_value, -- default_value + 1, -- min_n_values + 1, -- max_n_values + v_sort_order, -- sort_order + ''type_specific'', -- storage + ''f'' -- static_p + ); + + end if; + + end if; end if; + +-- insert the attribute_id into our own table for purposes +-- of tracking the package_id + + if p_package_id is null then + v_sitewide_p := ''t''; + else + v_sitewide_p := ''f''; + end if; + + insert into ca_attributes + (attribute_id, package_id, sitewide_p) + values + (v_attribute_id, p_package_id, v_sitewide_p); + + return v_attribute_id; +end; +' language 'plpgsql'; + + +select define_function_args('ca_attributes__drop_attribute','content_type,attribute_name'); + +create or replace function ca_attributes__drop_attribute (varchar,varchar) +returns integer as ' +declare + p_content_type alias for $1; + p_attribute_name alias for $2; + v_attribute_id ca_attributes.attribute_id%TYPE; +begin +-- get the attribute_id + select attribute_id into v_attribute_id + from acs_attributes + where object_type = p_content_type and + attribute_name = p_attribute_name; + +-- delete all attributes of this id + delete from ca_attribute_widget_values + where attribute_id = v_attribute_id; + + delete from ca_attribute_values + where attribute_id = v_attribute_id; + + delete from ca_attributes + where attribute_id = v_attribute_id; + + +-- is this object a subtype of content_revision + if content_item__is_subclass(p_content_type, ''content_revision'') = ''t'' then + PERFORM content_type__drop_attribute ( + p_content_type, + p_attribute_name, + ''f'' + ); + + else + + PERFORM acs_attribute__drop_attribute ( + p_content_type, + p_attribute_name + ); + end if; + + return null; +end; +' language 'plpgsql'; + + +select define_function_args('ca_attributes__register_widget','attribute_id,widget,label,html_options,select_options,validate,optional_p'); + +create or replace function ca_attributes__register_widget (integer,varchar,varchar,varchar,varchar,varchar,varchar) +returns integer as ' +declare + p_attribute_id alias for $1; + p_widget alias for $2; + p_label alias for $3; + p_html_options alias for $4; + p_select_options alias for $5; + p_validate alias for $6; + p_optional_p alias for $7; +begin + +-- DEDS: FIXME - check for options when inserting something that does not support it + + insert into ca_attribute_widget_values + (attribute_id, widget, label, html_options, select_options, validate, optional_p) + values + (p_attribute_id, p_widget, p_label, p_html_options, p_select_options, p_validate, p_optional_p); + + return null; +end; +' language 'plpgsql'; + + +select define_function_args('ca_attributes__unregister_widget','attribute_id'); + +create or replace function ca_attributes__unregister_widget (integer) +returns integer as ' +declare + p_attribute_id alias for $1; +begin + + delete from ca_attribute_widget_values + where attribute_id = p_attribute_id; + + return null; +end; +' language 'plpgsql'; + + +select define_function_args('ca_attributes__add_generic_value','object_id,attribute_id,attr_value'); + +create or replace function ca_attributes__add_generic_value (integer,integer,varchar) +returns integer as ' +declare + p_object_id alias for $1; + p_attribute_id alias for $2; + p_attr_value alias for $3; +begin + + insert into ca_attribute_values + (object_id, attribute_id, attr_value) + values + (p_object_id, p_attribute_id, p_attr_value); + + return null; +end; +' language 'plpgsql'; + + +select define_function_args('ca_attributes__edit_generic_value','object_id,attribute_id,attr_value'); + +create or replace function ca_attributes__edit_generic_value (integer,integer,varchar) +returns integer as ' +declare + p_object_id alias for $1; + p_attribute_id alias for $2; + p_attr_value alias for $3; +begin + + update ca_attribute_values + set attr_value = p_attr_value + where object_id = p_object_id and + attribute_id = p_attribute_id; + + return null; +end; +' language 'plpgsql'; + + + + Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-package-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-package-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-package-drop.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,13 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: attributes-package-drop.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +drop function ca_attributes__create_attribute (varchar,varchar,varchar,varchar,varchar,integer,varchar,varchar,varchar,varchar,integer); +drop function ca_attributes__drop_attribute (varchar,varchar); +drop function ca_attributes__register_widget (integer,varchar,varchar,varchar,varchar,varchar,varchar); +drop function ca_attributes__unregister_widget (integer); +drop function ca_attributes__add_generic_value (integer,integer,varchar); +drop function ca_attributes__edit_generic_value (integer,integer,varchar); Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/classified-ads-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/classified-ads-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/classified-ads-create.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,25 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: classified-ads-create.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +-- load module-specific init +\i cr-classifieds-create.sql +\i cr-classifieds-package-create.sql + +-- load the attributes +\i attributes-create.sql +\i attributes-package-create.sql + +-- load the ads +\i ads-create.sql +\i ads-package-create.sql + +-- load the images +\i images-create.sql + +-- load post steps +\i post-steps-create.sql + Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/classified-ads-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/classified-ads-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/classified-ads-drop.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,25 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: classified-ads-drop.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +-- remove post steps +\i post-steps-drop.sql + +-- remove the images +\i images-drop.sql + +-- remove the ads +\i ads-package-drop.sql +\i ads-drop.sql + +-- remove the attributes +\i attributes-package-drop.sql +\i attributes-drop.sql + +-- remove module-specific stuff +\i cr-classifieds-package-drop.sql +\i cr-classifieds-drop.sql + Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/cr-classifieds-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/cr-classifieds-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/cr-classifieds-create.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,53 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: cr-classifieds-create.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +create function inline_0 () +returns integer as' +declare + v_package_key apm_packages.package_key%TYPE; + v_name cr_items.name%TYPE; + v_label cr_folders.label%TYPE; + v_folder_description cr_folders.description%TYPE; + v_heading cr_keywords.heading%TYPE; + v_keyword_description cr_keywords.description%TYPE; + v_folder_id cr_folders.folder_id%TYPE; +begin + +-- these are magic values + v_package_key := ''classified-ads''; + v_name := v_package_key; + v_label := v_package_key; + v_folder_description := v_package_key || '' Root Folder, all classified ads items go here''; + v_heading := v_package_key || ''-main-category''; + v_keyword_description := v_heading || '' Main Category, this is where all classified ads categories are rooted''; + +-- create the root folder for classified ads + v_folder_id := content_folder__new ( + v_name, -- name + v_label, -- label + v_folder_description, -- description + null -- parent_id + ); + +-- create the root keyword for classified ads +-- this is used for categorization + PERFORM content_keyword__new ( + v_heading, -- heading + v_keyword_description, -- description + null, -- parent_id + null, -- keyword_id + now(), -- creation_date + null, -- creation_user + null, -- creation_ip + ''content_keyword'' -- object_type + ); + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0(); Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/cr-classifieds-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/cr-classifieds-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/cr-classifieds-drop.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,75 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: cr-classifieds-drop.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +create function inline_0 () +returns integer as' +declare + v_package_key apm_packages.package_key%TYPE; + v_name cr_items.name%TYPE; + v_label cr_folders.label%TYPE; + v_folder_description cr_folders.description%TYPE; + v_heading cr_keywords.heading%TYPE; + v_keyword_description cr_keywords.description%TYPE; + v_folder_id cr_folders.folder_id%TYPE; + v_keyword_id cr_keywords.keyword_id%TYPE; + v_rec record; +begin + +-- these are magic values + v_package_key := ''classified-ads''; + v_name := v_package_key; + v_label := v_package_key; + v_folder_description := v_package_key || '' Root Folder, all classified ads items go here''; + v_heading := v_package_key || ''-main-category''; + v_keyword_description := v_heading || '' Main Category, this is where all classified ads categories are rooted''; + +-- get the root keyword id for classified ads + select keyword_id into v_keyword_id + from cr_keywords + where heading = v_heading and + description = v_keyword_description; + +-- loop through all classified ads child keywords in cr_keywords and delete them + for v_rec in + select c2.keyword_id + from cr_keywords c1, cr_keywords c2 + where c1.keyword_id = v_keyword_id and + c2.tree_sortkey between tree_left(c1.tree_s\ortkey) and tree_right(c1.tree_sortkey) + order by c2.tree_sortkey desc + LOOP + PERFORM content_keyword__delete (v_rec.keyword_id); + end LOOP; + +-- delete the root keyword for classified ads + PERFORM content_keyword__delete (v_keyword_id); + +-- get the root folder id for classified ads + select folder_id into v_folder_id + from cr_folders f, cr_items i + where i.name = v_name and + f.label = v_label and + f.description = v_folder_description; + + +-- delete all folders + for v_rec in + select a2.object_id + from acs_objects a1, acs_objects a2 + where a1.object_id = v_folder_id and + a2.tree_sortkey between a1.tree_sortkey and tree_right(a1.tree_sortkey) and + a2.object_type = ''content_folder'' + order by a2.tree_sortkey desc + LOOP + PERFORM content_folder__delete (v_rec.object_id); + end LOOP; + + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0(); Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/cr-classifieds-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/cr-classifieds-package-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/cr-classifieds-package-create.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,58 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: cr-classifieds-package-create.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +select define_function_args('ca__get_folder_id','package_id'); + +create function ca__get_folder_id (integer) +returns integer as ' +declare + p_package_id alias for $1; + v_folder_id integer; +begin + select folder_id into v_folder_id + from cr_folders + where package_id = p_package_id; + if not found then + v_folder_id := 0; + end if; + + return v_folder_id; +end; +' language 'plpgsql'; + + +select define_function_args('ca__set_package_folder','folder_id,package_id'); + +create function ca__set_package_folder (integer,integer) +returns integer as ' +declare + p_folder_id alias for $1; + p_package_id alias for $2; +begin + update cr_folders + set package_id = p_package_id + where folder_id = p_folder_id; + + return p_folder_id; +end; +' language 'plpgsql'; + +create or replace function ca_ads__name (integer) +returns varchar as ' +declare + p_ad_id alias for $1; + v_title cr_revisions.title%TYPE; + +begin + select into v_title title + from cr_revisions + where revision_id=p_ad_id; + + return v_title; +end;' language 'plpgsql'; + + Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/cr-classifieds-package-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/cr-classifieds-package-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/cr-classifieds-package-drop.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,9 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: cr-classifieds-package-drop.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +drop function ca__get_folder_id (integer); +drop function ca__set_package_folder (integer,integer); Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/images-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/images-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/images-create.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,45 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: images-create.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +create function inline_0 () +returns integer as' +begin + PERFORM content_type__create_type ( + ''ca_image'', -- object_type + ''image'', -- supertype + ''Classified Ads Image'', -- pretty_name + ''Classified Ads Images'', -- pretty_plural + ''cr_ca_images'', -- table_name + ''ca_image_id'', -- id_column + ''ca_images__name'' -- name_method + ); + +-- register child relations + PERFORM content_type__register_child_type ( + ''ca_ad'', -- parent_type + ''ca_image'', -- child_type + ''ad_images_rel'', -- relation_tag + 0, -- min_n + null -- max_n + ); + +-- register mime_types + PERFORM content_type__register_mime_type ( + ''ca_image'', -- content_type + ''image/gif'' -- mime_type + ); + + PERFORM content_type__register_mime_type ( + ''ca_image'', -- content_type + ''image/jpeg'' -- mime_type + ); + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0(); Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/images-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/images-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/images-drop.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,42 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: images-drop.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +-- DEDS: FIXME - drop objects +create function inline_0 () +returns integer as ' +begin +-- unregister child relations + PERFORM content_type__unregister_child_type ( + ''ca_ad'', -- parent_type + ''ca_image'', -- child_type + ''ad_images_rel'' -- relation_tag + ); + +-- unregister the mime types + PERFORM content_type__unregister_mime_type ( + ''ca_image'', -- content_type + ''image/gif'' -- mime_type + ); + + PERFORM content_type__unregister_mime_type ( + ''ca_image'', -- content_type + ''image/jpeg'' -- mime_type + ); + +-- delete the content_type + PERFORM content_type__drop_type ( + ''ca_image'', -- object_type + ''t'', -- drop children? + ''t'' -- drop table? + ); + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0 (); + Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/post-steps-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/post-steps-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/post-steps-create.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,55 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: post-steps-create.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +create function inline_0 () +returns integer as' +declare + v_package_key apm_packages.package_key%TYPE; + v_name cr_items.name%TYPE; + v_label cr_folders.label%TYPE; + v_folder_description cr_folders.description%TYPE; + v_folder_id cr_folders.folder_id%TYPE; +begin + +-- these are magic values + v_package_key := ''classified-ads''; + v_name := v_package_key; + v_label := v_package_key; + v_folder_description := v_package_key || '' Root Folder, all classified ads items go here''; + + +-- get the root folder for classified ads + select folder_id into v_folder_id + from cr_folders f, cr_items i + where i.name = v_name and + f.label = v_label and + f.description = v_folder_description; + +-- associate content types with classified ads folder + PERFORM content_folder__register_content_type ( + v_folder_id, -- folder_id + ''ca_ad'', -- content_type + ''t'' -- include_subtypes + ); + + PERFORM content_folder__register_content_type ( + v_folder_id, -- folder_id + ''content_revision'', -- content_type + ''t'' -- include_subtypes + ); + + PERFORM content_folder__register_content_type ( + v_folder_id, -- folder_id + ''content_folder'', -- content_type + ''t'' -- include_subtypes + ); + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0(); Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/post-steps-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/post-steps-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/post-steps-drop.sql 16 Jul 2003 04:52:31 -0000 1.1 @@ -0,0 +1,66 @@ +-- Classified Ads Package +-- +-- @author Deds Castillo (deds@infiniteinfo.com) +-- @creation-date 2002-10-08 +-- @cvs-id $Id: post-steps-drop.sql,v 1.1 2003/07/16 04:52:31 rmello Exp $ +-- + +create function inline_0 () +returns integer as' +declare + v_package_key apm_packages.package_key%TYPE; + v_name cr_items.name%TYPE; + v_label cr_folders.label%TYPE; + v_folder_description cr_folders.description%TYPE; + v_folder_id cr_folders.folder_id%TYPE; + v_rec record; +begin + +-- these are magic values + v_package_key := ''classified-ads''; + v_name := v_package_key; + v_label := v_package_key; + v_folder_description := v_package_key || '' Root Folder, all classified ads items go here''; + +-- get the root folder id for classified ads + select folder_id into v_folder_id + from cr_folders f, cr_items i + where i.name = v_name and + f.label = v_label and + f.description = v_folder_description; + + +-- remove association of content types from all classified ads folder + for v_rec in + select a2.object_id + from acs_objects a1, acs_objects a2 + where a1.object_id = v_folder_id and + a2.tree_sortkey between a1.tree_sortkey and tree_right(a1.tree_sortkey) and + a2.object_type = ''content_folder'' + order by a2.tree_sortkey desc + LOOP + PERFORM content_folder__unregister_content_type ( + v_rec.object_id, -- folder_id + ''content_folder'', -- content_type + ''t'' -- include_subtypes + ); + + PERFORM content_folder__unregister_content_type ( + v_rec.object_id, -- folder_id + ''content_revision'', -- content_type + ''t'' -- include_subtypes + ); + + PERFORM content_folder__unregister_content_type ( + v_rec.object_id, -- folder_id + ''ca_ad'', -- content_type + ''t'' -- include_subtypes + ); + + end LOOP; + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0(); Index: openacs-4/contrib/packages/classified-ads/tcl/ads-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/ads-procs-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/ads-procs-postgresql.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,35 @@ + + + postgresql7.1 + + + + + + select ca_ad__delete (:ad_id) + + + + + + + + + select content_item__delete (:ad_id) + + + + + + + + + select * + from cr_ca_adsx + where revision_id = :revision_id + + + + + + Index: openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,145 @@ +ad_library { + + Classified Ads Procs (Containers) + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: ads-procs.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} + +namespace eval classified-ads::ads { + +ad_proc -public new { + {-item_id_element:required} + {-form_id:required} + {-category_id} +} { + Creates a new ad + + @author Deds Castillo + @author Roberto Mello + + @param form_id The ID of the form that contains the name/value pairs + @param item_id_element The name of the form element that should be used as the item id + @param category_id The category of this ad. + +} { + if { [empty_string_p $category_id] } { + # + # No category passed. Assign to package_id + # + set package_id [ad_conn package_id] + set category_id [get_folder_id -package_id $package_id] + } + + return [classified-ads::create_ca_item -item_id_element $item_id_element \ + -content_type "ca_ad" \ + -form_id $form_id \ + -category_id $category_id \ + ] +} + + +ad_proc -public edit { + {-item_id_element:required} + {-form_id:required} +} { + Edits properties of an existing ad + + @param form_id The ID of the form that contains the name/value pairs + @param item_id_element The name of the form element that should be used as the item id + +} { + return [classified-ads::edit_ca_item -item_id_element $item_id_element \ + -form_id $form_id \ + ] +} + + +ad_proc -public delete { + {-ad_id:required} +} { + delete an existing ad + + @param ad_id The item id of the ad to delete +} { + db_transaction { + db_exec_plsql delete_ad {} + db_exec_plsql delete_content {} + } + + return 0 +} + +ad_proc -public get { + {-ad_id:required} + {-revision_id ""} + {-array:required} +} { + Gets the data of a particular ad + + @param item_id The ID ad to get + @param revisionid If present, then get the data for this revision. If not get the data for the latest revision + @param array The array where the data is stored +} { + upvar $array row + + if {[empty_string_p $revision_id]} { + set revision_id [classified-ads::get_latest_revision -item_id $ad_id] + } + + db_1row select_data {} + + # DEDS: FIXME - you know what's wrong here right? + set row(title) $title + set row(description) $description + set row(data) [classified-ads::get_content -revision_id $revision_id] + + return 0 + } + + +ad_proc -public get_assigned_ads_by_category { + {-category_id_list ""} +} { + Gets all the ads assigned to categories + + @param category_id_list A list of category ids. The system returns all ads mapped to these categories. +} { + # DEDS: FIXME - this uses a subselect. this will get inefficient + # when faced with a large db. optimize this. + set condition_stub "" + + if {[llength $category_id_list]} { + set condition_stub "and keyword_id in ([join $category_id_list ", "])" + } + + set parent_id [classified-ads::get_folder_id -package_id [ad_conn package_id]] + + return [db_list_of_ns_sets select_ads {}] +} + + +ad_proc -public get_unassigned_ads_by_category { + {-category_id_list ""} +} { + Gets all the ads NOT assigned to the categories passed. + + @param container_id_list A list of category ids. The system returns all ads not mapped to these categories. + +} { + # DEDS: FIXME - this uses a subselect. this will get inefficient + # when faced with a large db. optimize this. + set condition_stub "" + + if {[llength $category_id_list]} { + set condition_stub "where keyword_id in ([join $category_id_list ", "])" + } + + set parent_id [classified-ads::get_folder_id -package_id [ad_conn package_id]] + + return [db_list_of_ns_sets select_ads {}] +} + +} Index: openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl.old =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl.old,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl.old 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,140 @@ +ad_library { + + Classified Ads Procs (Containers) + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: ads-procs.tcl.old,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} + +namespace eval classified-ads::ads {} + +ad_proc -public ::classified-ads::ads::new { + {-item_id_element:required} + {-form_id:required} + {-parent_id} +} { + Creates a new ad + + @author Deds Castillo + @author Roberto Mello + + @param form_id The ID of the form that contains the name/value pairs + @param item_id_element The name of the form element that should be used as the item id + @param parent_id The parent of this ad (category) + +} { + if { [empty_string_p $parent_id] } { + set package_id [ad_conn package_id] + set parent_id [get_folder_id -package_id $package_id] + } + + return [classified-ads::create_ca_item -item_id_element $item_id_element \ + -content_type "ca_ad" \ + -form_id $form_id \ + -parent_id $parent_id \ + ] +} + + +ad_proc -public ::classified-ads::ads::edit { + {-item_id_element:required} + {-form_id:required} +} { + Edits properties of an existing ad + + @param form_id The ID of the form that contains the name/value pairs + @param item_id_element The name of the form element that should be used as the item id + +} { + return [classified-ads::edit_ca_item -item_id_element $item_id_element \ + -form_id $form_id \ + ] +} + + +ad_proc -public ::classified-ads::ads::delete { + {-ad_id:required} +} { + delete an existing ad + + @param ad_id The item id of the ad to delete +} { + db_transaction { + db_exec_plsql delete_ad {} + db_exec_plsql delete_content {} + } + + return 0 +} + +ad_proc -public ::classified-ads::ads::get { + {-ad_id:required} + {-revision_id ""} + {-array:required} +} { + Gets the data of a particular ad + + @param item_id The ID ad to get + @param revisionid If present, then get the data for this revision. If not get the data for the latest revision + @param array The array where the data is stored +} { + upvar $array row + + if {[empty_string_p $revision_id]} { + set revision_id [classified-ads::get_latest_revision -item_id $ad_id] + } + + db_1row select_data {} + + # DEDS: FIXME - you know what's wrong here right? + set row(title) $title + set row(description) $description + set row(data) [classified-ads::get_content -revision_id $revision_id] + + return 0 + } + + +ad_proc -public ::classified-ads::ads::get_assigned_ads_by_category { + {-category_id_list ""} +} { + Gets all the ads assigned to categories + + @param category_id_list A list of category ids. The system returns all ads mapped to these categories. +} { + # DEDS: FIXME - this uses a subselect. this will get inefficient + # when faced with a large db. optimize this. + set condition_stub "" + + if {[llength $category_id_list]} { + set condition_stub "and keyword_id in ([join $category_id_list ", "])" + } + + set parent_id [classified-ads::get_folder_id -package_id [ad_conn package_id]] + + return [db_list_of_ns_sets select_ads {}] +} + + +ad_proc -public ::classified-ads::ads::get_unassigned_ads_by_category { + {-category_id_list ""} +} { + Gets all the ads NOT assigned to the categories passed. + + @param container_id_list A list of category ids. The system returns all ads not mapped to these categories. + +} { + # DEDS: FIXME - this uses a subselect. this will get inefficient + # when faced with a large db. optimize this. + set condition_stub "" + + if {[llength $category_id_list]} { + set condition_stub "where keyword_id in ([join $category_id_list ", "])" + } + + set parent_id [classified-ads::get_folder_id -package_id [ad_conn package_id]] + + return [db_list_of_ns_sets select_ads {}] +} Index: openacs-4/contrib/packages/classified-ads/tcl/ads-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/ads-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/ads-procs.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,45 @@ + + + + + + + + select cm.keyword_id, + ci.item_id, + cr.title + from cr_item_keyword_map cm, + cr_revisions cr, + cr_items ci + where cm.item_id = cr.item_id and + ci.latest_revision = cr.revision_id and + ci.parent_id = :parent_id and + ci.content_type = 'ca_ad' + $condition_stub + order by cm.keyword_id asc, + cr.title asc + + + + + + + + + select ci.item_id, + cr.title + from cr_revisions cr, + cr_items ci + where ci.item_id not in (select item_id + from cr_item_keyword_map cm + $condition_stub) and + ci.latest_revision = cr.revision_id and + ci.parent_id = :parent_id and + ci.content_type = 'ca_ad' + order by cr.title asc + + + + + + Index: openacs-4/contrib/packages/classified-ads/tcl/categories-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/categories-procs-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/categories-procs-postgresql.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,101 @@ + + + postgresql7.1 + + + + + + select content_keyword__new (:heading, + :description, + :parent_id, + :keyword_id, + now(), + :creation_user, + :creation_ip, + 'content_keyword') + + + + + + + + + select content_keyword__delete (:keyword_id) + + + + + + + + + select content_keyword__get_heading (:keyword_id) + + + + + + + + + select content_keyword__set_heading (:keyword_id, + :heading) + + + + + + + + + select content_keyword__get_description (:keyword_id) + + + + + + + + + select content_keyword__set_description (:keyword_id, + :description) + + + + + + + + + select content_keyword__get_path (:keyword_id) + + + + + + + + + select content_keyword__item_assign (:item_id, + :keyword_id, + null, + null, + null) + + + + + + + + + select content_keyword__item_unassign (:item_id, + :keyword_id) + + + + + + Index: openacs-4/contrib/packages/classified-ads/tcl/categories-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/categories-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/categories-procs.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,259 @@ +ad_library { + + Classified Ads Procs (Categories) + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: categories-procs.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} + +namespace eval classified-ads::categories { + + + ad_proc -public new { + {-keyword_id ""} + {-heading:required} + {-description ""} + {-parent_id ""} + } { + + creates a new keyword that's used for categorization + + @param keyword_id The keyword id for this new keyword. A new id will be provided if null. + @param heading The heading of the new keyword + @param description The description of the new keyword + @param parent_id The parent of this new keyword if it is a subcategory + + } { + set creation_user [ad_conn user_id] + set creation_ip [ad_conn peeraddr] + return [db_exec_plsql create_keyword {}] + } + + + ad_proc -public edit { + {-keyword_id:required} + {-heading:required} + {-description ""} + } { + + edits properties of an existing category + + @param keyword_id The keyword id of the category to edit + @param heading The new heading to use + @param description The new description to use + + } { + db_transaction { + set_heading -keyword_id $keyword_id -heading $heading + set_description -keyword_id $keyword_id -description $description + } on_error { + ad_return_complaint 1 "
  • the following error occured: $errmsg" + ad_script_abort + } + + return $keyword_id + } + + + ad_proc -public delete { + {-keyword_id:required} + } { + + deletes a category + + @param keyword_id The keyword id of the category to delete + + } { + return [db_exec_plsql delete_category {}] + } + + + ad_proc -public package_category_exists_p { + {-package_id ""} + } { + + returns the keyword_id of the associated category for this package + + @param package_id The package id to query, defaults to current package id if not specified + + } { + set main_keyword_id [classified-ads::main_keyword_exists_p] + + if {!$main_keyword_id} { + ad_return_error "Main Category Not Found" "The sytem can't find the main [classified-ads::package_key] category. Are you sure you have restarted the server?" + } + + if {[empty_string_p $package_id]} { + set package_id [ad_conn package_id] + } + + set heading "[classified-ads::package_key]-package-$package_id" + set package_keyword_id [db_string get_id {} -default 0] + + if {!$package_keyword_id} { + set package_keyword_id [classified-ads::categories::new -heading $heading \ + -description "Package Main Category" \ + -parent_id $main_keyword_id \ + ] + } + + return $package_keyword_id + } + + + ad_proc -public get { + {-keyword_id:required} + {-array:required} + } { + + returns the data for a particular category + + @param keyword_id The keyword id of the category to get the data + @param array An array where the data will be stored + + } { + upvar $array row + + set row(heading) [get_heading -keyword_id $keyword_id] + set row(description) [get_description -keyword_id $keyword_id] + + return 0 + } + + + ad_proc -public get_heading { + {-keyword_id:required} + } { + + returns the heading for a particular category + + @param keyword_id The keyword id of the category to get the heading + + } { + return [db_exec_plsql get_heading {}] + } + + + ad_proc -public set_heading { + {-keyword_id:required} + {-heading:required} + } { + + sets the heading for a particular category + + @param keyword_id The keyword id of the category to set the heading + @param heading The new heading + + } { + return [db_exec_plsql set_heading {}] + } + + + ad_proc -public get_description { + {-keyword_id:required} + } { + + returns the description for a particular category + + @param keyword_id The keyword id of the category to get the description + + } { + return [db_exec_plsql get_description {}] + } + + + ad_proc -public set_description { + {-keyword_id:required} + {-description ""} + } { + + sets the description for a particular category + + @param keyword_id The keyword id of the category to set the description + @param description The new description + + } { + return [db_exec_plsql set_description {}] + } + + + ad_proc -public get_path { + {-keyword_id:required} + } { + + returns the path of a particular category + + @param keyword_id The keyword id of the category to get the path + + } { + return [db_exec_plsql get_path {}] + } + + + ad_proc -public generate_trail { + {-keyword_id:required} + {-append_element} + } { + + generates a cookie trail for a particular category + + @param keyword_id The keyword id that defines the end of the trail to be generated + @param append_element The last element to put in the trail. If none then the element defined by keyword_id is used + + } { + set package_keyword_id [package_category_exists_p] + + set trail_list [list] + db_foreach get_trail {} { + if {[string match $keyword_id $package_keyword_id]} { + set heading "Categories" + set url "categories" + } else { + set url "categories?keyword_id=$keyword_id" + } + lappend trail_list [list $url $heading] + } + if {[exists_and_not_null append_element]} { + lappend trail_list $append_element + } else { + # no extra elements were passed, so our last element should have no link + set last_element_index [expr [llength $trail_list] - 1] + set trail_list [lreplace $trail_list $last_element_index $last_element_index $heading] + } + return $trail_list + } + + + ad_proc -public item_assign { + {-keyword_id:required} + {-item_id:required} + } { + + maps a content item to a keyword + + @param keyword_id The keyword id of the category we map to + @param item_id The item id of the content item we map + + } { + return [db_exec_plsql add_map {}] + } + + + ad_proc -public item_unassign { + {-keyword_id:required} + {-item_id:required} + } { + + unmaps a content item to a keyword + + @param keyword_id The keyword id of the category we unmap to + @param item_id The item id of the content item we unmap + + } { + return [db_exec_plsql delete_map {}] + } + + +} Index: openacs-4/contrib/packages/classified-ads/tcl/categories-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/categories-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/categories-procs.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,47 @@ + + + + + + + + select keyword_id + from cr_keywords + where heading = :heading and + parent_id = :main_keyword_id + + + + + + + + + select instance_name + from apm_packages + where package_id = :package_id + + + + + + + + + select keyword_id, + heading + from (select ck2.keyword_id, + ck2.heading, + tree_level(ck2.tree_sortkey) as tree_level + from cr_keywords ck1, cr_keywords ck2 + where ck1.keyword_id = :keyword_id and + ck1.tree_sortkey between ck2.tree_sortkey and + tree_right(ck2.tree_sortkey)) k + where tree_level > 1 + order by tree_level asc + + + + + + Index: openacs-4/contrib/packages/classified-ads/tcl/classified-ads-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/classified-ads-init.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/classified-ads-init.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,55 @@ +ad_library { + + initialize classified-ads + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @version $Id: classified-ads-init.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} + +ns_log Notice "classified-ads-init: starting..." + +# are we installed? +if {[classified-ads::is_instantiated]} { + + ns_log Notice "classified-ads-init: checking for root folder..." + set root_folder_id [classified-ads::root_folder_exists_p] + if {!$root_folder_id} { + ns_log Error "Root Folder for classified ads not found. Datamodel probably not loaded." + } else { + ns_log Notice "Root Folder for classified ads found." + # we have a root folder. let's now look for mounted instances of classified-ads and + # check if they have folders. if they don't let's create it for them + set package_list [classified-ads::get_mounted_packages] + foreach package_id $package_list { + set package_folder_id [classified-ads::get_folder_id -package_id $package_id] + if {!$package_folder_id} { + ns_log Notice "classified-ads-init: creating root folder for package $package_id..." + set package_folder_id [classified-ads::create_package_folder -root_folder_id $root_folder_id \ + -package_id $package_id \ + ] + } + # DEDS: FIXME - right now, the content types are hardcoded. This should not be the case. + # We should also loop through acs_object_types and get all child types + if {$package_folder_id} { + classified-ads::register_content_type -folder_id $package_folder_id -content_type ca_ad + ns_log Notice "classified-ads-init: registering ca_ad for $package_folder_id" + classified-ads::register_content_type -folder_id $package_folder_id -content_type content_revision + ns_log Notice "classified-ads-init: registering content_revision for $package_folder_id" + classified-ads::register_content_type -folder_id $package_folder_id -content_type ca_image + ns_log Notice "classified-ads-init: registering ca_image for $package_folder_id" + } + + } + } + + ns_log Notice "classified-ads-init: checking for root keyword..." + if {![classified-ads::main_keyword_exists_p]} { + ns_log Error "Root Keyword for classified ads not found. Datamodel probably not loaded." + } else { + ns_log Notice "Root Keyword for classified ads found." + } +} + +ns_log Notice "classified-ads-init: done" 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs-postgresql.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,225 @@ + + + postgresql7.1 + + + + + + select ca__get_folder_id (:package_id) + + + + + + + + + select content_item__get_content_type (:item_id) + + + + + + + + + select content_folder__register_content_type (:folder_id, + :content_type, + :include_subtypes) + + + + + + + + + select content_folder__new (:name, + :label, + :description, + :root_folder_id) + + + + + + + + + select ca__set_package_folder (:new_folder_id, + :package_id) + + + + + + + + + select content_item__new (:name::varchar, + :parent_id::int4, + :item_id::int4, + null, + now(), + :creation_user, + null, + :creation_ip, + :content_item, + :content_type, + null, + null, + 'text/plain', + null, + null, + 'text'::varchar) + + + + + + + + + select content_revision__new (:title, + :description, + now(), + null, + null, + :data, + :item_id, + null, + now(), + :creation_user, + :creation_ip) + + + + + + + + + $plsql_query + + + + + + + + select content_keyword__item_assign (:cr_item_id, + :category_id, + null, + null, + null) + + + + + + + select content_revision__new (:title, + :description, + now(), + null, + null, + :data, + :item_id, + null, + now(), + :creation_user, + :creation_ip) + + + + + + + + + update cr_revisions + set title = :title, + description = :description, + content = :data + where revision_id = :object_id + + + + + + + + + $plsql_query + + + + + + + + + select content_item__is_subclass (:content_type, + :parent_type) + + + + + + + + + select ca_attributes__add_generic_value (:object_id, + :attribute_id, + :attr_value) + + + + + + + + + select ca_attributes__edit_generic_value (:object_id, + :attribute_id, + :attr_value) + + + + + + + + + select content_item__get_latest_revision (:item_id) + + + + + + + + + select content_revision__get_content (:revision_id) + + + + + + + + + select site_node__url(n2.node_id) as url, + n2.object_id, + acs_object__name(n2.object_id) as object_name, + tree_level(n2.tree_sortkey) as level + from (select tree_ancestor_keys(site_node_get_tree_sortkey(:node_id)) as tree_sortkey) parents, + site_nodes n2 + where n2.tree_sortkey = parents.tree_sortkey + and tree_level(n2.tree_sortkey) > 1 + order by level asc + + + + 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,750 @@ +ad_library { + + Classified Ads Procs + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: classified-ads-procs.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} + +namespace eval classified-ads { + + + ad_proc -public package_key { + } { + + returns the package key + + } { + return "classified-ads" + } + + + ad_proc -public is_instantiated { + } { + + returns 1 if classified-ads is instantiated, 0 otherwise + + } { + return [ad_decode [apm_num_instances [package_key]] 0 0 1] + } + + + ad_proc -public main_keyword_exists_p { + } { + + returns the keyword id of the main category for the package, 0 if not yet created + + } { + + # These are magic values + set heading "[package_key]-main-category" + set description "$heading Main Category, this is where all classified ads categories are rooted" + + return [db_string get_main_keyword {} -default 0] + + } + + + ad_proc -public root_folder_exists_p { + } { + + returns the folder id of the classified ads root folder, 0 if not yet created + + } { + + # These are magic values + set name "[package_key]" + set label "[package_key]" + set description "$name Root Folder, all classified ads items go here" + + return [db_string get_root_folder {} -default 0] + + } + + + ad_proc -public get_root_folder_id { + } { + + returns the folder id of the classified ads root folder, error if none + + } { + + set folder_id [root_folder_exists_p] + if {!$folder_id} { + ad_return_error "Root Folder not found" "The root folder for [package_key] was not found. The datamodel might not be properly installed. Did you restart the server after installation?" + ad_script_abort + } + return $folder_id + + } + + + ad_proc -public get_folder_id { + {-package_id} + } { + + returns the folder_id for an instance of classified ads + + @param package_id The package id of this classified ads instance. Default to current instance if none passed. + + } { + if {![exists_and_not_null package_id]} { + set package_id [ad_conn package_id] + } + + return [db_string select_folder_id {}] + } + + + ad_proc -public get_mounted_packages { + } { + + returns a list of mounted classified-ads packages + + } { + set package_key [package_key] + + return [db_list select_packages {}] + + } + + + ad_proc -public get_content_type { + {-item_id:required} + } { + + gets the content type of a given item + + } { + + return [db_string select_type {}] + + } + + + ad_proc -public get_table_name { + {-content_type:required} + } { + + gets the table name of one content type + + } { + + return [db_string select_table_name {}] + + } + + + ad_proc -public register_content_type { + {-folder_id:required} + {-content_type:required} + {-include_subtypes "f"} + } { + + registers a given content type to a particular folder + + } { + + return [db_list register_content_type {}] + + } + + + ad_proc -public create_package_folder { + {-root_folder_id:required} + {-package_id:required} + } { + + creates a content revision folder for one instance of classified ads + + @param root_folder_id The root folder id for the whole classified ads package + @param package_id The package id of the instance whose folder is to be created + + } { + + set name "[package_key]-$package_id" + set label "$name folder" + set description "Container folder for one instance of classified-ads" + db_transaction { + set new_folder_id [db_exec_plsql create_folder {}] + db_exec_plsql associate_package {} + } + return $new_folder_id + + } + + + ad_proc -public create_ca_item { + {-item_id_element:required} + {-parent_id} + {-category_id} + {-content_type:required} + {-form_id:required} + {-title_column "title"} + {-description_column "description"} + {-data_column "data"} + } { + + Creates a classified ads item. This is generic enough to: + 1. handle items that are either derived from content_revision or not + 2. dynamically generate insert statements for extension tables + 3. dynamically generate insert statements to handle generic attributes + 4. create new revisions as appropriate + + @author Deds Castillo + @author Roberto Mello (rmello@fslc.usu.edu) + + @param item_id_element The name of the form element that should be used as the item id + @param content_type The type of the item being inserted + @param form_id The ID of the form that contains the the name/value pairs + + } { + set package_id [ad_conn package_id] + + if {![info exists parent_id]} { + set parent_id [get_folder_id -package_id $package_id] + } + + set creation_user [ad_conn user_id] + set creation_ip [ad_conn peeraddr] + + # DEDS: FIXME - for now we are assuming required fields are filtered + # out by the validation in the form procedures. i think we should + # double check it here again and barf if one of them is missing + + # get the item id, barf if not present + + if {[template::element::exists $form_id $item_id_element]} { + set item_id [template::element::get_value $form_id $item_id_element] + } else { + ad_return_complaint 1 "
  • passed in item id not found" + ad_script_abort + } + + # check if this is a subclass of content_revision + set cr_subclass_p [is_subclass -content_type $content_type -parent_type content_revision] + set content_item [get_supertype -content_type $content_type] + + set name "$content_type -- $item_id" + set title [template::element::get_value $form_id $title_column] + if {[empty_string_p $title]} { + # make sure there is always a title + set title $name + } + set description [template::element::get_value $form_id $description_column] + if {[template::element::exists $form_id $data_column]} { + set data [template::element::get_value $form_id $data_column] + } + + # do everything in a transaction + db_transaction { + # insert the content item + set object_id [db_exec_plsql insert_content_item {}] + set cr_item_id $object_id + + ns_log Warning "item_id IS: $cr_item_id" + + if {$cr_subclass_p} { + set object_id [db_exec_plsql insert_content_revision {}] + set foobar [db_1row ct "SELECT count(*) from cr_items where latest_revision = $cr_item_id"] + + ns_log Warning "object_id NOW IS (revision): $object_id. In cr_items? $foobar" + } + + # RBM: If a category was passed, assign the ad to it. + + if {[info exists category_id]} { + db_exec_plsql assign_item_to_category {} + } + + # DEDS: FIXME - this only supports one table + # fix it so that it can span multiple tables + + # get the type specific attributes + set type_specific_attr_list [get_attributes -content_type $content_type -storage "type_specific"] + + if {[llength $type_specific_attr_list]} { + # we always reference the item_id + set name_list [list $item_id_element] + set value_list [list $object_id] + set type_specific_bind_vars [ns_set create] + + foreach one_attribute $type_specific_attr_list { + set column_name [ns_set get $one_attribute column_name] + set table_name [ns_set get $one_attribute table_name] + + if {[template::element::exists $form_id $column_name]} { + lappend name_list $column_name + lappend value_list ":$column_name" + set one_value [template::element::get_value $form_id $column_name] + if {[string match "date" [ns_set get $one_attribute datatype]]} { + set one_value [classified-ads::widgets::date_widget_to_sql -date $one_value] + } + ns_set put $type_specific_bind_vars $column_name $one_value + + } else { + set default_value [ns_set get $one_attribute default_value] + if {![empty_string_p $default_value]} { + lappend name_list $column_name + lappend value_list ":$column_name" + ns_set put $type_specific_bind_vars $column_name $default_value + } + } + } + + # create the insert statement for type specific attributes + set plsql_query "insert into $table_name ([join $name_list ", "]) values ([join $value_list ", "])" + + # insert the type specific data + db_dml insert_data {} -bind $type_specific_bind_vars + ns_set free $type_specific_bind_vars + } + + # get the generic attributes + set generic_attr_list [get_attributes -content_type $content_type -storage "generic"] + + if {[llength $generic_attr_list]} { + + foreach one_attribute $generic_attr_list { + set attribute_id [ns_set get $one_attribute attribute_id] + set column_name [ns_set get $one_attribute column_name] + set datatype [ns_set get $one_attribute datatype] + + if {[template::element::exists $form_id $column_name]} { + set attr_value [template::element::get_value $form_id $column_name] + if {[string match "date" $datatype]} { + set attr_value [classified-ads::widgets::date_widget_to_sql -date $attr_value] + } + } else { + set default_value [ns_set get $one_attribute default_value] + if {![empty_string_p $default_value]} { + set attr_value $default_value + } else { + set attr_value "" + } + } + + insert_generic_value -object_id $item_id -attribute_id $attribute_id -attr_value $attr_value + } + } + } on_error { + ad_return_complaint 1 "
  • $errmsg" + ad_script_abort + } + + return $item_id + + } + + + ad_proc -public edit_ca_item { + {-item_id_element:required} + {-form_id:required} + {-title_column "title"} + {-description_column "description"} + {-data_column "data"} + {-revision_id} + } { + + edits a classified ads item. + + @param item_id_element The name of the form element that should be used as the item id + @param form_id The ID of the form that contains the the name/value pairs + @param title_column The element name in the form that will be used as title of this content + @param description_column The element name in the form that will be used as description of this content + + } { + + set creation_user [ad_conn user_id] + set creation_ip [ad_conn peeraddr] + + # DEDS: FIXME - for now we are assuming required fields are filtered + # out by the validation in the form procedures. i think we should + # double check it here again and barf if one of them is missing + + # get the item id, barf if not present + if {[template::element::exists $form_id $item_id_element]} { + set item_id [template::element::get_value $form_id $item_id_element] + } else { + ad_return_complaint 1 "
  • passed in item id not found" + ad_script_abort + } + + set create_revision_p 0 + + # check if this is a subclass of content_revision + set content_type [get_content_type -item_id $item_id] + set cr_subclass_p [is_subclass -content_type $content_type -parent_type content_revision] + if {$cr_subclass_p} { + if {[parameter::get -parameter create_new_ad_revision_p -default 0]} { + set create_revision_p 1 + } + if {[info exists revision_id]} { + set object_id $revision_id + } else { + set object_id [get_latest_revision -item_id $item_id] + } + + } else { + set object_id $item_id + } + + set name "$content_type -- $item_id" + set title [template::element::get_value $form_id $title_column] + if {[empty_string_p $title]} { + # make sure there is always a title + set title $name + } + set description [template::element::get_value $form_id $description_column] + if {[template::element::exists $form_id $data_column]} { + set data [template::element::get_value $form_id $data_column] + } + + # do everything in a transaction + db_transaction { + # DEDS: FIXME - this only supports one table + # fix it so that it can span multiple tables + + if {$create_revision_p} { + set object_id [db_exec_plsql insert_content_revision {}] + } elseif {$cr_subclass_p} { + # DEDS: FIXME - this is straghtforward update. we should be using cr api. + db_dml update_content_revision {} + } + + # get the type specific attributes + set type_specific_attr_list [get_attributes -content_type $content_type -storage "type_specific"] + if {[llength $type_specific_attr_list]} { + # we always reference the item_id + set update_list [list] + set name_list [list $item_id_element] + set value_list [list $object_id] + set type_specific_bind_vars [ns_set create] + foreach one_attribute $type_specific_attr_list { + set column_name [ns_set get $one_attribute column_name] + set table_name [ns_set get $one_attribute table_name] + set datatype [ns_set get $one_attribute datatype] + if {[template::element::exists $form_id $column_name]} { + lappend name_list $column_name + lappend value_list ":$column_name" + lappend update_list "$column_name = :$column_name" + set one_value [template::element::get_value $form_id $column_name] + if {[string match "date" $datatype]} { + set one_value [classified-ads::widgets::date_widget_to_sql -date $one_value] + } + ns_set put $type_specific_bind_vars $column_name $one_value + } + } + + ns_set put $type_specific_bind_vars item_id $object_id + + # create the update statement for type specific attributes + if {$create_revision_p} { + set plsql_query "insert into $table_name ([join $name_list ", "]) values ([join $value_list ", "])" + } else { + set plsql_query "update $table_name set [join $update_list ", "] where $item_id_element = :item_id" + } + + # update the type specific data + db_dml update_data {} -bind $type_specific_bind_vars + ns_set free $type_specific_bind_vars + } + + # get the generic attributes + set generic_attr_list [get_attributes -content_type $content_type -storage "generic"] + if {[llength $generic_attr_list]} { + foreach one_attribute $generic_attr_list { + set attribute_id [ns_set get $one_attribute attribute_id] + set column_name [ns_set get $one_attribute column_name] + set datatype [ns_set get $one_attribute datatype] + if {[template::element::exists $form_id $column_name]} { + set attr_value [template::element::get_value $form_id $column_name] + if {[string match "date" $datatype]} { + set attr_value [classified-ads::widgets::date_widget_to_sql -date $attr_value] + } + } + + if {$create_revision_p} { + insert_generic_value -object_id $object_id -attribute_id $attribute_id -attr_value $attr_value + } else { + update_generic_value -object_id $object_id -attribute_id $attribute_id -attr_value $attr_value + } + + } + } + + } on_error { + ad_return_complaint 1 "
  • $errmsg" + ad_script_abort + } + + return $object_id + + } + + + ad_proc -public is_subclass { + {-content_type:required} + {-parent_type:required} + } { + + returns 1 if an object type is a subclass of another + + @param content_type The object type to check + @param parent_type The supertype class the proc test against + + } { + return [ad_decode [db_string test_subclass {}] f 0 1] + } + + + ad_proc -public get_attributes { + {-content_type:required} + {-package_id} + {-storage "all"} + } { + + returns a list of lists of the attributes for one content type + + @param content_type This is the content type whose attributes we get + @param package_id Only the attributes belonging to this package is retrieved. + Defaults to current package. + @param storage Only the attributes who belong to this storage type are retrieved. + Can be "type_specific", "generic", or "all". + + } { + if {![exists_and_not_null package_id]} { + set package_id [ad_conn package_id] + } + + if {![string equal $storage "all"]} { + set storage_stub "and storage = '$storage'" + } else { + set storage_stub "" + } + + return [db_list_of_ns_sets select_attributes {}] + } + + + ad_proc -public get_attribute_names { + {-item_id} + {-storage "all"} + } { + + returns a list of lists of the attribute names for one item + + @param package_id The item id whose attribute names we get + + } { + if {![exists_and_not_null package_id]} { + set package_id [ad_conn package_id] + } + + if {![string equal $storage "all"]} { + set storage_stub "and storage = '$storage'" + } else { + set storage_stub "" + } + + set content_type [get_content_type -item_id $item_id] + return [db_list_of_lists select_names {}] + } + + + ad_proc -public get_attribute_values { + {-item_id:required} + {-item_id_element:required} + {-storage "all"} + {-revision_id} + } { + + returns a list of lists of the attribute values for one item + + @param item_id The ID of the object whose values we retrieve + @param storage Only the attribute values who belong to this storage type are retrieved. + Can be "type_specific", "generic", or "all". + + } { + set values_list [list] + + set cr_subclass_p [is_subclass -content_type [get_content_type \ + -item_id $item_id] \ + -parent_type content_revision] + if {![info exists revision_id] && $cr_subclass_p} { + set revision_id [get_latest_revision -item_id $item_id] + } + + if {[string match $storage "type_specific"] || [string match $storage "all"]} { + set table_name [get_table_name -content_type [get_content_type -item_id $item_id]] + set names_value_list [get_attribute_names -item_id $item_id -storage type_specific] + set names_list [list] + foreach one_name_value $names_value_list { + lappend names_list [lindex $one_name_value 0] + } + if {$cr_subclass_p} { + set query_string "select [join $names_list ", "] + from $table_name + where $item_id_element = '$revision_id'" + } else { + set query_string "select [join $names_list ", "] + from $table_name + where $item_id_element = '$item_id'" + } + db_1row select_values {} -column_array type_specific_row + foreach one_name_value $names_value_list { + set datatype [lindex $one_name_value 1] + set one_value $type_specific_row([lindex $one_name_value 0]) + if {[string match "date" $datatype] && ![empty_string_p $one_value]} { + set one_value [classified-ads::widgets::sql_to_date_widget -sql_date $one_value -format "YYYY-MM-DD"] + } + lappend values_list [list [lindex $one_name_value 0] $one_value] + } + } + + if {[string match $storage "generic"] || [string match $storage "all"]} { + if {$cr_subclass_p} { + set query_string "select coalesce(aa.column_name, aa.attribute_name) as column_name, + cav.attr_value, + aa.datatype + from acs_attributes aa, + ca_attribute_values cav + where aa.attribute_id = cav.attribute_id and + cav.object_id = '$revision_id'" + } else { + set query_string "select coalesce(aa.column_name, aa.attribute_name) as column_name, + cav.attr_value, + aa.datatype + from acs_attributes aa, + ca_attribute_values cav + where aa.attribute_id = cav.attribute_id and + cav.object_id = '$item_id'" + } + set generic_list [db_list_of_lists select_values {}] + foreach one_name $generic_list { + set datatype [lindex $one_name_value 2] + set one_value [lindex $one_name_value 1] + if {[string match "date" $datatype] && ![empty_string_p $one_value]} { + set one_value [classified-ads::widgets::sql_to_date_widget -sql_date $one_value -format "YYYY-MM-DD"] + } + lappend values_list [list [lindex $one_name 0] $one_value] + } + } + + return $values_list + } + + + ad_proc -public get_supertype { + {-content_type:required} + } { + + returns the direct ancestor of one content type + + @param content_type This is the content type whose ancestor we get + + } { + return [db_string select_supertype {}] + } + + + ad_proc -public insert_generic_value { + {-object_id:required} + {-attribute_id:required} + {-attr_value ""} + } { + + inserts one value for a generic attribute + + @param object_id The object id of the objects who owns this value + @param attribute_id The id of the attribute that will contain a new value + @param attr_value The associated value of this attribute for this object + + + } { + return [db_exec_plsql insert_value {}] + } + + + ad_proc -public update_generic_value { + {-object_id:required} + {-attribute_id:required} + {-attr_value ""} + } { + + updates one value for a generic attribute + + @param object_id The object id of the objects who owns this value + @param attribute_id The id of the attribute that will be updated + @param attr_value The associated value of this attribute for this object + + + } { + return [db_exec_plsql update_value {}] + } + + + ad_proc -public get_latest_revision { + {-item_id:required} + } { + + returns the latest revision for one item + + @param item_id The id of the item that we want to get the latest revision + + + } { + return [db_string get_revision {} -default 0] + } + + + ad_proc -public get_content { + {-revision_id:required} + } { + + returns the content of one item + + @param revision_id The id of the revision to get the data from + + + } { + return [db_string select_content {}] + } + + + ad_proc -public context_bar { + {-node_id} + args + } { + + returns a context bar relative to classified ads + + @param node_id if provided, then we work up from this node + + + } { + if { ![info exists node_id] } { + set node_id [ad_conn node_id] + } + + set context [list] + + db_foreach context {} { + lappend context [list $url $object_name] + } + if { [string match admin/* [ad_conn extra_url]] } { + lappend context [list "[ad_conn package_url]admin/" "Administration"] + } + + if {[llength $args] == 0} { + # fix last element to just be literal string + set context [lreplace $context end end [lindex [lindex $context end] 1]] + } + + return [ad_context_bar_html [concat $context $args]] + } + + +} 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,116 @@ + + + + + + + + select keyword_id + from cr_keywords + where heading = :heading and + description = :description + + + + + + + + + select folder_id + from cr_folders f, cr_items i + where i.name = :name and + f.label = :label and + f.description = :description + + + + + + + + + select a.package_id + from apm_packages a, + site_nodes s + where package_key = :package_key and + a.package_id = s.object_id + + + + + + + + + select table_name + from acs_object_types + where object_type = :content_type + + + + + + + + + select aa.attribute_id, + coalesce(aa.column_name, aa.attribute_name) as column_name, + aa.default_value, + coalesce(aa.table_name,at.table_name) as table_name, + aa.storage, + aa.datatype + from acs_attributes aa, + ca_attributes ca, + acs_object_types at + where aa.attribute_id = ca.attribute_id and + (ca.package_id = :package_id or + ca.sitewide_p = 't') and + aa.object_type = :content_type and + at.object_type = :content_type + $storage_stub + + + + + + + + + select coalesce(aa.column_name, aa.attribute_name) as column_name, + aa.datatype + from acs_attributes aa, + ca_attributes ca, + acs_object_types at + where aa.attribute_id = ca.attribute_id and + (ca.package_id = :package_id or + ca.sitewide_p = 't') and + aa.object_type = :content_type and + at.object_type = :content_type + $storage_stub + + + + + + + + + $query_string + + + + + + + + + select supertype + from acs_object_types + where object_type = :content_type + + + + + + Index: openacs-4/contrib/packages/classified-ads/tcl/containers-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/containers-procs-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/containers-procs-postgresql.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,53 @@ + + + postgresql7.1 + + + + + + select ca_container__delete (:container_id) + + + + + + + + + select ca_container__get_title (:container_id) + + + + + + + + + select ca_container__set_title (:container_id, + :title) + + + + + + + + + select ca_container__get_description (:container_id) + + + + + + + + + select ca_container__set_description (:container_id, + :description) + + + + + + Index: openacs-4/contrib/packages/classified-ads/tcl/containers-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/containers-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/containers-procs.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,140 @@ +ad_library { + + Classified Ads Procs (Containers) + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: containers-procs.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} + +namespace eval classified-ads::containers { + + + ad_proc -public new { + {-item_id_element:required} + {-form_id:required} + } { + + creates a new container + + @param form_id The ID of the form that contains the name/value pairs + @param item_id_element The name of the form element that should be used as the item id + + } { + return [classified-ads::create_ca_item -item_id_element $item_id_element \ + -content_type "ca_container" \ + -form_id $form_id \ + ] + } + + + ad_proc -public edit { + {-item_id_element:required} + {-form_id:required} + } { + + edits properties of an existing container + + @param form_id The ID of the form that contains the name/value pairs + @param item_id_element The name of the form element that should be used as the item id + + } { + return [classified-ads::edit_ca_item -item_id_element $item_id_element \ + -form_id $form_id \ + ] + } + + + ad_proc -public delete { + {-container_id:required} + } { + + delete an existing container + + @param container_id The container id of the container to delete + + } { + db_exec_plsql delete_container {} + + return 0 + } + + + ad_proc -public get { + {-container_id:required} + {-array:required} + } { + + returns the data for a particular container + + @param container_id The container id of the container to get the data + @param array An array where the data will be stored + + } { + upvar $array row + + set row(title) [get_title -container_id $container_id] + set row(description) [get_description -container_id $container_id] + + return 0 + } + + + ad_proc -public get_title { + {-container_id:required} + } { + + returns the title for a particular container + + @param container_id The container id of the container to get the title + + } { + return [db_exec_plsql get_title {}] + } + + + ad_proc -public set_title { + {-container_id:required} + {-title:required} + } { + + sets the title for a particular container + + @param container_id The container id of the container to set the title + @param title The new title + + } { + return [db_exec_plsql set_title {}] + } + + + ad_proc -public get_description { + {-container_id:required} + } { + + returns the description for a particular container + + @param container_id The container id of the container to get the description + + } { + return [db_exec_plsql get_description {}] + } + + + ad_proc -public set_description { + {-container_id:required} + {-description ""} + } { + + sets the description for a particular container + + @param container_id The container id of the container to set the description + @param description The new description + + } { + return [db_exec_plsql set_description {}] + } + + +} Index: openacs-4/contrib/packages/classified-ads/tcl/widget-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/widget-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/widget-procs.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,176 @@ +ad_library { + + Classified Ads Procs (Widgets) + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: widget-procs.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} + +namespace eval classified-ads::widgets { + + + # DEDS: FIXME - we need to accept extra options + # this is true for the format case in the date widgets + # we need support for date widgets + # check also the datatype in acs_attributes, we may be doing it wrong + + + + ad_proc -public get_widget_params { + {-content_type:required} + {-form_id:required} + } { + + returns the widgets for a particular content_type + + @param content_type The content type whose widgets we are interested in + @param form_id The id of the form where we create the widgets + + } { + + set package_id [ad_conn package_id] + set widget_list [db_list_of_ns_sets select_widgets {}] + + foreach one_widget $widget_list { + set extra_ops "" + + # were html options passed? + set html_options [ns_set get $one_widget html_options] + if {![empty_string_p $html_options]} { + append extra_ops " -html $html_options" + } + + # is there a default value? + set default_value [ns_set get $one_widget default_value] + if {![empty_string_p $default_value]} { + append extra_ops " -value $default_value" + } + + # is there a validate clause? + # DEDS: FIXME - i haven't tested this, although this may not work because of eval + set validate_clause [ns_set get $one_widget validate] + if {![empty_string_p $validate_clause]} { + append extra_ops " -validate $validate_clause" + } + + # is it optional? + if {[string equal [ns_set get $one_widget optional_p] "t"]} { + append extra_ops " -optional" + } + + set widget_command "template::element::create $form_id [ns_set get $one_widget attribute_name] \ + -label \"[ns_set get $one_widget label]\" \ + -datatype \"[ns_set get $one_widget datatype]\" \ + -options \"[ns_set get $one_widget select_options]\" \ + -widget \"[ns_set get $one_widget widget]\" $extra_ops" + + eval $widget_command + } + + + return 0 + + } + + + ad_proc -public set_widget_values { + {-form_id:required} + {-form_values:required} + } { + + assigns values to the elements of a form + + @param form_id The id of the form that we assign values to + @param form_values A list of lists containing the values to assign to. + Each sublist must have two elements with the first being the + element name and the second the element value. + + } { + + foreach one_pair $form_values { + template::element::set_properties $form_id [lindex $one_pair 0] -value [lindex $one_pair 1] + } + + return 0 + + } + + + ad_proc -public date_widget_to_sql { + {-date:required} + } { + + converts the contents of a date widget into a format understood by sql + + @param date the date value as passed by the widget + + } { + + set year [template::util::date::get_property year $date] + set month [template::util::date::get_property month $date] + set day [template::util::date::get_property day $date] + + # put together the sql date + set sql_date_string "$year-$month-$day" + if {[string match $sql_date_string "--"]} { + set sql_date_string "" + } + return $sql_date_string + + } + + + ad_proc -public sql_to_date_widget { + {-sql_date:required} + {-format:required} + } { + converts an sql date to those accepted by our widget + + @param sql_date the sql date + @param format the format to convert to. can be any of YYYY-MM-DD, + HH12:MIam, or HH24:MI + } { + # stolen from calendar procs + + set date [template::util::date::create] + + switch -exact -- $format { + {YYYY-MM-DD} { + regexp {([0-9]*)-([0-9]*)-([0-9]*)} $sql_date all year month day + + set date [template::util::date::set_property format $date {DD MONTH YYYY}] + set date [template::util::date::set_property year $date $year] + set date [template::util::date::set_property month $date $month] + set date [template::util::date::set_property day $date $day] + } + + {HH12:MIam} { + regexp {([0-9]*):([0-9]*) *([aApP][mM])} $sql_date all hours minutes ampm + + set date [template::util::date::set_property format $date {HH12:MI am}] + set date [template::util::date::set_property hours $date $hours] + set date [template::util::date::set_property minutes $date $minutes] + set date [template::util::date::set_property ampm $date [string tolower $ampm]] + } + + {HH24:MI} { + regexp {([0-9]*):([0-9]*)} $sql_date all hours minutes + + set date [template::util::date::set_property format $date {HH24:MI}] + set date [template::util::date::set_property hours $date $hours] + set date [template::util::date::set_property minutes $date $minutes] + } + + {HH24} { + set date [template::util::date::set_property format $date {HH24:MI}] + set date [template::util::date::set_property hours $date $sql_date] + set date [template::util::date::set_property minutes $date 0] + } + } + + return $date + } + +} Index: openacs-4/contrib/packages/classified-ads/tcl/widget-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/widget-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/tcl/widget-procs.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,46 @@ + + + + + + + + select cawv.*, + aa.default_value, + aa.attribute_name, + aa.datatype + from acs_attributes aa, + ca_attribute_widget_values cawv, + ca_attributes ca + where aa.attribute_id = cawv.attribute_id and + ca.attribute_id = aa.attribute_id and + aa.object_type = :content_type and + cawv.enabled_p = 't' and + (ca.sitewide_p = 't' or + ca.package_id = :package_id) + order by aa.sort_order asc + + + + + + + + + select aa.attribute_name + from acs_attributes aa, + ca_attribute_widget_values cawv, + ca_attributes ca + where aa.attribute_id = cawv.attribute_id and + ca.attribute_id = aa.attribute_id and + aa.object_type = :content_type and + cawv.enabled_p = 't' and + (ca.sitewide_p = 't' or + ca.package_id = :package_id) + order by aa.sort_order asc + + + + + + Index: openacs-4/contrib/packages/classified-ads/www/ad-new.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/ad-new.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/ad-new.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,6 @@ + +@title@ +@context@ +ad.title + + Index: openacs-4/contrib/packages/classified-ads/www/ad-new.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/ad-new.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/ad-new.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,80 @@ +ad_page_contract { + + Create a Classified Ads Ad + + @author Deds Castillo (deds@infiniteinfo.com) + @author Roberto Mello (rmello@fslc.usu.edu) + @creation-date 2003-01-15 + @cvs-id $Id: ad-new.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + keyword_id:integer + {return_url "one-category"} +} + +form create ad + +element create ad ad_id \ + -label "Ad ID" \ + -datatype integer \ + -widget hidden + +element create ad return_url \ + -label "Return URL" \ + -datatype text \ + -widget hidden \ + -value $return_url + +element create ad keyword_id \ + -label "keyword id" \ + -datatype text \ + -widget hidden \ + -value $keyword_id + +element create ad title \ + -label "Title" \ + -datatype text \ + -widget text \ + -html {size 60 maxlength 1000} + +element create ad description \ + -label "Description" \ + -datatype text \ + -widget textarea \ + -html {cols 60 rows 10 wrap soft} \ + -optional + +element create ad data \ + -label "Content" \ + -datatype text \ + -widget textarea \ + -html {cols 60 rows 10 wrap soft} \ + -optional + +classified-ads::widgets::get_widget_params -content_type "ca_ad" -form_id ad + + +if {[form is_valid ad]} { + + set ad_id [classified-ads::ads::new \ + -item_id_element ad_id \ + -form_id ad \ + -category_id $keyword_id] + + template::form get_values ad \ + return_url + + ad_returnredirect "$return_url?keyword_id=$keyword_id" + ad_script_abort +} + +if { [form is_request ad] } { + # Pre-fetch the ad_id + set ad_id [db_nextval acs_object_id_seq] + element set_properties ad ad_id -value $ad_id +} + +set title "Create New" +set context [list [list "ads" "Ads"] $title] + +ad_return_template Index: openacs-4/contrib/packages/classified-ads/www/ad-view.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/ad-view.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/ad-view.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,11 @@ + +@title@ +@context@ + +
      +
    • ad_id: @ad_id@ +
    • description: @description@ +
    • data: @data@ +
    • expires_on: expires_on +
    + Index: openacs-4/contrib/packages/classified-ads/www/ad-view.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/ad-view.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/ad-view.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,34 @@ +ad_page_contract { + ad-view.tcl + + @author Paul Doerwald + @creation-date 2002-12-30 +} { + ad_id:integer + {revision_id:integer ""} +} -properties { + context:onevalue + title:onevalue +} + +#classified-ads::widgets::get_widget_params -content_type "ca_ad" -form_id ad +#set form_values [classified-ads::get_attribute_values -item_id $ad_id -item_id_element ad_id] +#classified-ads::widgets::set_widget_values -form_id ad -form_values $form_values + +classified-ads::ads::get -ad_id $ad_id -revision_id $revision_id -array adinfo +set title $adinfo(title) +set description $adinfo(description) +#set data $adinfo(data) +#set employer $adinfo + +if { $revision_id == "" } { + set revision_id [classified-ads::get_latest_revision -item_id $ad_id] +} + +db_1row select_data { + select * from cr_ca_adsx where revision_id=:revision_id +} + +set data [classified-ads::get_content -revision_id $revision_id] + +set context [list $title] Index: openacs-4/contrib/packages/classified-ads/www/categories.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/categories.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/categories.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,52 @@ + +@title@ +@context@ + + +

    Categories

    +

    +

    +
    + + + + + + + + +

    + Place a new ad under this category. +

    +
    + + no ads assigned under this category + +

    + + Place a new ad without category. + + + Place a new ad under this category. + +

    +
    + + +

    Ads not assigned to any category

    + + +
    + Index: openacs-4/contrib/packages/classified-ads/www/categories.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/categories.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/categories.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,40 @@ +ad_page_contract { + + Classified Ads Administration + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: categories.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + {keyword_id ""} +} + +set root_folder_id [classified-ads::get_root_folder_id] +set package_category_id [classified-ads::categories::package_category_exists_p] +set package_category_p 0 + +if {[empty_string_p $keyword_id]} { + set keyword_id $package_category_id + set package_category_p 1 +} elseif {[string equal [classified-ads::main_keyword_exists_p] $keyword_id]} { + ad_return_complaint 1 "
  • no access to the root id" + ad_script_abort +} + +db_multirow categories select_categories {} + +template::util::list_of_ns_sets_to_multirow \ + -rows [classified-ads::ads::get_unassigned_ads_by_category] \ + -var_name unassigned_ads + +template::util::list_of_ns_sets_to_multirow \ + -rows [classified-ads::ads::get_assigned_ads_by_category -category_id_list [list $keyword_id]] \ + -var_name assigned_ads + +set return_url "[ad_conn url]?[ad_conn query]" + +set title "Categories" +set context [classified-ads::categories::generate_trail -keyword_id $keyword_id] + +ad_return_template Index: openacs-4/contrib/packages/classified-ads/www/categories.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/categories.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/categories.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,20 @@ + + + + + + + + select *, + (select count(*) + from cr_keywords + where parent_id = ck.keyword_id) as children_count + from cr_keywords ck + where parent_id = :keyword_id + order by heading + + + + + + Index: openacs-4/contrib/packages/classified-ads/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/index.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/index.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,12 @@ +ad_page_contract { + + Classified Ads User Interface + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: index.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} + + +ad_returnredirect categories Index: openacs-4/contrib/packages/classified-ads/www/one-category.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/one-category.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/one-category.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,29 @@ + +@category_heading@ +@context@ + + +

    @category_heading@

    + +

    +

    +
    + + + + + + + + + + no ads assigned under this category + Index: openacs-4/contrib/packages/classified-ads/www/one-category.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/one-category.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/one-category.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,30 @@ +ad_page_contract { + + Show one category and its ads + + @author Roberto Mello (rmello@fslc.usu.edu) + @creation-date 2003-01-25 + @cvs-id $Id: one-category.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + keyword_id:integer +} + +set root_folder_id [classified-ads::get_root_folder_id] +set category_heading [classified-ads::categories::get_heading -keyword_id $keyword_id] + +#set package_category_id [classified-ads::categories::package_category_exists_p] +#set package_category_p 0 + +db_multirow categories select_categories {} + +template::util::list_of_ns_sets_to_multirow \ + -rows [classified-ads::ads::get_assigned_ads_by_category -category_id_list [list $keyword_id]] \ + -var_name assigned_ads + +#set return_url "[ad_conn url]?[ad_conn query]" + +set title "Categories" +set context [classified-ads::categories::generate_trail -keyword_id $keyword_id] + +ad_return_template Index: openacs-4/contrib/packages/classified-ads/www/one-category.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/one-category.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/one-category.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,17 @@ + + + + + + + + select * + from cr_keywords ck + where parent_id = :keyword_id + order by heading + + + + + + Index: openacs-4/contrib/packages/classified-ads/www/admin/ad-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/ad-delete.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/ad-delete.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,19 @@ +ad_page_contract { + + Delete an Ad + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: ad-delete.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + ad_id:integer,notnull + {return_url "ads"} +} + +if {[catch {classified-ads::ads::delete -ad_id $ad_id} errmsg]} { + ad_return_complaint 1 "
  • the following error occured during deletion: $errmsg" + ad_script_abort +} + +ad_returnredirect $return_url Index: openacs-4/contrib/packages/classified-ads/www/admin/ad-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/ad-edit.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/ad-edit.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,6 @@ + +@title@ +@context@ +ad.title + + Index: openacs-4/contrib/packages/classified-ads/www/admin/ad-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/ad-edit.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/ad-edit.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,76 @@ +ad_page_contract { + + Create a Classified Ads Ad + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: ad-edit.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + {ad_id:notnull,integer} + {revision_id ""} + {return_url "ads"} +} + +form create ad + +element create ad ad_id \ + -label "Ad ID" \ + -datatype integer \ + -widget hidden + +element create ad return_url \ + -label "Return URL" \ + -datatype text \ + -widget hidden \ + -value $return_url + +element create ad title \ + -label "Title" \ + -datatype text \ + -widget text \ + -html {size 60 maxlength 1000} + +element create ad description \ + -label "Description" \ + -datatype text \ + -widget textarea \ + -html {cols 60 rows 10 wrap soft} \ + -optional + +element create ad data \ + -label "Content" \ + -datatype text \ + -widget textarea \ + -html {cols 60 rows 10 wrap soft} \ + -optional + +classified-ads::widgets::get_widget_params -content_type "ca_ad" -form_id ad + + +if {[form is_valid ad]} { + + set ad_id [classified-ads::ads::edit -item_id_element ad_id -form_id ad] + + template::form get_values ad \ + return_url + + ad_returnredirect $return_url + ad_script_abort +} + +if { [form is_request ad] } { + set form_values [classified-ads::get_attribute_values -item_id $ad_id -item_id_element ad_id] + classified-ads::widgets::set_widget_values -form_id ad -form_values $form_values + + classified-ads::ads::get -ad_id $ad_id -revision_id $revision_id -array adinfo + element set_properties ad ad_id -value $ad_id + element set_properties ad title -value $adinfo(title) + element set_properties ad description -value $adinfo(description) + element set_properties ad data -value $adinfo(data) +} + +set title "Edit" +set context [list [list "ads" "Ads"] $title] + +ad_return_template Index: openacs-4/contrib/packages/classified-ads/www/admin/ad-new.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/ad-new.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/ad-new.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,6 @@ + +@title@ +@context@ +ad.title + + Index: openacs-4/contrib/packages/classified-ads/www/admin/ad-new.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/ad-new.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/ad-new.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,69 @@ +ad_page_contract { + + Create a Classified Ads Ad + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: ad-new.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + {return_url "ads"} +} + +form create ad + +element create ad ad_id \ + -label "Ad ID" \ + -datatype integer \ + -widget hidden + +element create ad return_url \ + -label "Return URL" \ + -datatype text \ + -widget hidden \ + -value $return_url + +element create ad title \ + -label "Title" \ + -datatype text \ + -widget text \ + -html {size 60 maxlength 1000} + +element create ad description \ + -label "Description" \ + -datatype text \ + -widget textarea \ + -html {cols 60 rows 10 wrap soft} \ + -optional + +element create ad data \ + -label "Content" \ + -datatype text \ + -widget textarea \ + -html {cols 60 rows 10 wrap soft} \ + -optional + +classified-ads::widgets::get_widget_params -content_type "ca_ad" -form_id ad + + +if {[form is_valid ad]} { + + set ad_id [classified-ads::ads::new -item_id_element ad_id -form_id ad] + + template::form get_values ad \ + return_url + + ad_returnredirect $return_url + ad_script_abort +} + +if { [form is_request ad] } { + # Pre-fetch the ad_id + set ad_id [db_nextval acs_object_id_seq] + element set_properties ad ad_id -value $ad_id +} + +set title "Create New" +set context [list [list "ads" "Ads"] $title] + +ad_return_template Index: openacs-4/contrib/packages/classified-ads/www/admin/ads.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/ads.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/ads.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,18 @@ + +@title@ +@context@ + +

    Ads

    +

    +

    Index: openacs-4/contrib/packages/classified-ads/www/admin/ads.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/ads.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/ads.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,26 @@ +ad_page_contract { + + Classified Ads Administration + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: ads.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + {category_id ""} +} + +if {[empty_string_p $category_id]} { + set where_clause "" +} else { + set where_clause "and ci.item_id = :category_id" +} + +db_multirow ads select_ads {} + +set return_url "[ad_conn url]?[ad_conn query]" + +set title "Ads" +set context $title + +ad_return_template Index: openacs-4/contrib/packages/classified-ads/www/admin/ads.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/ads.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/ads.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,20 @@ + + + + + + + + select ci.item_id as ad_id, + cr.title + from cr_items ci, + cr_revisions cr + where ci.latest_revision = cr.revision_id and + content_type = 'ca_ad' + $where_clause + + + + + + Index: openacs-4/contrib/packages/classified-ads/www/admin/categories.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/categories.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/categories.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,41 @@ + +@title@ +@context@ + +

    Categories

    +

    +

    + + +

    Ads under this Category

    + +
    + + +

    Ads not assigned to any Category

    +
      + +
    • @unassigned_ads.title@ + +
    +
    \ No newline at end of file Index: openacs-4/contrib/packages/classified-ads/www/admin/categories.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/categories.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/categories.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,40 @@ +ad_page_contract { + + Classified Ads Administration + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: categories.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + {keyword_id ""} +} + +set root_folder_id [classified-ads::get_root_folder_id] +set package_category_id [classified-ads::categories::package_category_exists_p] +set package_category_p 0 + +if {[empty_string_p $keyword_id]} { + set keyword_id $package_category_id + set package_category_p 1 +} elseif {[string equal [classified-ads::main_keyword_exists_p] $keyword_id]} { + ad_return_complaint 1 "
  • no access to the root id" + ad_script_abort +} + +db_multirow categories select_categories {} + +template::util::list_of_ns_sets_to_multirow \ + -rows [classified-ads::ads::get_unassigned_ads_by_category] \ + -var_name unassigned_ads + +template::util::list_of_ns_sets_to_multirow \ + -rows [classified-ads::ads::get_assigned_ads_by_category -category_id_list [list $keyword_id]] \ + -var_name assigned_ads + +set return_url "[ad_conn url]?[ad_conn query]" + +set title "Categories" +set context [classified-ads::categories::generate_trail -keyword_id $keyword_id] + +ad_return_template Index: openacs-4/contrib/packages/classified-ads/www/admin/categories.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/categories.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/categories.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,20 @@ + + + + + + + + select *, + (select count(*) + from cr_keywords + where parent_id = ck.keyword_id) as children_count + from cr_keywords ck + where parent_id = :keyword_id + order by heading + + + + + + Index: openacs-4/contrib/packages/classified-ads/www/admin/category-assign-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/Attic/category-assign-2.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/category-assign-2.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,16 @@ +ad_page_contract { + + Classified Ads Administration + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: category-assign-2.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + {keyword_id:notnull,integer} + {item_id:notnull,integer} +} + +classified-ads::categories::item_assign -keyword_id $keyword_id -item_id $item_id + +ad_returnredirect "categories?keyword_id=$keyword_id" \ No newline at end of file Index: openacs-4/contrib/packages/classified-ads/www/admin/category-assign.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/Attic/category-assign.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/category-assign.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,14 @@ + +@title@ +@context@ +@context_bar@ +

    + + +

    Ads not assigned to this category

    + + \ No newline at end of file Index: openacs-4/contrib/packages/classified-ads/www/admin/category-assign.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/category-assign.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/category-assign.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,22 @@ +ad_page_contract { + + Classified Ads Administration + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: category-assign.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + {keyword_id:notnull,integer} +} + +template::util::list_of_ns_sets_to_multirow \ + -rows [classified-ads::ads::get_unassigned_ads_by_category -category_id_list [list $keyword_id]] \ + -var_name unassigned_ads + +set title "Assign an Ad" +set context [classified-ads::categories::generate_trail -keyword_id $keyword_id -append_element $title] + +set context_bar [eval classified-ads::context_bar $context] + +ad_return_template Index: openacs-4/contrib/packages/classified-ads/www/admin/category-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/category-delete.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/category-delete.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,19 @@ +ad_page_contract { + + Delete a Classified Ads Category + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: category-delete.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + keyword_id:integer,notnull + {return_url "categories"} +} + +if {[catch {classified-ads::categories::delete -keyword_id $keyword_id} errmsg]} { + ad_return_complaint 1 "
  • the following error occured during deletion: $errmsg" + ad_script_abort +} + +ad_returnredirect $return_url Index: openacs-4/contrib/packages/classified-ads/www/admin/category-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/category-edit.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/category-edit.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,6 @@ + +@title@ +@context@ +category.heading + + Index: openacs-4/contrib/packages/classified-ads/www/admin/category-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/category-edit.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/category-edit.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,65 @@ +ad_page_contract { + + Edit a Classified Ads Category + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: category-edit.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + keyword_id:integer,notnull + {return_url "categories"} +} + +form create category + +element create category keyword_id \ + -label "Keyword ID" \ + -datatype integer \ + -widget hidden + +element create category return_url \ + -label "Return URL" \ + -datatype text\ + -widget hidden + +element create category heading \ + -label "Category" \ + -datatype text \ + -widget text \ + -html {size 60} {maxlength 600} + +element create category description \ + -label "Description" \ + -datatype text \ + -widget textarea \ + -html {cols 60 rows 10 wrap soft} \ + -optional + +if {[form is_valid category]} { + template::form get_values category \ + keyword_id return_url heading description + + set keyword_id [classified-ads::categories::edit -keyword_id $keyword_id \ + -heading $heading \ + -description $description \ + ] + + ad_returnredirect $return_url + ad_script_abort +} + +set title "Edit" +set context [classified-ads::categories::generate_trail -keyword_id $keyword_id -append_element $title] + +if { [form is_request category] } { + # Select info for this category + classified-ads::categories::get -keyword_id $keyword_id -array category_info + + element set_properties category keyword_id -value $keyword_id + element set_properties category return_url -value $return_url + element set_properties category heading -value $category_info(heading) + element set_properties category description -value $category_info(description) +} + +ad_return_template Index: openacs-4/contrib/packages/classified-ads/www/admin/category-new.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/category-new.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/category-new.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,6 @@ + +@title@ +@context@ +category.heading + + Index: openacs-4/contrib/packages/classified-ads/www/admin/category-new.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/category-new.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/category-new.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,75 @@ +ad_page_contract { + + Create a Classified Ads Category + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: category-new.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + parent_id:integer,notnull + {return_url "categories"} +} + +form create category + +element create category keyword_id \ + -label "Keyword ID" \ + -datatype integer \ + -widget hidden + +element create category parent_id \ + -label "Parent ID" \ + -datatype integer \ + -widget hidden + +element create category return_url \ + -label "Return URL" \ + -datatype text \ + -widget hidden \ + -value $return_url + +element create category heading \ + -label "Category" \ + -datatype text \ + -widget text \ + -html {size 60} {maxlength 600} + +element create category description \ + -label "Description" \ + -datatype text \ + -widget textarea \ + -html {cols 60 rows 10 wrap soft} \ + -optional + +if {[form is_valid category]} { + template::form get_values category \ + keyword_id parent_id return_url heading description + + if {[catch {set keyword_id [classified-ads::categories::new -keyword_id $keyword_id \ + -heading $heading \ + -parent_id $parent_id \ + -description $description \ + ]} errmsg] + } { + # DEDS: FIXME - do this better via select and compare of keyword id + # double click protection + ad_return_complaint 1 "
  • you probably clicked the submit button more than once" + ad_script_abort + } + + ad_returnredirect $return_url + ad_script_abort +} + +if { [form is_request category] } { + # Pre-fetch the keyword_id + set keyword_id [db_nextval acs_object_id_seq] + element set_properties category keyword_id -value $keyword_id + element set_properties category parent_id -value $parent_id +} + +set title "Create" +set context [classified-ads::categories::generate_trail -keyword_id $parent_id -append_element $title] + +ad_return_template Index: openacs-4/contrib/packages/classified-ads/www/admin/category-new.tcl.bak =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/category-new.tcl.bak,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/category-new.tcl.bak 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,69 @@ +ad_page_contract { + + Create a Classified Ads Category + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: category-new.tcl.bak,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + parent_id:integer,notnull + {return_url "categories"} +} + +form create category + +element create category keyword_id \ + -label "Keyword ID" \ + -datatype integer \ + -widget hidden + +element create category parent_id \ + -label "Parent ID" \ + -datatype integer \ + -widget hidden + +element create category heading \ + -label "Category" \ + -datatype text \ + -widget text \ + -html {size 60} {maxlength 600} + +element create category description \ + -label "Description" \ + -datatype text \ + -widget textarea \ + -html {cols 60 rows 10 wrap soft} \ + -optional + +if {[form is_valid category]} { + template::form get_values category \ + keyword_id parent_id heading description + + if {[catch {set keyword_id [classified-ads::categories::new -keyword_id $keyword_id \ + -heading $heading \ + -parent_id $parent_id \ + -description $description \ + ]} errmsg] + } { + # DEDS: FIXME - do this better via select and compare of keyword id + # double click protection + ad_return_complaint 1 "
  • you probably clicked the submit button more than once" + ad_script_abort + } + + ad_returnredirect $return_url + ad_script_abort +} + +if { [form is_request category] } { + # Pre-fetch the keyword_id + set keyword_id [db_nextval acs_object_id_seq] + element set_properties category keyword_id -value $keyword_id + element set_properties category parent_id -value $parent_id +} + +set title "Create new category" +set context [classified-ads::categories::generate_trail -keyword_id $parent_id -append_element $title] + +ad_return_template Index: openacs-4/contrib/packages/classified-ads/www/admin/category-unassign.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/category-unassign.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/category-unassign.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,16 @@ +ad_page_contract { + + Classified Ads Administration + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: category-unassign.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} { + {keyword_id:notnull,integer} + {item_id:notnull,integer} +} + +classified-ads::categories::item_unassign -keyword_id $keyword_id -item_id $item_id + +ad_returnredirect "categories?keyword_id=$keyword_id" \ No newline at end of file Index: openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,45 @@ + +@title@ +@context@ +new_field.attribute_name + + + + +
    +

    Help

    + + +

    Attribute Name — A-Za-z0-9-_ only. + +

    Pretty Name, Pretty Plural — These are the names you'll know this field by (see Label) + +

    Datatype — The kind of value you want. + +

    Column Spec — The SQL data type of the column you want created in the database. Value in column spec must agree with value in datatype. e.g. integer, varchar(100), timestamp, numeric(9,2), etc. + +

    Sort Order (optional) — The order you want this field displayed in. + +

    Default Value (optional) — The default value for this field. + +

    Widget — How would you like the data entry field displayed? + +

    Label — This is the word that appears beside the field on the place ad form shown to users. + +

    HTML Options (optional) — For additional HTML attributes for the widget. Always surround with {braces} and always in attribute value order. e.g. {size 30 maxlength 100 onfocus "blur();"} + +

    Select Options (optional) — A list of options for select lists and button groups (check boxes or radio buttons). The list contains two-element lists in the form { {label value} {label value} {label value} ...} e.g. {{S "12.99"} {M "15.49"} {L "17.99}} renders in HTML:

    +<option value="12.99">S
    +<option value="15.49">M
    +<option value="17.99">L
    +
    + +

    Validiate (experts only) — A list of custom validation blocks in the form { name { expression } { message } name { expression } { message } ...} where name is a unique identifier for the validation step, expression is a block to Tcl code that evaluates to 1 or 0, and message is to be displayed to the user when the validation step fails. + +

    Optional — The user is not required to use this field. + +

    Enabled — This field will appear to the user. + + +

    + Index: openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,170 @@ +ad_page_contract { + Add/Edit fields (attributes) + + @author Paul Doerwald (paul@liquidmedia.ca) + @creation-date 2002-10-24 +} { + attribute_id:integer,notnull,optional + {attribute_name:nohtml ""} + {datatype:nohtml text} + {column_spec:nohtml ""} + {pretty_name:nohtml ""} + {pretty_plural:nohtml ""} + {sort_order:nohtml ""} + {default_value:nohtml ""} + {widget:nohtml text} + {label:nohtml ""} + {html_options:nohtml ""} + {select_options:nohtml ""} + {validate:nohtml ""} + {optional_p:boolean f} + {enabled_p:boolean t} +} -properties { + title:onevalue + context:onevalue +} + +set content_type "ca_ad" +set package_id [ad_conn package_id] + +template::form create new_field + +if {[template::form is_request new_field] && [info exists attribute_id]} { + template::element create new_field attribute_id \ + -widget hidden \ + -datatype integer \ + -value $attribute_id + + db_1row field { } + + set title "Edit Field" + set context [list [list "fields" "Fields"] "Edit Field"] + set cant_edit_html "onfocus \"blur();\" style \"background: #d3d3d3\"" + set column_spec "unknown" + + ## Widget values + db_0or1row widget_vars { } + +} else { + set title "Add Field" + set context [list [list "fields" "Fields"] "Add Field"] + set cant_edit_html "" +} + +template::element create new_field attribute_name \ + -datatype text \ + -label "Attribute Name" \ + -help "A-Z, a-z, 0-9, - and _ only" \ + -html "size 30 $cant_edit_html" \ + -value $attribute_name + +template::element create new_field pretty_name \ + -datatype text \ + -label "Pretty Name" \ + -html "size 30" \ + -value $pretty_name + +template::element create new_field pretty_plural \ + -datatype text \ + -label "Pretty Plural" \ + -html "size 30" \ + -value $pretty_plural + +template::element create new_field datatype \ + -widget select \ + -datatype text \ + -label "Datatype" \ + -html $cant_edit_html \ + -options [db_list_of_lists datatypes { }] \ + -value $datatype + +template::element create new_field column_spec \ + -datatype text \ + -label "Column Spec" \ + -html $cant_edit_html \ + -value $column_spec + +if { $sort_order == "" } { + db_1row max_sort_order { } + set sort_order [expr $sort_order + 1] +} + +template::element create new_field sort_order \ + -datatype integer \ + -label "Sort Order" \ + -html "size 5" \ + -value $sort_order + +template::element create new_field default_value \ + -datatype text \ + -label "Default Value" \ + -html "size 30" \ + -value $default_value + +template::element create new_field widget \ + -widget select \ + -datatype text \ + -label "Widget" \ + -html $cant_edit_html \ + -options [db_list_of_lists widgets { }] \ + -value $widget + +template::element create new_field label \ + -datatype text \ + -label "Label" \ + -html {size 30} \ + -value $label + +template::element create new_field html_options \ + -datatype text \ + -label "HTML Options" \ + -html {size 30} \ + -value $html_options + +template::element create new_field select_options \ + -datatype text \ + -label "Select Options" \ + -html {size 30} \ + -value $select_options + +template::element create new_field validate \ + -datatype text \ + -label "Validate" \ + -html {size 30} \ + -value $validate + +template::element create new_field optional_p \ + -datatype boolean \ + -widget checkbox \ + -label " " \ + -options {{Optional t}} \ + -value $optional_p + +template::element create new_field enabled_p \ + -datatype boolean \ + -widget checkbox \ + -label " " \ + -options {{Enabled t}} \ + -value $enabled_p + +if [template::form is_valid new_field] { + set user_id [ad_conn user_id] + set peeraddr [ad_conn peeraddr] + + ns_log Notice "RIGHT HERE" + if [info exists attribute_id] { + db_transaction { + db_dml attribute_update { } + db_dml widget_update { } + } + } else { + db_transaction { + db_1row attribute_new { } + db_1row widget_new { } + } + } + ad_returnredirect "fields" +} + +ad_return_template + Index: openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,67 @@ + + + + + select aa.attribute_id, coalesce(aa.column_name, aa.attribute_name) as column_name, aa.default_value, coalesce(aa.table_name,at.table_name) as table_name, aa.storage, aa.datatype, aa.sort_order, aa.attribute_name, aa.pretty_name, aa.pretty_plural + from acs_attributes aa, + ca_attributes ca, acs_object_types at + where aa.attribute_id = :attribute_id + and aa.attribute_id = ca.attribute_id + and (ca.package_id = :package_id or ca.sitewide_p = 't') + and aa.object_type = :content_type + and at.object_type = :content_type + + + + + + select widget, label, html_options, select_options, validate, optional_p, enabled_p + from ca_attribute_widget_values + where attribute_id=:attribute_id + + + + + + select distinct datatype, datatype from acs_attributes order by datatype + + + + + + select max(sort_order) as sort_order from acs_attributes + + + + + + select widget, widget from ca_attribute_widgets order by widget + + + + + + update acs_attributes set pretty_name=:pretty_name, pretty_plural=:pretty_plural, sort_order=:sort_order, default_value=:default_value where attribute_id=:attribute_id + + + + + + update ca_attribute_widget_values set label=:label, html_options=:html_options, select_options=:select_options, validate=:validate, optional_p=:optional_p, enabled_p=:enabled_p where attribute_id=:attribute_id + + + + + + select ca_attributes__create_attribute (:content_type::varchar, :attribute_name::varchar, :datatype::varchar, :pretty_name::varchar, :pretty_plural::varchar, :sort_order::int4, :default_value::varchar, 'type_specific'::varchar, 'cr_ca_ads'::varchar, :column_spec::varchar, :package_id::int4) as attribute_id + + + + + + select ca_attributes__register_widget (:attribute_id, :widget, :label, :html_options, :select_options, :validate, :optional_p) + + + + + Index: openacs-4/contrib/packages/classified-ads/www/admin/field-delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/field-delete.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/field-delete.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,31 @@ + +@title@ +@context@ + + +

    +

    Are you sure you want to delete this field? +

    + + + + + + + + + + + + +
    IDNamePretty NamePretty PluralOrderStorageDatatypeDefaultTableColumn
    @field.attribute_id@@field.attribute_name@@field.pretty_name@@field.pretty_plural@@field.sort_order@@field.storage@@field.datatype@@field.default_value@@field.table_name@@field.column_name@
    +
    + + + + + +
    +
    + + Index: openacs-4/contrib/packages/classified-ads/www/admin/field-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/field-delete.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/field-delete.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,28 @@ +ad_page_contract { + Delete one of the fields (attributes) + + @author Paul Doerwald (paul@liquidmedia.ca) + @creation-date 2002-10-24 +} { + attribute_id + content_type:optional + attribute_name:optional + {delete_p "f"} +} -properties { + title:onevalue + context:onevalue +} + +set title "Delete Field" +set context [list [list "fields" "Fields"] "Delete Field"] +set content_type "ca_ad" +set package_id [ad_conn package_id] + +if { $delete_p == "f" } { + db_1row one_field {} -column_array field + ad_return_template +} else { + db_1row delete_attribute {} + ad_returnredirect "fields" +} + Index: openacs-4/contrib/packages/classified-ads/www/admin/field-delete.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/field-delete.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/field-delete.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,23 @@ + + + + + select aa.attribute_id, coalesce(aa.column_name, aa.attribute_name) as column_name, aa.default_value, coalesce(aa.table_name,at.table_name) as table_name, aa.storage, aa.datatype, aa.sort_order, aa.attribute_name, aa.pretty_name, aa.pretty_plural + from acs_attributes aa, + ca_attributes ca, acs_object_types at + where aa.attribute_id = $attribute_id + and aa.attribute_id = ca.attribute_id + and (ca.package_id = :package_id or ca.sitewide_p = 't') + and aa.object_type = :content_type + and at.object_type = :content_type + order by sort_order + + + + + + select ca_attributes__drop_attribute(:content_type, :attribute_name); + + + + Index: openacs-4/contrib/packages/classified-ads/www/admin/fields.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/fields.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/fields.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,25 @@ + +@title@ +@context@ + +

    + + + + + + + + + + + + + + + + +
    IDNamePretty NamePretty PluralOrderStorageDatatypeDefaultTableColumnOptions
    @fields.attribute_id@@fields.attribute_name@@fields.pretty_name@@fields.pretty_plural@@fields.sort_order@@fields.storage@@fields.datatype@@fields.default_value@@fields.table_name@@fields.column_name@(delete)
    + Index: openacs-4/contrib/packages/classified-ads/www/admin/fields.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/fields.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/fields.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,19 @@ +ad_page_contract { + Configure fields (attributes) for ads in this package. + + @author Paul Doerwald (paul@liquidmedia.ca) + @creation-date 2002-22-24 +} { +} -properties { + context:onevalue +} + +set title "Fields" +set context "Fields" +set package_id [ad_conn package_id] +set content_type "ca_ad" + +db_multirow fields select_attributes {} + +ad_return_template + Index: openacs-4/contrib/packages/classified-ads/www/admin/fields.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/Attic/fields.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/fields.xql 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,16 @@ + + + + + select aa.attribute_id, coalesce(aa.column_name, aa.attribute_name) as column_name, aa.default_value, coalesce(aa.table_name,at.table_name) as table_name, aa.storage, aa.datatype, aa.sort_order, aa.attribute_name, aa.pretty_name, aa.pretty_plural + from acs_attributes aa, + ca_attributes ca, acs_object_types at + where aa.attribute_id = ca.attribute_id + and (ca.package_id = :package_id or ca.sitewide_p = 't') + and aa.object_type = :content_type + and at.object_type = :content_type + order by sort_order + + + + Index: openacs-4/contrib/packages/classified-ads/www/admin/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/index.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/index.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,10 @@ + +@title@ +@context@ + +

    +

    Index: openacs-4/contrib/packages/classified-ads/www/admin/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/index.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/admin/index.tcl 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,14 @@ +ad_page_contract { + + Classified Ads Administration + + @author Deds Castillo (deds@infiniteinfo.com) + @creation-date 2002-10-08 + @cvs-id $Id: index.tcl,v 1.1 2003/07/16 04:52:32 rmello Exp $ + +} + +set title "Classified Ads Administration" +set context "" + +ad_return_template Index: openacs-4/contrib/packages/classified-ads/www/doc/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/doc/index.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/classified-ads/www/doc/index.adp 16 Jul 2003 04:52:32 -0000 1.1 @@ -0,0 +1,51 @@ + +Classified Ads +{Classified Ads Documentation} + +

    Overview

    + +Authors: Deds Castillo and Paul Doerwalds. Roberto Mello made some modifications + and improvements and is now (July 2003) maintaining this package under OpenACS. + +

    The Classified Ads system can be used for all manner of ads, from buy/sell to wanted to job listings. +If one party has something another party wants or vice versa, the Classified Ads system can be used as the basis. + +

    Ads can be categorized and grouped into containers according to the following breakdown: + +

    +
    Classified Ads Instance -> Category -> Container -> Advertisement
    +
    + +

    Examples: + +

    +
    For Rent -> Apartment Buildings -> 319 Hazel St. -> Unit 205
    +
    Job Listings -> 
    +
    + +

    More coming here later.

    + +

    Features

    + +
      +
    • Uses the content repository. +
    • Categorization. +
    • Uses the templating system to build forms. +
    • Allows for custom fields per category. +
    • Others that I'm probably forgetting. +
    + +

    What needs to be improved

    + +
      +
    • Make it possible to place an ad under a category, instead of placing + under no category then assigning it to one. (DONE - Roberto)
    • +
    • Fix all the FIXME's in the code.
    • +
    • Give users a better UI for placing and viewing ads (will be done soon - Roberto) +
    • Add searching functionality. +
    • Integrate with notifications so users can be notified of new ads. +
    • Integrate with RSS so news aggregators can pick up new items (crazy idea? -Roberto) +
    • Check validation code for custom items. Seems not to be working. +
    • Give users a confirmation screen when placing new ads. +
    +