<?php

session_start();

include "../header.php";
include "../config.php";
include "../style.php";

$sort = $_GET["sortby"];

if( isset($_SESSION["alogin"]) ) {
?>

<script language="JavaScript">
function Inverse(form)
{
len = form.elements.length;
var i=0;
for( i=0; i<len; i++)
{
if (form.elements[i].type=='checkbox' )
{
form.elements[i].checked = !form.elements[i].checked;
}
}
return false;
}

function SelectAll(form)
{
len = form.elements.length;
var i=0;
for( i=0; i<len; i++)
{
if (form.elements[i].type=='checkbox' )
{
form.elements[i].checked = !form.elements[i].checked;
}
}
return false;
}
</script>

<table>
<tr>
<td width="15%" valign=top><br>
<? include("adminnavigation.php"); ?>
</td>
<td valign="top" align="center"><br><br>
<?
$data = "select * from jse_trafficlinklist";
$result = mysql_query( $data )
or die( "Query Failed " );

$num_rows = mysql_num_rows( $result );
?>
<center>
<font size='5'>Broken Traffic Links</font><br><br><br>
<?
echo( "<font size='4'>".$num_rows." entries found.</font><br><br>" );
?>
<b>Note:</b><br>
Please do know that some data in this list may be inaccurate and may seem to be flagged as broken but actually works. This may be because at the time the link was checked, there was a down time, maintenance or simply a very long load time.<br> There is no 100% working way to check whether an URL gets a valid response or not as some sites may take a lot longer to load. If an entry appears to work just fine while it's flagged as broken, simply press the "Ignore" button and it will be unflagged.<br><br>The list will now be displayed, please be patient as the script processes all data in meanwhile.<br><br><br>
<table><tr><td width='50' align='center' bgcolor='ccffcc'><td><td align='left'>This color means good. (Not used here.)</td></tr><tr><td width='50' align='center' bgcolor='ffcccc'><td><td align='left'>This color means bad.</td></tr></table><br><br>

<font size='4'>Below is the list of Traffic Links that gave a 404 not-found error. Please select those you want to take action against, then click one of the buttons to apply.</font><br><br><br>

<form method="POST" action="jse_dodelete.php?action=tlinks" name='tlinkslist'>
<table width='900px' cellpadding='2' cellspacing='2' align='center'>
<tr>
<td bgcolor="<? echo $contrastcolour; ?>"><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">&nbsp;</td>
<td bgcolor="<? echo $contrastcolour; ?>" width='200px'><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center>Posted By</font></center></td>
<td bgcolor="<? echo $contrastcolour; ?>" width='100px'><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center>Subject</font></center></td>
<td bgcolor="<? echo $contrastcolour; ?>" width='100px'><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center>Target URL</font></center></td>
<td bgcolor="<? echo $contrastcolour; ?>" width='200px'><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center>Date Flagged</font></center></td>
<td bgcolor="<? echo $contrastcolour; ?>" width='100px'><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center>Ignore</font></center></td>
<td bgcolor="<? echo $contrastcolour; ?>" width='100px'><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center>Delete</font></center></td>
<td bgcolor="<? echo $contrastcolour; ?>" width='100px'><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><center>Send Back</font></center></td>
</tr>
<?

while( $line = mysql_fetch_array( $result ) )
{
$id			= $line['tlinkid'];
$userid		= $line['userid'];
$subject	= $line['subject'];
$url		= $line['url'];
$flagdate	= $line['flagdate'];

$targettext = $url;
$targettext = substr($targettext, 0, 30);

$subject = substr($subject, 0, 30);

?>
<tr>
<!-- The Checkbox -->
<td bgcolor="<? echo $basecolour; ?>">
<input type="checkbox" name="id[]" value="<? echo $id; ?>">
</td>
<td bgcolor="<? echo $basecolour; ?>" width='200px'><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">
<!-- Display Posted By-->
<center><? echo( $userid ); ?></center>
</td>
<td align='center' bgcolor="<? echo $basecolour; ?>" width='100px'>
<!-- Subject -->
<?echo( $subject );?>...
</td>
<td align='center' bgcolor='ffcccc' width='100px'>
<!-- Target URL -->
<a href='sitecheck.php?url=<?echo( $url );?>' target='_blank'><?echo( $targettext );?></a>...
</td>
<!--Date Flagged-->
<td bgcolor="<? echo $basecolour; ?>" width='200px'><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">
<center>
<? echo( $flagdate ); ?>
</center>
</td>
<!--Ignore Button-->
<td bgcolor="<? echo $basecolour; ?>" width='50px' align='center'><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">
<input type="hidden" name="targeturl" value="<? echo $targeturl; ?>">
<input type="hidden" name="bannerurl" value="<? echo $bannerurl; ?>">
<input type="submit" name='button' value="Ignore">

</td>
<!--Delete Button-->
<td bgcolor="<? echo $basecolour; ?>" width='50px' align='center'><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">
<input type="hidden" name="targeturl" value="<? echo $targeturl; ?>">
<input type="hidden" name="bannerurl" value="<? echo $bannerurl; ?>">
<input type="submit" name='button' value="Delete">
</td>
<!--Send Back-->
<td bgcolor="<? echo $basecolour; ?>" width='50px' align='center'><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">
<input type="hidden" name="targeturl" value="<? echo $targeturl; ?>">
<input type="hidden" name="bannerurl" value="<? echo $bannerurl; ?>">
<input type="submit" name='button' value="Send Back">
</td>
</tr>
<?
} //return Inverse(document.banner);
?>

</center>
</table>

<table width='900px'>
<tr>
<td align='right'>
<input type="button" onClick="return Inverse(document.tlinkslist);" value="Inverse">
</td>

<td align='left'>
<input type="button" onClick="return SelectAll(document.tlinkslist);" value="Select All">
</td>
<td>
</form>
</table>
<?
echo "</td></tr></table>";
?>
<?
}
else
{
echo "Unauthorised Access!";
}

include "../footer.php";
mysql_close($dblink);
?>