<?xml version="1.0" encoding="UTF-8"?>
<!--
 -
 -  $Id: history.vspx,v 1.6.2.1 2009/06/04 14:56:22 source Exp $
 -
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -
 -  Copyright (C) 1998-2006 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="id" type="integer" default="NULL" param-name="id"/>
      <v:variable name="cluster_key" type="varchar" param-name="cluster"/>

      <v:variable name="topic" type="WV.WIKI.TOPICINFO" default="NULL"/>
      <v:variable name="revisions" type="any" default="NULL"/>
      <v:variable name="allow_change" type="int" default="0"/>
      <v:variable name="source_page" type="varchar"/>
      <v:on-init><![CDATA[
        self.sid := get_keyword('sid', params);
    self.realm := get_keyword('realm', params, 'wa');
	self.vspx_user := coalesce ((select VS_UID from DB.DBA.VSPX_SESSION where VS_SID = self.sid and VS_REALM = self.realm), 'WikiGuest');
	declare _topic WV.WIKI.TOPICINFO;
	_topic := WV.WIKI.TOPICINFO();
	_topic.ti_id := self.id;
	_topic.ti_find_metadata_by_id();	
	self.topic := _topic;
	self.source_page := WV.WIKI.READONLYWIKIWORDLINK (_topic.ti_cluster_name,_topic.ti_local_name);
	
        declare pwd varchar;
	pwd := (select pwd_magic_calc (U_NAME, U_PASSWORD, 1) from DB.DBA.SYS_USERS where U_NAME = self.vspx_user);
	if (DAV_HIDE_ERROR (DAV_AUTHENTICATE (self.topic.ti_res_id, 'R', '_1_', self.vspx_user, pwd)) is not null)
	  self.allow_change := 1;
      ]]></v:on-init>
      <v:after-data-bind><![CDATA[
	if (self.vspx_user = 'WikiGuest')
	  {
	    self.allow_change := 0;
	  }
	self.t1.vc_data_bind(e);
      ]]></v:after-data-bind>
      <v:before-data-bind><![CDATA[
	self.revisions := self.topic.ti_revisions(1,0);
	WV.WIKI.VECTOR_NREVERSE (self.revisions);
    --	elf.ds.vc_data_bind(e);
      ]]></v:before-data-bind>
      <vm:page title="History">
      <vm:body>
	  <div class="wiki-error"><v:error-summary/></div>
	    <v:label name="topic_name" value="--self.topic.ti_cluster_name || '.' || self.topic.ti_local_name"/>
	      <table class="wikitable" width="70%">
	        <tr bgcolor="#DFFFDF">
		 <th width="10%" align="left">Revisions:</th>
		 <th width="70%" align="left"></th>
		 <th width="20%" align="left">Actions:</th>
		</tr>
		<v:form type="simple" method="POST">
		 <v:data-set name="ds" data="--self.revisions" meta="--vector()" scrollable="1" nrows="1000">
		   <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>
    		          <td colspan="3">No Revisions</td>
    		        </tr>
		     </v:template>
		     <v:template name="template2" type="browse" name-to-remove="table" set-to-remove="both">
		      <tr>
		       <td>
    		            <img src="images/notep_16.png" title="View Revision" alt="View Revision"/>
    		            <v:button name="link" action="simple" style="url" value="--'1.' || (control.vc_parent as vspx_row_template).te_rowset">
			   <v:on-post><![CDATA[
			     -- self.vc_redirect ('../main/' || WV.WIKI.READONLYWIKIWORDLINK (self.topic.ti_cluster_name, self.topic.ti_local_name) || '?rev=' || (control.vc_parent as vspx_row_template).te_rowset);
			     self.vc_redirect (self.topic.ti_fill_url() || '?rev=' || (control.vc_parent as vspx_row_template).te_rowset);
			      ;
			   ]]></v:on-post>
			</v:button>
		       </td>
		       <td>
		        <v:template name="diff_tmpl" type="simple" enabled="--case when (control.vc_parent as vspx_row_template).te_ctr = ((control.vc_parent.vc_parent as vspx_data_set).ds_rows_total - 1) then 0 else 1 end">
      		            <img src="images/opts_16.png" title="View Diff" alt="View Diff"/>
      		            <v:button name="diff" action="simple" style="url" value="View Diff">
			   <v:on-post><![CDATA[
			     -- self.vc_redirect ('../main/' || WV.WIKI.READONLYWIKIWORDLINK (self.topic.ti_cluster_name, self.topic.ti_local_name) || sprintf ('?command=diff&rev=%ld', cast ((control.vc_parent.vc_parent as vspx_row_template).te_rowset as int) -1 ));
           self.vc_redirect (sprintf ('%s?command=diff&rev=%ld', self.topic.ti_fill_url(), cast ((control.vc_parent.vc_parent as vspx_row_template).te_rowset as int) -1 ));
			      ;
			   ]]></v:on-post>
			 </v:button>
			</v:template>
		       </td>
		       <td>
		        <v:template name="delete_tmpl" type="simple" enabled="--case when (control.vc_parent as vspx_row_template).te_ctr > 0 and self.allow_change then 1 else 0 end">
      		            <img src="images/del_16.png" title="Delete Revision" alt="Delete" enabled="--self.allow_change"/>
      		            <v:button name="del" action="simple" value="Delete" style="url" enabled="--self.allow_change">
			  <v:on-init>control.vc_parent.vc_focus := 1;</v:on-init>
			  <v:on-post><![CDATA[
			     self.vc_redirect (sprintf ('revision_delete.vspx?id=%ld&rev=%s', self.topic.ti_id, (control.vc_parent.vc_parent as vspx_row_template).te_rowset));
			  ]]></v:on-post>
			 </v:button> 
      		            <img src="images/undo_16.png" title="Undo" alt="Undo" enabled="--self.allow_change"/>
      		            <v:button name="rollback" action="simple" value="Rollback" style="url" enabled="--self.allow_change">
			  <v:on-init>control.vc_parent.vc_focus := 1;</v:on-init>
			  <v:on-post><![CDATA[
			     self.vc_redirect (sprintf ('revision_rollback.vspx?id=%ld&rev=%s', self.topic.ti_id, (control.vc_parent.vc_parent as vspx_row_template).te_rowset));
			  ]]></v:on-post>
			 </v:button> 
			</v:template> 
		       </td>
		      </tr>
		      </v:template>
		     </v:template>
		   </v:data-set>
		  </v:form>
		<tr>
		<v:template name="t1" type="simple">
		 <v:form type="simple" method="POST">
		  <td colspan="2">
		    <vm:back-button/>
		  </td>
	    	 </v:form>
		</v:template>
		</tr>
	      </table>
       </vm:body>
      </vm:page>
     </v:page>
