Index: openacs-4/packages/simulation/lib/messages.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/messages.tcl,v
diff -u -r1.21.2.3 -r1.21.2.4
--- openacs-4/packages/simulation/lib/messages.tcl	2 Nov 2006 07:17:10 -0000	1.21.2.3
+++ openacs-4/packages/simulation/lib/messages.tcl	2 Nov 2006 10:44:12 -0000	1.21.2.4
@@ -96,8 +96,10 @@
 } else {
     lappend elements delete
     lappend elements {
-      link_url_col delete_url
       label {[_ simulation.Delete]}
+      display_template {
+        <a href="@messages.delete_url@" title="#simulation.Delete#"><img src="/resources/acs-subsite/Delete16.gif" alt="delete" /></a>
+      }
     }
     
     lappend extend delete
Index: openacs-4/packages/simulation/lib/portfolio.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/portfolio.tcl,v
diff -u -r1.10.2.2 -r1.10.2.3
--- openacs-4/packages/simulation/lib/portfolio.tcl	2 Nov 2006 07:17:10 -0000	1.10.2.2
+++ openacs-4/packages/simulation/lib/portfolio.tcl	2 Nov 2006 10:44:12 -0000	1.10.2.3
@@ -74,16 +74,20 @@
 } else {
     lappend elements delete
     lappend elements {
-      link_url_col delete_url
       label {[_ simulation.Delete]}
+      display_template {
+        <a href="@documents.delete_url@" title="#simulation.Delete#"><img src="/resources/acs-subsite/Delete16.gif" alt="delete" /></a>
+      }
     }
     
 }
 
 lappend elements rename
 lappend elements {
-  link_url_col rename_url
   label {[_ simulation.Rename]}
+  display_template {
+    <a href="@documents.rename_url@" title="#simulation.Rename#"><img src="/resources/acs-subsite/Edit16.gif" alt="Rename" /></a>
+  }
 }
 
 template::list::create \
Index: openacs-4/packages/simulation/lib/sim-template-roles.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/sim-template-roles.tcl,v
diff -u -r1.14.2.1 -r1.14.2.2
--- openacs-4/packages/simulation/lib/sim-template-roles.tcl	31 Oct 2006 10:13:02 -0000	1.14.2.1
+++ openacs-4/packages/simulation/lib/sim-template-roles.tcl	2 Nov 2006 10:44:12 -0000	1.14.2.2
@@ -62,6 +62,18 @@
             display_col pretty_name
             link_url_col edit_url
         }
