<?php
/*
*----------------------------phpMyBitTorrent V 2.0.4---------------------------*
*--- The Ultimate BitTorrent Tracker and BMS (Bittorrent Management System) ---*
*--------------   Created By Antonio Anzivino (aka DJ Echelon)   --------------*
*-------------               http://www.p2pmania.it               -------------*
*------------ Based on the Bit Torrent Protocol made by Bram Cohen ------------*
*-------------              http://www.bittorrent.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 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 --*
*--                                                                          --*
*------------------------------------------------------------------------------*
*------              ©2005 phpMyBitTorrent Development Team              ------*
*-----------               http://phpmybittorrent.com               -----------*
*------------------------------------------------------------------------------*
*-----------------   Sunday, September 14, 2008 9:05 PM   ---------------------*
*/
if (!defined('IN_PMBT')) die ("You can't access this file directly");
$warnlength = (isset($_POST["warnlength"])) ? $_POST["warnlength"]  : false;
$warnpm = (isset($_POST["warnpm"])) ? $_POST["warnpm"]  : false;
$warned = (isset($_POST["warned"])) ? $_POST["warned"]  : false;
//$uploadtoadd = $_POST["amountup"];
//$downloadtoadd=  $_POST["amountdown"];
//$formatup = $_POST["formatup"];
//$formatdown = $_POST["formatdown"];
//$mpup = $_POST["upchange"];
//$mpdown = $_POST["downchange"];

if (!$user->user) loginrequired("user");

$admin_mode = false;
if (isset($id)) {
        if (!$user->admin) loginrequired("admin");
		if(!checkaccess("edit_user")){
OpenErrTable(_btaccdenied);
echo "<p>You do not have access to edit Profiles</p>";
CloseErrTable();
die();
}
        else {
                $uid = intval($id);
                $admin_mode = true;
        }
} else $uid = $user->id;
if(getlevel($uid) == "owner" && $user->group != "owner"){
OpenErrTable(_btaccdenied);
echo "<p>You do not have access to edit this Person</p>";
CloseErrTable();
die();
}
$sql_profile = "SELECT * FROM ".$db_prefix."_users where id = '".$uid."' LIMIT 1;";
$res_profile = $db->sql_query($sql_profile);
$userrow = $db->sql_fetchrow($res_profile);
$db->sql_freeresult($res_profile);

if ($admin_mode) $uname = $userrow["username"];
else $uname = $user->name;
$off_set ='';
$sql = ("SELECT id,name from ".$db_prefix."_time_offset ORDER BY name");
$tz_r = $db->sql_query($sql);
while ($tz_a = $db->sql_fetchrow($tz_r))
  $off_set .= "<option value=$tz_a[id]" . ($userrow["tzoffset"] == $tz_a['id'] ? " selected" : "") . ">$tz_a[name]</option>\n";

$countries = "<option value=0>----</option>\n";
$sql = ("SELECT id,name from ".$db_prefix."_countries ORDER BY name");
$ct_r = $db->sql_query($sql);
while ($ct_a = $db->sql_fetchrow($ct_r))
  $countries .= "<option value=$ct_a[id]" . ($userrow["country"] == $ct_a['id'] ? " selected" : "") . ">$ct_a[name]</option>\n";

echo <<<EOF
<script type="text/javascript" language="JavaScript">
function expand(id) {
        var i=1;
        var obj;
        while (obj = document.getElementById(id+"_"+i)) {
                if (obj.className == 'show') {
                        obj.className = 'hide';
                } else {
                        obj.className = 'show';
                }
                i++;
        }

}
</script>
EOF;


/*
NOTICE
When the user changes his password, authentication cookie automatically expires
It must then be updated
*/
function processinput($name,&$input) {
        global $sqlfields, $sqlvalues;
        if (!get_magic_quotes_gpc()) $input = addslashes($input);
        $sqlfields[] = $name;
        $sqlvalues[] = ($input != "NULL") ? "'".$input."'" : "NULL";
}

function processload($name,&$input) {
        global $sqlfields, $sqlvalues;
        $sqlfields[] = $name;
        $sqlvalues[] = ($input != 0) ? "".$input."" : 0;
}

