<% @heading = "Baseline Process: #{@site.title}" if @site.baseline_process? %>
<% @heading = "Wiki: #{@site.title}" if @site.wiki? %>
<% @overview = "Use this page to manage " + link_to_site(@site) %>

<div id="menu">
	<%= link_to 'Edit', {:action => 'edit', :id => @site}, :title => "Edit detail information of #{@site.title}" %>   
    <% if @site.wiki? %>
		 <% if admin? %>
		 	| <%= link_to 'New Wiki', :action => 'new_wiki' %>
		 <% end %>
    <% end %>
</div>

<% if @site.wiki?  %>
<br>
<br>

<div id="epfc_tabs">
	<ol id="epfc_tabs_toc">
		<%= menulink_to 'Description',  :controller => 'sites', :action => 'description', :id => @site.id %>
	    <%= menulink_to 'Versions',  :controller => 'sites', :action => 'versions', :id => @site.id %>
		<%= menulink_to 'Comments', :controller => 'sites', :action => 'comments', :id => @site.id %>
		<%= menulink_to 'Pages', :controller => 'sites', :action => 'pages', :id => @site.id %>		
		<%= menulink_to 'Uploads', :controller => 'sites', :action => 'uploads', :id => @site.id %>		
		<% if admin? %><%= menulink_to 'Feedback', :controller => 'sites', :action => 'feedback', :id => @site.id  %><% end %>
	</ol>
</div>


<% if @version_pages %>
	<%= links_to_pages(@version_pages)  %>
	<p>
	<form name="filter" method="get">
		Filter:
		<%= check_box('filter', 'done', {}, 'N', 'All' )%> Only Todo
		<%= check_box('filter', 'type_filter', {}, 'UserVersion', 'All' )%> Only User Versions
		<input type=submit value=OK>
	</form>
	</p>
	<%= render(:partial => 'versions/versions_list') %>
<% end %>

<% if @comment_pages %>
	<%= links_to_pages(@comment_pages)  %>
	<p>
	<form name="filter" method="get">
		Filter:
		<%= check_box('filter', 'done', {}, 'N', 'All' )%> Only Todo
		<input type=submit value=OK>
	</form>
	</p>
	<%= render(:partial => 'comments/comments_list')  %>
<% end  %>



<%= links_to_pages(@page_pages) if @page_pages %>
<%= links_to_pages(@upload_pages) if @upload_pages %>



<% if admin? %><%= links_to_pages(@feedback_pages) if @feedback_pages %><% end %>
<%= render(:partial => 'pages/list') if @page_pages %>
<%= render(:partial => 'uploads/list') if @upload_pages %>
<% if admin? %><%= render(:partial => 'feedbacks/list') if @feedback_pages %><% end %>

<br>
<br>
<% end %>

<% if params[:action] == 'description' %>

<div class="sectionHeading">Description</div>
<div class="sectionContent">
    <table cellpadding="0" cellspacing="0" border="0" class="sectionTable">
        <tr>
            <td class="sectionTableCell">
            	<%= if @site.description.blank? 
					link_to 'Click to add a description...', {:action => 'edit', :id => @site}
				else
					@site.description
				end %>
            </td>
        </tr>
    </table>
</div>


<% if @site.wiki? %>
<div class="sectionHeading">Updates</div>
<div class="sectionContent">
    <table cellpadding="0" cellspacing="0" border="0" class="sectionTable">
        <tr>
            <th scope="row" class="sectionTableHeading">Current Baseline Process</th>
            <td align="left" class="sectionTableCell">
    			<ul>
					<% if @site.status != 'Pending' %>
						<%= link_to_site @site.baseline_process if @site.baseline_process %>
					<% else %>
						<%= @site.title %> is pending and so there is no current Baseline Process Yet. The Wiki is empty.
					<% end %>
				</ul>
			</td>
        </tr>
        <tr>
            <th scope="row" class="sectionTableHeading">Status</th>
            <td align="left" class="sectionTableCell">
				<%= @site.status %>
			</td>
        </tr>
        <tr valign="top">
            <th scope="row" class="sectionTableHeading">Updates</th>
            <td align="left" class="sectionTableCell" >
             <ul>
             	<% @site.updates_done.each do |update| %>
					<li><%= link_to_site update.baseline_process %>  deployed on  <%= update.started_on.localtime.strftime(TIME_FORMAT) %> </li>
				<% end %>
             </ul>
            </td>
        </tr>
        <tr valign="top">
            <th scope="row" class="sectionTableHeading">Scheduled</th>
            <td align="left" class="sectionTableCell" >
             <ul>
             	<% @site.updates_todo.each do |update| %>
					<li><%= link_to_site update.baseline_process %> scheduled on <%= update.created_on.localtime.strftime(TIME_FORMAT) %> 
					[<%= link_to 'Cancel', {:action => 'update_cancel', :update_id => update.id, :id => @site.id}, :confirm => 'Are you sure?', :method => :post %>] 
					[<%= link_to 'Update Now', {:action => 'update_now', :update_id => update.id, :id => @site.id}, :confirm => 'Are you sure? It is recommended to schedule a task to run \'job_daily\' at night, or when ever your site is used the least. Depending on size of the baseline, users might notice a performance degradation if you do it right now.', :method => :post %>] </li>
				<% end %>
             </ul>
            </td>
        </tr>
        <tr valign="top">
            <th scope="row" class="sectionTableHeading">Schedule New Update</th>
            <td align="left" class="sectionTableCell" ><%= link_to_function("Select a Baseline Process ...") do |page| 
		    				page.visual_effect :toggle_appear, "baselines"  
		  				end %>
             <ul id="baselines" style="display:none;" >
             	<% BaselineProcess.find(:all, :order => 'created_on DESC', :conditions => ['obsolete_on is null']).each do |bp| %>
					<li><%= link_to bp.title, {:action => 'update', :baseline_process_id => bp.id, :id => @site.id}, :confirm => "Schedule update of Wiki '#{@site.title}' with Baseline Process '#{bp.title}'?", :method => :post %> created on <%= bp.created_on.localtime.strftime(TIME_FORMAT) %></li>
				<% end %>
             </ul>
            </td>
        </tr>		
    </table>
