Index: openacs-4/packages/new-portal/sql/oracle/portal-core-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/new-portal/sql/oracle/portal-core-create.sql,v
diff -u -r1.34 -r1.35
--- openacs-4/packages/new-portal/sql/oracle/portal-core-create.sql	21 Jan 2002 06:29:55 -0000	1.34
+++ openacs-4/packages/new-portal/sql/oracle/portal-core-create.sql	25 Jan 2002 20:04:45 -0000	1.35
@@ -167,19 +167,6 @@
 	unique(portal_id,sort_key)
 );
 
--- what's the current page for this portal?
-create table portal_current_page (
-	portal_id		constraint portal_cur_page_portal_id_fk
-				references portals
-                                on delete cascade
-                                not null,
-	page_id                 constraint portal_cur_page_id_fk
-				references portal_pages
-                                not null,
-	constraint portal_curr_page_un
-	unique(portal_id,page_id)
-);
-
 -- **** Portal Elements (PEs) ****
 
 
Index: openacs-4/packages/new-portal/tcl/portal-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/new-portal/tcl/portal-procs.tcl,v
diff -u -r1.107 -r1.108
--- openacs-4/packages/new-portal/tcl/portal-procs.tcl	23 Jan 2002 06:29:22 -0000	1.107
+++ openacs-4/packages/new-portal/tcl/portal-procs.tcl	25 Jan 2002 20:04:45 -0000	1.108
@@ -164,6 +164,7 @@
     
     ad_proc -public render { 
         {-page_id ""}
+        {-page_num ""}
         {-hide_links_p "f"} 
         {-render_style "individual"}
         portal_id
@@ -182,10 +183,12 @@
 	set master_template [ad_parameter master_template]
 	set css_path [ad_parameter css_path]
 	
-        # if no page_id set, render current
-        if {[empty_string_p $page_id]} {
-            set page_id [get_current_page -portal_id $portal_id]
-        }
+        # if no page_num set, render page 0
+        if {[empty_string_p $page_id] && [empty_string_p $page_num]} {
+            set page_id [get_page_id -portal_id $portal_id -sort_key 0]
+        } elseif {![empty_string_p $page_num]} {
+            set page_id [get_page_id -portal_id $portal_id -sort_key $page_num]
+        } 
 
 	# get the portal and layout
 	db_1row portal_select {} -column_array portal
@@ -212,7 +215,7 @@
             set element_src "[www_path]/render_styles/${render_style}/render-element"
             set template "<master src=\"@master_template@\">
             <property name=\"title\">@portal.name@</property>
-            <include src=\"@portal.layout_template@\" 
+            <include src=\"@portal.layout_filename@\" 
             element_list=\"@element_list@\"
             element_src=\"@element_src@\"
             theme_id=@portal.theme_id@
@@ -404,7 +407,7 @@
                 <P>Page <b>$portal(page_name)</b> has no Elements"
             } else {
                 append template "
-                <P>Page <b>$portal(page_name)</b> Elements</>
+                <P>Page <b>$portal(page_name)</b>
                 <include src=\"$portal(template)\" element_list=\"$element_list\" 
                 action_string=@action_string@ portal_id=@portal_id@
                 return_url=\"@return_url@\" element_src=\"@element_src@\"
@@ -611,61 +614,22 @@
         {-portal_id:required}
         {-page_name ""}
         {-sort_key "0"}
-        {-current "f"}
     } {
         Gets the id of the page with the given portal_id and sort_key
         if no sort_key is given returns the first page of the portal
         which is always there. 
 
 	@return the id of the page
 	@param portal_id 
-	@param current boolean get the current page if true
 	@param sort_key - optional, defaults to page 0
     } {
         if {![empty_string_p $page_name]} {
             return [db_string get_page_id_from_name {} -default ""]
         } else {
-            if {$current == "f"} {
                 return [db_string get_page_id_select {}]
-            } else {
-                # aks hack - bug - we sometimes lose the current page
-                if {[db_0or1row get_current_page_id_select {}] == 0} {
-                    set page_id [db_string get_page_id_select {}]
-                    db_dml aks_hack_current_page_insert {
-                        insert into portal_current_page 
-                        (portal_id, page_id) values (:portal_id, :page_id)
-                    }
-                    
-                }
-                
-                return $page_id
-            }
         }
     }
