<?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="user_edit_buss"
        doctype="-//W3C//DTD XHTML 1.0 Transitional//EN"
        fast-render="1" xmlns:v="http://www.openlinksw.com/vspx/"
        style="index.xsl"
        xmlns:xhtml="http://www.w3.org/1999/xhtml"
        xmlns:vm="http://www.openlinksw.com/vspx/ods/"
        xmlns:v="http://www.openlinksw.com/vspx/">

  <v:method name="savePersonal_5" arglist="">
    <![CDATA[
      declare params any;

      params := self.vc_page.vc_event.ve_params;
      if (self.vc_is_valid = 0)
        return;

      declare N, id integer;
      declare suffix varchar;
      declare IDd any;

      IDd := vector ();
      for (N := 0; N < length (params); N := N + 4)
      {
        if ((params [N] like 'x5_fld_1_%') and (trim (params [N+1]) <> ''))
        {
          suffix := replace (params [N], 'x5_fld_1_', '');
          id := cast (get_keyword ('x5_fld_0_'||suffix, params, '-1') as integer);
          if (id <> -1)
          {
            update WA_USER_BIOEVENTS
               set WUB_EVENT = trim (params [N+1]),
                   WUB_DATE = trim (get_keyword ('x5_fld_2_'||suffix, params, '')),
                   WUB_PLACE = trim (get_keyword ('x5_fld_3_'||suffix, params, ''))
             where WUB_ID = id;
            IDd := vector_concat (IDd, vector (id));
          }
        }
      }

      for (select WUB_ID as _id from WA_USER_BIOEVENTS where WUB_U_ID = self.u_id) do
      {
        for (N := 0; N < length (IDd); N := N + 1)
        {
          if (IDd[N] = _id)
            goto _exit2;
        }
        delete from WA_USER_BIOEVENTS where WUB_ID = _id;
      _exit2:;
      }
      for (N := 0; N < length (params); N := N + 4)
      {
        if ((params [N] like 'x5_fld_1_%') and (trim (params [N+1]) <> ''))
        {
          suffix := replace (params [N], 'x5_fld_1_', '');
          id := cast (get_keyword ('x5_fld_0_'||suffix, params, '-1') as integer);
          if (id = -1)
        {
            insert into WA_USER_BIOEVENTS ( WUB_EVENT, WUB_DATE, WUB_PLACE, WUB_U_ID)
              values (trim (params [N+1]), trim (get_keyword ('x5_fld_2_'||suffix, params, '')), trim (get_keyword ('x5_fld_3_'||suffix, params, '')), self.u_id);
          }
        }
      }

      WA_USER_VISIBILITY (self.u_name, WA_STR_PARAM (params, 'sel_'), 2);

      -- change user_text data
      WA_USER_TEXT_SET (self.u_id, WA_GET_USER_INFO (0, self.u_id, WA_USER_VISIBILITY (self.u_name), 0, 1));
    ]]>
  </v:method>

  <v:before-data-bind>
    <![CDATA[
      declare tmp any;

      if (e.ve_is_post and e.ve_button = self.page_form)
      {
        self.usr_personal_5.vc_focus := 1;
        self.usr_personal_5.vc_set_childs_focus(1, e);
      }
    ]]>
  </v:before-data-bind>

  <v:form name="usr_personal_5" type="simple" method="POST" action="uiedit.vspx?page=2">
    <div>
      <table class="ctl_grp">
        <tr>
          <td width="800px">
            <table id="x5_tbl" class="listing">
              <tr class="listing_header_row">
                <th width="15%">
                  Event
                </th>
                <th width="15%">
                  Date
                </th>
                <th>
                  Place
                </th>
                <th width="65px">
                  Action
                </th>
        </tr>
  		  <![CDATA[
   		    <script type="text/javascript">
              <?vsp
                  for (select WUB_ID, WUB_EVENT, WUB_DATE, WUB_PLACE from WA_USER_BIOEVENTS where WUB_U_ID = self.u_id) do
                {
                    http (sprintf ('ODSInitArray.push(function(){OAT.MSG.attach(OAT, "PAGE_LOADED", function(){TBL.createRow("x5", null, {id: "%d", fld_1: {mode: 11, value: "%s"}, fld_2: {mode: 3, value: "%s"}, fld_3: {value: "%s"}});});});', WUB_ID, WUB_EVENT, WUB_DATE, WUB_PLACE));
                }
              ?>
   		    </script>
     	  ]]>
             <tr id="x5_tr_no"><td colspan="4"><b>No Biographical Events</b></td></tr>
            </table>
          </td>
          <td valign="top" nowrap="1">
            <span class="button pointer" onclick="TBL.createRow('x5', null, {fld_1: {mode: 11}, fld_2: {mode: 3}, fld_3: {}});"><img class="button" src="/ods/images/icons/add_16.png" border="0" alt="Add Row" title="Add Row" /> Add</span>
          </td>
        </tr>
      </table>
      <br />
      <div>
        <v:button name="user_c_personal_5" value="Cancel" action="simple" xhtml_onclick="javascript: return initLoadProfile();">
          <v:on-post>
            self.vc_redirect (sprintf ('uhome.vspx?ufname=%U&amp;l=1', self.u_name));
          </v:on-post>
        </v:button>
        <v:button name="user_s_personal_5" value="Save" action="simple" xhtml_onclick="return validateInputs(this);">
          <v:on-post>
            <![CDATA[
              self.savePersonal_5();
            ]]>
          </v:on-post>
        </v:button>
        <v:button name="user_sn_personal_5" value="Save and Next" action="simple" xhtml_onclick="return validateInputs(this);">
          <v:on-post>
            <![CDATA[
              self.savePersonal_5();
              if (self.vc_is_valid)
   		          self.vc_redirect ('uiedit.vspx?page=1&tabNo=6');
            ]]>
          </v:on-post>
        </v:button>
      </div>
    </div>
  </v:form>
</v:page>
