<?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 name="blog-home-page" xmlns:vm="http://www.openlinksw.com/vspx/ods/" xmlns:v="http://www.openlinksw.com/vspx/" style="index.xsl"
    doctype="-//W3C//DTD XHTML 1.0 Transitional//EN"  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <vm:page>
    <vm:header>
      <vm:title>Received Invitations</vm:title>
    </vm:header>
    <vm:pagewrapper>
      <vm:variable name="conn_num" type="int" default="0" />
      <vm:variable name="sne_id" type="int" default="0" />
      <!--<vm:navigation on="home"/>
      <vm:navigation1 on="sn"/>-->
      <vm:navigation-new on="home"/>
      <vm:navigation2 on="sn_rec_inv"/>
      <vm:rawheader caption="Received Invitations"/>
      <vm:body>
      <script type="text/javascript">
  <![CDATA[
function selectAllCheckboxes (form, btn, txt)
{
  var i;
  for (i =0; i < form.elements.length; i++)
    {
      var contr = form.elements[i];
      if (contr != null && contr.type == "checkbox" && contr.name.indexOf (txt) != -1)
        {
    contr.focus();
    if (btn.value == 'Select All')
      contr.checked = true;
    else
            contr.checked = false;
  }
    }
  if (btn.value == 'Select All')
    btn.value = 'Unselect All';
  else
    btn.value = 'Select All';
  btn.focus();
}


]]>
</script>
        <vm:login redirect="login.vspx"/>
        <div id="container">
          <div>
	      <v:local-variable name="lv1">
		<v:after-data-bind>


		  whenever not found goto nf;
		  select sne_id into self.sne_id from sn_entity where sne_name = self.u_name;
		  select count(*) into self.conn_num from sn_invitation where sni_to = self.u_e_mail and sni_status = 0;
		  nf:;

		</v:after-data-bind>
	      </v:local-variable>
	      <p>You have <v:label name="lnc1" value="--self.conn_num" format="%d"/> unprocessed invitation(s)</p>
	      <table class="listing">
		  <tr class="listing_header_row">
		    <th>
			<input type="checkbox" value="Unselect All" onclick="selectAllCheckboxes(this.form, this, 'cb1')" checked="1"/>
		      From
		    </th>
		      <th>Name</th>
		  </tr>
	    <v:data-set
		name="ds_conn"
		sql="select sne_name, sne_id from sn_invitation, sn_entity where
			sni_from = sne_id and sni_to = :mail and sni_status = 0"
		nrows="1000"
		cursor-type="dynamic"
		scrollable="1"
		editable="1"
		>
		<v:param name="mail" value="--self.u_e_mail"/>
		<v:template type="repeat" name="ds_conn_rep">
		    <v:template name="ds_conn_no" type="if-not-exists">
			<tr><td colspan="2">No invitation(s) available</td></tr>
		    </v:template>
		    <v:template type="browse" name="ds_conn_brows">
			<tr class="<?V case when mod(control.te_ctr, 2) = 0 then 'listing_row_odd' else 'listing_row_even' end ?>">
			  <td>
			    <v:check-box name="cb1" group-name="cb1" value="--(control.vc_parent as vspx_row_template).te_rowset[1]" initial-checked="1"/>
			    <v:label name="l1" value="--(control.vc_parent as vspx_row_template).te_rowset[0]" />
			    </td>
			    <td>
			    <v:label name="l2" value="--coalesce (USER_GET_OPTION((control.vc_parent as vspx_row_template).te_rowset[0], 'FULL_NAME'), '')" />
			    </td>
			</tr>
		    </v:template>
		  </v:template>
		  <v:template name="ds_foot" type="simple" enabled="--(control.vc_parent as vspx_data_set).ds_rows_fetched">
		    <tr>
		      <td colspan="2">
			<span class="fm_ctl_btn">
			<v:button name="bt_conf1" value="Accept Invitations" action="simple" >
			  <v:on-post><![CDATA[
			    declare inx, sne_id int;
			    declare ent any;
			    while ((ent := adm_next_keyword ('cb1', e.ve_params, inx)) <> 0)
			      {
			        insert soft sn_related (snr_from, snr_to, snr_since, snr_serial, snr_source)
					values (ent, self.sne_id, now(), 0,1);
			        delete from sn_invitation where
			           sni_from = ent and sni_to = self.u_e_mail;
			      }
			    if (exists (select 1 from sn_invitation where sni_to = self.u_e_mail and sni_status <> -1))
			      self.ds_conn.vc_data_bind (e);
			    else
			      self.vc_redirect ('sn_connections.vspx');
			    ]]></v:on-post>
			</v:button>
			<v:button name="bt_conf2" value="Reject Invitations" action="simple" >
			  <v:on-post><![CDATA[
			    declare inx, sne_id int;
			    declare ent any;
			    while ((ent := adm_next_keyword ('cb1', e.ve_params, inx)) <> 0)
			      {
			        update sn_invitation set sni_status = -1 where
			           sni_from = ent and sni_to = self.u_e_mail;
			      }
			    if (exists (select 1 from sn_invitation where sni_to = self.u_e_mail and sni_status <> -1))
			      self.ds_conn.vc_data_bind (e);
			    else
			      self.vc_redirect ('sn_connections.vspx');
			    ]]></v:on-post>
			</v:button>
		      </span>
		      </td>
		    </tr>
		  </v:template>
		</v:data-set>
		<v:template name="tmpl_cancl" type="simple" enabled="--equ (self.ds_conn.ds_rows_fetched, 0)">
		  <tr>
		    <td colspan="2">
		      <span class="fm_ctl_btn">
		      <v:button name="bt_conf3" value="Back" action="simple">
			  <v:on-post><![CDATA[
			      self.vc_redirect ('sn_connections.vspx');
			    ]]></v:on-post>
		      </v:button>
		    </span>
		    </td>
		  </tr>
		</v:template>
	      </table>
          </div>
        </div>
      </vm:body>
    </vm:pagewrapper>
  </vm:page>
</v:page>
