Index: openacs-4/packages/simulation/www/simplay/enroll.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/enroll.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/simulation/www/simplay/enroll.tcl 12 Jan 2004 15:37:28 -0000 1.2 +++ openacs-4/packages/simulation/www/simplay/enroll.tcl 16 Jan 2004 12:47:56 -0000 1.3 @@ -6,26 +6,50 @@ workflow_id:integer } +# We need to identify the user auth::require_login -# TODO (.25h): integrate sim title into page title -set page_title "Enrollment complete" -set context [list [list "." "SimPlay"] $page_title] +set user_id [ad_conn user_id] -# TODO (5h): implement the pseudocode in this page +simulation::template::get -workflow_id $workflow_id -array simulation -# verify that the user has permission to enroll: -# simulation is open enrollment OR -# user has invitation for this sim -# if not, display error message "sorry, you don't have permission to enroll in this simulation" and link to openacs page for the simulation's owner or email or something +# Check that the user has permission to enroll +if { [string equal $simulation(enroll_type) "open"] } { + # Open simulation - anybody can enroll so the user is authorized +} else { + # Closed enrollment. The user needs to be invited to enroll + set user_invited_p [db_string user_invited_p { + select count(*) + from sim_party_sim_map + where simulation_id = :workflow_id + and party_id = :user_id + and type = 'invited' + }] -# enroll the user in the simulation -# simulation::template::enroll -workflow_id $workflow_id (should auto-detect user_id) + if { !$user_invited_p } { + acs_user::get -user_id $user_id -array user -# case simulation casting type: -# :auto-casting -# display this message now -# "You have been enrolled in @simulation.name@. This simulation will begin on @begin_date@" -# :group casting -# redirect to cast -# :open casting -# redirect to cast + ad_return_forbidden \ + "Cannot enroll in simulation \"$simulation(pretty_name)\"" \ + "
+ We are sorry, but simulation \"$simulation(pretty_name)\" is not open to enrollment and you are not invited to join the simulation so you cannot enroll at this time. +
" + ad_script_abort + } +} + +# The user is allowed to enroll, so enroll him +set simulation_edit(enrolled) $user_id +simulation::template::edit -workflow_id $workflow_id -array simulation_edit + +# If there are casting decisions open to the user, redirect to the casting page (casting_type group or open) +if { [string equal $simulation(casting_type) "auto"] } { + # Auto casting + # The user will be automatically cast right before the simulation starts +} else { + # Open or group casting, redirect to casting page + ad_returnredirect [export_vars -base cast { workflow_id }] + ad_script_abort +} + +set page_title "You have been enrolled in simulation \"$simulation(pretty_name)\"" +set context [list [list "." "SimPlay"] $page_title]