<?php

#############################################################################
#                              WIZZ FORUM
#  Wizz Forum is a KISS Forum: Keep It Small and Simple.
#
# About the Wizz Forum:
# Original Idea & PHP coding: Mike Kroger (mikek@icon.co.za),
# who granted permission to put Wizz forum uder the GNU GPL.  
# Code adaptations and modularization for Site@School:
# Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# forumnewacc.php: last changed 05/10/2006  version 2.4.10
#                  by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: forumnewacc.php,v 1.2 2006/10/15 19:08:54 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
# Copyright (C) 2006, Rosa Boekdrukker Primary School, Holland.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
##############################################################################
if (!defined('IN_SAS'))
{
	die("Hacking attempt");
}

if (IsSet ($_POST[forumuserid]))
{
	$forumuserid = sql_addslashes($_POST[forumuserid]);
}
if (IsSet ($_POST[password]))
{
	$password = sql_addslashes($_POST[password]);
}
if (IsSet ($_POST[password2]))
{
	$password2 = sql_addslashes($_POST[password2]);
}
if (IsSet ($_POST[firstname]))
{
	$firstname = sql_addslashes($_POST[firstname]);
}
if (IsSet ($_POST[lastname]))
{
	$lastname = sql_addslashes($_POST[lastname]);
}
if (IsSet ($_POST[emailaddress]))
{
	$emailaddress = sql_addslashes($_POST[emailaddress]);
}
if (IsSet ($_POST[showemail]))
{
	$showemail = sql_addslashes($_POST[showemail]);
}
if (IsSet ($_POST[weburl]))
{
	$weburl = sql_addslashes($_POST[weburl]);
}
if (IsSet ($_GET[save]))
{
	$save = $_GET[save];
}
if (IsSet ($_GET[forumid]))
{
	$forumid = intval($_GET[forumid]);
}

