# -*- coding: utf-8 -*-
class SectionsController < ApplicationController
  layout "pricelist"
  before_filter :isAuthorization
  before_filter :set_var
  around_filter :isAccessSuper
 
  def new
    @section = Section.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @section }
    end
  end

  # GET /sections/1/edit
  def edit
    @section = Section.find(params[:id])
  end

  # POST /sections
  # POST /sections.xml
  def create
    @section = Section.new(params[:section])
    @section.usr =  Employee.current_user.id
    respond_to do |format|
      if @section.save
        format.html { redirect_to(pricelist_index_path, :notice => 'Запись сохранена.') }
      else
        format.html { render :action => "new" }
      end
    end
  end

  # PUT /sections/1
  # PUT /sections/1.xml
  def update
    @section = Section.find(params[:id])
    respond_to do |format|
      if @section.update_attributes(params[:section])
        format.html { redirect_to(pricelist_index_path, :notice => 'Запись сохранена.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
      end
    end
  end

  
  private
  
  def set_var
    Employee.current_user = Employee.find(session[:user_id]) unless session[:user_id].nil?
  end


end
