Index: openacs-4/contrib/packages/survey/survey.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/Attic/survey.info,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/survey.info 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,32 @@ + + + + + Survey + Surveys + f + f + + + Dave Bauer + Luke Pond + Malte Sussdorff + New version of survey package for dotLRN/OpenACS 5.0 + dotLRN + New version of survey package for dotLRN/OpenACS 5.0 + + + + + + + + + + + + + + + + Index: openacs-4/contrib/packages/survey/sql/oracle/survey-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/oracle/Attic/survey-create.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/oracle/survey-create.sql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,475 @@ +-- 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 2003/09/19 16:48:03 rmello 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.create_privilege('survey_create_section'); +-- acs_privilege.create_privilege('survey_modify_section'); +-- acs_privilege.create_privilege('survey_delete_section'); + +-- acs_privilege.add_child('survey_admin_survey','survey_create_section'); +-- acs_privilege.add_child('survey_admin_survey','survey_modify_section'); +-- acs_privilege.add_child('survey_admin_survey','survey_delete_section'); + +-- acs_privilege.add_child('write','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_predefined_question', + pretty_name => 'Predefined Survey Question', + pretty_plural => 'Predefined Survey Questions', + table_name => 'SURVEY_PREDEFINED_QUESTIONS', + id_column => 'PREDEFINED_QUESTION_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 survey_templates ( +-- until we got a better solution + template_id integer primary key, + template_file varchar(400) unique, + description varchar(4000) +); + +insert into survey_templates(template_id,template_file,description) values (acs_object_id_seq.nextval,'plain','Plain'); +insert into survey_templates(template_id,template_file,description) values (acs_object_id_seq.nextval,'standard','Standard Blue'); +insert into survey_templates(template_id,template_file,description) values (acs_object_id_seq.nextval,'standard-lars','Silver'); +insert into survey_templates(template_id,template_file,description) values (acs_object_id_seq.nextval,'two-column','Two Column'); + + +create table surveys ( + survey_id 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 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, + public_p char(1) default 't' + constraint surveys_public_p_ck + check(public_p in ('t','f')), + status_bar_color varchar(100) default null + constraint surveys_status_bar_colors + check(status_bar_color in ('blue','red','green','yellow')), + template integer references survey_templates(template_id) +); + +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')), + sort_key integer default 0 not null, + branch_p char(1) default 'f' + constraint survey_sections_branch_p_ck + check (branch_p in ('t','f')), + -- are there any branches dependant from this section? + branched_p char(1) default 'f' + constraint survey_sections_branched_p_ck + check (branched_p in ('t','f')), + block_section_p char(1) default 'f' + constraint survey_sections_block_p_ck + check (block_section_p in ('t','f')), + page_break_p char(1) default 't' + constraint survey_sections_break_p_ck + check (page_break_p in ('t','f')) +); + +create index survey_sections_survey_id_fk on survey_sections(survey_id); + +create table survey_predefined_questions ( + predefined_question_id constraint survey_pq_pquestion_id_fk + references acs_objects (object_id) + constraint survey_pq_pquestion_id_pk + primary key, + question_text clob + constraint survey_pq_question_text_nn + not null, + question_html_p char(1) default 'f' + constraint survey_pq_question_html_p_ck + check(question_html_p in ('t','f')), + abstract_data_type varchar(30) + constraint survey_pq_abs_data_type_ck + check (abstract_data_type in ('text', 'shorttext', 'boolean', 'number', 'integer', 'choice', 'date','blob')), + presentation_type varchar(20) + constraint survey_pq_pres_type_nn + not null + constraint survey_pq_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_pq_pres_alignment_ck + check(presentation_alignment in ('below','beside')), + summary_type varchar(20) + constraint survey_pq_summary_type check + (summary_type in ('sum','avg','concat')), + action_type varchar(20) + constraint survey_pq_action_type_ck + check(action_type in ('tcl','db')), + tcl clob, + table_name varchar(100), + column_name varchar(100), + key_name varchar(100) + ); + + +create table survey_predef_question_choices ( + choice_id integer constraint survey_pqc_choice_id_nn + not null + constraint survey_pqc_choice_id_pk + primary key, + question_id constraint survey_pqc_question_id_nn + not null + constraint survey_pqc_question_id_fk + references survey_predefined_questions, + -- human readable + label varchar(500) constraint survey_pqc_label_nn + not null, + -- might be useful for averaging or whatever, generally null + numeric_value number, + -- lower is earlier + sort_order integer, + presentation_alignment varchar(15) default 'right' + constraint survey_pqc_pres_align_ck + check (presentation_alignment in ('left','right')), + more_info_type varchar(30) default '' + constraint survey_pqc_more_info_ck + check (more_info_type in ('','varchar','number')) +); + + +create table survey_questions ( + question_id constraint survey_q_question_id_fk + references acs_objects (object_id) + on delete cascade + constraint survey_q_question_id_pk + primary key, + section_id 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 clob + constraint survey_q_question_text_nn + not null, + question_html_p char(1) default 'f' + constraint survey_q_question_html_p_ck + check(question_html_p in ('t','f')), + 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')), + summary_type varchar(20) + constraint survey_q_summary_type check + (summary_type in ('sum','avg','concat')), + -- describing the options of radio button set + answer_description varchar(100), + predefined_question_id constraint survey_q_pred_q_id_fk + references survey_predefined_questions +); + +create table survey_block_questions ( + block_section_id integer, + section_id integer + constraint survey_b_q_section_id_fk + references survey_sections, + choice_id integer + constraint survey_b_q_choice_id_nn + not null, + label varchar(200), + sort_order integer + constraint survey_b_q_sort_order_nn + not null +); +create sequence survey_block_section_id_seq; +create sequence survey_block_choice_id_seq; +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, + predef_choice_id constraint survey_qc_predef_choice_id_fk + references survey_predef_question_choices, + question_id 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 number, + -- lower is earlier + sort_order integer, + presentation_alignment varchar(15) default 'right' + constraint survey_qc_pres_align_ck + check (presentation_alignment in ('left','right')), + more_info_type varchar(30) default '' + constraint survey_qc_more_info_ck + check (more_info_type in ('','varchar','number')) +); + +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); + +create sequence survey_branch_id_sequence start with 1; +create sequence survey_condition_id_sequence start with 1; + +create table survey_conditions ( + condition_id integer + constraint survey_cond_pk + primary key, + question_id constraint survey_cond_question_id_nn + not null + constraint survey_cond_question_id_fk + references survey_questions, + -- like question_responses + choice_id constraint survey_cond_choice_id_fk + references survey_question_choices, + boolean_answer char(1) + constraint survey_cond_boolean_answer_ck + check(boolean_answer in ('t','f')) +); + +create table survey_branches ( + branch_id integer + constraint survey_branches_pk + primary key, + section_id constraint survey_branches_section_id_fk + references survey_sections, + after constraint survey_branches_after_nn + not null + constraint survey_branches_after_fk + references survey_sections, + -- null means always + condition constraint survey_branches_condition_fk + references survey_conditions +); + + +-- 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) + on delete cascade + constraint survey_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 + on delete cascade, + title varchar(100), + notify_on_comment_p char(1) + constraint survey_resp_noton_com_p_ck + check(notify_on_comment_p in ('t','f')), + finished_p char(1) default 'f' + constraint survey_resp_finished_p_ck + check (finished_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 constraint survey_qr_response_id_nn + not null + constraint survey_qr_response_id_fk + references survey_responses, + question_id 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 constraint survey_qr_choice_id_fk + references survey_question_choices + on delete cascade, + 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, + -- file name including extension but not path + attachment_file_name varchar(500), + attachment_file_type varchar(100), -- this is a MIME type (e.g., image/jpeg) + attachment_file_extension varchar(50), -- e.g., "jpg" + constraint surv_quest_resp_uq unique(response_id,question_id,choice_id) +); + +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); + + +create or replace function survey_question_all_choices +(v_question_id in integer) return varchar +is + v_answers varchar(4000); + first_p integer; + cursor choice_cursor is + select label + from survey_question_choices + where question_id = v_question_id + order by sort_order; +begin + v_answers := ''; + first_p := 0; + for choice_rec in choice_cursor loop + if first_p = 0 then + v_answers := choice_rec.label; + first_p := 1; + else + v_answers := v_answers || ',' || choice_rec.label; + end if; + end loop; + + return v_answers; +end; +/ +show errors + +@@ survey-package-create.sql +@@ survey-notifications-init.sql +@@ survey-portlet-create.sql Index: openacs-4/contrib/packages/survey/sql/oracle/survey-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/oracle/Attic/survey-drop.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/oracle/survey-drop.sql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,70 @@ +-- +-- drop SQL for survey package +-- +-- by nstrug@arsdigita.com on 29th September 2000 +-- +-- $Id: survey-drop.sql,v 1.1 2003/09/19 16:48:03 rmello Exp $ + +@@ survey-package-drop.sql + +drop view survey_ques_responses_latest; +drop table survey_question_responses cascade constraints; +drop view survey_responses_latest; +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_block_questions; +drop table survey_branches; +drop sequence survey_branch_id_sequence; +drop table survey_conditions; +drop sequence survey_condition_id_sequence; +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 ('write','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_section'); +-- acs_privilege.remove_child ('survey_admin_survey','survey_modify_section'); +-- acs_privilege.remove_child ('survey_admin_survey','survey_create_section'); +-- 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_section'); +-- acs_privilege.drop_privilege('survey_modify_section'); +-- acs_privilege.drop_privilege('survey_create_section'); +-- 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/contrib/packages/survey/sql/oracle/survey-notifications-init.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/oracle/Attic/survey-notifications-init.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/oracle/survey-notifications-init.sql 19 Sep 2003 16:48:03 -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/contrib/packages/survey/sql/oracle/survey-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/oracle/Attic/survey-package-create.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/oracle/survey-package-create.sql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,579 @@ +-- 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, + public_p in surveys.public_p%TYPE default 't', + 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, + sort_key in survey_sections.sort_key%TYPE default 0, + branch_p in survey_sections.branch_p%TYPE default 'f', + branched_p in survey_sections.branched_p%TYPE default 'f', + block_section_p in survey_sections.block_section_p%TYPE default 'f', + page_break_p in survey_sections.page_break_p%TYPE default 't', + 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_predefined_question +-- + +create or replace package survey_predefined_question +as + function new ( + predefined_question_id in survey_predefined_questions.predefined_question_id%TYPE default null, + question_text in survey_predefined_questions.question_text%TYPE default null, + abstract_data_type in survey_predefined_questions.abstract_data_type%TYPE default null, + presentation_type in survey_predefined_questions.presentation_type%TYPE default null, + presentation_options in survey_predefined_questions.presentation_options%TYPE default null, + presentation_alignment in survey_predefined_questions.presentation_alignment%TYPE default 'below', + question_html_p in survey_predefined_questions.question_html_p%TYPE default 'f', + summary_type in survey_predefined_questions.summary_type%TYPE, + action_type in survey_predefined_questions.action_type%TYPE default null, + tcl in survey_predefined_questions.tcl%TYPE default null, + table_name in survey_predefined_questions.table_name%TYPE default null, + column_name in survey_predefined_questions.column_name%TYPE default null, + key_name in survey_predefined_questions.key_name%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'survey_predefined_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; + +end survey_predefined_question; +/ +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', + question_html_p in survey_questions.question_html_p%TYPE default 'f', + summary_type in survey_questions.summary_type%TYPE, + answer_description in survey_questions.answer_description%TYPE, + predefined_question_id in survey_questions.predefined_question_id%TYPE default null, + 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, + public_p in surveys.public_p%TYPE default 't', + 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, public_p) + 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, new.public_p); + + 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, + sort_key in survey_sections.sort_key%TYPE default 0, + branch_p in survey_sections.branch_p%TYPE default 'f', + branched_p in survey_sections.branched_p%TYPE default 'f', + block_section_p in survey_sections.block_section_p%TYPE default 'f', + page_break_p in survey_sections.page_break_p%TYPE default 't', + 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, sort_key, branch_p, branched_p,page_break_p, block_section_p) + values + (v_section_id, new.survey_id, new.name, new.description, new.description_html_p, new.sort_key, new.branch_p, new.branched_p,new.page_break_p,new.block_section_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_predefined_question +as + function new ( + predefined_question_id in survey_predefined_questions.predefined_question_id%TYPE default null, + question_text in survey_predefined_questions.question_text%TYPE default null, + abstract_data_type in survey_predefined_questions.abstract_data_type%TYPE default null, + presentation_type in survey_predefined_questions.presentation_type%TYPE default null, + presentation_options in survey_predefined_questions.presentation_options%TYPE default null, + presentation_alignment in survey_predefined_questions.presentation_alignment%TYPE default 'below', + question_html_p in survey_predefined_questions.question_html_p%TYPE default 'f', + summary_type in survey_predefined_questions.summary_type%TYPE, + action_type in survey_predefined_questions.action_type%TYPE default null, + tcl in survey_predefined_questions.tcl%TYPE default null, + table_name in survey_predefined_questions.table_name%TYPE default null, + column_name in survey_predefined_questions.column_name%TYPE default null, + key_name in survey_predefined_questions.key_name%TYPE default null, + object_type in acs_objects.object_type%TYPE default 'survey_predefined_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_predefined_question_id survey_predefined_questions.predefined_question_id%TYPE; + begin + v_predefined_question_id := acs_object.new ( + object_id => predefined_question_id, + object_type => object_type, + creation_date => creation_date, + creation_user => creation_user, + creation_ip => creation_ip + ); + insert into survey_predefined_questions + (predefined_question_id,question_text,abstract_data_type,presentation_type,presentation_options,presentation_alignment,question_html_p,summary_type,action_type,tcl,table_name,column_name,key_name) + values + (v_predefined_question_id,new.question_text,new.abstract_data_type,new.presentation_type,new.presentation_options,new.presentation_alignment,new.question_html_p,new.summary_type,new.action_type,new.tcl,new.table_name,new.column_name,new.key_name); + return v_predefined_question_id; + end new; + +end survey_predefined_question; +/ +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', + question_html_p in survey_questions.question_html_p%TYPE default 'f', + summary_type in survey_questions.summary_type%TYPE, + answer_description in survey_questions.answer_description%TYPE, + predefined_question_id in survey_questions.predefined_question_id%TYPE default null, + 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,predefined_question_id) + 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,new.predefined_question_id); + 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 as initial_user_id + from survey_responses sr, + acs_objects o, + (select max(response_id) as response_id + from survey_responses + group by nvl(initial_response_id, response_id)) latest + where nvl(sr.initial_response_id, 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/contrib/packages/survey/sql/oracle/survey-package-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/oracle/Attic/survey-package-drop.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/oracle/survey-package-drop.sql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,5 @@ +drop package survey_response; +drop package survey_question; +drop package survey_section; +drop package survey_predefined_question; +drop package survey; Index: openacs-4/contrib/packages/survey/sql/oracle/survey-portlet-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/oracle/Attic/survey-portlet-create.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/oracle/survey-portlet-create.sql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,159 @@ + +-- This is free software distributed under the terms of the GNU Public +-- License version 2 or higher. Full text of the license is available +-- from the GNU Project: http://www.fsf.org/copyleft/gpl.html + + + +declare + ds_id portal_datasources.datasource_id%TYPE; +begin + ds_id := portal_datasource.new( + name => 'survey_portlet', + description => 'Displays surveys to take' + ); + + -- 4 defaults procs + + -- shadeable_p + portal_datasource.set_def_param ( + datasource_id => ds_id, + config_required_p => 't', + configured_p => 't', + key => 'shadeable_p', + value => 't' +); + + -- shaded_p + portal_datasource.set_def_param ( + datasource_id => ds_id, + config_required_p => 't', + configured_p => 't', + key => 'shaded_p', + value => 'f' +); + + -- hideable_p + portal_datasource.set_def_param ( + datasource_id => ds_id, + config_required_p => 't', + configured_p => 't', + key => 'hideable_p', + value => 't' +); + + -- user_editable_p + portal_datasource.set_def_param ( + datasource_id => ds_id, + config_required_p => 't', + configured_p => 't', + key => 'user_editable_p', + value => 'f' +); + + -- link_hideable_p + portal_datasource.set_def_param ( + datasource_id => ds_id, + config_required_p => 't', + configured_p => 't', + key => 'link_hideable_p', + value => 't' +); + + +end; +/ +show errors + + +declare + foo integer; +begin + -- create the implementation + foo := acs_sc_impl.new ( + 'portal_datasource', + 'survey_portlet', + 'survey_portlet' + ); + +end; +/ +show errors + +declare + foo integer; +begin + + -- add all the hooks + foo := acs_sc_impl.new_alias ( + 'portal_datasource', + 'survey_portlet', + 'GetMyName', + 'survey_portlet::get_my_name', + 'TCL' + ); + + foo := acs_sc_impl.new_alias ( + 'portal_datasource', + 'survey_portlet', + 'GetPrettyName', + 'survey_portlet::get_pretty_name', + 'TCL' + ); + + foo := acs_sc_impl.new_alias ( + 'portal_datasource', + 'survey_portlet', + 'Link', + 'survey_portlet::link', + 'TCL' + ); + + foo := acs_sc_impl.new_alias ( + 'portal_datasource', + 'survey_portlet', + 'AddSelfToPage', + 'survey_portlet::add_self_to_page', + 'TCL' + ); + + foo := acs_sc_impl.new_alias ( + 'portal_datasource', + 'survey_portlet', + 'Show', + 'survey_portlet::show', + 'TCL' + ); + + foo := acs_sc_impl.new_alias ( + 'portal_datasource', + 'survey_portlet', + 'Edit', + 'survey_portlet::edit', + 'TCL' + ); + + foo := acs_sc_impl.new_alias ( + 'portal_datasource', + 'survey_portlet', + 'RemoveSelfFromPage', + 'survey_portlet::remove_self_from_page', + 'TCL' + ); + +end; +/ +show errors + +declare + foo integer; +begin + + -- Add the binding + acs_sc_binding.new ( + contract_name => 'portal_datasource', + impl_name => 'survey_portlet' + ); +end; +/ +show errors Index: openacs-4/contrib/packages/survey/sql/postgresql/survey-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/postgresql/Attic/survey-create.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/postgresql/survey-create.sql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,505 @@ +-- 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 2003/09/19 16:48:03 rmello Exp $ + +-- We don't want these any longer +-- select acs_privilege__create_privilege('survey_create_survey', null, null); +-- select acs_privilege__create_privilege('survey_modify_survey', null, null); +-- select acs_privilege__create_privilege('survey_delete_survey', null, null); +-- select acs_privilege__create_privilege('survey_create_question', null, null); +-- select acs_privilege__create_privilege('survey_modify_question', null, null); +-- select acs_privilege__create_privilege('survey_delete_question', null, null); +-- select acs_privilege__create_privilege('survey_take_survey', null, null); +-- select acs_privilege__create_privilege('survey_admin_survey', null, null); + +-- select acs_privilege__create_privilege('survey_create_section', null, null); +-- select acs_privilege__create_privilege('survey_modify_section', null, null); +-- select acs_privilege__create_privilege('survey_delete_section', null, null); + + +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('write','survey_take_survey'); +-- select acs_privilege__add_child('admin','survey_admin_survey'); + +-- select acs_privilege__add_child('survey_admin_survey','survey_create_section'); +-- select acs_privilege__add_child('survey_admin_survey','survey_modify_section'); +-- select acs_privilege__add_child('survey_admin_survey','survey_delete_section'); + +-- -- 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 (); + +commit; + + + + select acs_object_type__create_type ( + 'survey', + 'Survey', + 'Surveys', + 'acs_object', + 'surveys', + 'survey_id', + null, + 'f', + null, + 'survey__name' + ); + + select acs_object_type__create_type ( + 'survey_section', + 'Survey Section', + 'Survey Sections', + 'acs_object', + 'survey_sections', + 'section_id', + null, + 'f', + null, + null + ); + + select acs_object_type__create_type ( + 'survey_predefined_question', + 'Predefined Survey Question', + 'Predefined Survey Questions', + 'acs_object', + 'survey_predefined_questions', + 'predefined_question_id', + null, + 'f', + null, + null + ); + + select acs_object_type__create_type ( + 'survey_question', + 'Survey Question', + 'Survey Questions', + 'acs_object', + 'survey_questions', + 'question_id', + null, + 'f', + null, + null + ); + + select acs_object_type__create_type ( + 'survey_response', + 'Survey Response', + 'Survey Responses', + 'acs_object', + 'survey_responses', + 'response_id', + null, + 'f', + null, + null + ); + + +create table survey_templates ( +-- until we got a better solution + template_id integer + constraint survey_templates_pk + primary key, + template_file varchar(400) + constraint survey_templates_tpl_file_un + unique, + description varchar(4000) +); + +insert into survey_templates(template_id,template_file,description) values (acs_object_id_seq.nextval,'plain','Plain'); +insert into survey_templates(template_id,template_file,description) values (acs_object_id_seq.nextval,'standard','Standard Blue'); +insert into survey_templates(template_id,template_file,description) values (acs_object_id_seq.nextval,'standard-lars','Silver'); +insert into survey_templates(template_id,template_file,description) values (acs_object_id_seq.nextval,'two-column','Two Column'); + +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, + public_p boolean default TRUE, + status_bar_color varchar(100) default null + constraint surveys_status_bar_colors + check(status_bar_color in ('blue','red','green','yellow')), + template integer + constraint surveys_template_fk + references survey_templates(template_id) +); + + +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, + sort_key integer default 0 not null, + branch_p boolean default FALSE, + -- are there any branches dependant from this section? + branched_p boolean default FALSE, + block_section_p boolean default FALSE, + page_break_p boolean default TRUE +); + +create index survey_sections_survey_id_fk on survey_sections(survey_id); + +create table survey_predefined_questions ( + predefined_question_id integer + constraint survey_pq_pquestion_id_fk + references acs_objects (object_id) + constraint survey_pq_pquestion_id_pk + primary key, + question_text text + constraint survey_pq_question_text_nn + not null, + question_html_p boolean default FALSE, + abstract_data_type varchar(30) + constraint survey_pq_abs_data_type_ck + check (abstract_data_type in ('text', 'shorttext', 'boolean', 'number', 'integer', 'choice', 'date','blob')), + presentation_type varchar(20) + constraint survey_pq_pres_type_nn + not null + constraint survey_pq_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_pq_pres_alignment_ck + check(presentation_alignment in ('below','beside')), + summary_type varchar(20) + constraint survey_pq_summary_type + check + (summary_type in ('sum','avg','concat')), + action_type varchar(20) + constraint survey_pq_action_type_ck + check(action_type in ('tcl','db')), + tcl text, + table_name varchar(100), + column_name varchar(100), + key_name varchar(100) +); + + +create table survey_predef_question_choices ( + choice_id integer + constraint survey_pqc_choice_id_pk + primary key, + question_id integer + constraint survey_pqc_question_id_nn + not null + constraint survey_pqc_question_id_fk + references survey_predefined_questions(predefined_question_id), + -- human readable + label varchar(500) + constraint survey_pqc_label_nn + not null, + -- might be useful for averaging or whatever, generally null + numeric_value numeric, + -- lower is earlier + sort_order integer, + presentation_alignment varchar(15) default 'right' + constraint survey_pqc_pres_align_ck + check (presentation_alignment in ('left','right')), + more_info_type varchar(30) default '' + constraint survey_pqc_more_info_ck + check (more_info_type in ('','varchar','number')) +); + +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, + question_html_p boolean default FALSE, + 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 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')), + summary_type varchar(20) + constraint survey_q_summary_type check + (summary_type in ('sum','avg','concat')), + -- describing the options of radio button set + answer_description varchar(100), + predefined_question_id integer + constraint survey_q_pred_q_id_fk + references survey_predefined_questions +); + +create index survey_q_sort_order on survey_questions(sort_order); +create index survey_q_active_p on survey_questions(active_p); + +create table survey_block_questions ( + block_section_id integer, + section_id integer + constraint survey_b_q_section_id_fk + references survey_sections, + choice_id integer + constraint survey_b_q_choice_id_nn + not null, + label varchar(200), + sort_order integer + constraint survey_b_q_sort_order_nn + not null +); + +create sequence survey_block_section_id_seq; +create sequence survey_block_choice_id_seq; + +-- for when a question has a fixed set of responses + +create sequence survey_choice_id_sequence; + +create table survey_question_choices ( + choice_id integer + constraint survey_qc_choice_id_nn + not null + constraint survey_qc_choice_id_pk + primary key, + predef_choice_id integer + constraint survey_qc_predef_choice_id_fk + references survey_predef_question_choices(choice_id), + 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, + presentation_alignment varchar(15) default 'right' + constraint survey_qc_pres_align_ck + check (presentation_alignment in ('left','right')), + more_info_type varchar(30) default '' + constraint survey_qc_more_info_ck + check (more_info_type in ('','varchar','number')) +); + + +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); + +create sequence survey_branch_id_sequence start 1; +create sequence survey_condition_id_sequence start 1; + +create table survey_conditions ( + condition_id integer + constraint survey_conditions_pk + primary key, + question_id integer + constraint survey_conditions_question_id_nn + not null + constraint survey_conditions_question_id_fk + references survey_questions, + -- like question_responses + choice_id integer + constraint survey_conditions_choice_id_fk + references survey_question_choices, + boolean_answer char(1), + constraint survey_c_boolean_answer_ck + check(boolean_answer in ('t','f')) +); + +create table survey_branches ( + branch_id integer + constraint survey_branches_pk + primary key, + section_id integer + constraint survey_branches_section_id_fk + references survey_sections, + after integer + constraint survey_branches_after_nn + not null + constraint survey_branches_after_fk + references survey_sections, + -- null means always + condition integer + constraint survey_branches_condition_fk + references survey_conditions +); + +-- 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, + finished_p boolean default FALSE +); + +-- 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 timestamptz, + attachment_answer integer + constraint survey_q_response_item_id_fk + references cr_revisions(revision_id) + on delete cascade, + -- file name including extension but not path + attachment_file_name varchar(500), + attachment_file_type varchar(100), -- this is a MIME type (e.g., image/jpeg) + attachment_file_extension varchar(50), -- e.g., "jpg" + constraint surv_quest_resp_uq unique(response_id,question_id,choice_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); +create index survey_response_index on survey_question_responses (response_id, question_id); + +create or replace function survey_question_all_choices +(integer) +returns text as ' +declare + v_answers text; + first_p integer; + choice_cursor RECORD; + v_question_id alias for $1; +begin + v_answers := ''''; + first_p := 0; + + for choice_cursor in + SELECT cast (label as text) + from survey_question_choices + where question_id = v_question_id + order by sort_order + loop + if first_p = 0 then + v_answers := choice_cursor.label::text; + first_p := 1; + else + v_answers := v_answers || '','' || choice_cursor.label::text; + end if; + end loop; + + return v_answers; +end' language 'plpgsql'; + +\i survey-package-create.sql +\i survey-notifications-init.sql + Index: openacs-4/contrib/packages/survey/sql/postgresql/survey-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/postgresql/Attic/survey-drop.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/postgresql/survey-drop.sql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,71 @@ +-- +-- drop SQL for survey package +-- +-- by nstrug@arsdigita.com on 29th September 2000 +-- +-- $Id: survey-drop.sql,v 1.1 2003/09/19 16:48:03 rmello Exp $ + +\i survey-package-drop.sql +\i survey-notifications-drop.sql + +drop view survey_ques_responses_latest; +drop view survey_responses_latest; +drop table survey_question_responses; +drop table survey_responses; +drop table survey_question_choices; +drop sequence survey_choice_id_sequence; +drop table survey_questions; +drop table survey_predef_question_choices; +drop table survey_predefined_questions; +drop table survey_block_questions; +drop sequence survey_block_section_id_seq; +drop sequence survey_block_choice_id_seq; +drop table survey_branches; +drop sequence survey_branch_id_sequence; +drop table survey_conditions; +drop sequence survey_condition_id_sequence; +drop table survey_sections; +drop table surveys; + +drop table survey_templates; + + +-- 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'; + + select acs_object_type__drop_type ('survey_response','f'); + select acs_object_type__drop_type ('survey_question','f'); + select acs_object_type__drop_type ('survey_predefined_question','f'); + select acs_object_type__drop_type ('survey_section','f'); + select acs_object_type__drop_type ('survey','f'); + +-- select acs_privilege__remove_child ('admin','survey_admin_survey'); +-- select acs_privilege__remove_child ('write','survey_take_survey'); +-- select acs_privilege__remove_child ('survey_admin_survey','survey_delete_question'); +-- select acs_privilege__remove_child ('survey_admin_survey','survey_modify_question'); +-- select acs_privilege__remove_child ('survey_admin_survey','survey_create_question'); +-- select acs_privilege__remove_child ('survey_admin_survey','survey_delete_section'); +-- select acs_privilege__remove_child ('survey_admin_survey','survey_modify_section'); +-- select acs_privilege__remove_child ('survey_admin_survey','survey_create_section'); +-- select acs_privilege__remove_child ('survey_admin_survey','survey_delete_survey'); +-- select acs_privilege__remove_child ('survey_admin_survey','survey_modify_survey'); +-- select acs_privilege__remove_child ('survey_admin_survey','survey_create_survey'); + +-- select acs_privilege__drop_privilege('survey_admin_survey'); +-- select acs_privilege__drop_privilege('survey_take_survey'); +-- select acs_privilege__drop_privilege('survey_delete_question'); +-- select acs_privilege__drop_privilege('survey_modify_question'); +-- select acs_privilege__drop_privilege('survey_create_question'); +-- select acs_privilege__drop_privilege('survey_delete_section'); +-- select acs_privilege__drop_privilege('survey_modify_section'); +-- select acs_privilege__drop_privilege('survey_create_section'); +-- select acs_privilege__drop_privilege('survey_delete_survey'); +-- select acs_privilege__drop_privilege('survey_modify_survey'); +-- select acs_privilege__drop_privilege('survey_create_survey'); + + + Index: openacs-4/contrib/packages/survey/sql/postgresql/survey-notifications-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/postgresql/Attic/survey-notifications-drop.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/postgresql/survey-notifications-drop.sql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,75 @@ +create function inline_0 () +returns integer as ' +declare + row record; +begin + for row in select nt.type_id + from notification_types nt + where nt.short_name in (''survey_response_notif'') + loop + perform notification_type__delete(row.type_id); + end loop; + + return null; +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0 (); + +create function inline_0() returns integer as ' +declare + impl_id integer; + v_foo integer; +begin + -- the notification type impl + impl_id := acs_sc_impl__get_id ( + ''NotificationType'', -- impl_contract_name + ''survey_response_notif_type'' -- impl_name + ); + + PERFORM acs_sc_binding__delete ( + ''NotificationType'', + ''survey_response_notif_type'' + ); + + v_foo := acs_sc_impl_alias__delete ( + ''NotificationType'', -- impl_contract_name + ''survey_response_notif_type'', -- impl_name + ''GetURL'' -- impl_operation_name + ); + + v_foo := acs_sc_impl_alias__delete ( + ''NotificationType'', -- impl_contract_name + ''survey_response_notif_type'', -- impl_name + ''ProcessReply'' -- impl_operation_name + ); + + select into v_foo type_id + from notification_types + where sc_impl_id = impl_id + and short_name = ''survey_response_notif''; + + perform notification_type__delete (v_foo); + + delete from notification_types_intervals + where type_id = v_foo + and interval_id in ( + select interval_id + from notification_intervals + where name in (''instant'',''hourly'',''daily'') + ); + + delete from notification_types_del_methods + where type_id = v_foo + and delivery_method_id in ( + select delivery_method_id + from notification_delivery_methods + where short_name in (''email'') + ); + + return (0); +end; +' language 'plpgsql'; + +select inline_0(); +drop function inline_0(); Index: openacs-4/contrib/packages/survey/sql/postgresql/survey-notifications-init.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/postgresql/Attic/survey-notifications-init.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/postgresql/survey-notifications-init.sql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,71 @@ +-- Survey +-- +-- @author dave@thedesignexperience.org, ben@openforce.biz +-- @creation-date 2002-08-03 +-- +-- integration with Notifications +create function inline_0 () +returns integer as ' + +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_alias__new ( + ''NotificationType'', + ''survey_response_notif_type'', + ''GetURL'', + ''survey::notification::get_url'', + ''TCL'' + ); + + v_foo := acs_sc_impl_alias__new ( + ''NotificationType'', + ''survey_response_notif_type'', + ''ProcessReply'', + ''survey::notification::process_reply'', + ''TCL'' + ); + + perform acs_sc_binding__new ( + ''NotificationType'', + ''survey_response_notif_type'' + ); + + v_foo:= notification_type__new ( + NULL, + impl_id, + ''survey_response_notif'', + ''Survey Response Notification'', + ''Notifications for Survey'', + current_timestamp, + NULL, + NULL, + 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''); +return 0; +end;' language 'plpgsql'; + +select inline_0(); + +drop function inline_0(); + + Index: openacs-4/contrib/packages/survey/sql/postgresql/survey-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/postgresql/Attic/survey-package-create.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/postgresql/survey-package-create.sql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,410 @@ +-- API for survey objects + +create or replace function survey__new (integer,varchar,text,boolean,boolean,boolean,boolean,boolean,varchar,varchar,integer,boolean,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__public_p alias for $12; -- default t + new__creation_user alias for $13; -- default null + new__context_id alias for $14; -- 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, public_p) + 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, new__public_p); + + return v_survey_id; + +end;' language 'plpgsql'; + +create or replace function survey__remove (integer) +returns integer as ' +declare + remove__survey_id alias for $1; + 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 + PERFORM 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 + PERFORM survey_section__remove(v_section_row.section_id); + end loop; + + delete from surveys + where survey_id = remove__survey_id; + + PERFORM acs_object__delete(remove__survey_id); + + return 0; + +end;' language 'plpgsql'; + +create or replace function survey__name (integer) +returns varchar as ' +declare + name__survey_id alias for $1; + v_name surveys.name%TYPE; +begin + select into v_name name + from surveys + where survey_id = name__survey_id; + + return v_name; +end;' language 'plpgsql'; + + +-- API for survey_section objects + +create or replace function survey_section__new (integer,integer,varchar,text,boolean,integer,boolean,boolean,boolean,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__sort_key alias for $6; -- default 0 + new__branch_p alias for $7; -- default f + new__branched_p alias for $8; -- default f + new__block_section_p alias for $9; -- default f + new__page_break_p alias for $10; -- default t + new__creation_user alias for $11; -- default null + new__context_id alias for $12; -- 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, sort_key, branch_p, branched_p, page_break_p, block_section_p) + values + (v_section_id, new__survey_id, new__name, new__description, new__description_html_p, new__sort_key, new__branch_p, new__branched_p, new__page_break_p, new__block_section_p); + + return v_section_id; + +end;' language 'plpgsql'; + +create or replace function survey_section__remove (integer) +returns integer as ' +declare + remove__section_id alias for $1; + 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 + PERFORM survey_question__remove(v_question_row.question_id); + end loop; + + delete from survey_sections + where section_id = remove__section_id; + + PERFORM acs_object__delete(remove__section_id); + + return 0; + +end;' language 'plpgsql'; + +-- API for predefined questions + +create or replace function survey_predefined_question__new (integer,text,varchar,varchar,varchar,varchar,boolean,varchar,varchar,text,varchar,varchar,varchar,integer,integer) +returns integer as ' +declare + new__predefined_question_id alias for $1; -- default null + new__question_text alias for $2; -- default null + new__abstract_data_type alias for $3; -- default null + new__presentation_type alias for $4; -- default null + new__presentation_options alias for $5; -- default null + new__presentation_alignment alias for $6; -- default below + new__question_html_p alias for $7; -- default f + new__summary_type alias for $8; + new__action_type alias for $9; -- default null + new__tcl alias for $10; -- default null + new__table_name alias for $11; -- default null + new__column_name alias for $12; -- default null + new__key_name alias for $13; -- default null + new__creation_user alias for $14; -- default null + new__context_id alias for $15; -- default null + v_predefined_question_id survey_predefined_questions.predefined_question_id%TYPE; +begin + v_predefined_question_id := acs_object__new ( + new__predefined_question_id, + ''survey_predefined_question'', + now(), + new__creation_user, + null, + new__context_id + ); + + insert into survey_predefined_questions + (predefined_question_id,question_text,abstract_data_type,presentation_type,presentation_options,presentation_alignment,question_html_p,summary_type,action_type,tcl,table_name,column_name,key_name) + values + (v_predefined_question_id,new__question_text,new__abstract_data_type,new__presentation_type,new__presentation_options,new__presentation_alignment,new__question_html_p,new__summary_type,new__action_type,new__tcl,new__table_name,new__column_name,new__key_name); + + return v_predefined_question_id; + +end;' language 'plpgsql'; + +-- API for Survey questions + +create or replace function survey_question__new (integer,integer,integer,text,varchar,boolean,boolean,varchar,varchar,varchar,boolean,varchar,varchar,integer,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__question_html_p alias for $11; -- default f + new__summary_type alias for $12; + new__answer_description alias for $13; + new__predefined_question_id alias for $14; -- default null + new__creation_user alias for $15; -- default null + new__context_id alias for $16; -- 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, predefined_question_id) + 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, new__predefined_question_id); + + return v_question_id; + +end;' language 'plpgsql'; + +create or replace function survey_question__remove (integer) +returns integer as ' +declare + remove__question_id alias for $1; +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; + + PERFORM acs_object__delete(remove__question_id); + + return 0; + +end;' language 'plpgsql'; + + + +-- API for survey responses + +create or replace 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 or replace 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 or replace 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 or replace function survey_response__remove(integer) +returns integer as ' +declare + remove__response_id alias for $1; + 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 + PERFORM survey_response__del(v_response_row.response_id); + end loop; + + PERFORM survey_response__del(remove__response_id); + + return 0; + +end;' language 'plpgsql'; + +create or replace function survey_response__del (integer) +returns integer as ' +declare + del__response_id alias for $1; + 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 + PERFORM content_item__delete(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; + PERFORM acs_object__delete(del__response_id); + return 0; + +end;' language 'plpgsql'; + +create or replace function survey_response__boolean_answer (varchar,integer) +returns varchar as ' +declare + boolean_answer__answer alias for $1; + boolean_answer__question_id alias for $2; + + v_answer varchar(100); + v_presentation_options survey_questions.presentation_options%TYPE; + v_split_pos integer; +begin + if boolean_answer__answer is NOT NULL then + select into v_presentation_options presentation_options + from survey_questions where question_id=boolean_answer__question_id; + + v_split_pos:= instr(v_presentation_options, ''/''); + + if boolean_answer__answer = ''t'' then + v_answer:=substr(v_presentation_options, 1, v_split_pos -1 ); + end if; + if boolean_answer__answer = ''f'' then + v_answer:=substr(v_presentation_options, v_split_pos + 1 ); + end if; + + else + v_answer := ''; + end if; + return v_answer; + +end;' language 'plpgsql'; + +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); + +create 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/contrib/packages/survey/sql/postgresql/survey-package-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/postgresql/Attic/survey-package-drop.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/postgresql/survey-package-drop.sql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,9 @@ +-- drop SQL for survey package "packages" +-- +-- PostgreSQL port by jarkko.m.laine@tut.fi on 15th July 2003 + +select drop_package('survey_response'); +select drop_package('survey_question'); +select drop_package('survey_section'); +select drop_package('survey_predefined_question'); +select drop_package('survey'); Index: openacs-4/contrib/packages/survey/sql/postgresql/survey-portlet-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/postgresql/Attic/survey-portlet-create.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/postgresql/survey-portlet-create.sql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,142 @@ + +-- This is free software distributed under the terms of the GNU Public +-- License version 2 or higher. Full text of the license is available +-- from the GNU Project: http://www.fsf.org/copyleft/gpl.html + +create function inline_0 () +returns integer as ' + +declare + ds_id portal_datasources.datasource_id%TYPE; +begin + + ds_id := portal_datasource__new( + ''survey_portlet'', + ''Displays surveys to take'' + ); + + -- 4 defaults procs + + -- shadeable_p + perform portal_datasource__set_def_param ( + ds_id, + ''t'', + ''t'', + ''shadeable_p'', + ''t'' +); + + -- shaded_p + perform portal_datasource__set_def_param ( + ds_id, + ''t'', + ''t'', + ''shaded_p'', + ''f'' +); + + -- hideable_p + perform portal_datasource__set_def_param ( + ds_id, + ''t'', + ''t'', + ''hideable_p'', + ''t'' +); + + -- user_editable_p + perform portal_datasource__set_def_param ( + ds_id, + ''t'', + ''t'', + ''user_editable_p'', + ''f'' +); + + -- link_hideable_p + perform portal_datasource__set_def_param ( + ds_id, + ''t'', + ''t'', + ''link_hideable_p'', + ''t'' +); + +return 0; + +end;' language 'plpgsql'; + +select inline_0(); +drop function inline_0(); + + +-- create the implementation +select acs_sc_impl__new ( + 'portal_datasource', + 'survey_portlet', + 'survey_portlet' +); + +-- add all the needed hooks for the implementation +select acs_sc_impl_alias__new ( + 'portal_datasource', + 'survey_portlet', + 'GetMyName', + 'survey_portlet::get_my_name', + 'TCL' +); + +select acs_sc_impl_alias__new ( + 'portal_datasource', + 'survey_portlet', + 'GetPrettyName', + 'survey_portlet::get_pretty_name', + 'TCL' +); + +select acs_sc_impl_alias__new ( + 'portal_datasource', + 'survey_portlet', + 'Link', + 'survey_portlet::link', + 'TCL' +); + +select acs_sc_impl_alias__new ( + 'portal_datasource', + 'survey_portlet', + 'AddSelfToPage', + 'survey_portlet::add_self_to_page', + 'TCL' +); + +select acs_sc_impl_alias__new ( + 'portal_datasource', + 'survey_portlet', + 'Show', + 'survey_portlet::show', + 'TCL' +); + +select acs_sc_impl_alias__new ( + 'portal_datasource', + 'survey_portlet', + 'Edit', + 'survey_portlet::edit', + 'TCL' +); + +select acs_sc_impl_alias__new ( + 'portal_datasource', + 'survey_portlet', + 'RemoveSelfFromPage', + 'survey_portlet::remove_self_from_page', + 'TCL' +); + +-- Add the binding +select acs_sc_binding__new ( + 'portal_datasource', + 'survey_portlet' +); + Index: openacs-4/contrib/packages/survey/sql/postgresql/survey-portlet-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/postgresql/Attic/survey-portlet-drop.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/sql/postgresql/survey-portlet-drop.sql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,54 @@ +-- remove all the hooks for the implementation +select acs_sc_impl_alias__delete ( + 'portal_datasource', + 'survey_portlet', + 'GetMyName' +); + +select acs_sc_impl_alias__delete ( + 'portal_datasource', + 'survey_portlet', + 'GetPrettyName' +); + +select acs_sc_impl_alias__delete ( + 'portal_datasource', + 'survey_portlet', + 'Link' +); + +select acs_sc_impl_alias__delete ( + 'portal_datasource', + 'survey_portlet', + 'AddSelfToPage' +); + +select acs_sc_impl_alias__delete ( + 'portal_datasource', + 'survey_portlet', + 'Show' +); + +select acs_sc_impl_alias__delete ( + 'portal_datasource', + 'survey_portlet', + 'Edit' +); + +select acs_sc_impl_alias__delete ( + 'portal_datasource', + 'survey_portlet', + 'RemoveSelfFromPage' +); + +-- drop the binding +select acs_sc_binding__delete ( + 'portal_datasource', + 'survey_portlet' +); + +-- drop the implementation +select acs_sc_impl__delete ( + 'portal_datasource', + 'survey_portlet' +); \ No newline at end of file Index: openacs-4/contrib/packages/survey/tcl/survey-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/tcl/Attic/survey-init.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/tcl/survey-init.tcl 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,6 @@ +# for csv-export +#db_foreach surveys "select package_id from apm_packages where package_key='survey'" { +# ns_log notice "ns_register_proc GET \"[apm_package_url_from_id $package_id]admin/responses-export.csv\" survey_export_csv" +# ns_register_proc GET "[apm_package_url_from_id $package_id]admin/responses-export.csv" survey_export_csv +#} + Index: openacs-4/contrib/packages/survey/tcl/survey-notification-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/tcl/Attic/survey-notification-procs.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/tcl/survey-notification-procs.tcl 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,26 @@ +ad_library { + Notification procs for Survey + + Currently this is a place holder file. These procs are not currently needeed and have not been implemented. + + At some point the notification procs in survey-procs should be moved into this file. + + @creation-date 2002-10-29 + +} + +namespace eval survey::notification {} + +ad_proc -public survey::notification::get_url { + object_id +} { + set package_id [db_string get_package_id {}] + set package_url [site_node::get_url_from_object_id -object_id $package_id] + return "${package_url}admin/one?survey_id=$object_id" +} + +ad_proc -public survey::notification::process_reply { + reply_id +} { + +} \ No newline at end of file Index: openacs-4/contrib/packages/survey/tcl/survey-notification-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/tcl/Attic/survey-notification-procs.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/tcl/survey-notification-procs.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,10 @@ + + + + + + select package_id from surveys + where survey_id=:object_id + + + \ No newline at end of file Index: openacs-4/contrib/packages/survey/tcl/survey-portal-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/tcl/Attic/survey-portal-procs.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/tcl/survey-portal-procs.tcl 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,94 @@ +# +# Copyright (C) 2001, 2002 MIT +# +# This file is part of dotLRN. +# +# dotLRN is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# dotLRN is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# + +ad_library { + + Procedures to support the survey portlet + + @creation-date April 2003 + @author mail@koljalehmann.de + @cvs-id $Id: survey-portal-procs.tcl,v 1.1 2003/09/19 16:48:03 rmello Exp $ + +} + +namespace eval survey_portlet { + + ad_proc -private get_my_name { + } { + return "survey_portlet" + } + + ad_proc -private my_package_key { + } { + return "survey" + } + + ad_proc -public get_pretty_name { + } { + return "Surveys" + } + + ad_proc -public link { + } { + return "" + } + + ad_proc -public add_self_to_page { + {-portal_id:required} + {-package_id:required} + } { + Adds a news PE to the given portal. + + @param portal_id The page to add self to + @param package_id The community with the folder + + @return element_id The new element's id + } { + return [portal::add_element_parameters \ + -portal_id $portal_id \ + -portlet_name [get_my_name] \ + -value $package_id \ + -pretty_name [get_pretty_name] \ + ] + } + + ad_proc -public remove_self_from_page { + {-portal_id:required} + {-package_id:required} + } { + Removes a news PE from the given page or the package_id of the + news package from the portlet if there are others remaining + + @param portal_id The page to remove self from + @param package_id + } { + portal::remove_element_parameters \ + -portal_id $portal_id \ + -portlet_name [get_my_name] \ + -value $package_id + } + + ad_proc -public show { + cf + } { + } { + portal::show_proc_helper \ + -package_key [my_package_key] \ + -config_list $cf \ + -template_src "survey-portlet" + } + +} Index: openacs-4/contrib/packages/survey/tcl/survey-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/tcl/Attic/survey-procs-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/tcl/survey-procs-oracle.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,257 @@ + + + + oracle8.1.6 + + + + select count(distinct survey_response.initial_user_id(response_id)) + from + survey_responses + where survey_id=:survey_id + + + + + + select min(question_id) as question_id, + dbms_lob.substr(question_text) as question_text from + survey_questions where section_id=:section_id group by + dbms_lob.substr(question_text) order by min(sort_order) + + + + + + select question_id, required_p + from survey_questions where + section_id=:section_id and + 0=dbms_lob.compare(question_text,(select question_text from + survey_questions where question_id=:q_id)) + + + + + + + + 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, + question_html_p => :question_html_p, + summary_type => :summary_type, + answer_description => :answer_description, + predefined_question_id => :predefined_question_id + ); + end; + + + + + + + + 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, + public_p => :public_p + ); + 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, + sort_key=>:sort_key, + branch_p=>:branch_p, + branched_p=>:branched_p, + block_section_p=>:block_section_p, + page_break_p=>:page_break_p, + context_id =>:new_survey_id + ); + end; + + + + + + select r.initial_response_id, o.creation_user as responding_user_id, r.response_id, + u.first_names || ' ' || u.last_name as user_name, + edit_p, + o.creation_date as response_date, o.creation_user as responding_user_id + from (select nvl(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 o.creation_user = u.user_id(+) + and r.response_id = o.object_id + + + + + + select nvl(max(sort_key),0) from + survey_sections s,survey_question_responses qr, survey_questions q where + qr.response_id=:response_id and qr.question_id=q.question_id and + s.section_id=q.section_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, + ss.sort_key + from survey_questions q, (select initial_user_id as user_id, creation_date, response_id from survey_responses_latest rt where survey_id=:survey_id) 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_key, + sq.sort_order, + sq.question_id, + resp.sort_order + + + + + +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, + ss.sort_key + from survey_questions q, (select initial_user_id as user_id, creation_date, response_id from survey_responses_latest rt where survey_id=:survey_id) 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_key, + sq.sort_order, + sq.question_id, + resp.sort_order + + + + + Index: openacs-4/contrib/packages/survey/tcl/survey-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/tcl/Attic/survey-procs-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/tcl/survey-procs-postgresql.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,267 @@ + + + + postgresql7.1 + + + + select count(distinct survey_response__initial_user_id(response_id)) + from + survey_responses + where survey_id=:survey_id + + + + + + + select min(question_id) as question_id, + question_text + from survey_questions + where section_id=:section_id + group by question_text + order by min(sort_order) + + + + + + select question_id, required_p + from survey_questions where + section_id=:section_id and + question_text = (select question_text from + survey_questions where question_id=:q_id) + + + + + + + SELECT survey_question__new ( + NULL, + :section_id, + :new_sort_order, + :question_text, + :abstract_data_type, + :required_p, + :active_p, + :presentation_type, + :presentation_options, + :presentation_alignment, + :question_html_p, + :summary_type, + :answer_description, + :predefined_question_id, + :user_id, + :section_id + ); + + + + + + + + select survey__new ( + NULL, + :name, + :description, + :description_html_p, + :single_response_p, + :editable_p, + :enabled_p, + :single_section_p, + :type, + :display_type, + :package_id, + :public_p, + :user_id, + :package_id + ); + + + + + + select survey_section__new ( + NULL, + :new_survey_id, + :name, + :description, + :description_html_p, + :sort_key, + :branch_p, + :branched_p, + :block_section_p, + :page_break_p, + :user_id, + :package_id + ); + + + + + + select r.initial_response_id, o.creation_user as 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 + left outer join cc_users u on (o.creation_user = u.user_id) + where r.response_id=:response_id + and r.response_id = o.object_id + + + + + + select coalesce(max(sort_key),0) from + survey_sections s,survey_question_responses qr, survey_questions q + where + qr.response_id=:response_id and qr.question_id=q.question_id and s.section_id=q.section_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 + inner join + survey_question_responses sqr + on (sr.response_id = sqr.response_id) + right outer join + survey_question_choices sqc + on (sqr.question_id = sqc.question_id + and sqr.choice_id = sqc.choice_id) + where + sr.survey_id=:survey_id) resp + right outer join + (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, + ss.sort_key + from survey_questions q, (select initial_user_id as user_id, creation_date, response_id from survey_responses_latest rt where survey_id=:survey_id) 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 + on (sq.response_id = resp.response_id + and sq.question_id = resp.question_id) + order by + sq.response_id, + sq.sort_key, + sq.sort_order, + sq.question_id, + resp.sort_order + + + + + +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 + inner join + survey_question_responses sqr + on (sr.response_id = sqr.response_id) + right outer join survey_question_choices sqc + on (sqr.question_id = sqc.question_id + and sqr.choice_id = sqc.choice_id) + where + sr.survey_id=:survey_id) resp left outer join + + (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, + ss.sort_key + from survey_questions q + inner join survey_sections ss on + (q.section_id=ss.section_id) + inner join + (select initial_user_id as user_id, survey_id, creation_date, response_id from survey_responses_latest rt where survey_id=:survey_id) r + on (ss.survey_id = r.survey_id) + right outer join cc_users u on + (r.user_id = u.user_id) + where ss.survey_id=:survey_id) sq + + on (sq.response_id = resp.response_id + and sq.question_id = resp.question_id) + order by + sq.response_id, + sq.sort_key, + sq.sort_order, + sq.question_id, + resp.sort_order + + + + + Index: openacs-4/contrib/packages/survey/tcl/survey-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/tcl/Attic/survey-procs.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/tcl/survey-procs.tcl 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,974 @@ +# /tcl/survey-procs.tcl + +ad_library { + + Support procs for simple survey module, most important being + survey_question_add_to_form instead, which uses the form manager to add a question to a form + + @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 {![info exists survey_info(survey_id)]} { + # survey doesn't exist, caller has to handle this in their + # own way + return + } + # 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 + } + + # quote description where needed, name is usually needed quoted + set survey_info(name_unquoted) $survey_info(name) + set survey_info(name) [ad_quotehtml $survey_info(name)] + set survey_info(description_unquoted) $survey_info(description) + if {$survey_info(description_html_p)=="f"} { + set survey_info(description) [ad_quotehtml $survey_info(description)] + } + + # These aren't used anywhere but cause a lot of load to the db, so just kick them out, + # I think, they are not so useful - Kolja + # 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 get_section_info { + {-section_id ""} +} { + creates a tcl array variable named "section_info" in the caller's environment, + which contains key/value pairs for all properties of the requested section. + +} { + upvar section_info section_info + + db_1row get_info_by_section_id "" -column_array section_info + if {![info exists section_info(survey_id)]} { + # section doesn't exist, caller has to handle this in their + # own way + return + } + + # quote description where needed, name is usually needed quoted + set section_info(name_unquoted) $section_info(name) + set section_info(name) [ad_quotehtml $section_info(name)] + set section_info(description_unquoted) $section_info(description) + if {$section_info(description_html_p)=="f"} { + set section_info(description) [ad_quotehtml $section_info(description)] + } +} + +ad_proc -public survey_section_add_to_form { + form + section_id + {response_id ""} +} { + adds the questions for the specified section to the specified form. the forms must have been created with ad_form or template::form:create. This uses survey_question_add_to_form, unless the section is a block section +} { + + get_section_info -section_id $section_id + + # create the section + template::form::section $form "$section_info(name)" + + template::element create $form section_info$section_id \ + -widget inform \ + -label "" \ + -value $section_info(description) + + # Is there a template for the section? + set template_filename "[template::get_resource_path]/forms/survey/sections/${section_id}.adp" + if {[file exists $template_filename]} { + set section_template [template::util::read_file $template_filename] + uplevel [list set section_template($section_info(name)) $section_template] + } + + # If this is a block section, generate a block question, else add questions one by one + if {$section_info(block_section_p)=="t"} { + # display as block + # for this, the "options"-parameter has to be built, which is somewhat complicated + set explanation "" + set options [list] + set all_choices [list] + set old_block 0 + db_foreach block_choices "" { + # replace {xxx.gif} by image inclusion + regsub -all "\{(\[^\{\}\]*)\}" $label {} label + if {$old_block!=$block_section_id && [llength $all_choices]>0} { + set old_block $block_section_id + lappend choice_lists $all_choices + set all_choices [list $label] + } else { + set old_block $block_section_id + lappend all_choices $label + } + } + lappend choice_lists $all_choices + lappend options [list $explanation $choice_lists] + + set question_list [db_list_of_lists questions ""] + foreach question $question_list { + set q_id [lindex $question 0] + set question_text [lindex $question 1] + set details [db_list_of_lists question_details ""] + set detail_list [list] + foreach detail $details { + set question_id [lindex $detail 0] + set required_p [lindex $detail 1] + set choice_id_list [db_list choice_ids ""] + lappend detail_list [list "response_to_question.$question_id" $required_p $choice_id_list] + } + lappend options [list $question_text $detail_list] + } + + if {![empty_string_p $response_id]} { + set responses [db_list checked ""] + } else { + set responses [list] + } + + template::element::create $form "section$section_id" \ + -datatype integer \ + -widget block \ + -options $options \ + -value $responses + } else { + db_foreach all_questions "" { + # add all questions to the form + survey_question_add_to_form $form $question_id $response_id + } + } +} + +ad_proc -public survey_question_add_to_form { + form + question_id + {response_id ""} +} {Adds the question to the form. the form has to be created by ad_form or with template::form::create. 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 "" + + set user_value "" + + db_1row predefined_question_id "" + if {$predefined_question_id!=[db_null]} { + # question is a predefined question. If it has already been answered, get the last response value from the db + # if it is a predefined question with action_type="db" get the value from the db instead. + db_1row predefined_question_data "" + if {$action_type == "db"} { + # select preselected value from the db + set user_id [ad_get_user_id] + set user_value [db_string ignore "select $column_name from $table_name where $key_name=:user_id"] + set choice_id $user_value + set boolean_answer $user_value + set clob_answer $user_value + set number_answer $user_value + set varchar_answer $user_value + set date_answer $user_value + set attachment_answer $user_value + } else { + # select preselected value from latest response + set user_id [ad_get_user_id] + if {[db_0or1row locate_predef_preselect ""]} { + set count 0 + db_foreach prev_response_query_predef {} { + 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 "" + } + set edit_previous_response_p "t" + } else { + set choice_id 0 + set boolean_answer "" + set clob_answer "" + set number_answer "" + set varchar_answer "" + set date_answer "" + set attachment_answer "" + } + } + } else { + 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 "" + } + } + } + + if {$edit_previous_response_p == "t"} { + switch -- $abstract_data_type { + "choice" { + set user_value $choice_id + } + "shorttext" { + set user_value $varchar_answer + } + "boolean" { + set user_value $boolean_answer + } + "integer" - + "number" { + set user_value $number_answer + } + "text" { + set user_value $clob_answer + } + "date" { + set user_value $date_answer + } + "blob" { + if {![empty_string_p $attachment_answer]} { + set package_id [ad_conn package_id] + set filename [db_string get_file_name ""] + regsub "_$response_id$" $filename "" filename + set user_value "Uploaded file: \"$filename\"" + } + } + } + } + + # add the form elements, depending on the presentation type + switch -- $presentation_type { + "upload_file" { + template::element::create $form $element_name \ + -widget file \ + -label "$question_text" \ + -required_p $required_p \ + -value $user_value + } + "textbox" { + set html [ad_decode $presentation_options "large" {size 70} "medium" {size 40} {size 10}] + template::element::create $form $element_name \ + -datatype text \ + -widget text \ + -label "$question_text" \ + -value $user_value \ + -html $html \ + -required_p $required_p + } + "textarea" { + set html [ad_decode $presentation_options "large" {rows 20 cols 65} "medium" {rows 15 cols 55} {rows 8 cols 35}] + template::element::create $form $element_name \ + -datatype text \ + -widget textarea \ + -label "$question_text" \ + -value $user_value \ + -html $html \ + -required_p $required_p + } + "date" { + #set options {format "DD Month YYYY"} + template::element::create $form $element_name \ + -datatype date \ + -widget date \ + -label "$question_text" \ + -value $user_value \ + -required_p $required_p + } + "select" { + if { $abstract_data_type == "boolean" } { + 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 options "{$choice_t t} {$choice_f f}" + } else { + # at some point, we may want to add a UI option for the admin + # to sepcify multiple or not for select + set optionlist [list] + db_foreach question_choices "" { + lappend optionlist [list $label $choice_id] + } + set options $optionlist + } + template::element::create $form $element_name \ + -datatype text \ + -widget select \ + -label "$question_text" \ + -value $user_value \ + -options $options \ + -required_p $required_p + } + "radio" { + set widget "text(radio)" + if { $abstract_data_type == "boolean" } { + 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 options "{$choice_t t} {$choice_f f}" + } else { + set optionlist [list] + db_foreach question_choices_2 "" { + # replace {xxx.gif} by image inclusion + regsub -all "\{(\[^\{\}\]*)\}" $label {} label + lappend optionlist [list $label $choice_id] + } + set options $optionlist + } + template::element::create $form $element_name \ + -datatype text \ + -widget radio \ + -label "$question_text" \ + -value $user_value \ + -options $options \ + -required_p $required_p + } + + "checkbox" { + set choices [list] + set optionlist [list] + db_foreach question_choices_3 "" { + lappend optionlist [list $label $choice_id] + } + set options $optionlist + template::element::create $form $element_name \ + -datatype text \ + -widget checkbox \ + -label "$question_text" \ + -value $user_value \ + -options $options \ + -required_p $required_p + } + } +} + +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 "" + + set last_section_id "" + db_foreach summary "" { + if {$section_id != $last_section_id} { + append return_string "

[ad_quotehtml $section_name]

" + set last_section_id $section_id + } + + 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 {}] + regsub "_$response_id$" $filename "" 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_nextval survey_choice_id_sequence] + 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 + if package_id is specific it copies the 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 { + db_1row get_section_info "" + 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"] + if {![empty_string_p $community_id]} { + set community_name [dotlrn_community::get_community_name $community_id] + } else { + set community_name "No Community" + } + set community_url "[ad_parameter -package_id [ad_acs_kernel_id] SystemURL][dotlrn_community::get_community_url $community_id]" + } + db_1row get_response_info {} + + 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 +} + +ad_proc survey_next_sections { + {-edit_p "f"} + survey_id + section_id + response_id +} { + returns the following sections in the survey. First get a list of all sections after the one just completed, then see, if their condition (in case of branching) holds. If yes or if there are no conditions, add the section. Repeat this, until a condition cannot be decided or a section has page_break_p="t" +} { + if {$section_id==0} { + # no last section given, get the last one answered or the first one if editing + if {$edit_p=="t"} { + set sort_key 0 + } else { + set sort_key [db_string get_last_answered_section_sort_key ""] + } + } else { + set sort_key [db_string sort_key ""] + } + + set result [list] + set sections [db_list_of_lists get_following_sections ""] + foreach section $sections { + set section_id [lindex $section 0] + set page_break_p [lindex $section 1] + set ok "t" + db_foreach get_condition "" { + if {![db_0or1row get_response ""]} { + set ok "f" + } + } + if {$ok=="t"} { + lappend result $section_id + } + if {$page_break_p=="t" && $result!=[list]} { + return $result + } + } + return $result +} + +ad_proc survey_status_bar { + section_id +} { + returns a status bar, indicating the progress within a survey +} { + db_1row percentage "" + if {[empty_string_p $status_bar_color]} { + return "" + } + set html " + + + + +
+ + + + + + + + +
$percentage% Complete +
+ + + + + +
+ + + + + +
\"\" +
+ +
+ +
+
+" + return $html +} + +ad_proc survey_block_section_candidate_p { + section_id +} { + return 1 if the section can be made a block section, 0 if not + criteria: + - at least one question + - All questions are multiple choice, radio button + - For each question_text there must be the same set(s) of choices +} { + set return_value 1 + db_foreach get_questions "" { + if {$abstract_data_type != "choice" || $presentation_type!= "radio"} { + set return_value 0 + } + if {[info exist question($question_text)]} { + append question($question_text) ":$all_choices" + } else { + set question($question_text) $all_choices + } + } if_no_rows { + set return_value 0 + } + set count 0 + foreach name [array names question] { + if {$count==0} { + set answers $question($name) + } else { + if {$question($name)!=$answers} { + return 0 + } + } + incr count + } + return $return_value +} + +ad_proc survey_export_csv { + conn + args +} { + Return csv data of a survey to a user, invoked by ns_register_proc from survey-init.tcl +} { + ad_page_contract { + + CSV export of responses to particular survey. + + @author sebastian@arsdigita.com + @date July 2000 + @cvs-id $Id: survey-procs.tcl,v 1.1 2003/09/19 16:48:03 rmello Exp $ + + } { + + survey_id:integer,notnull + {anonymous_p:boolean "t"} + {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 admin + + set n_responses [db_string get_n_responses {}] + + if {$n_responses==0} { + #get_survey_info -survey_id $survey_id + #set context_bar [ad_context_bar [list "one?[export_url_vars survey_id]" $survey_info(name)] "CSV Export"] + #_return_template "no-responses" + ad_return_complaint 1 "No responses" + return + } + + set question_id_list [list] + set responses_table survey_responses + + set headline "email,first_names,last_name,user_id,submission_date,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 "text/comma-separated-values" + ns_write "$headline \r\n" + + if {$anonymous_p=="t"} { + set query "get_all_survey_question_responses_with_anonymous" + } else { + set query "get_all_survey_question_responses" + } + db_foreach $query "" { + + 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 +} + + + Index: openacs-4/contrib/packages/survey/tcl/survey-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/tcl/Attic/survey-procs.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/tcl/survey-procs.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,490 @@ + + + + + + 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 min(section_id) as section_id + from survey_sections + where survey_id = :survey_id + + + + + + + select count(*) from dotlrn_member_rels_full + where rel_type='dotlrn_member_rel' + and community_id=:community_id + + + + + + + select s.*, + o.creation_user, o.creation_date + from survey_sections s, acs_objects o + where o.object_id = :section_id + and s.section_id = o.object_id + + + + + + select label,block_section_id from survey_block_questions where section_id=:section_id order by block_section_id, + sort_order + + + + + + select choice_id from survey_question_choices where + question_id=:question_id order by sort_order + + + + + + + select name, description, description_html_p, block_section_p from survey_sections where section_id=:section_id + + + + + + + select choice_id as selected_choice_id from + survey_question_responses qr, survey_questions q where + section_id=:section_id and q.question_id=qr.question_id and response_id=:response_id + + + + + + select question_id, question_text from survey_questions where + section_id=:section_id order by sort_order + + + + + +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 predefined_question_id from survey_questions where + question_id=:question_id + + + + + + select action_type,table_name,column_name,key_name from + survey_predefined_questions where predefined_question_id=:predefined_question_id + + + + + + +select question_id as preselect_question_id, object_id as response_id +from survey_question_responses, acs_objects + where question_id in ( + select question_id from survey_questions where + predefined_question_id=:predefined_question_id) + and object_type='survey_response' + and response_id=object_id + and creation_date=(select min(creation_date) from + survey_question_responses, acs_objects + where question_id in ( + select question_id from survey_questions where + predefined_question_id=:predefined_question_id) + and object_type='survey_response' + and response_id=object_id) + + + + + + + +select + choice_id, + boolean_answer, + clob_answer, + number_answer, + varchar_answer, + to_char(date_answer,'YYYY MM DD HH24 MI SS') as date_answer, + attachment_answer + from survey_question_responses + where question_id = :preselect_question_id + and response_id = :response_id + + + + + + +select + choice_id, + boolean_answer, + clob_answer, + number_answer, + varchar_answer, + to_char(date_answer,'YYYY MM DD HH24 MI SS') as date_answer, + attachment_answer + from survey_question_responses + where question_id = :question_id + and response_id = :response_id + + + + + + + select name from cr_items i, cr_revisions r where + i.item_id=r.item_id and r. revision_id=:attachment_answer + + + + + + + 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 + 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, + s.name as section_name +from + survey_questions sq, + survey_question_responses sqr, + survey_sections s +where + sqr.response_id = :response_id + and sq.question_id = sqr.question_id + and sq.active_p = 't' + and s.section_id=sq.section_id +order by s.sort_key,sq.sort_order + + + + + + + + select name from cr_items i, cr_revisions r where + i.item_id=r.item_id and + revision_id=:attachment_answer + + + + + + + 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 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 = :new_question_id + + + + + + 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, presentation_alignment, more_info_type, predef_choice_id) + values + (:new_choice_id, :new_question_id, :label, + :numeric_value, :sort_order, :presentation_alignment, + :more_info_type, :predef_choice_id) + + + + + + + +select * from surveys where survey_id=:survey_id + + + + + + select section_id from survey_sections where survey_id=:survey_id + + + + + +select name, description, description_html_p, sort_key, branch_p, +branched_p, block_section_p, page_break_p from survey_sections where section_id=:section_id + + + + + + update survey_sections set description=:description + where section_id=:new_section_id + + + + + +select question_id from survey_questions + where section_id in (select section_id from survey_sections + where survey_id=:survey_id) + + + + + + + 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 presentation_options + from survey_questions + where question_id=:question_id + + + + + + select sort_key from survey_sections where section_id=:section_id + + + + + + select section_id,page_break_p from survey_sections where + survey_id=:survey_id and sort_key>:sort_key order by sort_key + + + + + + select question_id,choice_id,boolean_answer + from survey_conditions c, survey_branches b + where b.section_id=:section_id and b.condition=c.condition_id + + + + + + select 1 + from survey_question_responses where response_id=:response_id + and question_id=:question_id + and (choice_id=:choice_id or boolean_answer=:boolean_answer) + + + + + + + + select to_char((sort_key-1)/(select max(sort_key) from survey_sections ssec + where ssec.survey_id=ss.survey_id)*100,'999') as percentage, + status_bar_color from survey_sections ss, surveys s where + section_id=:section_id and s.survey_id=ss.survey_id + + + + + + + + + select question_text,abstract_data_type, presentation_type, + survey_question_all_choices(question_id) as all_choices + from survey_questions where section_id=:section_id + + + + + + + + + select count(*) from survey_responses_latest + where survey_id=:survey_id + + + + + + + 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 s.sort_key,q.sort_order,q.question_id + + + + + + + select title from cr_revisions where + revision_id=:attachment_answer + + + + Index: openacs-4/contrib/packages/survey/www/index-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/index-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/index-oracle.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,22 @@ + + +oracle8.1.6 + + + +select s.survey_id, s.name, s.editable_p, s.single_response_p, +sub.response_id, to_char(sub.creation_date,'Month FMDD, YYYY') as creation_date +from surveys s, +(select creation_date, survey_id, response_id from survey_responses + sr, acs_objects o where o.creation_user=:user_id and + o.object_id=sr.response_id +) sub +where s.package_id=:package_id +and s.enabled_p='t' +and 't' = acs_permission.permission_p(s.survey_id, :user_id, 'write') +and s.survey_id=sub.survey_id(+) +order by upper(s.name), creation_date desc + + + + Index: openacs-4/contrib/packages/survey/www/index-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/index-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/index-postgresql.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,22 @@ + + + +postgresql7.1 + + + +select s.survey_id, s.name, s.editable_p, s.single_response_p, +sub.response_id, to_char(sub.creation_date,'Month FMDD, YYYY') as creation_date +from surveys s left outer join +(select creation_date, survey_id, response_id from survey_responses + sr, acs_objects o where o.creation_user=:user_id and + o.object_id=sr.response_id +) sub on (s.survey_id=sub.survey_id) +where s.package_id=:package_id +and s.enabled_p='t' +and 't' = acs_permission__permission_p(s.survey_id, :user_id, 'write') +order by upper(s.name), creation_date desc + + + + Index: openacs-4/contrib/packages/survey/www/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/index.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/index.adp 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,33 @@ + +Surveys +@context_bar;noquote@ +

Administer Surveys +

+ Index: openacs-4/contrib/packages/survey/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/index.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/index.tcl 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,30 @@ +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 2003/09/19 16:48:03 rmello Exp $ +} { + +} -properties { + surveys:multirow +} + +set package_id [ad_conn package_id] + +set context_bar [ad_context_bar] + +# Allow public surveys +# set user_id [ad_maybe_redirect_for_registration] +set user_id [ad_conn user_id] + +set admin_p [ad_permission_p $package_id admin] + +db_multirow surveys survey_select {} + + +ad_return_template + Index: openacs-4/contrib/packages/survey/www/one-respondent.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/one-respondent.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/one-respondent.adp 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,30 @@ + +Answers to @survey_name@ +@context_bar;noquote@ + + @description@ +

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

