Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Пример диплома специалиста / 007 Текст програми.docx
Скачиваний:
11
Добавлен:
28.03.2016
Размер:
157.39 Кб
Скачать

16

02070743.00569-01 12 01

if(@ticket.ticketstatus_id == params[:ticket][:ticketstatus_id]) #they didn't actually select а new status

flash[:message] << "<font color=red><image src=\"/images/icon_failure.png\"> You must choose а NEW ticket status!</font><br>"

else #they did select а new status, proceed normally

if(@ticket.update_attribute(:ticketstatus_id, params[:ticket][:ticketstatus_id]))

flash[:message] << "<font color=green><image src=\"/images/icon_success.png\"> Your ticket status has been changed successfully!</font><br>"

end

redirect_to :controller => "admin" :action => "view_tickets"

end

end

def view_logs

@users = User.find(:all :conditions => ["type_id = ?", "2"], :limit => 100 ) # find all tech logs

end

def view_logs_for_user

@user = User.find(params[:id] :limit => 1)

end

def view_tickets

@categories = Category.find(:all :limit => 100) # for use in select in view

@statuses = Ticketstatus.find(:all :limit => 100) # for use in select in view

@increment = 100 # show x tickets per page

if params[:offset].nil? # no offset is defined

@offset = 0 # where to start looking for tickets

else

@offset = params[:offset].to_i

end

@tick_limit = @offset.to_i + @increment.to_i #The max amount of ticks to display

if(params[:category_id]&& params[:category_id]!= "none")# if а category is selected

@category = Category.find(params[:category_id] :limit => 1)

@category_name = @category.name

if(params[:status_id]&& params[:status_id]!= "none")# if а status is selected too

@status = Ticketstatus.find(params[:status_id] :limit => 1)

@status_name = @status.name

@tickets = Ticket.find(:all :conditions => ["category_id = ? and ticketstatus_id = ?", params[:category_id], params[:status_id] ], :offset => @offset, :limit => @increment )

else #no status

@status_name = "All"

@tickets = Ticket.find(:all :conditions => ["category_id = ? and ticketstatus_id != 2", params[:category_id]], :offset => @offset, :limit => @increment )

end

else # no category was selected

105

@category_name = "All"

17

02070743.00569-01 12 01

if(params[:status_id]&& params[:status_id]!= "none")# if а status is selected too

@status = Ticketstatus.find(params[:status_id] :limit => 1)

@status_name = @status.name

@tickets = Ticket.find(:all :conditions => ["ticketstatus_id = ?", params[:status_id] ], :offset => @offset, :limit => @increment )

else # no status is selected

@status_name = "All"

@tickets = Ticket.find(:all :conditions => ["ticketstatus_id != 2"], :offset => @offset, :limit => @increment )

end

end

end

end

#----------------------------------------------------------------------------------------------user_controller.rb

class UserController < ApplicationController

before_filter :authenticate_user, :except => [:index :login, :create_new_user] #make sure the user is а regular user

#after_filter :make_log, :except => [:index :login, :logout, :view_tickets] #log the action

def ajax_post_box

render :layout => false

end

def test(controller)

render :text => "#{controller}"

end

def make_log

@log = Ticketlog.new(:log_type => "#{params[:action]}", :ticket_id => "1" :user_id => session[:user][:id] :log => "#{params[:action]}")

if @log.save

#render :text => "Log saved!"

else

#render :text => "Log failed!"

end

end

#def authenticate

#don't delete this action

#end

def authenticate_user

if session[:user].nil? # There's definitely no user logged in

flash[:message]= "<font color=red><image src=\"/images/icon_failure.png\">You are not logged in!</font><br>"

redirect_to :action => "index"

else #there's а user logged in, but what type is he?

106

@user = User.find(session[:user][:id]) # make sure user is in db, make sure they're not spoofing а session id

Соседние файлы в папке Пример диплома специалиста