Index: openacs-4/contrib/packages/simulation/lib/sim-objects.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/sim-objects.tcl,v
diff -u -r1.7 -r1.8
--- openacs-4/contrib/packages/simulation/lib/sim-objects.tcl	18 Nov 2003 14:58:49 -0000	1.7
+++ openacs-4/contrib/packages/simulation/lib/sim-objects.tcl	18 Nov 2003 15:59:11 -0000	1.8
@@ -17,6 +17,8 @@
 
 set package_id [ad_conn package_id]
 
+set add_url [export_vars -base "[ad_conn package_url]citybuild/object-edit" { parent_id }]
+
 if { ![exists_and_not_null parent_id] } {
     set parent_id [bcms::folder::get_id_by_package_id -parent_id 0]
 }
@@ -74,8 +76,6 @@
     set filter_sql ""
 }
 
-set add_url [export_vars -base "[apm_package_url_from_id $package_id]citybuild/object-edit" { parent_id }]
-
 template::list::create \
     -name objects \
     -multirow objects \
@@ -115,5 +115,3 @@
         }
     }
 }
-
-
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.2 -r1.3
--- openacs-4/contrib/packages/simulation/tcl/template-procs.tcl	18 Nov 2003 12:19:39 -0000	1.2
+++ openacs-4/contrib/packages/simulation/tcl/template-procs.tcl	18 Nov 2003 15:59:12 -0000	1.3
@@ -41,18 +41,27 @@
             -workflow_id $workflow_id \
             -short_name "dummy action" \
             -pretty_name "dummy action"
-        
-        db_dml new_sim "
+
+        set suggested_duration [string trim $suggested_duration]
+        if { [empty_string_p $suggested_duration] } {
+            db_dml new_sim {
+                insert into sim_simulations
+                (simulation_id, ready_p)
+                values (:workflow_id, :ready_p)
+            }
+        } else {
+            db_dml new_sim "
             insert into sim_simulations
             (simulation_id, ready_p, suggested_duration)
-            values ($workflow_id, '$ready_p', interval '$suggested_duration')
-        "
-            
+            values ('$workflow_id', '$ready_p', interval '$suggested_duration')"            
         }
