<?xml version="1.0"?>
<!--
 -
 -  $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 xmlns:vm="http://www.openlinksw.com/vspx/weblog/"
  	xmlns:v="http://www.openlinksw.com/vspx/"
	name="nntpf_thread_view"
	style="main.xsl"
	on-error-redirect="nntpf_error.vspx"
	on-deadlock-retry="3"
	doctype="-//W3C//DTD XHTML 1.0 Transitional//EN"
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<v:variable name="grp" type="int" default="null" param-name="group" />
	<v:variable name="from_page" type="int" default="1" param-name="grp-page" />
	<v:variable name="mid" type="varchar" default="null" param-name="id" />
	<v:variable name="subj" type="varchar" default="null" />
	<v:on-init><![CDATA[
	    declare subj, mid varchar;
	    if (self.mid is not null)
	      {
	        declare exit handler for not found
		{
		  self.vc_is_valid := 0;
		  self.vc_error_message := 'The group or topic does ot longer exists, please select another.';
		  return;
		};
	        select t.FTHR_SUBJ, t.FTHR_MESS_ID  into subj, mid
	            from NNFE_THR m, NNFE_THR t
		    where m.FTHR_GROUP = self.grp and m.FTHR_MESS_ID = self.mid
		    and t.FTHR_GROUP = self.grp and t.FTHR_MESS_ID = m.FTHR_TOPIC_ID;
		self.mid := mid;
		nntpf_decode_subj (subj);
		self.subj := subj;
	      }
	    ]]></v:on-init>
  <html>
    <head>
      <base href="<?V WA_GET_PROTOCOL() || WA_GET_HOST () || http_path () ?>" />
      <v:include url="virtuoso_app_links.xhtml"/>
      <link rel="stylesheet" type="text/css" href="nntpf.css"/>
      <title>ODS Discussion</title>
    </head>
    <body>
      <vm:js/>
      <vm:page>
	<v:form name="nnv" method="POST" type="simple">
          <vm:nntpf-title/>
          <div class="menu">
            <vm:menu-bar/>
          </div>
          <div id="PC">
            <div id="LT">
              <div class="login">
                <vm:login/>
	      </div>
	      <div class="error"><v:error-summary /></div>
	      <table width="100%"
		  class="news_summary_encapsul"
		  cellspacing="0"
		  border="0"
		  cellpadding="0">
		  <tr>
		      <td>
			  <h2>Please confirm subscription to the
			      "<?V (select NG_NAME from NEWS_GROUPS where NG_GROUP = self.grp) ?>" group<br />
			      <?vsp
			        if (self.mid is not null)
				  {
				    http ('Thread: "'); http (self.subj); http ('"');
				  }
			      ?>
			  </h2>
			  <label>E-mail: </label><v:text value="--self.u_e_mail" name="sub_email" xhtml_size="70" error-glyph="*">
			      <v:validator name="vv_e_mail"
				  test="regexp" regexp="[^@]+@([^\.]+.)*[^\.]+" message="Invalid e-mail address" />
			  </v:text>
			  <br />
			  <v:check-box name="sub_cb" value="1" xhtml_id="sub_cb" />
			  <label for="sub_cb">Send digests</label>
			  <br />
			  <br />
			  <v:button action="simple" name="sub_bt" value="Subscribe">
			      <v:on-post><![CDATA[
				  if (not self.vc_is_valid)
				    return;

				  insert soft NNTPF_SUBS (NS_USER, NS_MAIL, NS_GROUP, NS_THREAD_ID, NS_TYPE, NS_TS)
				  values (coalesce (self.u_id, http_nobody_uid()),
				     self.sub_email.ufl_value, self.grp, coalesce (self.mid, ''),
				    self.sub_cb.ufl_selected, now ());
				  if (row_count () = 0)
				    {
				      self.vc_is_valid := 0;
				      self.vc_error_message := 'Already subscribed.';
				      return;
				    }
				  if (self.from_page = 2)
				    self.vc_redirect (sprintf ('nntpf_thread_view.vspx?group=%d', self.grp));
				  else
				    self.vc_redirect (sprintf ('nntpf_nthread_view.vspx?group=%d', self.grp));
				  ]]></v:on-post>
			  </v:button>
			  <v:button action="simple" name="cancel_bt" value="Cancel">
			      <v:on-post><![CDATA[
				  if (self.from_page = 2)
				    self.vc_redirect (sprintf ('nntpf_thread_view.vspx?group=%d', self.grp));
				  else
				    self.vc_redirect (sprintf ('nntpf_nthread_view.vspx?group=%d', self.grp));
				  ]]></v:on-post>
			  </v:button>
		      </td>
		  </tr>
	      </table>
            </div> <!-- LT -->
            <div id="RT">
              <div class="calctr">
                <div class="calendar">
                  <vm:nntp-cal />
                </div>
              </div>
            </div> <!-- RT -->
          </div> <!-- PC -->
        </v:form>
      </vm:page>
    </body>
  </html>
</v:page>
