<repo_name>rachelober/PSYU612<file_sep>/app/controllers/page_controller.rb
class PageController < ApplicationController
  layout 'standard'

  def index
    if request.get?
      if logged_in?
        flash.now[:notice] = 'You have successfully logged off.'
      end
      logout
    elsif request.post?
      userid = params[:login][:userid]
      if userid.empty?
        flash.now[:warning] = 'Please fill in the userid that will be tested.'
      else
        @user = User.find(:first, :conditions => ['id = ?', userid])
        session[:user_id] = @user.id
        redirect_to :action => 'guidelines'
      end
    end
  end

  def guidelines
    @user = logged_in_user
    if request.post?
      redirect_to :controller => 'article', :action => 'article1'
    end
  end

  def summary
    @user = logged_in_user
    if request.post?
      redirect_to :controller => 'page', :action => 'index'
    end
  end
end
<file_sep>/app/controllers/application.rb
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  # Pick a unique cookie name to distinguish our session data from others'
  session :session_key => '_psyu612_session_id'

  #functions for logged-in sessions
  def logged_in?
    session[:user_id] != nil
  end
  
  def logged_in_user
    User.find session[:user_id]
  rescue ActiveRecord::RecordNotFound
    nil
  end
  
  def logout
    session[:user_id] = nil
  end
end
<file_sep>/app/helpers/application_helper.rb
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper

  FLASH_TYPES = [
    :notice,      # positive feedback (ie - action successful)
    :message,     # neutral (ie - reminders)
    :warning      # errors (ie - login failed)
  ]
  
  def flash_messages
    flash.keys.collect { |k|
      content_tag("div", flash[k], :class => "flash_#{k}")}.join("\n")
  end
end
<file_sep>/app/controllers/pause_controller.rb
class PauseController < ApplicationController
  layout 'standard'

  # Pause after reading first article
  def pausea1
    if request.post?
      redirect_to :controller => 'question', :action => 'question1'
    end
  end

  # Pause after reading second article
  def pausea2
    if request.post?
      redirect_to :controller => 'question', :action => 'question2'
    end
  end

  # Pause after reading third article
  def pausea3
    if request.post?
      redirect_to :controller => 'question', :action => 'question3'
    end
  end

  # Pause after answering first article questions
  def pauseq1
    if request.post?
      redirect_to :controller => 'article', :action => 'article2'
    end
  end

  # Pause after answering second article questions
  def pauseq2
    if request.post?
      redirect_to :controller => 'article', :action => 'article3'
    end
  end

  # Pause after answering third article questions
  def pauseq3
    if request.post?
      redirect_to :controller => 'question', :action => 'general'
    end
  end
end
<file_sep>/app/controllers/article_controller.rb
class ArticleController < ApplicationController
  layout 'standard'

  def article1
    @user = logged_in_user
    @article = @user.article1
    @article_width = @user.article1_width
    if request.post?
      redirect_to :controller => 'pause', :action => 'pausea1'
    end  
  end

  def article2
    @user = logged_in_user
    @article = @user.article2
    @article_width = @user.article2_width
    if request.post?
      redirect_to :controller => 'pause', :action => 'pausea2'
    end  
  end

  def article3
    @user = logged_in_user
    @article = @user.article3
    @article_width = @user.article3_width
    if request.post?
      redirect_to :controller => 'pause', :action => 'pausea3'
    end  
  end