+    }
+
     return $workflow_id
 }
 
 ad_proc -public simulation::template::edit {
+    {-workflow_id:required}
     {-short_name:required}
     {-pretty_name:required}
     {-ready_p "f"}
@@ -77,34 +86,40 @@
             update workflows
                set short_name=:short_name,
                    pretty_name=:pretty_name
-             where workflow_id=:object_id
-"
-        
-        db_dml edit_sim "
-            update sim_simulations
-               set ready_p=:ready_p, 
-                   suggested_duration=(interval ':suggested_duration')
-             where simulation_id=:object_id
-        "
-            
+             where workflow_id=:workflow_id"
+
+        if { [empty_string_p $suggested_duration] } {
+            db_dml edit_sim {
+                update sim_simulations
+                   set ready_p=:ready_p, 
+                       suggested_duration = null
+                 where simulation_id=:workflow_id
+            }
+        } else {
+            db_dml edit_sim "
+                update sim_simulations
+                   set ready_p=:ready_p, 
+                       suggested_duration=(interval '$suggested_duration')
+                 where simulation_id=:workflow_id
+            "
         }
-    return $workflow_id
+    }
 }
 
 ad_proc -public simulation::template::get {
-    {-package_key:required}
-    {-object_id:required}
+    {-workflow_id:required}
     {-array:required}
 } {
-    STUB ONLY.  Return information about a simulation template.  This should be a wrapper anound workflow::get, supplementing it with the columns from sim_simulation.
+    Return information about a simulation template.  This is a wrapper around 
+    workflow::get, supplementing it with the columns from sim_simulation.
 
-    @param object_id ID of simulation template.
+    @param workflow_id ID of simulation template.
     @param array name of array in which the info will be returned
-    @return An array list with keys workflow_id, short_name,
-            pretty_name, object_id, package_key, object_type, initial_action,
-            and callbacks, plus records in sim_simulation.
+                 Array will contain keys from the tables workflows and sim_simulations.
 } {
-    return 1
+    upvar $array row
+
+    db_1row select_template {} -column_array row
 }
 
 ad_proc -public simulation::template::delete {
Index: openacs-4/contrib/packages/simulation/tcl/template-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/template-procs.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/contrib/packages/simulation/tcl/template-procs.xql	18 Nov 2003 15:59:12 -0000	1.1
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<queryset>
+
+  <fullquery name="simulation::template::get.select_template">
+        <querytext>
+          select w.workflow_id,
+                 w.short_name,
+                 w.pretty_name, 
+                 w.object_id, 
+                 w.package_key, 
+                 w.object_type, 
+                 s.suggested_duration,
+                 s.ready_p,
+                 s.enroll_type,
+                 s.casting_type,
+                 s.enroll_start,
+                 s.enroll_end,
+                 s.case_start,
+                 s.case_end,
+                 s.send_start_note_date 
+          from workflows w,
+               sim_simulations s
+          where w.workflow_id = :workflow_id
+            and w.workflow_id = s.simulation_id
+        </querytext>
+  </fullquery>
+
+</queryset>
Index: openacs-4/contrib/packages/simulation/test/demo-data-setup.test
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/test/Attic/demo-data-setup.test,v
diff -u -r1.4 -r1.5
--- openacs-4/contrib/packages/simulation/test/demo-data-setup.test	14 Nov 2003 13:46:46 -0000	1.4
+++ openacs-4/contrib/packages/simulation/test/demo-data-setup.test	18 Nov 2003 15:59:12 -0000	1.5
@@ -51,7 +51,7 @@
 
     ::twt::log_section "Create an image object"
     do_request /simulation/citybuild
-    link follow ~u object-edit?.*parent
+    link follow ~u object-edit
     form find ~n object
     field find ~n content_type
     field select2 ~v image
Index: openacs-4/contrib/packages/simulation/test/simulation-test-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/test/Attic/simulation-test-procs.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/packages/simulation/test/simulation-test-procs.tcl	14 Nov 2003 13:47:16 -0000	1.1
+++ openacs-4/contrib/packages/simulation/test/simulation-test-procs.tcl	18 Nov 2003 15:59:12 -0000	1.2
@@ -20,7 +20,7 @@
     Create a new simulation image
 } {
     do_request /simulation/citybuild
-    link follow ~u object-edit?.*parent
+    link follow ~u object-edit
 
     # Choose object type image
     set_object_form_type image
@@ -47,7 +47,7 @@
     Create a new simulation object
 } {
     do_request /simulation/citybuild
-    link follow ~u object-edit?.*parent
+    link follow ~u object-edit
 
     set_object_form_type $type
 
Index: openacs-4/contrib/packages/simulation/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/index.tcl,v
diff -u -r1.9 -r1.10
--- openacs-4/contrib/packages/simulation/www/index.tcl	18 Nov 2003 09:44:31 -0000	1.9
+++ openacs-4/contrib/packages/simulation/www/index.tcl	18 Nov 2003 15:59:12 -0000	1.10
@@ -69,10 +69,6 @@
 
 set action_list [list "Add an Object" [export_vars -base object-edit { parent_id }] ]
 
-#error "
-#object_add_url: $object_add_url
-#add_action: $add_action"
-
 template::list::create \
     -name object_count \
     -multirow object_count \
Index: openacs-4/contrib/packages/simulation/www/simbuild/template-edit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/template-edit.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/contrib/packages/simulation/www/simbuild/template-edit.tcl	18 Nov 2003 12:19:39 -0000	1.2
+++ openacs-4/contrib/packages/simulation/www/simbuild/template-edit.tcl	18 Nov 2003 15:59:12 -0000	1.3
@@ -31,20 +31,18 @@
         {label "Template Name"}
         {html {size 40}}
     }
-    {ready_p:boolean(checkbox),optional
+    {ready_p:boolean(radio),optional
         {label "Ready for use?"}
-        {options {""}}
+        {options {{Yes t} {No f}}}
     }
-    {suggested_duration:string,optional
+    {suggested_duration:text,optional
         {label "Suggested Duration"}
     }
 } -edit_request {
-    workflow::get -workflow_id $workflow_id -array sim_template_array
+    simulation::template::get -workflow_id $workflow_id -array sim_template_array
     set name $sim_template_array(pretty_name)
-    set ready_p 't' 
-#TODO: replace workflow api call with simulation::template::get,
-# combining data from workflows with data from sim_simulation,
-# hence providing $sim_template_array(ready_p)
+    set ready_p $sim_template_array(ready_p)
+    set suggested_duration $sim_template_array(suggested_duration)
 } -new_data {
     set workflow_id [simulation::template::new \
                          -short_name $name \
@@ -54,17 +52,17 @@
                          -package_key $package_key \
                          -object_id $package_id]
 } -edit_data {
-    set workflow_id [simulation::template::edit \
-                         -short_name $name \
-                         -pretty_name $name \
-                         -ready_p $ready_p \
-                         -suggested_duration $suggested_duration \
-                         -package_key $package_key \
-                         -object_id $package_id]
+    simulation::template::edit \
+        -workflow_id $workflow_id \
+        -short_name $name \
+        -pretty_name $name \
+        -ready_p $ready_p \
+        -suggested_duration $suggested_duration \
+        -package_key $package_key \
+        -object_id $package_id
 
-
 } -after_submit {
-    ad_returnredirect template-edit?workflow_id=$workflow_id
+    ad_returnredirect [export_vars -base "template-edit" { workflow_id }]
     ad_script_abort
 }
 
Index: openacs-4/packages/simulation/lib/sim-objects.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/sim-objects.tcl,v
diff -u -r1.7 -r1.8
--- openacs-4/packages/simulation/lib/sim-objects.tcl	18 Nov 2003 14:58:49 -0000	1.7
+++ openacs-4/packages/simulation/lib/sim-objects.tcl	18 Nov 2003 15:59:11 -0000	1.8
@@ -17,6 +17,8 @@
 
 set package_id [ad_conn package_id]
 
+set add_url [export_vars -base "[ad_conn package_url]citybuild/object-edit" { parent_id }]
+
 if { ![exists_and_not_null parent_id] } {
     set parent_id [bcms::folder::get_id_by_package_id -parent_id 0]
 }
@@ -74,8 +76,6 @@
     set filter_sql ""
 }
 