</div>


<div class="sectionHeading">Harvesting/Reviewing</div>
<div class="sectionContent">
    <table cellpadding="0" cellspacing="0" border="0" class="sectionTable">
        <tr>
            <th scope="row" class="sectionTableHeading">Versions</th>
            <td align="left" class="sectionTableCell">
            	<%= Version.count(:conditions => ['wiki_id=? and done=? and baseline_process_id is null', @site.id, 'N']).to_s %> to do of a total of <%= Version.count(:conditions => ['wiki_id=? and baseline_process_id is null', @site.id]).to_s %> versions
			</td>
        </tr>
        <tr valign="top">
            <th scope="row" class="sectionTableHeading">Comments</th>
            <td align="left" class="sectionTableCell" >
            	<%= @site.comments.count(:conditions => ['done=?', 'N']).to_s %> to do of a total of <%= @site.comments.count.to_s %> comments
            </td>
        </tr>
        <tr valign="top">
            <th scope="row" class="sectionTableHeading">Uploads</th>
            <td align="left" class="sectionTableCell" >
				<%= Upload.count(:conditions => ['done=?', 'N']).to_s %> to do of a total of <%= Upload.count.to_s %> uploads
            </td>
        </tr>
        <tr valign="top">
            <th scope="row" class="sectionTableHeading">Feedback</th>
            <td align="left" class="sectionTableCell" >
				<%= Feedback.count(:conditions => ['done=?', 'N']).to_s %> to do of a total of <%= Feedback.count.to_s %> feedback items
            </td>
        </tr>
    </table>
</div>
<% end %>

