Commit a8833b7b authored by Frank Bergmann's avatar Frank Bergmann

Initial import

parents
<?xml version="1.0"?>
<!-- Generated by the OpenACS Package Manager -->
<package key="simple-survey" url="http://openacs.org/repository/apm/simple-survey" type="apm_application">
<package-name>Simple Survey</package-name>
<pretty-plural>Simple Surveys</pretty-plural>
<initial-install-p>f</initial-install-p>
<singleton-p>f</singleton-p>
<version name="0.2d" url="http://openacs.org/repository/download/apm/simple-survey-0.2d.apm">
<database-support>
<database>oracle</database>
<database>postgresql</database>
</database-support>
<owner url="mailto:nstrug@redhat.com">Nicholas Strugnell</owner>
<summary>Ask users questions and record results.</summary>
<release-date>2001-02-14</release-date>
<vendor url="http://openacs.org">OpenACS</vendor>
<description format="text/html">Simple survey is a survey builder. Surveys can contain questions with different types of answer several types: multiple choice (radio buttons), multiple answer (checkboxes) or free text entry. Multiple choice questions may also be scored on one or more variables.
In general survey is a better choice than simple-survey.
</description>
<requires url="acs-kernel" version="5.0d13"/>
<parameters>
<!-- No version parameters -->
</parameters>
</version>
</package>
This diff is collapsed.
--
-- drop SQL for survsimp package
--
-- by nstrug@arsdigita.com on 29th September 2000
--
-- $Id$
@@ simple-survey-package-drop.sql
drop table survsimp_logic_surveys_map cascade constraints;
drop sequence survsimp_logic_id_sequence;
drop table survsimp_logic;
drop table survsimp_choice_scores cascade constraints;
drop table survsimp_variables_surveys_map cascade constraints;
drop table survsimp_variables;
drop sequence survsimp_variable_id_sequence;
drop view survsimp_question_responses_un;
drop table survsimp_question_responses cascade constraints;
drop view survsimnp_responses_unique;
drop table survsimp_responses cascade constraints;
drop table survsimp_question_choices cascade constraints;
drop sequence survsimp_choice_id_sequence;
drop table survsimp_questions cascade constraints;
drop table survsimp_surveys cascade constraints;
-- nuke all created objects
-- need to do this before nuking the types
delete from acs_objects where object_type = 'survsimp_response';
delete from acs_objects where object_type = 'survsimp_question';
delete from acs_objects where object_type = 'survsimp_survey';
begin
acs_rel_type.drop_type('user_blob_response_rel');
acs_object_type.drop_type ('survsimp_response');
acs_object_type.drop_type ('survsimp_question');
acs_object_type.drop_type ('survsimp_survey');
acs_privilege.remove_child ('admin','survsimp_admin_survey');
acs_privilege.remove_child ('read','survsimp_take_survey');
acs_privilege.remove_child ('survsimp_admin_survey','survsimp_delete_question');
acs_privilege.remove_child ('survsimp_admin_survey','survsimp_modify_question');
acs_privilege.remove_child ('survsimp_admin_survey','survsimp_create_question');
acs_privilege.remove_child ('survsimp_admin_survey','survsimp_delete_survey');
acs_privilege.remove_child ('survsimp_admin_survey','survsimp_modify_survey');
acs_privilege.remove_child ('survsimp_admin_survey','survsimp_create_survey');
acs_privilege.drop_privilege('survsimp_admin_survey');
acs_privilege.drop_privilege('survsimp_take_survey');
acs_privilege.drop_privilege('survsimp_delete_question');
acs_privilege.drop_privilege('survsimp_modify_question');
acs_privilege.drop_privilege('survsimp_create_question');
acs_privilege.drop_privilege('survsimp_delete_survey');
acs_privilege.drop_privilege('survsimp_modify_survey');
acs_privilege.drop_privilege('survsimp_create_survey');
end;
/
show errors
-- gilbertw - logical_negation is defined in utilities-create.sql in acs-kernel
-- drop function logical_negation;
This diff is collapsed.
drop package survsimp_response;
drop package survsimp_question;
drop package survsimp_survey;
This diff is collapsed.
This diff is collapsed.
--
-- drop SQL for survsimp package
--
-- by nstrug@arsdigita.com on 29th September 2000
--
-- $Id$
select drop_package('survsimp_response');
select drop_package('survsimp_question');
select drop_package('survsimp_survey');
drop table survsimp_logic_surveys_map;
drop view survsimp_logic_id_sequence;
drop sequence survsimp_logic_id_seq;
drop table survsimp_logic;
drop table survsimp_choice_scores;
drop table survsimp_variables_surveys_map;
drop table survsimp_variables;
drop view survsimp_variable_id_sequence;
drop sequence survsimp_variable_id_seq;
drop view survsimp_question_responses_un;
drop table survsimp_question_responses;
drop view survsimp_responses_unique;
drop table survsimp_responses;
drop table survsimp_question_choices;
drop view survsimp_choice_id_sequence;
drop sequence survsimp_choice_id_seq;
drop table survsimp_questions;
drop table survsimp_surveys;
-- nuke all created objects
-- need to do this before nuking the types
delete from acs_objects where object_type = 'survsimp_response';
delete from acs_objects where object_type = 'survsimp_question';
delete from acs_objects where object_type = 'survsimp_survey';
create function inline_0 ()
returns integer as '
begin
PERFORM acs_rel_type__drop_type (''user_blob_response_rel'',''f'');
PERFORM acs_object_type__drop_type (''survsimp_response'',''f'');
PERFORM acs_object_type__drop_type (''survsimp_question'',''f'');
PERFORM acs_object_type__drop_type (''survsimp_survey'',''f'');
PERFORM acs_privilege__remove_child (''admin'',''survsimp_admin_survey'');
PERFORM acs_privilege__remove_child (''read'',''survsimp_take_survey'');
PERFORM acs_privilege__remove_child (''survsimp_admin_survey'',''survsimp_delete_question'');
PERFORM acs_privilege__remove_child (''survsimp_admin_survey'',''survsimp_modify_question'');
PERFORM acs_privilege__remove_child (''survsimp_admin_survey'',''survsimp_create_question'');
PERFORM acs_privilege__remove_child (''survsimp_admin_survey'',''survsimp_delete_survey'');
PERFORM acs_privilege__remove_child (''survsimp_admin_survey'',''survsimp_modify_survey'');
PERFORM acs_privilege__remove_child (''survsimp_admin_survey'',''survsimp_create_survey'');
PERFORM acs_privilege__drop_privilege(''survsimp_admin_survey'');
PERFORM acs_privilege__drop_privilege(''survsimp_take_survey'');
PERFORM acs_privilege__drop_privilege(''survsimp_delete_question'');
PERFORM acs_privilege__drop_privilege(''survsimp_modify_question'');
PERFORM acs_privilege__drop_privilege(''survsimp_create_question'');
PERFORM acs_privilege__drop_privilege(''survsimp_delete_survey'');
PERFORM acs_privilege__drop_privilege(''survsimp_modify_survey'');
PERFORM acs_privilege__drop_privilege(''survsimp_create_survey'');
return 0;
end;' language 'plpgsql';
select inline_0 ();
drop function inline_0 ();
-- gilbertw - logical_negation is defined in utilities-create.sql in acs-kernel
-- drop function logical_negation(boolean);
<?xml version="1.0"?>
<queryset>
<rdbms><type>oracle</type><version>8.1.6</version></rdbms>
<fullquery name="get_date">
<querytext>
select to_char(creation_date, 'DD/MM/YYYY')
from acs_objects
where object_id = :response_id
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>postgresql</type><version>7.1</version></rdbms>
<fullquery name="get_date">
<querytext>
select to_char(creation_date, 'DD/MM/YYYY')
from acs_objects
where object_id = :response_id
</querytext>
</fullquery>
</queryset>
This diff is collapsed.
<?xml version="1.0"?>
<queryset>
<fullquery name="survsimp_question_properties">
<querytext>
select
survey_id,
sort_key,
question_text,
abstract_data_type,
required_p,
active_p,
presentation_type,
presentation_options,
presentation_alignment,
creation_user,
creation_date
from
survsimp_questions, acs_objects
where
object_id = question_id
and question_id = :question_id
</querytext>
</fullquery>
<fullquery name="survsimp_question_choices">
<querytext>
select choice_id, label
from survsimp_question_choices
where question_id = :question_id
order by sort_order
</querytext>
</fullquery>
<fullquery name="sursimp_question_choices_2">
<querytext>
select choice_id, label
from survsimp_question_choices
where question_id = :question_id
order by sort_order
</querytext>
</fullquery>
<fullquery name="sursimp_question_choices_3">
<querytext>
select * from survsimp_question_choices
where question_id = :question_id
order by sort_order
</querytext>
</fullquery>
<fullquery name="survsimp_label_list">
<querytext>
select label
from survsimp_question_choices, survsimp_question_responses
where survsimp_question_responses.question_id = :question_id
and survsimp_question_responses.response_id = :response_id
and survsimp_question_choices.choice_id = survsimp_question_responses.choice_id
</querytext>
</fullquery>
<fullquery name="survsimp_creator_p">
<querytext>
select creation_user
from survsimp_surveys
where survey_id = :survey_id
</querytext>
</fullquery>
<fullquery name="survsimp_responses_new">
<querytext>
select survey_id, name, description, u.user_id, first_names || ' ' || last_name as creator_name, creation_date
from survsimp_surveys s, $users_table u
where s.creation_user = u.user_id
and creation_date> :since_when
order by creation_date desc
</querytext>
</fullquery>
<fullquery name="survsimp_id_from_shortname">
<querytext>
select survey_id from survsimp_surveys where lower(short_name) = lower(:short_name)
</querytext>
</fullquery>
<fullquery name="get_response_id">
<querytext>
select response_id
from acs_objects, survsimp_responses
where object_id = response_id
and creation_user = :user_id
and survey_id = :survey_id
and creation_date = (select max(creation_date)
from survsimp_responses, acs_objects
where object_id = response_id
and creation_user = :user_id
and survey_id = :survey_id)
</querytext>
</fullquery>
<fullquery name="get_score">
<querytext>
select
sum(score)
from survsimp_choice_scores,
survsimp_question_responses, survsimp_variables
where
survsimp_choice_scores.choice_id = survsimp_question_responses.choice_id
and survsimp_choice_scores.variable_id = survsimp_variables.variable_id
and survsimp_question_responses.response_id = :response_id
</querytext>
</fullquery>
</queryset>
<master>
<property name=title>Edit Description Confirmation</property>
<property name="context">@context;noquote@</property>
Here is how your survey description will appear:
<blockquote><p>
@description@
<form method=post action="<%= [ns_conn url] %>">
<%= [export_form_vars description desc_html survey_id] %>
<input type=hidden name=checked_p value="t">
<br><center><input type=submit value="Confirm"></center>
</form>
</blockquote>
<font size=-1 face="verdana, arial, helvetica">
Note: if the text above has a bunch of visible HTML tags then you probably
should have selected "HTML" rather than "Plain Text". If it is all smashed together
and you want the original line breaks saved then choose "Preformatted Text".
Use your browser's Back button to return to the submission form.
</font>
# /www/survsimp/admin/description-edit-2.tcl
ad_page_contract {
Updates database with the new description
information and return user to the main survey page.
@param survey_id survey which description we're updating
@param desc_html is the description html or plain text
@param description text of survey description
@param checked_p confirmation flag
@author jsc@arsdigita.com
@author nstrug@arsdigita.com
@creation-date February 16, 2000
@cvs-id $Id$
} {
survey_id:integer
desc_html:notnull
description:html
{checked_p "f"}
}
ad_require_permission $survey_id survsimp_modify_survey
set exception_count 0
set exception_text ""
if { [empty_string_p $description] } {
incr exception_count
append exception_text "<li>You didn't enter a description for this survey.\n"
}
if {$exception_count > 0} {
ad_return_complaint $exception_count $exception_text
ad_script_abort
}
if {$checked_p == "f"} {
set context [list [list "one?[export_url_vars survey_id]" "Administer Survey"] "Confirm Description"]
switch $desc_html {
"t" {
}
"pre" {
regsub "\[ \012\015\]+\$" $description {} description
set description "<pre>[ns_quotehtml $description]</pre>"
set desc_html "t"
}
default {
set description "[util_convert_plaintext_to_html $description]"
}
}
} else {
db_dml survsimp_update_description "update survsimp_surveys
set description = :description,
description_html_p = :desc_html
where survey_id = :survey_id"
db_release_unused_handles
ad_returnredirect "one?[export_url_vars survey_id]"
ad_script_abort
}
<?xml version="1.0"?>
<queryset>
<fullquery name="survsimp_update_description">
<querytext>
update survsimp_surveys
set description = :description,
description_html_p = :desc_html
where survey_id = :survey_id
</querytext>
</fullquery>
</queryset>
<master>
<property name=title>@survey_name;noquote@: Edit Description</property>
<property name="context">@context;noquote@</property>
<blockquote>
Edit and submit to change the description for this survey:
<form method=post action="description-edit-2">
<%= [export_form_vars survey_id] %>
<textarea name=description rows=10 cols=65>@description@</textarea>
<br>
The description above is:
<input type=radio name=desc_html value="pre">Preformatted text
<%= [survsimp_bt_mergepiece "<input type=radio name=desc_html value=\"f\">Plain text
<input type=radio name=desc_html value=\"t\">" $html_p_set] %> HTML
<P>
<center>
<input type=submit value=Update>
</center>
</blockquote>
ad_page_contract {
Form to allow user to the description of a survey.
@param survey_id integer denoting survey whose description we're changing
@author Jin Choi (jsc@arsdigita.com)
@author nstrug@arsdigita.com
@creation-date February 16, 2000
@cvs-id $Id$
} {
survey_id:integer
}
ad_require_permission $survey_id survsimp_modify_survey
db_1row survey_properites "select name as survey_name, description, description_html_p as desc_html
from survsimp_surveys
where survey_id = :survey_id"
set html_p_set [ns_set create]
ns_set put $html_p_set desc_html $desc_html
set context [list [list "one?[export_url_vars survey_id]" "Administer Survey"] "Edit Description"]
<?xml version="1.0"?>
<queryset>
<fullquery name="survey_properites">
<querytext>
select name as survey_name, description, description_html_p as desc_html
from survsimp_surveys
where survey_id = :survey_id
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>oracle</type><version>8.1.6</version></rdbms>
<fullquery name="update_logic">
<querytext>
update survsimp_logic
set logic = empty_clob()
where logic_id = :logic_id
returning logic into :1
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>postgresql</type><version>7.1</version></rdbms>
<fullquery name="update_logic">
<querytext>
update survsimp_logic
set logic = :logic
where logic_id = :logic_id
</querytext>
</fullquery>
</queryset>
ad_page_contract {
Process response from edit-logic.tcl
@param logic_id id of logic record to update
@param survey_id id of survey to return to
@param logic new value for logic
@author Nick Strugnell (nstrug@arsdigita.com)
@creation-date September 14, 2000
@cvs-id $Id$
} {
logic_id:integer,notnull
survey_id:integer,notnull
logic:allhtml,notnull
}
ad_require_permission $survey_id survsimp_modify_survey
db_dml update_logic "update survsimp_logic
set logic = empty_clob()
where logic_id = :logic_id
returning logic into :1" -clobs [list $logic]
db_release_unused_handles
ad_returnredirect "one?survey_id=$survey_id"
ad_page_contract {
This page is used to edit the logic used by scored surveys to determine actions based on the score.
@param survey_id integer denoting survey to edit
@author Nick Strugnell (nstrug@arsdigita.com)
@creation-date September 14, 2000
@cvs-id $Id$
} {
survey_id:integer
}
ad_require_permission $survey_id survsimp_modify_survey
set exception_count 0
set exception_text ""
set type [db_string get_survey_type "select type from survsimp_surveys where survey_id = :survey_id"]
if { $type != "scored" } {
incr exception_count
append exception_text "<li>Only scored surveys have editable logic.\n"
}
if { $exception_count > 0 } {
ad_return_complaint $exception_count $exception_text
}
# get the existing logic
set survey_name [db_string set_survey_name "select name from survsimp_surveys where survey_id = :survey_id"]
db_1row get_logic "select logic, survsimp_logic.logic_id from survsimp_logic, survsimp_logic_surveys_map
where survsimp_logic.logic_id = survsimp_logic_surveys_map.logic_id
and survey_id = :survey_id"
db_release_unused_handles
doc_return 200 text/html "[ad_header "Edit Survey Logic"]
<h2>$survey_name</h2>
[ad_context_bar [list "./" "Simple Survey Admin"] [list "one?[export_url_vars survey_id]" "Administer Survey"] "Edit Logic"]
<hr>
<form method=post action=\"edit-logic-2\">
[export_form_vars logic_id survey_id]
Logic:
<blockquote>
<textarea name=logic wrap=off rows=20 cols=65>$logic</textarea>
<p>
<center>
<input type=submit value=\"Continue\">
</center>
</form>
[ad_footer]
"
<?xml version="1.0"?>
<queryset>
<fullquery name="get_survey_type">
<querytext>
select type from survsimp_surveys where survey_id = :survey_id
</querytext>
</fullquery>
<fullquery name="set_survey_name">
<querytext>
select name from survsimp_surveys where survey_id = :survey_id
</querytext>
</fullquery>
<fullquery name="get_logic">
<querytext>
select logic, survsimp_logic.logic_id from survsimp_logic, survsimp_logic_surveys_map
where survsimp_logic.logic_id = survsimp_logic_surveys_map.logic_id
and survey_id = :survey_id
</querytext>
</fullquery>
</queryset>
<master>
<property name=title>Survey Administration</property>
<property name="context">@context;noquote@</property>
<ul>
<multiple name=surveys>
<group column="enabled_p">
<li> <a href=one?survey_id=@surveys.survey_id@>@surveys.name@</a>
</group>
</multiple>
<p>
<li> <a href=survey-create>New Survey</a>
</ul>
# /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
@creation-date 3rd October, 2000
@cvs-id $Id$
} {
}
set context [list "Survey Admin"]
set package_id [ad_conn package_id]
# bounce the user if they don't have permission to admin surveys
ad_require_permission $package_id survsimp_admin_survey
set disabled_header_written_p 0
db_multirow surveys select_surveys "select survey_id, name, enabled_p
from survsimp_surveys
where package_id= :package_id
order by enabled_p desc, upper(name)"
<?xml version="1.0"?>
<queryset>
<fullquery name="survsimp_surveys">
<querytext>
select survey_id, name, enabled_p
from survsimp_surveys
where package_id= :package_id
order by enabled_p desc, upper(name)
</querytext>
</fullquery>
</queryset>
ad_page_contract {
Modify question responses
@param survey_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)
@creation-date September 15, 2000
@cvs-id $Id$
} {
survey_id:integer,notnull
question_id:integer,notnull
{responses:multiple ""}
{scores:multiple,array,integer ""}
{variable_id_list ""}
{choice_id_list ""}
}
ad_require_permission $survey_id survsimp_modify_question
db_transaction {
set i 0
foreach choice_id $choice_id_list {
set trimmed_response [string trim [lindex $responses $i]]
db_dml update_survsimp_question_choice "update survsimp_question_choices
set label = :trimmed_response
where choice_id = :choice_id"
foreach variable_id $variable_id_list {
set score_list $scores($variable_id)
set score [lindex $score_list $i]
db_dml update_survsimp_scores "update survsimp_choice_scores
set score = :score
where choice_id = :choice_id
and variable_id = :variable_id"
}
incr i
}
}
db_release_unused_handles
ad_returnredirect "one?survey_id=$survey_id"
<?xml version="1.0"?>
<queryset>
<fullquery name="update_survsimp_question_choice">
<querytext>
update survsimp_question_choices
set label = :trimmed_response
where choice_id = :choice_id
</querytext>
</fullquery>
<fullquery name="update_survsimp_scores">
<querytext>
update survsimp_choice_scores
set score = :score
where choice_id = :choice_id
and variable_id = :variable_id
</querytext>
</fullquery>
</queryset>
ad_page_contract {
Modify question responses and scores
@param question_id which question we'll be changing responses of
@param survey_id survey providing this question
@author Nick Strugnell (nstrug@arsdigita.com)
@creation-date September 15, 2000
@cvs-id $Id$
} {
question_id:integer
survey_id:integer
}
ad_require_permission $survey_id survsimp_modify_question
set survey_name [db_string survey_name_from_id "select name from survsimp_surveys where survey_id=:survey_id" ]
set question_text [db_string survsimp_question_text_from_id "select question_text
from survsimp_questions
where question_id = :question_id" ]
set table_html "<table border=0>
<tr><th>Response</th>"
set variable_id_list [list]
db_foreach get_variable_names "select variable_name, survsimp_variables.variable_id as variable_id
from survsimp_variables, survsimp_variables_surveys_map
where survsimp_variables.variable_id = survsimp_variables_surveys_map.variable_id
and survey_id = :survey_id
order by variable_name" {
lappend variable_id_list $variable_id
append table_html "<th>$variable_name</th>"
}
append table_html "</tr>\n"
set choice_id_list [list]
db_foreach get_choices "select choice_id, label from survsimp_question_choices where question_id = :question_id order by choice_id" {
lappend choice_id_list $choice_id
append table_html "<tr><td align=center><input name=\"responses\" value=\"$label\" size=80></td>"
db_foreach get_scores "select score, survsimp_variables.variable_id as variable_id
from survsimp_choice_scores, survsimp_variables
where survsimp_choice_scores.choice_id = :choice_id
and survsimp_choice_scores.variable_id = survsimp_variables.variable_id
order by variable_name" {
append table_html "<td align=center><input name=\"scores.$variable_id\" value=\"$score\" size=2></td>"
}
append table_html "</tr>\n"
}
append table_html "</table>\n"
db_release_unused_handles
doc_return 200 text/html "[ad_header "Modify Responses"]
<h2>$survey_name</h2>
[ad_context_bar [list "one?[export_url_vars survey_id]" "Administer Survey"] "Modify Question Responses"]
<hr>
Question: $question_text
<p>
<form action=\"modify-responses-2\" method=get>
[export_form_vars survey_id question_id choice_id_list variable_id_list]
$table_html
<p>
<center>
<input type=submit value=\"Submit\">
</center>
</form>
[ad_footer]
"
<?xml version="1.0"?>
<queryset>
<fullquery name="survey_name_from_id">
<querytext>
select name from survsimp_surveys where survey_id=:survey_id
</querytext>
</fullquery>
<fullquery name="survsimp_question_text_from_id">
<querytext>
select question_text
from survsimp_questions
where question_id = :question_id
</querytext>
</fullquery>
<fullquery name="get_variable_names">
<querytext>
select variable_name, survsimp_variables.variable_id as variable_id
from survsimp_variables, survsimp_variables_surveys_map
where survsimp_variables.variable_id = survsimp_variables_surveys_map.variable_id
and survey_id = :survey_id
order by variable_name
</querytext>
</fullquery>
<fullquery name="get_choices">
<querytext>
select choice_id, label from survsimp_question_choices where question_id = :question_id order by choice_id
</querytext>
</fullquery>
<fullquery name="get_scores">
<querytext>
select score, survsimp_variables.variable_id as variable_id
from survsimp_choice_scores, survsimp_variables
where survsimp_choice_scores.choice_id = :choice_id
and survsimp_choice_scores.variable_id = survsimp_variables.variable_id
order by variable_name
</querytext>
</fullquery>
</queryset>
# /www/survsimp/admin/description-edit-2.tcl
ad_page_contract {
Updates database with the new name
information and return user to the main survey page.
@param survey_id survey which description we're updating
@param desc_html is the description html or plain text
@param description text of survey description
@param checked_p confirmation flag
@author jsc@arsdigita.com
@author nstrug@arsdigita.com
@creation-date February 16, 2000
@cvs-id $Id$
} {
survey_id:integer
name:trim,notnull
}
ad_require_permission $survey_id survsimp_modify_survey
set exception_count 0
set exception_text ""
db_dml survsimp_update_name "update survsimp_surveys
set name= :name, short_name= :name
where survey_id = :survey_id"
ad_returnredirect "one?[export_url_vars survey_id]"
<master>
<property name=title>@survey_name;noquote@: Edit Name</property>
<property name="context">@context;noquote@</property>
<blockquote>
Edit and submit to change the name for this survey:
<form method=post action="name-edit-2">
<%= [export_form_vars survey_id] %>
<INPUT TYPE=text name=name value="@survey_name@" size=80>
<br>
<center>
<input type=submit value=Update>
</center>
</blockquote>
ad_page_contract {
Edit the name of the survey
@param survey_id integer denoting survey whose description we're changing
@author Jin Choi (jsc@arsdigita.com)
@author nstrug@arsdigita.com
@creation-date February 16, 2000
@cvs-id $Id$
} {
survey_id:integer
}
ad_require_permission $survey_id survsimp_modify_survey
db_1row survey_properties "select name as survey_name, description, description_html_p as desc_html
from survsimp_surveys
where survey_id = :survey_id"
set html_p_set [ns_set create]
ns_set put $html_p_set desc_html $desc_html
set context [list [list "one?[export_url_vars survey_id]" "Administer Survey"] "Edit Name"]
ad_return_template
ad_page_contract {
Display the filled-out survey for a single user.
@param user_id user whose response we're viewing
@param survey_id survey we're viewing
@author jsc@arsdigita.com
@author nstrug@arsdigita.com
@creation-date February 11, 2000
@cvs-id $Id$
} {
user_id:integer
survey_id:integer
}
ad_require_permission $survey_id survsimp_admin_survey
set survey_exists_p [db_0or1row survsimp_survey_properties "select name as survey_name, description, type
from survsimp_surveys
where survey_id = :survey_id" ]
if { !$survey_exists_p } {
ad_return_error "Not Found" "Could not find survey #$survey_id"
return
}
# survey_name and description are now set
set user_exists_p [db_0or1row user_name_from_id "select first_names, last_name from persons where person_id = :user_id" ]
if { !$user_exists_p } {
ad_return_error "Not Found" "Could not find user #$user_id"
return
}
set whole_page "[ad_header "Response from $first_names $last_name"]
<h2>Response from $first_names $last_name</h2>
[ad_context_bar [list "" "Simple Survey Admin"] \
[list "one?survey_id=$survey_id" "Administer Survey"] \
[list "respondents?survey_id=$survey_id" "Respondents"] \
"One Respondent"]
<hr>
Here is what <a href=\"/shared/community-member?[export_url_vars user_id]\">$first_names $last_name</a> had to say in response to $survey_name:
<p>
"
# now we have to query Oracle to find out what the questions are and
# how to present them
set response_id_date_list [db_list_of_lists survsimp_survey_response_dates_for_users "select response_id, creation_date
from survsimp_responses, acs_objects
where response_id = object_id
and creation_user = :user_id
and survey_id = :survey_id
order by creation_date desc" ]
# function to insert survey type-specific form html
proc survey_specific_html { type response_id } {
switch $type {
"general" {
set return_html ""
}
"scored" {
set return_html "<table border=0 align=center>\n<tr><th>Variable</th><th>Score</th>\n"
db_foreach get_survey_scores "select variable_name, sum(score) as sum_score
from survsimp_choice_scores, survsimp_question_responses, survsimp_variables
where survsimp_choice_scores.choice_id = survsimp_question_responses.choice_id
and survsimp_choice_scores.variable_id = survsimp_variables.variable_id
and survsimp_question_responses.response_id = :response_id
group by variable_name" {
append return_html "<tr><th>$variable_name</th><td align=center>$sum_score</td></tr>\n"
}
append return_html "</table>\n"
}
default {
set return_html ""
}
}
return $return_html
}
if { ![empty_string_p $response_id_date_list] } {
foreach response_id_date $response_id_date_list {
append whole_page "<h3>Response on [lindex $response_id_date 1]</h3>\n"
set response_id [lindex $response_id_date 0]
append whole_page [survey_specific_html $type $response_id]
append whole_page "[survsimp_answer_summary_display $response_id 1 ]
<hr width=50%>"
}
}
doc_return 200 text/html "$whole_page
[ad_footer]"
<?xml version="1.0"?>
<queryset>
<fullquery name="survsimp_survey_properties">
<querytext>
select name as survey_name, description, type
from survsimp_surveys
where survey_id = :survey_id
</querytext>
</fullquery>
<fullquery name="user_name_from_id">
<querytext>
select first_names, last_name from persons where person_id = :user_id
</querytext>
</fullquery>
<fullquery name="survsimp_survey_response_dates_for_users">
<querytext>
select response_id, creation_date
from survsimp_responses, acs_objects
where response_id = object_id
and creation_user = :user_id
and survey_id = :survey_id
order by creation_date desc
</querytext>
</fullquery>
<fullquery name="get_survey_scores">
<querytext>
select variable_name, sum(score) as sum_score
from survsimp_choice_scores, survsimp_question_responses, survsimp_variables
where survsimp_choice_scores.choice_id = survsimp_question_responses.choice_id
and survsimp_choice_scores.variable_id = survsimp_variables.variable_id
and survsimp_question_responses.response_id = :response_id
group by variable_name
</querytext>
</fullquery>
</queryset>
<master>
<property name=title>One Survey: @survey_name;noquote@</property>
<property name="context">@context;noquote@</property>
<ul>
<li>Created by: <a href="<%= [acs_community_member_url -user_id $creation_user] %>">@creator_name@</a>
<li>Name: @survey_name@ <font size=-1>[ <a href="name-edit?survey_id=@survey_id@">edit</a> ]</font>
<li>Created: <%= [util_AnsiDatetoPrettyDate $creation_date] %>
<li>Status: @survey_status@ <font size=-1>@toggle_enabled_link;noquote@</font>
<li>Display Type: @display_type@ <font size=-1>@display_type_toggle;noquote@</font>
<li>Responses per user: @survey_response_limit@ <font size=-1>[ <a href="response-limit-toggle?survey_id=@survey_id@">@response_limit_toggle@</a> @response_editable_link;noquote@ ]</font>
<li>Description: @survey_description@ <font size=-1>[ <a href="description-edit?survey_id=@survey_id@">edit</a> ]</font>
<li>Type: @type@
<li>View responses: <a href="respondents?survey_id=@survey_id@">by user</a> | <a href="responses?survey_id=@survey_id@">summary</a>
@survey_specific_html;noquote@
</ul>
<p>
@questions_summary;noquote@
ad_page_contract {
This page allows the admin to administer a single survey.
@param survey_id integer denoting survey we're administering
@author jsc@arsdigita.com
@author nstrug@arsdigita.com
@creation-date February 9, 2000
@cvs-id $Id$
} {
survey_id:integer
}
ad_require_permission $survey_id survsimp_admin_survey
set package_id [ad_conn package_id]
# Get the survey information.
db_1row survsimp_properties "select name as survey_name,
short_name, description as survey_description,
first_names || ' ' || last_name as creator_name, creation_user,
creation_date, decode(enabled_p, 't', 'Enabled', 'f', 'Disabled') as survey_status, enabled_p,
decode(single_response_p, 't', 'One', 'f', 'Multiple') as survey_response_limit,
decode(single_editable_p, 't', 'Editable', 'f', 'Non-editable') as survey_editable_single, type, display_type
from survsimp_surveys, acs_objects, persons
where object_id = survey_id
and person_id = creation_user
and survey_id = :survey_id
and package_id= :package_id"
if {$survey_response_limit == "One"} {
set response_limit_toggle "allow Multiple"
if {$survey_editable_single == "Editable"} {
set response_editable_link "| Editable: <a href=\"response-editable-toggle?[export_url_vars survey_id]\">make non-editable</a>"
} else {
set response_editable_link "| Non-editable: <a href=\"response-editable-toggle?[export_url_vars survey_id]\">make editable</a>"
}
} else {
set response_limit_toggle "limit to One"
set response_editable_link ""
}
# allow site-wide admins to enable/disable surveys directly from here
set target "one?[export_url_vars survey_id]"
set toggle_enabled_link "\[ <a href=\"survey-toggle?[export_url_vars survey_id enabled_p target]\">"
if {$enabled_p == "t"} {
append toggle_enabled_link "Disable"
} else {
append toggle_enabled_link "Enable"
}
append toggle_enabled_link "</a> \]"
# Display Type (ben)
set display_type_toggle "\[ "
set d_count 0
foreach one_disp_type [survsimp_display_types] {
if {$one_disp_type == $display_type} {
continue
}
if {$d_count > 0} {
append display_type_toggle " | "
}
incr d_count
append display_type_toggle "<a href=survey-display-type-edit?survey_id=$survey_id&display_type=$one_disp_type>$one_disp_type</a>"
}
append display_type_toggle " \]"
set questions_summary "<form><ol>\n"
set count 0
# Questions summary.
proc survey_specific_question_option_html { type survey_id question_id } {
switch $type {
"general" {
set return_html ""
}
"scored" {
set return_html "<a href=\"modify-responses?[export_url_vars survey_id question_id]\">modify responses</a>"
}
default {
set return_html ""
}
return $return_html
}
}
db_foreach sursimp_survey_questions "select question_id, sort_key, active_p, required_p
from survsimp_questions
where survey_id = :survey_id
order by sort_key" {
set question_options [list "<a href=\"question-modify-text?[export_url_vars question_id survey_id]\">modify text</a>" "<a href=\"question-delete?question_id=$question_id\">delete</a>" "<a href=\"question-add?[export_url_vars survey_id]&after=$sort_key\">add new question</a>"]
if { $count > 0 } {
lappend question_options "<a href=\"question-swap?[export_url_vars survey_id sort_key]\">swap with prev</a>"
}
if {$active_p == "t"} {
lappend question_options "Active: <a href=\"question-active-toggle?[export_url_vars survey_id question_id active_p]\">inactivate</a>"
if {$required_p == "t"} {
lappend question_options "Response Required: <a href=\"question-required-toggle?[export_url_vars survey_id question_id required_p]\">don't require</a>"
} else {
lappend question_options "Response Not Required: <a href=\"question-required-toggle?[export_url_vars survey_id question_id required_p]\">require</a>"
}
} else {
lappend question_options "Inactive: <a href=\"question-active-toggle?[export_url_vars survey_id question_id active_p]\">activate</a>"
}
lappend question_options [survey_specific_question_option_html $type $survey_id $question_id]
append questions_summary "
<li>[survsimp_question_display $question_id]
<br>
<font size=-1>
\[ [join $question_options " | "] \]
</font>
<p>"
incr count
}
if {$count == 0} {
append questions_summary "<p><a href=\"question-add?survey_id=$survey_id\">Add a question</a>\n"
}
append questions_summary "</ol></form>\n"
proc survey_specific_html { type } {
switch $type {
"general" {
set return_html ""
}
"scored" {
upvar survey_id local_survey_id
set return_html "<li><a href=\"edit-logic?survey_id=$local_survey_id\">Edit survey logic</a>"
}
default {
set return_html ""
}
return $return_html
}
}
set context [list "Administer Survey"]
set survey_specific_html [survey_specific_html $type]
ad_return_template
<?xml version="1.0"?>
<queryset>
<fullquery name="survsimp_properties">
<querytext>
select name as survey_name,
short_name, description as survey_description,
first_names || ' ' || last_name as creator_name, creation_user,
creation_date, (case when enabled_p = 't' then 'Enabled' when enabled_p = 'f' then 'Disabled' end) as survey_status, enabled_p,
(case when single_response_p = 't' then 'One' when single_response_p = 'f' then 'Multiple' end) as survey_response_limit,
(case when single_editable_p = 't' then 'Editable' when single_editable_p = 'f' then 'Non-editable' end) as survey_editable_single, type,display_type
from survsimp_surveys, acs_objects, persons
where object_id = survey_id
and person_id = creation_user
and survey_id = :survey_id
and package_id= :package_id
</querytext>
</fullquery>
<fullquery name="sursimp_survey_questions">
<querytext>
select question_id, sort_key, active_p, required_p
from survsimp_questions
where survey_id = :survey_id
order by sort_key
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>oracle</type><version>8.1.6</version></rdbms>
<fullquery name="survsimp_question_required_toggle">
<querytext>
update survsimp_questions set active_p = util.logical_negation(active_p)
where survey_id = :survey_id
and question_id = :question_id
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>postgresql</type><version>7.1</version></rdbms>
<fullquery name="survsimp_question_required_toggle">
<querytext>
update survsimp_questions set active_p = util__logical_negation(active_p)
where survey_id = :survey_id
and question_id = :question_id
</querytext>
</fullquery>
</queryset>
# /www/survsimp/admin/question-active-toggle.tcl
ad_page_contract {
Toggles if a response to required for a given question.
@param survey_id survey we're operating with
@param question_id denotes which question in survey we're updating
@cvs-id $Id$
} {
survey_id:integer
question_id:integer
}
ad_require_permission $survey_id survsimp_admin_survey
db_dml survsimp_question_required_toggle "update survsimp_questions set active_p = util.logical_negation(active_p)
where survey_id = :survey_id
and question_id = :question_id"
db_release_unused_handles
ad_returnredirect "one?[export_url_vars survey_id]"
<master>
<property name=title>Survey Administration: Add a Question (cont.)</property>
<property name="context">@context;noquote@</property>
<form action="question-add-3" method=post>
@form_var_list;noquote@
Question:
<blockquote>
@question_text@
</blockquote>
@presentation_options_html;noquote@
@response_type_html;noquote@
@response_fields;noquote@
<p>
Response Location: <input type=radio name=presentation_alignment value="beside"> Beside the question <input type=radio name=presentation_alignment value="below" checked> Below the question
<p>
<center>
<input type=submit value="Submit">
</center>
</form>
# /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 survey_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
@creation-date February 9, 2000
@cvs-id $Id$
} {
survey_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 survsimp_create_question
set question_id [db_nextval acs_object_id_seq]
db_1row survsimp_survey_properties {select name, description, type
from survsimp_surveys
where survey_id = :survey_id}
set exception_count 0
set exception_text ""
if { $type != "general" && $type != "scored" } {
incr exception_count
append exception_text "<li>Surveys of type $type are not currently available\n"
}
if { $presentation_type == "upload_file" } {
incr exception_count
append exception_text "<li>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 {select count(variable_name) as n_variables
from survsimp_variables, survsimp_variables_surveys_map
where survsimp_variables.variable_id = survsimp_variables_surveys_map.variable_id
and survey_id = :survey_id}
set response_fields "<table border=0>
<tr><th>Answer Text</th><th colspan=$n_variables>Score</th></tr>
<tr><td></td>"
set sql_query "select variable_name, survsimp_variables.variable_id as variable_id
from survsimp_variables, survsimp_variables_surveys_map
where survsimp_variables.variable_id = survsimp_variables_surveys_map.variable_id
and survey_id = :survey_id order by survsimp_variables.variable_id"
set variable_id_list [list]
db_foreach select_variable_names $sql_query {
lappend variable_id_list $variable_id
append response_fields "<th>$variable_name</th>"
}
append response_fields "</tr>\n"
for {set response 0} {$response < $n_responses} {incr response} {
append response_fields "<tr><td align=center><input type=text name=\"responses\" size=80></td>"
for {set variable 0} {$variable < $n_variables} {incr variable} {
append response_fields "<td align=center><input type=text name=\"scores.$variable\" size=2></td>"
}
append response_fields "</tr>\n"
}
append response_fields "</table>\n"
set response_type_html "<input type=hidden name=abstract_data_type value=\"choice\">"
set presentation_options_html ""
set form_var_list [export_form_vars survey_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.
set presentation_options ""
switch -- $presentation_type {
"textbox" {
set presentation_options "<select name=textbox_size>
<option value=small>Small</option>
<option value=medium>Medium</option>
<option value=large>Large</option>
</select>"
}
"textarea" {
set presentation_options "Rows: <input name=textarea_rows size=3> Columns: <input name=textarea_cols size=3>"
}
}
set presentation_options_html ""
if { ![empty_string_p $presentation_options] } {
set presentation_options_html "Presentation Options: $presentation_options\n"
}
# Let user enter valid responses for selections, radio buttons, and check boxes.
set response_fields ""
switch -- $presentation_type {
"radio" -
"select" {
set response_fields "Select one of the following:<p>
<table border=0 width=80% align=center>
<tr valign=top<td valign=middle align=center>
<td>
<input type=radio name=abstract_data_type value=\"boolean\"> True or False
<td valign=middle>
<b>OR</b>
<td>
<input type=radio name=abstract_data_type value=\"choice\" checked> Multiple choice (enter one per line):
<blockquote>
<textarea name=valid_responses rows=10 cols=50></textarea>
</blockquote>
</table>
"
set response_type_html ""
}
"checkbox" {
set response_fields "Valid Responses (enter one per line):
<blockquote>
<textarea name=valid_responses rows=10 cols=80></textarea>
</blockquote>
"
set response_type_html "<input type=hidden name=abstract_data_type value=\"choice\">"
}
"textbox" -
"textarea" {
# Fields where users enter free text responses require an abstract type.
set response_type_html "<p>
Type of Response:
<select name=\"abstract_data_type\">
<option value=\"shorttext\">Short Text (< 4000 characters)</option>
<option value=\"text\">Text</option>
<option value=\"boolean\">Boolean</option>
<option value=\"number\">Number</option>
<option value=\"integer\">Integer</option>
</select>
"
}
"date" {
set response_type_html "<input type=hidden name=abstract_data_type value=date>"
}
"upload_file" {
set response_type_html "<input type=hidden name=abstract_data_type value=blob>"
}
}
set form_var_list [export_form_vars survey_id question_id question_text presentation_type after required_p active_p type]
}
set context [list [list "one?[export_url_vars survey_id]" "Administer Survey"] "Add A Question"]
ad_return_template
<?xml version="1.0"?>
<queryset>
<fullquery name="survsimp_survey_properties">
<querytext>
select name, description, type
from survsimp_surveys
where survey_id = :survey_id
</querytext>
</fullquery>
<fullquery name="count_variable_names">
<querytext>
select count(variable_name) as n_variables
from survsimp_variables, survsimp_variables_surveys_map
where survsimp_variables.variable_id = survsimp_variables_surveys_map.variable_id
and survey_id = :survey_id
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>oracle</type><version>8.1.6</version></rdbms>
<fullquery name="create_question">
<querytext>
begin
:1 := survsimp_question.new (
question_id => :question_id,
survey_id => :survey_id,
sort_key => :sort_key,
question_text => empty_clob(),
abstract_data_type => :abstract_data_type,
presentation_type => :presentation_type,
presentation_alignment => :presentation_alignment,
active_p => :active_p,
required_p => :required_p,
context_id => :survey_id,
creation_user => :user_id
);
end;
</querytext>
</fullquery>
<fullquery name="get_choice_id">
<querytext>
select survsimp_choice_id_sequence.nextval as choice_id from dual
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>postgresql</type><version>7.1</version></rdbms>
<fullquery name="create_question">
<querytext>
select survsimp_question__new (
:question_id,
:survey_id,
:sort_key,
:question_text,
:abstract_data_type,
:required_p,
:active_p,
:presentation_type,
:presentation_options,
:presentation_alignment,
:user_id,
:survey_id
)
</querytext>
</fullquery>
<fullquery name="get_choice_id">
<querytext>
select survsimp_choice_id_sequence.nextval as choice_id
</querytext>
</fullquery>
</queryset>
# /www/survsimp/admin/question-add-3.tcl
ad_page_contract {
Inserts a new question into the database.
@param survey_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_cols number of columns for textarea answer widget
@param textarea_rows number of rows for 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)
@author nstrug@arsdigita.com
@creation-date February 9, 2000
@cvs-id $Id$
} {
survey_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_cols:naturalnum ""}
{textarea_rows:naturalnum ""}
{required_p t}
{active_p t}
{responses:multiple ""}
{scores:multiple,array,integer ""}
{n_variables:integer ""}
{variable_id_list ""}
}
set package_id [ad_conn package_id]
set user_id [ad_get_user_id]
ad_require_permission $package_id survsimp_create_question
set exception_count 0
set exception_text ""
if { [empty_string_p $question_text] } {
incr exception_count
append exception_text "<li>You did not enter a question.\n"
}
if { $type != "scored" && $type != "general" } {
incr exception_count
append exception_text "<li>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 "<li>You did not enter a list of valid responses/choices.\n"
}
if { $type == "scored" } {
set i 0
foreach response $responses {
set trimmed_response [string trim $response]
if { [empty_string_p $trimmed_response] } {
incr exception_count
incr i
append exception_text "<li>You did not enter a valid choice for choice number $i.\n"
}
}
if { $n_variables < 1 } {
incr exception_count
append exception_text "<li>You must score on at least one variable.\n"
}
}
if { $exception_count > 0 } {
ad_return_complaint $exception_count $exception_text
ad_script_abort
}
if { $type == "scored" } {
db_transaction {
if { [exists_and_not_null after] } {
# We're inserting between existing questions; move everybody down.
set sort_key [expr { $after + 1 }]
db_dml renumber_sort_keys "update survsimp_questions
set sort_key = sort_key + 1
where survey_id = :survey_id
and sort_key > :after"
} else {
set sort_key 1
}
set question_id [db_exec_plsql create_question {
begin
:1 := survsimp_question.new (
question_id => :question_id,
survey_id => :survey_id,
sort_key => :sort_key,
question_text => :question_text,
abstract_data_type => :abstract_data_type,
presentation_type => :presentation_type,
presentation_alignment => :presentation_alignment,
active_p => :active_p,
required_p => :required_p,
context_id => :survey_id,
creation_user => :user_id
);
end;
}]
db_dml add_question_text {
update survsimp_questions
set question_text = :question_text
where question_id = :question_id
}
set count 0
foreach response $responses {
set trimmed_response [string trim $response]
set choice_id [db_string get_choice_id "select survsimp_choice_id_sequence.nextval as choice_id from dual"]
db_dml insert_survsimp_question_choice "
insert into survsimp_question_choices
(choice_id, question_id, label, sort_order)
values
(:choice_id, :question_id, :trimmed_response, :count)"
for {set i 0} {$i < $n_variables} {incr i} {
set score_list $scores($i)
set score [lindex $score_list $count]
set variable_id [lindex $variable_id_list $i]
db_dml insert_survsimp_scores "
insert into survsimp_choice_scores
(choice_id, variable_id, score)
values
(:choice_id, :variable_id, :score)"
}
incr count
}
} on_error {
set already_inserted_p [db_string already_inserted_p "select decode(count(*),0,0,1) from survsimp_questions where question_id = :question_id"]
if { !$already_inserted_p } {
db_release_unused_handles
ad_return_error "Database Error" "<pre>$errmsg</pre>"
ad_script_abort
}
}
} elseif { $type == "general" } {
# Generate presentation_options.
set presentation_options ""
if { $presentation_type == "textarea" } {
if { [exists_and_not_null textarea_rows] } {
append presentation_options " rows=$textarea_rows"
}
if { [exists_and_not_null textarea_cols] } {
append presentation_options " cols=$textarea_cols"
}
} elseif { $presentation_type == "textbox" } {
if { [exists_and_not_null textbox_size] } {
# Will be "small", "medium", or "large".
set presentation_options $textbox_size
}
}
db_transaction {
if { [exists_and_not_null after] } {
# We're inserting between existing questions; move everybody down.
set sort_key [expr { $after + 1 }]
db_dml renumber_sort_keys "update survsimp_questions
set sort_key = sort_key + 1
where survey_id = :survey_id
and sort_key > :after"
} else {
set sort_key 1
}
db_exec_plsql create_question {
begin
:1 := survsimp_question.new (
question_id => :question_id,
survey_id => :survey_id,
sort_key => :sort_key,
question_text => empty_clob(),
abstract_data_type => :abstract_data_type,
presentation_type => :presentation_type,
presentation_options => :presentation_options,
presentation_alignment => :presentation_alignment,
active_p => :active_p,
required_p => :required_p,
context_id => :survey_id
);
end;
}
db_dml add_question_text {
update survsimp_questions
set question_text = :question_text
where question_id = :question_id
}
# For questions where the user is selecting a canned response, insert
# the canned responses into survsimp_question_choices by parsing the valid_responses
# field.
if { $presentation_type == "checkbox" || $presentation_type == "radio" || $presentation_type == "select" } {
if { $abstract_data_type == "choice" } {
set responses [split $valid_responses "\n"]
set count 0
foreach response $responses {
set trimmed_response [string trim $response]
if { [empty_string_p $trimmed_response] } {
# skip empty lines
continue
}
### added this next line to
set choice_id [db_string get_choice_id "select survsimp_choice_id_sequence.nextval as choice_id from dual"]
db_dml insert_survsimp_question_choice "insert into survsimp_question_choices (choice_id, question_id, label, sort_order)
values (survsimp_choice_id_sequence.nextval, :question_id, :trimmed_response, :count)"
incr count
}
}
}
} on_error {
set already_inserted_p [db_string already_inserted_p "select decode(count(*),0,0,1) from survsimp_questions where question_id = :question_id" ]
if { !$already_inserted_p } {
db_release_unused_handles
ad_return_error "Database Error" "<pre>$errmsg</pre>"
ad_script_abort
}
}
}
db_release_unused_handles
ad_returnredirect "one?survey_id=$survey_id"
<?xml version="1.0"?>
<queryset>
<fullquery name="renumber_sort_keys">
<querytext>
update survsimp_questions
set sort_key = sort_key + 1
where survey_id = :survey_id
and sort_key > :after
</querytext>
</fullquery>
<fullquery name="add_question_text">
<querytext>
update survsimp_questions
set question_text = :question_text
where question_id = :question_id
</querytext>
</fullquery>
<fullquery name="insert_survsimp_question_choice">
<querytext>
insert into survsimp_question_choices
(choice_id, question_id, label, sort_order)
values
(:choice_id, :question_id, :trimmed_response, :count)
</querytext>
</fullquery>
<fullquery name="insert_survsimp_scores">
<querytext>
insert into survsimp_choice_scores
(choice_id, variable_id, score)
values
(:choice_id, :variable_id, :score)
</querytext>
</fullquery>
<fullquery name="renumber_sort_keys">
<querytext>
update survsimp_questions
set sort_key = sort_key + 1
where survey_id = :survey_id
and sort_key > :after
</querytext>
</fullquery>
<fullquery name="already_inserted_p">
<querytext>
select case when count(*) = 0 then 0 else 1 end from survsimp_questions where question_id = :question_id
</querytext>
</fullquery>
</queryset>
<master>
<property name=title>@name;noquote@: New Question</property>
<property name="context">@context;noquote@</property>
<form action="question-add-2" method=post>
<%= [export_form_vars survey_id after] %>
Question:
<blockquote>
<textarea name=question_text rows=5 cols=70></textarea>
</blockquote>
<%= [survey_specific_html $type] %>
<p>
Active?
<input type=radio value=t name=active_p checked>Yes
<input type=radio value=f name=active_p>No
<br>
Required?
<input type=radio value=t name=required_p checked>Yes
<input type=radio value=f name=required_p>No
<center>
<input type=submit value="Continue">
</center>
</form>
ad_page_contract {
Present form to begin adding a question to a survey.
Lets user enter the question and select a presentation type.
@param survey_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
@creation-date February 9, 2000
@cvs-id $Id$
} {
survey_id:integer
{after:integer ""}
}
set package_id [ad_conn package_id]
set user_id [ad_get_user_id]
ad_require_permission $package_id survsimp_create_question
db_1row simpsurv_survey_properties "select name, description, type
from survsimp_surveys
where survey_id = :survey_id"
# function to insert survey type-specific form html
proc survey_specific_html { type } {
switch $type {
"general" {
set return_html "
Response Presentation:
<select name=\"presentation_type\">
<option value=\"textbox\">One Line Answer (Text Field)</option>
<option value=\"textarea\">Essay Answer (Text Area)</option>
<option value=\"select\">Multiple Choice (Drop Down)</option>
<option value=\"radio\">Multiple Choice (Radio Buttons)</option>
<option value=\"checkbox\">Multiple Choice (Checkbox)</option>
<option value=\"date\">Date</option>
<!-- Removed by gwong@orchardlabs.com because this option was not supported
in the original code.
<option value=\"upload_file\">File Attachment</option>
-->
</select>
<p>"
}
"scored" {
# scored surveys always use radio buttons (for the time being) - we just need to know the number of desired responses
set return_html "
Response Presentation:
<select name=\"presentation_type\">
<option value=\"radio\">Radio Buttons (single choice only)</option>
<option value=\"checkbox\">Checkbox (multiple choices allowed)</option>
</select>
<p>
Number of possible responses? <input type=text name=\"n_responses\" value=2 size=2>
"
}
default {
set return_html ""
}
}
return $return_html
}
set context [list [list "one?[export_url_vars survey_id]" "Administer Survey"] "Add A Question"]
<?xml version="1.0"?>
<queryset>
<fullquery name="simpsurv_survey_properties">
<querytext>
select name, description, type
from survsimp_surveys
where survey_id = :survey_id
</querytext>
</fullquery>
</queryset>
# /www/survsimp/admin/question-delete.tcl
ad_page_contract {
Delete a question from a survey, along with all responses.
@param question_id question we're deleting
@author jsc@arsdigita.com
@creation-date March 13, 2000
@cvs-id $Id$
} {
question_id:integer
}
ad_require_permission $question_id survsimp_delete_question
set user_id [ad_get_user_id]
set survey_id [db_string survsimp_survey_id_from_question_id "select survey_id from survsimp_questions where question_id = :question_id" ]
survsimp_survey_admin_check $user_id $survey_id
db_transaction {
db_dml survsimp_question_responses_delete "delete from survsimp_question_responses where question_id = :question_id"
db_dml survsimp_question_choices_score_delete "delete from survsimp_choice_scores where choice_id in (select choice_id from survsimp_question_choices
where question_id = :question_id)"
db_dml survsimp_question_choices_delete "delete from survsimp_question_choices where question_id = :question_id"
db_dml survsimp_questions_delete "delete from survsimp_questions where question_id = :question_id"
} on_error {
ad_return_error "Database Error" "There was an error while trying to delete the question:
<pre>
$errmsg
</pre>
<p> Please go back to the <a href=\"one?survey_id=$survey_id\">survey</a>.
"
ad_script_abort
}
db_release_unused_handles
ad_returnredirect "one?survey_id=$survey_id"
<?xml version="1.0"?>
<queryset>
<fullquery name="survsimp_survey_id_from_question_id">
<querytext>
select survey_id from survsimp_questions where question_id = :question_id
</querytext>
</fullquery>
<fullquery name="survsimp_question_responses_delete">
<querytext>
delete from survsimp_question_responses where question_id = :question_id
</querytext>
</fullquery>
<fullquery name="survsimp_question_choices_score_delete">
<querytext>
delete from survsimp_choice_scores
where choice_id in (select choice_id from survsimp_question_choices
where question_id = :question_id)
</querytext>
</fullquery>
<fullquery name="survsimp_question_choices_delete">
<querytext>
delete from survsimp_question_choices where question_id = :question_id
</querytext>
</fullquery>
<fullquery name="survsimp_questions_delete">
<querytext>
delete from survsimp_questions where question_id = :question_id
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>oracle</type><version>8.1.6</version></rdbms>
<fullquery name="survsimp_delete_question">
<querytext>
begin
survsimp_question.del (:question_id);
end;
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>postgresql</type><version>7.1</version></rdbms>
<fullquery name="survsimp_delete_question">
<querytext>
select survsimp_question__delete (:question_id);
</querytext>
</fullquery>
</queryset>
# /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
@creation-date March 13, 2000
@cvs-id $Id$
} {
question_id:integer
}
ad_require_permission $question_id survsimp_delete_question
set survey_id [db_string survsimp_id_from_question_id "select survey_id from survsimp_questions where question_id = :question_id" ]
set n_responses [db_string survsimp_number_responses "select count(*)
from survsimp_question_responses
where question_id = :question_id" ]
if { $n_responses == 0 } {
db_transaction {
db_dml survsimp_question_choices_score_delete "delete from survsimp_choice_scores where choice_id in (select choice_id from survsimp_question_choices
where question_id = :question_id)"
db_dml survsimp_question_choices_delete "delete from survsimp_question_choices where
question_id = :question_id"
db_exec_plsql survsimp_delete_question {
begin
survsimp_question.delete (:question_id);
end;
}
} on_error {
ad_return_error "Database Error" "There was an error while trying to delete the question:
<pre>
$errmsg
</pre>
<p> Please go back using your browser.
"
ad_script_abort
}
db_release_unused_handles
ad_returnredirect "one?survey_id=$survey_id"
ad_script_abort
} else {
doc_return 200 text/html "[ad_header "Confirm Question Deletion"]
<h2>Really Delete?</h2>
[ad_context_bar [list "one?[export_url_vars survey_id]" "Administer Survey"] "Delete Question"]
<hr>
Deleting this question will also delete all $n_responses responses. Really delete?
<p>
<a href=\"question-delete-2?[export_url_vars question_id]\">Yes</a> /
<a href=\"one?[export_url_vars survey_id]\">No</a>
[ad_footer]
"
}
<?xml version="1.0"?>
<queryset>
<fullquery name="survsimp_id_from_qeustion_id">
<querytext>
select survey_id from survsimp_questions where question_id = :question_id
</querytext>
</fullquery>
<fullquery name="survsimp_number_responses">
<querytext>
select count(*)
from survsimp_question_responses
where question_id = :question_id
</querytext>
</fullquery>
<fullquery name="survsimp_question_choices_score_delete">
<querytext>
delete from survsimp_choice_scores
where choice_id in (select choice_id from survsimp_question_choices
where question_id = :question_id)
</querytext>
</fullquery>
<fullquery name="survsimp_question_choices_delete">
<querytext>
delete from survsimp_question_choices where
question_id = :question_id
</querytext>
</fullquery>
</queryset>
# /www/survsimp/admin/question-modify-text-2.tcl
ad_page_contract {
Submission page for allowing the user to modify the text of a question.
@param question_id which question we'll be changing text of
@param survey_id survey providing this question
@param question_text new text of question
@author cmceniry@arsdigita.com
@creation-date Jun 16, 2000
@cvs-id $Id$
} {
question_id:integer
survey_id:integer
question_text:html,notnull
}
ad_require_permission $survey_id survsimp_modify_question
db_dml survey_question_text_update "update survsimp_questions set question_text=:question_text where question_id=:question_id"
db_release_unused_handles
ad_returnredirect "one?survey_id=$survey_id"
<?xml version="1.0"?>
<queryset>
<fullquery name="survey_question_text_update">
<querytext>
update survsimp_questions set question_text=:question_text where question_id=:question_id
</querytext>
</fullquery>
</queryset>
<master>
<property name=title>@survey_name;noquote@: Modify Question Text</property>
<property name="context">@context;noquote@</property>
<form action="question-modify-text-2" method=GET>
<%= [export_form_vars question_id survey_id] %>
Question:
<blockquote>
<textarea name=question_text rows=5 cols=70><%= [ns_quotehtml $question_text] %></textarea>
</blockquote>
<p>
<center>
<input type=submit value="Continue">
</center>
</form>
ad_page_contract {
Allow the user to modify the text of a question.
@param survey_id survey this question belongs to
@param question_id question which text we're changing
@author cmceniry@arsdigita.com
@author nstrug@arsdigita.com
@creation-date Jun 16, 2000
@cvs-id $Id$
} {
question_id:integer
survey_id:integer
}
ad_require_permission $survey_id survsimp_modify_question
set survey_name [db_string survey_name_from_id "select name from survsimp_surveys where survey_id=:survey_id" ]
set question_text [db_string survsimp_question_text_from_id "select question_text
from survsimp_questions
where question_id = :question_id" ]
set context [list [list "one?[export_url_vars survey_id]" "Administer Survey"] "Modify a Question's Text"]
<?xml version="1.0"?>
<queryset>
<fullquery name="survey_name_from_id">
<querytext>
select name from survsimp_surveys where survey_id=:survey_id
</querytext>
</fullquery>
<fullquery name="survsimp_question_text_from_id">
<querytext>
select question_text
from survsimp_questions
where question_id = :question_id
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>oracle</type><version>8.1.6</version></rdbms>
<fullquery name="survsimp_question_required_toggle">
<querytext>
update survsimp_questions set required_p = util.logical_negation(required_p)
where survey_id = :survey_id
and question_id = :question_id
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>postgresql</type><version>7.1</version></rdbms>
<fullquery name="survsimp_question_required_toggle">
<querytext>
update survsimp_questions set required_p = util__logical_negation(required_p)
where survey_id = :survey_id
and question_id = :question_id
</querytext>
</fullquery>
</queryset>
# /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 survey_id survey this question belongs to
@param question_id question we're dealing with
@author jsc@arsdigita.com
@creation-date February 9, 2000
@cvs-id $Id$
} {
required_p:notnull
survey_id:integer
question_id:integer
}
ad_require_permission $survey_id survsimp_modify_question
db_dml survsimp_question_required_toggle "update survsimp_questions set required_p = util.logical_negation(required_p)
where survey_id = :survey_id
and question_id = :question_id"
db_release_unused_handles
ad_returnredirect "one?[export_url_vars survey_id]"
ad_page_contract {
Swaps two sort keys for a survey, sort_key and sort_key - 1.
@param survey_id survey we're acting upon
@param sort_key integer determining position of question which is
about to be replaced with previous one
@author nstrug@arsdigita.com
@cvs-id $Id$
} {
survey_id:integer,notnull
sort_key:integer,notnull
}
ad_require_permission $survey_id survsimp_modify_survey
set next_sort_key [expr { $sort_key - 1 }]
db_transaction {
db_dml swap_sort_keys "update survsimp_questions
set sort_key = decode(sort_key, :sort_key, :next_sort_key, :next_sort_key, :sort_key)
where survey_id = :survey_id
and sort_key in (:sort_key, :next_sort_key)"
ad_returnredirect "one?[export_url_vars survey_id]"
} on_error {
ad_return_error "Database error" "A database error occured while trying
to swap your questions. Here's the error:
<pre>
$errmsg
</pre>
"
}
<?xml version="1.0"?>
<queryset>
<fullquery name="swap_sort_keys">
<querytext>
update survsimp_questions
set sort_key = (case when sort_key = :sort_key then :next_sort_key when sort_key = :next_sort_key then :sort_key end)
where survey_id = :survey_id
and sort_key in (:sort_key, :next_sort_key)
</querytext>
</fullquery>
</queryset>
<master>
<property name="title">@survey_name;noquote@: Respondents</property>
<property name="context">@context;noquote@</property>
<ul>
<multiple name="respondents">
<li>
<a href="one-respondent?survey_id=@survey_id@&user_id=@respondents.user_id@">
@respondents.name@ (@respondents.email@)
</a>
</li>
</multiple>
</ul>
ad_page_contract {
List respondents to this survey.
@param survey_id which survey we're displaying respondents to
@author jsc@arsdigita.com
@author nstrug@arsdigita.com
@creation-date February 11, 2000
@cvs-id $Id$
} -query {
survey_id:integer
} -properties {
survey_name:onevalue
respondents:multirow
}
ad_require_permission $survey_id survsimp_admin_survey
set user_list [list]
db_multirow respondents select_respondents {} {
lappend user_list $user_id
}
set survey_name [db_string select_survey_name {}]
set context [list \
[list "one?survey_id=$survey_id" "Administer Survey"] \
"Respondents" \
]
ad_return_template
<?xml version="1.0"?>
<queryset>
<fullquery name="select_respondents">
<querytext>
select persons.first_names || ' ' || persons.last_name as name,
acs_objects.creation_user as user_id,
parties.email
from survsimp_responses,
persons,
parties,
acs_objects
where survsimp_responses.survey_id = :survey_id
and survsimp_responses.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
order by persons.last_name
</querytext>
</fullquery>
<fullquery name="select_survey_name">
<querytext>
select name
from survsimp_surveys
where survey_id = :survey_id
</querytext>
</fullquery>
</queryset>
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
@creation-date February 16, 2000
@cvs-id $Id$
} {
question_id:integer,notnull
choice_id:integer,notnull
}
ad_require_permission $question_id survsimp_admin_survey
# get the prompt text for the question and the ID for survey of
# which it is part
set question_exists_p [db_0or1row get_question_text "
select survey_id, question_text
from survsimp_questions
where question_id = :question_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 "
select label as response_text
from survsimp_question_choices
where choice_id = :choice_id"]
if { !$response_exists_p } {
db_release_unused_handles
ad_return_error "Response Not Found" "Could not find the response #$choice_id"
return
}
set user_id [ad_get_user_id]
set survey_name [db_string survey_name "select name from survsimp_surveys where survey_id = :survey_id"]
set results ""
# Get information of users who responded in particular manner to
# choice question.
db_foreach all_users_for_response "
select
first_names || ' ' || last_name as responder_name,
person_id,
creation_date
from
acs_objects,
survsimp_responses sr,
persons u,
survsimp_question_responses qr
where
qr.response_id = sr.response_id
and qr.response_id = object_id
and creation_user = person_id
and qr.question_id = :question_id
and qr.choice_id = :choice_id" {
append results "<li><a href=\"one-respondent?[export_url_vars user_id survey_id]\">$responder_name</a>\n"
}
doc_return 200 text/html "[ad_header "People who answered \"$response_text\""]
<h2>Responder List</h2>
[ad_context_bar [list "one?survey_id=$survey_id" "Administer Survey"] \
[list "responses?survey_id=$survey_id" "Responses"] \
"One Response"]
<hr>
$survey_name responders who answered \"$response_text\"
when asked \"$question_text\":
<ul>
$results
</ul>
[ad_footer]
"
<?xml version="1.0"?>
<queryset>
<fullquery name="get_question_text">
<querytext>
select survey_id, question_text
from survsimp_questions
where question_id = :question_id
</querytext>
</fullquery>
<fullquery name="get_response_text">
<querytext>
select label as response_text
from survsimp_question_choices
where choice_id = :choice_id
</querytext>
</fullquery>
<fullquery name="survey_name">
<querytext>
select name from survsimp_surveys where survey_id = :survey_id
</querytext>
</fullquery>
<fullquery name="all_users_for_response">
<querytext>
select
first_names || ' ' || last_name as responder_name,
person_id,
creation_date
from
acs_objects,
survsimp_responses sr,
persons u,
survsimp_question_responses qr
where
qr.response_id = sr.response_id
and qr.response_id = object_id
and creation_user = person_id
and qr.question_id = :question_id
and qr.choice_id = :choice_id
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>oracle</type><version>8.1.6</version></rdbms>
<fullquery name="survsimp_response_editable_toggle">
<querytext>
update survsimp_surveys set single_editable_p = util.logical_negation(single_editable_p)
where survey_id = :survey_id
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>postgresql</type><version>7.1</version></rdbms>
<fullquery name="survsimp_response_editable_toggle">
<querytext>
update survsimp_surveys set single_editable_p = util__logical_negation(single_editable_p)
where survey_id = :survey_id
</querytext>
</fullquery>
</queryset>
ad_page_contract {
Toggles a survey between allowing a user to
edit to or not.
@param survey_id survey we're dealing with
@author Jin Choi (jsc@arsdigita.com)
@author nstrug@arsdigita.com
@cvs-id $Id$
} {
survey_id:integer
}
ad_require_permission $survey_id survsimp_admin_survey
db_dml survsimp_response_editable_toggle "update survsimp_surveys set single_editable_p = util.logical_negation(single_editable_p)
where survey_id = :survey_id"
db_release_unused_handles
ad_returnredirect "one?[export_url_vars survey_id]"
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<master>
<property name=title>@survey_name;noquote@: Responses</property>
<property name="context">@context;noquote@</property>
@unique_users_toggle;noquote@
<%= [survey_specific_html $type] %>
<p>
@response_sentence@
<ul>
@results;noquote@
</ul>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment