Added search feauture

This commit is contained in:
ivan 2017-09-26 19:19:12 +03:00
parent e1b81c2396
commit 4c4d09a953
6 changed files with 95 additions and 10 deletions

2
README
View File

@ -1,4 +1,4 @@
PHPCSV Guestbook version 0.94 PHPCSV Guestbook version 0.95
Simple php guestbook with csv file data storage. Simple php guestbook with csv file data storage.

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Administration program file of PHPCSV Guestbook version 0.94 * Administration program file of PHPCSV Guestbook
* See settings.php for configuration. * See settings.php for configuration.
* Edit page.php for change appearance. * Edit page.php for change appearance.
*/ */
@ -23,16 +23,48 @@ function SaveEntries() {
global $GBdata; global $GBdata;
global $AdminEntries; global $AdminEntries;
$fhandle=fopen($GBdata,"w"); $fhandle=fopen($GBdata,"w");
foreach($AdminEntries as $e=>$Entry) fputcsv($fhandle,$Entry); foreach($AdminEntries as $e=>$Entry) {
unset($Entry[7]);
fputcsv($fhandle,$Entry);
}
fclose($fhandle); fclose($fhandle);
} }
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 (!(($_SESSION["EditStatus"]) or ($_SESSION["DeleteStatus"]=="deletion"))) if ($GBsearch) {
echo "<form action=administration.php method=post>";
echo "<input type=text name=\"serachq\" value=\"\" maxlength=255>";
echo "<input type=submit name=\"search\" value=\"$Titles[Search]\">";
echo "</form>";
}
}
function AdminHeaderView() { function AdminHeaderView() {
global $Titles; global $Titles;
global $GBadmin; global $GBadmin;
global $GBpassword; global $GBpassword;
echo "<h2><a href=\"index.php\">$Titles[AdminHeader]</a></h2>\n"; echo "<h2><a href=\"index.php\">$Titles[AdminHeader]</a></h2>\n";
if ($_SESSION["SessionStatus"]==(md5($GBadmin.$GBpassword))) { if ($_SESSION["SessionStatus"]==(md5($GBadmin.$GBpassword))) {
echo "<div style=\"position: absolute; right: 127px; top: 59px;\">",AddSearchBar(),"</div>";
echo "<form action=administration.php method=post>\n"; echo "<form action=administration.php method=post>\n";
echo " <p align=\"right\"><input type=submit name=\"exit\" value=\"$Titles[AdminExit]\"></p>\n"; echo " <p align=\"right\"><input type=submit name=\"exit\" value=\"$Titles[AdminExit]\"></p>\n";
echo "</form>\n"; echo "</form>\n";
@ -68,6 +100,14 @@ function AdminEntriesView() {
echo "<input type=submit name=\"canceledit\" value=\"$Titles[AdminCancel]\">\n"; echo "<input type=submit name=\"canceledit\" value=\"$Titles[AdminCancel]\">\n";
echo "</form>\n"; echo "</form>\n";
} else { } else {
if($_POST['search']&&$_POST['serachq']) {
$SearchResult=Search($_POST['serachq']);
if ($SearchResult) {
$GBpagination=0;
unset($AdminEntries);
foreach($SearchResult as $n=>$Entry) $AdminEntries[$n]=$Entry[1];
} else echo "$Titles[NoResult]: '",$_POST['serachq'],"'.<br>\n";
}
if (($GBpagination>0)&&(count($AdminEntries)>$GBpagination)) { if (($GBpagination>0)&&(count($AdminEntries)>$GBpagination)) {
$Entries=array_reverse($AdminEntries); $Entries=array_reverse($AdminEntries);
if ($_GET['page']) switch ($_GET['page']) { if ($_GET['page']) switch ($_GET['page']) {

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Main program file of PHPCSV Guestbook version 0.94 * Main program file of PHPCSV Guestbook
* See settings.php for configuration. * See settings.php for configuration.
* Edit page.php for change appearance. * Edit page.php for change appearance.
* See license.txt for licensing information. * See license.txt for licensing information.
@ -77,14 +77,50 @@ function AddEntryView() {
} }
} }
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>";
}
}
function EntriesView() { function EntriesView() {
global $Titles; global $Titles;
global $DataStatus; global $DataStatus;
global $Entries; global $Entries;
global $GBpagination; global $GBpagination;
if ($DataStatus=="empty") echo "$Titles[EmptyFile]"; if ($DataStatus=="empty") echo "$Titles[EmptyFile]";
else if (($GBpagination>0)&&(count($Entries)>$GBpagination)) { else if($_POST['search']&&$_POST['serachq']) {
$Entries=array_reverse($Entries); $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)) {
$Entries=array_reverse($Entries);
if ($_GET['page']) switch ($_GET['page']) { if ($_GET['page']) switch ($_GET['page']) {
case $Titles[First]: case $Titles[First]:
$CurrentPage=0; $CurrentPage=0;

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Main page of PHPCSV Guestbook version 0.94 * Main page of PHPCSV Guestbook
* See settings.php for configuration. * See settings.php for configuration.
* For changing appearance you can edit this file like simple html. For example: add css tags. * For changing appearance you can edit this file like simple html. For example: add css tags.
*/ */
@ -14,6 +14,9 @@
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<div style="position: absolute; right: 5px; top: 25px;"><?php /* Absolute position of SearchBar */ ?>
<?php AddSearchBar();?>
</div>
<?php AddEntryView();?> <?php AddEntryView();?>
<hr> <hr>
<?php EntriesView();?> <?php EntriesView();?>

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Settings file of PHPCSV Guestbook version 0.94 * Settings file of PHPCSV Guestbook
* Edit page.php for change appearance. * Edit page.php for change appearance.
* $GBdata parameter for changing entries data file. * $GBdata parameter for changing entries data file.
* Please, change $GBadmin and $GBpassword parameters for access to administration page. * Please, change $GBadmin and $GBpassword parameters for access to administration page.
@ -11,6 +11,7 @@ $GBdata="gbdb.csv";
$GBadmin="root"; $GBadmin="root";
$GBpassword="password"; $GBpassword="password";
$GBpagination=10; // pagination for entries, 0 - disabled $GBpagination=10; // pagination for entries, 0 - disabled
$GBsearch=true; // enable or disable search bar
$GBnotificationmailto=""; // leave empty if you don't want send notification $GBnotificationmailto=""; // leave empty if you don't want send notification
$GBnotificationmailfrom=""; $GBnotificationmailfrom="";
$Titles[HeadTitle]="Guestbook"; $Titles[HeadTitle]="Guestbook";
@ -56,4 +57,6 @@ $Titles[First]="First";
$Titles[Last]="Last"; $Titles[Last]="Last";
$Titles[Previous]="<<"; $Titles[Previous]="<<";
$Titles[Next]=">>"; $Titles[Next]=">>";
$Titles[Search]="Search";
$Titles[NoResult]="No search result";
?> ?>

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* Russian version of settings file PHPCSV Guestbook version 0.94 * Russian version of settings file PHPCSV Guestbook
* Для руссификации гостевой книги замените оригинальный settings.php на содержимое этого файла. * Для руссификации гостевой книги замените оригинальный settings.php на содержимое этого файла.
* Редактируйте page.php для изменения внешнего вида. * Редактируйте page.php для изменения внешнего вида.
* $GBdata параметр служит для смены файла данных записей гостевой книги. * $GBdata параметр служит для смены файла данных записей гостевой книги.
@ -12,6 +12,7 @@ $GBdata="gbdb.csv";
$GBadmin="root"; $GBadmin="root";
$GBpassword="password"; $GBpassword="password";
$GBpagination=10; // количество записей на странице, 0 - все записи на одной странице $GBpagination=10; // количество записей на странице, 0 - все записи на одной странице
$GBsearch=true; // включение или отключения строки поиска
$GBnotificationmailto=""; // оставьте поле пустым, если не хотите отправки уведомлений о новых записях $GBnotificationmailto=""; // оставьте поле пустым, если не хотите отправки уведомлений о новых записях
$GBnotificationmailfrom=""; $GBnotificationmailfrom="";
$Titles[HeadTitle]="Гостевая книга"; $Titles[HeadTitle]="Гостевая книга";
@ -57,4 +58,6 @@ $Titles[First]="В начало";
$Titles[Last]="В конец"; $Titles[Last]="В конец";
$Titles[Previous]="Назад"; $Titles[Previous]="Назад";
$Titles[Next]="Вперед"; $Titles[Next]="Вперед";
$Titles[Search]="Поиск";
$Titles[NoResult]="Ничего не найдено";
?> ?>