Index: openacs-4/packages/survey/survey.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/survey.info,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/survey.info 15 Sep 2002 23:56:54 -0000 1.1 @@ -0,0 +1,189 @@ + + + + + Survey + Surveys + f + f + + + + oracle + postgresql + + Dave Bauer + Luke Pond + New version of survey package for dotLRN/OpenACS4.5 + dotLRN + New version of survey package for dotLRN/OpenACS4.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: openacs-4/packages/survey/sql/oracle/diff =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/sql/oracle/Attic/diff,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/sql/oracle/diff 15 Sep 2002 23:57:20 -0000 1.1 @@ -0,0 +1,30 @@ +Index: survey-create.sql +=================================================================== +RCS file: /usr/local/cvsroot/ssv2/packages/survey/sql/oracle/survey-create.sql,v +retrieving revision 1.5 +diff -r1.5 survey-create.sql +120c120 +< title varchar(4000) +--- +> name varchar(4000) +131c131 +< -- each question can be +--- +> create index survey_sections_survey_id_fk on survey_sections(survey_id); +140,141c140,141 +< sort_key integer +< constraint survey_q_sort_key_nn +--- +> sort_order integer +> constraint survey_q_sort_order_nn +167a168,170 +> create index survey_q_sort_order on survey_questions(sort_order); +> create index survey_q_active_p on survey_questions(active_p); +> +189a193,195 +> create index survey_q_c_question_id on survey_question_choices(question_id); +> create index survey_q_c_sort_order on survey_question_choices(sort_order); +> +231a238,239 +> create index survey_q_r_choice_id on survey_question_responses(choice_id); +> create index survey_q_r_attachment_answer on survey_question_responses(attachment_answer); Index: openacs-4/packages/survey/sql/oracle/survey-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/sql/oracle/survey-create.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/sql/oracle/survey-create.sql 15 Sep 2002 23:57:20 -0000 1.1 @@ -0,0 +1,242 @@ +-- based on student work from 6.916 in Fall 1999 +-- which was in turn based on problem set 4 +-- in http://photo.net/teaching/one-term-web.html +-- +-- by philg@mit.edu and raj@alum.mit.edu on February 9, 2000 +-- converted to ACS 4.0 by nstrug@arsdigita.com on 29th September 2000 +-- modified for dotLRN/OpenACS4.5 and renamed from "simple-survey" to "survey" +-- by dave@thedesignexperience.org on 13 July 2002 +-- +-- $Id: survey-create.sql,v 1.1 2002/09/15 23:57:20 daveb Exp $ + +begin + + acs_privilege.create_privilege('survey_create_survey'); + acs_privilege.create_privilege('survey_modify_survey'); + acs_privilege.create_privilege('survey_delete_survey'); + acs_privilege.create_privilege('survey_create_question'); + acs_privilege.create_privilege('survey_modify_question'); + acs_privilege.create_privilege('survey_delete_question'); + acs_privilege.create_privilege('survey_take_survey'); + + acs_privilege.create_privilege('survey_admin_survey'); + + acs_privilege.add_child('survey_admin_survey','survey_create_survey'); + acs_privilege.add_child('survey_admin_survey','survey_modify_survey'); + acs_privilege.add_child('survey_admin_survey','survey_delete_survey'); + acs_privilege.add_child('survey_admin_survey','survey_create_question'); + acs_privilege.add_child('survey_admin_survey','survey_modify_question'); + acs_privilege.add_child('survey_admin_survey','survey_delete_question'); + + acs_privilege.add_child('read','survey_take_survey'); + acs_privilege.add_child('admin','survey_admin_survey'); + + acs_object_type.create_type ( + supertype => 'acs_object', + object_type => 'survey', + pretty_name => 'Survey', + pretty_plural => 'Surveys', + table_name => 'SURVEYS', + id_column => 'SURVEY_ID', + name_method => 'survey.name' + ); + acs_object_type.create_type ( + supertype => 'acs_object', + object_type => 'survey_section', + pretty_name => 'Survey_Section', + pretty_plural => 'Survey_Sections', + table_name => 'SURVEY_SECTIONS', + id_column => 'SECTION_ID' + ); + + acs_object_type.create_type ( + supertype => 'acs_object', + object_type => 'survey_question', + pretty_name => 'Survey Question', + pretty_plural => 'Survey Questions', + table_name => 'SURVEY_QUESTIONS', + id_column => 'QUESTION_ID' + ); + + acs_object_type.create_type ( + supertype => 'acs_object', + object_type => 'survey_response', + pretty_name => 'Survey Response', + pretty_plural => 'Survey Responses', + table_name => 'SURVEY_RESPONSES', + id_column => 'RESPONSE_ID' + ); + + +end; +/ +show errors + +create table surveys ( + survey_id constraint surveys_survey_id_fk + references acs_objects (object_id) + constraint surveys_pk + primary key, + name varchar(4000) + constraint surveys_name_nn + not null, + description varchar(4000) + constraint surveys_desc_nn + not null, + description_html_p char(1) + constraint surveys_desc_html_p_ck + check(description_html_p in ('t','f')), + enabled_p char(1) + constraint surveys_enabled_p_ck + check(enabled_p in ('t','f')), + -- limit to one response per user + single_response_p char(1) + constraint surveys_single_resp_p_ck + check(single_response_p in ('t','f')), + editable_p char(1) + constraint surveys_single_edit_p_ck + check(editable_p in ('t','f')), + single_section_p char(1) + constraint surveys_single_section_p_ck + check(single_section_p in ('t','f')), + type varchar(20), + display_type varchar(20), + package_id integer + constraint surveys_package_id_nn not null + constraint surveys_package_id_fk references + apm_packages (package_id) on delete cascade +); + +create table survey_sections ( + section_id constraint survey_sections_section_id_fk + references acs_objects (object_id) + constraint survey_sections_pk + primary key, + survey_id integer + constraint survey_sections_survey_id_nn + not null + constraint survey_sections_survey_id_fk + references surveys, + name varchar(4000) + constraint survey_sections_name_nn + not null, + description clob + constraint survey_sections_desc_nn + not null, + description_html_p char(1) + constraint survey_sections_desc_html_p_ck + check(description_html_p in ('t','f')) +); + +create index survey_sections_survey_id_fk on survey_sections(survey_id); + +create table survey_questions ( + question_id constraint survey_q_question_id_fk + references acs_objects (object_id) + constraint survey_q_question_id_pk + primary key, + section_id constraint survey_q_section_id_fk + references survey_sections, + sort_order integer + constraint survey_q_sort_order_nn + not null, + question_text clob + constraint survey_q_question_text_nn + not null, + abstract_data_type varchar(30) + constraint survey_q_abs_data_type_ck + check (abstract_data_type in ('text', 'shorttext', 'boolean', 'number', 'integer', 'choice', 'date','blob')), + required_p char(1) + constraint survey_q_required_p_ck + check (required_p in ('t','f')), + active_p char(1) + constraint survey_q_qctive_p_ck + check (active_p in ('t','f')), + presentation_type varchar(20) + constraint survey_q_pres_type_nn + not null + constraint survey_q_pres_type_ck + check(presentation_type in ('textbox','textarea','select','radio', 'checkbox', 'date', 'upload_file')), + -- for text, "small", "medium", "large" sizes + -- for textarea, "rows=X cols=X" + presentation_options varchar(50), + presentation_alignment varchar(15) + constraint survey_q_pres_alignment_ck + check(presentation_alignment in ('below','beside')) +); + +create index survey_q_sort_order on survey_questions(sort_order); +create index survey_q_active_p on survey_questions(active_p); + +-- for when a question has a fixed set of responses + +create sequence survey_choice_id_sequence start with 1; + +create table survey_question_choices ( + choice_id integer constraint survey_qc_choice_id_nn + not null + constraint survey_qc_choice_id_pk + primary key, + question_id constraint survey_qc_question_id_nn + not null + constraint survey_qc_question_id_fk + references survey_questions, + -- human readable + label varchar(500) constraint survey_qc_label_nn + not null, + -- might be useful for averaging or whatever, generally null + numeric_value number, + -- lower is earlier + sort_order integer +); + +create index survey_q_c_question_id on survey_question_choices(question_id); +create index survey_q_c_sort_order on survey_question_choices(sort_order); + +-- this records a response by one user to one survey +-- (could also be a proposal in which case we'll do funny +-- things like let the user give it a title, send him or her +-- email if someone comments on it, etc.) +create table survey_responses ( + response_id constraint survey_resp_response_id_fk + references acs_objects (object_id) + constraint srvsimp_resp_response_id_pk + primary key, + initial_response_id constraint init_resp_id_fk + references survey_responses (response_id), + survey_id constraint survey_resp_survey_id_fk + references surveys, + title varchar(100), + notify_on_comment_p char(1) + constraint survey_resp_noton_com_p_ck + check(notify_on_comment_p in ('t','f')) +); + + + +-- this table stores the answers to each question for a survey +-- we want to be able to hold different data types in one long skinny table +-- but we also may want to do averages, etc., so we can't just use CLOBs + +create table survey_question_responses ( + response_id not null references survey_responses, + question_id not null references survey_questions, + -- if the user picked a canned response + choice_id references survey_question_choices, + boolean_answer char(1) check(boolean_answer in ('t','f')), + clob_answer clob, + number_answer number, + varchar_answer varchar(4000), + date_answer date, + attachment_answer integer + constraint survey_q_resp_rev_id_fk + references cr_revisions(revision_id) + on delete cascade +); + +create index survey_response_index on survey_question_responses (response_id, question_id); +create index survey_q_r_choice_id on survey_question_responses(choice_id); +create index survey_q_r_attachment_answer on survey_question_responses(attachment_answer); + +@@ survey-package-create.sql +@@ survey-notifications-init.sql \ No newline at end of file Index: openacs-4/packages/survey/sql/oracle/survey-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/sql/oracle/survey-drop.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/sql/oracle/survey-drop.sql 15 Sep 2002 23:57:20 -0000 1.1 @@ -0,0 +1,60 @@ +-- +-- drop SQL for survey package +-- +-- by nstrug@arsdigita.com on 29th September 2000 +-- +-- $Id: survey-drop.sql,v 1.1 2002/09/15 23:57:20 daveb Exp $ + +@@ survey-package-drop.sql + + +drop view survey_question_responses_un; +drop table survey_question_responses cascade constraints; +drop view survey_responses_unique; +drop table survey_responses cascade constraints; +drop table survey_question_choices cascade constraints; + +drop sequence survey_choice_id_sequence; +drop table survey_questions cascade constraints; +drop table survey_sections cascade constraints; +drop table surveys cascade constraints; + +-- nuke all created objects +-- need to do this before nuking the types +delete from acs_objects where object_type = 'survey_response'; +delete from acs_objects where object_type = 'survey_question'; +delete from acs_objects where object_type = 'survey_section'; +delete from acs_objects where object_type = 'survey'; + +begin + acs_rel_type.drop_type('user_blob_response_rel'); + + acs_object_type.drop_type ('survey_response'); + acs_object_type.drop_type ('survey_question'); + acs_object_type.drop_type ('survey_section'); + acs_object_type.drop_type ('survey'); + + acs_privilege.remove_child ('admin','survey_admin_survey'); + acs_privilege.remove_child ('read','survey_take_survey'); + acs_privilege.remove_child ('survey_admin_survey','survey_delete_question'); + acs_privilege.remove_child ('survey_admin_survey','survey_modify_question'); + acs_privilege.remove_child ('survey_admin_survey','survey_create_question'); + acs_privilege.remove_child ('survey_admin_survey','survey_delete_survey'); + acs_privilege.remove_child ('survey_admin_survey','survey_modify_survey'); + acs_privilege.remove_child ('survey_admin_survey','survey_create_survey'); + + acs_privilege.drop_privilege('survey_admin_survey'); + acs_privilege.drop_privilege('survey_take_survey'); + acs_privilege.drop_privilege('survey_delete_question'); + acs_privilege.drop_privilege('survey_modify_question'); + acs_privilege.drop_privilege('survey_create_question'); + acs_privilege.drop_privilege('survey_delete_survey'); + acs_privilege.drop_privilege('survey_modify_survey'); + acs_privilege.drop_privilege('survey_create_survey'); + + +end; +/ +show errors + + Index: openacs-4/packages/survey/sql/oracle/survey-notifications-init.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/sql/oracle/survey-notifications-init.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/sql/oracle/survey-notifications-init.sql 15 Sep 2002 23:57:20 -0000 1.1 @@ -0,0 +1,62 @@ +-- +-- Survey +-- +-- -- @author dave@thedesignexperience.org, ben@openforce.biz +-- @creation-date 2002-08-03 +-- +-- integration with Notifications +declare + impl_id integer; + v_foo integer; +begin + -- the notification type impl + impl_id := acs_sc_impl.new ( + 'NotificationType', + 'survey_response_notif_type', + 'survey' + ); + + v_foo := acs_sc_impl.new_alias ( + 'NotificationType', + 'survey_response_notif_type', + 'GetURL', + 'survey::notification::get_url', + 'TCL' + ); + + v_foo := acs_sc_impl.new_alias ( + 'NotificationType', + 'survey_response_notif_type', + 'ProcessReply', + 'survey::notification::process_reply', + 'TCL' + ); + + acs_sc_binding.new ( + contract_name => 'NotificationType', + impl_name => 'survey_response_notif_type' + ); + + v_foo:= notification_type.new ( + short_name => 'survey_response_notif', + sc_impl_id => impl_id, + pretty_name => 'Survey Response', + description => 'Notifications for Survey', + creation_user => NULL, + creation_ip => NULL + ); + + -- enable the various intervals and delivery methods + insert into notification_types_intervals + (type_id, interval_id) + select v_foo, interval_id + from notification_intervals where name in ('instant','hourly','daily'); + + insert into notification_types_del_methods + (type_id, delivery_method_id) + select v_foo, delivery_method_id + from notification_delivery_methods where short_name in ('email'); + +end; +/ +show errors Index: openacs-4/packages/survey/sql/oracle/survey-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/sql/oracle/survey-package-create.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/sql/oracle/survey-package-create.sql 15 Sep 2002 23:57:20 -0000 1.1 @@ -0,0 +1,484 @@ +-- start off with package declarations + + +create or replace package survey +as + function new ( + survey_id in surveys.survey_id%TYPE default null, + name in surveys.name%TYPE, + description in surveys.description%TYPE, + description_html_p in surveys.description_html_p%TYPE default 'f', + single_response_p in surveys.single_response_p%TYPE default 'f', + editable_p in surveys.editable_p%TYPE default 't', + enabled_p in surveys.enabled_p%TYPE default 'f', + single_section_p in surveys.single_section_p%TYPE default 't', + type in surveys.type%TYPE default 'general', + display_type in surveys.display_type%TYPE default 'list', + package_id in surveys.package_id%TYPE, + object_type in acs_objects.object_type%TYPE default 'survey', + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE default null, + creation_ip in acs_objects.creation_ip%TYPE default null, + context_id in acs_objects.context_id%TYPE default null +) return acs_objects.object_id%TYPE; + + procedure remove ( + survey_id in surveys.survey_id%TYPE + ); + + function name ( + survey_id in surveys.survey_id%TYPE + ) return varchar; + +end survey; +/ +show errors + + + +-- survey_section + +create or replace package survey_section +as + function new ( + section_id in survey_sections.section_id%TYPE default null, + survey_id in survey_sections.survey_id%TYPE default null, + name in survey_sections.name%TYPE default null, + description in survey_sections.description%TYPE default null, + description_html_p in survey_sections.description_html_p%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'survey_section', + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE default null, + creation_ip in acs_objects.creation_ip%TYPE default null, + context_id in acs_objects.context_id%TYPE default null + ) return acs_objects.object_id%TYPE; + + procedure remove ( + section_id in survey_sections.section_id%TYPE + ); +end survey_section; +/ +show errors + +-- +-- constructor for a survey_question +-- + +create or replace package survey_question +as + function new ( + question_id in survey_questions.question_id%TYPE default null, + section_id in survey_questions.section_id%TYPE default null, + sort_order in survey_questions.sort_order%TYPE default null, + question_text in survey_questions.question_text%TYPE default null, + abstract_data_type in survey_questions.abstract_data_type%TYPE default null, + required_p in survey_questions.required_p%TYPE default 't', + active_p in survey_questions.active_p%TYPE default 't', + presentation_type in survey_questions.presentation_type%TYPE default null, + presentation_options in survey_questions.presentation_options%TYPE default null, + presentation_alignment in survey_questions.presentation_alignment%TYPE default 'below', + object_type in acs_objects.object_type%TYPE default 'survey_question', + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE default null, + creation_ip in acs_objects.creation_ip%TYPE default null, + context_id in acs_objects.context_id%TYPE default null + ) return acs_objects.object_id%TYPE; + + procedure remove ( + question_id in survey_questions.question_id%TYPE + ); +end survey_question; +/ +show errors + + +-- +-- constructor for a survey_response +-- + +create or replace package survey_response +as + function new ( + response_id in survey_responses.response_id %TYPE default null, + survey_id in survey_responses.survey_id%TYPE default null, + title in survey_responses.title%TYPE default null, + notify_on_comment_p in survey_responses.notify_on_comment_p%TYPE default 'f', + object_type in acs_objects.object_type%TYPE default 'survey_response', + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE default null, + creation_ip in acs_objects.creation_ip%TYPE default null, + context_id in acs_objects.context_id%TYPE default null, + initial_response_id in survey_responses.initial_response_id%TYPE default null + ) return acs_objects.object_id%TYPE; + + function initial_response_id ( + response_id in survey_responses.response_id%TYPE + ) return survey_responses.response_id%TYPE; + + function initial_user_id ( + response_id in survey_responses.response_id%TYPE + ) return acs_objects.creation_user%TYPE; + + procedure remove ( + response_id in survey_responses.response_id%TYPE + ); + + procedure del ( + response_id in survey_responses.response_id%TYPE + ); + + function boolean_answer ( + answer varchar, + question_id survey_questions.question_id%TYPE + ) return varchar; + +end survey_response; +/ +show errors + + +-- next we define the package bodies + +create or replace package body survey +as + function new ( + survey_id in surveys.survey_id%TYPE default null, + name in surveys.name%TYPE, + description in surveys.description%TYPE, + description_html_p in surveys.description_html_p%TYPE default 'f', + single_response_p in surveys.single_response_p%TYPE default 'f', + editable_p in surveys.editable_p%TYPE default 't', + enabled_p in surveys.enabled_p%TYPE default 'f', + single_section_p in surveys.single_section_p%TYPE default 't', + type in surveys.type%TYPE default 'general', + display_type in surveys.display_type%TYPE default 'list', + package_id in surveys.package_id%TYPE, + object_type in acs_objects.object_type%TYPE default 'survey', + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE default null, + creation_ip in acs_objects.creation_ip%TYPE default null, + context_id in acs_objects.context_id%TYPE default null + ) return acs_objects.object_id%TYPE + is + v_survey_id surveys.survey_id%TYPE; + begin + v_survey_id := acs_object.new ( + object_id => survey_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => context_id + ); + insert into surveys + (survey_id, name, description, description_html_p, + single_response_p, editable_p, enabled_p, single_section_p, type, display_type, package_id) + values + (v_survey_id, new.name, new.description, new.description_html_p, + new.single_response_p, new.editable_p, new.enabled_p, new.single_section_p, new.type, new.display_type, new.package_id); + + return v_survey_id; + end new; + + procedure remove ( + survey_id surveys.survey_id%TYPE + ) + is + v_response_row survey_responses%ROWTYPE; + v_section_row survey_sections%ROWTYPE; + begin + + for v_response_row in (select response_id + from survey_responses + where survey_id=remove.survey_id + and initial_response_id is NULL) loop + survey_response.remove(v_response_row.response_id); + end loop; + + for v_section_row in (select section_id + from survey_sections + where survey_id=remove.survey_id) loop + survey_section.remove(v_section_row.section_id); + end loop; + + delete from surveys where survey_id=remove.survey_id; + acs_object.delete(survey_id); + end remove; + + function name ( + survey_id in surveys.survey_id%TYPE + ) return varchar + is + v_name surveys.name%TYPE; + begin + select name + into v_name + from surveys + where survey_id = name.survey_id; + + return v_name; + end name; +end survey; +/ +show errors + + +create or replace package body survey_section +as + function new ( + section_id in survey_sections.section_id%TYPE default null, + survey_id in survey_sections.survey_id%TYPE default null, + name in survey_sections.name%TYPE default null, + description in survey_sections.description%TYPE default null, + description_html_p in survey_sections.description_html_p%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'survey_section', + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE default null, + creation_ip in acs_objects.creation_ip%TYPE default null, + context_id in acs_objects.context_id%TYPE default null + + ) return acs_objects.object_id%TYPE + is + v_section_id survey_sections.section_id%TYPE; + begin + v_section_id := acs_object.new ( + object_id => section_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => context_id + ); + insert into survey_sections + (section_id, survey_id, name, description, description_html_p) + values + (v_section_id, new.survey_id, new.name, new.description, new.description_html_p); + + return v_section_id; + end new; + + procedure remove ( + section_id in survey_sections.section_id%TYPE + ) is + v_question_row survey_questions%ROWTYPE; + begin + for v_question_row in (select question_id + from survey_questions + where section_id=remove.section_id) loop + survey_question.remove(v_question_row.question_id); + end loop; + delete from survey_sections where section_id=remove.section_id; + acs_object.delete(remove.section_id); + end remove; +end survey_section; +/ +show errors + + +create or replace package body survey_question +as + function new ( + question_id in survey_questions.question_id%TYPE default null, + section_id in survey_questions.section_id%TYPE default null, + sort_order in survey_questions.sort_order%TYPE default null, + question_text in survey_questions.question_text%TYPE default null, + abstract_data_type in survey_questions.abstract_data_type%TYPE default null, + required_p in survey_questions.required_p%TYPE default 't', + active_p in survey_questions.active_p%TYPE default 't', + presentation_type in survey_questions.presentation_type%TYPE default null, + presentation_options in survey_questions.presentation_options%TYPE default null, + presentation_alignment in survey_questions.presentation_alignment%TYPE default 'below', + object_type in acs_objects.object_type%TYPE default 'survey_question', + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE default null, + creation_ip in acs_objects.creation_ip%TYPE default null, + context_id in acs_objects.context_id%TYPE default null + ) return acs_objects.object_id%TYPE + is + v_question_id survey_questions.question_id%TYPE; + begin + v_question_id := acs_object.new ( + object_id => question_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => section_id + ); + insert into survey_questions + (question_id, section_id, sort_order, question_text, abstract_data_type, + required_p, active_p, presentation_type, presentation_options, + presentation_alignment) + values + (v_question_id, new.section_id, new.sort_order, new.question_text, new.abstract_data_type, + new.required_p, new.active_p, new.presentation_type, new.presentation_options, + new.presentation_alignment); + return v_question_id; + end new; + + procedure remove ( + question_id in survey_questions.question_id%TYPE + ) + is + begin + + delete from survey_question_responses + where question_id=remove.question_id; + delete from survey_question_choices + where question_id=remove.question_id; + delete from survey_questions + where question_id = remove.question_id; + acs_object.delete(remove.question_id); + end remove; +end survey_question; +/ +show errors + + +create or replace package body survey_response +as + function new ( + response_id in survey_responses.response_id %TYPE default null, + survey_id in survey_responses.survey_id%TYPE default null, + title in survey_responses.title%TYPE default null, + notify_on_comment_p in survey_responses.notify_on_comment_p%TYPE default 'f', + object_type in acs_objects.object_type%TYPE default 'survey_response', + creation_date in acs_objects.creation_date%TYPE default sysdate, + creation_user in acs_objects.creation_user%TYPE default null, + creation_ip in acs_objects.creation_ip%TYPE default null, + context_id in acs_objects.context_id%TYPE default null, + initial_response_id in survey_responses.initial_response_id%TYPE default null + ) return acs_objects.object_id%TYPE + is + v_response_id survey_responses.response_id%TYPE; + begin + v_response_id := acs_object.new ( + object_id => response_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip, + context_id => context_id + ); + insert into survey_responses (response_id, survey_id, title, notify_on_comment_p, initial_response_id) + values + (v_response_id, new.survey_id, new.title, new.notify_on_comment_p, new.initial_response_id); + return v_response_id; + end new; + + function initial_response_id ( + response_id in survey_responses.response_id%TYPE + ) return survey_responses.response_id%TYPE + is + v_initial_response_id survey_responses.response_id%TYPE; + begin + select initial_response_id into v_initial_response_id + from survey_responses where + response_id = initial_response_id.response_id; + if v_initial_response_id is NULL then + v_initial_response_id := initial_response_id.response_id; + end if; + return v_initial_response_id; + end initial_response_id; + + function initial_user_id ( + response_id in survey_responses.response_id%TYPE + ) return acs_objects.creation_user%TYPE + is + v_user_id acs_objects.creation_user%TYPE; + begin + select creation_user into v_user_id + from acs_objects + where object_id = survey_response.initial_response_id(initial_user_id.response_id); + return v_user_id; + end initial_user_id; + + procedure remove ( + response_id in survey_responses.response_id%TYPE + ) is + v_response_row survey_responses%ROWTYPE; + begin + for v_response_row in (select response_id from survey_responses + where initial_response_id=remove.response_id) loop + survey_response.del(v_response_row.response_id); + end loop; + + survey_response.del(remove.response_id); + end remove; + + procedure del ( + response_id in survey_responses.response_id%TYPE + ) + is + v_question_response_row survey_question_responses%ROWTYPE; + begin + for v_question_response_row in ( + select item_id + from survey_question_responses, cr_revisions + where response_id=del.response_id + and attachment_answer=revision_id) + loop + content_item.delete(v_question_response_row.item_id); + end loop; + + delete from survey_question_responses + where response_id=del.response_id; + delete from survey_responses + where response_id=del.response_id; + acs_object.delete(del.response_id); + end del; + + function boolean_answer ( + answer varchar, + question_id survey_questions.question_id%TYPE + ) return varchar + is + v_answer varchar(100); + v_presentation_options survey_questions.presentation_options%TYPE; + v_split_pos integer; + begin + + if answer is NOT NULL then + select presentation_options into v_presentation_options + from survey_questions where question_id=boolean_answer.question_id; + + v_split_pos:= instr(v_presentation_options, '/'); + + if answer = 't' then + v_answer:=substr(v_presentation_options, 1, v_split_pos -1 ); + end if; + if answer = 'f' then + v_answer:=substr(v_presentation_options, v_split_pos + 1 ); + end if; + + else + v_answer := ''; + end if; + return v_answer; + end boolean_answer; + +end survey_response; +/ +show errors + + +-- these views depend on functions in this file -DaveB +-- this view contains only the most recently edited version +-- of each survey response. + +create or replace view survey_responses_latest as +select sr.*, o.creation_date, + o.creation_user, + survey_response.initial_user_id(sr.response_id) as initial_user_id + from survey_responses sr, + acs_objects o, + (select max(response_id) as response_id + from survey_responses + group by survey_response.initial_response_id(response_id)) latest + where sr.response_id = o.object_id + and sr.response_id= latest.response_id; + +create or replace view survey_ques_responses_latest as +select qr.* + from survey_question_responses qr, survey_responses_latest r + where qr.response_id=r.response_id; Index: openacs-4/packages/survey/sql/oracle/survey-package-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/sql/oracle/survey-package-drop.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/sql/oracle/survey-package-drop.sql 15 Sep 2002 23:57:20 -0000 1.1 @@ -0,0 +1,4 @@ +drop package survey_response; +drop package survey_question; +drop package survey_section; +drop package survey; Index: openacs-4/packages/survey/sql/postgresql/survey-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/sql/postgresql/survey-create.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/sql/postgresql/survey-create.sql 15 Sep 2002 23:57:48 -0000 1.1 @@ -0,0 +1,567 @@ +-- ported to OpenACS 4 by Gilbert Wong (gwong@orchardlabs.com) on 2001-05-20 +-- +-- based on student work from 6.916 in Fall 1999 +-- which was in turn based on problem set 4 +-- in http://photo.net/teaching/one-term-web.html +-- +-- by philg@mit.edu and raj@alum.mit.edu on February 9, 2000 +-- converted to ACS 4.0 by nstrug@arsdigita.com on 29th September 2000 +-- modified for dotLRN/OpenACS4.5 and renamed from "simple-survey" to "survey" +-- by dave@thedesignexperience.org on 13 July 2002 +-- +-- $Id: survey-create.sql,v 1.1 2002/09/15 23:57:48 daveb Exp $ + +create function inline_0 () +returns integer as ' +begin + PERFORM acs_privilege__create_privilege(''survey_create_survey'', null, null); + PERFORM acs_privilege__create_privilege(''survey_modify_survey'', null, null); + PERFORM acs_privilege__create_privilege(''survey_delete_survey'', null, null); + PERFORM acs_privilege__create_privilege(''survey_create_question'', null, null); + PERFORM acs_privilege__create_privilege(''survey_modify_question'', null, null); + PERFORM acs_privilege__create_privilege(''survey_delete_question'', null, null); + PERFORM acs_privilege__create_privilege(''survey_take_survey'', null, null); + PERFORM acs_privilege__create_privilege(''survey_admin_survey'', null, null); + + return 0; + +end;' language 'plpgsql'; + +select inline_0 (); +drop function inline_0 (); + + +begin; + -- temporarily drop this trigger to avoid a data-change violation + -- on acs_privilege_hierarchy_index while updating the child privileges. + drop trigger acs_priv_hier_ins_del_tr on acs_privilege_hierarchy; + + select acs_privilege__add_child('survey_admin_survey','survey_create_survey'); + select acs_privilege__add_child('survey_admin_survey','survey_modify_survey'); + select acs_privilege__add_child('survey_admin_survey','survey_delete_survey'); + select acs_privilege__add_child('survey_admin_survey','survey_create_question'); + select acs_privilege__add_child('survey_admin_survey','survey_modify_question'); + select acs_privilege__add_child('survey_admin_survey','survey_delete_question'); + + select acs_privilege__add_child('read','survey_take_survey'); + + -- re-enable the trigger before the last insert to force the + -- acs_privilege_hierarchy_index table to be updated. + + create trigger acs_priv_hier_ins_del_tr after insert or delete + on acs_privilege_hierarchy for each row + execute procedure acs_priv_hier_ins_del_tr (); + + select acs_privilege__add_child('admin','survey_admin_survey'); + +end; + + + +create function inline_1 () +returns integer as ' +begin + + PERFORM acs_object_type__create_type ( + ''survey'', + ''Survey'', + ''Surveys'', + ''acs_object'', + ''surveys'', + ''survey_id'', + null, + ''f'', + null, + null + ); + + PERFORM acs_object_type__create_type ( + ''survey_section'', + ''Survey Section'', + ''Survey Sections'', + ''acs_object'', + ''survey_sections'', + ''section_id'', + null, + ''f'', + null, + null + ); + + PERFORM acs_object_type__create_type ( + ''survey_question'', + ''Survey Question'', + ''Survey Questions'', + ''acs_object'', + ''survey_questions'', + ''question_id'', + null, + ''f'', + null, + null + ); + + PERFORM acs_object_type__create_type ( + ''survey_response'', + ''Survey Response'', + ''Survey Responses'', + ''acs_object'', + ''survey_responses'', + ''response_id'', + null, + ''f'', + null, + null + ); + + return 0; + +end;' language 'plpgsql'; + +select inline_1 (); +drop function inline_1 (); + +create table surveys ( + survey_id integer constraint surveys_survey_id_fk + references acs_objects (object_id) + on delete cascade + constraint surveys_pk + primary key, + name varchar(4000) + constraint surveys_name_nn + not null, + description text + constraint surveys_desc_nn + not null, + description_html_p boolean not null, + enabled_p boolean not null, + -- limit to one response per user + single_response_p boolean not null, + editable_p boolean not null, + single_section_p boolean not null, + type varchar(20), + display_type varchar(20), + package_id integer constraint surveys_package_id_nn + not null + constraint surveys_package_id_fk + references apm_packages (package_id) on delete cascade +); + + +create table survey_sections ( + section_id integer constraint survey_sections_section_id_fk + references acs_objects (object_id) + constraint survey_sections_pk + primary key, + survey_id integer + constraint survey_sections_survey_id_nn + not null + constraint survey_sections_survey_id_fk + references surveys, + name varchar(4000) + constraint survey_sections_name_nn + not null, + description text + constraint survey_sections_desc_nn + not null, + description_html_p boolean +); + +create index survey_sections_survey_id_fk on survey_sections(survey_id); +-- each question can be + +create table survey_questions ( + question_id integer constraint survey_q_question_id_fk + references acs_objects (object_id) + on delete cascade + constraint survey_q_question_id_pk + primary key, + section_id integer constraint survey_q_section_id_fk + references survey_sections + on delete cascade, + sort_order integer + constraint survey_q_sort_order_nn + not null, + question_text text + constraint survey_q_question_text_nn + not null, + abstract_data_type varchar(30) + constraint survey_q_abs_data_type_ck + check (abstract_data_type in ('text', 'shorttext', 'boolean', 'number', 'integer', 'choice','date')), + required_p boolean, + active_p boolean, + presentation_type varchar(20) + constraint survey_q_pres_type_nn + not null + constraint survey_q_pres_type_ck + check(presentation_type in ('textbox','textarea','select','radio', 'checkbox', 'date', 'upload_file')), + -- for text, "small", "medium", "large" sizes + -- for textarea, "rows=X cols=X" + presentation_options varchar(50), + presentation_alignment varchar(15) + constraint survey_q_pres_alignment_ck + check(presentation_alignment in ('below','beside')) +); + + +create index survey_q_sort_order on survey_questions(sort_order); +create index survey_q_active_p on survey_questions(active_p); + +-- for when a question has a fixed set of responses + +create sequence survey_choice_id_seq; +create view survey_choice_id_sequence as select nextval('survey_choice_id_seq') as nextval; + +create table survey_question_choices ( + choice_id integer constraint survey_qc_choice_id_nn + not null + constraint survey_qc_choice_id_pk + primary key, + question_id integer constraint survey_qc_question_id_nn + not null + constraint survey_qc_question_id_fk + references survey_questions + on delete cascade, + -- human readable + label varchar(500) constraint survey_qc_label_nn + not null, + -- might be useful for averaging or whatever, generally null + numeric_value numeric, + -- lower is earlier + sort_order integer +); + + +create index survey_q_c_question_id on survey_question_choices(question_id); +create index survey_q_c_sort_order on survey_question_choices(sort_order); + +-- this records a response by one user to one survey +-- (could also be a proposal in which case we'll do funny +-- things like let the user give it a title, send him or her +-- email if someone comments on it, etc.) +create table survey_responses ( + response_id integer constraint survey_resp_response_id_fk + references acs_objects (object_id) + on delete cascade + constraint survey_resp_response_id_pk + primary key, + initial_response_id integer constraint survey_resp_initial_fk + references survey_responses(response_id), + survey_id integer constraint survey_resp_survey_id_fk + references surveys + on delete cascade, + title varchar(100), + notify_on_comment_p boolean +); + + +create index survey_response_index on survey_question_responses (response_id, question_id); +create index survey_q_r_choice_id on survey_question_responses(choice_id); +create index survey_q_r_attachment_answer on survey_question_responses(attachment_answer); + + +-- this view contains only the most recently edited version +-- of each survey response. + +create view survey_responses_latest as +select sr.*, o.creation_date, + o.creation_user, + survey_response__initial_user_id(sr.response_id) as initial_user_id + from survey_responses sr + join acs_objects o + on (sr.response_id = o.object_id) + join (select max(response_id) as response_id + from survey_responses + group by survey_response__initial_response_id(response_id)) latest + on (sr.response_id = latest.response_id); + + + +-- this table stores the answers to each question for a survey +-- we want to be able to hold different data types in one long skinny table +-- but we also may want to do averages, etc., so we can't just use CLOBs + +create table survey_question_responses ( + response_id integer constraint survey_qr_response_id_nn + not null + constraint survey_qr_response_id_fk + references survey_responses + on delete cascade, + question_id integer constraint survey_qr_question_id_nn + not null + constraint survey_qr_question_id_fk + references survey_questions + on delete cascade, + -- if the user picked a canned response + choice_id integer constraint survey_qr_choice_id_fk + references survey_question_choices + on delete cascade, + boolean_answer boolean, + clob_answer text, + number_answer numeric, + varchar_answer text, + date_answer timestamp, + attachment_answer integer + constraint survey_q_response_item_id_fk + references cr_items(item_id) + on delete cascade +); + + +create or replace view survey_ques_responses_latest as +select qr.* + from survey_question_responses qr, survey_responses_latest r + where qr.response_id=r.response_id; + + + +create index survey_response_index on survey_question_responses (response_id, question_id); + +-- We create a view that selects out only the last response from each +-- user to give us at most 1 response from all users. +-- create or replace view survey_question_responses_un as +-- select qr.* +-- from survey_question_responses qr, survey_responses_unique r +-- where qr.response_id=r.response_id; + + +-- API for survey objects + +create function survey__new (integer,varchar,text,boolean,boolean,boolean,boolean,boolean,varchar,varchar,integer,integer,integer) +returns integer as ' +declare + new__survey_id alias for $1; -- default null + new__name alias for $2; + new__description alias for $3; + new__description_html_p alias for $4; -- default f + new__single_response_p alias for $5; -- default f + new__editable_p alias for $6; -- default t + new__enabled_p alias for $7; -- default f + new__single_section_p alias for $8; -- default t + new__type alias for $9; -- default general + new__display_type alias for $10; + new__package_id alias for $11; + new__creation_user alias for $12; -- default null + new__context_id alias for $13; -- default null + v_survey_id integer; +begin + v_survey_id := acs_object__new ( + new__survey_id, + ''survey'', + now(), + new__creation_user, + null, + new__context_id + ); + + insert into surveys + (survey_id, name, description, + description_html_p, single_response_p, editable_p, + enabled_p, single_section_p, type, display_type, package_id) + values + (v_survey_id, new__name, new__description, + new__description_html_p, new__single_response_p, new__editable_p, + new__enabled_p, new__single_section_p, new__type, new__display_type, new__package_id); + + return v_survey_id; + +end;' language 'plpgsql'; + + +create function survey__delete (integer) +returns integer as ' +declare + delete__survey_id alias for $1; +begin + delete from surveys + where survey_id = delete__survey_id; + + PERFORM acs_object__delete(delete__survey_id); + + return 0; + +end;' language 'plpgsql'; + + +-- API for survey_section objects + +create function survey_section__new (integer,integer,varchar,text,boolean,integer,integer) +returns integer as ' +declare + new__section_id alias for $1; -- default null + new__survey_id alias for $2; -- default null + new__name alias for $3; -- default null + new__description alias for $4; -- default null + new__description_html_p alias for $5; -- default f + new__creation_user alias for $6; -- default null + new__context_id alias for $7; -- default null + v_section_id integer; +begin + v_section_id := acs_object__new ( + new__section_id, + ''survey_section'', + now(), + new__creation_user, + null, + new__context_id + ); + + insert into survey_sections + (section_id, survey_id, name, description, description_html_p) + values + (v_section_id, new__survey_id, new__name, new__description, new__description_html_p); + + return v_section_id; + +end;' language 'plpgsql'; + + + +create function survey_section__delete (integer) +returns integer as ' +declare + delete__section_id alias for $1; +begin + delete from survey_sections + where section_id = delete__section_id; + + PERFORM acs_object__delete(delete__section_id); + + return 0; + +end;' language 'plpgsql'; + + + +create function survey_question__new (integer,integer,integer,text,varchar,boolean,boolean,varchar,varchar,varchar,integer,integer) +returns integer as ' +declare + new__question_id alias for $1; -- default null + new__section_id alias for $2; -- default null + new__sort_order alias for $3; -- default null + new__question_text alias for $4; -- default null + new__abstract_data_type alias for $5; -- default null + new__required_p alias for $6; -- default t + new__active_p alias for $7; -- default + new__presentation_type alias for $8; -- default null + new__presentation_options alias for $9; -- default null + new__presentation_alignment alias for $10; -- default below + new__creation_user alias for $11; -- default null + new__context_id alias for $12; -- default null + v_question_id integer; +begin + v_question_id := acs_object__new ( + new__question_id, + ''survey_question'', + now(), + new__creation_user, + null, + new__context_id + ); + + insert into survey_questions + (question_id, section_id, sort_order, question_text, + abstract_data_type, required_p, active_p, + presentation_type, presentation_options, + presentation_alignment) + values + (v_question_id, new__section_id, new__sort_order, new__question_text, + new__abstract_data_type, new__required_p, new__active_p, + new__presentation_type, new__presentation_options, + new__presentation_alignment); + + return v_question_id; + +end;' language 'plpgsql'; + +-- procedure delete +create function survey_question__delete (integer) +returns integer as ' +declare + delete__question_id alias for $1; +begin + delete from survey_questions + where question_id = delete__question_id; + + PERFORM acs_object__delete(delete__question_id); + + return 0; + +end;' language 'plpgsql'; + + +-- create or replace package body survey_response +-- procedure new +create function survey_response__new(integer,integer,varchar,boolean,integer,varchar,integer,integer) +returns integer as ' +declare + new__response_id alias for $1; -- default null + new__survey_id alias for $2; -- default null + new__title alias for $3; -- default null + new__notify_on_comment_p alias for $4; -- default f + new__creation_user alias for $5; -- default null + new__creation_ip alias for $6; -- default null + new__context_id alias for $7; -- default null + new__initial_response_id alias for $8; -- default null + v_response_id integer; +begin + v_response_id := acs_object__new ( + new__response_id, + ''survey_response'', + now(), + new__creation_user, + new__creation_ip, + new__context_id + ); + + insert into survey_responses + (response_id, survey_id, title, notify_on_comment_p, initial_response_id) + values + (v_response_id, new__survey_id, new__title, new__notify_on_comment_p, new__initial_response_id); + + return v_response_id; + +end;' language 'plpgsql'; + +--function initial_response_id +create function survey_response__initial_response_id(integer) +returns integer as ' +declare + p_response_id alias for $1; + v_initial_response_id integer; +begin + select into v_initial_response_id initial_response_id from + survey_responses where response_id = p_response_id; + if v_initial_response_id is NULL then + v_initial_response_id := p_response_id; + end if; + return v_initial_response_id; +end;' language 'plpgsql'; + +create function survey_response__initial_user_id (integer) +returns integer as ' +declare +p_response_id alias for $1; +v_user_id integer; +begin + select into v_user_id creation_user + from acs_objects where + object_id = survey_response__initial_response_id(p_response_id); +return v_user_id; +end;' language 'plpgsql'; + +-- procedure delete +create function survey_response__delete(integer) +returns integer as ' +declare + delete__response_id alias for $1; +begin + delete from survey_responses + where response_id = delete__response_id; + + PERFORM acs_object__delete(delete__response_id); + + return 0; + +end;' language 'plpgsql'; + Index: openacs-4/packages/survey/sql/postgresql/survey-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/sql/postgresql/survey-drop.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/sql/postgresql/survey-drop.sql 15 Sep 2002 23:57:48 -0000 1.1 @@ -0,0 +1,76 @@ +-- +-- drop SQL for survey package +-- +-- by nstrug@arsdigita.com on 29th September 2000 +-- +-- $Id: survey-drop.sql,v 1.1 2002/09/15 23:57:48 daveb Exp $ + +select drop_package('survey_response'); +select drop_package('survey_question'); +select drop_package('survey_section'); +select drop_package('survey'); + +drop table survey_logic_surveys_map; +drop view survey_logic_id_sequence; +drop sequence survey_logic_id_seq; +drop table survey_logic; +drop table survey_choice_scores; +drop table survey_variables_surveys_map; +drop table survey_variables; +drop view survey_variable_id_sequence; +drop sequence survey_variable_id_seq; +drop view survey_question_responses_un; +drop table survey_question_responses; +drop view survey_responses_unique; +drop table survey_responses; +drop table survey_question_choices; +drop view survey_choice_id_sequence; +drop sequence survey_choice_id_seq; +drop table survey_questions; +drop table survey_sections; +drop table surveys; + +-- nuke all created objects +-- need to do this before nuking the types +delete from acs_objects where object_type = 'survey_response'; +delete from acs_objects where object_type = 'survey_question'; +delete from acs_objects where object_type = 'survey_section'; +delete from acs_objects where object_type = 'survey'; + +create function inline_0 () +returns integer as ' +begin + + PERFORM acs_object_type__drop_type (''survey_response'',''f''); + PERFORM acs_object_type__drop_type (''survey_question'',''f''); + PERFORM acs_object_type__drop_type (''survey_section'',''f''); + PERFORM acs_object_type__drop_type (''survey'',''f''); + + PERFORM acs_privilege__remove_child (''admin'',''survey_admin_survey''); + PERFORM acs_privilege__remove_child (''read'',''survey_take_survey''); + PERFORM acs_privilege__remove_child (''survey_admin_survey'',''survey_delete_question''); + PERFORM acs_privilege__remove_child (''survey_admin_survey'',''survey_modify_question''); + PERFORM acs_privilege__remove_child (''survey_admin_survey'',''survey_create_question''); + PERFORM acs_privilege__remove_child (''survey_admin_survey'',''survey_delete_survey''); + PERFORM acs_privilege__remove_child (''survey_admin_survey'',''survey_modify_survey''); + PERFORM acs_privilege__remove_child (''survey_admin_survey'',''survey_create_survey''); + + PERFORM acs_privilege__drop_privilege(''survey_admin_survey''); + PERFORM acs_privilege__drop_privilege(''survey_take_survey''); + PERFORM acs_privilege__drop_privilege(''survey_delete_question''); + PERFORM acs_privilege__drop_privilege(''survey_modify_question''); + PERFORM acs_privilege__drop_privilege(''survey_create_question''); + PERFORM acs_privilege__drop_privilege(''survey_delete_survey''); + PERFORM acs_privilege__drop_privilege(''survey_modify_survey''); + PERFORM acs_privilege__drop_privilege(''survey_create_survey''); + + return 0; +end;' language 'plpgsql'; + +select inline_0 (); +drop function inline_0 (); + +-- gilbertw - logical_negation is defined in utilities-create.sql in acs-kernel +-- drop function logical_negation(boolean); + + Index: openacs-4/packages/survey/sql/postgresql/survey-notifications-init.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/sql/postgresql/survey-notifications-init.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/sql/postgresql/survey-notifications-init.sql 15 Sep 2002 23:57:48 -0000 1.1 @@ -0,0 +1,62 @@ +-- daveb: not tested, this will probably break on postgresql +-- Survey +-- +-- -- @author dave@thedesignexperience.org, ben@openforce.biz +-- @creation-date 2002-08-03 +-- +-- integration with Notifications + +declare + impl_id integer; + v_foo integer; +begin + -- the notification type impl + impl_id := acs_sc_impl__new ( + 'NotificationType', + 'survey_response_notif_type', + 'survey' + ); + + v_foo := acs_sc_impl__new_alias ( + 'NotificationType', + 'survey_response_notif_type', + 'GetURL', + 'survey::notification::get_url', + 'TCL' + ); + + v_foo := acs_sc_impl__new_alias ( + 'NotificationType', + 'survey_response_notif_type', + 'ProcessReply', + 'survey::notification::process_reply', + 'TCL' + ); + + acs_sc_binding__new ( + contract_name => 'NotificationType', + impl_name => 'survey_response_notif_type' + ); + + v_foo:= notification_type__new ( + short_name => 'survey_response_notif', + sc_impl_id => impl_id, + pretty_name => 'Survey Response Notification', + description => 'Notifications for Survey', + creation_user => NULL, + creation_ip => NULL + ); + + -- enable the various intervals and delivery methods + insert into notification_types_intervals + (type_id, interval_id) + select v_foo, interval_id + from notification_intervals where name in ('instant','hourly','daily'); + + insert into notification_types_del_methods + (type_id, delivery_method_id) + select v_foo, delivery_method_id + from notification_delivery_methods where short_name in ('email'); + +end; + Index: openacs-4/packages/survey/tcl/survey-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/tcl/survey-procs-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/tcl/survey-procs-oracle.xql 15 Sep 2002 23:56:54 -0000 1.1 @@ -0,0 +1,83 @@ + + + + oracle8.1.6 + + + + + begin + :1 := survey_question.new ( + question_id => NULL, + section_id => :section_id, + sort_order => :new_sort_order, + question_text => empty_clob(), + abstract_data_type => :abstract_data_type, + presentation_type => :presentation_type, + presentation_alignment => :presentation_alignment, + presentation_options => :presentation_options, + active_p => :active_p, + required_p => :required_p, + context_id => :section_id, + creation_user => :user_id + ); + end; + + + + + + +select survey_choice_id_sequence.nextval as choice_id from dual + + + + + + select count(distinct survey_response.initial_user_id(response_id)) + from + survey_responses + where survey_id=:survey_id + + + + + + + begin + :1 := survey.new ( + survey_id => NULL, + name => :name, + description => :description, + description_html_p => :description_html_p, + editable_p => :editable_p, + single_response_p => :single_response_p, + enabled_p => :enabled_p, + single_section_p => :single_section_p, + type => :type, + display_type => :display_type, + package_id => :package_id, + context_id => :package_id, + creation_user => :user_id + ); + end; + + + + + + begin + :1 := survey_section.new ( + section_id=>NULL, + survey_id=>:new_survey_id, + name=>:name, + description=>empty_clob(), + description_html_p=>:description_html_p, + context_id =>:new_survey_id + ); + end; + + + + + Index: openacs-4/packages/survey/tcl/survey-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/tcl/survey-procs-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/tcl/survey-procs-postgresql.xql 15 Sep 2002 23:56:54 -0000 1.1 @@ -0,0 +1,33 @@ + + + + postgresql7.1 + + + + begin + PERFORM survey_question__new ( + NULL, + :section_id, + :new_sort_order, + :question_text, + :abstract_data_type, + :required_p, + :active_p, + :presentation_type, + :presentation_options, + :presentation_alignment, + :user_id, + :section_id + ); + end; + + + + + +select survey_choice_id_sequence.nextval as choice_id + + + + \ No newline at end of file Index: openacs-4/packages/survey/tcl/survey-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/tcl/survey-procs.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/tcl/survey-procs.tcl 15 Sep 2002 23:56:54 -0000 1.1 @@ -0,0 +1,519 @@ +# /tcl/survey-procs.tcl + +ad_library { + + Support procs for simple survey module, most important being + survey_question_display which generates a question widget based + on data retrieved from database. + + @author philg@mit.edu on + @author teadams@mit.edu + @author nstrug@arsdigita.com + @date February 9, 2000 + @cvs-id survey-simple-defs.tcl,v 1.29.2.5 2000/07/19 20:11:24 seb Exp + +} + +ad_proc -public get_survey_info { + {-survey_id ""} + {-section_id ""} +} { + creates a tcl array variable named "survey_info" in the caller's environment, + which contains key/value pairs for all properties of the requested survey. + + If survey_id is passed in, and it's a single-section survey, the + section_id will also be looked up and returned in the survey_info array. + + @author luke@museatech.net + @date 2002-07-24 +} { + upvar survey_info survey_info + + if {[empty_string_p $survey_id]} { + db_1row lookup_survey_id "" + } + + db_1row get_info_by_survey_id "" -column_array survey_info + + # If it's a single-section survey, look up the section_id + if {[empty_string_p $section_id] && $survey_info(single_section_p) == "t"} { + db_1row lookup_single_section_id "" + set survey_info(section_id) $section_id + } + + # some useful stats about the survey, dotLRN specific for sloanspace + if {[apm_package_installed_p dotlrn]} { + set community_id [dotlrn_community::get_community_id_from_url] + set survey_info(eligible) [db_string n_eligible {}] + set survey_info(completed) [db_string n_completed {}] + set survey_info(not_completed) [expr {$survey_info(eligible) - $survey_info(completed)}] + } +} + + +ad_proc -public survey_question_display { + question_id + {response_id ""} +} {Returns a string of HTML to display for a question, suitable for embedding in a form. The form variable is of the form \"response_to_question.\$question_id} { + + if {![empty_string_p $response_id]} { + set edit_previous_response_p "t" + } else { + set edit_previous_response_p "f" + } + + set element_name "response_to_question.$question_id" + + db_1row survey_question_properties "" + if {$required_p == "t"} { + set html "*" + } else { + set html " " + } + + append html $question_text + if { $presentation_alignment == "below" } { + append html "
" + } else { + append html " " + } + + set user_value "" + + if {$edit_previous_response_p == "t"} { + set user_id [ad_get_user_id] + + set count 0 + db_foreach prev_response_query {} { + incr count + + if {$presentation_type == "checkbox"} { + set selected_choices($choice_id) "t" + } + } if_no_rows { + set choice_id 0 + set boolean_answer "" + set clob_answer "" + set number_answer "" + set varchar_answer "" + set date_answer "" + set attachment_answer "" + } + } + + switch -- $presentation_type { + "upload_file" { + if {$edit_previous_response_p == "t"} { + set user_value $attachment_answer + } + append html "" + } + "textbox" { + if {$edit_previous_response_p == "t"} { + if {$abstract_data_type == "number" || $abstract_data_type == "integer"} { + set user_value $number_answer + } else { + set user_value $varchar_answer + } + } + + append html "" + } + "textarea" { + if {$edit_previous_response_p == "t"} { + + set user_value $clob_answer + } + + set presentation_options [ad_decode $presentation_options "large" "rows=20 cols=65" "medium" "rows=15 cols=55" "rows=8 cols=35"] + append html "" + } + "date" { + if {$edit_previous_response_p == "t"} { + set user_value $date_answer + } + + append html "[ad_dateentrywidget $element_name $user_value]" + } + "select" { + if { $abstract_data_type == "boolean" } { + if {$edit_previous_response_p == "t"} { + set user_value $boolean_answer + } + + if {![empty_string_p $presentation_options]} { + set options_list [split $presentation_options "/"] + set choice_t [lindex $options_list 0] + set choice_f [lindex $options_list 1] + } else { + set choice_t "True" + set choice_f "False" + } + + append html " +" + } else { + if {$edit_previous_response_p == "t"} { + set user_value $choice_id + } + +# at some point, we may want to add a UI option for the admin +# to sepcify multiple or not for select + append html "" + } + } + + "radio" { + if { $abstract_data_type == "boolean" } { + if {$edit_previous_response_p == "t"} { + set user_value $boolean_answer + } + if {![empty_string_p $presentation_options]} { + set options_list [split $presentation_options "/"] + set choice_t [lindex $options_list 0] + set choice_f [lindex $options_list 1] + } else { + set choice_t "True" + set choice_f "False" + } + + set choices [list " $choice_t" \ + " $choice_f"] + } else { + if {$edit_previous_response_p == "t"} { + set user_value $choice_id + } + + set choices [list] + db_foreach question_choices_2 "" { + if { $user_value == $choice_id } { + lappend choices " $label" + } else { + lappend choices " $label" + } + } + } + if { $presentation_alignment == "beside" } { + append html [join $choices " "] + } else { + append html "
\n[join $choices "
\n"]\n
" + } + } + + "checkbox" { + set choices [list] + db_foreach question_choices_3 "" { + if { [info exists selected_choices($choice_id)] } { + lappend choices " $label" + } else { + lappend choices " $label" + } + } + if { $presentation_alignment == "beside" } { + append html [join $choices " "] + } else { + append html "
\n[join $choices "
\n"]\n
" + } + } + } + + return $html +} + +ad_proc -public util_show_plain_text { text_to_display } "allows plain text (e.g. text entered through forms) to look good on screen without using tags; preserves newlines, angle brackets, etc." { + regsub -all "\\&" $text_to_display "\\&" good_text + regsub -all "\>" $good_text "\\>" good_text + regsub -all "\<" $good_text "\\<" good_text + regsub -all "\n" $good_text "
\n" good_text + # get rid of stupid ^M's + regsub -all "\r" $good_text "" good_text + return $good_text +} + +ad_proc -public survey_answer_summary_display {response_id {html_p 1}} "Returns a string with the questions and answers. If html_p =t, the format will be html. Otherwise, it will be text. If a list of category_ids is provided, the questions will be limited to that set of categories." { + + set return_string "" + set question_id_previous "" + + db_foreach summary "" { + + if {$question_id == $question_id_previous} { + continue + } + + if $html_p { + append return_string "# $sort_order: $question_text +
" + } else { + append return_string "# $sort_order: $question_text: " + } + append return_string [util_show_plain_text "$clob_answer $number_answer $varchar_answer $date_answer"] + + if {![empty_string_p $attachment_answer]} { + set package_id [ad_conn package_id] + set filename [db_string get_filename {}] + append return_string "Uploaded file: \"$filename\"" + } + + if {$choice_id != 0 && ![empty_string_p $choice_id] && $question_id != $question_id_previous} { + set label_list [db_list survey_label_list ""] + append return_string "[join $label_list ", "]" + } + + if ![empty_string_p $boolean_answer] { + append return_string "[survey_decode_boolean_answer -response $boolean_answer -question_id $question_id]" + + } + + if $html_p { + append return_string "
+

" + } else { + append return_string "\n\n" + } + + set question_id_previous $question_id + } + + return "$return_string" +} + + + +ad_proc -public survey_get_score {section_id user_id} "Returns the score of the user's most recent response to a survey" { + + set response_id [ survey_get_response_id $section_id $user_id ] + + if { $response_id != 0 } { + set score [db_string get_score "" -default 0] + } else { + set score {} + } + + return $score +} + + +ad_proc -public survey_display_types { +} { + return {list table paragraph} +} + + +ad_proc -public survey_question_copy { + {-new_section_id ""} + {-question_id:required} +} { copies a question within the same survey +} { + set user_id [ad_conn user_id] + db_1row get_question_details {} + if {![empty_string_p $new_section_id]} { + set section_id $new_section_id + } + + set old_question_id $question_id + if {[empty_string_p $new_section_id]} { + set after $sort_order + set new_sort_order [expr {$after + 1}] + db_dml renumber_sort_orders {} + } else { + set new_sort_order $sort_order + } + + set new_question_id [db_exec_plsql create_question {}] + db_dml insert_question_text {} + db_foreach get_survey_question_choices {} { + set new_choice_id [db_string get_choice_id {}] + db_dml insert_survey_question_choice {} + + } + + return $new_question_id +} + +ad_proc survey_copy { + {-survey_id:required} + {-package_id ""} + {-new_name ""} +} { + copies a survey, copying all questions, but not responses + is package_id is specific it copies they survey to another + survey package instance, otherwise it copies the survey to the + same package instance +} { + + if {[empty_string_p $package_id]} { + set package_id [ad_conn package_id] + } + + db_1row get_survey_info {} + if {![empty_string_p $new_name]} { + set name $new_name + } + set user_id [ad_conn user_id] + set new_survey_id [db_exec_plsql survey_create {} ] + set sections_list [db_list get_sections {}] + + + foreach section_id $sections_list { + + set new_section_id [db_exec_plsql section_create {}] + set new_section_ids($section_id) $new_section_id + if {![empty_string_p $description]} { + db_dml set_section_description {} + } + } + db_foreach get_questions {} { + + survey_question_copy -new_section_id $new_section_ids($section_id) -question_id $question_id + } +return $new_survey_id + +} + +ad_proc -public survey_do_notifications { + {-response_id ""} +} { process notifications when someone responds to a survey + or edits a response +} { + + set survey_id [db_string get_survey_id_from_response {}] + get_survey_info -survey_id $survey_id + set survey_name $survey_info(name) + set subject "Response to $survey_name" + + #dotlrn specific info + set dotlrn_installed_p [apm_package_installed_p dotlrn] + if {$dotlrn_installed_p} { + set package_id [ad_conn package_id] + set community_id [dotlrn_community::get_community_id] + set segment_id [dotlrn_community::get_rel_segment_id -community_id $community_id -rel_type "dotlrn_member_rel"] + set community_name [dotlrn_community::get_community_name $community_id] + set community_url "[ad_parameter -package_id [ad_acs_kernel_id] SystemURL][dotlrn_community::get_community_url $community_id]" + } + db_1row get_response_info { + select r.initial_response_id, r.responding_user_id, r.response_id, + u.first_names || ' ' || u.last_name as user_name, + edit_p, + o.creation_date as response_date + from (select survey_response.initial_user_id(response_id) as responding_user_id, + survey_response.initial_response_id(response_id) as initial_response_id, + response_id, (case when initial_response_id is NULL then 'f' else 't' end) as edit_p + from survey_responses) r, acs_objects o, + cc_users u where r.response_id=:response_id + and r.responding_user_id = u.user_id + and r.response_id = o.object_id + } + + set notif_text "" + if {$dotlrn_installed_p} { + append notif_text " +Group: $community_name" + } + append notif_text " +Survey: $survey_name +Respondent: $user_name + +Here is what $user_name <[acs_community_member_url -user_id $responding_user_id]> +had to say in response to $survey_name: + " + + if {$edit_p} { + append notif_text " +Edited " + } + append notif_text "Response on $response_date\n" + + append notif_text [survey_answer_summary_display $response_id 0] + +# add summary info for sloanspace + if {$dotlrn_installed_p} { + set n_responses [db_string n_responses {}] + if {$n_responses > 0} { + append notif_text " ----- +Already Responsed: $n_responses users + +View these users. <$community_url/survey/admin/respondents?response_type=responded> + +Spam these users. <$community_url/survey/admin/send-mail?survey_id=$survey_id&to=responded> + +" + } + set n_members [db_string n_members {}] + set n_awaiting [expr {$n_members - $n_responses}] + + append notif_text " +Awaiting a response: $n_awaiting users + +View these users. <$community_url/survey/admin/respondents?response_type=not_responded> + +Spam these users. <$community_url/survey/admin/send-mail?survey_id=$survey_id&to=not_responded> + +The whole group: $n_members + +View these users. <$community_url/survey/admin/respondents?response_type=all> + +Spam these users. <$community_url/survey/admin/send-mail?survey_id=$survey_id&to=all> + +Responses: +" + + db_foreach get_questions {} { + append notif_text "$sort_order. $question_text - View responses. <$community_url/survey/view-text-responses?question_id=$question_id> + " + } + } + notification::new \ + -type_id [notification::type::get_type_id \ + -short_name survey_response_notif] \ + -object_id $survey_id \ + -response_id $survey_id \ + -notif_subject $subject \ + -notif_text $notif_text + +} + + +ad_proc survey_decode_boolean_answer { + {-response:required} + {-question_id:required} +} { + takes t/f value from a boolean_answer column and + decodes it based on the presentation_options of the question + + @author Dave Bauer + + @param -response text value of response to be decoded + @param -question_id question_id of question response is from +} { + set presentation_options [db_string get_presentation_options {}] + if {[empty_string_p $presentation_options]} { + set presentation_options "True/False" + } + + + if {![empty_string_p $response]} { + set options_list [split $presentation_options "/"] + + if {$response=="t"} { + set response [lindex $options_list 0] + } else { + set response [lindex $options_list 1] + } + } + return $response +} \ No newline at end of file Index: openacs-4/packages/survey/tcl/survey-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/tcl/survey-procs.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/tcl/survey-procs.xql 15 Sep 2002 23:56:54 -0000 1.1 @@ -0,0 +1,295 @@ + + + + + + select count(*) from dotlrn_member_rels_full + where rel_type='dotlrn_member_rel' + and community_id=:community_id + + + + + + + select min(section_id) as section_id + from survey_sections + where survey_id = :survey_id + + + + + + select survey_id + from survey_sections + where section_id = :section_id + + + + + + select s.*, + o.creation_user, o.creation_date, p.first_names || ' ' || p.last_name as creator_name, + (case when enabled_p = 't' then 'Enabled' else 'Disabled' end) as enabled_display, + (case when single_response_p = 't' then 'One response' else 'Multiple responses' end) as single_response_display, + (case when editable_p = 'f' then 'Non-Editable' else 'Editable' end) as editable_display, + (case when single_section_p = 'f' then 'Multiple sections' else 'Single section' end) as single_section_display + from surveys s, acs_objects o, persons p + where o.object_id = :survey_id + and s.survey_id = o.object_id + and p.person_id = o.creation_user + + + + + + +select + choice_id, + boolean_answer, + clob_answer, + number_answer, + varchar_answer, + date_answer, + attachment_answer + from survey_question_responses + where question_id = :question_id + and response_id = :response_id + + + + + + +select + choice_id, + boolean_answer, + clob_answer, + number_answer, + varchar_answer, + date_answer, + attachment_answer + from survey_question_responses + where question_id = :question_id + and response_id = :response_id + + + + + + + +select + section_id, + sort_order, + question_text, + abstract_data_type, + required_p, + active_p, + presentation_type, + presentation_options, + presentation_alignment, + creation_user, + creation_date +from + survey_questions, acs_objects +where + object_id = question_id + and question_id = :question_id + + + + + + select choice_id, label +from survey_question_choices +where question_id = :question_id +order by sort_order + + + + + + + select choice_id, label +from survey_question_choices +where question_id = :question_id +order by sort_order + + + + + + + select * from survey_question_choices +where question_id = :question_id +order by sort_order + + + + + + + + select label + from survey_question_choices, survey_question_responses + where survey_question_responses.question_id = :question_id + and survey_question_responses.response_id = :response_id + and survey_question_choices.choice_id = survey_question_responses.choice_id + + + + + + + + +select * from survey_questions +where question_id=:question_id + + + + + + update survey_questions + set question_text = :question_text + where question_id = :new_question_id + + + + + +update survey_questions + set sort_order = sort_order + 1 + where section_id = :section_id + and sort_order > :after + + + + + + select * from survey_question_choices + where question_id=:old_question_id + + + + + +insert into survey_question_choices + (choice_id, question_id, label, numeric_value, sort_order) + values + (:new_choice_id, :new_question_id, :label, + :numeric_value, :sort_order) + + + + + + select survey_id from survey_responses + where response_id=:response_id + + + + + + select count(*) from survey_responses_latest + where survey_id=:survey_id + + + + + + select count(*) from party_approved_member_map + where party_id=:segment_id + + + + + + select sort_order, question_text, question_id + from survey_questions + where section_id in + (select section_id + from survey_sections + where survey_id=:survey_id) + + + + + +select * from surveys where survey_id=:survey_id + + + + + + update survey_sections set description=:description + where section_id=:new_section_id + + + + + + select section_id from survey_sections where survey_id=:survey_id + + + + + +select question_id from survey_questions + where section_id in (select section_id from survey_sections + where survey_id=:survey_id) + + + + + + +select + sq.question_id, + sq.section_id, + sq.sort_order, + sq.question_text, + sq.abstract_data_type, + sq.required_p, + sq.active_p, + sq.presentation_type, + sq.presentation_options, + sq.presentation_alignment, + sqr.response_id, + sqr.question_id, + sqr.choice_id, + sqr.boolean_answer, + sqr.clob_answer, + sqr.number_answer, + sqr.varchar_answer, + sqr.date_answer, + sqr.attachment_answer +from + survey_questions sq, + survey_question_responses sqr +where + sqr.response_id = :response_id + and sq.question_id = sqr.question_id + and sq.active_p = 't' +order by sort_order + + + + + + + select presentation_options + from survey_questions + where question_id=:question_id + + + + + + select title from cr_revisions where + revision_id=:attachment_answer + + + + Index: openacs-4/packages/survey/www/index-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/index-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/index-oracle.xql 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,21 @@ + + + + + + + +select s.survey_id, s.name, s.editable_p, s.single_response_p, + sr.response_id, sr.creation_date + from surveys s ,(select survey_id, response_id, creation_date + from survey_responses_latest + where initial_user_id = :user_id) sr + where s.package_id=:package_id +and s.survey_id = sr.survey_id(+) +and s.enabled_p='t' + order by upper(s.name) + + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/index-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/index-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/index-postgresql.xql 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,22 @@ + + + + + + + +select s.survey_id, s.name, s.editable_p, s.single_response_p, + sr.response_id, sr.creation_date + from surveys s left outer join + (select survey_id, response_id, creation_date + from survey_responses_latest + where initial_user_id = :user_id) sr + on (s.survey_id = sr.survey_id) + where s.package_id=:package_id + and s.enabled_p='t' + order by upper(s.name) + + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/index.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/index.adp 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,33 @@ + +Surveys +@context_bar@ +

Administer Surveys +

+ Index: openacs-4/packages/survey/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/index.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/index.tcl 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,28 @@ +ad_page_contract { + + Lists all the enabled surveys + a user is eligable to complete. + + @author philg@mit.edu + @author nstrug@arsdigita.com + @date 28th September 2000 + @cvs-id $Id: index.tcl,v 1.1 2002/09/16 00:00:23 daveb Exp $ +} { + +} -properties { + surveys:multirow +} + +set package_id [ad_conn package_id] + +set context_bar [ad_context_bar] + +set user_id [ad_maybe_redirect_for_registration] + +set admin_p [ad_permission_p $package_id admin] + +db_multirow surveys survey_select {} + + +ad_return_template + Index: openacs-4/packages/survey/www/master.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/Attic/master.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/master.adp 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,8 @@ + +@title@ +

@title@

+ + @context_bar@ + +

+ Index: openacs-4/packages/survey/www/one-respondent.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/one-respondent.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/one-respondent.adp 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,30 @@ + +Answers to @survey_name@ +@context_bar@ + + @description@ +

+ + + @responses.pretty_submission_date@ | + + + @responses.pretty_submission_date@ + + +

+ + + + + + + + +
Your response + on @responses.pretty_submission_date@ + [edit this response] +
@responses.answer_summary@
+
+ \ No newline at end of file Index: openacs-4/packages/survey/www/one-respondent.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/one-respondent.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/one-respondent.tcl 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,45 @@ +ad_page_contract { + + Display the user's previous responses. + + @param section_id id of survey for which responses are displayed + @param return_url if provided, generate a 'return' link to that URL + @param group_id if specified, display all the responses for all + users of that group + + @author philg@mit.edu + @author nstrug@arsdigita.com + @date 28th September 2000 + @cvs-id $Id: one-respondent.tcl,v 1.1 2002/09/16 00:00:23 daveb Exp $ +} { + + survey_id:integer + {return_url ""} + +} -validate { + survey_exists -requires {survey_id} { + if ![db_0or1row survey_exists {}] { + ad_complain "Survey $section_id does not exist" + } + } +} -properties { + survey_name:onerow + description:onerow + responses:multirow +} + +# If group_id is specified, we return all the responses for that group by any user + +set user_id [ad_verify_and_get_user_id] + +get_survey_info -survey_id $survey_id + +set survey_name $survey_info(name) +set description $survey_info(description) +set editable_p $survey_info(editable_p) +set context_bar [ad_context_bar "Responses"] +db_multirow -extend {answer_summary} responses responses_select {} { + set answer_summary [survey_answer_summary_display $response_id 1] +} + +ad_return_template Index: openacs-4/packages/survey/www/one-respondent.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/one-respondent.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/one-respondent.xql 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,25 @@ + + + + + + + select 1 from surveys where survey_id = :survey_id + + + + + + + + select response_id, creation_date, + to_char(creation_date, 'Month DD, YYYY') as pretty_submission_date + from survey_responses_latest + where survey_id=:survey_id + and initial_user_id = :user_id + order by creation_date desc + + + + + Index: openacs-4/packages/survey/www/one-survey-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/one-survey-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/one-survey-oracle.xql 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,22 @@ + + + + + + + +select s.survey_id, s.name, s.editable_p, s.single_response_p, + sr.response_id, sr.creation_date + from surveys s ,(select survey_id, response_id, creation_date + from survey_responses_latest + where initial_user_id = :user_id) sr + where s.survey_id=:survey_id +and s.package_id=:package_id +and s.survey_id = sr.survey_id(+) +and s.enabled_p='t' +order by sr.creation_date desc + + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/one-survey-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/one-survey-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/one-survey-postgresql.xql 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,23 @@ + + + + + + + +select s.survey_id, s.name, s.editable_p, s.single_response_p, + sr.response_id, sr.creation_date + from surveys s left outer join + (select survey_id, response_id, creation_date + from survey_responses_latest + where initial_user_id = :user_id) sr + on (s.survey_id = sr.survey_id) + where s.survey_id=:survey_id + and s.package_id=:package_id + and s.enabled_p='t' + order by upper(s.name) + + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/one-survey.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/one-survey.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/one-survey.adp 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,31 @@ + +Surveys +@context_bar@ +

Admin

+ + Index: openacs-4/packages/survey/www/one-survey.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/one-survey.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/one-survey.tcl 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,29 @@ +ad_page_contract { + + Lists all the enabled surveys + a user is eligable to complete. + + @author philg@mit.edu + @author nstrug@arsdigita.com + @date 28th September 2000 + @cvs-id $Id: one-survey.tcl,v 1.1 2002/09/16 00:00:23 daveb Exp $ +} { + survey_id:integer,notnull +} -properties { + survey_details:multirow +} + +set package_id [ad_conn package_id] + +set context_bar [ad_context_bar] + +set user_id [ad_maybe_redirect_for_registration] + +set take_survey_p [ad_permission_p $survey_id survey_take_survey] + +set admin_p [ad_permission_p $survey_id survey_admin_survey] + +db_multirow survey_details get_survey_details {} + +ad_return_template + Index: openacs-4/packages/survey/www/one_list.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/one_list.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/one_list.adp 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,5 @@ +
    + +
  1. @questions:item@ + +
Index: openacs-4/packages/survey/www/one_paragraph.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/one_paragraph.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/one_paragraph.adp 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,4 @@ + +@questions:item@

+ + Index: openacs-4/packages/survey/www/one_table.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/one_table.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/one_table.adp 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,5 @@ + + + + +
@questions:item@
Index: openacs-4/packages/survey/www/process-response-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/process-response-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/process-response-oracle.xql 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,64 @@ + + + + oracle8.1.6 + + + + + begin + :1 := survey_response.new ( + response_id => :response_id, + survey_id => :survey_id, + context_id => :survey_id, + creation_user => :user_id, + initial_response_id => :initial_response_id + ); + end; + + + + + + + + + insert into survey_question_responses + (response_id, question_id, clob_answer) + values + (:response_id, :question_id, empty_clob()) + returning clob_answer into :1 + + + + + + + + + begin + :1 := content_item.new ( + name => :name, + creation_ip => :creation_ip + ); + end; + + + + + + + + + begin + :1 := acs_rel.new ( + rel_type => 'user_blob_response_rel', + object_id_one => :user_id, + object_id_two => :item_id); + end; + + + + + + Index: openacs-4/packages/survey/www/process-response-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/process-response-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/process-response-postgresql.xql 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,32 @@ + + + + postgresql7.1 + + + + select survey_response__new ( + :response_id, + :survey_id, + null, + 'f', + :user_id, + :creation_ip, + :survey_id, + :initial_response_id + ) + + + + + + + insert into survey_question_responses + (response_id, question_id, clob_answer) + values + (:response_id, :question_id, :clob_answer) + + + + + Index: openacs-4/packages/survey/www/process-response.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/process-response.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/process-response.adp 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,8 @@ + +Response Submitted +@context_bar@ +

+

Response submitted. Thank you.

+

Return to the survey index page.

+ +
Index: openacs-4/packages/survey/www/process-response.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/process-response.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/process-response.tcl 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,326 @@ +ad_page_contract { + + Insert user response into database. + This page receives an input for each question named + response_to_question.$question_id + + @param section_id survey user is responding to + @param return_url optional redirect address + @param group_id + @param response_to_question since form variables are now named as response_to_question.$question_id, this is actually array holding user responses to all survey questions. + + @author jsc@arsdigita.com + @author nstrug@arsdigita.com + @date 28th September 2000 + @cvs-id $Id: process-response.tcl,v 1.1 2002/09/16 00:00:23 daveb Exp $ +} { + survey_id:integer + section_id:integer + {initial_response_id:integer 0} + return_url:optional + response_to_question:array,optional,multiple,html + +} -validate { + + section_exists -requires { section_id } { + if ![db_0or1row section_exists {}] { + ad_complain "Section $section_id does not exist" + } + } + + check_questions -requires { section_id:integer } { + + set question_info_list [db_list_of_lists survey_question_info_list { + select question_id, question_text, abstract_data_type, presentation_type, required_p + from survey_questions + where section_id = :section_id + and active_p = 't' + order by sort_order + }] + + ## Validate input. + + set questions_with_missing_responses [list] + + foreach question $question_info_list { + set question_id [lindex $question 0] + set question_text [lindex $question 1] + set abstract_data_type [lindex $question 2] + set required_p [lindex $question 4] + + # Need to clean-up after mess with :array,multiple flags + # in ad_page_contract. Because :multiple flag will sorround empty + # strings and all multiword values with one level of curly braces {} + # we need to get rid of them for almost any abstract_data_type + # except 'choice', where this is intended behaviour. Why bother + # with :multiple flag at all? Because otherwise we would lost all + # but first value for 'choice' abstract_data_type - see ad_page_contract + # doc and code for more info. + # + if { [exists_and_not_null response_to_question($question_id)] } { + if {$abstract_data_type != "choice"} { + set response_to_question($question_id) [join $response_to_question($question_id)] + } + } + + + if { $abstract_data_type == "date" } { + if [catch { set response_to_question($question_id) [validate_ad_dateentrywidget "" response_to_question.$question_id [ns_getform]]} errmsg] { + ad_complain "$errmsg: Please make sure your dates are valid." + } + } + + if { [exists_and_not_null response_to_question($question_id)] } { + set response_value [string trim $response_to_question($question_id)] + } elseif {$required_p == "t"} { + lappend questions_with_missing_responses $question_text + continue + } else { + set response_to_question($question_id) "" + set response_value "" + } + + if {![empty_string_p $response_value]} { + if { $abstract_data_type == "number" } { + if { ![regexp {^(-?[0-9]+\.)?[0-9]+$} $response_value] } { + + ad_complain "The response to \"$question_text\" must be a number. Your answer was \"$response_value\"." + continue + } + } elseif { $abstract_data_type == "integer" } { + if { ![regexp {^[0-9]+$} $response_value] } { + + ad_complain "The response to \"$question_text\" must be an integer. Your answer was \"$response_value\"." + continue + } + } + } + + if { $abstract_data_type == "blob" } { + set tmp_filename $response_to_question($question_id.tmpfile) + set n_bytes [file size $tmp_filename] + if { $n_bytes == 0 && $required_p == "t" } { + + ad_complain "Your file is zero-length. Either you attempted to upload a zero length file, a file which does not exist, or something went wrong during the transfer." + } + } + + } + + if { [llength $questions_with_missing_responses] > 0 } { + ad_complain "You didn't respond to all required sections. You skipped:" + foreach skipped_question $questions_with_missing_responses { + ad_complain $skipped_question + } + return 0 + } else { + return 1 + } + } +} -properties { + + survey_name:onerow +} + +ad_require_permission $survey_id survey_take_survey + +set user_id [ad_verify_and_get_user_id] + +# Do the inserts. +# here we need to decide if it is an edit or multiple response, and create +# a new response, possibly linked to a previous response. + +set response_id [db_nextval acs_object_id_seq] +set creation_ip [ad_conn peeraddr] +if {$initial_response_id==0} { + set initial_response_id "" +} +db_transaction { + + db_exec_plsql create_response {} + + set question_info_list [db_list_of_lists survey_question_info_list { + select question_id, question_text, abstract_data_type, presentation_type, required_p + from survey_questions + where section_id = :section_id + and active_p = 't' + order by sort_order }] + + + foreach question $question_info_list { + set question_id [lindex $question 0] + set question_text [lindex $question 1] + set abstract_data_type [lindex $question 2] + set presentation_type [lindex $question 3] + + set response_value [string trim $response_to_question($question_id)] + + switch -- $abstract_data_type { + "choice" { + if { $presentation_type == "checkbox" } { + # Deal with multiple responses. + set checked_responses $response_to_question($question_id) + foreach response_value $checked_responses { + if { [empty_string_p $response_value] } { + set response_value [db_null] + } + + db_dml survey_question_response_checkbox_insert "insert into survey_question_responses (response_id, question_id, choice_id) + values (:response_id, :question_id, :response_value)" + } + } else { + if { [empty_string_p $response_value] } { + set response_value [db_null] + } + + db_dml survey_question_response_choice_insert "insert into survey_question_responses (response_id, question_id, choice_id) + values (:response_id, :question_id, :response_value)" + } + } + "shorttext" { + db_dml survey_question_choice_shorttext_insert "insert into survey_question_responses (response_id, question_id, varchar_answer) + values (:response_id, :question_id, :response_value)" + } + "boolean" { + if { [empty_string_p $response_value] } { + set response_value [db_null] + } + + db_dml survey_question_response_boolean_insert "insert into survey_question_responses (response_id, question_id, boolean_answer) + values (:response_id, :question_id, :response_value)" + } + "integer" - + "number" { + if { [empty_string_p $response_value] } { + set response_value [db_null] + } + db_dml survey_question_response_integer_insert "insert into survey_question_responses (response_id, question_id, number_answer) + values (:response_id, :question_id, :response_value)" + } + "text" { + if { [empty_string_p $response_value] } { + set response_value [db_null] + } + + db_dml survey_question_response_text_insert " +insert into survey_question_responses +(response_id, question_id, clob_answer) +values (:response_id, :question_id, empty_clob()) + returning clob_answer into :1" -clobs [list $response_value] + } + "date" { + if { [empty_string_p $response_value] } { + set response_value [db_null] + } + + db_dml survey_question_response_date_insert "insert into survey_question_responses (response_id, question_id, date_answer) + values (:response_id, :question_id, :response_value)" + } + "blob" { + + if { ![empty_string_p $response_value] } { + # this stuff only makes sense to do if we know the file exists + set tmp_filename $response_to_question($question_id.tmpfile) + + set file_extension [string tolower [file extension $response_value]] + # remove the first . from the file extension + regsub {\.} $file_extension "" file_extension + set guessed_file_type [ns_guesstype $response_value] + + set n_bytes [file size $tmp_filename] + # strip off the C:\directories... crud and just get the file name + if ![regexp {([^/\\]+)$} $response_value match client_filename] { + # couldn't find a match + set client_filename $response_value + } + if { $n_bytes == 0 } { + error "This should have been checked earlier." + } else { + set unique_name "${response_value}_${response_id}" + set mime_type [ns_guesstype $client_filename] + set revision_id [cr_import_content -title $client_filename "" $tmp_filename $n_bytes $mime_type $unique_name ] +# we use cr_import_content now --DaveB +# this abstracts out for use the blob handling for oracle or postgresql +# we are linking the file item_id to the survey_question_response attachment_answer field now + db_dml survey_question_response_attachment_insert " + insert into survey_question_responses + (response_id, question_id, attachment_answer) + values + (:response_id, :question_id, :revision_id + )" + } + } + } + } + } + +} + +survey_do_notifications -response_id $response_id + +# +# Survey type-specific stuff +# +get_survey_info -survey_id $survey_id +set type $survey_info(type) +set survey_id $survey_info(survey_id) +set survey_name $survey_info(name) + +#set type [db_string get_type "select type from survey_sections where section_id = :section_id"] + +switch $type { + + "general" { + + #set survey_name [db_string survey_name_from_id "select name from survey_sections where section_id = :section_id" ] + + db_release_unused_handles + + if {[info exists return_url] && ![empty_string_p $return_url]} { + ad_returnredirect "$return_url" + return + } else { + set context_bar [ad_context_bar "Response Submitted for $survey_name"] + ad_return_template + } + } + + "scored" { + + db_foreach get_score "select variable_name, sum(score) as sum_of_scores + from survey_choice_scores, survey_question_responses, survey_variables + where survey_choice_scores.choice_id = survey_question_responses.choice_id + and survey_choice_scores.variable_id = survey_variables.variable_id + and survey_question_responses.response_id = :response_id + group by variable_name" { + set sum_score($variable_name) $sum_of_scores + } + + set logic [db_string get_logic "select logic from survey_logic, survey_logic_surveys_map + where survey_logic.logic_id = survey_logic_surveys_map.logic_id + and section_id = :section_id"] + + + if {[info exists return_url] && ![empty_string_p $return_url]} { + + ad_returnredirect $return_url + + } + + eval $logic + + } + + default { + if {[info exists return_url] && ![empty_string_p $return_url]} { + ad_returnredirect "$return_url" + return + } else { + set context_bar [ad_context_bar "Response Submitted for $survey_name"] + + ad_return_template + } + } +} + + Index: openacs-4/packages/survey/www/process-response.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/process-response.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/process-response.xql 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,131 @@ + + + + + + + select 1 from survey_sections where section_id = :section_id + + + + + + + + + select question_id, question_text, abstract_data_type, presentation_type, required_p + from survey_questions + where section_id = :section_id + and active_p = 't' + order by sort_order + + + + + + + + + select question_id, question_text, abstract_data_type, presentation_type, required_p + from survey_questions + where section_id = :section_id + and active_p = 't' + order by sort_order + + + + + + + + insert into survey_question_responses (response_id, question_id, choice_id) + values (:response_id, :question_id, :response_value) + + + + + + + insert into survey_question_responses (response_id, question_id, choice_id) + values (:response_id, :question_id, :response_value) + + + + + + + insert into survey_question_responses (response_id, question_id, varchar_answer) + values (:response_id, :question_id, :response_value) + + + + + + + insert into survey_question_responses (response_id, question_id, boolean_answer) + values (:response_id, :question_id, :response_value) + + + + + + + insert into survey_question_responses (response_id, question_id, number_answer) + values (:response_id, :question_id, :response_value) + + + + + + + insert into survey_question_responses (response_id, question_id, date_answer) + values (:response_id, :question_id, :response_value) + + + + + + + select type from survey_sections where section_id = :section_id + + + + + + + select name from survey_sections where section_id = :section_id + + + + + + + select variable_name, sum(score) as sum_of_scores + from survey_choice_scores, survey_question_responses, survey_variables + where survey_choice_scores.choice_id = survey_question_responses.choice_id + and survey_choice_scores.variable_id = survey_variables.variable_id + and survey_question_responses.response_id = :response_id + group by variable_name + + + + + + + select logic from survey_logic, survey_logic_surveys_map + where survey_logic.logic_id = survey_logic_surveys_map.logic_id + and section_id = :section_id + + + + + + + insert into survey_question_responses + (response_id, question_id, attachment_file) + values + (:response_id, :question_id, :revision_id) + + + + Index: openacs-4/packages/survey/www/respond-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/respond-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/respond-oracle.xql 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,24 @@ + + + + oracle8.1.6 + + + + + select survey_response.initial_response_id(:response_id) as initial_response_id from dual + + + + + + + select count(*) from survey_responses + where survey_id=:survey_id + and survey_response.initial_user_id(response_id)=:user_id + and initial_response_id is null + + + + + Index: openacs-4/packages/survey/www/respond.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/respond.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/respond.adp 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,28 @@ + +One Survey: @name@ +@context_bar@ + + + + + + + + + + + + + + + + + + +
@description@
* denotes a required question

+ @form_vars@ + +
+ +
Index: openacs-4/packages/survey/www/respond.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/respond.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/respond.tcl 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,82 @@ +ad_page_contract { + + Display a questionnaire for one survey. + + @param section_id id of displayed survey + + @author philg@mit.edu + @author nstrug@arsdigita.com + @date 28th September 2000 + @cvs-id $Id: respond.tcl,v 1.1 2002/09/16 00:00:23 daveb Exp $ + +} { + + survey_id:integer,notnull + {section_id:integer 0} + {response_id:integer 0} + return_url:optional + +} -validate { + survey_exists -requires {survey_id} { + if ![db_0or1row survey_exists {}] { + ad_complain "Survey $survey_id does not exist" + } + set user_id [ad_maybe_redirect_for_registration] + set number_of_responses [db_string count_responses {}] + get_survey_info -survey_id $survey_id + set name $survey_info(name) + set description $survey_info(description) + set single_response_p $survey_info(single_response_p) + set editable_p $survey_info(editable_p) + set display_type $survey_info(display_type) + if {($single_response_p=="t" && $editable_p=="f" && $number_of_responses>0) || ($single_response_p=="t" && $editable_p=="t" && $number_of_responses>0 && $response_id==0)} { + ad_complain "You have already completed this survey" + } elseif {$response_id>0 && $editable_p=="f"} { + ad_complain "This survey is not editable" + } + } +} -properties { + + name:onerow + section_id:onerow + button_label:onerow + questions:onerow + description:onerow + modification_allowed_p:onerow + return_url:onerow +} + +ad_require_permission $survey_id survey_take_survey + +set context_bar [ad_context_bar "$name"] +set button_label "Submit response" +if {$editable_p == "t"} { + if {$response_id > 0} { + set button_label "Modify previous response" + db_1row get_initial_response "" + } +} + +# build a list containing the HTML (generated with survey_question_display) for each question +set rownum 0 + +set questions [list] + +db_foreach survey_sections {} { + + db_foreach question_ids_select {} { + lappend questions [survey_question_display $question_id $response_id] + } + + # return_url is used for infoshare - if it is set + # the survey will return to it rather than + # executing the survey associated with the logic + # after the survey is completed + # + if ![info exists return_url] { + set return_url {} + } +} +set form_vars [export_form_vars section_id survey_id] +ad_return_template + Index: openacs-4/packages/survey/www/respond.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/respond.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/respond.xql 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,31 @@ + + + + + + + select 1 from surveys where survey_id = :survey_id + + + + + + + + select question_id + from survey_questions + where section_id = :section_id + and active_p = 't' + order by sort_order + + + + + + +select section_id from survey_sections +where survey_id=:survey_id + + + + Index: openacs-4/packages/survey/www/response-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/Attic/response-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/response-postgresql.xql 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,20 @@ + + + + postgresql7.1 + + + + select survey_response__initial_response_id(:response_id) as initial_response_id + + + + + + select count(*) from survey_responses + where survey_id=:survey_id + and survey_response__initial_user_id(response_id)=:user_id + + + + Index: openacs-4/packages/survey/www/view-attachment.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/view-attachment.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/view-attachment.tcl 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,33 @@ +ad_page_contract { + + View the attachment contents of a given response. + This page has been modified to use the CR for attachment storage dave@thedesignexperience.org + + @param response_id id of complete survey response submitted by user + @param question_id id of question for which this file was submitted as an answer + + + @author jbank@arsdigita.com + @author nstrug@arsdigita.com + @date 28th September 2000 + @cvs-id $Id: view-attachment.tcl,v 1.1 2002/09/16 00:00:23 daveb Exp $ +} { + + response_id:integer,notnull + question_id:integer,notnull + +} -validate { + attachment_exists -requires {response_id question_id} { + db_1row get_file_info {} + + if { [empty_string_p $file_type] } { + ad_complain "Couldn't find attachment. Couldn't find an attachment matching the response_id $response_id, question_id $question_id given." + } + } +} + +ReturnHeaders $file_type + +cr_write_content -revision_id $revision_id + + Index: openacs-4/packages/survey/www/view-attachment.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/view-attachment.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/view-attachment.xql 16 Sep 2002 00:00:23 -0000 1.1 @@ -0,0 +1,17 @@ + + + + + + select r.revision_id, r.mime_type as file_type + from cr_revisions r + where revision_id=( + select attachment_answer from survey_question_responses + where question_id=:question_id + and response_id=:response_id + ) + + + + + Index: openacs-4/packages/survey/www/admin/#response-drill-down.adp# =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/Attic/#response-drill-down.adp#,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/#response-drill-down.adp# 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,9 @@ + + +@survey_id@ + +@survey_name@: Responses to Question +@context_bar@ +@question_text@ + + Index: openacs-4/packages/survey/www/admin/#response-drill-down.tcl# =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/Attic/#response-drill-down.tcl#,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/#response-drill-down.tcl# 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,80 @@ +ad_page_contract { + + Display the list of users who gave a particular answer to a + particular question. + + @param question_id question for which we're drilling down responses + @param choice_id we're seeking respondents who selected this choice + as an answer to question + + @author philg@mit.edu + @author jsc@arsdigita.com + @author nstrug@arsdigita.com + @date February 16, 2000 + @cvs-id $Id: #response-drill-down.tcl#,v 1.1 2002/09/16 00:00:24 daveb Exp $ + +} { + + question_id:integer,notnull + choice_id:integer,notnull + +} + +ad_require_permission $question_id survey_admin_survey + +# get the prompt text for the question and the ID for survey of +# which it is part + +set question_exists_p [db_0or1row get_question_text ""] +get_survey_info -section_id $section_id +set survey_name $survey_info(name) +set survey_id $survey_info(survey_id) + +if { !$question_exists_p } { + db_release_unused_handles + ad_return_error "Survey Question Not Found" "Could not find a survey question #$question_id" + return +} + +set response_exists_p [db_0or1row get_response_text ""] + +if { !$response_exists_p } { + db_release_unused_handles + ad_return_error "Response Not Found" "Could not find the response #$choice_id" + return +} + +set user_id [ad_get_user_id] + +set results "" + +# Get information of users who responded in particular manner to +# choice question. +db_multirow users all_users_for_response "" { + + append results "
  • $responder_name\n" +} + + + +doc_return 200 text/html "[ad_header "People who answered \"$response_text\""] + +

    Responder List

    + +[ad_context_bar \ + [list "one?[export_url_vars survey_id]" $survey_info(name)] \ + [list "responses?[export_url_vars survey_id]" "Responses"] \ + "One Response"] + +
    + +$survey_name responders who answered \"$response_text\" +when asked \"$question_text\": + +
      +$results +
    + +[ad_footer] +" + Index: openacs-4/packages/survey/www/admin/description-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/description-edit.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/description-edit.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,7 @@ + +@survey_id@ + +@survey_name@: Edit Description +@context_bar@ + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/description-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/description-edit.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/description-edit.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,55 @@ +ad_page_contract { + + Form to allow user to the description of a survey. + + @param section_id integer denoting survey whose description we're changing + + @author Jin Choi (jsc@arsdigita.com) + @author nstrug@arsdigita.com + @date February 16, 2000 + @cvs-id $Id: description-edit.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + + survey_id:integer + +} + +ad_require_permission $survey_id survey_modify_survey +ad_form -name edit-survey -form { + survey_id:key + {description:text(textarea) {label "Survey Description"} {html {rows 10 cols 65}}} + {desc_html:text(radio) {label "The Above Description is"} + {options {{"Preformatted Text" "pre"} + {"HTML" "html"} {"Plain Text" "plain"}}}} +} -edit_request { + get_survey_info -survey_id $survey_id + set survey_name $survey_info(name) + set description $survey_info(description) + set description_html_p $survey_info(description_html_p) + set desc_html "" + if {$description_html_p=="t"} { + set desc_html "html" + } else { + set desc_html "plain" + } + ad_set_form_values desc_html description + +} -validate { + {description {[string length $description] <= 4000} + "Description must be less than 4000 characters" + } +} +} -edit_data { + if {$desc_html=="pre" || $desc_html=="html"} { + set description_html_p t + } else { + set description_html_p f + } + db_dml survey_update_description "" + + ad_returnredirect "one?[export_url_vars survey_id]" +} + +set context_bar [ad_context_bar [list "one.tcl?[export_url_vars survey_id]" $survey_info(name)] "Edit Description"] + +ad_return_template Index: openacs-4/packages/survey/www/admin/description-edit.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/description-edit.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/description-edit.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,22 @@ + + + + + + select name as survey_name, description, description_html_p as desc_html +from surveys +where survey_id = :survey_id + + + + + + + update surveys + set description = :description, + description_html_p = :description_html_p + where survey_id = :survey_id + + + + Index: openacs-4/packages/survey/www/admin/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/index.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/index.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,15 @@ + + +Survey Administration +@context_bar@ +1 + Index: openacs-4/packages/survey/www/admin/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/index.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/index.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,24 @@ +# /www/survsimp/admin/index.tcl +ad_page_contract { + This page is the main table of contents for navigation page + for simple survey module administrator + + @author philg@mit.edu + @author nstrug@arsdigita.com + @date 3rd October, 2000 + @cvs-id $Id: index.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + +} + +set context_bar [ad_context_bar] + +set package_id [ad_conn package_id] + +# bounce the user if they don't have permission to admin surveys +ad_require_permission $package_id survey_admin_survey + +set disabled_header_written_p 0 + +db_multirow surveys select_surveys {} +ad_return_template Index: openacs-4/packages/survey/www/admin/index.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/index.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/index.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,14 @@ + + + + + + select survey_id, name, enabled_p +from surveys +where package_id= :package_id +order by enabled_p desc, upper(name) + + + + + Index: openacs-4/packages/survey/www/admin/master.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/master.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/master.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,11 @@ + + + @context_bar@ + + +

    @title@

    +
    +Group Survey Administration | Admin This Survey + +

    + Index: openacs-4/packages/survey/www/admin/modify-responses-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/modify-responses-2.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/modify-responses-2.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,51 @@ +ad_page_contract { + Modify question responses + + @param section_id integer denoting which survey we're adding question to + @param question_id id of new question + @param responses list of possible responses + @param scores list of variable scores + + @author Nick Strugnell (nstrug@arsdigita.com) + @date September 15, 2000 + @cvs-id $Id: modify-responses-2.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + section_id:integer,notnull + question_id:integer,notnull + {responses:multiple ""} + {scores:multiple,array,integer ""} + {variable_id_list ""} + {choice_id_list ""} +} + +ad_require_permission $section_id survey_modify_question + +db_transaction { + + set i 0 + foreach choice_id $choice_id_list { + set trimmed_response [string trim [lindex $responses $i]] + db_dml update_survey_question_choice "update survey_question_choices + set label = :trimmed_response + where choice_id = :choice_id" + + foreach variable_id $variable_id_list { + set score_list $scores($variable_id) + set score [lindex $score_list $i] + db_dml update_survey_scores "update survey_choice_scores + set score = :score + where choice_id = :choice_id + and variable_id = :variable_id" + } + + incr i + } +} + +db_release_unused_handles + +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) +ad_returnredirect "one?[export_url_vars survey_id]" + + Index: openacs-4/packages/survey/www/admin/modify-responses-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/modify-responses-2.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/modify-responses-2.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,23 @@ + + + + + + update survey_question_choices + set label = :trimmed_response + where choice_id = :choice_id + + + + + + + update survey_choice_scores + set score = :score + where choice_id = :choice_id + and variable_id = :variable_id + + + + + Index: openacs-4/packages/survey/www/admin/modify-responses.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/modify-responses.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/modify-responses.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,88 @@ +ad_page_contract { + + Modify question responses and scores + + @param question_id which question we'll be changing responses of + @param section_id survey providing this question + + @author Nick Strugnell (nstrug@arsdigita.com) + @date September 15, 2000 + @cvs-id $Id: modify-responses.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + + question_id:integer + section_id:integer + +} + +ad_require_permission $section_id survey_modify_question + +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) + +set survey_name [db_string survey_name_from_id "select name from survey_sections where section_id=:section_id" ] + +set question_text [db_string survey_question_text_from_id "select question_text +from survey_questions +where question_id = :question_id" ] + +set table_html " +" + +set variable_id_list [list] + +db_foreach get_variable_names "select variable_name, survey_variables.variable_id as variable_id + from survey_variables, survey_variables_surveys_map + where survey_variables.variable_id = survey_variables_surveys_map.variable_id + and section_id = :section_id + order by variable_name" { + + lappend variable_id_list $variable_id + append table_html "" + } + +append table_html "\n" + +set choice_id_list [list] + +db_foreach get_choices "select choice_id, label from survey_question_choices where question_id = :question_id order by choice_id" { + lappend choice_id_list $choice_id + append table_html "" + + db_foreach get_scores "select score, survey_variables.variable_id as variable_id + from survey_choice_scores, survey_variables + where survey_choice_scores.choice_id = :choice_id + and survey_choice_scores.variable_id = survey_variables.variable_id + order by variable_name" { + + append table_html "" + } + + append table_html "\n" +} + +append table_html "
    Response$variable_name
    \n" + +db_release_unused_handles + +doc_return 200 text/html "[ad_header "Modify Responses"] +

    $survey_name

    + +[ad_context_bar [list "one?[export_url_vars survey_id]" $survey_info(name)] "Modify Question Responses"] + +
    + +Question: $question_text +

    +

    +[export_form_vars section_id question_id choice_id_list variable_id_list] +$table_html +

    +

    + +
    + +
    + +[ad_footer] +" Index: openacs-4/packages/survey/www/admin/modify-responses.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/modify-responses.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/modify-responses.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,49 @@ + + + + + + select name from survey_sections where section_id=:section_id + + + + + + + select question_text +from survey_questions +where question_id = :question_id + + + + + + + select variable_name, survey_variables.variable_id as variable_id + from survey_variables, survey_variables_surveys_map + where survey_variables.variable_id = survey_variables_surveys_map.variable_id + and section_id = :section_id + order by variable_name + + + + + + + select choice_id, label from survey_question_choices where question_id = :question_id order by choice_id + + + + + + + select score, survey_variables.variable_id as variable_id + from survey_choice_scores, survey_variables + where survey_choice_scores.choice_id = :choice_id + and survey_choice_scores.variable_id = survey_variables.variable_id + order by variable_name + + + + + Index: openacs-4/packages/survey/www/admin/name-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/name-edit.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/name-edit.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,8 @@ + +@survey_id@ + +@survey_name@: Edit Name +@context_bar@ + +Edit and submit to change the name for this survey: + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/name-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/name-edit.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/name-edit.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,45 @@ +ad_page_contract { + + Edit the name of the survey + + @param section_id integer denoting survey whose description we're changing + + @author Jin Choi (jsc@arsdigita.com) + @author nstrug@arsdigita.com + @date February 16, 2000 + @cvs-id $Id: name-edit.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + + survey_id:integer + {name ""} +} + +get_survey_info -survey_id $survey_id +set survey_name $survey_info(name) +set survey_description $survey_info(description) + +ad_require_permission $survey_id survey_modify_survey + +ad_form -name edit-name -form { + survey_id:key + {name:text(text) {label "Survey Name"} {html {size 80}} + {value $survey_name}} + {description:text(textarea) {label "Description"} + {html {rows 10 cols 65}} + {value $survey_description}} +} -validate { + {name {[string length $name] <= 4000} + "Survey Name must be less than 4000 characters" + } +} -edit_request { + set name $survey_name +} -edit_data { + db_dml survey_update "" + ad_returnredirect "one?[export_vars survey_id]" +} +set context_bar [ad_context_bar "Edit Name"] + + +ad_return_template + + Index: openacs-4/packages/survey/www/admin/name-edit.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/name-edit.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/name-edit.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,11 @@ + + + + +update surveys +set name= :name, + description= :description +where survey_id = :survey_id + + + Index: openacs-4/packages/survey/www/admin/one-respondent-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/one-respondent-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/one-respondent-oracle.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,18 @@ + + + + oracle8.1.6 + + + + + select response_id, case when initial_response_id is NULL then 'T' else 'F' end as original_p, survey_response.initial_response_id(response_id) as initial_response, creation_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 + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/one-respondent-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/one-respondent-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/one-respondent-postgresql.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,16 @@ + + + + postgresql7.1 + + + select response_id, case when initial_response_id is NULL then 'T' else 'F' end as original_p, survey_response__initial_response_id(response_id) as initial_response, creation_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 + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/one-respondent.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/one-respondent.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/one-respondent.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,36 @@ + + +@survey_id@ + +@survey_id@ +@survey_info.name@ +One Respondent: @first_names@ @last_name@ +@context_bar@ + + + + + + + + + + +
    + Here is what @first_names@ @last_name@ had to say in response to @survey_name@: +
    + + + +Delete + + [OriginalEdited + Response on @responses.creation_date@] +
    +@responses.response_display@ + + +
    +

    + Index: openacs-4/packages/survey/www/admin/one-respondent.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/one-respondent.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/one-respondent.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,41 @@ +ad_page_contract { + + Display the filled-out survey for a single user. + + @param user_id user whose response we're viewing + @param section_id survey we're viewing + @author jsc@arsdigita.com + @author nstrug@arsdigita.com + @date February 11, 2000 + @cvs-id $Id: one-respondent.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + + user_id:integer + survey_id:integer + +} + +ad_require_permission $survey_id survey_admin_survey + +get_survey_info -survey_id $survey_id +set survey_name $survey_info(name) +set description $survey_info(description) +set type $survey_info(type) + +# survey_name and description are now set + +set user_exists_p [db_0or1row user_name_from_id "select first_names, last_name from persons where person_id = :user_id" ] + +if { !$user_exists_p } { + ad_return_error "Not Found" "Could not find user #$user_id" + return +} + +set context_bar [ad_context_bar "One Respondent"] + + +db_multirow -extend {response_display} responses get_responses {} { +set response_display [survey_answer_summary_display $response_id 1 ] +} + +ad_return_template \ No newline at end of file Index: openacs-4/packages/survey/www/admin/one-respondent.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/one-respondent.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/one-respondent.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,12 @@ + + + + + + select first_names, last_name from persons where person_id = :user_id + + + + + + Index: openacs-4/packages/survey/www/admin/one.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/one.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/one.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,100 @@ + +@survey_id@ + +One Survey: @survey_info.name@ +@context_bar@ +

    Group Survey Administration

    +@survey_info.name@ - Created by @survey_info.creator_name@, on @creation_date@ + + + + + + + + + + + + + + + + + + + + + + + + +
    This survey is @survey_info.enabled_display@@survey_info.enabled_display@. - @toggle_enabled_text@
    Survey Name:

    +Description:

    +Preview + + Edit +@survey_info.name@

    +@survey_info.description@

    View Responses: + By user | Summary | + CSV file
    Response Options: @survey_info.single_response_display@ - [ + @response_limit_toggle@ + ]
    Users may edit their responsesUsers may not edit their respones - [ make non-editable ]
    Display Opinons: @survey_info.display_type@ - [@survey_display_types:item@]
    Email Options:@notification_chunk@
    Send bulk + mail regarding this survey
    + +
    Extreme Actions: + Delete this survey - Removes all questions and responses
    + Copy this survey - Lets you use this survey as a template to create a new survey. +
    +
    + +

    Questions

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    add new question
    @questions.rownum@. Edit +[inactive] +Copy +Add New +Move DownMove UpDelete
    +
    @questions.question_display@
    +
    add new question
    Index: openacs-4/packages/survey/www/admin/one.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/one.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/one.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,90 @@ +ad_page_contract { + + This page allows the admin to administer a single survey. + + @param section_id integer denoting survey we're administering + + @author jsc@arsdigita.com + @author nstrug@arsdigita.com + @author dave@thedesignexperience.org + @date February 9, 2000 + @cvs-id $Id: one.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + + survey_id:integer + {section_id:integer ""} +} + +set package_id [ad_conn package_id] + +ad_require_permission $package_id survey_admin_survey + +# Get the survey information. +get_survey_info -survey_id $survey_id + +# get users and # who responded etc... +set community_id [dotlrn_community::get_community_id_from_url] +set n_eligible [db_string n_eligible { + select count(*) from dotlrn_member_rels_full + where rel_type='dotlrn_member_rel' + and community_id=:community_id}] + +set return_html "" + +# Leaving this commented out until we evaluate scored surveys -- Luke +# switch $survey_info(type) { +# "general" { +# set return_html "" +# } +# "scored" { +# upvar section_id local_section_id +# set return_html "
  • Edit survey logic" +# } + +# default { +# set return_html "" +# } +# return $return_html +# } + +set creation_date [util_AnsiDatetoPrettyDate $survey_info(creation_date)] +set user_link [acs_community_member_url -user_id $survey_info(creation_user)] +if {$survey_info(single_response_p) == "t"} { + set response_limit_toggle "allow multiple" +} else { + set response_limit_toggle "limit to one" +} + + +# allow site-wide admins to enable/disable surveys directly from here +set target "one?[export_url_vars survey_id]" +set enabled_p $survey_info(enabled_p) +set toggle_enabled_url "survey-toggle?[export_vars {survey_id enabled_p target}]" +if {$enabled_p == "t"} { + append toggle_enabled_text "disable" +} else { + append toggle_enabled_text "enable" +} + + +# Display Type (ben) +# provide list survey_display_types to adp process with +set survey_display_types [survey_display_types] + + +# Questions summary. +# We need to get the questions for ALL sections. + +set context_bar [ad_context_bar $survey_info(name)] + +db_multirow -extend { question_display } questions survey_questions "" {set question_display [survey_question_display $question_id]} + + +set notification_chunk [notification::display::request_widget \ + -type survey_response_notif \ + -object_id $survey_id \ + -pretty_name $survey_info(name) \ + -url [ad_conn url]?survey_id=$survey_id \ +] + +ad_return_template Index: openacs-4/packages/survey/www/admin/one.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/one.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/one.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,20 @@ + + + + + +select question_id, sort_order, active_p, required_p, section_id + from survey_questions + where section_id in ( select section_id from survey_sections where survey_id=:survey_id) + order by section_id, sort_order + + + + + +select section_id from survey_sections +where survey_id=:survey_id + + + + Index: openacs-4/packages/survey/www/admin/question-active-toggle-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-active-toggle-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-active-toggle-oracle.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,14 @@ + + + oracle8.1.6 + + + + update survey_questions set active_p = util.logical_negation(active_p) +where section_id = :section_id +and question_id = :question_id + + + + + Index: openacs-4/packages/survey/www/admin/question-active-toggle-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-active-toggle-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-active-toggle-postgresql.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,14 @@ + + + postgresql7.1 + + + + update survey_questions set active_p = util__logical_negation(active_p) +where section_id = :section_id +and question_id = :question_id + + + + + Index: openacs-4/packages/survey/www/admin/question-active-toggle.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-active-toggle.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-active-toggle.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,27 @@ +# /www/survsimp/admin/question-active-toggle.tcl +ad_page_contract { + + Toggles if a response to required for a given question. + + @param section_id survey we're operating with + @param question_id denotes which question in survey we're updating + + @cvs-id question-active-toggle.tcl,v 1.5.2.4 2000/07/21 04:04:11 ron Exp +} { + + section_id:integer + question_id:integer + +} + +ad_require_permission $section_id survey_admin_survey + +db_dml survey_question_required_toggle "update survey_questions set active_p = util.logical_negation(active_p) +where section_id = :section_id +and question_id = :question_id" + +db_release_unused_handles +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) +ad_returnredirect "one?[export_url_vars survey_id]" + Index: openacs-4/packages/survey/www/admin/question-add-2.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-add-2.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-add-2.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,8 @@ + +@survey_id@ + +Survey Administration: Add a Question (cont.) +@context_bar@ + + + Index: openacs-4/packages/survey/www/admin/question-add-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-add-2.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-add-2.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,177 @@ +# /www/survsimp/admin/question-add-2.tcl +ad_page_contract { + + Based on the presentation type selected in previous form, + gives the user various options on how to lay out the question. + + @param section_id integer determining survey we're dealing with + @param after optional integer determining placement of question + @param question_text text comprising this question + @param presentation_type string denoting widget used to provide answer + @param required_p flag indicating whether this question is mandatory + @param active_p flag indicating whether this question is active + @param category_id optional integer describing category of this question (within survey) + + @author Jin Choi (jsc@arsdigita.com) + @author nstrug@arsdigita.com + @date February 9, 2000 + @cvs-id $Id: question-add-2.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + + section_id:integer + question_text:html,notnull + presentation_type + {after:integer ""} + {required_p t} + {active_p t} + {n_responses ""} + +} + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] +ad_require_permission $package_id survey_create_question + +set question_id [db_nextval acs_object_id_seq] +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) +set type $survey_info(type) + +# create a blank form, we fill it based on the question type +# maybe put question_id:key in there if we move the processing from quesion-add-3 to this form. + +ad_form -name create-question-2 -action question-add-3 -form { + {question:text(inform) {label "Question Text"} {value $question_text}} + {survey_id:text(hidden) {value $survey_id}} + {section_id:text(hidden) {value $section_id}} + {question_id:text(hidden) {value $question_id}} + {question_text:text(hidden) {value $question_text}} + {presentation_type:text(hidden) {value $presentation_type}} + {after:text(hidden) {value $after}} + {required_p:text(hidden) {value $required_p}} + {active_p:text(hidden) {value $active_p}} + {type:text(hidden) {value $type}} +} + + +# set exception_count 0 +# set exception_text "" + +# if { $type != "general" && $type != "scored" } { +# incr exception_count +# append exception_text "
  • Surveys of type $type are not currently available\n" +# } + +# if { $presentation_type == "upload_file" } { +# # incr exception_count +# # append exception_text "
  • The presentation type: upload file is not supported at this time." + +# } + +# if { $exception_count > 0 } { +# ad_return_complaint $exception_count $exception_text +# return +# } + +# Survey-type specific question settings + +if { $type == "scored" } { + + db_1row count_variable_names "" + + set response_fields " + +" + + set variable_id_list [list] + db_foreach select_variable_names "" { + lappend variable_id_list $variable_id + append response_fields "" + } + + append response_fields "\n" + + for {set response 0} {$response < $n_responses} {incr response} { + append response_fields "" + for {set variable 0} {$variable < $n_variables} {incr variable} { + append response_fields "" + } + append response_fields "\n" + } + + append response_fields "
    Answer TextScore
    $variable_name
    \n" + set response_type_html "" + set presentation_options_html "" + set form_var_list [export_form_vars section_id question_id question_text presentation_type after required_p active_p type n_variables variable_id_list] + +} elseif { $type == "general" } { + +# Display presentation options for sizing text input fields and textareas. + + switch -- $presentation_type { + "textbox" { + + ad_form -extend -name create-question-2 -form { + {textbox_size:text(select) {options {{Small small} {Medium medium} {Large large}}} {label "Size"}} + {abstract_data_type:text(select) {label "Type of Response"} + {options {{"Short Text" shorttext} {Text text} {Boolean boolean} {Number number} {Integer integer}}} + } + + } + } + "textarea" { + ad_form -extend -name create-question-2 -form { + {textarea_size:text(select) {options {{Small small} {Medium medium} {Large large}}} {label "Size"}} + {abstract_data_type:text(hidden) {value "text"}} + + } + } + } +} +# Let user enter valid responses for selections, radio buttons, and check boxes. + + set response_fields "" + + switch -- $presentation_type { + "radio" - + "select" { + + ad_form -extend -name create-question-2 -form { + {abstract_data_type:text(radio) + {label "Type of Response"} {value "choice"} + {options {{"True or False" boolean} {"Yes or No" yn} {"Multiple Choice" choice}}}} + {valid_responses:text(textarea) + {label "For Multiple Choice
    Enter a List of Valid Responses
    (enter one choice per line)"} + {html {rows 10 cols 50}}} + } + } + + "checkbox" { + ad_form -extend -name create-question-2 -form { + {valid_responses:text(textarea) {label "Valid Resposnes (enter one choice per line)"} {html {rows 10 cols 50}}} + {abstract_data_type:text(hidden) {value "choice"}} + } + } + + + + "date" { + + ad_form -extend -name create-question-2 -form { + {abstract_data_type:text(hidden) {value date}} + } + + } + "upload_file" { + ad_form -extend -name create-question-2 -form { + {abstract_data_type:text(hidden) {value blob}} + } + } + } + +ad_form -extend -name create-question-2 -form { + {presentation_alignment:text(radio) {options {{"Beside the question" beside} {"Below the question" below}}} {value below} {label "Presentation Alignment"}} +} +set context_bar [ad_context_bar [list "one?[export_url_vars survey_id]" $survey_info(name)] "Add A Question"] + +ad_return_template Index: openacs-4/packages/survey/www/admin/question-add-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-add-2.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-add-2.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,24 @@ + + + + + + + select count(variable_name) as n_variables + from survey_variables, survey_variables_surveys_map + where survey_variables.variable_id = survey_variables_surveys_map.variable_id + and section_id = :section_id + + + + + + select variable_name, survey_variables.variable_id as variable_id + from survey_variables, survey_variables_surveys_map + where survey_variables.variable_id = survey_variables_surveys_map.variable_id + and section_id = :section_id order by survey_variables.variable_id + + + + + Index: openacs-4/packages/survey/www/admin/question-add-3-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-add-3-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-add-3-oracle.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,37 @@ + + + + oracle8.1.6 + + + + + begin + :1 := survey_question.new ( + question_id => :question_id, + section_id => :section_id, + sort_order => :sort_order, + question_text => empty_clob(), + abstract_data_type => :abstract_data_type, + presentation_type => :presentation_type, + presentation_alignment => :presentation_alignment, + presentation_options => :presentation_options, + active_p => :active_p, + required_p => :required_p, + context_id => :section_id, + creation_user => :user_id + ); + end; + + + + + + + + select survey_choice_id_sequence.nextval as choice_id from dual + + + + + Index: openacs-4/packages/survey/www/admin/question-add-3-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-add-3-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-add-3-postgresql.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,35 @@ + + + + postgresql7.1 + + + + + select survey_question__new ( + :question_id, + :section_id, + :sort_order, + :question_text, + :abstract_data_type, + :required_p, + :active_p, + :presentation_type, + :presentation_options, + :presentation_alignment, + :user_id, + :section_id + ) + + + + + + + + select survey_choice_id_sequence.nextval as choice_id + + + + + Index: openacs-4/packages/survey/www/admin/question-add-3.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-add-3.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-add-3.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,145 @@ +# /www/survsimp/admin/question-add-3.tcl +ad_page_contract { + Inserts a new question into the database. + + @param section_id integer denoting which survey we're adding question to + @param question_id id of new question + @param after optional integer determining position of this question + @param question_text text of question + @param abstract_data_type string describing datatype we expect as answer + @param presentation_type string describing widget for providing answer + @param presentation_alignment string determining placement of answer widget relative to question text + @param valid_responses string containing possible choices, one per line + @param textbox_size width of textbox answer widget + @param textarea_size size of textarea answer widget + @param required_p flag telling us whether an answer to this question is mandatory + @param active_p flag telling us whether this question will show up at all + + @author Jin Choi (jsc@arsdigita.com) February 9, 2000 + @author nstrug@arsdigita.com + @cvs-id $Id: question-add-3.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + section_id:integer,notnull + question_id:integer,notnull + after:integer,optional + question_text:html + {abstract_data_type ""} + presentation_type + presentation_alignment + type:notnull + {valid_responses ""} + {textbox_size ""} + {textarea_size: "medium"} + {required_p t} + {active_p t} + {responses:multiple ""} + {scores:multiple,array,integer ""} + {n_variables:integer ""} + {variable_id_list ""} +} + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] +ad_require_permission $package_id survey_create_question +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) +set exception_count 0 +set exception_text "" + +if { [empty_string_p $question_text] } { + incr exception_count + append exception_text "
  • You did not enter a question.\n" +} + +if { $type != "scored" && $type != "general" } { + incr exception_count + append exception_text "
  • Surveys of type $type are not currently available.\n" +} + +if { $type == "general" && $abstract_data_type == "choice" && [empty_string_p $valid_responses] } { + incr exception_count + append exception_text "
  • You did not enter a list of valid responses/choices.\n" +} + + +if { $exception_count > 0 } { + ad_return_complaint $exception_count $exception_text + return +} + + +# Generate presentation_options. + set presentation_options "" + if { $presentation_type == "textbox" } { + if { [exists_and_not_null textbox_size] } { + # Will be "small", "medium", or "large". + set presentation_options $textbox_size + } + } elseif { $presentation_type == "textarea" } { + if { [exists_and_not_null textarea_size] } { + # Will be "small", "medium", or "large". + set presentation_options $textarea_size + } + } elseif { $abstract_data_type == "yn" } { + set abstract_data_type "boolean" + set presentation_options "Yes/No" + } elseif { $abstract_data_type == "boolean" } { + set presentation_options "True/False" + } + + db_transaction { + if { [exists_and_not_null after] } { + # We're inserting between existing questions; move everybody down. + set sort_order [expr { $after + 1 }] + db_dml renumber_sort_orders {} + } else { + set sort_order [expr [db_string max_question {}] + 1] + } + + db_exec_plsql create_question {} + + db_dml add_question_text {} + + + # For questions where the user is selecting a canned response, insert + # the canned responses into survey_question_choices by parsing the valid_responses + # field. + if { $presentation_type == "checkbox" || $presentation_type == "radio" || $presentation_type == "select" } { + if { $abstract_data_type == "choice" } { + set responses [split $valid_responses "\n"] + set count 0 + foreach response $responses { + set trimmed_response [string trim $response] + if { [empty_string_p $trimmed_response] } { + # skip empty lines + continue + } + ### added this next line to + set choice_id [db_string get_choice_id "select survey_choice_id_sequence.nextval as choice_id from dual"] + db_dml insert_survey_question_choice "insert into survey_question_choices (choice_id, question_id, label, sort_order) +values (survey_choice_id_sequence.nextval, :question_id, :trimmed_response, :count)" + incr count + } + } + } + } on_error { + + set already_inserted_p [db_string already_inserted_p "select decode(count(*),0,0,1) from survey_questions where question_id = :question_id" ] + + if { !$already_inserted_p } { + db_release_unused_handles + ad_return_error "Database Error" "
    $errmsg
    " + return + } + } + + +db_release_unused_handles +ad_returnredirect "one?survey_id=$survey_id&#${sort_order}" + + + + + + + Index: openacs-4/packages/survey/www/admin/question-add-3.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-add-3.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-add-3.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,59 @@ + + + + + + update survey_questions + set sort_order = sort_order + 1 + where section_id = :section_id + and sort_order > :after + + + + + + + + update survey_questions + set question_text = :question_text + where question_id = :question_id + + + + + + + + insert into survey_question_choices + (choice_id, question_id, label, sort_order) + values + (:choice_id, :question_id, :trimmed_response, :count) + + + + + + + insert into survey_choice_scores + (choice_id, variable_id, score) + values + (:choice_id, :variable_id, :score) + + + + + + + select case when count(*) = 0 then 0 else 1 end from survey_questions where question_id = :question_id + + + + + + + select max(sort_order) from survey_questions + where section_id=:section_id + + + + Index: openacs-4/packages/survey/www/admin/question-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-add.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-add.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,9 @@ + +@survey_id@ + +@survey_info.name@: New Question +@context_bar@ + + + + Index: openacs-4/packages/survey/www/admin/question-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-add.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-add.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,66 @@ +ad_page_contract { + Present form to begin adding a question to a survey. + Lets user enter the question and select a presentation type. + + @param section_id integer designating survey we're adding question to + @param after optinal integer denoting position of question within survey + + @author jsc@arsdigita.com + @author nstrug@arsdigita.com + @date February 9, 2000 + @cvs-id $Id: question-add.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + section_id:integer + {after:integer ""} + +} + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] +ad_require_permission $package_id survey_create_question + +get_survey_info -section_id $section_id + +# function to insert survey type-specific form html +ad_form -name create_question -action question-add-2 -export { after } -form { + question_id:key + {section_id:text(hidden) {value $section_id}} + {question_text:text(textarea) {label "Question"} {html {rows 5 cols 70}}} +} + +ad_form -extend -name create_question -form { + {presentation_type:text(select) + {label "Presentation Type"} + {options {{ "One Line Answer (Text Field)" "textbox" } + { "Essay Answer (Text Area)" "textarea" } + { "Multiple Choice (Drop Down, single answer allowed)" "select" } + { "Multiple Choice (Radio Buttons, single answer allowed)" "radio" } + { "Multiple Choice (Checkbox, multiple answers allowed)" "checkbox" } + { "Date" "date" } + { "File Attachment" "upload_file" } } } } +} + + + +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) +set context_bar [ad_context_bar [list "one?[export_url_vars survey_id]" $survey_info(name)] "Add A Question"] + +if {[ad_parameter allow_question_deactivation_p] == 1} { + ad_form -extend -name create_question -form { + {active:text(radio) {label "Active?"} {options {{Yes t} {No f}}} {value t}} + } +} else { + ad_form -extend -name create_question -form { + {active:text(hidden) {value t}} + } +} +ad_form -extend -name create_question -form { + {required:text(radio) {label "Required?"} {options {{Yes t} {No f}}} {value t}} +} + +ad_return_template + + + + Index: openacs-4/packages/survey/www/admin/question-copy-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/Attic/question-copy-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-copy-postgresql.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,33 @@ + + + + postgresql7.1 + + + + begin + PERFORM survey_question__new ( + NULL, + :section_id, + :new_sort_order, + :question_text, + :abstract_data_type, + :required_p, + :active_p, + :presentation_type, + :presentation_options, + :presentation_alignment, + :user_id, + :section_id + ); + end; + + + + + +select survey_choice_id_sequence.nextval as choice_id + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/question-copy.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-copy.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-copy.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,21 @@ +ad_page_contract { + Copy a question to the same survey + @author dave@thedesignexperience.org + @date July 29, 2002 + @cvs-id $Id: +} { + question_id:integer,notnull + {sort_order 0} +} + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] + +ad_require_permission $package_id survey_create_question +set section_id [db_string get_section_id_from_question {}] +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) +set new_question_id [survey_question_copy -question_id $question_id] +incr sort_order +ad_returnredirect "one?[export_vars survey_id]&#${sort_order}" + Index: openacs-4/packages/survey/www/admin/question-copy.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-copy.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-copy.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,10 @@ + + + + + +select section_id from survey_questions + where question_id=:question_id + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/question-delete-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/Attic/question-delete-2.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-delete-2.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,44 @@ +# /www/survsimp/admin/question-delete.tcl +ad_page_contract { + + Delete a question from a survey, along with all responses. + + @param question_id question we're deleting + @author jsc@arsdigita.com + @date March 13, 2000 + @cvs-id question-delete-2.tcl,v 1.6.2.4 2000/07/21 20:22:35 seb Exp +} { + + question_id:integer + +} + +ad_require_permission $question_id survey_delete_question + +set user_id [ad_get_user_id] + +db_1row section_id_from_question_id "" + +db_transaction { + db_dml survey_question_responses_delete "delete from survey_question_responses where question_id = :question_id" + +db_dml survey_question_choices_score_delete "delete from survey_choice_scores where choice_id in (select choice_id from survey_question_choices + where question_id = :question_id)" + + db_dml survey_question_choices_delete "delete from survey_question_choices where question_id = :question_id" + + db_dml survey_questions_delete "delete from survey_questions where question_id = :question_id" + +} on_error { + ad_return_error "Database Error" "There was an error while trying to delete the question: +
    +        $errmsg
    +        
    +

    Please go back to the survey. + " + return +} + +db_release_unused_handles +ad_returnredirect "one?[export_url_vars survey_id]" + Index: openacs-4/packages/survey/www/admin/question-delete-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/Attic/question-delete-2.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-delete-2.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,46 @@ + + + + + + select sq.section_id, sec.survey_id + from survey_questions sq, survey_sections sec + where sq.question_id = :question_id + and sq.section_id = sec.section_id + + + + + + + delete from survey_question_responses where question_id = :question_id + + + + + + + + delete from survey_choice_scores + where choice_id in (select choice_id from survey_question_choices + where question_id = :question_id) + + + + + + + + delete from survey_question_choices where question_id = :question_id + + + + + + + delete from survey_questions where question_id = :question_id + + + + + Index: openacs-4/packages/survey/www/admin/question-delete-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-delete-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-delete-oracle.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,14 @@ + + + + oracle8.1.6 + + + + begin + survey_question.remove (:question_id); + end; + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/question-delete-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-delete-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-delete-postgresql.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,15 @@ + + + + postgresql7.1 + + + + + select survey_question__delete (:question_id); + + + + + + Index: openacs-4/packages/survey/www/admin/question-delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-delete.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-delete.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,8 @@ + + +@survey_id@ + +DELETE: Question +@context_bar@ + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/question-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-delete.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-delete.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,84 @@ +# /www/survsimp/admin/question-delete.tcl +ad_page_contract { + + Delete a question from a survey + (or ask for confirmation if there are responses). + + @param question_id question we're about to delete + + @author jsc@arsdigita.com + @date March 13, 2000 + @cvs-id question-delete.tcl,v 1.5.2.4 2000/07/21 04:04:15 ron Exp +} { + + question_id:integer + {sort_order ""} +} + +ad_require_permission $question_id survey_delete_question + +db_1row section_id_from_question_id "" + +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) + +set n_responses [db_string survey_number_responses {} ] + +ad_form -name confirm_delete -export {sort_order} -form { + question_id:key + {question_text:text(inform) {label "Delete:"}} + {from:text(inform) {label "From:"} {value $survey_info(name)}} +} + +if {$n_responses > 0} { + if {$n_responses >1} { + set response_text "responses" + } else { + set response_text "response" + } + ad_form -extend -name confirm_delete -form { + {warning:text(inform) {value "This question has $n_responses $response_text that will be deleted if you continue. (Note: This can not be undone.)"} + {label "Warning!"}} + } + +} + +ad_form -extend -name confirm_delete -form { + {confirmation:text(radio) {label " "} + {options + {{"Continue with Delete" t } + {"Cancel and return to survey responses" f }} } + {value f}} + } -select_query_name {get_question_details} -on_submit { + if {$confirmation} { + db_transaction { + + db_dml survey_question_responses_delete {} + + db_dml survey_question_choices_delete {} + + db_exec_plsql survey_delete_question {} + if {![empty_string_p $sort_order]} { + db_exec_plsql survey_renumber_questions {} + } + } on_error { + + ad_return_error "Database Error" "There was an error while trying to delete the question: +

    +		$errmsg
    +		
    +

    Please go back using your browser. + " + return + } + + db_release_unused_handles + set sort_order [expr {$sort_order -1}] + } + ad_returnredirect "one?[export_url_vars survey_id]&#${sort_order}" + return + } + +set context_bar [ad_context_bar "Delete Question"] +ad_return_template + Index: openacs-4/packages/survey/www/admin/question-delete.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-delete.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-delete.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,52 @@ + + + + + + select section_id + from survey_questions + where question_id = :question_id + + + + + + + select count(*) +from survey_question_responses +where question_id = :question_id + + + + + + + delete from survey_question_responses + where question_id=:question_id + + + + + + delete from survey_question_choices where + question_id = :question_id + + + + + + select * from survey_questions where question_id=:question_id + + + + + +update survey_questions set sort_order=sort_order -1 +where section_id in ( + select section_id from surveys where + survey_id=:survey_id) +and sort_order > :sort_order + + + + Index: openacs-4/packages/survey/www/admin/question-modify-text.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-modify-text.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-modify-text.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,8 @@ + +@survey_id@ + +@survey_name@: Modify Question Text +@context_bar@ + + + Index: openacs-4/packages/survey/www/admin/question-modify-text.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-modify-text.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-modify-text.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,39 @@ +ad_page_contract { + + Allow the user to modify the text of a question. + + @param section_id survey this question belongs to + @param question_id question which text we're changing + + @author cmceniry@arsdigita.com + @author nstrug@arsdigita.com + @date Jun 16, 2000 + @cvs-id $Id: question-modify-text.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + + question_id:integer + section_id:integer + +} + +ad_require_permission $section_id survey_modify_question + +get_survey_info -section_id $section_id +set survey_name $survey_info(name) +set survey_id $survey_info(survey_id) + +ad_form -name modify_question -form { + question_id:key + {question_text:text(textarea) {label Question} {html {rows 5 cols 70}}} + {section_id:text(hidden) {value $section_id}} + {survey_id:text(hidden) {value $survey_id}} +} -select_query_name {survey_question_text_from_id} -edit_data { + +db_dml survey_question_text_update "update survey_questions set question_text=:question_text where question_id=:question_id" +ad_returnredirect "one.tcl?survey_id=$survey_id" + +} + +set context_bar [ad_context_bar [list "one?[export_url_vars survey_id]" $survey_info(name)] "Modify a Question's Text"] + +ad_return_template Index: openacs-4/packages/survey/www/admin/question-modify-text.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-modify-text.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-modify-text.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,20 @@ + + + + + + select name from survey_sections where section_id=:section_id + + + + + + +select question_text +from survey_questions +where question_id = :question_id + + + + + Index: openacs-4/packages/survey/www/admin/question-modify.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-modify.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-modify.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,8 @@ + +@survey_id@ + +@survey_name@: Modify Question Text +@context_bar@ + + + Index: openacs-4/packages/survey/www/admin/question-modify.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-modify.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-modify.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,146 @@ +ad_page_contract { + + Allow the user to modify a question. + + @param section_id survey this question belongs to + @param question_id question which text we're changing + + @author cmceniry@arsdigita.com + @author nstrug@arsdigita.com + @date Jun 16, 2000 + @cvs-id $Id: question-modify.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + + question_id:integer + section_id:integer + {valid_responses ""} + {presentation_options ""} + {sort_order ""} +} + +get_survey_info -section_id $section_id +set survey_name $survey_info(name) +set survey_id $survey_info(survey_id) +ad_require_permission $survey_id survey_modify_question +set allow_question_deactivation [ad_parameter "allow_question_deactivation_p"] +set n_responses [db_string survey_number_responses {} ] + +ad_form -name modify_question -form { + question_id:key +} + +if {$n_responses > 0} { + if {$n_responses >1} { + set isare "are" + set resp "responses" + } else { + set isare "is" + set resp "response" + } + ad_form -extend -name modify_question -form { + {warning:text(inform) {label "Warning!"} {value "There $isare $n_responses $resp to this question. Editing a question with responses is not recommnded. No record of the original question will remain. Proceed with caution."}} + } +} +ad_form -extend -name modify_question -export {sort_order} -form { + {question_number:text(inform) {label "Modify Question #"}} + {survey_name:text(inform) {label "From"} {value $survey_name}} + {question_text:text(textarea) {label Question} {html {rows 5 cols 70}}} +} + +if {$allow_question_deactivation == 1} { + ad_form -extend -name modify_question -form { + {active_p:text(radio) {label "Active?"} {options {{Yes t} {No f}}}} + } +} else { + ad_form -extend -name modify_question -form { + {active_p:text(hidden) {value t}} + } +} +ad_form -extend -name modify_question -form { + {required_p:text(radio) {label "Required?"} {options {{Yes t} {No f}}}} + {section_id:text(hidden) {value $section_id}} + {survey_id:text(hidden) {value $survey_id}} +} + + +db_1row presentation {} + +if {($presentation_type=="checkbox" || $presentation_type=="select" || $presentation_type=="radio") && $abstract_data_type != "boolean"} { + set valid_responses_list [db_list survey_question_valid_responses {}] + set response_list "" + foreach response $valid_responses_list { + append valid_responses "$response\n" + } + ad_form -extend -name modify_question -form { + {valid_responses:text(textarea) + {label "For Multiple Choice
    Enter a List of Valid Responses
    (enter one choice per line)"} + {html {rows 10 cols 50}} + {value $valid_responses}} + } +} + +if {$presentation_type == "textarea" || $presentation_type == "textbox"} { + ad_form -extend -name modify_question -form { + {presentation_options:text(select) {options {{Small small} {Medium medium} {Large large}}} {value $presentation_options} {label "[string totitle $presentation_type] Size"}} + + } + } + + +ad_form -extend -name modify_question -select_query_name {survey_question_details} -edit_data { + + db_dml survey_question_update {} + +# add new responses is choice type question + + + if {[info exists valid_responses]} { + + set responses [split $valid_responses "\n"] + set count 0 + set response_list "" + foreach response $responses { + set trimmed_response [string trim $response] + if { [empty_string_p $trimmed_response] } { + # skip empty lines + continue + } + + lappend response_list [list "$trimmed_response" "$count"] + incr count + } + + set choice_id_to_update_list [db_list get_choice_id {}] + set choice_count 0 + foreach one_response $response_list { + set choice_name [lindex $one_response 0] + set choice_value [lindex $one_response 1] + set choice_id_to_update [lindex $choice_id_to_update_list $choice_count] +if {[empty_string_p $choice_id_to_update]} { + db_dml insert_new_choice {} +} else { + + db_dml update_new_choice {} +} + incr choice_count +} +while {[llength $choice_id_to_update_list] >= $choice_count} { + set choice_id_to_delete [lindex $choice_id_to_update_list $choice_count] +db_dml delete_old_choice {} + incr choice_count +} + +} + + + + + +ad_returnredirect "one.tcl?survey_id=$survey_id&#${sort_order}" + +} + + +set context_bar [ad_context_bar "Modify Question"] + +ad_return_template Index: openacs-4/packages/survey/www/admin/question-modify.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-modify.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-modify.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,92 @@ + + + + + + select count(*) + from survey_question_responses + where question_id=:question_id + + + + + + select name from survey_sections where section_id=:section_id + + + + + + +select + question_id, + question_text, + abstract_data_type, + presentation_alignment, + presentation_options, + sort_order as question_number, + required_p, + sort_order +from survey_questions +where question_id = :question_id + + + + + +select label from survey_question_choices +where question_id=:question_id +order by sort_order + + + + + +select presentation_type, presentation_options, abstract_data_type, +sort_order as anchor +from survey_questions +where question_id=:question_id + + + + + +update survey_questions + set question_text=:question_text, + active_p=:active_p, + required_p=:required_p, + presentation_options=:presentation_options + where question_id=:question_id + + + + + +insert into survey_question_choices +(choice_id, question_id, label, sort_order) +values (survey_choice_id_sequence.nextval, :question_id, :choice_name, :choice_value) + + + + + +update survey_question_choices + set label=:choice_name where choice_id=:choice_id_to_update + + + + + +delete from survey_question_choices where choice_id = :choice_id_to_delete + + + + + + select choice_id from survey_question_choices + where question_id=:question_id + order by sort_order + + + + Index: openacs-4/packages/survey/www/admin/question-required-toggle-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-required-toggle-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-required-toggle-oracle.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,14 @@ + + + oracle8.1.6 + + + + update survey_questions set required_p = util.logical_negation(required_p) +where section_id = :section_id +and question_id = :question_id + + + + + Index: openacs-4/packages/survey/www/admin/question-required-toggle-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-required-toggle-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-required-toggle-postgresql.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,15 @@ + + + postgresql7.1 + + + + + update survey_questions set required_p = util__logical_negation(required_p) +where section_id = :section_id +and question_id = :question_id + + + + + Index: openacs-4/packages/survey/www/admin/question-required-toggle.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-required-toggle.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-required-toggle.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,32 @@ +# /www/survsimp/admin/question-required-toggle.tcl +ad_page_contract { + + Toggle required field for a question. + + @param required_p flag indicating original status of this question + @param section_id survey this question belongs to + @param question_id question we're dealing with + + @author jsc@arsdigita.com + @date February 9, 2000 + @cvs-id question-required-toggle.tcl,v 1.5.2.5 2000/07/23 16:53:34 seb Exp + +} { + + required_p:notnull + section_id:integer + question_id:integer + +} + +ad_require_permission $section_id survey_modify_question + +db_dml survey_question_required_toggle "update survey_questions set required_p = util.logical_negation(required_p) +where section_id = :section_id +and question_id = :question_id" + +db_release_unused_handles +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) +ad_returnredirect "one?[export_url_vars survey_id]" + Index: openacs-4/packages/survey/www/admin/question-swap.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-swap.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-swap.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,44 @@ +ad_page_contract { + + Swaps two sort keys for a survey, sort_order and sort_order - 1. + + @param section_id survey we're acting upon + @param sort_order integer determining position of question which is + about to be replaced with previous one + + @author nstrug@arsdigita.com + + @cvs-id $Id: question-swap.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ + +} { + survey_id:integer,notnull + section_id:integer,notnull + sort_order:integer,notnull + direction:notnull +} + +ad_require_permission $section_id survey_modify_survey + +if { $direction=="up" } { + set next_sort_order [expr { $sort_order - 1 }] +} else { + set next_sort_order [expr { $sort_order + 1 }] +} +db_transaction { + db_dml swap_sort_orders "update survey_questions +set sort_order = decode(sort_order, :sort_order, :next_sort_order, :next_sort_order, :sort_order) +where section_id = :section_id +and sort_order in (:sort_order, :next_sort_order)" + +ad_returnredirect "one?survey_id=$survey_id&#${sort_order}" + +} on_error { + + ad_return_error "Database error" "A database error occured while trying +to swap your questions. Here's the error: +

    +$errmsg
    +
    +" +} + Index: openacs-4/packages/survey/www/admin/question-swap.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/question-swap.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/question-swap.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,14 @@ + + + + + +update survey_questions +set sort_order = (case when sort_order = :sort_order then :next_sort_order when sort_order = :next_sort_order then :sort_order end) +where section_id = :section_id +and sort_order in (:sort_order, :next_sort_order) + + + + + Index: openacs-4/packages/survey/www/admin/respondents.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/respondents.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/respondents.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,7 @@ + +@survey_id@ + +@survey_name@: Respondents +@context_bar@ + +@respondents_table@ Index: openacs-4/packages/survey/www/admin/respondents.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/respondents.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/respondents.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,40 @@ +ad_page_contract { + List respondents to this survey. + + @param section_id which survey we're displaying respondents to + + @author jsc@arsdigita.com + @author nstrug@arsdigita.com + @creation-date February 11, 2000 + @version $Id: respondents.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} -query { + survey_id:integer + {orderby "email"} + {response_type "responded"} +} -properties { + survey_name:onevalue + respondents:multirow +} + +ad_require_permission $survey_id survey_admin_survey + +# for sloanspace, we can also list users who have NOT responded or +# the entire group. + + +get_survey_info -survey_id $survey_id +set survey_name $survey_info(name) + +set context_bar [ad_context_bar [list "one.tcl?[export_url_vars survey_id]" $survey_info(name)] "Respondents"] + +set table_def { + {first_names "First Name" {upper(first_names) $order} {$first_names}} + {last_name "Last Name" "" {$last_name}} + {email "Email Address" "" {$email}} + {actions "Actions" no_sort {View}} +} + +set respondents_table [ad_table -Torderby $orderby -Textra_vars {survey_id} select_respondents {} $table_def] + +ad_return_template + Index: openacs-4/packages/survey/www/admin/respondents.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/respondents.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/respondents.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,25 @@ + + + + + + select persons.first_names, persons.last_name, + acs_objects.creation_user as user_id, + parties.email + from survey_responses_latest s, + persons, + parties, + acs_objects + where s.survey_id=:survey_id + and s.response_id = acs_objects.object_id + and acs_objects.creation_user = persons.person_id + and persons.person_id = parties.party_id + group by acs_objects.creation_user, + parties.email, + persons.first_names, + persons.last_name + [ad_order_by_from_sort_spec $orderby $table_def] + + + + Index: openacs-4/packages/survey/www/admin/response-delete-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/response-delete-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/response-delete-oracle.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,25 @@ + + + + oracle8.1.6 + + +begin + survey_response.remove(:response_id); +end; + + + + + +select survey_id, survey_response.initial_user_id(response_id) as user_id, + u.first_names || ' ' || last_name as user_name, + o.creation_date as response_date +from survey_responses, cc_users u, acs_objects o +where response_id=:response_id +and o.object_id = response_id +and u.user_id = survey_response.initial_user_id(response_id) + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/response-delete-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/response-delete-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/response-delete-postgresql.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,21 @@ + + + + oracle8.1.6 + + +begin + survey_response__remove(:response_id); +end; + + + + + +select survey_id, survey_response__initial_user_id(response_id) as user_id +from survey_responses +where response_id=:response_id + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/response-delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/response-delete.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/response-delete.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,8 @@ + + +@survey_id@ + +DELETE: Survey Response +@context_bar@ + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/response-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/response-delete.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/response-delete.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,39 @@ +ad_page_contract { + + This page allows the admin to delete survey and all responses. + + @param survey_id + + @author dave@thedesignexperience.org + @date August 7, 2002 + @cvs-id $Id: response-delete.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + response_id:integer,optional +} + +set package_id [ad_conn package_id] +ad_require_permission $package_id survey_admin_survey + +db_1row get_response_info {} + +ad_form -name confirm_delete -form { + {response_id:text(hidden) {value $response_id}} + {survey_id:text(hidden) {value $survey_id}} + {user_id:text(hidden) {value $user_id}} + {warning:text(inform) {value "Completely delete ${user_name}'s response from $response_date? (Note: This can not be undone.)"} + {label "Warning!"}} + {confirmation:text(radio) {label " "} + {options + {{"Continue with Delete" t } + {"Cancel and return to survey responses" f }} } + {value f} + } + +} -on_submit { + if {$confirmation} { + db_exec_plsql delete_response {} + } + ad_returnredirect "one-respondent?[export_vars {survey_id user_id}]" +} + +set context_bar [ad_context_bar "Delete Response"] \ No newline at end of file Index: openacs-4/packages/survey/www/admin/response-drill-down.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/response-drill-down.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/response-drill-down.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,15 @@ + +@survey_id@ + +People who answered @response_text@ +@context_bar@ + +@survey_name@ responders who answered @response_text@ +when asked @question_text@: + + Index: openacs-4/packages/survey/www/admin/response-drill-down.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/response-drill-down.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/response-drill-down.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,57 @@ +ad_page_contract { + + Display the list of users who gave a particular answer to a + particular question. + + @param question_id question for which we're drilling down responses + @param choice_id we're seeking respondents who selected this choice + as an answer to question + + @author philg@mit.edu + @author jsc@arsdigita.com + @author nstrug@arsdigita.com + @date February 16, 2000 + @cvs-id $Id: response-drill-down.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ + +} { + + question_id:integer,notnull + choice_id:integer,notnull + +} + +ad_require_permission $question_id survey_admin_survey + +# get the prompt text for the question and the ID for survey of +# which it is part + +set question_exists_p [db_0or1row get_question_text ""] +get_survey_info -section_id $section_id +set survey_name $survey_info(name) +set survey_id $survey_info(survey_id) + +if { !$question_exists_p } { + db_release_unused_handles + ad_return_error "Survey Question Not Found" "Could not find a survey question #$question_id" + return +} + +set response_exists_p [db_0or1row get_response_text ""] + +if { !$response_exists_p } { + db_release_unused_handles + ad_return_error "Response Not Found" "Could not find the response #$choice_id" + return +} + +# Get information of users who responded in particular manner to +# choice question. + +db_multirow user_responses all_users_for_response {} + +set context_bar [ad_context_bar \ + [list "one?[export_url_vars survey_id]" $survey_info(name)] \ + [list "responses?[export_url_vars survey_id]" "Responses"] \ + "One Response"] + +ad_return_template Index: openacs-4/packages/survey/www/admin/response-drill-down.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/response-drill-down.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/response-drill-down.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,46 @@ + + + + + + +select section_id, question_text, section_id +from survey_questions +where question_id = :question_id + + + + + + + + +select label as response_text +from survey_question_choices +where choice_id = :choice_id + + + + + + +select + first_names || ' ' || last_name as responder_name, + person_id as user_id, + creation_date +from + acs_objects, + survey_responses sr, + persons u, + survey_question_responses qr +where + qr.response_id = sr.response_id + and qr.response_id = object_id + and creation_user = person_id + and qr.question_id = :question_id + and qr.choice_id = :choice_id + + + + + Index: openacs-4/packages/survey/www/admin/response-editable-toggle-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/response-editable-toggle-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/response-editable-toggle-oracle.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,13 @@ + + + oracle8.1.6 + + + + update surveys set editable_p = util.logical_negation(editable_p) +where survey_id = :survey_id + + + + + Index: openacs-4/packages/survey/www/admin/response-editable-toggle-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/response-editable-toggle-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/response-editable-toggle-postgresql.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,13 @@ + + + postgresql7.1 + + + + update surveys set editable_p = util__logical_negation(editable_p) +where survey_id = :survey_id + + + + + Index: openacs-4/packages/survey/www/admin/response-editable-toggle.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/response-editable-toggle.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/response-editable-toggle.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,22 @@ +ad_page_contract { + + Toggles a survey between allowing a user to + edit to or not. + + @param section_id survey we're dealing with + + @author Jin Choi (jsc@arsdigita.com) + @author nstrug@arsdigita.com + @cvs-id $Id: response-editable-toggle.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + + survey_id:integer + +} + +ad_require_permission $survey_id survey_admin_survey + +db_dml survey_response_editable_toggle "" + +db_release_unused_handles +ad_returnredirect "one?[export_url_vars survey_id]" Index: openacs-4/packages/survey/www/admin/response-limit-toggle-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/response-limit-toggle-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/response-limit-toggle-oracle.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,14 @@ + + + oracle8.1.6 + + + + update surveys +set single_response_p = util.logical_negation(single_response_p) +where survey_id = :survey_id + + + + + Index: openacs-4/packages/survey/www/admin/response-limit-toggle-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/response-limit-toggle-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/response-limit-toggle-postgresql.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,14 @@ + + + postgresql7.1 + + + + update surveys +set single_response_p = util__logical_negation(single_response_p) +where survey_id = :survey_id + + + + + Index: openacs-4/packages/survey/www/admin/response-limit-toggle.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/response-limit-toggle.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/response-limit-toggle.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,21 @@ +# /www/survsimp/admin/response-limit-toggle.tcl +ad_page_contract { + + Toggles a survey between allowing multiple responses or one response per user. + + @param section_id survey whose properties we're changing + + @cvs-id response-limit-toggle.tcl,v 1.2.2.6 2000/07/21 04:04:21 ron Exp + +} { + + survey_id:integer + +} + +ad_require_permission $survey_id survey_admin_survey + +db_dml survey_reponse_toggle "" + +db_release_unused_handles +ad_returnredirect "one?[export_url_vars survey_id]" Index: openacs-4/packages/survey/www/admin/responses-export-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/responses-export-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/responses-export-oracle.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,77 @@ + + + + oracle8.1.6 + + + + select question_id, abstract_data_type, q.sort_order, + question_text + from survey_questions q, survey_sections s + where s.survey_id = :survey_id + and s.section_id=q.section_id + order by q.sort_order,q.question_id + + + + + +select + sq.response_id, + sq.question_id, + sq.email, + sq.first_names, + sq.last_name, + sq.user_id, + sq.creation_date, + resp.boolean_answer, + resp.number_answer, + resp.date_answer, + resp.varchar_answer, + resp.clob_answer, + resp.attachment_answer, + resp.label + from + (select + sqr.response_id, + sqr.question_id, + sqr.boolean_answer, + sqr.number_answer, + sqr.date_answer, + sqr.varchar_answer, + sqr.clob_answer, + sqr.attachment_answer, + sqc.label, + sqc.sort_order + from + survey_responses sr, + survey_question_responses sqr, + survey_question_choices sqc + where + sr.survey_id=:survey_id + and sr.response_id = sqr.response_id + and sqr.question_id = sqc.question_id (+) + and sqr.choice_id = sqc.choice_id (+)) resp, + (select r.response_id, + q.question_id, + u.email, + u.first_names, + u.last_name, + r.user_id, + r.creation_date, + q.abstract_data_type, + q.sort_order + from survey_questions q, (select creation_user as user_id, creation_date, response_id from (select rownum as r_num, rt.* from survey_responses_latest rt where survey_id=:survey_id) where r_num >= $start and r_num <= $end) r, cc_users u, survey_sections ss + where ss.survey_id=:survey_id + and q.section_id=ss.section_id + and r.user_id = u.user_id) sq + where sq.response_id = resp.response_id (+) + and sq.question_id = resp.question_id (+) + order by + sq.response_id, + sq.sort_order, + sq.question_id, + resp.sort_order + + + Index: openacs-4/packages/survey/www/admin/responses-export.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/responses-export.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/responses-export.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,136 @@ +# /www/survey/admin/responses-export.tcl +ad_page_contract { + + CSV export of responses to particular survey. + + @author sebastian@arsdigita.com + @date July 2000 + @cvs-id $Id: responses-export.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ + +} { + + survey_id:integer,notnull + {unique_users_p f} + on_what_id:optional,integer + {start:naturalnum 1} + {end:naturalnum 10000} +} +set csv_export "" +set package_id [ad_conn package_id] +ad_require_permission $package_id survey_admin_survey + +set question_id_list [list] +set responses_table survey_responses + +set headline "email,first_names,last_name,user_id,submission_date,ip_address,response_id" + +db_foreach get_question_data_types {} { + lappend question_id_list $question_id + regsub -all {"} $question_text {""} question_text + append headline ",\"$question_text" + append headline "\"" + set question_data_type($question_id) $abstract_data_type + switch -- $abstract_data_type { + "date" { + set question_column($question_id) "date_answer" + } + "text" { + set question_column($question_id) "clob_answer" + } + "shorttext" { + set question_column($question_id) "varchar_answer" + } + "boolean" { + set question_column($question_id) "boolean_answer" + } + "integer" - + "number" { + set question_column($question_id) "number_answer" + } + "choice" { + set question_column($question_id) "label" + } + "blob" { + set question_column($question_id) "attachment_answer" + } + default { + set question_column($question_id) "varchar_answer" + } + } + +} + +# We're looping over all question responses in survey_question_responses + +set current_response_id "" +set current_response "" +set current_question_id "" +set current_question_list [list] +set csv_export "" +set r 0 +ReturnHeaders "application/text" +ns_write "$headline \r\n" + +db_foreach get_all_survey_question_responses "" { + + if { $response_id != $current_response_id } { + if { ![empty_string_p $current_question_id] } { + append current_response ",\"[join $current_question_list ","]\"" + } + + if { ![empty_string_p $current_response_id] } { + append csv_export "$current_response \r\n" + } + set current_response_id $response_id + set one_response [list $email $first_names $last_name $user_id $creation_date $response_id] + regsub -all {"} $one_response {""} one_response + set current_response "\"[join $one_response {","}]\"" + + set current_question_id "" + set current_question_list [list] + } + + set response_value [set $question_column($question_id)] + # Properly escape double quotes to make Excel & co happy + regsub -all {"} $response_value {""} response_value + + # Remove any CR or LF characters that may be present in text fields + regsub -all {[\r\n]} $response_value {} response_value + + if { $question_id != $current_question_id } { + if { ![empty_string_p $current_question_id] } { + append current_response ",\"[join $current_question_list ","]\"" + } + set current_question_id $question_id + set current_question_list [list] + } +# decode boolean answers + if {$question_data_type($question_id)=="boolean"} { + set response_value [survey_decode_boolean_answer -response $response_value -question_id $question_id] + } + if {$question_data_type($question_id)=="blob"} { + set response_value [db_string get_filename {} -default ""] + } + lappend current_question_list $response_value + + incr r + if {$r>99} { + ns_write "${csv_export} " + set csv_export "" + set rows 0 + } + + } + + if { ![empty_string_p $current_question_id] } { + append current_response ",\"[join $current_question_list ","]\"" + } + if { ![empty_string_p $current_response_id] } { + append csv_export "$current_response\r\n" + } + if {[empty_string_p $csv_export]} { + set csv_export "\r\n" + } + ns_write $csv_export + +ns_conn close \ No newline at end of file Index: openacs-4/packages/survey/www/admin/responses-export.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/responses-export.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/responses-export.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,10 @@ + + + + + select title from cr_revisions where + revision_id=:attachment_answer + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/responses-export.xql~ =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/Attic/responses-export.xql~,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/responses-export.xql~ 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,9 @@ + + + + + select title from cr_revisions where + revision_id=:attachment_answer + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/responses.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/responses.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/responses.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,13 @@ + +@survey_id@ + +@survey_name@: Responses +@context_bar@ + +@return_html@ +

    +@response_sentence@ + +

      +@results@ +
    Index: openacs-4/packages/survey/www/admin/responses.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/responses.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/responses.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,92 @@ +ad_page_contract { + + View summary of all responses to one survey. + + @param section_id survey for which we're building list of responses + @param unique_users_p whether we will display only latest response for each user + + @author jsc@arsdigita.com + @author nstrug@arsdigita.com + @date February 11, 2000 + @cvs-id $Id: responses.tcl,v 1.1 2002/09/16 00:00:24 daveb Exp $ +} { + + survey_id:integer + +} + +ad_require_permission $survey_id survey_admin_survey + +set user_id [ad_get_user_id] + +# nstrug - 12/9/2000 +# Summarise scored responses for all users + +get_survey_info -survey_id $survey_id +set survey_name $survey_info(name) +set type $survey_info(type) + +set return_html "" + +# mbryzek - 3/27/2000 +# We need a way to limit the summary page to 1 response from +# each user. We use views to select out only the latest response +# from any given user + + +set results "" + +db_foreach survey_question_list {} { + append results "
  • #$sort_order $question_text +
    +" + switch -- $abstract_data_type { + "date" - + "text" - + "shorttext" { + append results "View responses\n" + } + + "boolean" { + + db_foreach survey_boolean_summary "" { + append results "[survey_decode_boolean_answer -response $boolean_answer -question_id $question_id]: $n_responses
    \n" + } + } + "integer" - + "number" { + db_foreach survey_number_summary "" { + append results "$number_answer: $n_responses
    \n" + } + db_1row survey_number_average "" + append results "

    Mean: $mean
    Standard Dev: $standard_deviation
    \ +\n" + + } + "choice" { + db_foreach survey_section_question_choices "" { + append results "$label: $n_responses
    \n" + } + } + "blob" { + db_foreach survey_attachment_summary {} { + append results "$title
    " + } + } + } + append results "

    \n" +} + + + +set n_responses [db_string survey_number_responses {} ] + +if { $n_responses == 1 } { + set response_sentence "There has been 1 response." +} else { + set response_sentence "There have been $n_responses responses." +} + +set context_bar [ad_context_bar [list "one?[export_url_vars survey_id]" $survey_info(name)] "Responses"] + +ad_return_template Index: openacs-4/packages/survey/www/admin/responses.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/responses.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/responses.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,76 @@ + + + + + + select question_id, question_text, abstract_data_type, sort_order +from survey_questions +where section_id in (select section_id from survey_sections + where survey_id=:survey_id) +order by sort_order + + + + + + +select count(*) as n_responses, (case when boolean_answer = 't' then 'True' when boolean_answer = 'f' then 'False' end) as boolean_answer +from survey_ques_responses_latest +where question_id = :question_id +group by boolean_answer +order by boolean_answer desc + + + + + + + select count(*) as n_responses, number_answer +from survey_ques_responses_latest +where question_id = :question_id +group by number_answer +order by number_answer + + + + + + + select avg(number_answer) as mean, stddev(number_answer) as standard_deviation +from survey_ques_responses_latest +where question_id = :question_id + + + + + + + select count(*) as n_responses, label, qc.choice_id +from survey_ques_responses_latest qr, survey_question_choices qc +where qr.choice_id = qc.choice_id + and qr.question_id = :question_id +group by label, sort_order, qc.choice_id +order by sort_order + + + + + + select cr.title, qr.question_id, qr.response_id + from cr_revisions cr, survey_ques_responses_latest qr + where + revision_id=attachment_answer + and qr.question_id=question_id + + + + + + select count(*) +from survey_responses_latest +where survey_id=:survey_id + + + + + Index: openacs-4/packages/survey/www/admin/send-mail-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/send-mail-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/send-mail-oracle.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,139 @@ + + + oracle8.1.6 + + + + select '$sender_email' as from_addr, + '$sender_first_names' as sender_first_names, + '$sender_last_name' as sender_last_name, + parties.email, + decode(acs_objects.object_type, + 'user', + (select first_names + from persons + where person_id = parties.party_id), + 'group', + (select group_name + from groups + where group_id = parties.party_id), + 'rel_segment', + (select segment_name + from rel_segments + where segment_id = parties.party_id), + '') as first_names, + decode(acs_objects.object_type, + 'user', + (select last_name + from persons + where person_id = parties.party_id), + '') as last_name, + '$community_name' as community_name, + '$community_url' as community_url + from party_approved_member_map, + parties, + acs_objects + where party_approved_member_map.party_id = $segment_id + and party_approved_member_map.member_id <> $segment_id + and party_approved_member_map.member_id = parties.party_id + and parties.party_id = acs_objects.object_id + + + + + + select '$sender_email' as from_addr, + '$sender_first_names' as sender_first_names, + '$sender_last_name' as sender_last_name, + parties.email, + decode(acs_objects.object_type, + 'user', + (select first_names + from persons + where person_id = parties.party_id), + 'group', + (select group_name + from groups + where group_id = parties.party_id), + 'rel_segment', + (select segment_name + from rel_segments + where segment_id = parties.party_id), + '') as first_names, + decode(acs_objects.object_type, + 'user', + (select last_name + from persons + where person_id = parties.party_id), + '') as last_name, + '$community_name' as community_name, + '$community_url' as community_url + from party_approved_member_map, + parties, + acs_objects + where party_approved_member_map.party_id = $segment_id + and party_approved_member_map.member_id <> $segment_id + and party_approved_member_map.member_id = parties.party_id + and parties.party_id = acs_objects.object_id + and parties.party_id in ( + select survey_response.initial_user_id(response_id) + from survey_responses_latest where survey_id=$survey_id) + + + + + + select '$sender_email' as from_addr, + '$sender_first_names' as sender_first_names, + '$sender_last_name' as sender_last_name, + parties.email, + decode(acs_objects.object_type, + 'user', + (select first_names + from persons + where person_id = parties.party_id), + 'group', + (select group_name + from groups + where group_id = parties.party_id), + 'rel_segment', + (select segment_name + from rel_segments + where segment_id = parties.party_id), + '') as first_names, + decode(acs_objects.object_type, + 'user', + (select last_name + from persons + where person_id = parties.party_id), + '') as last_name, + '$community_name' as community_name, + '$community_url' as community_url + from party_approved_member_map, + parties, + acs_objects + where party_approved_member_map.party_id = $segment_id + and party_approved_member_map.member_id <> $segment_id + and party_approved_member_map.member_id = parties.party_id + and parties.party_id = acs_objects.object_id + and parties.party_id not in ( + select survey_response.initial_user_id(response_id) + from survey_responses_latest where survey_id=$survey_id) + + + + + + select '$sender_email' as from_addr, + '$sender_first_names' as sender_first_names, + '$sender_last_name' as sender_last_name, + parties.email, + from parties + where parties.party_id = acs_objects.object_id + and parties.party_id in ( + select survey_response.initial_user_id(response_id) + from survey_responses_latest where survey_id=$survey_id) + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/send-mail-oracle.xql~ =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/Attic/send-mail-oracle.xql~,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/send-mail-oracle.xql~ 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,42 @@ + + + oracle8.1.6 + + + + select '$sender_email' as from_addr, + '$sender_first_names' as sender_first_names, + '$sender_last_name' as sender_last_name, + parties.email, + decode(acs_objects.object_type, + 'user', + (select first_names + from persons + where person_id = parties.party_id), + 'group', + (select group_name + from groups + where group_id = parties.party_id), + 'rel_segment', + (select segment_name + from rel_segments + where segment_id = parties.party_id), + '') as first_names, + decode(acs_objects.object_type, + 'user', + (select last_name + from persons + where person_id = parties.party_id), + '') as last_name, + '$community_name' as community_name, + '$community_url' as community_url + from party_approved_member_map, + parties, + acs_objects + where party_approved_member_map.party_id = $segment_id + and party_approved_member_map.member_id <> $segment_id + and party_approved_member_map.member_id = parties.party_id + and parties.party_id = acs_objects.object_id + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/send-mail-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/send-mail-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/send-mail-postgresql.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,140 @@ + + + + postgresql7.1 + + + + select '$sender_email' as from_addr, + '$sender_first_names' as sender_first_names, + '$sender_last_name' as sender_last_name, + parties.email, + coalesce(acs_objects.object_type, + 'user', + (select first_names + from persons + where person_id = parties.party_id), + 'group', + (select group_name + from groups + where group_id = parties.party_id), + 'rel_segment', + (select segment_name + from rel_segments + where segment_id = parties.party_id), + '') as first_names, + coalesce(acs_objects.object_type, + 'user', + (select last_name + from persons + where person_id = parties.party_id), + '') as last_name, + '$community_name' as community_name, + '$community_url' as community_url + from party_approved_member_map, + parties, + acs_objects + where party_approved_member_map.party_id = $segment_id + and party_approved_member_map.member_id <> $segment_id + and party_approved_member_map.member_id = parties.party_id + and parties.party_id = acs_objects.object_id + + + + + + select '$sender_email' as from_addr, + '$sender_first_names' as sender_first_names, + '$sender_last_name' as sender_last_name, + parties.email, + coalesce(acs_objects.object_type, + 'user', + (select first_names + from persons + where person_id = parties.party_id), + 'group', + (select group_name + from groups + where group_id = parties.party_id), + 'rel_segment', + (select segment_name + from rel_segments + where segment_id = parties.party_id), + '') as first_names, + coalesce(acs_objects.object_type, + 'user', + (select last_name + from persons + where person_id = parties.party_id), + '') as last_name, + '$community_name' as community_name, + '$community_url' as community_url + from party_approved_member_map, + parties, + acs_objects + where party_approved_member_map.party_id = $segment_id + and party_approved_member_map.member_id <> $segment_id + and party_approved_member_map.member_id = parties.party_id + and parties.party_id = acs_objects.object_id + and parties.party_id in ( + select survey_response__initial_user_id(response_id) + from survey_responses_latest where survey_id=$survey_id) + + + + + + select '$sender_email' as from_addr, + '$sender_first_names' as sender_first_names, + '$sender_last_name' as sender_last_name, + parties.email, + coalesce(acs_objects.object_type, + 'user', + (select first_names + from persons + where person_id = parties.party_id), + 'group', + (select group_name + from groups + where group_id = parties.party_id), + 'rel_segment', + (select segment_name + from rel_segments + where segment_id = parties.party_id), + '') as first_names, + coalesce(acs_objects.object_type, + 'user', + (select last_name + from persons + where person_id = parties.party_id), + '') as last_name, + '$community_name' as community_name, + '$community_url' as community_url + from party_approved_member_map, + parties, + acs_objects + where party_approved_member_map.party_id = $segment_id + and party_approved_member_map.member_id <> $segment_id + and party_approved_member_map.member_id = parties.party_id + and parties.party_id = acs_objects.object_id + and parties.party_id not in ( + select survey_response__initial_user_id(response_id) + from survey_responses_latest where survey_id=$survey_id) + + + + + + select '$sender_email' as from_addr, + '$sender_first_names' as sender_first_names, + '$sender_last_name' as sender_last_name, + parties.email, + from parties + where parties.party_id = acs_objects.object_id + and parties.party_id in ( + select survey_response__initial_user_id(response_id) + from survey_responses_latest where survey_id=$survey_id) + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/send-mail-postgresql.xql~ =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/Attic/send-mail-postgresql.xql~,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/send-mail-postgresql.xql~ 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,44 @@ + + + + postgresql7.1 + + + + select '$sender_email' as from_addr, + '$sender_first_names' as sender_first_names, + '$sender_last_name' as sender_last_name, + parties.email, + coalesce(acs_objects.object_type, + 'user', + (select first_names + from persons + where person_id = parties.party_id), + 'group', + (select group_name + from groups + where group_id = parties.party_id), + 'rel_segment', + (select segment_name + from rel_segments + where segment_id = parties.party_id), + '') as first_names, + coalesce(acs_objects.object_type, + 'user', + (select last_name + from persons + where person_id = parties.party_id), + '') as last_name, + '$community_name' as community_name, + '$community_url' as community_url + from party_approved_member_map, + parties, + acs_objects + where party_approved_member_map.party_id = $segment_id + and party_approved_member_map.member_id <> $segment_id + and party_approved_member_map.member_id = parties.party_id + and parties.party_id = acs_objects.object_id + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/send-mail.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/send-mail.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/send-mail.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,9 @@ + + +@survey_id@ + +Send Mail Re: @survey_name@ +@context_bar@ + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/send-mail.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/send-mail.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/send-mail.tcl 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,104 @@ +ad_page_contract { + + this page offers options for sending email regarding + a survey to various groups + + @param survey_id + + @author dave@thedesignexperience.org + @date July 29, 2002 + @cvs-id $Id: +} { + survey_id:integer,notnull + {package_id:integer 0} + {to "all"} +} + +set package_id [ad_conn package_id] +set user_id [ad_conn user_id] +set sender_id [ad_conn user_id] +set rel_type "dotlrn_member_rel" + +ad_require_permission $survey_id survey_admin_survey + +get_survey_info -survey_id $survey_id +set survey_name $survey_info(name) +db_1row select_sender_info {} +set dotlrn_installed_p [apm_package_installed_p dotlrn] +if {$dotlrn_installed_p} { + set community_id [dotlrn_community::get_community_id] + set segment_id [db_string select_rel_segment_id {}] + set community_name [dotlrn_community::get_community_name $community_id] + set community_url "[ad_parameter -package_id [ad_acs_kernel_id] SystemURL][dotlrn_community::get_community_url $community_id]" + + set n_responses [db_string n_responses {}] + if {$n_responses > 0} { + ad_form -name send-mail -form { + {to:text(radio) {options { + {"Everyone eligible to take this survey" "all"} + {"Everyone who has already taken this survey" "responded"} + {"Everyone who has not yet taken this survey" "not_responded"}}} + {label "Send mail to"} + {value $to} + } + } + } else { + ad_form -name send-mail -form { + {to:text(radio) {options { + {"Everyone eligible to take this survey" "all"} + {"Everyone who has not yet taken this survey" "not_responded"}}} + {label "Send mail to"} + {value $to} + } + } + } +} else { + ad_form -name send-mail -form { + {to:text(radio) {options { + {"Everyone who has already taken this survey" "all"}}} + {value "all"} + {label "Send mail to"} + } + } +} + +ad_form -extend -name send-mail -form { + {subject:text(text) {value $survey_name} {label "Message Subject"} {html {size 50}}} + {message:text(textarea) {label "Enter Message"} {html {rows 15 cols 60}}} + {survey_id:text(hidden) {value $survey_id}} + {package_id:text(hidden) {value $package_id}} +} -on_submit { + +set query "" + switch $to { + all { + if {$dotlrn_installed_p} { + set query [db_map dotlrn_all {}] + } + } + responded { + if {$dotlrn_installed_p} { + set query [db_map dotlrn_responded {}] + } else { + set query [db_map responded {}] + } + } + not_responded { + if {$dotlrn_installed_p} { + set query [db_map dotlrn_not_responded {}] + } + } + } + + bulk_mail::new \ + -package_id $package_id \ + -from_addr $sender_email \ + -subject $subject \ + -message $message \ + -query $query + ad_returnredirect "one.tcl?survey_id=$survey_id" +} + +set context_bar [ad_context_bar "Send Mail"] +ad_return_template + Index: openacs-4/packages/survey/www/admin/send-mail.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/send-mail.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/send-mail.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,33 @@ + + + + + + + select parties.email as sender_email, + persons.first_names as sender_first_names, + persons.last_name as sender_last_name + from parties, + persons + where parties.party_id = :sender_id + and persons.person_id = :sender_id + + + + + + select rel_segments.segment_id + from rel_segments + where rel_segments.group_id = :community_id + and rel_segments.rel_type = :rel_type + + + + + + select count(*) from survey_responses_latest + where survey_id=:survey_id + + + + Index: openacs-4/packages/survey/www/admin/site-wide-survey-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/site-wide-survey-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/site-wide-survey-oracle.xql 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,21 @@ + + + + oracle8.1.6 + + + + select s.survey_id, s.name, s.editable_p, s.single_response_p, + s.package_id, + acs_object.name(apm_package.parent_id(s.package_id)) as parent_name, + (select site_node.url(site_nodes.node_id) + from site_nodes + where site_nodes.object_id = s.package_id) as url + from surveys s + where enabled_p='t' + order by +parent_name, +upper(s.name) + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/site-wide-survey-oracle.xql~ =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/Attic/site-wide-survey-oracle.xql~,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/site-wide-survey-oracle.xql~ 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,18 @@ + + + + oracle8.1.6 + + +select s.survey_id, s.name, s.editable_p, s.single_response_p, + s.package_id, + acs_object.name(apm_package.parent_id(s.package_id)) as parent_name, + (select site_node.url(site_nodes.node_id) + from site_nodes + where site_nodes.object_id = s.package_id) as url + from surveys s + where s.package_id in ([join $list_of_package_ids ,]) + and s.enabled_p='t' + order by +parent_name, +upper(s.name) Index: openacs-4/packages/survey/www/admin/site-wide-survey.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/site-wide-survey.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/site-wide-survey.adp 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,16 @@ + + + + +@surveys.parent_name@ + + Index: openacs-4/packages/survey/www/admin/site-wide-survey.adp~ =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/Attic/site-wide-survey.adp~,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/site-wide-survey.adp~ 16 Sep 2002 00:00:24 -0000 1.1 @@ -0,0 +1,18 @@ + + + + + + +@surveys.parent_name@ + + Index: openacs-4/packages/survey/www/admin/site-wide-survey.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/site-wide-survey.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/site-wide-survey.tcl 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,25 @@ +ad_page_contract { + Shows list of all surveys + in all mounted survey packages +} { + +} + +set user_id [ad_conn user_id] +permission::require_permission -party_id $user_id -object_id 0 -privilege admin + +db_multirow surveys get_surveys { + select s.survey_id, s.name, s.editable_p, s.single_response_p, + s.package_id, + acs_object.name(apm_package.parent_id(s.package_id)) as parent_name, + (select site_node.url(site_nodes.node_id) + from site_nodes + where site_nodes.object_id = s.package_id) as url + from surveys s + where enabled_p='t' + order by +parent_name, +upper(s.name) +} + +ad_return_template \ No newline at end of file Index: openacs-4/packages/survey/www/admin/site-wide-survey.tcl~ =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/Attic/site-wide-survey.tcl~,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/site-wide-survey.tcl~ 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,13 @@ +ad_page_contract { + Shows list of all surveys + in all mounted survey packages +} { + +} + +set user_id [ad_conn user_id] +permission::require_permission -party_id $user_id -object_id 0 -privilege admin + +db_multirow surveys get_surveys {} + +ad_return_template \ No newline at end of file Index: openacs-4/packages/survey/www/admin/survey-category-add-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-category-add-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-category-add-oracle.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,25 @@ + + + + oracle8.1.6 + + + + select + category_id_sequence.nextval from dual + + + + + + + insert into site_wide_category_map + (map_id, category_id, + on_which_table, on_what_id, mapping_date, one_line_item_desc) + values (site_wide_cat_map_id_seq.nextval, :category_id, 'survey_sections', + :section_id, sysdate, :one_line_item_desc) + + + + + Index: openacs-4/packages/survey/www/admin/survey-category-add-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-category-add-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-category-add-postgresql.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,25 @@ + + + + postgresql7.1 + + + + select + category_id_sequence.nextval + + + + + + + insert into site_wide_category_map + (map_id, category_id, + on_which_table, on_what_id, mapping_date, one_line_item_desc) + values (site_wide_cat_map_id_seq.nextval, :category_id, 'survey_sections', + :section_id, current_timestamp, :one_line_item_desc) + + + + + Index: openacs-4/packages/survey/www/admin/survey-category-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-category-add.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-category-add.tcl 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,44 @@ +# /www/survsimp/admin/one-respondent.tcl +ad_page_contract { + + Inserts a category into the central categories table + and maps it to this survey. + + @param section_id which survey we'll assign category to + @param category name of a category to be created and assigned to survey + + @cvs-id survey-category-add.tcl,v 1.4.2.4 2000/07/21 04:04:22 ron Exp +} { + + section_id:integer,notnull + category:notnull + +} + + + + +db_transaction { + + set category_id [db_string category_id_next_sequence "select + category_id_sequence.nextval from dual"] + + db_dml category_insert "insert into categories + (category_id, category,category_type) + values (:category_id, :category, 'survsimp')" + + set one_line_item_desc "Survey: [db_string survey_name " + select name from survey_sections where section_id = :section_id" ]" + + db_dml category_map_insert "insert into site_wide_category_map + (map_id, category_id, + on_which_table, on_what_id, mapping_date, one_line_item_desc) + values (site_wide_cat_map_id_seq.nextval, :category_id, 'survey_sections', + :section_id, sysdate, :one_line_item_desc)" + +} + +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) +ad_returnredirect "one?[export_url_vars survey_id]" + Index: openacs-4/packages/survey/www/admin/survey-category-add.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-category-add.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-category-add.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,21 @@ + + + + + + insert into categories + (category_id, category,category_type) + values (:category_id, :category, 'survsimp') + + + + + + + + select name from survey_sections where section_id = :section_id + + + + + Index: openacs-4/packages/survey/www/admin/survey-copy-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-copy-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-copy-postgresql.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,40 @@ + + + + postgresql7.1 + + + + :1 := survey__new ( + NULL, + :name, + :description, + :description_html_p, + :single_response_p, + :editable_p, + :enabled_p, + :single_section_p, + :type, + :display_type, + :package_id, + :user_id, + :package_id, + ); + + + + + + :1 := survey_section__new ( + NULL, + :new_survey_id, + :name, + :description, + :description_html_p, + :user_id, + :package_id + ); + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/survey-copy.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-copy.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-copy.adp 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,6 @@ + +@survey_id@ +Copy: @title_name@ +@context_bar@ + + Index: openacs-4/packages/survey/www/admin/survey-copy.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-copy.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-copy.tcl 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,37 @@ +ad_page_contract { + Copy a survey + @author dave@thedesignexperience.org + @date August 3, 2002 + @cvs-id $Id: +} { + survey_id:integer,notnull + name:optional + new_survey_id:optional +} + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] + +ad_require_permission $package_id survey_create_question + +db_1row get_survey_info {} +set title_name $name +set name "Copy of $name" + +ad_form -name copy_survey -form { + new_survey_id:key + {message:text(inform) {value "Copying a survey will create a new survey with copies of all the questions.
    None of the response data will be duplicated."}} + {name:text(text) {label Name} {html {size 60}} {value $name}} + {survey_id:text(hidden) {value $survey_id}} + +} -on_submit { + set new_survey_id [survey_copy -survey_id $survey_id -new_name $name] + +set survey_id $new_survey_id + +ad_returnredirect "one?[export_vars survey_id]" +} + + +set context_bar [ad_context_bar "Copy $title_name"] +ad_return_template Index: openacs-4/packages/survey/www/admin/survey-copy.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-copy.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-copy.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,10 @@ + + + + + +select * from surveys where survey_id=:survey_id + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/survey-create-choice.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-create-choice.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-create-choice.tcl 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,44 @@ +# /www/survsimp/admin/survey-create-choice.tcl +ad_page_contract { + + Ask the user what kind of survey they wish to create. + + @author nstrug@arsdigita.com + @date September 13, 2000 + @cvs-id $Id: survey-create-choice.tcl,v 1.1 2002/09/16 00:00:25 daveb Exp $ + +} { + + + +} + +set package_id [ad_conn package_id] +ad_require_permission $package_id survey_create_survey + +set whole_page "[ad_header "Choose Survey Type"] + +

    Choose a Survey Type

    + +[ad_context_bar "Choose Type"] + +
    + +
    +
    Scored Survey +
    This is a multiple choice survey where each answer can be scored on one +or more variables. This survey also allows you to execute arbitrary +code (e.g. for redirects) conditional on the user's score at the end +of the survey.
    +
    General Survey +
    This survey allows you to specify the type of response +required. Use this survey if you want to allow users to enter their +own answers rather than choose from a list. You should also use this +survey if you wish to mix question types, e.g. have multiple choice +and free text answer questions in the same survey.
    +
    + +[ad_footer] +" + +doc_return 200 text/html $whole_page Index: openacs-4/packages/survey/www/admin/survey-create-confirm.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-create-confirm.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-create-confirm.adp 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,11 @@ + +Confirm Survey Details + Survey Name: @name@ +

    +Here is how your survey description will appear: +

    +@description@ +
    +

    + + Index: openacs-4/packages/survey/www/admin/survey-create-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-create-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-create-oracle.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,49 @@ + + + + oracle8.1.6 + + + + begin + :1 := survey.new ( + survey_id => :survey_id, + name => :name, + description => :description, + description_html_p => :description_html_p, + type => :type, + display_type => :display_type, + package_id => :package_id, + context_id => :package_id, + creation_user => :user_id, + enabled_p => :enabled_p + ); + end; + + + + + + begin + :1 := survey_section.new ( + section_id=>:section_id, + survey_id=>:survey_id, + name=>:name, + description=>empty_clob(), + description_html_p=>:description_html_p, + context_id=>:survey_id + ); + end; + + + + + + insert into survey_logic + (logic_id, logic) + values + (:logic_id, empty_clob()) returning logic into :1 + + + + Index: openacs-4/packages/survey/www/admin/survey-create-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-create-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-create-postgresql.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,49 @@ + + + + postgresql7.1 + + + + select survey__new ( + :survey_id, + :name, + :description, + :description_html_p, + 'f', + 't', + 'f', + 't', + :type, + :display_type, + :package_id, + :user_id, + :package_id + ) + + + + + + select survey_section__new ( + :section_id, + :survey_id, + :name, + :description, + :description_html_p, + :user_id, + :package_id + ) + + + + + + insert into survey_logic + (logic_id, logic) + values + (:logic_id, :logic) + + + + Index: openacs-4/packages/survey/www/admin/survey-create.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-create.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-create.adp 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,7 @@ + + +Survey Administration: Create New Survey +@context_bar@ + + + Index: openacs-4/packages/survey/www/admin/survey-create.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-create.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-create.tcl 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,113 @@ +# /www/survsimp/admin/survey-create.tcl +ad_page_contract { + + Form for creating a survey. + + @param name title for new survey + @param description description for new survey + + @author raj@alum.mit.edu + @author nstrug@arsdigita.com + @date February 9, 2000 + @cvs-id $Id: survey-create.tcl,v 1.1 2002/09/16 00:00:25 daveb Exp $ + +} { + survey_id:optional + {name ""} + {description:html ""} + {variable_names ""} + {type "general"} +} + +set package_id [ad_conn package_id] + +# bounce the user if they don't have permission to admin surveys +ad_require_permission $package_id survey_create_survey +set user_id [ad_conn user_id] + +# use ad_form --DaveB +set display_type "list" + +ad_form -name create_survey -confirm_template survey-create-confirm -form { + survey_id:key + {display_type:text(hidden) {value $display_type}} + {name:text(text) {label "Survey Name"} {html {size 55}}} + {description:text(textarea) {label "Description"} {html {rows 10 cols 40}}} + {desc_html:text(radio) {label "The Above Description is"} + {options {{"Preformatted Text" "pre"} + {"HTML" "html"} {"Plain Text" "plain"}}} + {value "plain"} + } + +} -validate { + {name {[string length $name] <= 4000} + "Survey Name must be 4000 characters or less" +} {description {[string length $description] <= 4000} + "Survey Name must be 4000 characters or less" +} + +} -new_data { + + if {[string compare $desc_html "plain"] == 0} { + set description_html_p "f" + } else { + set description_html_p "t" + } + + if {[parameter::get -package_id $package_id -parameter survey_enabled_default_p -default 0]} { + set enabled_p "t" + } else { + set enabled_p "f" + } + db_transaction { + db_exec_plsql create_survey "" + + # survey type-specific inserts + + if { $type == "scored" } { + + foreach variable_name [split $variable_names ","] { + + set variable_id [db_nextval "survey_variable_id_sequence"] + + db_dml add_variable_name "" + + db_dml map_variable_name "" + } + + set logic_id [db_nextval "survey_logic_id_sequence"] + + ### since survey_logic contains a clob on oracle and a text column + ### on postgresql, the sql statement is different for each database + db_dml add_logic "" -clobs [list $logic] + + db_dml map_logic "" + } + + # create new section here. the questions go in the section + # section_id is null to create a new section + # we might want to specify a section_id later for + # multiple section surveys + set section_id "" + set section_id [db_exec_plsql create_section ""] + } + ad_returnredirect "question-add.tcl?section_id=$section_id" +} + + + + +# function to insert survey type-specific form html + +if {$type=="scored"} { + upvar variable_names local_variable_names + ad_form -extend -name create_survey -form { + {variable_names:text(text) {label "Survey variable names
    (comma-seperated list)"} {value $local_variable_names} + {html {size 65}} } + } +} + +set context_bar [ad_context_bar "Create Survey"] + +ad_return_template + Index: openacs-4/packages/survey/www/admin/survey-create.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-create.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-create.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,36 @@ + + + + postgresql7.1 + + + + + insert into survey_variables + (variable_id, variable_name) + values + (:variable_id, :variable_name) + + + + + + + insert into survey_variables_surveys_map + (variable_id, section_id) + values + (:variable_id, :section_id) + + + + + + + insert into survey_logic_surveys_map + (logic_id, section_id) + values + (:logic_id, :section_id) + + + + Index: openacs-4/packages/survey/www/admin/survey-delete-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-delete-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-delete-oracle.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,13 @@ + + + + oracle8.1.6 + + +begin + survey.remove(:survey_id); +end; + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/survey-delete-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-delete-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-delete-postgresql.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,13 @@ + + + + postgresql7.1 + + +begin + survey__remove(:survey_id); +end; + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/survey-delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-delete.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-delete.adp 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,9 @@ + +@survey_id@ + +@survey_id@ + +DELETE: @survey_info.name@ +@context_bar@ + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/survey-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-delete.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-delete.tcl 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,43 @@ +ad_page_contract { + + This page allows the admin to delete survey and all responses. + + @param survey_id + + @author dave@thedesignexperience.org + @date August 7, 2002 + @cvs-id $Id: survey-delete.tcl,v 1.1 2002/09/16 00:00:25 daveb Exp $ +} { + + survey_id:integer + +} + +set package_id [ad_conn package_id] +ad_require_permission $package_id survey_admin_survey + +get_survey_info -survey_id $survey_id + +set questions_count "" +set responses_count "" + +ad_form -name confirm_delete -form { + {survey_id:text(hidden) {value $survey_id}} + {warning:text(inform) {label "Warning:"} {value "Deleting this survey will delete all $questions_count questions and all $responses_count responses associated with this survey!"}} + {confirmation:text(radio) {label " "} + {options + {{"Continue with Delete" t } + {"Cancel and return to survey administration" f }} } + {value f} + } + +} -on_submit { + if {$confirmation} { + db_exec_plsql delete_survey {} + ad_returnredirect "." + } else { + ad_returnredirect "one.tcl?[export_vars survey_id]" + } +} + +set context_bar [ad_context_bar "Delete Survey"] \ No newline at end of file Index: openacs-4/packages/survey/www/admin/survey-display-type-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-display-type-edit.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-display-type-edit.tcl 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,20 @@ +ad_page_contract { + + Set the display type + + @param section_id survey whose properties we're changing + @cvs-id response-limit-toggle.tcl,v 1.2.2.6 2000/07/21 04:04:21 ron Exp + +} { + survey_id:integer + display_type:notnull +} + +ad_require_permission $survey_id survey_admin_survey + +if {[lsearch [survey_display_types] $display_type] > -1} { + db_dml survey_display_type_edit "" +} + +db_release_unused_handles +ad_returnredirect "one?[export_url_vars survey_id]" Index: openacs-4/packages/survey/www/admin/survey-display-type-edit.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-display-type-edit.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-display-type-edit.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,10 @@ + + + + +update surveys + set display_type= :display_type + where survey_id = :survey_id + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/survey-preview.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-preview.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-preview.adp 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,28 @@ + +@survey_id@ + +Preview One Survey: @name@ +@context_bar@ +Return + + + + + + + + + + + + + + + + + +
    @description@
    * denotes a required question

    + @form_vars@ + +
    +
    Index: openacs-4/packages/survey/www/admin/survey-preview.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-preview.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-preview.tcl 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,63 @@ +ad_page_contract { + + Display a questionnaire for one survey. + + @param section_id id of displayed survey + + @author philg@mit.edu + @author nstrug@arsdigita.com + @date 28th September 2000 + @cvs-id $Id: survey-preview.tcl,v 1.1 2002/09/16 00:00:25 daveb Exp $ + +} { + + survey_id:integer,notnull + {section_id:integer ""} + return_url:optional + +} -validate { + survey_exists -requires {survey_id} { + if ![db_0or1row survey_exists {}] { + ad_complain "Survey $survey_id does not exist" + } + } +} -properties { + + name:onerow + section_id:onerow + button_label:onerow + questions:onerow + description:onerow + modification_allowed_p:onerow + return_url:onerow +} + +ad_require_permission $survey_id survey_take_survey + + get_survey_info -survey_id $survey_id + set name $survey_info(name) + set description $survey_info(description) + set single_response_p $survey_info(single_response_p) + set editable_p $survey_info(editable_p) + set display_type $survey_info(display_type) + +set context_bar [ad_context_bar "Preview $name"] + +# build a list containing the HTML (generated with survey_question_display) for each question +set rownum 0 + +set questions [list] + +db_foreach survey_sections {} { + + db_foreach question_ids_select {} { + lappend questions [survey_question_display $question_id] + } + + + } + +set return_url "one?[export_vars survey_id]" +set form_vars [export_form_vars section_id survey_id] +ad_return_template + Index: openacs-4/packages/survey/www/admin/survey-preview.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-preview.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-preview.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,27 @@ + + + + + + select 1 from surveys where survey_id = :survey_id + + + + + + select question_id + from survey_questions + where section_id = :section_id + and active_p = 't' + order by sort_order + + + + + + select section_id from survey_sections + where survey_id=:survey_id + + + + Index: openacs-4/packages/survey/www/admin/survey-toggle.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-toggle.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-toggle.tcl 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,29 @@ +ad_page_contract { + Survey,-toggle.tcl will toggle (ie - enable or disable) a single survey. + + @param section_id survey we're toggling + @param enabled_p flag describing original state of survey + @param target URL where we will be redirected to after toggling + + @author raj@alum.mit.edu + @author nstrug@arsdigita.com + @date February 9, 2000 + @cvs-id $Id: survey-toggle.tcl,v 1.1 2002/09/16 00:00:25 daveb Exp $ +} { + survey_id:integer + enabled_p + {target "index.tcl"} +} + +ad_require_permission $survey_id survey_admin_survey + +if {$enabled_p == "f"} { + set enabled_p "t" +} else { + set enabled_p "f" +} + +db_dml survey_active_toggle "" + +ad_returnredirect "$target" + Index: openacs-4/packages/survey/www/admin/survey-toggle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/survey-toggle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/survey-toggle.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,13 @@ + + + + + + update surveys + set enabled_p = :enabled_p + where survey_id = :survey_id + + + + + Index: openacs-4/packages/survey/www/admin/user-responses-delete-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/user-responses-delete-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/user-responses-delete-oracle.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,24 @@ + + + + oracle8.1.6 + + + + begin + survey_response.remove(:response_id); + end; + + + + + + + select survey_id, survey_response.initial_user_id(response_id) as user_id, response_id, initial_response_id + from survey_responses + where survey_id=:survey_id + and survey_response.initial_user_id(response_id)=:user_id + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/user-responses-delete-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/user-responses-delete-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/user-responses-delete-postgresql.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,24 @@ + + + + oracle8.1.6 + + + + begin + survey_response__remove(:response_id); + end; + + + + + + + select survey_id, survey_response__initial_user_id(response_id) as user_id, response_id, initial_response_id + from survey_responses + where survey_id=:survey_id + and survey_response__initial_user_id(response_id)=:user_id + + + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/user-responses-delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/user-responses-delete.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/user-responses-delete.adp 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,9 @@ + +@survey_id@ + +@survey_id@ + +DELETE: Survey Response +@context_bar@ + + \ No newline at end of file Index: openacs-4/packages/survey/www/admin/user-responses-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/user-responses-delete.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/user-responses-delete.tcl 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,43 @@ +ad_page_contract { + + This page allows the admin to delete survey and all responses. + + @param survey_id + + @author dave@thedesignexperience.org + @date August 7, 2002 + @cvs-id $Id: user-responses-delete.tcl,v 1.1 2002/09/16 00:00:25 daveb Exp $ +} { + survey_id:integer + user_id:integer +} + +set package_id [ad_conn package_id] +ad_require_permission $package_id survey_admin_survey + +db_multirow responses get_response_info {} + +set response_count [template::multirow size responses] +ad_form -name confirm_delete -form { + {survey_id:text(hidden) {value $survey_id}} + {user_id:text(hidden) {value $user_id}} + {warning:text(inform) {label "Warning:"} {value "This will remove $response_count responses"}} + {confirmation:text(radio) {label " "} + {options + {{"Continue with Delete" t } + {"Cancel and return to survey responses" f }} } + {value f} + } + +} -on_submit { + if {$confirmation} { + template::multirow foreach responses { + if {[empty_string_p $initial_response_id]} { + db_exec_plsql delete_response {} + } + } + } + ad_returnredirect "one-respondent?[export_vars {survey_id user_id}]" +} + +set context_bar [ad_context_bar "Delete Response"] \ No newline at end of file Index: openacs-4/packages/survey/www/admin/view-text-responses-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/view-text-responses-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/view-text-responses-oracle.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,25 @@ + + + + + + select + $column_name as response, + person.name(o.creation_user) as respondent_name, + o.creation_date as submission_date, + o.creation_user, + o.creation_ip as ip_address + from + survey_responses r, + survey_question_responses qr, + acs_objects o + where + qr.response_id = r.response_id + and qr.question_id = :question_id + and o.object_id = qr.response_id + order by submission_date + + + + + Index: openacs-4/packages/survey/www/admin/view-text-responses-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/view-text-responses-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/view-text-responses-postgresql.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,24 @@ + + + + + + + select + $column_name as response, + person__name(acs_object__get_attribute(r.response_id,'creation_user')::text::integer) as respondent_name, + acs_object__get_attribute(r.response_id,'creation_date') as submission_date, + acs_object__get_attribute(r.response_id,'creation_user') as creation_user, + acs_object__get_attribute(r.response_id,'creation_ip') as ip_address + from + survey_responses r, + survey_question_responses qr + where + qr.response_id = r.response_id + and qr.question_id = :question_id + order by submission_date + + + + + Index: openacs-4/packages/survey/www/admin/view-text-responses.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/view-text-responses.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/view-text-responses.adp 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,14 @@ + + +@survey_id@ + +@survey_name@: Responses to Question +@context_bar@ +@question_text@ +
    + +@responses.respondent_name@ + on @responses.submission_date@ | @responses.response@ +
    +
    \ No newline at end of file Index: openacs-4/packages/survey/www/admin/view-text-responses.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/view-text-responses.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/view-text-responses.tcl 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,43 @@ +# /www/survsimp/admin/view-text-responses.tcl +ad_page_contract { + + View all the typed-in text responses for one question. + + @param question_id which question we want to list answers to + + @author jsc@arsdigita.com + @date February 11, 2000 + @cvs-id view-text-responses.tcl,v 1.5.2.3 2000/07/21 04:04:25 ron Exp + +} { + + question_id:integer,notnull + +} + +db_1row one_question "" + +get_survey_info -section_id $section_id +set survey_name $survey_info(name) +set survey_id $survey_info(survey_id) + +ad_require_permission $survey_id survey_admin_survey + +set abstract_data_type [db_string abstract_data_type "select abstract_data_type +from survey_questions q +where question_id = :question_id"] + +if { $abstract_data_type == "text" } { + set column_name "clob_answer" +} elseif { $abstract_data_type == "shorttext" } { + set column_name "varchar_answer" +} elseif { $abstract_data_type == "date" } { + set column_name "date_answer" +} + +set results "" + + +db_multirow responses all_responses_to_question {} + +set context_bar [ad_context_bar [list "one?[export_url_vars survey_id]" $survey_info(name)] "Responses to Question"] Index: openacs-4/packages/survey/www/admin/view-text-responses.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/admin/view-text-responses.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/admin/view-text-responses.xql 16 Sep 2002 00:00:25 -0000 1.1 @@ -0,0 +1,22 @@ + + + + + + select sq.question_text, sq.section_id + from survey_questions sq, survey_sections sec + where sq.question_id = :question_id + and sq.section_id = sec.section_id + + + + + + + select abstract_data_type + from survey_questions q + where question_id = :question_id + + + + Index: openacs-4/packages/survey/www/doc/index.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/survey/www/doc/index.html,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/survey/www/doc/index.html 15 Sep 2002 23:56:35 -0000 1.1 @@ -0,0 +1,109 @@ + + + +Survey + + + +

    Survey

    + +A package for OpenACS 4.6 + +
    + +

    The Big Idea

    + +We want to be able to survey users. We want a non-technical person to +be able to design surveys from HTML forms. We want someone who is not +a site-admin to be able to review answers (we just give them admin + over the survey package.) + +

    Survey Question Possibilities

    + +Each survey question specifies an abstract data type for responses: + +
      + +
    • boolean +
    • number +
    • integer +
    • shorttext (less than 4000 characters) +
    • text +
    • choice + +
    + +Each survey also specifies a presentation type: + +
      +
    • textbox +
    • textarea (size can be specified in +presentation_options) +
    • select (from a fixed set of options in survsimp_question_choices) +
    • radio (from a fixed set of options in survsimp_question_choices) +
    • checkbox (from a fixed set of options in survsimp_question_choices) + +
    + +

    The data model

    + +We use the following tables: + +
      +
    • survey_questions -- questions for each survey +
    • surveys -- specs for one survey form (except the + questions) +
    • survey-sections allows for future development of + branched or multi-part surveys +
    • survey_responses -- user responses to surveys +
    • survey_question_responses -- user responses to +individual questions within a survey + +
    + +The philosophy about storing the users responses is to use one single table to store all responses, i.e., we do not create a new table +when we create a new survey. In order to make it possible to store all +kinds of data in one table, we give the +survey_question_responses table five columns. + +
    +
    
    +	-- if the user picked a canned response
    +	choice_id		references survey_question_choices,
    +	boolean_answer		char(1) check(boolean_answer in ('t','f')),
    +	clob_answer		clob,
    +	number_answer		number,
    +	attachment_answer       integer references cr_revisions(revision_id) 
    +	varchar_answer		varchar(4000),
    +
    +
    + +Only one of the columns will be not-null. + +

    + +Why the CLOB in addition to the varchar? The CLOB is necessary when +people are using this system for proposal solicitation (people might +type more than 4000 characters).

    +

    NOTE: Postgresql uses a text column in place of CLOB.

    +

    Attachment_answer allows for uploaded files to be stored in + the content-repository

    . +

    User Interface

    + +The user interface for creating a survey is as follows: +
      +
    1. User creates a survey, giving it a name and a description. +
    2. User adds questions one by one, and is given the opportunity to reorder questions. + +
    3. To add a question, user first types in the question and selects +its presentation type (radio buttons, checkbox, text field, etc.). +
    4. Then the user is given the opportunity to specify further +attributes for the question depending upon the presentation type that +was chosen. For instance, any "choice" presentation (radio buttons, +checkboxes, and select lists) require a list of choices. A text field +requires the user to specify an abstract data type and the size of the +input field. +
    + + + \ No newline at end of file