<?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="main" 
	  style="comp.xsl"
	  on-error-redirect="../main/" 
	  xmlns:v="http://www.openlinksw.com/vspx/" 
	  xmlns:vm="http://www.openlinksw.com/vspx/macro">
	  
      <v:variable name="tag" type="varchar" default="NULL" param-name="tag"/>
      <v:variable name="encoded_tag" type="varchar" default="NULL"/>
      <v:variable name="id" type="integer" default="NULL" param-name="id"/>
      <v:variable name="privatep" type="integer" default="NULL" param-name="privatep"/>
      <v:variable name="topic" type="WV.WIKI.TOPICINFO" default="NULL"/>
      <v:variable name="source_page" type="varchar"/>

      <v:variable name="uid" type="int" default="NULL" persist="1"/>
      <v:on-init><![CDATA[
	declare _topic WV.WIKI.TOPICINFO;
	_topic := WV.WIKI.TOPICINFO();
	_topic.ti_id := self.id;
	_topic.ti_find_metadata_by_id();	
	self.source_page := WV.WIKI.READONLYWIKIWORDLINK (_topic.ti_cluster_name,_topic.ti_local_name);
	self.topic := _topic;
	-- dbg_obj_print (self.topic);

	--  dbg_obj_print (self.encoded_tag);
      ]]></v:on-init>
      <v:after-data-bind><![CDATA[
        self.login.vc_data_bind(e);
	if (self.privatep)
	  self.uid := (select U_ID from DB.DBA.SYS_USERS where U_NAME = self.vspx_user);
	else
	  self.uid := (select U_ID from DB.DBA.SYS_USERS where U_NAME = 'nobody');
        self.ds.vc_data_bind(e);
      ]]></v:after-data-bind>
      <v:method name="make_url" arglist="in res_id int">
      <![CDATA[
      	declare _topic WV.WIKI.TOPICINFO;
	_topic := WV.WIKI.TOPICINFO();
	_topic.ti_res_id := res_id;
	_topic.ti_find_metadata_by_res_id();
	if (_topic.ti_id <> 0)
	  return _topic.ti_cluster_name || '.' || _topic.ti_local_name;
	else
	  return '***no wiki resource***';
      ]]></v:method>
      
      <vm:page title="Tag">
      <vm:body>
	  <div class="wiki-error"><v:error-summary/></div>
	  Documents labeled by tag [<v:label name="tag_name" value="--self.tag"/>]
	    <table class="wikitable" width="70%">
	        <tr bgcolor="#DFFFDF">
		 <th align="left">Topics:</th>
		</tr>
		<tr>
		 <td>
		  <v:data-set name="ds" sql="SELECT DT_RES_ID from WS.WS.SYS_DAV_TAG  where DT_U_ID = :uid and contains (DT_TAGS, :tag)" scrollable="1" nrows="1000">
		    <v:column name="DT_RES_ID"/>
		    <v:param name="tag" value="self.tag"/>
		    <v:param name="uid" value="self.uid"/>
		    <table class="wikitable" width="100%">
		     <v:template name="template1" type="repeat" name-to-remove="" set-to-remove=""> 
		       <v:template name="template7" type="if-not-exists" name-to-remove="table" set-to-remove="both">
		         <tr width="100%">
			  <td>Nothing has been found</td>
			 </tr>
		       </v:template>
		       <v:template name="template2" type="browse" name-to-remove="table" set-to-remove="both">
		        <tr width="100%">
			 <td>
			   <v:button name="call_cc" action="simple" value="--self.make_url ((control.vc_parent as vspx_row_template).te_rowset[0])" style="url">
			    <v:on-post><![CDATA[
			      declare res_id, id int;
			      res_id := (control.vc_parent as vspx_row_template).te_rowset[0];
			      id := (select TopicId from WV.WIKI.TOPIC where ResId = res_id);
			      declare _topic WV.WIKI.TOPICINFO;
			      _topic := WV.WIKI.TOPICINFO();
			      _topic.ti_id := id;
			      _topic.ti_find_metadata_by_id();	

			      self.vc_redirect (WV..TOPIC_URL(sprintf('%s/%s', _topic.ti_cluster_name, _topic.ti_local_name)));
			    ]]></v:on-post>
			   </v:button>				
			 </td>
			</tr>
		       </v:template>
		     </v:template>
		    </table>
		   </v:data-set>
		 </td>
		</tr>
		<tr>
		 <td>
		  <v:form type="simple" method="POST">
		    <vm:back-button/>
		  </v:form>
		 </td>
		</tr>
	      </table>
       </vm:body>
      </vm:page>
     </v:page>

