<%# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011    Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012    Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-15 Karel Picman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.%>

<p>
  <%= content_tag(:label, l(:label_maximum_files_upload)) %>
  <%= text_field_tag 'settings[dmsf_max_file_upload]', @settings['dmsf_max_file_upload'], :size => 10 %>
  <em class="info">
    <%= l(:note_maximum_number_of_files_uploaded) %> <%= l(:label_default) %>: 0    
  </em>
</p>

<p>
  <%= content_tag(:label, l(:label_maximum_files_download)) %>
  <%= text_field_tag 'settings[dmsf_max_file_download]', @settings['dmsf_max_file_download'], :size => 10 %>
  <em class="info">
    <%= l(:note_maximum_number_of_files_downloaded) %> <%= l(:label_default) %>: 0
  </em>
</p>

<p>
  <%= content_tag(:label, l(:label_maximum_email_filesize)) %>
  <%= text_field_tag 'settings[dmsf_max_email_filesize]', @settings['dmsf_max_email_filesize'], :size => 10 %>
  <em class="info">
    <%= l(:note_maximum_email_filesize) %> <%= l(:label_default) %>: 0  
  </em>
</p>

<p>
  <%= content_tag(:label, l(:label_maximum_ajax_upload_filesize)) %>  
  <%= text_field_tag 'settings[dmsf_max_ajax_upload_filesize]', @settings['dmsf_max_ajax_upload_filesize'], :size => 10 %>
  <em class="info">
    <%= l(:note_maximum_ajax_upload_filesize) %> <%= l(:label_default) %>: 100
  </em>
</p>

<p>
  <%=  content_tag(:label, l(:label_file_storage_directory)) %>
  <% 
    storage_dir = @settings['dmsf_storage_directory'].strip if @settings['dmsf_storage_directory'].present?
    storage_dir = "#{Rails.root}/files/dmsf" if storage_dir.blank?
  %>
  <%= text_field_tag 'settings[dmsf_storage_directory]', storage_dir, :size => 50 %>
  <em class="info">
    <%= l(:label_default) %>: <%= "#{Rails.root}/files/dmsf" %>
  </em>
</p>
<% unless File.exist?(storage_dir) %>
  <% begin %>
     <% Dir.mkdir(storage_dir) %>
  <% rescue %>
    <p class="warning"><%= l(:error_file_storage_directory_does_not_exist) %></p> 
  <% end %>
<% end %>
<% testfilename = "#{storage_dir}/test.test" %>
<% if File.exist?(storage_dir) %>
  <%	begin %>
    <% File.open(testfilename, 'wb') do |file| %>
    <% end %>
  <% rescue %>
    <p class="warning"><%= l(:error_file_can_not_be_created) %></p>
  <%	ensure %>
    <% File.delete(testfilename) if File.exist?(testfilename) %>
  <% end %>
<% end %>

<p>
  <%= content_tag(:label, l(:label_physical_file_delete)) %>
  <%= check_box_tag('settings[dmsf_really_delete_files]', true, @settings['dmsf_really_delete_files']) %>
  <em class="info">
    <%= l(:label_default)%>: <%= l(:general_text_No)%>
  </em>
</p>

<p>
  <%= content_tag(:label, l(:label_default_notifications)) %>
  <%= select_tag('settings[dmsf_default_notifications]', 
    options_for_select([
                    [l(:select_option_deactivated), nil], 
                    [l(:select_option_activated), '1']], 
                    :selected => @settings['dmsf_default_notifications'])) %>
  <em class="info">
    <%= l(:label_default) %>: <%= l(:select_option_deactivated) %>
  </em>
</p>

<p>
  <%= content_tag(:label, l(:label_display_notified_recipients)) %>
  <%= select_tag('settings[dmsf_display_notified_recipients]',
    options_for_select([
      [l(:select_option_deactivated), nil],
      [l(:select_option_activated), '1']],
      :selected => @settings['dmsf_display_notified_recipients'])) %>
  <em class="info">
    <%= l(:note_display_notified_recipients).html_safe %> <%= l(:label_default) %>: <%= l(:select_option_deactivated) %>
  </em>
</p>

