Making the Database: Database: `forum2`
--
-- Table structure for table `languages`
--
CREATE TABLE IF NOT EXISTS `languages` (
`lang_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
`lang` varchar(60) NOT NULL,
`lang_eng` varchar(20) NOT NULL,
PRIMARY KEY (`lang_id`),
UNIQUE KEY `lang` (`lang`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
--
-- Dumping data for table `languages`
--
INSERT INTO `languages` (`lang_id`, `lang`, `lang_eng`) VALUES
(1, 'English', 'English'),
(2, 'Português', 'Portuguese'),
(3, 'Français', 'French'),
(4, 'Norsk', 'Norwegian'),
(5, 'Romanian', 'Romanian'),
(6, '????????', 'Greek'),
(7, 'Deutsch', 'German'),
(8, 'Srpski', 'Serbian'),
(9, '???', 'Japanese'),
(10, 'Nederlands', 'Dutch');
-- --------------------------------------------------------
--
-- Table structure for table `posts`
--
CREATE TABLE IF NOT EXISTS `posts` (
`post_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`thread_id` int(10) unsigned NOT NULL,
`user_id` int(10) unsigned NOT NULL,
`message` text NOT NULL,
`posted_on` datetime NOT NULL,
PRIMARY KEY (`post_id`),
KEY `thread_id` (`thread_id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ;
--
-- Dumping data for table `posts`
--
INSERT INTO `posts` (`post_id`, `thread_id`, `user_id`, `message`, `posted_on`) VALUES
(1, 1, 3, 'Jeg har nettopp gått over til PHP 5.0 og forsøkte å benytte meg av mine gamle scripts. Dette viste seg å være noe vanskelig ettersom de bare generer feil. Hovedproblemet virker å være at jeg ikke får tilgang til variabler som tidligere var tilgjengelige. Noen som har noen forslag?', '2007-10-29 04:15:52'),
(2, 1, 1, 'Har du sjekket om variablene du prøver å få tilgang på er superglobals? Dette forandret seg fra 4.2 og utover, tror jeg...', '2007-10-29 04:20:52'),
(3, 1, 4, 'Hva er superglobals?', '2007-10-29 04:30:30'),
(4, 1, 1, 'http://no.php.net/variables.predefined', '2007-10-30 06:16:30'),
(5, 1, 5, 'Linken Terje ga er manualsiden, men du kan også ta en titt på http://www.linuxjournal.com/article/6559 for en grundig innføring og forklaring. Lykke til!', '2007-10-29 10:26:57'),
(6, 2, 2, 'Har sett flere sider hvor man må skrive inn noen tall for å kunne laste ned, registrere seg, osv. Er dette PHP? Kan noen hjelpe meg å få til en slik?', '2007-10-29 22:45:57'),
(7, 3, 1, 'Je voudrais afficher simplement une nouvelle page HTML ou PHP dans mon\r\nnavigateur web depuis un bout de programme en PHP.\r\nLancer par exemple http://www.google.fr/ depuis un condition if (a>0)\r\nJe trouve pas de solution sur google ni dans mes bouquins', '2007-10-29 04:42:38'),
(8, 3, 2, 'header("Location: http://www.domaine.com");\r\nAttention, cette fonction doit être utilisé avant toute sortie vers le navigateur... le moindre echo et c''est foutu\r\n', '2007-10-29 05:17:38'),
(9, 4, 3, 'J''utilise PHP List. J''ai un formulaire contact avec une case à cocher\r\npermettant de choisir de s''abonner à une newsletter. Je traite ce\r\nformullaire en PHP.\r\nExiste-t-il un moyen au moment où je traite le formulaire d''ajouter la\r\npersonne dans ma liste de diffusion PHP List ?\r\nJe suppose que le problème n''est pas compliqué mais je n''ai pas encore\r\ntrouvé comment faire...\r\n', '2007-10-29 04:43:28'),
(10, 4, 5, 'Dans ce genre de problématiques le mieux est de :\r\na/ regarder de quelle manière php list gère les abonnés dans la base ( en\r\ngros, regarder la structure de la table ).\r\nb/ créer une fonction qui ajoute manuellement les données de votre\r\nformulaire dans la ou les tables mysql utilisée(s) par php list ( en se\r\nméfiant des doublons : est ce que cette adresse est déjà dans la liste ? )\r\nc/ faire un ou plusieurs tests...\r\n', '2007-10-31 12:06:28'),
(11, 5, 2, 'PHP ?????MySql?????? ?????????????\r\n???????????????????????????', '2007-10-29 04:57:55'),
(12, 5, 3, '??????????????', '2007-10-29 04:57:55'),
(13, 5, 4, '?????????????????', '2007-10-29 04:58:10'),
(14, 7, 1, 'This is the body of the sample thread. This is the body of the sample thread. This is the body of the sample thread. ', '2007-10-29 05:12:02'),
(15, 7, 1, 'I like your thread. It''s simple and sweet.', '2007-10-29 05:44:07'),
(16, 8, 1, 'its new thread for all', '2014-04-27 10:02:49'),
(17, 8, 1, 'whats uppp', '2014-04-27 10:03:03'),
(18, 3, 1, '\r\n?', '2014-04-27 10:06:13');
-- --------------------------------------------------------
--
-- Table structure for table `threads`
--
CREATE TABLE IF NOT EXISTS `threads` (
`thread_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`lang_id` tinyint(3) unsigned NOT NULL,
`user_id` int(10) unsigned NOT NULL,
`subject` varchar(150) NOT NULL,
PRIMARY KEY (`thread_id`),
KEY `lang_id` (`lang_id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
--
-- Dumping data for table `threads`
--
INSERT INTO `threads` (`thread_id`, `lang_id`, `user_id`, `subject`) VALUES
(1, 4, 1, 'Byttet til PHP 5.0 fra PHP 4.0 - variabler utilgjengelige'),
(2, 4, 2, 'Automatisk bildekontroll'),
(3, 3, 5, 'Lancer une Page HTML en PHP'),
(4, 3, 4, 'Ajouter des adresses a PHP List depuis un formulaire'),
(5, 9, 4, '???????'),
(7, 1, 1, 'Sample Thread'),
(8, 1, 1, 'This is new thread ');
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`user_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`lang_id` tinyint(3) unsigned NOT NULL,
`time_zone` varchar(30) NOT NULL,
`username` varchar(30) NOT NULL,
`pass` char(40) NOT NULL,
`email` varchar(60) NOT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`),
KEY `login` (`username`,`pass`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`user_id`, `lang_id`, `time_zone`, `username`, `pass`, `email`) VALUES
(1, 1, 'America/New_York', 'troutster', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 'email@example.com'),
(2, 7, 'Europe/Berlin', 'Ute', 'a5a7569327c9925049693dbfda8cd1d0106f4550', 'email1@example.com'),
(3, 4, 'Europe/Oslo', 'Silje', 'e408d64f8bcd85ebb7d84bc13540c5683ce1b6c9', 'email2@example.com'),
(4, 2, 'America/Sao_Paulo', 'João', '2d2553bcdeda4aa9d3b09965e90c6d283a8cfce1', 'email3@example.com'),
(5, 1, 'Pacific/Auckland', 'kiwi', '9c147500fd397d8f90a2e5005524fee515099760', 'kiwi@example.org');
-- --------------------------------------------------------
--
-- Table structure for table `words`
--
CREATE TABLE IF NOT EXISTS `words` (
`word_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
`lang_id` tinyint(3) unsigned NOT NULL,
`title` varchar(80) NOT NULL,
`intro` tinytext NOT NULL,
`home` varchar(30) NOT NULL,
`forum_home` varchar(40) NOT NULL,
`language` varchar(40) NOT NULL,
`register` varchar(30) NOT NULL,
`login` varchar(30) NOT NULL,
`logout` varchar(30) NOT NULL,
`new_thread` varchar(40) NOT NULL,
`subject` varchar(30) NOT NULL,
`body` varchar(30) NOT NULL,
`submit` varchar(30) NOT NULL,
`posted_on` varchar(30) NOT NULL,
`posted_by` varchar(30) NOT NULL,
`replies` varchar(30) NOT NULL,
`latest_reply` varchar(40) NOT NULL,
`post_a_reply` varchar(40) NOT NULL,
PRIMARY KEY (`word_id`),
UNIQUE KEY `lang_id` (`lang_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
--
-- Dumping data for table `words`
--
INSERT INTO `words` (`word_id`, `lang_id`, `title`, `intro`, `home`, `forum_home`, `language`, `register`, `login`, `logout`, `new_thread`, `subject`, `body`, `submit`, `posted_on`, `posted_by`, `replies`, `latest_reply`, `post_a_reply`) VALUES
(1, 1, 'PHP and MySQL for Dynamic Web Sites: The Forum!', '<p>Welcome to our site....please use the links above...blah, blah, blah.</p>\r\n<p>Welcome to our site....please use the links above...blah, blah, blah.</p>', 'Home', 'Forum Home', 'Language', 'Register', 'Login', 'Logout', 'New Thread', 'Subject', 'Body', 'Submit', 'Posted on', 'Posted by', 'Replies', 'Latest Reply', 'Post a Reply'),
(2, 4, 'PHP og MySQL for Dyaniske Websider: Forumet!', '<p>"Velkommen til denne siden. Introduksjonstekst."</p>\r\n<p>"Velkommen til denne siden. Introduksjonstekst."</p>', 'Hjem', 'Forumet Hjem', 'Språk', 'Registrer deg', 'Logg inn', 'Logg ut', 'Ny tråd', 'Emne', 'Kropp', 'SUBMIT', 'Lagt til', 'Lagt til av', 'REPLIES', 'LATEST REPLY', 'POST A REPLY'),
(3, 5, 'Forumul PHP si MySQL pentru site-uri web dinamice', 'Bine ati venit pe acest site. Text introductiv. Bine ati venit pe acest site. Text introductiv. Bine ati venit pe acest site. Text introductiv.', 'Inregistrare', 'Conectare', 'Deconectare', 'Discutie noua', 'Subiect', 'Continut', 'Limba', 'Acasa', 'SUBMIT', 'Afisat pe', 'Afisat de', 'REPLIES', 'LATEST REPLY', 'POST A REPLY', 'Forumul Acasa'),
(4, 3, 'Sites internet dynamiques avec PHP et MySQL : le forum!', 'Bienvenue sur ce site. Texte d''introduction. Bienvenue sur ce site. Texte d''introduction. Bienvenue sur ce site. Texte d''introduction.', 'S''enregistrer', 'Se connecter', 'Déconnexion', 'Nouvelle discussion', 'Sujet', 'Contenu', 'Langue', 'Accueil', 'Soumettez', 'Posté le', 'Posté par', 'Réponses', 'La Plus défunte Réponse', 'Signalez une réponse', 'Le Forum Accueil'),
(5, 7, 'PHP en MYSQL voor Dynamische Websites: Het Forum!', 'Welkom op deze site! Inleidingstekst. Hier vind je alles op het gebied van php!', 'Registreer', 'Uitloggen', 'Inloggen', 'Nieuw onderwerp', 'Onderwerp', 'Body', 'Taal', 'Index', 'SUBMIT', 'Geplaatst op', 'Geplaatst door', 'REPLIES', 'LATEST REPLY', 'POST A REPLY', 'Forum Index'),
(6, 9, 'PHP ?MySql???????????????????????', '???????????????????????????? ????????????????????????????', '???', '???????????', '??', '?????', ' ????', '?????', '??? ???? ', '??', '??', '?????', '???', ' ???', '???', '?????', '?????');
<?php # Script 15.3 - index.php
// This is the main page for the site.
// Include the HTML header:
include ('includes/header.html');
// The content on this page is introductory text
// pulled from the database, based upon the
// selected language:
echo $words['intro'];
// Include the HTML footer file:
include ('includes/footer.html');
?>
<?php # Script 15.4 - forum.php
// This page shows the threads in a forum.
include ('includes/header.html');
// Retrieve all the messages in this forum...
// If the user is logged in and has chosen a time zone,
// use that to convert the dates and times:
if (isset($_SESSION['user_tz'])) {
$first = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['user_tz']}')";
$last = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['user_tz']}')";
} else {
$first = 'p.posted_on';
$last = 'p.posted_on';
}
// The query for retrieving all the threads in this forum, along with the original user,
// when the thread was first posted, when it was last replied to, and how many replies it's had:
$q = "SELECT t.thread_id, t.subject, username, COUNT(post_id) - 1 AS responses, MAX(DATE_FORMAT($last, '%e-%b-%y %l:%i %p')) AS last, MIN(DATE_FORMAT($first, '%e-%b-%y %l:%i %p')) AS first FROM threads AS t INNER JOIN posts AS p USING (thread_id) INNER JOIN users AS u ON t.user_id = u.user_id WHERE t.lang_id = {$_SESSION['lid']} GROUP BY (p.thread_id) ORDER BY last DESC";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) > 0) {
// Create a table:
echo '<table width="100%" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<td align="left" width="50%"><em>' . $words['subject'] . '</em>:</td>
<td align="left" width="20%"><em>' . $words['posted_by'] . '</em>:</td>
<td align="center" width="10%"><em>' . $words['posted_on'] . '</em>:</td>
<td align="center" width="10%"><em>' . $words['replies'] . '</em>:</td>
<td align="center" width="10%"><em>' . $words['latest_reply'] . '</em>:</td>
</tr>';
// Fetch each thread:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo '<tr>
<td align="left"><a href="read.php?tid=' . $row['thread_id'] . '">' . $row['subject'] . '</a></td>
<td align="left">' . $row['username'] . '</td>
<td align="center">' . $row['first'] . '</td>
<td align="center">' . $row['responses'] . '</td>
<td align="center">' . $row['last'] . '</td>
</tr>';
}
echo '</table>'; // Complete the table.
} else {
echo '<p>There are currently no messages in this forum.</p>';
}
// Include the HTML footer file:
include ('includes/footer.html');
?>
<?php # Script 15.8 - search.php
// This page displays and handles a search form.
// Include the HTML header:
include ('includes/header.html');
// Show the search form:
echo '<form action="search.php" method="get" accept-charset="utf-8">
<p><em>' . $words['search'] . '</em>: <input name="terms" type="text" size="30" maxlength="60" ';
// Check for existing value:
if (isset($_GET['terms'])) {
echo 'value="' . htmlspecialchars($_GET['terms']) . '" ';
}
// Complete the form:
echo '/><input name="submit" type="submit" value="' . $words['submit'] . '" /></p></form>';
if (isset($_GET['terms'])) { // Handle the form.
// Clean the terms:
$terms = mysqli_real_escape_string($dbc, htmlentities(strip_tags($_GET['terms'])));
// Run the query...
$q = "SELECT * FROM languages WHERE lang_id = 100";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) > 0) {
echo '<h2>Search Results</h2>';
} else {
echo '<p>No results found.</p>';
}
}
// Include the HTML footer file:
include ('includes/footer.html');
?>
<?php # Script 15.7 - post.php
// This page handles the message post.
// It also displays the form if creating a new thread.
include ('includes/header.html');
if (isset($_POST['submitted'])) { // Handle the form.
// Language ID ($lid) is in the session.
// Validate thread ID ($tid), which may not be present:
$tid = FALSE;
if (isset($_POST['tid']) && is_numeric($_POST['tid']) ) {
$tid = (int) $_POST['tid'];
if ($tid <= 0) {
$tid = FALSE;
}
}
// If there's no thread ID, a subject must be provided:
if (!$tid && empty($_POST['subject'])) {
$subject = FALSE;
echo '<p>Please enter a subject for this post.</p>';
} elseif (!$tid && !empty($_POST['subject'])) {
$subject = htmlspecialchars(strip_tags($_POST['subject']));
} else { // Thread ID, no need for subject.
$subject = TRUE;
}
// Validate the body:
if (!empty($_POST['body'])) {
$body = htmlentities($_POST['body']);
} else {
$body = FALSE;
echo '<p>Please enter a body for this post.</p>';
}
if ($subject && $body) { // OK!
// Add the message to the database...
if (!$tid) { // Create a new thread.
$q = "INSERT INTO threads (lang_id, user_id, subject) VALUES ({$_SESSION['lid']}, {$_SESSION['user_id']}, '" . mysqli_real_escape_string($dbc, $subject) . "')";
$r = mysqli_query($dbc, $q);
if (mysqli_affected_rows($dbc) == 1) {
$tid = mysqli_insert_id($dbc);
} else {
echo '<p>Your post could not be handled due to a system error.</p>';
}
}
if ($tid) { // Add this to the replies table:
$q = "INSERT INTO posts (thread_id, user_id, message, posted_on) VALUES ($tid, {$_SESSION['user_id']}, '" . mysqli_real_escape_string($dbc, $body) . "', UTC_TIMESTAMP())";
$r = mysqli_query($dbc, $q);
if (mysqli_affected_rows($dbc) == 1) {
echo '<p>Your post has been entered.</p>';
} else {
echo '<p>Your post could not be handled due to a system error.</p>';
}
}
} else { // Include the form:
include ('post_form.php');
}
} else { // Display the form:
include ('post_form.php');
}
include ('includes/footer.html');
?>
<?php # Script 15.5 - read.php
// This page shows the messages in a thread.
include ('includes/header.html');
// Check for a thread ID...
$tid = FALSE;
if (isset($_GET['tid']) && is_numeric($_GET['tid'])) {
$tid = (int) $_GET['tid'];
if ($tid > 0) { // Check against the database...
// Convert the date if the user is logged in:
if (isset($_SESSION['user_tz'])) {
$posted = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['user_tz']}')";
} else {
$posted = 'p.posted_on';
}
// Run the query:
$q = "SELECT t.subject, p.message, username, DATE_FORMAT($posted, '%e-%b-%y %l:%i %p') AS posted FROM threads AS t LEFT JOIN posts AS p USING (thread_id) INNER JOIN users AS u ON p.user_id = u.user_id WHERE t.thread_id = $tid ORDER BY p.posted_on ASC";
$r = mysqli_query($dbc, $q);
if (!(mysqli_num_rows($r) > 0)) {
$tid = FALSE; // Invalid thread ID!
}
} // End of ($tid > 0) IF.
} // End of isset($_GET['tid']) IF.
if ($tid) { // Get the messages in this thread...
$printed = FALSE; // Flag variable.
// Fetch each:
while ($messages = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
// Only need to print the subject once!
if (!$printed) {
echo "<h2>{$messages['subject']}</h2>\n";
$printed = TRUE;
}
// Print the message:
echo "<p>{$messages['username']} ({$messages['posted']})<br />{$messages['message']}</p><br />\n";
} // End of WHILE loop.
// Show the form to post a message:
include ('post_form.php');
} else { // Invalid thread ID!
echo '<p>This page has been accessed in error.</p>';
}
include ('includes/footer.html');
?>
<?php # Script 15.6 - post_form.php
// This page shows the form for posting messages.
// It's included by other pages, never called directly.
// Redirect if this page is called directly:
if (!isset($words)) {
header ("Location: http://www.example.com/index.php");
exit();
}
// Only display this form if the user is logged in:
if (isset($_SESSION['user_id'])) {
// Display the form:
echo '<form action="post.php" method="post" accept-charset="utf-8">';
// If on read.php...
if (isset($tid) && $tid) {
// Print a caption:
echo '<h3>' . $words['post_a_reply'] . '</h3>';
// Add the thread ID as a hidden input:
echo '<input name="tid" type="hidden" value="' . $tid . '" />';
} else { // New thread
// Print a caption:
echo '<h3>' . $words['new_thread'] . '</h3>';
// Create subject input:
echo '<p><em>' . $words['subject'] . '</em>: <input name="subject" type="text" size="60" maxlength="100" ';
// Check for existing value:
if (isset($subject)) {
echo "value=\"$subject\" ";
}
echo '/></p>';
} // End of $tid IF.
// Create the body textarea:
echo '<p><em>' . $words['body'] . '</em>: <textarea name="body" rows="10" cols="60">';
if (isset($body)) {
echo $body;
}
echo '</textarea></p>';
// Finish the form:
echo '<input name="submit" type="submit" value="' . $words['submit'] . '" /><input name="submitted" type="hidden" value="TRUE" />
</form>';
} else {
echo '<p>You must be logged in to post messages.</p>';
}
?>
Footer.html
<!-- Script 15.2 - footer.html -->
</td>
</tr>
<tr>
<td colspan="2" align="center">© 2013 Aamir Javed & www.E-pagespk.com</td>
</tr>
</table>
</body>
</html>
<?php # Script 15.1 - header.html
/* This script...
* - starts the HTML template.
* - indicates the encoding using header().
* - starts the session.
* - gets the language-specific words from the database.
* - lists the available languages.
*/
// Indicate the encoding:
header ('Content-Type: text/html; charset=UTF-8');
// Start the session:
session_start();
// For testing purposes:
$_SESSION['user_id'] = 1;
$_SESSION['user_tz'] = 'America/New_York';
//$_SESSION = array();
// Need the database connection:
require_once('../mysqli_connect.php');
// The language ID is stored in the session.
// Check for a new language ID...
if (isset($_GET['lid']) && is_numeric($_GET['lid'])) {
$_SESSION['lid'] = (int) $_GET['lid'];
} elseif (!isset($_SESSION['lid'])) {
$_SESSION['lid'] = 1; // Default.
}
// Get the words for this language.
$words = FALSE; // Flag variable.
if ($_SESSION['lid'] > 0) {
$q = "SELECT * FROM words WHERE lang_id = {$_SESSION['lid']}";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) == 1) {
$words = mysqli_fetch_array($r, MYSQLI_ASSOC);
}
}
// If we still don't have the words, get the default language:
if (!$words) {
$_SESSION['lid'] = 1; // Default.
$q = "SELECT * FROM words WHERE lang_id = {$_SESSION['lid']}";
$r = mysqli_query($dbc, $q);
$words = mysqli_fetch_array($r, MYSQLI_ASSOC);
}
mysqli_free_result($r);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><?php echo $words['title']; ?></title>
<style type="text/css" media="screen">
body { background-color: #ffffff; }
.content {
background-color: #f5f5f5;
padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px;
margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px;
}
a.navlink:link { color: #003366; text-decoration: none; }
a.navlink:visited { color: #003366; text-decoration: none; }
a.navlink:hover { color: #cccccc; text-decoration: none; }
.title {
font-size: 24px; font-weight: normal; color: #ffffff;
margin-top: 5px; margin-bottom: 5px; margin-left: 20px;
padding-top: 5px; padding-bottom: 5px; padding-left: 20px;
}
</style>
</head>
<body>
<table width="90%" border="0" cellspacing="10" cellpadding="0" align="center">
<tr>
<td colspan="2" bgcolor="#003366" align="center"><p class="title"><?php echo $words['title']; ?></p></td>
</tr>
<tr>
<td valign="top" nowrap="nowrap" width="10%">
<b>
<?php // Display links:
// Default links:
echo '<a href="index.php" class="navlink">' . $words['home'] . '</a><br />
<a href="forum.php" class="navlink">' . $words['forum_home'] . '</a><br />';
// Display links based upon login status:
if (isset($_SESSION['user_id'])) {
// If this is the forum page, add a link for posting new threads:
if (stripos($_SERVER['PHP_SELF'], 'forum.php')) {
echo '<a href="post.php" class="navlink">' . $words['new_thread'] . '</a><br />';
}
// Add the logout link:
echo '<a href="logout.php" class="navlink">' . $words['logout'] . '</a><br />';
} else {
// Register and login links:
echo '<a href="register.php" class="navlink">' . $words['register'] . '</a><br />
<a href="login.php" class="navlink">' . $words['login'] . '</a><br />';
}
// For choosing a forum/language:
echo '</b><p><form action="forum.php" method="get">
<select name="lid">
<option value="0">' . $words['language'] . '</option>
';
// Retrieve all the languages...
$q = "SELECT lang_id, lang FROM languages ORDER BY lang_eng ASC";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) > 0) {
while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) {
echo "<option value=\"$menu_row[0]\">$menu_row[1]</option>\n";
}
}
mysqli_free_result($r);
unset($menu_row);
echo '</select><br />
<input name="submit" type="submit" value="' . $words['submit'] . '" />
</form></p>
</td>
<td valign="top" class="content">';
?>
--
-- Table structure for table `languages`
--
CREATE TABLE IF NOT EXISTS `languages` (
`lang_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
`lang` varchar(60) NOT NULL,
`lang_eng` varchar(20) NOT NULL,
PRIMARY KEY (`lang_id`),
UNIQUE KEY `lang` (`lang`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
--
-- Dumping data for table `languages`
--
INSERT INTO `languages` (`lang_id`, `lang`, `lang_eng`) VALUES
(1, 'English', 'English'),
(2, 'Português', 'Portuguese'),
(3, 'Français', 'French'),
(4, 'Norsk', 'Norwegian'),
(5, 'Romanian', 'Romanian'),
(6, '????????', 'Greek'),
(7, 'Deutsch', 'German'),
(8, 'Srpski', 'Serbian'),
(9, '???', 'Japanese'),
(10, 'Nederlands', 'Dutch');
-- --------------------------------------------------------
--
-- Table structure for table `posts`
--
CREATE TABLE IF NOT EXISTS `posts` (
`post_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`thread_id` int(10) unsigned NOT NULL,
`user_id` int(10) unsigned NOT NULL,
`message` text NOT NULL,
`posted_on` datetime NOT NULL,
PRIMARY KEY (`post_id`),
KEY `thread_id` (`thread_id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ;
--
-- Dumping data for table `posts`
--
INSERT INTO `posts` (`post_id`, `thread_id`, `user_id`, `message`, `posted_on`) VALUES
(1, 1, 3, 'Jeg har nettopp gått over til PHP 5.0 og forsøkte å benytte meg av mine gamle scripts. Dette viste seg å være noe vanskelig ettersom de bare generer feil. Hovedproblemet virker å være at jeg ikke får tilgang til variabler som tidligere var tilgjengelige. Noen som har noen forslag?', '2007-10-29 04:15:52'),
(2, 1, 1, 'Har du sjekket om variablene du prøver å få tilgang på er superglobals? Dette forandret seg fra 4.2 og utover, tror jeg...', '2007-10-29 04:20:52'),
(3, 1, 4, 'Hva er superglobals?', '2007-10-29 04:30:30'),
(4, 1, 1, 'http://no.php.net/variables.predefined', '2007-10-30 06:16:30'),
(5, 1, 5, 'Linken Terje ga er manualsiden, men du kan også ta en titt på http://www.linuxjournal.com/article/6559 for en grundig innføring og forklaring. Lykke til!', '2007-10-29 10:26:57'),
(6, 2, 2, 'Har sett flere sider hvor man må skrive inn noen tall for å kunne laste ned, registrere seg, osv. Er dette PHP? Kan noen hjelpe meg å få til en slik?', '2007-10-29 22:45:57'),
(7, 3, 1, 'Je voudrais afficher simplement une nouvelle page HTML ou PHP dans mon\r\nnavigateur web depuis un bout de programme en PHP.\r\nLancer par exemple http://www.google.fr/ depuis un condition if (a>0)\r\nJe trouve pas de solution sur google ni dans mes bouquins', '2007-10-29 04:42:38'),
(8, 3, 2, 'header("Location: http://www.domaine.com");\r\nAttention, cette fonction doit être utilisé avant toute sortie vers le navigateur... le moindre echo et c''est foutu\r\n', '2007-10-29 05:17:38'),
(9, 4, 3, 'J''utilise PHP List. J''ai un formulaire contact avec une case à cocher\r\npermettant de choisir de s''abonner à une newsletter. Je traite ce\r\nformullaire en PHP.\r\nExiste-t-il un moyen au moment où je traite le formulaire d''ajouter la\r\npersonne dans ma liste de diffusion PHP List ?\r\nJe suppose que le problème n''est pas compliqué mais je n''ai pas encore\r\ntrouvé comment faire...\r\n', '2007-10-29 04:43:28'),
(10, 4, 5, 'Dans ce genre de problématiques le mieux est de :\r\na/ regarder de quelle manière php list gère les abonnés dans la base ( en\r\ngros, regarder la structure de la table ).\r\nb/ créer une fonction qui ajoute manuellement les données de votre\r\nformulaire dans la ou les tables mysql utilisée(s) par php list ( en se\r\nméfiant des doublons : est ce que cette adresse est déjà dans la liste ? )\r\nc/ faire un ou plusieurs tests...\r\n', '2007-10-31 12:06:28'),
(11, 5, 2, 'PHP ?????MySql?????? ?????????????\r\n???????????????????????????', '2007-10-29 04:57:55'),
(12, 5, 3, '??????????????', '2007-10-29 04:57:55'),
(13, 5, 4, '?????????????????', '2007-10-29 04:58:10'),
(14, 7, 1, 'This is the body of the sample thread. This is the body of the sample thread. This is the body of the sample thread. ', '2007-10-29 05:12:02'),
(15, 7, 1, 'I like your thread. It''s simple and sweet.', '2007-10-29 05:44:07'),
(16, 8, 1, 'its new thread for all', '2014-04-27 10:02:49'),
(17, 8, 1, 'whats uppp', '2014-04-27 10:03:03'),
(18, 3, 1, '\r\n?', '2014-04-27 10:06:13');
-- --------------------------------------------------------
--
-- Table structure for table `threads`
--
CREATE TABLE IF NOT EXISTS `threads` (
`thread_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`lang_id` tinyint(3) unsigned NOT NULL,
`user_id` int(10) unsigned NOT NULL,
`subject` varchar(150) NOT NULL,
PRIMARY KEY (`thread_id`),
KEY `lang_id` (`lang_id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
--
-- Dumping data for table `threads`
--
INSERT INTO `threads` (`thread_id`, `lang_id`, `user_id`, `subject`) VALUES
(1, 4, 1, 'Byttet til PHP 5.0 fra PHP 4.0 - variabler utilgjengelige'),
(2, 4, 2, 'Automatisk bildekontroll'),
(3, 3, 5, 'Lancer une Page HTML en PHP'),
(4, 3, 4, 'Ajouter des adresses a PHP List depuis un formulaire'),
(5, 9, 4, '???????'),
(7, 1, 1, 'Sample Thread'),
(8, 1, 1, 'This is new thread ');
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`user_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`lang_id` tinyint(3) unsigned NOT NULL,
`time_zone` varchar(30) NOT NULL,
`username` varchar(30) NOT NULL,
`pass` char(40) NOT NULL,
`email` varchar(60) NOT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`),
KEY `login` (`username`,`pass`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`user_id`, `lang_id`, `time_zone`, `username`, `pass`, `email`) VALUES
(1, 1, 'America/New_York', 'troutster', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 'email@example.com'),
(2, 7, 'Europe/Berlin', 'Ute', 'a5a7569327c9925049693dbfda8cd1d0106f4550', 'email1@example.com'),
(3, 4, 'Europe/Oslo', 'Silje', 'e408d64f8bcd85ebb7d84bc13540c5683ce1b6c9', 'email2@example.com'),
(4, 2, 'America/Sao_Paulo', 'João', '2d2553bcdeda4aa9d3b09965e90c6d283a8cfce1', 'email3@example.com'),
(5, 1, 'Pacific/Auckland', 'kiwi', '9c147500fd397d8f90a2e5005524fee515099760', 'kiwi@example.org');
-- --------------------------------------------------------
--
-- Table structure for table `words`
--
CREATE TABLE IF NOT EXISTS `words` (
`word_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
`lang_id` tinyint(3) unsigned NOT NULL,
`title` varchar(80) NOT NULL,
`intro` tinytext NOT NULL,
`home` varchar(30) NOT NULL,
`forum_home` varchar(40) NOT NULL,
`language` varchar(40) NOT NULL,
`register` varchar(30) NOT NULL,
`login` varchar(30) NOT NULL,
`logout` varchar(30) NOT NULL,
`new_thread` varchar(40) NOT NULL,
`subject` varchar(30) NOT NULL,
`body` varchar(30) NOT NULL,
`submit` varchar(30) NOT NULL,
`posted_on` varchar(30) NOT NULL,
`posted_by` varchar(30) NOT NULL,
`replies` varchar(30) NOT NULL,
`latest_reply` varchar(40) NOT NULL,
`post_a_reply` varchar(40) NOT NULL,
PRIMARY KEY (`word_id`),
UNIQUE KEY `lang_id` (`lang_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
--
-- Dumping data for table `words`
--
INSERT INTO `words` (`word_id`, `lang_id`, `title`, `intro`, `home`, `forum_home`, `language`, `register`, `login`, `logout`, `new_thread`, `subject`, `body`, `submit`, `posted_on`, `posted_by`, `replies`, `latest_reply`, `post_a_reply`) VALUES
(1, 1, 'PHP and MySQL for Dynamic Web Sites: The Forum!', '<p>Welcome to our site....please use the links above...blah, blah, blah.</p>\r\n<p>Welcome to our site....please use the links above...blah, blah, blah.</p>', 'Home', 'Forum Home', 'Language', 'Register', 'Login', 'Logout', 'New Thread', 'Subject', 'Body', 'Submit', 'Posted on', 'Posted by', 'Replies', 'Latest Reply', 'Post a Reply'),
(2, 4, 'PHP og MySQL for Dyaniske Websider: Forumet!', '<p>"Velkommen til denne siden. Introduksjonstekst."</p>\r\n<p>"Velkommen til denne siden. Introduksjonstekst."</p>', 'Hjem', 'Forumet Hjem', 'Språk', 'Registrer deg', 'Logg inn', 'Logg ut', 'Ny tråd', 'Emne', 'Kropp', 'SUBMIT', 'Lagt til', 'Lagt til av', 'REPLIES', 'LATEST REPLY', 'POST A REPLY'),
(3, 5, 'Forumul PHP si MySQL pentru site-uri web dinamice', 'Bine ati venit pe acest site. Text introductiv. Bine ati venit pe acest site. Text introductiv. Bine ati venit pe acest site. Text introductiv.', 'Inregistrare', 'Conectare', 'Deconectare', 'Discutie noua', 'Subiect', 'Continut', 'Limba', 'Acasa', 'SUBMIT', 'Afisat pe', 'Afisat de', 'REPLIES', 'LATEST REPLY', 'POST A REPLY', 'Forumul Acasa'),
(4, 3, 'Sites internet dynamiques avec PHP et MySQL : le forum!', 'Bienvenue sur ce site. Texte d''introduction. Bienvenue sur ce site. Texte d''introduction. Bienvenue sur ce site. Texte d''introduction.', 'S''enregistrer', 'Se connecter', 'Déconnexion', 'Nouvelle discussion', 'Sujet', 'Contenu', 'Langue', 'Accueil', 'Soumettez', 'Posté le', 'Posté par', 'Réponses', 'La Plus défunte Réponse', 'Signalez une réponse', 'Le Forum Accueil'),
(5, 7, 'PHP en MYSQL voor Dynamische Websites: Het Forum!', 'Welkom op deze site! Inleidingstekst. Hier vind je alles op het gebied van php!', 'Registreer', 'Uitloggen', 'Inloggen', 'Nieuw onderwerp', 'Onderwerp', 'Body', 'Taal', 'Index', 'SUBMIT', 'Geplaatst op', 'Geplaatst door', 'REPLIES', 'LATEST REPLY', 'POST A REPLY', 'Forum Index'),
(6, 9, 'PHP ?MySql???????????????????????', '???????????????????????????? ????????????????????????????', '???', '???????????', '??', '?????', ' ????', '?????', '??? ???? ', '??', '??', '?????', '???', ' ???', '???', '?????', '?????');
<?php # Script 15.3 - index.php
// This is the main page for the site.
// Include the HTML header:
include ('includes/header.html');
// The content on this page is introductory text
// pulled from the database, based upon the
// selected language:
echo $words['intro'];
// Include the HTML footer file:
include ('includes/footer.html');
?>
<?php # Script 15.4 - forum.php
// This page shows the threads in a forum.
include ('includes/header.html');
// Retrieve all the messages in this forum...
// If the user is logged in and has chosen a time zone,
// use that to convert the dates and times:
if (isset($_SESSION['user_tz'])) {
$first = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['user_tz']}')";
$last = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['user_tz']}')";
} else {
$first = 'p.posted_on';
$last = 'p.posted_on';
}
// The query for retrieving all the threads in this forum, along with the original user,
// when the thread was first posted, when it was last replied to, and how many replies it's had:
$q = "SELECT t.thread_id, t.subject, username, COUNT(post_id) - 1 AS responses, MAX(DATE_FORMAT($last, '%e-%b-%y %l:%i %p')) AS last, MIN(DATE_FORMAT($first, '%e-%b-%y %l:%i %p')) AS first FROM threads AS t INNER JOIN posts AS p USING (thread_id) INNER JOIN users AS u ON t.user_id = u.user_id WHERE t.lang_id = {$_SESSION['lid']} GROUP BY (p.thread_id) ORDER BY last DESC";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) > 0) {
// Create a table:
echo '<table width="100%" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<td align="left" width="50%"><em>' . $words['subject'] . '</em>:</td>
<td align="left" width="20%"><em>' . $words['posted_by'] . '</em>:</td>
<td align="center" width="10%"><em>' . $words['posted_on'] . '</em>:</td>
<td align="center" width="10%"><em>' . $words['replies'] . '</em>:</td>
<td align="center" width="10%"><em>' . $words['latest_reply'] . '</em>:</td>
</tr>';
// Fetch each thread:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo '<tr>
<td align="left"><a href="read.php?tid=' . $row['thread_id'] . '">' . $row['subject'] . '</a></td>
<td align="left">' . $row['username'] . '</td>
<td align="center">' . $row['first'] . '</td>
<td align="center">' . $row['responses'] . '</td>
<td align="center">' . $row['last'] . '</td>
</tr>';
}
echo '</table>'; // Complete the table.
} else {
echo '<p>There are currently no messages in this forum.</p>';
}
// Include the HTML footer file:
include ('includes/footer.html');
?>
<?php # Script 15.8 - search.php
// This page displays and handles a search form.
// Include the HTML header:
include ('includes/header.html');
// Show the search form:
echo '<form action="search.php" method="get" accept-charset="utf-8">
<p><em>' . $words['search'] . '</em>: <input name="terms" type="text" size="30" maxlength="60" ';
// Check for existing value:
if (isset($_GET['terms'])) {
echo 'value="' . htmlspecialchars($_GET['terms']) . '" ';
}
// Complete the form:
echo '/><input name="submit" type="submit" value="' . $words['submit'] . '" /></p></form>';
if (isset($_GET['terms'])) { // Handle the form.
// Clean the terms:
$terms = mysqli_real_escape_string($dbc, htmlentities(strip_tags($_GET['terms'])));
// Run the query...
$q = "SELECT * FROM languages WHERE lang_id = 100";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) > 0) {
echo '<h2>Search Results</h2>';
} else {
echo '<p>No results found.</p>';
}
}
// Include the HTML footer file:
include ('includes/footer.html');
?>
<?php # Script 15.7 - post.php
// This page handles the message post.
// It also displays the form if creating a new thread.
include ('includes/header.html');
if (isset($_POST['submitted'])) { // Handle the form.
// Language ID ($lid) is in the session.
// Validate thread ID ($tid), which may not be present:
$tid = FALSE;
if (isset($_POST['tid']) && is_numeric($_POST['tid']) ) {
$tid = (int) $_POST['tid'];
if ($tid <= 0) {
$tid = FALSE;
}
}
// If there's no thread ID, a subject must be provided:
if (!$tid && empty($_POST['subject'])) {
$subject = FALSE;
echo '<p>Please enter a subject for this post.</p>';
} elseif (!$tid && !empty($_POST['subject'])) {
$subject = htmlspecialchars(strip_tags($_POST['subject']));
} else { // Thread ID, no need for subject.
$subject = TRUE;
}
// Validate the body:
if (!empty($_POST['body'])) {
$body = htmlentities($_POST['body']);
} else {
$body = FALSE;
echo '<p>Please enter a body for this post.</p>';
}
if ($subject && $body) { // OK!
// Add the message to the database...
if (!$tid) { // Create a new thread.
$q = "INSERT INTO threads (lang_id, user_id, subject) VALUES ({$_SESSION['lid']}, {$_SESSION['user_id']}, '" . mysqli_real_escape_string($dbc, $subject) . "')";
$r = mysqli_query($dbc, $q);
if (mysqli_affected_rows($dbc) == 1) {
$tid = mysqli_insert_id($dbc);
} else {
echo '<p>Your post could not be handled due to a system error.</p>';
}
}
if ($tid) { // Add this to the replies table:
$q = "INSERT INTO posts (thread_id, user_id, message, posted_on) VALUES ($tid, {$_SESSION['user_id']}, '" . mysqli_real_escape_string($dbc, $body) . "', UTC_TIMESTAMP())";
$r = mysqli_query($dbc, $q);
if (mysqli_affected_rows($dbc) == 1) {
echo '<p>Your post has been entered.</p>';
} else {
echo '<p>Your post could not be handled due to a system error.</p>';
}
}
} else { // Include the form:
include ('post_form.php');
}
} else { // Display the form:
include ('post_form.php');
}
include ('includes/footer.html');
?>
<?php # Script 15.5 - read.php
// This page shows the messages in a thread.
include ('includes/header.html');
// Check for a thread ID...
$tid = FALSE;
if (isset($_GET['tid']) && is_numeric($_GET['tid'])) {
$tid = (int) $_GET['tid'];
if ($tid > 0) { // Check against the database...
// Convert the date if the user is logged in:
if (isset($_SESSION['user_tz'])) {
$posted = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['user_tz']}')";
} else {
$posted = 'p.posted_on';
}
// Run the query:
$q = "SELECT t.subject, p.message, username, DATE_FORMAT($posted, '%e-%b-%y %l:%i %p') AS posted FROM threads AS t LEFT JOIN posts AS p USING (thread_id) INNER JOIN users AS u ON p.user_id = u.user_id WHERE t.thread_id = $tid ORDER BY p.posted_on ASC";
$r = mysqli_query($dbc, $q);
if (!(mysqli_num_rows($r) > 0)) {
$tid = FALSE; // Invalid thread ID!
}
} // End of ($tid > 0) IF.
} // End of isset($_GET['tid']) IF.
if ($tid) { // Get the messages in this thread...
$printed = FALSE; // Flag variable.
// Fetch each:
while ($messages = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
// Only need to print the subject once!
if (!$printed) {
echo "<h2>{$messages['subject']}</h2>\n";
$printed = TRUE;
}
// Print the message:
echo "<p>{$messages['username']} ({$messages['posted']})<br />{$messages['message']}</p><br />\n";
} // End of WHILE loop.
// Show the form to post a message:
include ('post_form.php');
} else { // Invalid thread ID!
echo '<p>This page has been accessed in error.</p>';
}
include ('includes/footer.html');
?>
<?php # Script 15.6 - post_form.php
// This page shows the form for posting messages.
// It's included by other pages, never called directly.
// Redirect if this page is called directly:
if (!isset($words)) {
header ("Location: http://www.example.com/index.php");
exit();
}
// Only display this form if the user is logged in:
if (isset($_SESSION['user_id'])) {
// Display the form:
echo '<form action="post.php" method="post" accept-charset="utf-8">';
// If on read.php...
if (isset($tid) && $tid) {
// Print a caption:
echo '<h3>' . $words['post_a_reply'] . '</h3>';
// Add the thread ID as a hidden input:
echo '<input name="tid" type="hidden" value="' . $tid . '" />';
} else { // New thread
// Print a caption:
echo '<h3>' . $words['new_thread'] . '</h3>';
// Create subject input:
echo '<p><em>' . $words['subject'] . '</em>: <input name="subject" type="text" size="60" maxlength="100" ';
// Check for existing value:
if (isset($subject)) {
echo "value=\"$subject\" ";
}
echo '/></p>';
} // End of $tid IF.
// Create the body textarea:
echo '<p><em>' . $words['body'] . '</em>: <textarea name="body" rows="10" cols="60">';
if (isset($body)) {
echo $body;
}
echo '</textarea></p>';
// Finish the form:
echo '<input name="submit" type="submit" value="' . $words['submit'] . '" /><input name="submitted" type="hidden" value="TRUE" />
</form>';
} else {
echo '<p>You must be logged in to post messages.</p>';
}
?>
Footer.html
<!-- Script 15.2 - footer.html -->
</td>
</tr>
<tr>
<td colspan="2" align="center">© 2013 Aamir Javed & www.E-pagespk.com</td>
</tr>
</table>
</body>
</html>
<?php # Script 15.1 - header.html
/* This script...
* - starts the HTML template.
* - indicates the encoding using header().
* - starts the session.
* - gets the language-specific words from the database.
* - lists the available languages.
*/
// Indicate the encoding:
header ('Content-Type: text/html; charset=UTF-8');
// Start the session:
session_start();
// For testing purposes:
$_SESSION['user_id'] = 1;
$_SESSION['user_tz'] = 'America/New_York';
//$_SESSION = array();
// Need the database connection:
require_once('../mysqli_connect.php');
// The language ID is stored in the session.
// Check for a new language ID...
if (isset($_GET['lid']) && is_numeric($_GET['lid'])) {
$_SESSION['lid'] = (int) $_GET['lid'];
} elseif (!isset($_SESSION['lid'])) {
$_SESSION['lid'] = 1; // Default.
}
// Get the words for this language.
$words = FALSE; // Flag variable.
if ($_SESSION['lid'] > 0) {
$q = "SELECT * FROM words WHERE lang_id = {$_SESSION['lid']}";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) == 1) {
$words = mysqli_fetch_array($r, MYSQLI_ASSOC);
}
}
// If we still don't have the words, get the default language:
if (!$words) {
$_SESSION['lid'] = 1; // Default.
$q = "SELECT * FROM words WHERE lang_id = {$_SESSION['lid']}";
$r = mysqli_query($dbc, $q);
$words = mysqli_fetch_array($r, MYSQLI_ASSOC);
}
mysqli_free_result($r);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><?php echo $words['title']; ?></title>
<style type="text/css" media="screen">
body { background-color: #ffffff; }
.content {
background-color: #f5f5f5;
padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px;
margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px;
}
a.navlink:link { color: #003366; text-decoration: none; }
a.navlink:visited { color: #003366; text-decoration: none; }
a.navlink:hover { color: #cccccc; text-decoration: none; }
.title {
font-size: 24px; font-weight: normal; color: #ffffff;
margin-top: 5px; margin-bottom: 5px; margin-left: 20px;
padding-top: 5px; padding-bottom: 5px; padding-left: 20px;
}
</style>
</head>
<body>
<table width="90%" border="0" cellspacing="10" cellpadding="0" align="center">
<tr>
<td colspan="2" bgcolor="#003366" align="center"><p class="title"><?php echo $words['title']; ?></p></td>
</tr>
<tr>
<td valign="top" nowrap="nowrap" width="10%">
<b>
<?php // Display links:
// Default links:
echo '<a href="index.php" class="navlink">' . $words['home'] . '</a><br />
<a href="forum.php" class="navlink">' . $words['forum_home'] . '</a><br />';
// Display links based upon login status:
if (isset($_SESSION['user_id'])) {
// If this is the forum page, add a link for posting new threads:
if (stripos($_SERVER['PHP_SELF'], 'forum.php')) {
echo '<a href="post.php" class="navlink">' . $words['new_thread'] . '</a><br />';
}
// Add the logout link:
echo '<a href="logout.php" class="navlink">' . $words['logout'] . '</a><br />';
} else {
// Register and login links:
echo '<a href="register.php" class="navlink">' . $words['register'] . '</a><br />
<a href="login.php" class="navlink">' . $words['login'] . '</a><br />';
}
// For choosing a forum/language:
echo '</b><p><form action="forum.php" method="get">
<select name="lid">
<option value="0">' . $words['language'] . '</option>
';
// Retrieve all the languages...
$q = "SELECT lang_id, lang FROM languages ORDER BY lang_eng ASC";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) > 0) {
while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) {
echo "<option value=\"$menu_row[0]\">$menu_row[1]</option>\n";
}
}
mysqli_free_result($r);
unset($menu_row);
echo '</select><br />
<input name="submit" type="submit" value="' . $words['submit'] . '" />
</form></p>
</td>
<td valign="top" class="content">';
?>
No comments:
Post a Comment