<% # encoding: utf-8 %>

<%= flash_messages %>

<h1 class="h1"><%= @page.title rescue nil %></h1>

<% if !@item.frontend_field.blank? %>

<% if @frontend_style == '1' %>

	<div class="news news1">
		<table class="newstb" border="0" cellpadding="0" cellspacing="0" >
		<thead>
			<tr>
				<% @item.frontend_field.each do |ff|  %>
				<th><span class="<%= ff[1] %>"><%= t("announcement.bulletin.#{ff[0]}") if !ff[0].blank? %></span></th>
				<% end %>
			</tr>
		</thead>
		<% @bulletins.each do |post| %>
			<% @item.frontend_field.each do |ff|  %>
			<tr class="<%= cycle('odd', '')%>">
				<td>
				<span class="<%= ff[1] %>">
				<% if ff[1] == 'title' %>
					<%= link_to post.send("#{ff[0]}")[I18n.locale], panel_announcement_front_end_bulletin_path(post, :category_id => post.send("#{post.class.to_s.underscore}_category_id")) %>
				<% elsif ff[1] == 'date' %>
					<%= display_date(post.send(ff[0])) %>
				<% elsif ff[1] == 'category' %>
					<%= post.send("#{post.class.to_s.underscore}_#{ff[0]}").i18n_variable[I18n.locale] rescue nil %>
				<% elsif ff[1] == 'img' %>
					<div class="img app-pic"><%= image_tag(post.send(wf[0]).url) %></div>
				<% elsif ff[1] == 'text' %>
					<%#= post.send("#{ff[0]}[#{I18n.locale}]").html_safe %>
					<%= post.send("#{ff[0]}")[I18n.locale].html_safe %>
				<% elsif ff[1] == 'status' %>
					<% if post.is_top? %>
						<span class="top"><%= t(:top) %></span>
					<% end %>
					<% if post.is_hot? %>
						<span class="hot"><%= t(:hot) %></span>
					<% end %>
				<% elsif ff[1] == 'link' %>
				<% elsif ff[1] == 'file' %>
				<% elsif ff[1] == 'tag' %>
				<% elsif ff[1] == 'viewcount' %>
					<%= dislpay_view_count(post) %>
				<% elsif ff[1] == 'poster' %>
					<%= User.from_id(post.update_user_id).name rescue ''%>
				<% end %>
				</span>
				</td>
			</tr>
			<% end %>
		<% end %>
		</table>
	</div>

<% elsif @frontend_style == '2' %>

	<div class="news news2">	
		<ul class="newslist">
		<% @bulletins.each do |post| %>
			<li class="<%= cycle('odd', '')%>">
				<div class="img app-pic"><%= image_tag(post.image.url) %></div>
				
				<% @item.frontend_field.each do |ff|  %>
				<span class="<%= ff[1] %>">
				<% if ff[1] == 'title' %>
					<%= link_to post.title[I18n.locale], panel_announcement_front_end_bulletin_path(post, :category_id => post.bulletin_category_id) %>
				<% elsif ff[1] == 'date' %>
					<%= display_date(post.send(ff[0])) %>
				<% elsif ff[1] == 'category' %>
					<%= post.send("#{post.class.to_s.underscore}_#{ff[0]}").i18n_variable[I18n.locale] rescue nil %>
				<% elsif ff[1] == 'text' %>
					<%#= post.send("#{ff[0]}[#{I18n.locale}]").html_safe %>
					<%= post.send("#{ff[0]}")[I18n.locale].html_safe %>
				<% elsif ff[1] == 'status' %>
					<% if post.is_top? %>
						<span class="top"><%= t(:top) %></span>
					<% end %>
					<% if post.is_hot? %>
						<span class="hot"><%= t(:hot) %></span>
					<% end %>
				<% elsif ff[1] == 'link' %>
				<% elsif ff[1] == 'file' %>
				<% elsif ff[1] == 'tag' %>
				<% elsif ff[1] == 'viewcount' %>
					<%= dislpay_view_count(post) %>
				<% elsif ff[1] == 'poster' %>
					<%= User.from_id(post.update_user_id).name rescue ''%>
				<% end %>
				</span>
				<% end %>
			</li>
		<% end %>
		</ul>
	</div>

<% elsif @frontend_style == '3' %>

	<div class="news news3">	
		<ul class="newslist">
		
		<% @bulletins.each do |post| %>
			<li class="<%= cycle('odd', '')%>">
				<div class="img app-pic"><%= image_tag(post.image.url) %></div>
				<div class="wrap">
					<% @item.frontend_field.each do |ff|  %>
					<span class="<%= ff[1] %>">
					<% if ff[1] == 'title' %>
						<%= link_to post.send("#{ff[0]}")[I18n.locale], panel_announcement_front_end_bulletin_path(post, :category_id => post.send("#{post.class.to_s.underscore}_category_id")) %>
					<% elsif ff[1] == 'date' %>
						<%= display_date(post.send(ff[0])) %>
					<% elsif ff[1] == 'category' %>
						<%= post.send("#{post.class.to_s.underscore}_#{ff[0]}").i18n_variable[I18n.locale] rescue nil %>
					<% elsif ff[1] == 'text' %>
						<%#= post.send("#{ff[0]}[#{I18n.locale}]").html_safe %>
						<%= post.send("#{ff[0]}")[I18n.locale].html_safe %>
					<% elsif ff[1] == 'status' %>
						<% if post.is_top? %>
							<span class="top"><%= t(:top) %></span>
						<% end %>
						<% if post.is_hot? %>
							<span class="hot"><%= t(:hot) %></span>
						<% end %>
					<% elsif ff[1] == 'link' %>
					<% elsif ff[1] == 'file' %>
					<% elsif ff[1] == 'tag' %>
					<% elsif ff[1] == 'viewcount' %>
						<%= dislpay_view_count(post) %>
					<% elsif ff[1] == 'poster' %>
						<%= User.from_id(post.update_user_id).name rescue ''%>
					<% end %>
					</span>
					<% end %>
				</div>
			</li>
			<% end %>
		</ul>
		
	</div>

<% elsif @frontend_style == '4' %>

	<div class="news news4">	
		<ul class="newslist">
		
		<% @bulletins.each do |post| %>
			<li class="<%= cycle('odd', '')%>">
				<div class="img app-pic"><%= image_tag(post.image.url) %></div>
				<div class="wrap">
					<% @item.frontend_field.each do |ff|  %>
					<span class="<%= ff[1] %>">
					<% if ff[1] == 'title' %>
						<%= link_to post.send("#{ff[0]}")[I18n.locale], panel_announcement_front_end_bulletin_path(post, :category_id => post.send("#{post.class.to_s.underscore}_category_id")) %>
					<% elsif ff[1] == 'date' %>
						<%= display_date(post.send(ff[0])) %>
					<% elsif ff[1] == 'category' %>
						<%= post.send("#{post.class.to_s.underscore}_#{ff[0]}").i18n_variable[I18n.locale] rescue nil %>
					<% elsif ff[1] == 'text' %>
						<%#= post.send("#{ff[0]}[#{I18n.locale}]").html_safe %>
						<%= post.send("#{ff[0]}")[I18n.locale].html_safe %>
					<% elsif ff[1] == 'status' %>
						<% if post.is_top? %>
							<span class="top"><%= t(:top) %></span>
						<% end %>
						<% if post.is_hot? %>
							<span class="hot"><%= t(:hot) %></span>
						<% end %>
					<% elsif ff[1] == 'link' %>
					<% elsif ff[1] == 'file' %>
					<% elsif ff[1] == 'tag' %>
					<% elsif ff[1] == 'viewcount' %>
						<%= dislpay_view_count(post) %>
					<% elsif ff[1] == 'poster' %>
						<%= User.from_id(post.update_user_id).name rescue ''%>
					<% end %>
					</span>
					<% end %>
				</div>
			</li>
			<% end %>
		</ul>
		
	</div>

<% elsif @frontend_style == '5' %>

	<div class="news news5">
		<div class="img app-pic"><%= image_tag(@bulletins.first.image.url) %></div>
		<ul class="newslist">
			<% @bulletins.each do |post| %>
			<li class="<%= cycle('odd', '')%>">
				<% @item.frontend_field.each do |ff|  %>
				<span class="<%= ff[1] %>">
				<% if ff[1] == 'title' %>
					<%= link_to post.send("#{ff[0]}")[I18n.locale], panel_announcement_front_end_bulletin_path(post, :category_id => post.send("#{post.class.to_s.underscore}_category_id")) %>
				<% elsif ff[1] == 'date' %>
					<%= display_date(post.send(ff[0])) %>
				<% elsif ff[1] == 'category' %>
					<%= post.send("#{post.class.to_s.underscore}_#{ff[0]}").i18n_variable[I18n.locale] rescue nil %>
				<% elsif ff[1] == 'text' %>
					<%#= post.send("#{ff[0]}[#{I18n.locale}]").html_safe %>
					<%= post.send("#{ff[0]}")[I18n.locale].html_safe %>
				<% elsif ff[1] == 'status' %>
					<% if post.is_top? %>
						<span class="top"><%= t(:top) %></span>
					<% end %>
					<% if post.is_hot? %>
						<span class="hot"><%= t(:hot) %></span>
					<% end %>
				<% elsif ff[1] == 'link' %>
				<% elsif ff[1] == 'file' %>
				<% elsif ff[1] == 'tag' %>
				<% elsif ff[1] == 'viewcount' %>
					<%= dislpay_view_count(post) %>
				<% elsif ff[1] == 'poster' %>
					<%= User.from_id(post.update_user_id).name rescue ''%>
				<% end %>
				</span>
				<% end %>
			</li>
			<% end %>
		</ul>
	</div>

<table class="table table-bordered">
  <tr>
      <%= content_tag (:th) do %>
        <%= t(:category) %>
      <% end  if (!params[:search_query].blank? or params[:category_id].blank?)-%>
	<th><%= t(:title) %></th>
	<th><%= t(:postdate) %></th>
  </tr>
    <% if !params[:name].blank?%>
      <%= t("search.unit_get",:unit_name => params[:name],:item_num=>@bulletins.count) %>
    <% end %>

    <% if @bulletins.blank? and !params[:search_query].blank? %>
      <%=render :partial => 'shared/search_not_found'  %>
      <% elsif  !params[:search_query].blank?  %>
        <%= t("search.result_get",:search_word => params[:search_query],:item_num=>@bulletins.count) unless (@bulletins.count == 30) %>
        <%= t("search.too_many",:search_word => params[:search_query],:exceed_num=>@bulletins.count) if (@bulletins.count ==30) %>
     <% end %>

<% @bulletins.each do |post| %>
  <tr class=<%= cycle('odd', '') %>>
      <%= content_tag(:th) do%>
	   <td><%= (post.bulletin_category.title rescue nil ) %></td>
     <% end if(!params[:search_query].blank?  or params[:category_id].blank?) %>
		<td><%= link_to post.title, panel_announcement_front_end_bulletin_path(post, :category_id => post.bulletin_category_id) %>
		<%#= link_to post.title, panel_announcement_back_end_bulletin_path(post) %>
		</td>
		<td class="date"><%= display_date_time(post.postdate) %></td>
  </tr>
  
<% end %>
</table>

<% else %>

	<table class="table table-bordered">
	  <tr>
		<th><%= t('announcement.bulletin.category') %></th>
		<th><%= t('announcement.bulletin.title') %></th>
		<th><%= t('announcement.bulletin.postdate') %></th>
	  </tr>

	<% @bulletins.each do |post| %>
	  <tr>
		<td><%= post.bulletin_category.i18n_variable[I18n.locale] rescue nil %></td>
		<td><%= link_to post.title[I18n.locale], panel_announcement_front_end_bulletin_path(post, :category_id => post.bulletin_category_id) %>
		<%#= link_to post.title, panel_announcement_back_end_bulletin_path(post) %>
		</td>
		<td><%= display_date_time(post.postdate) %></td>
	  </tr>
	  
	<% end %>

	</table>

<% end %>

<%= paginate @bulletins, :param_name => :page_main, :params => {:inner => 'false'} %>

