Index: openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.tcl 2 Jun 2005 06:39:43 -0000 1.2
+++ openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.tcl 4 Jun 2005 10:05:18 -0000 1.3
@@ -20,6 +20,8 @@
participant_id:optional
{cancel ""}
+
+ user_ids:integer,multiple,optional
} -properties {
} -validate {
} -errors {
@@ -66,6 +68,16 @@
and (case when :patron = ''
then true
else lower(first_names||' '||last_name||' '||email) like '%'||lower(:patron)||'%' end)
+ and not user_id
+ in (select object_id_two
+ from acs_rels
+ where object_id_one = :user_id
+ and rel_type = 'patron_rel')
+ and not user_id
+ in (select object_id_one
+ from acs_rels
+ where object_id_two = :user_id
+ and rel_type = 'patron_rel')
}] 0 {{} 0}]
if { [llength $patron_list] == 1 } {
@@ -99,13 +111,13 @@
}
lappend validate {relationship
- { $relationship != [list [list 0 $community_id]] || ![empty_string_p [template::element::get_value patron relationship_new]] }
+ { ![empty_string_p $relationship] || ![empty_string_p [template::element::get_value patron relationship_new]] }
"Please select a relationship or enter a new one"
}
} else {
ad_form -name "patron" -export { patron } -form {
{patron_id:integer(select),optional {label "Patron"} {options {$patron_list}}
- {help_text "Select a patron from the list. Can't find the patron?
Create an account and return to this form"}
+ {help_text "Select a patron from the list. Can't find the patron?
Create an account and return to this form"}
}
}
@@ -115,15 +127,15 @@
}
lappend validate {relationship
- { $relationship != [list [list 0 $community_id]] || ![empty_string_p [template::element::get_value patron relationship_new]] }
+ { ![empty_string_p $relationship] || ![empty_string_p [template::element::get_value patron relationship_new]] }
"Please select a relationship or enter a new one"
}
}
-ad_form -extend -name "patron" -export { user_id community_id section_id referer } \
+ad_form -extend -name "patron" -export { user_id community_id section_id referer user_ids:multiple } \
-validate $validate \
-form {
- {relationship:text(category),optional,multiple {label "Relationship"} {category_application_id $community_id} {html {size 4}}
+ {relationship:text(category),multiple,optional {label "Relationship"} {category_application_id $community_id} {html {size 4}}
{help_text "Please select one or enter one below if not in the list"}
{assign_single_p t}
}
@@ -153,7 +165,7 @@
}
# Check if no categories were selected
- if { $relationship == [list [list 0 $community_id]] } {
+ if { [empty_string_p $relationship] } {
set relationship ""
# See if user entered a new relationship and add that
@@ -175,13 +187,15 @@
# ad_returnredirect [export_vars -base membership-add { user_id { confirmed_p 1 } community_id section_id referer }]
if { ! [empty_string_p [template::element get_value patron proceed]] } {
- ad_returnredirect [export_vars -base "[apm_package_url_from_key ecommerce]shopping-cart-add" { product_id }]
+ ad_returnredirect [export_vars -base "ecommerce/shopping-cart-add" { product_id { user_id $patron_id } { participant_id $user_id } }]
} else {
ad_returnredirect $referer
}
ad_script_abort
}
+if { ! [info exists user_ids] } {
+
template::list::create \
-name "patrons" \
-multirow "patrons" \
@@ -192,18 +206,52 @@
}
relationship {
label Relationship
+ display_template {
+ @patrons.relationship;noquote@
+ }
}
+ actions {
+ label ""
+ display_template {
+ Select as Patron
+ }
+ }
}
-db_multirow -extend { relationship } patrons patrons {
- select rel_id, person__name(object_id_two) as patron
- from acs_rels
- where rel_type = 'patron_rel'
- and object_id_one = :user_id
+db_multirow -extend { relationship patron_url } patrons patrons {
+ select r.rel_id, u.user_id as patron_id, u.first_names||' '||u.last_name||' ('||u.email||')' as patron, 1 as direction
+ from acs_rels r, dotlrn_users u
+ where r.object_id_two = u.user_id
+ and r.rel_type = 'patron_rel'
+ and r.object_id_one = :user_id
+
+ union
+
+ select r.rel_id, u.user_id as patron_id, u.first_names||' '||u.last_name||' ('||u.email||')' as patron, 2 as direction
+ from acs_rels r, dotlrn_users u
+ where r.object_id_one = u.user_id
+ and r.rel_type = 'patron_rel'
+ and r.object_id_two = :user_id
+ and not r.object_id_one in (select object_id_two
+ from acs_rels r
+ where rel_type = 'patron_rel'
+ and object_id_one = :user_id)
} {
foreach category [category::get_mapped_categories $rel_id] {
lappend relationship [category::get_name $category]
}
set relationship [join $relationship ", "]
+
+ if { $direction == 1 } {
+ set relationship "« $relationship"
+ } else {
+ set relationship "$relationship »"
+ }
+
+ set patron_url [export_vars -base "ecommerce/shopping-cart-add" { product_id { user_id $patron_id } { participant_id $user_id } }]
+}
+
+} else {
+set group_name "[person::name -person_id [lindex $user_ids 0]] to [person::name -person_id [lindex $user_ids [expr [llength $user_ids]-1]]]"
}
\ No newline at end of file