Jump to content
MakeWebGames

War_Hero

Members
  • Posts

    232
  • Joined

  • Last visited

Everything posted by War_Hero

  1. I always tab and indent my code. It helps me so much when trying to debug anything. @Paul - I also tab my tables. It makes it much easier to see the text/info/data on each row and in each cell. And I, too, use the same indent size in each of my scripts. I use Quanta Plus on my Ubuntu laptop, and Notepad++ on my Windows one. Used to use Crimson Editor, but the formatting started to frustrate me. Thanks for this post a_bertrand. :)
  2. It depends on the size of the indent. :) But you've just gone against your original point....indentation in this form hardly makes a difference in file size, and it make it easier to read the script. I always indent my code, but maybe not as much as this. :)
  3. For a mod like this, it's a matter of KBs between a file with the identation and a file without. So it wouldn't have much of an effect, really....maybe on a bigger mod, yeah, but not on one this size. :)
  4. Why am I not surprised that you thought you were going to get flamed? Oh, because a lot of people in this community just flame others for trying their hardest. I guess they have their reasons. Anyway...it's looking good. The visitors in the city is a good idea. Come the time when players want to attack each other, it'll be a quick way of finding out who's in the same city as they are. It's great that you're using a game to develop your PHP skills. You're not using McCodes, are you? If you are, I will advise you not to use it until the new version comes out. I made the mistake of developing my PHP skills through McCodes. I'm slowly coming out of my bad habits! haha I hope the development goes well. Believe it or not, there are some nice people in this community. Those of us who don't flame and actually respect other's work will probably be more than happy to assist you if you have any problems, questions or issues. :) Welcome to the community.
  5. Cheers guys. :) Let me know what you think of it, please?
  6. Installation (Part 2) Step 3 Create a file called staff_banner.php and paste this into it: <?php /* -------------------------------------------------------------------------------------------- + Created by Emlyn Kinzett (War_Hero) + Feature: JQuery Banner Selector (FREE) + File: staff_banner.php + Rights: Do not re-distribute or sell, please. + Notes: Please do not remove this top bit. -------------------------------------------------------------------------------------------- */ if(!$_POST['globalsplease']) { include_once(DIRNAME(__FILE__) ."/sglobals.php"); } else { session_start(); require_once('config.php'); global $_CONFIG; define("MONO_ON", 1); require_once('class/class_db_'.$_CONFIG['driver'].'.php'); $db=new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c=$db->connection_id; require_once('global_func.php'); $_POST['globalsplease'] = abs(@intval($_POST['globalsplease'])); $_POST['what'] = mysql_real_escape_string(htmlentities($_POST['what'])); $_POST['thedata'] = htmlentities($_POST['thedata']); $_POST['theban'] = mysql_real_escape_string(htmlentities($_POST['theban'])); $_POST['thepath'] = htmlentities($_POST['thepath']); $_POST['avail'] = mysql_real_escape_string(htmlentities($_POST['avail'])); if($_POST['what']) { //add functions if($_POST['what'] == 'name') { //print "what: ". $_POST['what'] ." -- thedata: ". $_POST['thedata'] ." "; $checkNames = mysql_query("SELECT title FROM banners WHERE title = '". $_POST['thedata'] ."'") OR die(mysql_error()); $return = (mysql_num_rows($checkNames) > 0) ? "<span style = 'color: #FF0000'>Unavailable</span>" : "<span style = 'color: #82CAFA'>Available</span>"; print $return; } elseif($_POST['what'] == 'path') { $checkPaths = mysql_query("SELECT href FROM banners WHERE href = '". $_POST['thedata'] ."'") OR die(mysql_error()); $return = (mysql_num_rows($checkPaths) > 0) ? "<span style = 'color: #FF0000'>Unavailable</span>" : "<span style = 'color: #82CAFA'>Available</span>"; print $return; } elseif($_POST['what'] == 'add') { $checkBanner = mysql_query("SELECT title, href FROM banners WHERE title = '". $_POST['theban'] ."' OR href = '". $_POST['thepath'] ."'") OR die(mysql_error()); if(mysql_num_rows($checkBanner) > 0) { print "<p style = 'color: #FF0000'>Either the title or path of the banner are unavailable.</p>"; } else { if($_POST['theban'] == "" || $_POST['thepath'] == "") { print "<p style = 'color: #FF0000'>One of the fields was not filled in.</p>"; } else { print "<p style = 'color: #82CAFA'>The banner has successfully been added.</p>"; $insert = ("INSERT INTO banners (id, title, href, available) VALUES('', '". $_POST['theban'] ."', '". $_POST['thepath'] ."', '". $_POST['avail'] ."')"); mysql_query($insert) OR die(mysql_error()); } } } // edit functions elseif($_POST['what'] == 'editname') { $_POST['oldval2'] = mysql_real_escape_string($_POST['oldval2']); $_POST['newval2'] = mysql_real_escape_string($_POST['newval2']); if($_POST['oldval2'] == $_POST['newval2']) { print "<span style = 'color: #82CAFA'>Available</span>"; } else { $checkNewName = mysql_query("SELECT title FROM banners WHERE title = '". $_POST['newval2'] ."'"); $return = (mysql_num_rows($checkNewName) > 0) ? "<span style = 'color: #FF0000'>Unavailable</span>" : "<span style = 'color: #82CAFA'>Available</span>"; print $return; } } elseif($_POST['what'] == 'editpath') { $_POST['oldval2'] = htmlentities($_POST['oldval2'], ENT_QUOTES); $_POST['newval2'] = htmlentities($_POST['newval2'], ENT_QUOTES); if($_POST['oldval2'] == $_POST['newval2']) { print "<span style = 'color: #82CAFA'>Available</span>"; } else { $checkNewPath = mysql_query("SELECT href FROM banners WHERE href = '". $_POST['newval2'] ."'"); $return = (mysql_num_rows($checkNewPath) > 0) ? "<span style = 'color: #FF0000'>Unavailable</span>" : "<span style = 'color: #82CAFA'>Available</span>"; print $return; } } elseif($_POST['what'] == 'edit') { $_POST['id'] = abs(@intval($_POST['id'])); $_POST['isnewname'] = abs(@intval($_POST['isnewname'])); $_POST['isnewpath'] = abs(@intval($_POST['isnewpath'])); if($_POST['isnewname'] == 1 && $_POST['isnewpath'] == 1) { $updateBanner = ("UPDATE banners SET available = '". $_POST['avail'] ."' WHERE id = ". $_POST['id'] .""); mysql_query($updateBanner) OR die(mysql_error()); print "<p style = 'color: #82CAFA'>The banner has been updated</p>"; print " <a href = 'staff_banner.php?a=edit'>Back</a></p>"; } else { $changeName = TRUE; $changePath = TRUE; if($_POST['isnewname'] == 2) { $checkName = mysql_query("SELECT title FROM banners WHERE title = '". $_POST['theban'] ."'"); if(mysql_num_rows($checkName) > 0) { print "<p style = 'color: #FF0000'>That name is already taken.</p>"; $changeName = FALSE; } else { $changeName = TRUE; } } if($_POST['isnewpath'] == 2) { $checkPath = mysql_query("SELECT href FROM banners WHERE href = '". $_POST['thepath'] ."'"); if(mysql_num_rows($checkPath) > 0) { print "<p style = 'color: #FF0000'>That path is already taken.</p>"; $changePath = FALSE; } else { $changePath = TRUE; } } if($changeName === TRUE && $changePath === TRUE) { print "<p style = 'color: #82CAFA'>The banner has been edited.</p>"; print " <a href = 'staff_banner.php?a=edit'>Back</a></p>"; $updateBanner = ("UPDATE banners SET title = '". $_POST['theban'] ."', href = '". $_POST['thepath'] ."', available = '". $_POST['avail'] ."' WHERE id = ". $_POST['id'] .""); mysql_query($updateBanner) OR die(mysql_error()); } } } // delete functions elseif($_POST['what'] == 'delete') { $_POST['idofban'] = abs(@intval($_POST['idofban'])); if($_POST['idofban'] == 1) { print "<p style = 'color: #FF0000'>That banner cannot be deleted.</p>"; } else { $bannerGet = mysql_query("SELECT b1.id, b1.href, b1.title, b2.href as bhref, b2.title as btitle, b2.id as bid FROM banners b1 JOIN banners b2 WHERE b1.id = ". $_POST['idofban'] ." LIMIT 1") OR die(mysql_error()); if(mysql_num_rows($bannerGet) <= 0) { print "<p style = 'color: #FF0000'>That banner cannot be found.</p>"; } else { $bg = mysql_fetch_assoc($bannerGet); $return = "<p style = 'color: #82CAFA'>The banner was successfully deleted.</p>"; $changeOthers = ("UPDATE users SET banner = '". $bg['bhref'] ."' WHERE banner = '". $bg['href'] ."'"); mysql_query($changeOthers) OR die(mysql_error()); $numRows = mysql_affected_rows(); $return .= "<p style = 'color: #82CAFA'>A total of ". number_format($numRows) ." users had their banner changed because of this deletion.</p>"; $return .= " <a href = 'staff_banner.php?a=del'>Back</a></p>"; $deleteBanner = ("DELETE FROM banners WHERE id = ". $_POST['idofban'] .""); mysql_query($deleteBanner) OR die(mysql_error()); print $return; } } } // 'safety' statement else { print "An error occurred."; } } } ?> <script src = "jsquery.js" type = "text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> <script type = "text/javascript"> function checkValue(postdata,area,subdata) { //alert(postdata + ", " + area + ", " + subdata); $(area).fadeOut(750, function() { $.post("staff_banner.php", { globalsplease: 1, what: postdata, thedata: subdata }, function(data) { $(area).html(data).fadeIn(750); }); }); } function addBanner() { $('#outcome').fadeOut(750, function() { var banner = $('input:text[name=banName]').val(); var path = $('input:text[name=banPath]').val(); var sel = $('input:radio[name=banAv]:checked').val(); $.post("staff_banner.php", { globalsplease: 1, what: "add", theban: banner, thepath: path, avail: sel }, function(data) { $('#outcome').html(data).fadeIn(750, function() { $('#outcome').delay(2500).fadeOut(750, function() { $('#nameSpan').fadeOut(500, function() { $('#nameSpan').html("<span style = 'font-style: italic;font-size: 8px'>Result</span>").fadeIn(750); }); $('#pathSpan').fadeOut(500, function() { $('#pathSpan').html("<span style = 'font-style: italic;font-size: 8px'>Result</span>").fadeIn(750); }); document.getElementById("banNameID").value = ""; document.getElementById("banPathID").value = ""; }); }); }); }); } function checkValueEdit(span,spanName,ol,ne) { //alert(ol + ", " + ne + " -- " + span + ", " + spanName); if(spanName == "#nameSpan") { if(ol != ne) { document.getElementById("nameNewID").checked = true; } else if(ol == ne) { document.getElementById("nameNewID").checked = false; } } else if(spanName == "#pathSpan") { if(ol != ne) { document.getElementById("pathNewID").checked = true; } else if(ol == ne) { document.getElementById("pathNewID").checked = false; } } $(spanName).fadeOut(750, function() { $.post("staff_banner.php", { globalsplease: 1, what: span, oldval2: ol, newval2: ne }, function(data) { $(spanName).html(data).fadeIn(750); }); }); } function editBanner(id) { $('#outcome').fadeOut(750, function() { var banner = $('input:text[name=banName]').val(); var path = $('input:text[name=banPath]').val(); var sel = $('input:radio[name=banAv]:checked').val(); var newPath = 1; var newName = 1; if(document.getElementById("pathNewID").checked == true) { newPath = 2; } if(document.getElementById("nameNewID").checked == true) { newName = 2; } $.post("staff_banner.php", { globalsplease: 1, what: "edit", id: id, theban: banner, thepath: path, avail: sel, isnewname: newName, isnewpath: newPath }, function(data) { $('#outcome').html(data).fadeIn(750); }); }); } function deleteBanner(delid) { if(delid == 1) { alert("You cannot delete that banner!"); } else { $('#result').fadeOut(1200, function() { $.post("staff_banner.php", { globalsplease: 1, what: "delete", idofban: delid }, function(data) { $('#result').html("Please wait... ").fadeIn(1200, function() { $('#result').delay(1500).fadeOut(1200, function() { $('#result').html(data).fadeIn(1200); }); }); }); }); } } </script> <?php switch($_GET['a']) { case "new": newBanner(); break; case "edit": editBanner(); break; case "del": deleteBanner(); break; } if(isset($_GET['a'])) { $allowed = array("new","edit","del"); if(!in_array($_GET['a'],$allowed)) { print "<p style = 'color: #FF0000'>That action is not allowed.</p>"; $h->endpage(); exit(); } } function newBanner() { global $ir, $userid, $c, $h; print " Fill in the form below to add a new banner. Upload the image via your cPanel (or whatever else you use) before adding in a new banner.</p> <form action = '' id = 'newBanner' method = 'POST'> <table width = '100%' style = 'text-align:center'> <tr> <th>Banner Name</th> <td><input type = 'text' size = '7' name = 'banName' id = 'banNameID' onChange =\"checkValue('name','#nameSpan',this.value);\" /></td> <td width = '25%'><div id = 'nameSpan'><span style = 'font-style: italic;font-size: 8px'>Result</span></div></td> </tr> <tr> <th>Banner Path</th> <td><input type = 'text' size = '7' name = 'banPath' id = 'banPathID' onChange = \"checkValue('path','#pathSpan',this.value);\" /></td> <td width = '25%'><div id = 'pathSpan'><span style = 'font-style: italic;font-size: 8px'>Result</span></div></td> </tr> <tr> <th>Banner Available</th> <td><input type = 'radio' name = 'banAv' id = 'banAvID' value = 'Y' checked = 'checked' />Yes <input type = 'radio' name = 'banAv' id = 'banAvID' value = 'N' />No</td> <td width = '25%'></th> </tr> <tr> <td colspan = '3'><input type = 'button' name = 'subForm' id = 'subFormID' value = 'Add Banner' onClick = 'addBanner();' /></td> </tr> <tr> <td colspan = '3'><div id = 'outcome'></div></td> </tr> </table> </form> </p>"; } function editBanner() { global $ir, $userid, $c, $h; $_POST['banID'] = abs(@intval($_POST['banID'])); if(!$_POST['banID']) { print " Choose a banner from below to edit its details:</p> "; $getBanners = mysql_query("SELECT id, title FROM banners ORDER BY id ASC"); if(mysql_num_rows($getBanners) <= 0) { print "<p style = 'color: #FF0000'>No banners to edit.</p>"; $h->endpage(); exit(); } else { print " <form action = 'staff_banner.php?a=edit' method = 'POST'> <select name = 'banID' type = 'dropdown'>"; while($bans = mysql_fetch_assoc($getBanners)) { print "<option value = '". abs(@intval($bans['id'])) ."'>". stripslashes($bans['title']) ."</option>"; } print "</select> <input type = 'submit' value = 'Continue...' /> </form>"; } print "</p>"; } else { $details = mysql_query("SELECT * FROM banners WHERE id = ". $_POST['banID'] ." LIMIT 1"); if(mysql_num_rows($details) <= 0) { print "<p style = 'color: #FF0000'>That banner does not exist.</p> <a href = 'staff_banner.php?a=edit'>Back</a></p>"; $h->endpage(); exit(); } else { $dd = mysql_fetch_assoc($details); $title = $dd['title']; $href = $dd['href']; $id = $_POST['banID']; $radio = ($dd['available'] == 'Y') ? "<input type = 'radio' name = 'banAv' id = 'banAvID' value = 'Y' checked = 'checked' />Yes <input type = 'radio' name = 'banAv' id = 'banAvID' value = 'N' />No" : "<input type = 'radio' name = 'banAv' id = 'banAvID' value = 'Y' />Yes <input type = 'radio' name = 'banAv' id = 'banAvID' value = 'N' checked = 'checked' />No"; print " <form action = '' id = 'editBanner' method = 'POST'> <table width = '100%' style = 'text-align:center'> <tr> <th>Banner Name</th> <td><input type = 'text' size = '7' value = '". $dd['title'] ."' name = 'banName' id = 'banNameID' onChange =\"checkValueEdit('editname','#nameSpan','". $title ."',this.value);\" /><input type = 'checkbox' name = 'nameNew' id = 'nameNewID' disabled = 'disabled' /></td> <td width = '25%'><div id = 'nameSpan'><span style = 'font-style: italic;font-size: 8px'>Result</span></div></td> </tr> <tr> <th>Banner Path</th> <td><input type = 'text' size = '7' value = '". $dd['href'] ."' name = 'banPath' id = 'banPathID' onChange = \"checkValueEdit('editpath','#pathSpan','". $href ."',this.value);\" /><input type = 'checkbox' name = 'pathNew' id = 'pathNewID' disabled = 'disabled' /></td> <td width = '25%'><div id = 'pathSpan'><span style = 'font-style: italic;font-size: 8px'>Result</span></div></td> </tr> <tr> <th>Banner Available</th> <td>". $radio ."</td> <td width = '25%'></th> </tr> <tr> <td colspan = '3'><input type = 'button' name = 'subForm' id = 'subFormID' value = 'Edit Banner' onClick = 'editBanner(". $id .");' /></td> </tr> <tr> <td colspan = '3'><div id = 'outcome'></div></td> </tr> </table> </form> </p>"; } } } function deleteBanner() { global $ir, $userid, $c, $h; $_POST['delID'] = abs(@intval($_POST['delID'])); print "<h2>Deleting a Banner</h2>"; if(!$_POST['delID']) { print " Choose a banner from below to delete. Please note that you cannot delete the first banner you added as any user with the soon-to-be-deleted banner chosen as their banner will have the the first banner set as their preferred one (if that makes any sense!)</p>"; $deleting = mysql_query("SELECT title, id FROM banners WHERE id != 1 ORDER BY id ASC"); if(mysql_num_rows($deleting) <= 0) { print "<p style = 'color: #FF0000'>There are no banners to delete.</p>"; $h->endpage(); exit(); } else { print " <form action = 'staff_banner.php?a=del' method = 'POST'> <select name = 'delID' type = 'dropdown'>"; while($del = mysql_fetch_assoc($deleting)) { print "<option value = '". abs(@intval($del['id'])) ."'>". stripslashes($del['title']) ."</option>"; } print "</select> <input type = 'submit' name = 'subDel' value = 'Delete' /> </form> </p>"; } } else { $checkDel = mysql_query("SELECT id, href FROM banners WHERE id = ". $_POST['delID'] ." LIMIT 1"); if(mysql_num_rows($checkDel) <= 0) { print "<p style = 'color: #FF0000'>That banner does not exist.</p>"; $h->endpage(); exit(); } else { $cd = mysql_fetch_assoc($checkDel); if($_POST['delID'] == 1) { print "<p style = 'color: #FF0000'>You cannot delete the first banner you added.</p>"; $h->endpage(); exit(); } else { print " <div align = 'center' style = 'text-align:center' id = 'result'> Are you sure you want to delete this banner?</p> <input type = 'button' value = 'Yes' id = 'y' onClick = \"deleteBanner(". $_POST['delID'] .");\" /> <input type = 'button' value = 'No' id = 'n' onClick = \"javascript:parent.location='staff_banner.php?a=del'\" /> </p> </div>"; } } } } if(!$_POST['globalsplease']) { $h->endpage(); } ?>   Step 4 Go into your header.php and find the bit where your banner is displayed. Add this code to it, before the image is shown: $userBanner = mysql_query("SELECT banner FROM users WHERE userid = ". abs(@intval($ir['userid'])) ." LIMIT 1"); $uB = mysql_fetch_object($userBanner); $image = $uB->banner; and then replace the <img src = 'yourbannerhere.png' /> with <img src = '". $image ."' alt = 'Banner' /> Step 5 Go into preferences.php and add in the link so players can change their banner: <a href = 'choosebanner.php'>Choose Banner</a>   Step 6 Go into smenu.php and add in the following links somewhere: <a href = 'staff_banner.php?a=new'>Add a Banner</a> <a href = 'staff_banner.php?a=edit'>Edit a Banner</a> <a href = 'staff_banner.php?a=del'>Delete a Banner</a>   And I believe you're done! :) Oh, if for some reason when you add the field into the users table, the banner isn't set to the default for the users, run this in PHPMYADMIN (if you didn't know how to): UPDATE users SET banner = 'defaultbannerhere.png' WHERE banner = '';   That should do the trick.   Please give me any type of feedback, but please don't flame. You wouldn't like it if one of us flamed your post or idea. ;) I'll gladly fix any bugs or errors that come up, but I've tested it and haven't received any. Cheers, War_Hero Edit: Screw the screen shots. I just spent 10 minutes sorting them out only to be greeted by a Fatal Error page. That's frustrated me, so I'll post them later maybe.
  7. Hello again everyone. Now I know what you're thinking when you read the subject for this thread, "There are already 2 or 3 of these out there." But this one uses JQuery. :D I've recently been developing my JQuery skills so I can create an updates page which is all done using JQuery. Description This mod will allow the admin to add new banners to the game. They type in the name of the banner, the href (path) of the banner and select whether it is available for players to choose. You will have to upload the image to your public_html folder via your cPanel or whatever you use, but that's not much of a hassle. Checks are made upon entering the name and path to make sure there are no other banners with the same path and name. Editing a banner's details also uses JQuery (mostly). This, too, ensures that the name entered doesn't match any other banner name. Likewise with the path. Obviously, if they aren't changed, no comparison will be made. Deleting a banner also uses JQuery and will delete the banner from the DB. But the image itself won't be deleted. Any user with that banner selected will be reverted back to the default banner, so as you can guess, you cannot delete the first banner you enter. Installation (Part 1) Step 1 Run the following SQLs in your PHPMYADMIN. Remember to change the yourbannerhere.png to your default banner. CREATE TABLE IF NOT EXISTS banners ( id INTEGER(11) NOT NULL AUTO_INCREMENT, title VARCHAR(35) NOT NULL, href TEXT NOT NULL, available ENUM('Y','N') NOT NULL DEFAULT 'Y', PRIMARY KEY (id) ) ENGINE = MyISAM DEFAULT CHARSET = utf8; ALTER TABLE users ADD banner VARCHAR(50) NOT NULL DEFAULT 'yourbannerhere.png';   Step 2 Create a file called choosebanner.php and paste this into it. <?php /* -------------------------------------------------------------------------------------------- + Created by Emlyn Kinzett (War_Hero) + Feature: JQuery Banner Selector (FREE) + File: choosebanner.php + Rights: Do not re-distribute or sell, please. + Notes: Please do not remove this top bit. -------------------------------------------------------------------------------------------- */ if(!$_POST['blah']) { include_once(DIRNAME(__FILE__) ."/globals.php"); } else { session_start(); require_once('config.php'); global $_CONFIG; define("MONO_ON", 1); require_once('class/class_db_'.$_CONFIG['driver'].'.php'); $db=new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c=$db->connection_id; require_once('global_func.php'); $details = mysql_query("SELECT userid, username, banner FROM users WHERE userid = ". abs(@intval($_SESSION['userid'])) .""); $d = mysql_fetch_assoc($details); } $_POST['banner'] = abs(@intval($_POST['banner'])); $_POST['view'] = abs(@intval($_POST['view'])); $_POST['blah'] = abs(@intval($_POST['blah'])); ?> <script src = "jsquery.js" type = "text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> <script language = "javascript" type = "text/javascript"> //alert("Javascript is a pain"); function changeBanner(theBanner) { //alert(theBanner); if(theBanner == 0) { alert("No banner to show."); } else { $('#viewbanner').animate({ opacity: 0.5 }, function() { $('#viewbanner').hide("explode", { pieces: 9 }, 500, function() { $.post("choosebanner.php", { blah: 1, view: theBanner }, function(data) { $('#viewbanner').html(data).show("explode",{ pieces: 9 }, 1300, function() { $('#viewbanner').animate({ opacity: 1.0 }, 500); }); }); }); }); document.getElementById("subBanner").disabled = false; } } function saveBanner() { var check = $('input:radio[name=banners]:checked').val(); if(check == "") { alert("You did not select a banner."); } else { //alert("check: " + check); $('#viewbanner').animate({ opacity: 0.0 }, function() { $.post("choosebanner.php", { blah: 1, set: check }, function(data) { $('#viewbanner').html(data).animate({ opacity: 1.0 }, 500); }); }); } } </script> <?php if($_POST['view']) { if(!is_numeric($_POST['view'])) { print "<p style = 'color:#FF0000'>Invalid banner selected.</p>"; } else { $width = 300; /* Change these two values */ $height = 68; /* to alter the size of the mini banners for the user to preview */ $chosen = mysql_query("SELECT * FROM banners WHERE id = ". $_POST['view'] ." LIMIT 1"); $ch = mysql_fetch_assoc($chosen); if(mysql_num_rows($chosen) <= 0) { print "<p style = 'color: #FF0000'>That banner does not exist.</p>"; } elseif($ch['available'] != 'Y') { print "<p style = 'color: #FF0000'>That banner is not available at the moment.</p>"; } else { $showBanner = "<img src = '". $ch['href'] ."' alt = 'Banner' width = '". $width ."' height = '". $height ."' />"; print $showBanner; } } } elseif($_POST['set']) { $chosen = mysql_query("SELECT * FROM banners WHERE id = ". $_POST['set'] ." LIMIT 1"); $ch = mysql_fetch_assoc($chosen); if(mysql_num_rows($chosen) <= 0) { print "<p style = 'color: #FF0000'>That banner does not exist.</p>"; } elseif($ch['available'] != 'Y') { print "<p style = 'color: #FF0000'>That banner is not available at the moment.</p>"; } else { $final = $ch['href']; if($final != $d['banner']) { print "<p style = 'color: #82CAFA'>You successfully changed your preferred banner.</p>"; $updateBanner = ("UPDATE users SET banner = '". $final ."' WHERE userid = ". abs(@intval($d['userid'])) .""); mysql_query($updateBanner) OR die("Could not update banner: ". mysql_error()); } else { print "<p style = 'color: #893BFF'>No change was made to your preferred banner.</p>"; } } } if(!$_POST['blah']) { $getBanners = mysql_query("SELECT * FROM banners WHERE available = 'Y' ORDER BY id ASC"); if(mysql_num_rows($getBanners) <= 0) { print "<p style = 'color: #FF0000'>No banners to choose from. Please contact an admin.</p>"; $h->endpage(); exit(); } else { $yourBanner = mysql_query("SELECT b.title, b.href, u.userid, u.banner FROM banners b LEFT JOIN users u ON b.href = u.banner WHERE u.userid = ". abs(@intval($ir['userid'])) ." LIMIT 1"); $yB = mysql_fetch_assoc($yourBanner); print " Here, you can change the current banner you see at the top of the page!</p> Select one from below. Please be patient while the image loads.</p> You currently have the [b]". stripslashes($yB['title']) ."[/b] banner selected.</p> <form action = '' id = 'bannerChoice' method = 'post'>"; while($gb = mysql_fetch_assoc($getBanners)) { print "<input type = 'radio' name = 'banners' id = 'bannerID' value = '". $gb['id'] ."' onClick = 'changeBanner(this.value);' />". stripslashes($gb['title']) ." "; } print " <input type = 'button' id = 'subBanner' value = 'Choose Banner' onClick = 'saveBanner();' disabled = 'disabled' /> </form> </p>"; } } print "<div id = 'viewbanner'></div>"; if(!$_POST['blah']) { $h->endpage(); } ?> Edit lines 90 and 91 to change the size of the banner preview. Make sure it's scaled down from the main banner image, otherwise it'll look odd. Part 2 next
  8. I've fixed it now. :) Thanks for your help.
  9. I always space out my code, whether it be HTML, JS or PHP. Just a personal preference and I find it easier to read. :) Ohhh. So would that prevent the image 'appearing' below my radio buttons? Or another problem altogether? :S
  10. Hi everyone. I'm pretty new to JQuery and Ajax and am having some problems with the $.post() function in JQuery. My aim, to include in my game, is to allow users to choose which banner they want at the top. So when they click on one of the radio buttons provided, a preview of the banner will fade in below the buttons. But no matter what I try, I can't get it to work. I've tried sending the data to another file, using the $.ajax() instead. At the moment, I'm using the if xmlhttp.onreadystatechange==4 type of Ajax, which (to my knowledge or lack of skills) doesn't allow me to use effects. Here is my file: <?php include_once(DIRNAME(__FILE__) ."/globals.php"); $_POST['banner'] = abs(@intval($_POST['banner'])); $_POST['view'] = abs(@intval($_POST['view'])); ?> <script src = "js/jquery/jquery-1.3.2.js" type = "text/javascript"></script> <script language = "javascript" type = "text/javascript"> //alert("Javascript is a pain"); function changeBanner(theBanner) { //alert(theBanner); if(theBanner == 0) { alert("No banner to show."); } else { $.post("choosebanner.php", { view: theBanner }, function(data) { $('#viewbanner').html(data); } ); } } </script> <?php print " Here, you can change the current banner you see at the top of the page!</p> Select one from the dropdown below. You will see the banner when you select it.</p> <form action = '' name = 'bannerChoice' method = 'post'>"; $value = 1; while($value < 4) { print "<input type = 'radio' name = 'banner' id = 'bannerID' value = '". $value ."' onClick = 'changeBanner(this.value);' />Banner ". $value; $value++; } print " <input type = 'button' name = 'subBanner' value = 'Choose Banner' onClick = \"saveBanner();\" /> </form> </p>"; print "<div id = 'viewbanner'></div>"; if($_POST['view']) { print "view: ". $_POST['view'] ." "; if(!is_numeric($_POST['view'])) { print "<p style = 'color:#FF0000'>Invalid banner selected.</p>"; } else { $banners = array(1 => "grungebanner.php", 2 => "banner3.png", 3 => "banner.png"); $showBanner = "crysis/". $banners[$_POST['view']]; $showBanner2 = "<img src = '". $showBanner ."' alt = 'Banner' />"; print $showBanner2; } } $h->endpage(); ?>   I've not tried the fading in bit yet as I can't even get the image selected to show. Any help will be highly appreciated, as I've tried looking on the JQuery site, and although the tutorials on there are helpful, they haven't been able to help me much.
  11. You could try this. I'm not sure if it will work, as I've not tested it:   <?php $i=('globals.php'); include "$i"; $_GET['LID'] = abs((int) $_GET['LID']); $_GET['DID'] = abs((int) $_GET['DID']); if($_GET['LID']) { $p = $db->query("SELECT fr_like FROM users WHERE userid = ". abs(@intval($ir['userid'])) ." LIMIT 1"); $r = $db->fetch_row($p); $likes = explode(",",$r['fr_like']); if (in_array($_GET['LID'],$likes)) { echo "You already voted on this topic"; } else { echo "You have liked the topic"; $db->query("UPDATE forum_topics SET ft_like=ft_like+1 WHERE ft_id=". $_GET['LID'] .""); $db->query("UPDATE users SET fr_like = concat('". $_GET['LID'] ."') WHERE userid = ". abs(@intval($ir['userid'])) .""); } } else if($_GET['DID']) { $p = $db->query("SELECT ft_id, ft_name FROM forum_topics WHERE ft_id = ".$_GET['DID']); $r = $db->fetch_row($p); $dislikes = $db->query("SELECT fr_dislike FROM users WHERE userid = ". abs(@intval($ir['userid'])) ." LIMIT 1"); $dl = $db->fetch_row($dislikes); $dis = explode(",",$dl['fr_dislike']); if (in_array($_GET['DID'],$dis)) { echo "You have already voted on this topic."; } else { echo "You have disliked the topic"; $db->query("UPDATE forum_topics SET ft_dislike=ft_dislike+1 WHERE ft_id={$r['ft_id']}"); $db->query("UPDATE users SET fr_dislike=concat('" .$r['ft_id'] ."') WHERE userid=". abs(@intval($ir['userid'] .""); } } else { echo "Invalid use of file"; } ?>
  12. Sorry if my message seemed abrupt and harsh, I didn't mean it to. :) And thank you very much. :D I may have to alter it though. Although it is more realistic and what not, it is very, very, very, very unlikely the jackpot will be won due to the small amount of tickets that will actually be bought. I'll think of something. :)
  13. Notice anything there... using mysql_fetch_assoc is the same as using $db->fetch_row i really do wish people would read things they code in. I know this. :) I just use mysql_fetch_assoc in my mods so it's easier for others to convert to V1 or Lite. I know they could probably do a simple find and replace in their editor, but it's still easier. Also, my editor changes the colour of the mysql functions, so it helps me notice if I've misspelled one. :)
  14. Nicely done! I like using JQuery. There's just something satisfying seeing an image (or text) slide and fade away. :) This mod will be perfect for those with item images. :D
  15. I'm currently learning Python at University. It's relatively easy to use/program in once you learn. It's different from most languages in the fact that you don't need a delimiter. An example in PHP and Python:   PHP print "Hello world.";   Python print "Hello world."   Also, indentation is vital in Python. But as I say, it's a nice language. (Bet I won't be saying that in a couple of weeks when I need to create a game using PyGame. :S )   As stated above by several others, it's best to decide what you specifically want to do, and then decide how you want to do it. :)
  16. You haven't installed it correctly if you're receiving those errors. It seems like the tables, specifically lotteryDetails and lotteryTickets, aren't in your database. Make sure they are. I can't think of another reason as to why those errors would occur.
  17. Thanks for all of your thoughts. I've not had time to work on this yet, unfortunately. But hopefully I will be able to soon. :)
  18. Again, this is an alternative. Put not every user checks the forums. This'll be like the mail, events and announcements...the link in the menu will display the number of new updates. So users are immediately informed of new updates. I guess you could add the update in the forum and then post an announcement, but that's twice as much work. ;)
  19. You could replace the first three lines: <?php $name=$ip." Website Visitor : "; //The name of the user   with:   <?php include_once(DIRNAME(__FILE__) ."/globals.php"); $name=$ir['username']; //The name of the user   Not sure if that will work, but it should do....
  20. Yeah, true. But they don't use JQuery...I don't think. :) Very true. This will be used as part of a 'portfolio' so others can see examples of my work. I don't think the lottery alone will do. :)
  21. I think one has already been made. So there would be no point. Really, this is just a remake of the announcements. The announcements feature is pretty poor anyway...well, the default one anyway. So it's just going to be a nice revamp.
  22. Yeah, essentially. But it'll focus more on the game updates rather than news. So donator specials, warnings, down-time notifcations, etc won't be made using this. This would primarily be for admins to inform users about the game updates, and possibly allow them to comment on it. :)
  23. Hi all. Hope you are all well. I was thinking of making an updates page where the admins (or any other staff level) can inform the other users what updates have been added to the game. I know it seems pretty simple, but I will be attempting to do it all using JQuery/AJAX. I'm also considering adding a feature so users can comment on the updates with their opinions of the feature, etc. This feature will also be made using JQuery, so virtually no refreshing will be needed. Please let me know what you think of this idea. :) Cheers, War_Hero
  24. This is a good little feature, but I did notice something: you're not checking to see if the $_GET['id'] contains a valid userid. After $p=$db->query("SELECT * FROM users WHERE userid={$_GET['ID']}"); you should add in: if($db->num_rows($p) == 0) { print "That user does not exist!"; $h->endpage(); exit(); } else { and then run the rest of the code. Just a bit of error checking. :)
  25. Thank you for clearing that up for me. I had a slight feeling it was one of the 'add this and you will secure your site' sort of things. So anyone experiencing any problems with this feature, please comment out the header code with the $val and see if the lottery works. Please let me know how it goes. :)
×
×
  • Create New...