Index: openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-2.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-2.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-2.adp	24 Aug 2008 11:00:43 -0000	1.1
@@ -0,0 +1,75 @@
+<master>
+  <property name="doc(title)">@title;noquote@</property>
+  <property name="context">@context;noquote@</property>
+<h2>@title@</h2>
+
+<if @c_user_identification_id@ nil>
+@customer_id_html;noquote@
+</if>
+
+<h3>One issue</h3><p>A customer may discuss several issues during the course of one interaction.  Please
+enter the information about only one issue below:</p>
+
+<form method="post" action="interaction-add-3">
+ @export_form_vars1.html;noquote@
+  <table cellspacing="1" cellpadding="2">
+   @form_body_html;noquote@
+
+<if @issue_id@ nil>
+  <tr>
+    <td bgcolor="#cccccc" valign="top" align="right"><p>Previous Issue ID:</p></td>
+    <td bgcolor="#cccccc" valign="top"><input type="text" size="4" name="issue_id">
+    <p>If this is a new issue, please leave this blank (a new Issue ID will be generated)</p></td>
+    </tr>
+    <tr>
+    <td bgcolor="#cccccc" valign="top" align="right"><p>New Issue Type:</p></td>
+    <td bgcolor="#cccccc" valign="top"><p>(leave blank if based on an existing issue) @issue_type_widget_html;noquote@</p></td>
+    </tr>
+    <tr>
+    <td bgcolor="#99ccff" valign="top" align="right"><p>Order ID:</p></td>
+    <td bgcolor="#99ccff" valign="top"><input type="text" size="7" name="order_id">
+    <p>Fill this in if this inquiry is about a specific order.</p>
+    </td>
+    </tr>
+
+</if><else>
+
+<tr>
+    <td bgcolor="#99ccff" valign="top" align="right"><p>Issue ID:</p></td>
+    <td bgcolor="#99ccff" valign="top"><p>@issue_id@@export_form_vars_issue_id_html;noquote@</p></td>
+    </tr>
+    <tr>
+    <td bgcolor="#99ccff" valign="top" align="right"><p>Issue Type</p></td>
+    <td bgcolor="#99ccff" valign="top"><p>@issue_type_list_html;noquote@</p></td>
+    </tr>
+    <tr>
+    <td bgcolor="#99ccff" valign="top" align="right"><p>Order ID:</p></td>
+    <td bgcolor="#99ccff" valign="top"><p>@order_id_html;noquote@</p></td>
+    </tr>
+</else>
+
+<tr>
+<td bgcolor="#99ccff" valign="top" align="right"><p>Issue details:<br>(action_details)</p></td>
+<td bgcolor="#99ccff" valign="top"><textarea wrap name="action_details" rows="6" cols="45"></textarea></td>
+</tr>
+<tr>
+<td bgcolor="#99ccff" valign="top" align="right"><p>Resources used:</p></td>
+<td bgcolor="#99ccff" valign="top"><p>Information used to respond to inquiry @info_used_widget_html;noquote@</p></td>
+</tr>
+<tr>
+<td bgcolor="#99ccff" valign="top" align="right" rowspan="2"><p>Requires follow-up?</p></td>
+<td bgcolor="#99ccff" valign="top"><p><input type=radio name=close_issue_p value="f" checked>yes <b>requires follow-up</b><br>
+  &nbsp; &nbsp; Please&nbsp;elaborate:</p><textarea wrap name="follow_up_required" rows="2" cols="45"></textarea>
+</td>
+</tr>
+<tr>
+
+<td bgcolor="#99ccff" valign="top"><input type="radio" name="close_issue_p" value="t"><p>no (resolved)</p></td>
+</tr>
+</table>
+
+<center><p>Customer</p>
+<input type="submit" name="submit" value="Interaction complete">
+<input type="submit" name="submit" value="Add another issue as part of this interaction">
+</center>
+</form>
Index: openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-2.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-2.tcl,v
diff -u -r1.8 -r1.9
--- openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-2.tcl	18 Aug 2008 11:02:22 -0000	1.8
+++ openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-2.tcl	24 Aug 2008 11:00:43 -0000	1.9
@@ -1,5 +1,5 @@
 # interaction-add-2.tcl
-ad_page_contract { 
+ad_page_contract {
     @param open_date:optional
     @param interaction_type:optional
     @param interaction_type_other:optional
@@ -44,62 +44,55 @@
 # return_to_issue
 
 # the customer service rep must be logged on
-
 set customer_service_rep [ad_get_user_id]
-if {[empty_string_p $insert_id]} {
+if { [empty_string_p $insert_id] } {
     set insert_id 1
 }
-if {$insert_id ==0 } { 
 
+if { $insert_id == 0 } {
     # YYYY-MM-DD HH24:MI:SS
     set open_date_year  $open_date(year)
     set open_date_month $open_date(month)
     set open_date_day  $open_date(day)
     set open_date_time $open_date(time)
-
     set open_date_str "$open_date_year-$open_date_month-$open_date_day $open_date_time"
 } 
 
-if {$insert_id ==1} {
+if { $insert_id == 1 } {
     set open_date_str [db_string select_time "select to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') from dual"]
-
 }
 
-
 #doc_return  200 text/html "<b>year: $open_date_year <br>
 #month: $open_date_month <br>
 #day: $open_date_day<br>
 #time: $open_date_time<br></b>"
 
-if {$customer_service_rep == 0} {
+if { $customer_service_rep == 0 } {
     set return_url "[ad_conn url]?[export_entire_form_as_url_vars]"
     ad_returnredirect "/register.tcl?[export_url_vars return_url]"
     ad_script_abort
-}
+ }
 
 if { ![info exists interaction_id] } {
-
     set exception_count 0
     set exception_text ""
     
     if { ![info exists interaction_type] || [empty_string_p $interaction_type] } {
-	incr exception_count
-	append exception_text "<li>You forgot to specify the method of inquiry (phone/email/etc.).\n"
+        incr exception_count
+        append exception_text "<li>No method of inquiry (phone/email/etc.) exists. Please add.</li>\n"
     } elseif { $interaction_type == "other" && (![info exists interaction_type_other] || [empty_string_p $interaction_type_other]) } {
-	incr exception_count
-	append exception_text "<li>You forgot to fill in the text box detail for Other.\n"
+        incr exception_count
+        append exception_text "<li>The text box detail for Other is empty. Please add detail.</li>\n"
     } elseif { $interaction_type != "other" && ([info exists interaction_type_other] && ![empty_string_p $interaction_type_other]) } {
-	incr exception_count
-	append exception_text "<li>You selected \"Inquired via: [string toupper [string index $interaction_type 0]][string range $interaction_type 1 [expr [string length $interaction_type] -1]]\", but you also filled in something in the \"If Other, specify\" field.  This is inconsistent.\n"
+        incr exception_count
+        append exception_text "<li>You selected \"Inquired via: [string toupper [string index $interaction_type 0]][string range $interaction_type 1 [expr [string length $interaction_type] -1]]\", but you also filled in something in the \"If Other, specify\" field.  Please fill in one or the other, not both.</li>\n"
     }
-    
     if { $exception_count > 0 } {
-	ad_return_complaint $exception_count $exception_text
+        ad_return_complaint $exception_count $exception_text
         ad_script_abort
     }
-
     # done error checking
-}
+ }
 
 
 # Have to generate action_id
@@ -108,238 +101,137 @@
 # interaction_id will not be generated until the next page (if it doesn't
 # exist) so that I can use the fact of its existence or lack of existence
 # to create this page's UI
-
 set action_id [db_nextval ec_action_id_sequence]
 
+set title "One Issue"
+set context [list [list index "Customer Service"] $title]
 
-
-append doc_body "[ad_admin_header "One Issue"] 
-<h2>One Issue</h2>
-[ad_context_bar [list "../index.tcl" "Ecommerce([ec_system_name])"] [list "index.tcl" "Customer Service Administration"] "One Issue (part of New Interaction)"]
-
-<hr noshade>"
-
 if { ![info exists c_user_identification_id] } {
-    append doc_body "
-    <p><b>Customer identification:</b></p>
-    <p>
-    Here's what we could determine about the customer given the information you typed
-    into the previous form:
-    </p><ul>
-    "
-    
+    set customer_id_html "<p><b>Customer identification:</b></p>
+    <p>Here's what we could determine about the customer given the information you typed
+    into the previous form:</p><ul>"
     set positively_identified_p 0
     
     # see if we can find their city/state from the zip code
-    
     set location [ec_location_based_on_zip_code $postal_code]
-
     if { ![empty_string_p $location] } {
-	append doc_body "<li>They live in $location.</li>"
+        append customer_id_html "<li>They live in $location.</li>"
     }
-
     
     # I'll be setting variables d_user_id, d_user_identification_id, d_first_names, etc.,
     # based on the user info they typed into the last form.  "d" stands for "determined",
     # meaning that I determined it, as opposed to it being something that they typed in
     
     # if their email address was filled in, see if they're a registered user
     if { ![empty_string_p $email] } {
-	set email [string toupper $email]
-	if {  [db_0or1row get_does_row_exist_p "select first_names as d_first_names, last_name as d_last_name, user_id as d_user_id from cc_users where email =lower(:email) "]==1 } {
-	
-
-	    append doc_body "<li>This is a registered user of the system: <a target=user_window href=\"[ec_acs_admin_url]users/one?user_id=$d_user_id\">$d_first_names $d_last_name</a>.
-	    [export_form_vars d_user_id]"
-	    set positively_identified_p 1
-	}
-	
+        set email [string toupper $email]
+        if {  [db_0or1row get_does_row_exist_p "select first_names as d_first_names, last_name as d_last_name, user_id as d_user_id from cc_users where email =lower(:email) "]==1 } {
+            append customer_id_html "<li>This is a registered user of the system: <a target=user_window href=\"[ec_acs_admin_url]users/one?user_id=$d_user_id\">$d_first_names $d_last_name</a>.[export_form_vars d_user_id]</li>"
+            set positively_identified_p 1
+        }
     }
     
     if { !$positively_identified_p } {
-	# then keep trying to identify them
-	
-	if { ![empty_string_p $first_names] || ![empty_string_p $last_name] } {
-	    if { ![empty_string_p $first_names] && ![empty_string_p $last_name] } {
-		set sql "select email, user_id as d_user_id from cc_users where upper(first_names)=upper (:first_names) and upper(last_name)=upper(:last_name)"
-		db_foreach get_user_ids $sql {
-		    append doc_body "<li>This may be the registered user <a target=user_window href=\"customer-history?customer_type=user_id&customer_id=$d_user_id\">$first_names $last_name</a> $email (check here <input type=checkbox name=d_user_id value=$d_user_id> if this is correct).</li>"
-		}
-	    } elseif { ![empty_string_p $first_names] } {
-		set sql "select email, user_id as d_user_id, last_name as d_last_name from cc_users where upper(first_names)=upper(:first_names)"
-		
-		db_foreach get_user_id_and_lname $sql {
-		    
-		    append doc_body "<li>This may be the registered user <a target=user_window href=\"customer-history?customer_type=user_id&customer_id=$d_user_id\">$first_names $d_last_name</a> $email (check here <input type=checkbox name=d_user_id value=$d_user_id> if this is correct).\n</li>"
-		}
-		
-	    } elseif { ![empty_string_p $last_name] } {
-		set sql "select email, user_id as d_user_id, first_names as d_first_names from cc_users where upper(last_name)=upper(:last_name)"
-		
-		db_foreach get_user_id_and_names $sql {
-		    
-		    append doc_body "<li>This may be the registered user <a target=user_window href=\"customer-history?customer_type=user_id&customer_id=$d_user_id\">$d_first_names $last_name</a> $email (check here <input type=checkbox name=d_user_id value=$d_user_id> if this is correct).\n</li>"
-		}
-		
-	    }
-	}
-
-	# also see if they might be a non-user who
-	# has had an interaction before
-	
-	set already_selected_user_identification_id_list [list]
-	if { ![empty_string_p $email] } {
-	    set sql "select user_identification_id as d_user_identification_id from ec_user_identification where email=lower(:email) and user_id is null"
-	    
-	    db_foreach get_user_identification $sql {
-		
-		append doc_body "<li>This may be the non-registered person who has had a previous interaction with us: [ec_user_identification_summary $d_user_identification_id "t"] (check here <input type=checkbox name=d_user_identification_id value=$d_user_identification_id> if this is correct).</li>"
-		lappend already_selected_user_identification_id_list $d_user_identification_id
-	    }
-	}
-	
-	set additional_and_clause ""
-	if { [llength $already_selected_user_identification_id_list] > 0 } {
-	    set additional_and_clause "and user_identification_id not in ([join $already_selected_user_identification_id_list ", "])"
-	}
-	
-	if { ![empty_string_p $first_names] || ![empty_string_p $last_name] } {
-	    if { ![empty_string_p $first_names] && ![empty_string_p $last_name] } {
-		set sql "select user_identification_id as d_user_identification_id from ec_user_identification where upper(first_names)=upper(:first_names) and upper(last_name)=upper(:last_name) and user_id is null $additional_and_clause"
-	    } elseif { ![empty_string_p $first_names] } {
-		set sql "select user_identification_id as d_user_identification_id from ec_user_identification where upper(first_names)=upper(:first_names) and user_id is null $additional_and_clause"
-	    } elseif { ![empty_string_p $last_name] } {
-		set sql "select user_identification_id as d_user_identification_id from ec_user_identification where upper(last_name)=upper(:last_name) and user_id is null $additional_and_clause"
-	    }
-	    
-	    db_foreach get_user_identification_info $sql {
+        # then keep trying to identify them
+        if { ![empty_string_p $first_names] || ![empty_string_p $last_name] } {
+            if { ![empty_string_p $first_names] && ![empty_string_p $last_name] } {
+                set sql "select email, user_id as d_user_id from cc_users where upper(first_names)=upper (:first_names) and upper(last_name)=upper(:last_name)"
+                db_foreach get_user_ids $sql {
+                    append customer_id_html "<li>This may be the registered user <a target=user_window href=\"customer-history?customer_type=user_id&customer_id=$d_user_id\">$first_names $last_name</a> $email (check here <input type=checkbox name=d_user_id value=$d_user_id> if this is correct).</li>"
+                }
+            } elseif { ![empty_string_p $first_names] } {
+                set sql "select email, user_id as d_user_id, last_name as d_last_name from cc_users where upper(first_names)=upper(:first_names)"
+                db_foreach get_user_id_and_lname $sql {
+                    append customer_id_html "<li>This may be the registered user <a target=user_window href=\"customer-history?customer_type=user_id&customer_id=$d_user_id\">$first_names $d_last_name</a> $email (check here <input type=checkbox name=d_user_id value=$d_user_id> if this is correct).\n</li>"
+                }
+            } elseif { ![empty_string_p $last_name] } {
+                set sql "select email, user_id as d_user_id, first_names as d_first_names from cc_users where upper(last_name)=upper(:last_name)"
+                db_foreach get_user_id_and_names $sql {
+                    append customer_id_html "<li>This may be the registered user <a target=user_window href=\"customer-history?customer_type=user_id&customer_id=$d_user_id\">$d_first_names $last_name</a> $email (check here <input type=checkbox name=d_user_id value=$d_user_id> if this is correct).\n</li>"
+                }
+            }
+        }
+        
+        # also see if they might be a non-user who
+        # has had an interaction before
+        set already_selected_user_identification_id_list [list]
+        if { ![empty_string_p $email] } {
+            set sql "select user_identification_id as d_user_identification_id from ec_user_identification where email=lower(:email) and user_id is null"
+            db_foreach get_user_identification $sql {
+                append customer_id_html "<li>This may be the non-registered person who has had a previous interaction with us: [ec_user_identification_summary $d_user_identification_id "t"] (check here <input type=checkbox name=d_user_identification_id value=$d_user_identification_id> if this is correct).</li>"
+                lappend already_selected_user_identification_id_list $d_user_identification_id
+            }
+        }
+        
+        set additional_and_clause ""
+        if { [llength $already_selected_user_identification_id_list] > 0 } {
+            set additional_and_clause "and user_identification_id not in ([join $already_selected_user_identification_id_list ", "])"
+        }
+        if { ![empty_string_p $first_names] || ![empty_string_p $last_name] } {
+            if { ![empty_string_p $first_names] && ![empty_string_p $last_name] } {
+                set sql "select user_identification_id as d_user_identification_id from ec_user_identification where upper(first_names)=upper(:first_names) and upper(last_name)=upper(:last_name) and user_id is null $additional_and_clause"
+            } elseif { ![empty_string_p $first_names] } {
+                set sql "select user_identification_id as d_user_identification_id from ec_user_identification where upper(first_names)=upper(:first_names) and user_id is null $additional_and_clause"
+            } elseif { ![empty_string_p $last_name] } {
+                set sql "select user_identification_id as d_user_identification_id from ec_user_identification where upper(last_name)=upper(:last_name) and user_id is null $additional_and_clause"
+            }
+            db_foreach get_user_identification_info $sql {
 # need to add a db0or1row select ec_customer_service_issues.user_identification where ec_customer_service_issues.issue_id = ec_cs_issue_type_map.issue_id and ec_customer_service_issues.user_identification = $user_identification  *** actually, see if you can add the restriction to the loops query, and check if db_foreach skips if no hits, otherwise have to check for it first.
-# if exists then proceed with this iteration of the loop, otherwise ignore it as a false positive.		
+# if exists then proceed with this iteration of the loop, otherwise ignore it as a false positive.        
 # the other possibility is to identify when the customer_service.issue_id is created, and why the map is not...
-		append doc_body "<li>This may be the non-registered person who has had a previous interaction with us: [ec_user_identification_summary $d_user_identification_id "t"] (check here <input type=checkbox name=d_user_identification_id value=$d_user_identification_id> if this is correct).</li>"
-		lappend already_selected_user_identification_id_list $d_user_identification_id
-	    }
-	}
-	
-	if { [llength $already_selected_user_identification_id_list] > 0 } {
-	    set additional_and_clause "and user_identification_id not in ([join $already_selected_user_identification_id_list ", "])"
-	}
-	
-	if { ![empty_string_p $other_id_info] } {
-	    set sql "select user_identification_id as d_user_identification_id from ec_user_identification where other_id_info like '%[DoubleApos $other_id_info]%' $additional_and_clause"
-	    
-	    db_foreach get_user_identification_info $sql {
-		
-		append doc_body "<li>This may be the non-registered person who has had a previous interaction with us: [ec_user_identification_summary $d_user_identification_id "t"] (check here <input type=checkbox name=d_user_identification_id value=$d_user_identification_id> if this is correct).</li>"
-		lappend already_selected_user_identification_id_list $d_user_identification_id
-	    }
-	    
-	}
-	
-	if { [llength $already_selected_user_identification_id_list] > 0 } {
-	    set additional_and_clause "and user_identification_id not in ([join $already_selected_user_identification_id_list ", "])"
-	}
-	
-	if { ![empty_string_p $postal_code] } {
-	    set sql "select user_identification_id as d_user_identification_id from ec_user_identification where postal_code=:postal_code $additional_and_clause"
-	    
-	    db_foreach get_user_ids_by_postal_code $sql {
-		
-		append doc_body "<li>This may be the non-registered person who has had a previous interaction with us: [ec_user_identification_summary $d_user_identification_id "t"] (check here <input type=checkbox name=d_user_identification_id value=$d_user_identification_id> if this is correct).</li>"
-		lappend already_selected_user_identification_id_list $d_user_identification_id
-	    }
-	}
+                append customer_id_html "<li>This may be the non-registered person who has had a previous interaction with us: [ec_user_identification_summary $d_user_identification_id "t"] (check here <input type=checkbox name=d_user_identification_id value=$d_user_identification_id> if this is correct).</li>"
+                lappend already_selected_user_identification_id_list $d_user_identification_id
+            }
+        }
+    
+        if { [llength $already_selected_user_identification_id_list] > 0 } {
+            set additional_and_clause "and user_identification_id not in ([join $already_selected_user_identification_id_list ", "])"
+        }
+        if { ![empty_string_p $other_id_info] } {
+            set sql "select user_identification_id as d_user_identification_id from ec_user_identification where other_id_info like '%[DoubleApos $other_id_info]%' $additional_and_clause"
+            db_foreach get_user_identification_info $sql {
+                append customer_id_html "<li>This may be the non-registered person who has had a previous interaction with us: [ec_user_identification_summary $d_user_identification_id "t"] (check here <input type=checkbox name=d_user_identification_id value=$d_user_identification_id> if this is correct).</li>"
+                lappend already_selected_user_identification_id_list $d_user_identification_id
+            }
+        }
+        
+        if { [llength $already_selected_user_identification_id_list] > 0 } {
+            set additional_and_clause "and user_identification_id not in ([join $already_selected_user_identification_id_list ", "])"
+        }
+        if { ![empty_string_p $postal_code] } {
+            set sql "select user_identification_id as d_user_identification_id from ec_user_identification where postal_code=:postal_code $additional_and_clause"
+            db_foreach get_user_ids_by_postal_code $sql {
+                append customer_id_html "<li>This may be the non-registered person who has had a previous interaction with us: [ec_user_identification_summary $d_user_identification_id "t"] (check here <input type=checkbox name=d_user_identification_id value=$d_user_identification_id> if this is correct).</li>"
+                lappend already_selected_user_identification_id_list $d_user_identification_id
+            }
+        }
     }
-    append doc_body "</ul>"
+    append customer_id_html "</ul>"
 }
 
-append doc_body "<h3>One issue</h3><p>A customer may discuss several issues during the course of one interaction.  Please
-enter the information about only one issue below:</p>
+set export_form_vars1_html [export_form_vars interaction_id c_user_identification_id action_id open_date_str interaction_type interaction_type_other interaction_originator first_names last_name email postal_code other_id_info return_to_issue insert_id]
 
-<form method=\"post\" action=\"interaction-add-3\">
-[export_form_vars interaction_id c_user_identification_id action_id open_date_str interaction_type interaction_type_other interaction_originator first_names last_name email postal_code other_id_info return_to_issue insert_id]
-
-<table cellspacing=\"1\" cellpadding=\"2\">"
-
 if { [info exists c_user_identification_id] } {
-    append doc_body "<tr>
+    append form_body_html "<tr>
     <td bgcolor=\"\#cccccc\" valign=\"top\" align=\"right\">Customer:</td>
     <td bgcolor=\"\#cccccc\" valign=\"top\">[ec_user_identification_summary $c_user_identification_id "t"]"
 
     if { [info exists postal_code] } {
-	append doc_body "<br>
-	[ec_location_based_on_zip_code $postal_code]"
+        append form_body_html "<br>[ec_location_based_on_zip_code $postal_code]"
     }
+    append form_body_html "</td></tr>\n"
+ }
 
-    append doc_body "</td>
-    </tr>"
-}
-
-if { ![info exists issue_id] } {
-    append doc_body "<tr>
-    <td bgcolor=\"\#cccccc\" valign=\"top\" align=\"right\">Previous Issue ID:</td>
-    <td bgcolor=\"\#cccccc\" valign=\"top\"><input type=\"text\" size=\"4\" name=\"issue_id\">
-    If this is a new issue, please leave this blank (a new Issue ID will be generated)</td>
-    </tr>
-    <tr>
-    <td bgcolor=\"\#cccccc\" valign=\"top\" align=\"right\">New Issue Type:</td>
-    <td bgcolor=\"\#cccccc\" valign=\"top\"> (leave blank if based on an existing issue) [ec_issue_type_widget]</td>
-    </tr>
-    <tr>
-    <td bgcolor=\"\#99ccff\" valign=\"top\" align=\"right\">Order ID:</td>
-    <td bgcolor=\"\#99ccff\" valign=\"top\"><input type=\"text\" size=\"7\" name=\"order_id\">
-    Fill this in if this inquiry is about a specific order.
-    </td>
-    </tr>
-    "
-} else {
+if { [info exists issue_id] } {
     set order_id [db_string get_order_id "select order_id from ec_customer_service_issues where issue_id=:issue_id"]
-    set issue_type_list [db_list get_is`<sue_type_list "select issue_type from ec_cs_issue_type_map where issue_id=:issue_id"]
-
-    append doc_body "<tr>
-    <td bgcolor=\"\#99ccff\" valign=\"top\" align=\"right\">Issue ID:</td>
-    <td bgcolor=\"\#99ccff\" valign=\"top\">$issue_id[export_form_vars issue_id]</td>
-    </tr>
-    <tr>
-    <td bgcolor=\"\#99ccff\" valign=\"top\" align=\"right\">Issue Type</td>
-    <td bgcolor=\"\#99ccff\" valign=\"top\">[join $issue_type_list ", "]</td>
-    </tr>
-    <tr>
-    <td bgcolor=\"\#99ccff\" valign=\"top\" align=\"right\">Order ID:</td>
-    <td bgcolor=\"\#99ccff\" valign=\"top\">[ec_decode $order_id "" "none" $order_id]</td>
-    </tr>
-"
+    set issue_type_list [db_list get_issue_type_list "select issue_type from ec_cs_issue_type_map where issue_id=:issue_id"]
+    set issue_type_list_html [join $issue_type_list ", "]
+    set export_form_vars_issue_id_html [export_form_vars issue_id]
+    set order_id_html [ec_decode $order_id "" "none" $order_id]
+} else {
+    set issue_type_widget_html [ec_issue_type_widget]
 }
-append doc_body "<tr>
-<td bgcolor=\"\#99ccff\" valign=\"top\" align=\"right\">Issue details:<br>(action_details)</td>
-<td bgcolor=\"\#99ccff\" valign=\"top\"><textarea wrap name=\"action_details\" rows=\"6\" cols=\"45\"></textarea></td>
-</tr>
-<tr>
-<td bgcolor=\"\#99ccff\" valign=\"top\" align=\"right\">Resources used:</td>
-<td bgcolor=\"\#99ccff\" valign=\"top\">Information used to respond to inquiry [ec_info_used_widget]</td>
-</tr>
-<tr>
-<td bgcolor=\"\#99ccff\" valign=\"top\" align=\"right\" rowspan=\"2\">Requires follow-up?</td>
-<td bgcolor=\"\#99ccff\" valign=\"top\">
-<input type=radio name=close_issue_p value=\"f\" checked>yes <b>requires follow-up</b><br>
-&nbsp;&nbsp;&nbsp;&nbsp;Please elaborate:<textarea wrap name=\"follow_up_required\" rows=\"2\" cols=\"45\"></textarea>
 
-</td>
-</tr>
-<tr>
+set info_used_widget_html [ec_info_used_widget]
 
-<td bgcolor=\"\#99ccff\" valign=\"top\"><input type=\"radio\" name=\"close_issue_p\" value=\"t\">no (resolved)</td>
-</tr>
-</table>
-"
 
-
-append doc_body "<center>Customer 
-<input type=\"submit\" name=\"submit\" value=\"Interaction complete\">
-<input type=\"submit\" name=\"submit\" value=\"Add another issue as part of this interaction\">
-</center>
-</form>
-[ad_admin_footer]
-"
-doc_return  200 text/html $doc_body
-
Index: openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-3.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-3.adp,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-3.adp	24 Aug 2008 11:00:43 -0000	1.1
@@ -0,0 +1,51 @@
+<master>
+  <property name="doc(title)">@title;noquote@</property>
+  <property name="context">@context;noquote@</property>
+<h2>@title@</h2>
+
+<if @error_path@ eq "1">
+ <p>The selected user is not the customer involved in this interaction.</p>
+ <p>Would you like to make this user be the owner of this interaction?
+ (If not, push Back button and fix the issue ID.)</p>
+ <form method="post" action="interaction-add-3">
+  @hidden_input_html;noquote@
+  @export_entire_form_except_html;noquote@
+  <center>
+   <input type="submit" value="Yes">
+  </center>
+ </form>
+</if><else>
+
+<if @error_path@ eq "2">
+ <p>Issue ID @issue_id@ belongs to the the non-registered person who
+has had a previous interaction with us: @user_id_summary_html;noquote@
+However, that user has not been selected as the customer involved in this interaction.
+ </p><p>
+Would you like to make this user be the owner of this interaction?
+(If not, push Back button and fix the issue ID.)</p>
+ <form method="post" action="interaction-add-3">
+  @hidden_input_html;noquote@  @export_entire_form_html;noquote@
+  <center>
+   <input type="submit" value="Yes">
+  </center>
+ </form>
+</if><else>
+
+<if @error_path@ eq "3">
+  <p>Order ID @order_id@ belongs to the registered user
+  @registered_user_html;noquote@.  However, you haven't selected that user as the customer involved in this interaction.
+</p><p>
+Would you like to make this user be the owner of this interaction?
+(If not, push Back button and fix the order ID.)
+</p>
+<form method="post" action="interaction-add-3">
+ @hidden_input_html;noquote@  @export_entire_form_html;noquote@
+  <center>
+    <input type="submit" value="Yes">
+  </center>
+ </form>
+</if><else>
+
+<!-- no input/output here. Page should redirect -->
+
+</else></else></else>
Index: openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-3.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-3.tcl,v
diff -u -r1.8 -r1.9
--- openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-3.tcl	18 Aug 2008 11:02:23 -0000	1.8
+++ openacs-4/packages/ecommerce/www/admin/customer-service/interaction-add-3.tcl	24 Aug 2008 11:00:43 -0000	1.9
@@ -1,5 +1,4 @@
 # interaction-add-3.tcl
-
 ad_page_contract {  
     @param open_date_str:optional
     @param interaction_type:optional
@@ -63,7 +62,7 @@
 
 # doubleclick protection:
 if { [db_string get_service_action_count "select count(*) from ec_customer_service_actions where action_id=:action_id"] > 0 } {
-ns_log Notice "interaction-add-3.tcl: double click protection, line 65"
+    ns_log Notice "interaction-add-3.tcl: double click protection, line 65"
     ad_returnredirect index
 } elseif { $submit != "Interaction complete" } {
 	# I have to use the action_id to figure out user_identification_id
@@ -77,7 +76,6 @@
 }
 
 # the customer service rep must be logged on
-
 set customer_service_rep [ad_get_user_id]
 
 if {$customer_service_rep == 0} {
@@ -87,6 +85,7 @@
 }
 
 # error checking
+set error_path 0
 # what matters for the logic of the customer service system:
 # 1. that we don't have more than one d_user_id or d_user_identification_id
 #    (it's ok to have zero -- then a new user_identification_id will be generated,
@@ -102,26 +101,21 @@
 # first some little checks on the input data
 
 # issue_id and order_id should be numbers and action_details should be non-empty
-
 if { [regexp "\[^0-9\]+" $issue_id] } {
     incr exception_count
-    append exception_text "<li>The issue ID should be numeric.\n"
+    append exception_text "<li>The issue ID should be numeric.</li>\n"
 }
-
 if { [info exists order_id] && [regexp "\[^0-9\]+" $order_id] } {
     incr exception_count
-    append exception_text "<li>The Order ID should be numeric.\n"
+    append exception_text "<li>The Order ID should be numeric.</li>\n"
 }
-
 if { $exception_count > 0 } {
     ad_return_complaint $exception_count $exception_text
     ad_script_abort
 }
 
 # now for the painful checks
 
-
-
 # consistent issue ownership
 
 # If it's the first time through, give them the chance of matching up a 
@@ -135,98 +129,53 @@
     where u.user_identification_id = i.user_identification_id
     and i.issue_id=:issue_id"]==0 } {
 
-	ad_return_complaint 1 "<li>The Issue ID that you specified is invalid.  Please go back and check the Issue ID you entered.  If this is a new issue, please leave the issue ID blank.</li>"
+        ad_return_complaint 1 "<li>The Issue ID that you specified is invalid.  Please go back and check the Issue ID you entered.  If this is a new issue, please leave the issue ID blank.</li>"
         ad_script_abort
-    }
-    
+    }    
 
     if { ![info exists c_user_identification_id] } {
-	# if the issue has a user_id associated with it and d_user_id doesn't exist or match
-	# the associated user_id, then give them a message with the chance to make them match
-	if { ![empty_string_p $issue_user_id] } {
-	    if { ![info exists d_user_id] || [string compare $d_user_id $issue_user_id] != 0 } {
-		
-		append doc_body "[ad_admin_header "User Doesn't Match Issue"]
-		<h2>User Doesn't Match Issue</h2>
-		[ad_context_bar [list "../index.tcl" "Ecommerce([ec_system_name])"] [list "index.tcl" "Customer Service Administration"] "New Interaction"]
-		
-		<hr>
-		Issue ID $issue_id belongs to the registered user <a href=\"[ec_acs_admin_url]users/one?user_id=$issue_user_id\">[db_string get_full_name "select first_names || ' ' || last_name from cc_users where user_id=:issue_user_id"]</a>.
-		
-		</p><p>
-		
-		However, you haven't selected that user as the customer involved in this interaction.
-		
-		</p><p>
-		
-		Would you like to make this user be the owner of this interaction?  (If not, push Back and fix the issue ID.)
-		</p>
-		<form method=\"post\" action=\"interaction-add-3\">
-		[ec_hidden_input "d_user_id" $issue_user_id]
-		[ec_export_entire_form_except d_user_id d_user_identification_id]
-		<center>
-		<input type=\"submit\" value=\"Yes\">
-		</center>
-		</form>
-		
-		[ad_admin_footer]
-		"
-                ad_script_abort
-	    }
-	} elseif { ![info exists d_user_identification_id] || [string compare $d_user_identification_id $issue_user_identification_id] != 0 } {
-	    # if d_user_identification_id doesn't match the issue's user_identification_id, give
-	    # them a message with the chance to make them match
+        # if the issue has a user_id associated with it and d_user_id doesn't exist or match
+        # the associated user_id, then give them a message with the chance to make them match
+        set title  "Error: User Does Not Match Issue"
+        set context [list [list index "Customer Service"] $title]
 
-	    
-	    append doc_body "[ad_admin_header "User Doesn't Match Issue"]
-	    <h2>User Doesn't Match Issue</h2>
-	    [ad_context_bar [list "../index.tcl" "Ecommerce([ec_system_name])"] [list "index.tcl" "Customer Service Administration"] "New Interaction"]
-	    
-	    <hr>
- 	    <p>Issue ID $issue_id belongs to the the non-registered person who has had a previous interaction with us: [ec_user_identification_summary $issue_user_identification_id]
-	    
-	    </p><p>
-	    
-	    However, you haven't selected that user as the customer involved in this interaction.
-	    
-	    </p><p>
-	    
-	    Would you like to make this user be the owner of this interaction?  (If not, push Back and fix the issue ID.)
-	    </p>
-	    <form method=\"post\" action=\"interaction-add-3\">
-	    [ec_hidden_input "d_user_identification_id" $issue_user_identification_id]
-	    [ec_export_entire_form_except d_user_id d_user_identification_id]
-	    <center>
-	    <input type=\"submit\" value=\"Yes\">
-	    </center>
-	    </form>
-	    
-	    [ad_admin_footer]
-	    "
+        if { ![empty_string_p $issue_user_id] } {
+            if { ![info exists d_user_id] || [string compare $d_user_id $issue_user_id] != 0 } {
+                set error_path 1
+                set hidden_input_html [ec_hidden_input "d_user_id" $issue_user_id]
+                set export_entire_form_except_html [ec_export_entire_form_except d_user_id d_user_identification_id]
+                ad_script_abort
+            }
+        } elseif { ![info exists d_user_identification_id] || [string compare $d_user_identification_id $issue_user_identification_id] != 0 } {
+            # if d_user_identification_id doesn't match the issue's user_identification_id, give
+            # them a message with the chance to make them match
+            set error_path 2
+ 	        set user_id_summary_html [ec_user_identification_summary $issue_user_identification_id]
+            set hidden_input_html [ec_hidden_input "d_user_identification_id" $issue_user_identification_id]
+            set export_entire_form_html [ec_export_entire_form_except d_user_id d_user_identification_id]
             ad_script_abort
-	}
-
+        }
     } else {
-	# non-new interaction; user_identification_id fixed
-	# if the issue has a user_id, then the user_id associated with user_identification_id should match.
-	# since it's possible for the same user to be represented by more than one user_identification_id,
-	# we can't require that they match, although it is unfortunate if they don't (but it's too late to
-	# do anything about it at this point -- I should make some way to combine user_identifications)
-	if { ![empty_string_p $issue_user_id] } {
-	    # find out the user_id associated with c_user_identification_id
-	    set c_user_id [db_string get_user_id "select user_id from ec_user_identification where user_identification_id=:c_user_identification_id"]
-	    # if the c_user_id is null, they should be told about the option of matching up a user_id with
-	    # user_identification_id
-	    # otherwise, if the issue doesn't belong to them, they just get a plain error message
-	    if { [empty_string_p $c_user_id] } {
-		ad_return_complaint 1 "The issue ID you specified belongs to the registered user
-		<a href=\"[ec_acs_admin_url]users/one?user_id=$issue_user_id\">[db_string get_full_name "select first_names || ' ' || last_name from cc_users where user_id=:issue_user_id"]</a>.  However, you haven't associated this interaction with any registered user.  You've associated it with the unregistered user [ec_user_identification_summary $c_user_identification_id].  If these are really the same user, match them up by clicking on the \"user info\" link and then you can reload this page without getting this error message." 
+        # non-new interaction; user_identification_id fixed
+        # if the issue has a user_id, then the user_id associated with user_identification_id should match.
+        # since it's possible for the same user to be represented by more than one user_identification_id,
+        # we can't require that they match, although it is unfortunate if they don't (but it's too late to
+        # do anything about it at this point -- I should make some way to combine user_identifications)
+        if { ![empty_string_p $issue_user_id] } {
+            # find out the user_id associated with c_user_identification_id
+            set c_user_id [db_string get_user_id "select user_id from ec_user_identification where user_identification_id=:c_user_identification_id"]
+            # if the c_user_id is null, they should be told about the option of matching up a user_id with
+            # user_identification_id
+            # otherwise, if the issue doesn't belong to them, they just get a plain error message
+            if { [empty_string_p $c_user_id] } {
+                ad_return_complaint 1 "<li>The issue ID you specified belongs to the registered user
+		<a href=\"[ec_acs_admin_url]users/one?user_id=$issue_user_id\">[db_string get_full_name "select first_names || ' ' || last_name from cc_users where user_id=:issue_user_id"]</a>.  However, you haven't associated this interaction with any registered user.  You've associated it with the unregistered user [ec_user_identification_summary $c_user_identification_id].  If these are really the same user, match them up by clicking on the \"user info\" link and then you can reload this page without getting this error message.</li>" 
                 ad_script_abort
-	    } elseif { [string compare $c_user_id $issue_user_id] != 0 } {
-		ad_return_complaint 1 "The issue ID you specified does not belong to the user you specified."
+            } elseif { [string compare $c_user_id $issue_user_id] != 0 } {
+                ad_return_complaint 1 "<li>The issue ID you specified does not belong to the user you specified.</li>"
                 ad_script_abort
-	    }
-	}
+            }
+        }
     }
 }
 
@@ -235,61 +184,38 @@
     # see who the order belongs to
     set row_exists_p [db_0or1row get_order_owner "select user_id as order_user_id from ec_orders where order_id=:order_id"]
     if { $row_exists_p==0 } {
-	ad_return_complaint 1 "<li>The shopping cart Order ID that you specified is invalid.  Please go back and check the order ID you entered.  If this issue is not about a specific online order, please leave the Order ID blank.</li>"
+        ad_return_complaint 1 "<li>The shopping cart Order ID that you specified is invalid.  Please go back and check the order ID you entered.  If this issue is not about a specific online order, please leave the Order ID blank.</li>"
         ad_script_abort
     }
     
-
     if { ![empty_string_p $order_user_id] } {
-
-	if { ![info exists interaction_id] } {
-	    if { ![info exists d_user_id] || [string compare $d_user_id $order_user_id] != 0 } {
-		
-		
-		append doc_body "[ad_admin_header "User Doesn't Match Order"]
-		<h2>User Doesn't Match Order</h2>
-		[ad_context_bar [list "../index.tcl" "Ecommerce([ec_system_name])"] [list "index.tcl" "Customer Service Administration"] "New Interaction"]
-		
-		<hr>
-		<p>Order ID $order_id belongs to the registered user <a href=\"[ec_acs_admin_url]users/one?user_id=$order_user_id\">[db_string get_user_name "select first_names || ' ' || last_name from cc_users where user_id=:order_user_id"]</a>.
-		</p>
-		<p>
-		
-		However, you haven't selected that user as the customer involved in this interaction.
-		</p>
-		<p>
-		
-		Would you like to make this user be the owner of this interaction?  (If not, push Back and fix the order ID.)
-		</p>
-		<form method=\"post\" action=\"interaction-add-3\">
-		[ec_hidden_input "d_user_id" $order_user_id]
-		[ec_export_entire_form_except d_user_id d_user_identification_id]
-		<center>
-		<input type=\"submit\" value=\"Yes\">
-		</center>
-		</form>
-		
-		[ad_admin_footer]
-		"
+        if { ![info exists interaction_id] } {
+            if { ![info exists d_user_id] || [string compare $d_user_id $order_user_id] != 0 } {
+		        set title  "Error: User Does Not Match Order"
+                set context [list [list index "Customer Service"] $title]
+                set error_path 3
+                set registered_user_html "<a href=\"[ec_acs_admin_url]users/one?user_id=$order_user_id\">[db_string get_user_name "select first_names || ' ' || last_name from cc_users where user_id=:order_user_id"]</a>"
+                set hidden_input_html [ec_hidden_input "d_user_id" $order_user_id]
+                set export_entire_form_html [ec_export_entire_form_except d_user_id d_user_identification_id]
                 ad_script_abort
-	    }
-	} else {
-	    # interaction_id exists
-	    # find out the user_id associated with c_user_identification_id
-	    set c_user_id [db_string get_user_id_user "select user_id from ec_user_identification where user_identification_id=:c_user_identification_id"]
-	    # if the c_user_id is null, they should be told about the option of matching up a user_id with
-	    # user_identification_id
-	    # otherwise, if the order doesn't belong to them, they just get a plain error message
-	    if { [empty_string_p $c_user_id] } {
-		ad_return_complaint 1 "The order ID you specified belongs to the registered user
-		<a href=\"[ec_acs_admin_url]users/one?user_id=$order_user_id\">[db_stringget_user_full_name "select first_names || ' ' || last_name from cc_users where user_id=:order_user_id"]</a>.  However, you haven't associated this interaction with any registered user.  You've associated it with the unregistered user [ec_user_identification_summary $c_user_identification_id].  If these are really the same user, match them up by clicking on the \"user info\" link and then you can reload this page without getting this error message." 
+            }
+        } else {
+            # interaction_id exists
+            # find out the user_id associated with c_user_identification_id
+            set c_user_id [db_string get_user_id_user "select user_id from ec_user_identification where user_identification_id=:c_user_identification_id"]
+            # if the c_user_id is null, they should be told about the option of matching up a user_id with
+            # user_identification_id
+            # otherwise, if the order doesn't belong to them, they just get a plain error message
+            if { [empty_string_p $c_user_id] } {
+                ad_return_complaint 1 "<li>The order ID you specified belongs to the registered user 
+<a href=\"[ec_acs_admin_url]users/one?user_id=$order_user_id\">[db_stringget_user_full_name "select first_names || ' ' || last_name from cc_users where user_id=:order_user_id"]</a>.  
+However, you haven't associated this interaction with any registered user.  You've associated it with the unregistered user [ec_user_identification_summary $c_user_identification_id].  If these are really the same user, match them up by clicking on the \"user info\" link and then you can reload this page without getting this error message.</li>" 
                 ad_script_abort
-	    } elseif { [string compare $c_user_id $order_user_id] != 0 } {
-		ad_return_complaint 1 "The order ID you specified does not belong to the user you specified."
+            } elseif { [string compare $c_user_id $order_user_id] != 0 } {
+                ad_return_complaint 1 "<li>The order ID you specified does not belong to the user you specified.</li>"
                 ad_script_abort
-	    }
-	
-	}
+            }
+        }
     }
     # Otherwise, the order is in_basket (that's why it has no user_id associated with it).
     # If the user_identification_id has a user_id associated with it, we should
@@ -300,7 +226,6 @@
 
 # done error checking
 
-
 if { [info exists interaction_id] } {
     # then the open_date didn't get passed along to this
     # script (but we need it for new customer service issues)
@@ -319,137 +244,130 @@
 
 db_transaction {
 
-# I. Have to generate:
-#   1. interaction_id, unless it already exists
-#   2. issue_id, unless it already exists
+    # I. Have to generate:
+    #   1. interaction_id, unless it already exists
+    #   2. issue_id, unless it already exists
 
-# interaction_id will either be a number or it will not exist
-if { ![info exists interaction_id] } {
-    set interaction_id [db_nextval ec_interaction_id_sequence]
-}
+    # interaction_id will either be a number or it will not exist
+    if { ![info exists interaction_id] } {
+        set interaction_id [db_nextval ec_interaction_id_sequence]
+    }
 
-# issue_id will either be a number or it will be the empty string
-if { [empty_string_p $issue_id] } {
-    set issue_id [db_nextval ec_issue_id_sequence]
-    set create_new_issue_p "t"
-} else {
-    set create_new_issue_p "f"
-}
+    # issue_id will either be a number or it will be the empty string
+    if { [empty_string_p $issue_id] } {
+        set issue_id [db_nextval ec_issue_id_sequence]
+        set create_new_issue_p "t"
+    } else {
+        set create_new_issue_p "f"
+    }
 
-# II. User identification (first time through):
-#   1. If we have d_user_id, see if there's a user_identification with that user_id
-#   2. Otherwise, see if we have d_user_identification_id
-#   3. Otherwise, create a new user_identification_id
+    # II. User identification (first time through):
+    #   1. If we have d_user_id, see if there's a user_identification with that user_id
+    #   2. Otherwise, see if we have d_user_identification_id
+    #   3. Otherwise, create a new user_identification_id
 
-if { $create_new_interaction_p == "t" && ![info exists c_user_identification_id] } {
-    if { [info exists d_user_id] } {
-	db_0or1row get_uiid_to_insert "select user_identification_id as uiid_to_insert from ec_user_identification where user_id=:d_user_id"
-    }
-    if { ![info exists uiid_to_insert] } {
-	if { [info exists d_user_identification_id] } {
-	    set uiid_to_insert $d_user_identification_id
-	} else {
-	    set user_id_to_insert ""
-	    if { [info exists d_user_id] } {
-		set user_id_to_insert $d_user_id
-	    }
-	    
-	    set uiid_to_insert [db_nextval ec_user_ident_id_sequence]
-	    db_dml insert_new_uiid "insert into ec_user_identification
+    if { $create_new_interaction_p == "t" && ![info exists c_user_identification_id] } {
+        if { [info exists d_user_id] } {
+            db_0or1row get_uiid_to_insert "select user_identification_id as uiid_to_insert from ec_user_identification where user_id=:d_user_id"
+        }
+        if { ![info exists uiid_to_insert] } {
+            if { [info exists d_user_identification_id] } {
+                set uiid_to_insert $d_user_identification_id
+            } else {
+                set user_id_to_insert ""
+                if { [info exists d_user_id] } {
+                    set user_id_to_insert $d_user_id
+                }
+                
+                set uiid_to_insert [db_nextval ec_user_ident_id_sequence]
+                db_dml insert_new_uiid "insert into ec_user_identification
 	    (user_identification_id, user_id, email, first_names, last_name, postal_code, other_id_info)
 	    values
-	    (:uiid_to_insert, :user_id_to_insert, :email,:first_names,:last_name,:postal_code,:other_id_info)
-	    "
-	}
+	    (:uiid_to_insert, :user_id_to_insert, :email,:first_names,:last_name,:postal_code,:other_id_info)"
+            }
+        }
+    } else {
+        set uiid_to_insert $c_user_identification_id
     }
-} else {
-    set uiid_to_insert $c_user_identification_id
-}
-#    doc_return  200 text/html "<B>three: UTI:  $uiid_to_insert</B>" 
+    #    doc_return  200 text/html "<B>three: UTI:  $uiid_to_insert</B>" 
+    
+    # III. Interaction (only if this is the first time through):
+    #   Have to insert into ec_customer_serv_interactions:
+    #   1. interaction_id
+    #   2. customer_service_rep
+    #   3. user_identification_id (= uiid_to_insert determined in II)
+    #   4. interaction_date (= open_date)
+    #   5. interaction_originator
+    #   6. interaction_type (=  interaction_type or interaction_type_other)
 
-# III. Interaction (only if this is the first time through):
-#   Have to insert into ec_customer_serv_interactions:
-#   1. interaction_id
-#   2. customer_service_rep
-#   3. user_identification_id (= uiid_to_insert determined in II)
-#   4. interaction_date (= open_date)
-#   5. interaction_originator
-#   6. interaction_type (=  interaction_type or interaction_type_other)
-
-if { $create_new_interaction_p == "t" } {
-    db_dml insert_new_cs_interaction "insert into ec_customer_serv_interactions
+    if { $create_new_interaction_p == "t" } {
+        db_dml insert_new_cs_interaction "insert into ec_customer_serv_interactions
     (interaction_id, customer_service_rep, user_identification_id, interaction_date, interaction_originator, interaction_type)
     values
-    (:interaction_id, :customer_service_rep, :uiid_to_insert, $date_string, :interaction_originator, [ec_decode $interaction_type "other" ":interaction_type_other" ":interaction_type"])
-    "
-}
-
-# IV. Issue (unless we already have an issue):
-#   1. Have to insert into ec_customer_service_issues:
-#     A. issue_id (passed along or generated)
-#     B. user_identification_id (= uiid_to_insert determined in II)
-#     C. order_id
-#     D. open_date
-#     E. close_date (=null if close_issue_p=f, =open_date if close_issue_p=t)
-#     F. closed_by (=null if close_issue_p=f, =customer_service_rep if close_issue_p=t)
-#   2. Have to insert into ec_cs_issue_type_map:
-#     issue_id & issue_type for each issue_type in issue_type_list
-#ns_log Notice "issue_type [value_if_exists issue_type], create_new_issue_p $create_new_issue_p "
-if { $create_new_issue_p == "t" } {
-    if { $close_issue_p == "t" } {
-	set customer_service_rep_bit :customer_service_rep
-	set close_date $date_string
-    } else {
-	set customer_service_rep_bit [db_map customer_service_rep_bit_null_sql]
-	set close_date [db_map close_date_null_sql]
+    (:interaction_id, :customer_service_rep, :uiid_to_insert, $date_string, :interaction_originator, [ec_decode $interaction_type "other" ":interaction_type_other" ":interaction_type"])"
     }
-    db_dml insert_new_ec_cs_issue "insert into ec_customer_service_issues
+
+    # IV. Issue (unless we already have an issue):
+    #   1. Have to insert into ec_customer_service_issues:
+    #     A. issue_id (passed along or generated)
+    #     B. user_identification_id (= uiid_to_insert determined in II)
+    #     C. order_id
+    #     D. open_date
+    #     E. close_date (=null if close_issue_p=f, =open_date if close_issue_p=t)
+    #     F. closed_by (=null if close_issue_p=f, =customer_service_rep if close_issue_p=t)
+    #   2. Have to insert into ec_cs_issue_type_map:
+    #     issue_id & issue_type for each issue_type in issue_type_list
+    #ns_log Notice "issue_type [value_if_exists issue_type], create_new_issue_p $create_new_issue_p "
+    if { $create_new_issue_p == "t" } {
+        if { $close_issue_p == "t" } {
+            set customer_service_rep_bit :customer_service_rep
+            set close_date $date_string
+        } else {
+            set customer_service_rep_bit [db_map customer_service_rep_bit_null_sql]
+            set close_date [db_map close_date_null_sql]
+        }
+        db_dml insert_new_ec_cs_issue "insert into ec_customer_service_issues
     (issue_id, user_identification_id, order_id, open_date, close_date, closed_by)
     values
-    (:issue_id, :uiid_to_insert, :order_id, $date_string, $close_date, $customer_service_rep_bit)
-    "
-    set issue_type_list [concat $issue_type_list $issue_type]
+    (:issue_id, :uiid_to_insert, :order_id, $date_string, $close_date, $customer_service_rep_bit)"
+        set issue_type_list [concat $issue_type_list $issue_type]
 
-    foreach issue_type $issue_type_list {
-	db_dml insert_into_issue_tm "insert into ec_cs_issue_type_map
+        foreach issue_type $issue_type_list {
+            db_dml insert_into_issue_tm "insert into ec_cs_issue_type_map
 	(issue_id, issue_type)
 	values
-	(:issue_id, :issue_type)
-	"
+	(:issue_id, :issue_type)"
+        }
     }
-}
 
-# V. Action:
-#  1. Have to insert into ec_customer_service_actions:
-#     A. action_id
-#     B. issue_id (passed along or generated)
-#     C. interaction_id (generated in II)
-#     D. action_details
-#     E. follow_up_required
-#  2. Have to insert into ec_cs_action_info_used_map:
-#     action_id and info_used for each info_used in info_used_list   
-
-db_dml insert_new_ec_service_action "insert into ec_customer_service_actions
+    # V. Action:
+    #  1. Have to insert into ec_customer_service_actions:
+    #     A. action_id
+    #     B. issue_id (passed along or generated)
+    #     C. interaction_id (generated in II)
+    #     D. action_details
+    #     E. follow_up_required
+    #  2. Have to insert into ec_cs_action_info_used_map:
+    #     action_id and info_used for each info_used in info_used_list   
+    
+    db_dml insert_new_ec_service_action "insert into ec_customer_service_actions
 (action_id, issue_id, interaction_id, action_details, follow_up_required)
 values
-(:action_id, :issue_id, :interaction_id, :action_details,:follow_up_required)
-"
+(:action_id, :issue_id, :interaction_id, :action_details,:follow_up_required)"
 
-foreach info_used $info_used_list {
-    db_dml insert_into_cs_action_info_map "insert into ec_cs_action_info_used_map
+    foreach info_used $info_used_list {
+        db_dml insert_into_cs_action_info_map "insert into ec_cs_action_info_used_map
     (action_id, info_used)
     values
-    (:action_id, :info_used)
-    "
+    (:action_id, :info_used)"
+    }
 }
 
-}
-
 if { $submit == "Interaction complete" } {
     if {[value_if_exists return_to_issue] < 1 } {
-	ad_returnredirect index
+        ad_returnredirect index
     } else {
-	ad_returnredirect "issue?issue_id=$return_to_issue"
+        ad_returnredirect "issue?issue_id=$return_to_issue"
     }
 } else {
     # (in c_user_identification_id, "c" stands for "confirmed" meaning