Class: ODDB::State::SuggestAddress

Inherits:
Global show all
Defined in:
src/state/suggest_address.rb

Constant Summary

VIEW =
View::SuggestAddress
RECIPIENTS =
[ 'zdavatz@ywesee.com', 'hwyss@ywesee.com' ]

Constants inherited from Global

DIRECT_EVENT, GLOBAL_MAP, HOME_STATE, LIMITED, PRINT_STATES, READONLY_STATES, RESOLVE_STATES, REVERSE_MAP, VIEW, ZONE_NAVIGATION

Constants included from UmlautSort

FILTER_PAIRS

Instance Method Summary (collapse)

Methods inherited from Global

#_search_drugs, #_search_drugs_state, #_trigger, #add_to_interaction_basket, #allowed?, #atc_chooser, #checkout, #clear_interaction_basket, #creditable?, #direct_request_path, #doctorlist, #download, #export_csv, #extend, #fachinfo, #feedbacks, #help_navigation, #home_navigation, #home_state, #hospitallist, #interaction_basket, #limit_state, #limited?, #logout, #navigation, #notify, #password_reset, #paypal_return, #powerlink, #print, #proceed_download, #proceed_poweruser, #resolve, #resolve_state, #rss, #search, #show, #snapback_event, #sort, #sponsorlink, #suggest_address, #switch, #unique_email, #user_input, #user_navigation, #ywesee_contact, #zone_navigation, #zones

Methods included from Admin::LoginMethods

#autologin, #login

Methods included from UmlautSort

#sort_model, #umlaut_filter

Instance Method Details

- (Object) address_send



13
14
15
16
17
18
# File 'src/state/suggest_address.rb', line 13

def address_send
  if(sugg = save_suggestion)
    send_notification(sugg)
    AddressConfirm.new(@session, sugg)
  end
end

- (Object) save_suggestion



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'src/state/suggest_address.rb', line 19

def save_suggestion
  pointer = Persistence::Pointer.new(:address_suggestion)
  mandatory = [:name, :email]
  keys = [:additional_lines, :address, :location,
    :fon, :fax, :title, :canton, :message, 
    :address_type, :email_suggestion] + mandatory
  input = user_input(keys, mandatory)
  input[:fax] = input[:fax].to_s.split(/\s*,\s*/u)
  input[:fon] = input[:fon].to_s.split(/\s*,\s*/u)
  if msg = input[:message]
    input[:message] = msg[0,500]
  end
  lns = input[:additional_lines].to_s
  input.store(:additional_lines, 
    lns.split(/[\n\r]+/u))
  input.store(:type, input.delete(:address_type))
  input.store(:address_pointer, @model.pointer)
  parent = @model.parent(@session)
  input.store(:fullname, parent.fullname)
  input.store(:time, Time.now)
  unless error?
    @session.set_cookie_input(:email, input[:email])
    @session.app.update(pointer.creator, input, unique_email)
  end
end

- (Object) send_notification(suggestion)



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'src/state/suggest_address.rb', line 44

def send_notification(suggestion)
  from = suggestion. 
  config = ODDB.config
  mail = TMail::Mail.new
  mail.set_content_type('text', 'plain', 'charset'=>'UTF-8')
  mail.from = from #'suggest_address@oddb.org'
  mail.subject = "#{@session.lookandfeel.lookup(:address_subject)} #{suggestion.fullname}"
  mail.date = Time.now
  url = @session.lookandfeel._event_url(:resolve,
    {:pointer => suggestion.pointer})
  mail.body = [
    url,
  ].join("\n")
  Net::SMTP.start(config.smtp_server, config.smtp_port, config.smtp_domain,
                  config.smtp_user, config.smtp_pass,
                  config.smtp_authtype) { |smtp|
    RECIPIENTS.each { |rec|
      mail.to = [rec]
      smtp.sendmail(mail.encoded, from, rec) 
    }
  }
end