if (isset($postback)) {
//die($offset);
        ini_set("upload_max_filesize",307200);
        //Submit form
        $errors = Array();
        $sqlfields = Array();
        $sqlvalues = Array();
        if (isset($newpasswd) AND $newpasswd != "") {
                if ($newpasswd != $newpasswdconf) $errors[] = _btpasswnotsame;
                else {
                        $sqlfields[] = "password";
                        $sqlvalues[] = "'".md5($newpasswd)."'";
						if($forumshare)forum_pass($uid,$newpasswd); 
                }
        }
        if (!isset($name) OR $name == "") $name = "NULL";
        processinput("name",htmlspecialchars($name));
        if (!isset($user_torrent_per_page) OR $user_torrent_per_page == "") $user_torrent_per_page = "NULL";
        processload("torrent_per_page",$user_torrent_per_page);
		if ($admin_mode){
		if(checkaccess("edit_level")){
        if (!isset($group) OR $group == "") $group = "";
						if($userrow["can_do"] != $group)logerror('Group Changed for '.username_is($uid)." To ".$group, 'Group edit');
        processinput("can_do",$group);		
		}
        if (!isset($help_able) OR $help_able == "") $help_able = "";
        processinput("help_able",$help_able);		
        if (!isset($helper) OR $helper == "") $helper = "false";
        processinput("helper",$helper);		
        if (!isset($modcomment) OR $modcomment == "") $modcomment = "";
        processinput("modcomment",$modcomment);		
        if (!isset($seedbox) OR $seedbox == "") $seedbox = "0.0.0.0";
        processinput("seedbox",sprintf("%u",ip2long($seedbox)));
		?>
		<?php
		if (!isset($up) OR $up =="") $up = '0';
		processload("uploaded",$up);
		if (!isset($invit) OR $invit =="") $invit = '0';
		processload("invites",$invit);
		if (!isset($seed) OR $seed =="") $seed = '0';
		processload("seedbonus",$seed);
		if (!isset($down) OR $down =="") $down = '0';
		processload("downloaded",$down);
		}
		if (!isset($offset) OR $offset =="") $offset = '0';
		processload("tzoffset",$offset);
        if (!isset($aim) OR $aim == "") $aim = "NULL";
        processinput("aim",$aim);
        if (!isset($icq) OR $icq == "") $icq = "NULL";
        processinput("icq",$icq);
        if (!isset($jabber) OR $jabber == "") $jabber = "NULL";
        processinput("jabber",$jabber);
        if (!isset($msn) OR $msn == "") $msn = "NULL";
        processinput("msn",$msn);
        if (!isset($skype) OR $skype == "") $skype = "NULL";
        processinput("skype",$skype);
        if (!isset($yahoo) OR $yahoo == "") $yahoo = "NULL";
        processinput("yahoo",$yahoo);
		if($forumshare)forum_im($uid, $aim, $icq, $msn, $yahoo, $jabber); 
		?>
		<?php
//WARN things START  
     if ($warnlength != 0) $warned = "yes";
     if ($warn_torol == "yes") $warned = "no";
     if ($warned == "no")
     {
     $warnlength = 0;
     $warnstart = 0;
     $modcomment = "[ " . gmdate("Y-m-d H:i:s", time()) . " - WARN deleted by " . getusername($user) . " ]\n" . $modcomment;
     $added3 = gmdate("Y-m-d H:i:s", time());
     $msg3 = "Your WARNNING was deleted by " . $user->name . "!";
     $db->sql_query("INSERT INTO ".$db_prefix."_private_messages (sender, recipient, subject, text, sent) VALUES('". $user->id ."', '".$uid."', 'WARNNING',  '" . $msg3 . "', NOW())") or btsqlerror();
	 $db->sql_query("UPDATE ".$db_prefix."_users SET  modcomment='".$modcomment."', warned='0', warn_kapta='0', warn_hossz='0' WHERE id='".$uid."'") or die(mysql_error()); 
     }
     if ($warned == "yes")
     {
     $warnstart = strtotime(gmdate("Y-m-d H:i:s", time()));
     if ($warnlength == 604800) $weeks = '1 week';
     if ($warnlength == 1209600) $weeks = '2 weeks';
     if ($warnlength == 2419200) $weeks = '4 weeks';
     if ($warnlength == 4838400) $weeks = '8 weeks';
     if ($warnlength == -1) $weeks = "unlimited time";
     $added2 = (gmdate("Y-m-d H:i:s", time()));
     $modcomment =  "" . gmdate("Y-m-d H:i:s", time()) . " - WARNed for " . $weeks . "  by " . getusername($user) . " - Reason: " . $warnpm . " " . $modcomment."";
     $msg2 = ("You have been WARNNED by " . getusername($user) . " for  " . $weeks . "  with reason: " . $warnpm . ".");
     $db->sql_query("INSERT INTO ".$db_prefix."_private_messages (sender, recipient, subject, text, sent) VALUES('". $user->id ."', '".$uid."', 'WARNNING',  '" . $msg2 . "', NOW())") or die(mysql_error());
	 $db->sql_query("UPDATE ".$db_prefix."_users SET  modcomment='".$modcomment."', warned='1', warn_kapta='" . strtotime(gmdate("Y-m-d H:i:s", time())) . "', warn_hossz='".$warnlength."' WHERE id= '".$uid."'") or die(mysql_error());
     }
     if ($warned == "")
     {  
     $sql = ("SELECT warned, warn_kapta, warn_hossz FROM ".$db_prefix."_users WHERE id='".$uid."'") or die(mysql_error());
	 $warn_q = $db->sql_query($sql);
     $warn_sql_f = $db->sql_fetchrow($warn_q);
  $warned = $warn_sql_f["warned"];
  $warnstart = $warn_sql_f["warn_kapta"];
  $warnlength = $warn_sql_f["warn_hossz"];
  }
  $modcomment = $modcomment;		


        if (isset($accept_mail) AND $accept_mail == "true") {
                $sqlfields[] = "accept_mail";
                $sqlvalues[] = "'yes'";
        } else {
                $sqlfields[] = "accept_mail";
                $sqlvalues[] = "'no'";
        }
        if (isset($pm_notify) AND $pm_notify == "true") {
                $sqlfields[] = "pm_notify";
                $sqlvalues[] = "'true'";
        } else {
                $sqlfields[] = "pm_notify";
                $sqlvalues[] = "'false'";
        }
        if (isset($Show_online) AND $Show_online == "true") {
                $sqlfields[] = "Show_online";
                $sqlvalues[] = "'true'";
        } else {
                $sqlfields[] = "Show_online";
                $sqlvalues[] = "'false'";
        }
          if (isset($country))
          processinput("country",$country);

        if ($customlang == "0" OR !is_readable("language/".$customlang.".php")) $customlang = "NULL";
        processinput("language",$customlang);

        if ($customtheme == "0" OR $customtheme == "CVS" OR !is_dir("themes/".$customtheme)) $customtheme = "NULL";
        processinput("theme",$customtheme);

        if (($userrow["passkey"] == "" AND isset($use_passkey) AND $use_passkey == "true") OR (isset($use_passkey) AND $use_passkey == "true" AND isset($passkey_reset) AND $passkey_reset == "true")OR(isset($passkey_reset) AND $passkey_reset == "true" AND $force_passkey)) {
                //Generate new Passkey
                do {
                        $passkey = RandomAlpha(32);
                        //Check whether passkey already exists
                        $sql = "SELECT passkey FROM ".$db_prefix."_users WHERE passkey = '".$passkey."';";
                        $res = $db->sql_query($sql);
                        $cnt = $db->sql_numrows($sql);
                        $db->sql_freeresult($res);
                } while ($cnt > 0);
                processinput("passkey",$passkey);

        } elseif((!isset($use_passkey) OR $use_passkey != "true") AND $userrow["passkey"] != "") {
                //Remove Passkey
                $passkey = "NULL";
                if(!$force_passkey)processinput("passkey",$passkey);
        }

        if ($admin_mode AND in_array($level,Array("user","premium","moderator","admin"))) {
						if($userrow["level"] != $level)logerror('Level Changed for '.username_is($uid)." To ".$level, 'Level edit');
		processinput("level",$level);
		}
	if ($admin_mode AND in_array($active,Array("0","1"))) processload("active",$active);

        $avatar_uploaded = false;
        if (extension_loaded("gd")) {
                $avupload = $_FILES["avupload"];
                if ($avupload["name"] != "") {
                        $avatar_uploaded = true;
                        $filename = unesc($avupload["name"]);
                        if (eregi("\.(gif|jpg|jpeg|png)$",$filename)) {
                                $imageinfo = getimagesize($avupload["tmp_name"]);
                                $width = $imageinfo[0];
                                $height = $imageinfo[1];
                                if ($width > 100 OR $height > 150) {
                                        $errors[] = _btavatartoobig;
                                        unlink($avupload["tmp_name"]);
                                } else {
                                        $newfname = preg_replace("/^([^\\\\:\/<>|*\"?])*\\.(gif|jpg|jpeg|png)$/si", $uname.".\\2", $filename);
                                        //Deleting any previous images
                                        $fhandle = opendir("avatars/user");
                                        while ($file = readdir($fhandle)) {
                                                if (preg_match("/^".$uname."\.(gif|jpg|jpeg|png)$/si",$file)) @unlink("avatars/user/".$file);
                                        }
                                        closedir($fhandle);
                                        move_uploaded_file($avupload["tmp_name"],"avatars/user/".$newfname);
                                        $sqlfields[] = "avatar";
                                        $sqlvalues[] = "'user/".$newfname."'";
										if($forumshare)add_avatar_upload($uid, $newfname, $height, $width);
                                }
                        } else {
                                $errors[] = _btinvalidimagefile;
                                unlink($avupload["tmp_name"]);
                        }
                }
        }
        if (!$avatar_uploaded AND isset($avgallery) AND $avgallery != "none") {
                $sqlfields[] = "avatar";
                $sqlvalues[] = "'".$avgallery."'";
				if($forumshare)add_avatar_galery($uid, $avgallery);
        }
        if (count($errors) > 0) bterror($errors,_btedituserprofile,false);
        elseif (count($sqlfields) > 0) {

                $sql = "UPDATE ".$db_prefix."_users SET ";
                for ($i = 0; $i < count($sqlfields); $i++) $sql .= $sqlfields[$i] ." = ".$sqlvalues[$i].", ";
                $sql .= "act_key = ".(($admin_mode) ? "act_key" : "'".RandomAlpha(32)."'")." WHERE id = '".$uid."';"; //useless but needed to terminate SQL without a comma
                //echo $sql;
                //die();
                if (!$db->sql_query($sql)) btsqlerror($sql);

                if (!$admin_mode) userlogin($uname,$btuser); //SQL is executed, cookie is invalid and getusername() function returns nothing, so it must be called earlier
                $url = ($admin_mode) ? "user.php?op=editprofile&id=".$uid."&saved=1" : "user.php?op=editprofile&saved=1";
                header("Location: ".$url);
                die();
        }

}

#Default avatar script
echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n";
echo "function ChangeThumb(pic) {\n";
echo "        document.images.Thumb.src = 'avatars/'+pic\n";
echo "}\n";
echo "</script>\n";

if (isset($saved) AND $saved == 1) {
        OpenTable2();
        echo "<h3 align=\"center\">"._btprofilesaved."</h3>";
        CloseTable2();
}

OpenTable(_btedituserprofile);

echo "<form enctype=\"multipart/form-data\" action=\"user.php\" method=\"post\">\n";
if ($admin_mode) echo "<input type=\"hidden\" name=\"id\" value=\"".$uid."\" />\n";
echo "<input type=\"hidden\" name=\"op\" value=\"editprofile\" />\n";
echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"307200\" />";
echo "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\">\n";

#User Name
echo "<tr><td><p>"._btusername."</p></td><td><p><input type=\"text\" value=\"".$userrow["username"]."\" readonly size =\"40\" /></p></td></tr>\n";

#Email
echo "<tr><td><p>"._btemailaddress."</p></td><td><p><input type=\"text\" value=\"".$userrow["email"]."\" readonly size =\"40\" /></p></td></tr>\n";

#Password Change
echo "<tr><td><p>"._btnewpassword."</p></td><td><p><input type=\"password\" name=\"newpasswd\" size =\"40\" /></p></td></tr>\n";
echo "<tr><td><p>"._btnewpasswordconfirm."</p></td><td><p><input type=\"password\" name=\"newpasswdconf\" size =\"40\" /></p></td></tr>\n";

