Index: openacs-4/packages/survey-reports/survey-reports.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/survey-reports.info,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/survey-reports.info 14 Nov 2005 04:31:00 -0000 1.2
@@ -0,0 +1,30 @@
+
+
+
+
+ Survey Reports
+ Survey Reports
+ f
+ f
+
+
+ Dave Bauer
+ Deds Castillo
+ Manage reports based on survey responses.
+ SolutionGrove
+ Manage content repository templates using data from survey responses to build a report.
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: openacs-4/packages/survey-reports/lib/item-list.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/lib/item-list.adp,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/lib/item-list.adp 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,244 @@
+
+
+
+
+
+
+
+
+
+
+
Index: openacs-4/packages/survey-reports/lib/report-folder-form.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/lib/report-folder-form.tcl,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/lib/report-folder-form.tcl 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,44 @@
+#a form to create or edit a folder
+#
+# this file is meant to be included with the following parameters
+#
+# folder_id - if you are editing a folder
+# parent_id - if you are creating a folder
+# create_index_p - if true will create a blank page named "index" on the new folder, defaults to true
+# return_url - requires a return_url, so after creating or editing a folder it redirect to this url
+# form_mode - either "edit" or "display"
+
+# initialize the vars that don't exist
+if {![info exists parent_id]} {
+ if {![info exists folder_id]} {
+ error "you are likely going to use this form to create a new folder, please include a parent_id parameter"
+ }
+ set parent_id ""
+}
+if {![info exists create_index_p]} {
+ set create_index_p true
+}
+if {![info exists form_mode]} {
+ set form_mode edit
+}
+
+ad_form -name simpleform -mode $form_mode -has_edit 1 -form {
+ {folder_name:text(inform) {label "Folder Name"}}
+ {folder_label:text(inform) {label "Folder Label"}}
+ {description:text(inform),optional {label "Folder Description"}}
+ {create_index_p:boolean(hidden),optional {value $create_index_p}}
+ {parent_id:integer(hidden),optional {value $parent_id}}
+ {return_url:text(hidden) {value $return_url}}
+} -on_request {
+ content::item::get -item_id $folder_id -array_name folder
+ set folder_name $folder(name)
+ set folder_label $folder(label)
+ set description $folder(description)
+} -after_submit {
+ ad_returnredirect $return_url
+ ad_script_abort
+}
+
+
+ad_return_template "/packages/survey-reports/lib/simple-form"
+
Index: openacs-4/packages/survey-reports/lib/report-master.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/lib/report-master.adp,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/lib/report-master.adp 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,8 @@
+
+@survey_id@
+
+
+
Manage Reports
+ View Report (note you must have responded to the survey first)No report associated.
+ Associate a report to this survey(currently associated report is: @report_template_name@)
+Note: Creating a new report does not automatically associate at this point. After creating a new report, click on associate a report to this survey.
+
\ No newline at end of file
Index: openacs-4/packages/survey-reports/lib/survey-one-admin.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/lib/survey-one-admin.tcl,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/lib/survey-one-admin.tcl 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,9 @@
+# include for report administration inline in survey/www/admin/one
+# @param survey_id
+
+set report_template_id [survey::report::get_template -survey_id $survey_id]
+if {$report_template_id} {
+ set report_template_name [item::get_element -item_id $report_template_id -element name]
+} else {
+ set report_template_name ""
+}
Index: openacs-4/packages/survey-reports/lib/template-form.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/lib/template-form.tcl,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/lib/template-form.tcl 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,88 @@
+# this file is meant to be included with the following parameters
+
+# parent_id - if you are creating a new template
+# revision_id - if you are editing a template revision
+# return_url - requires a return_url, so after creating or editing a folder it redirect to this url
+# form_mode - either "edit" or "display"
+
+ad_form -name simpleform -mode display -has_edit 1 -has_submit 1 -form {
+ revision_id:key
+ {submit1:text(submit) {label "Edit"}}
+ {name:text(text) {label "Name"} {help_text "Allowed characaters are: alphanumeric, _, -"}}
+ {title:text(text) {label "Title"}}
+ {description:text(textarea),optional {html {rows 5 cols 80}} {label "Description"}}
+ {content:richtext,optional {html {rows 40 cols 100}} {label "Content"} {htmlarea_p 1}}
+ {parent_id:integer(hidden),optional {value $parent_id}}
+ {item_id:integer(hidden),optional}
+ {return_url:text(hidden) {value $return_url}}
+ {submit2:text(submit) {label "Edit"}}
+} -validate {
+ {name
+ {[expr {[set existing_item [content::item::get_id -root_folder_id $parent_id -item_path $name]] eq "" || $existing_item == $item_id}]}
+ "Template Name already exists, please use another Template Name"
+ }
+ {name
+ {![regexp {[^a-zA-z0-9\-_]} $name]}
+ "Illegal characters in name"
+ }
+} -edit_request {
+ if {[ns_queryget "form:mode"] eq "display"} {
+ element set_properties simpleform submit1 label "OK"
+ element set_properties simpleform submit2 label "OK"
+ }
+ db_1row get_revision "select cr.*, ci.name, ci.parent_id from cr_revisions cr, cr_items ci where cr.item_id=ci.item_id and cr.revision_id=:revision_id" -column_array one_revision
+ set item_id $one_revision(item_id)
+ set name $one_revision(name)
+ set title $one_revision(title)
+ set description $one_revision(description)
+ set folder_id $one_revision(parent_id)
+
+ # For now, just show the template thats in the database
+ # DAVEB
+
+ # set template_dir [parameter::get -parameter TemplateRoot]
+ # set template_root_id [parameter::get -parameter template_folder_id]
+ # set template_path [db_string get_url "select content_item__get_path(:item_id,:template_root_id)"]
+ # set template_root "[acs_root_dir]/${template_dir}"
+ #set template_filename "${template_root}/${template_path}.adp"
+ #ns_log notice "DAVEB: template-form template_filename $template_filename"
+ # # read the file contents from the file system
+ # if {[file exists $template_filename]} {
+ # set content [template::util::read_file $template_filename]
+ # } else {
+ set content [template::util::richtext::create $one_revision(content) "text/html"]
+ # }
+
+} -edit_data {
+ set content [template::util::richtext::get_property contents $content]
+ set new_revision_id [content::revision::new -item_id $item_id -title $title -content $content -description $description]
+
+# bcms::item::set_item -item_id $item_id -name $name
+
+ content::item::get -item_id $item_id -array_name item
+ ad_returnredirect [export_vars -base [ad_conn url] {{revision_id $new_revision_id}}]
+} -new_data {
+
+ set template_filename "[acs_root_dir]/packages/survey/www/reports/${name}.adp"
+ # read the file contents from the file system
+ if {[file exists $template_filename] && [empty_string_p $content]} {
+ set content [template::util::read_file $template_filename]
+ }
+
+# set content [demoronise $content]
+
+ # create the template and revision
+ db_transaction {
+ set item_id [content::item::new -name $name -parent_id $parent_id]
+ set revision_id [content::revision::new -item_id $item_id \
+ -title $title -content $content -description $description]
+ }
+
+} -after_submit {
+ ad_returnredirect $return_url
+ ad_script_abort
+}
+
+ad_return_template "/packages/survey-reports/lib/simple-form"
+
+
Index: openacs-4/packages/survey-reports/sql/postgresql/survey-reports-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/sql/postgresql/survey-reports-create.sql,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/sql/postgresql/survey-reports-create.sql 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,23 @@
+--
+-- packages/survey/sql/postgresql/survey-reports-create.sql
+--
+-- @author Deds Castillo (deds@i-manila.com.ph)
+-- @creation-date 2004-10-21
+-- @arch-tag: 3e2487d0-6986-4257-ba5e-a352d23a0c8e
+-- @cvs-id $Id: survey-reports-create.sql,v 1.2 2005/11/14 04:31:01 daveb Exp $
+--
+
+create table survey_reports_survey_map (
+ template_id integer
+ constraint surv_rep_surv_map_template_id_fk
+ references cr_items
+ on delete cascade,
+ survey_id integer
+ constraint surv_rep_surv_map_survey_id_fk
+ references surveys
+ on delete cascade,
+ primary key (template_id, survey_id),
+ survey_variables_p boolean,
+ survey_show_report_p boolean
+);
+
Index: openacs-4/packages/survey-reports/tcl/apm-callback-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/tcl/apm-callback-procs.tcl,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/tcl/apm-callback-procs.tcl 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,52 @@
+#
+
+ad_library {
+
+ Install and setup survey reports
+
+ @author Dave Bauer (dave@thedesignexperience.org)
+ @creation-date 2005-11-01
+ @arch-tag: 45462fee-df1c-408d-b84d-2206ebf59b76
+ @cvs-id $Id: apm-callback-procs.tcl,v 1.2 2005/11/14 04:31:01 daveb Exp $
+}
+
+namespace eval survey_reports::install {}
+
+ad_proc -private survey_reports::install::after_instantiate {
+ -package_id
+} {
+
+ Setup folder
+
+ @author Dave Bauer (dave@thedesignexperience.org)
+ @creation-date 2005-11-01
+
+ @return
+
+ @error
+} {
+ content::folder::new \
+ -name "survey_reports_${package_id}_root_folder" \
+ -parent_id "-200" \
+ -package_id $package_id
+}
+
+ad_proc -private survey_reports::install::before_uninstantiate {
+ -package_id
+} {
+ Remove folder and contents
+
+ @author Dave Bauer (dave@thedesignexperience.org)
+ @creation-date 2005-11-01
+
+ @param package_id
+
+ @return
+
+ @error
+} {
+ set folder_id [content::item::get_id -path "survey_reports_${package_id}_root_folder" -root_folder_id "-200"]
+ content::folder::delete \
+ -folder_id $folder_id \
+ -cascade_p t
+}
Index: openacs-4/packages/survey-reports/tcl/survey-report-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/tcl/survey-report-procs.tcl,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/tcl/survey-report-procs.tcl 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,126 @@
+# packages/survey/tcl/survey-report-procs.tcl
+
+ad_library {
+
+ survey report library
+
+ @author Deds Castillo (deds@i-manila.com.ph)
+ @creation-date 2004-10-21
+ @arch-tag: 3bb8b8a0-8149-465b-8820-42e08b817693
+ @cvs-id $Id: survey-report-procs.tcl,v 1.2 2005/11/14 04:31:01 daveb Exp $
+}
+
+namespace eval survey::report {}
+
+ad_proc -public survey::report::get_root_folder_name {
+ -package_id:required
+} {
+ gets the root folder name for a particular survey note that this
+ assumes a specific name.
+
+ @author Deds Castillo (deds@i-manila.com.ph)
+ @creation-date 2004-10-21
+
+ @param package_id
+
+ @return
+
+ @error
+} {
+ return "survey_reports_${package_id}_root_folder"
+}
+
+
+ad_proc -public survey::report::get_root_folder {
+ -package_id
+} {
+ gets the root template folder of a survey package. returns empty
+ string if none found.
+
+ @author Deds Castillo (deds@i-manila.com.ph)
+ @creation-date 2004-10-21
+
+ @param package_id
+
+ @return
+
+ @error
+} {
+ if {![exists_and_not_null package_id]} {
+ set package_id [ad_conn package_id]
+ }
+
+ set folder_name [get_root_folder_name -package_id $package_id]
+
+ set template_root_id -200
+
+ set root_folder_id [db_string get_root_folder {
+ select f.folder_id
+ from cr_items i,
+ cr_folders f
+ where f.folder_id = i.item_id
+ and i.parent_id = :template_root_id
+ and i.name = :folder_name
+ } -default ""]
+
+ return $root_folder_id
+}
+
+ad_proc -public survey::report::init_root_folder {
+ -package_id
+} {
+ creates a root folder for a survey package if there is none
+
+ @author Deds Castillo (deds@i-manila.com.ph)
+ @creation-date 2004-10-21
+
+ @param package_id
+
+ @return
+
+ @error
+} {
+ if {![exists_and_not_null package_id]} {
+ set package_id [ad_conn package_id]
+ }
+
+ set root_folder_id [get_root_folder -package_id $package_id]
+ if {[empty_string_p $root_folder_id]} {
+ set root_folder_id [bcms::folder::create_folder \
+ -name [get_root_folder_name -package_id $package_id] \
+ -folder_label "Survey Reports" \
+ -parent_id [bcms::template::get_cr_root_template_folder] \
+ -description "Survey Report Templates for survey package $package_id" \
+ -package_id $package_id \
+ -context_id $package_id \
+ -content_types "content_template"
+ ]
+ }
+
+ return $root_folder_id
+}
+
+ad_proc -public survey::report::get_template {
+ -survey_id:required
+} {
+ gets the associated template for a survey. 0 if none.
+
+ @author Deds Castillo (deds@i-manila.com.ph)
+ @creation-date 2004-10-21
+
+ @param survey_id
+
+ @return
+
+ @error
+} {
+ set template_id [db_string get_report {
+ select template_id
+ from survey_reports_survey_map
+ where survey_id = :survey_id
+ and survey_show_report_p = 't'
+ limit 1
+ } -default 0]
+
+ return $template_id
+}
Index: openacs-4/packages/survey-reports/www/index.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/www/index.adp,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/www/index.adp 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,5 @@
+
+@survey_id@
+
+@report_content@
+
Index: openacs-4/packages/survey-reports/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/www/index.tcl,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/www/index.tcl 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,231 @@
+ad_page_contract {
+
+ Set up template and see variables for a report based on a given survey.
+ WARNING: This page has a file storage proc in it that will need to be moved if this goes into the standard survey package\
+.
+
+ @param survey_id section we're adding a template to
+
+ @author Caroline@Meekshome.com
+ @date Feb 2004
+ @cvs-id $Id: index.tcl,v 1.2 2005/11/14 04:31:01 daveb Exp $
+} {
+ survey_id:integer
+ {user_id "[ad_conn user_id]"}
+ {rtf "f"}
+}
+
+ad_require_permission $survey_id read
+
+
+if [catch {acs_user::get -user_id $user_id -array user} errmsg] {
+ if { $user_id } {
+ ad_return_complaint 1 "[_ survey.Not_Found] [_ survey.lt_Could_not_find_user_u]"
+ return
+ } else {
+ ad_maybe_redirect_for_registration
+ }
+}
+
+#Check to see if there is a report. If there isn't show the the view one-respondant) page instead.
+
+ns_log debug "CM [acs_root_dir]/packages/survey/www/admin/reports/$survey_id"
+if { ![file exists "[acs_root_dir]/packages/survey/www/admin/reports/$survey_id.adp"] } {
+ ad_returnredirect "../one-respondent?survey_id=$survey_id"
+}
+
+
+#Now set prettier variables for the user to use.
+
+set username $user(username)
+set first_names $user(first_names)
+set last_name $user(last_name)
+set full_name $user(name)
+set email $user(email)
+set url $user(url)
+set screen_name $user(screen_name)
+set current_date [ns_fmttime [ns_time] "%B %e, %Y"]
+
+#For now we will only use the oldest response.
+db_0or1row last_response "select response_id, to_char(creation_date,'Month DD, YYYY') as response_date from survey_responses,\
+ acs_objects
+ where response_id = object_id
+and creation_user = :user_id
+and survey_id=:survey_id
+order by creation_date DESC
+LIMIT 1"
+
+if { ![exists_and_not_null response_id] } {
+ #Has not yet taken the survey. Send the user to the survey
+ ad_returnredirect "../respond?survey_id=$survey_id&return_url=reports/"
+ ad_script_abort
+}
+
+ad_require_permission $response_id read
+
+#Set all the variables.
+set duplicate_pretty_ids [db_list duplicate_pretty_ids {select distinct(q1.pretty_id)
+ from survey_questions q1 right outer join survey_sections s on q1.section_id = s.section_id
+where survey_id = :survey_id
+and 1 < (select count(*) from survey_questions q2 right outer join survey_sections s on q2.section_id = s.section_id
+ where survey_id = :survey_id
+ and q2.pretty_id = q1.pretty_id)}]
+
+# get all the questions and make variables for them based on their pretty_ids
+db_foreach survey_questions { select s.name as name, question_id, question_text, presentation_type, sort_order, active_p\
+, required_p, abstract_data_type,
+ s.section_id as section_id, branch_p,
+ coalesce(q.pretty_id,(question_id::varchar)) as question_pretty_id,
+ coalesce(s.pretty_id,(s.section_id::varchar)) as section_pretty_id
+ from survey_questions q right outer join survey_sections s
+ on (q.section_id = s.section_id)
+ where survey_id=:survey_id
+ and abstract_data_type in ('text','shorttext','boolean','number','integer','choice')
+ order by s.sort_key,s.section_id, sort_order} {
+ #The goal of this section is to list for the user all the variables he has available when he makes his template and the p\
+ossible answers.
+
+ #I'm being lazy here and not getting the responses at the same time I get all the questions.
+ #For now I'm not expecting a preformance issue but this may need to be rewritten at some time.
+ #If you ever do rewrite it remember to set unanswered questions to empty string.
+set full_id [fs::remove_special_file_system_characters -string "${section_pretty_id}_${question_pretty_id}"]
+
+lappend var_names full_name
+lappend var_names $full_id
+
+ns_log notice "\n-----\nDB full_id '${full_id}' \n ---- \n"
+switch $abstract_data_type {
+ "choice" {
+ set answer [db_list choice_answer "select label from survey_question_choices c, survey_question_responses \
+r
+ where r.choice_id = c.choice_id
+ and r.response_id = :response_id
+ and r.question_id = :question_id
+ and c.question_id = :question_id"]
+ if {[llength $answer] == 1} {
+ set answer [lindex $answer 0]
+ # DAVEB add median support to report
+
+ # ns_log notice "\n-----\nDB Choice Question full_id '${full_id}' \n ---- \n"
+
+ set ${full_id}_the_choice [db_string get_c "select sqc.numeric_value from survey_question_responses sqr, survey_question_choices sqc where sqc.question_id=:question_id and sqr.choice_id=sqc.choice_id and sqr.question_id=:question_id and sqr.response_id=:response_id"]
+ set stats [db_list get_stats "select sqc.numeric_value from survey_question_responses sqr , survey_question_choices sqc where sqr.question_id=:question_id and sqc.question_id=:question_id and sqr.choice_id=sqc.choice_id"]
+
+
+ if {![string equal "" [set ${full_id}_the_choice]]} {
+
+ set ${full_id}_median [format %0.2f [expr 1.0 * [math::statistics::BasicStats mean $stats]]]
+ lappend var_names ${full_id}_median
+ }
+ set mode_values ""
+ set mode_choice_ids ""
+ set mode_indexes ""
+ set mode_ids ""
+ set mode_labels ""
+ set ${full_id}_cp ""
+ db_foreach get_counts "select tr.total_responses, count(sqr.choice_id) as choice_count, to_char(((count(sqr.choice_id) / tr.total_responses :: float) * 100), '999.99%') as p ,sqr.choice_id, sqc.label, sqc.numeric_value from (select count(*) as total_responses from survey_question_responses where question_id=:question_id) as tr, survey_question_responses sqr left join survey_question_choices sqc on sqr.choice_id=sqc.choice_id where sqr.question_id=:question_id group by sqr.choice_id, sqc.label, sqc.numeric_value, sqc.sort_order, tr.total_responses order by sqc.sort_order" {
+ lappend mode_values $choice_count
+ lappend mode_choice_ids $choice_id
+ set choice_percent_array($p) "${label}: ${p}"
+ }
+ set choice_percents [array names choice_percent_array]
+ set choice_percents [lsort -decreasing $choice_percents]
+ if {[llength $choice_percents]} {
+ append ${full_id}_cp "
"
+ foreach c $choice_percents {
+ append ${full_id}_cp "
$choice_percent_array($c)
"
+ }
+ append ${full_id}_cp "
"
+ }
+
+ set mode_indexes [lsearch -all $mode_values [f::lmax $mode_values]]
+ foreach i $mode_indexes {
+ lappend mode_ids [lindex $mode_choice_ids $i]
+ }
+ if {[llength $mode_ids]} {
+ set mode_labels [join [db_list get_labels "select label from survey_question_choices where choice_id in ([template::util::tcl_to_sql_list $mode_ids])"] " and "]
+ }
+
+
+ set ${full_id}_mode $mode_labels
+
+ } else {
+ set ${full_id}_mode ""
+ set answer [join $answer ", "]
+ }
+ }
+ "boolean" {
+ set answer [db_string boolean_answer "select boolean_answer from survey_question_responses where response_id \
+= :response_id and question_id = :question_id" -default ""]
+ }
+ "number" - "integer" {
+ set answer [db_string number_answer "select number_answer from survey_question_responses where response_id =\
+ :response_id and question_id = :question_id" -default ""]
+ }
+ "text" {
+ set answer [db_string varchar_answer "select clob_answer from survey_question_responses where response_id\
+ = :response_id and question_id = :question_id" -default ""]
+ }
+ default {
+ set answer [db_string varchar_answer "select varchar_answer from survey_question_responses where response_id\
+ = :response_id and question_id = :question_id" -default ""]
+ }
+}
+
+
+ set $full_id $answer
+
+if { [lsearch $question_pretty_id $duplicate_pretty_ids] == -1 } {
+ set short_id [fs::remove_special_file_system_characters -string "$question_pretty_id"]
+ set $short_id $answer
+ lappend var_names $short_id
+}
+}
+
+
+set edit_url "../respond?[export_vars -url {response_id survey_id {edit_p 1}}]"
+
+set edit_link "Edit your response"
+
+# DAVEB
+upvar #[template::adp_level] __adp_master master
+set master "[acs_root_dir]/packages/survey/lib/report-master"
+upvar #[template::adp_level] __adp_properties properties
+
+ set properties(download_url) "[ad_return_url]&rtf=t"
+set properties(survey_id) $survey_id
+if {[string equal "t" $rtf]} {
+ set master "/home/prodcomp/openacs/packages/survey/lib/print-report-master"
+ set vars [list]
+ foreach var $var_names {
+ lappend vars $var [set $var]
+ }
+
+ foreach var {username first_names last_name email url screen_name current_date} {
+ lappend vars $var [set $var]
+ }
+
+ upvar #[template::adp_level] __adp_master master
+ set master ""
+ set html [template::adp_parse "/home/prodcomp/openacs/packages/survey/www/admin/reports/${survey_id}" $vars]
+ set filename_base [ns_mktemp "/home/prodcomp/temp/htmlXXXXXX"]
+ set fd [open "${filename_base}.html" w]
+ puts $fd $html
+ close $fd
+ set rtf_filename [html_to_rtf::convert_file -html_filename ${filename_base}.html]
+ ns_log notice "RTF FILENAME = '$rtf_filename'"
+ file delete ${filename_base}.html
+ if {$rtf_filename ne ""} {
+ get_survey_info -survey_id $survey_id
+ set download_filename "${survey_info(name)}.rtf"
+ns_log debug "DAVEB: download_filename='$download_filename'"
+ ns_set update [ns_conn outputheaders] Content-Disposition "attachment; filename=\"$download_filename\""
+ ns_returnfile 200 "text/rtf" ${filename_base}.rtf
+ file delete ${filename_base}.rtf
+ } else {
+ ad_returnredirect "/"
+ ad_script_abort
+ }
+}
+
+ad_return_template "../admin/reports/$survey_id"
Index: openacs-4/packages/survey-reports/www/index.vuh
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/www/index.vuh,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/www/index.vuh 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,38 @@
+# packages/survey/www/reports/index.vuh
+#
+# reports redirector
+#
+# @author Deds Castillo (deds@i-manila.com.ph)
+# @creation-date 2004-10-21
+# @arch-tag: c8d895f1-6c2d-4766-9b38-4b9a71b9edd9
+# @cvs-id $Id: index.vuh,v 1.2 2005/11/14 04:31:01 daveb Exp $
+
+ad_page_contract {
+} {
+
+}
+# {rtf "f"}
+set user_id [auth::require_login]
+
+set survey_id [ad_conn path_info]
+set package_id [ad_conn package_id]
+
+permission::require_permission \
+ -object_id $package_id \
+ -party_id $user_id \
+ -privilege read
+
+set template_id [survey::report::get_template -survey_id $survey_id]
+
+if {!$template_id} {
+ ad_returnredirect [export_vars -base "../admin/reports/manage/survey" {survey_id}]
+}
+
+set report_folder_id [survey::report::init_root_folder]
+
+content::item::get -item_id $template_id -revision live -array_name item
+
+rp_form_put template_item [array get item]
+rp_form_put survey_id $survey_id
+
+rp_internal_redirect view
Index: openacs-4/packages/survey-reports/www/need-respond.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/www/need-respond.adp,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/www/need-respond.adp 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,7 @@
+
+
+In order to view the report you must answer all required surveys.
+For this report you have not yet answered:
+
+
@survey_info.name;noquote@
+
\ No newline at end of file
Index: openacs-4/packages/survey-reports/www/need-respond.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/www/need-respond.tcl,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/www/need-respond.tcl 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,13 @@
+ad_page_contract {
+} {
+ survey_id:notnull
+ {return_url "[dotlrn_community::get_url]"}
+}
+
+#CM HACK Return url is ending up with 2 survey_ids and right now we just want to go back the main page of the community.
+
+set return_url [dotlrn_community::get_community_url "[dotlrn_community::get_community_id]"]
+
+get_survey_info -survey_id $survey_id
+
+set respond_url [export_vars -base "../respond" {survey_id return_url}]
\ No newline at end of file
Index: openacs-4/packages/survey-reports/www/template.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/www/template.tcl,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/www/template.tcl 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,15 @@
+ad_page_contract {
+} {
+ {template_id:notnull}
+ {rtf "f"}
+}
+
+set report_folder_id [survey::report::get_root_folder]
+
+content::item::get -item_id $template_id -revision live -array_name item
+set survey_id 0
+
+rp_form_put template_item [array get item]
+rp_form_put survey_id $survey_id
+
+rp_internal_redirect view
Index: openacs-4/packages/survey-reports/www/view.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/www/view.tcl,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/www/view.tcl 14 Nov 2005 04:31:01 -0000 1.2
@@ -0,0 +1,470 @@
+# packages/survey/www/views/view.tcl
+
+ad_page_contract {
+
+
+
+ @author Deds Castillo (deds@i-manila.com.ph)
+ @creation-date 2004-10-21
+ @arch-tag: 83ec419b-54be-454f-9432-ffb15586332b
+ @cvs-id $Id: view.tcl,v 1.2 2005/11/14 04:31:01 daveb Exp $
+} {
+ template_item
+ survey_id
+ {rtf "f"}
+} -properties {
+} -validate {
+} -errors {
+}
+
+set user_id [auth::require_login]
+set package_id [ad_conn package_id]
+
+array set item $template_item
+set item_id $item(item_id)
+
+# Roel 03/25, Prevent barfing when the report isn't live
+if { [empty_string_p [item::get_live_revision $item_id]] } {
+ ad_return_complaint "Page Not Available" "This page is not currently live."
+ ad_script_abort
+}
+
+if {[array size item] == 0} {
+ ns_returnnotfound
+}
+
+acs_user::get -user_id $user_id -array user
+set username $user(username)
+set first_names $user(first_names)
+set last_name $user(last_name)
+set full_name $user(name)
+set email $user(email)
+set url $user(url)
+set screen_name $user(screen_name)
+set current_date [ns_fmttime [ns_time] "%B %e, %Y"]
+
+set var_names [list]
+
+set used_list [list]
+set orig_survey_id $survey_id
+
+db_multirow surveys_used surveys_used {
+ select s.survey_id,
+ s.name as survey_name
+ from surveys s,
+ survey_reports_survey_map m
+ where m.template_id = :item_id
+ and m.survey_id = s.survey_id
+ and m.survey_variables_p = 't'
+} {
+ lappend used_list $survey_id
+}
+
+foreach one_survey_id $used_list {
+ db_0or1row last_response {
+ select response_id,
+ to_char(creation_date,'Month DD, YYYY') as response_date from survey_responses,
+ acs_objects
+ where response_id = object_id
+ and creation_user = :user_id
+ and survey_id=:one_survey_id
+ order by creation_date DESC
+ LIMIT 1
+ }
+
+ if { ![exists_and_not_null response_id] } {
+ #Has not yet taken the survey. Send the user to the survey
+# ad_returnredirect "../respond?survey_id=$survey_id&return_url=reports/"
+ set return_url [ad_return_url]
+ ad_returnredirect [export_vars -base "need-respond" {survey_id return_url}]
+ ad_script_abort
+ }
+
+ ad_require_permission $response_id read
+
+ #Set all the variables.
+ set duplicate_pretty_ids [db_list duplicate_pretty_ids {
+ select distinct(q1.pretty_id)
+ from survey_questions q1
+ right outer join survey_sections s
+ on q1.section_id = s.section_id
+ where survey_id = :one_survey_id
+ and 1 < (select count(*)
+ from survey_questions q2
+ right outer join survey_sections s
+ on q2.section_id = s.section_id
+ where survey_id = :one_survey_id
+ and q2.pretty_id = q1.pretty_id)
+ }]
+
+ # get all the questions and make variables for them based on their pretty_ids
+ db_foreach survey_questions {
+ select s.name as name,
+ question_id,
+ question_text,
+ presentation_type,
+ sort_order,
+ active_p,
+ required_p,
+ abstract_data_type,
+ s.section_id as section_id,
+ branch_p,
+ (select 1 from survey_question_choices sqc where sqc.question_id=q.question_id and numeric_value is not null limit 1) as median_p,
+ coalesce(q.pretty_id,(question_id::varchar)) as question_pretty_id,
+ coalesce(s.pretty_id,(s.section_id::varchar)) as section_pretty_id
+ from survey_questions q right outer join survey_sections s
+ on (q.section_id = s.section_id)
+ where survey_id=:one_survey_id
+ and abstract_data_type in ('text','shorttext','boolean','number','integer','choice')
+ order by s.sort_key,s.section_id, sort_order} {
+ # The goal of this section is to list for the user all the
+ # variables he has available when he makes his template and the possible answers.
+
+ #I'm being lazy here and not getting the responses at the same time I get all the questions.
+ #For now I'm not expecting a preformance issue but this may need to be rewritten at some time.
+ #If you ever do rewrite it remember to set unanswered questions to empty string.
+ set full_id [util_text_to_url -replacement _ -text "${section_pretty_id}_${question_pretty_id}"]
+ set full_section_id [util_text_to_url -replacement _ -text "${section_pretty_id}"]
+ lappend var_names $full_id
+ # Compute total points for multiple choice questions
+ # KSG Ticket #341
+ if { [lsearch $var_names ${full_section_id}_total] == -1 } {
+ set ${full_section_id}_total 0
+ lappend var_names ${full_section_id}_total
+ }
+
+ ns_log debug "\n-----\nDB full_id '${full_id}' \n ---- \n"
+ switch $abstract_data_type {
+ "choice" {
+ set answer [db_list choice_answer {
+ select label
+ from survey_question_choices c,
+ survey_question_responses r
+ where r.choice_id = c.choice_id
+ and r.response_id = :response_id
+ and r.question_id = :question_id
+ and c.question_id = :question_id
+ }]
+
+ set ctr 0
+ foreach one_label $answer {
+ incr ctr
+ set ${full_id}_choice_${ctr} "$one_label"
+ lappend var_names ${full_id}_choice_${ctr}
+ }
+
+ db_foreach get_counts "select sqc.sort_order,tr.total_responses, count(sqr.choice_id) as choice_count, to_char(((count(sqr.choice_id) / tr.total_responses :: float) * 100), '999.99%') as p ,sqc.choice_id, sqc.label, sqc.numeric_value from (select count(*) as total_responses from survey_question_responses where question_id=:question_id) as tr, survey_question_choices sqc left join survey_question_responses sqr on sqc.choice_id=sqr.choice_id where sqc.question_id=:question_id group by sqc.choice_id, sqc.label, sqc.numeric_value, sqc.sort_order, tr.total_responses order by sqc.sort_order" {
+ set ${full_id}_cid_${choice_id}_percent "${p}"
+ set ${full_id}_cid_${sort_order}_percent "${p}"
+ set ${full_id}_cid_${choice_id}_label "${label}"
+ set ${full_id}_cid_${sort_order}_label "${label}"
+ lappend var_names "${full_id}_cid_${choice_id}_percent"
+ lappend var_names "${full_id}_cid_${choice_id}_label"
+ lappend var_names "${full_id}_cid_${sort_order}_percent"
+ lappend var_names "${full_id}_cid_${sort_order}_label"
+ }
+
+ set ${full_id}_cp ""
+ set ${full_id}_c ""
+ set ${full_id}_d ""
+ set ${full_id}_mean ""
+ set ${full_id}_qt $question_text
+ lappend var_names "${full_id}_qt"
+ if {[llength $answer] == 1} {
+ set answer [lindex $answer 0]
+ # DAVEB add median support to report
+ # ns_log debug "\n-----\nDB Choice Question full_id '${full_id}' \n ---- \n"
+ set ${full_id}_the_choice [db_string get_c "select sqc.numeric_value from survey_question_responses sqr, survey_question_choices sqc where sqc.question_id=:question_id and sqr.choice_id=sqc.choice_id and sqr.question_id=:question_id and sqr.response_id=:response_id"]
+ set stats [db_list get_stats "select sqc.numeric_value from survey_question_responses sqr , survey_question_choices sqc where sqr.question_id=:question_id and sqc.question_id=:question_id and sqr.choice_id=sqc.choice_id"]
+ ns_log debug "\n------\nDAVEB Debugging survey/www/reports/index.tcl\nquestion_id='${question_id}'\nstats='${stats}'\n-----\n"
+ if {![string equal "" [set ${full_id}_the_choice]]} {
+ # ns_log debug "\n-----\nDB median '${full_id}_median' \n ---- \n"
+ set ${full_id}_median [format %0.2f [expr 1.0 * [math::statistics::BasicStats mean $stats]]]
+ lappend var_names ${full_id}_median
+ set ${full_id}_numeric_value [set ${full_id}_the_choice]
+ lappend var_names ${full_id}_numeric_value
+ }
+ set mode_values ""
+ set mode_choice_ids ""
+ set mode_indexes ""
+ set mode_ids ""
+ set mode_labels ""
+ if {[array exists choice_percent_array]} {
+ array unset choice_percent_array
+ }
+ set ${full_id}_c "
"
+ set ${full_id}_mean 0
+ set n 0
+ set points 0
+ db_foreach get_counts "select tr.total_responses, count(sqr.choice_id) as choice_count, to_char(((count(sqr.choice_id) / tr.total_responses :: float) * 100), '999.99%') as p ,sqr.choice_id, sqc.label, sqc.numeric_value from (select count(*) as total_responses from survey_question_responses where question_id=:question_id) as tr, survey_question_responses sqr left join survey_question_choices sqc on sqr.choice_id=sqc.choice_id where sqr.question_id=:question_id group by sqr.choice_id, sqc.label, sqc.numeric_value, sqc.sort_order, tr.total_responses order by sqc.sort_order" {
+ lappend mode_values $choice_count
+ lappend mode_choice_ids $choice_id
+ set choice_percent_array(${p}_${choice_id}) "${label}: ${p}"
+
+ if { [empty_string_p $numeric_value] } {
+ set numeric_value 0
+ }
+
+ if {![empty_string_p $label] && ![string equal $choice_count 0]} {
+ append ${full_id}_c "
"
+ set ${full_section_id}_total [expr [set ${full_section_id}_total] + $points]
+ if { $n } {
+ set ${full_id}_mean [format %0.2f [expr 1.0 * [set ${full_id}_mean] / $n]]
+ } else {
+ set ${full_id}_mean 0
+ }
+
+ set choice_percents [array names choice_percent_array]
+ set choice_percents [lsort -decreasing $choice_percents]
+ if {[llength $choice_percents]} {
+ append ${full_id}_cp "
"
+ foreach c $choice_percents {
+ append ${full_id}_cp "
$choice_percent_array($c)
"
+ }
+ append ${full_id}_cp "
"
+ }
+
+ set mode_indexes [lsearch -all $mode_values [f::lmax $mode_values]]
+ foreach i $mode_indexes {
+ lappend mode_ids [lindex $mode_choice_ids $i]
+ }
+ if {[llength $mode_ids]} {
+ set mode_labels [join [db_list get_labels "select label from survey_question_choices where choice_id in ([template::util::tcl_to_sql_list $mode_ids])"] " and "]
+ }
+ ns_log debug "\nDAVEB: survey report setting mode '${full_id}_mode' \n max = '[f::lmax $mode_values]' \n mode_values = '${mode_values} \n mode_choice_ids = '${mode_choice_ids}' \n mode_labels='${mode_labels}' \n mode_ids = '${mode_ids}'\n"
+ set ${full_id}_mode $mode_labels
+
+ } else {
+ if {[array exists choice_percent_array]} {
+ array unset choice_percent_array
+ }
+ set ${full_id}_c "
"
+ set ${full_id}_mean 0
+ set n 0
+ set points 0
+ db_foreach get_counts "select tr.total_responses, count(sqr.choice_id) as choice_count, to_char(((count(sqr.choice_id) / tr.total_responses :: float) * 100), '999.99%') as p ,sqr.choice_id, sqc.label, sqc.numeric_value from (select count(*) as total_responses from survey_question_responses where question_id=:question_id) as tr, survey_question_responses sqr left join survey_question_choices sqc on sqr.choice_id=sqc.choice_id where sqr.question_id=:question_id group by sqr.choice_id, sqc.label, sqc.numeric_value, sqc.sort_order, tr.total_responses order by sqc.sort_order" {
+ set choice_percent_array(${p}_${choice_id}) "${label}: ${p}"
+ set choice_count_array(${choice_count}_${choice_id}) "${label}: ${choice_count}"
+
+ if { [empty_string_p $numeric_value] } {
+ set numeric_value 0
+ }
+
+ append ${full_id}_c "
$label: $choice_count
"
+ incr n $choice_count
+ set points [expr $points + $choice_count * $numeric_value]
+ set ${full_id}_mean [expr [set ${full_id}_mean] + $choice_count * $numeric_value]
+ }
+ append ${full_id}_c "
"
+ set ${full_section_id}_total [expr [set ${full_section_id}_total] + $points]
+ if { $n } {
+ set ${full_id}_mean [format %0.2f [expr 1.0 * [set ${full_id}_mean] / $n]]
+ } else {
+ set ${full_id}_mean 0
+ }
+
+ set choice_percents [array names choice_percent_array]
+ set choice_percents [lsort -decreasing $choice_percents]
+
+ if {[llength $choice_percents]} {
+ append ${full_id}_cp "
"
+ foreach c $choice_percents {
+ append ${full_id}_cp "
$choice_percent_array($c)
"
+ }
+ append ${full_id}_cp "
"
+
+ set ctr 0
+ foreach c $choice_percents {
+ incr ctr
+ set ${full_id}_cp_top_${ctr} "$choice_percent_array($c)"
+ lappend var_names ${full_id}_cp_top_${ctr}
+ }
+ }
+ set ${full_id}_mode ""
+ set answer [join $answer ", "]
+ }
+ lappend var_names "${full_id}_cp"
+ lappend var_names "${full_id}_mean"
+ }
+ "boolean" {
+ set answer [db_string boolean_answer "select boolean_answer from survey_question_responses where response_id \
+= :response_id and question_id = :question_id" -default ""]
+ }
+ "number" - "integer" {
+ set answer [db_string number_answer "select number_answer from survey_question_responses where response_id =\
+ :response_id and question_id = :question_id" -default ""]
+ }
+ "text" {
+ set answer [db_string varchar_answer "select clob_answer from survey_question_responses where response_id\
+ = :response_id and question_id = :question_id" -default ""]
+ }
+ default {
+ set answer [db_string varchar_answer "select varchar_answer from survey_question_responses where response_id\
+ = :response_id and question_id = :question_id" -default ""]
+ }
+ }
+
+
+ set $full_id $answer
+
+ if { [lsearch $question_pretty_id $duplicate_pretty_ids] == -1 } {
+ set short_id [util_text_to_url -replacement _ -text "$question_pretty_id"]
+ set $short_id $answer
+ lappend var_names $short_id
+ }
+
+ }
+
+ # Compute delta per section
+ db_foreach sections {
+ select pretty_id as section_pretty_id, (select pretty_id
+ from survey_sections
+ where survey_id = :survey_id
+ and sort_key > s.sort_key
+ order by sort_key limit 1) as next_section_pretty_id
+ from survey_sections s
+ where survey_id = :survey_id
+ } {
+ set delta_id [util_text_to_url -replacement _ -text "${section_pretty_id}_${next_section_pretty_id}"]
+ if { ! [empty_string_p $next_section_pretty_id] } {
+ set ${delta_id}_delta_positive 0
+ set ${delta_id}_delta_negative 0
+ }
+ }
+
+ db_foreach section_points_delta {
+ select count(*), section_pretty_id, next_section_pretty_id, ((next_section_score - section_score) > 10) as direction
+
+ from (
+ select coalesce(sum(qc.numeric_value), 0) as section_score, r.response_id, q.section_id, s.pretty_id as section_pretty_id,
+
+ (select coalesce(sum(sqc.numeric_value), 0)
+ from survey_responses sr, survey_question_responses sqr, survey_questions sq, survey_question_choices sqc
+ where sr.response_id = sqr.response_id
+ and sqr.question_id = sq.question_id
+ and sq.question_id = sqc.question_id
+ and sr.response_id = r.response_id
+ and sqr.choice_id = sqc.choice_id
+ and sq.section_id = (select section_id
+ from survey_sections
+ where survey_id = :survey_id
+ and sort_key > s.sort_key
+ order by sort_key limit 1)) as next_section_score,
+ (select pretty_id
+ from survey_sections
+ where survey_id = :survey_id
+ and sort_key > s.sort_key
+ order by sort_key limit 1) as next_section_pretty_id
+
+ from survey_responses r, survey_question_responses qr, survey_question_choices qc, survey_questions q, survey_sections s
+
+ where r.response_id = qr.response_id
+ and qr.choice_id = qc.choice_id
+ and qr.question_id = q.question_id
+ and q.section_id = s.section_id
+ and r.survey_id = :survey_id
+
+ group by r.response_id, q.section_id, s.sort_key, section_pretty_id
+ order by r.response_id, s.sort_key
+
+ ) scores
+
+ where abs(section_score - next_section_score) > 10
+ group by response_id, section_pretty_id, next_section_pretty_id, (next_section_score - section_score) > 10;
+ } {
+ ns_log debug "DEBUG:: $section_pretty_id - $next_section_pretty_id - $direction"
+ if { ! [empty_string_p $next_section_pretty_id] } {
+ set delta_id [util_text_to_url -replacement _ -text "${section_pretty_id}_${next_section_pretty_id}"]
+ if { $direction == "f" } {
+ incr ${delta_id}_delta_negative
+ } else {
+ incr ${delta_id}_delta_positive
+ }
+ }
+ }
+
+
+ set edit_url "../respond?[export_vars -url {response_id survey_id {edit_p 1}}]"
+
+ set edit_link "Edit your response"
+
+}
+
+upvar #[template::adp_level] __adp_master master
+set master "[acs_root_dir]/packages/survey-reports/lib/report-master"
+upvar #[template::adp_level] __adp_properties properties
+
+if {$orig_survey_id} {
+ set properties(download_url) "[ad_conn package_url]$orig_survey_id?rtf=t"
+} else {
+ set properties(download_url) "[ad_conn package_url]/template?template_id=$item(item_id)&rtf=t"
+}
+set properties(survey_id) $orig_survey_id
+set properties(manage_url) "[ad_conn package_url]manage/${item(name)}"
+set properties(admin_p) [permission::permission_p -object_id $package_id -privilege admin]
+
+set vars [list]
+foreach var $var_names {
+ lappend vars $var [set $var]
+}
+
+if {[string equal "t" $rtf]} {
+ set master "[acs_root_dir]/packages/survey-reports/lib/print-report-master"
+
+ foreach var {username first_names last_name email url screen_name full_name response_date current_date} {
+ if {![info exists $var]} {
+ set $var ""
+ }
+ lappend vars $var [set $var]
+ }
+
+ upvar #[template::adp_level] __adp_master master
+ set master ""
+ set html [template::adp_parse "[acs_root_dir]/packages/survey-reports/lib/${item(item_id)}" $vars]
+
+
+
+# ns_log debug "BEFORE: \n $html \n"
+# set html [decruft $html]
+# set html [demoronise $html]
+# ns_log debug "AFTER: \n $html \n"
+
+ set filename_base [ns_mktemp "/var/tmp/htmlXXXXXX"]
+ set fd [open "${filename_base}.html" w]
+ puts $fd $html
+ close $fd
+ ns_log debug "\nDAVEB!!!!! filename_base='${filename_base}'\n"
+# ad_return_complaint 1 "TESTING"
+# ad_script_abort
+ set rtf_filename [html_to_rtf::convert_file -html_filename ${filename_base}.html]
+ ns_log debug "RTF FILENAME = '$rtf_filename'"
+ file delete ${filename_base}.html
+
+ if {$rtf_filename ne ""} {
+ if {[llength $used_list]} {
+ get_survey_info -survey_id $survey_id
+ } else {
+ set survey_info(name) "survey_report_${item_id}"
+ }
+ set download_filename "${item(name)}.rtf"
+ ns_log debug "DAVEB: download_filename='$download_filename'"
+ ns_set update [ns_conn outputheaders] Content-Disposition "attachment; filename=\"$download_filename\""
+ ns_returnfile 200 "text/rtf" $rtf_filename
+ file delete $rtf_filename
+ ad_script_abort
+ } else {
+ ad_returnredirect "/"
+ ad_script_abort
+ }
+}
+views::record_view -object_id $item_id -viewer_id $user_id
+
+ad_return_template "../lib/${item(item_id)}"
Index: openacs-4/packages/survey-reports/www/manage/available-vars.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/www/manage/available-vars.adp,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/www/manage/available-vars.adp 14 Nov 2005 04:31:02 -0000 1.2
@@ -0,0 +1,244 @@
+
+
+
+ View Template
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+This page lets you write a template for displaying a report on the above surveys. In the template you can have HTML,
+variable references, and conditional text. Variable references consist of putting '@' around the variable name. Below is
+a table of the names defined for this survey. If there was no response to a particular question, then the corresponding
+variable will contain an empty string. Conditional text consists of text surrounded by <if>,
+<elseif>, <else>, <switch>,
+<case>, or <default> tags. See the
+if, elseif, and else tag and
+switch, case, and default tag references for more details.
+
+
+
+
Standard for all Reports
+
User Info These are standard variables defined for the user viewing the report.
+
+
@user_id@
+
@username@
+
@first_names@
+
@last_name@
+
@full_name@ = "first_names last_name"
+
@email@
+
@url@
+
@screen_name@
+
@member_state@
+
@current_date@
+
+
+
+
Survey Info
+
@response_date@
+
Date the user last took the survey
+
+
+
+
+
@edit_url@
+
@edit_link@
+
+
+
Edit this response
+
+
+
+
Section: @vars.name@ (@vars.section_pretty_id@)
+
Variable Names
+
Possible Answers (type or choices)
+
+
+
+
+
Question (optional): @vars.question_text@
+
@@vars.full_id@@ or @@vars.short_id@@ \@@vars.full_id@_median\@
+
@vars.possible_values;noquote@
+
+
+
+
+
+
+
\ No newline at end of file
Index: openacs-4/packages/survey-reports/www/manage/available-vars.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/www/manage/available-vars.tcl,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/www/manage/available-vars.tcl 14 Nov 2005 04:31:02 -0000 1.2
@@ -0,0 +1,115 @@
+ad_page_contract {
+ Get the variables that are valid for the report
+} {
+ name
+}
+
+set report_folder_id [survey::report::get_root_folder ]
+set item_id [content::item::get_id -root_folder_id $report_folder_id -item_path $name]
+#ad_return_complaint 1 "folder_id '${report_folder_id}' item_id '${item_id}'"
+content::item::get -item_id $item_id -array_name content -revision latest
+
+if {[array size content] == 0} {
+ ns_returnnotfound
+}
+
+set revision_id $content(latest_revision)
+set package_id [ad_conn package_id]
+set used_list [list]
+
+db_multirow surveys_used surveys_used {
+ select s.survey_id,
+ s.name as survey_name
+ from surveys s,
+ survey_reports_survey_map m
+ where m.template_id = :item_id
+ and m.survey_id = s.survey_id
+ and m.survey_variables_p = 't'
+} {
+ lappend used_list $survey_id
+}
+
+if {[llength $used_list]} {
+ get_survey_info -survey_id $survey_id
+
+ if {![info exists survey_info(survey_id)]} {
+ ad_return_complaint 1 "[_ survey.lt_Requested_survey_does]"
+ ad_script_abort
+ }
+
+ set survey_name $survey_info(name)
+
+ set duplicate_pretty_ids [db_list duplicate_pretty_ids {
+ select distinct(q1.pretty_id)
+ from survey_questions q1
+ right outer join survey_sections s
+ on q1.section_id = s.section_id
+ where survey_id = :survey_id
+ and 1 < (select count(*)
+ from survey_questions q2
+ right outer join
+ survey_sections s
+ on q2.section_id = s.section_id
+ where survey_id = :survey_id
+ and q2.pretty_id = q1.pretty_id)
+ }]
+
+ # get all the questions and make variables for them based on their pretty_ids
+ db_multirow -extend {short_id full_id possible_values} vars survey_q_and_a "
+ select s.name as name,
+ question_id,
+ question_text,
+ presentation_type,
+ sort_order,
+ active_p,
+ required_p,
+ abstract_data_type,
+ s.section_id as section_id,
+ branch_p,
+ (select 1
+ from survey_question_choices sqc
+ where sqc.question_id=q.question_id
+ and numeric_value is not null
+ limit 1) as median_p,
+ coalesce(q.pretty_id,(question_id::varchar)) as question_pretty_id,
+ coalesce(s.pretty_id,(s.section_id::varchar)) as section_pretty_id
+ from survey_questions q right outer join survey_sections s
+ on (q.section_id = s.section_id)
+ where survey_id in ([join $used_list ","])
+ and abstract_data_type in ('text','shorttext','boolean','number','integer','choice')
+ order by survey_id,
+ s.sort_key,
+ s.section_id,
+ sort_order
+ " {
+ #The goal of this section is to list for the user all the variables he has available when he makes his template and the possible answers.
+ set full_id [util_text_to_url -text "${section_pretty_id}_${question_pretty_id}"]
+ if { [lsearch $question_pretty_id $duplicate_pretty_ids] == -1 } {
+ set short_id [util_text_to_url -replacement _ -text "$question_pretty_id"]
+ }
+ switch $abstract_data_type {
+ "choice" {
+ set answer_list [list]
+ foreach choice [db_list_of_lists answers {select sort_order, label from survey_question_choices where question_id = :question_id order by sort_order}] {
+ set sort_order [lindex $choice 0]
+ set label [lindex $choice 1]
+ lappend answer_list " ${label} @${full_id}_cid_${sort_order}@ @${full_id}_cid_${sort_order}_percent@ @${full_id}_cid_${sort_order}_label@ "
+ }
+ set possible_values "[join $answer_list " "]"
+ }
+ "text" -
+ "shorttext" {
+ set possible_values "text string"
+ }
+ "boolean" {
+ set possible_values "boolean (use <if @var@ true> or <if @var@ false>)"
+ }
+ default {
+ set possible_values "$abstract_data_type"
+ }
+ }
+
+ }
+} else {
+ set no_surveys_associated_p 1
+}
Index: openacs-4/packages/survey-reports/www/manage/folder-view.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/www/manage/folder-view.adp,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/www/manage/folder-view.adp 14 Nov 2005 04:31:02 -0000 1.2
@@ -0,0 +1,14 @@
+
+ @title;noquote@
+ @context;noquote@
+
+
+
+
Index: openacs-4/packages/survey-reports/www/manage/folder-view.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/www/manage/folder-view.tcl,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/www/manage/folder-view.tcl 14 Nov 2005 04:31:02 -0000 1.2
@@ -0,0 +1,74 @@
+# packages/survey/www/admin/reports/manage/folder-view.tcl
+
+ad_page_contract {
+
+ views a folder
+
+ @author Deds Castillo (deds@i-manila.com.ph)
+ @creation-date 2004-10-21
+ @arch-tag: ef91384f-9bb6-455a-9f3a-db28b35434ba
+ @cvs-id $Id: folder-view.tcl,v 1.2 2005/11/14 04:31:02 daveb Exp $
+} {
+ item
+ {orderby:optional}
+ {page:optional}
+ {return_url "[ad_conn url]"}
+} -properties {
+} -validate {
+} -errors {
+}
+
+if {![regexp {/$} [ad_conn url]]} {
+ ad_returnredirect "[ad_conn url]/"
+ ad_script_abort
+}
+
+set root_id [survey::report::get_root_folder]
+array set current_item $item
+set folder_id $current_item(item_id)
+# TODO make a CR proc?
+
+set package_url [ad_conn package_url]
+
+set type_options {{Report template-add}}
+
+ad_form -name add-item -export {return_url} -form {
+ {submit:text(submit) {label "Add New"} {value "Add New"}}
+ {item_type:text(select) {label ""} {options $type_options } }
+ {parent_id:text(hidden) {value $folder_id}}
+} -on_submit {
+ ad_returnredirect "${item_type}?[export_vars {parent_id return_url}]"
+}
+
+template::list::create \
+ -name item_list \
+ -multirow item_list \
+ -pass_properties { package_url } \
+ -key item_id \
+ -bulk_actions [list "Delete" "template-delete" "Delete checked items"] \
+ -bulk_action_export_vars {
+ return_url
+ } \
+ -elements {
+ name {
+ label "Name"
+ link_url_col name
+ }
+ title {
+ label "Title"
+ }
+ publish_status {
+ label "Status"
+ }
+ }
+
+# TODO replace multirow proc with a db_multirow DAVEB
+db_multirow item_list get_item_list "select ci.publish_status,* from cr_revisionsx cr, cr_items ci where cr.parent_id=:folder_id and cr.item_id=ci.item_id and cr.revision_id=ci.latest_revision"
+
+set title "View Folder"
+
+# TODO get paths for folder to feed to context DAVEB
+#set context [bcms::widget::item_context -item_id $folder_id -root_id $root_id -root_url [ad_conn package_url]manage/ ]
+#set context [lrange $context 0 [expr [llength $context] - 2]]
+set context [list "Manage Reports"]
+lappend context $current_item(label)
\ No newline at end of file
Index: openacs-4/packages/survey-reports/www/manage/index.vuh
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/www/manage/index.vuh,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/www/manage/index.vuh 14 Nov 2005 04:31:02 -0000 1.2
@@ -0,0 +1,45 @@
+# packages/survey/www/admin/reports/manage/index.vuh
+#
+# manage survey reports
+# a lot of these were taken from xcms and bcms so credits go out alsto
+# to DaveB and Jun Yamog
+#
+# @author Deds Castillo (deds@i-manila.com.ph)
+# @creation-date 2004-10-21
+# @arch-tag: ba5fb6a6-a8b8-4fe3-bdc2-4a9862e50f9f
+# @cvs-id $Id: index.vuh,v 1.2 2005/11/14 04:31:02 daveb Exp $
+
+set the_url "[ad_conn path_info]"
+if {$the_url eq ""} {
+ set the_url "/"
+}
+permission::require_permission \
+ -object_id [ad_conn package_id] \
+ -party_id [ad_conn user_id] \
+ -privilege admin
+
+
+set report_folder_id [survey::report::get_root_folder -package_id [ad_conn package_id]]
+
+set item_id [content::item::get_id \
+ -root_folder_id $report_folder_id \
+ -item_path $the_url ]
+
+content::item::get -item_id $item_id -revision latest -array_name item
+
+if {[array size item] == 0} {
+ ns_returnnotfound
+}
+
+rp_form_put item [array get item]
+
+switch -- $item(content_type) {
+ content_folder {
+ rp_internal_redirect "folder-view"
+ }
+
+ default { # content_template
+ rp_internal_redirect "template-view"
+ }
+
+}
Index: openacs-4/packages/survey-reports/www/manage/master.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/survey-reports/www/manage/master.adp,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/survey-reports/www/manage/master.adp 14 Nov 2005 04:31:02 -0000 1.2
@@ -0,0 +1,11 @@
+
+ @title@
+ @header_stuff;noquote@
+ @context;noquote@
+ @focus@
+
+