-set add_url [export_vars -base "[apm_package_url_from_id $package_id]citybuild/object-edit" { parent_id }]
-
 template::list::create \
     -name objects \
     -multirow objects \
@@ -115,5 +115,3 @@
         }
     }
 }
-
-
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.2 -r1.3
--- openacs-4/packages/simulation/tcl/template-procs.tcl	18 Nov 2003 12:19:39 -0000	1.2
+++ openacs-4/packages/simulation/tcl/template-procs.tcl	18 Nov 2003 15:59:12 -0000	1.3
@@ -41,18 +41,27 @@
             -workflow_id $workflow_id \
             -short_name "dummy action" \
             -pretty_name "dummy action"
-        
-        db_dml new_sim "
+
+        set suggested_duration [string trim $suggested_duration]
+        if { [empty_string_p $suggested_duration] } {
+            db_dml new_sim {
+                insert into sim_simulations
+                (simulation_id, ready_p)
+                values (:workflow_id, :ready_p)
+            }
+        } else {
+            db_dml new_sim "
             insert into sim_simulations
             (simulation_id, ready_p, suggested_duration)
-            values ($workflow_id, '$ready_p', interval '$suggested_duration')
-        "
-            
+            values ('$workflow_id', '$ready_p', interval '$suggested_duration')"            
         }
