<?php

/********************************************************************************
	- MemHT Portal -
	
	Copyright (C) 2007-2008 by Miltenovik Manojlo
	http://www.memht.com
	
	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 opinion) 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, see <http://www.gnu.org/licenses/> (GPLv2)
	or write to the Free Software Foundation, Inc., 51 Franklin Street,
	Fifth Floor, Boston, MA02110-1301, USA.
		
********************************************************************************/

if (!defined("_LOAD_PAGE_")) {
	die("<table style='padding: 2px; border: 1px solid #999; background-color: #EEE; font-family: Verdana; font-size: 10px;' align='center'><tr><td><b>Error:</b> This file cannot be opened directly!</td></tr></table>");
}

$op = (isset($_GET['op'])) ? inCode($_GET['op']) : "" ;
$usert = (isset($_GET['usert'])) ? inCode($_GET['usert']) : "" ;
$uid = (isset($_GET['uid'])) ? intval($_GET['uid']) : 0 ;

function login() {
	global $dblink,$siteConfig,$visitorInfo,$userid,$page;
	
	if (isUser($userid)) {
		$row_info = $dblink->get_row("SELECT *,DATE_FORMAT(regdate, '".$siteConfig['timestamp']."') as regdate FROM memht_utenti WHERE id=$userid");
		$user = outCode($row_info['user']);
		$pass = $row_info['pass'];
		$email = outCode($row_info['email']);
		$regdate = $row_info['regdate'];
		$sito = outCode($row_info['sito']);
		$icq = outCode($row_info['icq']);
		$msn = outCode($row_info['msn']);
		$aol = outCode($row_info['aol']);
		$yahoo = outCode($row_info['yahoo']);
		$avatar = outCode($row_info['avatar']);
		$post = intval($row_info['post']);
		$gender = intval($row_info['gender']);
		$title_enabled = intval($row_info['title_enabled']);
		$title_text = outCode($row_info['title_text']);
		$signature = censure(bb2html(outCode($row_info['signature'],0)));
		$feedurl = outCode($row_info['feed']);
		$contributes = intval($row_info['contributes']);
		
		if ($avatar=="") { $avatar = "blank.png"; }
		switch ($gender) {
			case 1: $gender_img = "<img src='images/male.gif' alt='"._MALE_."' title='"._MALE_."'>"; break;
			case 2: $gender_img = "<img src='images/female.gif' alt='"._FEMALE_."' title='"._FEMALE_."'>"; break;
			default: $gender_img = "<img src='images/neutral.gif' alt='"._NEUTRAL_."' title='"._NEUTRAL_."'>"; break;
		}
		
		if (file_exists("templates/".$siteConfig['template']."/images/users/profile.gif")) {
			$prfimg = "<img src='templates/".$siteConfig['template']."/images/users/profile.gif' border='0' alt='"._USERS_PROFILE_."'>";
		} else {
			$prfimg = "<img src='pages/$page/images/profile.gif' border='0' alt='"._USERS_PROFILE_."'>";
		}
		if (file_exists("templates/".$siteConfig['template']."/images/users/logout.gif")) {
			$lotimg = "<img src='templates/".$siteConfig['template']."/images/users/logout.gif' border='0' alt='"._LOGOUT_."'>";
		} else {
			$lotimg = "<img src='pages/$page/images/logout.gif' border='0' alt='"._LOGOUT_."'>";
		}
		
		//
		if ($pm = $dblink->get_num("SELECT id FROM memht_pvtmsg WHERE recipient='$user' AND new=1")) {
			openTable();
				echo "<div class='box'><a href='index.php?page=pvtmsg' title='"._NEWMESSAGES_."'><font color='#990000'><b>"._NEWMESSAGES_."</b></a>: $pm</font></div>";
			closeTable();
		}
		if ($result = $dblink->get_list("SELECT *,DATE_FORMAT(joined, '".$siteConfig['timestamp']."') as joined,DATE_FORMAT(expire, '".$siteConfig['timestamp']."') as expire FROM memht_groups_members WHERE user=$userid")) {
			foreach ($result as $row) {
				$groupid = intval($row['groupid']);
				$permanent = intval($row['permanent']);
				$joined = outCode($row['joined']);
				$expire = outCode($row['expire']);
				$standby = intval($row['standby']);
				
				if ($expire==0 AND $permanent) { $expire = _PERMANENT_; }
				
				$row = $dblink->get_row("SELECT * FROM memht_groups WHERE id=$groupid");
				$groupname = outCode($row['name']);
				
				openTable();
				if ($standby) {
					echo "<div class='box'><b>"._MEMBERSHIP_EXPIRED_.":</b><br>&nbsp;&nbsp;- "._GROUP_.": <b>$groupname</b> (<i>"._JOINED_."</i>: $joined - <i>"._EXPIRE_."</i>: $expire)</div>";
				} else {
					echo "<div class='box'><b>"._GROUPS_.":</b><br>&nbsp;&nbsp;- "._GROUP_.": <b>$groupname</b> (<i>"._JOINED_."</i>: $joined - <i>"._EXPIRE_."</i>: $expire)</div>";
				}
				closeTable();
			}
		}
		//

		openTable(_USERINFO_);
		
		echo "<div align='center'><a href='index.php?page=users&op=editProfile' title='"._MODIFYPROFILE_."'>$prfimg</a> <a href='index.php?page=users&logout=1' title='"._LOGOUT_."'>$lotimg</a></div>\n";
			
			echo "<table width='100%' border='0' cellspacing='0' cellpadding='2'>\n";
				echo "<tr>\n";
					echo "<td width='25%' valign='top'>\n";
						echo "<b>$user</b><br>\n";
						if ($title_enabled==1) {
							echo "<span class='small'>$title_text</span><br>\n";
						}
						echo "<img src='images/avatar/$avatar' border='0' title='$user' alt='"._AVATAR_."'><br>\n";
						echo "<br>\n";
						echo "<b>"._POSTS_.":</b> $post\n";
						
						$row = $dblink->get_row("SELECT contributes FROM memht_utenti ORDER BY contributes DESC LIMIT 1");
						$maxcontr = intval($row['contributes']);
						$imgcontrib = ceil(@($contributes/$maxcontr)*9);
						if ($imgcontrib<0) { $imgcontrib = 0; }
						if ($imgcontrib>9) { $imgcontrib = 9; }
						echo "<br><img src='images/bars/{$imgcontrib}.gif' alt='"._CONTRIBUTES_.": $contributes' title='"._CONTRIBUTES_.": $contributes'><br><br>\n";
						
						echo "<b>"._GENDER_.":</b> $gender_img<br><br>\n";
					echo "</td>\n";
					echo "<td width='75%' valign='top'>\n";
						echo "<table width='100%' border='0' cellspacing='0' cellpadding='2'>\n";
							echo "<tr><td width='5%'><b>"._REGISTERED_.":</b>&nbsp;</td><td>$regdate</td></tr>\n";
							echo "<tr><td><b>"._EMAIL_.":</b></td><td>$email</td></tr>\n";
							if ($sito!="") { echo "<tr><td><b>"._SITE_.":</b></td><td>$sito</td></tr>\n"; }
							if ($icq!="") { echo "<tr><td><b>"._ICQ_.":</b></td><td>$icq</td></tr>\n"; }
							if ($msn!="") { echo "<tr><td><b>"._MSN_.":</b></td><td>$msn</td></tr>\n"; }
							if ($aol!="") { echo "<tr><td><b>"._AOL_.":</b></td><td>$aol</td></tr>\n"; }
							if ($yahoo!="") { echo "<tr><td><b>"._YAHOO_.":</b></td><td>$yahoo</td></tr>\n"; }
							//Customized profile
							//3.8.5
							if ($result = $dblink->get_list("SELECT title,content FROM memht_utenti_profile AS p JOIN memht_utenti_profile_data AS d ON p.id=d.pid WHERE d.uid=$userid")) {
								echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
								foreach ($result as $row) {
									$ptitle = outCode($row['title']);
									$pcontent = outCode($row['content']);
									if ($pcontent!="") { echo "<tr><td valign='top'><b>$ptitle:</b></td><td valign='top'>$pcontent</td></tr>\n"; }
								}
							}
						echo "</table>\n";
					echo "</td>\n";
				echo "</tr>\n";
				if ($signature!="") {
					echo "<tr><td colspan='2'><div class='box' style='overflow:auto;'>$signature<div></td></tr>\n";
				}
			echo "</table>\n";
		closeTable();
		
		openTable(_RSS_FEEDS_);
			if ($feedurl!="") {
				define('MAGPIE_CACHE_DIR', 'inc/magpie/cache');
				require_once("inc/magpie/rss_fetch.inc");
				if ($rss = @fetch_rss($feedurl)) {
				echo "<div class='box'><b>".@$rss->channel['title']."</b></div>";
					foreach ($rss->items as $item) {
						$href = @$item['link'];
						$title = @$item['title'];
						if ($href!="" AND $title!="") {
							echo "<div><img src='images/bullet_paper.gif' alt='Bullet'> <a href=\"$href\" target='_blank' title=\"$title\">$title</a></div>";
						}
					}
				} else {
					echo "<div align='center' id='errorText' class='box'><b>"._CANNOTREADFEED_."</b></div>";
				}
			} else {
				echo "<div align='center' class='box'><b>"._NOFEEDSELECTED_."</b></div>";
			}
		closeTable();
	} else {
		openTable();
			if ($dblink->get_num("SELECT ip FROM memht_login_flood WHERE ip='".$visitorInfo['ip']."' AND attempts>=5")==0) {
				echo "<form name='user01' method='post' action='index.php?page=users'>\n";
				echo "<table align='center' border='0'>\n";
				echo "<tr><td><b>"._USERNAME_."</b></td><td><input type='text' name='post_username'></td></tr>\n";
				echo "<tr><td><b>"._PASSWORD_."</b></td><td><input type='password' name='post_password'></td></tr>\n";
				echo "<tr><td><input type='submit' name='Submit' value='"._LOGIN_."'></td><td><a href='index.php?page=users&op=register' title='"._REGISTER_."'>"._REGISTER_."</a></td></tr>\n";
				echo "<tr><td>&nbsp;</td><td><a href='index.php?page=users&op=lostPassword' title='"._LOSTPASS_."'>"._LOSTPASS_."</a></td></tr>";
				echo "</table>\n";
				echo "<input type='hidden' name='login' value='true'>";
				echo "</form>\n";
			} else {
				echo "<div align='center'><b>"._YOUMUSTWAITTOLOGINAGAIN_."</b></div>\n";
			}
		closeTable();		
	}
}

