Index: openacs-4/packages/dotlrn-ecommerce/www/applications.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/www/applications.tcl,v diff -u -r1.18 -r1.19 --- openacs-4/packages/dotlrn-ecommerce/www/applications.tcl 7 Aug 2005 13:30:53 -0000 1.18 +++ openacs-4/packages/dotlrn-ecommerce/www/applications.tcl 16 Aug 2005 10:36:27 -0000 1.19 @@ -12,6 +12,7 @@ type:optional orderby:optional section_id:optional + {csv_p 0} } -properties { } -validate { } -errors { @@ -25,6 +26,12 @@ set admin_p [permission::permission_p -object_id $package_id -privilege "admin"] set return_url [ad_return_url] +set header_stuff { + +} + set enable_applications_p [parameter::get -package_id [ad_conn package_id] -parameter EnableCourseApplicationsP -default 1] if { [exists_and_not_null type] } { @@ -48,11 +55,14 @@ template::list::create \ -name "applications" \ + -key rel_id \ -multirow "applications" \ -no_data "[_ dotlrn-ecommerce.No_applications]" \ -pass_properties { return_url } \ -page_flush_p 1 \ -pass_properties { admin_p return_url _type } \ + -actions [list "[_ dotlrn-ecommerce.View_previously_email]" "sent-emails" "[_ dotlrn-ecommerce.View_previously_email]"] \ + -bulk_actions [list "[_ dotlrn-ecommerce.Email_applicants]" "email-applicants" "[_ dotlrn-ecommerce.Email_applicants]"] \ -elements { section_name { label "[_ dotlrn-ecommerce.Section]" @@ -128,6 +138,21 @@ label "[_ dotlrn-ecommerce.Phone_Number]" hide_p {[ad_decode $_type "waitinglist approved" 0 "request approved" 0 "payment received" 0 "all" 0 1]} } + comments { + label "[_ dotlrn-ecommerce.Notes]" + display_template { + + [_ dotlrn-ecommerce.Add_note] + + + [_ dotlrn-ecommerce.View] + + } + } + comments_text_plain { + label "[_ dotlrn-ecommerce.Notes]" + hide_p 1 + } actions { label "" display_template { @@ -151,6 +176,11 @@ where_clause { member_state = :type } } section_id {} + csv_p { + label "[_ dotlrn-ecommerce.Export]" + values {{"[_ dotlrn-ecommerce.CSV]" 1}} + has_default_p 1 + } }] -orderby { section_name { label "[_ dotlrn-ecommerce.Section_1]" @@ -192,7 +222,9 @@ set member_state_clause { and member_state in ('needs approval', 'waitinglist approved', 'request approval', 'request approved') } } -db_multirow -extend { approve_url reject_url asm_url section_edit_url person_url register_url } applications applications [subst { +set general_comments_url [apm_package_url_from_key "general-comments"] + +db_multirow -extend { approve_url reject_url asm_url section_edit_url person_url register_url comments comments_text_plain add_comment_url } applications applications [subst { select person__name(r.user_id) as person_name, member_state, r.community_id, r.user_id as applicant_user_id, s.section_name, t.course_name, s.section_id, r.rel_id, e.phone, o.creation_user as patron_id, (select count(*) from (select * @@ -284,4 +316,123 @@ set section_edit_url [export_vars -base admin/one-section { section_id return_url }] set person_url [export_vars -base /acs-admin/users/one { {user_id $applicant_user_id} }] set register_url [export_vars -base admin/process-purchase-course { section_id {user_id $patron_id} {participant_id $applicant_user_id} }] + + # get associated comment + if {![empty_string_p $asm_url]} { + db_foreach get_comments { + select g.comment_id, + r.content as gc_content, + r.title as gc_title, + r.mime_type as gc_mime_type, + acs_object__name(o.creation_user) as gc_author, + to_char(o.creation_date, 'YYYY-MM-DD HH24:MI:SS') as gc_creation_date_ansi + from general_comments g, + cr_revisions r, + cr_items ci, + acs_objects o + where g.object_id = :session_id + and r.revision_id = ci.live_revision + and ci.item_id = g.comment_id + and o.object_id = g.comment_id + order by o.creation_date + } { + if {[string equal $gc_mime_type "text/plain"]} { + set html_comment [dotlrn_ecommerce::util::text_to_html -text $gc_content] + } else { + set html_comment $gc_content + } + append comments "$gc_title
${html_comment}
- $gc_author on $gc_creation_date_ansi

" + } + if {[empty_string_p $comments]} { + set add_comment_url [export_vars -base "${general_comments_url}comment-add" {{object_id $session_id} {object_name "Application"} return_url}] + } + set comments_text_plain [ad_html_text_convert -from "text/html" -to "text/plain" $html_comment] + } + } + +# if we are CSV we need to get the assessment items +# since template::list has been prepared at this point we need +# to add columns to the multirow manually and output manually +# instead of template::list::write_csv + +if {$csv_p == 1} { + set csv_cols [list "section_name" "number" "person_name" "member_state" "phone" "comments_text_plain"] + template::list::get_reference -name applications + set __list_name applications + foreach __element_name $csv_cols { + template::list::element::get_reference -list_name $__list_name -element_name $__element_name -local_name __element_properties + set csv_cols_labels($__element_name) $__element_properties(label) + } + + set csv_as_item_list [list] + + # first pass -- extend the multirow + template::multirow foreach applications { + if {![empty_string_p $session_id]} { + db_foreach get_session_data { + select a.as_item_id, + case + when o.object_type = 'as_item_type_mc' then cr.title + else + d.text_answer + end as answer, + cr2.title as question + from as_item_data d + left join as_item_data_choices c on (d.item_data_id = c.item_data_id) + left join cr_revisions cr on (c.choice_id = cr.revision_id), + as_items a, + acs_objects o, + as_item_rels r, + cr_revisions cr2, + as_session_item_map m + where d.as_item_id = a.as_item_id + and a.as_item_id = r.item_rev_id + and r.target_rev_id = o.object_id + and r.rel_type = 'as_item_type_rel' + and cr2.revision_id = a.as_item_id + and m.session_id = :session_id + and d.item_data_id = m.item_data_id + } { + if {[lsearch $csv_as_item_list $as_item_id] == -1} { + lappend csv_as_item_list $as_item_id + template::multirow extend applications $as_item_id + set csv_cols_labels($as_item_id) $question + lappend csv_cols $as_item_id + } + set $as_item_id $answer + } + } + } + + set __output {} + set __cols [list] + + # output the headers + foreach __col_name $csv_cols { + lappend __cols [template::list::csv_quote $csv_cols_labels($__col_name)] + } + append __output "\"[join $__cols "\",\""]\"\n" + + # second pass - write out the data + template::multirow foreach applications { + + set __cols [list] + + foreach __col_name $csv_cols { + lappend __cols [template::list::csv_quote [set $__col_name]] + } + append __output "\"[join $__cols "\",\""]\"\n" + } + + # do not cache csv exports + ns_set put [ns_conn outputheaders] "Cache-Control" "private" + ns_set put [ns_conn outputheaders] "Expires" "Thu, 01 Jan 1998 07:00:00 GMT" + + # force to download and set type and filename + set title "applications_[ns_fmttime [ns_time] "%Y%m%d_%H%M"].csv" + ns_set put [ns_conn outputheaders] "Content-Disposition" "attachment; filename=$title" + + ns_return 200 "text/x-csv" $__output + ad_script_abort +}