Index: openacs-4/packages/dotlrn-ecommerce/dotlrn-ecommerce.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/dotlrn-ecommerce.info,v diff -u -r1.1 -r1.2 --- openacs-4/packages/dotlrn-ecommerce/dotlrn-ecommerce.info 31 May 2005 22:04:53 -0000 1.1 +++ openacs-4/packages/dotlrn-ecommerce/dotlrn-ecommerce.info 2 Jun 2005 06:39:41 -0000 1.2 @@ -14,6 +14,9 @@ Package to tie the dotLRN, Ecommerce, Assessments and dotLRN Catalog packages together. Initially intended for the MOS and MGH projects, the goal is to create a reusable module for similar projects. + + + Index: openacs-4/packages/dotlrn-ecommerce/lib/user-info.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/lib/user-info.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn-ecommerce/lib/user-info.adp 2 Jun 2005 06:39:41 -0000 1.1 @@ -0,0 +1,6 @@ +@focus;noquote@ + + + +

#acs-subsite.Notice# #acs-subsite.Elements_not_editable#

+
\ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/lib/user-info.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/lib/user-info.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn-ecommerce/lib/user-info.tcl 2 Jun 2005 06:39:41 -0000 1.1 @@ -0,0 +1,247 @@ +# +# Expects: +# user_id:optional +# return_url:optional +# edit_p:optional +# message:optional +# + +if { ! [empty_string_p $cancel] } { + ad_returnredirect $return_url + ad_script_abort +} + +auth::require_login -account_status closed + +if { ![exists_and_not_null user_id] } { + set user_id [ad_conn untrusted_user_id] +} elseif { $user_id != [auth::get_user_id -account_status closed] } { + permission::require_permission -object_id $user_id -privilege admin +} + +if { ![exists_and_not_null return_url] } { + set return_url [ad_conn url] +} + + +set action_url "[subsite::get_element -element url]user/basic-info-update" + +acs_user::get -user_id $user_id -array user -include_bio + +set authority_name [auth::authority::get_element -authority_id $user(authority_id) -element pretty_name] + +set form_elms { authority_id username first_names last_name email screen_name url bio } +foreach elm $form_elms { + set elm_mode($elm) {} +} +set read_only_elements [auth::sync::get_sync_elements -authority_id $user(authority_id)] +set read_only_notice_p [expr [llength $read_only_elements] > 0] +if { ![acs_user::site_wide_admin_p] } { + lappend read_only_elements authority_id username +} +foreach elm $read_only_elements { + set elm_mode($elm) {display} +} +set first_element {} +foreach elm $form_elms { + if { [empty_string_p $elm_mode($elm)] && (![string equal $elm "username"] && [auth::UseEmailForLoginP]) } { + set first_element $elm + break + } +} +set focus "user_info.$first_element" +set edit_mode_p [expr ![empty_string_p [form::get_action user_info]]] + +set form_mode display +if { [exists_and_equal edit_p 1] } { + set form_mode edit +} + +ad_form -name user_info -cancel_url $return_url -mode $form_mode -export {section_id community_id} -form { + {user_id:integer(hidden),optional} + {return_url:text(hidden),optional} + {message:text(hidden),optional} +} + +if { [llength [auth::authority::get_authority_options]] > 1 } { + ad_form -extend -name user_info -form { + {authority_id:text(select) + {mode $elm_mode(authority_id)} + {label "[_ acs-subsite.Authority]"} + {options {[auth::authority::get_authority_options]}} + } + } +} +if { $user(authority_id) != [auth::authority::local] || ![auth::UseEmailForLoginP] || \ + ([acs_user::site_wide_admin_p] && [llength [auth::authority::get_authority_options]] > 1) } { + ad_form -extend -name user_info -form { + {username:text(text) + {label "[_ acs-subsite.Username]"} + {mode $elm_mode(username)} + } + } +} + +# TODO: Use get_registration_form_elements, or auto-generate the form somehow? Deferred. + + +ad_form -extend -name user_info -form { + {first_names:text + {label "[_ acs-subsite.First_names]"} + {html {size 50}} + {mode $elm_mode(first_names)} + } + {last_name:text + {label "[_ acs-subsite.Last_name]"} + {html {size 50}} + {mode $elm_mode(last_name)} + } + {email:text + {label "[_ acs-subsite.Email]"} + {html {size 50}} + {mode $elm_mode(email)} + } +} + +if {[apm_package_enabled_p "categories"]} { + set main_site_id [subsite::main_site_id] + if {![empty_string_p [category_tree::get_mapped_trees $main_site_id]]} { + category::ad_form::add_widgets -container_object_id $main_site_id -categorized_object_id $user_id -form_name user_info + } +} + +if { ![string equal [acs_user::ScreenName] "none"] } { + ad_form -extend -name user_info -form \ + [list \ + [list screen_name:text[ad_decode [acs_user::ScreenName] "solicit" ",optional" ""] \ + {label "[_ acs-subsite.Screen_name]"} \ + {html {size 50}} \ + {mode $elm_mode(screen_name)} \ + ]] +} + +ad_form -extend -name user_info -form { + {url:text,optional + {label "[_ acs-subsite.Home_page]"} + {html {size 50}} + {mode $elm_mode(url)} + } + {bio:text(textarea),optional + {label "[_ acs-subsite.About_You]"} + {html {rows 8 cols 60}} + {mode $elm_mode(bio)} + {display_value {[ad_text_to_html -- $user(bio)]}} + } + + {grade:text,optional + {label "Grade"} + {html {size 10}} + } + + {allergies:text,optional + {label "Allergies"} + {html {size 40}} + } + + {age:integer,optional + {label "Age"} + {html {size 10}} + } + + {add:text(submit) {label "Update Participant"}} + {addpatron:text(submit) {label "Update Participant and Select Patron"}} + {cancel:text(submit) {label "Cancel"}} +} -on_request { + foreach var { authority_id first_names last_name email username screen_name url bio } { + set $var $user($var) + } + db_0or1row person_info { + select * + from person_info + where person_id = :user_id + } +} -on_submit { + set user_info(authority_id) $user(authority_id) + set user_info(username) $user(username) + foreach elm $form_elms { + if { [empty_string_p $elm_mode($elm)] && [info exists $elm] } { + set user_info($elm) [string trim [set $elm]] + } + } + + array set result [auth::update_local_account \ + -authority_id $user(authority_id) \ + -username $user(username) \ + -array user_info] + + + # Handle authentication problems + switch $result(update_status) { + ok { + # Continue below + } + default { + # Adding the error to the first element, but only if there are no element messages + if { [llength $result(element_messages)] == 0 } { + form set_error user_info $first_element $result(update_message) + } + + # Element messages + foreach { elm_name elm_error } $result(element_messages) { + form set_error user_info $elm_name $elm_error + } + break + } + } + + if {[apm_package_enabled_p "categories"]} { + category::map_object -object_id $user_id [category::ad_form::get_categories -container_object_id $main_site_id] + } + + # Roel: Extra info for students + if { [db_0or1row person_info { + select 1 + from person_info + where person_id = :user_id + }] } { + db_dml update_extra_info { + update person_info + set grade = :grade, + allergies = :allergies, + age = :age + where person_id = :user_id + } + } else { + db_dml insert_extra_info { + insert into person_info (person_id, grade, allergies, age) + values (:user_id, :grade, :allergies, :age) + } + } + + dotlrn::user_add -user_id $user_id +} -after_submit { + if { [string equal [ad_conn account_status] "closed"] } { + auth::verify_account_status + } + + if { ! [empty_string_p [template::element get_value user_info add]] } { + ad_returnredirect $add_url + } elseif { ! [empty_string_p [template::element get_value user_info addpatron]] } { + ad_returnredirect $addpatron_url + } else { + ad_returnredirect $return_url + } + ad_script_abort +} + +# LARS HACK: Make the URL and email elements real links +if { ![form is_valid user_info] } { + element set_properties user_info email -display_value "[element get_value user_info email]" + if {![string match -nocase "http://*" [element get_value user_info url]]} { + element set_properties user_info url -display_value \ + "[element get_value user_info url]" + } else { + element set_properties user_info url -display_value \ + "[element get_value user_info url]" + } +} \ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/lib/user-new.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/lib/user-new.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn-ecommerce/lib/user-new.adp 2 Jun 2005 06:39:41 -0000 1.1 @@ -0,0 +1 @@ + \ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/lib/user-new.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/lib/user-new.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn-ecommerce/lib/user-new.tcl 2 Jun 2005 06:39:41 -0000 1.1 @@ -0,0 +1,221 @@ +# Expects parameters: +# +# self_register_p - Is the form for users who self register (1) or +# for administrators who create other users (0)? +# next_url - Any url to redirect to after the form has been submitted. The +# variables user_id, password, and account_messages will be added to the URL. Optional. +# email - Prepopulate the register form with given email. Optional. +# return_url - URL to redirect to after creation, will not get any query vars added +# rel_group_id - The name of a group which you want to relate this user to after creating the user. +# Will add an element to the form where the user can pick a relation among the permissible +# rel-types for the group. + +# Check if user can self register +auth::self_registration + +# Set default parameter values +array set parameter_defaults { + self_register_p 1 + next_url {} + return_url {} + add_url {} + addpatron_url {} +} +foreach parameter [array names parameter_defaults] { + if { ![exists_and_not_null $parameter] } { + set $parameter $parameter_defaults($parameter) + } +} + +# Redirect to HTTPS if so configured +if { [security::RestrictLoginToSSLP] } { + security::require_secure_conn +} + +# Log user out if currently logged in, if specified in the includeable chunk's parameters, +# e.g. not when creating accounts for other users +if { $self_register_p } { + ad_user_logout +} + +if {[apm_package_installed_p "assessment"]} { + + set exist_assessment [parameter::get -parameter AsmForRegisterId] +} else { + set exist_assessment "" +} + +if { $exist_assessment != "" && $exist_assessment!=0} { + set package_id [db_string package_id {select package_id from cr_folders where folder_id=(select context_id from acs_objects where object_id=:exist_assessment)}] + set url [apm_package_url_from_id $package_id] + + ad_returnredirect "${url}assessment?assessment_id=$exist_assessment&return_url=$return_url" +} else { + +# Pre-generate user_id for double-click protection +set user_id [db_nextval acs_object_id_seq] + +ad_form -name register -export {next_url user_id return_url add_url addpatron_url} -form [auth::get_registration_form_elements] + +if { [exists_and_not_null rel_group_id] } { + ad_form -extend -name register -form { + {rel_group_id:integer(hidden),optional} + } + + if { [permission::permission_p -object_id $rel_group_id -privilege "admin"] } { + ad_form -extend -name register -form { + {rel_type:text(select) + {label "Role"} + {options {[group::get_rel_types_options -group_id $rel_group_id]}} + } + } + } else { + ad_form -extend -name register -form { + {rel_type:text(hidden) + {value "membership_rel"} + } + } + } +} + +# Roel: Extra info for students +ad_form -extend -name register -form { + {grade:text,optional + {label "Grade"} + {html {size 10}} + } + + {allergies:text,optional + {label "Allergies"} + {html {size 40}} + } + + {age:integer,optional + {label "Age"} + {html {size 10}} + } + + {add:text(submit) {label "Add Participant"}} + {addpatron:text(submit) {label "Add Participant and Select Patron"}} +} + +ad_form -extend -name register -on_request { + # Populate elements from local variables + +} -on_submit { + + db_transaction { + array set creation_info [auth::create_user \ + -user_id $user_id \ + -verify_password_confirm \ + -username $username \ + -email $email \ + -first_names $first_names \ + -last_name $last_name \ + -screen_name $screen_name \ + -password $password \ + -password_confirm $password_confirm \ + -url $url \ + -secret_question $secret_question \ + -secret_answer $secret_answer] + + if { [string equal $creation_info(creation_status) "ok"] && [exists_and_not_null rel_group_id] } { + group::add_member \ + -group_id $rel_group_id \ + -user_id $user_id \ + -rel_type $rel_type + } + + db_dml insert_extra_info { + insert into person_info (person_id, grade, allergies, age) + values (:user_id, :grade, :allergies, :age) + } + } + + # Handle registration problems + + switch $creation_info(creation_status) { + ok { + # Continue below + } + default { + # Adding the error to the first element, but only if there are no element messages + if { [llength $creation_info(element_messages)] == 0 } { + array set reg_elms [auth::get_registration_elements] + set first_elm [lindex [concat $reg_elms(required) $reg_elms(optional)] 0] + form set_error register $first_elm $creation_info(creation_message) + } + + # Element messages + foreach { elm_name elm_error } $creation_info(element_messages) { + form set_error register $elm_name $elm_error + } + break + } + } + + switch $creation_info(account_status) { + ok { + # Continue below + } + default { + # Display the message on a separate page + ad_returnredirect [export_vars -base "[subsite::get_element -element url]register/account-closed" { { message $creation_info(account_message) } }] + ad_script_abort + } + } + + if { ! [dotlrn::user_p -user_id $user_id] } { + dotlrn::user_add -user_id $user_id + } + +} -after_submit { + + if { ! [empty_string_p [template::element get_value register add]] } { + ad_returnredirect [export_vars -base $add_url { user_id }] + ad_script_abort + } elseif { ! [empty_string_p [template::element get_value register addpatron]] } { + ad_returnredirect [export_vars -base $addpatron_url { user_id }] + ad_script_abort + } + + if { ![empty_string_p $next_url] } { + # Add user_id and account_message to the URL + ad_returnredirect [export_vars -base $next_url {user_id password {account_message $creation_info(account_message)}}] + ad_script_abort + } + + + # User is registered and logged in + if { ![exists_and_not_null return_url] } { + # Redirect to subsite home page. + set return_url [subsite::get_element -element url] + } + + # If the user is self registering, then try to set the preferred + # locale (assuming the user has set it as a anonymous visitor + # before registering). + if { $self_register_p } { + # We need to explicitly get the cookie and not use + # lang::user::locale, as we are now a registered user, + # but one without a valid locale setting. + set locale [ad_get_cookie "ad_locale"] + if { ![empty_string_p $locale] } { + lang::user::set_locale $locale + ad_set_cookie -replace t -max_age 0 "ad_locale" "" + } + } + + # Handle account_message + if { ![empty_string_p $creation_info(account_message)] && $self_register_p } { + # Only do this if user is self-registering + # as opposed to creating an account for someone else + ad_returnredirect [export_vars -base "[subsite::get_element -element url]register/account-message" { { message $creation_info(account_message) } return_url }] + ad_script_abort + } else { + # No messages + ad_returnredirect $return_url + ad_script_abort + } +} +} \ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-create.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-create.sql 31 May 2005 22:04:53 -0000 1.1 +++ openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-create.sql 2 Jun 2005 06:39:42 -0000 1.2 @@ -41,4 +41,13 @@ -- actual dates - comes from the calendar items in the community select acs_rel_type__create_role('as_session_role', 'Assessment Sessions Role', 'Assessment Sessions Role'); -select acs_rel_type__create_role('ec_product_role', 'Ecommerce Product Role', 'Ecommerce Product Role'); \ No newline at end of file +select acs_rel_type__create_role('ec_product_role', 'Ecommerce Product Role', 'Ecommerce Product Role'); + +create table person_info ( + person_id integer references persons not null, + grade text, + allergies text, + age integer +); + +\i dotlrn-ecommerce-memberships-create.sql \ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-drop.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-drop.sql 31 May 2005 22:04:53 -0000 1.1 +++ openacs-4/packages/dotlrn-ecommerce/sql/postgresql/dotlrn-ecommerce-drop.sql 2 Jun 2005 06:39:42 -0000 1.2 @@ -8,6 +8,7 @@ -- drop table dotlrn_ecommerce_section; +drop table person_info; select acs_rel_type__drop_role('as_session_role'); select acs_rel_type__drop_role('ec_product_role'); \ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/tcl/apm-callback-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/tcl/apm-callback-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/dotlrn-ecommerce/tcl/apm-callback-procs.tcl 31 May 2005 22:04:53 -0000 1.1 +++ openacs-4/packages/dotlrn-ecommerce/tcl/apm-callback-procs.tcl 2 Jun 2005 06:39:42 -0000 1.2 @@ -25,8 +25,10 @@ } { # add new rel types for student and instructors - rel_types::new -supertype dotlrn_member_rel -role_two student dotlrn_club_student_rel "dotLRN Club Student" "dotLRN Club Students" dotlrn_club 0 "" user 0 "" - rel_types::new -supertype dotlrn_member_rel -role_two instructor "dotLRN Club Instructor" "dotLRN Club Instructors" dotlrn_club 0 ""D user 0 "" + # Roel: Figure out why this is failing but dotlrn_club_student_rel + # is being created + catch {rel_types::new -supertype dotlrn_member_rel -role_two student dotlrn_club_student_rel "dotLRN Club Student" "dotLRN Club Students" dotlrn_club 0 "" user 0 ""} +# rel_types::new -supertype dotlrn_member_rel -role_two instructor "dotLRN Club Instructor" "dotLRN Club Instructors" dotlrn_club 0 "" user 0 "" rel_types::new -role_one user -role_two user patron_rel "Patron" "Patrons" user 0 65535 user 0 65535 Index: openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.adp 31 May 2005 22:04:54 -0000 1.1 +++ openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.adp 2 Jun 2005 06:39:43 -0000 1.2 @@ -2,13 +2,13 @@ @title@ @context;noquote@ - You are about to add user @user.first_names@ @user.last_name@ (@user.email@) to section @section_name@ +

