form scratch
This commit is contained in:
parent
a7dd8c90c9
commit
08dc7ecdd3
238 changed files with 9393 additions and 13192 deletions
195
app/controllers/application_controller.rb
Executable file → Normal file
195
app/controllers/application_controller.rb
Executable file → Normal file
|
@ -1,189 +1,24 @@
|
|||
# The filters added to this controller will be run for all controllers in the application.
|
||||
# Likewise will all the methods added be available for all controllers.
|
||||
require 'yaml'
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
|
||||
protect_from_forgery
|
||||
protect_from_forgery
|
||||
|
||||
before_filter :user_login_filter
|
||||
before_filter :add_scripts
|
||||
#before_filter :localize
|
||||
before_filter :load_defaults
|
||||
before_filter :set_locale
|
||||
|
||||
protected
|
||||
|
||||
#filter_parameter_logging :password #upgrade to Rails3
|
||||
def load_defaults
|
||||
@defaults = YAML::load(File.open(Rails.root.join('config','defaults.yml')))
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def theme_resolver
|
||||
CDF::CONFIG[:theme] || CDF::CONFIG[:default_theme]
|
||||
end
|
||||
|
||||
def secure_user?() true end
|
||||
def secure_cust?() false end
|
||||
def additional_scripts() "" end
|
||||
def onload_function() "" end
|
||||
|
||||
private
|
||||
def add_scripts
|
||||
@additional_scripts = additional_scripts()
|
||||
@onload_function = onload_function()
|
||||
end
|
||||
|
||||
def user_login_filter
|
||||
if (secure_user? or secure_cust? )and logged_user.nil?
|
||||
|
||||
#upgrade Rails 3
|
||||
#session["return_to"] = request.request_uri
|
||||
logger.debug "*** return_to => #{request.fullpath}"
|
||||
session["return_to"] = request.fullpath
|
||||
|
||||
redirect_to :controller=>"/login", :action => "index"
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
alias login_required user_login_filter
|
||||
|
||||
def logged_user # returns customer id
|
||||
session['user']
|
||||
end
|
||||
|
||||
def logged_customer
|
||||
session['user']
|
||||
end
|
||||
|
||||
def localize
|
||||
# We will use instance vars for the locale so we can make use of them in
|
||||
# the templates.
|
||||
@charset = 'utf-8'
|
||||
headers['Content-Type'] = "text/html; charset=#{@charset}"
|
||||
# Here is a very simplified approach to extract the prefered language
|
||||
# from the request. If all fails, just use 'en_EN' as the default.
|
||||
temp = if request.env['HTTP_ACCEPT_LANGUAGE'].nil?
|
||||
[]
|
||||
else
|
||||
request.env['HTTP_ACCEPT_LANGUAGE'].split(',').first.split('-') rescue []
|
||||
end
|
||||
language = temp.slice(0)
|
||||
dialect = temp.slice(1)
|
||||
@language = language.nil? ? 'en' : language.downcase # default is en
|
||||
# If there is no dialect use the language code ('en' becomes 'en_EN').
|
||||
@dialect = dialect.nil? ? @language.upcase : dialect
|
||||
# The complete locale string consists of
|
||||
# language_DIALECT (en_EN, en_GB, de_DE, ...)
|
||||
@locale = "#{@language}_#{@dialect.upcase}"
|
||||
@htmllang = @language == @dialect ? @language : "#{@language}-#{@dialect}"
|
||||
# Finally, bind the textdomain to the locale. From now on every used
|
||||
# _('String') will get translated into the right language. (Provided
|
||||
# that we have a corresponding mo file in the right place).
|
||||
bindtextdomain('messages', "#{RAILS_ROOT}/locale", @locale, @charset)
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
def include_tinymce(mode="textareas",elements="")
|
||||
tinymce=''
|
||||
tinymce << '
|
||||
<script language="javascript" type="text/javascript" src="/tiny_mce/tiny_mce.js"></script>
|
||||
<script language="javascript" type="text/javascript">
|
||||
tinyMCE.init({
|
||||
mode : "'
|
||||
tinymce << mode << '",'
|
||||
if mode == "exact"
|
||||
tinymce << 'elements : "' << elements << '",
|
||||
'
|
||||
end
|
||||
tinymce << '
|
||||
theme : "advanced",
|
||||
cleanup : true,
|
||||
width: "100%",
|
||||
remove_linebreaks : false,
|
||||
entity_encoding : "named",
|
||||
relative_urls : false,
|
||||
plugins : "table,save,advhr,advimage,advlink,iespell,preview,zoom,searchreplace,print,contextmenu,fullscreen,linkattach",
|
||||
theme_advanced_buttons1_add : "fontselect,fontsizeselect",
|
||||
theme_advanced_buttons2_add : "separator,preview,zoom",
|
||||
theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator",
|
||||
theme_advanced_buttons3_add_before : "tablecontrols,separator",
|
||||
theme_advanced_buttons3_add : "iespell,forecolor,backcolor,fullscreen",
|
||||
theme_advanced_source_editor_width : "700",
|
||||
theme_advanced_source_editor_height : "500",
|
||||
theme_advanced_styles : "Header 1=header1",
|
||||
theme_advanced_toolbar_location : "top",
|
||||
theme_advanced_toolbar_align : "left",
|
||||
theme_advanced_path_location : "none",
|
||||
extended_valid_elements : ""
|
||||
+"a[accesskey|charset|class|coords|href|hreflang|id|lang|name"
|
||||
+"|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup"
|
||||
+"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|rel|rev"
|
||||
+"|shape|style|tabindex|title|target|type],"
|
||||
+"dd[class|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup"
|
||||
+"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],"
|
||||
+"div[align|class|id|lang|onclick"
|
||||
+"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
|
||||
+"|onmouseout|onmouseover|onmouseup|style|title],"
|
||||
+"dl[class|compact|id|lang|onclick|ondblclick|onkeydown"
|
||||
+"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
|
||||
+"|onmouseup|style|title],"
|
||||
+"dt[class|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup"
|
||||
+"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],"
|
||||
+"img[align|alt|border|class|height"
|
||||
+"|hspace|id|ismap|lang|longdesc|name|onclick|ondblclick|onkeydown"
|
||||
+"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
|
||||
+"|onmouseup|src|style|title|usemap|vspace|width],"
|
||||
+"script[charset|defer|language|src|type],"
|
||||
+"style[lang|media|title|type],"
|
||||
+"table[align|bgcolor|border|cellpadding|cellspacing|class"
|
||||
+"|frame|height|id|lang|onclick|ondblclick|onkeydown|onkeypress"
|
||||
+"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|rules"
|
||||
+"|style|summary|title|width],"
|
||||
+"td[abbr|align|axis|bgcolor|char|charoff|class"
|
||||
+"|colspan|headers|height|id|lang|nowrap|onclick"
|
||||
+"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
|
||||
+"|onmouseout|onmouseover|onmouseup|rowspan|scope"
|
||||
+"|style|title|valign|width],"
|
||||
+"hr[align|class|id|lang|noshade|onclick"
|
||||
+"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
|
||||
+"|onmouseout|onmouseover|onmouseup|size|style|title|width],"
|
||||
+"font[class|color|face|id|lang|size|style|title],"
|
||||
+"span[align|class|class|id|lang|onclick|ondblclick|onkeydown"
|
||||
+"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
|
||||
+"|onmouseup|style|title]",
|
||||
external_link_list_url : "/cms/urlchoose/choose_tinymce",
|
||||
external_attachments_list_url : "/attachments/attachments/choose_tinymce",
|
||||
external_image_list_url : "/gallery/imgchoose/choose_tinymce",
|
||||
flash_external_list_url : "example_data/example_flash_list.js"
|
||||
});
|
||||
</script>'
|
||||
tinymce
|
||||
end
|
||||
|
||||
helper_method :include_tinymce
|
||||
|
||||
def include_simple_tinymce(mode="textareas",elements="")
|
||||
tinymce = ''
|
||||
tinymce << '<script language="javascript" type="text/javascript" src="/tiny_mce/tiny_mce.js"></script>
|
||||
<script language="javascript" type="text/javascript">
|
||||
tinyMCE.init({
|
||||
mode : "'
|
||||
tinymce << mode << '",'
|
||||
if mode == "exact"
|
||||
tinymce << 'elements : "' << elements << '",
|
||||
'
|
||||
end
|
||||
tinymce << '
|
||||
theme : "default",
|
||||
width : "100%",
|
||||
auto_reset_designmode : true
|
||||
});
|
||||
</script>'
|
||||
tinymce
|
||||
end
|
||||
|
||||
def _(text)
|
||||
t text
|
||||
end
|
||||
|
||||
helper_method :include_simple_tinymce, :_
|
||||
def theme_resolver
|
||||
@defaults['theme']
|
||||
end
|
||||
|
||||
def set_locale
|
||||
I18n.locale = @defaults['locale'] || I18n.default_locale
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
class ContactGroupsController < ApplicationController
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
layout 'public'
|
||||
|
||||
|
||||
def index
|
||||
@contact_group = ContactGroup.new
|
||||
@contact_group.customer_id = logged_user
|
||||
@contactgroups = ContactGroup.find_by_user(logged_user)
|
||||
end
|
||||
|
||||
def add
|
||||
@contactgroup = ContactGroup.new
|
||||
@contactgroup.customer_id = logged_user
|
||||
render("/contact_group/edit")
|
||||
end
|
||||
|
||||
def delete
|
||||
contactgroup = ContactGroup.find(@params["id"])
|
||||
contactgroup.destroy
|
||||
redirect_to(:action=>"list")
|
||||
end
|
||||
|
||||
def edit
|
||||
@contactgroup = ContactGroup.find(@params["id"])
|
||||
end
|
||||
|
||||
def save
|
||||
begin
|
||||
if @params["contactgroup"]["id"].nil? or @params["contactgroup"]["id"] == ""
|
||||
# New contactgroup
|
||||
@contactgroup = ContactGroup.create(@params["contactgroup"])
|
||||
else
|
||||
# Edit existing
|
||||
@contactgroup = ContactGroup.find(@params["contactgroup"]["id"])
|
||||
@contactgroup.attributes = @params["contactgroup"]
|
||||
end
|
||||
|
||||
if @contactgroup.save
|
||||
redirect_to(:action=>"list")
|
||||
else
|
||||
render "/contact_group/edit"
|
||||
end
|
||||
rescue CDF::ValidationError => e
|
||||
logger.info("RESCUE")
|
||||
@contactgroup = e.entity
|
||||
render("/contact_group/edit")
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def secure_user?() true end
|
||||
|
||||
end
|
|
@ -1,378 +0,0 @@
|
|||
class ContactsController < ApplicationController
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
layout :select_layout
|
||||
|
||||
def index
|
||||
if params[:letter] && params[:letter].any?
|
||||
@contacts = Contact.for_customer(logged_user).letter(params[:letter]).paginate :page => params[:page],
|
||||
:per_page => CDF::CONFIG[:contacts_per_page]
|
||||
else
|
||||
@contacts = Contact.for_customer(logged_user).paginate :page => params[:page], :per_page => CDF::CONFIG[:contacts_per_page]
|
||||
end
|
||||
end
|
||||
|
||||
def listLetter
|
||||
letters = CDF::CONFIG[:contact_letters]
|
||||
@contact_pages = Paginator.new(self, Contact.count(
|
||||
["customer_id = %s and substr(UPPER(fname),1,1) = '%s'", logged_user, letters[params['id'].to_i]]), CDF::CONFIG[:contacts_per_page], params['page'])
|
||||
@contacts = Contact.find(:all, :conditions=>["customer_id = %s and substr(UPPER(fname),1,1) = '%s'", logged_user, letters[params['id'].to_i]],
|
||||
:order=>['fname'], :limit=>CDF::CONFIG[:contacts_per_page], :offset=>@contact_pages.current.offset)
|
||||
|
||||
if params["mode"] == "groups"
|
||||
if params["group_id"] and not params["group_id"].nil? and not params["group_id"] == ''
|
||||
@group_id = params["group_id"].to_i
|
||||
@contacts_for_group = Hash.new
|
||||
for contact in @contacts
|
||||
@contacts_for_group[contact.id] = 0 # initialize
|
||||
for gr in contact.groups
|
||||
if gr.contact_group_id.to_i == @group_id
|
||||
@contacts_for_group[contact.id] = 1 # checked
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
render :action => "list"
|
||||
end
|
||||
|
||||
def new
|
||||
@contact = Contact.new
|
||||
@contact.customer_id = logged_user
|
||||
|
||||
# load related lists
|
||||
loadLists
|
||||
|
||||
# Init groups: because of checkbox
|
||||
# Set all to 0 => unchecked
|
||||
@groups = Hash.new
|
||||
@contactgroups.each {|g|
|
||||
@groups[g.id] = 0
|
||||
}
|
||||
end
|
||||
|
||||
def add_multiple
|
||||
@contact = Contact.new
|
||||
@contact["file_type"] = "1"
|
||||
end
|
||||
|
||||
def add_from_mail
|
||||
cstr = params['cstr']
|
||||
retmsg = params['retmsg']
|
||||
session["return_to"] = url_for(:controller=>'/webmail/webmail',
|
||||
:action=>'folders',
|
||||
:msg_id=>retmsg)
|
||||
# parse string
|
||||
if i = cstr.index("<")
|
||||
name, email = cstr.slice(0, i), cstr.slice((i+1)..(cstr.strip().index(">")-1))
|
||||
fname = name.split().first
|
||||
lname = name.split().last if name.split().size() > 1
|
||||
else
|
||||
fname, lname, email = "", "", cstr
|
||||
end
|
||||
|
||||
if @contact = Contact.find_by_user_email(logged_user, email)
|
||||
# load related lists
|
||||
loadLists
|
||||
|
||||
@contact.fname, @contact.lname = fname, lname
|
||||
|
||||
# groups = @contact.groups
|
||||
@groups = Hash.new
|
||||
@contactgroups.each {|g|
|
||||
groupSelected = false
|
||||
@contact.groups.each {|gr|
|
||||
if gr.contact_group_id.to_i == g.id.to_i
|
||||
groupSelected = true
|
||||
break
|
||||
end
|
||||
}
|
||||
if groupSelected
|
||||
@groups[g.id] = 1 # checked
|
||||
else
|
||||
@groups[g.id] = 0 # unchecked
|
||||
end
|
||||
}
|
||||
else
|
||||
@contact = Contact.new("fname"=>fname, "lname" => lname, "email" => email)
|
||||
@contact.customer_id = logged_user
|
||||
|
||||
# load related lists
|
||||
loadLists
|
||||
|
||||
# Init groups: because of checkbox
|
||||
# Set all to 0 => unchecked
|
||||
@groups = Hash.new
|
||||
@contactgroups.each {|g|
|
||||
@groups[g.id] = 0
|
||||
}
|
||||
end
|
||||
render :action => "new"
|
||||
end
|
||||
|
||||
def import_preview
|
||||
file = params["contact"]["data"]
|
||||
|
||||
flash["errors"] = Array.new
|
||||
|
||||
if file.size == 0
|
||||
flash["errors"] << _('You haven\'t selected file or the file is empty')
|
||||
@contact = Contact.new
|
||||
@contact["file_type"] = params["contact"]["file_type"]
|
||||
render :action => "add_multiple"
|
||||
end
|
||||
|
||||
file_type = params["contact"]["file_type"]
|
||||
if file_type.nil? or file_type == '1'
|
||||
separator = ','
|
||||
else
|
||||
separator = /\t/
|
||||
|
||||
end
|
||||
|
||||
@contacts = Array.new
|
||||
emails = Array.new
|
||||
|
||||
file.each {|line|
|
||||
cdata = line.strip.chomp.split(separator)
|
||||
cont = Contact.new
|
||||
cont.fname = cdata[0].to_s.strip.chomp
|
||||
cont.lname = cdata[1].to_s.strip.chomp
|
||||
cont.email = cdata[2].to_s.strip.chomp
|
||||
|
||||
# Check for duplicate emails in the file
|
||||
if emails.include?(cont.email)
|
||||
flash["errors"] << sprintf(_('Contact %'), file.lineno.to_s) + ": " + _('The e-mail duplicates the e-mail of another record!')
|
||||
else
|
||||
emails << cont.email
|
||||
end
|
||||
|
||||
@contacts << cont
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
def import
|
||||
contacts_count = params["contact"].length
|
||||
contacts_to_import = params["contact"]
|
||||
@contacts = Array.new
|
||||
emails = Array.new
|
||||
|
||||
flash["errors"] = Array.new
|
||||
|
||||
for i in 0...contacts_count
|
||||
contact = Contact.new
|
||||
contact.customer_id = logged_user
|
||||
contact.fname = contacts_to_import[i.to_s]["fname"]
|
||||
contact.lname = contacts_to_import[i.to_s]["lname"]
|
||||
contact.email = contacts_to_import[i.to_s]["email"]
|
||||
|
||||
begin
|
||||
# Check for duplicate emails in the submitted data
|
||||
if emails.include?(contact.email)
|
||||
flash["errors"] << sprintf(_('Contact %'), (i+1).to_s) + ": " + _('The e-mail duplicates the e-mail of another record!')
|
||||
else
|
||||
emails << contact.email
|
||||
end
|
||||
# Check if contact is valid
|
||||
contact.valid?
|
||||
rescue CDF::ValidationError => e
|
||||
if not contact.errors.empty?
|
||||
["fname", "lname", "email"].each do |attr|
|
||||
attr_errors = contact.errors.on(attr)
|
||||
attr_errors = [attr_errors] unless attr_errors.nil? or attr_errors.is_a? Array
|
||||
|
||||
if not attr_errors.nil?
|
||||
attr_errors.each do |msg|
|
||||
flash["errors"] << l(:contact_addmultiple_errorforcontact, (i+1).to_s) + ": " + l(msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end # rescue
|
||||
|
||||
@contacts << contact
|
||||
end # for
|
||||
|
||||
# If there are validation errors - display them
|
||||
if not flash["errors"].nil? and not flash["errors"].empty?
|
||||
render :action => "import_preview"
|
||||
else
|
||||
# save
|
||||
begin
|
||||
for contact in @contacts
|
||||
Contact.create(contact.attributes)
|
||||
end
|
||||
# Set message for successful import
|
||||
flash["alert"] = Array.new
|
||||
flash["alert"] << l(:contact_addmultiple_success, @contacts.length.to_s)
|
||||
keep_flash()
|
||||
redirect_to(:action=>"list")
|
||||
rescue Exception => exc
|
||||
flash["errors"] << exc
|
||||
render :action => "import_preview"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def choose
|
||||
if params["mode"] == "groups"
|
||||
save_groups
|
||||
end
|
||||
|
||||
@tos, @ccs, @bccs = Array.new, Array.new, Array.new
|
||||
|
||||
params["contacts_to"].each{ |id,value| @tos << Contact.find(id) if value == "1" } if params["contacts_to"]
|
||||
params["contacts_cc"].each{ |id,value| @ccs << Contact.find(id) if value == "1" } if params["contacts_cc"]
|
||||
params["contacts_bcc"].each{ |id,value| @bccs << Contact.find(id) if value == "1" } if params["contacts_bcc"]
|
||||
|
||||
params["groups_to"].each{ |id,value|
|
||||
ContactGroup.find(id).contacts.each {|c| @tos << c} if value == "1" } if params["groups_to"]
|
||||
params["groups_cc"].each{ |id,value|
|
||||
ContactGroup.find(id).contacts.each {|c| @ccs << c} if value == "1" } if params["groups_cc"]
|
||||
params["groups_bcc"].each{ |id,value|
|
||||
ContactGroup.find(id).contacts.each {|c| @bccs << c} if value == "1" } if params["groups_bcc"]
|
||||
end
|
||||
|
||||
def save_groups
|
||||
contacts_for_group = params["contacts_for_group"]
|
||||
group_id = params["group_id"]
|
||||
contact_group = ContactGroup.find(group_id)
|
||||
|
||||
|
||||
contacts_for_group.each { |contact_id,value|
|
||||
contact = Contact.find(contact_id)
|
||||
if value == "1" and not contact_group.contacts.include?(contact)
|
||||
contact_group.contacts << contact
|
||||
end
|
||||
if value == "0" and contact_group.contacts.include?(contact)
|
||||
contact_group.contacts.delete(contact)
|
||||
end
|
||||
}
|
||||
redirect_to(:action=>"index", :id=>group_id, :params=>{"mode"=>params["mode"]})
|
||||
end
|
||||
|
||||
def edit
|
||||
@contact = Contact.find(params["id"])
|
||||
# load related lists
|
||||
loadLists
|
||||
|
||||
# groups = @contact.groups
|
||||
@groups = Hash.new
|
||||
@contactgroups.each {|g|
|
||||
groupSelected = false
|
||||
@contact.groups.each {|gr|
|
||||
if gr.contact_group_id.to_i == g.id.to_i
|
||||
groupSelected = true
|
||||
break
|
||||
end
|
||||
}
|
||||
if groupSelected
|
||||
@groups[g.id] = 1 # checked
|
||||
else
|
||||
@groups[g.id] = 0 # unchecked
|
||||
end
|
||||
}
|
||||
render :action => "new"
|
||||
end
|
||||
|
||||
# Insert or update
|
||||
def create
|
||||
if params["contact"]["id"] == ""
|
||||
# New contact
|
||||
@contact = Contact.create(params["contact"])
|
||||
else
|
||||
# Edit existing
|
||||
@contact = Contact.find(params["contact"]["id"])
|
||||
@contact.attributes = params["contact"]
|
||||
end
|
||||
|
||||
@contactgroups = ContactGroup.find_by_user(logged_user)
|
||||
# Groups displayed
|
||||
groups = params['groups']
|
||||
tempGroups = Array.new
|
||||
tempGroups.concat(@contact.groups)
|
||||
|
||||
@contactgroups.each { |cgroup|
|
||||
includesCGroup = false
|
||||
tempGroups.each {|gr|
|
||||
if gr.contact_group_id.to_i == cgroup.id.to_i
|
||||
includesCGroup = true
|
||||
break
|
||||
end
|
||||
}
|
||||
if groups["#{cgroup.id}"] == "1" and not includesCGroup
|
||||
@contact.groups << cgroup
|
||||
end
|
||||
|
||||
if groups["#{cgroup.id}"] == "0" and includesCGroup
|
||||
@contact.groups.delete(cgroup)
|
||||
end
|
||||
}
|
||||
if @contact.save
|
||||
if params["paction"] == t(:save)
|
||||
redirect_to :action =>:index
|
||||
else
|
||||
redirect_to :action => :new
|
||||
end
|
||||
else
|
||||
loadLists
|
||||
@groups = Hash.new
|
||||
@contactgroups.each {|g|
|
||||
if @contact.groups.include?(g)
|
||||
@groups[g.id] = 1
|
||||
else
|
||||
@groups[g.id] = 0
|
||||
end
|
||||
}
|
||||
render :action => :new
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
Contact.destroy(params['id'])
|
||||
redirect_to(:action=>'index')
|
||||
end
|
||||
|
||||
protected
|
||||
def secure_user?() true end
|
||||
def additional_scripts()
|
||||
add_s = ''
|
||||
if action_name == "choose"
|
||||
add_s<<'<script type="text/javascript" src="/javascripts/global.js"></script>'
|
||||
add_s<<'<script type="text/javascript" src="/javascripts/contact_choose.js"></script>'
|
||||
end
|
||||
add_s
|
||||
end
|
||||
|
||||
def onload_function()
|
||||
if action_name == "choose"
|
||||
"javascript:respondToCaller();"
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
private
|
||||
def select_layout
|
||||
if params["mode"] == "choose"
|
||||
@mode = "choose"
|
||||
@contactgroups = ContactGroup.find_by_user(logged_user)
|
||||
'chooser'
|
||||
elsif params["mode"] == "groups"
|
||||
@mode = "groups"
|
||||
'public'
|
||||
else
|
||||
@mode = "normal"
|
||||
'public'
|
||||
end
|
||||
end
|
||||
|
||||
def loadLists
|
||||
if @contactgroups.nil?
|
||||
@contactgroups = ContactGroup.find_by_user(logged_user)
|
||||
end
|
||||
end
|
||||
end
|
18
app/controllers/core_controller.rb
Normal file
18
app/controllers/core_controller.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
class CoreController < ApplicationController
|
||||
|
||||
theme :theme_resolver
|
||||
layout "simple"
|
||||
|
||||
def login
|
||||
end
|
||||
|
||||
def logout
|
||||
reset_session
|
||||
flash[:notice] = t(:user_logged_out)
|
||||
redirect_to :action => "login"
|
||||
end
|
||||
|
||||
def authenticate
|
||||
end
|
||||
|
||||
end
|
|
@ -1,26 +0,0 @@
|
|||
require 'ezcrypto'
|
||||
class FoldersController < ApplicationController
|
||||
include ImapUtils
|
||||
|
||||
before_filter :login_required
|
||||
before_filter :load_imap_session
|
||||
after_filter :close_imap_session
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
layout 'public'
|
||||
|
||||
def index
|
||||
@folders = @mailbox.folders
|
||||
end
|
||||
|
||||
def create
|
||||
@mailbox.create_folder(CDF::CONFIG[:mail_inbox] + '.' + params[:folder])
|
||||
redirect_to folders_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@mailbox.delete_folder params[:id]
|
||||
redirect_to folders_path
|
||||
end
|
||||
end
|
|
@ -1,73 +0,0 @@
|
|||
require 'ezcrypto'
|
||||
require 'imapmailbox'
|
||||
|
||||
class LoginController < ApplicationController
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def index
|
||||
if not(logged_user.nil?)
|
||||
redirect_to :controller =>"webmail", :action=>"index"
|
||||
else
|
||||
@login_user = Customer.new
|
||||
end
|
||||
end
|
||||
|
||||
def authenticate
|
||||
if user = auth(params['login_user']["email"], params['login_user']["password"])
|
||||
session["user"] = user.id
|
||||
if CDF::CONFIG[:crypt_session_pass]
|
||||
session["wmp"] = EzCrypto::Key.encrypt_with_password(CDF::CONFIG[:encryption_password], CDF::CONFIG[:encryption_salt], params['login_user']["password"])
|
||||
else
|
||||
# dont use crypt
|
||||
session["wmp"] = params['login_user']["password"]
|
||||
end
|
||||
if session["return_to"]
|
||||
redirect_to(session["return_to"])
|
||||
session["return_to"] = nil
|
||||
else
|
||||
redirect_to :action=>"index"
|
||||
end
|
||||
else
|
||||
logger.debug "*** Not logged"
|
||||
@login_user = Customer.new
|
||||
flash["error"] = t :wrong_email_or_password
|
||||
redirect_to :action => "index"
|
||||
end
|
||||
end
|
||||
|
||||
def logout
|
||||
reset_session
|
||||
flash["status"] = t(:user_logged_out)
|
||||
redirect_to :action => "index"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def need_subdomain?() true end
|
||||
def secure_user?() false end
|
||||
|
||||
private
|
||||
|
||||
def auth(email, password)
|
||||
mailbox = IMAPMailbox.new(Rails.logger)
|
||||
logger.info "*** mailbox #{mailbox.inspect}"
|
||||
begin
|
||||
mailbox.connect(email, password)
|
||||
rescue Exception => exc
|
||||
logger.debug "*** auth/Mailbox Object => #{exc.message}"
|
||||
return nil
|
||||
end
|
||||
|
||||
mailbox.disconnect
|
||||
mailbox = nil
|
||||
if user = Customer.find_by_email(email)
|
||||
return user
|
||||
else
|
||||
# create record in database
|
||||
user = Customer.create("email"=>email)
|
||||
MailPref.create('customer_id' => user.id)
|
||||
return user
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,424 +0,0 @@
|
|||
require 'cdfmail'
|
||||
require 'net/smtp'
|
||||
require 'net/imap'
|
||||
require 'mail2screen'
|
||||
require 'ezcrypto'
|
||||
require 'imapmailbox'
|
||||
require 'imap_utils'
|
||||
|
||||
|
||||
class WebmailController < ApplicationController
|
||||
include ImapUtils
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
logger.info "*** WebmailController #{logger.inspect}"
|
||||
|
||||
# Administrative functions
|
||||
before_filter :login_required
|
||||
before_filter :obtain_cookies_for_search_and_nav, :only=>[:messages]
|
||||
before_filter :load_imap_session
|
||||
after_filter :close_imap_session
|
||||
|
||||
layout "public", :except => [:view_source, :download]
|
||||
|
||||
# model :filter, :expression, :mail_pref, :customer
|
||||
|
||||
BOOL_ON = "on"
|
||||
|
||||
def index
|
||||
redirect_to(:action=>"messages")
|
||||
end
|
||||
|
||||
def error_connection
|
||||
end
|
||||
|
||||
def refresh
|
||||
@mailbox.reload
|
||||
@folders = @mailbox.folders
|
||||
redirect_to(:action=>'messages')
|
||||
end
|
||||
|
||||
def messages
|
||||
session["return_to"] = nil
|
||||
@search_field = params['search_field']
|
||||
@search_value = params['search_value']
|
||||
|
||||
# handle sorting - tsort session field contains last reverse or no for field
|
||||
# and lsort - last sort field
|
||||
if session['tsort'].nil? or session['lsort'].nil?
|
||||
session['lsort'] = "DATE"
|
||||
session['tsort'] = {"DATE" => true, "FROM" => true, "SUBJECT" => true, "TO" => false}
|
||||
end
|
||||
|
||||
case operation_param
|
||||
when t(:copy) # copy
|
||||
msg_ids = []
|
||||
messages_param.each { |msg_id, bool|
|
||||
msg_ids << msg_id.to_i if bool == BOOL_ON and dst_folder != @folder_name } if messages_param
|
||||
folder.copy_multiple(msg_ids, dst_folder) if msg_ids.size > 0
|
||||
when t(:move) # move
|
||||
msg_ids = []
|
||||
messages_param.each { |msg_id, bool|
|
||||
msg_ids << msg_id.to_i if bool == BOOL_ON and dst_folder != @folder_name } if messages_param
|
||||
folder.move_multiple(msg_ids, dst_folder) if msg_ids.size > 0
|
||||
when t(:delete) # delete
|
||||
msg_ids = []
|
||||
messages_param.each { |msg_id, bool| msg_ids << msg_id.to_i if bool == BOOL_ON } if messages_param
|
||||
folder.delete_multiple(msg_ids) if msg_ids.size > 0
|
||||
when t(:mark_read) # mark as read
|
||||
messages_param.each { |msg_id, bool| msg = folder.mark_read(msg_id.to_i) if bool == BOOL_ON } if messages_param
|
||||
when t(:mark_unread) # mark as unread
|
||||
messages_param.each { |msg_id, bool| msg = folder.mark_unread(msg_id.to_i) if bool == BOOL_ON } if messages_param
|
||||
when "SORT"
|
||||
session['lsort'] = sort_query = params["scc"]
|
||||
session['tsort'][sort_query] = (session['tsort'][sort_query]? false : true)
|
||||
@search_field, @search_value = session['search_field'], session['search_value']
|
||||
when t(:search) # search
|
||||
session['search_field'] = @search_field
|
||||
session['search_value'] = @search_value
|
||||
when t(:show_all) # search
|
||||
session['search_field'] = @search_field = nil
|
||||
session['search_value'] = @search_value = nil
|
||||
else
|
||||
# get search criteria from session
|
||||
@search_field = session['search_field']
|
||||
@search_value = session['search_value']
|
||||
end
|
||||
|
||||
sort_query = session['lsort']
|
||||
reverse_sort = session['tsort'][sort_query]
|
||||
query = ["ALL"]
|
||||
@page = params["page"]
|
||||
@page ||= session['page']
|
||||
session['page'] = @page
|
||||
if @search_field and @search_value and not(@search_field.strip() == "") and not(@search_value.strip() == "")
|
||||
@pages = Paginator.new self, 0, get_mail_prefs.wm_rows, @page
|
||||
@messages = folder.messages_search([@search_field, @search_value], sort_query + (reverse_sort ? ' desc' : ' asc'))
|
||||
else
|
||||
@pages = Paginator.new self, folder.total, get_mail_prefs.wm_rows, @page
|
||||
@messages = folder.messages(@pages.current.first_item - 1, get_mail_prefs.wm_rows, sort_query + (reverse_sort ? ' desc' : ' asc'))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def delete
|
||||
@msg_id = msg_id_param.to_i
|
||||
folder.delete(@msg_id)
|
||||
redirect_to(:action=>"messages")
|
||||
end
|
||||
|
||||
def reply # not ready at all
|
||||
@msg_id = msg_id_param.to_i
|
||||
@imapmail = folder.message(@msg_id)
|
||||
fb = @imapmail.full_body
|
||||
@tmail = TMail::Mail.parse(fb)
|
||||
|
||||
@mail = prepare_mail
|
||||
@mail.reply(@tmail, fb, get_mail_prefs.mail_type)
|
||||
|
||||
render :action => 'compose'
|
||||
end
|
||||
|
||||
def forward
|
||||
@msg_id = msg_id_param.to_i
|
||||
@imapmail = folder.message(@msg_id)
|
||||
fb = @imapmail.full_body
|
||||
@tmail = TMail::Mail.parse(fb)
|
||||
|
||||
@mail = prepare_mail
|
||||
@mail.forward(@tmail, fb)
|
||||
|
||||
render :action => 'compose'
|
||||
end
|
||||
|
||||
def compose
|
||||
if @mail.nil?
|
||||
operation = operation_param
|
||||
if operation == t(:send)
|
||||
@mail = create_mail
|
||||
encmail = @mail.send_mail
|
||||
get_imap_session
|
||||
@mailbox.message_sent(encmail)
|
||||
|
||||
# delete temporary files (attachments)
|
||||
@mail.delete_attachments()
|
||||
render :action => :mailsent
|
||||
elsif operation == t(:add)
|
||||
@mail = create_mail
|
||||
if params['attachment']
|
||||
attachment = CDF::Attachment.new(@mail)
|
||||
attachment.file = params['attachment']
|
||||
end
|
||||
else
|
||||
# default - new email create
|
||||
@mail = create_mail
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def empty # empty trash folder (works for any one else :-))
|
||||
folder.messages(0, -1).each{ |message|
|
||||
folder.delete(message)
|
||||
}
|
||||
folder.expunge
|
||||
redirect_to(:action=>"messages")
|
||||
end
|
||||
|
||||
def message
|
||||
@msg_id = msg_id_param
|
||||
@imapmail = folder.message(@msg_id)
|
||||
folder.mark_read(@imapmail.uid) if @imapmail.unread
|
||||
@mail = TMail::Mail.parse(@imapmail.full_body)
|
||||
end
|
||||
|
||||
def download
|
||||
msg_id = msg_id_param
|
||||
imapmail = folder.message(msg_id)
|
||||
mail = TMail::Mail.parse(imapmail.full_body)
|
||||
|
||||
if mail.multipart?
|
||||
get_parts(mail).each { |part|
|
||||
return send_part(part) if part.header and part.header['content-type']['name'] == params['ctype']
|
||||
}
|
||||
render("webmail/noattachment")
|
||||
else
|
||||
render("webmail/noattachment")
|
||||
end
|
||||
end
|
||||
|
||||
def prefs
|
||||
@customer = Customer.find(logged_customer)
|
||||
@mailpref = MailPref.find_or_create_by_customer_id logged_customer
|
||||
|
||||
if params['op'] == _('Save')
|
||||
if params['customer']
|
||||
@customer.fname = params['customer']['fname']
|
||||
@customer.lname = params['customer']['lname']
|
||||
@customer.save
|
||||
end
|
||||
@mailpref.attributes = params["mailpref"]
|
||||
@mailpref.save
|
||||
session["wmimapseskey"] = nil
|
||||
redirect_to(:action=>"messages")
|
||||
end
|
||||
end
|
||||
|
||||
# Message filters management
|
||||
def filters
|
||||
end
|
||||
|
||||
def filter
|
||||
if params['op']
|
||||
@filter = Filter.new(params['filter'])
|
||||
@filter.customer_id = logged_customer
|
||||
params['expression'].each { |index, expr| @filter.expressions << Expression.new(expr) unless expr["expr_value"].nil? or expr["expr_value"].strip == "" }
|
||||
case params['op']
|
||||
when _('Add')
|
||||
@filter.expressions << Expression.new
|
||||
when _('Save')
|
||||
if params['filter']['id'] and params['filter']['id'] != ""
|
||||
@sf = Filter.find(params['filter']['id'])
|
||||
@sf.name, @sf.destination_folder = @filter.name, @filter.destination_folder
|
||||
@sf.expressions.each{|expr| Expression.delete(expr.id) }
|
||||
@filter.expressions.each {|expr| @sf.expressions << Expression.create(expr.attributes) }
|
||||
else
|
||||
@sf = Filter.create(@filter.attributes)
|
||||
@sf.order_num = @user.filters.size
|
||||
@filter.expressions.each {|expr| @sf.expressions << Expression.create(expr.attributes) }
|
||||
end
|
||||
# may be some validation will be needed
|
||||
@sf.save
|
||||
@user.serialize_to_file
|
||||
return redirect_to(:action=>"filters")
|
||||
end
|
||||
@expressions = @filter.expressions
|
||||
else
|
||||
@filter = Filter.find(params["id"]) if params["id"]
|
||||
@expressions = @filter.expressions
|
||||
end
|
||||
@destfolders = get_to_folders
|
||||
end
|
||||
|
||||
def filter_delete
|
||||
Filter.delete(params["id"])
|
||||
# reindex other filters
|
||||
@user = Customer.find(logged_customer)
|
||||
findex = 0
|
||||
@user.filters.each { |filter|
|
||||
findex = findex + 1
|
||||
filter.order_num = findex
|
||||
filter.save
|
||||
}
|
||||
@user.serialize_to_file
|
||||
redirect_to :action=>"filters"
|
||||
end
|
||||
|
||||
def filter_up
|
||||
filt = @user.filters.find(params['id'])
|
||||
ufilt = @user.filters.find_all("order_num = #{filt.order_num - 1}").first
|
||||
ufilt.order_num = ufilt.order_num + 1
|
||||
filt.order_num = filt.order_num - 1
|
||||
ufilt.save
|
||||
filt.save
|
||||
@user.serialize_to_file
|
||||
redirect_to :action=>"filters"
|
||||
end
|
||||
|
||||
def filter_down
|
||||
filt = Filter.find(params["id"])
|
||||
dfilt = @user.filters[filt.order_num]
|
||||
dfilt.order_num = dfilt.order_num - 1
|
||||
filt.order_num = filt.order_num + 1
|
||||
dfilt.save
|
||||
filt.save
|
||||
@user.serialize_to_file
|
||||
redirect_to :action=>"filters"
|
||||
end
|
||||
|
||||
def filter_add
|
||||
@filter = Filter.new
|
||||
@filter.expressions << Expression.new
|
||||
@expressions = @filter.expressions
|
||||
@destfolders = get_to_folders
|
||||
render "filter"
|
||||
end
|
||||
# end of filters
|
||||
|
||||
def view_source
|
||||
@msg_id = msg_id_param.to_i
|
||||
@imapmail = folder.message(@msg_id)
|
||||
@msg_source = CGI.escapeHTML(@imapmail.full_body).gsub("\n", "<br/>")
|
||||
end
|
||||
|
||||
def auto_complete_for_mail_to
|
||||
auto_complete_responder_for_contacts params[:mail][:to]
|
||||
end
|
||||
|
||||
def auto_complete_for_mail_cc
|
||||
auto_complete_responder_for_contacts params[:mail][:cc]
|
||||
end
|
||||
|
||||
def auto_complete_for_mail_bcc
|
||||
auto_complete_responder_for_contacts params[:mail][:bcc]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def auto_complete_responder_for_contacts(value)
|
||||
# first split by "," and take last name
|
||||
searchName = value.split(',').last.strip
|
||||
|
||||
# if there are 2 names search by them
|
||||
if searchName.split.size > 1
|
||||
fname, lname = searchName.split.first, searchName.split.last
|
||||
conditions = ['customer_id = ? and LOWER(fname) LIKE ? and LOWER(lname) like ?', logged_customer, fname.downcase + '%', lname.downcase + '%']
|
||||
else
|
||||
conditions = ['customer_id = ? and LOWER(fname) LIKE ?', logged_customer, searchName.downcase + '%']
|
||||
end
|
||||
@contacts = Contact.find(:all, :conditions => conditions, :order => 'fname ASC',:limit => 8)
|
||||
render :partial => 'contacts'
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def additional_scripts()
|
||||
@additional_css = ["webmail/webmail"]
|
||||
@additional_js = ["webmail"]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_to_folders
|
||||
res = Array.new
|
||||
@folders.each{|f| res << f unless f.name == CDF::CONFIG[:mail_sent] or f.name == CDF::CONFIG[:mail_inbox] }
|
||||
res
|
||||
end
|
||||
|
||||
|
||||
def create_mail
|
||||
m = CDF::Mail.new(user.mail_temporary_path)
|
||||
if params["mail"]
|
||||
ma = params["mail"]
|
||||
m.body, m.content_type, m.from, m.to, m.cc, m.bcc, m.subject = ma["body"], ma["content_type"], ma["from"], ma["to"], ma["cc"], ma["bcc"], ma["subject"]
|
||||
if params["att_files"]
|
||||
att_files, att_tfiles, att_ctypes = params["att_files"], params["att_tfiles"], params["att_ctypes"]
|
||||
att_files.each {|i, value|
|
||||
att = CDF::Attachment.new(m)
|
||||
att.filename, att.temp_filename, att.content_type = value, att_tfiles[i], att_ctypes[i]
|
||||
}
|
||||
end
|
||||
else
|
||||
m.from, m.content_type = user.friendlly_local_email, get_mail_prefs.mail_type
|
||||
end
|
||||
m.customer_id = logged_customer
|
||||
m
|
||||
end
|
||||
|
||||
def prepare_mail
|
||||
m = CDF::Mail.new(user.mail_temporary_path)
|
||||
m.from, m.content_type = user.friendlly_local_email, get_mail_prefs.mail_type
|
||||
m
|
||||
end
|
||||
|
||||
|
||||
def send_part(part)
|
||||
if part.content_type == "text/html"
|
||||
disposition = "inline"
|
||||
elsif part.content_type.include?("image/")
|
||||
disposition = "inline"
|
||||
else
|
||||
disposition = "attachment"
|
||||
end
|
||||
headers['Content-Length'] = part.body.size
|
||||
response.headers['Accept-Ranges'] = 'bytes'
|
||||
headers['Content-type'] = part.content_type.strip
|
||||
headers['Content-Disposition'] = disposition << %(; filename="#{part.header['content-type']['name']}")
|
||||
render :text => part.body
|
||||
end
|
||||
|
||||
def get_parts(mail)
|
||||
parts = Array.new
|
||||
parts << mail
|
||||
mail.parts.each { |part|
|
||||
if part.multipart?
|
||||
parts = parts.concat(get_parts(part))
|
||||
elsif part.content_type and part.content_type.include?("rfc822")
|
||||
parts = parts.concat(get_parts(TMail::Mail.parse(part.body))) << part
|
||||
else
|
||||
parts << part
|
||||
end
|
||||
}
|
||||
parts
|
||||
end
|
||||
|
||||
def obtain_cookies_for_search_and_nav
|
||||
@srch_class = ((cookies['_wmlms'] and cookies['_wmlms'] == 'closed') ? 'closed' : 'open')
|
||||
@srch_img_src = ((cookies['_wmlms'] and cookies['_wmlms'] == 'closed') ? 'closed' : 'opened')
|
||||
@ops_class = ((cookies['_wmlmo'] and cookies['_wmlmo'] == 'closed') ? 'closed' : 'open')
|
||||
@ops_img_src = ((cookies['_wmlmo'] and cookies['_wmlmo'] == 'closed') ? 'closed' : 'opened')
|
||||
end
|
||||
|
||||
###################################################################
|
||||
### Some fixed parameters and session variables
|
||||
###################################################################
|
||||
def folder
|
||||
@folders[@folder_name]
|
||||
end
|
||||
|
||||
def msg_id_param
|
||||
params["msg_id"]
|
||||
end
|
||||
|
||||
def messages_param
|
||||
params["messages"]
|
||||
end
|
||||
|
||||
def dst_folder
|
||||
params["cpdest"]
|
||||
end
|
||||
|
||||
def operation_param
|
||||
params["op"]
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue