Tcmaker Posted February 18, 2010 Share Posted February 18, 2010 I was thinking to stop people putting stupid names on games as there name a mod where they have to request to change name then this has to be approved by an admin but once they have submitted there name once they cant do this again till it has been approved or declined Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted February 18, 2010 Share Posted February 18, 2010 UPDATE: The ability to notify the players friends (in their friendslist) has been added - suggested by cjholder. I've left it off by default, simply change $notifyFriends = 0; to $notifyFriends = 1; Simple stuff. Here you go :) [mysql]CREATE TABLE `username_requests` ( `req_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY, `req_time` INT( 11 ) NOT NULL DEFAULT 0, `req_user` INT( 11 ) NOT NULL DEFAULT 0, `req_name` VARCHAR( 255 ) NOT NULL DEFAULT 'n/a' ) ENGINE = MyISAM;[/mysql] Edit smenu.php Add this link: [url='staff_requests.php?action=view']View Username Requests[/url] For those of you bothered about a few milliseconds of speed, use the codes posted in the SECOND (2ND) expander [expander=Slightly slower method (by a few milliseconds)]Edit: preferences.php Replace the entire name_change() function with this: function name_change() { global $ir, $db, $userid, $h; echo "<h3>Changing your username</h3>"; $select = sprintf("SELECT req_id FROM username_requests WHERE (req_user = %u)", $userid); $query = $db->query($select); if($db->num_rows($query)) { echo "You have already requested a username change. Please wait until your current request is dealt with. [url='preferences.php']Back[/url]"; $h->endpage(); exit; } if(!isset($_POST['submit'])) { echo "<form action='preferences.php?action=namechange' method='post'>"; echo "<table class='table' width='50%' style='text-align:center;'>"; echo "<tr>"; echo "<th>New Name</th>"; echo sprintf("<td><input type='text' name='newName' value=\"%s\" /></td>", stripslashes(htmlspecialchars($ir['username']))); echo "</tr>"; echo "<tr>"; echo "<td colspan='2'><input type='submit' name='submit' value='Request Name Change' /></td>"; echo "</tr>"; echo "</table>"; echo "</form>"; } else { if(empty($_POST['newName']) OR trim($_POST['newName']) == '') { echo "You cannot request a blank name"; $h->endpage(); exit; } $_POST['newName'] = $db->escape($_POST['newName']); $insert = sprintf("INSERT INTO username_requests VALUES ('', %u, %u, '%s')", time(), $userid, $_POST['newName']); $db->query($insert); echo "You username request has been successfully submitted"; } } Create file: staff_requests.php <?php include(DIRNAME(__FILE__) . '/sglobals.php'); if($ir['user_level'] != 2) { echo "Access denied"; $h->endpage(); exit; } $notifyFriends = 0; $_GET['action'] = isset($_GET['action']) && is_string($_GET['action']) ? strtolower(trim($_GET['action'])) : false; switch($_GET['action']) { case 'view': viewRequests(); break; case 'accept': acceptRequest(); break; case 'decline': declineRequest(); break; default: echo "Action not specified"; break; } function viewRequests() { global $db; echo "<h3>Viewing Username Change Requests</h3>"; $select = $db->query( "SELECT r.*, u.username " . "FROM username_requests r " . "LEFT JOIN users u ON (r.req_user = u.userid) " . "ORDER BY r.req_time ASC"); echo "<table class='table' width='75%'>"; echo "<tr>"; echo "<th>User</th>"; echo "<th>Time</th>"; echo "<th>Request</th>"; echo "<th>Actions</th>"; echo "</tr>"; if(!$db->num_rows($select)) { echo "<tr>"; echo "<td colspan='3' style='text-align:center;'>There are currently no requests</td>"; echo "</tr>"; } else { while($row = $db->fetch_row($select)) { echo "<tr>"; echo sprintf("<td>[url='viewuser.php?u=%u']%s[/url] [%s]</a></td>", $row['req_user'], stripslashes(htmlspecialchars($row['username'])), number_format($row['userid'])); echo sprintf("<td>%s</td>", date('H:i:s d/m/y', $row['req_time'])); echo sprintf("<td>%s</td>", stripslashes(htmlspecialchars($row['req_name']))); echo sprintf("<td>[[url='staff_requests.php?action=accept&ID=%u']Accept[/url]] [[url='staff_requests.php?action=decline&ID=%u']Decline[/url]]</td>", $row['req_id'], $row['req_id']); echo "</tr>"; } echo "</table>"; stafflog_add("View the username change requests"); } } function acceptRequest() { global $db, $h, $notifyFriends; echo "<h3>Accepting a username change request</h3>"; $_GET['ID'] = abs(@intval($_GET['ID'])); if(!$_GET['ID']) { echo "No ID specified"; $h->endpage(); exit; } $select = sprintf("SELECT * FROM username_requests WHERE (req_id = %u)", $_GET['ID']); $query = $db->query($select); if(!$db->num_rows($query)) { echo "This request does not exist"; $h->endpage(); exit; } $row = $db->fetch_row($query); $oldName = $db->fetch_single($db->query(sprintf("SELECT username FROM users WHERE (userid = %u)", $row['req_user']))); $updateUser = sprintf("UPDATE users SET username = '%s' WHERE (userid = %u)", $row['req_name'], $row['req_user']); $deleteReq = sprintf("DELETE FROM username_requests WHERE (req_id = %u)", $row['req_id']); $db->query($updateUser); $db->query($deleteReq); event_add($row['req_user'], sprintf("Your username change request that was requested on %s has been accepted.", date('H:i:s, d/m/y', $row['req_time'])); if($notifyFriends) { $selectFriends = sprintf("SELECT fl_ADDED FROM friendslist WHERE (fl_ADDER = %u)", $row['req_user']); $queryFriends = $db->query($selectFriends); if($db->num_rows($queryFriends)) { while($friend = $db->fetch_row($queryFriends)) { event_add($friend['fl_ADDED'], sprintf("[url='viewuser.php?u=%u']%s[/url] [%s] has changed their name to “%s”", $row['req_user'], $oldName, number_format($row['req_user']), $row['req_name'])); } } } stafflog_add(sprintf("Accepted the username change request from %s - now known as %s", $oldName, $row['req_name'])); echo "You have accepted the request"; } function declineRequest() { global $db, $h; echo "<h3>Declining a username change request</h3>"; $_GET['ID'] = abs(@intval($_GET['ID'])); if(!$_GET['ID']) { echo "No ID specified"; $h->endpage(); exit; } $select = sprintf("SELECT * FROM username_requests WHERE (req_id = %u)", $_GET['ID']); $query = $db->query($select); if(!$db->num_rows($query)) { echo "This request does not exist"; $h->endpage(); exit; } $row = $db->fetch_row($query); $currentName = $db->fetch_single($db->query(sprintf("SELECT username FROM users WHERE (userid = %u)", $row['req_user']))); $deleteReq = sprintf("DELETE FROM username_requests WHERE (req_id = %u)", $row['req_id']); $db->query($deleteReq); event_add($row['req_user'], sprintf("Your username change request that was requested on %s has been declined.", date('H:i:s, d/m/y', $row['req_time'])); stafflog_add(sprintf("Declined the username change request from %s", $currentName); echo "You have declined the request"; } $h->endpage(); ?> [/expander] [expander=Slightly faster method]preferences.php edit function name_change() { global $ir, $db, $userid, $h; echo "<h3>Changing your username</h3>"; $query = $db->query("SELECT req_id FROM username_requests WHERE (req_user = ".$userid.")"); if($db->num_rows($query)) { echo "You have already requested a username change. Please wait until your current request is dealt with. [url='preferences.php']Back[/url]"; $h->endpage(); exit; } if(!isset($_POST['submit'])) { echo "<form action='preferences.php?action=namechange' method='post'> <table class='table' width='50%' style='text-align:center;'> <tr> <th>New Name</th> <td><input type='text' name='newName' value=\"".stripslashes(htmlspecialchars($ir['username']))."\" /></td> </tr> <tr> <td colspan='2'><input type='submit' name='submit' value='Request Name Change' /></td> </tr> </table> </form>"; } else { if(empty($_POST['newName']) OR trim($_POST['newName']) == '') { echo "You cannot request a blank name"; $h->endpage(); exit; } $db->query("INSERT INTO username_requests VALUES ('', ".time().", ".$userid.", '".$db->escape($_POST['newName'])."')"); echo "You username request has been successfully submitted"; } } staff_requests.php <?php include(DIRNAME(__FILE__) . '/sglobals.php'); if($ir['user_level'] != 2) { echo "Access denied"; $h->endpage(); exit; } $notifyFriends = 0; $_GET['action'] = isset($_GET['action']) && is_string($_GET['action']) ? strtolower(trim($_GET['action'])) : false; switch($_GET['action']) { case 'view': viewRequests(); break; case 'accept': acceptRequest(); break; case 'decline': declineRequest(); break; default: echo "Action not specified"; break; } function viewRequests() { global $db; echo "<h3>Viewing Username Change Requests</h3>"; $select = $db->query( "SELECT r.*, u.username " . "FROM username_requests r " . "LEFT JOIN users u ON (r.req_user = u.userid) " . "ORDER BY r.req_time ASC"); echo "<table class='table' width='75%'> <tr> <th>User</th> <th>Time</th> <th>Request</th> <th>Actions</th> </tr>"; if(!$db->num_rows($select)) { echo "<tr> <td colspan='3' style='text-align:center;'>There are currently no requests</td> </tr>"; } else { while($row = $db->fetch_row($select)) { echo "<tr> <td>[url='viewuser.php?u=".$row[']".stripslashes(htmlspecialchars($row['username']))."[/url] [".number_format($row['userid'])."]</a></td> <td>".date('H:i:s d/m/y', $row['req_time'])."</td> <td>".stripslashes(htmlspecialchars($row['req_name']))."</td> <td>[[url='staff_requests.php?action=accept&ID=".$row[']Accept[/url]] [[url='staff_requests.php?action=decline&ID=".$row[']Decline[/url]]</td> </tr>"; } echo "</table>"; stafflog_add("View the username change requests"); } } function acceptRequest() { global $db, $h, $notifyFriends; echo "<h3>Accepting a username change request</h3>"; $_GET['ID'] = abs(@intval($_GET['ID'])); if(!$_GET['ID']) { echo "No ID specified"; $h->endpage(); exit; } $query = $db->query("SELECT * FROM username_requests WHERE (req_id = ".$_GET['ID'].")"); if(!$db->num_rows($query)) { echo "This request does not exist"; $h->endpage(); exit; } $row = $db->fetch_row($query); $oldName = $db->fetch_single($db->query("SELECT username FROM users WHERE (userid = ".$row['req_user'].")")); $db->query("UPDATE users SET username = '".$row['req_name']."' WHERE (userid = ".$row['req_user'].")"); $db->query("DELETE FROM username_requests WHERE (req_id = ".$row['req_id'].")"); event_add($row['req_user'], "Your username change request that was requested on ".date('H:i:sd/m/y', $row['req_time'])." has been accepted."); if($notifyFriends) { $queryFriends = $db->query("SELECT fl_ADDED FROM friendslist WHERE (fl_ADDER = ".$row['req_user'].")"); if($db->num_rows($queryFriends)) { while($friend = $db->fetch_row($queryFriends)) { event_add($friend['fl_ADDED'], "[url='viewuser.php?u=".$row[']".$oldName."[/url] [".number_format($row['req_user'])."] has changed their name to “".$row['req_name']."”"); } } } stafflog_add("Accepted the username change request from ".$oldName." - now known as ".$row['req_name']); echo "You have accepted the request"; } function declineRequest() { global $db, $h; echo "<h3>Declining a username change request</h3>"; $_GET['ID'] = abs(@intval($_GET['ID'])); if(!$_GET['ID']) { echo "No ID specified"; $h->endpage(); exit; } $query = $db->query("SELECT * FROM username_requests WHERE (req_id = ".$_GET['ID'].")"); if(!$db->num_rows($query)) { echo "This request does not exist"; $h->endpage(); exit; } $row = $db->fetch_row($query); $currentName = $db->fetch_single($db->query("SELECT username FROM users WHERE (userid = ".$row['req_user'].")")); $db->query("DELETE FROM username_requests WHERE (req_id = ".$row['req_id'].")"); event_add($row['req_user'], "Your username change request that was requested on ".date('H:i:sd/m/y', $row['req_time'])." has been declined."); stafflog_add("Declined the username change request from ".$currentName); echo "You have declined the request"; } $h->endpage(); ?> [/expander] Code is tested, and works fine Quote Link to comment Share on other sites More sharing options...
Joshua Posted February 18, 2010 Share Posted February 18, 2010 omg i could kill you lmao I started on this 20 minutes ago, am finishing the staff function bit now lol Quote Link to comment Share on other sites More sharing options...
Jordan Palmer Posted February 18, 2010 Share Posted February 18, 2010 Good idea mate Nice work Magictallguy =] Quote Link to comment Share on other sites More sharing options...
Joshua Posted February 18, 2010 Share Posted February 18, 2010 Well I finished mine and I'm posting it anyways :P Quote Link to comment Share on other sites More sharing options...
Jordan Palmer Posted February 18, 2010 Share Posted February 18, 2010 What would be the point? It's already been done -_- Quote Link to comment Share on other sites More sharing options...
Joshua Posted February 18, 2010 Share Posted February 18, 2010 I coded it MTG's is a bit slower, and mine would be easier to convert for V1 users :) so why not :P Quote Link to comment Share on other sites More sharing options...
Jordan Palmer Posted February 18, 2010 Share Posted February 18, 2010 Well I finished mine and I'm posting it anyways :P I coded it MTG's is a bit slower, and mine would be easier to convert for V1 users :) so why not :P Magictallguy's is ''slower'' not much but yes, And that's also easy to convert if you have 5seconds to spare -_- But as I said, Good work Quote Link to comment Share on other sites More sharing options...
Tcmaker Posted February 18, 2010 Author Share Posted February 18, 2010 thank you so much guys Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted February 18, 2010 Share Posted February 18, 2010 If you're really so bothered about speed, I'm happy to "convert" my code out of sprintf() -.- Quote Link to comment Share on other sites More sharing options...
Joshua Posted February 18, 2010 Share Posted February 18, 2010 Why i already coded one myself :P I was about halfway through the last file staff file when you posted yours so i just finished mine and posted it lol :P Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted February 18, 2010 Share Posted February 18, 2010 Original post updated, you can now choose which one you want *mutters under his breath: annoying little {censored} so bothered a less than a millisecond of parsing speed* *angel icon* Quote Link to comment Share on other sites More sharing options...
Joshua Posted February 18, 2010 Share Posted February 18, 2010 LOL Mines still faster neener ^_^ I couldnt just stop making the one i was doing lol :P Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted February 18, 2010 Share Posted February 18, 2010 LOL Mines still faster neener ^_^ I couldnt just stop making the one i was doing lol :P Maybe so, but is it secure? Quote Link to comment Share on other sites More sharing options...
Equinox Posted February 18, 2010 Share Posted February 18, 2010 LOL Mines still faster neener ^_^ I couldnt just stop making the one i was doing lol :P Maybe so, but is it secure? A few milliseconds is better than nothing.... I'd rather have my page load a few milliseconds faster, than slower. Forgive me if I'm an "annoying little {censored}" for expressing my view Quote Link to comment Share on other sites More sharing options...
Joshua Posted February 18, 2010 Share Posted February 18, 2010 Look at it yourself and tell me, I think it is :-) Quote Link to comment Share on other sites More sharing options...
Djkanna Posted February 18, 2010 Share Posted February 18, 2010 Meh all I can say is I'd rather use Magictallguy's version ;) I don't give a damn about speed and neither really should you especially with a Mc Codes game..... Nice work MTG, nice work ImmortalThug. Quote Link to comment Share on other sites More sharing options...
Equinox Posted February 18, 2010 Share Posted February 18, 2010 Meh all I can say is I'd rather use Magictallguy's version ;) I don't give a damn about speed and neither really should you especially with a Mc Codes game..... Nice work MTG, nice work ImmortalThug. May just be an Mc Codes game, but you're just saying, just because it's Mc Codes and it's your game, you don't need to give a crap? Yes Mc Codes is crap, don't make it worse :S Quote Link to comment Share on other sites More sharing options...
CherryDarling Posted February 18, 2010 Share Posted February 18, 2010 Nice idea, I have added it but I get an error T_VARIABLE, expecting ',' or ';' in /home/77777/public_html/staff_requests.php on line 50 Which is : global $db$h; Any help would be good thanks Quote Link to comment Share on other sites More sharing options...
Analog Posted February 18, 2010 Share Posted February 18, 2010 Nice idea, I have added it but I get an error T_VARIABLE, expecting ',' or ';' in /home/77777/public_html/staff_requests.php on line 50 Which is : global $db$h; Any help would be good thanks Should be global $db, $h; Quote Link to comment Share on other sites More sharing options...
CherryDarling Posted February 18, 2010 Share Posted February 18, 2010 Hmm I get this when I go to view the name changes : QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.username FROM username_requests r LEFT JOIN users u ON (r.req_user = u.userid) ' at line 1 Query was SELECT r.*u.username FROM username_requests r LEFT JOIN users u ON (r.req_user = u.userid) ORDER BY r.req_time ASC Quote Link to comment Share on other sites More sharing options...
Joshua Posted February 19, 2010 Share Posted February 19, 2010 Use mine, posted in free mods, it's tested and works :p I'll look at ^ code in a bit and see what happenz Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted February 19, 2010 Share Posted February 19, 2010 i'd prefer to use MTG's he's a more experienced coder, a few milliseconds... who notices that (human eye wouldn't). People come to play a game not see how fast it is lol i've never even tested the speed of one my scripts personally seems abit sad. Quote Link to comment Share on other sites More sharing options...
Joshua Posted February 19, 2010 Share Posted February 19, 2010 users preferance, again I only posted mine because I was so far into it when mtg posted his and didnt want to stop ^_^ Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted February 19, 2010 Share Posted February 19, 2010 Sorry guys, code modified.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.