Jump to content
MakeWebGames

peterisgb

Members
  • Posts

    738
  • Joined

  • Last visited

  • Days Won

    41

Everything posted by peterisgb

  1. Ugh, I got the basics, But i fail at maintaining the base, Doing advanced stuff and surviving hehe, Always get killed.
  2. oh ok, i've been doing the oppsite, my last site the header was massive, I've split it up into sections on different pages. Header.php being only 140ish lines.
  3. As Adam said, Its a odd thing to do. But hey, I'm Down. This is Untested. <?php require_once('globals.php'); if (!isset($_GET['action'])) { $_GET['action'] = ''; } switch ($_GET['action']) { case 'iteminfo': iteminfo(); break; case 'itemsend': itemsend(); break; case 'itemsell': itemsell(); break; case 'imadd': imadd(); break; case 'itemuse': itemuse(); break; default: index(); break; } function itemuse(){ global $db, $ir, $c, $userid, $h; $_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs(intval($_GET['ID'])) : ''; if (!$_GET['ID']) { echo 'Invalid use of file'; } else { $i = $db->query( "SELECT `effect1`, `effect2`, `effect3`, `effect1_on`, `effect2_on`, `effect3_on`, `itmname`, `inv_itemid` FROM `inventory` AS `iv` INNER JOIN `items` AS `i` ON `iv`.`inv_itemid` = `i`.`itmid` WHERE `iv`.`inv_id` = {$_GET['ID']} AND `iv`.`inv_userid` = $userid"); if ($db->num_rows($i) == 0) { $db->free_result($i); echo 'Invalid item ID'; } else { $r = $db->fetch_row($i); $db->free_result($i); if (!$r['effect1_on'] && !$r['effect2_on'] && !$r['effect3_on']) { echo 'Sorry, this item cannot be used as it has no effect.'; die($h->endpage()); } for ($enum = 1; $enum <= 3; $enum++) { if ($r["effect{$enum}_on"]) { $einfo = unserialize($r["effect{$enum}"]); if ($einfo['inc_type'] == "percent") { if (in_array($einfo['stat'], array('energy', 'will', 'brave', 'hp'))) { $inc = round( $ir['max' . $einfo['stat']] / 100 * $einfo['inc_amount']); } else { $inc = round( $ir[$einfo['stat']] / 100 * $einfo['inc_amount']); } } else { $inc = $einfo['inc_amount']; } if ($einfo['dir'] == "pos") { if (in_array($einfo['stat'], array('energy', 'will', 'brave', 'hp'))) { $ir[$einfo['stat']] = min($ir[$einfo['stat']] + $inc, $ir['max' . $einfo['stat']]); } else { $ir[$einfo['stat']] += $inc; } } else { $ir[$einfo['stat']] = max($ir[$einfo['stat']] - $inc, 0); } $upd = $ir[$einfo['stat']]; if (in_array($einfo['stat'], array('strength', 'agility', 'guard', 'labour', 'IQ'))) { $db->query( "UPDATE `userstats` SET `{$einfo['stat']}` = '{$upd}' WHERE `userid` = {$userid}"); } else { $db->query( "UPDATE `users` SET `{$einfo['stat']}` = '{$upd}' WHERE `userid` = {$userid}"); } } } echo $r['itmname'] . ' used successfully!'; item_remove($userid, $r['inv_itemid'], 1); } } } function imadd() { global $db, $ir, $c, $userid, $h; $_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs(intval($_GET['ID'])) : ''; $_POST['price'] = (isset($_POST['price']) && is_numeric($_POST['price'])) ? abs(intval($_POST['price'])) : ''; $_POST['QTY'] = (isset($_POST['QTY']) && is_numeric($_POST['QTY'])) ? abs(intval($_POST['QTY'])) : ''; $_POST['currency'] = (isset($_POST['currency']) && in_array($_POST['currency'], array('money', 'crystals'))) ? $_POST['currency'] : 'money'; if ($_POST['price'] && $_POST['QTY'] && $_GET['ID']) { if (!isset($_POST['verf']) || !verify_csrf_code("imadd_{$_GET['ID']}", stripslashes($_POST['verf']))) { echo "Your request to add this item to the market has expired. Please try again.<br /> &gt; <a href='?action=imadd&ID={$_GET['ID']}'>Back</a>"; die($h->endpage()); } $q = $db->query( "SELECT `inv_qty`, `inv_itemid`, `inv_id`, `itmname` FROM `inventory` AS `iv` INNER JOIN `items` AS `i` ON `iv`.`inv_itemid` = `i`.`itmid` WHERE `inv_id` = {$_GET['ID']} AND `inv_userid` = $userid"); if ($db->num_rows($q) == 0) { $db->free_result($q); echo "Invalid Item ID"; } else { $r = $db->fetch_row($q); $db->free_result($q); if ($r['inv_qty'] < $_POST['QTY']) { echo 'You do not have enough of this item.'; $h->endpage(); exit; } $checkq = sprintf( 'SELECT `imID` FROM `itemmarket` WHERE `imITEM` = %u AND `imPRICE` = %u AND `imADDER` = %u AND `imCURRENCY` = "%s"', $r['inv_itemid'], $_POST['price'], $userid, $_POST['currency']); $checkq = $db->query($checkq); if ($db->num_rows($checkq) > 0) { $cqty = $db->fetch_row($checkq); $query = sprintf( 'UPDATE `itemmarket` SET imQTY = imQTY + %u WHERE imID = %u', $_POST['QTY'], $cqty['imID']); $db->query($query); } else { $db->query( "INSERT INTO `itemmarket` VALUES (NULL, '{$r['inv_itemid']}', {$userid}, {$_POST['price']}, '{$_POST['currency']}', {$_POST['QTY']})"); } $db->free_result($checkq); item_remove($userid, $r['inv_itemid'], $_POST['QTY']); $imadd_log = $db->escape( "{$ir['username']} added {$r['itmname']} " . "x{$_POST['QTY']} to the item market for " . "{$_POST['price']} {$_POST['currency']}"); $db->query( "INSERT INTO `imarketaddlogs` VALUES (NULL, {$r['inv_itemid']}, {$_POST['price']}, {$r['inv_id']}, $userid, " . time() . ", '{$imadd_log}')"); echo "Item added to market."; } } else { $q = $db->query( "SELECT COUNT(`inv_id`) FROM `inventory` WHERE `inv_id` = {$_GET['ID']} AND `inv_userid` = $userid"); if ($db->fetch_single($q) == 0) { echo 'Invalid Item ID'; } else { $imadd_csrf = request_csrf_code("imadd_{$_GET['ID']}"); echo " Adding an item to the item market...<br /> <form action='?action=imadd&ID={$_GET['ID']}' method='post'> <input type='hidden' name='verf' value='{$imadd_csrf}' /> Quantity: <input type='text' name='QTY' value=''><br /> Price: <input type='text' name='price' value='0' /><br /> <select name='currency' type='dropdown'> <option value='money'>Money</option> <option value='crystals'>Crystals</option> </select><br /> <input type='submit' value='Add' /> </form> "; } $db->free_result($q); } } function itemsell() { global $db, $ir, $c, $userid, $h; $_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs(intval($_GET['ID'])) : ''; $_POST['qty'] = (isset($_POST['qty']) && is_numeric($_POST['qty'])) ? abs(intval($_POST['qty'])) : ''; if (!empty($_POST['qty']) && !empty($_GET['ID'])) { $id = $db->query( "SELECT `inv_qty`, `itmsellprice`, `itmid`, `itmname` FROM `inventory` AS `iv` INNER JOIN `items` AS `it` ON `iv`.`inv_itemid` = `it`.`itmid` WHERE `iv`.`inv_id` = {$_GET['ID']} AND `iv`.`inv_userid` = {$userid} LIMIT 1"); if ($db->num_rows($id) == 0) { echo 'Invalid item ID'; } else { $r = $db->fetch_row($id); if (!isset($_POST['verf']) || !verify_csrf_code("sellitem_{$_GET['ID']}", stripslashes($_POST['verf']))) { echo '<h3>Error</h3><hr /> This transaction has been blocked for your security.<br /> Please sell items quickly after you open the form - do not leave it open in tabs.<br /> &gt; <a href="itemsell.php?ID=' . $_GET['ID'] . '">Try Again</a>'; die($h->endpage()); } if ($_POST['qty'] > $r['inv_qty']) { echo 'You are trying to sell more than you have!'; } else { $price = $r['itmsellprice'] * $_POST['qty']; item_remove($userid, $r['itmid'], $_POST['qty']); $db->query( "UPDATE `users` SET `money` = `money` + {$price} WHERE `userid` = $userid"); $priceh = money_formatter($price); echo 'You sold ' . $_POST['qty'] . ' ' . $r['itmname'] . '(s) for ' . $priceh; $is_log = $db->escape( "{$ir['username']} sold {$_POST['qty']} {$r['itmname']}(s) for {$priceh}"); $db->query( "INSERT INTO `itemselllogs` VALUES (NULL, $userid, {$r['itmid']}, $price, {$_POST['qty']}, " . time() . ", '{$is_log}')"); } } $db->free_result($id); } else if (!empty($_GET['ID']) && empty($_POST['qty'])) { $id = $db->query( "SELECT `inv_qty`, `itmname` FROM `inventory` AS `iv` INNER JOIN `items` AS `it` ON `iv`.`inv_itemid` = `it`.`itmid` WHERE `iv`.`inv_id` = {$_GET['ID']} AND `iv`.`inv_userid` = {$userid} LIMIT 1"); if ($db->num_rows($id) == 0) { echo 'Invalid item ID'; } else { $r = $db->fetch_row($id); $code = request_csrf_code("sellitem_{$_GET['ID']}"); echo " <b>Enter how many {$r['itmname']} you want to sell. You have {$r['inv_qty']} to sell.</b> <br /> <form action='?action=itemsell&ID={$_GET['ID']}' method='post'> <input type='hidden' name='verf' value='{$code}' /> Quantity: <input type='text' name='qty' value='' /> <br /> <input type='submit' value='Sell Items (no prompt so be sure!' /> </form> "; } $db->free_result($id); } else { echo 'Invalid use of file.'; } } function itemsend() { global $db, $ir, $c, $userid, $h; $_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs(intval($_GET['ID'])) : ''; $_POST['user'] = (isset($_POST['user']) && is_numeric($_POST['user'])) ? abs(intval($_POST['user'])) : ''; $_POST['qty'] = (isset($_POST['qty']) && is_numeric($_POST['qty'])) ? abs(intval($_POST['qty'])) : ''; if (!empty($_POST['qty']) && !empty($_POST['user'])) { $id = $db->query( "SELECT `inv_qty`, `inv_itemid`, `itmname`, `itmid` FROM `inventory` AS `iv` INNER JOIN `items` AS `it` ON `iv`.`inv_itemid` = `it`.`itmid` WHERE `iv`.`inv_id` = {$_GET['ID']} AND iv.`inv_userid` = {$userid} LIMIT 1"); if ($db->num_rows($id) == 0) { echo 'Invalid item ID'; } else { $r = $db->fetch_row($id); $m = $db->query( "SELECT `lastip`,`username` FROM `users` WHERE `userid` = {$_POST['user']} LIMIT 1"); if (!isset($_POST['verf']) || !verify_csrf_code("senditem_{$_GET['ID']}", stripslashes($_POST['verf']))) { echo '<h3>Error</h3><hr /> This transaction has been blocked for your security.<br /> Please send items quickly after you open the form - do not leave it open in tabs.<br /> &gt; <a href="?action=itemsend&ID=' . $_GET['ID'] . '">Try Again</a>'; die($h->endpage()); } else if ($_POST['qty'] > $r['inv_qty']) { echo 'You are trying to send more than you have!'; } else if ($db->num_rows($m) == 0) { echo 'You are trying to send to an invalid user!'; } else { $rm = $db->fetch_row($m); item_remove($userid, $r['inv_itemid'], $_POST['qty']); item_add($_POST['user'], $r['inv_itemid'], $_POST['qty']); echo 'You sent ' . $_POST['qty'] . ' ' . $r['itmname'] . '(s) to ' . $rm['username']; event_add($_POST['user'], "You received {$_POST['qty']} {$r['itmname']}(s) from <a href='viewuser.php?u=$userid'>{$ir['username']}</a>", $c); $db->query( "INSERT INTO `itemxferlogs` VALUES(NULL, $userid, {$_POST['user']}, {$r['itmid']}, {$_POST['qty']}, " . time() . ", '{$ir['lastip']}', '{$rm['lastip']}')"); } $db->free_result($m); } $db->free_result($id); } else if (!empty($_GET['ID'])) { $id = $db->query( "SELECT `inv_qty`, `itmname` FROM `inventory` iv INNER JOIN `items` AS `it` ON `iv`.`inv_itemid` = `it`.`itmid` WHERE `iv`.`inv_id` = {$_GET['ID']} AND `iv`.`inv_userid` = $userid LIMIT 1"); if ($db->num_rows($id) == 0) { echo 'Invalid item ID'; } else { $r = $db->fetch_row($id); $code = request_csrf_code("senditem_{$_GET['ID']}"); echo " <b>Enter who you want to send {$r['itmname']} to and how many you want to send. You have {$r['inv_qty']} to send.</b> <br /> <form action='?action=itemsend&ID={$_GET['ID']}' method='post'> User ID: <input type='text' name='user' value='' /> <br /> Quantity: <input type='text' name='qty' value='' /> <br /> <input type='hidden' name='verf' value='{$code}' /> <input type='submit' value='Send Items (no prompt so be sure!' /> </form> "; } $db->free_result($id); } else { echo 'Invalid use of file.'; } } function iteminfo() { global $db, $ir, $c, $userid, $h; $_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs(intval($_GET['ID'])) : ''; $itmid = $_GET['ID']; if (!$itmid) { echo 'Invalid item ID'; } else { $q = $db->query( "SELECT `itmname`, `itmdesc`, `itmbuyprice`, `itmsellprice`, `itmtypename` FROM `items` AS `i` INNER JOIN `itemtypes` AS `it` ON `i`.`itmtype` = `it`.`itmtypeid` WHERE `i`.`itmid` = {$itmid} LIMIT 1"); if ($db->num_rows($q) == 0) { echo 'Invalid item ID'; } else { $id = $db->fetch_row($q); echo " <table width=75% class='table' cellspacing='1'> <tr style='background: gray;'> <th colspan=2><b>Looking up info on {$id['itmname']}</b></th> </tr> <tr style='background: #dfdfdf;'> <td colspan=2>The <b>{$id['itmname']}</b> is a/an {$id['itmtypename']} Item - <b>{$id['itmdesc']}</b></th> </tr> <tr style='background: gray;'> <th colspan=2>Item Info</th> </tr> <tr style='background:gray'> <th>Item Buy Price</th> <th>Item Sell Price</th> </tr> <tr> <td> "; if ($id['itmbuyprice']) { echo money_formatter($id['itmbuyprice']); } else { echo 'N/A'; } echo ' </td> <td> '; if ($id['itmsellprice']) { echo money_formatter($id['itmsellprice']) . ' </td> </tr> </table> '; } else { echo ' N/A</td> </tr> </table> '; } } $db->free_result($q); } } function index() { global $db, $ir, $c, $userid, $h; $q = $db->query( "SELECT `itmid`, `itmname` FROM `items` WHERE `itmid` IN({$ir['equip_primary']}, {$ir['equip_secondary']}, {$ir['equip_armor']})"); echo "<h3>Equipped Items</h3><hr />"; $equip = array(); while ($r = $db->fetch_row($q)) { $equip[$r['itmid']] = $r; } $db->free_result($q); echo "<table width='75%' cellspacing='1' class='table'> <tr> <th>Primary Weapon</th> <td>"; if (isset($equip[$ir['equip_primary']])) { print $equip[$ir['equip_primary']]['itmname'] . "</td><td><a href='unequip.php?type=equip_primary'>Unequip Item</a></td>"; } else { echo "None equipped.</td><td>&nbsp;</td>"; } echo "</tr> <tr> <th>Secondary Weapon</th> <td>"; if (isset($equip[$ir['equip_secondary']])) { print $equip[$ir['equip_secondary']]['itmname'] . "</td><td><a href='unequip.php?type=equip_secondary'>Unequip Item</a></td>"; } else { echo "None equipped.</td><td>&nbsp;</td>"; } echo "</tr> <tr> <th>Armor</th> <td>"; if (isset($equip[$ir['equip_armor']])) { print $equip[$ir['equip_armor']]['itmname'] . "</td><td><a href='unequip.php?type=equip_armor'>Unequip Item</a></td>"; } else { echo "None equipped.</td><td>&nbsp;</td>"; } echo "</tr> </table><hr /> <h3>Inventory</h3><hr />"; $inv = $db->query( "SELECT `inv_qty`, `itmsellprice`, `itmid`, `inv_id`, `effect1_on`, `effect2_on`, `effect3_on`, `itmname`, `weapon`, `armor`, `itmtypename` FROM `inventory` AS `iv` INNER JOIN `items` AS `i` ON `iv`.`inv_itemid` = `i`.`itmid` INNER JOIN `itemtypes` AS `it` ON `i`.`itmtype` = `it`.`itmtypeid` WHERE `iv`.`inv_userid` = {$userid} ORDER BY `i`.`itmtype` ASC, `i`.`itmname` ASC"); if ($db->num_rows($inv) == 0) { echo "<b>You have no items!</b>"; } else { echo "<b>Your items are listed below.</b><br /> <table width=100% class=\"table\" border=\"0\" cellspacing=\"1\"> <tr> <td class=\"h\">Item</td> <td class=\"h\">Sell Value</td> <td class=\"h\">Total Sell Value</td> <td class=\"h\">Links</td> </tr>"; $lt = ""; while ($i = $db->fetch_row($inv)) { if ($lt != $i['itmtypename']) { $lt = $i['itmtypename']; echo "\n<tr> <td colspan='4'> <b>{$lt}</b> </td> </tr>"; } if ($i['weapon']) { $i['itmname'] = "<span style='color: red;'>*</span>" . $i['itmname']; } if ($i['armor']) { $i['itmname'] = "<span style='color: green;'>*</span>" . $i['itmname']; } echo "<tr> <td>{$i['itmname']}"; if ($i['inv_qty'] > 1) { echo "&nbsp;x{$i['inv_qty']}"; } echo "</td> <td>" . money_formatter($i['itmsellprice']) . "</td> <td>"; echo money_formatter($i['itmsellprice'] * $i['inv_qty']); echo "</td> <td> [<a href='?action=iteminfo&ID={$i['itmid']}'>Info</a>] [<a href='?action=itemsend&ID={$i['inv_id']}'>Send</a>] [<a href='?action=itemsell&ID={$i['inv_id']}'>Sell</a>] [<a href='?action=imadd.php&ID={$i['inv_id']}'>Add To Market</a>]"; if ($i['effect1_on'] || $i['effect2_on'] || $i['effect3_on']) { echo " [<a href='?action=itemuse&ID={$i['inv_id']}'>Use</a>]"; } if ($i['weapon'] > 0) { echo " [<a href='equip_weapon.php?ID={$i['inv_id']}'>Equip as Weapon</a>]"; } if ($i['armor'] > 0) { echo " [<a href='equip_armor.php?ID={$i['inv_id']}'>Equip as Armor</a>]"; } echo "</td> </tr>"; } echo "</table>"; $db->free_result($inv); echo "<small><b>NB:</b> Items with a small red </small><span style='color: red;'>*</span><small> next to their name can be used as weapons in combat.<br /> Items with a small green </small><span style='color: green;'>*</span><small> next to their name can be used as armor in combat.</small>"; } } $h->endpage(); As Said, Untested, Using Default Mccodes from V2.0.6
  4. Haha, I don't mind the money but isn't my main goal, Player Activeness and people Playing and enjoying it it number 1, money eh, like it helps but keeping people playing means more.
  5. Nope, If you got a domain, Follow these steps in the picture and make sure you point the DNS to the right location.
  6. I am trying to be different, tho, do be light on the critism as the site is after all only 27 days old now. But critism and feedback is very welcome. I will deffo look at the register system, just hasnt been high on my list being it works currently 😄
  7. Some of the updates i've been working on. Picture 1: Stock Market, I use this too determine the Sell Price of Crystals in the game, It goes up and down, Also this page allows the buying and selling of share of crystals. Picture 2: Workshop, This is the workshop mod that was posted on this forum a while back but i've messed around with the looks to make it look better. Green is good, Red is Bad. Picture 3: This is just the explore page. But it gives the overall of how the template layout is currently looking like.
  8. Mccodes doesn't typically use mysql_real but $db->escape();
  9. Out of curiosity, how hard is it to update mccodes v2 to work in PHP 8?
  10. Thanks, The website is a box standard look from my old game, Its simple, easy to maintain and nice simple way to track my mods 😄 My mods output is slow at the moment as i'm working on v3 of infamous wars (started 1st August)
  11. 2023 Update. We are still here, But we have a new template, Tad Harder now. Heres the new screenshots Different colours your ask, No it doesn't change on reload, that'd be annoying, Its just a theme changer for the users so i though might aswell show that off aswell. Unlike infamous (2018-2023) This is mobile friendly for the most part. Link is the same, you can find it above or in my signature.
  12. After Checking, This has now been resolved.
  13. Lol, ticket open, We did this last year when it was incorrectly flagged 😄
  14. My main site is now showing account suspended.......
  15. I run 2 sites, my main is good, but my other has been deemed the same. Bloody Google controlling the internet telling lies, grrr. I think all name.makeweb.games is being effected by this currently.
  16. peterisgb

    Hi

    His website claims that what he has is a game engine. Should mention that the game engine isn't his.
  17. Oh. Over the last 15 years, I've watched people come and go. Uridium/Illusions joining just a month before i did hehe. I'll be here lurking around till the server goes offline (again)
  18. As to help guide, i have this which i made quite a while ago.
  19. Well i went for just me for safety, and there isn't any benifit to the user as of yet (if there ever will be i dunno), As to like Torn, I've never played it or been on it so i couldn't say.
  20. Simple Library to Add, Read, Edit and delete books. create php file library.php <?php include "globals.php"; $version = '0.1.0'; $bookcount = $db->fetch_single($db->query('SELECT COUNT(*) FROM library')); if (!isset($_GET['a'])) { $_GET['a'] = ''; } switch ($_GET['a']) { case 'read': read(); break; case 'createbook': createBook(); break; case 'editbook': editBook(); break; case 'deletebook': deleteBook(); break; default: home(); break; } function bbcode_format($text) { // Convert [b]...[/b] tags to <strong>...</strong> $text = preg_replace('/\[b\](.*?)\[\/b\]/s', '<strong>$1</strong>', $text); // Convert [i]...[/i] tags to <em>...</em> $text = preg_replace('/\[i\](.*?)\[\/i\]/s', '<em>$1</em>', $text); // Convert [u]...[/u] tags to <u>...</u> $text = preg_replace('/\[u\](.*?)\[\/u\]/s', '<u>$1</u>', $text); // Convert [url=URL]text[/url] tags to <a href="URL">text</a> $text = preg_replace('/\[url=(.*?)\](.*?)\[\/url\]/s', '<a href="$1">$2</a>', $text); // Convert [img]URL[/img] tags to <img src="URL" alt="" /> $text = preg_replace('/\[img\](.*?)\[\/img\]/s', '<img src="$1" alt="" />', $text); // Convert [color=COLOR]...[/color] tags to <span style="color:COLOR">...</span> $text = preg_replace('/\[color=(.*?)\](.*?)\[\/color\]/s', '<span style="color:$1">$2</span>', $text); // Return the formatted text return $text; } function bbcode_legend() { $legend = '<h3>BBCode Legend:</h3>'; $legend .= '<ul>'; $legend .= '<li><strong>[b]text[/b]</strong>: <strong>bold</strong></li>'; $legend .= '<li><em>[i]text[/i]</em>: <em>italic</em></li>'; $legend .= '<li><u>[u]text[/u]</u>: <u>underline</u></li>'; $legend .= '<li><a href="URL">[url=URL]text[/url]</a>: <a href="URL">link</a></li>'; $legend .= '<li><img src="URL" alt="">[img]URL[/img]: image</li>'; $legend .= '<li><span style="color:red">[color=red]text[/color]</span>: <span style="color:red">colored text</span></li>'; // Add more BBCode options as needed $legend .= '</ul>'; return $legend; } function home() { global $db, $ir, $userid, $h, $version, $bookcount; // Check if a search query is submitted $searchQuery = isset($_GET['q']) ? $db->escape($_GET['q']) : ''; // Check if an order value is specified $order = isset($_GET['order']) ? $db->escape($_GET['order']) : 'id'; // Define the available order options and their corresponding column names $orderOptions = array( 'id' => 'id', 'created' => 'Created', 'views' => 'Views', 'title' => 'Title' ); // Check if the specified order is valid; otherwise, use the default order if (!array_key_exists($order, $orderOptions)) { $order = 'created'; } // Get the current page number $currentPage = isset($_GET['page']) ? intval($_GET['page']) : 1; // Set the number of books to display per page $booksPerPage = 20; ?> <h2 class='fontface'><a href="?a=home"><span class='green'>L</span>ibrary - Books: <?php echo $bookcount; ?> - v<?php echo $version; ?></a> - <small><a href="?a=createbook">Create a Book</a></small></h2> <div style="max-width: 1000px; margin: 0 auto;"> <form action="?a=home" method="GET"> <input type="text" name="q" placeholder="Search books..." value="<?php echo $searchQuery; ?>"> <input type="submit" value="Search"> | Order by: <select name="order"> <?php // Display the order options foreach ($orderOptions as $optionValue => $optionText) { $selected = ($order == $optionValue) ? 'selected' : ''; echo "<option value=\"$optionValue\" $selected>$optionText</option>"; } ?> </select> <input type="submit" value="Apply"> </form> <table width="100%"> <tr class="min"> <td align="center"><span class="black"><b>Book</b></span></td> <td align="center"><span class="black"><b>Book Info</b></span></td> <td align="center"><span class="black"><b>Views</b></span></td> <td align="center"><span class="black"><b>Pages</b></span></td> <td align="center"><span class="black"><b>Options</b></span></td> </tr> <?php // Calculate the offset for pagination $offset = ($currentPage - 1) * $booksPerPage; // Modify the query to include search functionality and order by clause if (!empty($searchQuery)) { $countQuery = $db->query("SELECT COUNT(*) FROM library WHERE title LIKE '%$searchQuery%'"); $fetchbooks = $db->query("SELECT * FROM library WHERE title LIKE '%$searchQuery%' ORDER BY $order DESC LIMIT $offset, $booksPerPage"); } else { $countQuery = $db->query("SELECT COUNT(*) FROM library"); $fetchbooks = $db->query("SELECT * FROM library ORDER BY $order DESC LIMIT $offset, $booksPerPage"); } while ($book = $db->fetch_row($fetchbooks)) { if ($book['lastedited'] == '0000-00-00 00:00:00') { $edited = ''; } else { $edited = 'Edited: '.$book['lastedited']; } $owner = $book['author']; $getuser = $db->query("SELECT * FROM users WHERE userid=$owner"); $r = $db->fetch_row($getuser); echo '<td align=center>'.number_format($book['id']).'</td> <td> <table> <tr> <td><a href="?a=read&book='.$book['id'].'">'; if($book['cover']) { echo '<img src="'.$book['cover'].'" height="150px" width="150px">'; } else { echo '<img src="images/library/no.png" height="150px" width="150px">'; } echo '</a></td> <td>&nbsp; &nbsp;</td> <td><strong>'.$book['title'].'</strong><br /> Description: <a href="#" class="see-more-link" data-description="'.$book['content'].'"><u>See More</u></a><br /> Author: <a href="viewuser.php?u='.$r['userid'].'"><font color="lightblue">'.$r['username'].' ('.$r['userid'].')</font></a><br /> Created: '.$book['created'].'<br /> '.$edited.'</td> </tr> </table> </td> <td>'.number_format($book['views']).'</td> <td>'.number_format(getBookPageCount($book)).'</td> <td> <a href="?a=read&book='.$book['id'].'"><font color="lightblue">READ</font></a><br />'; if ($userid == $book['author']) { echo '<a href="?a=editbook&book='.$book['id'].'"><font color="lightgreen">EDIT</font></a><br /><br />'; } if ($userid == '1') { echo '<a href="?a=deletebook&book='.$book['id'].'"><font color="red">DELETE</font></a>'; } echo '</td></tr>'; } ?> </table> <hr /> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { $(".see-more-link").click(function(e) { e.preventDefault(); var description = $(this).data("description"); alert(description); // Replace alert with a pop-up/modal to show the description }); }); </script> <div> <?php // Get the total number of books for pagination $totalBooks = $db->fetch_single($countQuery); $totalPages = ceil($totalBooks / $booksPerPage); // Display pagination buttons echo "Pages: "; for ($page = 1; $page <= $totalPages; $page++) { $isActive = ($page == $currentPage) ? 'active' : ''; echo "<a href='?a=home&page=$page&q=$searchQuery&order=$order' class='$isActive'><u>$page</u></a> "; } ?> </div> </div> <?php } function read() { global $db, $ir, $userid, $h; ?><br /><hr /> <div style="text-align: center;"> <a href="?a=home">BACK TO HOME</a><hr /> </div> <div style="text-align: left;"> <div style="max-width: 750px; margin: 0 auto;"> <?php $bookid = $_GET['book']; $fetchbook = $db->query("SELECT * FROM library WHERE id=$bookid"); $book = $db->fetch_row($fetchbook); $currentPage = isset($_GET['page']) ? $_GET['page'] : 1; $pagesPerBook = getBookPageCount($book); $pageSize = 1; $startPage = ($currentPage - 1) * $pageSize; $endPage = $startPage + $pageSize; // Get the title of the book $bookTitle = $book['title']; // Display the book title and page information echo "<h3>$bookTitle - Page $currentPage / $pagesPerBook</h3><hr />"; for ($i = $startPage; $i < $endPage; $i++) { $page = "page" . str_pad($i + 1, 2, "0", STR_PAD_LEFT); // Generate the column name (page01, page02, ...) if (!empty($book[$page])) { echo bbcode_format($book[$page]) . "<br>"; echo "<hr />"; } } // Check if it's the first page (initial access) if ($currentPage == 1) { // Increment the views count by 1 $db->query("UPDATE library SET views = views + 1 WHERE id = $bookid"); } ?> </div> </div> <div style="text-align: right;"> <?php if ($currentPage > 1) { $prevPage = $currentPage - 1; echo '<a href="?a=read&book='.$book['id'].'&page='.$prevPage.'">Back Page</a> | '; } if ($currentPage < $pagesPerBook) { $nextPage = $currentPage + 1; echo '<a href="?a=read&book='.$book['id'].'&page='.$nextPage.'">Next Page</a>'; } ?> </div> <?php } function getBookPageCount($book) { $pageCount = 0; for ($i = 1; $i <= 26; $i++) { $page = "page" . str_pad($i, 2, "0", STR_PAD_LEFT); if (!empty($book[$page])) { $pageCount++; } } return $pageCount; } function createBook() { global $db, $ir, $userid, $h; // Check if the form is submitted if (isset($_POST['submit'])) { // Get the form data $author = $db->escape($_POST['author']); $title = $db->escape($_POST['title']); $cover = $db->escape($_POST['cover']); $content = $db->escape($_POST['content']); $created = date('Y-m-d H:i:s'); $lastedited = '0000-00-00 00:00:00'; // Create an array to store the page content $pages = array(); // Iterate over the page fields and store the content in the array for ($i = 1; $i <= 26; $i++) { $page = "page" . str_pad($i, 2, "0", STR_PAD_LEFT); if (!empty($_POST[$page])) { $pages[$page] = $db->escape($_POST[$page]); } } // Prepare the SQL query to insert the book data $insertQuery = "INSERT INTO library (author, title, cover, content, created, lastedited"; foreach ($pages as $pageField => $pageContent) { $insertQuery .= ", $pageField"; } $insertQuery .= ") VALUES ('$author', '$title', '$cover', '$content', '$created', '$lastedited'"; foreach ($pages as $pageField => $pageContent) { $insertQuery .= ", '$pageContent'"; } $insertQuery .= ")"; // Execute the SQL query $db->query($insertQuery); // Redirect the user to the home page or display a success message echo "Book created successfully.<br /><br />"; echo "<a href='?a=home'>Back to Home</a>"; exit(); } // Display the book creation form ?><style> .form-container { max-width: 500px; margin: 0 auto; } .form-container input[type="text"], .form-container textarea { width: 100%; padding: 10px; margin-bottom: 10px; } .form-container #pagesContainer textarea { margin-top: 10px; } .form-container .button { padding: 10px 20px; background-color: #4CAF50; color: #fff; border: none; cursor: pointer; } .form-container .button:hover { background-color: #45a049; } .form-container hr { margin-top: 20px; margin-bottom: 20px; border: 0; border-top: 1px solid #ccc; } </style> <h2 class="fontface">Creating New Book - <small><a href="?a=home">Back to Library</a></small></h2> <?php echo bbcode_legend(); ?><hr /> <div class="form-container"> <form action="?a=createbook" method="POST" id="createBookForm"> <input type="hidden" name="author" value="<?php echo $userid; ?>"><br> <label>Book Title:</label> <input type="text" name="title"><br> <label>Book Cover:</label> <input type="text" name="cover"><br> <label>Description:</label> <textarea name="content" rows="5"></textarea><br> <label>Pages:</label><br> <div id="pagesContainer"> <textarea name="page01" rows="4" cols="50" placeholder="Page 1:"></textarea><br> </div> <button type="button" id="addPageButton" class="button">Add Page</button> <hr> <input type="submit" name="submit" value="Create Book" class="button"> </form> </div> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { var totalPages = 1; // Event listener for the "Add Page" button $("#addPageButton").click(function() { totalPages++; // Generate the page number in the format "Page X:" var pageNumber = "Page " + totalPages + ":"; // Generate the name attribute for the textarea var fieldName = "page" + ("0" + totalPages).slice(-2); // Create a new textarea for the page with the placeholder and name attributes set var newTextarea = $("<textarea name='" + fieldName + "' rows='4' cols='50' placeholder='" + pageNumber + "'></textarea><br>"); // Append the new textarea to the pages container $("#pagesContainer").append(newTextarea); }); }); </script> <?php } function editBook() { global $db, $ir, $userid, $h; // Check if the form is submitted if (isset($_POST['submit'])) { // Get the book ID from the URL $bookId = (int)$_GET['book']; // Verify if the user is the owner of the book $bookQuery = $db->query("SELECT author FROM library WHERE id = $bookId"); $book = $db->fetch_row($bookQuery); $bookAuthor = (int)$book['author']; // Get the form data $author = $db->escape($_POST['author']); $title = $db->escape($_POST['title']); $cover = $db->escape($_POST['cover']); $content = $db->escape($_POST['content']); $lastedited = date('Y-m-d H:i:s'); if ($userid !== $author) { echo "You are not authorized to edit this book."; return; } // Create an array to store the page content $pages = array(); // Iterate over the page fields and store the content in the array for ($i = 1; $i <= 26; $i++) { $page = "page" . str_pad($i, 2, "0", STR_PAD_LEFT); $pages[$page] = $db->escape($_POST[$page]); } // Prepare the SQL query to update the book data $updateQuery = "UPDATE library SET author = '$author', title = '$title', cover = '$cover', content = '$content', lastedited = '$lastedited'"; foreach ($pages as $pageField => $pageContent) { $updateQuery .= ", $pageField = '$pageContent'"; } $updateQuery .= " WHERE id = $bookId"; // Execute the SQL query $db->query($updateQuery); // Redirect the user to the home page or display a success message echo "Book edited successfully.<br /><br />"; echo "<a href='?a=home'>Back to Home</a>"; exit(); } // Display the book editing form $bookId = (int)$_GET['book']; $fetchbook = $db->query("SELECT * FROM library WHERE id = $bookId"); $book = $db->fetch_row($fetchbook); ?> <style> .form-container { max-width: 500px; margin: 0 auto; } .form-container input[type="text"], .form-container textarea { width: 100%; padding: 10px; margin-bottom: 10px; } .form-container .button { padding: 10px 20px; background-color: #4CAF50; color: #fff; border: none; cursor: pointer; } .form-container .button:hover { background-color: #45a049; } .form-container hr { margin-top: 20px; margin-bottom: 20px; border: 0; border-top: 1px solid #ccc; } </style> <h2 class="fontface">EDIT BOOK - <small><a href="?a=home">Back to Home</a></small></h2> <?php echo bbcode_legend(); ?> <hr /> <div class="form-container"> <form action="?a=editbook&book=<?php echo $bookId; ?>" method="POST"> <input type="hidden" name="author" value="<?php echo $book['author']; ?>"><br> <label>Title:</label> <input type="text" name="title" value="<?php echo $book['title']; ?>"><br> <label>Cover:</label> <input type="text" name="cover" value="<?php echo $book['cover']; ?>"><br> <label>Content:</label> <textarea name="content" rows="5"><?php echo $book['content']; ?></textarea><br> <label>Pages:</label><br> <?php for ($i = 1; $i <= 26; $i++) { $page = "page" . str_pad($i, 2, "0", STR_PAD_LEFT); echo "<label>$page:</label><br>"; echo "<textarea name='$page' cols='50' rows='10'>{$book[$page]}</textarea><br>"; } ?> <input type="submit" name="submit" value="Save Changes" class="button"> </form> </div> <?php } function deleteBook() { global $db, $ir, $userid, $h; // Check if the user is authorized to delete the book if ($userid != 1) { echo "You are not authorized to delete books."; return; } // Check if the book ID is provided if (!isset($_GET['book'])) { echo "Invalid book ID."; return; } $bookID = intval($_GET['book']); // Check if the book exists $checkQuery = $db->query("SELECT id FROM library WHERE id=$bookID"); if ($db->num_rows($checkQuery) == 0) { echo "Book not found."; return; } // Delete the book $deleteQuery = $db->query("DELETE FROM library WHERE id=$bookID"); if ($deleteQuery) { echo "Book deleted successfully."; } else { echo "Error deleting book."; } echo "<br /><br />"; echo "<a href='?a=home'>Back to Home</a>"; exit(); } $h->endpage(); ?> And here is your SQL CREATE TABLE `library` ( `id` int(11) NOT NULL AUTO_INCREMENT, `author` int(11) NOT NULL, `title` varchar(255) NOT NULL, `cover` varchar(255) DEFAULT NULL, `content` varchar(255) DEFAULT NULL, `created` datetime DEFAULT NULL, `lastedited` datetime DEFAULT NULL, `views` int(11) DEFAULT NULL, `page01` varchar(255) DEFAULT NULL, `page02` varchar(255) DEFAULT NULL, `page03` varchar(255) DEFAULT NULL, `page04` varchar(255) DEFAULT NULL, `page05` varchar(255) DEFAULT NULL, `page06` varchar(255) DEFAULT NULL, `page07` varchar(255) DEFAULT NULL, `page08` varchar(255) DEFAULT NULL, `page09` varchar(255) DEFAULT NULL, `page10` varchar(255) DEFAULT NULL, `page11` varchar(255) DEFAULT NULL, `page12` varchar(255) DEFAULT NULL, `page13` varchar(255) DEFAULT NULL, `page14` varchar(255) DEFAULT NULL, `page15` varchar(255) DEFAULT NULL, `page16` varchar(255) DEFAULT NULL, `page17` varchar(255) DEFAULT NULL, `page18` varchar(255) DEFAULT NULL, `page19` varchar(255) DEFAULT NULL, `page20` varchar(255) DEFAULT NULL, `page21` varchar(255) DEFAULT NULL, `page22` varchar(255) DEFAULT NULL, `page23` varchar(255) DEFAULT NULL, `page24` varchar(255) DEFAULT NULL, `page25` varchar(255) DEFAULT NULL, `page26` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; You'll need to create the Directory images/library/ in your File Manager, Upload the image attached that i've used for no cover image. Please note that this is the VERY first Version and Revision, I'll update this with changes i made. Here is a Screenshot
  21. 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.
  22. I think you should add a picture of ingame so that the person who reads this will get some idea of where you are going as i find its best to keep the same theme ingame as on the login page.
  23. 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. 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.'" />'; } }
  24. Yeah, to be honest, its not great look but then it doesn't bother me. I dont make any money out of it to make it a viable option to put loads of work into it. Its was made and for use for free, maybe a donation on it would encourage me to improove it but as is, there isn't any point, It works, gives links and quick access to all my mods in one place. Maybe in a couple years i'll update it, but for now, it will be as is. Thank you for your input and if i ever update it i will take your inputs and impliment it.
  25. More mods added and looks tweeked.
×
×
  • Create New...