<?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="saveBusiness_2" 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 IDx any;

      IDx := vector ();
      for (N := 0; N < length (params); N := N + 4)
      {
        if ((params [N] like 'y1_fld_1_%') and (trim (params [N+1]) <> ''))
        {
          suffix := replace (params [N], 'y1_fld_1_', '');
          id := cast (get_keyword ('y1_fld_0_'||suffix, params, '-1') as integer);
          if (id <> -1)
          {
			      update WA_USER_OL_ACCOUNTS
			         set WUO_NAME = trim (params [N+1]),
			             WUO_URL = trim (get_keyword ('y1_fld_2_'||suffix, params, '')),
			             WUO_URI = trim (get_keyword ('y1_fld_3_'||suffix, params, ''))
			       where WUO_ID = id;
            IDx := vector_concat (IDx, vector (id));
          }
        }
      }
	    for (select WUO_ID as _id from WA_USER_OL_ACCOUNTS where WUO_U_ID = self.u_id and WUO_TYPE = 'B') do
	    {
	      for (N := 0; N < length (IDx); N := N + 1)
	      {
	        if (IDx[N] = _id)
	          goto _exit;
	      }
        delete from WA_USER_OL_ACCOUNTS where WUO_ID = _id;
      _exit:;
		  }
      for (N := 0; N < length (params); N := N + 4)
      {
        if ((params [N] like 'y1_fld_1_%') and (trim (params [N+1]) <> ''))
        {
          suffix := replace (params [N], 'y1_fld_1_', '');
          id := cast (get_keyword ('y1_fld_0_'||suffix, params, '-1') as integer);
          if ((id = -1) and (trim (get_keyword ('y1_fld_2_'||suffix, params, '')) <> ''))
          {
			      insert into WA_USER_OL_ACCOUNTS ( WUO_NAME, WUO_URL, WUO_URI, WUO_U_ID, WUO_TYPE)
		          values (trim (params [N+1]), trim (get_keyword ('y1_fld_2_'||suffix, params, '')), trim (get_keyword ('y1_fld_3_'||suffix, params, '')), self.u_id, 'B');
          }
        }
      }

      -- 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:form name="usr_bussiness_2" type="simple" method="POST" action="uiedit.vspx?page=2">
    <input type="hidden" name="c_nick" id="c_nick" value="<?V coalesce ((select WAUI_NICK from WA_USER_INFO where WAUI_U_ID = self.u_id), '') ?>"/>
    <div>
      <table class="ctl_grp">
        <tr>
          <td width="800px">
            <table id="y1_tbl" class="listing">
                <tr class="listing_header_row">
                <th width="30%">
                  Select from Service List or Type New One
                  </th>
                <th width="30%">
                  Member Home Page URI
                  </th>
                <th width="30%">
                  Account URI
                </th>
                <th width="65px">
                    Action
                  </th>
                </tr>
            		  <![CDATA[
            		    <script type="text/javascript">
            		    <?vsp
                  for (select WUO_ID, WUO_NAME, WUO_URL, WUO_URI from WA_USER_OL_ACCOUNTS where WUO_TYPE = 'B' and WUO_U_ID = self.u_id) do
                  {
                    http (sprintf ('ODSInitArray.push(function(){OAT.MSG.attach(OAT, "PAGE_LOADED", function(){TBL.createRow("y1", null, {id: "%d", fld_1: {mode: 10, value: "%s"}, fld_2: {value: "%s", className: "_validate_ _uri_ _canEmpty_"}, fld_3: {value: "%s"}});});});', WUO_ID, WUO_NAME, WUO_URL, WUO_URI));
                  }
            		    ?>
            		    </script>
            		  ]]>
              <tr id="y1_tr_no"><td colspan="3"><b>No Services</b></td></tr>
            </table>
          </td>
          <td valign="top" nowrap="1">
            <span class="button pointer" onclick="TBL.createRow('y1', null, {fld_1: {mode: 10}, fld_2: {className: '_validate_ _uri_ _canEmpty_'}, 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_business_2" 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_business_2" value="Save" action="simple" xhtml_onclick="return validateInputs(this);">
          <v:on-post>
            <![CDATA[
              self.saveBusiness_2();
            ]]>
          </v:on-post>
        </v:button>
        <v:button name="user_sn_business_2" value="Save and Next" action="simple" xhtml_onclick="return validateInputs(this);">
          <v:on-post>
            <![CDATA[
              self.saveBusiness_2();
              if (self.vc_is_valid)
   		          self.vc_redirect ('uiedit.vspx?page=2&tabNo=3');
            ]]>
          </v:on-post>
        </v:button>
      </div>
    </div>
  </v:form>
</v:page>