+ + + + + + + + +
Your response + on @responses.pretty_submission_date@ + [edit this response] +
@responses.answer_summary;noquote@
+
+ Index: openacs-4/contrib/packages/survey/www/one-respondent.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/one-respondent.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/one-respondent.tcl 19 Sep 2003 16:48:03 -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 2003/09/19 16:48:03 rmello Exp $ +} { + + survey_id:integer + {return_url ""} + +} -validate { + survey_exists -requires {survey_id} { + if ![db_0or1row survey_exists {}] { + ad_complain "Survey $survey_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/contrib/packages/survey/www/one-respondent.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/one-respondent.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/one-respondent.xql 19 Sep 2003 16:48:03 -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/contrib/packages/survey/www/one-survey-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/one-survey-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/one-survey-oracle.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,23 @@ + + + +oracle8.1.6 + + + + +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 + + + + + Index: openacs-4/contrib/packages/survey/www/one-survey-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/one-survey-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/one-survey-postgresql.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,22 @@ + + + +postgresql7.1 + + + + +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' + + + + Index: openacs-4/contrib/packages/survey/www/one-survey.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/one-survey.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/one-survey.adp 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,31 @@ + +Surveys +@context_bar;noquote@ +

Admin

+ + Index: openacs-4/contrib/packages/survey/www/one-survey.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/one-survey.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/one-survey.tcl 19 Sep 2003 16:48:03 -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 2003/09/19 16:48:03 rmello 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 write] + +set admin_p [ad_permission_p $survey_id admin] + +db_multirow survey_details get_survey_details {} + +ad_return_template + Index: openacs-4/contrib/packages/survey/www/one_list.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/one_list.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/one_list.adp 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,5 @@ +
    + +
  1. @questions:item@ + +
Index: openacs-4/contrib/packages/survey/www/one_paragraph.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/one_paragraph.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/one_paragraph.adp 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,4 @@ + +@questions:item@

+ + Index: openacs-4/contrib/packages/survey/www/one_table.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/one_table.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/one_table.adp 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,5 @@ + + + + +
@questions:item@
Index: openacs-4/contrib/packages/survey/www/process-response-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/process-response-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/process-response-oracle.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,44 @@ + + + + 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, + creation_ip => :creation_ip + ); + 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 + content_item.delete(:old_item); +end; + + + + Index: openacs-4/contrib/packages/survey/www/process-response-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/process-response-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/process-response-postgresql.xql 19 Sep 2003 16:48:03 -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, :response_value) + + + + + Index: openacs-4/contrib/packages/survey/www/process-response.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/process-response.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/process-response.adp 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,12 @@ + +Response Submitted +@context_bar;noquote@ +

