<?

include dirname(__FILE__).'/../includes/config.php';



#if ($_POST['pwd'] != '') setcookie('password', strtoupper(md5($_POST['pwd'])),0,'/');

if ($_POST['pwd'] != '') setcookie('password', strtoupper(md5($_POST['pwd'])),0,'/', $server);





if ((strtoupper($_COOKIE['password']) != strtoupper(md5(ADMIN_PASS))) And ( strtoupper(md5($_POST['pwd'])) != strtoupper(md5(ADMIN_PASS)))){

echo "<center>Please Enter Your Password: <p> <form method=post><input type=password name=pwd size=20><p><input type=submit value='Go &raquo;'></center>";

exit();

}

?>
<?php



session_start();



if(!empty($_REQUEST['action'])){ $action=$_REQUEST['action']; } else { $action=''; }



if ($action == 'remove')

{

$lines=array();

$lines=file(dirname(__FILE__).'/../data/links.dat');

unset($lines[$_GET['id']]);

$lines = implode('',$lines);

$fp = fopen(dirname(__FILE__).'/../data/links.dat','wb') or problem('Can\'t write to links file.');

fputs($fp,$lines);

fclose($fp);

done('<font color="#008000"><b>Link Deleted<b></font>');

} elseif ($action == 'check'){

$lines=array();

$lines=file(dirname(__FILE__).'/../data/links.dat');

$site_url =strtolower(DOMAIN_NAME);

$i=1;

$rewrite=0;

echo <<<EOC

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">

<link rel="STYLESHEET" type="text/css" href="style.css">

<title>Checking reciprocal links...</title>

</head>

<body>

EOC;

foreach($lines as $thisline) {

list($name,$email,$title,$url,$recurl,$description)=explode("\t",$thisline);

echo "<p>Checking link N. <b>$i</b>...<br>\n";

echo "-&gt; Link URL: $url<br>\n";

if ($recurl == 'http://nolink'){

echo '<font color="#008000">No reciprocal link required for this link.</font><br><br>';

echo '- - - - - - - - - - - - - - - - - - - - - - - - - - - -</p>';

$i++;

flush();

continue;

} else {

echo "-&gt; Reciprocal URL: $recurl<br>\n";

}

echo '-&gt; Opening and reading reciprocal URL ';

$html = @file_get_contents($recurl) or $html='NO';

if ($html == 'NO')

{

if (empty($_POST['docantopen']))

{

echo '<br><font color="#FF6600">Unable to load reciprocal url.</font><br><br>Owner (click on name for e-mail): <a href="mailto:'.$email.'">'.$name.'</a><br>';

}

else

{

echo '<br><font color="#FF0000">Unable to load reciprocal url.</font><br><br>Removing link ...<br>';

unset($lines[$i-1]);

$rewrite=1;

}

}

else

{

$html=strtolower($html);

if (strstr($html,$site_url))

{

echo '<br><font color="#008000">'.DOMAIN_NAME.' was found in HTML.</font><br><br>';

}

elseif (empty($_POST['dowhat']))

{

echo '<br><font color="#FF0000">Link not found.</font><br><br>Owner (click on name for e-mail): <a href="mailto:'.$email.'">'.$name.'</a><br>';

}

else

{

echo '<br><font color="#FF0000">Link not found.</font><br><br>Removing link ...<br>';

unset($lines[$i-1]);

$rewrite=1;

}

}

$i++;

echo '- - - - - - - - - - - - - - - - - - - - - - - - - - - -</p>';

flush();

}



if ($rewrite == 1)

{

$lines = implode('',$lines);

$fp = fopen(dirname(__FILE__).'/../data/links.dat','wb') or problem('Can\'t write to links file.');

fputs($fp,$lines);

fclose($fp);

}



echo <<<EOC

<p>&nbsp;</p>

<p><b>Finished.</b></p>

<p><a href="linkadmin.php?action=main">Back to main page</a></p>

</body>

</html>

EOC;



exit();

	}

