# /www/master-default.tcl
#
# Set basic attributes and provide the logical defaults for variables that
# aren't provided by the slave page.
#
# Author: Kevin Scaldeferri (kevin@arsdigita.com)
# Creation Date: 14 Sept 2000
# $Id: interlink.tcl,v 1.13 2006/10/11 11:54:36 cvs Exp $
#

# fall back on defaults
ad_page_contract {

    ARM Theme
    
    @author SriHarsha Chintalapani(sriharsha.ch@azri.biz)
    @cvs-id $Id: interlink.tcl,v 1.13 2006/10/11 11:54:36 cvs Exp $
} {
    {search_p:optional}
    {help_p:optional}
    {from_cms_p:optional}
    {admin_link:optional}
} 





if { [template::util::is_nil subnavbar_link] } {
    set subnavbar_link ""
}


if { ![exists_and_not_null active_section] } {
   set active_section 1
}



if { ![exists_and_not_null cms_admin_link] } {
   set cms_admin_link ""
}


set skin_css [list "/resources/skin/interlink/css/interlink.css"  "/resources/skin/interlink/css/site-master.css" "/resources/skin/interlink/css/forms.css" "/resources/skin/interlink/css/lists.css"]
set css_root "/resources/skin/interlink/css/"

if { [exists_and_not_null css_include] } {
    append css_root $css_include
    lappend skin_css $css_root
}

set package_id [ad_conn package_id]
if { ![exists_and_not_null help_p] } {
set help_p ""
}

if { $help_p == "on" } {
    set helpon [parameter::set_value -parameter help_p -value off]
} elseif { $help_p == "off" } {
    set helpon [parameter::set_value -parameter help_p -value on]
}

set package_key [apm_package_key_from_id $package_id]
#get the user_id
set user_id [ad_get_user_id]

# Context bar
if { [info exists context] } {
    set context_tmp $context
    unset context
} else {
    set context_tmp {}
}

ad_context_bar_multirow -- $context_tmp



if {![exists_and_not_null from_cms_p]} {    
    set from_cms_p ""
}




if {![exists_and_not_null cms_admin_link]} {
    set cms_admin_link ""
}


ad_context_bar_multirow  -- $context_tmp

set class_p [classes::class_p]



if {$class_p == 1} {
    set nearest_class_package_id  [site_node_closest_ancestor_package  "acs-subsite"]    
    set status_p [db_string archived_status_p "select 1 from classes where subsite_id = :nearest_class_package_id and archive_p like 't'" -default 0]
    
    if { $status_p == 1 } {
	ad_returnredirect "/classes/"
	ad_script_abort
    }
    
}


if { [regexp "donations" [ad_conn url]] } {
    set donations_p 1
} else {
    set donations_p 0
}

if { ( ![exists_and_not_null active_section] ) || ( $active_section == 1 )  } {

    switch -exact -- $package_key {
	user-directory { set active_section 6 }
	photo-album { set active_section 10 }
	dotlrn { set active_section 3 }
	edit-this-page {		
	    if { ([exists_and_not_null from_cms_p]) || ( $donations_p == 0)  } {		
		    if {$class_p == 1} {		    
			set active_section 4
		    } else {
			set active_section 1
		    }
	} else {
	    set active_section 9
	}

    } 
    sbn {set active_section 7}
    careers {set active_section 8}
    mailing-lists/index {set active_section 8}    
    acs-admin {set active_section 12}
    donation-helper { set active_section 9}
    events { 
      if { $class_p == 1 } {
        set active_section 4
        } else {
         set active_section 11
         }
   }
   calendar {
   set active_section 3
   }
    file-storage {
        if { $class_p == 1 } {
        set active_section 4
        } else {
        set active_section 3
        }
    }
    survey {
        set active_section 3
    }
   default {set active_section 1 }

}
}


 if { [template::util::is_nil title] } {
    set title [ad_conn instance_name]
}

set i 1
if {[exists_and_not_null navigation_second]} {
 foreach naventry $navigation_second {
	  set navtext [lindex $naventry 0]
	  set navlink [lindex $naventry 1]
          set class_name [lindex $naventry 2]
     if { ![exists_and_not_null class_name] } {
	 set class_name "link"
     }

     if { $class_name == "activelink" } {
	 if { [regexp "Admin" $navtext] } {

             set class_name "link_admin"
            }
         
          append navhref "<div class=\"$class_name\" id=\"menu$i\">$navtext</div>"
     } else {
	 if { [regexp "Admin" $navtext] } {
             set class_name "link_admin"
            }
	 append navhref "<div class=\"$class_name\" id=\"menu$i\"><a href=\"$navlink\">$navtext</a></div>"
        
     }
          incr i
 }
}




if {[regexp "de" [ad_conn url]] } {
    set from_en_p 1
} else {
    set from_en_p 0
}

set system_name [ad_system_name]
set system_url [ad_url]
if { [string equal [ad_conn url] "/"] } {
    set system_url ""
}



# Get user information
set sw_admin_p 0
set user_id [ad_conn user_id]
set untrusted_user_id [ad_conn untrusted_user_id]

set admin_p [acs_user::site_wide_admin_p -user_id $user_id]

if {![info exists link_control_panel]} {
    set link_control_panel 1
}
if {$link_control_panel} {
    set link_control_panel 1
} else {
    set link_control_panel 0
}

if {![info exists control_panel_text]} {
    set control_panel_text "Control Panel"
}

if {![info exists link_all]} {
    set link_all 0
} 

set extra_spaces "&nbsp;&nbsp;"    
set extra_stuff_infront_p 0
set extra_stuff ""



if { $untrusted_user_id != 0 } {
    set user_name [person::name -person_id $untrusted_user_id]
    set pvt_home_url [ad_pvt_home]
	set pvt_home_name [_ acs-subsite.Your_Account]
    set logout_url [ad_get_logout_url]

    # Site-wide admin link
    set admin_url {}

    set sw_admin_p [acs_user::site_wide_admin_p -user_id $untrusted_user_id]

    if { $sw_admin_p } {
        set admin_url "/acs-admin/"
        set devhome_url "/acs-admin/developer"
        set locale_admin_url "/acs-lang/admin"
    } else {
        set subsite_admin_p [permission::permission_p \
                                 -object_id [subsite::get_element -element object_id] \
                                 -privilege admin \
                                 -party_id $untrusted_user_id]

        if { $subsite_admin_p  } {
            set admin_url "[subsite::get_element -element url]admin/"
        }
    }
} 

if { $untrusted_user_id == 0 } {
    set login_url [ad_get_login_url -return]
}



set num_users_online [lc_numeric [whos_online::num_users]]

if { $user_id == 0 } {
    #    ns_returnnotice 200 [whos_online::num_users]----------
}

set whos_online_url "[subsite::get_element -element url]shared/whos-online"

set num_of_locales [llength [lang::system::get_locales]]

set change_locale_url   "/acs-lang/?[export_vars { { package_id "[ad_conn package_id]" } }]"


#	set active_p [membership_track -user_id $user_id]
#	if { $active_p == 0 } {


#	}