#Complete name
echo "<tr><td><p>"._btcompletename."</p></td><td><p><input type=\"text\" name=\"name\" value=\"".$userrow["name"]."\" size =\"40\" /></p></td></tr>\n";

#Separator
echo "<tr><td><HR SIZE=1 NOSHADE></td><td></td></tr>\n";

#Contacts
echo "<tr><td><p>".pic("button_aim.gif")._btaol."</p></td><td><p><input type=\"text\" name=\"aim\" value=\"".$userrow["aim"]."\" size =\"40\" /></p></td></tr>\n";
echo "<tr><td><p>".pic("button_icq.gif")._bticq."</p></td><td><p><input type=\"text\" name=\"icq\" value=\"".$userrow["icq"]."\" size =\"40\" /></p></td></tr>\n";
echo "<tr><td><p>".pic("button_jabber.gif")._btjabber."</p></td><td><p><input type=\"text\" name=\"jabber\" value=\"".$userrow["jabber"]."\" size =\"40\" /></p></td></tr>\n";
echo "<tr><td><p>".pic("button_msn.gif")._btmsn."</p></td><td><p><input type=\"text\" name=\"msn\" value=\"".$userrow["msn"]."\" size =\"40\" /></p></td></tr>\n";
echo "<tr><td><p>".pic("button_skype.gif")._btskype."</p></td><td><p><input type=\"text\" name=\"skype\" value=\"".$userrow["skype"]."\" size =\"40\" /></p></td></tr>\n";
echo "<tr><td><p>".pic("button_yahoo.gif")._btyim."</p></td><td><p><input type=\"text\" name=\"yahoo\" value=\"".$userrow["yahoo"]."\" size =\"40\" /></p></td></tr>\n";
echo "<tr><td><p>"._btacceptmail."</p></td><td><p><input type=\"checkbox\" name=\"accept_mail\" value=\"true\" ";
if ($userrow["accept_mail"] == "yes") echo "checked ";
echo "></p></td></tr>\n";
echo "<tr><td><p>Accespt pm notifacation</p></td><td><p><input type=\"checkbox\" name=\"pm_notify\" value=\"true\" ";
if ($userrow["pm_notify"] == "true") echo "checked ";
echo "></p></td></tr>\n";
echo "<tr><td><p>Show your self online</p></td><td><p><input type=\"checkbox\" name=\"Show_online\" value=\"true\" ";
if ($userrow["Show_online"] == "true") echo "checked ";
if ($user->moderator)echo "<tr><td><p>Torrents Perpage</p></td><td><p><input type=\"text\" name=\"user_torrent_per_page\" value=\"".$userrow["torrent_per_page"]."\" size =\"40\" /></p></td></tr>\n";
if ($user->moderator)echo "<tr><td><p>Seedbox</p></td><td><p><input type=\"text\" name=\"seedbox\" value=\"".long2ip($userrow["seedbox"])."\" size =\"40\" /></p></td></tr>\n";


