2016-05-06 20:02:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2017-09-26 16:19:12 +00:00
|
|
|
* Main program file of PHPCSV Guestbook
|
2016-05-06 20:02:56 +00:00
|
|
|
* See settings.php for configuration.
|
|
|
|
* Edit page.php for change appearance.
|
|
|
|
* See license.txt for licensing information.
|
|
|
|
*/
|
|
|
|
session_start();
|
|
|
|
include "settings.php";
|
|
|
|
|
2017-01-27 10:28:04 +00:00
|
|
|
function SendMail() {
|
|
|
|
global $Titles;
|
|
|
|
global $GBnotificationmailto;
|
|
|
|
global $GBnotificationmailfrom;
|
|
|
|
$message=$_POST['name']." ".$Titles[From]." ".$_POST['from']."("
|
|
|
|
.$_POST['link'].", ".$_POST['email'].") ".$Titles[Wrote].":\r\n\r\n".$_POST['text']
|
|
|
|
."\r\n\r\n_____\r\n".$Titles[MailAdmin];
|
|
|
|
mail($GBnotificationmailto, $Titles[MailSubject], $message,
|
|
|
|
"From: ".$GBnotificationmailfrom." \r\n"."Content-type: text/plain; charset=utf-8\r\n"
|
|
|
|
."X-Mailer: PHP/".phpversion());
|
|
|
|
}
|
|
|
|
|
2016-05-06 20:02:56 +00:00
|
|
|
function ReadEntries() {
|
|
|
|
global $GBdata;
|
|
|
|
global $DataStatus;
|
|
|
|
$fhandle=fopen($GBdata,"r") or $DataStatus="empty";
|
|
|
|
for($e=0; $entrydata=fgetcsv($fhandle, 16384, ","); $e++) {
|
|
|
|
$Entries["$e"]=$entrydata;
|
|
|
|
$Entries["$e"][7]=$e+1;
|
|
|
|
}
|
|
|
|
fclose($fhandle);
|
|
|
|
if (!$Entries[0]) $DataStatus="empty";
|
|
|
|
return $Entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
function AddEntry() {
|
|
|
|
global $GBdata;
|
|
|
|
global $Titles;
|
|
|
|
global $PageStatus;
|
|
|
|
$NewEntry[name]=$_POST['name'];
|
|
|
|
$NewEntry[from]=$_POST['from'];
|
|
|
|
$NewEntry[link]=$_POST['link'];
|
|
|
|
$NewEntry[email]=$_POST['email'];
|
|
|
|
$NewEntry[text]=$_POST['text'];
|
|
|
|
$NewEntry[datetime]=time();
|
|
|
|
$NewEntry[response]="";
|
|
|
|
$fhandle=fopen($GBdata,"a");
|
|
|
|
fputcsv($fhandle,$NewEntry);
|
|
|
|
fclose($fhandle);
|
|
|
|
$PageStatus="added";
|
|
|
|
$_SESSION['captcha']="";
|
|
|
|
}
|
|
|
|
|
|
|
|
function AddEntryView() {
|
|
|
|
global $Titles;
|
|
|
|
global $Values;
|
|
|
|
global $PageStatus;
|
2017-09-27 06:26:08 +00:00
|
|
|
global $GBcaptcha;
|
2017-09-27 07:31:42 +00:00
|
|
|
global $GBtextlenght;
|
2016-05-06 20:02:56 +00:00
|
|
|
echo "<h2>",$Titles[Page],"</h2><br>\n";
|
|
|
|
if ($PageStatus=="added") echo "$Titles[Added]"; else {
|
|
|
|
$captchanumber11=rand(1, 4);
|
|
|
|
$captchanumber12=rand(0, 9);
|
|
|
|
$captchanumber21=rand(1, 4);
|
|
|
|
$captchanumber22=rand(0, 9);
|
|
|
|
$_SESSION['captcha']=md5(base64_encode(($captchanumber11.$captchanumber12)+($captchanumber21.$captchanumber22)));
|
|
|
|
echo "<form action=index.php method=post>\n";
|
|
|
|
echo " $Titles[Name]: <input type=text name=\"name\" value=\"",$Values["name"],"\" maxlength=255> ($Titles[Required])<br>\n";
|
|
|
|
echo " $Titles[City]: <input type=text name=\"from\" value=\"",$Values["from"],"\" maxlength=255><br>\n";
|
|
|
|
echo " $Titles[Link]: <input type=text name=\"link\" value=\"",$Values["link"],"\" maxlength=255><br>\n";
|
|
|
|
echo " $Titles[Email]: <input type=text name=\"email\" value=\"",$Values["email"],"\" maxlength=255> ($Titles[NotPublic])<br>\n";
|
2017-09-27 07:31:42 +00:00
|
|
|
echo " $Titles[Text]:<br>\n <textarea name=\"text\" wrap=virtual cols=50 rows=5 maxlength=$GBtextlenght>",$Values["text"],"</textarea><br>\n";
|
2017-09-27 06:26:08 +00:00
|
|
|
if ($GBcaptcha) echo " $Titles[Captcha]: <font class=\"text\">$captchanumber11</font><font>$captchanumber11</font><font>$captchanumber12</font> $Titles[CaptchaPlus] <font>$captchanumber21</font><font>$captchanumber22</font><font class=\"text\">$captchanumber21</font> = <input type=text name=\"captcha\" size=2 maxlength=2> ?<br>\n";
|
2016-05-06 20:02:56 +00:00
|
|
|
echo " <input type=submit name=\"submit\" value=\"$Titles[Submit]\">\n";
|
|
|
|
echo "</form>\n";
|
|
|
|
if ($PageStatus=="emptyname") echo "$Titles[EmptyName]<br>\n";
|
|
|
|
if ($PageStatus=="emptytext") echo "$Titles[EmptyText]<br>\n";
|
|
|
|
if ($PageStatus=="wrongcaptcha") echo "$Titles[WrongCaptcha]<br>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 16:19:12 +00:00
|
|
|
function Search($SearchQuery) {
|
|
|
|
$Entries=ReadEntries();
|
|
|
|
$SearchResultCount=0;
|
|
|
|
$SearchResult=false;
|
|
|
|
foreach($Entries as $e=>$Entry) {
|
|
|
|
for($p=0; $p<7; $p++) {
|
|
|
|
if (mb_stristr($Entry[$p],$SearchQuery)) {
|
|
|
|
$SearchResult[$SearchResultCount][0]=$e;
|
|
|
|
$SearchResult[$SearchResultCount][1]=$Entry;
|
|
|
|
$SearchResultCount++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $SearchResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
function AddSearchBar() {
|
|
|
|
global $Titles;
|
|
|
|
global $GBsearch;
|
|
|
|
if ($GBsearch) {
|
|
|
|
echo "<form action=index.php method=post>";
|
|
|
|
echo "<input type=text name=\"serachq\" value=\"\" maxlength=255>";
|
|
|
|
echo "<input type=submit name=\"search\" value=\"$Titles[Search]\">";
|
|
|
|
echo "</form>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-06 20:02:56 +00:00
|
|
|
function EntriesView() {
|
|
|
|
global $Titles;
|
|
|
|
global $DataStatus;
|
|
|
|
global $Entries;
|
2017-09-25 09:39:36 +00:00
|
|
|
global $GBpagination;
|
2017-09-27 07:31:42 +00:00
|
|
|
global $GBreadmore;
|
2016-05-06 20:02:56 +00:00
|
|
|
if ($DataStatus=="empty") echo "$Titles[EmptyFile]";
|
2017-09-26 16:19:12 +00:00
|
|
|
else if($_POST['search']&&$_POST['serachq']) {
|
|
|
|
$SearchResult=Search($_POST['serachq']);
|
|
|
|
if ($SearchResult) {
|
|
|
|
$GBpagination=0;
|
|
|
|
unset($Entries);
|
|
|
|
foreach($SearchResult as $n=>$Entry) $Entries[$n]=$Entry[1];
|
|
|
|
} else echo "$Titles[NoResult]: '",$_POST['serachq'],"'.<br>\n";
|
|
|
|
}
|
|
|
|
if (($GBpagination>0)&&(count($Entries)>$GBpagination)) {
|
2017-09-27 06:26:08 +00:00
|
|
|
$Entries=array_reverse($Entries);
|
2017-09-25 09:39:36 +00:00
|
|
|
if ($_GET['page']) switch ($_GET['page']) {
|
|
|
|
case $Titles[First]:
|
|
|
|
$CurrentPage=0;
|
|
|
|
break;
|
|
|
|
case $Titles[Last]:
|
2017-09-27 06:26:08 +00:00
|
|
|
$CurrentPage=intdiv((count($Entries)-1),$GBpagination);
|
2017-09-25 09:39:36 +00:00
|
|
|
break;
|
|
|
|
case "$Titles[Previous]":
|
|
|
|
$CurrentPage=$_SESSION['currentpage']-1;
|
|
|
|
break;
|
|
|
|
case "$Titles[Next]":
|
|
|
|
$CurrentPage=$_SESSION['currentpage']+1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$CurrentPage=$_GET['page']-1;
|
2017-09-26 16:19:12 +00:00
|
|
|
}
|
2017-09-25 09:39:36 +00:00
|
|
|
else $CurrentPage=0;
|
|
|
|
for ($e = ($GBpagination*$CurrentPage); $e < ($GBpagination*($CurrentPage+1)); $e++) {
|
|
|
|
if ($e>=count($Entries)) break;
|
|
|
|
echo " <div class=\"entry\"><div class=\"messages_header\"><h4>",$Entries[$e][7],". ";
|
2017-09-26 06:34:10 +00:00
|
|
|
if ($Entries[$e][2]) echo "<a href=\"",$Entries[$e][2],"\">";
|
2017-09-25 19:51:59 +00:00
|
|
|
echo "<b>",$Entries[$e][0],"</b>";
|
2017-09-25 09:39:36 +00:00
|
|
|
if ($Entries[$e][2]) echo "</a>";
|
|
|
|
if ($Entries[$e][1]) echo " ",$Titles[From]," <b>",$Entries[$e][1],"</b>";
|
|
|
|
echo ", ",date("j.m.Y, H:i",$Entries[$e][5]),", ",$Titles[Wrote],":</div></h4><br>\n";
|
2017-09-27 07:31:42 +00:00
|
|
|
if ($GBreadmore>0) {
|
|
|
|
$Message=strip_tags($Entries[$e][4]);
|
|
|
|
if (strlen($Message)>$GBreadmore) {
|
|
|
|
$readmorenumber="readmore".$Entries[$e][7];
|
|
|
|
if ($_POST[$readmorenumber]) echo " ",nl2br($Entries[$e][4]),"<br>\n";
|
|
|
|
else {
|
|
|
|
$Message = substr($Message, 0, $GBreadmore);
|
|
|
|
$Message = substr($Message, 0, strrpos($Message, ' '))."... <form action=\"\" method=\"post\"><button type=\"submit\" name=\"readmore".$Entries[$e][7]."\" value=\"read\" class=\"btn-link\">".$Titles[ReadMore]."</button></form>";
|
|
|
|
echo " ",nl2br($Message),"<br>\n";
|
|
|
|
}
|
|
|
|
} else echo " ",nl2br($Entries[$e][4]),"<br>\n";
|
|
|
|
} else echo " ",nl2br($Entries[$e][4]),"<br>\n";
|
2017-09-25 09:39:36 +00:00
|
|
|
if ($Entries[$e][6]) echo "<br><i><b>$Titles[Response]:</b><br>\n";
|
|
|
|
if ($Entries[$e][6]) echo nl2br($Entries[$e][6]),"</i><br>\n";
|
|
|
|
echo "</div><hr>\n";
|
|
|
|
}
|
2017-09-27 06:26:08 +00:00
|
|
|
echo "<form action=index.php method=\"get\">\n";
|
2017-09-25 09:39:36 +00:00
|
|
|
if ($CurrentPage>0) {
|
|
|
|
echo " <input type=\"submit\" value=\"$Titles[First]\" name=\"page\"/>\n";
|
|
|
|
echo " <input type=\"submit\" value=\"$Titles[Previous]\" name=\"page\"/>\n";
|
|
|
|
}
|
|
|
|
for ($p = ($CurrentPage-2); $p <= ($CurrentPage+2); $p++) {
|
|
|
|
$page = $p+1;
|
|
|
|
if (($p>=0)&&($p<(count($Entries)/$GBpagination))) {
|
|
|
|
echo " <input type=\"submit\" value=\"$page\" name=\"page\"";
|
|
|
|
if ($p==$CurrentPage) echo " disabled";
|
|
|
|
echo "/>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($CurrentPage<((count($Entries)/$GBpagination)-1)) {
|
|
|
|
echo " <input type=\"submit\" value=\"$Titles[Next]\" name=\"page\"/>\n";
|
|
|
|
echo " <input type=\"submit\" value=\"$Titles[Last]\" name=\"page\"/>\n";
|
|
|
|
}
|
|
|
|
echo "</form>\n";
|
|
|
|
$_SESSION['currentpage']=$CurrentPage;
|
|
|
|
} else {
|
2016-05-06 20:02:56 +00:00
|
|
|
$Entries=array_reverse($Entries);
|
|
|
|
foreach($Entries as $e=>$Entry) {
|
2017-01-27 10:28:04 +00:00
|
|
|
echo " <div class=\"entry\"><div class=\"messages_header\"><h4>",$Entry[7],". ";
|
2016-05-06 20:02:56 +00:00
|
|
|
if ($Entry[2]) echo "<a href=\"$Entry[2]\">";
|
|
|
|
echo "<b>",$Entry[0],"</b>";
|
|
|
|
if ($Entry[2]) echo "</a>";
|
|
|
|
if ($Entry[1]) echo " ",$Titles[From]," <b>",$Entry[1],"</b>";
|
2017-01-27 10:28:04 +00:00
|
|
|
echo ", ",date("j.m.Y, H:i",$Entry[5]),", ",$Titles[Wrote],":</div></h4><br>\n";
|
2017-09-27 07:31:42 +00:00
|
|
|
if (($GBreadmore>0)&&(!$SearchResult)) {
|
|
|
|
$Message=strip_tags($Entries[$e][4]);
|
|
|
|
if (strlen($Message)>$GBreadmore) {
|
|
|
|
$readmorenumber="readmore".$Entries[$e][7];
|
|
|
|
if ($_POST[$readmorenumber]) echo " ",nl2br($Entries[$e][4]),"<br>\n";
|
|
|
|
else {
|
|
|
|
$Message = substr($Message, 0, $GBreadmore);
|
|
|
|
$Message = substr($Message, 0, strrpos($Message, ' '))."... <form action=\"\" method=\"post\"><button type=\"submit\" name=\"readmore".$Entries[$e][7]."\" value=\"read\" class=\"btn-link\">".$Titles[ReadMore]."</button></form>";
|
|
|
|
echo " ",nl2br($Message),"<br>\n";
|
|
|
|
}
|
|
|
|
} else echo " ",nl2br($Entries[$e][4]),"<br>\n";
|
|
|
|
} else echo " ",nl2br($Entries[$e][4]),"<br>\n";
|
2016-05-06 20:02:56 +00:00
|
|
|
if ($Entry[6]) echo "<br><i><b>$Titles[Response]:</b><br>\n";
|
|
|
|
if ($Entry[6]) echo nl2br($Entry[6]),"</i><br>\n";
|
2017-01-27 10:28:04 +00:00
|
|
|
echo "</div><hr>\n";
|
2016-05-06 20:02:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($_POST['submit']) {
|
|
|
|
if(!$_POST['text']) $PageStatus="emptytext";
|
|
|
|
if(!$_POST['name']) $PageStatus="emptyname";
|
|
|
|
if(($_POST['name'])&&($_POST['text']))
|
2017-01-27 10:28:04 +00:00
|
|
|
if ($_POST["captcha"]&&(md5(base64_encode($_POST["captcha"]))==$_SESSION["captcha"])) {
|
|
|
|
AddEntry();
|
|
|
|
if ($GBnotificationmailto) SendMail();
|
2017-09-27 06:26:08 +00:00
|
|
|
} else if (!$GBcaptcha) {
|
|
|
|
AddEntry();
|
|
|
|
if ($GBnotificationmailto) SendMail();
|
|
|
|
} else $PageStatus="wrongcaptcha";
|
2016-05-06 20:02:56 +00:00
|
|
|
if (($PageStatus)&&!($PageStatus=="added")) {
|
|
|
|
$SESSION["value"]["name"]=$_POST['name'];
|
|
|
|
$SESSION["value"]["from"]=$_POST['from'];
|
|
|
|
$SESSION["value"]["link"]=$_POST['link'];
|
|
|
|
$SESSION["value"]["email"]=$_POST['email'];
|
|
|
|
$SESSION["value"]["text"]=$_POST['text'];
|
|
|
|
$Values=$SESSION["value"];
|
|
|
|
} else Unset($SESSION["value"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$Entries=ReadEntries();
|
|
|
|
|
|
|
|
include "page.php";
|
|
|
|
?>
|