<?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">
  <v:before-data-bind>
    <![CDATA[
	    declare exit handler for not found { goto _end; };

      if (isnull(get_keyword ('f_rows', self.vc_page.vc_event.ve_params)))
      {
        self.v_conversation := ENEWS.WA.settings(self.domain_id, -1);
  			return;
  		}

		_end:
		  if (isnull(self.v_conversation))
        self.v_conversation := vector();
      return;
    ]]>
  </v:before-data-bind>
  <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: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_rows" value="Rows per page"/>
                </th>
                <td>
                  <v:text name="f_rows" value="--get_keyword ('rows', self.settings, '10')" xhtml_class="field-text"/>
                </td>
              </tr>
              <tr>
                <th />
                <td>
                  <label>
                  <v:check-box name="f_favourites" xhtml_id="f_favourites" is-boolean="1" true-value="1" false-value="0" value="--cast(get_keyword ('favourites', self.settings, '0') as integer)"  xhtml_title="Show Favourites" />
                    show Favourites
                  </label>
                </td>
              </tr>
              <tr>
                <th />
                <td>
                  <label>
                  <v:check-box name="f_feedIcons" xhtml_id="f_feedIcons" is-boolean="1" true-value="1" false-value="0" value="--cast(get_keyword ('feedIcons', self.settings, '1') as integer)"  xhtml_title="Show Feed Icons" />
                    show Feed's Image
                  </label>
                </td>
              </tr>
              <tr>
                <th rowspan="2" valign="top">
                  <v:label value="Auto-refresh at login"/>
                </th>
                <td>
                  <label>
                  <v:check-box name="f_updateFeeds" xhtml_id="f_updateFeeds" is-boolean="1" true-value="1" false-value="0" value="--cast(get_keyword('updateFeeds', self.settings, '0') as integer)" xhtml_title="Auto-refresh feeds at login" />
                    for feeds
                  </label>
                </td>
              </tr>
              <tr>
                <td>
                  <label>
                  <v:check-box name="f_updateBlogs" xhtml_id="f_updateBlogs" is-boolean="1" true-value="1" false-value="0" value="--cast(get_keyword('updateBlogs', self.settings, '0') as integer)"  xhtml_title="Auto-refresh blogs at login" />
                    for blogs
                  </label>
                </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 (ENEWS.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 ENEWS.WA.discussion_check ())
          				    S := 'disabled="disabled"';
                    T := '';
          				  if (cast(get_keyword ('conv', self.v_conversation, '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 ENEWS.WA.discussion_check ())
          				    S := 'disabled="disabled"';
                    T := '';
          				  if (cast(get_keyword ('conv_init', self.v_conversation, '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 conv, f_conv, f_conv_init, tmp, params any;

              params := self.vc_page.vc_event.ve_params;
              tmp := trim(self.f_rows.ufl_value);
              if (not ENEWS.WA.validate('integer', tmp) or (cast(tmp as integer) < 5) or (cast(tmp as integer) > 1000))
              {
                self.vc_error_message := 'The parameter ''Rows per page'' must be integer in range [5, 1000].';
             		self.vc_is_valid := 0;
          		  return;
              }
              tmp := cast(tmp as varchar);
              self.settings := ENEWS.WA.set_keyword ('favourites', self.settings, self.f_favourites.ufl_selected);
              self.settings := ENEWS.WA.set_keyword('rows', self.settings, tmp);
              self.settings := ENEWS.WA.set_keyword('updateFeeds', self.settings, self.f_updateFeeds.ufl_selected);
              self.settings := ENEWS.WA.set_keyword('updateBlogs', self.settings, self.f_updateBlogs.ufl_selected);
              self.settings := ENEWS.WA.set_keyword('feedIcons', self.settings, self.f_feedIcons.ufl_selected);
              self.settings := ENEWS.WA.set_keyword('atomVersion', self.settings, self.f_atomVersion.ufl_value);

              conv := cast(get_keyword('conv', self.v_conversation, '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.v_conversation := ENEWS.WA.set_keyword ('conv', self.v_conversation, f_conv);
              self.v_conversation := ENEWS.WA.set_keyword ('conv_init', self.v_conversation, f_conv_init);

              insert replacing ENEWS.WA.SETTINGS(ES_DOMAIN_ID, ES_ACCOUNT_ID, ES_DATA) values(self.domain_id, self.account_id, serialize(self.settings));
              insert replacing ENEWS.WA.SETTINGS(ES_DOMAIN_ID, ES_ACCOUNT_ID, ES_DATA) values(self.domain_id, -1, serialize(self.v_conversation));
              commit work;

              ENEWS.WA.domain_gems_create(self.domain_id, self.account_id);
          		if (ENEWS.WA.discussion_check ())
          		{
    					  ENEWS.WA.nntp_update (self.domain_id, null, null, conv, f_conv);
         				if (f_conv and f_conv_init)
  					    ENEWS.WA.nntp_fill (self.domain_id);
    					}
              self.vc_redirect (ENEWS.WA.utf2wide (ENEWS.WA.page_url (self.domain_id, 'news.vspx')));
      	    ]]>
      	  </v:on-post>
        </v:button>
        <v:button name="clear" 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 ENEWS.WA.SETTINGS where ES_DOMAIN_ID = self.domain_id;
              ENEWS.WA.nntp_update (self.domain_id, null, null, 1, 0);
              commit work;

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