<p>
  <%= content_tag(:label, l(:label_title_format)) %>  
  <%= text_field_tag 'settings[dmsf_global_title_format]', @settings['dmsf_global_title_format'], :size => 10 %>
  <em class="info">
    <%= l(:text_title_format) %> <%= l(:label_default) %>: %t_%v
  </em>
</p>

<hr/>

<p>
  <%= content_tag(:label, l(:label_webdav)) %>
  <%= select_tag('settings[dmsf_webdav]',
    options_for_select([
      [l(:select_option_deactivated), nil],
      [l(:select_option_activated), '1']],
      :selected => @settings['dmsf_webdav'])) %>
  <em class="info">
    <%= l(:note_webdav, :protocol => Setting.protocol, :domain => Setting.host_name).html_safe %> <%= l(:label_default) %>: <%= l(:select_option_activated) %>
  </em>  
</p>

<% if @settings['dmsf_webdav'].nil? || !@settings['dmsf_webdav'].empty? %>
  <p>
    <%= content_tag(:label, l(:label_webdav_strategy)) %>
    <%= select_tag('settings[dmsf_webdav_strategy]',
      options_for_select([
        [l(:select_option_webdav_readonly), 'WEBDAV_READ_ONLY'],
        [l(:select_option_webdav_readwrite), 'WEBDAV_READ_WRITE']],
        :selected => @settings['dmsf_webdav_strategy'])) %><br/>
    <em class="info">
      <%= l(:note_webdav_strategy).html_safe %> <%= l(:label_default) %>: <%= l(:select_option_webdav_readonly) %>    
    </em>
  </p>
<% end %>

<hr/>

<% begin %>
  <% require 'xapian' %>
  <% xapian_disabled = false %>
<% rescue LoadError %>
  <p class="warning"><%= l(:warning_xapian_not_available) %></p> 
  <% xapian_disabled = true %>
<% end %>

<p>
  <%= content_tag(:label, l(:label_index_database)) %>
  <%= text_field_tag 'settings[dmsf_index_database]', @settings['dmsf_index_database'], :disabled => xapian_disabled, :size => 50 %>
  <em class="info">
    <%= l(:label_default) %>: <%= "#{Rails.root}/files/dmsf_index" %>
  </em>
</p>

<% stem_langs = %w(danish dutch english finnish french german hungarian italian norwegian portuguese romanian russian spanish swedish turkish) %>

<p>  
  <%= content_tag(:label, l(:label_stemming_language)) %>
  <%= select_tag('settings[dmsf_stemming_lang]', options_for_select(stem_langs, @settings['dmsf_stemming_lang']))%>
  <em class="info">
    <%= l(:note_possible_values) %>: <%= stem_langs.join(', ') %>. <%= "#{l(:label_default)}: #{stem_langs[2]}" %>
  </em>
</p>

<p>
  <%= content_tag(:label, l(:label_stem_strategy)) %>
  <%= radio_button_tag 'settings[dmsf_stemming_strategy]', 'STEM_NONE', @settings['dmsf_stemming_strategy'] == 'STEM_NONE', :disabled => xapian_disabled, :checked => true  %> <%= l(:option_stem_none) %><br/>
  <%= radio_button_tag 'settings[dmsf_stemming_strategy]', 'STEM_SOME', @settings['dmsf_stemming_strategy'] == 'STEM_SOME', :disabled => xapian_disabled  %> <%= l(:option_stem_some) %><br/>
  <%= radio_button_tag 'settings[dmsf_stemming_strategy]', 'STEM_ALL', @settings['dmsf_stemming_strategy'] == 'STEM_ALL', :disabled => xapian_disabled  %> <%= l(:option_stem_all) %><br/>
  <em class="info">
    <%= l(:label_stemming_description) %>:<br/>    
    &nbsp;&nbsp;STEM_NONE: <%= l(:note_do_not_stem) %><br/>
    &nbsp;&nbsp;STEM_SOME: <%= l(:note_stem_some) %><br/>
    &nbsp;&nbsp;STEM_ALL: <%= l(:note_stem_all) %><br/>    
    <%= l(:note_stemming_applied) %>
  </em>
</p>
