home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 March / PCWorld_2001-03_cd.bin / KOMUNIK / progweb / progweb.exe / phpnuke / html / user.php < prev    next >
PHP Script  |  2000-12-05  |  29KB  |  644 lines

  1. <?PHP
  2.  
  3. ######################################################################
  4. # PHP-NUKE: Web Portal System
  5. # ===========================
  6. #
  7. # Copyright (c) 2000 by Francisco Burzi (fburzi@ncc.org.ve)
  8. # http://phpnuke.org
  9. #
  10. # This modules is to manage all registered user's options
  11. #
  12. # This program is free software. You can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 2 of the License.
  15. ######################################################################
  16.  
  17. if(!isset($mainfile)) { include("mainfile.php"); }
  18.  
  19. function nav() {
  20.     global $uimages;
  21.     ?>
  22.     <center> 
  23.     <a href="user.php?op=edituser"><img src=<?php echo "$uimages"; ?>/edit.gif border=0></a>  
  24.     <a href="user.php?op=edithome"><img src=<?php echo "$uimages"; ?>/change.gif border=0></a>  
  25.     <a href="user.php?op=editcomm"><img src=<?php echo "$uimages"; ?>/conf_comments.gif border=0></a>  
  26.     <a href="user.php?op=chgtheme"><img src=<?php echo "$uimages"; ?>/theme.gif border=0></a>  
  27.     <a href="user.php?op=logout"><img src=<?php echo "$uimages"; ?>/exit.gif border=0></a><br><br>
  28.     </center>
  29. <?php
  30. }
  31.  
  32. function userCheck($uname, $email) {
  33.     global $stop;
  34.     if ((!$email) || ($email=="") || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$email))) $stop = "<center>".translate("ERROR: Invalid email")."</center><br>";
  35.     if (strrpos($uname,' ') > 0) $stop = "<center>".translate("ERROR: Email addresses do not contain spaces.")."</center>";
  36.     if ((!$uname) || ($uname=="") || (ereg("[^a-zA-Z0-9_-]",$uname))) $stop = "<center>".translate("ERROR: Invalid Nickname")."</center><br>";
  37.     if (strlen($uname) > 25) $stop = "<center>".translate("Nickname is too long. It must be less than 25 characters.")."</center>";
  38.     if (eregi("^((root)|(adm)|(linux)|(webmaster)|(admin)|(god)|(administrator)|(administrador)|(nobody)|(anonymous)|(anonimo)|(an≤nimo)|(operator))$",$uname)) $stop = "<center>".translate("ERROR: Name is reserved.")."";
  39.     if (strrpos($uname,' ') > 0) $stop = "<center>".translate("There cannot be any spaces in the Nickname.")."</center>";
  40.     if (mysql_num_rows(mysql_query("select uname from users where uname='$uname'")) > 0) $stop = "<center>".translate("ERROR: Nickname taken")."</center><br>";
  41.     if (mysql_num_rows(mysql_query("select email from users where email='$email'")) > 0) $stop = "<center>".translate("ERROR: Email address already registered")."</center><br>";
  42.     return($stop);
  43. }
  44.  
  45. function makePass() {
  46.     $makepass="";
  47.     $syllables="er,in,tia,wol,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,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";
  48.     $syllable_array=explode(",", $syllables);
  49.     srand((double)microtime()*1000000);
  50.     for ($count=1;$count<=4;$count++) {
  51.         if (rand()%10 == 1) {
  52.             $makepass .= sprintf("%0.0f",(rand()%50)+1);
  53.         } else {
  54.             $makepass .= sprintf("%s",$syllable_array[rand()%62]);
  55.         }
  56.     }
  57.     return($makepass);
  58. }
  59.  
  60. function confirmNewUser($uname, $email) {
  61.     global $stop, $EditedMessage;
  62.     include("header.php");
  63.     filter_text($uname);
  64.     $uname = $EditedMessage;
  65.     userCheck($uname, $email);
  66.     if (!$stop) {
  67.         echo "Username: $uname<br>"
  68.             ."Email: $email<br>"; ?>
  69.         <form action="user.php" method="post">
  70.         <input type="hidden" name="uname" value="<?PHP echo"$uname"; ?>">
  71.         <input type="hidden" name="email" value="<?PHP echo"$email"; ?>">
  72.         <br><br><input type=hidden name=op value=finish><input type="submit" value="<?php echo translate("Finish"); ?>"></form>
  73. <?PHP
  74.     } else {
  75.         echo "$stop";
  76.     }
  77.     include("footer.php");
  78. }
  79.  
  80. function finishNewUser($uname, $email) {
  81.     global $stop, $makepass, $EditedMessage, $system;
  82.     include("header.php");
  83.     userCheck($uname, $email);
  84.     if (!isset($stop)) {
  85.         $makepass=makepass();
  86.         
  87.         if(!$system) 
  88.             $cryptpass=crypt($makepass);
  89.         else    
  90.             $cryptpass=$makepass;
  91.  
  92.         $result = mysql_query("insert into users values (NULL,'','$uname','$email','','','$cryptpass',10,'',0,0,0,'',0,'','','$commentlimit', '0')");
  93.         if(!$result) {
  94.             echo mysql_errno(). ": ".mysql_error(). "<br>";
  95.         } else {
  96.             $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";
  97.             $subject="".translate("User Password for")." $uname";
  98.             $from="$adminmail";
  99.             if ($system == 1) {
  100.                 echo "".translate("Your password is: ")."<b>$makepass</b><br>";
  101.                 echo "<a href=\"user.php?op=login&uname=$uname&pass=$makepass\">Login</a> to change your info";
  102.             } else {
  103.                 mail($email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion());
  104.                 echo "".translate("You are now registered. You should receive your password at the email account you provided.")."";
  105.             }
  106.         }
  107.     } else {
  108.         echo "$stop";
  109.     }
  110.     include("footer.php");
  111. }
  112.  
  113. function userinfo($uname, $bypass=0) {
  114.     global $user, $cookie, $sitename;
  115.     $result = mysql_query("select femail, url, bio from users where uname='$uname'");
  116.     $userinfo = mysql_fetch_array($result);
  117.     if(!$bypass) cookiedecode($user);
  118.     include("header.php");
  119.     if(($uname == $cookie[1]) || ($bypass==1)) {
  120.         echo "<font size=4><center>$uname, ".translate("Welcome to")." $sitename!<br><br>";
  121.         echo "<font size=3>".translate("This is your personal page")."<hr size=1 noshade>";
  122.         nav();
  123.     }
  124.     if((mysql_num_rows($result)==1) && ($userinfo[url] || $userinfo[femail] || $userinfo[bio])) {
  125.         if ($userinfo[url]) { echo "".translate("My HomePage:")." <a href=\"$userinfo[url]\">$userinfo[url]</a><br>\n"; }
  126.         if ($userinfo[femail]) { echo "".translate("My E-Mail:")." <a href=\"mailto:$userinfo[femail]\">$userinfo[femail]</a><br>\n"; }
  127.         if ($userinfo[bio]) { echo "<br><b>".translate("Extra Info:")." </b><br>$userinfo[bio]<br>\n"; }
  128.     } else {
  129.         echo "<center>".translate("There is no available info for")." $uname</center>";
  130.     }
  131.     echo "<center><br><br>";
  132.     echo "<table cellpadding=1 cellspacing=0 border=0 bgcolor=000000 width=80%><tr><td>";
  133.     echo "<table cellpadding=8 cellspacing=0 border=0 bgcolor=FFFFFF width=100%><tr><td>";
  134.     echo "<b>".translate("Last 10 comments by")." $uname:</b><br>";
  135.     $result = mysql_query("select tid, sid, subject from comments where name='$uname' order by tid DESC limit 0,10");
  136.     while(list($tid, $sid, $subject) = mysql_fetch_row($result)) {
  137.         echo "<li><a href=article.php?thold=-1&mode=flat&order=0&sid=$sid#$tid>$subject</a><br>";
  138.     }
  139.     echo "</td></tr></table></td></tr></table>";
  140.     echo "<br><br>";
  141.     echo "<table cellpadding=1 cellspacing=0 border=0 bgcolor=000000 width=80%><tr><td>";
  142.     echo "<table cellpadding=8 cellspacing=0 border=0 bgcolor=FFFFFF width=100%><tr><td>";
  143.     echo "<b>".translate("Last 10 news submissions sent by")." $uname:</b><br>";
  144.     $result = mysql_query("select sid, title from stories where informant='$uname' order by sid DESC limit 0,10");
  145.     while(list($sid, $title) = mysql_fetch_row($result)) {
  146.         echo "<li><a href=article.php?sid=$sid>$title</a><br>";
  147.     }
  148.     echo "</td></tr></table></td></tr></table>";
  149.     include("footer.php");
  150. }
  151.  
  152. function main($user) {
  153.     global $stop;
  154.     if(!isset($user)) {
  155.         include("header.php");
  156.         ?>
  157.         <?PHP if ($stop) echo "<center><blink><marquee><h3>".translate("Incorrect Login!")."</h3></marquee></blink></center>"; ?>
  158.         <?php
  159.         if ($user) {
  160.         } else {
  161.         ?>
  162.         <table cellpadding=1 cellspacing=0 border=0 bgcolor=000000 width="100%"><tr><td>
  163.         <table cellpadding=8 cellspacing=0 border=0 bgcolor=FFFFFF width="100%">
  164.         <tr><td valign="top">
  165.         <form action="user.php" method="post">
  166.         <b><?php echo translate("User Login"); ?></b><br><br>
  167.         <?php echo translate("Nickname: "); ?><input class=textbox type="text" name="uname" size=26 maxlength=25><br>
  168.         <?php echo translate("Password: "); ?><input class=textbox type="password" name="pass" size=21 maxlength=20><br>
  169.         <input type=hidden name=op value="login">
  170.         <input type="submit" value="<?php echo translate("Login"); ?>">
  171.         </td</tr></table></td</tr></table></form>
  172.         <br>
  173.         <?php } ?>
  174.  
  175.         <table cellpadding=1 cellspacing=0 border=0 bgcolor=000000 width="100%"><tr><td>
  176.         <table cellpadding=8 cellspacing=0 border=0 bgcolor=FFFFFF width="100%">
  177.         <tr><td valign="top">
  178.         <form action="user.php" method="post">
  179.         <b><?php echo translate("New User:"); ?></b><br><br>
  180.         <?php echo translate("Nickname: "); ?><input class=textbox type="text" name="uname" size=26 maxlength=25><br>
  181.         <?php echo translate("E-Mail: "); ?><input class=textbox type="text" name="email" size=25 maxlength=60><br>
  182.         <input type=hidden name=op value="new user">
  183.         <input type="submit" value="<?php echo translate("New User"); ?>">
  184.         </form>
  185.         <font size=2><?php echo translate("(Password will be sent to the email address you enter.)"); ?><br><br>
  186.         <font size=2><?php echo translate("Notice: Account preferences are cookie based."); ?></font><br>
  187.         <?php echo translate("As a registered user you can:"); ?><br>
  188.         <li> <?php echo translate("Post comments with your name"); ?>
  189.         <li> <?php echo translate("Send news with your name"); ?>
  190.         <li> <?php echo translate("Have a personal box in the Home"); ?>
  191.         <li> <?php echo translate("Select how many news you want in the Home"); ?>
  192.         <li> <?php echo translate("Customize the comments"); ?>
  193.         <li> <?php echo translate("Select different themes"); ?>
  194.         <li> <?php echo translate("some other cool stuff..."); ?><br>
  195.         <?php echo translate("Register Now! It's Free!"); ?><br>
  196.         <?php echo translate("We don't sell/give to others your personal info."); ?>
  197.         </td</tr></table></td</tr></table>
  198.         <br><br>
  199.  
  200.         <table cellpadding=1 cellspacing=0 border=0 bgcolor=000000 width="100%"><tr><td>
  201.         <table cellpadding=8 cellspacing=0 border=0 bgcolor=FFFFFF width="100%">
  202.         <tr><td valign="top">
  203.         <b><?php echo translate("Lost your Password?"); ?></b><br><br>
  204.         <font size=2>
  205.         <?php echo translate("No problem. Just type your Nickname and click on send button."); ?><br>
  206.         <?php echo translate("Confirmation Info"); ?><br>
  207.         <form action="user.php" method="post">
  208.         <?php echo translate("Nickname: "); ?><input class=textbox type="text" name="uname" size=26 maxlength=25>  
  209.         <?php echo translate("Confirmation Code: "); ?><input class=textbox type="text" name="code" size=5 maxlength=6><br>
  210.         <input type=hidden name=op value=mailpasswd>
  211.         <input type="submit" value="<?php echo translate("Send Password"); ?>">
  212.         </td></tr></table></td></tr></table></form>
  213.  
  214.         <?PHP
  215.         include("footer.php");
  216.     } elseif(isset($user)) {
  217.         global $cookie;
  218.         cookiedecode($user);
  219.         userinfo($cookie[1]);
  220.     }
  221. }
  222.  
  223. function logout() {
  224.     setcookie("user");
  225.     include("header.php");
  226.     ?>
  227.     <?php echo "
  228.     <center><font size=4><br><br>
  229.     ".translate("You are now logged out")."
  230.     </center>"; ?>
  231.     <?PHP
  232.     include("footer.php");
  233. }
  234.  
  235. function mail_password($uname, $code) {
  236.     global $system, $aminmail, $nuke_url;
  237.     $result = mysql_query("select email, pass from users where (uname='$uname')");
  238.     if(!$result) {
  239.         echo "<center>".translate("Sorry, no corresponding user info was found")."</center>";
  240.     } else {
  241.         $host_name = getenv("REMOTE_ADDR");
  242.         list($email, $pass) = mysql_fetch_row($result);
  243.  
  244.         $areyou = substr($pass, 0, 5);
  245.         if ($areyou==$code) {
  246.         
  247.         $newpass=makepass();
  248.         $message = "".translate("The user account")." '$uname' ".translate("at")." $nuke_url ".translate("has this email associated with it.")."  ".translate("A web user from")." $host_name ".translate("has just requested that password be sent.")."\n\n".translate("Your New Password is:")." $newpass\n\n ".translate("You can change it after you login at")." $nuke_url/user.php\n\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.")."";
  249.         $subject="".translate("User Password for")." $uname";
  250.         mail($email, $subject, $message, "From: $adminmail\nX-Mailer: PHP/" . phpversion());
  251.  
  252.     // Next step: add the new password to the database
  253.     
  254.         if(!$system) {
  255.             $cryptpass=crypt($newpass);
  256.         } else {
  257.             $cryptpass=$newpass;
  258.         }
  259.         $query="update users set pass='$cryptpass' where uname='$uname'";
  260.         if(!mysql_query($query)) {
  261.             echo "mail_password: could not update user entry. Contact the Administrator";
  262.         }
  263.     
  264.         $titlebar = "User password sent";
  265.         include ("header.php");
  266.         echo "<center>".translate("Password for")." $uname ".translate("mailed.")."";
  267.         include ("footer.php");
  268.  
  269.     // If no Code, send it
  270.  
  271.         } else {
  272.  
  273.             $result = mysql_query("select email, pass from users where (uname='$uname')");
  274.         if(!$result) {
  275.             echo "<center>".translate("Sorry, no corresponding user info was found")."</center>";
  276.         } else {
  277.             $host_name = getenv("REMOTE_ADDR");
  278.             list($email, $pass) = mysql_fetch_row($result);
  279.             $areyou = substr($pass, 0, 5);
  280.  
  281.         $message = "".translate("The user account")." '$uname' ".translate("at")." $nuke_url ".translate("has this email associated with it.")." ".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.")."";
  282.         $subject="".translate("Confirmation Code for")." $uname";
  283.         mail($email, $subject, $message, "From: $adminmail\nX-Mailer: PHP/" . phpversion());
  284.  
  285.         include ("header.php");
  286.         echo "<center>".translate("Confirmation Code for")." $uname ".translate("mailed.")."";
  287.         include ("footer.php");
  288.             }        
  289.     }
  290.     }
  291. }
  292.  
  293. function docookie($setuid, $setuname, $setpass, $setstorynum, $setumode, $setuorder, $setthold, $setnoscore, $setublockon, $settheme, $setcommentmax) {
  294.     $info = base64_encode("$setuid:$setuname:$setpass:$setstorynum:$setumode:$setuorder:$setthold:$setnoscore:$setublockon:$settheme:$setcommentmax");
  295.     setcookie("user","$info",time()+15552000); // 6 mo is 15552000
  296. }
  297.  
  298. function login($uname, $pass) {
  299.     global $setinfo, $system, $nuke_url;
  300.     $result = mysql_query("select pass, uid, storynum, umode, uorder, thold, noscore, ublockon, theme, commentmax from users where uname='$uname'");
  301.     if(mysql_num_rows($result)==1) {
  302.         $setinfo = mysql_fetch_array($result);
  303.         
  304.         $dbpass=$setinfo[pass];
  305.         
  306.         if(!$system)
  307.              $pass=crypt($pass,substr($dbpass,0,2));
  308.  
  309.         if (strcmp($dbpass,$pass)) {
  310.                         Header("Location: $nuke_url/user.php?stop=1");
  311.                         return;
  312.                 }
  313.  
  314.  
  315.  
  316.         docookie($setinfo[uid], $uname, $pass, $setinfo[storynum], $setinfo[umode], $setinfo[uorder], $setinfo[thold], $setinfo[noscore], $setinfo[ublockon], $setinfo[theme], $setinfo[commentmax]);
  317.         Header("Location: user.php?op=userinfo&bypass=1&uname=$uname");
  318.     } else {
  319.         Header("Location: user.php?stop=1");
  320.     }
  321. }
  322.  
  323. function infoCheck($uid, $email, $url) {
  324.     global $stop;
  325.     if ((!$email) || ($email=="") || (!ereg("[@]",$email)) || (!ereg("[.]",$email)) || (strlen($email) < 7) || (ereg("[^a-zA-Z0-9@.]",$email))) { $stop = "Invalid email<br>"; }
  326.     if (($url) && ($url!="http://") && ((!ereg("[http://]",$url)) || (!ereg("[.]",$url)) || (strlen($url) < 12) || (ereg("[^a-zA-Z0-9~.:/]",$url)))) { $stop = "Invalid URL<br>"; }
  327.     list($test) = mysql_fetch_row(mysql_query("select email from users where (email='$email' and uid!=$uid)"));
  328.     if ("$test"=="$email") $stop = "<center>".translate("ERROR: Email address already registered")."</center><br>";
  329.     return($stop);
  330. }
  331.  
  332. function edituser() {
  333.     global $user, $userinfo;
  334.     include("header.php");
  335.     getusrinfo($user);
  336.     nav();
  337.     ?>
  338.     <table cellpadding=8 border=0><tr><td>
  339.     <form action="user.php" method="post">
  340.     <b><?php echo translate("Real Name"); ?></b> <?php echo translate("(optional)"); ?><br>
  341.     <input class=textbox type="text" name="name" value="<?PHP echo"$userinfo[name]"; ?>" size=30 maxlength=60><br>
  342.     <b><?php echo translate("Real Email"); ?></b> <?php echo translate("(required)"); ?><br>
  343.     <?php echo translate("(This Email will not be public but is required, will be used to send your password if you lost it)"); ?><br>
  344.     <input class=textbox type="text" name="email" value="<?PHP echo"$userinfo[email]"; ?>" size=30 maxlength=60><br>
  345.     <b><?php echo translate("Fake Email"); ?></b> <?php echo translate("(optional)"); ?><br>
  346.     <?php echo translate("(This Email will be public. Just type what you want, Spam proof)"); ?><br>
  347.     <input class=textbox type="text" name="femail" value="<?PHP echo"$userinfo[femail]"; ?>" size=30 maxlength=60><br>
  348.     <b><?php echo translate("Your HomePage"); ?></b> <?php echo translate("(optional)"); ?><br>
  349.     <input class=textbox type="text" name="url" value="<?PHP echo"$userinfo[url]"; ?>" size=30 maxlength=100><br>
  350.     <b><?php echo translate("Extra Info"); ?></b> <?php echo translate("(optional)"); ?><br>
  351.     <?php echo translate("(255 characters max. Type what others can know about yourself)"); ?><br>
  352.     <textarea class=textbox wrap=virtual cols=50 rows=5 name=bio><?PHP echo"$userinfo[bio]"; ?></TEXTAREA>
  353.     <br><br>
  354.     <b><?php echo translate("Password"); ?></b> <?php echo translate("(type a new password twice to change it)"); ?><br>
  355.     <input class=textbox type="password" name="pass" size=10 maxlength=20> <input class=textbox type="password" name="vpass" size=10 maxlength=20>
  356.     <br><br>
  357.     <input type="hidden" name="uname" value="<?PHP echo"$userinfo[uname]"; ?>">
  358.     <input type="hidden" name="uid" value="<?PHP echo"$userinfo[uid]"; ?>">
  359.     <input type="hidden" name="op" value="saveuser">
  360.     <input type="submit" value="<?php echo translate("Save Changes"); ?>">
  361.     </form></td></tr></table>
  362.     <?PHP
  363.     include("footer.php");
  364. }
  365.  
  366. function saveuser($uid, $name, $uname, $email, $femail, $url, $pass, $vpass, $bio) {
  367.     global $user, $cookie, $userinfo, $EditedMessage, $system, $minpass;
  368.     cookiedecode($user);
  369.     // Vulnerability fix thanks to DrBrain
  370.     $user_check=$cookie[1];
  371.     $result=mysql_query("select uid from users where uname='$user_check'");
  372.     $vuid=mysql_result($result,0,"uid");
  373.     if ($user AND ($cookie[1] == $uname) AND ($uid == $vuid)) {
  374.     if ((isset($pass)) && ("$pass" != "$vpass")) {
  375.         echo "<center>".translate("Both passwords are different. They need to be identical.")."</center>";
  376.     } elseif (($pass != "") && (strlen($pass) < $minpass)) {
  377.         echo "<center>".translate("Sorry, your password must be at least")." <b>$minpass</b> ".translate("characters long")."</center>";
  378.     } else {
  379.         if ($bio) { filter_text($bio); $bio = $EditedMessage; $bio = FixQuotes($bio); }
  380.         if ($pass != "") {
  381.             mysql_query("LOCK TABLES users WRITE");
  382.     
  383.             if(!$system)
  384.                 $pass=crypt($pass);
  385.             mysql_query("update users set name='$name', email='$email', femail='$femail', url='$url', pass='$pass', bio='$bio' where uid='$uid'");
  386.             $result = mysql_query("select uid, uname, pass, storynum, umode, uorder, thold, noscore, ublockon, theme from users where uname='$uname' and pass='$pass'");
  387.             if(mysql_num_rows($result)==1) {
  388.                 $userinfo = mysql_fetch_array($result);
  389.                 docookie($userinfo[uid],$userinfo[uname],$userinfo[pass],$userinfo[storynum],$userinfo[umode],$userinfo[uorder],$userinfo[thold],$userinfo[noscore],$userinfo[ublockon],$userinfo[theme],$userinfo[commentmax]);
  390.             } else {
  391.                 echo "<center>".translate("Something screwed up... don't you hate that?")."</center><br>";
  392.             }
  393.             mysql_query("UNLOCK TABLES");
  394.         } else {
  395.             mysql_query("update users set name='$name', email='$email', femail='$femail', url='$url', bio='$bio' where uid=$uid");
  396.         }
  397.         Header("Location: user.php?"); // question is wierd bugfix
  398.     }
  399.     } else {
  400.         Header("Location: user.php");
  401.     }
  402.  
  403. }
  404.  
  405. function edithome() {
  406.     global $user, $userinfo, $Default_Theme;
  407.     include ("header.php");
  408.     getusrinfo($user);
  409.     nav();
  410.     if($userinfo[theme]=="") $userinfo[theme] = "$Default_Theme";
  411.     ?>
  412.     <table cellpadding=8 border=0><tr><td>
  413.     <form action="user.php" method="post">
  414.     <b><?php echo translate("News number in the Home"); ?></b> (max: 127)<br>
  415.     <input class=textbox type="text" name="storynum" size=3 maxlength=3 value=<?PHP echo"$userinfo[storynum]"; ?>>
  416.     <br><br>
  417.     <B><?php echo translate("Activate Personal Menu"); ?></B> <INPUT type=checkbox name=ublockon <?PHP if ($userinfo[ublockon]==1) { echo "checked"; } ?>>
  418.     <br><?php echo translate("(Check this option and the following text will appear in the Home)"); ?>
  419.     <br><?php echo translate("(You can use HTML code to put links, for example)"); ?><br>
  420.     <textarea class=textbox cols=55 rows=5 name=ublock><?PHP echo"$userinfo[ublock]"; ?></textarea>
  421.     <br><br>
  422.     <input type="hidden" name="theme" value="<?PHP echo"$userinfo[theme]"; ?>">
  423.     <input type="hidden" name="uname" value="<?PHP echo"$userinfo[uname]"; ?>">
  424.     <input type="hidden" name="uid" value="<?PHP echo"$userinfo[uid]"; ?>">
  425.     <input type="hidden" name="op" value="savehome">
  426.     <input type="submit" value="<?php echo translate("Save Changes!"); ?>">
  427.     </form></td></tr></table>
  428.     <?PHP
  429.     include ("footer.php");
  430. }
  431.  
  432. function chgtheme() {
  433.     global $user, $userinfo;
  434.     include ("header.php");
  435.     getusrinfo($user);
  436.     nav();
  437.     ?>
  438.     <center>
  439.     <form action="user.php" method="post">
  440.     <b><?php echo translate("Select One Theme"); ?></b><br>
  441.     <select class=textbox name=theme>
  442.     <?php
  443.     include("themes/list.php");
  444.     $themelist = explode(" ", $themelist);
  445.     for ($i=0; $i < sizeof($themelist); $i++) {
  446.         if($themelist[$i]!="") {
  447.             echo "<option value=\"$themelist[$i]\" ";
  448.             if((($userinfo[theme]=="") && ($themelist[$i]=="$Default_Theme")) || ($userinfo[theme]==$themelist[$i])) echo "selected";
  449.             echo ">$themelist[$i]\n";
  450.         }
  451.     }
  452.     if($userinfo[theme]=="") $userinfo[theme] = "Default_Theme";
  453.     ?>
  454.     </select><br>
  455.     <?php echo "
  456.     ".translate("This option will change the look for the whole site.")."<br>
  457.     ".translate("The changes will be valid only to you.")."<br>
  458.     ".translate("Each user can view the site with different theme.")."<br>
  459.     "; ?>
  460.     <br>
  461.  
  462.     <input type="hidden" name="storynum" value="<?PHP echo"$userinfo[storynum]"; ?>">
  463.     <input type="hidden" name="ublockon" value="<?PHP echo"$userinfo[ublockon]"; ?>">
  464.     <input type="hidden" name="ublock" value="<?PHP echo"$userinfo[ublock]"; ?>">
  465.  
  466.     <input type="hidden" name="uname" value="<?PHP echo"$userinfo[uname]"; ?>">
  467.     <input type="hidden" name="uid" value="<?PHP echo"$userinfo[uid]"; ?>">
  468.     <input type="hidden" name="op" value="savetheme">
  469.     <input type="submit" value="<?php echo translate("Save Changes!"); ?>">
  470.     </form>
  471.     <?PHP
  472.     include ("footer.php");
  473. }
  474.  
  475.  
  476. function savehome($uid, $uname, $theme, $storynum, $ublockon, $ublock) {
  477.     global $user, $userinfo, $cookie;
  478.     cookiedecode($user);
  479.     $user_check=$cookie[1];
  480.     $result=mysql_query("select uid from users where uname='$user_check'");
  481.     $vuid=mysql_result($result,0,"uid");
  482.     if ($user AND ($cookie[1] == $uname) AND ($uid == $vuid)) {
  483.     if(isset($ublockon)) $ublockon=1; else $ublockon=0;    
  484.     $ublock = FixQuotes($ublock);
  485.     mysql_query("update users set storynum='$storynum', ublockon='$ublockon', ublock='$ublock' where uid=$uid");
  486.     getusrinfo($user);
  487.     docookie($userinfo[uid],$userinfo[uname],$userinfo[pass],$userinfo[storynum],$userinfo[umode],$userinfo[uorder],$userinfo[thold],$userinfo[noscore],$userinfo[ublockon],$userinfo[theme],$userinfo[commentmax]);
  488.     Header("Location: user.php?theme=$theme");
  489.     }
  490. }
  491.  
  492. function savetheme($uid, $theme) {
  493.     global $user, $userinfo, $cookie;
  494.     cookiedecode($user);
  495.     $user_check=$cookie[1];
  496.     $result=mysql_query("select uid, uname from users where uname='$user_check'");
  497.     list($ni, $uname) = mysql_fetch_row($result);
  498.     $vuid=mysql_result($result,0,"uid");
  499.     if ($user AND ($cookie[1] == $uname) AND ($uid == $vuid)) {
  500.     mysql_query("update users set theme='$theme' where uid=$uid");
  501.     getusrinfo($user);
  502.     docookie($userinfo[uid],$userinfo[uname],$userinfo[pass],$userinfo[storynum],$userinfo[umode],$userinfo[uorder],$userinfo[thold],$userinfo[noscore],$userinfo[ublockon],$userinfo[theme],$userinfo[commentmax]);
  503.     Header("Location: user.php?theme=$theme");
  504.     }
  505. }
  506.  
  507. function editcomm() {
  508.     global $user, $userinfo;
  509.     include ("header.php");
  510.     getusrinfo($user);
  511.     nav();
  512.     ?>
  513.     <table cellpadding=8 border=0><tr><td>
  514.     <form action="user.php" method="post">
  515.     <b><?php echo translate("Display Mode"); ?></b>
  516.     <select class=textbox name=umode>
  517.     <option value="nocomments" <?PHP if ($userinfo[umode] == 'nocomments') { echo "selected"; } ?>><?php echo translate("No Comments"); ?>
  518.     <option value="nested" <?PHP if ($userinfo[umode] == 'nested') { echo "selected"; } ?>><?php echo translate("Nested"); ?>
  519.     <option value="flat" <?PHP if ($userinfo[umode] == 'flat') { echo "selected"; } ?>><?php echo translate("Flat"); ?>
  520.     <option value="thread" <?PHP if (!isset($userinfo[umode]) || ($userinfo[umode]=="") || $userinfo[umode]=='thread') { echo "selected"; } ?>><?php echo translate("Thread"); ?>
  521.     </select>
  522.     <br><br>
  523.     <b><?php echo translate("Sort Order"); ?></b>
  524.     <select class=textbox name=uorder>
  525.     <option value="0" <?PHP if (!$userinfo[uorder]) { echo "selected"; } ?>><?php echo translate("Oldest First"); ?>
  526.     <option value="1" <?PHP if ($userinfo[uorder]==1) { echo "selected"; } ?>><?php echo translate("Newest First"); ?>
  527.     <option value="2" <?PHP if ($userinfo[uorder]==2) { echo "selected"; } ?>><?php echo translate("Highest Scores First"); ?>
  528.     </select>
  529.     <br><br>
  530.     <b><?php echo translate("Threshold"); ?></b>
  531.     <?php echo translate("Comments scored less than this setting will be ignored."); ?><br>
  532.     <select class=textbox name=thold>
  533.     <option value="-1" <?PHP if ($userinfo[thold]==-1) { echo "selected"; } ?>>-1: <?php echo translate("Uncut and Raw"); ?>
  534.     <option value="0" <?PHP if ($userinfo[thold]==0) { echo "selected"; } ?>>0: <?php echo translate("Almost Everything"); ?>
  535.     <option value="1" <?PHP if ($userinfo[thold]==1) { echo "selected"; } ?>>1: <?php echo translate("Filter Most Anon"); ?>
  536.     <option value="2" <?PHP if ($userinfo[thold]==2) { echo "selected"; } ?>>2: <?php echo translate("Score"); ?> +2
  537.     <option value="3" <?PHP if ($userinfo[thold]==3) { echo "selected"; } ?>>3: <?php echo translate("Score"); ?> +3
  538.     <option value="4" <?PHP if ($userinfo[thold]==4) { echo "selected"; } ?>>4: <?php echo translate("Score"); ?> +4
  539.     <option value="5" <?PHP if ($userinfo[thold]==5) { echo "selected"; } ?>>5: <?php echo translate("Score"); ?> +5
  540.     </select><br>
  541.     <?php echo translate("Anonymous posts start at 0, logged in posts start at 1. Moderators add and subtract points."); ?>
  542.     <br><br>
  543.     <INPUT type=checkbox name=noscore <?PHP if ($userinfo[noscore]==1) { echo "checked"; } ?>><B> <?php echo translate("Do Not Display Scores"); ?></B> <?php echo translate("(Hides score: They still apply, you just don't see them.)"); ?>
  544.     <br><br>
  545.     <b><?php echo translate("Max Comment Length"); ?></b> <?php echo translate("(Truncates long comments, and adds a Read More link. Set really big to disable)"); ?><br>
  546.     <input class=textbox type="text" name="commentmax" value="<?PHP echo $userinfo[commentmax] ?>" size=11 maxlength=11> bytes (1024 bytes = 1K)
  547.     <br><br>
  548.     <input type="hidden" name="uname" value="<?PHP echo"$userinfo[uname]"; ?>">
  549.     <input type="hidden" name="uid" value="<?PHP echo"$userinfo[uid]"; ?>">
  550.     <input type="hidden" name="op" value="savecomm">
  551.     <input type="submit" value="<?php echo translate("Save Changes"); ?>">
  552.     </form></td></tr></table>
  553.     <?PHP
  554.     include ("footer.php");
  555. }
  556.  
  557. function savecomm($uid, $uname, $umode, $uorder, $thold, $noscore, $commentmax) {
  558.     global $user, $userinfo, $cookie;
  559.     cookiedecode($user);
  560.     $user_check=$cookie[1];
  561.     $result=mysql_query("select uid from users where uname='$user_check'");
  562.     $vuid=mysql_result($result,0,"uid");
  563.     if ($user AND ($cookie[1] == $uname) AND ($uid == $vuid)) {
  564.     if(isset($noscore)) $noscore=1; else $noscore=0;
  565.     mysql_query("update users set umode='$umode', uorder='$uorder', thold='$thold', noscore='$noscore', commentmax='$commentmax' where uid=$uid");
  566.     getusrinfo($user);
  567.     docookie($userinfo[uid],$userinfo[uname],$userinfo[pass],$userinfo[storynum],$userinfo[umode],$userinfo[uorder],$userinfo[thold],$userinfo[noscore],$userinfo[ublockon],$userinfo[theme],$userinfo[commentmax]);
  568.     Header("Location: user.php?");
  569.     }
  570. }
  571.  
  572. switch($op) {
  573.  
  574.     case "logout":
  575.         logout();
  576.         break;
  577.  
  578.     case "lost_pass":
  579.         lost_pass();
  580.         break;
  581.  
  582.     case "new user":
  583.         confirmNewUser($uname, $email);
  584.         break;
  585.  
  586.     case "finish":
  587.         finishNewUser($uname, $email);
  588.         break;
  589.  
  590.     case "mailpasswd":
  591.         mail_password($uname, $code);
  592.         break;
  593.  
  594.     case "userinfo":
  595.         userinfo($uname, $bypass);
  596.         break;
  597.  
  598.     case "login":
  599.         login($uname, $pass);
  600.         break;
  601.  
  602.     case "dummy":
  603.     // this is needed to give the cookie a chance to digest
  604.         Header("Location: user.php");
  605.         break;
  606.  
  607.     case "edituser":
  608.         edituser();
  609.         break;
  610.  
  611.     case "saveuser":
  612.         saveuser($uid, $name, $uname, $email, $femail, $url, $pass, $vpass, $bio);
  613.         break;
  614.  
  615.     case "edithome":
  616.         edithome();
  617.         break;
  618.     
  619.     case "chgtheme":
  620.         chgtheme();
  621.         break;
  622.     
  623.     case "savehome":
  624.         savehome($uid, $uname, $theme, $storynum, $ublockon, $ublock);
  625.         break;
  626.  
  627.     case "savetheme":
  628.         savetheme($uid, $theme);
  629.         break;
  630.  
  631.  
  632.     case "editcomm":
  633.         editcomm();
  634.         break;
  635.  
  636.     case "savecomm":
  637.         savecomm($uid, $uname, $umode, $uorder, $thold, $noscore, $commentmax);
  638.         break;
  639.  
  640.     default:
  641.         main($user);
  642.         break;
  643. }
  644. ?>