<?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>
    <v:on-init>
      <![CDATA[
        select U_NAME, WAM_MEMBER_TYPE, WAM_INST into self.nam, self.st, self.wam_inst
        from SYS_USERS, WA_MEMBER, WA_INSTANCE
        where WAM_USER = U_ID and WAM_INST = WAI_NAME and WAI_ID = self.wai_id and U_ID = self.wam_user;
      ]]>
    </v:on-init>
    <vm:header>
      <vm:title>Members Edit Page</vm:title>
    </vm:header>
    <vm:pagewrapper>
      <vm:variable name="nam" type="varchar" default="null" />
      <vm:variable name="wam_inst" type="varchar" default="null" />
      <vm:variable name="st" type="int" default="null" />
      <vm:variable name="wai_id" type="int" default="null" param-name="wai_id"/>
      <vm:variable name="wam_user" type="int" default="null" param-name="m"/>
      <vm:navigation on="settings"/>
      <vm:navigation1 on="members"/>
      <vm:rawheader caption="Edit Member Settings"/>
      <vm:body>
        <vm:login redirect="index.vspx"/>
        <div class="box">
        <v:form type="simple" method="POST" name="embf1">
      <table>
        <tr>
          <td>Member</td><td><b><v:label name="nam1" value="--self.nam" /></b></td>
        </tr>
        <tr>
          <td>Status</td>
          <td>
      <v:select-list name="st1" value="--self.st">
        <v:item value="-1" name="pending" />
        <v:item value="1" name="owner" />
        <v:item value="2" name="admin" />
        <v:item value="3" name="member" />
      </v:select-list>
          </td>
        </tr>
        <tr>
          <td>
      <v:button action="simple" value="Accept" name="emb1">
        <v:on-post><![CDATA[
          if (self.st = 1 and self.st1.ufl_value <> '1')
          signal ('22023', 'Owner of application can\'t be changed');
          if (self.st <> 1 and self.st1.ufl_value = '1')
          signal ('22023', 'Owner of application can\'t be changed');
          if (self.st1.ufl_value in ('-1','2','3'))
          {
          declare inst web_app;
          declare h any;

          select WAI_INST into inst from WA_INSTANCE where WAI_NAME = self.wam_inst;
         {
           declare exit handler for sqlstate '*' {
             self.vc_is_valid := 0;
             declare _use_sys_errors, _sys_error, _error any;
             _sys_error := concat (__SQL_STATE,' ',__SQL_MESSAGE);
             _error := 'Due to a transient problem in the system, your approval could not be
                 processed at the moment. The system administrators have been notified. Please
                 try again later';
             _use_sys_errors := (select top 1 WS_SHOW_SYSTEM_ERRORS from WA_SETTINGS);
             if(_use_sys_errors) {
               self.vc_error_message := _error || ' ' || _sys_error;
             }
             else {
               self.vc_error_message := _error;
             }
             rollback work;
             return;
           };
           update WA_MEMBER set WAM_MEMBER_TYPE = atoi (self.st1.ufl_value) where
           WAM_USER = self.wam_user and WAM_INST = self.wam_inst;
         }

          h := udt_implements_method (inst, 'wa_join_approve');
          if (h)
          call (h) (inst, self.nam);
          }
          ]]>
        </v:on-post>
      </v:button>
          </td>
          <td>
      <v:button action="simple" value="Reject" name="emr1">
        <v:on-post><![CDATA[
          if (self.st = 1)
          signal ('22023', 'Owner of application can\'t be deleted');
           {
             declare exit handler for sqlstate '*' {
               self.vc_is_valid := 0;
               declare _use_sys_errors, _sys_error, _error any;
               _sys_error := concat (__SQL_STATE,' ',__SQL_MESSAGE);
               _error := 'Due to a transient problem in the system, your rejection could not be
                   processed at the moment. The system administrators have been notified. Please
                   try again later';
               _use_sys_errors := (select top 1 WS_SHOW_SYSTEM_ERRORS from WA_SETTINGS);
               if(_use_sys_errors) {
                 self.vc_error_message := _error || ' ' || _sys_error;
               }
               else {
                 self.vc_error_message := _error;
               }
               rollback work;
               return;
             };
             delete from WA_MEMBER where WAM_MEMBER_TYPE = -1 and WAM_USER = self.wam_user
             and WAM_INST = self.wam_inst;
           }
          http_request_status ('HTTP/1.1 302 Found');
          http_header (sprintf ('Location: inst.vspx?sid=%s&realm=%s\r\n', self.sid, self.realm));
          ]]>
        </v:on-post>
      </v:button>
          </td>
        </tr>
      </table>
        </v:form>
        </div>
        <div class="box">
          <vm:home-link name="back">Back</vm:home-link>
        </div>
      </vm:body>
    </vm:pagewrapper>
  </vm:page>
</v:page>
