<?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_2" arglist="">
    <![CDATA[
      declare params any;

      params := self.vc_page.vc_event.ve_params;
      if (self.vc_is_valid = 0)
        return;
      self.hstate := get_keyword ('h_state', params);

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

      WA_USER_EDIT (self.u_name, 'WAUI_HADDRESS1', self.h_address1.ufl_value);
      WA_USER_EDIT (self.u_name, 'WAUI_HADDRESS2', self.h_address2.ufl_value);
      WA_USER_EDIT (self.u_name, 'WAUI_HCODE', self.h_code.ufl_value);
      WA_USER_EDIT (self.u_name, 'WAUI_HCITY', self.h_city.ufl_value);
      WA_USER_EDIT (self.u_name, 'WAUI_HSTATE', self.hstate);
      WA_USER_EDIT (self.u_name, 'WAUI_HCOUNTRY', self.h_country.ufl_value);
      WA_USER_EDIT (self.u_name, 'WAUI_HTZONE', self.h_tzone.ufl_value);
      WA_USER_EDIT (self.u_name, 'WAUI_HPHONE', self.h_phone.ufl_value);
      WA_USER_EDIT (self.u_name, 'WAUI_HPHONE_EXT', self.h_phone_ext.ufl_value);
      WA_USER_EDIT (self.u_name, 'WAUI_HMOBILE', self.h_mobile.ufl_value);

      -- 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:variable persist="0" name="haddress1" type="varchar" default="''"/>
  <v:variable persist="0" name="haddress2" type="varchar" default="''"/>
  <v:variable persist="0" name="hcode" type="varchar" default="''"/>
  <v:variable persist="0" name="hcity" type="varchar" default="''"/>
  <v:variable persist="0" name="hstate" type="varchar" default="''"/>
  <v:variable persist="0" name="hcountry" type="varchar" default="''"/>
  <v:variable persist="0" name="htzone" type="varchar" default="''"/>
  <v:variable persist="0" name="hphone" type="varchar" default="''"/>
  <v:variable persist="0" name="hphone_ext" type="varchar" default="''"/>
  <v:variable persist="0" name="hmobile" type="varchar" default="''"/>
  <v:variable persist="0" name="lat" type="real" default="0.00"/>
  <v:variable persist="0" name="lng" type="real" default="0.00"/>
  <v:variable persist="0" name="hlatlng_def" type="int" default="1"/>

  <v:variable name="sav15" type="varchar" default="'1'" />
  <v:variable name="sav57" type="varchar" default="'1'" />
  <v:variable name="sav58" type="varchar" default="'1'" />
  <v:variable name="sav59" type="varchar" default="'1'" />
  <v:variable name="sav16" type="varchar" default="'1'" />
  <v:variable name="sav17" type="varchar" default="'1'" />
  <v:variable name="sav18" type="varchar" default="'1'" />
  <v:variable name="sav39" type="varchar" default="'1'" />

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

      select wa_utf8_to_wide (WAUI_HADDRESS1),
             wa_utf8_to_wide (WAUI_HADDRESS2),
             WAUI_HCODE,
             wa_utf8_to_wide (WAUI_HCITY),
             wa_utf8_to_wide (WAUI_HSTATE),
             WAUI_HCOUNTRY,
             WAUI_HTZONE,
             WAUI_HPHONE,
             WAUI_HPHONE_EXT,
             WAUI_HMOBILE,
             WAUI_LAT,
             WAUI_LNG,
             WAUI_LATLNG_HBDEF
        INTO self.haddress1,
             self.haddress2,
             self.hcode,
             self.hcity,
             self.hstate,
             self.hcountry,
             self.htzone,
             self.hphone,
             self.hphone_ext,
             self.hmobile,
             self.lat,
             self.lng,
             self.hlatlng_def
        FROM WA_USER_INFO,
             DB.DBA.SYS_USERS
       where WAUI_U_ID = U_ID
         and U_NAME = self.u_name;

      declare tmp any;

      tmp := WA_USER_VISIBILITY(self.u_name);
      if (tmp is not null and length (tmp) >= 70 )
      {
        self.sav15 := tmp[15];
        self.sav57 := tmp[57];
        self.sav58 := tmp[58];
        self.sav59 := tmp[59];
        self.sav16 := tmp[16];
        self.sav17 := tmp[17];
        self.sav18 := tmp[18];
        self.sav39 := tmp[39];
      }
      if (e.ve_is_post and e.ve_button = self.page_form)
      {
        self.usr_personal_2.vc_focus := 1;
        self.usr_personal_2.vc_set_childs_focus(1, e);
      }
    ]]>
  </v:before-data-bind>

  <v:form name="usr_personal_2" type="simple" method="POST" action="uiedit.vspx?page=2">
    <div>
      <table class="ctl_grp">
        <tr>
          <th><label for="h_country">Country</label></th>
          <td class="listing_col" nowrap="1">
            <v:data-list name="h_country"
                         xhtml_id="h_country"
                         value="--self.hcountry"
                         sql="select 'Not Specified' as WC_NAME from WA_COUNTRY union select WC_NAME from WA_COUNTRY" key-column="WC_NAME" value-column="WC_NAME"
                         xhtml_onchange="javascript: updateState(\'h_country\', \'h_state\');"
                         xhtml_style="width:220px"/>
            <vm:u-prop-select name="sel_16" value="self.sav16" />
          </td>
        </tr>
        <tr>
          <th>
            <label for="h_state">State/Province</label>
          </th>
          <td class="listing_col" nowrap="1">
            <span id="span_h_state">
              <![CDATA[
                <script type="text/javascript">
                  function categoryCombo ()
                  {
                    var cc = createState("h_state", "<?V self.hstate ?>");
                    cc.addOption("");
                    <?vsp
                      for (select * from WA_PROVINCE where WP_COUNTRY = self.h_country.ufl_value) do
                        http (sprintf ('cc.addOption("%s");', WP_PROVINCE));
                    ?>
                  }
                  ODSInitArray.push ( function () { OAT.Loader.load(["combolist"], categoryCombo); } );
                </script>
              ]]>
            </span>
            <vm:u-prop-select name="sel_59" value="self.sav59" />
          </td>
        </tr>
        <tr>
          <th><label for="h_city">City/Town</label></th>
          <td class="listing_col" nowrap="1">
            <v:text name="h_city"
                    value="--self.hcity"
                    xhtml_onchange="javascript: updateGeodata(\'h\');"
                    xhtml_style="width:216px"/>
            <vm:u-prop-select name="sel_58" value="self.sav58" />
          </td>
        </tr>
        <tr>
          <th><label for="h_code">Zip/Postal Code</label></th>
          <td class="listing_col" nowrap="1">
            <v:text name="h_code"
                    value="--self.hcode"
                    xhtml_onchange="javascript: updateGeodata(\'h\');"
                    xhtml_style="width:216px"/>
            <vm:u-prop-select name="sel_57" value="self.sav57" />
          </td>
        </tr>
        <tr>
          <th><label for="h_address1">Address1</label></th>
          <td class="listing_col" nowrap="1">
            <v:text name="h_address1"
                    value="--self.haddress1"
                    xhtml_onchange="javascript: updateGeodata(\'h\');"
                    xhtml_style="width:216px"/>
            <vm:u-prop-select name="sel_15" value="self.sav15" />
          </td>
        </tr>
        <tr>
          <th><label for="h_address2">Address2</label></th>
          <td class="listing_col" nowrap="1">
            <v:text name="h_address2"
                    value="--self.haddress2"
                    xhtml_style="width:216px"/>
          </td>
        </tr>
        <tr>
          <th><label for="h_tzone">Time-Zone</label></th>
          <td class="listing_col" nowrap="1">
            <v:select-list name="h_tzone" xhtml_id="regtz" xhtml_style="width:220px" enabled="1">
              <v:on-init>
                <![CDATA[
                  {
                    declare i,j int;
                    declare x,y any;
                    x := make_array (25, 'any');
                    y := make_array (25, 'any');
                    i := -12; j:= 0;
                    while (i <= 12)
                    {
                      x[j] := cast (i as varchar);
                      y[j] := sprintf ('GMT %s%02d:00', case when i < 0 then '-' else '+' end,  abs(i));
                      i := i + 1;
                      j := j + 1;
                    }
                    control.vsl_item_values := x;
                    control.vsl_items := y;
                    control.ufl_value := '0';
                  }
                ]]>
              </v:on-init>
              <v:before-data-bind>
                control.ufl_value := self.htzone;
              </v:before-data-bind>
            </v:select-list>
            <vm:u-prop-select name="sel_17" value="self.sav17" />
          </td>
        </tr>
        <tr>
          <th><label for="h_lat">Latitude</label></th>
          <td class="listing_col" nowrap="1">
            <v:text name="h_lat"
                    xhtml_id="h_lat"
                    value="--case when self.lat is not null then sprintf ('%.6f', coalesce (self.lat, 0.00)) else '' end"
                    xhtml_style="width:216px;"/>
            <vm:u-prop-select name="sel_39" value="self.sav39" />
          </td>
        </tr>
        <tr>
          <th><label for="h_lng">Longitude</label></th>
          <td class="listing_col" nowrap="1">
            <v:text name="h_lng"
                    xhtml_id="h_lng"
                    value="--case when self.lng is not null then sprintf ('%.6f', coalesce (self.lng, 0.00)) else '' end"
                    xhtml_style="width:216px;"/>
            <v:check-box name="set_hlatlng_def" initial-checked="0" value="-- case self.hlatlng_def when 1 then 0 else 1 end" xhtml_id="set_hlatlng_def" >
              <v:after-data-bind>
               if (not e.ve_is_post)
               {
                 if(self.hlatlng_def=0)
                 {
                   control.ufl_selected := 1;
                 } else {
                   control.ufl_selected := 0;
                 }
               }
              </v:after-data-bind>
            <br/>
            </v:check-box>
            <label for="set_hlatlng_def">Use as default map location</label>
          </td>
        </tr>
        <tr>
          <th><label for="h_phone">Phone</label></th>
          <td class="listing_col" nowrap="1">
            <v:text name="h_phone"
                    value="--self.hphone"
                    xhtml_style="width:216px"/>
            <b>Ext.</b>
            <v:text name="h_phone_ext"
                    value="--self.hphone_ext"
                    xhtml_size="5"/>
            <vm:u-prop-select name="sel_18" value="self.sav18" />
          </td>
        </tr>
        <tr>
          <th><label for="h_mobile">Mobile</label></th>
          <td class="listing_col" nowrap="1">
            <v:text name="h_mobile"
                    value="--self.hmobile"
                    xhtml_style="width:216px"/>
          </td>
        </tr>
        <tr>
          <th><label for="set_personal_2">Set access for all fields as </label></th>
          <td class="ctrl">
            <v:select-list name="set_personal_2" xhtml_id="set_personal_2" value="0" xhtml_onchange='javascript: setSelectLists (this.value, this.form, "sel_")'>
              <v:item name="*no change*"  value="0" />
              <v:item name="public"  value="1" />
              <v:item name="acl" value="2" />
              <v:item name="private" value="3" />
            </v:select-list>
          </td>
        </tr>
      </table>
      <br />
      <div>
        <v:button name="user_c_personal_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_personal_2" value="Save" action="simple" xhtml_onclick="return validateInputs(this);">
          <v:on-post>
            <![CDATA[
              self.savePersonal_2();
            ]]>
          </v:on-post>
        </v:button>
        <v:button name="user_sn_personal_2" value="Save and Next" action="simple" xhtml_onclick="return validateInputs(this);">
          <v:on-post>
            <![CDATA[
              self.savePersonal_2();
              if (self.vc_is_valid)
   		          self.vc_redirect ('uiedit.vspx?page=1&tabNo=3');
            ]]>
          </v:on-post>
        </v:button>
      </div>
    </div>
  </v:form>
</v:page>