+

Response submitted. Thank you.

+

Return to the survey + index page. + Return to where you were. + +

+ +
Index: openacs-4/contrib/packages/survey/www/process-response.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/process-response.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/process-response.tcl 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,334 @@ +ad_page_contract { + + Insert user response into database. + This page receives an input for each question named + response_to_question.$question_id + + @param survey_id survey user is responding to + @param section_ids sections on the last page + @param return_url optional redirect address + + @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 2003/09/19 16:48:03 rmello Exp $ +} { + survey_id:integer + section_ids + {initial_response_id:integer 0} + {return_url:optional ""} + response_to_question:array,optional,multiple,html + response_id:integer,notnull + {edit_p "f"} +} -validate { + sections_exist -requires { section_ids } { + foreach section_id $section_ids { + if {[ad_var_type_check_integer_p $section_id]} { + if ![db_0or1row section_exists {}] { + ad_complain "Section $section_id does not exist" + } + } else { + ad_complain "Section_id $section_id is not an integer" + } + } + } + + check_questions -requires { section_ids } { + set question_info_list [list] + foreach section_id $section_ids { + set question_info_list [concat $question_info_list [db_list_of_lists survey_question_info_list {}]] + } + ## 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)] + } else { + if { [empty_string_p [lindex $response_to_question($question_id) 0 ] ] } { + set 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 {$abstract_data_type=="blob"} { + # check if file was already uploaded earlier + if {[db_0or1row upload_file_exist ""]} { + set upload_file_exist($question_id) $attachment_answer + } + } + + if { [exists_and_not_null response_to_question($question_id)] } { + + set response_value [string trim $response_to_question($question_id)] + } elseif {$required_p == "t" && ![info exists upload_file_exist($question_id)]} { + 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" } { + if {![info exist upload_file_exist($question_id)]} { + 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 } { + set missing "" + foreach skipped_question $questions_with_missing_responses { + append missing "
  • $skipped_question" + } + ad_complain "You didn't respond to all required sections. You skipped:
      $missing
    " + return 0 + } else { + return 1 + } + } + +} -properties { + + survey_name:onerow +} + +ad_require_permission $survey_id write + +set user_id [ad_conn user_id] +# anonymous user: +if {$user_id == 0} { + set user_id [db_null] +} + +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) + + +# 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 $response_id + +set creation_ip [ad_conn peeraddr] +if {$initial_response_id==0} { + set initial_response_id "" +} + +foreach section_id $section_ids { + db_transaction { + + if {[db_string get_response_count {}] == 0} { + db_exec_plsql create_response {} + } + + set question_info_list [db_list_of_lists survey_question_info_list {}] + + # in case of editing a response, clear old responses + db_dml clear_section_response "" + + 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 required_p [lindex $question 4] + set predefined_question_id [lindex $question 5] + + if {[info exists response_to_question($question_id)]} { + if {$abstract_data_type=="date"} { + set response_value "$response_to_question($question_id.year)-$response_to_question($question_id.month)-$response_to_question($question_id.day)" + } else { + set response_value [string trim $response_to_question($question_id)] + } + } else { + set response_value [db_null] + } + + # If this is a predefined question, handle it accordingly + if {$predefined_question_id != [db_null]} { + db_1row predefined "" + if {$action_type=="db"} { + # insert value into db + db_dml ignore "update $table_name set $column_name=:response_value where $key_name=:user_id" + } else { + if {$action_type=="tcl"} { + # execute tcl code - need more specs on that - Kolja + } + } + } + + 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] || [empty_string_p [lindex $response_value 0]] } { + 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 {} -clobs [list $response_value] + } + "date" { + if { [empty_string_p $response_value] } { + set response_value [db_null] + } + + db_dml survey_question_response_date_insert {} + } + "blob" { + + if { ![empty_string_p $response_value] } { + # this stuff only makes sense to do if we know the file exists + # cannot use [template::data::transform::file because of the . in the var name + set filename [ns_queryget response_to_question.$question_id] + set tmp_filename [ns_queryget response_to_question.$question_id.tmpfile] + set mime_type [ns_queryget response_to_question.$question_id.content-type] + set file_extension [string tolower [file extension $response_value]] + # remove the first . from the file extension + regsub {\.} $file_extension "" file_extension + + set n_bytes [file size $tmp_filename] + + if { $n_bytes == 0 } { + error "This should have been checked earlier." + } else { + set unique_name "${filename}_${response_id}" + if {[ad_conn user_id]=="0"} { + # anonymous answer + set creation_user [db_null] + } else { + set creation_user [ad_conn user_id] + } + if {[info exist upload_file_exist($question_id)]} { + set old_revision_id $upload_file_exist($question_id) + set old_item [db_string get_item_id ""] + set revision_id [cr_import_content -item_id $old_item -creation_user $creation_user -title $filename "" $tmp_filename $n_bytes $mime_type $unique_name ] + db_dml survey_question_response_file_attachment_update "" + db_dml update_item_description "" + } else { + set revision_id [cr_import_content -creation_user $creation_user -title $filename "" $tmp_filename $n_bytes $mime_type $unique_name ] + db_dml survey_question_response_file_attachment_insert "" + } + # 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 + + } + } + } + } + } +} +} + +# Look for next section +set section_ids [survey_next_sections -edit_p $edit_p $survey_id $section_id $response_id] +if {$section_ids!=""} { + # found following section + ad_returnredirect "respond.tcl?[export_vars -url {survey_id response_id return_url edit_p section_ids:multiple}]" +} else { + # survey is finished + db_dml finish_response {} +} + +survey_do_notifications -response_id $response_id + + + +if {[exists_and_not_null return_url]} { + ad_returnredirect "$return_url" + ad_script_abort +} else { + set context_bar [ad_context_bar "Response Submitted for $survey_name"] + ad_return_template +} + + + + Index: openacs-4/contrib/packages/survey/www/process-response.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/process-response.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/process-response.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,160 @@ + + + + + + select 1 from survey_sections where section_id = :section_id + + + + + + + select question_id, question_text, abstract_data_type, + presentation_type, required_p, predefined_question_id + from survey_questions + where section_id = :section_id + and active_p = 't' + order by sort_order + + + + + + +select attachment_answer + from survey_question_responses where question_id=:question_id and response_id=:response_id and attachment_answer is not null + + + + + + select count(*) from survey_responses + where response_id=:response_id + + + + + + delete from survey_question_responses where question_id in + (select question_id from survey_questions where + section_id=:section_id) + and response_id=:response_id and attachment_answer is null + + + + + + + select action_type, tcl, table_name, column_name, key_name + from survey_predefined_questions + where predefined_question_id=:predefined_question_id + + + + + + + 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 item_id as old_item from cr_revisions where revision_id=:old_revision_id + + + + + + + update survey_question_responses + set attachment_answer=:revision_id, + attachment_file_name=:filename, attachment_file_type=:mime_type, + attachment_file_extension=:file_extension + where question_id=:question_id and response_id=:response_id + + + + + + update cr_items + set name=:unique_name + where item_id=:old_item + + + + + + + insert into survey_question_responses + (response_id, question_id, attachment_answer,attachment_file_name,attachment_file_type,attachment_file_extension) + values + (:response_id, :question_id, :revision_id,:filename,:mime_type,:file_extension) + + + + + + update survey_responses set finished_p='t' where + survey_id=:survey_id and response_id=:response_id + + + + + + + select type from survey_sections where section_id = :section_id + + + + + + + select name from survey_sections where section_id = :section_id + + + + + Index: openacs-4/contrib/packages/survey/www/respond-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/respond-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/respond-oracle.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,44 @@ + + + + oracle8.1.6 + + + + select count(*) from survey_responses, acs_objects + where survey_id=:survey_id + and response_id=object_id + and initial_response_id is null + + + + + + select max(response_id) from survey_responses + where survey_id=:survey_id + and survey_response.initial_user_id(response_id)=:user_id + and initial_response_id is null + + + + + + + select survey_response.initial_response_id(:response_id) as initial_response_id from dual + + + + + + + select max(response_id) as response_id,count(*) as unfinished + from survey_responses r, acs_objects o where finished_p='f' and + r.response_id=o.object_id and creation_user=:user_id + and survey_id=:survey_id + + + + + + + Index: openacs-4/contrib/packages/survey/www/respond-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/respond-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/respond-postgresql.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,48 @@ + + + + postgresql7.1 + + + + 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 + + + + + + select max(response_id) from survey_responses + where survey_id=:survey_id + and survey_response__initial_user_id(response_id)=:user_id + and initial_response_id is null + + + + + + + + select survey_response__initial_response_id(:response_id) as initial_response_id + + + + + + + + select max(response_id) as response_id,count(*) as unfinished + from survey_responses r + inner join acs_objects o + on (r.response_id=o.object_id) + where finished_p='f' + and creation_user=:user_id + and survey_id=:survey_id + + + + + + Index: openacs-4/contrib/packages/survey/www/respond.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/respond.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/respond.adp 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,7 @@ + +One Survey: @name;noquote@ +@context_bar;noquote@ +@status_bar;noquote@ +* denotes a required question + + Index: openacs-4/contrib/packages/survey/www/respond.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/respond.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/respond.tcl 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,118 @@ +ad_page_contract { + + Display a questionnaire for one survey. + + @param survey_id id of displayed survey + @param section_ids sections that should be displayed + + @author philg@mit.edu + @author nstrug@arsdigita.com + @date 28th September 2000 + @cvs-id $Id: respond.tcl,v 1.1 2003/09/19 16:48:03 rmello Exp $ + +} { + + survey_id:integer,notnull + {section_ids:integer,multiple 0} + {response_id:integer 0} + return_url:optional + {edit_p "f"} +} -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] + # Allow public surveys + set user_id [ad_conn user_id] + set number_of_responses [db_string count_responses {}] + # If we have a response in the system, and the survey is editable + # set the response_id to the latest response unless response_id is + # submited when calling the function + if {$number_of_responses!=0 && $response_id==0} { + set response_id [db_string get_latest_response_id {}] + } + + get_survey_info -survey_id $survey_id + #set single_section_p $survey_info(single_section_p) + # if {$section_id==0 && $single_section_p=="t"} { + # set section_id $survey_info(section_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 write + +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 "" + } +} + +if {$section_ids == 0} { + # If no section_id is given, start the survey + # first check if there is already a response_id (edit) + # if not check for an unfinished response + # if yes, take the first unfinished section of that + # if no, start a new + if {$response_id==0} { + db_1row unfinished_surveys "" + if {$unfinished==0} { + # No unfinished, start a new response + set response_id [db_nextval acs_object_id_seq] + } + set section_ids [survey_next_sections $survey_id 0 $response_id] + } else { + set section_ids [survey_next_sections -edit_p t $survey_id 0 $response_id] + } +} + +if {[llength $section_ids]==0} { + # No following section, so mark this response finished and start a new one. + # Normally this should already be handled in process-response + db_dml finish_survey "" + set response_id [db_nextval acs_object_id_seq] + set section_ids [survey_next_sections -edit_p t $survey_id 0 $response_id] +} + +ad_form -name take_survey -action process-response -html {enctype multipart/form-data} -form { + {survey_id:text(hidden) {value $survey_id}} + {section_ids:text(hidden) {value $section_ids}} + {response_id:text(hidden) {value $response_id}} + {return_url:text(hidden) {value $return_url}} +} + +foreach section_id $section_ids { + survey_section_add_to_form take_survey $section_id $response_id +} + +# status bar +set status_bar [survey_status_bar [lindex $section_ids 0]] + +# select survey style +set style "survey/standard" +db_0or1row get_style "" + +ad_return_template Index: openacs-4/contrib/packages/survey/www/respond.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/respond.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/respond.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,61 @@ + + + + + + select 1 from surveys where survey_id = :survey_id + + + + + + update survey_responses set finished_p='t' where response_id=:response_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 + + + + + + select section_id from survey_sections where + survey_id=:survey_id and rownum=1 + order by sort_key + + + + + +select question_text, presentation_type, abstract_data_type, + question_id, required_p from survey_questions where + section_id=:section_id and active_p='t' order by sort_order + + + + + + + + select 'survey/'||template_file as style from survey_templates t, surveys s + where s.survey_id=:survey_id + and s.template=t.template_id + + + + Index: openacs-4/contrib/packages/survey/www/survey-portlet-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/survey-portlet-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/survey-portlet-oracle.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,23 @@ + + +oracle8.1.6 + + + + +select s.survey_id, s.name, s.editable_p, s.single_response_p, +sub.response_id, to_char(sub.creation_date,'Month FMDD, YYYY') as creation_date +from surveys s, +(select creation_date, survey_id, response_id from survey_responses + sr, acs_objects o where o.creation_user=:user_id and + o.object_id=sr.response_id +) sub +where s.package_id=:package_id +and s.enabled_p='t' +and 't' = acs_permission.permission_p(s.survey_id, :user_id, 'write') +and s.survey_id=sub.survey_id(+) +order by upper(s.name), creation_date desc + + + + Index: openacs-4/contrib/packages/survey/www/survey-portlet-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/survey-portlet-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/survey-portlet-postgresql.xql 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,21 @@ + + +postgresql7.1 + + + +select s.survey_id, s.name, s.editable_p, s.single_response_p, +sub.response_id, to_char(sub.creation_date,'Month FMDD, YYYY') as creation_date +from surveys s left outer join +(select creation_date, survey_id, response_id from survey_responses + sr, acs_objects o where o.creation_user=:user_id and + o.object_id=sr.response_id +) sub on (s.survey_id=sub.survey_id) +where s.package_id=:package_id +and s.enabled_p='t' +and 't' = acs_permission__permission_p(s.survey_id, :user_id, 'write') +order by upper(s.name), creation_date desc + + + + Index: openacs-4/contrib/packages/survey/www/survey-portlet.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/survey-portlet.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/survey-portlet.adp 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,30 @@ +

    Administer Surveys +

      + + +
    • @surveys.name@ + Answer Survey + Answer Survey +
    • + +
        + +
      • Previous response on: @surveys.creation_date@ + View Response + + Edit Response +
      • +
        +
      +
      +
      + + +
    • No surveys active + + +
    + Index: openacs-4/contrib/packages/survey/www/survey-portlet.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/survey-portlet.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/survey-portlet.tcl 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,36 @@ +# +# Copyright (C) 2001, 2002 MIT +# +# This file is part of dotLRN. +# +# dotLRN is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# dotLRN is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# + +# +# /survey/www/survey-portlet.tcl +# +# arjun@openforce.net +# +# The logic for the survey portlet +# +# $Id: survey-portlet.tcl,v 1.1 2003/09/19 16:48:03 rmello Exp $ +# + +set parent_package_id [ad_conn package_id] +set user_id [ad_conn user_id] + +set package_id [site_node_apm_integration::get_child_package_id -package_id $parent_package_id -package_key survey] +array set config $cf +set shaded_p $config(shaded_p) +set admin_p [ad_permission_p $package_id admin] +set url [ad_conn url] + +db_multirow surveys survey_select {} Index: openacs-4/contrib/packages/survey/www/view-attachment.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/view-attachment.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/view-attachment.tcl 19 Sep 2003 16:48:03 -0000 1.1 @@ -0,0 +1,32 @@ +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 2003/09/19 16:48:03 rmello Exp $ +} { + + response_id:integer,notnull + question_id:integer,notnull + +} -validate { + attachment_exists -requires {response_id question_id} { + if {![db_0or1row get_file_info {}]} { + 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 +# already in cr_write_content + +cr_write_content -revision_id $revision_id + + Index: openacs-4/contrib/packages/survey/www/view-attachment.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/Attic/view-attachment.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/view-attachment.xql 19 Sep 2003 16:48:03 -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/contrib/packages/survey/www/admin/block-question-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/block-question-add.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/block-question-add.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,9 @@ + +@survey_id@ + +@survey_info.name;noquote@: New Question +@context_bar;noquote@ + + + + Index: openacs-4/contrib/packages/survey/www/admin/block-question-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/block-question-add.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/block-question-add.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,57 @@ +ad_page_contract { + Present form to begin adding a question to a survey. + For Questions in a block section + Lets user enter the question. Presentation and choices are determined by the type of section (block section) + + @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: block-question-add.tcl,v 1.1 2003/09/19 16:48:04 rmello Exp $ +} { + section_id:integer + {after:integer ""} + +} + +set package_id [ad_conn package_id] +set user_id [ad_conn user_id] +ad_require_permission $package_id admin + +get_survey_info -section_id $section_id +get_section_info -section_id $section_id + +if {$section_info(block_section_p)!="t"} { + ad_complain 1 "Not a measurement section" +} + +set question_id [db_nextval "acs_object_id_seq"] +set type $survey_info(type) +ad_form -name create_question -action question-add-3 -export { after } -form { + {question_id:text(hidden) {value $question_id}} + {section_id:text(hidden) {value $section_id}} + {question_text:text(textarea) {label "Question"} {html {rows 5 cols 70}}} + {abstract_data_type:text(hidden) {value "choice"}} + {presentation_type:text(hidden) {value "radio"}} + {presentation_alignment:text(hidden) {value "beside"}} + {required:text(radio) {label "Required?"} {options {{Yes t} {No f}}} {value t}} + {valid_responses:text(hidden) {value "block"}} + {type:text(hidden) {value $type}} +} + +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_return_template Index: openacs-4/contrib/packages/survey/www/admin/condition-add-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/condition-add-2.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/condition-add-2.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,45 @@ +ad_page_contract { + Add a condition to an existing branch +} { + branch_id:integer,notnull + section_id:integer,notnull + condition_id:integer,notnull + choice:notnull +} -validate { + choice_format -requires {choice:notnull} { + if {!([regexp {^[0-9]+:[0-9]+$} $choice] || [regexp {^[0-9]+:[tf]$} $choice])} { + ad_complain "Invalid Choice!" + } + } +} + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] +ad_require_permission $package_id admin + +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) + +set choice_id [db_null] +set boolean_answer [db_null] +regexp {^([0-9]+):([0-9]+)$} $choice match question_id choice_id +regexp {^([0-9]+):([tf])$} $choice match question_id boolean_answer + +db_transaction { + if {[db_0or1row get_old_condition ""]} { + db_dml unlink_old_condition "" + db_dml remove_old_condition "" + } + db_dml add_condition "" + db_dml link_condition "" +} on_error { + + db_release_unused_handles + ad_return_error "Database Error $test" "
    $errmsg
    " + ad_script_abort + +} + + +ad_returnredirect "one?survey_id=$survey_id" + Index: openacs-4/contrib/packages/survey/www/admin/condition-add-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/condition-add-2.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/condition-add-2.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,39 @@ + + + + + + + select condition as old_condition_id from survey_branches + where branch_id=:branch_id + + + + + + update survey_branches set condition=null where branch_id=:branch_id + + + + + + delete from survey_conditions where condition_id=:old_condition_id + + + + + + insert into survey_conditions (condition_id, question_id, + choice_id, boolean_answer) values (:condition_id, :question_id, + :choice_id, :boolean_answer) + + + + + + update survey_branches + set condition=:condition_id where branch_id=:branch_id + + + + Index: openacs-4/contrib/packages/survey/www/admin/condition-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/condition-add.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/condition-add.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,9 @@ + +@survey_id@ + +@survey_info.name;noquote@: Branching Condition +@context_bar;noquote@ + + + + Index: openacs-4/contrib/packages/survey/www/admin/condition-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/condition-add.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/condition-add.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,46 @@ +ad_page_contract { + Present form to add a condition to an existing branch +} { + section_id:integer,notnull +} + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] +ad_require_permission $package_id admin + +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 Section"] + +db_1row branch_info "" + +set condition_id [db_nextval survey_condition_id_sequence] + +set options [list] +db_foreach questions "" { + if {$abstract_data_type == "boolean"} { + set choices [list [list "t" Yes] [list "f" No]] + } else { + set choices [db_list_of_lists choices ""] + } + set question "$question_text: " + foreach choice $choices { + set choice_id [lindex $choice 0] + set choicelabel [lindex $choice 1] + lappend options [list "${question}$choicelabel" "${question_id}:${choice_id}"] + } +} + +if {[empty_string_p $options]} { + ad_return_complaint 1 "No appropriate questions found" + ad_script_abort +} + +ad_form -name add_condition -action condition-add-2 -form { + {condition_id:text(hidden) {value $condition_id}} + {branch_id:text(hidden) {value $branch_id}} + {section_id:text(hidden) {value $section_id}} + {choice:text(radio) {label "Which choice should lead to this branch?"} {options $options}} +} + + Index: openacs-4/contrib/packages/survey/www/admin/condition-add.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/condition-add.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/condition-add.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,31 @@ + + + + + + + select branch_id,after from survey_branches where section_id=:section_id + + + + + + select question_id, question_text, abstract_data_type + from survey_questions q, survey_sections s + where s.survey_id=:survey_id + and sort_key<=(select sort_key from survey_sections where + section_id=:after) and + q.section_id=s.section_id and + abstract_data_type in ('boolean','choice') and + presentation_type in ('select', 'radio', 'checkbox') + + + + + + select choice_id,label from survey_question_choices where + question_id=:question_id order by sort_order + + + + Index: openacs-4/contrib/packages/survey/www/admin/description-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/description-edit.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/description-edit.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,7 @@ + +@survey_id@ + +@survey_name;noquote@: Edit Description +@context_bar;noquote@ + + Index: openacs-4/contrib/packages/survey/www/admin/description-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/description-edit.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/description-edit.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,56 @@ +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 2003/09/19 16:48:04 rmello Exp $ +} { + + survey_id:integer + +} + +ad_require_permission $survey_id admin +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]" + ad_script_abort +} + +set context_bar [ad_context_bar [list "one?[export_url_vars survey_id]" $survey_info(name)] "Edit Description"] + +ad_return_template Index: openacs-4/contrib/packages/survey/www/admin/description-edit.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/description-edit.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/description-edit.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,13 @@ + + + + + + update surveys + set description = :description, + description_html_p = :description_html_p + where survey_id = :survey_id + + + + Index: openacs-4/contrib/packages/survey/www/admin/import-responses-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/import-responses-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/import-responses-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,36 @@ + + + + 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, + creation_ip => :creation_ip + ); + end; + + + + + + + + insert into survey_question_responses + (response_id, question_id, clob_answer) + values + (:response_id, :question_id, empty_clob()) + returning clob_answer into :1 + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/import-responses-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/import-responses-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/import-responses-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,30 @@ + + + + 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, :response_value) + + + + Index: openacs-4/contrib/packages/survey/www/admin/import-responses.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/import-responses.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/import-responses.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,7 @@ + +@survey_id@ + +@survey_name;noquote@: Import responses +@context_bar;noquote@ + + Index: openacs-4/contrib/packages/survey/www/admin/import-responses.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/import-responses.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/import-responses.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,242 @@ +ad_page_contract { + + This page allows the admin to bulk upload responses to a survey + + @param survey_id integer denoting survey we're administering + @param csvfile uploaded csv-file, whose fields will be + interpreted as replies to the survey + + @author koljalehmann@uni.de + @date September 3rd, 2003 + @cvs-id $Id: import-responses.tcl,v 1.1 2003/09/19 16:48:04 rmello Exp $ +} { + survey_id:integer + {csvfile:array,optional} + {filename ""} +} -validate { + file_given { + if {![info exists csvfile(tmpfile)] && $filename==""} { + ad_complain "No file given for import!" + } + } +} + +set package_id [ad_conn package_id] + +ad_require_permission $package_id admin + +# Get the survey information. +get_survey_info -survey_id $survey_id +if {![info exists survey_info(survey_id)]} { + ad_return_complaint 1 "Requested survey does not exist" + ad_script_abort +} +set survey_name $survey_info(name) +set context_bar [ad_context_bar [list "one?[export_url_vars survey_id]" $survey_info(name)] "Import responses"] + +if {[info exists csvfile(tmpfile)]} { + # preserve the file for future use + set filename [ns_tmpnam] + file rename $csvfile(tmpfile) $filename +} + +# First, create a list of all fields in the csv +set file [open $filename r] +set numfields [ns_getcsv $file fields] + +set fieldlist [list [list "-- Please Choose --" ""]] +set i 0 +foreach field $fields { + lappend fieldlist [list $field $i] + incr i +} + +ad_form -name pick-fields -form { + {survey_id:text(hidden) {value $survey_id}} + {filename:text(hidden) {value $filename}} + {identifier:text(select) {label "Identify user by"} {options {{UserID user_id} {Email email}}}} + {idfield:text(select) {label "Identifying field"} {options $fieldlist} {required_p "t"}} +} + +set question_ids [list] +set section "" +db_foreach get_questions {} { + if {$section_desc != $section} { + template::form::section pick-fields $section_desc + set section $section_desc + } + template::element create pick-fields question$question_id \ + -widget select \ + -label $question_text \ + -options $fieldlist \ + -required_p $required_p + lappend question_ids $question_id + set question($question_id.datatype) $abstract_data_type + set question($question_id.required_p) $required_p + set question($question_id.question_text) $question_text + if {$abstract_data_type=="choice"} { + # get the possible choices + db_foreach get_choices "" { + set question($question_id.choices.$label) $choice_id + } + } +} + +ad_form -extend -name pick-fields -form { + {test:text(submit) {label "Test"}} + {import:text(submit) {label "Import"}} +} -on_submit { + # Now, get the data ready to insert into the db + if {[info exists import] && $import=="Import"} { + set mode "import" + } + if {[info exists test] && $test=="Test"} { + set mode "test" + } + + # First, get the user id, the response belongs to + set debug "" + set errors "" + set line 0 + while {[ns_getcsv $file data]!=-1} { + set error 0 + incr line + db_transaction { + if {$identifier=="user_id"} { + set user_id [lindex $data $idfield] + if {[db_0or1row user_exists ""]==0} { + # no user for this user_id + set error 1 + } + } else { + set email [lindex $data $idfield] + if {![db_0or1row get_user_id ""]} { + # no user for this email + set error 1 + } + } + if {$error} { + # user does not exist + lappend errors "Line $line: User with $identifier \"[lindex $data $idfield]\" does not exist" + db_abort_transaction + } + append debug "$user_id:" + + # Now, get a response_id + # If it is a "single_response" survey, overwrite if necessary +ns_log notice 1 + if {[db_0or1row get_response_id ""]} { + set overwrite 1 + # delete old response + db_dml delete_old_response "" + } else { + # No response_id to overwrite + set response_id [db_nextval acs_object_id_seq] + set overwrite 0 + # create the response + set creation_ip [ad_conn peeraddr] + set initial_response_id $response_id + db_exec_plsql create_response {} + } +ns_log notice 2 + + # Now, get the question responses ready + foreach question_id $question_ids { + set response_value [lindex $data [set question$question_id]] + if {[empty_string_p $response_value]} { + # there is an empty value + # If question is not required, no problem, just skip it + # else, note an error + if {$question($question_id.required_p)=="t"} { + set error 1 + lappend errors "Line $line: Answer to question $question($question_id.question_text) cannot be empty" + } + continue + } + switch $question($question_id.datatype) { + choice { + foreach choice [split $response_value ","] { + if {[info exists question($question_id.choices.$choice)]} { + set choice_id $question($question_id.choices.$choice) + db_dml create_choice_response "" + } else { + set error 1 + lappend errors "Line $line: Choice \"$choice\" does not exist in question $question($question_id.question_text)" + } + } + } + shorttext { + set varchar_answer $response_value + db_dml create_varchar_response "" + } + boolean { + switch $response_value { + "Yes" - + "True" { + set boolean_answer "t" + db_dml create_boolean_response "" + } + "No" - + "False" { + set boolean_answer "f" + db_dml create_boolean_response "" + } + default { + set error 1 + lappend errors "Line $line: Invalid boolean value \"$response_value\" for question $question($question_id.question_text)" + } + } + } + integer - + number { + if {[ad_var_type_check_number_p $response_value]} { + set number_answer $response_value + db_dml create_number_response "" + } else { + set error 1 + lappend errors "Line $line: Invalid Number \"$response_value\" for question $question($question_id.question_text)" + } + } + text { + db_dml create_clob_response {} -clobs [list $response_value] + } + date { + if [regexp {(.*)-(.*)-(.*)$} $response_value match year month day] { + set date_answer $response_value + db_dml create_date_response "" + } else { + set error 1 + lappend errors "Line $line: Invalid Date \"$response_value\" for question $question($question_id.question_text)" + } + } + blob { + # Just do nothing + } + } + + } + if {$error||$mode=="test"} { + db_abort_transaction + } + } on_error { + # There needs to be an on_error block + if [exists_and_not_null errmsg] { + ns_returnnotice 200 "$errmsg :: $line" + } + } + + } + if {[llength $errors]==0} { + # No errors + if {$mode=="test"} { + ns_returnnotice 200 "Test successful" "There were no problems with the import. $line records can be created. Go back and hit Import to proceed" + } else { + ns_returnnotice 200 "Import successful" "There were no problems with the import. $line records have been created. Return to the survey" + } + } else { + # There were errors + ns_returnnotice 200 "Errors encountered" "There were some errors:
    • [join $errors "
    • "]
    " + } +} +close $file + Index: openacs-4/contrib/packages/survey/www/admin/import-responses.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/import-responses.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/import-responses.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,88 @@ + + + + + + select question_id, question_text, s.name as section_desc, + required_p, abstract_data_type + from survey_questions q, survey_sections s where + s.survey_id=:survey_id and s.section_id=q.section_id + order by s.sort_key, q.sort_order + + + + + + select label,choice_id from survey_question_choices where question_id=:question_id + + + + + + select user_id from cc_users where email=:email + + + + + + select 1 from users where user_id=:user_id + + + + + + select response_id from survey_responses_latest r, surveys s + where r.survey_id=s.survey_id and s.single_response_p='t' and + r.creation_user=:user_id and s.survey_id=:survey_id + + + + + + delete from survey_question_responses where response_id=:response_id + + + + + + insert into survey_question_responses(response_id, question_id, + choice_id) values (:response_id, :question_id, :choice_id) + + + + + + insert into survey_question_responses(response_id, question_id, + varchar_answer) values (:response_id, :question_id, :varchar_answer) + + + + + + insert into survey_question_responses(response_id, question_id, + date_answer) values (:response_id, :question_id, :date_answer) + + + + + + insert into survey_question_responses(response_id, question_id, + clob_answer) values (:response_id, :question_id, :clob_answer) + + + + + + insert into survey_question_responses(response_id, question_id, + boolean_answer) values (:response_id, :question_id, :boolean_answer) + + + + + + insert into survey_question_responses(response_id, question_id, + number_answer) values (:response_id, :question_id, :number_answer) + + + + Index: openacs-4/contrib/packages/survey/www/admin/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/index.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/index.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,24 @@ + + +Survey Administration +@context_bar;noquote@ +1 + + +

    + +New Survey + +

    + Manage predefined questions + Index: openacs-4/contrib/packages/survey/www/admin/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/index.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/index.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,29 @@ +# /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 2003/09/19 16:48:04 rmello 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 admin + +if {[ad_permission_p [acs_magic_object "security_context_root"] "admin"]} { + set predefined_question_link "predefined-question-admin" +} + + +set disabled_header_written_p 0 + +db_multirow surveys select_surveys {} +ad_return_template Index: openacs-4/contrib/packages/survey/www/admin/index.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/index.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/index.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/master.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/master.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/master.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,14 @@ + + + + @context_bar;noquote@ + + + + @title;noquote@ + + +Main Survey Administration | Admin This Survey + +

    + Index: openacs-4/contrib/packages/survey/www/admin/modify-responses-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/modify-responses-2.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/modify-responses-2.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,46 @@ +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 2003/09/19 16:48:04 rmello 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 admin + +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 {} + + foreach variable_id $variable_id_list { + set score_list $scores($variable_id) + set score [lindex $score_list $i] + db_dml update_survey_scores {} + } + + 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/contrib/packages/survey/www/admin/modify-responses-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/modify-responses-2.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/modify-responses-2.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/modify-responses.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/modify-responses.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/modify-responses.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,78 @@ +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 2003/09/19 16:48:04 rmello Exp $ +} { + + question_id:integer + section_id:integer + +} + +ad_require_permission $section_id admin + +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) + +set survey_name [db_string survey_name_from_id {} ] + +set question_text [db_string survey_question_text_from_id {} ] + +set table_html " +" + +set variable_id_list [list] + +db_foreach get_variable_names {} { + + lappend variable_id_list $variable_id + append table_html "" + } + +append table_html "\n" + +set choice_id_list [list] + +db_foreach get_choices {} { + lappend choice_id_list $choice_id + append table_html "" + + db_foreach get_scores {} { + + 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/contrib/packages/survey/www/admin/modify-responses.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/modify-responses.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/modify-responses.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/name-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/name-edit.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/name-edit.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,8 @@ + +@survey_id@ + +@survey_name;noquote@: Edit Name +@context_bar;noquote@ + +Edit and submit to change the name for this survey: + Index: openacs-4/contrib/packages/survey/www/admin/name-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/name-edit.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/name-edit.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,51 @@ +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 2003/09/19 16:48:04 rmello Exp $ +} { + + survey_id:integer + {name ""} +} + +get_survey_info -survey_id $survey_id +set survey_name_unquoted $survey_info(name_unquoted) +set survey_name $survey_info(name) +set survey_description $survey_info(description_unquoted) +set html_p $survey_info(description_html_p) + +ad_require_permission $survey_id admin + +ad_form -name edit-name -form { + survey_id:key + {name:text(text) {label "Survey Name"} {html {size 80}} + {value $survey_name_unquoted}} + {description:text(textarea) {label "Description"} + {html {rows 10 cols 65}} + {value $survey_description}} + {description_html_p:text(radio) {label "The Above Description is"} + {options {{"HTML" "t"} {"Plain Text" "f"}}} {value $html_p} + } +} -validate { + {name {[string length $name] <= 4000} + "Survey Name must be less than 4000 characters" + } +} -edit_request { + set name $survey_name_unquoted +} -edit_data { + db_dml survey_update "" + ad_returnredirect "one?[export_vars survey_id]" + ad_script_abort +} + +set context_bar [ad_context_bar "Edit Name"] + +ad_return_template + + Index: openacs-4/contrib/packages/survey/www/admin/name-edit.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/name-edit.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/name-edit.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,12 @@ + + + + +update surveys +set name= :name, + description= :description, + description_html_p=:description_html_p +where survey_id = :survey_id + + + Index: openacs-4/contrib/packages/survey/www/admin/no-responses.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/no-responses.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/no-responses.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,8 @@ + +@survey_id@ +No Responses for: @survey_name;noquote@ +@context_bar;noquote@ + +

    No Responses for @survey_name;noquote@

    + +Return to survey administration Index: openacs-4/contrib/packages/survey/www/admin/one-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/one-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/one-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,16 @@ + + + + oracle8.1.6 + + + +select s.name as name, question_id, question_text, presentation_type, sort_order, active_p, required_p, + s.section_id as section_id, branch_p + from survey_questions q, survey_sections s + where survey_id=:survey_id and q.section_id(+)=s.section_id + order by s.sort_key,s.section_id, sort_order + + + + Index: openacs-4/contrib/packages/survey/www/admin/one-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/one-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/one-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,19 @@ + + + + postgresql7.1 + + + + select s.name as name, question_id, question_text, presentation_type, sort_order, active_p, required_p, + s.section_id as section_id, branch_p + from survey_questions q right outer join survey_sections s + on (q.section_id = s.section_id) + where survey_id=:survey_id + order by s.sort_key,s.section_id, sort_order + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/one-respondent-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/one-respondent-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/one-respondent-oracle.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/one-respondent-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/one-respondent-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/one-respondent-postgresql.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/one-respondent.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/one-respondent.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/one-respondent.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,35 @@ + + +@survey_id@ +@survey_info.name;noquote@ +One Respondent: @first_names;noquote@ @last_name;noquote@ +@context_bar;noquote@ + + + + + + + + + + + +
    + Here is what @first_names@ @last_name@ had to say in response to @survey_name;noquote@: +
    + + + + Delete + + + [ + Original + Edited + Response on @responses.creation_date@] +
    + @responses.response_display;noquote@ +
    +

    + Index: openacs-4/contrib/packages/survey/www/admin/one-respondent.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/one-respondent.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/one-respondent.tcl 19 Sep 2003 16:48:04 -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 2003/09/19 16:48:04 rmello Exp $ +} { + + user_id:integer + survey_id:integer + +} + +ad_require_permission $survey_id admin + +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 "" ] + +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 Index: openacs-4/contrib/packages/survey/www/admin/one-respondent.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/one-respondent.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/one-respondent.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,12 @@ + + + + + + select first_names, last_name from persons where person_id = :user_id + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/one.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/one.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/one.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,230 @@ + +@survey_id;noquote@ + +One Survey: @survey_info.name;noquote@ +@context_bar;noquote@ + +

    Main Survey Administration

    + +@survey_info.name;noquote@ - Created by @survey_info.creator_name@, on @creation_date@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <% # removed Display types, we use styles now + # + # + # + # + %> + + + + + + + + + + + + + + + + + + + + + + + +
    This survey is + @survey_info.enabled_display@ + @survey_info.enabled_display@ + . - @toggle_enabled_text@ +
    Survey Name:

    + Description:

    + + Preview + + + Edit + + @survey_info.name;noquote@

    + @survey_info.description;noquote@ +

    View Responses: + By user | + Summary | + CSV file (with anonymous answers) | + CSV file (without anonymous answers) +
    Import Responses: + + Import responses from a .csv file + + +
    Sectioning: + + Survey is not sectioned - [ Make sectioned ] + + + Survey is sectioned - [ Compress to single section ] + +
    Status Bar: + [ + No Status Bar + No Status Bar + | + Blue + Blue + | + Red + Red + | + Green + Green + | + Yellow + Yellow + ] +
    + Style + + +
    + Response Options: + @survey_info.single_response_display@ - [ + @response_limit_toggle@ ] +
    + Users may edit their responses + Users may not edit their responses - [ + make + non- + editable + ] +
    Display Options: @survey_info.display_type@ - + # + # + # [@survey_display_types:item@] + # + # + #
    Accessibility: + Public + Not public - [Toggle] +
    Email Options:@notification_chunk;noquote@
    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. +
    + +
    + + + + @sections.name@ + EditDelete + @sections.branch_text;noquote@ + +
      Questions + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    add new question
    @sections.rownum@. Edit +[inactive] +Copy +Add New +Move Down +Move UpDelete
    +
    @sections.question_text;noquote@ + + +@formgroup.widget;noquote@ @formgroup.label;noquote@ + + + + + +
    +
    No Questions
    add new question
    +
    +
    +add new section + Index: openacs-4/contrib/packages/survey/www/admin/one.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/one.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/one.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,117 @@ +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 2003/09/19 16:48:04 rmello Exp $ +} { + + survey_id:integer + {section_id:integer ""} +} + +set package_id [ad_conn package_id] + +ad_require_permission $package_id admin + +# Get the survey information. +get_survey_info -survey_id $survey_id +if {![info exists survey_info(survey_id)]} { + ad_return_complaint 1 "Requested survey does not exist" + ad_script_abort +} +# get users and # who responded etc... +if {[apm_package_installed_p dotlrn]} { + set community_id [dotlrn_community::get_community_id_from_url] + set n_eligible [db_string n_eligible {}] +} +set return_html "" + +set creation_date [util_AnsiDatetoPrettyDate $survey_info(creation_date)] +set public_p $survey_info(public_p) +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)] + +# form for response upload +ad_form -name import_responses -action import-responses -html {enctype multipart/form-data} -form { + {survey_id:text(hidden) {value $survey_id}} + {csvfile:file {label File}} +} + +# form for selection of style +set styles [db_list_of_lists styles ""] +set style [db_string get_style ""] +ad_form -name style_select -action style-select -form { + {survey_id:text(hidden) {value $survey_id}} + {style:integer(select) {label Style} {options $styles} {value $style}} +} + +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_form -name admin_survey -form { + {survey_id:text(hidden) {value $survey_id}} +} + +set last_section_id "" +db_multirow -extend {question_display branch_text} sections survey_questions "" { + if {$section_id != $last_section_id} { + get_section_info -section_id $section_id + template::form::section admin_survey $section_info(name) + if {$branch_p == "t"} { + if {[db_0or1row branchquestion ""]} { + if {$abstract_data_type == "boolean"} { + set bchoice [ad_decode $boolean_answer "t" "Yes" "No"] + } else { + db_1row branchchoice "" + } + set branch_text "Branch is displayed, if answer to \"$bquestion\" is \"$bchoice\" (Change)" + } else { + set branch_text "No condition defined. Add one" + } + } else { + set branch_text "" + } + } + if {![empty_string_p $question_id]} { + survey_question_add_to_form admin_survey $question_id + } +} + + +ad_return_template Index: openacs-4/contrib/packages/survey/www/admin/one.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/one.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/one.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,44 @@ + + + + + + select count(*) from dotlrn_member_rels_full + where rel_type='dotlrn_member_rel' + and community_id=:community_id + + + + + + select description,template_id from survey_templates + + + + + + select template from surveys + where survey_id=:survey_id + + + + + + + + select question_text as bquestion, abstract_data_type, boolean_answer from survey_branches b, survey_conditions c, survey_questions q + where q.question_id=c.question_id and c.condition_id=b.condition + and b.section_id=:section_id + + + + + + select label as bchoice from survey_branches b, survey_conditions c, survey_question_choices qc + where qc.choice_id=c.choice_id and c.condition_id=b.condition + and b.section_id=:section_id + + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-2-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-2-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-2-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,49 @@ + + + + oracle8.1.6 + + + + select decode(count(*),0,0,1) from survey_questions where question_id = :question_id + + + + + + declare + v integer; + begin + v := 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, + question_html_p => :question_html_p, + summary_type => :summary_type, + answer_description => :answer_description, + predefined_question_id => :predefined_question_id + ); + end; + + + + + + +select question_id from survey_questions +where question_id = :question_id +for update of question_text + + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-2-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-2-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-2-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,48 @@ + + + + postgresql7.1 + + + + select + case when count(*)=0 then '0' + else '1' + end + from survey_questions where question_id = :question_id + + + + + + + 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, + :question_html_p, + :summary_type, + :answer_description, + :predefined_question_id, + :user_id, + :section_id + ) + + + + + +select question_id from survey_questions +where question_id = :question_id +for update + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-2.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-2.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,105 @@ +# /www/survsimp/admin/question-add-3.tcl +ad_page_contract { + Inserts a new question into the database based on a predefined question. + + @param question_id id of new question + @param section_id integer determining survey we're dealing with + @param after optional integer determining position of this question + @param predefined_question_id id of the predefined question to copy + @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 Kolja Lehmann + @cvs-id $Id: predefined-question-2.tcl,v 1.1 2003/09/19 16:48:04 rmello Exp $ +} { + predefined_question_id:integer,notnull + section_id:integer,notnull + question_id:integer,notnull + after:integer,optional + {required_p t} + {active_p t} + {question_text ""} +} + +# Variables that will be used later... +set question_html_p "f" +set summary_type [db_null] +set answer_description [db_null] +### + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] +ad_require_permission $package_id admin +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) +get_section_info -section_id $section_id + +if {![info exists survey_info(survey_id)]} { + ad_return_complaint 1 "Requested survey does not exist" + ad_script_abort +} + +set survey_id $survey_info(survey_id) +set exception_count 0 +set exception_text "" + +if { $exception_count > 0 } { + ad_return_complaint $exception_count $exception_text + ad_script_abort +} + +set already_inserted_p [db_string already_inserted_p {}] + +if { $already_inserted_p } { + ad_returnredirect "one?[export_vars survey_id]" + ad_script_abort +} + + set new_question_text $question_text + db_1row get_predefinition "" + if {![empty_string_p $new_question_text]} { + set question_text $new_question_text + } + + 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 {} +# ns_returnnotice 200 test + #db_0or1row prepare_add_question_text {} + db_dml add_question_text {} + + + # For questions where the user is selecting a canned response, insert + # the canned responses into survey_question_choices by using the predefined + # choices + + if { $presentation_type == "checkbox" || $presentation_type == "radio" || $presentation_type == "select" } { + if { $abstract_data_type == "choice" } { + set new_choice [db_nextval survey_choice_id_sequence] + db_dml add_new_choices "" + } + } +} on_error { + db_release_unused_handles + ad_return_error "Database Error" "
    $errmsg
    " + ad_script_abort + +} + + +db_release_unused_handles +ad_returnredirect "one?survey_id=$survey_id&#${sort_order}" + + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-2.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-2.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,81 @@ + + + + + + select * from survey_predefined_questions where predefined_question_id=:predefined_question_id + + + + + + update survey_questions + set sort_order = sort_order + 1 + where section_id = :section_id + and sort_order > :after + + + + + + select max(sort_order) from survey_questions + where section_id=:section_id + + + + + + + update survey_questions + set question_text = :question_text + where question_id = :question_id + + + + + + + + insert into + survey_question_choices(choice_id,predef_choice_id,question_id,label,numeric_value,sort_order,presentation_alignment,more_info_type) + (select + :new_choice,choice_id,:question_id,label,numeric_value,sort_order,presentation_alignment,more_info_type + from survey_predef_question_choices where question_id=:predefined_question_id) + + + + + + + + + + + select distinct survey_question_all_choices(question_id) as + all_choices from + survey_questions where section_id=:section_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) + + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-admin.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-admin.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-admin.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,14 @@ + + +Survey Administration +@context_bar;noquote@ +1 + + +Create a New + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-admin.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-admin.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-admin.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,23 @@ +ad_page_contract { + List predefined questions and allows editing + + @author koljalehmann@uni.de + @date June 13, 2003 + @cvs-id $Id: predefined-question-admin.tcl,v 1.1 2003/09/19 16:48:04 rmello Exp $ +} { + +} + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] +set context_bar [ad_context_bar "Predefined Questions"] +# require sitewide admin +ad_require_permission [acs_magic_object "security_context_root"] "admin" + +db_multirow predefined_questions get_predefined_questions "" + +ad_return_template + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-admin.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-admin.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-admin.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,11 @@ + + + + + + select question_text,predefined_question_id from survey_predefined_questions + + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-ae-2-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,30 @@ + + + + oracle8.1.6 + + + +declare v integer; +begin + v:=survey_predefined_question.new( + predefined_question_id => :predefined_question_id, + question_text =>empty_clob(), + question_html_p =>:question_html_p, + abstract_data_type =>:abstract_data_type, + presentation_type => :presentation_type, + presentation_options => :presentation_options, + presentation_alignment => :presentation_alignment, + summary_type => null, + action_type => :action_type, + table_name => :table_name, + column_name => :column_name, + key_name => :key_name, + creation_user => :user_id, + context_id => :package_id + ); +end; + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-ae-2-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,27 @@ + + + + postgresql7.1 + + + + select survey_predefined_question__new( + :predefined_question_id, + :question_text, + :abstract_data_type, + :presentation_type, + :presentation_options, + :presentation_alignment, + :question_html_p, + NULL, + :action_type, + NULL, + :table_name, + :column_name, + :key_name, + :user_id, + null); + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-ae-2.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,9 @@ + + +Survey Administration +@context_bar;noquote@ +1 + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-ae-2.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,182 @@ +ad_page_contract { + List predefined questions and allows editing + + @author koljalehmann@uni.de + @date June 13, 2003 + @cvs-id $Id: predefined-question-ae-2.tcl,v 1.1 2003/09/19 16:48:04 rmello Exp $ +} { + predefined_question_id:optional + question_text + question_html_p:boolean + presentation_type +} + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] +set context_bar [ad_context_bar "Predefined Questions"] +# require sitewide admin +ad_require_permission [acs_magic_object "security_context_root"] "admin" + +ad_form -name predef -form { + predefined_question_id:key + {question_text:text(hidden) {value $question_text}} + {question_html_p:text(hidden) {value $question_html_p}} + {presentation_type:text(hidden) {value $presentation_type}} + {question_text_inform:text(inform) {label "Question"} {html {rows 5 cols 70}} {value $question_text}} +} -select_query { + select * from survey_predefined_questions where predefined_question_id=:predefined_question_id +} + +if {[info exist predefined_question_id]} { + # get choices + set valid_responses "" + set valid_responses_list [db_list survey_question_valid_responses {}] + set response_list "" + foreach response $valid_responses_list { + append valid_responses "$response\n" + } +} else { + set valid_responses "" +} + + +switch $presentation_type { + textbox { + ad_form -extend -name predef -form { + {presentation:text(inform) {label "Presentation Type"} {value "One Line Answer"}} + {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}}} + } + } -select_query { + select * from survey_predefined_questions where predefined_question_id=:predefined_question_id +} + } + textarea { + ad_form -extend -name predef -form { + {presentation:text(inform) {label "Presentation Type"} {value "Essay Answer"}} + {textarea_size:text(select) {options {{Small small} {Medium medium} {Large large}}} {label "Size"}} + {abstract_data_type:text(hidden) {value "text"}} + } -select_query { + select * from survey_predefined_questions where predefined_question_id=:predefined_question_id + } + } + "radio" - + "select" { + ad_form -extend -name predef -form { + {presentation:text(inform) {label "Presentation Type"} {value "Multiple Choice"}} + {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}} {value $valid_responses}} + } -select_query { + select * from survey_predefined_questions where predefined_question_id=:predefined_question_id + } -validate { + {valid_responses {$abstract_data_type!="choice" || ![empty_string_p $valid_responses]} "You did not enter a set of valid responses"} + } + + } + "checkbox" { + ad_form -extend -name predef -form { + {presentation:text(inform) {label "Presentation Type"} {value "Multiple Choice"}} + {valid_responses:text(textarea) {label "Valid Resposnes (enter one choice per line)"} {html {rows 10 cols 50}}} + {abstract_data_type:text(hidden) {value "choice"}} + } -select_query { + select * from survey_predefined_questions where predefined_question_id=:predefined_question_id + } -validate { + {valid_responses {$abstract_data_type!="choice" || ![empty_string_p $valid_responses]} "You did not enter a set of valid responses"} + } + } + "date" { + ad_form -extend -name predef -form { + {presentation:text(inform) {label "Presentation Type"} {value "Date Answer"}} + {abstract_data_type:text(hidden) {value date}} + } -select_query { + select * from survey_predefined_questions where predefined_question_id=:predefined_question_id + } + } + "upload_file" { + ad_form -extend -name predef -form { + {presentation:text(inform) {label "Presentation Type"} {value "Attachment Answer"}} + {abstract_data_type:text(hidden) {value blob}} + } -select_query { + select * from survey_predefined_questions where predefined_question_id=:predefined_question_id + } + } +} + +ad_form -extend -name predef -form { +# {presentation_alignment:text(radio) {options {{"Beside the question" beside} {"Below the question" below}}} {value below} {label "Presentation Alignment"}} + {presentation_alignment:text(hidden) {value beside}} + {action_type:text(radio) {label "Action on submit"} {options {{"Update DB" db} {"Execute TCL-Code" tcl} {"Nothing" "null"}}} {value "null"}} + {tcl:text(textarea),optional {label "TCL-Code"}} + {table_name:text(text),optional {label "Table"}} + {column_name:text(text),optional {label "Column"}} + {key_name:text(text),optional {label "Key Column"}} +} -select_query { + select * from survey_predefined_questions where predefined_question_id=:predefined_question_id +} -validate { + {tcl {$action_type=="tcl" || [empty_string_p $tcl]} "Please select \"Execute TCL-Code\" if you want to enter code"} + {tcl {![empty_string_p $tcl] || $action_type!="tcl"} "Please enter TCL-Code"} + {table_name {$action_type=="db" || [empty_string_p $table_name]} "Please select \"Update DB\" if you want to insert values into the Database"} + {table_name {![empty_string_p $table_name] || $action_type!="db"} "Please enter a table name"} + {column_name {![empty_string_p $column_name] || $action_type!="db"} "Please enter a column name"} + {column_name {$action_type=="db" || [empty_string_p $column_name]} "Please select \"Update DB\" if you want to insert values into the Database"} + {key_name {$action_type=="db" || [empty_string_p $key_name]} "Please select \"Update DB\" if you want to insert values into the Database"} + {key_name {![empty_string_p $key_name] || $action_type!="db"} "Please enter a key name"} +} -on_submit { + if {$action_type=="null"} { + set action_type [db_null] + } + # 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" + } +} -new_data { + db_transaction { + db_exec_plsql new_predefined_question "" + db_dml update_question_text "" + 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_nextval survey_choice_id_sequence] db_dml insert_survey_question_choice "" + incr count + } + } + } + } +} -edit_data { + db_dml edit_predefined_question "" +} -after_submit { + ad_returnredirect predefined-question-admin + ad_script_abort +} + +ad_return_template + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-ae-2.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-ae-2.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,35 @@ + + + + + + select label from survey_predef_question_choices where question_id=:predefined_question_id + + + + + + update survey_predefined_questions set + question_text=:question_text where predefined_question_id=:predefined_question_id + + + + + + + insert into survey_predef_question_choices (choice_id, question_id, label, sort_order) + values (:choice_id, :predefined_question_id, :trimmed_response, :count) + + + + + + update survey_predefined_questions set + question_text=:question_text,question_html_p=:question_html_p,abstract_data_type=:abstract_data_type,presentation_type=:presentation_type,presentation_options=:presentation_options,presentation_alignment=:presentation_alignment,action_type=:action_type,table_name=:table_name,column_name=:column_name,key_name=:key_name + where predefined_question_id=:predefined_question_id + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-ae.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-ae.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-ae.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,9 @@ + + +Survey Administration +@context_bar;noquote@ +1 + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question-ae.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question-ae.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question-ae.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,47 @@ +ad_page_contract { + List predefined questions and allows editing + + @author koljalehmann@uni.de + @date June 13, 2003 + @cvs-id $Id: predefined-question-ae.tcl,v 1.1 2003/09/19 16:48:04 rmello Exp $ +} { + predefined_question_id:optional +} + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] +set context_bar [ad_context_bar "Predefined Questions"] +# require sitewide admin +ad_require_permission [acs_magic_object "security_context_root"] "admin" + +ad_form -name predef -form { + predefined_question_id:key + {question_text:text(textarea) {label "Question"} {html {rows 5 cols 70}}} + {question_html_p:text(radio) {label "HTML?"} {options {{"Yes" t} {"No" f}}} {value f}} + {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" } } } } +} -select_query { + select * from survey_predefined_questions where predefined_question_id=:predefined_question_id +} -after_submit { + if {$__new_p==1} { + # new entry, so don't transmit the id + ad_returnredirect predefined-question-ae-2?[export_url_vars question_html_p presentation_type question_text] + } else { + ad_returnredirect predefined-question-ae-2?[export_url_vars predefined_question_id question_html_p presentation_type question_text] + } + ad_script_abort +} + + +ad_return_template + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,9 @@ + +@survey_id@ + +@survey_info.name;noquote@: New Question +@context_bar;noquote@ + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,60 @@ +ad_page_contract { + Present form to begin adding a predefined question to a survey. + + @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: predefined-question.tcl,v 1.1 2003/09/19 16:48:04 rmello 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 admin + +get_survey_info -section_id $section_id +get_section_info -section_id $section_id + +if {$section_info(block_section_p)=="t"} { + ad_returnredirect "block-question-add?[export_url_vars section_id after]" + ad_script_abort +} + +set predefs [db_list_of_lists predefined_questions ""] + +set next_question_id [db_nextval acs_object_id_seq] + +ad_form -name create_question -action predefined-question-2 -export { after } -form { + {question_id:text(hidden) {value $next_question_id}} + {section_id:text(hidden) {value $section_id}} + {predefined_question_id:integer(select) {label "Question"} {options $predefs}} + {question_text:text(textarea) {label "Question (leave empty to keep original)"} {html {rows 5 cols 70}}} +} + +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_p:text(radio) {label "Required?"} {options {{Yes t} {No f}}} {value t}} +} + +ad_return_template + + + + Index: openacs-4/contrib/packages/survey/www/admin/predefined-question.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/predefined-question.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/predefined-question.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,11 @@ + + + + + + select question_text,predefined_question_id from survey_predefined_questions + + + + + Index: openacs-4/contrib/packages/survey/www/admin/public-toggle-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/public-toggle-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/public-toggle-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,14 @@ + + + oracle8.1.6 + + + + update surveys +set public_p = util.logical_negation(public_p) +where survey_id = :survey_id + + + + + Index: openacs-4/contrib/packages/survey/www/admin/public-toggle-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/public-toggle-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/public-toggle-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,14 @@ + + + postgresql7.1 + + + + update surveys +set public_p = util__logical_negation(public_p) +where survey_id = :survey_id + + + + + Index: openacs-4/contrib/packages/survey/www/admin/public-toggle.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/public-toggle.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/public-toggle.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,33 @@ +# /packages/survey/www/admin/public-toggle.tcl +ad_page_contract { + + Toggles a survey between public and non-public + + @param section_id survey whose properties we're changing + + @cvs-id + +} { + + survey_id:integer + +} + +ad_require_permission $survey_id admin + +db_transaction { + db_dml survey_public_toggle "" + set public_id [acs_magic_object "the_public"] + db_1row survey_public_p "" + if {$public_p == "t"} { + # switch to public_p + permission::grant -party_id $public_id -object_id $survey_id -privilege write + } else { + # switch to not public_p + permission::revoke -party_id $public_id -object_id $survey_id -privilege write + } +} + +db_release_unused_handles + +ad_returnredirect "one?[export_url_vars survey_id]" Index: openacs-4/contrib/packages/survey/www/admin/public-toggle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/public-toggle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/public-toggle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,16 @@ + + + + + + select object_id from acs_magic_objects where name='the_public' + + + + + + select public_p from surveys where survey_id = :survey_id + + + + Index: openacs-4/contrib/packages/survey/www/admin/question-active-toggle-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-active-toggle-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-active-toggle-oracle.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/question-active-toggle-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-active-toggle-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-active-toggle-postgresql.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/question-active-toggle.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-active-toggle.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-active-toggle.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,25 @@ +# /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 admin + +db_dml survey_question_required_toggle "" + +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/contrib/packages/survey/www/admin/question-add-2.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-add-2.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-add-2.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,8 @@ + +@survey_id@ + +Survey Administration: Add a Question (cont.) +@context_bar;noquote@ + + + Index: openacs-4/contrib/packages/survey/www/admin/question-add-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-add-2.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-add-2.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,186 @@ +# /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 2003/09/19 16:48:04 rmello 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 admin + +set question_id [db_nextval acs_object_id_seq] +get_survey_info -section_id $section_id + +if {![info exists survey_info(survey_id)]} { + ad_return_complaint 1 "Requested survey does not exist" + ad_script_abort +} + +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} {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"}} + {presentation_alignment:text(hidden) {value beside}} +} + + +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/contrib/packages/survey/www/admin/question-add-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-add-2.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-add-2.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/question-add-3-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-add-3-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-add-3-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,40 @@ + + + + oracle8.1.6 + + + + select decode(count(*),0,0,1) from survey_questions where question_id = :question_id + + + + + + + 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, + question_html_p => :question_html_p, + summary_type => :summary_type, + answer_description => :answer_description + ); + end; + + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/question-add-3-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-add-3-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-add-3-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,40 @@ + + + + postgresql7.1 + + + + select case when count(*) = 0 then 0 else 1 end from survey_questions where question_id = :question_id + + + + + + + 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, + :question_html_p, + :summary_type, + :answer_description, + NULL, + :user_id, + :section_id + ) + + + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/question-add-3.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-add-3.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-add-3.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,182 @@ +# /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 2003/09/19 16:48:04 rmello 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 ""} +} + +# Variables that will be used later... +set question_html_p "f" +set summary_type [db_null] +set answer_description [db_null] +### + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] +ad_require_permission $package_id admin +get_survey_info -section_id $section_id +get_section_info -section_id $section_id + +if {![info exists survey_info(survey_id)]} { + ad_return_complaint 1 "Requested survey does not exist" + ad_script_abort +} + +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 + ad_script_abort +} + +set already_inserted_p [db_string already_inserted_p {}] + +if { $already_inserted_p } { + ad_returnredirect "one?[export_vars survey_id]" + ad_script_abort +} +# 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 this is a block section, get the choices and run the block for + # every choice set + if {$section_info(block_section_p)=="t"} { + set all_choices_list [db_list all_choices ""] + } else { + set all_choices_list {dummy} + } + + set count 0 + foreach all_choices $all_choices_list { + # Get the canned responses for a block section if applicable + if {$section_info(block_section_p)=="t"} { + # block section, get the valid_responses + regsub -all "," $all_choices "\n" valid_responses + } + # If we insert multiple questions (because of block questions) + # generate a new question_id + if {$count>0} { + set question_id [db_nextval acs_object_id_seq] + } + incr count + + + 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_nextval survey_choice_id_sequence] + db_dml insert_survey_question_choice "" + incr count + } + } + } + } + } on_error { + + db_release_unused_handles + ad_return_error "Database Error" "
    $errmsg
    " + ad_script_abort + + } + + +db_release_unused_handles +ad_returnredirect "one?survey_id=$survey_id&#${sort_order}" + + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/question-add-3.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-add-3.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-add-3.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,62 @@ + + + + + + select distinct survey_question_all_choices(question_id) as + all_choices from + survey_questions where section_id=:section_id + + + + + + update survey_questions + set sort_order = sort_order + 1 + where section_id = :section_id + and sort_order > :after + + + + + + select max(sort_order) from survey_questions + where section_id=:section_id + + + + + + + + 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) + + + + + Index: openacs-4/contrib/packages/survey/www/admin/question-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-add.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-add.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,11 @@ + +@survey_id@ + +@survey_info.name;noquote@: New Question +@context_bar;noquote@ + + + + Add a question from the question catalogue + + Index: openacs-4/contrib/packages/survey/www/admin/question-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-add.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-add.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,68 @@ +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 2003/09/19 16:48:04 rmello 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 admin + +get_survey_info -section_id $section_id +get_section_info -section_id $section_id + +if {$section_info(block_section_p)=="t"} { + ad_returnredirect "block-question-add?[export_url_vars section_id after]" + ad_script_abort +} + +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" } } } } +} + +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_p:text(radio) {label "Required?"} {options {{Yes t} {No f}}} {value t}} +} +set catalogue_link "predefined-question?[export_url_vars section_id after]" +ad_return_template + + + + Index: openacs-4/contrib/packages/survey/www/admin/question-copy.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-copy.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-copy.tcl 19 Sep 2003 16:48:04 -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 admin +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/contrib/packages/survey/www/admin/question-copy.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-copy.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-copy.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/question-delete-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-delete-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-delete-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,24 @@ + + + + oracle8.1.6 + + + + + select question_id from survey_questions where + section_id=:section_id and + 0=dbms_lob.compare(question_text,(select question_text from + survey_questions where question_id=:question_id)) + + + + + + begin + survey_question.remove (:question_id); + end; + + + + Index: openacs-4/contrib/packages/survey/www/admin/question-delete-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-delete-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-delete-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,24 @@ + + + + postgresql7.1 + + + + select question_id from survey_questions where + section_id=:section_id and + question_text = (select question_text from + survey_questions where question_id=:question_id)) + + + + + + + select survey_question__remove (:question_id); + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/question-delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-delete.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-delete.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,8 @@ + + +@survey_id@ + +DELETE: Question +@context_bar;noquote@ + + Index: openacs-4/contrib/packages/survey/www/admin/question-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-delete.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-delete.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,107 @@ +# /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 admin + +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} { + if {[db_string block_section_p ""]=="t"} { + db_transaction { + db_foreach questions_to_delete "" { + 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_dml 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. + " + ad_script_abort + } + } else { + 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_dml 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. + " + ad_script_abort + } + } + db_release_unused_handles + set sort_order [expr {$sort_order -1}] + } + ad_returnredirect "one?[export_url_vars survey_id]&#${sort_order}" + ad_script_abort + } + +set context_bar [ad_context_bar "Delete Question"] +ad_return_template + Index: openacs-4/contrib/packages/survey/www/admin/question-delete.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-delete.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-delete.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,60 @@ + + + + + + select section_id + from survey_questions + where question_id = :question_id + + + + + + + select count(*) +from survey_question_responses +where question_id = :question_id + + + + + + select block_section_p from survey_sections + where section_id=:section_id + + + + + + + + delete from survey_question_responses + where question_id=:question_id + + + + + + delete from survey_question_choices where + question_id = :question_id + + + + + +update survey_questions set sort_order=sort_order - 1 +where section_id = :section_id +and sort_order > :sort_order + + + + + + select * from survey_questions where question_id=:question_id + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/question-modify-text.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-modify-text.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-modify-text.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,8 @@ + +@survey_id@ + +@survey_name;noquote@: Modify Question Text +@context_bar;noquote@ + + + Index: openacs-4/contrib/packages/survey/www/admin/question-modify-text.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-modify-text.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-modify-text.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,40 @@ +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 2003/09/19 16:48:04 rmello Exp $ +} { + + question_id:integer + section_id:integer + +} + +ad_require_permission $section_id admin + +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 {} + ad_returnredirect "one?survey_id=$survey_id" + ad_script_abort + +} + +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/contrib/packages/survey/www/admin/question-modify-text.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-modify-text.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-modify-text.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,27 @@ + + + + + + update survey_questions set question_text=:question_text + where question_id=:question_id + + + + + + select name from survey_sections where section_id=:section_id + + + + + + +select question_text +from survey_questions +where question_id = :question_id + + + + + Index: openacs-4/contrib/packages/survey/www/admin/question-modify.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-modify.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-modify.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,8 @@ + +@survey_id@ + +@survey_name;noquote@: Modify Question Text +@context_bar;noquote@ + + + Index: openacs-4/contrib/packages/survey/www/admin/question-modify.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-modify.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-modify.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,171 @@ +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 2003/09/19 16:48:04 rmello Exp $ +} { + + question_id:integer + section_id:integer + {valid_responses ""} + {presentation_options ""} + {sort_order ""} +} + +get_survey_info -section_id $section_id +get_section_info -section_id $section_id +set survey_name $survey_info(name) +set survey_id $survey_info(survey_id) +ad_require_permission $survey_id admin +set allow_question_deactivation [ad_parameter "allow_question_deactivation_p"] +set n_responses [db_string survey_number_responses {} ] +set block_p $section_info(block_section_p) + +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 recommended. 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" && $block_p=="f"} { + ad_form -extend -name modify_question -form { + {presentation_type:text(radio) {options {{"Radio buttons" radio} {"Checkboxes" checkbox} {"Select box" select}}} {value $presentation_type} {label "Presentation"}} + } + 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"}} + + } +} + +if {$section_info(block_section_p)=="f"} { + set sections [db_list_of_lists sections ""] + ad_form -extend -name modify_question -form { + {new_section:integer(select) {options $sections} {label "Move to section"} {value $section_id}} + } +} + +ad_form -extend -name modify_question -select_query_name {survey_question_details} -edit_data { + + db_transaction { + if {[info exists new_section]} { + set anchor [db_string new_anchor ""] + set section_id $new_section + } + + db_dml survey_question_update {} + + # add new responses is choice type question + + + if {[info exists valid_responses] && $block_p=="f"} { + + 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]} { + set new_choice_id [db_nextval survey_choice_id_sequence] + 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 + } + + } + } on_error { + + db_release_unused_handles + ad_return_error "Database Error" "

    $errmsg
    " + ad_script_abort + + } + + + + + ad_returnredirect "one?survey_id=$survey_id&#${sort_order}" + ad_script_abort +} + + +set context_bar [ad_context_bar "Modify Question"] + +ad_return_template Index: openacs-4/contrib/packages/survey/www/admin/question-modify.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-modify.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-modify.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,115 @@ + + + + + + select count(*) + from survey_question_responses + where question_id=:question_id + + + + + +select presentation_type, presentation_options, abstract_data_type, +sort_order as anchor +from survey_questions +where question_id=:question_id + + + + + + select name,section_id from survey_sections + where survey_id=:survey_id and block_section_p='f' + order by sort_key + + + + + +select label from survey_question_choices +where question_id=:question_id +order by sort_order + + + + + + +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 max(sort_order) from survey_questions where question_id=:question_id + + + + + +update survey_questions + set question_text=:question_text, + section_id=:section_id, + sort_order=:anchor, + active_p=:active_p, + required_p=:required_p, + presentation_type=:presentation_type, + presentation_options=:presentation_options + where question_id=:question_id + + + + + + select choice_id from survey_question_choices + where question_id=:question_id + order by sort_order + + + + + +insert into survey_question_choices +(choice_id, question_id, label, sort_order) +values (:new_choice_id, :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 name from survey_sections where section_id=:section_id + + + + + Index: openacs-4/contrib/packages/survey/www/admin/question-required-toggle-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-required-toggle-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-required-toggle-oracle.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/question-required-toggle-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-required-toggle-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-required-toggle-postgresql.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/question-required-toggle.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-required-toggle.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-required-toggle.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,30 @@ +# /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 admin + +db_dml survey_question_required_toggle "" + +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/contrib/packages/survey/www/admin/question-swap-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-swap-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-swap-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,15 @@ + + +oracle8.1.6 + + + +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/contrib/packages/survey/www/admin/question-swap-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-swap-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-swap-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,18 @@ + + +postgresql7.1 + + + +update survey_questions +set sort_order = (case when sort_order = (cast (:sort_order as integer)) then + cast (:next_sort_order as integer) + when +sort_order = (cast (:next_sort_order as integer)) then cast (:sort_order as integer) end) +where section_id = :section_id +and sort_order in (:sort_order, :next_sort_order) + + + + + Index: openacs-4/contrib/packages/survey/www/admin/question-swap.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/question-swap.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/question-swap.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,41 @@ +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 2003/09/19 16:48:04 rmello Exp $ + +} { + survey_id:integer,notnull + section_id:integer,notnull + sort_order:integer,notnull + direction:notnull +} + +ad_require_permission $section_id admin + +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 "" + +} on_error { + + ad_return_error "Database error" "A database error occured while trying +to swap your questions. Here's the error: +
    +$errmsg
    +
    +" + ad_script_abort +} +ad_returnredirect "one?survey_id=$survey_id&#${sort_order}" + Index: openacs-4/contrib/packages/survey/www/admin/respondents.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/respondents.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/respondents.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,7 @@ + +@survey_id@ + +@survey_name;noquote@: Respondents +@context_bar;noquote@ + +@respondents_table;noquote@ Index: openacs-4/contrib/packages/survey/www/admin/respondents.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/respondents.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/respondents.tcl 19 Sep 2003 16:48:04 -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 2003/09/19 16:48:04 rmello Exp $ +} -query { + survey_id:integer + {orderby "email"} + {response_type "responded"} +} -properties { + survey_name:onevalue + respondents:multirow +} + +ad_require_permission $survey_id admin + +# 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?[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/contrib/packages/survey/www/admin/respondents.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/respondents.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/respondents.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/response-delete-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-delete-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-delete-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,28 @@ + + + + oracle8.1.6 + + + +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) + + + + + +begin + survey_response.remove(:response_id); +end; + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/response-delete-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-delete-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-delete-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,24 @@ + + + +postgresql7.1 + + + +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) + + + + + + select survey_response__remove(:response_id); + + + + Index: openacs-4/contrib/packages/survey/www/admin/response-delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-delete.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-delete.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,8 @@ + + +@survey_id@ + +DELETE: Survey Response +@context_bar;noquote@ + + Index: openacs-4/contrib/packages/survey/www/admin/response-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-delete.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-delete.tcl 19 Sep 2003 16:48:04 -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 2003/09/19 16:48:04 rmello Exp $ +} { + response_id:integer,optional +} + +set package_id [ad_conn package_id] +ad_require_permission $package_id admin + +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"] Index: openacs-4/contrib/packages/survey/www/admin/response-drill-down-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-drill-down-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-drill-down-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,24 @@ + + +oracle8.1.6 + + + + +select + decode(creation_user,null,'Anonymous user',person.name(creation_user)) as responder_name, + creation_user as user_id, + creation_date +from + acs_objects, + survey_responses sr, + survey_question_responses qr +where + qr.response_id = sr.response_id + and qr.response_id = object_id + and qr.question_id = :question_id + and qr.choice_id = :choice_id + + + + Index: openacs-4/contrib/packages/survey/www/admin/response-drill-down-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-drill-down-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-drill-down-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,27 @@ + + + +postgresql7.1 + + + + +select + (case when creation_user IS NULL then 'Anonymous user' + else person__name(creation_user) + end) as responder_name, + creation_user as user_id, + creation_date +from + acs_objects, + survey_responses sr, + survey_question_responses qr +where + qr.response_id = sr.response_id + and qr.response_id = object_id + and qr.question_id = :question_id + and qr.choice_id = :choice_id + + + + Index: openacs-4/contrib/packages/survey/www/admin/response-drill-down.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-drill-down.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-drill-down.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,18 @@ + +@survey_id@ + +People who answered @response_text@ +@context_bar;noquote@ + +@survey_name@ responders who answered @response_text@ +when asked @question_text@: + + Index: openacs-4/contrib/packages/survey/www/admin/response-drill-down.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-drill-down.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-drill-down.tcl 19 Sep 2003 16:48:04 -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 2003/09/19 16:48:04 rmello Exp $ + +} { + + question_id:integer,notnull + choice_id:integer,notnull + +} + +ad_require_permission $question_id admin + +# 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/contrib/packages/survey/www/admin/response-drill-down.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-drill-down.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-drill-down.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,25 @@ + + + + + + +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 + + + + + Index: openacs-4/contrib/packages/survey/www/admin/response-editable-toggle-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-editable-toggle-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-editable-toggle-oracle.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/response-editable-toggle-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-editable-toggle-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-editable-toggle-postgresql.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/response-editable-toggle.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-editable-toggle.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-editable-toggle.tcl 19 Sep 2003 16:48:04 -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 2003/09/19 16:48:04 rmello Exp $ +} { + + survey_id:integer + +} + +ad_require_permission $survey_id admin + +db_dml survey_response_editable_toggle "" + +db_release_unused_handles +ad_returnredirect "one?[export_url_vars survey_id]" Index: openacs-4/contrib/packages/survey/www/admin/response-limit-toggle-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-limit-toggle-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-limit-toggle-oracle.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/response-limit-toggle-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-limit-toggle-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-limit-toggle-postgresql.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/response-limit-toggle.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/response-limit-toggle.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/response-limit-toggle.tcl 19 Sep 2003 16:48:04 -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 admin + +db_dml survey_reponse_toggle "" + +db_release_unused_handles +ad_returnredirect "one?[export_url_vars survey_id]" Index: openacs-4/contrib/packages/survey/www/admin/responses-export-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/responses-export-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/responses-export-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,96 @@ + + + + oracle8.1.6 + + + +select + sub.response_id, + sub.question_id, + sub.email, + sub.first_names, + sub.last_name, + sub.user_id, + sub.creation_date, + qr.boolean_answer, + qr.number_answer, + qr.date_answer, + qr.varchar_answer, + qr.clob_answer, + qr.attachment_answer, + qc.label +from +(select + r.response_id, + q.question_id, + u.email, + u.first_names, + u.last_name, + u.user_id, + to_char(r.creation_date,'YYYY-MM-DD HH24:MI:SS') as creation_date, + q.sort_order as q_sort_order +from survey_responses_latest r, cc_users u,survey_questions q, survey_sections s + where + s.survey_id=:survey_id +and r.survey_id=:survey_id + and q.section_id=s.section_id +and r.initial_user_id=u.user_id) sub, survey_question_responses qr, + survey_question_choices qc +where qr.question_id(+)=sub.question_id +and sub.response_id=qr.response_id(+) + and qc.choice_id(+)=qr.choice_id + order by + sub.response_id, + sub.q_sort_order, + sub.question_id, + qc.sort_order + + + + + +select + sub.response_id, + sub.question_id, + sub.email, + sub.first_names, + sub.last_name, + sub.user_id, + sub.creation_date, + qr.boolean_answer, + qr.number_answer, + qr.date_answer, + qr.varchar_answer, + qr.clob_answer, + qr.attachment_answer, + qc.label +from +(select + r.response_id, + q.question_id, + u.email, + nvl(u.first_names,'Unregistered') as first_names, + nvl(u.last_name,'Visitor') as last_name, + u.user_id, + to_char(r.creation_date,'YYYY-MM-DD HH24:MI:SS') as creation_date, + q.sort_order as q_sort_order +from survey_responses_latest r, cc_users u,survey_questions q, survey_sections s + where + s.survey_id=:survey_id +and r.survey_id=:survey_id + and q.section_id=s.section_id +and nvl(r.initial_user_id,0)=u.user_id(+)) sub, survey_question_responses qr, + survey_question_choices qc +where qr.question_id(+)=sub.question_id +and sub.response_id=qr.response_id(+) + and qc.choice_id(+)=qr.choice_id + order by + sub.response_id, + sub.q_sort_order, + sub.question_id, + qc.sort_order + + + + Index: openacs-4/contrib/packages/survey/www/admin/responses-export-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/responses-export-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/responses-export-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,95 @@ + + + + postgresql7.1 + + + +select + sub.response_id, + sub.question_id, + sub.email, + sub.first_names, + sub.last_name, + sub.user_id, + sub.creation_date, + qr.boolean_answer, + qr.number_answer, + qr.date_answer, + qr.varchar_answer, + qr.clob_answer, + qr.attachment_answer, + qc.label +from +(select + r.response_id, + q.question_id, + u.email, + u.first_names, + u.last_name, + u.user_id, + to_char(r.creation_date,'YYYY-MM-DD HH24:MI:SS') as creation_date, + q.sort_order as q_sort_order +from survey_responses_latest r, cc_users u,survey_questions q, survey_sections s + where + s.survey_id=:survey_id +and r.survey_id=:survey_id + and q.section_id=s.section_id +and r.initial_user_id=u.user_id) sub + left outer join survey_question_responses qr on ( + qr.question_id=sub.question_id and sub.response_id=qr.response_id) + left outer join survey_question_choices qc on ( + qc.choice_id=qr.choice_id) + order by + sub.response_id, + sub.q_sort_order, + sub.question_id, + qc.sort_order + + + + + +select + sub.response_id, + sub.question_id, + sub.email, + sub.first_names, + sub.last_name, + sub.user_id, + sub.creation_date, + qr.boolean_answer, + qr.number_answer, + qr.date_answer, + qr.varchar_answer, + qr.clob_answer, + qr.attachment_answer, + qc.label +from +(select + r.response_id, + q.question_id, + u.email, + coalesce(u.first_names,'Unregistered') as first_names, + coalesce(u.last_name,'Visitor') as last_name, + u.user_id, + to_char(r.creation_date,'YYYY-MM-DD HH24:MI:SS') as creation_date, + q.sort_order as q_sort_order +from survey_responses_latest r + left outer join cc_users u on (coalesce(r.initial_user_id,0)=u.user_id) + inner join survey_sections s using (survey_id) + inner join survey_questions q using (section_id) +where s.survey_id=:survey_id) sub +left outer join survey_question_responses qr on + (qr.question_id=sub.question_id and sub.response_id=qr.response_id) +left outer join survey_question_choices qc on + (qc.choice_id=qr.choice_id) +order by + sub.response_id, + sub.q_sort_order, + sub.question_id, + qc.sort_order + + + + Index: openacs-4/contrib/packages/survey/www/admin/responses-export.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/responses-export.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/responses-export.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,145 @@ +# /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 2003/09/19 16:48:04 rmello 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 n_responses [db_string get_n_responses {}] + +if {$n_responses==0} { + get_survey_info -survey_id $survey_id + set context_bar [ad_context_bar [list "one?[export_url_vars survey_id]" $survey_info(name)] "CSV Export"] + ad_return_template "no-responses" + return +} + +set question_id_list [list] +set responses_table survey_responses + +set headline "email,first_names,last_name,user_id,submission_date,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 "text/comma-separated-values" +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 r 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 Index: openacs-4/contrib/packages/survey/www/admin/responses-export.vuh =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/responses-export.vuh,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/responses-export.vuh 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,157 @@ +# /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.vuh,v 1.1 2003/09/19 16:48:04 rmello Exp $ + +} { + + survey_id:integer,notnull + {unique_users_p f} + on_what_id:optional,integer + {start:naturalnum 1} + {end:naturalnum 10000} + {anonymous_p f} +} +set csv_export "" +set package_id [ad_conn package_id] +ad_require_permission $package_id admin + +set n_responses [db_string get_n_responses {}] + +if {$n_responses==0} { + get_survey_info -survey_id $survey_id + set context_bar [ad_context_bar [list "one?[export_url_vars survey_id]" $survey_info(name)] "CSV Export"] + + set args [list [list survey_id $survey_id] [list survey_name $survey_info(name)] [list context_bar $context_bar]] + + ad_return_exception_template -status 200 -params $args "no-responses" + return +} + +set question_id_list [list] +set responses_table survey_responses + +set headline "email,first_names,last_name,user_id,submission_date,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 -1 +set current_question_list [list] +set csv_export "" +set r 0 +ReturnHeaders "text/comma-separated-values" +ns_write "$headline \r\n" + +if {$anonymous_p=="t"} { + set query get_all_survey_question_responses_anonymous +} else { + set query get_all_survey_question_responses +} +db_foreach $query "" { + + if { $response_id != $current_response_id } { + if {$current_question_id!="-1" } { + 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 "-1" + set current_question_list [list] + } + + if {[info exists question_column($question_id)]} { + 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 || $current_question_id=="" } { + if { $current_question_id!="-1" } { + append current_response ",\"[join $current_question_list ","]\"" + } + set current_question_id $question_id + set current_question_list [list] + } + # decode boolean answers + if {[info exists question_data_type($question_id)] && $question_data_type($question_id)=="boolean"} { + set response_value [survey_decode_boolean_answer -response $response_value -question_id $question_id] + } + if {[info exists question_data_type($question_id)] && $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 r 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 + Index: openacs-4/contrib/packages/survey/www/admin/responses-export.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/responses-export.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/responses-export.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,30 @@ + + + + + + select count(*) from survey_responses_latest + where survey_id=:survey_id + + + + + + 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 title from cr_revisions where + revision_id=:attachment_answer + + + + Index: openacs-4/contrib/packages/survey/www/admin/responses.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/responses.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/responses.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,20 @@ + +@survey_id@ + +@survey_name;noquote@: Responses +@context_bar;noquote@ + +@response_sentence@ +

    + + @responses.section_name@ +

      + +
    • #@responses.sort_order@ @responses.question_text@ +
      + @responses.extrainfo;noquote@ +
      + +
    + + Index: openacs-4/contrib/packages/survey/www/admin/responses.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/responses.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/responses.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,85 @@ +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 2003/09/19 16:48:04 rmello Exp $ +} { + + survey_id:integer + +} + +ad_require_permission $survey_id admin + +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) + +# 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 + + +db_multirow -extend {extrainfo} responses survey_question_list {} { + switch -- $abstract_data_type { + "date" - + "text" - + "shorttext" { + set extrainfo "View responses\n" + } + + "boolean" { + set extrainfo "" + db_foreach survey_boolean_summary "" { + append extrainfo "[survey_decode_boolean_answer -response $boolean_answer -question_id $question_id]: $n_responses
    \n" + } + } + "integer" - + "number" { + set extrainfo "" + db_foreach survey_number_summary "" { + append extrainfo results "$number_answer: $n_responses
    \n" + } + db_1row survey_number_average "" + append extrainfo "

    Mean: $mean
    Standard Dev: $standard_deviation
    \ +\n" + + } + "choice" { + set extrainfo "" + db_foreach survey_section_question_choices "" { + append extrainfo "$label: $n_responses
    \n" + } + } + "blob" { + set extrainfo "" + db_foreach survey_attachment_summary {} { + append extrainfo "[ad_quotehtml $title]
    " + } + } + } +} + +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/contrib/packages/survey/www/admin/responses.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/responses.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/responses.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,79 @@ + + + + + + select question_id, question_text, abstract_data_type, + sort_order, s.section_id, sort_key, name as section_name + +from survey_questions q, survey_sections s +where survey_id=:survey_id and s.section_id=q.section_id +order by sort_key,sort_order + + + + + + +select count(*) as n_responses, (case when boolean_answer = 't' then + 'True' when boolean_answer = 'f' then 'False' end) as + boolean_answer_pretty, 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/contrib/packages/survey/www/admin/section-add-2-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-add-2-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-add-2-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,30 @@ + + + + oracle8.1.6 + + + + 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, + sort_key => :sort_key, + branch_p => :branch_p, + page_break_p => :page_break_p + ); + end; + + + + + + + select decode(count(*),0,0,1) from survey_sections where section_id = :section_id + + + Index: openacs-4/contrib/packages/survey/www/admin/section-add-2-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-add-2-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-add-2-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,36 @@ + + + + postgresql7.1 + + + + select case when count(*) = 0 then '0' + else '1' + end + from survey_sections where section_id = :section_id + + + + + + select survey_section__new ( + :section_id, + :survey_id, + :name, + :description, + :description_html_p, + :sort_key, + :branch_p, + FALSE, + FALSE, + :page_break_p, + :user_id, + :survey_id + ); + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/section-add-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-add-2.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-add-2.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,96 @@ +# /packages/survey/www/admin/section-add-2.tcl +ad_page_contract { + Inserts a new section into the database. + + @param survey_id integer denoting which survey we're adding section to + @param section_id id of new section + @param after integer determining position of this section + @param name name of the new section + @param description description of the new section + @param description_html_p is the description in html? + + @author Jin Choi (jsc@arsdigita.com) February 9, 2000 + @author nstrug@arsdigita.com + @cvs-id $Id: section-add-2.tcl,v 1.1 2003/09/19 16:48:04 rmello Exp $ +} { + section_id:integer,notnull + survey_id:integer,notnull + after:integer,notnull + description:html,notnull + description_html_p:boolean,notnull + name:notnull + branch_p:boolean,notnull + page_break_p:boolean,notnull +} -validate { + first_section_not_branch -requires {branch_p:notnull} { + if {$branch_p=="t" && $after==0} { + ad_complain "First section cannot be branch" + } + } +} + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] +ad_require_permission $package_id admin +get_survey_info -survey_id $survey_id + +if {![info exists survey_info(survey_id)]} { + ad_return_complaint 1 "Requested survey does not exist" + ad_script_abort +} + +set exception_count 0 +set exception_text "" + +if { [empty_string_p $description] } { + incr exception_count + append exception_text "

  • You did not enter a description.\n" +} + +if { $exception_count > 0 } { + ad_return_complaint $exception_count $exception_text + ad_script_abort +} + +set already_inserted_p [db_string already_inserted_p {}] + +if { $already_inserted_p } { + ad_returnredirect "one?[export_vars survey_id]" + ad_script_abort +} + +db_transaction { + # We're inserting between existing sections; move everybody down. + set sort_key [expr { $after + 1 }] + db_dml renumber_sort_keys {} + + db_exec_plsql create_section {} + db_dml make_description "" + if {$branch_p == "t"} { + set branch_id [db_nextval survey_branch_id_sequence] + db_dml add_branch "" + } + +} on_error { + + db_release_unused_handles + ad_return_error "Database Error" "
    $errmsg
    " + ad_script_abort + +} + + +db_release_unused_handles +if {$branch_p == "t"} { + ad_returnredirect "condition-add?section_id=$section_id" + ad_script_abort +} + +ad_returnredirect "one?survey_id=$survey_id&#${sort_key}" + + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/section-add-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-add-2.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-add-2.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,32 @@ + + + + + + update survey_sections + set sort_key = sort_key + 1 + where survey_id = :survey_id + and sort_key > :after + + + + + + + insert into + survey_branches(branch_id,section_id,after,condition) values ( + :branch_id,:section_id,(select section_id from survey_sections + where survey_id=:survey_id and sort_key=:after),null) + + + + + + + update survey_sections set description=:description where section_id=:section_id + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/section-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-add.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-add.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,9 @@ + +@survey_id@ + +@survey_info.name@: New Section +@context_bar;noquote@ + + + + Index: openacs-4/contrib/packages/survey/www/admin/section-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-add.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-add.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,47 @@ +ad_page_contract { + Present form to begin adding a section to a survey. + Lets user enter the section and select a presentation type. + + @param survey_id integer designating survey we're adding question to + @param after optinal integer denoting position of section within survey + + @author jsc@arsdigita.com + @author nstrug@arsdigita.com + @date February 9, 2000 + @cvs-id $Id: section-add.tcl,v 1.1 2003/09/19 16:48:04 rmello Exp $ +} { + survey_id:integer + +} + +set package_id [ad_conn package_id] +set user_id [ad_get_user_id] +ad_require_permission $package_id admin + +set next_section_id [db_nextval acs_object_id_seq] + +ad_form -name create_section -action section-add-2 -form { + {section_id:text(hidden) {value $next_section_id}} + {survey_id:text(hidden) {value $survey_id}} + {name:text(text) {label "Section Name"} {html {size 30}}} + {description:text(textarea) {label "Description"} {html {rows 5 cols 70}}} + {description_html_p:text(radio) {label "The above description is"} {options {{HTML t} {"Plain text" f}}} {value f}} + {branch_p:text(radio) {label "Branch"} {options {{Yes t} {No f}}} {value f}} + {page_break_p:text(radio) {label "Begin new Page after this section"} {options {{Yes t} {No f}}} {value t}} +} + +set poslist [list [list "First Section" 0]] +db_foreach positions "" { + lappend poslist [list $secname $secsortkey] +} +set lastsec $secsortkey + +ad_form -extend -name create_section -form { + {after:integer(Select) {label "Position"} {options $poslist} {value $lastsec}} +} + +get_survey_info -survey_id $survey_id +set context_bar [ad_context_bar [list "one?[export_url_vars survey_id]" $survey_info(name)] "Add A Section"] + +ad_return_template + Index: openacs-4/contrib/packages/survey/www/admin/section-add.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-add.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-add.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,13 @@ + + + + + + + select 'After Section "'||name||'"' as secname, sort_key as secsortkey from + survey_sections where survey_id=:survey_id + order by sort_key + + + + Index: openacs-4/contrib/packages/survey/www/admin/section-delete-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-delete-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-delete-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,13 @@ + + + oracle8.1.6 + + + + begin + survey_section.remove (:section_id); + end; + + + + Index: openacs-4/contrib/packages/survey/www/admin/section-delete-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-delete-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-delete-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,11 @@ + + + postgresql7.1 + + + +select survey_section__remove (:section_id); + + + + Index: openacs-4/contrib/packages/survey/www/admin/section-delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-delete.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-delete.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,8 @@ + + +@survey_id@ + +DELETE: Section +@context_bar;noquote@ + + Index: openacs-4/contrib/packages/survey/www/admin/section-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-delete.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-delete.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,62 @@ +# /www/survsimp/admin/question-delete.tcl +ad_page_contract { + + Delete a section from a survey + (or ask for confirmation if there are responses). + + @param section_id section we're about to delete + + @author koljalehmann@uni.de + @date August 8th, 2003 + @cvs-id $Id: section-delete.tcl,v 1.1 2003/09/19 16:48:04 rmello Exp $ +} { + + section_id:integer +} + +ad_require_permission $section_id admin + +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) + +set n_questions [db_string section_number_questions {} ] + +set error 0 +if {$n_questions==0} { + # section does not contain any question, just delete it + db_transaction { + db_dml section_reorder {} + set conditions [db_list conditions {}] + db_dml delete_branches {} + foreach condition_id $conditions { + db_dml delete_condition {} + } + if {[db_0or1row replacement_section {}]} { + # the attribute "after" of survey_branches is not really used, will disappear soon + # if a new first_section cannot be found, there shouldn't be any branches + db_dml branch_reorder {} + } + db_exec_plsql section_delete {} + } on_error { + ad_form -name warning -action "one" -form { + {survey_id:text(hidden) {value $survey_id}} + {warning:text(inform) {label "Warning"} {value "Unable to delete section. This was the Error:
    $errmsg
    "}} + } + set context_bar [ad_context_bar "Delete Section"] + ad_return_template + set error 1 + } +} else { + # there are still questions in the section. give a warning + ad_form -name warning -action "one" -form { + {survey_id:text(hidden) {value $survey_id}} + {warning:text(inform) {label "Warning"} {value "Unable to delete section. It does contain questions, which must be deleted first"}} + } + set context_bar [ad_context_bar "Delete Section"] + ad_return_template + set error 1 +} + +if {!$error} { + ad_returnredirect "one?survey_id=$survey_id" +} Index: openacs-4/contrib/packages/survey/www/admin/section-delete.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-delete.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-delete.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,52 @@ + + + + + + select count(*) +from survey_questions +where section_id = :section_id + + + + + + update survey_sections set sort_key=sort_key-1 where + survey_id=:survey_id and + sort_key>( + select sort_key from survey_sections where section_id=:section_id) + + + + + + select section_id as replacement_section from survey_sections + where survey_id=:survey_id and sort_key=1 and section_id!=:section_id + + + + + + select condition from survey_branches where section_id=:section_id + + + + + + delete from survey_conditions where condition_id=:condition_id + + + + + + delete from survey_branches where section_id=:section_id + + + + + + update survey_branches set after=:replacement_section where after=:section_id + + + + Index: openacs-4/contrib/packages/survey/www/admin/section-edit-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-edit-2.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-edit-2.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,115 @@ +ad_page_contract { + + Allow the user to modify a section. + + @param section_id section we're changing + + @author cmceniry@arsdigita.com + @author nstrug@arsdigita.com + @date Jun 16, 2000 + @cvs-id $Id: section-edit-2.tcl,v 1.1 2003/09/19 16:48:04 rmello Exp $ +} { + + section_id:integer,notnull + name:notnull + description:html,notnull + description_html_p:boolean,notnull + after:integer,notnull + branch_p:boolean,notnull + {block_section_p:boolean "f"} + page_break_p:boolean,notnull +} -validate { + first_section_not_branch -requires {branch_p:notnull} { + if {$branch_p=="t" && $after==0} { + ad_complain "First section cannot be branch" + } + } +} + +get_survey_info -section_id $section_id +set survey_id $survey_info(survey_id) +db_1row get_section_info "" + +set refers_to 0 +db_0or1row referring_sort_key "" + + +db_1row old_sort_key "" +if {$after>$sort_key} { + incr after -1 +} +set sort_key [expr { $after + 1 }] + +# if there are branches dependant from this section +# that would be over this section, raise an error +set dependant [db_string dependant ""] +if {![empty_string_p $dependant] && $sort_key>=$dependant} { + ad_return_complaint 1 "Cannot move section below dependant sections" + ad_script_abort +} + +db_transaction { + if {$old_block_section_p=="f" && $block_section_p=="t"} { + if {![survey_block_section_candidate_p $section_id]} { + ad_return_complaint 1 "Cannot make measurement section" + ad_script_abort + } + # Make this a block section + # - create a row in survey_block_questions for each of the choices of the questions + # - mark section as block-section + + db_foreach example_questions "" { + set block_id [db_nextval survey_block_section_id_seq] + set choice_id [db_nextval survey_block_choice_id_seq] + db_dml make_block_choices "" + } + db_dml make_block_section "" + + } else { + if {$old_block_section_p=="t" && $block_section_p=="f"} { + # undo block section + db_dml make_noblock_section "" + db_dml remove_block_questions "" + } + } + + # after is the section which is to be newly above the section + # refers_to is the section our condition refers to + # if after is before refers_to we're before our condition and that case should be avoided + # -> drop the condition + + if {$after<$refers_to} { + db_dml modify_branch "" + db_dml drop_condition "" + } + + db_dml remove_sort_key "" + db_dml reorder_sort_key "" + db_dml modify_section "" + + if {$branch_p=="t" && $old_branch_p=="f"} { + set branch_id [db_nextval survey_branch_id_sequence] + db_dml add_branch "" + } + + + if {$old_branch_p=="t" && $branch_p=="f"} { + # remove branch and condition + db_dml drop_branch "" + if {[info exists condition]} { + db_dml drop_condition "" + } + } + +} on_error { + + db_release_unused_handles + ad_return_error "Database Error" "
    $errmsg
    " + ad_script_abort + +} + +ad_returnredirect "one?survey_id=$survey_id&#${sort_key}" +ad_script_abort + + Index: openacs-4/contrib/packages/survey/www/admin/section-edit-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-edit-2.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-edit-2.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,157 @@ + + + + + + + select branch_p as old_branch_p, branched_p as old_branched_p, + block_section_p as old_block_section_p + from survey_sections where section_id=:section_id + + + + + + select s.sort_key as refers_to, condition from survey_sections s, survey_branches b, survey_conditions c, + survey_questions q where b.section_id=:section_id and b.condition=c.condition_id and + c.question_id=q.question_id and q.section_id=s.section_id + + + + + + select sort_key from survey_sections where section_id=:section_id + + + + + + select min(s.sort_key) from survey_sections s, survey_branches b, survey_conditions c, + survey_questions q where q.section_id=:section_id and b.condition=c.condition_id and + c.question_id=q.question_id and b.section_id=s.section_id + + + + + + select question_id from survey_questions where + section_id=:section_id and 0=dbms_lob.compare(question_text,(select question_text + from survey_questions where section_id=:section_id and rownum=1)) + + + + + + + insert into + survey_block_questions(block_section_id,section_id,choice_id,label,sort_order) + select + :block_id,:section_id,:choice_id,label,sort_order + from survey_question_choices where question_id=:question_id + + + + + + update survey_sections set block_section_p='t' where section_id=:section_id + + + + + + update survey_sections set block_section_p='f' where section_id=:section_id + + + + + + delete from survey_block_questions where section_id=:section_id + + + + + + + update survey_branches set after=(select section_id from + survey_sections where survey_id=:survey_id and sort_key=:after), condition=null + where section_id=:section_id + + + + + + delete from survey_conditions where condition_id=:condition + + + + + + update survey_sections set sort_key=sort_key-1 where + sort_key>(select sort_key from survey_sections where + section_id=:section_id) and survey_id=:survey_id + + + + + + update survey_sections set sort_key=sort_key+1 where + sort_key>=:sort_key and survey_id=:survey_id + + + + + + update survey_sections set name=:name, description=:description, + description_html_p=:description_html_p, sort_key=:sort_key, + branch_p=:branch_p, page_break_p=:page_break_p where section_id=:section_id + + + + + + insert into + survey_branches(branch_id,section_id,after,condition) values ( + :branch_id,:section_id,(select section_id from survey_sections + where survey_id=:survey_id and sort_key=:after),null) + + + + + + + delete from survey_branches where section_id=:section_id + + + + + + + + + + + + + + + + + + + + + select after as old_parent_section,condition from survey_branches where section_id=:section_id + + + + + + select section_id as new_parent_section from survey_sections where + survey_id=:survey_id and sort_key=:after + + + + + + + Index: openacs-4/contrib/packages/survey/www/admin/section-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-edit.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-edit.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,16 @@ + +@survey_id@ + +@survey_info.name;noquote@: Edit Section +@context_bar;noquote@ + + + + + Section is rendered by a custom template. Edit the template + + + Section is rendered by the normal template. Create a custom template + Index: openacs-4/contrib/packages/survey/www/admin/section-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-edit.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-edit.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,58 @@ +ad_page_contract { + + Allow the user to modify a section. + + @param section_id section we're changing + + @author cmceniry@arsdigita.com + @author nstrug@arsdigita.com + @date Jun 16, 2000 + @cvs-id $Id: section-edit.tcl,v 1.1 2003/09/19 16:48:04 rmello Exp $ +} { + + section_id:integer +} + +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 admin + +ad_form -name modify_section -action section-edit-2 -form { + {section_id:text(hidden) {value $section_id}} +} + +db_1row section_info "" +set poslist [list [list "First Section" 0]] +db_foreach positions "" { + lappend poslist [list $secname $secsortkey] +} + +ad_form -extend -name modify_section -form { + {name:text(text) {label "Section Name"} {html {size 30}} {value $name}} + {description:text(textarea) {label "Description"} {html {rows 5 cols 70}} {value $description}} + {description_html_p:text(radio) {label "The above description is"} {options {{HTML t} {"Plain text" f}}} {value $description_html_p}} + {branch_p:text(radio) {label "Branch"} {options {{Yes t} {No f}}} {value $branch_p}} + {after:integer(Select) {label "Position"} {options $poslist} {value $after}} + {page_break_p:text(radio) {label "New Page after this section"} {options {{Yes t} {No f}}} {value $page_break_p}} +} + +if {[survey_block_section_candidate_p $section_id]} { + ad_form -extend -name modify_section -form { + {block_section_p:text(radio) {label "Measurement Section"} {options {{Yes t} {No f}}} {value $block_section_p}} + } +} else { + ad_form -extend -name modify_section -form { + {block_section_p:text(hidden) {value $block_section_p}} + } +} + +if {[file exists "[template::get_resource_path]/forms/survey/sections/${section_id}.adp"]} { + set template_exists "t" +} else { + set template_exists "f" +} + +set context_bar [ad_context_bar "Edit Section"] + +ad_return_template Index: openacs-4/contrib/packages/survey/www/admin/section-edit.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-edit.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-edit.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,21 @@ + + + + + + + select name,description,description_html_p,sort_key-1 as after, + sort_key, branch_p, block_section_p, page_break_p from survey_sections where section_id=:section_id + + + + + + select 'After Section "'||name||'"' as secname, sort_key as secsortkey from + survey_sections where survey_id=:survey_id and section_id != + :section_id + order by sort_key + + + + Index: openacs-4/contrib/packages/survey/www/admin/section-template-ae.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-template-ae.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-template-ae.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,11 @@ + +@survey_id@ + +Edit Section: @section_info.name;noquote@ +@context_bar;noquote@ + + + +
    +

    Preview

    + Index: openacs-4/contrib/packages/survey/www/admin/section-template-ae.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-template-ae.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-template-ae.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,92 @@ +ad_page_contract { + + Allow the user to add a custom template for a section + + @param section_id section we're adding a template to + + @author koljalehmann@uni.de + @date Jul, 7, 2003 + @cvs-id $Id: section-template-ae.tcl,v 1.1 2003/09/19 16:48:04 rmello Exp $ +} { + section_id:integer +} + +get_section_info -section_id $section_id +set section_name $section_info(name) +set survey_id $section_info(survey_id) +ad_require_permission $survey_id admin + +# If there is already a custom template for the section, load it, +# else generate a new one +set template_filename "[template::get_resource_path]/forms/survey/sections/${section_id}.adp" + +if {[file exists $template_filename]} { + set templatesource [template::util::read_file $template_filename] +} else { + set templatesource " + + + $section_info(name) + + + + $section_info(description) + + " + + # get all the questions and insert them into the template + db_foreach questions "" { + if {$presentation_type=="radio" || $presentation_type=="checkbox"} { + # radio and checkbox questions need an extra treatment + # the choices are generated with a tag + set widget_code " + + @formgroup.widget;noquote@ + @formgroup.label@ + " + } else { + set widget_code " + " + } + append templatesource " + [ad_decode $required_p "t" "*" ""]$question_text + $widget_code + +" + } +} + +ad_form -name edit_template -form { + {section_id:text(hidden) {value $section_id}} + {template_source:text(textarea) {label "Template Code"} {html {rows 20 cols 80}} {value $templatesource}} + {apply:text(submit) {label "Apply"}} + {revert:text(submit) {label "Erase custom template"}} +} -on_submit { + if {$apply=="Apply"} { + # write edited template into a file + set file_handle [open $template_filename w] + puts $file_handle $template_source + close $file_handle + } + if {$revert=="Erase custom template"} { + # erase template file + if {[file exists $template_filename]} { + file delete $template_filename + } + ad_returnredirect "section-template-ae?section_id=$section_id" + } +} + +ad_form -name preview_section -form { + {section_id:text(hidden) {value $section_id}} +} + +survey_section_add_to_form preview_section $section_id + +set context_bar [ad_context_bar "Edit Section"] + +set style "survey/standard" +db_0or1row get_style "" + +ad_return_template + Index: openacs-4/contrib/packages/survey/www/admin/section-template-ae.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/section-template-ae.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/section-template-ae.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,20 @@ + + + + + + + select question_id, question_text, presentation_type,required_p from + survey_questions where section_id=:section_id + + + + + + select 'survey/'||template_file as style from survey_templates + t, surveys s where s.survey_id=:survey_id + and s.template=t.template_id + + + + Index: openacs-4/contrib/packages/survey/www/admin/send-mail-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/send-mail-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/send-mail-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,139 @@ + + + oracle8.1.6 + + + + select '[db_quote $sender_email]' as from_addr, + '[db_quote $sender_first_names]' as sender_first_names, + '[db_quote $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, + '[db_quote $community_name]' as community_name, + '[db_quote $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 '[db_quote $sender_email]' as from_addr, + '[db_quote $sender_first_names]' as sender_first_names, + '[db_quote $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, + '[db_quote $community_name]' as community_name, + '[db-quote $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 '[db_quote $sender_email]' as from_addr, + '[db_quote $sender_first_names]' as sender_first_names, + '[db_quote $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, + '[db_quote $community_name]' as community_name, + '[db_quote $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 '[db_quote $sender_email]' as from_addr, + '[db_quote $sender_first_names]' as sender_first_names, + '[db_quote $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/contrib/packages/survey/www/admin/send-mail-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/send-mail-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/send-mail-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,139 @@ + + + + postgresql7.1 + + + + select '[db_quote $sender_email]' as from_addr, + '[db_quote $sender_first_names]' as sender_first_names, + '[db_quote $sender_last_name]' as sender_last_name, + parties.email, + (case acs_objects.object_type + when 'user' then + (select first_names + from persons + where person_id = parties.party_id) + when 'group' then + (select group_name + from groups + where group_id = parties.party_id) + when 'rel_segment' then + (select segment_name + from rel_segments + where segment_id = parties.party_id) + else '' end) as first_names, + (case acs_objects.object_type + when 'user' then + (select last_name + from persons + where person_id = parties.party_id) + else '' end) as last_name, + '[db_quote $community_name]' as community_name, + '[db_quote $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 '[db_quote $sender_email]' as from_addr, + '[db_quote $sender_first_names]' as sender_first_names, + '[db_quote $sender_last_name]' as sender_last_name, + parties.email, + (case acs_objects.object_type + when 'user' then + (select first_names + from persons + where person_id = parties.party_id) + when 'group' then + (select group_name + from groups + where group_id = parties.party_id) + when 'rel_segment' then + (select segment_name + from rel_segments + where segment_id = parties.party_id) + else '' end) as first_names, + (case acs_objects.object_type + when 'user' then + (select last_name + from persons + where person_id = parties.party_id) + else '' end) as last_name, + '[db_quote $community_name]' as community_name, + '[db_quote $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 '[db_quote $sender_email]' as from_addr, + '[db_quote $sender_first_names]' as sender_first_names, + '[db_quote $sender_last_name]' as sender_last_name, + parties.email, + (case acs_objects.object_type + when 'user' then + (select first_names + from persons + where person_id = parties.party_id) + when 'group' then + (select group_name + from groups + where group_id = parties.party_id) + when 'rel_segment' then + (select segment_name + from rel_segments + where segment_id = parties.party_id) + else '' end) as first_names, + (case acs_objects.object_type + when 'user' then + (select last_name + from persons + where person_id = parties.party_id) + else '' end) as last_name, + '[db_quote $community_name]' as community_name, + '[db_quote $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 '[db_quote $sender_email]' as from_addr, + '[db_quote $sender_first_names]' as sender_first_names, + '[db_quote $sender_last_name]' as sender_last_name, + parties.email + from parties + where parties.party_id in ( + select survey_response__initial_user_id(response_id) + from survey_responses_latest where survey_id=$survey_id) + + + + Index: openacs-4/contrib/packages/survey/www/admin/send-mail.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/send-mail.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/send-mail.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,9 @@ + + +@survey_id@ + +Send Mail Re: @survey_name;noquote@ +@context_bar;noquote@ + + + Index: openacs-4/contrib/packages/survey/www/admin/send-mail.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/send-mail.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/send-mail.tcl 19 Sep 2003 16:48:04 -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 "responded"} +} + +set package_id [ad_conn package_id] +set user_id [ad_conn user_id] +set sender_id [ad_conn user_id] + +ad_require_permission $survey_id admin + +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 rel_type "dotlrn_member_rel" + 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 "" + +if {$dotlrn_installed_p} { + switch $to { + all { + set query [db_map dotlrn_all] + } + + responded { + set query [db_map dotlrn_responded] + } + + not_responded { + set query [db_map dotlrn_not_responded] + } + } +} else { + set query [db_map responded] +} + + bulk_mail::new \ + -package_id $package_id \ + -from_addr $sender_email \ + -subject $subject \ + -message $message \ + -query $query + ad_returnredirect "one?survey_id=$survey_id" + ad_script_abort +} + +set context_bar [ad_context_bar "Send Mail"] +ad_return_template + Index: openacs-4/contrib/packages/survey/www/admin/send-mail.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/send-mail.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/send-mail.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/site-wide-survey-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/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/contrib/packages/survey/www/admin/site-wide-survey-oracle.xql 19 Sep 2003 16:48:04 -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) + + + Index: openacs-4/contrib/packages/survey/www/admin/site-wide-survey-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/site-wide-survey-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/site-wide-survey-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,22 @@ + + + + postgresql7.1 + + + + 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) + + + + Index: openacs-4/contrib/packages/survey/www/admin/site-wide-survey.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/site-wide-survey.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/site-wide-survey.adp 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,16 @@ + + + + +@surveys.parent_name@ + + Index: openacs-4/contrib/packages/survey/www/admin/site-wide-survey.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/site-wide-survey.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/site-wide-survey.tcl 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/style-select.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/style-select.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/style-select.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,24 @@ +# /packages/survey/www/admin/style-select.tcl +ad_page_contract { + + changes the style of a survey + + @param survey_id + @param style id of the new style + + @cvs-id $Id: style-select.tcl,v 1.1 2003/09/19 16:48:04 rmello Exp $ + +} { + + survey_id:integer + style:integer + +} + +ad_require_permission $survey_id admin + +db_dml change_style "" + + +db_release_unused_handles +ad_returnredirect "one?[export_url_vars survey_id]" Index: openacs-4/contrib/packages/survey/www/admin/style-select.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/style-select.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/style-select.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,11 @@ + + + + + + + update surveys set template=:style where survey_id=:survey_id + + + + Index: openacs-4/contrib/packages/survey/www/admin/survey-category-add-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-category-add-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-category-add-oracle.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,17 @@ + + + + oracle8.1.6 + + + + 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/contrib/packages/survey/www/admin/survey-category-add-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-category-add-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-category-add-postgresql.xql 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,17 @@ + + + + postgresql7.1 + + + + insert into site_wide_category_map + (map_id, category_id, + on_which_table, on_what_id, mapping_date, one_line_item_desc) + values (nextval('site_wide_cat_map_id_seq'), :category_id, 'survey_sections', + :section_id, current_timestamp, :one_line_item_desc) + + + + + Index: openacs-4/contrib/packages/survey/www/admin/survey-category-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-category-add.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-category-add.tcl 19 Sep 2003 16:48:04 -0000 1.1 @@ -0,0 +1,35 @@ +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_nextval category_id_sequence] + + db_dml category_insert "" + + set one_line_item_desc "Survey: [db_string survey_name ""]" + + db_dml category_map_insert "" + +} + +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/contrib/packages/survey/www/admin/survey-category-add.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-category-add.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-category-add.xql 19 Sep 2003 16:48:04 -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/contrib/packages/survey/www/admin/survey-copy-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-copy-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-copy-postgresql.xql 19 Sep 2003 16:48:05 -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/contrib/packages/survey/www/admin/survey-copy.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-copy.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-copy.adp 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,6 @@ + +@survey_id@ +Copy: @title_name;noquote@ +@context_bar;noquote@ + + Index: openacs-4/contrib/packages/survey/www/admin/survey-copy.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-copy.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-copy.tcl 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,38 @@ +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 admin + +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]" + ad_script_abort +} + + +set context_bar [ad_context_bar "Copy $title_name"] +ad_return_template Index: openacs-4/contrib/packages/survey/www/admin/survey-copy.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-copy.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-copy.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,10 @@ + + + + + +select * from surveys where survey_id=:survey_id + + + + \ No newline at end of file Index: openacs-4/contrib/packages/survey/www/admin/survey-create-choice.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-create-choice.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-create-choice.tcl 19 Sep 2003 16:48:05 -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 2003/09/19 16:48:05 rmello Exp $ + +} { + + + +} + +set package_id [ad_conn package_id] +ad_require_permission $package_id admin + +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/contrib/packages/survey/www/admin/survey-create-confirm.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-create-confirm.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-create-confirm.adp 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,21 @@ + +Confirm Survey Details + Survey Name: @name@ +

    +Here is how your survey description will appear: +

    + +@description@ + + +
    +@description@
    +
    +
    + +@description;noquote@ + +
    +

    + + Index: openacs-4/contrib/packages/survey/www/admin/survey-create-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-create-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-create-oracle.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,52 @@ + + + + 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 => :context_id, + creation_user => :user_id, + enabled_p => :enabled_p, + public_p => :public_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, + sort_key => 1 + ); + end; + + + + + + insert into survey_logic + (logic_id, logic) + values + (:logic_id, empty_clob()) returning logic into :1 + + + + Index: openacs-4/contrib/packages/survey/www/admin/survey-create-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-create-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-create-postgresql.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,55 @@ + + + + postgresql7.1 + + + + select survey__new ( + :survey_id, + :name, + :description, + :description_html_p, + 'f', + 't', + 'f', + 't', + :type, + :display_type, + :package_id, + :public_p, + :user_id, + :package_id + ) + + + + + + select survey_section__new ( + :section_id, + :survey_id, + :name, + :description, + :description_html_p, + 1, + 'f', + 'f', + 'f', + 't', + :user_id, + :package_id + ) + + + + + + insert into survey_logic + (logic_id, logic) + values + (:logic_id, :logic) + + + + Index: openacs-4/contrib/packages/survey/www/admin/survey-create.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-create.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-create.adp 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,7 @@ + + +Survey Administration: Create New Survey +@context_bar;noquote@ + + + Index: openacs-4/contrib/packages/survey/www/admin/survey-create.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-create.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-create.tcl 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,103 @@ +# /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 2003/09/19 16:48:05 rmello 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 admin +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 +ad_form -name create_survey -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"} + } + {public_p:text(radio) {label "Public?"} {options {{Yes t} {No f}}} {value t}} +} -validate { + {name {[string length $name] <= 4000} + "Survey Name must be 4000 characters or less" +} {name {[string length $name] > 0} + "Please enter a name for the survey" +} {description {[string length $description] <= 4000} + "Survey Description must be 4000 characters or less" +} {description {[string length $description] > 0} + "Please enter a description for the survey" +} + {survey_id {[db_string count_surveys ""] < 1} "oops" + } + +} -new_data { + if {[string compare $desc_html "plain"] == 0} { + set description_html_p "f" + } else { + set description_html_p "t" + if {[string compare $desc_html "pre"] == 0} { + set description "
    $description
    " + } + } + + 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 { + set context_id $package_id + db_exec_plsql create_survey "" + + if {$public_p=="t"} { + # survey is public: grant permission to take survey to The Public + set public_id [acs_magic_object "the_public"] + permission::grant -party_id $public_id -object_id $survey_id -privilege write + } + # survey type-specific inserts + + + # 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?section_id=$section_id" + ad_script_abort +} + + + + +# function to insert survey type-specific form html + +set context_bar [ad_context_bar "Create Survey"] + +ad_return_template + Index: openacs-4/contrib/packages/survey/www/admin/survey-create.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-create.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-create.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,41 @@ + + + + + + +select count(survey_id) from surveys where survey_id=:survey_id + + + + + + + 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/contrib/packages/survey/www/admin/survey-delete-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-delete-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-delete-oracle.xql 19 Sep 2003 16:48:05 -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/contrib/packages/survey/www/admin/survey-delete-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-delete-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-delete-postgresql.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,14 @@ + + + + postgresql7.1 + + +begin + perform survey__remove(:survey_id); +return NULL; +end; + + + + \ No newline at end of file Index: openacs-4/contrib/packages/survey/www/admin/survey-delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-delete.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-delete.adp 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,7 @@ + +@survey_id@ + +DELETE: @survey_info.name;noquote@ +@context_bar;noquote@ + + Index: openacs-4/contrib/packages/survey/www/admin/survey-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-delete.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-delete.tcl 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,45 @@ +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 2003/09/19 16:48:05 rmello Exp $ +} { + + survey_id:integer + +} + +set package_id [ad_conn package_id] +ad_require_permission $package_id admin + +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 "." + ad_script_abort + } else { + ad_returnredirect "one?[export_vars survey_id]" + ad_script_abort + } +} + +set context_bar [ad_context_bar "Delete Survey"] Index: openacs-4/contrib/packages/survey/www/admin/survey-display-type-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-display-type-edit.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-display-type-edit.tcl 19 Sep 2003 16:48:05 -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 admin + +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/contrib/packages/survey/www/admin/survey-display-type-edit.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-display-type-edit.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-display-type-edit.xql 19 Sep 2003 16:48:05 -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/contrib/packages/survey/www/admin/survey-preview.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-preview.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-preview.adp 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,27 @@ + +@survey_id@ + +Preview One Survey: @name;noquote@ +@context_bar;noquote@ +Return + + + + + + + + + + + + + + + + +
    @description@
    * denotes a required question

    + +
    +
    + Index: openacs-4/contrib/packages/survey/www/admin/survey-preview.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-preview.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-preview.tcl 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,62 @@ +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 2003/09/19 16:48:05 rmello 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 admin + + 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"] + +set rownum 0 + +ad_form -name preview_survey -action one -form { + {survey_id:text(hidden) {value $survey_id}} +} + +db_foreach survey_sections {} { + survey_section_add_to_form preview_survey $section_id +} + +set style "survey/standard" +db_0or1row get_style "" + +set return_url "one?[export_vars survey_id]" +set form_vars [export_form_vars section_id survey_id] +ad_return_template + Index: openacs-4/contrib/packages/survey/www/admin/survey-preview.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-preview.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-preview.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,43 @@ + + + + + + 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,block_section_p from survey_sections + where survey_id=:survey_id order by sort_key + + + + + +select question_text, presentation_type, abstract_data_type, + question_id, required_p from survey_questions where + section_id=:section_id and active_p='t' order by sort_order + + + + + + select 'survey/'||template_file as style from survey_templates t, surveys s + where s.survey_id=:survey_id + and s.template=t.template_id + + + + Index: openacs-4/contrib/packages/survey/www/admin/survey-sectioned-toggle-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-sectioned-toggle-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-sectioned-toggle-oracle.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,13 @@ + + + oracle8.1.6 + + + + update surveys +set single_section_p = util.logical_negation(single_section_p) +where survey_id = :survey_id + + + + Index: openacs-4/contrib/packages/survey/www/admin/survey-sectioned-toggle-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-sectioned-toggle-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-sectioned-toggle-postgresql.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,14 @@ + + + postgresql7.1 + + + + update surveys +set single_section_p = util__logical_negation(single_section_p) +where survey_id = :survey_id + + + + + Index: openacs-4/contrib/packages/survey/www/admin/survey-sectioned-toggle.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-sectioned-toggle.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-sectioned-toggle.tcl 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,45 @@ +# /packages/survey/www/admin/survey-sectioned-toggle.tcl +ad_page_contract { + + Toggles a survey between having only one or multiple sections + + @param section_id survey whose properties we're changing + + @cvs-id + +} { + + survey_id:integer + +} + +ad_require_permission $survey_id admin + +db_transaction { + get_survey_info -survey_id $survey_id + ns_log notice "survey_info(single_section_p) is $survey_info(single_section_p)" + if {$survey_info(single_section_p)=="f"} { + # compress to single section + db_1row block_sections "" + if {$num_blocked > 0} { + ad_return_complaint 1 "This survey contains measurement sections, which cannot be compressed" + ad_script_abort + } + + set new_sort_order 1 + db_1row first_section "" + db_foreach all_questions "" { + db_dml move_question "" + set new_sort_order [expr $new_sort_order + 1] + } + db_dml remove_unused_sections "" + set return_url "one?[export_url_vars survey_id]" + } else { + set return_url "section-edit?section_id=$survey_info(section_id)" + } + db_dml survey_sectioned_toggle "" +} + + +db_release_unused_handles +ad_returnredirect $return_url Index: openacs-4/contrib/packages/survey/www/admin/survey-sectioned-toggle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-sectioned-toggle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-sectioned-toggle.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,47 @@ + + + + + + select count(*) as num_blocked from survey_sections where + survey_id=:survey_id and block_section_p='t' + + + + + + select section_id + from survey_sections s + where survey_id=:survey_id + and sort_key=1 + + + + + + select question_id + from survey_questions q, survey_sections s + where survey_id=:survey_id + and q.section_id=s.section_id + order by s.sort_key,q.sort_order + + + + + + update survey_questions + set section_id =:section_id, + sort_order=:new_sort_order + where question_id=:question_id + + + + + + delete from survey_sections where survey_id=:survey_id and + sort_key != 1 + + + + + Index: openacs-4/contrib/packages/survey/www/admin/survey-status-bar-color-change.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-status-bar-color-change.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-status-bar-color-change.tcl 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,30 @@ +# /packages/survey/www/admin/survey-status-bar-color-change.tcl +ad_page_contract { + + Changes the color of the status bar for a multi-sectioned survey + + @param survey_id + @param color New color (or null for no status bar) + + @cvs-id + +} { + + survey_id:integer + color + +} + +ad_require_permission $survey_id admin + +db_transaction { + get_survey_info -survey_id $survey_id + if {$color=="null"} { + set color [db_null] + } + db_dml change_color "" +} + + +db_release_unused_handles +ad_returnredirect "one?[export_url_vars survey_id]" Index: openacs-4/contrib/packages/survey/www/admin/survey-status-bar-color-change.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-status-bar-color-change.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-status-bar-color-change.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,11 @@ + + + + + + + update surveys set status_bar_color=:color where survey_id=:survey_id + + + + Index: openacs-4/contrib/packages/survey/www/admin/survey-toggle.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-toggle.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-toggle.tcl 19 Sep 2003 16:48:05 -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 2003/09/19 16:48:05 rmello Exp $ +} { + survey_id:integer + enabled_p + {target "./"} +} + +ad_require_permission $survey_id admin + +if {$enabled_p == "f"} { + set enabled_p "t" +} else { + set enabled_p "f" +} + +db_dml survey_active_toggle "" + +ad_returnredirect "$target" + Index: openacs-4/contrib/packages/survey/www/admin/survey-toggle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/survey-toggle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/survey-toggle.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,13 @@ + + + + + + update surveys + set enabled_p = :enabled_p + where survey_id = :survey_id + + + + + Index: openacs-4/contrib/packages/survey/www/admin/user-responses-delete-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/user-responses-delete-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/user-responses-delete-oracle.xql 19 Sep 2003 16:48:05 -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/contrib/packages/survey/www/admin/user-responses-delete-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/user-responses-delete-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/user-responses-delete-postgresql.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,22 @@ + + + + postgresql7.1 + + + + select survey_response__remove(:response_id) + + + + + + + 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 + + + + Index: openacs-4/contrib/packages/survey/www/admin/user-responses-delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/user-responses-delete.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/user-responses-delete.adp 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,7 @@ + +@survey_id@ + +DELETE: Survey Response +@context_bar;noquote@ + + Index: openacs-4/contrib/packages/survey/www/admin/user-responses-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/user-responses-delete.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/user-responses-delete.tcl 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,44 @@ +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 2003/09/19 16:48:05 rmello Exp $ +} { + survey_id:integer + user_id:integer +} + +set package_id [ad_conn package_id] +ad_require_permission $package_id admin + +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}]" + ad_script_abort +} + +set context_bar [ad_context_bar "Delete Response"] Index: openacs-4/contrib/packages/survey/www/admin/view-text-responses-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/view-text-responses-oracle.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/view-text-responses-oracle.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,26 @@ + + +oracle8.1.6 + + + + select + $column_name as response, + decode(o.creation_user,null,'Anonymous user',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/contrib/packages/survey/www/admin/view-text-responses-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/view-text-responses-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/view-text-responses-postgresql.xql 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,31 @@ + + +postgresql7.1 + + + + + select + $column_name as response, + (case o.creation_user + when null then 'Anonymous_user' + else + person__name(acs_object__get_attribute(r.response_id,'creation_user')::text::integer) + end) 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, + 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/contrib/packages/survey/www/admin/view-text-responses.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/view-text-responses.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/view-text-responses.adp 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,20 @@ + + +@survey_id@ + +@survey_name;noquote@: Responses to Question +@context_bar;noquote@ +@question_text@ +
    + + No Responses + + +@responses.respondent_name@ + +@responses.respondent_name@ + on @responses.submission_date@ | @responses.response@ +
    +
    Index: openacs-4/contrib/packages/survey/www/admin/view-text-responses.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/view-text-responses.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/view-text-responses.tcl 19 Sep 2003 16:48:05 -0000 1.1 @@ -0,0 +1,41 @@ +# /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 admin + +set abstract_data_type [db_string abstract_data_type ""] + +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/contrib/packages/survey/www/admin/view-text-responses.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/admin/Attic/view-text-responses.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/admin/view-text-responses.xql 19 Sep 2003 16:48:05 -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/contrib/packages/survey/www/doc/admin-interface.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/doc/Attic/admin-interface.html,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/doc/admin-interface.html 19 Sep 2003 16:48:07 -0000 1.1 @@ -0,0 +1,311 @@ + + + +Survey documentation - Administration interface + + + +

    Survey - Administration Interface

    + +A package for OpenACS 4.6 + + +
    + + +

    Administration Interface

    +

    Creating a survey

    +When you start creating a survey you are first asked to enter a name +and a description for your survey, and wether this survey should be +public or not. Public surveys can be taken by anybody, even +unregistered users, if the survey module itself is readible for +everyone (check this in the site-map). +

    +After confirming you are prompted to add a first question to the +survey. You can do this now or click on the "Admin this Survey"-Link +to skip this step for now. + +

    Administrating a survey

    +Wether you add a question now or not afterwards you get to the +administration menu for your new survey. Here you can adjust some more +parameters, view and add questions and manage the results of a survey. +

    +The first option is to enable or disable the survey. A disabled survey +is not shown to users and cannot be answered to. This is the standard +for newly created surveys. When you are done editing the survey and +want it to become accessible to users, you need simply toggle this +setting and all users that are allowed to take this survey will see it +in their list of unifnished surveys. +

    +Underneath this setting you can find the name and description of the +survey. You can change these with the "Edit"-Button. "Preview" will +give you a preview of the survey. Please note that for multi-sectioned +and branched surveys this will display all sections on a single page. +

    +The next block allows viewing the results of survey. This feature is +described further below. +

    +When you create a survey it is by default a single-section +survey. That is, all questions will be presented to the user on one +page. If you want to split very long survey to multiple pages or if +you need to branch depending on the answers, you need to make the +survey multi-sectioned. +

    +In a multi-sectioned survey each section has a name and a description +of their own, which can be edited like the ones for surveys. It is +also possible to compress a multi-sectioned survey to a +single-sectioned one. However, this is not encouraged and in some +cases it is not even possible unless you change the sections +accordingly. +

    +For sectioned survey you can choose to display a status bar which +illustrates the progress the user has made in a survey as a percentage +of the survey. Single sectioned surveys do not have a status bar. +

    +Underneath the status bar you can select the style to use for +rendering the survey. These styles affect the layout of the complete +survey. Predefined are four different styles. It is possible to +further customize the layout of sections in the page for editing a +section. +

    +The directory to put new styles to is +
    +/packages/acs-templating/resources/forms/survey/ +but you also have to register them in the table survey_templates, like +this: +
    + +insert into survey_templates(template_id,template_file,description) +values (acs_object_id_seq.nextval,'standard-lars','Silver'); + +
    +There is no interface to this yet. +

    +You can select several options for how a user can respond to a +survey. The first option is to limit the user to one response per +survey or allow answering multiple times to a survey. The second +option is wether or not allowing a user to edit his old responses. +

    +The display options (list/table/paragraph) are not yet +functional. These will allow controlling the layout of surveys. +

    +The section "Accessibility" allows you to control who can take a +survey. At the moment this is limited to allowing the public access to +the survey. Taking a survey requires the privilege +"read" on the survey. +

    +You can request notification whenever someone has answered to the +survey, so you can instantly process the new response. You also have +the possibility to send bulk mail concerning a survey, for example +thanking everyone who has taken the survey or remind whoever has not +yet filled in the survey to do so. +

    +The last two options allow deleting a survey or making a copy of +it. This is especially useful if you often have similar surveys that +differ in details. +

    +After the survey options you will find a list of all sections with +their questions that are associated with this survey. If the survey is +single-sectioned, the enclosing section will not be explicitly +displayed. +

    +Here you can edit the properties of sections, add new questions or +reorder the existing questions by clicking on the up and down +arrows. + +

    Creating a question

    +There are different possibilities to add a new question to a survey. +When starting the creation of a new survey you are prompted to enter a +question. Later on you can always add new questions by selecting "add +new Question" in a section or clicking "new" at a question. The +difference between these two is that "New" will create the new +question underneath the one you selected "New" at, "add new question" +will just add at the end of this section. +

    +You can enter a text for your question and decide, if aswering the +question will be optional or required. Then you have to select a +"presentation type". +

    +There are different types of questions, and they require different +types of presentation and different types of answers. The first step +in creating a new question is choosing the presentation type. There +are seven different type to choose here: +

      +
    • One Line Answer - A question that requires the user to enter a +word or a short phrase +
    • Essay Answer - A Textbox for entering larger texts +
    • Multiple Choice (Drop Down) - This presents the user a drop down +list to choose one of several alternatives +
    • Multiple Choice (Radio Buttons) - This allows the user to choose +one of several possible answers to a question by selecting a radio button +
    • Date - Presents the user an entry field for a date +
    • File Attachment - Allows uploading a file as the answer to a question +
    +Depending on the choice for the presentation type, there are different +further options for each type of question, further specifying the +layout of the question. One Line and Essay answers need to specify the +size of the input box, multiple choice questions need the choices from +which to select the answer. This can be Yes/No, True/False (Not for +checkbox questions) or an own set of responses. These have to be +entered one choice per line in the textbox. For all questions you can +select if the entry widget(s) should be displayed next to the question +or below it. + +
    Image answers
    +It is possible to add images for choices in multiple choice +questions (radio buttons or checkboxes). The images that can be used +for this reside in "/www/graphics/survey" +To include, for example a smiley (file +/www/graphics/survey/small_smiley1.gif) you just type +"{small_smiley1.gif}" as a choice. + +

    Making a multi-sectioned survey

    +If you are not only creating very short surveys you might want to +split the survey into multiple sections. Another reason for sectioning +a survey is the possibility to create branches, that are executed +conditionally. +

    +Once you have set the survey to multi-sectioned, you can add new +sections to the survey by selecting "add new section". You can enter a +name and a description for the section, as well as the position +relative to the already existing sections. +

    +If you indicate that this section should be a branch, this section +will only be displayed, if a condition is met. After entering the data +for the section, you will be prompted to select a condition. The +possible conditions come from earlier questions in the survey that are +multiple choice questions. +

    +Conditions can be chosen from any multiple choice question, that +stands before the current section. That way it is possible to base a +branching decision at the end of a survey on a choice in the beginning +of that survey or have two or more streams of a survey depending on an +initial choice. + +

    Editing a section

    +After the name of a section in a multi-sectioned survey you can find a +link to edit the section properties. These are +
      +
    • The section name - This will be spelled out in the head of the +sections before the questions +
    • Section description - Actually this is not displayed anywhere +
    • Branch - If you select branching you will be asked to define a +condition afterwards. See Branching for details +
    • Position - Specifies the order of sections in a survey. You can +select after which sections this section shall be +
    • New Page after this section - If set to "No" multiple sections will +be displayed on one page until the first section is met that requires +a page break (regardless of wether it is actualy displayed ot not). A +page break will automatically occur if the next section is a branch +section and the question that determines the branch has not yet been +answered. +
    +Underneath this form there is a link to create or edit a custom +template for rendering of this section. Like this it is possible for a +designer to individually adapt the layout of the section. +

    +For that purpose a default template will be generated which contains +all the questions that are in the Survey. At the moment all survey +styles feature a two-column layout with questions on the left and +widgets on the right side. If you need a different layout you have to +wrap it into a <tr><td colspan=2> tag inside of which you +are free to place whatever layout you want. +

    +The questions are already prefilled from the database, if you want, +you can edit them to your needs. However, please do not change the +<formwidget> and <formgroup> tags, which render the +widgets that will be used for data entry unless you are very sure what +you are doing and retain the original variable names. In general this +should not be necessary. +

    +The <formgroup> tags are for radio button and +checkbox-groups. Inside these groups @formgroup.widget@ is used to +display the radio button or checkbox and @formgroup.label@ holds the +label of this option. For these especially holds what has been said +before: Be careful with changing these. +

    +"Apply" writes the template to the file system, from where it will be +called every time this section is to be displayed. "Erase custom +template" will delete the file and return to normal rendering of the +section. +

    +Underneath this form you will see a preview of the section. This uses +the style selected for the survey, of course. +

    +Please note that the predefined section templates are not tailored to +every survey style but fit best with the Standard template. However, +since you can modify everything, it should be easy to adapt them to +match the rest of the survey, especially if you customize every +section within the survey. + +

    Measurement sections

    +Measurement sections are sections in which all questions are multiple +choice questions and have the same set of possible answers. For +example this could be a number of statements to which the user +answering the survey could state "agree fully", "agree", "unsure", +"disagree", "disagree heavily". Instead of typing all the same +responses over and over again for each question, it is possible to +create a measurement section. +

    +You begin by creating a new section and add one question. Make it a +Multiple Choice (Radio Buttons) and enter the choices you want for +each of the questions. Then choose "edit" next to the name of the +section. Set "Measurement section" to "yes". This first does a check, +if this section can be made a meaurement section, that is, it only +contains multiple choice (radio) questions that have all the same set +of answers. If this check is positive, the section is transformed into +a measurement section. +

    +When adding new questions to a measurement section, you don't need to +do much. you just enter the question text, the type, responses and the +layout options are set automatically. Display also is affected by +choosing a measurement section. The questions in such a section are +arranged in a table with the answers given only once at the top for +easier orientation. + +

    The question catalogue

    +The question catalogue contains questions that are common to multiple +surveys. They can be easily selected from a list to integrate them +into a survey. However, they do not behave exactly as normal +questions. +

    +If a user has already answered a catalogue question in a previous +survey, the answer he gave then will be preselected. Like that the +user won't have to bother answering the same question multiple times. +

    +Furthermore, catalogue questions have the option to associate special +actions with them. These are updating a row in the database or +executing tcl code. However, these catalogue questions can only be +created by site-wide administrators, not by "normal" survey admins. +

    +The definition of catalogue questions is done via the page +"/wherever/survey/is/mounted/admin/predefined-question-admin". +On this page you will find a list of the already defined catalogue +questions. You can edit them there or create new ones. +

    +The creation of catalogue questions is analogous to the creation of +normal questions, only you have to select an action. If you select +"Update DB", you have to give a table name, a column name and a Key +column name to determine which DB row to update. If you want to write +the answer as the new last name of a person into the database, for +example, you would select + +table name: persons +column: last_name +key column: person_id + +The key column will always be matched against the user_id of the user +filling out the survey. +

    +The option "Execute Tcl-Code" ath the moment does the same as the +option "Nothing". The exact behaviour of this option still has to be +defined further. All options share, however, that previously given +answers to a question will be prefilled. If the question is of the +type "DB" and there has not yet been an answer to this question the +value will be prefilled from the given DB row. + + Index: openacs-4/contrib/packages/survey/www/doc/index.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/doc/Attic/index.html,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/doc/index.html 19 Sep 2003 16:48:07 -0000 1.1 @@ -0,0 +1,100 @@ + + + +Survey documentation + + + +

    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.) + +

    Data-Model

    +We use the following tables: + +
      +
    • surveys General Information about a survey, like the + name of the survey, display options etc. +
    • survey-sections A Survey is made up of one or more + sections, which are displayed each on one page, when + taking the survey. In addition to structuring the survey + this allows for branching. Each section is associated to + a survey. +
    • survey_branches This table links sections and + conditions. A branch is a section that is not always + displayed but only if some condition is met, that is, if + a user has given some answer to a specific question + earlier on in the survey. +
    • survey_conditions A condition for executing a certain + branch of a survey. That is a question (which must be + boolean or multipe choice) and one answer to that + question. +
    • survey_questions Contains data about questions. Each + question is associated to a section. +
    • survey_block_questions Block sections are sections + that contain only questions that have the same set of + answers and are arranged as a block, for example having + answers like "Agree fully, agree, unsure, disagree, + disagree heavily" and ask for the attitude of a user + concerning a list of statements. +
    • survey_question_choices For multiple choice + questions, the different choices are held in this table +
    • survey_predefined_questions Holds questions in the + question catalogue. These questions are treated in a + special way. +
    • survey_predef_question_choices Like + survey_question_choices, only forpredefined questions. +
    • survey_templates Holds information about survey + templates. This includes a template_id, that is + referenced in surveys, a file_name (under + /packages/acs-templating/resources/forms/surveys) and a + descriptive name. +
    • survey_responses Describes a user's response to a + survey. The flag "finished_p" allows to look for + unfinished responses of a user. +
    • survey_question_responses The answer of a user to an + individual question. It is possible, that a user answers + multiple times to the same survey, so the answers are + identified by the response_id. +
    + +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

    . + Index: openacs-4/contrib/packages/survey/www/doc/user-interface.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/doc/Attic/user-interface.html,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/survey/www/doc/user-interface.html 19 Sep 2003 16:48:07 -0000 1.1 @@ -0,0 +1,67 @@ + + + +Survey documentation - User interface + + + +

    Survey - User Interface

    + +A package for OpenACS 4.6 + +
    + + +

    User Interface

    + +

    Taking a survey

    +The taking of a survey is quite straightforward. Once the user has +selected a survey, he is presented the questions of the first +section. After he has answered them, they are tested, if they are ok +(e.g. no text answers to number questions) and complete, that is, he +did not omit any questions that were marked as required (with a red +star). +

    +If there is a mistake, there is little page telling so and the user +needs to reanswer the questions. If they were alright, the next +section is displayed. If there are branches, this section can depend +on the choices, the user made. If there are no further sections the +survey is finished and the user is thanked. +

    +In a multisectioned survey, there can be a little status bar in the +top of the survey, indicating the progress towards completion. +

    +If the user leaves the surve before completing it, the survey is +marked as unfinished and the next time he starts this survey he can +continue just where he left. This option is of course not available if +the user is not logged in and responding to a public survey. +

    +If it is possible to edit the responses one has given in a survey, the +prior responses are listed to the user, when he chooses a survey to +take so he can choose to edit one of them. In that case, the answers +he gave that time are already filled in. + +

    Processing the results of a survey

    +There are several ways to process the results of a survey which are +accessible from the administration of the survey. +If you choose to view the results by user you are presented a list of +users who have taken the survey. Selecting a user gives you his +responses to the survey in detail. +

    +Summary gives a summarized view of the results. Multiple choice +questions are added up by response, showing the distribution of +answers. To get more information, there are special drill-down pages to +access the answers to all questions along with the users that gave +these answers. +

    +For more thorough examination it is possible to export the answers in +.csv (Comma Separated Values) format. These data can easily be exported +into other applications for further processing (for example into +Excel). You have the option to download only the responses of +registered users or all responses including not logged-in users. + + Index: openacs-4/contrib/packages/survey/www/graphics/add.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/graphics/Attic/add.gif,v diff -u -N Binary files differ Index: openacs-4/contrib/packages/survey/www/graphics/admin.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/graphics/Attic/admin.gif,v diff -u -N Binary files differ Index: openacs-4/contrib/packages/survey/www/graphics/answer.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/graphics/Attic/answer.gif,v diff -u -N Binary files differ Index: openacs-4/contrib/packages/survey/www/graphics/copy.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/graphics/Attic/copy.gif,v diff -u -N Binary files differ Index: openacs-4/contrib/packages/survey/www/graphics/delete.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/graphics/Attic/delete.gif,v diff -u -N Binary files differ Index: openacs-4/contrib/packages/survey/www/graphics/down.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/graphics/Attic/down.gif,v diff -u -N Binary files differ Index: openacs-4/contrib/packages/survey/www/graphics/edit.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/graphics/Attic/edit.gif,v diff -u -N Binary files differ Index: openacs-4/contrib/packages/survey/www/graphics/new.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/graphics/Attic/new.gif,v diff -u -N Binary files differ Index: openacs-4/contrib/packages/survey/www/graphics/preview.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/graphics/Attic/preview.gif,v diff -u -N Binary files differ Index: openacs-4/contrib/packages/survey/www/graphics/spacer.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/graphics/Attic/spacer.gif,v diff -u -N Binary files differ Index: openacs-4/contrib/packages/survey/www/graphics/up.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/graphics/Attic/up.gif,v diff -u -N Binary files differ Index: openacs-4/contrib/packages/survey/www/graphics/view.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/www/graphics/Attic/view.gif,v diff -u -N Binary files differ