#Separator
echo "<tr><td><HR SIZE=1 NOSHADE></td><td></td></tr>\n";

//Admin options
if ($admin_mode) {
		if(checkaccess("edit_level")){
        echo "<tr><td><p>Group</p></td><td><p>";
        echo selectaccess($userrow["can_do"]);
        echo "</p></td></tr>";
		}
        echo "<tr><td><p>Helper</p></td><td><p>";
		echo"<input type=\"radio\" name=\"helper\" value=\"true\"";
		if($userrow['helper'] == 'true')echo "checked";
		echo ">Yes";
		echo"<input type=\"radio\" name=\"helper\" value=\"false\"";
		if($userrow['helper'] == 'false')echo "checked";
		echo ">No";
        echo "</p></td></tr>";
        echo "<tr><td><p>Helper For</p></td><td><p><textarea cols=30 rows=1 name=help_able>".$userrow['help_able']."</textarea>";
        echo "</p></td></tr>";
        echo "<tr><td><p>"._btaccesslevel."</p></td><td><p>";
        echo "<select name=\"level\">";
        echo "<option "; if ($userrow["level"] == "user") echo "selected "; echo "value=\"user\">"._btclassuser."</option>";
        echo "<option "; if ($userrow["level"] == "premium") echo "selected "; echo "value=\"premium\">"._btclasspremium."</option>";
        echo "<option "; if ($userrow["level"] == "moderator") echo "selected "; echo "value=\"moderator\">"._btclassmoderator."</option>";
        echo "<option "; if ($userrow["level"] == "admin") echo "selected "; echo "value=\"admin\">"._btclassadmin."</option>";
        echo "</select>";
        echo "</p></td></tr>";
        echo "<tr><td><hr /></td><td></td></tr>\n";
		$modcomment = htmlspecialchars($userrow["modcomment"]);
		print("<tr><td>Mod Comment</td><td align=left><textarea cols=60 rows=8 name=modcomment>$modcomment</textarea></td></tr>\n");
        #Separator
        echo "<tr><td><HR SIZE=1 NOSHADE></td><td></td></tr>\n";

	echo "<tr><td><p>";
	help(pic("help.gif"),_btaccountstatusexplain,_btaccountstatus);
	echo _btaccountstatus;
	echo "</p></td><td><p>";
	echo "<select name=\"active\">";
        echo "<option "; if ($userrow["active"] == "0") echo "selected "; echo "value=\"0\">"._btaccountinactive."</option>";
        echo "<option "; if ($userrow["active"] == "1") echo "selected "; echo "value=\"1\">"._btaccountactive."</option>";
	echo "</select>";
	echo "</p></td></tr>";		
print("<tr><td><b>WARNNED?</b></td><td align=left>");
if ($userrow["warned"])
{
print("Yes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Delete WARN&nbsp;<b><input name=warned value=no type=checkbox></td>");
}
 else
 { print("No</td>");
   print("<tr><td><b>WARN:</b></td><td align=left>For <select name=warnlength>\n");
   print("<option value=0>------</option>\n");
   print("<option value=604800>1 week</option>\n");
   print("<option value=1209600>2 weeks</option>\n");
   print("<option value=2419200>4 weeks</option>\n");
   print("<option value=4838400>8 weeks</option>\n");
   print("<option value=-1>unlimited time</option>\n");
   print("</select></td></tr><tr><td><b>Reason:<b></td>\n");
   print("<td><input type=\"text\" rows=\"5\" size =\"40\" name=\"warnpm\"></td></tr>");
 }
	echo "<tr><td><HR SIZE=1 NOSHADE></td><td></td></tr>\n";
echo "<tr><td><p>";
echo help(pic("help.gif"),_btsetuploadexplain,_btusesetupload),"Uploaded</p></td><td><p><input type=\"text\" name=\"up\" value=\"".$userrow["uploaded"]."\" size =\"40\" />&nbsp;&nbsp;".mksize($userrow[uploaded])."</p></td></tr>\n";
echo "<tr><td><p>";
echo help(pic("help.gif"),_btsetDownloadexplain,_btuseDownload),"Downloaded</p></td><td><p><input type=\"text\" name=\"down\" value=\"".$userrow["downloaded"]."\" size =\"40\" />&nbsp;&nbsp;".mksize($userrow[downloaded])."</p></td></tr>\n";
echo "<tr><td><p>";
echo help(pic("help.gif"),_btseedbonusexplain,_btuseseedbonus),"Seedbonus</p></td><td><p><input type=\"text\" name=\"seed\" value=\"".$userrow["seedbonus"]."\" size =\"40\" />&nbsp;&nbsp;".$userrow[seedbonus]."</p></td></tr>\n";
echo "<tr><td><p>";
echo help(pic("help.gif"),_btsetinvitesexplain,_btuseinvites),"Invites</p></td><td><p><input type=\"text\" name=\"invit\" value=\"".$userrow["invites"]."\" size =\"40\" />&nbsp;&nbsp;".$userrow[invites]."</p></td></tr>\n";

}

