Index: openacs-4/packages/simple-survey/simple-survey.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simple-survey/simple-survey.info,v diff -u -r1.1 -r1.2 --- openacs-4/packages/simple-survey/simple-survey.info 20 Apr 2001 20:51:22 -0000 1.1 +++ openacs-4/packages/simple-survey/simple-survey.info 15 Jun 2001 00:45:42 -0000 1.2 @@ -4,6 +4,7 @@ Simple Survey Simple Surveys + f t @@ -23,48 +24,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: openacs-4/packages/simple-survey/sql/oracle/survsimp-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simple-survey/sql/oracle/Attic/survsimp-create.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/simple-survey/sql/oracle/survsimp-create.sql 20 Apr 2001 20:51:22 -0000 1.1 +++ openacs-4/packages/simple-survey/sql/oracle/survsimp-create.sql 15 Jun 2001 00:45:42 -0000 1.2 @@ -76,6 +76,23 @@ table_name => 'SURVSIMP_RESPONSES', id_column => 'RESPONSE_ID' ); + + acs_rel_type.create_type ( + rel_type => 'user_blob_response_rel', + pretty_name => 'User Blob Response', + pretty_plural => 'User Blob Responses', + object_type_one => 'user', + role_one => 'user', + table_name => 'survsimp_question_responses', + id_column => 'user_id', + package_name => 'user_blob_response_rel', + min_n_rels_one => 1, + max_n_rels_one => 1, + object_type_two => 'content_item', + min_n_rels_two => 0, + max_n_rels_two => 1 + ); + end; / show errors @@ -130,7 +147,7 @@ not null, abstract_data_type varchar(30) constraint survsimp_q_abs_data_type_ck - check (abstract_data_type in ('text', 'shorttext', 'boolean', 'number', 'integer', 'choice')), + check (abstract_data_type in ('text', 'shorttext', 'boolean', 'number', 'integer', 'choice', 'date')), required_p char(1) constraint survsimp_q_required_p_ck check (required_p in ('t','f')), @@ -156,14 +173,20 @@ create sequence survsimp_choice_id_sequence start with 1; create table survsimp_question_choices ( - choice_id integer not null primary key, - question_id not null references survsimp_questions, - -- human readable - label varchar(500) not null, - -- might be useful for averaging or whatever, generally null - numeric_value number, - -- lower is earlier - sort_order integer + choice_id integer constraint survsimp_qc_choice_id_nn + not null + constraint survsimp_qc_choice_id_pk + primary key, + question_id constraint survsimp_qc_question_id_nn + not null + constraint survsimp_qc_question_id_fk + references survsimp_questions, + -- human readable + label varchar(500) constraint survsimp_qc_label_nn not null, + -- might be useful for averaging or whatever, generally null + numeric_value number, + -- lower is earlier + sort_order integer ); -- this records a response by one user to one survey @@ -521,4 +544,4 @@ - \ No newline at end of file + Index: openacs-4/packages/simple-survey/sql/oracle/survsimp-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simple-survey/sql/oracle/Attic/survsimp-drop.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/simple-survey/sql/oracle/survsimp-drop.sql 20 Apr 2001 20:51:22 -0000 1.1 +++ openacs-4/packages/simple-survey/sql/oracle/survsimp-drop.sql 15 Jun 2001 00:45:42 -0000 1.2 @@ -5,28 +5,65 @@ -- -- $Id$ -begin - acs_object_type.drop_type ('survsimp_survey'); -end; -/ -show errors +drop_package survsimp_response; +drop_package survsimp_question; +drop_package survsimp_survey; - -drop view survsimp_question_responses_un; 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 sequence survsimp_response_id_sequence; drop table survsimp_question_choices cascade constraints; + drop sequence survsimp_choice_id_sequence; drop table survsimp_questions cascade constraints; -drop sequence survsimp_question_id_sequence; drop table survsimp_surveys cascade constraints; -drop sequence survsimp_survey_id_sequence; + +-- 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 + + +drop function logical_negation; + Index: openacs-4/packages/simple-survey/tcl/survsimp-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simple-survey/tcl/survsimp-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/simple-survey/tcl/survsimp-procs.tcl 20 Apr 2001 20:51:22 -0000 1.1 +++ openacs-4/packages/simple-survey/tcl/survsimp-procs.tcl 15 Jun 2001 00:45:42 -0000 1.2 @@ -447,4 +447,309 @@ return $date } - \ No newline at end of file +proc_doc survsimp_bt_mergepiece {htmlpiece values} { + HTMLPIECE is a form usually; VALUES is an ns_set + + NEW VERSION DONE BY BEN ADIDA (ben@mit.edu) + Last modification (ben@mit.edu) on Jan ?? 1998 + added support for dates in the date_entry_widget. + + modification (ben@mit.edu) on Jan 12th, 1998 + when the val of an option tag is "", things screwed up + FIXED. + + This used to count the number of vars already introduced + in the form (see remaining num_vars statements), so as + to end early. However, for some unknown reason, this cut off a number + of forms. So now, this processes every tag in the HTML form. +} { + + set newhtml "" + + set html_piece_ben $htmlpiece + + set num_vars 0 + + for {set i 0} {$i<[ns_set size $values]} {incr i} { + if {[ns_set key $values $i] != ""} { + set database_values([ns_set key $values $i]) [philg_quote_double_quotes [ns_set value $values $i]] + incr num_vars + } + } + + set vv {[Vv][Aa][Ll][Uu][Ee]} ; # Sorta obvious + set nn {[Nn][Aa][Mm][Ee]} ; # This is too + set qq {"([^"]*)"} ; # Matches what's in quotes + set pp {([^ ]*)} ; # Matches a word (mind yer pp and qq) + + set slist {} + + set count 0 + + while {1} { + + incr count + set start_point [string first < $html_piece_ben] + if {$start_point==-1} { + append newhtml $html_piece_ben + break; + } + if {$start_point>0} { + append newhtml [string range $html_piece_ben 0 [expr $start_point - 1]] + } + set end_point [string first > $html_piece_ben] + if {$end_point==-1} break + incr start_point + incr end_point -1 + set tag [string range $html_piece_ben $start_point $end_point] + incr end_point 2 + set html_piece_ben [string range $html_piece_ben $end_point end] + set CAPTAG [string toupper $tag] + + set first_white [string first " " $CAPTAG] + set first_word [string range $CAPTAG 0 [expr $first_white - 1]] + + switch -regexp $CAPTAG { + + {^INPUT} { + if {[regexp {TYPE[ ]*=[ ]*("IMAGE"|"SUBMIT"|"RESET"|IMAGE|SUBMIT|RESET)} $CAPTAG]} { + + ### + # Ignore these + ### + + append newhtml <$tag> + + } elseif {[regexp {TYPE[ ]*=[ ]*("CHECKBOX"|CHECKBOX)} $CAPTAG]} { + # philg and jesse added optional whitespace 8/9/97 + ## If it's a CHECKBOX, we cycle through + # all the possible ns_set pair to see if it should + ## end up CHECKED or not. + + if {[regexp "$nn=$qq" $tag m nam]} {}\ + elseif {[regexp "$nn=$pp" $tag m nam]} {}\ + else {set nam ""} + + if {[regexp "$vv=$qq" $tag m val]} {}\ + elseif {[regexp "$vv=$pp" $tag m val]} {}\ + else {set val ""} + + regsub -all {[Cc][Hh][Ee][Cc][Kk][Ee][Dd]} $tag {} tag + + # support for multiple check boxes provided by michael cleverly + if {[info exists database_values($nam)]} { + if {[ns_set unique $values $nam]} { + if {$database_values($nam) == $val} { + append tag " checked" + incr num_vars -1 + } + } else { + for {set i [ns_set find $values $nam]} {$i < [ns_set size $values]} {incr i} { + if {[ns_set key $values $i] == $nam && [philg_quote_double_quotes [ns_set value $values $i]] == $val} { + append tag " checked" + incr num_vars -1 + break + } + } + } + } + + append newhtml <$tag> + + } elseif {[regexp {TYPE[ ]*=[ ]*("RADIO"|RADIO)} $CAPTAG]} { + + ## If it's a RADIO, we remove all the other + # choices beyond the first to keep from having + ## more than one CHECKED + + if {[regexp "$nn=$qq" $tag m nam]} {}\ + elseif {[regexp "$nn=$pp" $tag m nam]} {}\ + else {set nam ""} + + if {[regexp "$vv=$qq" $tag m val]} {}\ + elseif {[regexp "$vv=$pp" $tag m val]} {}\ + else {set val ""} + + #Modified by Ben Adida (ben@mit.edu) so that + # the checked tags are eliminated only if something + # is in the database. + + if {[info exists database_values($nam)]} { + regsub -all {[Cc][Hh][Ee][Cc][Kk][Ee][Dd]} $tag {} tag + if {$database_values($nam)==$val} { + append tag " checked" + incr num_vars -1 + } + } + + append newhtml <$tag> + + } else { + + ## If it's an INPUT TYPE that hasn't been covered + # (text, password, hidden, other (defaults to text)) + ## then we add/replace the VALUE tag + + if {[regexp "$nn=$qq" $tag m nam]} {}\ + elseif {[regexp "$nn=$pp" $tag m nam]} {}\ + else {set nam ""} + + set nam [ns_urldecode $nam] + + if {[info exists database_values($nam)]} { + regsub -all "$vv=$qq" $tag {} tag + regsub -all "$vv=$pp" $tag {} tag + append tag " value=\"$database_values($nam)\"" + incr num_vars -1 + } else { + if {[regexp {ColValue.([^.]*).([^ ]*)} $tag all nam type]} { + set nam [ns_urldecode $nam] + set typ "" + if {[string match $type "day"]} { + set typ "day" + } + if {[string match $type "year"]} { + set typ "year" + } + if {$typ != ""} { + if {[info exists database_values($nam)]} { + regsub -all "$vv=$qq" $tag {} tag + regsub -all "$vv=$pp" $tag {} tag + append tag " value=\"[ns_parsesqldate $typ $database_values($nam)]\"" + } + } + #append tag "> + } + } + + {^TEXTAREA} { + + ### + # Fill in the middle of this tag + ### + + if {[regexp "$nn=$qq" $tag m nam]} {}\ + elseif {[regexp "$nn=$pp" $tag m nam]} {}\ + else {set nam ""} + + if {[info exists database_values($nam)]} { + while {![regexp {^<( *)/[Tt][Ee][Xx][Tt][Aa][Rr][Ee][Aa]} $html_piece_ben]} { + regexp {^.[^<]*(.*)} $html_piece_ben m html_piece_ben + } + append newhtml <$tag>$database_values($nam) + incr num_vars -1 + } else { + append newhtml <$tag> + } + } + + {^SELECT} { + + ### + # Set the snam flag, and perhaps smul, too + ### + + set smul [regexp "MULTIPLE" $CAPTAG] + + set sflg 1 + + set select_date 0 + + if {[regexp "$nn=$qq" $tag m snam]} {}\ + elseif {[regexp "$nn=$pp" $tag m snam]} {}\ + else {set snam ""} + + set snam [ns_urldecode $snam] + + # In case it's a date + if {[regexp {ColValue.([^.]*).month} $snam all real_snam]} { + if {[info exists database_values($real_snam)]} { + set snam $real_snam + set select_date 1 + } + } + + lappend slist $snam + + append newhtml <$tag> + } + + {^OPTION} { + + ### + # Find the value for this + ### + + if {$snam != ""} { + + if {[lsearch -exact $slist $snam] != -1} {regsub -all {[Ss][Ee][Ll][Ee][Cc][Tt][Ee][Dd]} $tag {} tag} + + if {[regexp "$vv *= *$qq" $tag m opt]} {}\ + elseif {[regexp "$vv *= *$pp" $tag m opt]} {}\ + else { + if {[info exists opt]} { + unset opt + } } + # at this point we've figured out what the default from the form was + # and put it in $opt (if the default was spec'd inside the OPTION tag + # just in case it wasn't, we're going to look for it in the + # human-readable part + regexp {^([^<]*)(.*)} $html_piece_ben m txt html_piece_ben + if {![info exists opt]} { + set val [string trim $txt] + } else { + set val $opt + } + + if {[info exists database_values($snam)]} { + # If we're dealing with a date + if {$select_date == 1} { + set db_val [ns_parsesqldate month $database_values($snam)] + } else { + set db_val $database_values($snam) + } + + if { + ($smul || $sflg) && + [string match $db_val $val] + } then { + append tag " selected" + incr num_vars -1 + set sflg 0 + } + } + } + append newhtml <$tag>$txt + } + + {^/SELECT} { + + ### + # Do we need to add to the end? + ### + + set txt "" + + if {$snam != ""} { + if {[info exists database_values($snam)] && $sflg} { + append txt "