Code:
<?php
error_reporting(E_ALL ^ E_NOTICE);
require_once('settings.php');
if($settings['system'] == 2) {$settings['newline']="\r\n";}
elseif($settings['system'] == 3) {$settings['newline']="\r";}
else {$settings['newline']="\n";}
$a=$_REQUEST['a'];
printTopHTML();
if (!(empty($a))) {
if($a=="sign") {
printSign();
} elseif($a=="delete") {
$num=gbook_isNumber($_REQUEST['num'],"Invalid ID");
confirmDelete($num);
} elseif($a=="add") {
$comments=gbook_input($_REQUEST['comments'],"Molim unesite Vaš oglas!");
if ($settings['autosubmit'] == 1)
{
if ($_SESSION['checked'] == "N")
{
print_secimg($comments);
}
elseif ($_SESSION['checked'] == "P")
{
$_SESSION['checked'] = "N";
$secnumber=gbook_isNumber($_REQUEST['secnumber']);
if(empty($secnumber)) {print_secimg($comments,1);}
$secimg=check_secnum($secnumber,$_SESSION['checksum']);
if (empty($secimg))
{print_secimg($comments,2);}
}
else {problem("Internal script error. Wrong session parameters!");}
}
addEntry($comments);
} elseif($a=="confirmdelete") {
$pass=gbook_input($_REQUEST['pass'],"Molim unesite Vaš password");
$num=gbook_isNumber($_REQUEST['num'],"Invalid ID");
doDelete($pass,$num);
} else {
problem("This is not a valid action!");
}
}
$page=gbook_isNumber($_REQUEST['page']);
if ($page>0) {
$start=($page*10)-9;$end=$start+9;
} else {
$page=1;$start=1;$end=10;
}
$filesize=filesize($settings['logfile']);
$fp = @fopen($settings['logfile'],"rb") or problem("Can't open the log file ($settings[logfile]) for reading! CHMOD this file to 666 (rw-rw-rw)!");
$content=@fread($fp,$filesize);
fclose($fp);
$content = trim(chop($content));
$lines = explode($settings['newline'],$content);
if ($filesize == 0) {$total=0;}
else {
$total = count($lines);
if ($end > $total) {$end=$total;}
$pages = ceil($total/10);
echo '<p>Prikazujem stranicu '.$page.' od '.$pages.'. Stranice: ';
for ($i=1; $i<=$pages; $i++) {
if($i == $page) {echo "<b>$i</b>\n";}
else {echo '<a href="gbook.php?page='.$i.'">'.$i.'</a> ';}
}
}
echo '</p>
<table border="0" cellspacing="0" cellpadding="2" width="95%" class="entries">';
if ($filesize == 0) {
echo '<tr>
<td>Još nema oglasa!</td>
</tr>';
}
else {printEntries($lines,$start,$end);}
echo '</table>';
if ($filesize != 0) {
echo '<p>Stranice: ';
for ($i=1; $i<=$pages; $i++) {
if($i == $page) {echo "<b>$i</b>\n";}
else {echo '<a href="gbook.php?page='.$i.'">'.$i.'</a> ';}
}
}
printCopyHTML();
printDownHTML();
exit();
// >>> START FUNCTIONS <<< //
function doDelete($pass,$num) {
global $settings;
if ($pass != $settings[apass]) {problem("Pogrešan password! Oglas nije izbrisan.","1");}
$filesize=filesize($settings['logfile']);
$fp = @fopen($settings['logfile'],"rb") or problem("Can't open the log file ($settings[logfile]) for reading! CHMOD this file to 666 (rw-rw-rw)!");
$content=@fread($fp,$filesize);
fclose($fp);
$content = trim(chop($content));
$lines = explode($settings['newline'],$content);
unset($lines[$num]);
$fp = fopen($settings['logfile'],"wb") or problem("Couldn't open links file ($settings[logfile]) for writing! Please CHMOD all $settings[logfile] to 666 (rw-rw-rw)!");
foreach ($lines as $thisline) {
$thisline .= $settings['newline'];
fputs($fp,$thisline);
}
fclose($fp);
?>
<p> </p>
<p> </p>
<p><b>Odabrani oglas je uspješno uklonjen!</b></p>
<p><a href="gbook.php?page=1">Kliknite ovdje za nastavak</a></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<?php
printCopyHTML();
printDownHTML();
exit();
} // END doDelete
function confirmDelete($num) {
?>
<p> </p>
<p> </p>
<form action="gbook.php" method="POST"><input type="hidden" name="a" value="confirmdelete">
<input type="hidden" name="num" value="<?php echo($num); ?>">
<p><b>Molim unesite vaš password:</b><br>
<input type="password" name="pass" size="20"></p>
<p><b>Jeste li sigurni da želite izbrisati odabrani oglas!</b></p>
<p><input type="submit" value="Da, izbriši ovaj oglas!"> | <a href="gbook.php">NE, predomislio sma se</a></p>
</form>
<p> </p>
<p> </p>
<?php
printCopyHTML();
printDownHTML();
exit();
} // END confirmDelete
function addEntry($comments) {
global $settings;
/* This part will help prevent multiple submissions */
if ($settings['one_per_session'] && $_SESSION['add'])
{
problem("You may only submit this guestbook once per session!");
}
$delimiter="\t";
$added=date ("F j, Y");
$comments_nosmileys=$comments;
$comments = str_replace("\r\n","<br>",$comments);
$comments = str_replace("\n","<br>",$comments);
$comments = str_replace("\r","<br>",$comments);
$comments = wordwrap($comments,$settings['max_word'],'<br>',1);
$addline = "$comments$delimiter$added$delimiter$settings[newline]";
$fp = @fopen($settings['logfile'],"rb") or problem("Can't open the log file ($settings[logfile]) for reading! CHMOD this file to 666 (rw-rw-rw)!");
$links = @fread($fp,filesize($settings['logfile']));
fclose($fp);
$addline .= $links;
$fp = fopen($settings['logfile'],"wb") or problem("Couldn't open links file ($settings[logfile]) for writing! Please CHMOD all $settings[logfile] to 666 (rw-rw-rw)!");
fputs($fp,$addline);
fclose($fp);
/* Register this session variable */
$_SESSION['add']=1;
?>
<p> </p>
<p> </p>
<p><b>Vaš oglas je uspješno postavljen!</b></p>
<p><a href="gbook.php?page=1">Kliknite ovdje za nastavak</a></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<?php
printCopyHTML();
printDownHTML();
exit();
} // END addEntry
function printSign() {
global $settings;
?>
<h3 align="center">Dodaj oglas</h3>
<form action="gbook.php" method="POST" name="form"><input type="hidden" name="a" value="add">
<table class="entries" cellspacing="0" cellpadding="4" border="0">
<tr>
<td>
<p align="center"><b>Oglas:</b><br>
<textarea name="comments" rows="20" cols="80"></textarea> </p>
<p align="center"><input type="submit" value=" Postavi moj oglas "></p>
</td>
</tr>
</table>
</form>
<?php
printCopyHTML();
printDownHTML();
exit();
} // END printSign
function printEntries($lines,$start,$end) {
$start=$start-1;
$end=$end-1;
$delimiter="\t";
for ($i=$start;$i<=$end;$i++) {
list($comment,$added)=explode($delimiter,$lines[$i]);
echo '
<tr>
<td class="upper" width="100%"><b>Oglas:</b></td>
</tr>
<tr>
<td width="100%">';
echo $comment;
echo '<hr>
<font class="smaller">Postavljeno: '.$added.'
<a href="gbook.php?a=delete&num='.$i.'"><img src="images/delete.gif" width="16" height="14" border="0" alt="Obriši ovaj oglas"></a></font>
</td>
</tr>
';
}
} // END printEntries
function problem($myproblem,$backlink="1") {
$html = '<p> </p>
<p> </p>
<p align="center"><b>Greška</b></p>
<p align="center">'.$myproblem.'</p>
<p> </p>
';
if ($backlink) {
$html .= '<p align="center"><a href="Javascript:history.go(-1)">Nazad na prethodnu stranicu</a></p>';
}
$html .= '<p> </p> <p> </p>';
echo $html;
printCopyHTML();
printDownHTML();
exit();
} // END problem
function printNoCache() {
header("Expires: Mon, 26 Jul 2000 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
} // END printNoCache
function printTopHTML() {
global $settings;
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>'.$settings['gbook_title'].'</title>
<meta content="text/html; charset=windows-1250">
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
';
include_once 'header.txt';
echo '<h3 align="center">'.$settings['gbook_title'].'</h3>
<p align="center"><a href="'.$settings['website_url'].'">Nazad na '.$settings['website_title'].'</a>
| <a href="gbook.php">Pregledaj oglasnu ploču</a>
| <a href="gbook.php?a=sign">Postavi oglas</a></p>
<div align="center">
<center>
';
} // END printTopHTML
function printDownHTML() {
global $settings;
echo '</center>
</div>';
include_once 'footer.txt';
echo '</body>
</html>';
} // END printDownHTML
function printCopyHTML() {
global $settings;
echo rawurldecode('%3Chr%20width%3D%2295%25%22%3E%0D%0A%3C%21--%0D%0AChanging%20the%20%22Powered%20by%22%20credit%20sentence%20without%20purchasing%20a%20licence%20is%20illegal%21%0D%0APlease%20visit%20http%3A%2F%2Fwww.phpjunkyard.com%2Fcopyrigh...3EPHP%20guestbook%3C%2Fa%3E%20').$settings['verzija'].rawurldecode('%20from%0D%0A%3Ca%20href%3D%22http%3A%2F%2Fwww.phpjunkyard.com%2F%22%20ta...%2Fa%3E%3C%2Ffont%3E%3C%2Fp%3E');
} // END printCopyHTML
function gbook_input($in,$error=0) {
$in = trim($in);
if (strlen($in))
{
$in = htmlspecialchars($in);
}
elseif ($error)
{
problem($error);
}
return stripslashes($in);
} // END gbook_input()
function gbook_isNumber($in,$error=0) {
$in = trim($in);
if (preg_match("/\D/",$in) || $in=="")
{
if ($error)
{
problem($error);
}
else
{
return '0';
}
}
return $in;
} // END gbook_isNumber()
?>
<?php
error_reporting(E_ALL ^ E_NOTICE);
require_once('settings.php');
if($settings['system'] == 2) {$settings['newline']="\r\n";}
elseif($settings['system'] == 3) {$settings['newline']="\r";}
else {$settings['newline']="\n";}
$a=$_REQUEST['a'];
printTopHTML();
if (!(empty($a))) {
if($a=="sign") {
printSign();
} elseif($a=="delete") {
$num=gbook_isNumber($_REQUEST['num'],"Invalid ID");
confirmDelete($num);
} elseif($a=="add") {
$comments=gbook_input($_REQUEST['comments'],"Molim unesite Vaš oglas!");
if ($settings['autosubmit'] == 1)
{
if ($_SESSION['checked'] == "N")
{
print_secimg($comments);
}
elseif ($_SESSION['checked'] == "P")
{
$_SESSION['checked'] = "N";
$secnumber=gbook_isNumber($_REQUEST['secnumber']);
if(empty($secnumber)) {print_secimg($comments,1);}
$secimg=check_secnum($secnumber,$_SESSION['checksum']);
if (empty($secimg))
{print_secimg($comments,2);}
}
else {problem("Internal script error. Wrong session parameters!");}
}
addEntry($comments);
} elseif($a=="confirmdelete") {
$pass=gbook_input($_REQUEST['pass'],"Molim unesite Vaš password");
$num=gbook_isNumber($_REQUEST['num'],"Invalid ID");
doDelete($pass,$num);
} else {
problem("This is not a valid action!");
}
}
$page=gbook_isNumber($_REQUEST['page']);
if ($page>0) {
$start=($page*10)-9;$end=$start+9;
} else {
$page=1;$start=1;$end=10;
}
$filesize=filesize($settings['logfile']);
$fp = @fopen($settings['logfile'],"rb") or problem("Can't open the log file ($settings[logfile]) for reading! CHMOD this file to 666 (rw-rw-rw)!");
$content=@fread($fp,$filesize);
fclose($fp);
$content = trim(chop($content));
$lines = explode($settings['newline'],$content);
if ($filesize == 0) {$total=0;}
else {
$total = count($lines);
if ($end > $total) {$end=$total;}
$pages = ceil($total/10);
echo '<p>Prikazujem stranicu '.$page.' od '.$pages.'. Stranice: ';
for ($i=1; $i<=$pages; $i++) {
if($i == $page) {echo "<b>$i</b>\n";}
else {echo '<a href="gbook.php?page='.$i.'">'.$i.'</a> ';}
}
}
echo '</p>
<table border="0" cellspacing="0" cellpadding="2" width="95%" class="entries">';
if ($filesize == 0) {
echo '<tr>
<td>Još nema oglasa!</td>
</tr>';
}
else {printEntries($lines,$start,$end);}
echo '</table>';
if ($filesize != 0) {
echo '<p>Stranice: ';
for ($i=1; $i<=$pages; $i++) {
if($i == $page) {echo "<b>$i</b>\n";}
else {echo '<a href="gbook.php?page='.$i.'">'.$i.'</a> ';}
}
}
printCopyHTML();
printDownHTML();
exit();
// >>> START FUNCTIONS <<< //
function doDelete($pass,$num) {
global $settings;
if ($pass != $settings[apass]) {problem("Pogrešan password! Oglas nije izbrisan.","1");}
$filesize=filesize($settings['logfile']);
$fp = @fopen($settings['logfile'],"rb") or problem("Can't open the log file ($settings[logfile]) for reading! CHMOD this file to 666 (rw-rw-rw)!");
$content=@fread($fp,$filesize);
fclose($fp);
$content = trim(chop($content));
$lines = explode($settings['newline'],$content);
unset($lines[$num]);
$fp = fopen($settings['logfile'],"wb") or problem("Couldn't open links file ($settings[logfile]) for writing! Please CHMOD all $settings[logfile] to 666 (rw-rw-rw)!");
foreach ($lines as $thisline) {
$thisline .= $settings['newline'];
fputs($fp,$thisline);
}
fclose($fp);
?>
<p> </p>
<p> </p>
<p><b>Odabrani oglas je uspješno uklonjen!</b></p>
<p><a href="gbook.php?page=1">Kliknite ovdje za nastavak</a></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<?php
printCopyHTML();
printDownHTML();
exit();
} // END doDelete
function confirmDelete($num) {
?>
<p> </p>
<p> </p>
<form action="gbook.php" method="POST"><input type="hidden" name="a" value="confirmdelete">
<input type="hidden" name="num" value="<?php echo($num); ?>">
<p><b>Molim unesite vaš password:</b><br>
<input type="password" name="pass" size="20"></p>
<p><b>Jeste li sigurni da želite izbrisati odabrani oglas!</b></p>
<p><input type="submit" value="Da, izbriši ovaj oglas!"> | <a href="gbook.php">NE, predomislio sma se</a></p>
</form>
<p> </p>
<p> </p>
<?php
printCopyHTML();
printDownHTML();
exit();
} // END confirmDelete
function addEntry($comments) {
global $settings;
/* This part will help prevent multiple submissions */
if ($settings['one_per_session'] && $_SESSION['add'])
{
problem("You may only submit this guestbook once per session!");
}
$delimiter="\t";
$added=date ("F j, Y");
$comments_nosmileys=$comments;
$comments = str_replace("\r\n","<br>",$comments);
$comments = str_replace("\n","<br>",$comments);
$comments = str_replace("\r","<br>",$comments);
$comments = wordwrap($comments,$settings['max_word'],'<br>',1);
$addline = "$comments$delimiter$added$delimiter$settings[newline]";
$fp = @fopen($settings['logfile'],"rb") or problem("Can't open the log file ($settings[logfile]) for reading! CHMOD this file to 666 (rw-rw-rw)!");
$links = @fread($fp,filesize($settings['logfile']));
fclose($fp);
$addline .= $links;
$fp = fopen($settings['logfile'],"wb") or problem("Couldn't open links file ($settings[logfile]) for writing! Please CHMOD all $settings[logfile] to 666 (rw-rw-rw)!");
fputs($fp,$addline);
fclose($fp);
/* Register this session variable */
$_SESSION['add']=1;
?>
<p> </p>
<p> </p>
<p><b>Vaš oglas je uspješno postavljen!</b></p>
<p><a href="gbook.php?page=1">Kliknite ovdje za nastavak</a></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<?php
printCopyHTML();
printDownHTML();
exit();
} // END addEntry
function printSign() {
global $settings;
?>
<h3 align="center">Dodaj oglas</h3>
<form action="gbook.php" method="POST" name="form"><input type="hidden" name="a" value="add">
<table class="entries" cellspacing="0" cellpadding="4" border="0">
<tr>
<td>
<p align="center"><b>Oglas:</b><br>
<textarea name="comments" rows="20" cols="80"></textarea> </p>
<p align="center"><input type="submit" value=" Postavi moj oglas "></p>
</td>
</tr>
</table>
</form>
<?php
printCopyHTML();
printDownHTML();
exit();
} // END printSign
function printEntries($lines,$start,$end) {
$start=$start-1;
$end=$end-1;
$delimiter="\t";
for ($i=$start;$i<=$end;$i++) {
list($comment,$added)=explode($delimiter,$lines[$i]);
echo '
<tr>
<td class="upper" width="100%"><b>Oglas:</b></td>
</tr>
<tr>
<td width="100%">';
echo $comment;
echo '<hr>
<font class="smaller">Postavljeno: '.$added.'
<a href="gbook.php?a=delete&num='.$i.'"><img src="images/delete.gif" width="16" height="14" border="0" alt="Obriši ovaj oglas"></a></font>
</td>
</tr>
';
}
} // END printEntries
function problem($myproblem,$backlink="1") {
$html = '<p> </p>
<p> </p>
<p align="center"><b>Greška</b></p>
<p align="center">'.$myproblem.'</p>
<p> </p>
';
if ($backlink) {
$html .= '<p align="center"><a href="Javascript:history.go(-1)">Nazad na prethodnu stranicu</a></p>';
}
$html .= '<p> </p> <p> </p>';
echo $html;
printCopyHTML();
printDownHTML();
exit();
} // END problem
function printNoCache() {
header("Expires: Mon, 26 Jul 2000 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
} // END printNoCache
function printTopHTML() {
global $settings;
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>'.$settings['gbook_title'].'</title>
<meta content="text/html; charset=windows-1250">
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
';
include_once 'header.txt';
echo '<h3 align="center">'.$settings['gbook_title'].'</h3>
<p align="center"><a href="'.$settings['website_url'].'">Nazad na '.$settings['website_title'].'</a>
| <a href="gbook.php">Pregledaj oglasnu ploču</a>
| <a href="gbook.php?a=sign">Postavi oglas</a></p>
<div align="center">
<center>
';
} // END printTopHTML
function printDownHTML() {
global $settings;
echo '</center>
</div>';
include_once 'footer.txt';
echo '</body>
</html>';
} // END printDownHTML
function printCopyHTML() {
global $settings;
echo rawurldecode('%3Chr%20width%3D%2295%25%22%3E%0D%0A%3C%21--%0D%0AChanging%20the%20%22Powered%20by%22%20credit%20sentence%20without%20purchasing%20a%20licence%20is%20illegal%21%0D%0APlease%20visit%20http%3A%2F%2Fwww.phpjunkyard.com%2Fcopyrigh...3EPHP%20guestbook%3C%2Fa%3E%20').$settings['verzija'].rawurldecode('%20from%0D%0A%3Ca%20href%3D%22http%3A%2F%2Fwww.phpjunkyard.com%2F%22%20ta...%2Fa%3E%3C%2Ffont%3E%3C%2Fp%3E');
} // END printCopyHTML
function gbook_input($in,$error=0) {
$in = trim($in);
if (strlen($in))
{
$in = htmlspecialchars($in);
}
elseif ($error)
{
problem($error);
}
return stripslashes($in);
} // END gbook_input()
function gbook_isNumber($in,$error=0) {
$in = trim($in);
if (preg_match("/\D/",$in) || $in=="")
{
if ($error)
{
problem($error);
}
else
{
return '0';
}
}
return $in;
} // END gbook_isNumber()
?>