-    
 
-    ad_proc -public set_current_page {
-        {-portal_id:required}
-        {-page_id:required}
-    } {
-        Sets the current page id 
-
-	@param portal_id 
-	@param page_id 
-    } {
-        db_dml set_current_page_update {}
-    }
-
-    ad_proc -public get_current_page {
-        {-portal_id:required}
-    } {
-        gets the current page id 
-
-	@param portal_id 
-    } {
-        return [get_page_id -current "t" -portal_id $portal_id]
-    }
-
     ad_proc -public page_count {
         {-portal_id:required}
     } {
@@ -721,48 +685,45 @@
         return $foo
     }
 
-    ad_proc -public list_pages {
+    ad_proc -public navbar {
         {-portal_id:required}
+        {-td_align "left"}
         {-link ""}
         {-pre_html ""}
         {-post_html ""}
-        {-separator "&nbsp;"}
-        {-return_url ""}
         {-link_all 0}
+        {-extra_td_html ""}
+        {-table_html_args ""}
     } {
-        Returns an html string of the pretty names of the pages in the 
-        given portal. 
+        Wraps ad_dimensional to create a dotlrn navbar
 
 	@return the id of the page
 	@param portal_id 
 	@param link the relative link to set for hrefs
         @param current_page_link f means that there is no link for the current page
     } {
-        set html $pre_html
-        set current_page_id [get_page_id -current "t" -portal_id $portal_id]
+        set ad_dim_struct [list]
+       
+        db_foreach list_page_nums_select {
+            select pretty_name, sort_key as page_num from portal_pages where
+            portal_id = :portal_id
+            order by sort_key
+        } {
+            lappend ad_dim_struct [list $page_num $pretty_name [list]]
+        } 
 
-        foreach page [list_pages_tcl_list -portal_id $portal_id] {
-            if {$page == $current_page_id && !$link_all} {
-                append html "[get_page_pretty_name -page_id $page]"
-            } else {
-                if {[empty_string_p $return_url]} {
-                    set url_length [string length [ns_conn url]]
-                    if {[string range [ns_conn url] [expr $url_length - 1] end] != "/"} {
-                        # if the url dosen't end in a /, set the return_url to the filename
-                        set return_url [lindex [ns_conn urlv] [expr [ns_conn urlc] - 1]]
-                    } else {
-                        set return_url ""
-                    }
-                } 
+        set ad_dim_struct "{ page_num \"Page:\" 0  [list $ad_dim_struct] }"
 
-                append html "<a href=$link?portal_id=$portal_id&page_id=$page"
-                append html "&return_url=$return_url>[get_page_pretty_name -page_id $page]</a>"
-            }
-            append html $separator
-        }
-        
-        return [append html $post_html]
-        
+        return [ad_dimensional -no_header \
+                -no_bars \
+                -link_all $link_all \
+                -td_align $td_align \
+                -pre_html $pre_html \
+                -post_html $post_html \
+                -extra_td_html $extra_td_html \
+                -table_html_args $table_html_args \
+                $ad_dim_struct \
+                $link]
     }
 
     #
@@ -873,12 +834,11 @@
 	# First, check if this portal 1) has a portal template and
 	# 2) that that template has an element of this DS in it. If 
 	# so, copy stuff. If not, just insert normally. 
+	if { [db_0or1row get_template_info_select {}] == 1 } {
 
-	if { [db_0or1row check_new {}] == 1 } {
-
             db_transaction {
                 set new_element_id [db_nextval acs_object_id_seq]
-                db_dml template_page_insert {}
+                db_1row get_target_page_id {}
                 db_dml template_insert {}
                 db_dml template_params_insert {}
             }
Index: openacs-4/packages/new-portal/tcl/portal-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/new-portal/tcl/portal-procs.xql,v
diff -u -r1.13 -r1.14
--- openacs-4/packages/new-portal/tcl/portal-procs.xql	23 Jan 2002 06:29:22 -0000	1.13
+++ openacs-4/packages/new-portal/tcl/portal-procs.xql	25 Jan 2002 20:04:45 -0000	1.14
@@ -33,23 +33,22 @@
 
 <fullquery name="portal::render.portal_select">      
   <querytext>
-    select p.name, pcp.portal_id, pl.filename as layout_template, 
-    p.theme_id as theme_id, pp.layout_id as layout_id
-    from portals p, portal_current_page pcp, portal_layouts pl, portal_pages pp
-    where pcp.page_id = :page_id
-    and pcp.portal_id = :portal_id
-    and p.portal_id = pcp.portal_id
-    and pp.page_id = pcp.page_id
-    and pl.layout_id = pp.layout_id
+    select p.name, p.portal_id, p.theme_id as theme_id, 
+    pl.layout_id as layout_id, pl.filename as layout_filename
+    from portals p, portal_pages pp, portal_layouts pl
+    where :page_id = pp.page_id 
+    and pp.portal_id = p.portal_id
+    and pp.layout_id = pl.layout_id
   </querytext>
 </fullquery> 
 
 <fullquery name="portal::render.element_select">      
   <querytext>
     select element_id, region, pem.sort_key
-    from portal_element_map pem, portal_current_page pcp
-    where pcp.portal_id = :portal_id
-    and pcp.page_id = pem.page_id
+    from portal_element_map pem, portal_pages pp
+    where pp.portal_id = :portal_id
+    and pem.page_id = :page_id
+    and pem.page_id = pp.page_id
     and state != 'hidden'
     order by region, sort_key
   </querytext>
@@ -132,7 +131,7 @@
 <fullquery name="portal::configure_dispatch.toggle_pinned_select">
   <querytext>
     select state
-    from portal_element_map pem, portal_current_page pcp 
+    from portal_element_map pem, portal_currentXXXX_page pcp 
     where pcp.portal_id = :portal_id 
     and pem.page_id = pcp.page_id
     and element_id = :element_id
@@ -190,31 +189,6 @@
   </querytext>
 </fullquery> 
 
-<fullquery name="portal::set_current_page.set_current_page_update">      
-  <querytext>
-   update portal_current_page
-   set page_id = :page_id
-   where portal_id = :portal_id 
-  </querytext>
-</fullquery> 
-
-<fullquery name="portal::get_page_id.get_page_id_from_name">      
-  <querytext>
-   select page_id
-   from portal_pages
-   where portal_id = :portal_id 
-   and pretty_name= :page_name
-  </querytext>
-</fullquery> 
-
-<fullquery name="portal::get_page_id.get_current_page_id_select">      
-  <querytext>
-   select page_id
-   from portal_current_page
-   where portal_id = :portal_id 
-  </querytext>
-</fullquery> 
-
 <fullquery name="portal::get_page_pretty_name.get_page_pretty_name_select">      
   <querytext>
    select pretty_name
@@ -257,52 +231,53 @@
   </querytext>
 </fullquery> 
 
-<fullquery name="portal::add_element_to_region.check_new">      
+<fullquery name="portal::add_element_to_region.get_template_info_select">
   <querytext>
-     select 1 
+     select pp.page_id as template_page_id, 
+       pp.sort_key as template_page_sort_key,
+       pem.element_id as template_element_id
      from portals p, portal_element_map pem, portal_pages pp
      where p.portal_id = :portal_id
-     and p.template_id = pp.portal_id
-     and pp.portal_id = pem.page_id
-     and pem.datasource_id = :ds_id
+       and p.template_id = pp.portal_id
+       and pp.page_id = pem.page_id
+       and pem.datasource_id = :ds_id
   </querytext>
 </fullquery> 
 
-<fullquery name="portal::add_element_to_region.template_page_insert">      
+<fullquery name="portal::add_element_to_region.get_target_page_id">      
   <querytext>
-    insert into portal_pages
-    (element_id, name, pretty_name, page_id, datasource_id, region,  sort_key, state)
-    select :new_element_id, name, pretty_name, :page_id, :ds_id, region, sort_key, state
-    from portals p, portal_element_map pem, portal_pages pp
-    where pem.page_id = pp.page_id
-    and pp.portal_id = :template_id
-    and pem.datasource_id = :ds_id
+   select page_id as target_page_id
+   from portal_pages pp
+   where pp.portal_id = :portal_id 
+   and pp.sort_key = :template_page_sort_key   
   </querytext>
 </fullquery> 
 
 <fullquery name="portal::add_element_to_region.template_insert">      
   <querytext>
     insert into portal_element_map
     (element_id, name, pretty_name, page_id, datasource_id, region,  sort_key, state)
-    select :new_element_id, name, pretty_name, :page_id, :ds_id, region, sort_key, state
-    from portals p, portal_element_map pem, portal_pages pp
-    where pem.page_id = pp.page_id
-    and pp.portal_id = :template_id
-    and pem.datasource_id = :ds_id
+    select 
+    :new_element_id,
+    name, 
+    pretty_name,
+    :target_page_id,
+    :ds_id,
+    region,
+    sort_key,
+    state
+    from portal_element_map pem
+    where pem.element_id = :template_element_id
   </querytext>
 </fullquery> 
 
 <fullquery name="portal::add_element_to_region.template_params_insert">      
   <querytext>
     insert into portal_element_parameters
-    (parameter_id, element_id, config_required_p, configured_p,  key, value)
+    (parameter_id, element_id, config_required_p, configured_p, key, value)
     select acs_object_id_seq.nextval, :new_element_id, config_required_p, configured_p, key, value
     from portal_element_parameters
-    where element_id = (select element_id
-                        from portal_element_map pem, portal_pages pp
-                        where pem.page_id = pp.page_id 
-                        and pp.portal_id = :template_id
-                        and pem.datasource_id = :ds_id)
+    where element_id = :template_element_id
 </querytext>
 </fullquery> 
 
@@ -554,6 +529,14 @@
   </querytext>
 </fullquery> 
 
+<fullquery name="portal::get_page_id.get_page_id_from_name">      
+   <querytext>
+    select page_id
+    from portal_pages
+    where portal_id = :portal_id 
+    and pretty_name= :page_name
+   </querytext>
+ </fullquery>
 
 
 </queryset>
Index: openacs-4/packages/new-portal/www/template-place-element.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/new-portal/www/template-place-element.adp,v
diff -u -r1.7 -r1.8
--- openacs-4/packages/new-portal/www/template-place-element.adp	13 Dec 2001 21:10:02 -0000	1.7
+++ openacs-4/packages/new-portal/www/template-place-element.adp	25 Jan 2002 20:04:45 -0000	1.8
@@ -59,7 +59,15 @@
 <else>User Shadeable? No [<a href="@target_stub@-2?portal_id=@portal_id@&op=toggle_shadeable&element_id=@element_multi.element_id@&return_url=@return_url@">allow shading</a>]
 </else>
 
-<p>
+<br>
+
+    <include src=place-element-other-page &="element_multi" 
+             target_stub=@target_stub@
+             portal_id=@portal_id@
+             page_id=@element_multi.page_id@>
+    <br>
+<P>
+
 </multiple>
 
 
Index: openacs-4/packages/new-portal/www/template-place-element.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/new-portal/www/template-place-element.tcl,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/new-portal/www/template-place-element.tcl	22 Jan 2002 20:02:40 -0000	1.6
+++ openacs-4/packages/new-portal/www/template-place-element.tcl	25 Jan 2002 20:04:45 -0000	1.7
@@ -21,9 +21,9 @@
 
 # get the elements for this region.
 set region_count 0
-template::multirow create element_multi element_id name sort_key state hideable_p shadeable_p description
+template::multirow create element_multi element_id name sort_key state hideable_p shadeable_p description page_id
 db_foreach select_elements_by_region {
-    select pem.element_id, pem.name, pem.sort_key, state, pd.description
+    select element_id, pem.pretty_name as name, pem.sort_key, state, pp.page_id, pd.description
      from portal_element_map pem, portal_datasources pd, portal_pages pp
      where
        pp.portal_id = :portal_id 
@@ -41,7 +41,7 @@
 		"select value as hideable_p from portal_element_parameters where key = 'hideable_p' and element_id = :element_id"
 	
 	template::multirow append element_multi \
-		$element_id $name $sort_key $state $hideable_p $shadeable_p $description
+		$element_id $name $sort_key $state $hideable_p $shadeable_p $description $page_id
 	incr region_count
 	
     }