+    }
+
     return $workflow_id
 }
 
 ad_proc -public simulation::template::edit {
+    {-workflow_id:required}
     {-short_name:required}
     {-pretty_name:required}
     {-ready_p "f"}
@@ -77,34 +86,40 @@
             update workflows
                set short_name=:short_name,
                    pretty_name=:pretty_name
-             where workflow_id=:object_id
-"
-        
-        db_dml edit_sim "
-            update sim_simulations
-               set ready_p=:ready_p, 
-                   suggested_duration=(interval ':suggested_duration')
-             where simulation_id=:object_id
-        "
-            
+             where workflow_id=:workflow_id"
+
+        if { [empty_string_p $suggested_duration] } {
+            db_dml edit_sim {
+                update sim_simulations
+                   set ready_p=:ready_p, 
+                       suggested_duration = null
+                 where simulation_id=:workflow_id
+            }
+        } else {
+            db_dml edit_sim "
+                update sim_simulations
+                   set ready_p=:ready_p, 
+                       suggested_duration=(interval '$suggested_duration')
+                 where simulation_id=:workflow_id
+            "
         }
-    return $workflow_id
+    }
 }
 
 ad_proc -public simulation::template::get {
-    {-package_key:required}
-    {-object_id:required}
+    {-workflow_id:required}
     {-array:required}
 } {
-    STUB ONLY.  Return information about a simulation template.  This should be a wrapper anound workflow::get, supplementing it with the columns from sim_simulation.
+    Return information about a simulation template.  This is a wrapper around 
+    workflow::get, supplementing it with the columns from sim_simulation.
 
-    @param object_id ID of simulation template.
+    @param workflow_id ID of simulation template.
     @param array name of array in which the info will be returned
-    @return An array list with keys workflow_id, short_name,
-            pretty_name, object_id, package_key, object_type, initial_action,
-            and callbacks, plus records in sim_simulation.
+                 Array will contain keys from the tables workflows and sim_simulations.
 } {
-    return 1
+    upvar $array row
+
+    db_1row select_template {} -column_array row
 }
 
 ad_proc -public simulation::template::delete {
Index: openacs-4/packages/simulation/tcl/template-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/template-procs.xql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/simulation/tcl/template-procs.xql	18 Nov 2003 15:59:12 -0000	1.1
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<queryset>
+
+  <fullquery name="simulation::template::get.select_template">
+        <querytext>
+          select w.workflow_id,
+                 w.short_name,
+                 w.pretty_name, 
+                 w.object_id, 
+                 w.package_key, 
+                 w.object_type, 
+                 s.suggested_duration,
+                 s.ready_p,
+                 s.enroll_type,
+                 s.casting_type,
+                 s.enroll_start,
+                 s.enroll_end,
+                 s.case_start,
+                 s.case_end,
+                 s.send_start_note_date 
+          from workflows w,
+               sim_simulations s
+          where w.workflow_id = :workflow_id
+            and w.workflow_id = s.simulation_id
+        </querytext>
+  </fullquery>
+
+</queryset>
Index: openacs-4/packages/simulation/test/demo-data-setup.test
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/test/demo-data-setup.test,v
diff -u -r1.4 -r1.5
--- openacs-4/packages/simulation/test/demo-data-setup.test	14 Nov 2003 13:46:46 -0000	1.4
+++ openacs-4/packages/simulation/test/demo-data-setup.test	18 Nov 2003 15:59:12 -0000	1.5
@@ -51,7 +51,7 @@
 
     ::twt::log_section "Create an image object"
     do_request /simulation/citybuild
-    link follow ~u object-edit?.*parent
+    link follow ~u object-edit
     form find ~n object
     field find ~n content_type
     field select2 ~v image
Index: openacs-4/packages/simulation/test/simulation-test-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/test/simulation-test-procs.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/simulation/test/simulation-test-procs.tcl	14 Nov 2003 13:47:16 -0000	1.1
+++ openacs-4/packages/simulation/test/simulation-test-procs.tcl	18 Nov 2003 15:59:12 -0000	1.2
@@ -20,7 +20,7 @@
     Create a new simulation image
 } {
     do_request /simulation/citybuild
-    link follow ~u object-edit?.*parent
+    link follow ~u object-edit
 
     # Choose object type image
     set_object_form_type image
@@ -47,7 +47,7 @@
     Create a new simulation object
 } {
     do_request /simulation/citybuild
-    link follow ~u object-edit?.*parent
+    link follow ~u object-edit
 
     set_object_form_type $type
 
Index: openacs-4/packages/simulation/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/index.tcl,v
diff -u -r1.9 -r1.10
--- openacs-4/packages/simulation/www/index.tcl	18 Nov 2003 09:44:31 -0000	1.9
+++ openacs-4/packages/simulation/www/index.tcl	18 Nov 2003 15:59:12 -0000	1.10
@@ -69,10 +69,6 @@
 
 set action_list [list "Add an Object" [export_vars -base object-edit { parent_id }] ]
 
-#error "
-#object_add_url: $object_add_url
-#add_action: $add_action"
-
 template::list::create \
     -name object_count \
     -multirow object_count \
Index: openacs-4/packages/simulation/www/simbuild/template-edit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/template-edit.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/simulation/www/simbuild/template-edit.tcl	18 Nov 2003 12:19:39 -0000	1.2
+++ openacs-4/packages/simulation/www/simbuild/template-edit.tcl	18 Nov 2003 15:59:12 -0000	1.3
@@ -31,20 +31,18 @@
         {label "Template Name"}
         {html {size 40}}
     }
-    {ready_p:boolean(checkbox),optional
+    {ready_p:boolean(radio),optional
         {label "Ready for use?"}
-        {options {""}}
+        {options {{Yes t} {No f}}}
     }
-    {suggested_duration:string,optional
+    {suggested_duration:text,optional
         {label "Suggested Duration"}
     }
 } -edit_request {
-    workflow::get -workflow_id $workflow_id -array sim_template_array
+    simulation::template::get -workflow_id $workflow_id -array sim_template_array
     set name $sim_template_array(pretty_name)
-    set ready_p 't' 
-#TODO: replace workflow api call with simulation::template::get,
-# combining data from workflows with data from sim_simulation,
-# hence providing $sim_template_array(ready_p)
+    set ready_p $sim_template_array(ready_p)
+    set suggested_duration $sim_template_array(suggested_duration)
 } -new_data {
     set workflow_id [simulation::template::new \
                          -short_name $name \
@@ -54,17 +52,17 @@
                          -package_key $package_key \
                          -object_id $package_id]
 } -edit_data {
-    set workflow_id [simulation::template::edit \
-                         -short_name $name \
-                         -pretty_name $name \
-                         -ready_p $ready_p \
-                         -suggested_duration $suggested_duration \
-                         -package_key $package_key \
-                         -object_id $package_id]
+    simulation::template::edit \
+        -workflow_id $workflow_id \
+        -short_name $name \
+        -pretty_name $name \
+        -ready_p $ready_p \
+        -suggested_duration $suggested_duration \
+        -package_key $package_key \
+        -object_id $package_id
 
-
 } -after_submit {
-    ad_returnredirect template-edit?workflow_id=$workflow_id
+    ad_returnredirect [export_vars -base "template-edit" { workflow_id }]
     ad_script_abort
 }