text: <?xml version="1.0" encoding="UTF-8"?>
  <!--
   -
   -  $Id$
   -
   -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
   -  project.
   -
   -  Copyright (C) 1998-2020 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="foaf-import-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">
  
    <v:variable name="ol_mode" type="varchar" default="'OL/browse'"/>
  
  	<v:variable name="ol_id" type="any" default="null" />
  	<v:variable name="ol_type" type="varchar" default="'1'" />
  	<v:variable name="ol_properties" type="any" default="null" />
  	<v:variable name="ol_newProperties" type="any" default="null" />
  
  	<v:form name="usr_personal_054" type="simple" method="POST" xhtml_enctype="multipart/form-data">
      <h3>My Offers</h3>
      <vm:if test="self.ol_mode = 'OL/browse'">
        <?vsp
          if (0)
          {
        ?>
          <v:button name="ol_dButton" action="simple" value="Delete">
            <v:on-post>
              <![CDATA[
                delete from DB.DBA.WA_USER_OFFERLIST where WUOL_ID = get_keyword ('ol_id', self.vc_page.vc_event.ve_params) and WUOL_U_ID = self.u_id;
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
        <?vsp
          }
        ?>
        <input type="hidden" name="ol_id" id="ol_id" value="" />
        <div style="padding: 0 0 0.5em 0;">
          <v:button name="ol_aButton" action="simple" style="url" value="''" xhtml_class="img_button">
            <v:before-render>
              <![CDATA[
                control.ufl_value := '<img src="images/icons/add_16.png" border="0" /> Add';
              ]]>
            </v:before-render>
            <v:on-post>
              <![CDATA[
                self.ol_mode := 'OL/add';
                self.ol_flag.ufl_value := null;
                self.ol_offer.ufl_value := null;
                self.ol_comment.ufl_value := null;
                self.ol_properties := ODS..jsonObject ();
                self.ol_newProperties := vector (vector_concat (ODS..jsonObject (), vector ('id', '0', 'ontology', 'http://purl.org/goodrelations/v1#', 'items', vector ())));
  
                self.vc_data_bind(e);
              ]]>
            </v:on-post>
          </v:button>
        </div>
  
  	    <v:data-set name="ol_ds"
  	                sql="select WUOL_ID, WUOL_OFFER, WUOL_COMMENT from DB.DBA.WA_USER_OFFERLIST where WUOL_U_ID = :self.u_id and WUOL_TYPE = :self.ol_type"
  		              scrollable="1"
  		              editable="1"
  		              nrows="0">
  
          <v:template name="ol_ds_header" type="simple" name-to-remove="table" set-to-remove="bottom">
  	  <table class="listing" rules="groups">
  	    <tr class="listing_header_row">
        		    <th>Offer</th>
        		    <th width="50px">Action</th>
  	    </tr>
            </table>
          </v:template>
  
          <v:template name="ol_ds_repeat" type="repeat" name-to-remove="" set-to-remove="">
  
            <v:template name="ol_ds_empty" type="if-not-exists" name-to-remove="table" set-to-remove="both">
              <table>
                <tr align="center">
                  <td colspan="2">No Offers</td>
                </tr>
              </table>
            </v:template>
  
            <v:template name="ol_ds_browse" type="browse" name-to-remove="table" set-to-remove="both">
              <table>
    			      <tr class="<?V case when mod(control.te_ctr, 2) then 'listing_row_odd' else 'listing_row_even' end ?>">
                  <td nowrap="nowrap" width="100%">
                    <v:label value="--(control.vc_parent as vspx_row_template).te_column_value('WUOL_OFFER')" format="%s" name="ol_ds_browse_1_label"/>
                  </td>
                  <td nowrap="nowrap">
                    <v:button name="ol_eButton" action="simple" style="url" value="''" xhtml_class="img_button">
                      <v:before-render>
                        <![CDATA[
                          control.ufl_value := '<img src="images/icons/edit_16.png" border="0" alt="Edit Offer" title="Edit Offer"/> Edit';
                        ]]>
                      </v:before-render>
                      <v:on-post>
                        <![CDATA[
                          self.ol_mode := 'OL/edit';
                          self.ol_id := (control.vc_parent as vspx_row_template).te_column_value('WUOL_ID');
                          self.ol_newProperties := vector (vector_concat (ODS..jsonObject (), vector ('id', '0', 'ontology', 'http://purl.org/goodrelations/v1#', 'items', vector ())));
  
                          select WUOL_FLAG,
                                 WUOL_OFFER,
                                 WUOL_COMMENT,
                                 deserialize (WUOL_PROPERTIES)
                            into self.ol_flag.ufl_value,
                                 self.ol_offer.ufl_value,
                                 self.ol_comment.ufl_value,
                                 self.ol_properties
                            from DB.DBA.WA_USER_OFFERLIST
                           where WUOL_ID = self.ol_id;
  
                          if (get_keyword ('version', self.ol_properties) = '1.0')
                          self.ol_newProperties := vector (vector_concat (ODS..jsonObject (), vector ('id', '0', 'ontology', 'http://purl.org/goodrelations/v1#', 'items', get_keyword ('products', self.ol_properties, vector ()))));
  
                          if (get_keyword ('version', self.ol_properties) = '2.0')
                            self.ol_newProperties := get_keyword ('ontologies', self.ol_properties, vector ());
  
                          self.vc_data_bind(e);
                        ]]>
                      </v:on-post>
                    </v:button>
                    <span class="button pointer" onclick="javascript: if (confirm('Are you sure you want to delete this record?')) {$('ol_id').value = <?V (control as vspx_row_template).te_column_value('WUOL_ID') ?>; doPost('page_form', 'ol_dButton');}">
                      <img class="button" src="/ods/images/icons/trash_16.png"/> Delete
                    </span>
  			        </td>
  			      </tr>
              </table>
  		      </v:template>
  		    </v:template>
  
  		    <v:template name="ol_ds_footer" type="simple" name-to-remove="table" set-to-remove="top">
            <table>
            </table>
  		    </v:template>
  	    </v:data-set>
  
      </vm:if>
  
      <vm:if test="self.ol_mode <> 'OL/browse'">
  	  <div class="fm">
  				<table>
  				  <tr>
  				    <th width="100px">
  		          Access
  		        </th>
  		        <td>
                <v:select-list name="ol_flag" xhtml_id="ol_flag">
                  <v:item name="public" value="1" />
                  <v:item name="acl" value="2" />
                  <v:item name="private" value="3" />
                </v:select-list>
              </td>
            </tr>
  				  <tr>
  				    <th>
    		          Offer Name
  		        </th>
  		        <td>
          <v:text name="ol_offer" value="" xhtml_id="ol_offer" xhtml_size="50" xhtml_class="_validate_" />
              </td>
            </tr>
  				  <tr>
  				    <th valign="top">
  		          Comment
  		        </th>
  		        <td>
  		    <v:textarea name="ol_comment" value="" xhtml_id="ol_comment" xhtml_rows="5" xhtml_cols="50"/>
              </td>
            </tr>
            <tr>
    				    <th valign="top">
    		          Products
    		        </th>
                <td width="800px">
                <table class="ctl_grp">
                  <tr>
                    <td width="800px">
                  <table id="ol_tbl" class="listing">
                        <thead>
                          <tr class="listing_header_row">
                            <th>
                              <div style="width: 16px;"><![CDATA[&nbsp;]]></div>
                            </th>
                            <th width="100%">
                              Ontology
                            </th>
                            <th width="80px">
                              Action
                            </th>
                    </tr>
                        </thead>
                        <tbody id="ol_tbody" class="colorize">
                          <tr id="ol_tr_no"><td colspan="3"><b>No Attached Ontologies</b></td></tr>
                    </tbody>
  			  </table>
                    </td>
                    <td valign="top" nowrap="nowrap">
                      <span class="button pointer" onclick="TBL.createRow('ol', null, {fld_1: {mode: 40, cssText: 'display: none;'}, fld_2: {mode: 41, labelValue: 'Ontology: ', cssText: 'width: 95%;'}, btn_1: {mode: 40}, btn_2: {mode: 41, title: 'Attach'}});"><img class="button" src="/ods/images/icons/add_16.png" border="0" alt="Add Ontology" title="Add Ontology" /> Add</span>
                      <br /><br />
                      <span class="button pointer" onclick="RDF.showRDF('ol', 'RDF');"><img class="button" src="/ods/images/icons/rdf_11.png" border="0" alt="Show RDF Data" title="Show RDF Data" /> RDF</span>
                      <br /><br />
                      <span class="button pointer" onclick="RDF.showRDF('ol', 'TTL');"><img class="button" src="/ods/images/icons/rdf_11.png" border="0" alt="Show RDF Data" title="Show RDF Data" /> TTL</span>
                    </td>
                  </tr>
                </table>
                  <input type="hidden" id="ol_no" name="ol_no" value="1" />
            <script type="text/javascript">
              <![CDATA[
                ODSInitArray.push ( function () {
                        OAT.Loader.load(["ajax", "json", "combolist"], function(){
                          RDF.tablePrefix = 'ol';
                          RDF.tableOptions = {itemType: {fld_1: {cssText: "display: none;"}, btn_1: {cssText: "display: none;"}}};
                          RDF.itemTypes = <?vsp http (replace (ODS..obj2json (self.ol_newProperties, 10), 'class:', 'className:')); ?>;
                          RDF.showItemTypes();
                  });
                });
              ]]>
            </script>
                </td>
              </tr>
            <tr>
              <td></td>
              <td>
                <br />
      		      <v:button name="user_c_personal_054" value="Cancel" action="simple">
  		        <v:on-post>
                  self.ol_mode := 'OL/browse';
                  self.vc_data_bind (e);
  		        </v:on-post>
  		      </v:button>
      		      <v:button name="user_s_personal_054" value="--case when self.ol_mode = 'OL/add' then 'Add' else 'Update' end" action="simple" xhtml_onclick="return validateInputs(this);">
  		        <v:on-post><![CDATA[
                  if (self.vc_is_valid = 0)
                    return;
  
                  declare ontologies, IDs any;
  
                  IDs := vector ();
                  ontologies := vector ();
                  self.getItems ('ol', 'gr', ontologies, IDs);
                    self.ol_properties := vector_concat (ODS..jsonObject (), vector ('version', '2.0', 'ontologies', ontologies));
                  if (self.ol_mode = 'OL/add')
                {
                      if (exists (select 1 from DB.DBA.WA_USER_OFFERLIST where WUOL_U_ID = self.u_id and WUOL_TYPE = self.ol_type and WUOL_OFFER = self.ol_offer.ufl_value))
                      {
                        self.vc_error_message := 'An offer with same name already exists, please specify unique name.';
                        self.vc_is_valid := 0;
                        return;
                      }
                      insert into DB.DBA.WA_USER_OFFERLIST (WUOL_U_ID, WUOL_TYPE, WUOL_FLAG, WUOL_OFFER, WUOL_COMMENT, WUOL_PROPERTIES)
                        values (self.u_id, self.ol_type, self.ol_flag.ufl_value, self.ol_offer.ufl_value, self.ol_comment.ufl_value, serialize (self.ol_properties));
                }
                else
                {
                    update DB.DBA.WA_USER_OFFERLIST
                         set WUOL_FLAG = self.ol_flag.ufl_value,
                             WUOL_OFFER = self.ol_offer.ufl_value,
                         WUOL_COMMENT = self.ol_comment.ufl_value,
                         WUOL_PROPERTIES = serialize (self.ol_properties)
                     where WUOL_ID = self.ol_id;
                }
  
                  self.ol_mode := 'OL/browse';
                  self.vc_data_bind (e);
              ]]></v:on-post>
            </v:button>
              </td>
            </tr>
          </table>
      </div>
        <div id="rdfDiv" style="display: none;">
          <pre id="rdfData">
          </pre>
        </div>
      </vm:if>
  	</v:form>
  </v:page>
  