Index: openacs-4/packages/contacts/contacts.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/contacts.info,v diff -u -r1.4 -r1.5 --- openacs-4/packages/contacts/contacts.info 18 May 2005 17:13:20 -0000 1.4 +++ openacs-4/packages/contacts/contacts.info 21 May 2005 21:00:41 -0000 1.5 @@ -10,9 +10,9 @@ Matthew Geddert This application lets you collaboratively view, edit and categorize contacts. - 2004-07-28 - Contacts is an application for managing all those people and or organization you need to keep track of. It has a complete UI for storing, grouping, relating and doing advanced searches for contacts. It also provides emailing and letter mail merge functionality. Each contact can have an arbitrary number of attributes associated with it via the AMS package (Attribute Management System). - + 2005-05-21 + Contacts is an application for managing all those people and or organization you need to keep track of. It has a complete UI for storing and categorizing contacts. Each contact can have an arbitrary number of custom attributes associated with it, including other contacts (i.e. a certain contact "belongs" to a certain organization). It also functions as a service contract provider for attributes related to users in your system + @@ -21,7 +21,7 @@ - + Index: openacs-4/packages/contacts/www/contact-rels-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-rels-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/contact-rels-postgresql.xql 21 May 2005 21:00:41 -0000 1.1 @@ -0,0 +1,45 @@ + + + + + +select primary_object_type + from contact_rel_types + where primary_role = :role_two + + + + + +select acs_rel_type__role_pretty_name(primary_role), + primary_role + from contact_rel_types + where secondary_object_type in ( :contact_type, 'party' ) + group by primary_role + order by upper(acs_rel_type__role_pretty_name(primary_role)) + + + + + +select rel_id, other_name, other_party_id, role_singular, rel_type, object_id_one, object_id_two +from +( + select CASE WHEN object_id_one = :party_id THEN contact__name(object_id_two) ELSE contact__name(object_id_one) END as other_name, + CASE WHEN object_id_one = :party_id THEN object_id_two ELSE object_id_one END as other_party_id, + CASE WHEN object_id_one = :party_id THEN role_two ELSE role_one END as role, + CASE WHEN object_id_one = :party_id THEN acs_rel_type__role_pretty_name(role_two) ELSE acs_rel_type__role_pretty_name(role_one) END as role_singular, + CASE WHEN object_id_one = :party_id THEN acs_rel_type__role_pretty_plural(role_two) ELSE acs_rel_type__role_pretty_name(role_two) END as role_plural, + role_one, role_two, + acs_rels.rel_id, acs_rels.rel_type, object_id_one, object_id_two + from acs_rels, + acs_rel_types + where acs_rels.rel_type = acs_rel_types.rel_type + and ( object_id_one = :party_id or object_id_two = :party_id ) + and acs_rels.rel_type in ( select object_type from acs_object_types where supertype = 'contact_rel') +) rels_temp +[template::list::orderby_clause -orderby -name "relationships"] + + + + Index: openacs-4/packages/contacts/www/contact-rels.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-rels.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/contacts/www/contact-rels.adp 18 May 2005 16:45:50 -0000 1.1 +++ openacs-4/packages/contacts/www/contact-rels.adp 21 May 2005 21:00:41 -0000 1.2 @@ -9,6 +9,8 @@ + +

Existing Relationships

