Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length

News:

Have you purchased a mod and lost your copy? Just file a support ticket through your "My Mods" page.


This forum is now closed and has moved to a new location! Click here to find out why.

AuthorTopic: User Name Change, Per Request  (Read 909 times)

JoshuaDams

  • Active Member
  • **
  • Reputation Power: 129
  • JoshuaDams is working their way up.JoshuaDams is working their way up.JoshuaDams is working their way up.
  • Offline Offline
  • Posts: 240
    • MSN Messenger - immortalthug4ever@hotmail.com
    • View Profile
    • WWW
User Name Change, Per Request
« on: February 18, 2010, 07:58:39 AM »
Requested by TCmaker off mwg.

Edit by Cronus:
You didn't really explain what this does in detail, so I'm just adding this so everyone knows =)
This lets your users "request" to change their username to something else.
This is a great addition for smaller games to make sure usernames are appropriate.


SQLS
Code: [Select]
CREATE TABLE IF NOT EXISTS `namechange` (
  `ID` int(11) NOT NULL auto_increment,
  `oldname` varchar(255) NOT NULL,
  `newname` varchar(255) NOT NULL,
  `userid` int(11) NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

staff_namerequest.php

Code: [Select]
<?php
require_once("sglobals.php");

$staffornot mysql_query("SELECT `user_level` FROM `users` WHERE `userid`=".$_SESSION['userid'].""$c);
$staff mysql_fetch_array($staffornot);

if(
$staff['user_level'] < 2)
{
echo 
"Only staff can manage this function!<br /><a href='index.php'><strong>Back</strong></a>";
$h->endpage();
exit;
}

$_GET['action'] = isset($_GET['action']) && is_string($_GET['action']) ? strtolower(trim($_GET['action'])) : false;
 
$_GET['ID'] = isset($_GET['ID']) && is_numeric($_GET['ID']) ? abs(@intval($_GET['ID'])) : false;

switch(
$_GET['action'])
{
case 
"namelist":namelist();break;
case 
"accept":accept();break;
case 
"deny":deny();break;
default:
namelist();break;
}
function 
namelist()    {
global 
$c;

//We list the requests.

$request mysql_query("SELECT `ID`,`oldname`,`newname`,`userid` FROM `namechange` ORDER BY `userid` ASC"$c);
if(!
mysql_num_rows($request))
{
echo 
"There are no requests at this time";
exit;
}

else
{
echo 
"<table width=90% class=table><tr><th>Old Name</th><th>Requested Name</th><th>User ID</th><th>Accept/Deny</tr>";

while(
$ss mysql_fetch_array($request))
{
 echo 
"<tr><td>".stripslashes(htmlentities($ss['oldname']))."</td>
           <td>"
.stripslashes(htmlentities($ss['newname']))."</td>
           <td>"
.$ss['userid']."</td>
           <td><a href='staff_namerequest.php?action=accept&ID="
.$ss['ID']."'><font color=red>Accept</font></a>/<a href='staff_namerequest.php?action=deny&ID=".$ss['ID']."'><font color=green>Deny</font></a></td></tr>";
}
echo 
"</table>";
}
}
function 
accept()
{
global 
$h,$c;

if(!
$_GET['ID']) 

echo 
"You did not select an ID.<br /><a href='index.php'><strong>Back</strong></a>";
$h->endpage();
exit;
}

$change mysql_query("SELECT `ID`,`oldname`,`newname`,`userid` FROM `namechange` WHERE `ID`={$_GET['ID']}"$c);

if(!
mysql_num_rows($change))
{
echo 
"The selected request does not exist!";
$h->endpage();
exit;
}

$cc mysql_fetch_array($change);

mysql_query("UPDATE `users` SET `username`='".$cc['newname']."' WHERE `userid`=".$cc['userid'].""$c);
event_add($cc['userid'], "The requested Name change you sent in has been accepted!"$c);
stafflog_add("Changed ".stripslashes($cc['oldname'])." to ".stripslashes($cc['newname']).""$c);
mysql_query("DELETE FROM `namechange` WHERE `ID`=".$_GET['ID']."");
echo 
"Users name has been changed successfully!";

}

function 
deny()   {
global 
$h,$c,$ir;

if(!
$_GET['ID'])
{
echo 
"The ID selected does not exist";
$h->endpage();
exit;
}

$change mysql_query("SELECT `oldname`,`newname`,`userid` FROM `namechange` WHERE `ID`=".$_GET['ID'].""$c);

if(!
mysql_num_rows($change))
{
echo 
"The selected request does not exist!";
$h->endpage();
exit;
}
$cc mysql_fetch_array($change);

event_add($cc['userid'], "The Name change you requested was denied by ".$ir['username'].".  Please consult them for any questions."$c);
stafflog_add("Denied Name change from <strong>".$cc['oldname']."</strong>."$c);
mysql_query("DELETE FROM `namechange` WHERE `ID`=".$_GET['ID']."");
echo 
"Users name change has been denied! An event has been sent to them";
$h->endpage();
exit;
}
?>