<div class="sectionHeading">Content</div>
<div class="sectionContent">
    <table cellpadding="0" cellspacing="0" border="0" class="sectionTable">
		<% if @site.wiki? %>
        <tr>
            <th scope="row" class="sectionTableHeading">Harvesting</th>
            <td align="left" class="sectionTableCell" colspan="2">
    			<ul>
					<li><%= Version.count(:conditions => ['wiki_id=? and done=? and baseline_process_id is null', @site.id, 'N']).to_s %> versions to do of <%= Version.count(:conditions => ['wiki_id=? and baseline_process_id is null', @site.id]).to_s %> </li>
					<li><%= @site.comments.count(:conditions => ['done=?', 'N']).to_s %> comments to do of <%= @site.comments.count.to_s %> </li>
					<li><%= Upload.count(:conditions => ['done=?', 'N']).to_s %> uploads to do of <%= Upload.count.to_s %> </li>
				</ul>
			</td>
        </tr>
		<% end %>
        <tr valign="top">
            <th scope="row" class="sectionTableHeading">Content Types</th>
			<% if @site.wiki? %>
	            <td align="left" class="sectionTableCell" >EPFC Pages:<ul><li>
					<%= WikiPage.count(:group => 'uma_type', :conditions => ['site_id=? and tool=?',@site.id, 'EPFC'] ).collect{|t|t.join(': ')}.join('</li><li>') %>
					</li></ul>
	            </td>
	            <td align="left" class="sectionTableCell" >Wiki Pages:<ul><li>
					<%= WikiPage.count(:group => 'uma_type', :conditions => ['site_id=? and tool=?',@site.id, 'Wiki'] ).collect{|t|t.join(': ')}.join('</li><li>') %>
					</li></ul>
	            </td>
			<% else %>
	            <td align="left" class="sectionTableCell" ><ul><li>
					<%= BaselineProcessPage.count(:group => 'uma_type', :conditions => ['site_id=?',@site.id] ).collect{|t|t.join(': ')}.join('</li><li>') %>
					</li></ul>
	            </td>
			<% end %>
        </tr>
		<% if @site.wiki? %>
        <tr valign="top">
            <th scope="row" class="sectionTableHeading">Status</th>
            <td align="left" class="sectionTableCell" >EPFC Pages:
				<ul><li>
					<%= WikiPage.count(:group => 'status', :conditions => ['site_id=? and tool=?',@site.id, 'EPFC'] ).collect{|t|t.join(': ')}.join('</li><li>') %>
				</li></ul>
            </td>
            <td align="left" class="sectionTableCell" >Wiki Pages:
				<ul><li>
					<%= WikiPage.count(:group => 'status', :conditions => ['site_id=? and tool=?',@site.id, 'Wiki'] ).collect{|t|t.join(': ')}.join('</li><li>') %>
				</li></ul>
            </td>
        </tr>
        <tr valign="top">
            <th scope="row" class="sectionTableHeading">Checkouts</th>
            <td align="left" class="sectionTableCell" colspan="2">
             <ul>
                <% for checkout in @site.checkouts %>
                <li>
                   <%= checkout.created_on.localtime.strftime(TIME_FORMAT) %> <%= link_to_user checkout.user %> of <%= link_to_page checkout.page %> in Wiki <%= link_to_site checkout.site %>
                </li>
                <% end %>
             </ul>
            </td>
        </tr>
		<% end %>
    </table>
</div>

<% if @site.wiki? %>
<div class="sectionHeading">Contributors</div>
<div class="sectionContent">
    <table cellpadding="0" cellspacing="0" border="0" class="sectionTable">
        <tr>
            <th scope="row" class="sectionTableHeading">Overall</th>
            <td align="left" class="sectionTableCell">
            	<ul>
            	<% @site.top_contributors.each do |c | %>
					<% if c[1] > 5 %>
					<li><%= link_to_user c[0] %>: <%= c[1].to_s %></li>
					<% end %>
				<% end %>
				</ul>
            </td>
        </tr>
        <tr valign="top">
            <th scope="row" class="sectionTableHeading">All</th>
            <td align="left" class="sectionTableCell" >
               <ul>
                   <% for user in @site.users %>
                   <li>
                      <%= link_to_user(user) %>
                   </li>
                   <% end %>
                </ul>
            </td>
        </tr>
    </table>
</div>
<% end %>

<div class="sectionHeading">Properties</div>
<div class="sectionContent">
<table cellpadding="0" cellspacing="0" border="0" class="sectionTable">
    <tr valign="top">
        <th scope="row" class="sectionTableHeading">ID</th>
        <td align="left" class="sectionTableCell"><%= @site.id %></td>
    </tr>
    <tr valign="top">
            <th scope="row" class="sectionTableHeading">Title</th>
            <td align="left" class="sectionTableCell"><%= @site.title %></td>
    </tr>
    <tr valign="top">
        <th scope="row" class="sectionTableHeading">Root Path</th>
        <td align="left" class="sectionTableCell"><%= @site.path %></td>
    </tr>
    <tr valign="top">
        <th scope="row" class="sectionTableHeading">URL</th>
        <td align="left" class="sectionTableCell"><%= url_for(@site.rel_path) %></td>
    </tr>
    <tr valign="top">
        <th scope="row" class="sectionTableHeading">Created On</th>
        <td align="left" class="sectionTableCell"><%= @site.created_on.strftime("%I:%M %p %d-%b-%y") %></td>
    </tr>
    <tr valign="top">
        <th scope="row" class="sectionTableHeading">Updated On</th>
        <td align="left" class="sectionTableCell"><%= @site.updated_on.strftime("%I:%M %p %d-%b-%y") %></td>
    </tr>
    <tr valign="top">
        <th scope="row" class="sectionTableHeading">Content Scanned On</th>
        <td align="left" class="sectionTableCell"><%= @site.content_scanned_on.strftime("%I:%M %p %d-%b-%y") if @site.content_scanned_on %>
        </td>
    </tr>

    <tr valign="top">
        <th scope="row" class="sectionTableHeading">Pages</th>
        <td align="left" class="sectionTableCell">
			<% if @site.wiki? %>
				<%= WikiPage.count(:conditions => ['site_id=?',@site.id] ) %>
			<% else %>
				<%= BaselineProcessPage.count(:conditions => ['site_id=?',@site.id] ) %>
			<% end %>
        </td>
    </tr>
</table>
</div>
<% end %>