<?php
// $Id: broken.php,v 1.5 2005/10/28 11:56:02 ohwada Exp $

// 2005-10-14 K.OHWADA
// BUG 3095: the number of links does not change, if delete link
// use del_link_vote_comm_catlink_by_lid($lid)

// 2005-09-04 K.OHWADA
// BUG 2932: dont work correctly when register_long_arrays = off

//=========================================================
// admin broken
// use class weblinksCategory, weblinksLink
// divid this file from index.php
// 2004/01/14 K.OHWADA
//=========================================================

function listBrokenLinks()
{
   	global $xoopsDB, $eh;
	global $tbl_category, $tbl_link, $tbl_broken, $tbl_votedate;

	$records1 = $tbl_broken->getRowsGroupLid();
   	$totalbrokenlinks = count($records1);

	xoops_cp_header();
	echo "<h4>"._WLS_WEBLINKSCONF."</h4>";
	print_index();
	echo "<h4>"._WLS_BROKENREPORTS." ($totalbrokenlinks)</h4><br />";

   	if ( $totalbrokenlinks == 0 ) 
   	{
		echo _WLS_NOBROKEN;
		echo"</td></tr></table>";
		xoops_cp_footer();
		return;
    } 

    echo "<center>
	"._WLS_IGNOREDESC."<br />
	"._WLS_DELETEDESC."</center><br /><br /><br />";
    $colorswitch="dddddd";
	echo "<table align=\"center\" width=\"90%\">";

    echo "
    <tr>
    <td><b>Link Name</b></td>
    <td><b>" ._WLS_REPORTER."</b></td>
    <td><b>" ._WLS_LINKSUBMITTER."</b></td>
    <td><b>" ._WLS_IGNORE."</b></td>
    <td><b>" ._EDIT."</b></td>
    <td><b>" ._WLS_DELETE."</b></td>
    </tr>";

    foreach ($records1 as $record1) 
    {
      	$lid    = $record1['lid'];
       	$sender = $record1['sender'];
       	$ip     = $record1['ip'];

		$flag = false;
		$title = '';
		$url   = '';
		$uid   = '';
        
		$record2 = $tbl_link->getRowByLid($lid);
		if ($record2)
		{
			$flag  = true;
			$title = $record2['title'];
			$url   = $record2['url'];
			$uid   = $record2['uid'];
		}

		if ( $sender != 0 ) 
		{
			$result3 = $xoopsDB->query("select uname, email from ".$xoopsDB->prefix("users")." where uid=$sender");
			list($uname, $email)=$xoopsDB->fetchRow($result3);
		}

   		$result4 = $xoopsDB->query("select uname, email from ".$xoopsDB->prefix("users")." where uid='$uid'");
   		list($owner, $owneremail)=$xoopsDB->fetchRow($result4);

		if ($flag)
   		{	echo "<tr><td bgcolor=$colorswitch><a href=$url target='_blank'>$title</a></td>";	}
   		else
   		{	echo "<tr><td bgcolor=$colorswitch><font color=red>"._WLS_ERRORNOLINK."</font></td>";	}

   		if ( $email=='' ) 
   		{	echo "<td bgcolor=\"".$colorswitch."\">".$sender." (".$ip.")";	} 
		else 
		{	echo "<td bgcolor=\"".$colorswitch."\"><a href=\"mailto:".$email."\">".$uname."</a> (".$ip.")";	}
   		
   		echo "</td>";
   		
   		if ( $owneremail == '' ) 
   		{	echo "<td bgcolor=\"".$colorswitch."\">".$owner."";	}
   		else 
   		{	echo "<td bgcolor=\"".$colorswitch."\"><a href=\"mailto:".$owneremail."\">".$owner."</a>";	}

		if ($flag)
		{
			echo "</td><td bgcolor='$colorswitch' align='center'>\n";
			echo myTextForm("index.php?op=ignoreBrokenLinks&lid=$lid" , "X");
			echo "</td><td bgcolor='$colorswitch' align='center'>\n";
			echo myTextForm("link_manage.php?op=modLink&lid=$lid" , "X");
			echo "</td><td align='center' bgcolor='$colorswitch'>\n";
			echo myTextForm("index.php?op=delBrokenLinks&lid=$lid" , "X");
			echo "</td>\n";
		}
		else
		{
			echo "</td><td bgcolor='$colorswitch' align='center'>\n";
			echo myTextForm("index.php?op=ignoreBrokenLinks&lid=$lid" , "X");
			echo "</td>\n";
			echo "<td align='center'>---</td>\n";
			echo "<td align='center'>---</td>\n";
		}
		echo "</tr>\n";

    	if ( $colorswitch == "#dddddd" ) $colorswitch="#ffffff";
		else                             $colorswitch="#dddddd";

	}

	echo "</table>";
	xoops_cp_footer();
}

function print_index()
{
	echo "<table width='80%' border='0' cellspacing='1' class='outer'>";
	echo "<tr class='odd'><td>";
	echo " - <a href='index.php'>"._WEBLINKS_ADMIN_INDEX."</a>";
	echo "<br /><br />\n";
	echo " - <a href='link_list.php'>"._WEBLINKS_ADMIN_LINK_LIST."</a>";
	echo "<br /><br />\n";
	echo"</td></tr></table>\n";
	echo "<br />\n";
}

function delBrokenLinks()
{
	global $eh;
	global $tbl_category, $tbl_link, $tbl_broken, $tbl_votedate;

// BUG 2932: dont work correctly when register_long_arrays = off
	$lid = get_get_int('lid');

	$tbl_broken->deleteByLid($lid) or $eh->show("0013");

// BUG 3095: the number of links does not change, if delete link
//	$tbl_link->delete($lid)        or $eh->show("0013");
	del_link_vote_comm_catlink_by_lid($lid);

    redirect_header("index.php",1,_WLS_LINKDELETED);
	exit();
}

function ignoreBrokenLinks()
{
	global $eh;
	global $tbl_category, $tbl_link, $tbl_broken, $tbl_votedate;

// BUG 2932: dont work correctly when register_long_arrays = off
	$lid = get_get_int('lid');

	$tbl_broken->deleteByLid($lid) or $eh->show("0013");

    redirect_header("index.php",1,_WLS_BROKENDELETED);
	exit();
}

?>