In preferances.
Overwrite both of your name change functions with

Code: [Select]
function namechange()  {
 global $c,$db,$ir;
 if (isset($_POST['NewName']))
{
  $CheckLog = mysql_num_rows(mysql_query(sprintf("SELECT `userid`, `username` FROM `users` WHERE `login_name`='%s' AND `userid`!='%d'", $_POST['NewName'], $_SESSION['userid'], $c)));
  $CheckGame = mysql_num_rows(mysql_query(sprintf("SELECT `userid`, `username` FROM `users` WHERE `username`='%s' AND `userid`!='%d'", $_POST['NewName'], $_SESSION['userid'], $c)));
  if (trim($_POST['NewName']) == '') {
   echo 'Error! <br /> You Did Not Enter A New Name <br />';
  } else if ($CheckLog) {
   echo 'Error! <br /> This Name Is In Use <br />';
  } else if ($CheckGame) {
   echo 'Error! <br /> This Name Is In Use <br />';
  } else if (strlen($_POST['NewName']) < '4') {
   echo 'Error! <br /> This Name Is Too Short';
  } else if (strlen($_POST['NewName']) > '15') {
   echo 'Error!<br /> This Name Is Too Long';
  } else {
   $_POST['NewName'] = str_replace(array("<", ">", "'", ";"), array("", "", "", ""), $_POST['NewName']);

   $db->query("INSERT INTO `namechange` VALUES('','".$ir['username']."','".$_POST['NewName']."',".$ir['userid'].")");
      echo 'You Have Sent your name change request!';
  }
 } else {
  echo '<h3>Name Change</h3>
  Please note that you still use the same name to login, this procedure simply changes the name that is displayed.  Name changes will not be immediate.  You must wait for the staff to Review and accept/Deny.  If denied you will be informed as to why.
  <form act="preferences.php?act=namechange" method="post">
   New Name: <input type="text" name="NewName" /><br />
   <input type="submit" value="Change Name" />
  </form>';
 }
}

Remove your old cases involving name change from your switch up top

add this one

Code: [Select]
case 'namechange':namechange();break;




Yes I use mysql_query Its faster.



Enjoy for any who use >,<
« Last Edit: February 18, 2010, 08:36:02 AM by Cronus »
Logged

Jordan

  • Active Member
  • **
  • Reputation Power: 55
  • Jordan has no influence.
  • Offline Offline
  • Posts: 102
  • Website Developer for hire;
    • MSN Messenger - Pudda2008@hotmail.co.uk
    • View Profile
    • WWW
    • Email
Re: User Name Change, Per Request
« Reply #1 on: February 19, 2010, 03:04:19 PM »
Looking good.

Magictallguy did a version which is good too =]
Logged
Contact me
MakeWebGames.com

dmkmonkey

  • Basic Member
  • *
  • Reputation Power: 23
  • dmkmonkey has no influence.
  • Offline Offline
  • Posts: 11
    • View Profile
    • Email
Re: User Name Change, Per Request
« Reply #2 on: February 26, 2011, 05:24:54 PM »
I must say, i do give 100% support for this mod, one of the best free mods :) Very good to keep control on them usernames.
Logged

kanzaw

  • Basic Member
  • *
  • Reputation Power: 0
  • kanzaw has no influence.
  • Offline Offline
  • Posts: 1
    • View Profile
Re: User Name Change, Per Request
« Reply #3 on: April 18, 2011, 04:29:44 AM »
it's for v2 or v1 ??
Logged

Cronus

  • Administrator
  • Senior Member
  • *****
  • Reputation Power: 2901
  • Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!Cronus is awe-inspiring!
  • Offline Offline
  • Posts: 550
    • MSN Messenger - preston__08@hotmail.com
    • View Profile
    • WWW
Re: User Name Change, Per Request
« Reply #4 on: April 18, 2011, 05:46:17 AM »
it's for v2 or v1 ??
looks like v2 to me
Logged
My msn is preston__08@hotmail.com if anyone is interested, I am online frequently.

MonoD

  • Basic Member
  • *
  • Reputation Power: 23
  • MonoD has no influence.
  • Offline Offline
  • Posts: 34
    • MSN Messenger - Contact@Monodistrict.com
    • View Profile
    • WWW
    • Email
Re: User Name Change, Per Request
« Reply #5 on: July 06, 2011, 08:22:59 PM »
Very good idea to be honest, Well if you have a smallish game, However if you have many staff on a big game then will work great also! Well done.
Logged
 


This forum is now closed and has moved to a new location! Click here to find out why.