<?xml version="1.0" encoding="UTF-8"?>
<!--
 -
  -  $Id$
 -
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -
 -  Copyright (C) 1998-2018 OpenLink Software
 -
 -  This project 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; only version 2 of the License, dated June 1991.
 -
 -  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 St, Fifth Floor, Boston, MA 02110-1301 USA
 -
-->
<v:page name="preferences" decor="template/template.vspx" style="template/template.xsl" fast-render="1" xmlns:v="http://www.openlinksw.com/vspx/" xmlns:vm="http://www.openlinksw.com/vspx/macro" doctype="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <vm:pagetitle>Preferences</vm:pagetitle>
  <vm:pagewrapper>
    <vm:header/>
    <vm:variables>
      <v:variable name="v_conversation" persist="0" type="varchar" default="null"/>
      <v:variable name="v_tabNo" param-name="tabNo" type="varchar" default="1"/>
    </vm:variables>
    <vm:pagebody>
      <v:before-render>
        <![CDATA[
          self.F1.uf_action := POLLS.WA.utf2wide (POLLS.WA.page_url (self.domain_id, 'settings.vspx'));
        ]]>
      </v:before-render>
      <v:text name="tabNo" xhtml_id="tabNo" type="hidden" value="--self.v_tabNo"/>
      <div class="form-header">
        Preferences
      </div>
      <div id="p" class="c1">
        <div class="tabs">
          &nbsp;<vm:tabCaption tab="p" tabsCount="2" tabNo="0" caption="Main" />
          &nbsp;<vm:tabCaption tab="p" tabsCount="2" tabNo="1" caption="Discussion" />
        </div>
        <div class="contents">
          <div id="p_content_0" class="tabContent">
        <table class="form-body" cellspacing="0">
          <tr>
            <th width="30%">
              <v:label for="f_chars" value="Polls name display"/>
            </th>
            <td>
              <?vsp
                declare S varchar;

                S := '';
                if (cast(get_keyword('chars', self.settings, '0') as integer) = 0)
                  S := 'checked="checked"';
                http(sprintf('<input type="radio" name="r_chars" id="r_chars_0" value="0" %s />', S));
              ?>
              <xsl:call-template name="nbsp"/><vm:label for="r_chars_0" value="--'show everything'" />
            </td>
          </tr>
          <tr>
            <th />
            <td>
              <?vsp
                declare S varchar;

                S := '';
                if (cast(get_keyword('chars', self.settings, '0') as integer) <> 0)
                  S := 'checked="checked"';
                http(sprintf('<input type="radio" name="r_chars" id="r_chars_1" value="1" %s />', S));
              ?>
              <xsl:call-template name="nbsp"/><vm:label for="r_chars_1" value="--'show no more than'" /><xsl:call-template name="nbsp"/>
              <v:text name="f_chars" null-value="--''" value="--get_keyword('chars', self.settings, '60')" xhtml_size="3"/>
              <xsl:call-template name="nbsp"/><vm:label for="r_chars_1" value="--'characters'" /><xsl:call-template name="nbsp"/>
            </td>
          </tr>
          <tr>
            <th/>
            <td>
              <v:check-box name="f_tbLabels" xhtml_id="f_tbLabels" is-boolean="1" true-value="1" false-value="0" value="--cast(get_keyword('tbLabels', self.settings, '1') as integer)" />
              <vm:label for="f_tbLabels" value="Show toolbar labels"/>
            </td>
          </tr>
          <tr>
            <th>
              <v:label for="f_rows" value="Rows per page"/>
            </th>
            <td>
              <v:text name="f_rows" value="--get_keyword('rows', self.settings, '10')" xhtml_size="3"/>
            </td>
          </tr>
          <tr>
            <th>
              Atom File Version
            </th>
            <td>
              <v:select-list name="f_atomVersion">
                <v:item value="0.3" name="0.3"/>
                <v:item value="1.0" name="1.0"/>
                <v:before-data-bind>
                  <![CDATA[
                    control.ufl_value := get_keyword('atomVersion', self.settings, '1.0');
                  ]]>
                </v:before-data-bind>
              </v:select-list>
            </td>
          </tr>
        </table>
      </div>
          <div id="p_content_1" class="tabContent" style="display: none;">
            <table class="form-body" cellspacing="0">
              <v:template type="simple" enabled="--either (equ (POLLS.WA.discussion_check (), 1), 0, 1)">
                <tr>
                  <td class="error_text" colspan="2">
                    <b>The Discussion feature is disabled. You need to install the ODS Discussion package in order to use it.</b>
                  </td>
                </tr>
              </v:template>
              <tr>
                <th width="30%">&nbsp;</th>
                <td>
                  <?vsp
                    declare S, T varchar;

                    S := '';
          				  if (not POLLS.WA.discussion_check ())
          				    S := 'disabled="disabled"';
                    T := '';
          				  if (cast(get_keyword ('conv', self.settings, '0') as integer) = 1)
          				    T := 'checked';
                    http (sprintf ('<input type="checkbox" name="f_conv" value="1" %s %s />', T, S));
                  ?>
          				<vm:label for="f_conv" value="Enable discussions on this instance" />
                </td>
              </tr>
              <tr>
                <th width="30%">&nbsp;</th>
                <td>
                  <?vsp
                    declare S, T varchar;

                    S := '';
          				  if (not POLLS.WA.discussion_check ())
          				    S := 'disabled="disabled"';
                    T := '';
          				  if (cast(get_keyword ('conv_init', self.settings, '0') as integer) = 1)
          				    T := 'checked';
                    http (sprintf ('<input type="checkbox" name="f_conv_init" value="1" %s %s />', T, S));
                  ?>
          				<vm:label for="f_conv_init" value="Initialize the news group with existing posts" />
                </td>
              </tr>
            </table>
          </div>
        </div>
      </div>
      <div class="form-footer">
        <v:button action="simple" value="Save" xhtml_class="form-button">
          <v:on-post>
            <![CDATA[
              declare rows, chars any;
              declare conv, f_conv, f_conv_init, params any;

              params := self.vc_page.vc_event.ve_params;

              declare exit handler for SQLSTATE '*'
              {
                if (__SQL_STATE = 'TEST')
                {
                  self.vc_error_message := POLLS.WA.test_clear(__SQL_MESSAGE);
                  self.vc_is_valid := 0;
                  return;
                }
                resignal;
              };

              rows := trim(self.f_rows.ufl_value);
              chars := trim(self.f_chars.ufl_value);
              if (get_keyword ('r_chars', params, '-1') = '0')
                chars := '0';

              POLLS.WA.test(rows, vector('name', 'Rows per page', 'class', 'integer', 'type', 'integer', 'minValue', 5, 'maxValue', 1000));
              POLLS.WA.test(chars, vector('name', 'Max name length', 'class', 'integer', 'type', 'integer', 'minValue', 0, 'maxValue', 1000));

              conv := cast (get_keyword ('conv', self.settings, '0') as integer);
              f_conv := cast (get_keyword ('f_conv', params, '0') as integer);
              f_conv_init := cast (get_keyword ('f_conv_init', params, '0') as integer);

              self.settings := POLLS.WA.set_keyword('chars', self.settings, cast(cast(chars as integer) as varchar));
              self.settings := POLLS.WA.set_keyword('rows', self.settings, cast(cast(rows as integer) as varchar));
              self.settings := POLLS.WA.set_keyword('tbLabels', self.settings, self.f_tbLabels.ufl_selected);
              self.settings := POLLS.WA.set_keyword('atomVersion', self.settings, self.f_atomVersion.ufl_value);
              self.settings := POLLS.WA.set_keyword ('conv', self.settings, f_conv);
              self.settings := POLLS.WA.set_keyword ('conv_init', self.settings, f_conv_init);

              insert replacing POLLS.WA.SETTINGS (S_DOMAIN_ID, S_ACCOUNT_ID, S_DATA) values (self.domain_id, self.account_id, serialize(self.settings));
              commit work;

              POLLS.WA.domain_gems_create(self.domain_id, self.account_id);

          		if (POLLS.WA.discussion_check ())
          		{
    					  POLLS.WA.nntp_update (self.domain_id, null, null, conv, f_conv);
         				if (f_conv and f_conv_init)
    					    POLLS.WA.nntp_fill (self.domain_id);
    					}

              self.vc_redirect (POLLS.WA.utf2wide (POLLS.WA.page_url (self.domain_id)));
            ]]>
          </v:on-post>
        </v:button>
        <v:button action="simple" value="Clear"  xhtml_onclick="javascript: return confirm (\'Do you want to reset settings to default?\');" xhtml_class="form-button">
          <v:on-post>
            <![CDATA[
              delete from POLLS.WA.SETTINGS where S_DOMAIN_ID = self.domain_id;

              self.vc_redirect (POLLS.WA.utf2wide (POLLS.WA.page_url (self.domain_id, 'settings.vspx')));
            ]]>
          </v:on-post>
        </v:button>
        <v:button action="simple" value="Cancel" xhtml_class="form-button">
          <v:on-post>
            <![CDATA[
              self.vc_redirect (POLLS.WA.utf2wide (POLLS.WA.page_url (self.domain_id)));
            ]]>
          </v:on-post>
        </v:button>
      </div>
    </vm:pagebody>
  </vm:pagewrapper>
</v:page>