end
<file_sep>/app/controllers/result_controller.rb
class ResultController < ApplicationController
  def index
    @user_pages, @users = paginate :users, :per_page => 24, :order_by => 'id'
  end

  def calculate
    @users = User.find(:all)
    @users.each{|user|
      article1 = @user.article1
      article2 = @user.article2
      article3 = @user.article3

      article1_width = @user.article1_width
      article2_width = @user.article2_width
      article3_width = @user.article3_width

      answers = Answer.find(:all, :conditions => 
       
  end  
end
<file_sep>/app/controllers/question_controller.rb
class QuestionController < ApplicationController
  layout 'standard'

  def question1
    @user = logged_in_user
    @article = @user.article1
    @answer = Answer.find (:first, :conditions => ['id = ?', @user.id])
  end

  def submit1
    @user = logged_in_user
    @answer = Answer.find (:first, :conditions => ['id = ?', @user.id])
    @answer.answer1_01 = params[:question][:answer_1]
    @answer.answer1_02 = params[:question][:answer_2]
    @answer.answer1_03 = params[:question][:answer_3]
    @answer.answer1_04 = params[:question][:answer_4]
    @answer.answer1_05 = params[:question][:answer_5]
    @answer.answer1_06 = params[:question][:answer_6]
    @answer.answer1_07 = params[:question][:answer_7]
    @answer.answer1_08 = params[:question][:answer_8]
    @answer.answer1_09 = params[:question][:answer_9]
    @answer.answer1_10 = params[:question][:answer_10]
    @answer.answer1_11 = params[:question][:answer_11]
    @answer.answer1_12 = params[:question][:answer_12]
    @answer.answer1_13 = params[:question][:answer_13]
    @answer.answer1_14 = params[:question][:answer_14]
    @answer.answer1_15 = params[:question][:answer_15]
    @answer.save
    redirect_to :controller => 'pause', :action => 'pauseq1'
  end

  def question2
    @user = logged_in_user
    @article = @user.article2
  end

  def submit2
    @user = logged_in_user
    @answer = Answer.find (:first, :conditions => ['id = ?', @user.id])
    @answer.answer2_01 = params[:question][:answer_1]
    @answer.answer2_02 = params[:question][:answer_2]
    @answer.answer2_03 = params[:question][:answer_3]
    @answer.answer2_04 = params[:question][:answer_4]
    @answer.answer2_05 = params[:question][:answer_5]
    @answer.answer2_06 = params[:question][:answer_6]
    @answer.answer2_07 = params[:question][:answer_7]
    @answer.answer2_08 = params[:question][:answer_8]
    @answer.answer2_09 = params[:question][:answer_9]
    @answer.answer2_10 = params[:question][:answer_10]
    @answer.answer2_11 = params[:question][:answer_11]
    @answer.answer2_12 = params[:question][:answer_12]
    @answer.answer2_13 = params[:question][:answer_13]
    @answer.answer2_14 = params[:question][:answer_14]
    @answer.answer2_15 = params[:question][:answer_15]
    @answer.save
    redirect_to :controller => 'pause', :action => 'pauseq2'
  end

  def question3
    @user = logged_in_user
    @article = @user.article3
  end
  
  def submit3
    @user = logged_in_user
    @answer = Answer.find (:first, :conditions => ['id = ?', @user.id])
    @answer.answer3_01 = params[:question][:answer_1]
    @answer.answer3_02 = params[:question][:answer_2]
    @answer.answer3_03 = params[:question][:answer_3]
    @answer.answer3_04 = params[:question][:answer_4]
    @answer.answer3_05 = params[:question][:answer_5]
    @answer.answer3_06 = params[:question][:answer_6]
    @answer.answer3_07 = params[:question][:answer_7]
    @answer.answer3_08 = params[:question][:answer_8]
    @answer.answer3_09 = params[:question][:answer_9]
    @answer.answer3_10 = params[:question][:answer_10]
    @answer.answer3_11 = params[:question][:answer_11]
    @answer.answer3_12 = params[:question][:answer_12]
    @answer.answer3_13 = params[:question][:answer_13]
    @answer.answer3_14 = params[:question][:answer_14]
    @answer.answer3_15 = params[:question][:answer_15]
    @answer.save
    redirect_to :controller => 'pause', :action => 'pauseq3'
  end

  def general
    @user = logged_in_user
  end

  def general_submit
    @user = logged_in_user
    @answer = User.find (:first, :conditions => ['id = ?', @user.id])
    @answer.age = params[:general][:age]
    @answer.avgcompuse = params[:general][:avgcompuse]
    @answer.comptime = params[:general][:comptime]
    @answer.howoftennews = params[:general][:howoftennews]
    @answer.onlinepaper = params[:general][:onlinepaper]
    @answer.monitorsize = params[:general][:monitorsize]
    @answer.resolution = params[:general][:resolution]
    @answer.save
    redirect_to :controller => 'page', :action => 'summary'
  end
end