#Tracker preferences

##Passkey Authentication
echo "<tr><td><p>";
if(!$force_passkey){
help(pic("help.gif"),_btpasskeyexplain,_btusepasskey);
echo _btusepasskey;
echo "</p></td><td><p>";
echo "<input type=\"checkbox\" onClick=\"javascript:expand('passkey_reset');\" name=\"use_passkey\" value=\"true\" "; if ($userrow["passkey"] != "") echo "checked"; echo " />";
//Display Passkey for debug
//if ($userrow["passkey"] != "") echo "<input type=\"text\" readonly value=\"".$userrow["passkey"]."\" /> ";
echo "</p></td></tr>\n";
}
if ($userrow["passkey"] != "" OR  $force_passkey) echo "<tr id=\"passkey_reset_1\" class=\"show\" ><td><p>"._btresetpasskey."</p></td><td><p><input type=\"checkbox\" name=\"passkey_reset\" value=\"true\" /><input rows=\"1\" size =\"32\" cols=\"32\" type=\"text\" readonly value=\"".$userrow["passkey"]."\" /><div style=\"width:300px;\"><p>"._btresetpasskeywarning."</p></div></p></td></tr>\n";


#Separator
echo "<tr><td><HR SIZE=1 NOSHADE></td><td></td></tr>\n";
echo "<tr><td><p>Country</p></td><td><p>";
echo "<select name=\"country\">\n<option value=\"0\">".$countries."</option>\n";
echo "<tr><td><p>Time zone </p></td><td><p>";
echo "<select name=\"offset\">\n<option value=\"0\">".$off_set."</option>\n";
#Tracker Appearence Preferences
##Custom Language
{
        $languages = Array();
        $langdir = "language";
        $langhandle = opendir($langdir);
        while ($langfile = readdir($langhandle)) {
                if (eregi("\.php$",$langfile) AND strtolower($langfile) != "mailtexts.php")
                        $languages[str_replace(".php","",$langfile)] = ucwords(str_replace(".php","",$langfile));
        }
        closedir($langhandle);
        unset($langdir,$langfile);
}
echo "<tr><td><p>"._btcustomlanguage."</p></td><td><p>";
echo "<select name=\"customlang\">\n<option value=\"0\">"._btdefault."</option>\n";
foreach ($languages as $key=>$val) {
        echo "<option ";
        if ($userrow["language"] == $key) echo "selected";
        echo " value=\"".$key."\">".$val."</option>\n";
}
unset($languages);
echo "</select>\n";
echo "</p></td></tr>\n";
{
        $themes = Array();
        $thememaindir = "themes";
        $themehandle = opendir($thememaindir);
        while ($themedir = readdir($themehandle)) {
                if (is_dir($thememaindir."/".$themedir) AND $themedir != "." AND $themedir != ".." AND $themedir != "CVS")
                        $themes[$themedir] = $themedir;
        }
        closedir($themehandle);
        unset($thememaindir,$themedir);
}
##Custom Theme
echo "<tr><td><p>"._btcustomtheme."</p></td><td><p>";
echo "<select name=\"customtheme\">\n<option value=\"0\">"._btdefault."</option>\n";
foreach ($themes as $key=>$val) {
        echo "<option ";
        if ($userrow["theme"] == $key) echo "selected";
        echo " value=\"".$key."\">".$val."</option>\n";
}
unset($themes);
echo "</select>\n";
echo "</p></td></tr>\n";
echo "<tr><td><HR SIZE=1 NOSHADE></td><td></td></tr>\n";