elseif ($action == 'add')

	{



global $settings;



$name=$_POST['name'];

$email=$_POST['email'];

$title=$_POST['title'];

$url=$_POST['url'];

$recurl=$_POST['recurl'];

if ($recurl != 'http://nolink') {

$html = @file_get_contents($recurl) or die('Can\'t Load URL');

$html = strtolower($html);

$site_url =strtolower(DOMAIN_NAME);

if (!strstr($html,$site_url)) {

problem('Your URL (<a href="'.DOMAIN_NAME.'">'.DOMAIN_NAME.

'</a>) wasn\'t found on the reciprocal links page (<a href="'.$recurl.

'">'.$recurl.'</a>).<br><br>If you don\'t require a reciprocal link from this website please set reciprocal URL to <b>http://nolink</b>');

}

}



$url=str_replace('&amp;','&',$url);

$recurl=str_replace('&amp;','&',$recurl);



$description=$_POST['description'];

$lines=@file(dirname(__FILE__).'/../data/links.dat');

if (count($lines)>MAX_LINKS) {

die('No More Links Can Be Added');

}



$replacement = "$name\t$email\t$title\t$url\t$recurl\t$description\n";



$fp = fopen(dirname(__FILE__).'/../data/links.dat','ab') or problem('Can\'t write to links file.');

fputs($fp,$replacement);

fclose($fp);

done('<font color="#008000"><b>The URL '.$url.' was successfully added to your links page</b></font>');	}

elseif ($action == 'main')

{

mainpage();

}

else {mainpage();}

exit();



function mainpage($notice='') {

global $settings;

?>

<link rel="STYLESHEET" type="text/css" href="style.css">

<title>Admin Area: Links Manager</title>

<script language="Javascript" type="text/javascript"><!--

function doconfirm(message) {

	if (confirm(message)) {return true;}

    else {return false;}

}

//-->

</script>

</head>

<body>

<fieldset>

  <legend>Comments Administration</legend>

  Please <a href="index.php">Click Here</a> to administer the article comments.

</fieldset>

<br><br>

<fieldset>

  <legend>Links Manager Administration</legend>

<div align="center"><center>

<table border="0" width="700" cellpadding="5">

<tr></td>

</tr>

<tr>

<td class="vmes">

<?php

$lines=array();

$lines=file(dirname(__FILE__).'/../data/links.dat');



if (count($lines)==0)

{

echo '<p>You don\'t have any links yet.</p>';

}

else

{

echo '<table border="0">';

$i=0;

foreach ($lines as $thisline)

{

$thisline=trim($thisline);

if (!empty($thisline)) {

list($name,$email,$title,$url,$recurl,$description)=explode("\t",$thisline);

echo '<tr>

<td valign="top">[<a href="linkadmin.php?action=remove&id='.$i.'" onclick="return doconfirm(\'Are you sure you want to remove this link? This cannot be undone.\');">Delete</a>]</td>

<td valign="top"><a href="'.$url.'" target="_blank">'.$title.'</a> - '.$description.'</td>

</tr>';

$i++;

}

}

echo '</table>';

}

?>

<hr>

<form action="linkadmin.php" method="POST">

<p>Check reciprocal links</p>

<p>This will check the links for a reciprocal url.</p>

<p>What to do if the reciprocal link is not found:</p>

<ul>

<input type="radio" name="dowhat" value="1">Delete<br>

<input type="radio" name="dowhat" value="0" checked>Don't delete</ul>

<p>What to do if the reciprocal URL can't be opened (is not available):</b></p>

<ul>

<input type="radio" name="docantopen" value="1">Delete<br>

<input type="radio" name="docantopen" value="0" checked>Don't delete</ul>

<input type="hidden" name="action" value="check"></p>

<p><input type="submit" value=" Check links "></p>

</form>

<hr>

<form action="linkadmin.php" method="POST">

<p>Add a link</p>

<p>Here you can manually add links to your links.php file. A link-back check will not be used.</p>

<p>If you don't want a reciprocal link from this website please type "http://nolink" in the "Reciprocal URL" field.

<input type="hidden" name="action" value="add"></p>

<table border="0">

<tr>

<td>Owner name:</td>

<td><input type="text" name="name" maxlength="50"></td>

</tr>

<tr>

<td>Owner e-mail:</td>

<td><input type="text" name="email" maxlength="50"></td>

</tr>

<tr>

<td>Website title:</td>

<td><input type="text" name="title" maxlength="50"></td>

</tr>

<tr>

<td>Website URL:</td>

<td><input type="text" name="url" maxlength="100" value="http://" size="40"></td>

</tr>

<tr>

<td>URL with reciprocal link:</td>

<td><input type="text" name="recurl" maxlength="100" value="http://" size="40"></td>

</tr>

</table>



<p>Website description:<br>

<input type="text" name="description" maxlength="200" size="50"></p>



<p><input type="submit" value=" Add this link "></p>

</form>

<td align="center" class="copyright"></td>

</tr>

</table>

</div></center>

</fieldset>

</body>

</html>

<?php

exit();

}

// END mainpage()



// START login()

function login() {

global $settings;

?>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">

<link rel="STYLESHEET" type="text/css" href="style.css">

<title>Admin Area: Links Manager</title>

</head>

<body>

<div align="center"><center>

<table border="0" width="700">

<tr>

<td align="center" class="glava"></td>

</tr>

<tr>

<td class="vmes"><p>&nbsp;</p>

<div align="center"><center>

<table width="400"> <tr>

<td align="center" class="head">Enter admin panel</td>

</tr>

<tr>

<td align="center" class="dol"><form method="POST" action="linkadmin.php"><p>&nbsp;<br><b>Please type in your admin password</b><br><br>

<input type="password" name="pass" size="20"><input type="hidden" name="action" value="login"></p>

<p><input type="submit" name="enter" value="Enter admin panel"></p>

</form>

</td>

</tr> </table>

</div></center>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

</td>

</tr>

<tr>



<td align="center" class="copyright"></td>

</tr>

</table>

</div></center>

</body>

</html>

<?php

exit();

}



function problem($myproblem) {

global $settings;

?>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">

<link rel="STYLESHEET" type="text/css" href="style.css">

<title>Admin Area: Links Manager</title>

</head>

<body>

<div align="center"><center>

<table border="0" width="700">

<tr>

<td align="center" class="glava"></td>

</tr>

<tr>

<td class="vmes"><p>&nbsp;</p>

<div align="center"><center>

<table width="400"> <tr>

<td align="center" class="head">ERROR</td>

</tr>

<tr>

<td align="center" class="dol">

<form>

<p>&nbsp;</p>

<p><b>An error occured:</b></p>

<p><?php echo($myproblem); ?></p>

<p>&nbsp;</p>

<p><a href="javascript:history.go(-1)">Back to the previous page</a></p>

<p>&nbsp;</p>

</form>

</td>

</tr> </table>

</div></center>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

</td>

</tr>

<tr>

<td align="center" class="copyright"></td>

</tr>

</table>

</div></center>

</body>

</html>

<?php

exit();

}



function done($message) {

global $settings;

?>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">

<link rel="STYLESHEET" type="text/css" href="style.css">

<title>Admin Area: Links Manager</title>

</head>

<body>

<div align="center"><center>

<table border="0" width="700">

<tr>

<td align="center" class="glava"></td>

</tr>

<tr>

<td class="vmes"><p>&nbsp;</p>

<div align="center"><center>

<table width="400"> <tr>

<td align="center" class="head">&nbsp;</td>

</tr>

<tr>

<td align="center" class="dol">

<form>

<p>&nbsp;</p>

<p><?php echo($message); ?></p>

<p>&nbsp;</p>

<p><a href="linkadmin.php?action=main">Click to continue</a></p>

<p>&nbsp;</p>

</form>

</td>

</tr> </table>

</div></center>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

</td>

</tr>

<tr>

<td align="center" class="copyright"></td>

</tr>

</table>

</div></center>

</body>

</html>

<?php

exit();

}

?>