<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* Original Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)   */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2004 by Philippe Brunier   */
/*                                                                      */
/* 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.       */
/************************************************************************/
/************************************************************************/
/* User Journal System Add-On                                           */
/* Brought to you by Chris "Surge" Kacerguis (surge@mindstorm.org)      */
/* http://www.mindstorm.org                                             */
/************************************************************************/
if (!function_exists("Mysql_Connexion")) {include ("mainfile.php");}
global $pdst; $pdst=1;

function message_error($ibid,$op) {
    include("header.php");
    OpenTable();
    echo "<p align=\"center\">";
    echo $ibid;
    if (($op=="only_newuser") or ($op=="new user") or ($op=="finish")) {
       hidden_form();
       echo "<input type=\"hidden\" name=\"op\" value=\"only_newuser\"><input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".translate("Go Back")."\"></form>";
    } else {
       echo "<a href=\"javascript:history.go(-1)\" class=\"NOIR\">".translate("Go Back")."</a>";
    }
    echo "</p>";
    closetable();
    include("footer.php");
}

function nav($mns) {
    echo "<table cellspacing=\"2\" cellpadding=\"2\" width=\"100%\" border=\"0\" class=\"HEADER\">";
    echo "<tr><td class=\"TITBOXC\" align=\"center\">
          &nbsp;[&nbsp;<a href=\"user.php?op=edituser\" class=\"HEADA\">".translate("Edit User")."</a>&nbsp;]</td><td class=\"TITBOXC\" align=\"center\">
          [&nbsp;<a href=\"user.php?op=editjournal\" class=\"HEADA\">".translate("Edit Journal")."</a>&nbsp;]</td><td class=\"TITBOXC\" align=\"center\">";

    include ("modules/upload/upload.conf.php");
    if (($mns) and ($autorise_upload_p)) {
       include ("modules/upload/upload_minisite.php");
       $PopUp=win_upload("popup");
       echo "[&nbsp;<a href=\"javascript:void(0);\" onClick=\"window.open($PopUp)\" class=\"HEADA\">".translate("Manage my Mini-Web site")."</a>&nbsp;]";
    }
    echo "</td></tr><tr><td class=\"TITBOXC\" align=\"CENTER\">";
    echo "&nbsp;[&nbsp;<a href=\"user.php?op=edithome\" class=\"HEADA\">".translate("Change the home")."</a>&nbsp;]</td><td class=\"TITBOXC\" align=\"center\">
          [&nbsp;<a href=\"user.php?op=editcomm\" class=\"HEADA\">".translate("Comments")."</a>&nbsp;]</td><td class=\"TITBOXC\" align=\"center\">
          [&nbsp;<a href=\"user.php?op=chgtheme\" class=\"HEADA\">".translate("Change Theme")."</a>&nbsp;]";
    echo "</td></tr><tr><td class=\"TITBOXC\" align=\"center\">";
    echo "&nbsp;</td><td class=\"TITBOXC\" align=\"center\">[&nbsp;<a href=\"user.php?op=logout\" class=\"ROUGE\">".translate("Logout")."</a>&nbsp;]</td><td class=\"TITBOXC\" align=\"center\">&nbsp;</td>";
    echo "</tr></table><div class=\"SEPAR\"></div>";
}

function userCheck($uname, $email) {
    if ((!$email) || ($email=="") || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$",$email))) $stop = "<p align=\"center\">".translate("ERROR: Invalid email")."</p><br />";
    if (strrpos($email,' ') > 0) $stop = "<p align=\"center\">".translate("ERROR: Email addresses do not contain spaces.")."</p><br />";
    if ((!$uname) || ($uname=="") || (ereg("[^a-zA-Z0-9_-]",$uname))) $stop = "<p align=\"center\">".translate("ERROR: Invalid Nickname")."</p><br />";
    if (strlen($uname) > 25) $stop = "<p align=\"center\">".translate("Nickname is too long. It must be less than 25 characters.")."</p><br />";
    if (eregi("^((root)|(adm)|(linux)|(webmaster)|(admin)|(god)|(administrator)|(administrador)|(nobody)|(anonymous)|(anonimo)|(anónimo)|(operator)|(dune)|(netadm))$",$uname)) $stop = "<p align=\"center\">".translate("ERROR: Name is reserved.")."</p><br />";
    if (strrpos($uname,' ') > 0) $stop = "<p align=\"center\">".translate("There cannot be any spaces in the Nickname.")."</p><br />";
    if (mysql_num_rows(mysql_query("select uname from users where uname='$uname'")) > 0) {
       $stop = "<p align=\"center\">".translate("ERROR: Nickname taken")."</p><br />";
    }
    if ($uname!="edituser") {
       if (mysql_num_rows(mysql_query("select email from users where email='$email'")) > 0) {
          $stop = "<p align=\"center\">".translate("ERROR: Email address already registered")."</p><br />";
       }
    }
    return($stop);
}

function makePass() {
    $makepass="";
    $syllables="er,in,tia,dun,fe,pre,vet,jo,nes,al,len,son,cha,ir,ler,bo,ok,tio,nar,sim,ple,bla,ten,toe,cho,co,lat,spe,ak,er,po,co,lor,pen,cil,li,ght,wh,at,the,he,ck,is,";
    $syllables.="mam,bo,no,fi,ve,any,way,pol,iti,cs,ra,dio,sou,rce,sea,rch,pa,per,com,bo,sp,eak,st,fi,rst,gr,oup,boy,ea,gle,tr,ail,bi,ble,brb,pri,dee,kay,en,be,se";
    $syllable_array=explode(",", $syllables);
    srand((double)microtime()*1000000);
    for ($count=1;$count<=4;$count++) {
       if (rand()%10 == 1) {
          $makepass .= sprintf("%0.0f",(rand()%50)+1);
       } else {
          $makepass .= sprintf("%s",$syllable_array[rand()%62]);
       }
    }
    return($makepass);
}

function Only_NewUser() {
    global $user;
    if (!$user) {
       global $smilies, $short_user, $memberpass;
       global $uname, $name, $email, $url, $user_avatar, $user_icq, $user_occ, $user_from, $user_intrest, $user_sig, $user_viewemail, $user_aim, $user_yim, $user_msnm, $pass, $vpass, $C1,$C2,$C3,$C4,$C5,$C6,$C7,$C8,$M1,$M2,$T1,$T2,$B1;
       if ($url=="") {$url="http://";}
       include("header.php");
       opentable();
       include ("modules/sform/extend-user/extend-user.php");
       closetable();
       opentable();
       echo "<p align=\"center\"><span class=\"ROUGE\">".translate("(Password will be sent to the email address you enter.)")."</span></p><br />
          ".translate("Notice: Account preferences are cookie based.")."<br /><br />
          <b>".translate("As a registered user you can:")."</b><br />
          <li>".translate("Post comments with your name")."
          <li>".translate("Send news with your name")."
          <li>".translate("Have a personal box in the Home")."
          <li>".translate("Upload personnal avatar")."
          <li>".translate("Select how many news you want in the Home")."
          <li>".translate("Customize the comments")."
          <li>".translate("Select different themes")."
          <li>".translate("some other cool stuff...")."<br />
          <br /><p align=\"center\">".translate("We don't sell/give to others your personal info.")."</p>";
       closetable();
       include("footer.php");
    } else {
      header("location: user.php");
    }
}
function hidden_form() {
    global $uname, $name, $email, $url, $user_avatar, $user_icq, $user_occ, $user_from, $user_intrest, $user_sig, $user_viewemail, $user_aim, $user_yim, $user_msnm, $pass, $vpass, $C1,$C2,$C3,$C4,$C5,$C6,$C7,$C8,$M1,$M2,$T1,$T2,$B1,$charte,$user_lnl;
    echo "<form action=user.php method=post>
          <input type=hidden name=uname value=\"$uname\">
          <input type=hidden name=name value=\"".removeHack($name)."\">
          <input type=hidden name=email value=\"$email\">";
    if (!$user_avatar) {$user_avatar="blank.gif";}
    echo "<input type=hidden name=user_avatar value=\"$user_avatar\">
          <input type=hidden name=user_icq value=\"".StripSlashes(removeHack($user_icq))."\">
          <input type=hidden name=url value=\"".removeHack($url)."\">
          <input type=hidden name=user_from value=\"".StripSlashes(removeHack(check_words($user_from)))."\">
          <input type=hidden name=user_occ value=\"".StripSlashes(removeHack(check_words($user_occ)))."\">
          <input type=hidden name=user_intrest value=\"".StripSlashes(removeHack(check_words($user_intrest)))."\">
          <input type=hidden name=user_sig value=\"".StripSlashes(removeHack(check_words($user_sig)))."\">
          <input type=hidden name=user_aim value=\"".StripSlashes(removeHack($user_aim))."\">
          <input type=hidden name=user_yim value=\"".StripSlashes(removeHack($user_yim))."\">
          <input type=hidden name=user_msnm value=\"".StripSlashes(removeHack($user_msnm))."\">
          <input type=hidden name=user_viewemail value=\"$user_viewemail\">
          <input type=hidden name=pass value=\"".removeHack($pass)."\">
          <input type=hidden name=user_lnl value=\"".removeHack($user_lnl)."\">";
    echo "<input type=hidden name=C1 value=\"".StripSlashes(removeHack(check_words($C1)))."\">
          <input type=hidden name=C2 value=\"".StripSlashes(removeHack(check_words($C2)))."\">
          <input type=hidden name=C3 value=\"".StripSlashes(removeHack(check_words($C3)))."\">
          <input type=hidden name=C4 value=\"".StripSlashes(removeHack(check_words($C4)))."\">
          <input type=hidden name=C5 value=\"".StripSlashes(removeHack(check_words($C5)))."\">
          <input type=hidden name=C6 value=\"".StripSlashes(removeHack(check_words($C6)))."\">
          <input type=hidden name=C7 value=\"".StripSlashes(removeHack(check_words($C7)))."\">
          <input type=hidden name=C8 value=\"".StripSlashes(removeHack(check_words($C8)))."\">
          <input type=hidden name=M1 value=\"".StripSlashes(removeHack(check_words($M1)))."\">
          <input type=hidden name=M2 value=\"".StripSlashes(removeHack(check_words($M2)))."\">
          <input type=hidden name=T1 value=\"".StripSlashes(removeHack(check_words($T1)))."\">
          <input type=hidden name=T2 value=\"".StripSlashes(removeHack(check_words($T2)))."\">
          <input type=hidden name=B1 value=\"".StripSlashes(removeHack(check_words($B1)))."\">";
}
function confirmNewUser($uname, $name, $email, $url, $user_avatar, $user_icq, $user_occ, $user_from, $user_intrest, $user_sig, $user_viewemail, $user_aim, $user_yim, $user_msnm, $pass, $vpass,$user_lnl,$C1,$C2,$C3,$C4,$C5,$C6,$C7,$C8,$M1,$M2,$T1,$T2,$B1) {
    global $smilies, $short_user, $minpass, $memberpass;
    $uname=filter_text($uname);
    if ($user_viewemail!=1) {$user_viewemail="0";}
    $stop=userCheck($uname, $email);
    if ($memberpass) {
       if ((isset($pass)) and ("$pass" != "$vpass")) {
          $stop="<p align=\"center\">".translate("Both passwords are different. They need to be identical.")."</p><br />";
       } elseif (strlen($pass) < $minpass) {
          $stop="<p align=\"center\">".translate("Sorry, your password must be at least")." <b>$minpass</b> ".translate("characters long")."</p><br />";
       }
    }
    if (!$stop) {
       include("header.php");
       OpenTable();
          include ("modules/sform/extend-user/aff_extend-user.php");
          hidden_form();
          global $charte;
          if (!$charte) {
             echo "<p align=\"center\">".translate("You must accept the terms of use of this website")."<br /><br />";
             echo "<input type=\"hidden\" name=\"op\" value=\"only_newuser\"><input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".translate("Go Back")."\"></p></form>";
          } else {
             echo "<input type=\"hidden\" name=\"op\" value=\"finish\"><input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".translate("Finish")."\"></form>";
          }
       CloseTable();
       include("footer.php");
    } else {
       message_error($stop,"new user");
    }
}
function finishNewUser($uname, $name, $email, $url, $user_avatar, $user_icq, $user_occ, $user_from, $user_intrest, $user_sig, $user_viewemail, $user_aim, $user_yim, $user_msnm, $pass,$user_lnl, $C1,$C2,$C3,$C4,$C5,$C6,$C7,$C8,$M1,$M2,$T1,$T2,$B1) {
    global $makepass, $system, $adminmail, $sitename, $AutoRegUser, $memberpass, $gmt;
    $stop=userCheck($uname, $email);
    $user_regdate = time()+($gmt*3600);
    $stop=userCheck($uname, $email);
    if (!$stop) {
       global $pdst; $pdst="1";
       include("header.php");
       if (!$memberpass) {
          $makepass=makepass();
       } else {
          $makepass=$pass;
       }
       if (!$system)
          $cryptpass=crypt($makepass,$cryptpass);
       else
          $cryptpass=$makepass;
       if ($url!="") {
           if (!substr_count($url,"http://")) {$url="http://".$url;}
           if (trim($url)=="http://") {$url="";}
       }
       $result = mysql_query("insert into users values (NULL,'$name','$uname','$email','','$url','$user_avatar','$user_regdate','$user_icq','$user_occ','$user_from','$user_intrest','$user_sig','$user_viewemail','','$user_aim','$user_yim','$user_msnm','','$cryptpass','10','','0','0','0','','0','','','$commentlimit','0','0','1','0','','','$user_lnl')");
       list($usr_id) = mysql_fetch_array(mysql_query("select uid from users where uname='$uname'"));
       $result = mysql_query("insert into users_extend values ('$usr_id','$C1','$C2','$C3','$C4','$C5','$C6','$C7','$C8','$M1','$M2','$T1','$T2', '$B1')");
       if ($user_sig) {
          $attach = 1;
       } else {
          $attach = 0;
       }
       if (($AutoRegUser==1) or (!isset($AutoRegUser))) {
          $result = mysql_query("insert into users_status values ('$usr_id','0','$attach','0','1','1','')");
       } else {
          $result = mysql_query("insert into users_status values ('$usr_id','0','$attach','0','1','0','')");
       }
       if ($result) {
          if (($system==1) or ($memberpass)) {
             OpenTable();
                echo translate("Your Password is: ")."<b>$makepass</b><br /><br />";
                echo translate("You can change it after you login at")." : <a href=\"user.php?op=login&uname=$uname&pass=$makepass\" class=\"NOIR\"><b>$sitename</b></a>";
             CloseTable();
          } else {
             $message = "".translate("Welcome to")." $sitename !\n\n".translate("You or someone else has used your email account")." ($email) ".translate("to register an account at")." $sitename. ".translate("The following is the member information:")."\n\n".translate("-Nickname: ")." $uname\n".translate("-Password: ")." $makepass\n\n";
             include ("signat.php");
             $subject="".translate("User Password for")." $uname";
             send_email($email, $subject, $message, "", true, "text");
             OpenTable();
                echo translate("You are now registered. You should receive your password at the email account you provided.")."";
             CloseTable();
          }
          //------------------------------------------------
          if (file_exists("modules/include/new_user.inc")) {
             include ("modules/include/new_user.inc");
             global $gmt;
             $time = date(translate("dateinternal"),time()+($gmt*3600));
             $message = meta_lang(AddSlashes(str_replace("\n","<br />", $message)));
             $sql = "INSERT INTO priv_msgs (msg_image, subject, from_userid, to_userid, msg_time, msg_text) ";
             $sql .= "VALUES ('', '$sujet', '$emetteur_id', '$usr_id', '$time', '$message')";
             mysql_query($sql);
          }
          //------------------------------------------------
       }
       include("footer.php");
    } else {
       message_error($stop, "finish");
    }
}

function userinfo($uname, $bypass=0) {
    global $user, $sitename, $smilies, $short_user, $site_font;
    global $name, $email, $url, $bio, $user_avatar, $user_icq, $user_aim, $user_yim, $user_msnm, $user_from, $user_occ, $user_intrest, $user_sig, $user_journal;

    $uname=removeHack($uname);
    $result = mysql_query("SELECT uid, name, femail, url, bio, user_avatar, user_icq, user_aim, user_yim, user_msnm, user_from, user_occ, user_intrest, user_sig, user_journal, mns FROM users WHERE uname='$uname'");
    list($uid, $name, $femail, $url, $bio, $user_avatar, $user_icq, $user_aim, $user_yim, $user_msnm, $user_from, $user_occ, $user_intrest, $user_sig, $user_journal, $mns) = mysql_fetch_array($result);
    if (!$uid) {
       header ("location: index.php");
    }
    if (!$bypass) {global $cookie;}
    include("header.php");

    if (($uname == $cookie[1]) || ($bypass==1)) {
       echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
       echo "$uname, ".translate("Welcome to")." $sitename";
       echo "</td></tr></table>\n";
       echo "<br />";
       echo "<p align=\"center\">".translate("This is your personal page")."</p><br />";
       nav($mns);
    }
    $email=removeHack($femail);
    $name=stripslashes(removeHack($name));
    $url=removeHack($url);
    $bio=stripslashes(removeHack($bio));
    $user_icq=stripslashes(removeHack($user_icq));
    $user_aim=stripslashes(removeHack($user_aim));
    $user_yim=stripslashes(removeHack($user_yim));
    $user_msnm=stripslashes(removeHack($user_msnm));
    $user_from=stripslashes(removeHack($user_from));
    $user_occ=stripslashes(removeHack($user_occ));
    $user_intrest=stripslashes(removeHack($user_intrest));
    $user_sig=nl2br(removeHack($user_sig));
    $user_journal=stripslashes(removeHack($user_journal));
    $op="userinfo";
    include("modules/sform/extend-user/aff_extend-user.php");
    echo "<br /><br />";
    opentable();
    if ($mns) {
       echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
       echo translate("Mini-Web site")."&nbsp;:&nbsp;<a href=\"minisite.php?op=$uname\" target=\"_blank\" class=\"ROUGE\"><b>".translate("the page")." ".translate("here")."</b></a></td></tr>";
       echo "</table>\n";
       echo "<br />";
    }
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo translate("Online journal for")." $uname :";
    echo "</td></tr><tr><td>\n";
    echo $user_journal;
    echo "</td></tr></table>\n";
    echo "<br />";
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo translate("Last 10 comments by")." $uname :";
    echo "</td></tr>\n";
    $result = mysql_query("select c.tid, c.sid, c.subject, s.ihome from comments c, stories s where c.sid=s.sid and name='$uname' order by tid DESC limit 0,10");
    while(list($tid, $sid, $subject, $ihome) = mysql_fetch_row($result)) {
       $rowcolor = tablos();
       if (ctrl_aff($ihome,0)) {
          echo "<tr $rowcolor><td><a href=\"article.php?thold=-1&amp;mode=flat&amp;order=0&amp;sid=$sid#$tid\" class=\"NOIR\">$subject</a></td></tr>";
       }
    }
    echo "</table>\n";
    echo "<br />";
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo translate("Last 10 news submissions sent by")." $uname :";
    echo "</td></tr>\n";
    $xtab=news_aff("libre", "where informant='$uname' order by sid DESC limit 10", "", 10);
    $story_limit=0;
    while (($story_limit<10) and ($story_limit<sizeof($xtab))) {
       $rowcolor = tablos();
       list($sid, $catid, $aid, $title) = $xtab[$story_limit];
       $story_limit++;
       echo "<tr $rowcolor><td><a href=\"article.php?sid=$sid\" class=\"NOIR\">".aff_langue($title)."</a></td></tr>";
    }
    echo "</table>\n";
    closetable();
    include("footer.php");
}

function main($user) {
    global $stop, $smilies;
    if (!isset($user)) {
       include("header.php");
       if ($stop==99) {
          echo "<p align=\"center\"><blink><marquee><h3>".translate("User not yet allowed by Administrator")."</h3></marquee></blink></p>";
       } elseif ($stop)  {
          echo "<p align=\"center\"><blink><marquee><h3>".translate("Incorrect Login!")."</h3></marquee></blink></p>";
       }
       if (!$user) {
          echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
          echo translate("User Login");
          echo "</td></tr></table>\n";
          opentable();
          echo "<form action=\"user.php\" method=\"post\" name=\"userlogin\">";
          echo "<br /><table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">";
          echo "<tr><td nowrap=\"nowrap\">".translate("Nickname: ")."</td><td><input class=\"TEXTBOX_STANDARD\" type=\"text\" name=\"uname\" size=\"26\" maxlength=\"25\"><br /></td><td>&nbsp;</td></tr>";
          echo "<tr><td nowrap=\"nowrap\">".translate("Password: ")."</td><td><input class=\"TEXTBOX_STANDARD\" type=\"password\" name=\"pass\" size=\"21\" maxlength=\"20\"><br /></td>";
          echo "<td width=\"30%\"><input type=\"hidden\" name=\"op\" value=\"login\">";
          echo "<input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".translate("Submit")."\">";
          echo "</td></tr></table>\n";
          echo "</form>";
          echo "<script type=\"text/javascript\" language=\"JavaScript\">document.userlogin.uname.focus();</script>";
          closetable();

          opentable();
          echo "<p align=\"center\"><a href=\"user.php?op=only_newuser\" class=\"NOIR\">".translate("New User")."</a>&nbsp;&nbsp;-::-&nbsp;&nbsp;<a href=user.php?op=forgetpassword class=\"NOIR\">".translate("Lost your Password?")."</a></p>";
          closetable();

          // include externe file from modules/include for functions, codes ...
          if (file_exists("modules/include/user.inc")) {
             opentable();
             include ("modules/include/user.inc");
             closetable();
          }
       }
       include("footer.php");
    } elseif (isset($user)) {
       $cookie=cookiedecode($user);
       userinfo($cookie[1]);
    }
}

function logout() {
    global $user, $cookie;
    if ($cookie[1]!="") {
       mysql_query("DELETE FROM session WHERE username='$cookie[1]'");
    }
    setcookie("user","",0);
    unset($user);
    setcookie("user_language","",0);
    unset($user_language);
    Header("Location: index.php");
}

function ForgetPassword() {
    include("header.php");
    OpenTable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo translate("Lost your Password?");
    echo "</td></tr></table>\n";
    echo "<br />";
    echo translate("No problem. Just type your Nickname and click on send button.")."<br />";
    echo translate("Confirmation Info")."<br />";
    echo "<form action=\"user.php\" method=\"post\">";
    echo "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\">";
    echo "<tr><td width=\"20%\">".translate("Nickname: ")."</td><td><input class=\"textbox\" type=\"text\" name=\"uname\" size=\"26\" maxlength=\"25\"><br /></td></tr>";
    echo "<tr><td width=\"20%\">".translate("Confirmation Code: ")."</td><td><input class=\"textbox\" type=\"text\" name=\"code\" size=\"5\" maxlength=\"6\"><br /></td></tr>";
    echo "<tr><td width=\"20%\">&nbsp;</td><td><input type=\"hidden\" name=\"op\" value=\"mailpasswd\">";
    echo "<input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".translate("Send Password")."\">";
    echo "</td></tr></table>\n";
    echo "</form>";
    closeTable();
    include ("footer.php");
}
function mail_password($uname, $code) {
    global $sitename, $system, $adminmail, $nuke_url;
    $result = mysql_query("select email, pass from users where uname='$uname'");
    $tmp_result=mysql_fetch_row($result);
    if (!$tmp_result) {
       message_error(translate("Sorry, no corresponding user info was found")."<br /><br />","");
    } else {
       $host_name = getip();
       list($email, $pass) = $tmp_result;
       $areyou = substr($pass, 0, 5);

       if ($areyou==$code) {
          $newpass=makepass();
          $message  = "".translate("The user account")." '$uname' ".translate("at")." $sitename ".translate("has this email associated with it.")."\n";
          $message .= translate("A web user from")." $host_name ".translate("has just requested that password be sent.")."\n\n";
          $message .= translate("Your New Password is:")." $newpass\n\n".translate("You can change it after you login at")." $nuke_url/user.php\n".translate("If you didn't ask for this, don't worry. You are seeing this message, not 'them'. If this was an error just login with your new password.")."\n";
          include("signat.php");
          $subject="".translate("User Password for")." $uname";
          send_email($email, $subject, $message, "", true, "text");

          // Next step: add the new password to the database
          if (!$system) {
             $cryptpass=crypt($newpass,$cryptpass);
          } else {
             $cryptpass=$newpass;
          }
          $query="update users set pass='$cryptpass' where uname='$uname'";
          if (!mysql_query($query)) {
             message_error(translate("mail_password: could not update user entry. Contact the Administrator")."<br /><br />","");
          }
          message_error(translate("Password for")." $uname ".translate("mailed.")."<br /><br />","");

       // If no Code, send it
       } else {
          $message = "".translate("The user account")." '$uname' ".translate("at")." $sitename ".translate("has this email associated with it.")."\n";
          $message .= translate("A web user from")." $host_name ".translate("has just requested a Confirmation Code to change the password.")."\n\n".translate("Your Confirmation Code is:")." $areyou \n\n".translate("With this code you can now assign a new password at")." $nuke_url/user.php\n".translate("If you didn't ask for this, don't worry. Just delete this Email.")."\n";
          include("signat.php");

          $subject="".translate("Confirmation Code for")." $uname";
          send_email($email, $subject, $message, "", true, "text");
          message_error(translate("Confirmation Code for")." $uname ".translate("mailed.")."<br /><br />","");
       }
    }
}

function docookie($setuid, $setuname, $setpass, $setstorynum, $setumode, $setuorder, $setthold, $setnoscore, $setublockon, $settheme, $setcommentmax, $user_langue) {
    $info = base64_encode("$setuid:$setuname:".md5($setpass).":$setstorynum:$setumode:$setuorder:$setthold:$setnoscore:$setublockon:$settheme:$setcommentmax");
    global $user_cook_duration;
    if ($user_cook_duration<=0) {$user_cook_duration=1;}
    $timeX=time()+(3600*$user_cook_duration);
    setcookie("user","$info",$timeX);
    if ($user_langue!="") {
       setcookie("user_language","$user_langue",$timeX);
    }
}

function login($uname, $pass) {
    global $setinfo, $system;

    $result = mysql_query("select pass, uid, uname, storynum, umode, uorder, thold, noscore, ublockon, theme, commentmax, user_langue from users where uname='$uname'");
    if (mysql_num_rows($result)==1) {
       $setinfo = mysql_fetch_array($result);
       $result = mysql_query("select open from users_status where uid='$setinfo[uid]'");
       list($open_user) = mysql_fetch_row($result);
       if ($open_user==0) {
          Header("Location: user.php?stop=99");
          return;
       }
       $dbpass=$setinfo[pass];
       if (cur_charset=="utf-8") {
          if (!$system) {
             $passwd=crypt($pass,$dbpass);
          } else {
             $passwd=$pass;
          }
          if (strcmp($dbpass,$passwd)!=0) {
             $pass=utf8_decode($pass);
             if (!$system) {
                $passwd=crypt($pass,$dbpass);
             } else {
                $passwd=$pass;
             }
             if (strcmp($dbpass,$passwd)!=0) {
                Header("Location: user.php?stop=1");
                return;
             }
          }
          docookie($setinfo[uid], $setinfo[uname], $passwd, $setinfo[storynum], $setinfo[umode], $setinfo[uorder], $setinfo[thold], $setinfo[noscore], $setinfo[ublockon], $setinfo[theme], $setinfo[commentmax], $setinfo[user_langue]);
       } else {
          if (!$system) {
             $passwd=crypt($pass,$dbpass);
          } else {
             $passwd=$pass;
          }
          if (strcmp($dbpass,$passwd)==0) {
             docookie($setinfo[uid], $setinfo[uname], $passwd, $setinfo[storynum], $setinfo[umode], $setinfo[uorder], $setinfo[thold], $setinfo[noscore], $setinfo[ublockon], $setinfo[theme], $setinfo[commentmax], $setinfo[user_langue]);
          } else {
             Header("Location: user.php?stop=1");
             return;
          }
       }

       $ip = getip();
       $result = mysql_query("SELECT * from session WHERE host_addr='$ip' and guest='1'");
       if ($row = mysql_fetch_array($result)) {
          mysql_query("DELETE FROM session WHERE host_addr='$ip' and guest='1'");
       }

       Header("Location: index.php");
    } else {
       Header("Location: user.php?stop=1");
    }
}

function edituser() {
    global $user, $smilies, $short_user, $subscribe, $member_invisible, $avatar_size;
    include("header.php");
    $userinfo=getusrinfo($user);
    nav($userinfo[mns]);
    OpenTable();
    global $C1, $C2, $C3, $C4, $C5, $C6, $C7, $C8, $M1, $M2, $T1, $T2,$B1;
    $result = mysql_query("SELECT C1, C2, C3, C4, C5, C6, C7, C8, M1, M2, T1, T2, B1 FROM users_extend WHERE uid='$userinfo[uid]'");
    list($C1, $C2, $C3, $C4, $C5, $C6, $C7, $C8, $M1, $M2, $T1, $T2, $B1) = mysql_fetch_array($result);
    include ("modules/sform/extend-user/mod_extend-user.php");
    CloseTable();
    include("footer.php");
}
function saveuser($uid, $name, $uname, $email, $femail, $url, $pass, $vpass, $bio, $user_avatar, $user_icq, $user_occ, $user_from, $user_intrest, $user_sig, $user_viewemail, $user_aim, $user_yim, $user_msnm, $attach, $usend_email, $uis_visible,$user_lnl, $C1,$C2,$C3,$C4,$C5,$C6,$C7,$C8,$M1,$M2,$T1,$T2,$B1,$MAX_FILE_SIZE,$raz_avatar) {
    global $user, $userinfo, $system, $minpass;
    $cookie=cookiedecode($user);
    $check = $cookie[1];
    $result = mysql_query("select uid, email from users where uname='$check'");
    list($vuid, $vemail) = mysql_fetch_row($result);
    if (($check == $uname) AND ($uid == $vuid)) {
        if ((isset($pass)) && ("$pass" != "$vpass")) {
           message_error(translate("Both passwords are different. They need to be identical.")."<br /><br />","");
        } elseif (($pass != "") && (strlen($pass) < $minpass)) {
           message_error(translate("Sorry, your password must be at least")." <b>$minpass</b> ".translate("characters long")."<br /><br />","");
        } else {
           $stop=userCheck("edituser", $email);
           if (!$stop)  {
              if ($bio) { $bio=FixQuotes(filter_text($bio)); }
              if ($attach) {$t = 1;} else {$t = 0;}
              if ($user_viewemail) {$a = 1;} else {$a = 0;}
              if ($usend_email) {$u = 1;} else {$u = 0;}
              if ($uis_visible) {$v = 0;} else {$v = 1;}
              if ($user_lnl) {$w = 1;} else {$w = 0;}
              if ($url!="") {
                 if (!substr_count($url,"http://")) {$url="http://".$url;}
                 if (trim($url)=="http://") {$url="";}
              }

              include_once("modules/upload/upload.conf.php");
              global $avatar_size;
              if (!$avatar_size) {$avatar_size="80*100";}
              $avatar_limit=explode("*",$avatar_size);
              if ($DOCUMENTROOT!="") {
                 $rep=$DOCUMENTROOT;
              } else {
                 global $DOCUMENT_ROOT;
                 if ($DOCUMENT_ROOT) {
                    $rep=$DOCUMENT_ROOT;
                 } else {
                    $rep=$_SERVER['DOCUMENT_ROOT'];
                 }
              }
              if ($B1!="none") {
                 global $language;
                 include_once("modules/upload/lang/upload.lang-$language.php");
                 include_once("modules/upload/clsUpload.php");

                 $upload = new Upload();
                 $upload->maxupload_size=$MAX_FILE_SIZE;
                 $field1_filename = trim($upload->getFileName("B1"));
                 $suffix = strtoLower(substr(strrchr($field1_filename,'.'),1));
                 if (($suffix=="gif") or ($suffix=="jpg") or ($suffix=="png")) {
                    $field1_filename=removeHack(eregi_replace ("[/\\\\:\*\?\"<>|']", "", rawurldecode($field1_filename)));
                    $field1_filename=eregi_replace("/etc","",$field1_filename);
                    $field1_filename=eregi_replace("\.\.","",$field1_filename);
                    $field1_filename=eregi_replace("config.php","",$field1_filename);
                    if ($field1_filename) {
                       if ($autorise_upload_p) {
                          $user_dir=$racine."/users_private/".$uname."/";
                          if (!is_dir($rep.$user_dir)) {
                             @umask("0000");
                             if (@mkdir($rep.$user_dir,0777)) {
                                $fp = fopen($rep.$user_dir."index.html", 'w');
                                fclose($fp);
                             } else {
                                $user_dir=$racine."/users_private/";
                             }
                          }
                       } else {
                          $user_dir=$racine."/users_private/";
                       }
                       if ($upload->saveAs($uname.".".$suffix ,$rep.$user_dir, "B1",true)) {
                          $old_user_avatar=$user_avatar;
                          $user_avatar=$user_dir.$uname.".".$suffix;
                          $img_size = @getimagesize($rep.$user_avatar);
                          if (($img_size[0]>$avatar_limit[0]) or ($img_size[1]>$avatar_limit[1])) {
                             $raz_avatar=true;
                          }
                       }
                    }
                 }
              }
              if ($raz_avatar) {
                 if (strstr($user_avatar,"/users_private")) {
                    @unlink($rep.$user_avatar);
                    @unlink($rep.$old_user_avatar);
                 }
                 $user_avatar="blank.gif";
              }

              if ($pass!="") {
                 cookiedecode($user);
                 if (!$system)
                    $pass=crypt($pass,$pass);
                 mysql_query("update users set name='$name', email='$email', femail='".removeHack($femail)."', url='".removeHack($url)."', pass='$pass', bio='".removeHack($bio)."', user_avatar='$user_avatar', user_icq='".removeHack($user_icq)."', user_occ='".removeHack(check_words($user_occ))."', user_from='".removeHack(check_words($user_from))."', user_intrest='".removeHack(check_words($user_intrest))."', user_sig='".removeHack(check_words($user_sig))."', user_aim='".removeHack($user_aim)."', user_yim='".removeHack($user_yim)."', user_msnm='".removeHack($user_msnm)."', user_viewemail='$a', send_email='$u', is_visible='$v', user_lnl='$w' where uid='$uid'");
                 $result = mysql_query("select uid, uname, pass, storynum, umode, uorder, thold, noscore, ublockon, theme from users where uname='$uname' and pass='$pass'");
                 if (mysql_num_rows($result)==1) {
                    $userinfo = mysql_fetch_array($result);
                    docookie($userinfo[uid],$userinfo[uname],$userinfo[pass],$userinfo[storynum],$userinfo[umode],$userinfo[uorder],$userinfo[thold],$userinfo[noscore],$userinfo[ublockon],$userinfo[theme],$userinfo[commentmax], "");
                 }
              } else {
                 mysql_query("update users set name='$name', email='$email', femail='".removeHack($femail)."', url='".removeHack($url)."', bio='".removeHack($bio)."', user_avatar='$user_avatar', user_icq='".removeHack($user_icq)."', user_occ='".removeHack(check_words($user_occ))."', user_from='".removeHack(check_words($user_from))."', user_intrest='".removeHack(check_words($user_intrest))."', user_sig='".removeHack(check_words($user_sig))."', user_aim='".removeHack($user_aim)."', user_yim='".removeHack($user_yim)."', user_msnm='".removeHack($user_msnm)."', user_viewemail='$a', send_email='$u', is_visible='$v', user_lnl='$w' where uid='$uid'");
              }
              mysql_query("update users_status set attachsig='$t' where uid='$uid'");
              $result=mysql_query("select uid from users_extend where uid='$uid'");
              if (mysql_num_rows($result)==1) {
                 mysql_query("update users_extend set C1='".removeHack(check_words($C1))."', C2='".removeHack(check_words($C2))."', C3='".removeHack(check_words($C3))."', C4='".removeHack(check_words($C4))."', C5='".removeHack(check_words($C5))."', C6='".removeHack(check_words($C6))."', C7='".removeHack(check_words($C7))."', C8='".removeHack(check_words($C8))."', M1='".removeHack(check_words($M1))."', M2='".removeHack(check_words($M2))."', T1='".removeHack(check_words($T1))."', T2='".removeHack(check_words($T2))."', B1='$B1' where uid='$uid'");
              } else {
                 $result = mysql_query("insert into users_extend values ('$uid','".removeHack(check_words($C1))."', '".removeHack(check_words($C2))."', '".removeHack(check_words($C3))."', '".removeHack(check_words($C4))."', '".removeHack(check_words($C5))."', '".removeHack(check_words($C6))."', '".removeHack(check_words($C7))."', '".removeHack(check_words($C8))."', '".removeHack(check_words($M1))."', '".removeHack(check_words($M2))."', '".removeHack(check_words($T1))."', '".removeHack(check_words($T2))."', '$B1')");
              }
              if ($pass!="") {
                 logout();
              } else {
                 header("location: user.php?op=edituser");
              }
           } else {
               message_error($stop, "");
           }
        }
    } else {
       Header("Location: index.php");
    }
}

function edithome() {
    global $user, $Default_Theme;
    include ("header.php");
    $userinfo=getusrinfo($user);
    nav($userinfo[mns]);
    if ($userinfo[theme]=="") {
       $userinfo[theme] = "$Default_Theme";
    }
    OpenTable();
    echo "<br /><table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo translate("Change the home");
    echo "</td></tr></table>\n";
    echo "<br /><form action=\"user.php\" method=\"post\">
          <b>".translate("News number in the Home")."</b> (max. 127) :
          <input class=\"TEXTBOX_STANDARD\" type=\"text\" name=\"storynum\" size=\"3\" maxlength=\"3\" value=\"$userinfo[storynum]\">
          <br /><br />";
    if ($userinfo[ublockon]==1) {
       $sel = "checked";
    }
    echo "<input type=\"checkbox\" name=\"ublockon\" $sel>
        <b>".translate("Activate Personal Menu")."</b>
        <br />".translate("(Check this option and the following text will appear in the Home)")."
        <br />".translate("(You can use HTML code to put links, for example)")."<br />
        <textarea class=\"TEXTBOX\" cols=\"38\" rows=\"5\" name=\"ublock\">$userinfo[ublock]</textarea>
        <br /><br />
        <input type=\"hidden\" name=\"theme\" value=\"$userinfo[theme]\">
        <input type=\"hidden\" name=\"uname\" value=\"$userinfo[uname]\">
        <input type=\"hidden\" name=\"uid\" value=\"$userinfo[uid]\">
        <input type=\"hidden\" name=\"op\" value=\"savehome\">
        <input  class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".translate("Save Changes!")."\">
        </form>";
    CloseTable();
    include ("footer.php");
}
function savehome($uid, $uname, $theme, $storynum, $ublockon, $ublock) {
    global $user;
    $cookie=cookiedecode($user);
    $check = $cookie[1];
    $result = mysql_query("select uid from users where uname='$check'");
    list($vuid) = mysql_fetch_row($result);
    if (($check == $uname) AND ($uid == $vuid)) {
        if(isset($ublockon)) $ublockon=1; else $ublockon=0;
        $ublock = FixQuotes($ublock);
        mysql_query("update users set storynum='$storynum', ublockon='$ublockon', ublock='$ublock' where uid='$uid'");
        $userinfo=getusrinfo($user);
        docookie($userinfo[uid],$userinfo[uname],$userinfo[pass],$userinfo[storynum],$userinfo[umode],$userinfo[uorder],$userinfo[thold],$userinfo[noscore],$userinfo[ublockon],$userinfo[theme],$userinfo[commentmax], "");
        // Include cache manager for purge cache Page
        $cache_obj = new cacheManager();
        $cache_obj->UsercacheCleanup();
        Header("Location: user.php?op=edithome");
    } else {
        Header("Location: index.php");
    }
}

function chgtheme() {
    global $user;
    include ("header.php");
    $userinfo=getusrinfo($user);
    nav($userinfo[mns]);
    OpenTable();
    echo "<br /><table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo translate("Select One Theme");
    echo "</td></tr></table>\n";
    echo "<p align=\"center\"><form action=\"user.php\" method=\"post\">
          <select class=\"TEXTBOX_STANDARD\" name=\"theme\">";
    include("themes/list.php");
    $themelist = explode(" ", $themelist);
    for ($i=0; $i < sizeof($themelist); $i++) {
       if ($themelist[$i]!="") {
          echo "<option value=\"$themelist[$i]\" ";
          if ((($userinfo[theme]=="") && ($themelist[$i]=="$Default_Theme")) || ($userinfo[theme]==$themelist[$i])) echo "selected";
             echo ">$themelist[$i]\n";
          }
    }
    if ($userinfo[theme]=="") $userinfo[theme] = "Default_Theme";
    echo "</select></p><br />
         <li>".translate("This option will change the look for the whole site.")."</li><br />
         <li>".translate("The changes will be valid only to you.")."</li><br />
         <li>".translate("Each user can view the site with different theme.")."</li><br />";

    echo "<input type=\"hidden\" name=\"storynum\" value=\"$userinfo[storynum]\">
          <input type=\"hidden\" name=\"ublockon\" value=\"$userinfo[ublockon]\">
          <input type=\"hidden\" name=\"ublock\" value=\"$userinfo[ublock]\">
          <input type=\"hidden\" name=\"uname\" value=\"$userinfo[uname]\">
          <input type=\"hidden\" name=\"uid\" value=\"$userinfo[uid]\">
          <input type=\"hidden\" name=\"op\" value=\"savetheme\"><br />
          <input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".translate("Save Changes!")."\">
          </form>";
    CloseTable();
    include ("footer.php");
}
function savetheme($uid, $theme) {
    global $user;
    $cookie=cookiedecode($user);
    $check = $cookie[1];
    $result = mysql_query("select uid from users where uname='$check'");
    list($vuid) = mysql_fetch_row($result);
    if ($uid == $vuid) {
        mysql_query("update users set theme='$theme' where uid='$uid'");
        $userinfo=getusrinfo($user);
        docookie($userinfo[uid],$userinfo[uname],$userinfo[pass],$userinfo[storynum],$userinfo[umode],$userinfo[uorder],$userinfo[thold],$userinfo[noscore],$userinfo[ublockon],$userinfo[theme],$userinfo[commentmax], "");
        // Include cache manager for purge cache Page
        $cache_obj = new cacheManager();
        $cache_obj->UsercacheCleanup();
        Header("Location: user.php");
    } else {
       Header("Location: index.php");
    }
}

function editcomm() {
    global $user;
    include ("header.php");
    $userinfo=getusrinfo($user);
    nav($userinfo[mns]);
    OpenTable();
    echo "<br /><table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo translate("Display Mode");
    echo "</td></tr></table>\n";
    echo "<br />\n";
    echo "<form action=\"user.php\" method=\"post\">
          <table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\"><tr><td>
          <b>".translate("Display Mode")." :</b>
          <select class=\"TEXTBOX_STANDARD\" name=\"umode\">
          <option value=\"nocomments\"";
    if ($userinfo[umode] == 'nocomments') { echo "selected"; }
    echo "> ".translate("No Comments");
    echo "<option value=\"nested\"";
    if ($userinfo[umode] == 'nested') { echo "selected"; }
    echo "> ".translate("Nested");
    echo "<option value=\"flat\"";
    if ($userinfo[umode] == 'flat') { echo "selected"; }
    echo "> ".translate("Flat");
    echo "<option value=\"thread\"";
    if (!isset($userinfo[umode]) || ($userinfo[umode]=="") || $userinfo[umode]=='thread') { echo "selected"; }
    echo "> ".translate("Thread");
    echo "</select>
          <br /><br />
          <b>".translate("Sort Order")." :</b>
          <select class=\"TEXTBOX_STANDARD\" name=\"uorder\">
          <option value=\"0\"";
    if (!$userinfo[uorder]) { echo "selected"; }
    echo "> ".translate("Oldest First");
    echo "<option value=\"1\"";
    if ($userinfo[uorder]==1) { echo "selected"; }
    echo "> ".translate("Newest First");
    echo "<option value=\"2\"";
    if ($userinfo[uorder]==2) { echo "selected"; }
    echo "> ".translate("Highest Scores First");
    echo "</select>
          <br /><br />
          <b>".translate("Threshold")."</b>
          ".translate("Comments scored less than this setting will be ignored.")."<br />
          <select class=\"TEXTBOX_STANDARD\" name=\"thold\">
          <option value=\"-1\"";
    if ($userinfo[thold]==-1) { echo "selected"; }
    echo "> ".translate("Uncut and Raw");
    echo "<option value=\"0\"";
    if ($userinfo[thold]==0) { echo "selected"; }
    echo ">0: ".translate("Almost Everything");
    echo "<option value=\"1\"";
    if ($userinfo[thold]==1) { echo "selected"; }
    echo ">1: ".translate("Filter Most Anon");
    echo "<option value=\"2\"";
    if ($userinfo[thold]==2) { echo "selected"; }
    echo ">2: ".translate("Score")." +2";
    echo "<option value=\"3\"";
    if ($userinfo[thold]==3) { echo "selected"; }
    echo ">3: ".translate("Score")." +3";
    echo "<option value=\"4\"";
    if ($userinfo[thold]==4) { echo "selected"; }
    echo ">4: ".translate("Score")." +4";
    echo "<option value=\"5\"";
    if ($userinfo[thold]==5) { echo "selected"; }
    echo ">5: ".translate("Score")." +5";
    echo "</select><br />";
    echo translate("Anonymous posts start at 0, logged in posts start at 1. Moderators add and subtract points.");
    echo "<br /><br />";
    echo "<input type=\"checkbox\" name=\"noscore\" ";
    if ($userinfo[noscore]==1) { echo "checked"; }
    echo "><b> ".translate("Do Not Display Scores")."</b> ".translate("(Hides score: They still apply, you just don't see them.)");
    echo "<br /><br />
          <b>".translate("Max Comment Length")." :</b> ".translate("(Truncates long comments, and adds a Read More link. Set really big to disable)")."<br />
          <input class=\"TEXTBOX_STANDARD\" type=\"text\" name=\"commentmax\" value=\"$userinfo[commentmax]\" size=\"11\" maxlength=\"11\"> bytes (1024 bytes = 1K)
          <br /><br />
          <input type=\"hidden\" name=\"uname\" value=\"$userinfo[uname]\">
          <input type=\"hidden\" name=\"uid\" value=\"$userinfo[uid]\">
          <input type=\"hidden\" name=\"op\" value=\"savecomm\">
          <input class=\"BOUTON_STANDARD\"type=\"submit\" value=\"".translate("Save Changes")."\">
          </td></tr></table></form>";
    CloseTable();
    include ("footer.php");
}
function savecomm($uid, $uname, $umode, $uorder, $thold, $noscore, $commentmax) {
    global $user;
    $cookie=cookiedecode($user);
    $check = $cookie[1];
    $result = mysql_query("select uid from users where uname='$check'");
    list($vuid) = mysql_fetch_row($result);
    if (($check == $uname) AND ($uid == $vuid)) {
        if(isset($noscore)) $noscore=1; else $noscore=0;
        mysql_query("update users set umode='$umode', uorder='$uorder', thold='$thold', noscore='$noscore', commentmax='$commentmax' where uid='$uid'");
        $userinfo=getusrinfo($user);
        docookie($userinfo[uid],$userinfo[uname],$userinfo[pass],$userinfo[storynum],$userinfo[umode],$userinfo[uorder],$userinfo[thold],$userinfo[noscore],$userinfo[ublockon],$userinfo[theme],$userinfo[commentmax], "");
        // Include cache manager for purge cache Page
        $cache_obj = new cacheManager();
        $cache_obj->UsercacheCleanup();
        Header("Location: user.php?op=editcom");
    } else {
        Header("Location: index.php");
    }
}

function editjournal(){
    global $user, $pdst;
    $pdst=0;
    include("header.php");
    $userinfo=getusrinfo($user);
    nav($userinfo[mns]);
    OpenTable();
    echo "<br /><table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo translate("Edit your journal");
    echo "</td></tr></table>\n";
    echo "<form action=\"user.php\" method=\"post\" name=\"adminForm\">";
    echo "<br />";
    echo "<textarea class=\"TEXTBOX\" cols=\"70\" rows=\"30\" name=\"journal\" style=\"width: 100%;\">$userinfo[user_journal]</textarea>";
    echo aff_editeur("journal", "true");
    echo "<br />";
    echo "<input type=\"hidden\" name=\"uname\" value=\"$userinfo[uname]\">";
    echo "<input type=\"hidden\" name=\"uid\" value=\"$userinfo[uid]\">";
    echo "<input type=\"hidden\" name=\"op\" value=\"savejournal\">";
    echo "<input type=\"checkbox\" name=\"datetime\" value=\"1\">".translate("Add date and time stamp")."<br /><br />";
    echo "<input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".translate("Save Journal")."\">";
    echo "</form>";
    CloseTable();
    include("footer.php");
}
function savejournal($uid, $journal, $datetime){
    global $user;
    $cookie=cookiedecode($user);
    $check = $cookie[1];
    $result = mysql_query("SELECT uid FROM users WHERE uname='$check'");
    list($vuid) = mysql_fetch_row($result);
    if ($uid == $vuid) {
       $journal = removeHack(stripslashes(FixQuotes(check_words($journal))));
       $upload=false;
       include("modules/upload/upload_f.php");
       if ($Xstring=prepa_upload("",$journal)) {$journal=$Xstring[0];$Xname=$Xstring[1];$upload=true;}
       if ($upload) {
          global $pdst; $pdst="1";
          include ('header.php');
          win_upload($Xname);
          opentable();
          $journal=urlencode($journal);
          echo "<br /><form action=\"user.php\" method=\"post\" name=\"adminForm\">";
          echo "<b>".translate("Submission in progress. After Uploading your files, please click on the OK button to finish.")."</b>";
          echo "<input type=\"hidden\" name=\"uid\" value=\"$uid\">";
          echo "<input type=\"hidden\" name=\"journal\" value=\"$journal\">";
          echo "<input type=\"hidden\" name=\"datetime\" value=\"$datetime\">";
          echo "<input type=\"hidden\" name=\"op\" value=\"savejournal\">";
          echo "<br /><br /><p aling=\"center\"><input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"Xop\" value=\"Ok\">&nbsp;&nbsp;<a href=\"javascript: history.go(-1)\" class=\"NOIR\">[ ".translate("Go Back")." ]</a></p>";
          echo "</form>";
          closetable();
          include ('footer.php');
       } else {
          $journal=urldecode($journal);
          if ($datetime) {
            $journalentry = $journal;
            $journalentry .= "<br /><br />";
            global $gmt;
            $journalentry .= date(translate("dateinternal"),time()+($gmt*3600));
            mysql_query("update users set user_journal='$journalentry' where uid='$uid'");
          } else {
            mysql_query("update users set user_journal='$journal' where uid='$uid'");
          }
          $userinfo=getusrinfo($user);
          Header("Location: user.php");
       }
    } else {
       Header("Location: index.php");
    }
}

switch ($op) {
    case "logout":
         logout();
         break;

    case "lost_pass":
         lost_pass();
         break;

    case "new user":
         confirmNewUser($uname, $name, $email, $url, $user_avatar, $user_icq, $user_occ, $user_from, $user_intrest, $user_sig, $user_viewemail, $user_aim, $user_yim, $user_msnm, $pass, $vpass, $user_lnl, $C1,$C2,$C3,$C4,$C5,$C6,$C7,$C8,$M1,$M2,$T1,$T2,$B1);
         break;

    case "finish":
         finishNewUser($uname, $name, $email, $url, $user_avatar, $user_icq, $user_occ, $user_from, $user_intrest, $user_sig, $user_viewemail, $user_aim, $user_yim, $user_msnm, $pass, $user_lnl, $C1,$C2,$C3,$C4,$C5,$C6,$C7,$C8,$M1,$M2,$T1,$T2,$B1);
         break;

    case "mailpasswd":
         if ($uname!="") {
            mail_password($uname, $code);
         } else {
            main($user);
         }
         break;

    case "userinfo":
         if (($member_list==1) AND (($user=="") AND (!isset($admin)))) {
            Header("Location: index.php");
         }
         if ($uname!="") {
            userinfo($uname, $bypass);
         } else {
            main($user);
         }
         break;

    case "login":
         login($uname, $pass);
         break;

    case "edituser":
         if ($user)
            edituser();
         else
            Header("Location: index.php");
         break;
    case "saveuser":
         $past = time()-300;
         mysql_query("DELETE FROM session WHERE time < $past");
         $result = mysql_query("SELECT time FROM session WHERE username='$cookie[1]'");
         if ($row = mysql_fetch_array($result)) {
            saveuser($uid, $name, $uname, $email, $femail, $url, $pass, $vpass, $bio, $user_avatar, $user_icq, $user_occ, $user_from, $user_intrest, $user_sig, $user_viewemail, $user_aim, $user_yim, $user_msnm, $attach, $usend_email, $uis_visible, $user_lnl, $C1,$C2,$C3,$C4,$C5,$C6,$C7,$C8,$M1,$M2,$T1,$T2,$B1,$MAX_FILE_SIZE,$raz_avatar);
         } else {
            Header("Location: user.php");
         }
         break;

    case "edithome":
         if ($user)
            edithome();
         else
            Header("Location: index.php");
         break;
    case "savehome":
         savehome($uid, $uname, $theme, $storynum, $ublockon, $ublock);
         break;

    case "chgtheme":
         if ($user)
            chgtheme();
         else
            Header("Location: index.php");
         break;
    case "savetheme":
         savetheme($uid, $theme);
         break;

    case "editcomm":
         if ($user)
            editcomm();
         else
            Header("Location: index.php");
         break;
    case "savecomm":
         savecomm($uid, $uname, $umode, $uorder, $thold, $noscore, $commentmax);
         break;

    case "editjournal":
         if ($user)
            editjournal();
         else
            Header("Location: index.php");
         break;
    case "savejournal":
         savejournal($uid, $journal, $datetime);
         break;

    case "forgetpassword":
         ForgetPassword();
         break;

    case "only_newuser":
         global $CloseRegUser;
         if ($CloseRegUser==0) {
            Only_NewUser();
         } else {
            include("header.php");
            include("static/closed.txt");
            include("footer.php");
         }
         break;

    default:
         if (!AutoReg()) { unset($user); }
         main($user);
         break;
}
?>