+        character {
+            label "Character"
+            display_template {
+              <if @roles.character_name@ eq "">
+              <em>Not selected</em>
+              </if>
+              <else>
+              @roles.character_name@
+              </else>
+            }
+            link_url_col char_url
+        }
         delete {
             sub_class narrow
             link_url_col delete_url
@@ -78,13 +90,19 @@
 db_multirow -extend { edit_url char_url delete_url up_url down_url } roles select_roles "
     select wr.role_id,
            wr.pretty_name,
-           wr.sort_order
-      from workflow_roles wr
+           wr.sort_order,
+           ci.name as character_name
+      from workflow_roles wr,
+           sim_roles sr
+      left join cr_items ci on (sr.character_id = ci.item_id)
      where wr.workflow_id = :workflow_id
+       and wr.role_id = sr.role_id
      order by wr.sort_order
 " {
     incr counter
     set edit_url [export_vars -base "[apm_package_url_from_id $package_id]simbuild/role-edit" { role_id }]
+    set char_url [ad_decode $character_name "" "" "[apm_package_url_from_id $package_id]object/${character_name}"]
+    
     set delete_url [export_vars -base "[apm_package_url_from_id $package_id]simbuild/role-delete" { role_id { return_url [ad_return_url] } }]
     if { $counter > 1 } {
         set up_url [export_vars -base "[ad_conn package_url]simbuild/template-object-reorder" { { type role } role_id { direction up } { return_url [ad_return_url] } }]
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.29.2.3 -r1.29.2.4
--- openacs-4/packages/simulation/sql/postgresql/simulation-tables-create.sql	2 Nov 2006 07:17:11 -0000	1.29.2.3
+++ openacs-4/packages/simulation/sql/postgresql/simulation-tables-create.sql	2 Nov 2006 10:44:12 -0000	1.29.2.4
@@ -206,21 +206,21 @@
 comment on table sim_cases is 'The object behind a simulation case.';
 
 create table sim_messages_trash (
-  message_id            integer         constraint sim_trash_id_nn
+  message_id            integer         constraint sim_messages_trash _id_nn
                                         not null
-                                        constraint sim_trash_id_fk
+                                        constraint sim_messages_trash _id_fk
                                         references sim_messages,
-  role_id               integer         constraint sim_trash_role_nn
+  role_id               integer         constraint sim_messages_trash _role_nn
                                         not null,
-  case_id               integer         constraint sim_trash_case_nn
+  case_id               integer         constraint sim_messages_trash _case_nn
                                         not null,
   PRIMARY KEY (message_id, role_id, case_id)
 );
 
 comment on table sim_messages_trash is 'For storing trashed messages per role per case.';
 
 create table sim_portfolio_trash (
-  object_id             integer         constraint sim_trash_id_nn
+  object_id             integer         constraint sim_pt_id_nn
                                         not null
                                         constraint sim_pt_object_id_fk
                                         references acs_objects ON DELETE CASCADE,
Index: openacs-4/packages/simulation/sql/postgresql/upgrade/upgrade-1.0.0b5-1.1.0b1.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/sql/postgresql/upgrade/Attic/upgrade-1.0.0b5-1.1.0b1.sql,v
diff -u -r1.1.2.2 -r1.1.2.3
--- openacs-4/packages/simulation/sql/postgresql/upgrade/upgrade-1.0.0b5-1.1.0b1.sql	2 Nov 2006 07:17:11 -0000	1.1.2.2
+++ openacs-4/packages/simulation/sql/postgresql/upgrade/upgrade-1.0.0b5-1.1.0b1.sql	2 Nov 2006 10:44:12 -0000	1.1.2.3
@@ -1,19 +1,19 @@
 create table sim_messages_trash (
-  message_id            integer         constraint sim_trash_id_nn
+  message_id            integer         constraint sim_messages_trash_id_nn
                                         not null
-                                        constraint sim_trash_id_fk
+                                        constraint sim_messages_trash_id_fk
                                         references sim_messages,
-  role_id               integer         constraint sim_trash_role_nn
+  role_id               integer         constraint sim_messages_trash_role_nn
                                         not null,
-  case_id               integer         constraint sim_trash_case_nn
+  case_id               integer         constraint sim_messages_trash_case_nn
                                         not null,
   PRIMARY KEY (message_id, role_id, case_id)
 );
 
 comment on table sim_messages_trash is 'For storing trashed messages per role per case.';
 
 create table sim_portfolio_trash (
-  object_id             integer         constraint sim_trash_id_nn
+  object_id             integer         constraint sim_pt_id_nn
                                         not null
                                         constraint sim_pt_object_id_fk
                                         references acs_objects ON DELETE CASCADE,
Index: openacs-4/packages/simulation/tcl/character-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/character-procs.tcl,v
diff -u -r1.3.2.1 -r1.3.2.2
--- openacs-4/packages/simulation/tcl/character-procs.tcl	31 Oct 2006 10:13:02 -0000	1.3.2.1
+++ openacs-4/packages/simulation/tcl/character-procs.tcl	2 Nov 2006 10:44:12 -0000	1.3.2.2
@@ -12,15 +12,21 @@
     {-character_id:required}
     {-array:required}
 } {
-    Get basic information about a character. Gets the following attributes: uri, title.
+    Get basic information about a character. Gets the following attributes: title, description, in_directory_p.
 
     @param  array       The name of an array into which you want the information put. 
 
     @author Peter Marklund
 } {
     upvar $array row
 
-    db_1row select_character_info {} -column_array row
+    db_1row select_character_info {
+      select sc.*, cr.title, cr.description
+      from sim_characters sc, cr_revisions cr, cr_items ci
+      where sc.character_id = cr.revision_id
+      and cr.item_id = ci.item_id
+      and (sc.character_id = :character_id or ci.item_id = :character_id)
+    } -column_array row
 }
 
 ad_proc -public simulation::character::get_element {
Index: openacs-4/packages/simulation/tcl/message-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/message-procs.tcl,v
diff -u -r1.6.2.2 -r1.6.2.3
--- openacs-4/packages/simulation/tcl/message-procs.tcl	2 Nov 2006 07:17:11 -0000	1.6.2.2
+++ openacs-4/packages/simulation/tcl/message-procs.tcl	2 Nov 2006 10:44:12 -0000	1.6.2.3
@@ -184,7 +184,7 @@
         db_dml delete "insert into sim_messages_trash values (:message_id, :role_id, :case_id)"
       } else {
         db_dml undelete "
-            delete from sim_trash
+            delete from sim_messages_trash
             where message_id = :message_id 
             and role_id = :role_id
             and case_id = :case_id"
Index: openacs-4/packages/simulation/tcl/sim-role-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/sim-role-procs.tcl,v
diff -u -r1.12.2.1 -r1.12.2.2
--- openacs-4/packages/simulation/tcl/sim-role-procs.tcl	31 Oct 2006 10:13:02 -0000	1.12.2.1
+++ openacs-4/packages/simulation/tcl/sim-role-procs.tcl	2 Nov 2006 10:44:12 -0000	1.12.2.2
@@ -81,6 +81,14 @@
             set insert_names [list]
             set insert_values [list]
 
+            foreach attr {
+                character_name character_title character_item_id
+            } {
+              if {[info exists row($attr)]} {
+                unset row($attr)
+              }
+            }
+
             # Handle columns in the sim_roles table
             foreach attr { 
                 character_id users_per_case
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.71.2.1 -r1.71.2.2
--- openacs-4/packages/simulation/tcl/template-procs.tcl	31 Oct 2006 10:13:02 -0000	1.71.2.1
+++ openacs-4/packages/simulation/tcl/template-procs.tcl	2 Nov 2006 10:44:12 -0000	1.71.2.2
@@ -1585,11 +1585,21 @@
                 where workflow_id = :workflow_id and
                       trigger_type = 'init' and
                       parent_action_id = :action_id"] } {
-	    set ret_val 0
-	    break
+	          return 0
         }
     }
     
+    if { [db_string get_empty_roles "
+        select count(*)
+        from sim_roles sr,
+             workflow_roles wr
+        where sr.character_id is null
+        and sr.role_id = wr.role_id
+        and wr.workflow_id = :workflow_id"]} {
+        
+        return 0
+    }
+    
     return $ret_val
 }
 
Index: openacs-4/packages/simulation/tcl/ui-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/ui-procs.tcl,v
diff -u -r1.7.2.1 -r1.7.2.2
--- openacs-4/packages/simulation/tcl/ui-procs.tcl	31 Oct 2006 10:13:02 -0000	1.7.2.1
+++ openacs-4/packages/simulation/tcl/ui-procs.tcl	2 Nov 2006 10:44:13 -0000	1.7.2.2
@@ -17,10 +17,6 @@
 } {
     return {
         {item_id:key}
-	{description:richtext,optional
-	    {label {[_ simulation.Description]}}
-	    {mode display}
-	}
         {document_file:file(file)
             {label "Document file"}
         }
Index: openacs-4/packages/simulation/www/simbuild/role-edit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/role-edit.tcl,v
diff -u -r1.9.2.1 -r1.9.2.2
--- openacs-4/packages/simulation/www/simbuild/role-edit.tcl	31 Oct 2006 10:13:03 -0000	1.9.2.1
+++ openacs-4/packages/simulation/www/simbuild/role-edit.tcl	2 Nov 2006 10:44:13 -0000	1.9.2.2
@@ -23,7 +23,22 @@
 
 set package_key [ad_conn package_key]
 set package_id [ad_conn package_id]
+set user_id [ad_conn user_id]
 
+# Get the characters to show in a dropdown list
+set character_options [db_list_of_lists character_options {
+    select sc.title,
+           sc.item_id
+    from   sim_charactersx sc,
+           cr_items ci,
+           acs_objects ao
+    where  sc.item_id = ao.object_id
+    and    ci.item_id = sc.item_id 
+    and    ci.live_revision = sc.object_id
+    and    (sc.in_directory_p = 't' or ao.creation_user = :user_id)
+    order by sc.title
+}]
+
 ######################################################################
 #
 # role
@@ -45,13 +60,17 @@
         {label "Role Name"}
         {html {size 20}}
     }
+    {character_id:text(select)
+        {label "Character"}
+        {options $character_options}}
 } -edit_request {
     simulation::role::get -role_id $role_id -array role_array
     set workflow_id $role_array(workflow_id)
 
     permission::require_write_permission -object_id $workflow_id
 
     set pretty_name $role_array(pretty_name)
+    set character_id $role_array(character_id)
 
     workflow::get -workflow_id $workflow_id -array sim_template_array
 
@@ -80,6 +99,7 @@
 } -after_submit {
 
     set row(pretty_name) $pretty_name
+    set row(character_id) $character_id
     set row(short_name) {}
 
     set role_id [simulation::role::edit \
@@ -91,7 +111,7 @@
     # Let's mark this template edited
     set sim_type "dev_template"
 
-    ad_returnredirect [export_vars -base "template-sim-type-update" { workflow_id sim_type }]
+    ad_returnredirect -message [_ simulation.role_updated] [export_vars -base "template-sim-type-update" { workflow_id sim_type }]
     ad_script_abort
 }
 
Index: openacs-4/packages/simulation/www/simbuild/template-sim-type-update.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/template-sim-type-update.tcl,v
diff -u -r1.2 -r1.2.2.1
--- openacs-4/packages/simulation/www/simbuild/template-sim-type-update.tcl	30 Nov 2004 21:09:16 -0000	1.2
+++ openacs-4/packages/simulation/www/simbuild/template-sim-type-update.tcl	2 Nov 2006 10:44:13 -0000	1.2.2.1
@@ -8,11 +8,16 @@
     inits_exist -requires {workflow_id:integer} {
 	if { [string match $sim_type "ready_template"] } {
 	    if { ![simulation::template::check_init_p -workflow_id $workflow_id] } {
-		ad_complain "<p>Either the simulation template or one of its subworkflows
-                             seems to be missing an initial action. Please correct this
+		ad_complain "<h2>The simulation cannot yet be marked as ready</h2>
+		<p>There are a few possible reasons for this:</p>
+		<ul>
+		<li>Either the simulation template or one of its subworkflows
+                             is missing an initial action. Please correct this
                              before you try to mark this template ready for use.</p>
                              <p>Note that every subworkflow and parallel task must
-                             also have its own initial action.</p>"
+                             also have its own initial action.</li>
+    <li>All roles don't have an associated character. Correct this by assigning a character for each role you create for the template.</li>
+    </ul>"
 	    }
 	}
     }
@@ -26,4 +31,6 @@
     -workflow_id $workflow_id \
     -array row
 
-ad_returnredirect $return_url
\ No newline at end of file
+set message [ad_decode $sim_type "ready_template" [_ simulation.template_marked_as_ready] ""]
+
+ad_returnredirect -message $message $return_url
\ No newline at end of file
Index: openacs-4/packages/simulation/www/siminst/simulation-casting-3.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/siminst/simulation-casting-3.tcl,v
diff -u -r1.24 -r1.24.6.1
--- openacs-4/packages/simulation/www/siminst/simulation-casting-3.tcl	27 Jan 2004 12:48:39 -0000	1.24
+++ openacs-4/packages/simulation/www/siminst/simulation-casting-3.tcl	2 Nov 2006 10:44:13 -0000	1.24.6.1
@@ -39,12 +39,14 @@
 }
 
 foreach role_id [workflow::get_roles -workflow_id $workflow_id] {
-    set role_${role_id}_pretty_name [workflow::role::get_element -role_id $role_id -element pretty_name]
+    simulation::role::get -role_id $role_id -array role
+    set role_${role_id}_pretty_name $role(pretty_name)
+    set character_${role_id}_name [simulation::character::get_element -character_id $role(character_id) -element title]
 
     if { $num_groups > 0 } {
         lappend form [list \
                           users_per_case_${role_id}:integer \
-                          [list label "Number of users for <b>\$role_${role_id}_pretty_name</b>"] \
+                          [list label "Number of users for <b>\$role_${role_id}_pretty_name</b> (\$character_${role_id}_name)"] \
                           {value 1} \
                           {html {size 2}} \
                           [list section "\$role_${role_id}_pretty_name"]
Index: openacs-4/packages/simulation/www/siminst/wizard.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/siminst/wizard.tcl,v
diff -u -r1.12 -r1.12.6.1
--- openacs-4/packages/simulation/www/siminst/wizard.tcl	13 Jan 2004 12:45:09 -0000	1.12
+++ openacs-4/packages/simulation/www/siminst/wizard.tcl	2 Nov 2006 10:44:13 -0000	1.12.6.1
@@ -11,10 +11,9 @@
 wizard create siminst \
     -steps {
         1 -label "Settings" -url "simulation-edit"
-        2 -label "Roles" -url "map-characters"
-        3 -label "Tasks" -url "map-tasks"
-        4 -label "Participants" -url "simulation-participants"
-        5 -label "Casting" -url "simulation-casting-3"
+        2 -label "Tasks" -url "map-tasks"
+        3 -label "Participants" -url "simulation-participants"
+        4 -label "Casting" -url "simulation-casting-3"
     } -params {
         workflow_id
     }
@@ -23,16 +22,15 @@
 
 array set title {
     1 "Simulation Settings"
-    2 "Assign Characters to Roles"
-    3 "Populate Tasks"
-    4 "Select Participants"
-    5 "Define Casting Rules"
+    2 "Populate Tasks"
+    3 "Select Participants"
+    4 "Define Casting Rules"
 }
 
 wizard set_param workflow_id $workflow_id
 
 set lowest_available 1
-set highest_available 5
+set highest_available 4
 
 # Set information about which tabs are complete
 array set tab_complete_p [simulation::template::get_inst_state -workflow_id $workflow_id]
Index: openacs-4/packages/simulation/www/simplay/document-upload.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/document-upload.tcl,v
diff -u -r1.11.2.1 -r1.11.2.2
--- openacs-4/packages/simulation/www/simplay/document-upload.tcl	2 Nov 2006 07:17:11 -0000	1.11.2.1
+++ openacs-4/packages/simulation/www/simplay/document-upload.tcl	2 Nov 2006 10:44:13 -0000	1.11.2.2
@@ -14,8 +14,7 @@
 set page_title [_ simulation.lt_Upload_new_document_t]
 set context [list [list . [_ simulation.SimPlay]] \
                    [list [export_vars -base case { case_id role_id }] \
-                         [_ simulation.Case]] \ 
-                   $page_title]
+                         [_ simulation.Case]] $page_title]
 
 set workflow_id [workflow::case::get_element -case_id $case_id -element workflow_id]
 
Index: openacs-4/packages/simulation/www/simplay/portfolio-rename.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/Attic/portfolio-rename.tcl,v
diff -u -r1.1.2.1 -r1.1.2.2
--- openacs-4/packages/simulation/www/simplay/portfolio-rename.tcl	2 Nov 2006 07:17:11 -0000	1.1.2.1
+++ openacs-4/packages/simulation/www/simplay/portfolio-rename.tcl	2 Nov 2006 10:44:13 -0000	1.1.2.2
@@ -34,6 +34,7 @@
       {title:text(text),optional
           {label "Title"}
           {html {size 50}}
+          {help_text "[_ simulation.leave_blank]"}
       }
     } -select_query {
       select title