<?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="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="tags" type="any" default="NULL"/>
 
      <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');

        declare _tags any;
	_tags := self.topic.ti_get_tags ();
	if (_tags is not null)
	  {
	    if (self.privatep) {
	      self.tags := xpath_eval ('//tagset[@type="private"]/tag/@name', _tags, 0);
	    } else {
	      self.tags := xpath_eval ('//tagset[@type="public"]/tag/@name', _tags, 0);
	    }
	  }	    
 
      ]]></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>
      <v:method name="set_tags" arglist="in uid int, in tags_str varchar"><![CDATA[
         declare _res int;
	 _res := WV.WIKI.GETLOCK (self.topic.ti_full_path(), self.vspx_user);
	 -- dbg_obj_print ('lock: ', _res);
	 connection_get ('vspx_user', self.vspx_user);
	 DAV_TAG_SET (self.topic.ti_res_id, 'R', uid, tags_str);
      ]]>
      </v:method>
 
      <vm:page title="Tag">
	<vm:body>
	  <div class="wiki-error"><v:error-summary/></div>
	    <table class="wikitable" width="70%">
	        <tr bgcolor="#DFFFDF">
		 <th align="left">Topics:</th>
		</tr>
		<tr>
		 <td>
		   Are you sure to remove tag from the topic?
		   <v:form type="simple" method="POST">
		     <v:button name="conf" action="simple" value="Yes">
			    <v:on-post><![CDATA[
			     self.tags := WV.WIKI.VECTOR_DROP (self.tags, self.tag);
			     self.set_tags (self.uid, WV.WIKI.STRJOIN(',', self.tags));

			      self.vc_redirect (sprintf ('tags.vspx?id=%d', self.id));
			    ]]></v:on-post>
		     </v:button>	
		     <v:button name="no" action="simple" value="No">
			    <v:on-post><![CDATA[
			      self.vc_redirect (sprintf ('tags.vspx?id=%d', self.id));
			    ]]></v:on-post>
		     </v:button>
	
		    <vm:back-button/>
		  </v:form>
		 </td>
		</tr>
	      </table>
	</vm:body>
      </vm:page>
    </v:page>
     
