$pagerow["babblebox"]="<div class=\"big\"><b>Guild Babblebox</b></div>\n<iframe src=\"index.php?do=babblebox&g=".$userrow["guild"]."\" name=\"sbox\" width=\"100%\" height=\"200\" frameborder=\"0\" id=\"bbox\">Your browser does not support inline frames! The Babble Box will not be available until you upgrade to a newer <a href=\"http://www.mozilla.org\" target=\"_new\">browser</a>.</iframe>";
if($userrow["gold"]<$controlrow["guildstartup"]){err("You do not have enough gold to create a Guild. Starting your own Guild requires ".number_format($controlrow["guildstartup"])." gold. Please <a href=\"index.php\">go back</a> and try again.");}
if($userrow["guild"]!=0){err("You are already a member of another Guild. You must renounce your current membership before starting your own Guild. Please <a href=\"index.php\">go back</a> and try again.");}
$appquery=doquery("SELECT * FROM {{table}} WHERE charid='".$userrow["id"]."' LIMIT 1","guildapps");
if(mysql_num_rows($appquery)!=0){err("You have already applied to join another Guild. Please <a href=\"index.php\">go back</a> and try again.");}
if($userrow["level"]<$controlrow["guildstartlvl"]){err("You cannot join a guild until you are at least Level ".$controlrow["guildstartlvl"].". Please continue playing until you make Level 10, then try again.");}
if(preg_match("/[^A-z\ 0-9_\-]/",$name)==1){$errors++;$errorlist.="Guild names can only contain letters, numbers, spaces and hyphens.<br />";}// Thanks to "Carlos Pires" from php.net!
if(preg_match("/[^A-z\ 0-9_\-]/",$rank1)==1){$errors++;$errorlist.="Rank 1 can only contain letters, numbers, spaces and hyphens.<br />";}// Thanks to "Carlos Pires" from php.net!
if(preg_match("/[^A-z\ 0-9_\-]/",$rank2)==1){$errors++;$errorlist.="Rank 2 can only contain letters, numbers, spaces and hyphens.<br />";}// Thanks to "Carlos Pires" from php.net!
if(preg_match("/[^A-z\ 0-9_\-]/",$rank3)==1){$errors++;$errorlist.="Rank 3 can only contain letters, numbers, spaces and hyphens.<br />";}// Thanks to "Carlos Pires" from php.net!
if(preg_match("/[^A-z\ 0-9_\-]/",$rank4)==1){$errors++;$errorlist.="Rank 4 can only contain letters, numbers, spaces and hyphens.<br />";}// Thanks to "Carlos Pires" from php.net!
if(preg_match("/[^A-z\ 0-9_\-]/",$rank5)==1){$errors++;$errorlist.="Rank 5 can only contain letters, numbers, spaces and hyphens.<br />";}// Thanks to "Carlos Pires" from php.net!
if(preg_match("/[^A-z0-9_\-]/",$tagline)==1){$errors++;$errorlist.="Guild taglines must be alphanumeric.<br />";}// Thanks to "Carlos Pires" from php.net!
if(trim($name)==""){$errors++;$errorlist.="Guild name is required.<br />";}
if(trim($tagline)==""){$errors++;$errorlist.="Tagline is required.<br />";}
if(trim($color1)=="#"){$errors++;$errorlist.="Tagline color is required.<br />";}
if(strlen($color1)<7){$errors++;$errorlist.="Tagline color must be 7 characters long.<br />";}
if(trim($color2)=="#"){$errors++;$errorlist.="Name color is required.<br />";}
if(strlen($color2)<7){$errors++;$errorlist.="Name color must be 7 characters long.<br />";}
if(trim($joincost)==""){$errors++;$errorlist.="Cost to join is required.<br />";}
if(!is_numeric($joincost)){$errors++;$errorlist.="Cost to join must be a number.<br />";}
if(trim($rank1)==""){$errors++;$errorlist.="Rank 1 is required.<br />";}
if(trim($rank2)==""){$errors++;$errorlist.="Rank 2 is required.<br />";}
if(trim($rank3)==""){$errors++;$errorlist.="Rank 3 is required.<br />";}
if(trim($rank4)==""){$errors++;$errorlist.="Rank 4 is required.<br />";}
if(trim($rank5)==""){$errors++;$errorlist.="Rank 5 is required.<br />";}
$query=doquery("INSERT INTO {{table}} SET $querystring","guilds");
// Now update the Founder's userrow.
$query=doquery("UPDATE {{table}} SET gold=gold-".$controlrow["guildstartup"].", guild='".mysql_insert_id()."',guildrank='5',guildtag='$tagline',tagcolor='$color1',namecolor='$color2' WHERE id='".$userrow["id"]."' LIMIT 1","users");
// And we're done.
display("Create a Guild","Your guild was successfully created.<br /><br />You may now return to <a href=\"index.php\">the game</a>.");
}else{
// Die gracefully on errors.
err("The following error(s) occurred when your account was being made:<br /><span style=\"color:red;\">$errorlist</span><br />Please <a href=\"users.php?do=register\">go back</a> and try again.");
display("Create a Guild",parsetemplate(gettemplate("guild_create"),$row));
}
functionguildedit(){
global$userrow;
$guild=dorow(doquery("SELECT * FROM {{table}} WHERE id='".$userrow["guild"]."' LIMIT 1","guilds"));
// Errors.
if($userrow["guildrank"]<5){err("You do not have permission to edit the Guild settings. Please <a href=\"index.php\">go back</a> and try again.");}
if(isset($_POST["submit"])){
extract($_POST);
// Errors.
$errors=0;$errorlist="";
if(preg_match("/[^A-z\ 0-9_\-]/",$rank1)==1){$errors++;$errorlist.="Rank 1 can only contain letters, numbers, spaces and hyphens.<br />";}// Thanks to "Carlos Pires" from php.net!
if(preg_match("/[^A-z\ 0-9_\-]/",$rank2)==1){$errors++;$errorlist.="Rank 2 can only contain letters, numbers, spaces and hyphens.<br />";}// Thanks to "Carlos Pires" from php.net!
if(preg_match("/[^A-z\ 0-9_\-]/",$rank3)==1){$errors++;$errorlist.="Rank 3 can only contain letters, numbers, spaces and hyphens.<br />";}// Thanks to "Carlos Pires" from php.net!
if(preg_match("/[^A-z\ 0-9_\-]/",$rank4)==1){$errors++;$errorlist.="Rank 4 can only contain letters, numbers, spaces and hyphens.<br />";}// Thanks to "Carlos Pires" from php.net!
if(preg_match("/[^A-z\ 0-9_\-]/",$rank5)==1){$errors++;$errorlist.="Rank 5 can only contain letters, numbers, spaces and hyphens.<br />";}// Thanks to "Carlos Pires" from php.net!
//if (preg_match("/#[a-fA-F0-9]/", $color1)==1) { $errors++; $errorlist .= "Tagline color does not appear to be a valid HTML color code.<br />"; }
//if (preg_match("/#[a-fA-F0-9]/", $color2)==1) { $errors++; $errorlist .= "Name color does not appear to be a valid HTML color code.<br />"; }
if(trim($color1)=="#"){$errors++;$errorlist.="Tagline color is required.<br />";}
if(strlen($color1)!=7){$errors++;$errorlist.="Tagline color must be 7 characters long.<br />";}
if(trim($color2)=="#"){$errors++;$errorlist.="Name color is required.<br />";}
if(strlen($color2)!=7){$errors++;$errorlist.="Name color must be 7 characters long.<br />";}
if(trim($joincost)==""){$errors++;$errorlist.="Cost to join is required.<br />";}
if(!is_numeric($joincost)){$errors++;$errorlist.="Cost to join must be a number.<br />";}
if(trim($rank1)==""){$errors++;$errorlist.="Rank 1 is required.<br />";}
if(trim($rank2)==""){$errors++;$errorlist.="Rank 2 is required.<br />";}
if(trim($rank3)==""){$errors++;$errorlist.="Rank 3 is required.<br />";}
if(trim($rank4)==""){$errors++;$errorlist.="Rank 4 is required.<br />";}
if(trim($rank5)==""){$errors++;$errorlist.="Rank 5 is required.<br />";}
// Should be fine. Go on and create it.
if($errors==0){
$querystring="";
unset($_POST["submit"]);
foreach($_POSTas$a=>$b){
$querystring.="$a='$b',";
}
$querystring.="id=id";
$query=doquery("UPDATE {{table}} SET $querystring WHERE id='".$guild["id"]."'","guilds");
$updatemem=doquery("UPDATE {{table}} SET namecolor='$color2', tagcolor='$color1' WHERE guild='".$guild["id"]."'","users");
// And we're done.
display("Edit Guild","Your guild was successfully edited.<br /><br />You may now return to <a href=\"index.php\">town</a> or to your <a href=\"index.php?do=guildhome\">Guild Hall</a>.");
}else{
// Die gracefully on errors.
err("The following error(s) occurred when your account was being made:<br /><span style=\"color:red;\">$errorlist</span><br />Please <a href=\"users.php?do=register\">go back</a> and try again.");
if(!is_numeric($id)){err("Invalid input. Please <a href=\"index.php\">go back</a> and try again.");}
$guild=dorow(doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1","guilds"));
if($guild==false){err("Invalid input. Please <a href=\"index.php\">go back</a> and try again.");}
// Errors.
if($userrow["gold"]<$guild["joincost"]){err("You do not have enough gold to join this Guild. Joining this Guild requires ".number_format($guild["joincost"])." gold. Please <a href=\"index.php\">go back</a> and try again.");}
if($userrow["guild"]!=0){err("You are already a member of another Guild. You must renounce your current membership before joining this Guild. Please <a href=\"index.php\">go back</a> and try again.");}
$appquery=doquery("SELECT * FROM {{table}} WHERE charid='".$userrow["id"]."' LIMIT 1","guildapps");
if(mysql_num_rows($appquery)!=0){err("You have already applied to join another Guild. Please <a href=\"index.php\">go back</a> and try again.");}
if($userrow["level"]<$controlrow["guildjoinlvl"]){err("You cannot join a guild until you are at least Level ".$controlrow["guildjoinlvl"].". Please continue playing until you make Level 10, then try again.");}
$query=doquery("INSERT INTO {{table}} SET id='',guild='$id',charid='".$userrow["id"]."',charname='".$userrow["charname"]."'","guildapps");
$update=doquery("UPDATE {{table}} SET bank=bank+".$guild["joincost"]." WHERE id='".$guild["id"]."' LIMIT 1","guilds");
$updatemem=doquery("UPDATE {{table}} SET gold=gold-".$guild["joincost"]." WHERE id='".$userrow["id"]."' LIMIT 1","users");
$send=doquery("INSERT INTO {{table}} SET id='', postdate=NOW(), senderid='0', sendername='".$guild["name"]."', recipientid='".$guild["founder"]."', recipientname='Guild Leader', status='0', title='New Guild Application', message='Someone has applied to join your Guild.<br /><br /><b>Do not reply to this message!</b>', gold='0'","messages");
display("Join a Guild","Thank you for applying to this Guild. If the Guild Leader approves your application, you will be notified via the Post Office.<br /><br />You may now return to <a href=\"index.php\">the game</a>.");
$guild=dorow(doquery("SELECT * FROM {{table}} WHERE id='".$userrow["guild"]."' LIMIT 1","guilds"));
if(isset($_POST["out"])){
$member=dorow(doquery("SELECT * FROM {{table}} WHERE id='$charid' LIMIT 1","users"));
// Errors.
if($userrow["guildrank"]<4){err("You do not have permission to distribute Guild funds. Please <a href=\"index.php\">go back</a> and try again.");}
if(!is_numeric($charid)){err("Invalid input. Please <a href=\"index.php\">go back</a> and try again.");}
if(!is_numeric($gold)){err("Invalid input. Please <a href=\"index.php\">go back</a> and try again.");}
if($gold<0){err("You can't send a negative amount of gold. Please <a href=\"index.php\">go back</a> and try again.");}
if($gold>$guild["bank"]){err("Your Guild does not have that much gold in the bank. Please <a href=\"index.php\">go back</a> and try again.");}
if($member==false){err("Invalid input. Please <a href=\"index.php\">go back</a> and try again.");}
if($member["guild"]!=$userrow["guild"]){err("That player is not in your Guild. Please <a href=\"index.php\">go back</a> and try again.");}
if($member["id"]==$userrow["id"]){err("You cannot send Guild money to yourself. Please <a href=\"index.php\">go back</a> and try again.");}
// Do stuff.
$send=doquery("INSERT INTO {{table}} SET id='', postdate=NOW(), senderid='0', sendername='".$guild["name"]."', recipientid='$charid', recipientname='".$member["charname"]."', status='0', title='Money from your Guild', message='Your Guild has sent you money from the Guild Bank.<br /><br /><b>Do not reply to this message!</b>', gold='$gold'","messages");
$update=doquery("UPDATE {{table}} SET bank=bank-$gold WHERE id='".$userrow["guild"]."' LIMIT 1","guilds");
if(!is_numeric($_POST["golddeposit"])){err("Invalid action. Please <a href=\"index.php\">go back</a> and try again.");}
if($_POST["golddeposit"]<1){err("Deposit amount must be greater than 0.");}
if($_POST["golddeposit"]>$userrow["gold"]){err("You do not have that much money in your pocket.");}
// Do stuff.
$update=doquery("UPDATE {{table}} SET bank=bank+".$_POST["golddeposit"]." WHERE id='".$userrow["guild"]."' LIMIT 1","guilds");
$updatemem=doquery("UPDATE {{table}} SET gold=gold-".$_POST["golddeposit"]." WHERE id='".$userrow["id"]."' LIMIT 1","users");
display("Guild Bank","Thank you for depositing money to the Guild Bank.<br /><br />You may now return to <a href=\"index.php\">Town</a> or to your <a href=\"index.php?do=guildhome\">Guild Hall</a>.");
}
}
functionguildpromote(){
global$userrow;
extract($_POST);
$guild=dorow(doquery("SELECT * FROM {{table}} WHERE id='".$userrow["guild"]."' LIMIT 1","guilds"));
$member=dorow(doquery("SELECT * FROM {{table}} WHERE id='$charid' LIMIT 1","users"));
if(isset($_POST["promote"])){
// Errors.
if($userrow["guildrank"]<4){err("You do not have permission to promote members. Please <a href=\"index.php\">go back</a> and try again.");}
if($userrow["guildrank"]==4&&$member["guildrank"]>=3){err("You do not have permission to promote this member any higher. Please <a href=\"index.php\">go back</a> and try again.");}
if($member["guildrank"]==5){err("This member cannot be promoted any higher. Please <a href=\"index.php\">go back</a> and try again.");}
if($member==false){err("Invalid input. Please <a href=\"index.php\">go back</a> and try again.");}
if($member["guild"]!=$userrow["guild"]){err("That player is not in your Guild. Please <a href=\"index.php\">go back</a> and try again.");}
// Do stuff.
$update=doquery("UPDATE {{table}} SET guildrank=guildrank+1 WHERE id='$charid' LIMIT 1","users");
}elseif(isset($_POST["demote"])){
// Errors.
if($userrow["guildrank"]<4){err("You do not have permission to demote members. Please <a href=\"index.php\">go back</a> and try again.");}
if($userrow["guildrank"]==4&&$member["guildrank"]>3){err("You do not have permission to demote this member. Please <a href=\"index.php\">go back</a> and try again.");}
if($member==false){err("Invalid input. Please <a href=\"index.php\">go back</a> and try again.");}
if($member["guild"]!=$userrow["guild"]){err("That player is not in your Guild. Please <a href=\"index.php\">go back</a> and try again.");}
if($member["guildrank"]==1){guildremove();}
// Do stuff.
$update=doquery("UPDATE {{table}} SET guildrank=guildrank-1 WHERE id='$charid' LIMIT 1","users");
}
display("Guild Ranks","Thank you for promoting/demoting this user.<br /><br />You may now return to <a href=\"index.php\">Town</a> or to your <a href=\"index.php?do=guildhome\">Guild Hall</a>.");
}
functionguildapprove(){
global$userrow;
extract($_POST);
$guild=dorow(doquery("SELECT * FROM {{table}} WHERE id='".$userrow["guild"]."' LIMIT 1","guilds"));
$member=dorow(doquery("SELECT * FROM {{table}} WHERE id='$charid' LIMIT 1","users"));
$app=dorow(doquery("SELECT * FROM {{table}} WHERE guild='".$userrow["guild"]."' AND charid='$charid' LIMIT 1","guildapps"));
// Errors.
if($userrow["guildrank"]<4){err("You do not have permission to approve new members. Please <a href=\"index.php\">go back</a> and try again.");}
if($app==false){err("Invalid input. Please <a href=\"index.php\">go back</a> and try again.");}
// Do stuff.
if(isset($_POST["approve"])){
$updatemem=doquery("UPDATE {{table}} SET guild='".$userrow["guild"]."', guildrank='1', guildtag='".$guild["tagline"]."', tagcolor='".$guild["color1"]."', namecolor='".$guild["color2"]."' WHERE id='".$app["charid"]."' LIMIT 1","users");
$updateguild=doquery("UPDATE {{table}} SET members=members+1 WHERE id='".$userrow["guild"]."' LIMIT 1","guilds");
$deleteapp=doquery("DELETE FROM {{table}} WHERE guild='".$userrow["guild"]."' AND charid='$charid' LIMIT 1","guildapps");
$send=doquery("INSERT INTO {{table}} SET id='', postdate=NOW(), senderid='0', sendername='".$guild["name"]."', recipientid='$charid', recipientname='".$member["charname"]."', status='0', title='Guild Approval', message='The Guild has approved you for membership, and you are now a member of ".$guild["name"].". Congratulations!<br /><br /><b>Do not reply to this message!</b>', gold='0'","messages");
display("Approve Members","Thank you for approving this user.<br /><br />You may now return to <a href=\"index.php\">Town</a> or to your <a href=\"index.php?do=guildhome\">Guild Hall</a>.");
}else{
$deleteapp=doquery("DELETE FROM {{table}} WHERE guild='".$userrow["guild"]."' AND charid='$charid' LIMIT 1","guildapps");
$send=doquery("INSERT INTO {{table}} SET id='', postdate=NOW(), senderid='0', sendername='".$guild["name"]."', recipientid='$charid', recipientname='".$member["charname"]."', status='0', title='Guild Denial', message='The Guild has denied your application for membership. Sorry.<br /><br /><b>Do not reply to this message!</b>', gold='0'","messages");
display("Approve Members","Thank you for denying this user.<br /><br />You may now return to <a href=\"index.php\">Town</a> or to your <a href=\"index.php?do=guildhome\">Guild Hall</a>.");
}
}
functionguildremove(){
global$userrow;
extract($_POST);
$guild=dorow(doquery("SELECT * FROM {{table}} WHERE id='".$userrow["guild"]."' LIMIT 1","guilds"));
$member=dorow(doquery("SELECT * FROM {{table}} WHERE id='$charid' LIMIT 1","users"));
if(isset($_POST["yes"])){
$update=doquery("UPDATE {{table}} SET members=members-1 WHERE id='".$guild["id"]."' LIMIT 1","guilds");
$updatemem=doquery("UPDATE {{table}} SET guild='0', guildrank='0', guildtag='', tagcolor='', namecolor='' WHERE id='$charid' LIMIT 1","users");
$send=doquery("INSERT INTO {{table}} SET id='', postdate=NOW(), senderid='0', sendername='".$guild["name"]."', recipientid='$charid', recipientname='".$member["charname"]."', status='0', title='Guild Removal', message='The Guild has removed you from their membership. Sorry.<br /><br /><b>Do not reply to this message!</b>', gold='0'","messages");
display("Remove Members","Thank you for removing this user.<br /><br />You may now return to <a href=\"index.php\">Town</a> or to your <a href=\"index.php?do=guildhome\">Guild Hall</a>.");
$guild=dorow(doquery("SELECT * FROM {{table}} WHERE id='".$userrow["guild"]."' LIMIT 1","guilds"));
// Errors.
if($userrow["guildrank"]<5){err("You do not have permission to edit Guild news. Please <a href=\"index.php\">go back</a> and try again.");}
if(isset($_POST["submit"])){
$query=doquery("UPDATE {{table}} SET news='".$_POST["news"]."' WHERE id='".$userrow["guild"]."' LIMIT 1","guilds");
display("Guild News","Thank you for updating your Guild News.<br /><br />You may now return to <a href=\"index.php\">Town</a> or to your <a href=\"index.php?do=guildhome\">Guild Hall</a>.");
$guild=dorow(doquery("SELECT * FROM {{table}} WHERE id='".$userrow["guild"]."' LIMIT 1","guilds"));
// Errors.
if($userrow["id"]!=$guild["founder"]){err("You do not have permission to disband the Guild. Please <a href=\"index.php\">go back</a> and try again.");}
$guildmembers=dorow(doquery("SELECT * FROM {{table}} WHERE guild='".$guild["id"]."'","users"),"id");
foreach($guildmembersas$a=>$b){
$send=doquery("INSERT INTO {{table}} SET id='', postdate=NOW(), senderid='0', sendername='".$guild["name"]."', recipientid='".$b["id"]."', recipientname='".$b["charname"]."', status='0', title='Guild Disbanded', message='Your Guild leader has chosen to disband the guild. Your member status has been reset, and you can now apply to join another guild if you wish.<br /><br /><b>Do not reply to this message!</b>', gold='0'","messages");