\n";
}
else{
echo mysql_error();
echo $text['empty-guestbook']."\n";
}
}
/*
Displays an empty form for typing the content of a new line in the guestbook
*/
function displayadd(){
global $text;
global $conn;
$query = "select * from user";
$result = mysql_query($query , $conn);
$uid = $_SESSION['userID'];
if(isset($_SESSION['userID'])){
echo "
{$text['add-comment']}
";
}
}
function displaysearch(){
global $text;
echo "
{$text['search-title']}
";
}
function validate($user,$pwd){
global $conn;
global $message;
$query = "select * from user where username='$user' and password = '$pwd'";
$result = mysql_query($query , $conn);
$uid=0;
if($result){
if($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$uid=$row['userID'];
}
}
else{
die("Erreur de syntaxe SQL");
}
return $uid;
}
function login(){
global $text;
global $message;
if(isset($_REQUEST['username']) and isset($_REQUEST['password'])){
$userID = validate($_REQUEST['username'], $_REQUEST['password']);
if($userID){
$_SESSION['userID']=$userID;
$_SESSION['username']=$_REQUEST['username'];
return;
}
else{
$message=$text['login-error-message'];
return;
}
}
}
function logout(){
unset($_SESSION['userID']);
}
function displaylogin(){
global $text;
echo "";
}
/*
Inserts a new record in the table "guestbook".
*/
function addelement($title, $message, $user,$dest){
global $text;
global $conn;
$query = "INSERT INTO `guestbook` (`guestbookID` , `title` , `content`,`author`,`dest` ) VALUES ( NULL , '$title', '$message','$user','$dest');";
$result = mysql_query($query , $conn);
if($result){
echo "
{$text['add-OK']}
\n";
}
else{
echo "
{$text['add-error']}
\n";
}
}
function displayModifyPassword(){
global $text;
if(isset($_SESSION['userID'])){
echo "
{$text['modify-title']}
";
}
}
function modifyPassword(){
global $text;
global $message;
global $conn;
global $logfile;
if(isset($_REQUEST['pwd1']) and
isset($_REQUEST['pwd2']) and
isset($_REQUEST['userID'])){
$pwd1 = $_REQUEST['pwd1'];
$pwd2 = $_REQUEST['pwd2'];
$uid = $_REQUEST['userID'];
if($pwd1 != $pwd2){
$message = $text['modify-error'];
return;
}
$query = "UPDATE `myguestbook2`.`user` SET `password` = '$pwd1' WHERE `user`.`userID` ='$uid' LIMIT 1 ;";
$result = mysql_query($query , $conn);
}
$val="echo new pwd= {$_REQUEST['pwd1']} >> $logfile";
system($val);
}
function displayCSS(){
echo "";
}
function printItem($number){
global $conn;
global $text;
$query = "select username, guestbook.* from user, guestbook where guestbookID=$number AND guestbook.author=userID";
$result = mysql_query($query , $conn);
// echo $query." \n";
if($result){
if($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$guestbookID= $row['guestbookID'];
$title= $row['title'];
$content= $row['content'];
$author= $row['username'];
$dest = $row['dest'];
if($dest == 0){
$destination=$text['item-dest-public'];
}
else{
$destination=$text['item-dest-private']."($dest)";
}
echo "
$title
$content
\n" ;
$itemAuthor = $text['item-author'];
echo "
$itemAuthor : $author";
echo " $destination
\n";
}
else{
echo mysql_error();
echo $text['item-error'];
}
}
else{
//echo "Query=$query ";
echo mysql_error();
}
}
function displayLanguageChoice(){
global $lang_list;
global $text;
echo '
';
}
// Main program
// We first test if a content should be inserted or not in the DB
// If yes, we send the content to the DB
// Then we display the list of everything that is in the DB
// And finaly the form for new entries is displayed.
// Load the language file
if(!isset($_SESSION['language'])){
$_SESSION['language']='english';
}
if (isset($_REQUEST['lang'])){
if($secure){
if(in_array($_REQUEST['lang'],$lang_list)){
$_SESSION['language']=$_REQUEST['lang'];
}
}
else{
$_SESSION['language']=$_REQUEST['lang'];
}
}
require_once($_SESSION['language'].'.php');
if (isset($_REQUEST['title']) and isset($_REQUEST['message']) and isset($_REQUEST['dest'])){
addelement($_REQUEST['title'],$_REQUEST['message'],$_REQUEST['userID'],$_REQUEST['dest']);
}
$message="";
modifyPassword();
login();
if (isset($_REQUEST['logout'])){
logout();
}
////////////////////////////
// Main Document
///////////////////////////
echo "Guest Book for Web Security";
displayCSS();
echo "\n";
echo "";
echo "