function newAccount() {
	global $dblink,$siteConfig,$visitorInfo,$tzNOW;

	if (isset($_POST['reg'])) { $reg = inCode($_POST['reg']); } else { $reg = false; }
	
	openTable();
	
	if (!$reg) {
		$infoimg_user = " <img src='images/info.gif' border='0' title='header=["._INFORMATIONS_."] body=[<b>"._ACCEPTED_CHARACTERS_.":</b> a-zA-Z0-9._-<br><b>"._LENGTH_.":</b> 4-".$siteConfig['user_max_lunghezza']."]' alt='"._INFORMATIONS_."'>";
		$infoimg_pass = " <img src='images/info.gif' border='0' title='header=["._INFORMATIONS_."] body=[<b>"._ACCEPTED_CHARACTERS_.":</b> a-zA-Z0-9._-<br><b>"._LENGTH_.":</b> 4-".$siteConfig['pass_max_lunghezza']."]' alt='"._INFORMATIONS_."'>";
		$infoimg_email = " <img src='images/info.gif' border='0' title='header=["._INFORMATIONS_."] body=[<b>"._FORMAT_.":</b> a-zA-Z0-9._- <b>(at)</b> a-zA-Z0-9._- <b>(dot)</b> a-zA-Z]' alt='"._INFORMATIONS_."'>";
		
		echo "<div align='center'>\n";
			echo "<form name='user02' method='post' action='index.php?page=users&op=register'>\n";
				echo "<table border='0' align='center'>\n";
				echo "<tr><td nowrap><b>"._USERNAME_."</b>$infoimg_user</td><td align='right'><input type='text' name='post_username'></td></tr>\n";
				echo "<tr><td nowrap><b>"._PASSWORD_."</b>$infoimg_pass</td><td align='right'><input type='password' name='post_password'></td></tr>\n";
				echo "<tr><td nowrap><b>"._EMAIL_."</b>$infoimg_email</td><td align='right'><input type='text' name='post_email'></td></tr>\n";
				echo "<tr><td><b>"._NEWSLETTER_."</b></td><td align='right'><span class='info'>"._SUBSCRIBE_."</span> <input type='checkbox' name='post_newsletter' value='true' checked></td></tr>\n";
				if (extension_loaded('gd') AND $siteConfig['graphic_check']==1) {
					echo "<tr><td valign='bottom' align='right' class='info'>"._CODE_."<br><input type='text' name='post_code_page' size='8' maxlength='255'></td><td><img src='".$siteConfig['site_url']."/imgCode.php?name=chk_users&nc=".md5(time()+rand())."' title='header=["._SECURITY_CODE_."] body=["._SECURITY_CODE_TEXT_."]' alt='Captcha'></td></tr>";
				}
				echo "<tr><td colspan='2' align='right'><input type='submit' name='Submit' value='"._REGISTER_."'></td></tr>\n";
				echo "</table>\n";
			echo "<input type='hidden' name='reg' value=true>";
			echo "</form>\n";
			

			echo "<div id='usercontainer' style='width:200px;'></div>\n";
		echo "</div>\n";
	} else {
		if (isset($_POST['post_username'])) { $post_username = inCode($_POST['post_username']); } else { $post_username = ""; }
		if (isset($_POST['post_password'])) { $post_password = inCode($_POST['post_password']); } else { $post_password = ""; }
		if (isset($_POST['post_email'])) { $post_email = inCode($_POST['post_email']); } else { $post_email = ""; }
		if (isset($_POST['post_newsletter']) AND $_POST['post_newsletter']==true) { $post_newsletter = 1; } else { $post_newsletter = 0; }
		
		@session_start();
		if ((isset($_POST['post_code_page']) AND isset($_SESSION['chk_users']) AND strtolower($_POST['post_code_page'])==strtolower($_SESSION['chk_users'])) OR !(extension_loaded('gd') AND $siteConfig['graphic_check']==1)) {
			$save = true;
			if ($row = $dblink->get_row("SELECT id FROM memht_utenti WHERE user='$post_username' OR email='$post_email'")) {
				$save = false;
				$msg = _USERALREADYEXISTS_." "._OR_." "._EMAILALREADYEXISTS_;
			}
			if ($row = $dblink->get_row("SELECT id FROM memht_utenti_attesa WHERE user='$post_username' OR email='$post_email'")) {
				$save = false;
				$msg = _USERALREADYEXISTS_."  "._OR_." "._EMAILALREADYEXISTS_;
				resendCode(intval($row['id']));
			}
			if (!validUser($post_username)) { $save = false; $msg = _INVALIDUSER_; }
			if (!validPass($post_password)) { $save = false; $msg = _PASSNOTVALID_; }
			if (!validEmail($post_email)) { $save = false; $msg = _MAILNOTVALID_; }
			
			if ($save) {
				if ($siteConfig['approve_users']==0) {
					//No moderation
					if ($siteConfig['user_confirm_email']==1) {
						//Email confirmation
						$codice = randString(10);
						$dblink->query("INSERT INTO memht_utenti_attesa (id,user,pass,email,newsletter,lastip,data,codice)
										VALUES (null,'$post_username','".md5($post_password)."','$post_email','$post_newsletter','".$visitorInfo['ip']."',$tzNOW,'$codice')");
						
						$row = $dblink->get_row("SELECT id FROM memht_utenti_attesa ORDER BY id DESC LIMIT 1");
						$actid = intval($row['id']);
						
						$subject = $siteConfig['site_name']." - "._REGISTRATION_;
						$msg = "$subject\n\n";
						$msg .= _WELCOMETO_." ".$siteConfig['site_name']."!\n\n";
						$msg .= _FOLLOWLINKTOACTIVATE_.":\n";
						$msg .= _LINK_.": ".$siteConfig['site_url']."/index.php?page=users&op=activate&actid=$actid&actcode=$codice\n\n";
						$msg .= _IP_." ".$visitorInfo['ip']."\n\n";

						sendEmail($post_email,$subject,$msg,$siteConfig['site_name'],$siteConfig['webmaster_mail'],0);
						echo "<div align='center'><b>"._REGRECEIVED_."</b><br>"._YOULLRECEIVEACTIVATIONLINK_.".</div>";
					} else {
						//No email confirmation
						if (memRunHooks('ActivateUser',array($post_username,$post_password,$post_email))) {
							$dblink->query("INSERT INTO memht_utenti (id,user,pass,email,regdate,lastip,lastlogin,enabled)
											VALUES (null,'$post_username','".md5($post_password)."','$post_email',$tzNOW,'".$visitorInfo['ip']."',$tzNOW,1)");
							
							memRunHooks('ActivateUserEnd',array($post_username,$post_password,$post_email));
						}
						if ($siteConfig['welcome_pm']!="") {
							$dblink->query("INSERT INTO memht_pvtmsg (id,recipient,author,name,text,date,smiles,new)
											VALUES (null,'$post_username','".$siteConfig['welcome_pm_author']."','".$siteConfig['welcome_pm_title']."','".$siteConfig['welcome_pm']."',$tzNOW,'1','1')");
						}
						if ($post_newsletter==1 AND $dblink->get_num("SELECT email FROM memht_newsletter WHERE email='$post_email'")==0) {
							if (memRunHooks('AddEmailToNewsletter',array($post_email))) {
								$dblink->query("INSERT INTO memht_newsletter (email,ip) VALUES ('$post_email','".$visitorInfo['ip']."')");
								
								memRunHooks('AddEmailToNewsletterEnd',array($post_email));
							}
						}
						echo "<div align='center'><b>"._ACCACTIVATED_."</b><br>"._NOWUCANEDITANDENTER_."</div>";
					}
				} else {
					//Moderation										
					if ($siteConfig['user_confirm_email']==1) {
						$codice = randString(10);
						$dblink->query("INSERT INTO memht_utenti_attesa (id,user,pass,email,newsletter,lastip,data,codice)
										VALUES (null,'$post_username','".md5($post_password)."','$post_email','$post_newsletter','".$visitorInfo['ip']."',$tzNOW,'$codice')");
						
						$row = $dblink->get_row("SELECT id FROM memht_utenti_attesa ORDER BY id DESC LIMIT 1");
						$actid = intval($row['id']);
						
						//Email confirmation
						$subject = $siteConfig['site_name']." - "._REGISTRATION_;
						$msg = "$subject\n\n";
						$msg .= _WELCOMETO_." ".$siteConfig['site_name']."!\n\n";
						$msg .= _FOLLOWLINKTOACTIVATE_.":\n";
						$msg .= _LINK_.": ".$siteConfig['site_url']."/index.php?page=users&op=activate&actid=$actid&actcode=$codice\n\n";
						$msg .= _IP_." ".$visitorInfo['ip']."\n\n";
					
						sendEmail($post_email,$subject,$msg,$siteConfig['site_name'],$siteConfig['webmaster_mail'],0);
						echo "<div align='center'><b>"._REGRECEIVED_."</b><br>"._YOULLRECEIVEACTIVATIONLINK_.".</div>";
					} else {
						//No email confirmation
						$codice = randString(10);
						$dblink->query("INSERT INTO memht_utenti_attesa (id,user,pass,email,newsletter,lastip,data,codice,activated)
										VALUES (null,'$post_username','".md5($post_password)."','$post_email','$post_newsletter','".$visitorInfo['ip']."',$tzNOW,'$codice','1')");
									
						echo "<div align='center'><b>"._REGRECEIVED_."</b><br>"._YOULLRECEIVEEMAILADMINACTIVATED_.".</div>";
					}
				}
			} else {
				echo "<div align='center' id='errorText'><b>$msg</b></div>";
			}
		} else {
			echo "<div align='center' id='errorText'><b>"._WRONGSECCODE_."</b></div>";
		}
	}
	
	closeTable();
}

function activateAccount() {
	global $dblink,$visitorInfo,$siteConfig,$tzNOW;

	openTable();
	
	if (isset($_GET['actid']) && isset($_GET['actcode'])) {
		$actid = intval($_GET['actid']);
		$actcode = inCode($_GET['actcode']);
		if ($row = $dblink->get_row("SELECT user,email,pass,newsletter FROM memht_utenti_attesa WHERE id='$actid' AND codice='$actcode'")) {
			$actuser = outCode($row['user']);
			$pass = $row['pass'];
			$email = outCode($row['email']);
			$newsletter = intval($row['newsletter']);
			if ($siteConfig['approve_users']==0) {
				//No moderation
				$dblink->query("DELETE FROM memht_utenti_attesa WHERE id=$actid");
				
				if (memRunHooks('ActivateUserMd5',array($actuser,$pass,$email))) {
					$dblink->query("INSERT INTO memht_utenti (id,user,pass,email,regdate,lastip,lastlogin,enabled)
									VALUES (null,'$actuser','$pass','$email',$tzNOW,'".$visitorInfo['ip']."',$tzNOW,1)");
					
					memRunHooks('ActivateUserMd5End',array($actuser,$pass,$email));
				}
				if ($siteConfig['welcome_pm']!="") {
					$dblink->query("INSERT INTO memht_pvtmsg (id,recipient,author,name,text,date,smiles,new)
									VALUES (null,'$actuser','".$siteConfig['welcome_pm_author']."','".$siteConfig['welcome_pm_title']."','".$siteConfig['welcome_pm']."',$tzNOW,'1','1')");
				}
				if ($newsletter==1 AND $dblink->get_num("SELECT email FROM memht_newsletter WHERE email='$email'")==0) {
					if (memRunHooks('AddEmailToNewsletter',array($email))) {
						$dblink->query("INSERT INTO memht_newsletter (email,ip) VALUES ('$email','".$visitorInfo['ip']."')");
						
						memRunHooks('AddEmailToNewsletterEnd',array($email));
					}
				}
				echo "<div align='center'><b>"._ACCACTIVATED_."</b><br>"._NOWUCANEDITANDENTER_."</div>";
			} else {
				//Moderation
				$dblink->query("UPDATE memht_utenti_attesa SET activated='1' WHERE user='$actuser' AND codice='$actcode'");
				echo "<div align='center'><b>"._ACCACTIVATED_."</b><br>"._YOULLRECEIVEEMAILADMINACTIVATED_."</div>";
			}
		} else {
			echo "<div align='center' id='errorText'><b>"._USERNOTFOUND_." "._OR_." "._WRONGCODE_."</b></div>";
		}
	} else {
		echo "<div align='center' id='errorText'><b>"._DATAMISSING_."</b></div>";
	}
	
	closeTable();
}

function resendCode($reactid) {
	global $dblink,$siteConfig,$visitorInfo;

	if ($row_resend = $dblink->get_row("SELECT * FROM memht_utenti_attesa WHERE id=$reactid")) {
		$recodice = $row_resend['codice'];
		$reemail = outCode($row_resend['email']);
	
		$subject = $siteConfig['site_name']." "._REGISTRATION_."";
		$msg = "$subject\n\n";
			
		$msg .= _WELCOMETO_." ".$siteConfig['site_name']."!\n\n";
		$msg .= _FOLLOWLINKTOACTIVATE_.":\n";
		$msg .= _LINK_.": ".$siteConfig['site_url']."/index.php?page=users&op=activate&actid=$reactid&actcode=$recodice\n\n";
		$msg .= _IP_." ".$visitorInfo['ip']."\n\n";
		
		$mailheaders = "From: ".$siteConfig['site_name']." <".$siteConfig['webmaster_mail'].">\n";
		$mailheaders .= "Reply-To: ".$siteConfig['webmaster_mail']."\n";
		$mailheaders .= "Content-type: text/plain; charset="._LANG_CHARSET_."\n";
		$mailheaders .= "Content-transfer-encoding: 8bit\n";
		$mailheaders .= "X-Mailer: PHP/".phpversion();
				
		sendEmail($reemail,$subject,$msg,$siteConfig['site_name'],$siteConfig['webmaster_mail'],0);
	}
}

function changeProfile() {
	global $dblink,$siteConfig,$userid;
	
	if (isset($_POST['chg'])) { $chg = inCode($_POST['chg']); } else { $chg = false; }
	
	if (!$chg) {
		if (isUser($userid)) {
			$row_info = $dblink->get_row("SELECT * FROM memht_utenti WHERE id=$userid");
			$user = outCode($row_info['user']);
			$pass = $row_info['pass'];
			$email = outCode($row_info['email']);
			$showemail = intval($row_info['showemail']);
			$sito = outCode($row_info['sito']);
			$icq = outCode($row_info['icq']);
			$msn = outCode($row_info['msn']);
			$aol = outCode($row_info['aol']);
			$yahoo = outCode($row_info['yahoo']);
			$notify_pvtmsg = intval($row_info['notify_pvtmsg']);
			$notify_forum = intval($row_info['notify_forum']);
			$avatar = outCode($row_info['avatar']);	
			$gender = intval($row_info['gender']);
			$signature = outCode($row_info['signature']);
			$showsignature = censure(bb2html(outCode($row_info['signature'],0)));
			$feedurl = outCode($row_info['feed']);
					
			openTable(_MODIFYPROFILE_);
			echo "<table width='100%' border='0' cellspacing='0' cellpadding='2'>\n";
				echo "<form name='form' method='post' action='index.php?page=users&op=editProfile' enctype='multipart/form-data'>\n";
				echo "<tr><td width='25%'><b>"._USERNAME_."</b></td><td><b>$user</b></td></tr>\n";
				echo "<tr><td><b>"._EMAIL_."</b></td><td><input type='text' name='chg_email' value=\"$email\" size='30' maxlength='255'></td></tr>\n";
				echo "<tr><td nowrap><b>"._SHOWEMAILINPROFILE_."</b></td><td>";
					echo "<select name='chg_showemail'>";
						if ($showemail==1) {
							echo "<option value='1' selected>"._YES_."</option>\n";
							echo "<option value='0'>"._NO_."</option>\n";
						} else {
							echo "<option value='1'>"._YES_."</option>\n";
							echo "<option value='0' selected>"._NO_."</option>\n";
						}
					echo "</select>";
				echo "</td></tr>\n";	
				echo "<tr><td><b>"._SITE_."</b></td><td><input type='text' name='chg_sito' value=\"$sito\" size='30' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._ICQ_."</b></td><td><input type='text' name='chg_icq' value=\"$icq\" size='30' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._MSN_."</b></td><td><input type='text' name='chg_msn' value=\"$msn\" size='30' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._AOL_."</b></td><td><input type='text' name='chg_aol' value=\"$aol\" size='30' maxlength='255'></td></tr>\n";
				echo "<tr><td><b>"._YAHOO_."</b></td><td><input type='text' name='chg_yahoo' value=\"$yahoo\" size='30' maxlength='255'></td></tr>\n";
				
				echo "<tr><td nowrap><b>"._NOTIFICATION_."</b> ("._MESSAGES_.")<b></b><div class='info'>"._ALWAYS_."</div></td><td>";
					echo "<select name='chg_notify_pvtmsg'>";
						if ($notify_pvtmsg==1) {
							echo "<option value='1' selected>"._YES_."</option>\n";
							echo "<option value='0'>"._NO_."</option>\n";
						} else {
							echo "<option value='1'>"._YES_."</option>\n";
							echo "<option value='0' selected>"._NO_."</option>\n";
						}
					echo "</select>";
				echo "</td></tr>\n";
				echo "<tr><td nowrap><b>"._NOTIFICATION_."</b> ("._FORUM_.")<b></b><div class='info'>"._ALWAYS_."</div></td><td>";
					echo "<select name='chg_notify_forum'>";
						if ($notify_forum==1) {
							echo "<option value='1' selected>"._YES_."</option>\n";
							echo "<option value='0'>"._NO_."</option>\n";
						} else {
							echo "<option value='1'>"._YES_."</option>\n";
							echo "<option value='0' selected>"._NO_."</option>\n";
						}
					echo "</select>";
				echo "</td></tr>\n";						
				echo "<tr><td valign='top'><b>"._AVATAR_."</b></td><td><img name='chgavapro' src='images/avatar/$avatar' border='0' title='$user' alt='Avatar'>";
					echo "<div style='padding:2px 0 0 0;'><select name='chg_avatar' onChange=\"document.form.chgavapro.src = 'images/avatar/'+this.options[this.selectedIndex].value;\">\n";
					unset($filearray);
					$filearray = array();
					$handle = opendir('images/avatar/');
					while (false !== ($file = readdir($handle))) {
						if ($file != "." AND $file != ".." AND $file!="blank.png" AND $file!="nosel.png" AND $file!="Thumbs.db" AND $file!="uploaded") {
								$filearray[] = "<option value='$file'>$file</option>\n";
						}
					}
					closedir($handle);
					@sort($filearray);
					@reset($filearray);
					echo "<option value='blank.png'>- "._NOAVATAR_." -</option>\n";
					echo "<option value='$avatar' selected>- "._DO_NOT_CHANGE_." -</option>\n";
					echo "<option value='$avatar'>----------------</option>\n";
					foreach($filearray as $line) {
						echo $line;
					}
					echo "</select></div>\n";
					
					//echo "<div style='padding:2px 0 0 0;'><input type='file' name='avatar' size='25'></div>";
					
				echo "</td></tr>\n";
				echo "<tr><td><b>"._GENDER_."</b></td><td>";
					echo "<select name='chg_gender'>\n";
						if ($gender==0) {
							echo "<option value='0' selected>"._NEUTRAL_."</option>\n";
							echo "<option value='1'>"._MALE_."</option>\n";
							echo "<option value='2'>"._FEMALE_."</option>\n";
						} else if ($gender==1) {
							echo "<option value='0'>"._NEUTRAL_."</option>\n";
							echo "<option value='1' selected>"._MALE_."</option>\n";
							echo "<option value='2'>"._FEMALE_."</option>\n";
						} else {
							echo "<option value='0'>"._NEUTRAL_."</option>\n";
							echo "<option value='1'>"._MALE_."</option>\n";
							echo "<option value='2' selected>"._FEMALE_."</option>\n";
						}
					echo "</select>\n";
				echo "</td></tr>\n";
				echo "<tr><td><b>"._RSS_FEEDS_."</b></td><td><select name='feedurl'>";
				$result = $dblink->get_list("SELECT title,link FROM memht_rssreader_links ORDER BY title");
				foreach ($result as $row) {
					$title = outCode($row['title']);
					$link = outCode($row['link']);
					
					$selected = ($feedurl==$link) ? " selected" : "" ;
					echo "<option value=\"$link\"$selected>$title</option>\n";
				}
				echo "</select></td></tr>\n";
				echo "<tr><td valign='top' colspan='2'><b>"._SIGNATURE_."</b><br><br>";
				if ($showsignature!="") { echo "<div class='box' style='overflow:auto;'>$showsignature</div><br>"; }
				bbcodeToolbar("form","chg_signature","public");
				echo "<br>";
				textarea("chg_signature","100%","100px",0,"",$signature);
				echo "</td></tr>\n";
				
				//Customized profile
				//3.8.5
				if ($result = $dblink->get_list("SELECT * FROM memht_utenti_profile ORDER BY id ASC")) {
					echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
					$n = 0;
					foreach ($result as $row) {
						$id = intval($row['id']);
						$name = strtolower(outCode($row['name']));
						$title = outCode($row['title']);
						$type = outCode($row['type']);
						
						$rows = $dblink->get_row("SELECT content FROM memht_utenti_profile_data WHERE pid=$id AND uid=$userid");
						$value = outCode($rows['content']);
						
						switch ($type) {
							case 0 : $type = "<input type='text' name='cp_{$name}' value=\"$value\" size='30' maxlength='255'>\n"; break;
							case 1 : $type = "<textarea name='cp_{$name}' cols='30' rows='5'>$value</textarea>\n"; break;
						}
						
						$class = (($n++%2)==0) ? "" : "" ;
						echo "<tr><td valign='top'{$class}><b>$title</b></td><td{$class}>$type</td></tr>\n";
					}
					echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
				}
				
				echo "<tr><td colspan='2' class='small'>"._COMPILEONLYIFCHANGEPASS_.":</td></tr>\n";
				echo "<tr><td><b>"._ACTUALPASSWORD_."</b></td><td><input type='password' name='chg_pass0' size='20' maxlength='50'></td></tr>\n";
				echo "<tr><td><b>"._PASSWORD_."</b></td><td><input type='password' name='chg_pass' size='20' maxlength='50'></td></tr>\n";
				echo "<tr><td><b>"._REPASSWORD_."</b></td><td><input type='password' name='chg_pass2' size='20' maxlength='50'></td></tr>\n";
				echo "<input type='hidden' name='chg' value='true'>";
				echo "<tr><td colspan='2' align='center'><input type='submit' name='Submit' value='"._MODIFY_."'></td></tr>\n";
				echo "</form>\n";
			echo "</table>";
		closeTable();
		} else {
			openTable();
			echo "<div align='center' id='errorText'><b>"._ACCESSDENIED_."</b></div>";
			closeTable();
		}
	} else {
		if (isUser($userid)) {
			if (isset($_POST['chg_email'])) { $chg_email = inCode($_POST['chg_email']); } else { $chg_email = ""; }
			if (isset($_POST['chg_showemail'])) { $chg_showemail = intval($_POST['chg_showemail']); } else { $chg_showemail = 0; }
			if (isset($_POST['chg_sito'])) { $chg_sito = inCode($_POST['chg_sito']); } else { $chg_sito = ""; }
			if (isset($_POST['chg_icq'])) { $chg_icq = inCode($_POST['chg_icq']); } else { $chg_icq = ""; }
			if (isset($_POST['chg_msn'])) { $chg_msn = inCode($_POST['chg_msn']); } else { $chg_msn = ""; }
			if (isset($_POST['chg_aol'])) { $chg_aol = inCode($_POST['chg_aol']); } else { $chg_aol = ""; }
			if (isset($_POST['chg_yahoo'])) { $chg_yahoo = inCode($_POST['chg_yahoo']); } else { $chg_yahoo = ""; }
			if (isset($_POST['chg_notify_pvtmsg'])) { $chg_notify_pvtmsg = intval($_POST['chg_notify_pvtmsg']); } else { $chg_notify_pvtmsg = 0; }
			if (isset($_POST['chg_notify_forum'])) { $chg_notify_forum = intval($_POST['chg_notify_forum']); } else { $chg_notify_forum = 0; }
			if (isset($_POST['chg_avatar'])) { $chg_avatar = inCode($_POST['chg_avatar']); } else { $chg_avatar = ""; }
			if (isset($_POST['chg_gender'])) { $chg_gender = inCode($_POST['chg_gender']); } else { $chg_gender = ""; }
			if (isset($_POST['chg_signature'])) { $chg_signature = inCode($_POST['chg_signature']); } else { $chg_signature = ""; }
			if (isset($_POST['chg_pass0'])) { $chg_pass0 = inCode($_POST['chg_pass0']); } else { $chg_pass0 = ""; }
			if (isset($_POST['chg_pass'])) { $chg_pass = inCode($_POST['chg_pass']); } else { $chg_pass = ""; }	
			if (isset($_POST['chg_pass2'])) { $chg_pass2 = inCode($_POST['chg_pass2']); } else { $chg_pass2 = ""; }
			$feedurl = (isset($_POST['feedurl'])) ? inCode($_POST['feedurl']) : "" ;			
			
			$change = true;

			if ($chg_sito!="" AND !validate($chg_sito,"url")) { $change = false; $msg = "<b>"._FIELDINVALID_."</b>: "._SITE_; }
			if (!validEmail($chg_email)) { $change = false; $msg = _MAILNOTVALID_; }
			$row_info = $dblink->get_row("SELECT pass FROM memht_utenti WHERE id=$userid");
			$old_pass = $row_info['pass'];
			
			/*require_once("inc/class/uploadFile.class.php");
			$upload = new uploadFile();
			$upload->show_errors = false;
			$upload->path = "images/avatar/uploaded/";
			$upload->mime = array('image/gif','image/pjpeg','image/jpeg','image/png','image/tiff','image/bmp');
			$upload->max_width = $siteConfig['avatar_max_w'];
			$upload->max_height = $siteConfig['avatar_max_h'];
			
			$upload->field = "avatar";
			if ($avatar = $upload->upload()) {
				$chg_avatar = "uploaded/".$avatar;
			} else if ($upload->selected) {
				$change = false;
				$msg = $upload->error;
			}*/
			
			if ($chg_pass!="" AND $chg_pass2!="") {
				if (validPass($chg_pass) && md5($chg_pass0)==$old_pass && $chg_pass==$chg_pass2) {
					$passquery = ",pass='".md5($chg_pass)."'";
				} else {
					$change = false;
					$msg = _PASSNOTVALID_;
				}
			} else { $passquery = ""; }
	
			if ($change) {
				//Customized profile
				//3.8.5
				if ($result = $dblink->get_list("SELECT * FROM memht_utenti_profile ORDER BY id ASC")) {
					foreach ($result as $row) {
						$id = intval($row['id']);
						$name = strtolower(outCode($row['name']));
						$title = outCode($row['title']);
						$type = outCode($row['type']);
						
						if (isset($_POST['cp_'.$name])) { $val = inCode($_POST['cp_'.$name]); } else { $val = ""; }
						
						if ($val=="") {
							$dblink->query("DELETE FROM memht_utenti_profile_data WHERE pid=$id AND uid=$userid");
						} else {
							if ($dblink->get_num_noerr("SELECT id FROM memht_utenti_profile_data WHERE pid=$id AND uid=$userid")>0) {
								$dblink->query("UPDATE memht_utenti_profile_data SET content='$val' WHERE pid=$id AND uid=$userid");
							} else {
								$dblink->query("INSERT INTO memht_utenti_profile_data (id,uid,pid,content)
												VALUES (null,'$userid','$id','$val')");
							}
						}
					}
				}
				
				$dblink->query("UPDATE memht_utenti SET email='$chg_email',showemail='$chg_showemail',sito='$chg_sito',icq='$chg_icq',msn='$chg_msn',aol='$chg_aol',yahoo='$chg_yahoo',avatar='$chg_avatar',gender='$chg_gender',signature='$chg_signature',feed='$feedurl',notify_pvtmsg='$chg_notify_pvtmsg',notify_forum='$chg_notify_forum'{$passquery} WHERE id=$userid");
				echo "<meta http-equiv='refresh' content='0;URL=".$siteConfig['site_url']."/index.php?page=users'>";
			} else {
				openTable();
					echo "<div align='center' id='errorText'>$msg</div>";
				closeTable();
			}
		} else {
			openTable();
				echo "<div align='center' id='errorText'><b>"._ACCESSDENIED_."</b></div>";
			closeTable();
		}
	}
}

function lostPass() {
	global $dblink,$siteConfig,$visitorInfo;

	if (isset($_GET['chg'])) { $chg = inCode($_GET['chg']); } else { $chg = ""; }
	if (isset($_GET['chkid'])) { $chkid = intval($_GET['chkid']); } else { $chkid = 0; }
	if (isset($_GET['chkcode'])) { $chkcode = inCode($_GET['chkcode']); } else { $chkcode = ""; }
	if (isset($_POST['lost_user'])) { $lost_user = inCode($_POST['lost_user']); } else { $lost_user = ""; }
	if (isset($_POST['lost_email'])) { $lost_email = inCode($_POST['lost_email']); } else { $lost_email = ""; }

	openTable();

	switch($chg) {
		case "sendcode":
			@session_start();
			if ((isset($_POST['post_code_page']) AND isset($_SESSION['chk_users']) AND strtolower($_POST['post_code_page'])==strtolower($_SESSION['chk_users'])) OR !(extension_loaded('gd') AND $siteConfig['graphic_check']==1)) {
				$send = true;
				$row_check = $dblink->get_row("SELECT * FROM memht_utenti WHERE user='$lost_user'");
				$uid = intval($row_check['id']);
				$user_check = outCode($row_check['user']);
				$email_check = outCode($row_check['email']);
				if (!validEmail($lost_email) || $email_check!=$lost_email || !$row_check) {
					$send = false;
				}
				if ($send) {
					$codice = randString(10);
					
					$subject = $siteConfig['site_name']." - "._REMAKEPASS_;
					$msg = "$subject\n\n";
					$msg .= _FOLLOWLINKTOREMAKEPASS_.":\n";
					$msg .= $siteConfig['site_url']."/index.php?page=users&op=lostPassword&chg=chgpass&chkid=$uid&chkcode=$codice\n\n";
					$msg .= _IP_.": ".$visitorInfo['ip']."\n\n";
					
					$dblink->query("UPDATE memht_utenti SET code='$codice' WHERE id=$uid");
					
					sendEmail($email_check,$subject,$msg,$siteConfig['site_name'],$siteConfig['webmaster_mail'],0);
					echo "<div align='center'><b>"._CODESENT_."</b></div>";
				} else {
					echo "<div align='center' id='errorText'><b>"._WRONGDATA_."</b></div>";
				}
			} else {
				echo "<div align='center' id='errorText'><b>"._WRONGSECCODE_."</b></div>";
			}
		break;
		case "chgpass":
			$row_check2 = $dblink->get_row("SELECT * FROM memht_utenti WHERE id=$chkid");
			$user_check2 = outCode($row_check2['user']);
			$code_check2 = outCode($row_check2['code']);
			
			if (isset($_POST['db'])) { $db = inCode($_POST['db']); } else { $db = false; }
			if (isset($_POST['lost_pass'])) { $lost_pass = inCode($_POST['lost_pass']); } else { $lost_pass =""; }
			if (isset($_POST['lost_pass2'])) { $lost_pass2 = inCode($_POST['lost_pass2']); } else { $lost_pass2 = ""; }
			
			if (!$db) {
				if ($chkcode==$code_check2 && !empty($chkcode)) {
					echo "<form name='rec2' method='post' action='index.php?page=users&op=lostPassword&chg=chgpass&chkid=$chkid&chkcode=$chkcode'>\n";
					echo "<table align='center' border='0'>";
					echo "<tr><td align='right'><b>"._PASSWORD_."</b></td><td align='right'><input type='password' name='lost_pass' size='20' maxlength='25'></td></tr>\n";
					echo "<tr><td align='right'><b>"._REPASSWORD_."</b></td><td align='right'><input type='password' name='lost_pass2' size='20' maxlength='25'></td></tr>\n";
					if (extension_loaded('gd') AND $siteConfig['graphic_check']==1) {
						echo "<tr><td valign='bottom' class='info' align='right'><b>"._CODE_."</b><br><input type='text' name='post_code_page' size='5' maxlength='255'></td><td><img src='".$siteConfig['site_url']."/imgCode.php?name=chk_users&nc=".md5(time()+rand())."' title='header=["._SECURITY_CODE_."] body=["._SECURITY_CODE_TEXT_."]' alt='Captcha'></td></tr>";
					}
					echo "<tr><td colspan='2' align='right'><input type='submit' name='Submit' value='"._REMAKEPASS_."'></td></tr>\n";
					echo "<input type='hidden' name='db' value=true>";
					echo "</table>\n";
					echo "</form>\n";				
				} else {
					echo "<div align='center' id='errorText'><b>"._WRONGDATA_."</b></div>";
				}
			} else {
				@session_start();
				if ((isset($_POST['post_code_page']) AND isset($_SESSION['chk_users']) AND strtolower($_POST['post_code_page'])==strtolower($_SESSION['chk_users'])) OR !(extension_loaded('gd') AND $siteConfig['graphic_check']==1)) {
					if ($lost_pass==$lost_pass2) {
						$dblink->query("UPDATE memht_utenti SET pass='".md5($lost_pass)."',code='' WHERE id=$chkid");
						echo "<div align='center'><b>"._PASSMODIFIED_."</b></div>";
					} else {
						echo "<div align='center' id='errorText'><b>"._DIFFERENTPASSWORD_."</b></div>";
					}
				} else {
					echo "<div align='center' id='errorText'><b>"._WRONGSECCODE_."</b></div>";
				}
			}
		break;
		default:
			echo "<form name='rec' method='post' action='index.php?page=users&op=lostPassword&chg=sendcode'>\n";
			echo "<table align='center' border='0'>";
			echo "<tr><td align='right'><b>"._USERNAME_."</b></td><td><input type='text' name='lost_user' size='20' maxlength='25'></td></tr>\n";
			echo "<tr><td align='right'><b>"._EMAIL_."</b></td><td><input type='text' name='lost_email' size='20' maxlength='255'></td></tr>\n";
			if (extension_loaded('gd') AND $siteConfig['graphic_check']==1) {
				echo "<tr><td valign='bottom' class='info' align='right'><b>"._CODE_."</b><br><input type='text' name='post_code_page' size='5' maxlength='255'></td><td><img src='".$siteConfig['site_url']."/imgCode.php?name=chk_users&nc=".md5(time()+rand())."' title='header=["._SECURITY_CODE_."] body=["._SECURITY_CODE_TEXT_."]' alt='Captcha'></td></tr>";
			}
			echo "<tr><td colspan='2' align='right'><input type='submit' name='Submit' value='"._SENDCODE_."'></td></tr>\n";
			echo "</table>\n";
			echo "</form>\n";
		break;
	}
	
	closeTable();
}

function userInfo($usert,$uid) {
	global $dblink,$userid,$userInfo,$siteConfig;
	
	$query = ($uid>0) ? "id=$uid" : "user='$usert'" ;
	if ($row_info = $dblink->get_row("SELECT *,DATE_FORMAT(regdate, '".$siteConfig['timestamp']."') as regdate,DATE_FORMAT(lastlogin, '".$siteConfig['timestamp']."') as lastlogin FROM memht_utenti WHERE $query")) {
		$uid = intval($row_info['id']);
		$usert = outCode($row_info['user']);
		$email = outCode($row_info['email']);
		$showemail = intval($row_info['showemail']);
		$regdate = $row_info['regdate'];
		$sito = outCode($row_info['sito']);
		$icq = outCode($row_info['icq']);
		$msn = outCode($row_info['msn']);
		$aol = outCode($row_info['aol']);
		$yahoo = outCode($row_info['yahoo']);
		$avatar = outCode($row_info['avatar']);
		$post = intval($row_info['post']);
		$gender = intval($row_info['gender']);
		$title_enabled = intval($row_info['title_enabled']);
		$title_text = outCode($row_info['title_text']);
		$signature = censure(bb2html(outCode($row_info['signature'],0)));
		$lastip = outCode($row_info['lastip']);
		$lastlogin = $row_info['lastlogin'];
		$contributes = intval($row_info['contributes']);
		
		if ($avatar=="") { $avatar = "blank.png"; }
		if ($gender==1) {
			$gender_img = "<img src='images/male.gif' alt='"._MALE_."' title='"._MALE_."'>";
		} else if ($gender==2) {
			$gender_img = "<img src='images/female.gif' alt='"._FEMALE_."' title='"._FEMALE_."'>";
		} else {
			$gender_img = "<img src='images/neutral.gif' alt='"._NEUTRAL_."' title='"._NEUTRAL_."'>";
		}
		
		$email = maskEmail($email);
		$msn = maskEmail($msn);
			
		openTable(_USERINFO_);
			echo "<table width='100%' border='0' cellspacing='0' cellpadding='2'>\n";
				echo "<tr>\n";
					echo "<td width='25%' valign='top'>\n";
						echo "<b>$usert</b><br>\n";
						if ($title_enabled==1) {
							echo "<span class='small'>$title_text</span><br>\n";
						}
						echo "<img src='images/avatar/$avatar' border='0' title='$usert' alt='Avatar'><br>\n";
						echo "<br>\n";
						echo "<b>"._POSTS_.":</b> $post\n";
						
						$row = $dblink->get_row("SELECT contributes FROM memht_utenti ORDER BY contributes DESC LIMIT 1");
						$maxcontr = intval($row['contributes']);
						$imgcontrib = ceil(@($contributes/$maxcontr)*9);
						if ($imgcontrib<0) { $imgcontrib = 0; }
						if ($imgcontrib>9) { $imgcontrib = 9; }
						echo "<br><img src='images/bars/{$imgcontrib}.gif' alt='"._CONTRIBUTES_.": $contributes' title='"._CONTRIBUTES_.": $contributes'><br><br>\n";
						
						echo "<b>"._GENDER_.":</b> $gender_img<br>\n";
						echo "<b>"._ONLINE_.":</b> ";
							echo ($dblink->get_num("SELECT ip FROM memht_online WHERE user='$usert'")>0 AND !($siteConfig['admin_ghosts'] AND $userInfo['rank']>1)) ? _YES_ : _NO_ ;
						echo "<br><br>\n";
					echo "</td>\n";
					echo "<td width='75%' valign='top'>\n";
						echo "<table width='100%' border='0' cellspacing='0' cellpadding='2'>\n";
							echo "<tr><td width='5%'><b>"._REGISTERED_.":</b>&nbsp;</td><td>$regdate</td></tr>\n";
							if ($showemail==1 OR isAuth($userid,3)) {
								echo "<tr><td><b>"._EMAIL_.":</b></td><td>$email</td></tr>\n";
							}
							if ($sito!="") { echo "<tr><td><b>"._SITE_.":</b></td><td>$sito</td></tr>\n"; }
							if ($icq!="") { echo "<tr><td><b>"._ICQ_.":</b></td><td>$icq</td></tr>\n"; }
							if ($msn!="") { echo "<tr><td><b>"._MSN_.":</b></td><td>$msn</td></tr>\n"; }
							if ($aol!="") { echo "<tr><td><b>"._AOL_.":</b></td><td>$aol</td></tr>\n"; }
							if ($yahoo!="") { echo "<tr><td><b>"._YAHOO_.":</b></td><td>$yahoo</td></tr>\n"; }
							
							//Customized profile
							//3.8.5
							if ($result = $dblink->get_list("SELECT title,content FROM memht_utenti_profile AS p JOIN memht_utenti_profile_data AS d ON p.id=d.pid WHERE d.uid=$uid")) {
								echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
								foreach ($result as $row) {
									$ptitle = outCode($row['title']);
									$pcontent = outCode($row['content']);
									if ($pcontent!="") { echo "<tr><td valign='top'><b>$ptitle:</b></td><td valign='top'>$pcontent</td></tr>\n"; }
								}
							}
							
							echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
							echo "<tr><td colspan='2'><a href='index.php?page=pvtmsg&op=newMessage&recipient=$usert' title='"._SENDPM_."'><img src='templates/".$siteConfig['template']."/images/forum/buttons/sendpm.gif' border='0' title='"._SENDPM_."' alt='"._SENDPM_."'></a></td></tr>\n";
						echo "</table>\n";
					echo "</td>\n";
				echo "</tr>\n";
				if ($signature!="") {
					echo "<tr><td colspan='2'><div class='box' style='overflow:auto;'>$signature<div></td></tr>\n";
				}
			echo "</table>\n";
		closeTable();
		
		if (isAuth($userid,3)) {
			openTable(_ADMIN_);
				echo "<table>";	
					echo "<tr><td><b>"._LASTIP_.":</b></td><td>$lastip <a href='admin.php?page=security&op=findip&ok=true&ip=$lastip' title='"._FIND_." $lastip'><img src='images/ip.gif' border='0' alt='"._LASTIP_."'></a></td></tr>\n";
					echo "<tr><td><b>"._LASTLOGIN_.":</b></td><td>$lastlogin</td></tr>\n";
					
					echo "<form name='admin_cfg' method='post' action='admin.php?page=users'>\n";
					echo "<input type='hidden' name='adm_user' value='$usert'>";
					echo "<input type='hidden' name='op' value='sendEmail'>";
					echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._SEND_." "._EMAIL_."'></td></tr>\n";
					echo "</form>\n";
					
					echo "<form name='admin_cfg' method='post' action='admin.php?page=users'>\n";
					echo "<input type='hidden' name='id' value='$uid'>";
					echo "<input type='hidden' name='op' value='editUser'>";
					echo "<tr><td colspan='2'><input type='submit' name='Submit' value='"._MODIFYPROFILEUSER_."'></td></tr>\n";
					echo "</form>\n";
				echo "</table>";
			closeTable();
		}
	} else {
		openTable();
		echo "<div align='center' id='errorText'><b>"._USERNOTFOUND_."!</b></div>";
		closeTable();
	}
}

	switch($op) {
		case "register":
			newAccount();
		break;
		
		case "activate":
			activateAccount();
		break;
		
		case "editProfile":
			changeProfile();
		break;
		
		case "lostPassword":
			lostPass();
		break;
		
		case "userInfo":
			userInfo($usert,$uid);
		break;
		
		default:
			login();
		break;
	}

?>