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

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

// 2004-11-28 K.OHWADA
// write fair, delete unnecessary comments

// 2004/08/10 K.OHWADA
// enable to install this module two or more. 

//================================================================
// submit broken link
// use class weblinksBroken
// 2004/01/14 K.OHWADA
//================================================================

include "header.php";

$tbl_broken   =& table_broken::getInstance();

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

if ( !empty($submit) ) 
{
	if (empty($xoopsUser)) 
	{	$sender = 0;	} 
	else 
	{	$sender = $xoopsUser->getVar('uid');	}

	if ($sender != 0) 
	{

// Check if REG user is trying to report twice.
		$count = $tbl_broken->getNumByLidSender($lid,$sender);
       	if ($count > 0) 
       	{
			redirect_header("index.php", 2, _WLS_ALREADYREPORTED);
			exit();
        }
  	}
  	else 
  	{
// Check if the sender is trying to vote more than once.
		$count = $tbl_broken->getNumByLidIp($lid, $server_remote_addr);
    	if ($count > 0) 
    	{
			redirect_header("index.php", 2, _WLS_ALREADYREPORTED);
			exit();
    	}
	}

	$tbl_broken->insert($lid, $sender, $server_remote_addr);

	$tags = array();
	$tags['BROKENREPORTS_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php?op=listBrokenLinks';
	$notification_handler =& xoops_gethandler('notification');
	$notification_handler->triggerEvent('global', 0, 'link_broken', $tags);
	redirect_header("index.php",2,_WLS_THANKSFORINFO);
	exit();
}
else 
{
// enable to install this module two or more. 
	$xoopsOption['template_main'] = $MODULE_DIRNAME."_brokenlink.html";

	include XOOPS_ROOT_PATH.'/header.php';

	$record = $tbl_link->getRowByLid($lid);
	$title  = $myts->htmlSpecialChars( $record['title'] );

	assignIndex();
	$xoopsTpl->assign('lang_reportbroken',  _WLS_REPORTBROKEN);
	$xoopsTpl->assign('lang_thanksforhelp', _WLS_THANKSFORHELP);
	$xoopsTpl->assign('lang_forsecurity',   _WLS_FORSECURITY);
	$xoopsTpl->assign('lang_cancel',        _WLS_CANCEL);

	$xoopsTpl->assign('link_id',    $lid);
	$xoopsTpl->assign('link_title', $title);

	include_once XOOPS_ROOT_PATH.'/footer.php';
}
?>