#Avatar
echo "<tr><td><p>"._btavatar."</p></td><td><p>";
if ($userrow["avatar"] == "blank.gif" OR $userrow["avatar"] == "") echo _btnone;
else echo "<img src=\"avatars/".$userrow["avatar"]."\" border=\"0\" />";
echo "</p></td></tr>\n";

echo "<tr><td><p>"._btnewavatargallery."</p></td><td><p>";
echo "<img src=\"avatars/blank.gif\" name=\"Thumb\" class=\"image\" />";
echo "<br />\n";
echo "<select name=\"avgallery\" onChange=\"if(this.options[this.selectedIndex].value != 'none') ChangeThumb(this.options[this.selectedIndex].value);\" onKeyUp=\"if(this.options[this.selectedIndex].value != 'none') ChangeThumb(this.options[this.selectedIndex].value);\">\n";
echo "<option value=\"none\">"._btchooseavatar."</option>\n";
echo "<option value=\"blank.gif\">"._btnone."</option>\n";
$dhandle = opendir("./avatars/");
while ($file = readdir($dhandle)) {
        if (is_dir("./avatars/".$file) OR $file == "blank.gif" OR !eregi("\.(gif|jpg|png)$",$file)) continue;
        echo "<option value=\"".$file."\">".$file."</option>\n";
}
closedir($dhandle);

echo "</select>\n";
echo "</p></td></tr>\n";
if (extension_loaded("gd")) echo "<tr><td><p>";help(pic("help.gif"),_btavatarnotice); echo _btnewavatarupload."</p></td><td><p><input type=\"file\" name=\"avupload\"></p></td></tr>";

echo "</table>\n";
echo "<p><input type=\"submit\" name=\"postback\" value=\""._btsend."\"></p>\n";
echo "</form>\n";
if($admin_mode)echo "<form action=\"user.php\" method=\"GET\"><input type=\"hidden\" name=\"op\" value=\"delete\" /><input type=\"hidden\" name=\"id\" value=\"".$uid."\" /><p><input type=\"submit\" value=\""._btdeleteaccount."\" /></p></form>";
//else
//echo "<form action=\"user.php\" method=\"GET\"><input type=\"hidden\" name=\"op\" value=\"delete\" /><p><input type=\"submit\" value=\""._btdeleteaccount."\" /></p></form>";
CloseTable();
?>