require "rubygems"
require "active_record"

ActiveRecord::Base.establish_connection(
  :adapter => "mysql",
  :host => "localhost",
  :username => "mds",
  :password => "mdsuser",
  :database => "ironworkers")

class Contact < ActiveRecord::Base
  def self.init
    ActiveRecord::Migration.create_table :contacts do |t|
      t.string :name
      t.string :email
      t.string :phone
      t.string :location
      t.text :comments
      t.string :fromform 
    end
  end

  def self.savecontact(name,email,phone,location,comments,fromform)
    contact = Contact.new
    contact.name = name
    contact.email = email
    contact.phone = phone
    contact.location = location
    contact.comments = comments
    contact.fromform = fromform
    contact.save
  end

  def self.getcontacts(fromform)
    contacts = Contact.find(:all, :conditions => ['fromform = ?',fromform])
    contacts
  end
end

if ARGV[0] == 'init'
  Contact.init
end

