Jump to content
MakeWebGames

New Edit User


peterisgb

Recommended Posts

What is it? Well its a Better edit user for mccodes v2.
This mod collects all fields from the users table and displays it out instead of having to add new fields each time you add something new to the users table. (which we know is a pain in the bum)
Also included is the users inventory so you can see and delete stuff. (yes this is in mccodes but for myself i added it for ease of use).

Save the page as whatever you want

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

Edited by peterisgb
  • Like 3
  • Thanks 1
Link to comment
Share on other sites

15 minutes ago, ags_cs4 said:

Oh amazing idea i wasa gonna work on GL acp user manager, Im gonna steal it dont mind me 😄 

nope, go for it. I got tired a couple years ago of adding new inputs into edit users so made this. Just feel time its given to the public 😄

Link to comment
Share on other sites

10 minutes ago, peterisgb said:

nope, go for it. I got tired a couple years ago of adding new inputs into edit users so made this. Just feel time its given to the public 😄

Amazing, Yeah it save so much codes and time finding inputs, Im gonna do something like this but using hooks on gl and chose what type input it is, Tho the select gonna be tricky

Link to comment
Share on other sites

2 hours ago, ags_cs4 said:

Amazing, Yeah it save so much codes and time finding inputs, Im gonna do something like this but using hooks on gl and chose what type input it is, Tho the select gonna be tricky

You could do something like this?
 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

Link to comment
Share on other sites

2 hours ago, peterisgb said:

You could do something like this?
 

$query = $db->query("SELECT * FROM users WHERE userid={$r['userid']}"); while ($row = $db->fetch_row()) { foreach ($row as $val => $value) { echo '<tr> <td>'.$val.'</td> <td>'.getFormField($val, $value).'</td> </tr>'; } } echo '<tr> <td colspan="2" class="min"><span class="black">USER STATS</span></td> </tr>'; $query = $db->query("SELECT * FROM userstats WHERE userid={$r['userid']}"); while ($row = $db->fetch_row()) { foreach ($row as $val => $value) { echo "<tr> <td>".$val."</td> <td>".getFormField($val, $value)."</td> </tr>"; } }

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

function getFormField($fieldName, $fieldValue) { // Define an array of fields that should be displayed as select dropdowns $selectFields = array('field1', 'field2', 'field3'); if (in_array($fieldName, $selectFields)) { // Display select dropdown return '<select name="'.$fieldName.'"> <option value="option1"'.($fieldValue == 'option1' ? ' selected' : '').'>Option 1</option> <option value="option2"'.($fieldValue == 'option2' ? ' selected' : '').'>Option 2</option> <option value="option3"'.($fieldValue == 'option3' ? ' selected' : '').'>Option 3</option> </select>'; } else { // Display text box return '<input type="text" name="'.$fieldName.'" value="'.$fieldValue.'" />'; } }

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

You can check GL inventory module "modules/installed/iventory/hooks/meta.php" for what i mean and why GL (Soon OpenPBBG) is amazing, I can take same concept 1nd make a new hook function to edit that field and i think if there is any predefined data i can grab them from DB 1nd call it a day, Tho i wont be doing it the same like you did by getting all columns of tables as i got 7 userStats tables but the idea i can add more user inputs its great @Dayo i will make that and send you the code you can ship it on the next major release as its a nice idea to have, Might impress more to upgrade their engine 

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Given the SHOW COLUMNS command returns a Type column too, you could add some basic input type guesstimates.
 

For example:

TinyInt, Int or BigInt - type="number" - If unsigned, add min="0"

Email fields = type="email"

When working on mobile, mainly, this would be beneficial because it'll throw up the correct keyboard for the input.

  • Like 1
Link to comment
Share on other sites

2 hours ago, SRB said:

Given the SHOW COLUMNS command returns a Type column too, you could add some basic input type guesstimates.
 

For example:

TinyInt, Int or BigInt - type="number" - If unsigned, add min="0"

Email fields = type="email"

When working on mobile, mainly, this would be beneficial because it'll throw up the correct keyboard for the input.

I like the idea, but its more hassle than its worth to do it. I use a PC and not a mobile and i only use this within my website. Plus i gunna refer back to my old rule. Its free and unless i'm being paid its not worth going full out on it 😄 Had this been paid mod i would be on it like a hawk as if you are paying for it you'd expect the best and support as i do with all my paid mods (1% of them are paid lol)
Thanks for the feedback.

Edit. I did post this up further in the post but with some basic skill you could use this part.
 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

Edited by peterisgb
Link to comment
Share on other sites

9 hours ago, Magictallguy said:

 

function renderEditUser(database $db, array $ir, headers $h, array $column_data, ?array $user_data = null): void { // Loop through the column data foreach ($column_data as $column => $data_type) { $type = in_array($data_type, ['tinyint', 'int', 'bigint', 'float', 'double', 'decimal']) ? 'number' : 'text'; ?> <div style="padding: 0.8em 0;"> <label for="<?php echo $column; ?>"><?php echo ucwords(str_replace('_', ' ', $column)); ?></label> <?php if ($data_type === 'text') { ?> <textarea name="<?php echo $column; ?>" id="<?php echo $column; ?>" class="form-control"><?php echo $user_data[$column]; ?></textarea> <?php } else { ?> <input type="<?php echo $type; ?>" name="<?php echo $column; ?>" id="<?php echo $column; ?>" value="<?php echo $user_data[$column]; ?>" class="form-control"> <?php } ?> </div> <?php } } function editUser(): void { global $db, $ir, $h; // These should really be passed in if ($ir['user_level'] != 2) { echo '403: Forbidden'; $h->endpage(); exit; } $user_id = $_GET['user'] ?? 0; // Get column data for both users and userstats tables // .. while omitting the stuff we don't need $unneeded = implode('\', \'', ['userid', 'userpass', 'pass_salt', 'lastrest_life', 'lastrest_other']); $get_user_cols = $db->query('SHOW COLUMNS FROM users WHERE Field NOT IN (\'' . $unneeded . '\')'); $get_stats_cols = $db->query('SHOW COLUMNS FROM userstats WHERE Field NOT IN (\'' . $unneeded . '\')'); // Loop column name => type into array $cols = [ 'users' => [], 'stats' => [], ]; while ($row = $db->fetch_row($get_user_cols)) { $cols['users'][$row['Field']] = strtolower(explode('(', $row['Type'])[0]); } while ($row = $db->fetch_row($get_stats_cols)) { $cols['stats'][$row['Field']] = strtolower(explode('(', $row['Type'])[0]); } // Get the relevant user data $user_data = null; if ($user_id > 0) { $get_user_data = $db->query( 'SELECT u.*, us.* FROM users AS u INNER JOIN userstats AS us ON u.userid = us.userid WHERE u.userid = '.$user_id, ); if (!$db->num_rows($get_user_data)) { echo 'Sod off.'; $h->endpage(); exit; } $user_data = $db->fetch_row($get_user_data); }?> <form action="/staff_users.php?action=edituser" method="post"> <h4>User</h4> <?php renderEditUser($db, $ir, $h, $cols['users'], $user_data); ?> <h4>Stats</h4> <?php renderEditUser($db, $ir, $h, $cols['stats'], $user_data); ?> <div style="padding: 1em 0;"> <button type="submit" name="submit" class="btn-submit"> <span class="fas fa-check"></span> Save Changes </button> </div> </form> <?php }

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

5 minutes o' fun 😄
 

5 minutes for you, I've heard and seen you type. You type like soooooo fast that my brain can't keep up with it. We ain't all as fast as you, i'm deffo not.

  • Haha 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...