<?PHP
/************************************************************************/
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* Based on PhpNuke 4.x source code                                     */
/*                                                                      */
/* NPDS Copyright (c) 2002-2008 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.       */
/************************************************************************/
if (!function_exists("Mysql_Connexion")) {
   include ("mainfile.php");
}

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 message_pass($ibid) {
    include("header.php");
    opentable();
    echo "<p align=\"center\">";
    echo $ibid;
    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\">";
    echo "[&nbsp;<a href=\"user.php?op=chgtheme\" class=\"heada\">".translate("Change Theme")."</a>&nbsp;]</td>";

    echo "<td class=\"titboxc\" align=\"center\">
          [&nbsp;<a href=\"user.php?op=logout\" class=\"rouge\">".translate("Logout")."</a>&nbsp;]";
    echo "</td></tr></table><div class=\"separ\"></div>";
}

function userCheck($uname, $email) {
    global $NPDS_Prefix;

    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 (sql_num_rows(sql_query("select uname from ".$NPDS_Prefix."users where uname='$uname'")) > 0) {
       $stop = "<p align=\"center\">".translate("ERROR: Nickname taken")."</p><br />";
    }
    if ($uname!="edituser") {
       if (sql_num_rows(sql_query("select email from ".$NPDS_Prefix."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, $memberpass;
    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();
       if (!$memberpass) {
          echo "<p align=\"center\"><span class=\"rouge\">".translate("(Password will be sent to the email address you enter.)")."</span></p><br />";
       }
       echo translate("Notice: Account preferences are cookie based.")."<br /><br />
          <b>".translate("As a registered user you can:")."</b>
          <ul><li>".translate("Post comments with your name")."</li>
          <li>".translate("Send news with your name")."</li>
          <li>".translate("Have a personal box in the Home")."</li>
          <li>".translate("Upload personnal avatar")."</li>
          <li>".translate("Select how many news you want in the Home")."</li>
          <li>".translate("Customize the comments")."</li>
          <li>".translate("Select different themes")."</li>
          <li>".translate("some other cool stuff...")."</li></ul>
          <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($user_from))."\">
          <input type=\"hidden\" name=\"user_occ\" value=\"".StripSlashes(removeHack($user_occ))."\">
          <input type=\"hidden\" name=\"user_intrest\" value=\"".StripSlashes(removeHack($user_intrest))."\">
          <input type=\"hidden\" name=\"user_sig\" value=\"".StripSlashes(removeHack($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($C1))."\">
          <input type=\"hidden\" name=\"C2\" value=\"".StripSlashes(removeHack($C2))."\">
          <input type=\"hidden\" name=\"C3\" value=\"".StripSlashes(removeHack($C3))."\">
          <input type=\"hidden\" name=\"C4\" value=\"".StripSlashes(removeHack($C4))."\">
          <input type=\"hidden\" name=\"C5\" value=\"".StripSlashes(removeHack($C5))."\">
          <input type=\"hidden\" name=\"C6\" value=\"".StripSlashes(removeHack($C6))."\">
          <input type=\"hidden\" name=\"C7\" value=\"".StripSlashes(removeHack($C7))."\">
          <input type=\"hidden\" name=\"C8\" value=\"".StripSlashes(removeHack($C8))."\">
          <input type=\"hidden\" name=\"M1\" value=\"".StripSlashes(removeHack($M1))."\">
          <input type=\"hidden\" name=\"M2\" value=\"".StripSlashes(removeHack($M2))."\">
          <input type=\"hidden\" name=\"T1\" value=\"".StripSlashes(removeHack($T1))."\">
          <input type=\"hidden\" name=\"T2\" value=\"".StripSlashes(removeHack($T2))."\">
          <input type=\"hidden\" name=\"B1\" value=\"".StripSlashes(removeHack($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=strip_tags($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 $NPDS_Prefix;
    global $makepass, $system, $adminmail, $sitename, $AutoRegUser, $memberpass, $gmt;
    $stop=userCheck($uname, $email);
    $user_regdate = time()+($gmt*3600);
    $stop=userCheck($uname, $email);
    if (!$stop) {
       include("header.php");
       if (!$memberpass) {
          $makepass=makepass();
       } else {
          $makepass=$pass;
       }
       if (!$system)
          $cryptpass=crypt($makepass,$makepass);
       else
          $cryptpass=$makepass;
       if ($url!="") {
           if (!substr_count($url,"http://")) {$url="http://".$url;}
           if (trim($url)=="http://") {$url="";}
       }
       $result = sql_query("insert into ".$NPDS_Prefix."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) = sql_fetch_row(sql_query("select uid from ".$NPDS_Prefix."users where uname='$uname'"));
       $result = sql_query("insert into ".$NPDS_Prefix."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 = sql_query("insert into ".$NPDS_Prefix."users_status values ('$usr_id','0','$attach','0','1','1','')");
       } else {
          $result = sql_query("insert into ".$NPDS_Prefix."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 ".$NPDS_Prefix."priv_msgs (msg_image, subject, from_userid, to_userid, msg_time, msg_text) ";
             $sql .= "VALUES ('', '$sujet', '$emetteur_id', '$usr_id', '$time', '$message')";
             sql_query($sql);
          }
          //------------------------------------------------
       }
       include("footer.php");
    } else {
       message_error($stop, "finish");
    }
}

function userinfo($uname, $bypass=0) {
    global $NPDS_Prefix;
    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 = sql_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 ".$NPDS_Prefix."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) = sql_fetch_row($result);
    if (!$uid) {
       header ("location: index.php");
    }
    if (!$bypass) {global $cookie;}
    include("header.php");
    include("functions.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 />";

    $file="";
    $handle=opendir('modules/comments');
    while ($file = readdir($handle)) {
       if (!eregi("(.conf.php)$",$file)) continue;
       include("modules/comments/$file");
       $filelist[$forum] = $url_ret;
    }
    closedir($handle);

    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=sql_query("select topic_id, forum_id, post_text, post_time from ".$NPDS_Prefix."posts where forum_id<0 and poster_id='$uid' order by post_time DESC limit 0,10");
    while(list($topic_id, $forum_id, $post_text, $post_time) = sql_fetch_row($result)) {
       $rowcolor = tablos();
       echo "<tr $rowcolor><td>".convertdate($post_time)." - <a href=\"".$filelist[$forum_id].$topic_id."\">".strip_tags($post_text)."</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 $NPDS_Prefix;
    global $user, $cookie;
    if ($cookie[1]!="") {
       sql_query("DELETE FROM ".$NPDS_Prefix."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, the new password you want and click on send button to recieve a email with the confirmation code.")."<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("Password: ")."</td><td><input class=\"textbox\" type=\"password\" name=\"code\" size=\"5\" maxlength=\"40\"><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")."\">";
    echo "</td></tr></table>\n";
    echo "</form>";
    closetable();
    include ("footer.php");
}
function mail_password($uname, $code) {
    global $NPDS_Prefix;
    global $sitename, $nuke_url;
    $uname=removeHack(stripslashes(htmlspecialchars(urldecode($uname), ENT_QUOTES)));
    $result = sql_query("select uname,email,pass from ".$NPDS_Prefix."users where uname='$uname'");
    $tmp_result=sql_fetch_row($result);
    if (!$tmp_result) {
       message_error(translate("Sorry, no corresponding user info was found")."<br /><br />","");
    } else {
       $host_name = getip();
       list($uname,$email, $pass) = $tmp_result;
       // On envoie une URL avec dans le contenu : username, email, le MD5 du passwd retenu et le timestamp
       $url="$nuke_url/user.php?op=validpasswd&code=".urlencode(encrypt($uname)."#fpwd#".encryptK($email."#fpwd#".$code."#fpwd#".time(),$pass));
       $url="<a href=\"".$url."\">".$url."</a>";

       $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 to change the password.")."\n\n".translate("Your Confirmation URL is:")." $url \n\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_pass(translate("Confirmation Code for")." $uname ".translate("mailed."));
       Ecr_Log("security", "Lost_password_request : ".$uname, "");
    }
}

function valid_password ($code) {
    global $NPDS_Prefix;

    $ibid=explode("#fpwd#",$code);
    $result = sql_query("select email,pass from ".$NPDS_Prefix."users where uname='".decrypt($ibid[0])."'");
    list($email, $pass) = sql_fetch_row($result);
    if ($email!="") {
       $ibid=explode("#fpwd#",decryptK($ibid[1],$pass));
       if ($email==$ibid[0]) {
          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("To valid your new password request, just re-type it.")."<br />";
          echo "<form action=\"user.php\" method=\"post\">";
          echo "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"2\" border=\"0\">";
          echo "<tr><td width=\"20%\">".translate("Password: ")."</td><td><input class=\"textbox\" type=\"password\" name=\"passwd\" size=\"5\"><br /></td></tr>";
          echo "<tr><td width=\"20%\">&nbsp;</td><td><input type=\"hidden\" name=\"op\" value=\"updatepasswd\">";
          echo "<input type=\"hidden\" name=\"code\" value=\"".$code."\">";
          echo "<input class=\"bouton_standard\" type=\"submit\" value=\"".translate("Submit")."\">";
          echo "</td></tr></table>\n";
          echo "</form>";
          closetable();
          include ("footer.php");
      } else {
          message_pass(translate("Error"));
          Ecr_Log("security", "Lost_password_valid NOK Mail not match : ".$ibid[0], "");
      }
   } else {
       message_pass(translate("Error"));
       Ecr_Log("security", "Lost_password_valid NOK Bad hash : ".$ibid[0], "");
   }
}

function update_password ($code, $passwd) {
    global $system;
    global $NPDS_Prefix;

    $ibid=explode("#fpwd#",$code);
    $uname=urlencode(decrypt($ibid[0]));
    $result = sql_query("select email,pass from ".$NPDS_Prefix."users where uname='$uname'");
    list($email, $pass) = sql_fetch_row($result);
    if ($email!="") {
       $ibid=explode("#fpwd#",decryptK($ibid[1],$pass));
       if ($email==$ibid[0]) {
          // Le lien doit avoir été généré dans les 24H00
          if ((time()-$ibid[2])<86400) {
             // le mot de passe est-il identique
             if ($ibid[1]==$passwd) {
                if (!$system) {
                   $cryptpass=crypt($ibid[1],$ibid[1]);
                } else {
                   $cryptpass=$ibid[1];
                }
                sql_query("update ".$NPDS_Prefix."users set pass='$cryptpass' where uname='$uname'");
                message_pass(translate ("Password update, please re-connect you."));
                Ecr_Log("security", "Lost_password_update OK : ".$uname, "");
             } else {
                message_pass(translate("Error"));
                Ecr_Log("security", "Lost_password_update Password not match : ".$uname, "");
             }
          } else {
             message_pass(translate("Error"));
             Ecr_Log("security", "Lost_password_update NOK Time > 24H00 : ".$uname, "");
          }
       } else {
          message_pass(translate("Error"));
          Ecr_Log("security", "Lost_password_update NOK Mail not match : ".$uname, "");
       }
    } else {
       message_pass(translate("Error"));
       Ecr_Log("security", "Lost_password_update NOK Empty Mail or bad user : ".$uname, "");
    }
}

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 $NPDS_Prefix;
    global $setinfo, $system;

    $result = sql_query("select pass, uid, uname, storynum, umode, uorder, thold, noscore, ublockon, theme, commentmax, user_langue from ".$NPDS_Prefix."users where uname='$uname'");
    if (sql_num_rows($result)==1) {
       $setinfo = sql_fetch_assoc($result);
       $result = sql_query("select open from users_status where uid='$setinfo[uid]'");
       list($open_user) = sql_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 = sql_query("SELECT * from ".$NPDS_Prefix."session WHERE host_addr='$ip' and guest='1'");
       if (sql_num_rows($result)==1) {
          sql_query("DELETE FROM ".$NPDS_Prefix."session WHERE host_addr='$ip' and guest='1'");
       }

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

function edituser() {
    global $NPDS_Prefix;
    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 = sql_query("SELECT C1, C2, C3, C4, C5, C6, C7, C8, M1, M2, T1, T2, B1 FROM ".$NPDS_Prefix."users_extend WHERE uid='$userinfo[uid]'");
    list($C1, $C2, $C3, $C4, $C5, $C6, $C7, $C8, $M1, $M2, $T1, $T2, $B1) = sql_fetch_row($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 $NPDS_Prefix;
    global $user, $userinfo, $system, $minpass;
    $cookie=cookiedecode($user);
    $check = $cookie[1];
    $result = sql_query("select uid, email from ".$NPDS_Prefix."users where uname='$check'");
    list($vuid, $vemail) = sql_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(strip_tags($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);
                 sql_query("update ".$NPDS_Prefix."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($user_occ)."', user_from='".removeHack($user_from)."', user_intrest='".removeHack($user_intrest)."', user_sig='".removeHack($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 = sql_query("select uid, uname, pass, storynum, umode, uorder, thold, noscore, ublockon, theme from ".$NPDS_Prefix."users where uname='$uname' and pass='$pass'");
                 if (sql_num_rows($result)==1) {
                    $userinfo = sql_fetch_assoc($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 {
                 sql_query("update ".$NPDS_Prefix."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($user_occ)."', user_from='".removeHack($user_from)."', user_intrest='".removeHack($user_intrest)."', user_sig='".removeHack($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'");
              }
              sql_query("update ".$NPDS_Prefix."users_status set attachsig='$t' where uid='$uid'");
              $result=sql_query("select uid from ".$NPDS_Prefix."users_extend where uid='$uid'");
              if (sql_num_rows($result)==1) {
                 sql_query("update ".$NPDS_Prefix."users_extend set C1='".removeHack($C1)."', C2='".removeHack($C2)."', C3='".removeHack($C3)."', C4='".removeHack($C4)."', C5='".removeHack($C5)."', C6='".removeHack($C6)."', C7='".removeHack($C7)."', C8='".removeHack($C8)."', M1='".removeHack($M1)."', M2='".removeHack($M2)."', T1='".removeHack($T1)."', T2='".removeHack($T2)."', B1='$B1' where uid='$uid'");
              } else {
                 $result = sql_query("insert into ".$NPDS_Prefix."users_extend values ('$uid','".removeHack($C1)."', '".removeHack($C2)."', '".removeHack($C3)."', '".removeHack($C4)."', '".removeHack($C5)."', '".removeHack($C6)."', '".removeHack($C7)."', '".removeHack($C8)."', '".removeHack($M1)."', '".removeHack($M2)."', '".removeHack($T1)."', '".removeHack($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\" 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 $NPDS_Prefix;
    global $user;
    $cookie=cookiedecode($user);
    $check = $cookie[1];
    $result = sql_query("select uid from ".$NPDS_Prefix."users where uname='$check'");
    list($vuid) = sql_fetch_row($result);
    if (($check == $uname) AND ($uid == $vuid)) {
        if(isset($ublockon)) $ublockon=1; else $ublockon=0;
        $ublock = FixQuotes($ublock);
        sql_query("update ".$NPDS_Prefix."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=\"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 $NPDS_Prefix;
    global $user;
    $cookie=cookiedecode($user);
    $check = $cookie[1];
    $result = sql_query("select uid from ".$NPDS_Prefix."users where uname='$check'");
    list($vuid) = sql_fetch_row($result);
    if ($uid == $vuid) {
        sql_query("update ".$NPDS_Prefix."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 editjournal(){
    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("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 $NPDS_Prefix;
    global $user;
    $cookie=cookiedecode($user);
    $check = $cookie[1];
    $result = sql_query("SELECT uid FROM ".$NPDS_Prefix."users WHERE uname='$check'");
    list($vuid) = sql_fetch_row($result);
    if ($uid == $vuid) {
       $journal = removeHack(stripslashes(FixQuotes($journal)));
       $upload=false;
       include("modules/upload/upload_f.php");
       if ($Xstring=prepa_upload("",$journal)) {$journal=$Xstring[0];$Xname=$Xstring[1];$upload=true;}
       if ($upload) {
          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));
            sql_query("update ".$NPDS_Prefix."users set user_journal='$journalentry' where uid='$uid'");
          } else {
            sql_query("update ".$NPDS_Prefix."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 "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 "forgetpassword":
         ForgetPassword();
         break;
    case "mailpasswd":
         if ($uname!="" and $code!="") {
            if (strlen($code)>=$minpass)
               mail_password($uname, $code);
            else
               ForgetPassword();
         } else {
            main($user);
         }
         break;
    case "validpasswd":
         if ($code!="") {
            valid_password($code);
         } else {
            main($user);
         }
         break;
    case "updatepasswd":
         if ($code!="" and $passwd!="") {
            update_password($code, $passwd);
         } 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;
         sql_query("DELETE FROM ".$NPDS_Prefix."session WHERE time < $past");
         $result = sql_query("SELECT time FROM ".$NPDS_Prefix."session WHERE username='$cookie[1]'");
         if (sql_num_rows($result)==1) {
            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 "editjournal":
         if ($user)
            editjournal();
         else
            Header("Location: index.php");
         break;
    case "savejournal":
         savejournal($uid, $journal, $datetime);
         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;
}
?>