+ - Index: openacs-4/packages/contacts/www/contact-rels.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-rels.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/contacts/www/contact-rels.tcl 18 May 2005 16:45:50 -0000 1.1 +++ openacs-4/packages/contacts/www/contact-rels.tcl 21 May 2005 21:00:41 -0000 1.2 @@ -11,6 +11,7 @@ {buttonsearch:optional} {buttonme:optional} {query ""} + {orderby "role,asc"} } -validate { contact_one_exists -requires {party_id} { if { ![contact::exists_p -party_id $party_id] } { @@ -35,9 +36,8 @@ set pretty_plural_list_name "contacts" -# create rel_type if the role requires a certain object_type if { [exists_and_not_null role_two] } { - set valid_object_types [db_list valid_object_types { select primary_object_type from contact_rel_types where primary_role = :role_two }] + set valid_object_types [db_list get_valid_object_types {}] set person_valid_p 0 set org_valid_p 0 foreach type $valid_object_types { @@ -79,16 +79,8 @@ -if { [exists_and_not_null orderby] } { - if { $orderby == "first_names,asc" } { - set name_order 0 - } else { - set name_order 1 - } -} else { - set name_order 0 -} +set name_order 0 set member_state "approved" set format "normal" @@ -140,6 +132,7 @@ -row_pretty_plural "$pretty_plural_list_name found in search, please try again or add a new contact" \ -checkbox_name checkbox \ -selected_format ${format} \ + -orderby_name "order_search" \ -key party_id \ -elements { type { @@ -193,10 +186,8 @@ } } -#ns_log notice [db_map contacts_select] set original_party_id $party_id -#ad_return_error "ERROR" [db_map dbqd.contacts.www.index.contacts_select] db_multirow -extend {map_url} -unclobber contacts dbqd.contacts.www.index.contacts_select {} { set map_url [export_vars -base "relationship-add" -url {{party_one $original_party_id} {party_two $party_id} {role_two $role_two}}] } @@ -205,13 +196,7 @@ -set rel_options [db_list_of_lists get_rels { - select acs_rel_type__role_pretty_name(primary_role), - primary_role - from contact_rel_types - where secondary_object_type in ( :contact_type, 'party' ) - order by upper(acs_rel_type__role_pretty_name(primary_role)) -}] +set rel_options [db_list_of_lists get_rels {}] set rel_options "{{-Select One-} {}} $rel_options" @@ -230,3 +215,77 @@ } -on_submit { } -after_submit { } + + + + + + + + + + +template::list::create \ + -html {width 100%} \ + -name "relationships" \ + -multirow "relationships" \ + -row_pretty_plural "relationships" \ + -selected_format "normal" \ + -elements { + role { + label "Role" + display_col role_singular + } + other_name { + label "Contact" + display_col other_name + link_url_eval $contact_url + } + details { + label "Details" + } + actions { + label "Actions" + display_template { + Delete + Edit Details + } + } + } -filters { + party_id {} + } -orderby { + other_name { + label "Contact" + orderby_asc "CASE WHEN object_id_one = :party_id THEN upper(contact__name(object_id_two)) ELSE upper(contact__name(object_id_one)) END asc, upper(role_singular) asc" + orderby_desc "CASE WHEN object_id_one = :party_id THEN upper(contact__name(object_id_two)) ELSE upper(contact__name(object_id_one)) END desc, upper(role_singular) asc" + } + role { + label "Role" + orderby_asc "upper(role_singular) asc, CASE WHEN object_id_one = :party_id THEN upper(contact__name(object_id_two)) ELSE upper(contact__name(object_id_one)) END asc" + orderby_desc "upper(role_singular) desc, CASE WHEN object_id_one = :party_id THEN upper(contact__name(object_id_two)) ELSE upper(contact__name(object_id_one)) END asc" + } + default_value role,asc + } -formats { + normal { + label "Table" + layout table + row { + role {} + other_name {} + details {} + actions {} + } + } + } + + +set package_id [ad_conn package_id] +set return_url [export_vars -base "[ad_conn package_url]contact-rels" -url {party_id}] +db_multirow -unclobber -extend {contact_url rel_add_edit_url rel_delete_url details} relationships get_relationships "" { + set contact_url [contact::url -party_id $other_party_id] + set list_exists_p [ams::list::exists_p -package_key "contacts" -object_type ${rel_type} -list_name ${package_id}] + if { $list_exists_p } { + set rel_add_edit_url [export_vars -base "relationship-ae" -url {rel_type object_id_one object_id_two party_id}] + } + set rel_delete_url [export_vars -base "relationship-delete" -url {rel_id party_id return_url}] +} Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/contacts/www/map-delete.tcl'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/contacts/www/relationship-add-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/relationship-add-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/relationship-add-postgresql.xql 21 May 2005 21:00:41 -0000 1.1 @@ -0,0 +1,40 @@ + + + + + +select 1 + from contact_rel_types + where primary_role = :role + limit 1 + + + + + +select acs_rel_type__role_pretty_name(:role_two) as secondary_role_pretty + + + + + +select rel_type, + primary_role, + acs_rel_type__role_pretty_name(primary_role) as primary_role_pretty + from contact_rel_types + where secondary_role = :role_two + and secondary_object_type in (:contact_type_two,'party') + and primary_object_type in (:contact_type_one,'party') + + + + + +select role_one as db_role_one, + role_two as db_role_two + from acs_rel_types + where rel_type = :rel_type + + + + Index: openacs-4/packages/contacts/www/relationship-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/relationship-add.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/contacts/www/relationship-add.tcl 18 May 2005 16:45:50 -0000 1.1 +++ openacs-4/packages/contacts/www/relationship-add.tcl 21 May 2005 21:00:41 -0000 1.2 @@ -1,17 +1,15 @@ ad_page_contract { - List and manage contacts. + Add a contact relationship @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 + @creation-date 2004-05-15 @cvs-id $Id$ } { {party_one:integer,notnull} {role_one:optional} {party_two:integer,notnull} {role_two:notnull} {rel_type:optional} - {comment ""} - {comment_format "text/plain"} {return_url ""} } -validate { contact_one_exists -requires {party_one} { @@ -25,12 +23,14 @@ } } role_one_exists -requires {role_one} { - if { ![db_0or1row role_exists {select 1 from contact_rel_types where primary_role = :role_one}] } { + set role $role_one + if { ![db_0or1row role_exists_p {}] } { ad_complain "The first role specified does not exist" } } role_two_exists -requires {role_two} { - if { ![db_0or1row role_exists {select 1 from contact_rel_types where primary_role = :role_two}] } { + set role $role_two + if { ![db_0or1row role_exists_p {}] } { ad_complain "The second role specified does not exist" } } @@ -41,17 +41,9 @@ set contact_name_two [contact::name -party_id $party_two] set contact_type_one [contact::type -party_id $party_id] set contact_type_two [contact::type -party_id $party_two] -set secondary_role_pretty [db_string getit { select acs_rel_type__role_pretty_name(:role_two) as secondary_role_pretty }] +set secondary_role_pretty [db_string get_secondary_role_pretty {}] if { ![exists_and_not_null rel_type] } { - set options_list [db_list_of_lists get_rel_type { - select rel_type, - primary_role, - acs_rel_type__role_pretty_name(primary_role) as primary_role_pretty - from contact_rel_types - where secondary_role = :role_two - and secondary_object_type in (:contact_type_two,'party') - and primary_object_type in (:contact_type_one,'party') - }] + set options_list [db_list_of_lists get_rel_types {}] set options_length [llength $options_list] if { $options_length == "0" } { ad_return_error "Error" "There was a problem with your input. this type of relationship cannot exist." @@ -74,12 +66,7 @@ if { [exists_and_not_null rel_type] } { - db_1row get_roles { - select role_one as db_role_one, - role_two as db_role_two - from acs_rel_types - where rel_type = :rel_type - } + db_1row get_roles {} if { $db_role_one == $role_one } { set object_id_one $party_one @@ -88,41 +75,10 @@ set object_id_one $party_two set object_id_two $party_one } - set existing_rel_id [db_string rel_exists { - select rel_id - from acs_rels - where rel_type = :rel_type - and object_id_one = :object_id_one - and object_id_two = :object_id_two - } -default {}] - - if { [empty_string_p $existing_rel_id] } { - set rel_id {} - set context_id {} - set creation_user [ad_conn user_id] - set creation_ip [ad_conn peeraddr] - set rel_id [db_exec_plsql create_rel { - select acs_rel__new ( - :rel_id, - :rel_type, - :object_id_one, - :object_id_two, - :context_id, - :creation_user, - :creation_ip - ) - }] - db_dml insert_rel { - insert into contact_rels - (rel_id,comment,comment_format) - values - (:rel_id,:comment,:comment_format) - } - } if { ![exists_and_not_null return_url] } { set return_url [export_vars -base "contact-rels" -url {{party_id $party_one}}] - ad_returnredirect -message "Relationship Added" $return_url } + ad_returnredirect [export_vars -base "relationship-ae" -url {object_id_one object_id_two rel_type return_url {party_id $party_one}}] ad_script_abort } Index: openacs-4/packages/contacts/www/relationship-ae-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/relationship-ae-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/relationship-ae-postgresql.xql 21 May 2005 21:00:41 -0000 1.1 @@ -0,0 +1,46 @@ + + + + + +select rel_id + from acs_rels + where rel_type = :rel_type + and ( object_id_one = :object_id_one and object_id_two = :object_id_two ) + + + + + +select rel_id + from acs_rels + where rel_type = :rel_type + and object_id_one = :object_id_one + and object_id_two = :object_id_two + + + + + +select acs_rel__new ( + :rel_id, + :rel_type, + :object_id_one, + :object_id_two, + :context_id, + :creation_user, + :creation_ip + ) + + + + + +insert into contact_rels + (rel_id) +values + (:rel_id) + + + + Index: openacs-4/packages/contacts/www/relationship-ae.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/relationship-ae.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/relationship-ae.adp 21 May 2005 21:00:41 -0000 1.1 @@ -0,0 +1,5 @@ + +@party_id@ + + + Index: openacs-4/packages/contacts/www/relationship-ae.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/relationship-ae.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/relationship-ae.tcl 21 May 2005 21:00:41 -0000 1.1 @@ -0,0 +1,104 @@ +ad_page_contract { + Add a Relationship and Manage Relationship Details + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-05-21 + @cvs-id $Id: relationship-ae.tcl,v 1.1 2005/05/21 21:00:41 matthewg Exp $ +} { + {object_id_one:integer,notnull} + {object_id_two:integer,notnull} + {party_id:integer,notnull} + {rel_type:notnull} + {return_url ""} +} -validate { + contact_one_exists -requires {object_id_one} { + if { ![contact::exists_p -party_id $object_id_one] } { + ad_complain "The first contact specified does not exist" + } + } + contact_two_exists -requires {object_id_two} { + if { ![contact::exists_p -party_id $object_id_two] } { + ad_complain "The second contact specified does not exist" + } + } + party_id_valid -requires {object_id_one object_id_two party_id} { + if { $party_id != $object_id_one && $party_id != $object_id_two } { + ad_complain "The contact specified is not one of the contacts in this relationship" + } + } +} + +set rel_id_from_db [db_string get_rel_id {} -default {}] +if { [exists_and_not_null rel_id_from_db] } { + set rel_id $rel_id_from_db +} +set package_id [ad_conn package_id] +set list_exists_p [ams::list::exists_p -package_key "contacts" -object_type ${rel_type} -list_name ${package_id}] + +if { $list_exists_p } { + + set form_elements { + rel_id:key + {object_id_one:integer(hidden)} + {object_id_two:integer(hidden)} + {party_id:integer(hidden)} + {rel_type:text(hidden)} + {return_url:text(hidden),optional} + } + append form_elements [ams::ad_form::elements -package_key "contacts" -object_type $rel_type -list_name [ad_conn package_id]] + + ad_form -name rel_form \ + -mode "edit" \ + -form $form_elements \ + -on_request { + } -new_request { + } -edit_request { + ams::ad_form::values -form_name "rel_form" -package_key "contacts" -object_type $rel_type -list_name [ad_conn package_id] -object_id $rel_id + } -on_submit { + } -new_data { + } -edit_data { + } -after_submit { + } + + +} + + + + + + + + + + +if { !$list_exists_p || [template::form::is_valid "rel_form"] } { + + set existing_rel_id [db_string rel_exists_p {} -default {}] + + if { [empty_string_p $existing_rel_id] } { + set rel_id {} + set context_id {} + set creation_user [ad_conn user_id] + set creation_ip [ad_conn peeraddr] + set rel_id [db_exec_plsql create_rel {}] + db_dml insert_contact_rel {} + util_user_message -message "Relationship Added" + } else { + util_user_message -message "Relationship Updated" + } + if { $list_exists_p } { + ams::ad_form::save -package_key "contacts" \ + -object_type $rel_type \ + -list_name [ad_conn package_id] \ + -form_name "rel_form" \ + -object_id $rel_id + } + if { ![exists_and_not_null return_url] } { + set return_url [export_vars -base "contact-rels" -url {{party_id $party_id}}] + } + ad_returnredirect $return_url + ad_script_abort +} + +ad_return_template Index: openacs-4/packages/contacts/www/relationship-delete-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/relationship-delete-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/relationship-delete-postgresql.xql 21 May 2005 21:00:41 -0000 1.1 @@ -0,0 +1,13 @@ + + + + + +select acs_object__delete(rel_id) + from acs_rels + where ( object_id_one = :party_id or object_id_two = :party_id ) + and rel_id = :rel_id + + + + Index: openacs-4/packages/contacts/www/relationship-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/relationship-delete.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/contacts/www/relationship-delete.tcl 21 May 2005 21:00:41 -0000 1.1 @@ -0,0 +1,26 @@ +ad_page_contract { + List and manage contacts. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: relationship-delete.tcl,v 1.1 2005/05/21 21:00:41 matthewg Exp $ +} { + {party_id:integer,notnull} + {rel_id:integer,notnull} + {return_url ""} +} -validate { + valid_party -requires {party_id} { + if { ![contact::exists_p -party_id $party_id] } { + ad_complain "The contact specified does not exist" + } + } +} + +ams::object_delete -object_id $rel_id +db_1row delete_rel {} + +if { ![exists_and_not_null return_url] } { + set return_url [export_vars -base "contact-rels" -url {party_id}] +} +ad_returnredirect -message "Relationship Deleted" $return_url +ad_script_abort Index: openacs-4/packages/contacts/www/admin/relationships.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/admin/relationships.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/contacts/www/admin/relationships.adp 18 May 2005 16:45:50 -0000 1.1 +++ openacs-4/packages/contacts/www/admin/relationships.adp 21 May 2005 21:00:41 -0000 1.2 @@ -24,7 +24,7 @@
    -
  • @rel_types.primary_role_pretty@ -> @rel_types.secondary_role_pretty@
  • +
  • @rel_types.primary_role_pretty@ -> @rel_types.secondary_role_pretty@ Attributes
Index: openacs-4/packages/contacts/www/admin/relationships.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/admin/relationships.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/contacts/www/admin/relationships.tcl 18 May 2005 16:45:50 -0000 1.1 +++ openacs-4/packages/contacts/www/admin/relationships.tcl 21 May 2005 21:00:41 -0000 1.2 @@ -19,17 +19,19 @@ set context [list $title] set package_id [ad_conn package_id] - +set url [ad_conn url] # Select out all relationship types, excluding the parent type names 'relationship' # Count up the number of relations that exists for each type. -db_multirow -extend { primary_type_pretty secondary_type_pretty } rel_types get_rels { +db_multirow -extend { primary_type_pretty secondary_type_pretty rel_form_url } rel_types get_rels { select CASE WHEN primary_object_type = 'party' THEN '1' WHEN primary_object_type = 'person' THEN '2' ELSE '3' END as sort_one, CASE WHEN secondary_object_type = 'party' THEN '2' WHEN secondary_object_type = 'person' THEN '3' ELSE '4' END as sort_two, acs_rel_type__role_pretty_name(primary_role) as primary_role_pretty, acs_rel_type__role_pretty_name(secondary_role) as secondary_role_pretty, - * - from contact_rel_types + contact_rel_types.*, + acs_object_types.pretty_name + from contact_rel_types, acs_object_types + where contact_rel_types.rel_type = acs_object_types.object_type order by sort_one, sort_two, primary_role_pretty } { @@ -43,6 +45,13 @@ organization { set secondary_type_pretty "Organization" } person { set secondary_type_pretty "Person" } } + set rel_form_url [ams::list::url \ + -package_key "contacts" \ + -object_type ${rel_type} \ + -list_name ${package_id} \ + -pretty_name ${pretty_name} \ + -return_url ${url} \ + -return_url_label "Return to \"$title\""] } ad_return_template