if ($save == "yes") // try to save the new account
{
	$error = true;

	if ($forumuserid == "")
	{
		$msg = $sas_lang[forum_msg1];
	}
	elseif (strlen($forumuserid) < 4)
	{
		$msg = $sas_lang[forum_msg2];
	}
	elseif ($password == "")
	{
		$msg = $sas_lang[forum_msg3];
	}
	elseif (strlen($password) < 5)
	{
		$msg = $sas_lang[forum_msg4];
	}
	elseif ($password != $password2)
	{
		$msg = $sas_lang[forum_msg5];
	}
	elseif ($password == $forumuserid)
	{
		$msg = $sas_lang[forum_msg6];
	}
	elseif ($firstname == "")
	{
		$msg = $sas_lang[forum_msg7];
	}
	elseif ($lastname == "")
	{
		$msg = $sas_lang[forum_msg8];
	}
	elseif ($emailaddress == "")
	{
		$msg = $sas_lang[forum_msg9];
	}
	else
	{

		$result = mysql_query("SELECT * FROM $forumuser_table where username = '" . $forumuserid . "'");
		if (mysql_num_rows($result) < 1)
		{
			if ($showemail == "on")
			{
				$semail = 1;
			}
			else
			{
				$semail = 0;
			}
			$now = date("Y-m-d H:i:s");
			$ins_str = "INSERT INTO $forumuser_table set username='" . $forumuserid . "', firstname='" . $firstname . "', surname='" . $lastname . "', email='" . $emailaddress . "', showemail=" . $semail . ", password='" . $password . "', joindate='" . $now . "', topics = 0, replies = 0, cat_index='" . $forumid . "'";
			if (mysql_query($ins_str))
			{
				$msg = $sas_lang[forum_msg10];
				$error = False;
			}
			else
			{
				$msg = "A database error occured while trying to create your forum account.";
			}
		}
		else
		{
			$msg = $sas_lang[forum_userid] . "<strong>" . $forumuserid . "</strong> " . $sas_lang[forum_msg11];
		}
	}
	if ($error)
	{
		print "<p><font color='red' face='Arial' size='2'>$msg</font>";
	}
	else
	{
		$result2 = mysql_query("SELECT name FROM $forumcat_table where cat_index = '$forumid'");
		if (mysql_num_rows($result2) > 0) //get the forum title 
		{
			$forum_title = mysql_result($result2, 0);
		}
		print "<p><font face='Arial' size='2'>$msg</font></p>
		               <table border='1' cellpadding='0' cellspacing='0' width='80%' bordercolor='$sas_lang[forum_bordercolor]'>
		               <tr>
		               <td width='100%'>
		               <table border='0' cellpadding='3' cellspacing='0' width='100%'>
		               <tr>
		               <td width='50%' align='right' bgcolor='$OddBackgroundColor'>
		               <font face='Arial' size='2'>$sas_lang[forum_userid]</font></td>
		               <td width='50%' bgcolor='$OddBackgroundColor'>
		               <font face='Arial' size='2'><b>$forumuserid</b></font></td>
		               </tr>
		               <tr>
		               <td width='50%' align='right' bgcolor='$EvenBackgroundColor'>
		               <font face='Arial' size='2'>$sas_lang[forum_password]</font></td>
		               <td width='50%' bgcolor='$EvenBackgroundColor'>
		               <font face='Arial' size='2'><b>$password</b></font></td>
		               </tr>
		               <tr>
		               <td width='50%' align='right' bgcolor='$OddBackgroundColor'>
		               <font face='Arial' size='2'>$sas_lang[forum_firstname]</font></td>
		               <td width='50%' bgcolor='$OddBackgroundColor'><font face='Arial' size='2'>
		               <b>$firstname</b></font></td>
		               </tr>
		               <tr>
		               <td width='50%' align='right' bgcolor='$EvenBackgroundColor'>
		               <font face='Arial' size='2'>$sas_lang[forum_name]</font></td>
		               <td width='50%' bgcolor='$EvenBackgroundColor'>
		               <font face='Arial' size='2'><b>$lastname</b></font></td>
		               </tr>
		               <tr>
		               <td width='50%' align='right' bgcolor='$OddBackgroundColor'>
		               <font face='Arial' size='2'>$sas_lang[forum_email]</font></td>
		               <td width='50%' bgcolor='$OddBackgroundColor'>
		               <font face='Arial' size='2'><b>$emailaddress</b></font></td>
		               </tr>
		               <tr>
		               <td width='50%' align='right' bgcolor='$EvenBackgroundColor'>
		               <font face='Arial' size='2'>$sas_lang[forum_email_visible]</font></td>";
		if ($semail == 1)
		{
			$tmptext = $sas_lang[forum_yes];
		}
		else
		{
			$tmptext = $sas_lang[forum_no];
		}
		print "<td width='50%' bgcolor='$EvenBackgroundColor'>
		               <font face='Arial' size='2'><b>$tmptext</b></font></td>
		               </tr>";
		print "<tr>
		               <td width='50%' align='right' bgcolor='$OddBackgroundColor'>
		               <font face='Arial' size='2'>$sas_lang[forum_website]</font></td>
		               <td width='50%' bgcolor='$OddBackgroundColor'>
		               <font face='Arial' size='2'><b>$weburl</b></font></td>
		               </tr>";
		print "<tr>
		               <td width='50%' align='right' bgcolor='$OddBackgroundColor'>
		               <font face='Arial' size='2'>$sas_lang[forum_header]</font></td>
		               <td width='50%' align='left' bgcolor='$OddBackgroundColor'>
		               <font face='Arial' size='2'><b>$forum_title</b></font></td>
		               </tr>
		               <tr>";
		print "<td width='50%' align='right' bgcolor='$EvenBackgroundColor'>
		               <font face='Arial' size='2'>$sas_lang[forum_joined_date]</font></td>";
		$ts = mktime(substr($now, 11, 2), substr($now, 14, 2), substr($now, 17, 2), substr($now, 5, 2), substr($now, 8, 2), substr($now, 0, 4));
		print "<td width='50%' bgcolor='$EvenBackgroundColor'>
		               <font face='Arial' size='2'><b>" . date("D d F Y H:i:s", $ts) . "</b></font></td>
		               </tr>
		               </table>
		               </td></tr>
		               </table>";
		print "<p><table cellspacing=\"0\" cellpadding=\"0\"><tr height=\"25\">
		               <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
		               <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
		               <a href = 'index.php?section=$section&page=$page&forumid=$forumid&option=forum'><b>$sas_lang[forum_main_page]</b></a></td>
		               <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
		               <td width=\"10\">&nbsp;</td>
		               <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
		               <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
		               <a href = 'index.php?option=login&section=$section&page=$page&forumid=$forumid'><b>$sas_lang[forum_login]</b></a></td>
		               <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
		               </tr></table>";
	}
}
if (($error) or ($save != "yes"))
{
	$result2 = mysql_query("SELECT name FROM $forumcat_table WHERE cat_index = '$forumid'");
	if (mysql_num_rows($result2) > 0) //get the forum title 
	{
		$forum_title = mysql_result($result2, 0);
	}
	print "<table border='0' cellpadding='2' cellspacing='0' width='100%'>
	            <tr>
	            <td width='100%'>
	            <font face='Arial' size='4'>$sas_lang[forum_create_account] $forum_title</font></td>
	            </tr>
	            </table><br>
	            <form method='POST' action='index.php?option=newacc&save=yes&section=$section&page=$page&forumid=$forumid' name='ForumNewAccSubmit'>
	            <center>
	            <table border='1' cellpadding='0' cellspacing='0' width='70%' bordercolor='$sas_lang[forum_bordercolor]'>
	            <tr>
	            <td width='100%'>
	            <table border='0' cellpadding='3' cellspacing='0' width='100%'>
	            <tr>
	            <td width='50%' align='right' bgcolor='$OddBackgroundColor'><font face='Arial' size='2'>$sas_lang[forum_userid]</font></td>
	            <td width='50%' bgcolor='$OddBackgroundColor'>
	            <input tabindex='1' type='text' name='forumuserid' value='$forumuserid' size='30'></td>
	            </tr>
	            <tr>
	            <td width='50%' align='right' bgcolor='$EvenBackgroundColor'>
	            <font face='Arial' size='2'>$sas_lang[forum_password]</font></td>
	            <td width='50%' bgcolor='$EvenBackgroundColor'>
	            <input tabindex='2' type='password' name='password' value='$password' size='30'></td>
	            </tr>
	            <tr>
	            <td width='50%' align='right' bgcolor='$OddBackgroundColor'>
	            <font face='Arial' size='2'>$sas_lang[forum_password]</font></td>
	            <td width='50%' bgcolor='$OddBackgroundColor'>
	            <input tabindex='3' type='password' name='password2' value='$password2' size='30'></td>
	            </tr>
	            <tr>
	            <td width='50%' align='right' bgcolor='$EvenBackgroundColor'>
	            <font face='Arial' size='2'>$sas_lang[forum_firstname]</font></td>
	            <td width='50%' bgcolor='$EvenBackgroundColor'>
	            <input tabindex='4' type='text' name='firstname' size='30' value='$firstname'>                           
	            </td>
	            </tr>
	            <tr>
	            <td width='50%' align='right' bgcolor='$OddBackgroundColor'>
	            <font face='Arial' size='2'>$sas_lang[forum_name]</font></td>
	            <td width='50%' bgcolor='$OddBackgroundColor'>
	            <input tabindex='5' type='text' name='lastname' value='$lastname' size='30'></td>
	            </tr>
	            <tr>
	            <td width='50%' align='right' bgcolor='$EvenBackgroundColor'>
	            <font face='Arial' size='2'>$sas_lang[forum_email]</font></td>
	            <td width='50%' bgcolor='$EvenBackgroundColor'>
	            <input tabindex='6' type='text' name='emailaddress' value='$emailaddress' size='30'></td>
	            </tr>
	            <tr>
	            <td width='50%' align='right' bgcolor='$OddBackgroundColor'>
	            <font face='Arial' size='2'>$sas_lang[forum_website]</font></td>
	            <td width='50%' bgcolor='$OddBackgroundColor'>
	            <input tabindex='7' type='text' name='weburl' value='$weburl' size='45'></td>
	            </tr>
	            <tr>
	            <td width='50%' align='right' bgcolor='$EvenBackgroundColor'>
	            <font face='Arial' size='2'>$sas_lang[forum_email_visible]</font></td>
	            <td width='50%' bgcolor='$EvenBackgroundColor'>
	            <input tabindex='8' type='checkbox' name='showemail'></td>
	            </tr>                                            
	            <td width='100%' colspan='2' align='center' bgcolor='$OddBackgroundColor'>
	            <input tabindex='9' type='submit' value='$sas_lang[forum_send]' name='B1'></td>
	            </tr> 
	            </table> 
	            </td></tr> 
	            </table> 
	            </center> 
	            </form>
	            <table cellspacing=\"0\" cellpadding=\"0\"><tr height=\"25\">
	            <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
	            <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
	            <a href = 'index.php?section=$section&page=$page&forumid=$forumid&option=forum'><b>$sas_lang[forum_main_page]</b></a></td>
	            <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
	            </tr></table>";
}
?>
