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 -r1.1 -r1.2 --- openacs-4/contrib/packages/classified-ads/tcl/ads-procs-postgresql.xql 16 Jul 2003 04:52:32 -0000 1.1 +++ openacs-4/contrib/packages/classified-ads/tcl/ads-procs-postgresql.xql 19 Jul 2003 01:48:45 -0000 1.2 @@ -21,15 +21,4 @@ - - - - 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 -r1.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl 18 Jul 2003 02:47:33 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl 19 Jul 2003 01:48:45 -0000 1.3 @@ -79,21 +79,32 @@ } { Gets the data of a particular ad + @author Deds Castillo + @author Roberto Mello + @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 + # Get extra widgets that we need to display + # + set package_id [ad_conn package_id] + set widget_list [db_list_of_ns_sets select_widgets {}] + if {[empty_string_p $revision_id]} { set revision_id [classified-ads::get_latest_revision -item_id $ad_id] } - db_1row select_data {} + # object_id, object_type, context_id, security_inherit_p, creation_user, + # creation_date, creation_ip, last_modified, modifying_user, modifying_ip, + # tree_sortkey, revision_id, title, item_id, description, publish_date, + # mime_type, nls_language, name, parent_id, ad_id + + db_1row select_data {} -column_array row - # DEDS: FIXME - you know what's wrong here right? - set row(title) $title - set row(description) $description + set row(pretty_publish_date) [util_AnsiDatetoPrettyDate $publish_date] set row(data) [classified-ads::get_content -revision_id $revision_id] return 0 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 -r1.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/tcl/ads-procs.xql 18 Jul 2003 02:47:33 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/tcl/ads-procs.xql 19 Jul 2003 01:48:45 -0000 1.3 @@ -8,7 +8,7 @@ select cm.keyword_id, ci.item_id, cr.title, - to_char(cr.publish_date, 'Mon DD, YYYY') as pretty_publish_date + to_char(cr.publish_date, 'Mon FMDD, YYYY') as pretty_publish_date from cr_item_keyword_map cm, cr_revisions cr, cr_items ci @@ -29,7 +29,7 @@ select ci.item_id, cr.title, - to_char(cr.publish_date, 'Mon DD, YYYY') as pretty_publish_date + to_char(cr.publish_date, 'Mon FMDD, YYYY') as pretty_publish_date from cr_revisions cr, cr_items ci where ci.item_id not in (select item_id @@ -43,5 +43,35 @@ + + + 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 * + from cr_ca_adsx + where revision_id = :revision_id + + + + Index: openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl 17 Jul 2003 21:30:13 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl 19 Jul 2003 01:48:45 -0000 1.3 @@ -9,51 +9,34 @@ } namespace eval classified-ads { - - - ad_proc -public package_key { + ad_proc -public package_key {} { + Returns the package key } { - - returns the package key - - } { return "classified-ads" } - ad_proc -public is_instantiated { + ad_proc -public is_instantiated {} { + Returns 1 if classified-ads is instantiated, 0 otherwise } { - - 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 { + ad_proc -public main_keyword_exists_p {} { + Returns the keyword id of the main category for the package, 0 if not yet created } { - - 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 { + ad_proc -public root_folder_exists_p {} { + Returns the folder id of the classified ads root folder, 0 if not yet created } { - - 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]" @@ -63,32 +46,28 @@ } - - ad_proc -public get_root_folder_id { + ad_proc -public get_root_folder_id {} { + Returns the folder id of the classified ads root folder, error if none } { - - 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_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 - 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. - + @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] @@ -98,84 +77,61 @@ } - ad_proc -public get_mounted_packages { + ad_proc -public get_mounted_packages {} { + Returns a list of mounted classified-ads 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 - + 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 - + 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 - + 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 - 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} @@ -186,7 +142,6 @@ {-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 @@ -219,28 +174,34 @@ 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_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 @@ -256,8 +217,9 @@ # 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]} { @@ -274,13 +236,16 @@ 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" @@ -290,14 +255,17 @@ } # 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]} { @@ -309,11 +277,13 @@ 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 { @@ -333,7 +303,6 @@ } - ad_proc -public edit_ca_item { {-item_id_element:required} {-form_id:required} @@ -342,14 +311,12 @@ {-data_column "data"} {-revision_id} } { + Edits a classified ads item. - 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] @@ -360,6 +327,7 @@ # 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 { @@ -370,8 +338,10 @@ 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 @@ -388,16 +358,20 @@ 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 @@ -411,16 +385,19 @@ # 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" @@ -436,26 +413,32 @@ 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] } @@ -469,27 +452,23 @@ } } - } 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 + 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] } @@ -500,15 +479,13 @@ {-package_id} {-storage "all"} } { - - returns a list of lists of the attributes for one content type + Returns a list of ns_sets 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] @@ -523,16 +500,13 @@ 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 + 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] @@ -556,18 +530,18 @@ {-revision_id} } { - returns a list of lists of the attribute values for one item + 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] + -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] } @@ -576,9 +550,11 @@ 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 @@ -588,13 +564,17 @@ 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] } } @@ -617,10 +597,13 @@ 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"] } @@ -631,15 +614,12 @@ return $values_list } - ad_proc -public get_supertype { {-content_type:required} } { - - returns the direct ancestor of one content type + 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 {}] } @@ -651,7 +631,7 @@ {-attr_value ""} } { - inserts one value for a generic attribute + 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 @@ -668,14 +648,11 @@ {-attribute_id:required} {-attr_value ""} } { - - updates one value for a generic attribute + 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 {}] } @@ -684,12 +661,9 @@ ad_proc -public get_latest_revision { {-item_id:required} } { - - returns the latest revision for one item + 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] } @@ -698,12 +672,9 @@ ad_proc -public get_content { {-revision_id:required} } { - - returns the content of one item + Returns the content of one item @param revision_id The id of the revision to get the data from - - } { return [db_string select_content {}] } @@ -713,12 +684,9 @@ {-node_id} args } { - - returns a context bar relative to classified ads + 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] @@ -729,12 +697,14 @@ 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]] } 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 -r1.1 -r1.2 --- openacs-4/contrib/packages/classified-ads/tcl/widget-procs.tcl 16 Jul 2003 04:52:32 -0000 1.1 +++ openacs-4/contrib/packages/classified-ads/tcl/widget-procs.tcl 19 Jul 2003 01:48:45 -0000 1.2 @@ -49,7 +49,7 @@ } # 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" 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 -r1.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/www/ad-new.tcl 18 Jul 2003 03:16:49 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/www/ad-new.tcl 19 Jul 2003 01:48:45 -0000 1.3 @@ -16,14 +16,23 @@ set package_category_id [classified-ads::categories::package_category_exists_p] set keyword_id $package_category_id set title "Place New Ad (no category)" + } elseif {[string equal [classified-ads::main_keyword_exists_p] $keyword_id]} { ad_return_complaint 1 "
  • No access to the root id" ad_script_abort + } else { # Select info for this category + classified-ads::categories::get -keyword_id $keyword_id -array category_info set category_heading $category_info(heading) set title "Place New $category_heading Ad" + + # If default return_url, make sure we send the user to this category + + if { [string equal $return_url "one-category"] } { + set return_url "one-category?keyword_id=$keyword_id" + } } ad_form -name ad -form { 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 -r1.3 -r1.4 --- openacs-4/contrib/packages/classified-ads/www/admin/ad-new.tcl 18 Jul 2003 03:16:49 -0000 1.3 +++ openacs-4/contrib/packages/classified-ads/www/admin/ad-new.tcl 19 Jul 2003 01:48:45 -0000 1.4 @@ -9,21 +9,30 @@ } { {keyword_id:integer,optional} - {return_url "ads"} + {return_url "categories"} } if {![info exists keyword_id]} { set package_category_id [classified-ads::categories::package_category_exists_p] set keyword_id $package_category_id set title "Place New Ad (no category)" + } elseif {[string equal [classified-ads::main_keyword_exists_p] $keyword_id]} { ad_return_complaint 1 "
  • No access to the root id" ad_script_abort + } else { # Select info for this category + classified-ads::categories::get -keyword_id $keyword_id -array category_info set category_heading $category_info(heading) set title "Place New $category_heading Ad" + + # If default return_url, make sure we send the user to this category + + if { [string equal $return_url "categories"] } { + set return_url "categories?keyword_id=$keyword_id" + } } ad_form -name ad -form { @@ -34,11 +43,9 @@ {value $keyword_id} } {title:text(text) {label "Title"} {html {size 60} {maxlength 1000}} } - {description:text(textarea) {label "Short Description"} - {optional} + {description:text(textarea),optional {label "Short Description"} {html {cols 60 rows 3 wrap soft}} } - {data:text(textarea) {label "Content"} - {optional} + {data:text(textarea),optional {label "Content"} {html {cols 60 rows 10 wrap soft}} } } -new_data { set ad_id [classified-ads::ads::new \ 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 -r1.3 -r1.4 --- openacs-4/contrib/packages/classified-ads/www/admin/categories.adp 18 Jul 2003 02:47:33 -0000 1.3 +++ openacs-4/contrib/packages/classified-ads/www/admin/categories.adp 19 Jul 2003 01:48:45 -0000 1.4 @@ -4,19 +4,19 @@ -

    Categories

    -

    - Create a new - - top-level category - - subcategory - + Create a new top-level category

    + + +
    + + Categories + +
    @@ -40,7 +40,7 @@ @@ -75,7 +75,7 @@ - -
    edit -  | delete +  | delete
     @assigned_ads.title@ +  @assigned_ads.pretty_publish_date@ @@ -115,7 +115,7 @@  @unassigned_ads.title@ +  @unassigned_ads.pretty_publish_date@