Select a patron for @user.first_names@ @user.last_name@ (@user.email@)

- Add Participant   Cancel +

- You may also select a patron for this participant - - \ No newline at end of file +

Other users related to @user.first_names@ @user.last_name@ (@user.email@)

+ +

+ \ No newline at end of file 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.1 -r1.2 --- openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.tcl 31 May 2005 22:04:54 -0000 1.1 +++ openacs-4/packages/dotlrn-ecommerce/www/admin/membership-add.tcl 2 Jun 2005 06:39:43 -0000 1.2 @@ -10,7 +10,6 @@ @cvs-id $Id$ } { user_id:integer,notnull - {confirmed_p:integer,notnull 0} community_id:integer,notnull section_id:integer,notnull @@ -20,154 +19,191 @@ referer:notnull participant_id:optional + {cancel ""} } -properties { } -validate { } -errors { } +if { ! [empty_string_p $cancel] } { + ad_returnredirect $referer + ad_script_abort +} + if { ! [dotlrn::user_p -user_id $user_id] } { dotlrn::user_add -user_id $user_id } - + if { [info exists participant_id] } { set patron_id $user_id set user_id $participant_id } set next_url [export_vars -base membership-add { section_id community_id referer patron patron_id {participant_id $user_id} }] -db_1row get_section_info "select c.course_id, s.section_name +db_1row get_section_info "select c.course_id, s.section_name, s.product_id from dotlrn_ecommerce_section s, dotlrn_catalogi c, cr_items ci where s.course_id = c.item_id and ci.live_revision=c.revision_id and s.section_id = :section_id" set context [list [list [export_vars -base course-info { course_id }] $section_name] "Process Purchase"] -if { $confirmed_p } { - set community_url [dotlrn_community::get_community_url $community_id] - set add_member_url [export_vars -base ${community_url}member-add-3 { user_id { rel_type dotlrn_member_rel } referer }] +set title "Select Patron" +db_1row section_name { + select section_name + from dotlrn_ecommerce_section + where section_id = :section_id +} - ad_returnredirect $add_member_url - ad_script_abort -} else { - set title "Confirm Purchase" - db_1row section_name { - select section_name - from dotlrn_ecommerce_section - where section_id = :section_id - } +acs_user::get -user_id $user_id -array user - acs_user::get -user_id $user_id -array user +set confirm_url [export_vars -base membership-add { user_id {confirmed_p 1} community_id section_id referer }] - set confirm_url [export_vars -base membership-add { user_id {confirmed_p 1} community_id section_id referer }] +set patron_list [linsert [db_list_of_lists patrons { + select first_names||' '||last_name||' ('||email||')', user_id + from dotlrn_users + where user_id != :user_id + and (case when :patron = '' + then true + else lower(first_names||' '||last_name||' '||email) like '%'||lower(:patron)||'%' end) +}] 0 {{} 0}] - set patron_list [linsert [db_list_of_lists patrons { - select first_names||' '||last_name||' ('||email||')', user_id - from dotlrn_users - where user_id != :user_id - and (case when :patron = '' - then true - else lower(first_names||' '||last_name||' '||email) like '%'||lower(:patron)||'%' end) - }] 0 {{} 0}] +if { [llength $patron_list] == 1 } { + set form [rp_getform] + ns_set delkey $form __refreshing_p + ns_set put $form __refreshing_p 0 +} - if { [llength $patron_list] == 1 } { - set form [rp_getform] - ns_set delkey $form __refreshing_p - ns_set put $form __refreshing_p 0 - } - - set validate [list] +set validate [list] - if { ( [empty_string_p $patron] || [llength $patron_list] == 1 ) && ! $patron_id } { - ad_form -name "patron" -export { {patron_id 0} } -form { - {patron:text,optional {label "Search Patron"} {html {onchange "if (this.value != '') { this.form.__refreshing_p.value = 1; } else { this.form.__refreshing_p.value = 0 ; }"}} - {help_text "Enter a string to search names and email addresses.
Or Create an account and return to this form"} - } +if { ( [empty_string_p $patron] || [llength $patron_list] == 1 ) && ! $patron_id } { + ad_form -name "patron" -export { {patron_id 0} } -form { + {patron:text,optional {label "Search Patron"} {html {onchange "if (this.value != '') { this.form.__refreshing_p.value = 1; } else { this.form.__refreshing_p.value = 0 ; }"}} + {help_text "Enter a string to search names and email addresses.
Or Create an account and return to this form"} } + } - lappend validate {patron - { ! [empty_string_p $patron] } - "Please enter a search string" - } - lappend validate {patron - { [llength $patron_list] > 1 } - "No users found. Please try again" - } - } elseif { $patron_id } { - acs_user::get -user_id $patron_id -array patron_user + lappend validate {patron + { ! [empty_string_p $patron] } + "Please enter a search string" + } + lappend validate {patron + { [llength $patron_list] > 1 } + "No users found. Please try again" + } +} elseif { $patron_id } { + acs_user::get -user_id $patron_id -array patron_user - ad_form -name "patron" -export { patron patron_id } -form { - {patron_name:text(inform) {label "Patron"} {value "$patron_user(first_names) $patron_user(last_name) ($patron_user(email))"}} + ad_form -name "patron" -export { patron patron_id } -form { + {patron_name:text(inform) {label "Patron"} {value "$patron_user(first_names) $patron_user(last_name) ($patron_user(email))"}} + } + + lappend validate {relationship + { $relationship != [list [list 0 $community_id]] || ![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"} } + } - lappend validate {relationship - { $relationship != [list [list 0 $community_id]] || ![empty_string_p [template::element::get_value patron relationship_new]] } - "Please select a relationship or enter a new one" + lappend validate {patron_id + { $patron_id } + "Please select a patron from the list" + } + + lappend validate {relationship + { $relationship != [list [list 0 $community_id]] || ![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 } \ + -validate $validate \ + -form { + {relationship:text(category),optional,multiple {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} } - } 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"} - } + {relationship_new:text,optional {label "Other Relationship"} + {help_text "This field is ignored if a relationship is selected from the list above"} } + {proceed:text(submit) {label "Select Patron"}} + {cancel:text(submit) {label "Cancel"}} + } -on_request { + } -on_submit { + set rel_id [relation::get_id -object_id_one $user_id -object_id_two $patron_id -rel_type "patron_rel"] - lappend validate {patron_id - { $patron_id } - "Please select a patron from the list" + if { [empty_string_p $rel_id] } { + # Create patron relationship + set rel_id [db_exec_plsql relate_patron { + select acs_rel__new (null, + 'patron_rel', + :user_id, + :patron_id, + null, + null, + null) + }] + ns_log notice "DEBUG:: Created relationship $rel_id: $user_id - $patron_id" + } else { + ns_log notice "DEBUG:: Existing relationship $rel_id: $user_id - $patron_id" } - lappend validate {relationship - { $relationship != [list [list 0 $community_id]] || ![empty_string_p [template::element::get_value patron relationship_new]] } - "Please select a relationship or enter a new one" - } - } + # Check if no categories were selected + if { $relationship == [list [list 0 $community_id]] } { + set relationship "" - ad_form -extend -name "patron" -export { user_id {confirmed_p 0} community_id section_id referer } \ - -validate $validate \ - -form { - {relationship:text(category),optional,multiple {label "Relationship"} {value {0 $community_id}} {html {size 4}} - {help_text "Please select one or enter one below if not in the list"} - {assign_single_p t} + # See if user entered a new relationship and add that + if { ! [empty_string_p $relationship_new] } { + set tree_id [parameter::get -package_id [ad_conn package_id] -parameter PatronRelationshipCategoryTree -default 0] + set relationship [list [category::add -name $relationship_new -tree_id $tree_id -parent_id ""]] } - {relationship_new:text,optional {label "Other Relationship"} - {help_text "This field is ignored if a relationship is selected from the list above"} - } - {proceed:text(submit) {label "Add Participant with Patron"}} - } -on_submit { - set rel_id [relation::get_id -object_id_one $user_id -object_id_two $patron_id -rel_type "patron_rel"] + } - if { [empty_string_p $rel_id] } { - # Create patron relationship - set rel_id [db_exec_plsql relate_patron { - select acs_rel__new (null, - 'patron_rel', - :user_id, - :patron_id, - null, - null, - null) - }] - ns_log notice "DEBUG:: Created relationship $rel_id: $user_id - $patron_id" - } else { - ns_log notice "DEBUG:: Existing relationship $rel_id: $user_id - $patron_id" - } + # Set relationships from categories + ns_log notice "DEBUG:: Categories $relationship rel_id $rel_id" + category::map_object -remove_old -object_id $rel_id $relationship - # Check if no categories were selected - if { $relationship == [list [list 0 $community_id]] } { - set relationship "" +# set community_url [dotlrn_community::get_community_url $community_id] +# set add_member_url [export_vars -base ${community_url}member-add-3 { user_id { rel_type dotlrn_member_rel } referer }] + +# ad_returnredirect $add_member_url - # See if user entered a new relationship and add that - if { ! [empty_string_p $relationship_new] } { - set tree_id [parameter::get -package_id [ad_conn package_id] -parameter PatronRelationshipCategoryTree -default 0] - set relationship [list [category::add -name $relationship_new -tree_id $tree_id -parent_id ""]] - } - } +# ad_returnredirect [export_vars -base membership-add { user_id { confirmed_p 1 } community_id section_id referer }] - # Set relationships from categories - ns_log notice "DEBUG:: Categories $relationship rel_id $rel_id" - category::map_object -remove_old -object_id $rel_id $relationship + 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 }] + } else { + ad_returnredirect $referer + } + ad_script_abort + } - ad_returnredirect [export_vars -base membership-add { user_id { confirmed_p 1 } community_id section_id referer }] - ad_script_abort +template::list::create \ + -name "patrons" \ + -multirow "patrons" \ + -no_data "No relationships listed for this user" \ + -elements { + patron { + label Patron } + relationship { + label Relationship + } + } + +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 +} { + foreach category [category::get_mapped_categories $rel_id] { + lappend relationship [category::get_name $category] + } + + set relationship [join $relationship ", "] } \ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/www/admin/participant-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/participant-add.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn-ecommerce/www/admin/participant-add.adp 2 Jun 2005 06:39:43 -0000 1.1 @@ -0,0 +1,9 @@ + + @title@ + @context@ + + \ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/www/admin/participant-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/participant-add.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/dotlrn-ecommerce/www/admin/participant-add.tcl 2 Jun 2005 06:39:43 -0000 1.1 @@ -0,0 +1,33 @@ +# packages/dotlrn-ecommerce/www/admin/participant-add.tcl + +ad_page_contract { + + + + @author Roel Canicula (roelmc@pldtdsl.net) + @creation-date 2005-06-01 + @arch-tag: 0ee8915f-9e76-4a92-9d43-89c2c757276d + @cvs-id $Id: participant-add.tcl,v 1.1 2005/06/02 06:39:43 hamiltonc Exp $ +} { + user_id:integer + {return_url ""} + section_id:integer + community_id:integer + {cancel ""} +} -properties { +} -validate { +} -errors { +} + +set title "" +set context "" + +db_1row get_section_info "select c.course_id, s.section_name, s.product_id + from dotlrn_ecommerce_section s, dotlrn_catalogi c, cr_items ci + where s.course_id = c.item_id + and ci.live_revision=c.revision_id + and s.section_id = :section_id" + +set context [list [list [export_vars -base course-info { course_id }] $section_name] "Participants and Patrons"] +set add_url [export_vars -base "[apm_package_url_from_key ecommerce]shopping-cart-add" { product_id }] +set addpatron_url [export_vars -base "[apm_package_url_from_key dotlrn-ecommerce]admin/membership-add" { user_id section_id community_id {referer $return_url} }] Index: openacs-4/packages/dotlrn-ecommerce/www/admin/patron-create.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/patron-create.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/dotlrn-ecommerce/www/admin/patron-create.adp 31 May 2005 22:04:54 -0000 1.1 +++ openacs-4/packages/dotlrn-ecommerce/www/admin/patron-create.adp 2 Jun 2005 06:39:43 -0000 1.2 @@ -1,6 +1,6 @@ Create a Patron Account {Create a Patron Account} - + \ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.adp 31 May 2005 22:04:54 -0000 1.1 +++ openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.adp 2 Jun 2005 06:39:43 -0000 1.2 @@ -1,6 +1,6 @@ Process Purchase - @context;noquote@ + @context;noquote@ @@ -15,14 +15,12 @@

Or create an account for the participant - - - - -

-

Members

-

- - - \ No newline at end of file + + + + + + \ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.tcl 31 May 2005 22:04:54 -0000 1.1 +++ openacs-4/packages/dotlrn-ecommerce/www/admin/process-purchase.tcl 2 Jun 2005 06:39:43 -0000 1.2 @@ -21,22 +21,18 @@ if { [exists_and_not_null section_id] } { - db_1row get_section_info "select c.course_id, s.section_name + db_1row get_section_info "select c.course_id, s.section_name, s.community_id, s.product_id from dotlrn_ecommerce_section s, dotlrn_catalogi c, cr_items ci where s.course_id = c.item_id and ci.live_revision=c.revision_id and s.section_id = :section_id" set context [list [list [export_vars -base course-info { course_id }] $section_name] "Process Purchase"] - - db_1row get_community { - select community_id - from dotlrn_ecommerce_section - where section_id = :section_id + + if { [empty_string_p $return_url] } { + set return_url [export_vars -base [ad_conn package_url]admin/course-info {course_id}] } - set return_url [export_vars -base [ad_conn package_url]admin/course-info {course_id}] - ad_form -name "search" -export { section_id patron return_url } -form { {search:text {label "Search existing users"}} } @@ -93,46 +89,14 @@ $page_query [template::list::page_where_clause -name users -key user_id -and] }] { - set add_member_url [export_vars -base membership-add { user_id {referer $return_url} section_id community_id }] +# set add_member_url [export_vars -base participant-add { user_id {referer $return_url} return_url section_id community_id }] +# set return_url_2 [export_vars -base "[apm_package_url_from_key dotlrn-ecommerce]admin/membership-add" { user_id section_id community_id {referer $return_url} }] + set add_member_url [export_vars -base participant-add { user_id return_url section_id community_id }] } } - template::list::create \ - -name members \ - -multirow members \ - -no_data "No users has purchased this section" \ - -page_flush_p 1 \ - -key user_id \ - -bulk_actions { "Remove Membership" membership-remove "Remove Membership" } \ - -bulk_action_export_vars { community_id return_url patron } \ - -elements { - user_id { - label "User ID" - } - email { - label "Email Address" - } - first_names { - label "First Name" - } - last_name { - label "Last Name" - } - } \ - -filters { - search {} - section_id {} - } - - db_multirow members members { - select r.user_id, r.rel_id, r.role, u.first_names, u.last_name, u.email - from dotlrn_member_rels_full r, dotlrn_users u - where r.member_state = 'approved' - and r.rel_type = 'dotlrn_member_rel' - and r.user_id = u.user_id - and r.community_id = :community_id - } - + set add_url [export_vars -base "[apm_package_url_from_key ecommerce]shopping-cart-add" { product_id }] + set addpatron_url [export_vars -base "[apm_package_url_from_key dotlrn-ecommerce]admin/membership-add" { user_id section_id community_id {referer $return_url} }] } set next_url [export_vars -base membership-add { section_id community_id { referer $return_url} }] \ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/www/admin/section-add-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/admin/section-add-edit.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/dotlrn-ecommerce/www/admin/section-add-edit.tcl 31 May 2005 22:04:54 -0000 1.1 +++ openacs-4/packages/dotlrn-ecommerce/www/admin/section-add-edit.tcl 2 Jun 2005 06:39:43 -0000 1.2 @@ -379,7 +379,7 @@ db_dml product_update { update ec_products - set active_p = 't' + set active_p = 't', no_shipping_avail_p = 't' where product_id = :product_id } # take care of custom fields