class ApplicationController < ActionController::Base
	protect_from_forgery

	before_filter :mailer_set_url_options

	def mailer_set_url_options
		ActionMailer::Base.default_url_options[:host] = request.host_with_port
	end

		def magick_order(default_row, default_a_d, name="default")
			session_order_name = (params[:controller]+"/"+params[:action]).to_slug.gsub('-','_')+"_"+name+"_magick_order"

			if params[:order]

				session[session_order_name] = []

				session[session_order_name][1] = params[:order] 
				session[session_order_name][2] = params[:a_d] 



			elsif session[session_order_name]

				params[:a_d] = session[session_order_name][2]
				params[:order] = session[session_order_name][1]
			else
				params[:order] = default_row
				params[:a_d] = default_a_d
			end

			return params[:order]+" "+params[:a_d]
		end
		
		def magick_per_page(per_page=20, name="defaut")
			session_search_name = (params[:controller]+"/"+params[:action]).to_slug.gsub('-','_')+"_"+name+"_magick_per_page"

			if params[:per_page]
		  		session[session_search_name] = params[:per_page]
			elsif session[session_search_name]
				params[:per_page] = session[session_search_name]
			else
				params[:per_page] = per_page

			end
		  end

		  def magick_page(name="defaut")
			session_search_name = (params[:controller]+"/"+params[:action]).to_slug.gsub('-','_')+"_"+name+"_magick_page"

			if params[:page]
		  		session[session_search_name] = params[:page]
			elsif session[session_search_name]
				params[:page] = session[session_search_name]



			end
		 end

		def to_my_log(message)
		    #current_user.user_logs.create(:message => message)
		  end


		def current_ability
		  @current_ability ||= Ability.new(current_admin)
		end

end
