Index: openacs-4/packages/contacts/catalog/contacts.en_US.ISO-8859-1.xml
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/catalog/contacts.en_US.ISO-8859-1.xml,v
diff -u -r1.92 -r1.93
--- openacs-4/packages/contacts/catalog/contacts.en_US.ISO-8859-1.xml 14 Dec 2006 09:19:30 -0000 1.92
+++ openacs-4/packages/contacts/catalog/contacts.en_US.ISO-8859-1.xml 16 Dec 2006 11:27:19 -0000 1.93
@@ -22,16 +22,17 @@
Add complaint to
Add Condition
Add Email Message
+ Add
Add Group
Add Letter Message
Add List
Add Message
Add New
Add new %object_type% selected groups
Add new owner
- Add Organization
+ Organization
Add Owner
- Add Person
+ Person
Add Relationship
Amount of relationships to be deleted
Amount of relationships to be deleted
@@ -50,7 +51,7 @@
Address
Admin
Administer Contacts
- Advanced Search
+ Search
Advanced Searches
Aggregate
Aggregate by
Index: openacs-4/packages/contacts/lib/contacts-master.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/lib/contacts-master.tcl,v
diff -u -r1.13 -r1.14
--- openacs-4/packages/contacts/lib/contacts-master.tcl 4 Mar 2006 22:58:41 -0000 1.13
+++ openacs-4/packages/contacts/lib/contacts-master.tcl 16 Dec 2006 11:27:19 -0000 1.14
@@ -16,6 +16,9 @@
lappend link_list "[_ contacts.Contacts]"
if { ![parameter::get -boolean -parameter "ForceSearchBeforeAdd" -default "0"] } {
+ lappend link_list "${package_url}add/employee"
+ lappend link_list "[_ contacts.Add_Employee]"
+
lappend link_list "${package_url}add/person"
lappend link_list "[_ contacts.Add_Person]"
Index: openacs-4/packages/contacts/lib/search-contact.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/lib/search-contact.tcl,v
diff -u -r1.4 -r1.5
--- openacs-4/packages/contacts/lib/search-contact.tcl 13 Mar 2006 14:27:07 -0000 1.4
+++ openacs-4/packages/contacts/lib/search-contact.tcl 16 Dec 2006 11:27:19 -0000 1.5
@@ -36,4 +36,4 @@
{return_url:text(hidden) {value $return_url}}
} -on_submit {
ad_returnredirect [export_vars -base "$contacts_url" -url {{query $keyword}}]
-} -has_submit {1}
\ No newline at end of file
+} -has_submit {1}
Index: openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl,v
diff -u -r1.52 -r1.53
--- openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl 14 Dec 2006 09:12:12 -0000 1.52
+++ openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl 16 Dec 2006 11:27:20 -0000 1.53
@@ -1,3 +1,4 @@
+
# packages/contacts/tcl/contacts-callback-procs.tcl
ad_library {
@@ -215,9 +216,14 @@
ad_proc -public -callback contact::special_attributes::ad_form_save {
{-party_id:required}
{-form:required}
+ {-object_type ""}
} {
This callback is executed first in the new_data or edit_data ad_from
blocks when creating or saving a contacts information
+
+ @party_id Party ID for which the elements are saved
+ @form Name of the form
+ @object_type Object Type of the party
} -
ad_proc -public -callback contact::special_attributes::ad_form_values -impl contacts {
@@ -1134,7 +1140,7 @@
# This is an example of how you can extend the entry forms.
#
-ad_proc -public -callback contact::contact_form -impl wieners {
+ad_proc -public -callback contact::contact_form -impl contacts {
{-package_id:required}
{-form:required}
{-object_type:required}
@@ -1166,10 +1172,12 @@
if { ![exists_and_not_null locale] } {
set locale [lang::system::site_wide_locale]
}
-
- ad_form -extend -name $form -form {
- {locale:text(select),optional {label "[_ contacts.preferred_locale]"} {options $list_of_locales} {value $locale}}
- }
+
+ if {![template::element::exists $form "locale"]} {
+ ad_form -extend -name $form -form {
+ {locale:text(select),optional {label "[_ contacts.preferred_locale]"} {options $list_of_locales} {value $locale}}
+ }
+ }
}
ad_proc -public -callback contact::special_attributes::ad_form_save -impl contacts {
Index: openacs-4/packages/contacts/www/contact-add.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/contact-add.tcl,v
diff -u -r1.52 -r1.53
--- openacs-4/packages/contacts/www/contact-add.tcl 8 Nov 2006 18:31:29 -0000 1.52
+++ openacs-4/packages/contacts/www/contact-add.tcl 16 Dec 2006 11:27:20 -0000 1.53
@@ -6,22 +6,21 @@
} {
- {object_type "person"}
+ {object_type "employee"}
{group_ids ""}
{rel_type ""}
{role_two ""}
{object_id_two ""}
} -validate {
valid_type -requires {object_type} {
- if { [lsearch [list organization person] $object_type] < 0 } {
+ if { [lsearch [list organization person employee] $object_type] < 0 } {
ad_complain "[_ contacts.lt_You_have_not_specifie]"
}
}
}
set master_src [parameter::get -parameter "ContactsMaster"]
set default_group [contacts::default_group]
-
set group_list [concat [list [list [_ contacts.All_Contacts] $default_group "0"]] [contact::groups]]
if {[empty_string_p $group_ids] && [llength $group_list] > 1} {
@@ -35,10 +34,12 @@
set path_info [ad_conn path_info]
-if { $path_info == "add/person" } {
+if { $path_info eq "add/person" } {
set object_type "person"
-} elseif { $path_info == "add/organization" } {
+} elseif { $path_info eq "add/organization" } {
set object_type "organization"
+} elseif { $path_info eq "add/employee" } {
+ set object_type "employee"
}
set package_id [ad_conn package_id]
@@ -80,7 +81,7 @@
# Adding the list_name to get the elements in the form
lappend list_names [list ${package_id}__${group_id}]
-
+
# Add the category widget(s)
set element_name "category_ids$group_id"
if {$group_id < 0} {
@@ -97,11 +98,24 @@
}
-set form_definition [ams::ad_form::elements \
- -package_key "contacts" \
- -object_type $object_type \
- -list_names $list_names]
+if {$object_type eq "employee"} {
+
+ # Make sure the relationship is set correctly
+ set rel_type "contact_rels_employment"
+ set role_two ""
+
+ # Employee is like adding a business card. First company information, then person information
+ set form_definition [ams::ad_form::elements \
+ -package_key "contacts" \
+ -object_types "[list person organization]" \
+ -list_names $list_names]
+} else {
+ set form_definition [ams::ad_form::elements \
+ -package_key "contacts" \
+ -object_type $object_type \
+ -list_names $list_names]
+}
if { [parameter::get -boolean -package_id $package_id -parameter "ContactPrivacyEnabledP" -default "0"] } {
set privacy_setting_options [list]
@@ -113,7 +127,7 @@
lappend privacy_setting_options [list [_ contacts.Do_not_email] email_p]
lappend privacy_setting_options [list [_ contacts.Do_not_mail] mail_p]
lappend privacy_setting_options [list [_ contacts.Do_not_phone] phone_p]
-
+
lappend form_definition [list contact_privacy_settings:boolean(checkbox),multiple,optional \
[list label [_ contacts.Privacy_Settings]] \
[list options $privacy_setting_options] \
@@ -122,8 +136,6 @@
-#ad_return_error "$object_type" "$list_names :: $form_definition"
-
# Creating the form
ad_form -extend -name party_ae -form $form_definition
@@ -145,25 +157,33 @@
# Append the option to create a user who get's a welcome message send
# Furthermore set the title.
-if { $object_type == "person" } {
+if { $object_type eq "person" } {
set title "[_ contacts.Add_a_Person]"
-} else {
+} elseif { $object_type eq "organization"} {
set title "[_ contacts.Add_an_Organization]"
+} else {
+ set title "[_ contacts.Add_an_Employee]"
}
set context [list $title]
-callback contact::contact_form -package_id $package_id -form party_ae -object_type $object_type -group_ids $group_ids -rel_type $rel_type
+if {$object_type eq "employee"} {
+ callback contact::contact_form -package_id $package_id -form party_ae -object_type "organization" -group_ids $group_ids -rel_type $rel_type
+ callback contact::contact_form -package_id $package_id -form party_ae -object_type "person" -group_ids $group_ids -rel_type $rel_type
+} else {
+ callback contact::contact_form -package_id $package_id -form party_ae -object_type $object_type -group_ids $group_ids -rel_type $rel_type
+}
ad_form -extend -name party_ae \
-on_request {
-
- if { $object_type == "person" } {
+
+ if { $object_type eq "person" } {
set required_attributes [list first_names last_name email]
- } else {
+ } elseif {$object_type eq "organization"} {
set required_attributes [list name]
+ } else {
+ set required_attributes [list first_names last_name email name]
}
-
set missing_elements [list]
foreach attribute $required_attributes {
if { [string is false [template::element::exists party_ae $attribute]] } {
@@ -189,132 +209,153 @@
}
}
} -on_submit {
-
+
# for orgs name needs to be unique
# for users username needs to be unique
# for all of them email needs to be unique
-
+
if { $object_type == "person" } {
if { ![exists_and_not_null first_names] } {
template::element::set_error party_ae first_names "[_ contacts.lt_First_Names_is_requir]"
}
if { ![exists_and_not_null last_name] } {
template::element::set_error party_ae last_name "[_ contacts.lt_Last_Name_is_required]"
}
+ } elseif {$object_type eq "organization"} {
+ if { ![exists_and_not_null name] } {
+ template::element::set_error party_ae name "[_ contacts.Name_is_required]"
+ }
} else {
if { ![exists_and_not_null name] } {
template::element::set_error party_ae name "[_ contacts.Name_is_required]"
- } else {
- # We (cognovis) got rid of the unique constraints on organization name as this does not make any sense
- # An organization could be in multiple locations and independend units of the same large organization could be
- # different organizations / customers. After all we deal with seperate business units and these should be treated seperately.
-
-# set other_organization_id [organization::get_by_name -name $name]
-# if { ![empty_string_p $other_organization_id] } {
-# set another_organization [contact::link -party_id $other_organization_id]
-# template::element::set_error party_ae name "[_ contacts.lt_-another_organization-_already_uses_this_name]"
-# }
- }
+ }
+ if { ![exists_and_not_null first_names] } {
+ template::element::set_error party_ae first_names "[_ contacts.lt_First_Names_is_requir]"
+ }
+ if { ![exists_and_not_null last_name] } {
+ template::element::set_error party_ae last_name "[_ contacts.lt_Last_Name_is_required]"
+ }
}
- if { [exists_and_not_null email] } {
- set other_party_id [party::get_by_email -email $email]
- if { ![empty_string_p $other_party_id] } {
- set another_contact [contact::link -party_id $other_party_id]
+ if { [exists_and_not_null email] } {
+ set other_party_id [party::get_by_email -email $email]
+ if { ![empty_string_p $other_party_id] } {
+ set another_contact [contact::link -party_id $other_party_id]
template::element::set_error party_ae email "[_ contacts.lt_-another_contact-_already_uses_this_email]"
}
}
-
+
if { ![template::form::is_valid party_ae] } {
break
}
} -new_data {
- if { $object_type == "person" } {
-
- if { ![exists_and_not_null url] } {
- set url ""
- }
+ if {$object_type eq "employee"} {
+ set object_types [list person organization]
+ set person_party_id $party_id
+ set organization_party_id ""
+ } else {
+ set object_types $object_type
+ set ${object_type}_party_id $party_id
+ }
+ set orig_object_type $object_type
- # Initialize Person
- template::form create add_party
- template::element create add_party email -value "$email"
- template::element create add_party first_names -value "$first_names"
- template::element create add_party last_name -value "$last_name"
- template::element create add_party url -value "$url"
- set party_id [party::new -party_id $party_id -form_id add_party person]
- # party::new does not correctly save email address
- party::update -party_id $party_id -email $email -url $url
-
- # in order to create a user we need a valid unique username (i.e. their email address).
- # the on_submit block has already validated that this is in fact a valid and unique
- # email address which will serve as their username
- callback contact::person_add -package_id $package_id -person_id $party_id
+ foreach object_type $object_types {
+ if { $object_type eq "person" } {
+
+ if { ![exists_and_not_null url] } {
+ set url ""
+ }
+
+ # Initialize Person
+ template::form create add_party
+ template::element create add_party email -value "$email"
+ template::element create add_party first_names -value "$first_names"
+ template::element create add_party last_name -value "$last_name"
+ template::element create add_party url -value "$url"
+ set person_party_id [party::new -party_id $person_party_id -form_id add_party person]
- # Add the new categories and enter the Party into the groups
- set cat_ids [list]
-
- foreach group_id $group_ids {
- group::add_member \
- -group_id $group_id \
- -user_id $party_id \
- -rel_type "membership_rel"
+ # party::new does not correctly save email address
+ party::update -party_id $person_party_id -email $email -url $url
+
+ # in order to create a user we need a valid unique username (i.e. their email address).
+ # the on_submit block has already validated that this is in fact a valid and unique
+ # email address which will serve as their username
+ callback contact::person_add -package_id $package_id -person_id $person_party_id
- set element_name "category_ids$group_id"
- if {$group_id < 0} {
- set element_name "category_ids[expr - $group_id]"
+ # Add the new categories and enter the Party into the groups
+ set cat_ids [list]
+
+ foreach group_id $group_ids {
+ group::add_member \
+ -group_id $group_id \
+ -user_id $person_party_id \
+ -rel_type "membership_rel"
+
+ set element_name "category_ids$group_id"
+ if {$group_id < 0} {
+ set element_name "category_ids[expr - $group_id]"
+ }
+
+ set cat_ids [concat $cat_ids \
+ [category::ad_form::get_categories \
+ -container_object_id $group_id \
+ -element_name $element_name]]
}
- set cat_ids [concat $cat_ids \
- [category::ad_form::get_categories \
- -container_object_id $group_id \
- -element_name $element_name]]
+ category::map_object -remove_old -object_id $person_party_id $cat_ids
+ callback contact::special_attributes::ad_form_save -party_id $person_party_id -form "party_ae" -object_type $object_type
+ } else {
+
+ # Initialize Party Entry for organization
+ set organization_party_id [organization::new -organization_id $organization_party_id -name $name]
+
+ foreach group_id $group_ids {
+ if {![empty_string_p $group_id]} {
+
+ # relation-add does not work as there is no
+ # special procedure for organizations at the moment.
+ set rel_id [db_string insert_rels { select acs_rel__new (NULL::integer,'organization_rel',:group_id,:organization_party_id,NULL,:user_id,:peeraddr) as org_rel_id }]
+ db_dml insert_state { insert into membership_rels (rel_id,member_state) values (:rel_id,'approved') }
+ }
+ }
+
+ callback contact::special_attributes::ad_form_save -party_id $organization_party_id -form "party_ae" -object_type $object_type
+ callback contact::organization_new -package_id $package_id -contact_id $organization_party_id -name $name
}
-
- category::map_object -remove_old -object_id $party_id $cat_ids
-
+
+ # Save the contact information
+ # No clue why this is not part of the db_transaction though ....
-
- } else {
-
- # Initialize Party Entry for organization
- set party_id [organization::new -organization_id $party_id -name $name]
-
+ set revision_id [contact::revision::new -party_id [set ${object_type}_party_id]]
foreach group_id $group_ids {
- if {![empty_string_p $group_id]} {
+ ams::ad_form::save -package_key "contacts" \
+ -object_type $object_type \
+ -list_name "${package_id}__${group_id}" \
+ -form_name "party_ae" \
+ -object_id $revision_id
+
+ callback contact::${object_type}_new_group -${object_type}_id [set ${object_type}_party_id] -group_id $group_id
- # relation-add does not work as there is no
- # special procedure for organizations at the moment.
- set rel_id [db_string insert_rels { select acs_rel__new (NULL::integer,'organization_rel',:group_id,:party_id,NULL,:user_id,:peeraddr) as org_rel_id }]
- db_dml insert_state { insert into membership_rels (rel_id,member_state) values (:rel_id,'approved') }
+ # execute group specific callbacks
+ group::get -group_id $group_id -array group_array
+ set group_name ${group_array(group_name)}
+ regsub -all " " $group_name "_" group_name
+ regsub -all {[^-a-zA-Z0-9_]} $group_name "" group_name
+
+ if {[info exists contact::${object_type}_${group_array(group_name)}_new]} {
+ callback contact::${object_type}_${group_array(group_name)}_new -package_id $package_id -contact_id [set ${object_type}_party_id]
}
}
-
- callback contact::organization_new -package_id $package_id -contact_id $party_id -name $name
}
-
- # Save the contact information
- # No clue why this is not part of the db_transaction though ....
- callback contact::special_attributes::ad_form_save -party_id $party_id -form "party_ae"
- set revision_id [contact::revision::new -party_id $party_id]
- foreach group_id $group_ids {
- ams::ad_form::save -package_key "contacts" \
- -object_type $object_type \
- -list_name "${package_id}__${group_id}" \
- -form_name "party_ae" \
- -object_id $revision_id
- callback contact::${object_type}_new_group -${object_type}_id $party_id -group_id $group_id
- # execute group specific callbacks
- group::get -group_id $group_id -array group_array
- set group_name ${group_array(group_name)}
- regsub -all " " $group_name "_" group_name
- regsub -all {[^-a-zA-Z0-9_]} $group_name "" group_name
-
- if {[info exists contact::${object_type}_${group_array(group_name)}_new]} {
- callback contact::${object_type}_${group_array(group_name)}_new -package_id $package_id -contact_id $party_id
- }
+ # For employees we need to correctly save the relationship
+ if {$orig_object_type eq "employee"} {
+ set rel_type "contact_rels_employment"
+ set party_id $person_party_id
+ set object_id_two $organization_party_id
+ set object_type "person"
}
# Insert the relationship
@@ -385,8 +426,9 @@
contact::search::flush_results_counts
callback contact::contact_form_after_submit -party_id $party_id -package_id $package_id -object_type $object_type -form "party_ae"
- # Now we have the organization or person created. Redirect as AMS can be saved in the background.
- #the formbutton does not work. No clue how to fix it.
+ if {$orig_object_type eq "employee"} {
+ callback contact::contact_form_after_submit -party_id $organization_party_id -package_id $package_id -object_type organization -form "party_ae"
+ }
if {[empty_string_p $object_id_two]} {
ad_returnredirect [contact::url -party_id $party_id]
} else {
Index: openacs-4/packages/contacts/www/index.vuh
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/index.vuh,v
diff -u -r1.18 -r1.19
--- openacs-4/packages/contacts/www/index.vuh 28 Nov 2006 17:33:41 -0000 1.18
+++ openacs-4/packages/contacts/www/index.vuh 16 Dec 2006 11:27:20 -0000 1.19
@@ -93,6 +93,12 @@
}
rp_internal_redirect contact-add
}
+ "add/employee" {
+ if { ![ns_queryexists object_type]} {
+ rp_form_put object_type "employee"
+ }
+ rp_internal_redirect contact-add
+ }
lists {
rp_internal_redirect /packages/contacts/lib/lists
}