<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Show Error Files</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style>
ul
{
margin-left:1px;
margin-top:1px;
padding-left:12px;
padding-top:0px;
}
li.completed
{
list-style-image: url('green_small.png');
font-family:verdana,arial,helvetica,sans-serif;
font-size:8pt;
margin-left:0px;
}
li.error
{
list-style-image: url('red_small.png');
font-family:verdana,arial,helvetica,sans-serif;
font-size:8pt;
margin-left:0px;
}
li.noerrorfiles
{
list-style-image: url('green_small.png');
font-family:verdana,arial,helvetica,sans-serif;
font-size:8pt;
margin-left:12px;
}
body
{
margin-left:1px;
}
</style>
<script type="text/javascript" src="/myserver/IS/mn/Files%20To%20Share/jquery-1.10.2.js"></script>
<script type="text/javascript">
// variable for how many files need to be read. So that it can be shared across the functions.
var giFileCount = 0;
var gOutPutHTMLString = "";
var gJobStatusFileURLPath = "";
var gMatchCode = "";
//getJobStatusFiles1("2014-12-19 04:22:01")
//alert("Here..");
//$(document).ready(function() {
getErrorFiles();
//})
// Get all Error Files for Today
function getErrorFiles()
{
var strDate = new Date();
var strToday = strDate.getFullYear() + "-" + (strDate.getMonth()+1) + "-" + pad(strDate.getDate());
$(document).ready(function() {
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
<listName>IT team to follow up</listName> \
<query><Query><Where><Geq><FieldRef Name='Modified'/><Value Type='DateTime' IncludeTimeValue='FALSE'>"+strToday+"</Value></Geq> \
</Where><OrderBy><FieldRef Name='ID' Ascending='TRUE' /></OrderBy></Query></query> \
<viewFields> \
<ViewFields> \
<FieldRef Name='Name' /> \
<FieldRef Name='Modified' /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: "/myserver/IS/mn/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processFiles,
contentType: "text/xml; charset=\"utf-8\""
});
});
}
function processFiles(xData, status)
{
var strForDropDown = "";
$(xData.responseXML).find("z\\:row, row").each(function() {
strForDropDown = strForDropDown + $(this).attr("ows_ID") + "@" + $(this).attr("ows_FileRef") + "@" + $(this).attr("ows_Modified") + "@" +"\n";
});
// Now populate the department dropdown with our extracted data
getFiles(strForDropDown);
}
function getFiles(strForDropDown)
{
if (strForDropDown != "")
{
var item_array = strForDropDown.split("\n");
giFileCount = item_array.length - 1;
for (var iCount = 0; iCount < (item_array.length-1); iCount++)
{
//alert(item_array[iCount].toString());
var items = item_array[iCount].split("@");
try
{
var strfileName = items[1].slice((items[1].indexOf('#')+1),items[1].len);
strfileName = "/" + strfileName;
var strfileModified = items[2];
//alert(items[1]);
var arrItemsCodes = items[1].split("_");
var strCodes = arrItemsCodes[arrItemsCodes.length-1]
var arrMatchCode = strCodes.split(".");
var strCode = arrMatchCode[0]
//alert(strCode);
//alert(strfileModified);
readFile(strfileName, iCount, strfileModified, strCode);
}
catch(ex)
{
alert("Possible array out of bound error - getFiles(strForDropDown)");
}
}
}
else
{
showNoErrorMessage();
}
}
// function to read from a text file held in SharePoint instead of SharePoint list data
function readFile(sName, nCurrentCount, strModified, strCodeMatch)
{
var iCurrentCount = nCurrentCount;
var bCloseList = "";
var bStartList = "";
if (nCurrentCount == 0)
{
bStartList = true;
}
else
{
bStartList = false;
}
if (giFileCount == (nCurrentCount+1))
{
bCloseList = true;
}
else
{
bCloseList = false;
}
//alert(iCurrentCount + " " + bStartList + " " + bCloseList);
var request = jQuery.get(sName, function(data) {
displayFile(data, bStartList, bCloseList, strModified, strCodeMatch);
//process text file line by line
//$('#div').html(data.replace('n','<br />'));
//$('#StatusMessagesTest').html(data.replace('\n','<br />'));
});
request.error(function(jqXHR, textStatus, errorThrown) {
//showNoErrorMessage();
});
}
function pad(d)
{
return (d < 10) ? '0' + d.toString() : d.toString();
}
function showNoErrorMessage()
{
var strOutput;
strOutput = "<ul class='statusMessage'>";
strOutput = strOutput + "<li class='noerrorfiles'>";
strOutput = strOutput + "No Errors - All Completed";
strOutput = strOutput + "</li>";
strOutput = strOutput + "</ul>";
document.getElementById("StatusMessages").innerHTML = strOutput;
}
function setModifiedTo(sMod)
{
var sReturnValue = "";
var item_array = sMod.split(":");
sReturnValue = item_array[0] + ":" + pad((parseInt(item_array[1], 10) + 1).toString()) + ":00Z";
return sReturnValue;
}
// Get all Error Files for Today
function getJobStatusFiles(strModified, strMatchCode)
{
//alert(strModified);
strModified = strModified.replace(" ", "T");
strModified = strModified + "Z";
//alert(strModified);
//strModified = "2014-12-18T04:22:22Z";
var strModifiedTo = setModifiedTo(strModified);
//alert(strModifiedTo);
$(document).ready(function() {
gMatchCode = strMatchCode; // Copy the MatchCode variable into a global first because of Async call we need it later to do a match if more than 1 JobStatus file is returned for the given modified time.
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
<listName>New Job Status</listName> \
<query><Query><Where><And><Geq><FieldRef Name='Modified'/><Value Type='DateTime' IncludeTimeValue='TRUE'>"+strModified+"</Value></Geq> \
<Leq><FieldRef Name='Modified'/><Value Type='DateTime' IncludeTimeValue='TRUE'>"+strModifiedTo+"</Value></Leq> \
</And> \
</Where><OrderBy><FieldRef Name='ID' Ascending='TRUE' /></OrderBy></Query></query> \
<viewFields> \
<ViewFields> \
<FieldRef Name='Name' /> \
<FieldRef Name='Modified' /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: "/myserver/IS/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processJobStatusFiles,
contentType: "text/xml; charset=\"utf-8\""
});
});
}
function processJobStatusFiles(xData, status)
{
var strForDropDown = "";
$(xData.responseXML).find("z\\:row, row").each(function() {
strForDropDown = strForDropDown + $(this).attr("ows_ID") + "@" + $(this).attr("ows_FileRef") + "@" + $(this).attr("ows_Modified") + "@" +"\n";
});
//alert(strForDropDown);
// Now extract the file's URL links
getJobStatusFileLinks(strForDropDown);
}
function getJobStatusFileLinks(strForDropDown)
{
var strfileNameLink = "";
//alert(gMatchCode);
if (strForDropDown != "")
{
var item_array = strForDropDown.split("\n");
//alert(item_array.length);
//alert(item_array.length);
if ((item_array.length-1) > 1)
{
for (var iCount = 0; iCount < (item_array.length-1); iCount++)
{
//alert(item_array[iCount].toString());
var items = item_array[iCount].split("@");
try
{
strfileNameLink = items[1].slice((items[1].indexOf('#')+1),items[1].len);
strfileNameLink = "/" + strfileNameLink ;
//alert("More than 1 file need to decide which is correct based on the match code for " + strfileNameLink);
var strMatchCode = gMatchCode;
if (FindMatchingFile(strMatchCode, strfileNameLink) == true)
{
return; // Can exit as file already found and opened.
}
else
{
// If we are in the last item and still no match then open the standard log view of Job Status.
if (iCount == (item_array.length-2))
{
openFile("File cannot be found - opening today's Job Status view.");
}
}
}
catch(ex)
{
alert("Possible array out of bound error - getJobStatusFileLinks(strForDropDown)");
}
}
}
else
{
var SingleItem = item_array[0].split("@");
strfileNameLink = SingleItem[1].slice((SingleItem[1].indexOf('#')+1),SingleItem[1].len);
strfileNameLink = "/" + strfileNameLink ;
//alert("Single File " + strfileNameLink);
openFile(strfileNameLink);
}
}
else
{
// alert("No Link to File.");
openFile("File cannot be found - opening today's Job Status view.");
}
}
function FindMatchingFile(strMatchCode, strFileName)
{
var arrItemsCodes = strFileName.split("_");
var strCodes = arrItemsCodes[arrItemsCodes.length-1]
var arrMatchCode = strCodes.split(".");
var strCode = arrMatchCode[0]
if (strMatchCode == strCode)
{
openFile(strFileName);
return true;
}
else
{
return false;
}
}
function openFile(strFileNameToOpen)
{
if (UrlExists(strFileNameToOpen) == true)
{
var newwindow = window.open(strFileNameToOpen, 'window2', 'toolbar=yes,resizable=yes,directories=no,status=no,menubar=no');
}
else
{
alert(strFileNameToOpen);
var newwindow = window.open('/myserver/IS/Job%20Status/Forms/LogView.aspx?RootFolder=%2fmyserver%2fIS%2fJob%20Status%2fAudit%20Report%20%28Interfaces%29&FolderCTID=&View=%7b89D199F3%2d0B74%2d4EDC%2d8F69%2d1C1918B7F42B%7d', '_blank');
}
}
// function that can check whether URL returns not found 404.
function UrlExists(url)
{
// Uncomment to view full path of report that program is trying to retrieve
//alert(url);
//document.all.Report_Name_Retrieved.innerHTML = "Report Name : " + url;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
var http = new XMLHttpRequest();
}
else
{// code for IE6, IE5
var http = new ActiveXObject("Microsoft.XMLHTTP");
}
var http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
return http.status!=404;
}
function displayFile(strData, bWriteStart, bWriteEnd, sModified, sCodeMatch)
{
//alert(strData);
var statusMessagesArray = strData.split('\n');
var strOutput = "";
var sReturn = "";
// Check if it is beginning of items to show.
if (bWriteStart == true)
{
strOutput = "<ul class='statusMessage'>";
gOutPutHTMLString = strOutput;
}
// Build the HTML output for the items
if (statusMessagesArray.length > 1)
{
for (var i = 0; i < (statusMessagesArray.length-1); i++)
{
//if ($("statusMessagesArray[i]:contains('Completed')"))
if (statusMessagesArray[i].toLowerCase().indexOf('completed') > 0)
{
strOutput = strOutput + "<li class='completed'><a href='/myserver/IS/Job%20Status/Forms/LogView.aspx?RootFolder=%2fmyserver%2fIS%2fJob%20Status%2fAudit%20Report%20%28Interfaces%29&FolderCTID=&View=%7b89D199F3%2d0B74%2d4EDC%2d8F69%2d1C1918B7F42B%7d' '_blank'>";
strOutput = strOutput + statusMessagesArray[i];
strOutput = strOutput + "</a></li>";
}
else
{
//alert(sModified);
//getJobStatusFiles(sModified);
//alert("1 " + gJobStatusFileURLPath);
//alert(this.gJobStatusFileURLPath);
//strOutput = strOutput + "<li class='error'><a href='/myserver/IS/Job%20Status/Forms/LogView.aspx?RootFolder=%2fmyserver%2fIS%2fJob%20Status%2fAudit%20Report%20%28Interfaces%29&FolderCTID=&View=%7b89D199F3%2d0B74%2d4EDC%2d8F69%2d1C1918B7F42B%7d' target='_blank'>";
strOutput = strOutput + "<li class='error'><a href='JavaScript:getJobStatusFiles('" + sModified + "','" + sCodeMatch +"');'>";
strOutput = strOutput + statusMessagesArray[i];
strOutput = strOutput + "</a></li>";
}
}
}
else
{
if (statusMessagesArray.length == 1)
{
if (statusMessagesArray[0].toLowerCase().indexOf('completed') > 0)
{
strOutput = strOutput + "<li class='completed'><a href='/myserver/IS/Job%20Status/Forms/LogView.aspx?RootFolder=%2fmyserver%2fIS%2fJob%20Status%2fAudit%20Report%20%28Interfaces%29&FolderCTID=&View=%7b89D199F3%2d0B74%2d4EDC%2d8F69%2d1C1918B7F42B%7d' '_blank'>";
strOutput = strOutput + statusMessagesArray[0];
strOutput = strOutput + "</a></li>";
}
else
{
//alert(sModified);gJobStatusFileURLPath
//getJobStatusFiles(sModified);
//alert("2" + gJobStatusFileURLPath.responseXML);
//strOutput = strOutput + "<li class='error'><a href='/myserver/IS/Job%20Status/Forms/LogView.aspx?RootFolder=%2fmyserver%2fIS%2fJob%20Status%2fAudit%20Report%20%28Interfaces%29&FolderCTID=&View=%7b89D199F3%2d0B74%2d4EDC%2d8F69%2d1C1918B7F42B%7d' target='_blank'>";
//alert(this.gJobStatusFileURLPath);
strOutput = strOutput + "<li class='error'><a href='JavaScript:getJobStatusFiles('" + sModified + "','" + sCodeMatch + "');'>";
strOutput = strOutput + statusMessagesArray[0];
strOutput = strOutput + "</a></li>";
}
}
}
//alert(giFileCount + " " + nCurrentCount);
// Check if need to end the UL
if (bWriteEnd == true)
{
//alert(strOutput)
strOutput = strOutput + "</ul>";
//document.getElementById("StatusMessages").innerHTML = document.getElementById("StatusMessages").innerHTML + strOutput;
gOutPutHTMLString = gOutPutHTMLString + strOutput;
}
else
{
//alert(strOutput)
//document.getElementById("StatusMessages").innerHTML = document.getElementById("StatusMessages").innerHTML + strOutput;
gOutPutHTMLString = gOutPutHTMLString + strOutput;
}
// write the HTML into the DIV
document.getElementById("StatusMessages").innerHTML = gOutPutHTMLString;
}
</script>
</head>
<BODY>
<div id="StatusMessages" style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; margin-left:0px">
</div>
<script type="text/javascript">
</script>
</BODY></html>