Index: openacs-4/contrib/packages/simulation/sql/postgresql/simulation-tables-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/sql/postgresql/Attic/simulation-tables-create.sql,v
diff -u -r1.20 -r1.21
--- openacs-4/contrib/packages/simulation/sql/postgresql/simulation-tables-create.sql 19 Dec 2003 13:03:20 -0000 1.20
+++ openacs-4/contrib/packages/simulation/sql/postgresql/simulation-tables-create.sql 14 Jan 2004 10:18:10 -0000 1.21
@@ -41,6 +41,19 @@
comment on table sim_simulations is 'Each record is an instantiation of a simulation template, and the parent of zero to many simulation cases.';
+create table sim_simulation_emails (
+ simulation_id integer constraint sim_simulation_emails_sid_fk
+ references workflows
+ on delete cascade,
+ user_id integer constraint sim_simulation_emails_uid_fk
+ references users(user_id),
+ email_type varchar(20) constraint sim_simulation_emails_et_ck
+ check (email_type in ('reminder')),
+ send_date timestamptz
+);
+
+comment on table sim_simulation_emails is 'Keeps track of notifications sent to users for a certain simulation.';
+
create table sim_roles (
role_id integer constraint sim_roles_ri_fk
references workflow_roles(role_id)
Index: openacs-4/contrib/packages/simulation/sql/postgresql/simulation-tables-drop.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/sql/postgresql/Attic/simulation-tables-drop.sql,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/packages/simulation/sql/postgresql/simulation-tables-drop.sql 19 Dec 2003 10:23:11 -0000 1.1
+++ openacs-4/contrib/packages/simulation/sql/postgresql/simulation-tables-drop.sql 14 Jan 2004 10:18:10 -0000 1.2
@@ -7,6 +7,7 @@
drop table sim_tasks;
drop table sim_role_party_map;
drop table sim_roles;
+drop table sim_simulation_emails;
select acs_object_type__drop_type(
'simulation',
't'
Index: openacs-4/contrib/packages/simulation/tcl/simulation-init.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/simulation-init.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/contrib/packages/simulation/tcl/simulation-init.tcl 11 Nov 2003 15:32:46 -0000 1.2
+++ openacs-4/contrib/packages/simulation/tcl/simulation-init.tcl 14 Jan 2004 10:18:10 -0000 1.3
@@ -6,3 +6,5 @@
}
ad_schedule_proc -thread t -schedule_proc ns_schedule_daily [list 02 00] simulation::object::xml::file_sweeper
+
+ad_schedule_proc -thread t -schedule_proc ns_schedule_daily [list 03 00] simulation::template::sweeper
Index: openacs-4/contrib/packages/simulation/tcl/template-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/template-procs.tcl,v
diff -u -r1.47 -r1.48
--- openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 13 Jan 2004 14:59:21 -0000 1.47
+++ openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 14 Jan 2004 10:18:10 -0000 1.48
@@ -449,8 +449,6 @@
@author Peter Marklund
} {
- # TODO (.25h): make sure the sweeper doesn't pick up simulations that have been forced to start.
-
simulation::template::get -workflow_id $workflow_id -array simulation
db_transaction {
@@ -502,16 +500,14 @@
} {
if { [string equal $type "auto_enroll"] } {
# enroll the user automatically
- lappend $simulation_edit(enrolled) $user_id
+ lappend simulation_edit(enrolled) $user_id
lappend enroll_email_list [list $email $user_name]
} else {
# Invite the user
lappend invite_email_list [list $email $user_name]
}
}
- # Remove duplicates
- set simulation_edit(enrolled) [lsort -unique $simulation_edit(enrolled)]
simulation::template::edit -workflow_id $workflow_id -array simulation_edit
simulation::template::get -workflow_id $workflow_id -array sim_template
@@ -552,12 +548,86 @@
set subject "You have been invited to join simulation $sim_template(pretty_name)"
set body "Dear $user_name,
You have been invited to join simulation $sim_template(pretty_name). Please visit the enrollment page at $enrollment_page_url to accept the invitation. Thank you!"
+ acs_mail_lite::send \
+ -to_addr $email \
+ -from_addr [ad_system_owner] \
+ -subject $subject\
+ -body $body
+ }
+}
+ad_proc -private simulation::template::sweeper {} {
+ Starts simulations and sends notifications.
+
+ @author Peter Marklund
+} {
+ # Make simulations go live
+ set simulations_to_start [db_list select_simulations_to_start {
+ select simulation_id
+ from sim_simulations
+ where sim_type <> 'live_sim'
+ and case_start < current_timestamp
+ }]
+ foreach simulation_id $simulations_to_start {
+ ns_log Notice "pm debug starting simulation $simulation_id"
+ start -workflow_id $simulation_id
+ }
+
+ # For simulations that are not live yet and have reached their send_start_note_date,
+ # send notifications to users in simulations that have not already been emailed.
+ set users_to_notify [db_list_of_lists select_simulations_to_start {
+ select cu.user_id,
+ cu.email,
+ cu.first_names || ' ' || cu.last_name as user_name,
+ ss.simulation_id,
+ w.pretty_name as simulation_name,
+ to_char(ss.case_start, 'YYYY-MM-DD') as simulation_start_date,
+ w.description as simulation_description
+ from sim_simulations ss,
+ workflows w,
+ sim_party_sim_map spsm,
+ cc_users cu
+ where sim_type <> 'live_sim'
+ and ss.simulation_id = spsm.simulation_id
+ and ss.simulation_id = w.workflow_id
+ and spsm.type = 'enrolled'
+ and cu.user_id = spsm.party_id
+ and ss.send_start_note_date < current_timestamp
+ and not exists (select 1
+ from sim_simulation_emails sse
+ where sse.simulation_id = ss.simulation_id
+ and sse.user_id = spsm.party_id
+ and sse.email_type = 'reminder')
+ }]
+ foreach row $users_to_notify {
+ set user_id [lindex $row 0]
+ set email [lindex $row 1]
+ set user_name [lindex $row 2]
+ set simulation_id [lindex $row 3]
+ set simulation_name [lindex $row 4]
+ set simulation_start_date [lindex $row 5]
+ set simulation_description [lindex $row 6]
+
+ set subject "Simulation $simulation_name starts on $simulation_start_date"
+ set body "Dear $user_name,
+this email is sent to you as a reminder that you are participating in simulation $simulation_name that will start on $simulation_start_date. Here is the
+simulation description:
+
+$simulation_description"
+
acs_mail_lite::send \
-to_addr $email \
-from_addr [ad_system_owner] \
-subject $subject\
-body $body
+
+ # Record that we sent email
+ db_dml record_simulation_email {
+ insert into sim_simulation_emails
+ (simulation_id, user_id, email_type, send_date)
+ values
+ (:simulation_id, :user_id, 'reminder', current_timestamp)
+ }
}
}
@@ -569,8 +639,6 @@
@author Peter Marklund
} {
- # TODO (.25h): invoke this proc from a sweep
-
simulation::template::get -workflow_id $workflow_id -array simulation
if { ![string equal $simulation(sim_type) "casting_sim"] } {
@@ -585,6 +653,32 @@
simulation::template::autocast -workflow_id $workflow_id
}
+
+ # Notify users enrolled in the simulation
+ db_foreach select_enrolled_users {
+ select distinct cu.user_id,
+ cu.email,
+ cu.first_names || ' ' || cu.last_name as user_name
+ from sim_party_sim_map spsm,
+ cc_users cu
+ where spsm.simulation_id = :workflow_id
+ and spsm.type = 'enrolled'
+ and spsm.party_id = cu.user_id
+ } {
+ # TODO: check that link to enrollment page is correct
+ set package_id [ad_conn package_id]
+ set simplay_url \
+ [export_vars -base "[ad_url][apm_package_url_from_id $package_id]/simplay/enroll" { email }]
+ set subject "Simulation $simulation(pretty_name) has started"
+ set body "Dear $user_name,
+Simulation $simulation(pretty_name) has now started. Please visit $simplay_url to participate. Thank you!"
+
+ acs_mail_lite::send \
+ -to_addr $email \
+ -from_addr [ad_system_owner] \
+ -subject $subject\
+ -body $body
+ }
}
ad_proc -public simulation::template::autocast {
@@ -834,10 +928,6 @@
} {
simulation::template::get -workflow_id $workflow_id -array sim_template
- # TODO (1.5h): Refactor this and the corresponding wizard.tcl/adp page
- # What we really need to know is whether each step is complete
- # They're all independent of each other, except for casting, which is dependent on participants.
-
foreach tab [get_wizard_tabs] {
set tab_complete_p($tab) 0
}
Index: openacs-4/contrib/packages/simulation/www/siminst/map-tasks.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/siminst/Attic/map-tasks.adp,v
diff -u -r1.11 -r1.12
--- openacs-4/contrib/packages/simulation/www/siminst/map-tasks.adp 13 Jan 2004 12:45:09 -0000 1.11
+++ openacs-4/contrib/packages/simulation/www/siminst/map-tasks.adp 14 Jan 2004 10:18:10 -0000 1.12
@@ -1,6 +1,6 @@
- TODO: (8h) make sure that we are generating all of the notifications - that we should: - -
TODO: A: Some data needs to be read only if you return to the wizard after you've clicked the finish button. Test this.
Index: openacs-4/packages/simulation/sql/postgresql/simulation-tables-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/sql/postgresql/simulation-tables-create.sql,v diff -u -r1.20 -r1.21 --- openacs-4/packages/simulation/sql/postgresql/simulation-tables-create.sql 19 Dec 2003 13:03:20 -0000 1.20 +++ openacs-4/packages/simulation/sql/postgresql/simulation-tables-create.sql 14 Jan 2004 10:18:10 -0000 1.21 @@ -41,6 +41,19 @@ comment on table sim_simulations is 'Each record is an instantiation of a simulation template, and the parent of zero to many simulation cases.'; +create table sim_simulation_emails ( + simulation_id integer constraint sim_simulation_emails_sid_fk + references workflows + on delete cascade, + user_id integer constraint sim_simulation_emails_uid_fk + references users(user_id), + email_type varchar(20) constraint sim_simulation_emails_et_ck + check (email_type in ('reminder')), + send_date timestamptz +); + +comment on table sim_simulation_emails is 'Keeps track of notifications sent to users for a certain simulation.'; + create table sim_roles ( role_id integer constraint sim_roles_ri_fk references workflow_roles(role_id) Index: openacs-4/packages/simulation/sql/postgresql/simulation-tables-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/sql/postgresql/simulation-tables-drop.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/simulation/sql/postgresql/simulation-tables-drop.sql 19 Dec 2003 10:23:11 -0000 1.1 +++ openacs-4/packages/simulation/sql/postgresql/simulation-tables-drop.sql 14 Jan 2004 10:18:10 -0000 1.2 @@ -7,6 +7,7 @@ drop table sim_tasks; drop table sim_role_party_map; drop table sim_roles; +drop table sim_simulation_emails; select acs_object_type__drop_type( 'simulation', 't' Index: openacs-4/packages/simulation/tcl/simulation-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/simulation-init.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/simulation/tcl/simulation-init.tcl 11 Nov 2003 15:32:46 -0000 1.2 +++ openacs-4/packages/simulation/tcl/simulation-init.tcl 14 Jan 2004 10:18:10 -0000 1.3 @@ -6,3 +6,5 @@ } ad_schedule_proc -thread t -schedule_proc ns_schedule_daily [list 02 00] simulation::object::xml::file_sweeper + +ad_schedule_proc -thread t -schedule_proc ns_schedule_daily [list 03 00] simulation::template::sweeper Index: openacs-4/packages/simulation/tcl/template-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/template-procs.tcl,v diff -u -r1.47 -r1.48 --- openacs-4/packages/simulation/tcl/template-procs.tcl 13 Jan 2004 14:59:21 -0000 1.47 +++ openacs-4/packages/simulation/tcl/template-procs.tcl 14 Jan 2004 10:18:10 -0000 1.48 @@ -449,8 +449,6 @@ @author Peter Marklund } { - # TODO (.25h): make sure the sweeper doesn't pick up simulations that have been forced to start. - simulation::template::get -workflow_id $workflow_id -array simulation db_transaction { @@ -502,16 +500,14 @@ } { if { [string equal $type "auto_enroll"] } { # enroll the user automatically - lappend $simulation_edit(enrolled) $user_id + lappend simulation_edit(enrolled) $user_id lappend enroll_email_list [list $email $user_name] } else { # Invite the user lappend invite_email_list [list $email $user_name] } } - # Remove duplicates - set simulation_edit(enrolled) [lsort -unique $simulation_edit(enrolled)] simulation::template::edit -workflow_id $workflow_id -array simulation_edit simulation::template::get -workflow_id $workflow_id -array sim_template @@ -552,12 +548,86 @@ set subject "You have been invited to join simulation $sim_template(pretty_name)" set body "Dear $user_name, You have been invited to join simulation $sim_template(pretty_name). Please visit the enrollment page at $enrollment_page_url to accept the invitation. Thank you!" + acs_mail_lite::send \ + -to_addr $email \ + -from_addr [ad_system_owner] \ + -subject $subject\ + -body $body + } +} +ad_proc -private simulation::template::sweeper {} { + Starts simulations and sends notifications. + + @author Peter Marklund +} { + # Make simulations go live + set simulations_to_start [db_list select_simulations_to_start { + select simulation_id + from sim_simulations + where sim_type <> 'live_sim' + and case_start < current_timestamp + }] + foreach simulation_id $simulations_to_start { + ns_log Notice "pm debug starting simulation $simulation_id" + start -workflow_id $simulation_id + } + + # For simulations that are not live yet and have reached their send_start_note_date, + # send notifications to users in simulations that have not already been emailed. + set users_to_notify [db_list_of_lists select_simulations_to_start { + select cu.user_id, + cu.email, + cu.first_names || ' ' || cu.last_name as user_name, + ss.simulation_id, + w.pretty_name as simulation_name, + to_char(ss.case_start, 'YYYY-MM-DD') as simulation_start_date, + w.description as simulation_description + from sim_simulations ss, + workflows w, + sim_party_sim_map spsm, + cc_users cu + where sim_type <> 'live_sim' + and ss.simulation_id = spsm.simulation_id + and ss.simulation_id = w.workflow_id + and spsm.type = 'enrolled' + and cu.user_id = spsm.party_id + and ss.send_start_note_date < current_timestamp + and not exists (select 1 + from sim_simulation_emails sse + where sse.simulation_id = ss.simulation_id + and sse.user_id = spsm.party_id + and sse.email_type = 'reminder') + }] + foreach row $users_to_notify { + set user_id [lindex $row 0] + set email [lindex $row 1] + set user_name [lindex $row 2] + set simulation_id [lindex $row 3] + set simulation_name [lindex $row 4] + set simulation_start_date [lindex $row 5] + set simulation_description [lindex $row 6] + + set subject "Simulation $simulation_name starts on $simulation_start_date" + set body "Dear $user_name, +this email is sent to you as a reminder that you are participating in simulation $simulation_name that will start on $simulation_start_date. Here is the +simulation description: + +$simulation_description" + acs_mail_lite::send \ -to_addr $email \ -from_addr [ad_system_owner] \ -subject $subject\ -body $body + + # Record that we sent email + db_dml record_simulation_email { + insert into sim_simulation_emails + (simulation_id, user_id, email_type, send_date) + values + (:simulation_id, :user_id, 'reminder', current_timestamp) + } } } @@ -569,8 +639,6 @@ @author Peter Marklund } { - # TODO (.25h): invoke this proc from a sweep - simulation::template::get -workflow_id $workflow_id -array simulation if { ![string equal $simulation(sim_type) "casting_sim"] } { @@ -585,6 +653,32 @@ simulation::template::autocast -workflow_id $workflow_id } + + # Notify users enrolled in the simulation + db_foreach select_enrolled_users { + select distinct cu.user_id, + cu.email, + cu.first_names || ' ' || cu.last_name as user_name + from sim_party_sim_map spsm, + cc_users cu + where spsm.simulation_id = :workflow_id + and spsm.type = 'enrolled' + and spsm.party_id = cu.user_id + } { + # TODO: check that link to enrollment page is correct + set package_id [ad_conn package_id] + set simplay_url \ + [export_vars -base "[ad_url][apm_package_url_from_id $package_id]/simplay/enroll" { email }] + set subject "Simulation $simulation(pretty_name) has started" + set body "Dear $user_name, +Simulation $simulation(pretty_name) has now started. Please visit $simplay_url to participate. Thank you!" + + acs_mail_lite::send \ + -to_addr $email \ + -from_addr [ad_system_owner] \ + -subject $subject\ + -body $body + } } ad_proc -public simulation::template::autocast { @@ -834,10 +928,6 @@ } { simulation::template::get -workflow_id $workflow_id -array sim_template - # TODO (1.5h): Refactor this and the corresponding wizard.tcl/adp page - # What we really need to know is whether each step is complete - # They're all independent of each other, except for casting, which is dependent on participants. - foreach tab [get_wizard_tabs] { set tab_complete_p($tab) 0 } Index: openacs-4/packages/simulation/www/siminst/map-tasks.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/siminst/map-tasks.adp,v diff -u -r1.11 -r1.12 --- openacs-4/packages/simulation/www/siminst/map-tasks.adp 13 Jan 2004 12:45:09 -0000 1.11 +++ openacs-4/packages/simulation/www/siminst/map-tasks.adp 14 Jan 2004 10:18:10 -0000 1.12 @@ -1,6 +1,6 @@- TODO: (8h) make sure that we are generating all of the notifications - that we should: - -
TODO: A: Some data needs to be read only if you return to the wizard after you've clicked the finish button. Test this.