Added display of admin change differences to last change on the change

detail page

git-svn-id: svn://192.168.202.10@2548 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2016-06-12 02:37:57 +00:00
parent bf574407cb
commit 0ee7ddbc2c
4 changed files with 469 additions and 2 deletions
+3
View File
@@ -265,6 +265,9 @@ OTHER CHANGES:
70. Added phone outbound alt caller ID to allow for phone-dialed calls to use 70. Added phone outbound alt caller ID to allow for phone-dialed calls to use
a separate CID number when dialing through a specific context a separate CID number when dialing through a specific context
71. Added display of admin change differences to last change on the change
detail page
+30 -2
View File
@@ -3822,12 +3822,13 @@ else
# 160514-1437 - Added ofcom_uk_drop_calc option # 160514-1437 - Added ofcom_uk_drop_calc option
# 160517-1927 - formatting fixes # 160517-1927 - formatting fixes
# 160602-1450 - Hiding email group settings that are not needed # 160602-1450 - Hiding email group settings that are not needed
# 160611-2230 - Added diff to last change on admin change detail display
# #
# make sure you have added a user to the vicidial_users MySQL table with at least user_level 9 to access this page the first time # make sure you have added a user to the vicidial_users MySQL table with at least user_level 9 to access this page the first time
$admin_version = '2.12-558a'; $admin_version = '2.12-559a';
$build = '160602-1450'; $build = '160611-2230';
$STARTtime = date("U"); $STARTtime = date("U");
$SQLdate = date("Y-m-d H:i:s"); $SQLdate = date("Y-m-d H:i:s");
@@ -36097,10 +36098,37 @@ if ($ADD==730000000000000)
echo "<TD ALIGN=RIGHT><B><FONT FACE=\"Arial,Helvetica\" size=2>"._QXZ("NOTES").": </B></TD>"; echo "<TD ALIGN=RIGHT><B><FONT FACE=\"Arial,Helvetica\" size=2>"._QXZ("NOTES").": </B></TD>";
echo "<TD ALIGN=LEFT><FONT FACE=\"Arial,Helvetica\" size=1>$row[8]</TD>"; echo "<TD ALIGN=LEFT><FONT FACE=\"Arial,Helvetica\" size=1>$row[8]</TD>";
echo "</TR><TR>\n"; echo "</TR><TR>\n";
$new_sql = $row[9];
$row[9] = preg_replace('/\',/i', '\' ,',$row[9]); $row[9] = preg_replace('/\',/i', '\' ,',$row[9]);
$row[9] = preg_replace("/\|/","<BR>",$row[9]); $row[9] = preg_replace("/\|/","<BR>",$row[9]);
echo "<TD ALIGN=RIGHT><B><FONT FACE=\"Arial,Helvetica\" size=2>"._QXZ("SQL").": </B></TD>"; echo "<TD ALIGN=RIGHT><B><FONT FACE=\"Arial,Helvetica\" size=2>"._QXZ("SQL").": </B></TD>";
echo "<TD ALIGN=LEFT width=700><p style=\"width: 700; text-wrap: normal; word-wrap: break-word\"><FONT FACE=\"Arial,Helvetica\" size=1>$row[9]</TD>"; echo "<TD ALIGN=LEFT width=700><p style=\"width: 700; text-wrap: normal; word-wrap: break-word\"><FONT FACE=\"Arial,Helvetica\" size=1>$row[9]</TD>";
$stmt="SELECT admin_log_id,event_date,val.user,ip_address,event_section,event_type,record_id,event_code,event_notes,event_sql,full_name,val.user_group from vicidial_admin_log val, vicidial_users vu where event_section='$row[4]' and event_type='$row[5]' and record_id='$row[6]' and event_code='$row[7]' and admin_log_id < $row[0] and val.user=vu.user $valLOGadmin_viewable_groupsSQL order by admin_log_id desc;";
if ($DB > 0) {echo "$stmt\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$last_to_print = mysqli_num_rows($rslt);
if ($last_to_print > 0)
{
$rowx=mysqli_fetch_row($rslt);
echo "</TR><TR>\n";
echo "<TD ALIGN=CENTER COLSPAN=2><B><FONT FACE=\"Arial,Helvetica\" size=2><BR>"._QXZ("DIFF TO LAST CHANGE")."<BR>"._QXZ("ID").": <a href=\"$PHP_SELF?ADD=730000000000000&stage=$rowx[0]\">$rowx[0]</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"._QXZ("DATE TIME").": $rowx[1] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"._QXZ("USER").": $rowx[2]</B></TD></TR>";
echo "<TR><TD ALIGN=LEFT COLSPAN=2>";
// include the Diff class
require_once './class.Diff.php';
$new_sql = preg_replace('/\',/i', '\' ,',$new_sql);
$new_sql = preg_replace('/ ,/', "\n",$new_sql);
$rowx[9] = preg_replace('/\',/i', '\' ,',$rowx[9]);
$rowx[9] = preg_replace('/ ,/', "\n",$rowx[9]);
// output the result of comparing two files as HTML
echo Diff::toTable(Diff::compare($rowx[9], $new_sql));
}
echo "</TD>";
echo "</TR>\n"; echo "</TR>\n";
echo "</TABLE><BR><BR>\n"; echo "</TABLE><BR><BR>\n";
echo "\n"; echo "\n";
+50
View File
@@ -64,6 +64,7 @@
# 160404-0934 - design changes # 160404-0934 - design changes
# 160429-1014 - Added admin_row_click option # 160429-1014 - Added admin_row_click option
# 160507-2324 - Added screen colors section # 160507-2324 - Added screen colors section
# 160611-2229 - Added style for diff on admin changes
# #
@@ -1245,6 +1246,54 @@ echo "</script>\n";
<style type="text/css"> <style type="text/css">
<!-- <!--
<?php
if ($ADD == '730000000000000')
{
?>
.diff table{
margin : 1px 1px 1px 1px;
border-collapse : collapse;
border-spacing : 0;
}
.diff td{
vertical-align : top;
font-family : monospace;
font-size : 9;
}
.diff span{
display:block;
min-height:1pm;
margin-top:-1px;
padding:1px 1px 1px 1px;
}
* html .diff span{
height:1px;
}
.diff span:first-child{
margin-top:1px;
}
.diffDeleted span{
border:1px solid rgb(255,51,0);
background:rgb(255,173,153);
}
.diffInserted span{
border:1px solid rgb(51,204,51);
background:rgb(102,255,51);
}
<?php
}
?>
.auraltext .auraltext
{ {
position: absolute; position: absolute;
@@ -1320,6 +1369,7 @@ echo "</script>\n";
{ {
--> -->
</style> </style>
<?php <?php
+386
View File
@@ -0,0 +1,386 @@
<?php
/*
class.Diff.php
A class containing a diff implementation
Created by Stephen Morley - http://stephenmorley.org/ - and released under the
terms of the CC0 1.0 Universal legal code:
http://creativecommons.org/publicdomain/zero/1.0/legalcode
*/
// A class containing functions for computing diffs and formatting the output.
class Diff{
// define the constants
const UNMODIFIED = 0;
const DELETED = 1;
const INSERTED = 2;
/* Returns the diff for two strings. The return value is an array, each of
* whose values is an array containing two values: a line (or character, if
* $compareCharacters is true), and one of the constants DIFF::UNMODIFIED (the
* line or character is in both strings), DIFF::DELETED (the line or character
* is only in the first string), and DIFF::INSERTED (the line or character is
* only in the second string). The parameters are:
*
* $string1 - the first string
* $string2 - the second string
* $compareCharacters - true to compare characters, and false to compare
* lines; this optional parameter defaults to false
*/
public static function compare(
$string1, $string2, $compareCharacters = false){
// initialise the sequences and comparison start and end positions
$start = 0;
if ($compareCharacters){
$sequence1 = $string1;
$sequence2 = $string2;
$end1 = strlen($string1) - 1;
$end2 = strlen($string2) - 1;
}else{
$sequence1 = preg_split('/\R/', $string1);
$sequence2 = preg_split('/\R/', $string2);
$end1 = count($sequence1) - 1;
$end2 = count($sequence2) - 1;
}
// skip any common prefix
while ($start <= $end1 && $start <= $end2
&& $sequence1[$start] == $sequence2[$start]){
$start ++;
}
// skip any common suffix
while ($end1 >= $start && $end2 >= $start
&& $sequence1[$end1] == $sequence2[$end2]){
$end1 --;
$end2 --;
}
// compute the table of longest common subsequence lengths
$table = self::computeTable($sequence1, $sequence2, $start, $end1, $end2);
// generate the partial diff
$partialDiff =
self::generatePartialDiff($table, $sequence1, $sequence2, $start);
// generate the full diff
$diff = array();
for ($index = 0; $index < $start; $index ++){
$diff[] = array($sequence1[$index], self::UNMODIFIED);
}
while (count($partialDiff) > 0) $diff[] = array_pop($partialDiff);
for ($index = $end1 + 1;
$index < ($compareCharacters ? strlen($sequence1) : count($sequence1));
$index ++){
$diff[] = array($sequence1[$index], self::UNMODIFIED);
}
// return the diff
return $diff;
}
/* Returns the diff for two files. The parameters are:
*
* $file1 - the path to the first file
* $file2 - the path to the second file
* $compareCharacters - true to compare characters, and false to compare
* lines; this optional parameter defaults to false
*/
public static function compareFiles(
$file1, $file2, $compareCharacters = false){
// return the diff of the files
return self::compare(
file_get_contents($file1),
file_get_contents($file2),
$compareCharacters);
}
/* Returns the table of longest common subsequence lengths for the specified
* sequences. The parameters are:
*
* $sequence1 - the first sequence
* $sequence2 - the second sequence
* $start - the starting index
* $end1 - the ending index for the first sequence
* $end2 - the ending index for the second sequence
*/
private static function computeTable(
$sequence1, $sequence2, $start, $end1, $end2){
// determine the lengths to be compared
$length1 = $end1 - $start + 1;
$length2 = $end2 - $start + 1;
// initialise the table
$table = array(array_fill(0, $length2 + 1, 0));
// loop over the rows
for ($index1 = 1; $index1 <= $length1; $index1 ++){
// create the new row
$table[$index1] = array(0);
// loop over the columns
for ($index2 = 1; $index2 <= $length2; $index2 ++){
// store the longest common subsequence length
if ($sequence1[$index1 + $start - 1]
== $sequence2[$index2 + $start - 1]){
$table[$index1][$index2] = $table[$index1 - 1][$index2 - 1] + 1;
}else{
$table[$index1][$index2] =
max($table[$index1 - 1][$index2], $table[$index1][$index2 - 1]);
}
}
}
// return the table
return $table;
}
/* Returns the partial diff for the specificed sequences, in reverse order.
* The parameters are:
*
* $table - the table returned by the computeTable function
* $sequence1 - the first sequence
* $sequence2 - the second sequence
* $start - the starting index
*/
private static function generatePartialDiff(
$table, $sequence1, $sequence2, $start){
// initialise the diff
$diff = array();
// initialise the indices
$index1 = count($table) - 1;
$index2 = count($table[0]) - 1;
// loop until there are no items remaining in either sequence
while ($index1 > 0 || $index2 > 0){
// check what has happened to the items at these indices
if ($index1 > 0 && $index2 > 0
&& $sequence1[$index1 + $start - 1]
== $sequence2[$index2 + $start - 1]){
// update the diff and the indices
$diff[] = array($sequence1[$index1 + $start - 1], self::UNMODIFIED);
$index1 --;
$index2 --;
}elseif ($index2 > 0
&& $table[$index1][$index2] == $table[$index1][$index2 - 1]){
// update the diff and the indices
$diff[] = array($sequence2[$index2 + $start - 1], self::INSERTED);
$index2 --;
}else{
// update the diff and the indices
$diff[] = array($sequence1[$index1 + $start - 1], self::DELETED);
$index1 --;
}
}
// return the diff
return $diff;
}
/* Returns a diff as a string, where unmodified lines are prefixed by ' ',
* deletions are prefixed by '- ', and insertions are prefixed by '+ '. The
* parameters are:
*
* $diff - the diff array
* $separator - the separator between lines; this optional parameter defaults
* to "\n"
*/
public static function toString($diff, $separator = "\n"){
// initialise the string
$string = '';
// loop over the lines in the diff
foreach ($diff as $line){
// extend the string with the line
switch ($line[1]){
case self::UNMODIFIED : $string .= ' ' . $line[0];break;
case self::DELETED : $string .= '- ' . $line[0];break;
case self::INSERTED : $string .= '+ ' . $line[0];break;
}
// extend the string with the separator
$string .= $separator;
}
// return the string
return $string;
}
/* Returns a diff as an HTML string, where unmodified lines are contained
* within 'span' elements, deletions are contained within 'del' elements, and
* insertions are contained within 'ins' elements. The parameters are:
*
* $diff - the diff array
* $separator - the separator between lines; this optional parameter defaults
* to '<br>'
*/
public static function toHTML($diff, $separator = '<br>'){
// initialise the HTML
$html = '';
// loop over the lines in the diff
foreach ($diff as $line){
// extend the HTML with the line
switch ($line[1]){
case self::UNMODIFIED : $element = 'span'; break;
case self::DELETED : $element = 'del'; break;
case self::INSERTED : $element = 'ins'; break;
}
$html .=
'<' . $element . '>'
. htmlspecialchars($line[0])
. '</' . $element . '>';
// extend the HTML with the separator
$html .= $separator;
}
// return the HTML
return $html;
}
/* Returns a diff as an HTML table. The parameters are:
*
* $diff - the diff array
* $indentation - indentation to add to every line of the generated HTML; this
* optional parameter defaults to ''
* $separator - the separator between lines; this optional parameter
* defaults to '<br>'
*/
public static function toTable($diff, $indentation = '', $separator = ''){
// initialise the HTML
$html = $indentation . "<table class=\"diff\">\n";
// loop over the lines in the diff
$index = 0;
while ($index < count($diff)){
// determine the line type
switch ($diff[$index][1]){
// display the content on the left and right
case self::UNMODIFIED:
$leftCell =
self::getCellContent(
$diff, $indentation, $separator, $index, self::UNMODIFIED);
$rightCell = $leftCell;
break;
// display the deleted on the left and inserted content on the right
case self::DELETED:
$leftCell =
self::getCellContent(
$diff, $indentation, $separator, $index, self::DELETED);
$rightCell =
self::getCellContent(
$diff, $indentation, $separator, $index, self::INSERTED);
break;
// display the inserted content on the right
case self::INSERTED:
$leftCell = '';
$rightCell =
self::getCellContent(
$diff, $indentation, $separator, $index, self::INSERTED);
break;
}
// extend the HTML with the new row
$html .=
$indentation
. " <tr>\n"
. $indentation
. ' <td class="diff'
. ($leftCell == $rightCell
? 'Unmodified'
: ($leftCell == '' ? 'Blank' : 'Deleted'))
. '">'
. $leftCell
. "</td>\n"
. $indentation
. ' <td class="diff'
. ($leftCell == $rightCell
? 'Unmodified'
: ($rightCell == '' ? 'Blank' : 'Inserted'))
. '">'
. $rightCell
. "</td>\n"
. $indentation
. " </tr>\n";
}
// return the HTML
return $html . $indentation . "</table>\n";
}
/* Returns the content of the cell, for use in the toTable function. The
* parameters are:
*
* $diff - the diff array
* $indentation - indentation to add to every line of the generated HTML
* $separator - the separator between lines
* $index - the current index, passes by reference
* $type - the type of line
*/
private static function getCellContent(
$diff, $indentation, $separator, &$index, $type){
// initialise the HTML
$html = '';
// loop over the matching lines, adding them to the HTML
while ($index < count($diff) && $diff[$index][1] == $type){
$html .=
'<span>'
. htmlspecialchars($diff[$index][0])
. '</span>'
. $separator;
$index ++;
}
// return the HTML
return $html;
}
}
?>