Commit be46152b authored by RobertPlummer's avatar RobertPlummer

[NEW] Added function diffSheetsAsHTML( $id, $dates ) to grid.php and some...

[NEW] Added function diffSheetsAsHTML( $id, $dates ) to grid.php and some necessary framework to get it to list 2 sheets side by side.
parent b4223175
......@@ -24,7 +24,7 @@ require_once( "lib/sheet/ole.php" );
require_once( "lib/sheet/excel/writer.php" );
//require_once( "lib/sheet/conf/config.inc.php" );
require_once( "lib/encoding/lib-encoding.php" );
include_once 'lib/diff/Diff.php';
// Constants {{{1
/*
......@@ -331,10 +331,7 @@ class TikiSheet
$subsheets = $sheetlib->get_sheet_subsheets($this->sheetId);
if (count($subsheets) > 0) {
foreach ($subsheets as $sub) {
$handler = new TikiSheetDatabaseHandler($sub['sheetId']);
if ($date) {
$handler->setReadDate($date);
}
$handler = new TikiSheetDatabaseHandler($sub['sheetId'], $date );
$subsheet = new TikiSheet($sub['sheetId'], true);
$subsheet->import($handler);
$data .= $subsheet->getTableHtml( false );
......@@ -1302,10 +1299,10 @@ class TikiSheetDatabaseHandler extends TikiSheetDataHandler
* @param $sheetId The ID of the sheet in the database.
* @param $db The database link to use.
*/
function TikiSheetDatabaseHandler( $sheetId )
function TikiSheetDatabaseHandler( $sheetId , $date )
{
$this->sheetId = $sheetId;
$this->readDate = time();
$this->readDate = ( $date ? $date : time() );
}
// _load {{{2
......@@ -2324,4 +2321,90 @@ function array_searchRecursive( $needle, $haystack, $strict=false, $path=array()
}
}
return false;
}
function diffSheetsAsHTML( $id, $dates = null )
{
global $prefs, $sheetlib;
function countLongest( $array1, $array2 )
{
return (count($array1) > count($array2) ? count($array1) : count($array2));
}
function joinWithSubGrids( $id, $date )
{
global $prefs, $sheetlib;
$result1 = "";
$result2 = "";
$handler = new TikiSheetDatabaseHandler($id, $date);
$handler->setReadDate($date);
$grid = new TikiSheet($id, true);
$grid->import($handler);
$subgrids = $sheetlib->get_sheet_subsheets($grid->sheetId);
$i = 0;
$grids = array($grid);
foreach ($subgrids as $sub) {
$handler = new TikiSheetDatabaseHandler($sub['sheetId'], $date);
$handler->setReadDate($date);
$subsheet = new TikiSheet($sub['sheetId'], true);
$subsheet->import($handler);
array_push($grids, $subsheet);
$i++;
}
return $grids;
}
$grids1 = joinWithSubGrids($_REQUEST["sheetId"], $dates[0]);
$grids2 = joinWithSubGrids($_REQUEST["sheetId"], $dates[1]);
for ( $i = 0; $i < countLongest($grids1, $grids2); $i++ ) { //cycle through the sheets within a spreadsheet
$result1 .= "<table>";
$result2 .= "<table>";
for ( $row = 0; $row < countLongest($grids1[$i]->dataGrid, $grids2[$i]->dataGrid); $row++ ) { //cycle through rows
$result1 .= "<tr>";
$result2 .= "<tr>";
for ( $col = 0; $col < countLongest($grids1[$i]->dataGrid[$row], $grids2[$i]->dataGrid[$row]); $col++ ) { //cycle through columns
$diff = new Text_Diff($grids1[$i]->dataGrid[$row][$col], $grids2[$i]->dataGrid[$row][$col]);
$changes = $diff->getDiff();
//print_r($changes);
$class1 = '';
$class2 = '';
//print_r($changes);
switch ( get_class($changes[0]) ) {
case 'Text_Diff_Op_copy':
$class1 = '';
$class2 = '';
break;
case 'Text_Diff_Op_change':
$class1 = 'diffadded';
$class2 = 'diffadded';
break;
case 'Text_Diff_Op_delete':
$class1 = 'diffdeleted';
$class2 = 'diffdeleted';
break;
case 'Text_Diff_Op_add':
$class1 = 'diffadded';
$class2 = 'diffadded';
break;
default:
$class1 = 'diffnotspecified';
$class2 = 'diffnotspecified';
//echo get_class($changes[0]);
}
$result1 .= "<td class='$class1'>".$grids1[$i]->dataGrid[$row][$col]."</td>";
$result2 .= "<td class='$class2'>".$grids2[$i]->dataGrid[$row][$col]."</td>";
}
$result1 .= "</tr>";
$result2 .= "</tr>";
}
$result1 .= "</table>";
$result2 .= "</table>";
}
return array($result1, $result2);
}
\ No newline at end of file
/**
* TikiSheet Client-side grid manipulation for viewing history.
* By Robert Plummer
* 2010
*/
// (c) Copyright 2002-2010 by authors of the Tiki Wiki/CMS/Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id:
$(function () {
$('#compareSheetsSubmit').click(function() {
var sheetId = $('#sheetId').val();
var sheetReadDates = '';
$('input.compareSheet:checked').each(function() {
$('input.compareSheet1:checked,input.compareSheet2:checked').each(function() {
sheetReadDates += $(this).val() + '|';
});
......@@ -20,20 +20,4 @@ $(function () {
return false;
});
});
function scrollLocker(obj, I) {
$($.sheet.instance).each(function(i) {
this.obj.pane()
.scrollLeft(obj.scrollLeft())
.scrollTop(obj.scrollTop());
});
}
function tabLocker(I) {
$($.sheet.instance).each(function(i) {
this.setActiveSheet(I);
});
}
\ No newline at end of file
});
\ No newline at end of file
......@@ -6,50 +6,53 @@
{$description}
</div>
<table style="width: 100%;">
<tr>
<th>Edit Date</th>
<th>User</th>
<th>Compare</th>
<th></th>
</tr>
{section name=revision_date loop=$history}
<tr>
<td>
{$history[revision_date].string}
</td>
<td>
{$history[revision_date].user}
</td>
<td style="vertical-align: middle; text-align: center;">
<input type="checkbox" class="compareSheet" value="{$history[revision_date].stamp}" />
</td>
<td>
<a href="tiki-view_sheets.php?sheetId={$sheetId}&readdate={$history[revision_date].stamp}">View</a>
</td>
</tr>
{/section}
<tr>
<td></td>
<td></td>
<td style="text-align: center;">
<input type="hidden" id="sheetId" value="{$sheetId}" />
<input type="button" id="compareSheetsSubmit" value="compare" />
</td>
<td></td>
</tr>
</table>
{if not $history eq ''}
<table style="width: 100%;" id="tiki_sheet_container">
<tr>
{foreach from=$grid_content item=thisGrid}
<td style="width: 50%;">
<div class="tiki_sheet" {if !empty($tiki_sheet_div_style)}
style="{$tiki_sheet_div_style}"
{/if}>
{$thisGrid}
</div>
</td>
{/foreach}
</tr>
</table>
\ No newline at end of file
<table style="width: 100%;">
<tr>
<th>Edit Date</th>
<th>User</th>
<th colspan="2">
<input type="hidden" id="sheetId" value="{$sheetId}" />
<input type="button" id="compareSheetsSubmit" value="compare" />
</th>
<th></th>
</tr>
{section name=revision_date loop=$history}
<tr>
<td>
{$history[revision_date].string}
</td>
<td>
{$history[revision_date].user}
</td>
<td style="vertical-align: middle; text-align: center;">
<input type="radio" name="compareSheet1" class="compareSheet1" value="{$history[revision_date].stamp}" />
</td>
<td style="vertical-align: middle; text-align: center;">
<input type="radio" name="compareSheet2" class="compareSheet2" value="{$history[revision_date].stamp}" />
</td>
<td>
<a href="tiki-view_sheets.php?sheetId={$sheetId}&readdate={$history[revision_date].stamp}">View</a>
</td>
</tr>
{/section}
</table>
{else}
<a href="tiki-history_sheets.php?sheetId={$sheetId}">Back</a>
<table style="width: 100%;" id="tiki_sheet_container">
<tr>
{foreach from=$grid_content item=thisGrid}
<td style="width: 50%;">
<div class="tiki_sheet" {if !empty($tiki_sheet_div_style)}
style="{$tiki_sheet_div_style}"
{/if}>
{$thisGrid}
</div>
</td>
{/foreach}
</tr>
</table>
{/if}
......@@ -49,9 +49,6 @@ if (empty($_REQUEST['readdate'])) {
include_once ('tiki-section_options.php');
ask_ticket('sheet');
} else {
// Process the insertion or modification of a gallery here
$grid = new TikiSheet($_REQUEST["sheetId"]);
$handler = new TikiSheetDatabaseHandler($_REQUEST["sheetId"]);
$dates = array(time());
$i = 0;
......@@ -65,35 +62,20 @@ if (empty($_REQUEST['readdate'])) {
$i++;
}
$tableHtml = array();
$i = 0;
foreach ( $dates as $date ) {
$smarty->assign('read_date', $date);
$handler->setReadDate($date);
$grid->import($handler);
$tableHtml[$i] = $grid->getTableHtml( true, $date );
$i++;
}
$smarty->assign('grid_content', $tableHtml);
$handler = new TikiSheetDatabaseHandler($_REQUEST["sheetId"]);
$grid->import($handler);
$smarty->assign('grid_content', diffSheetsAsHTML($_REQUEST["sheetId"], $dates));
$headerlib->add_jq_onready(
'if (typeof ajaxLoadingShow == "function") {
$headerlib->add_jq_onready('
if (typeof ajaxLoadingShow == "function") {
ajaxLoadingShow("role_main");
}
setTimeout (function () {
$("div.tiki_sheet").tiki("sheet", "",{
editable: false,
fnPaneScroll: scrollLocker,
fnSwitchSheet: tabLocker
fnPaneScroll: $.sheet.paneScrollLocker,
fnSwitchSheet: $.sheet.switchSheetLocker
});
}, 500);
instanceCount = ' . count($readdates) . ';
'
, 500);
', 500);
if ( $tiki_sheet_div_style) {
$smarty->assign('tiki_sheet_div_style', $tiki_sheet_div_style);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment