Guest User

Untitled

a guest
Mar 13th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 179.41 KB | None | 0 0
  1. <img id="ContentBoxHeadline" class="Title" src="layouts/tibiacom/images/header/headline-guilds.gif" alt="Contentbox headline">
  2. <?php
  3. if(!defined('INITIALIZED'))
  4.     exit;
  5.  
  6. if($action == 'login')
  7. {
  8.     if(check_guild_name($_REQUEST['guild']))
  9.         $guild = $_REQUEST['guild'];
  10.     if($_REQUEST['redirect'] == 'guild' || $_REQUEST['redirect'] == 'guilds')
  11.         $redirect = $_REQUEST['redirect'];
  12.     if(!$logged)
  13.     {
  14.         $main_content .= 'Please enter your account number and your password.<br/><a href="?subtopic=createaccount" >Create an account</a> if you do not have one yet.<br/><br/><form action="?subtopic=guilds&action=login&guild='.urlencode($guild).'&redirect='.$redirect.'" method="post" ><div class="TableContainer" >  <table class="Table1" cellpadding="0" cellspacing="0" >    <div class="CaptionContainer" >      <div class="CaptionInnerContainer" >        <span class="CaptionEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionBorderTop" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <div class="Text" >Account Login</div>        <span class="CaptionVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <span class="CaptionBorderBottom" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>      </div>    </div>    <tr>      <td>        <div class="InnerTableContainer" >          <table style="width:100%;" ><tr><td class="LabelV" ><span >Account Number:</span></td><td style="width:100%;" ><input type="password" name="account_login" SIZE="10" maxlength="10" ></td></tr><tr><td class="LabelV" ><span >Password:</span></td><td><input type="password" name="password_login" size="30" maxlength="29" ></td></tr>          </table>        </div>  </table></div></td></tr><br/><table width="100%" ><tr align="center" ><td><table border="0" cellspacing="0" cellpadding="0" ><tr><td style="border:0px;" ><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Submit" alt="Submit" src="'.$layout_name.'/images/buttons/_sbutton_submit.gif" ></div></div></td><tr></form></table></td><td><table border="0" cellspacing="0" cellpadding="0" ><form action="?subtopic=lostaccount" method="post" ><tr><td style="border:0px;" ><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Account lost?" alt="Account lost?" src="'.$layout_name.'/images/buttons/_sbutton_accountlost.gif" ></div></div></td></tr></form></table></td></tr></table>';
  15.     }
  16.     else
  17.     {
  18.         $main_content .= '<center><h3>Now you are logged. Redirecting...</h3></center>';
  19.         if($redirect == 'guilds')
  20.             header("Location: ?subtopic=guilds");
  21.         elseif($redirect == 'guild')
  22.             header("Location: ?subtopic=guilds&action=show&guild=".urlencode($guild));
  23.         else
  24.             $main_content .= 'Wrong address to redirect!';
  25.     }
  26. }
  27. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  28. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  29. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  30. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  31. //show list of guilds
  32. if($action == '')
  33. {
  34.     $world_name = $config['server']['serverName'];
  35.    
  36.     $guilds_list = new DatabaseList('Guild');
  37.     $guilds_list->addOrder(new SQL_Order(new SQL_Field('name'), SQL_Order::ASC));
  38.    
  39.     $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>
  40.     <center>
  41. <font size="3" color="black"><b><u>Inviting for Guild War</b></u></font>
  42.  
  43. </center>
  44. <br />
  45. <center><font size="3" color="black">To invite your opponent, you just need to be a Guild Leader and be logged on game, done that, in this same page below, <u>search for your own guild</u> and in the right side click "view",</font> <font size="3" color="black">then in the page that will opens click "START WAR" and after choose your opponent.<br />
  46. <b>The Wars will last 5 hours with unlimited frags.</b> </font><br />
  47.  
  48. <br />
  49.     <TR BGCOLOR='.$config['site']['vdarkborder'].'><TD COLSPAN=3 CLASS=white><B>Guilds on '.htmlspecialchars($world_name).'</B></TD></TR>
  50.     <TR BGCOLOR='.$config['site']['darkborder'].'><TD WIDTH=64><B>Logo</B></TD>
  51.     <TD WIDTH=100%><B>Description</B></TD>
  52.     <TD WIDTH=56><B>&#160;</B></TD></TR>';
  53.     $showed_guilds = 1;
  54.     if(count($guilds_list) > 0)
  55.     {
  56.         foreach($guilds_list as $guild)
  57.         {
  58.             if(is_int($showed_guilds / 2)) { $bgcolor = $config['site']['darkborder']; } else { $bgcolor = $config['site']['lightborder']; } $showed_guilds++;
  59.             $description = $guild->getDescription();
  60.             $newlines   = array("\r\n", "\n", "\r");
  61.             $description_with_lines = str_replace($newlines, '<br />', $description, $count);
  62.             if($count < $config['site']['guild_description_lines_limit'])
  63.                 $description = $description_with_lines;
  64.             $main_content .= '<TR BGCOLOR="'.$bgcolor.'"><TD><IMG SRC="'. $guild->getGuildLogoLink() .'" WIDTH=64 HEIGHT=64></TD>
  65.             <TD valign="top"><B>'.htmlspecialchars($guild->getName()).'</B><BR/>'.$description.'';
  66.             if($group_id_of_acc_logged >= $config['site']['access_admin_panel'])
  67.                 $main_content .= '<br /><a href="?subtopic=guilds&action=deletebyadmin&guild='.$guild->getId().'">Delete this guild (for ADMIN only!)</a>';
  68.             $main_content .= '</TD><TD><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild->getId().'" METHOD=post><TR><TD>
  69.             <INPUT TYPE=image NAME="View" ALT="View" SRC="'.$layout_name.'/images/buttons/sbutton_view.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  70.             </TD></TR></FORM></TABLE>
  71.             </TD></TR>';
  72.         }
  73.     }
  74.     else
  75.         $main_content .= '<TR BGCOLOR='.$config['site']['lightborder'].'><TD><IMG SRC="images/default_guild_logo.gif" WIDTH=64 HEIGHT=64></TD>
  76.         <TD valign="top"><B>Create guild</B><BR/>Currently there is no guild on server. Create first! Press button "Create Guild".</TD>
  77.         <TD><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds&action=createguild" METHOD=post><TR><TD>
  78.         <INPUT TYPE=image NAME="Create Guild" ALT="Create Guild" SRC="'.$layout_name.'/images/buttons/sbutton_createguild.png" BORDER=0 WIDTH=120 HEIGHT=18>
  79.         </TD></TR></FORM></TABLE></TD></TR>';
  80.     $main_content .= '</TABLE><br><br>';
  81.     if($logged)
  82.         $main_content .= '<TABLE BORDER=0 WIDTH=100%><TR><TD ALIGN=center><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=80 HEIGHT=1 BORDER=0<BR></TD><TD ALIGN=center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds&action=createguild" METHOD=post><TR><TD>
  83.         <INPUT TYPE=image NAME="Create Guild" ALT="Create Guild" SRC="'.$layout_name.'/images/buttons/sbutton_createguild.png" BORDER=0 WIDTH=120 HEIGHT=18>
  84.         </TD></TR></FORM></TABLE></TD><TD ALIGN=center><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=80 HEIGHT=1 BORDER=0<BR></TD></TR></TABLE>
  85.         <BR />If you have any problem with guilds try:
  86.         <BR /><a href="?subtopic=guilds&action=cleanup_players">Cleanup players</a> - can\'t join guild/be invited? Can\'t create guild? Try cleanup players.';
  87.     else
  88.         $main_content .= 'Before you can create guild you must login.<br><TABLE BORDER=0 WIDTH=100%><TR><TD ALIGN=center><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=80 HEIGHT=1 BORDER=0<BR></TD><TD ALIGN=center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds&action=login&redirect=guilds" METHOD=post><TR><TD>
  89.         <INPUT TYPE=image NAME="Login" ALT="Login" SRC="'.$layout_name.'/images/buttons/sbutton_login.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  90.         </TD></TR></FORM></TABLE></TD><TD ALIGN=center><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=80 HEIGHT=1 BORDER=0<BR></TD></TR></TABLE>';
  91. }
  92. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  93. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  94. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  95. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  96. //show guild page
  97. if($action == 'show')
  98. {
  99.     $guild_id = (int) $_REQUEST['guild'];
  100.     $guild = new Guild();
  101.     $guild->load($guild_id);
  102.     if(!$guild->isLoaded())
  103.         $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  104.     if(!empty($guild_errors))
  105.     {
  106.         //show errors
  107.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  108.         foreach($guild_errors as $guild_error)
  109.             $main_content .= '<li>'.$guild_error;
  110.         //errors and back button
  111.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br/><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  112.     }
  113.     else
  114.     {
  115.         //check is it vice or/and leader account (leader has vice + leader rights)
  116.         $guild_leader_char = $guild->getOwner();
  117.         $rank_list = $guild->getGuildRanksList();
  118.         $guild_leader = FALSE;
  119.         $guild_vice = FALSE;
  120.         if($logged)
  121.         {
  122.             $account_players = $account_logged->getPlayers();
  123.             foreach($account_players as $player)
  124.             {
  125.                 $players_from_account_ids[] = $player->getId();
  126.                 $player_rank = $player->getRank();
  127.                 if(!empty($player_rank))
  128.                     foreach($rank_list as $rank_in_guild)
  129.                         if($rank_in_guild->getId() == $player_rank->getId())
  130.                         {
  131.                             $players_from_account_in_guild[] = $player->getName();
  132.                             if($player_rank->getLevel() > 1)
  133.                             {
  134.                                 $guild_vice = TRUE;
  135.                                 $level_in_guild = $player_rank->getLevel();
  136.                             }
  137.                             if($guild->getOwner()->getId() == $player->getId())
  138.                             {
  139.                                 $guild_vice = TRUE;
  140.                                 $guild_leader = TRUE;
  141.                             }
  142.                         }
  143.             }
  144.         }
  145.         //show guild page
  146.         $description = $guild->getDescription();
  147.         $newlines   = array("\r\n", "\n", "\r");
  148.         $description_with_lines = str_replace($newlines, '<br />', $description, $count);
  149.         if($count < $config['site']['guild_description_lines_limit'])
  150.             $description = $description_with_lines;
  151.         $guild_owner = $guild->getOwner();
  152.         if($guild_owner->isLoaded())
  153.             $guild_owner = $guild_owner->getName();
  154.         $main_content .= '<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR>
  155.         <TD><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=10 HEIGHT=1 BORDER=0></TD><TD>
  156.         <TABLE BORDER=0 WIDTH=100%>
  157.         <TR><TD WIDTH=64><IMG SRC="' . $guild->getGuildLogoLink() . '" WIDTH=64 HEIGHT=64></TD>
  158.         <TD ALIGN=center WIDTH=100%><H1>'.htmlspecialchars($guild->getName()).'</H1></TD>
  159.         <TD WIDTH=64><IMG SRC="' . $guild->getGuildLogoLink() . '" WIDTH=64 HEIGHT=64></TD></TR>
  160.         </TABLE><BR>'.$description.'<BR><BR><a href="?subtopic=characters&name='.urlencode($guild_owner).'"><b>'.htmlspecialchars($guild_owner).'</b></a> is guild leader of <b>'.htmlspecialchars($guild->getName()).'</b>.<BR>The guild was founded on '.htmlspecialchars($config['server']['serverName']).' on '.date("j F Y", $guild->getCreationData()).'.';
  161.         if($guild_leader)
  162.             $main_content .= '&nbsp;&nbsp;&nbsp;<a href="?subtopic=guilds&action=manager&guild='.$guild_id.'"><IMG SRC="'.$layout_name.'/images/buttons/sbutton_manageguild.png" BORDER=0 WIDTH=120 HEIGHT=18 alt="Manage Guild"></a>';
  163.         $main_content .= '<BR><BR>
  164.         <TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>
  165.         <TR BGCOLOR='.$config['site']['vdarkborder'].'><TD COLSPAN=3 CLASS=white><B>Guild Members</B></TD></TR>
  166.         <TR BGCOLOR='.$config['site']['darkborder'].'><TD WIDTH=30%><B>Rank</B></TD>
  167.         <TD WIDTH=70%><B>Name and Title</B></TD></TR>';
  168.         $showed_players = 1;
  169.         foreach($rank_list as $rank)
  170.         {
  171.             $players_with_rank = $rank->getPlayersList();
  172.             $players_with_rank_number = count($players_with_rank);
  173.             if($players_with_rank_number > 0)
  174.             {
  175.                 if(is_int($showed_players / 2)) { $bgcolor = $config['site']['darkborder']; } else { $bgcolor = $config['site']['lightborder']; } $showed_players++;
  176.                 $main_content .= '<TR BGCOLOR="'.$bgcolor.'"><TD valign="top">'.htmlspecialchars($rank->getName()).'</TD>
  177.                 <TD><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>';
  178.                 foreach($players_with_rank as $player)
  179.                 {
  180.                     $main_content .= '<TR><TD><FORM ACTION="?subtopic=guilds&action=change_nick&name='.urlencode($player->getName()).'" METHOD="post"><A HREF="?subtopic=characters&name='.urlencode($player->getName()).'">'.($player->isOnline() ? "<font color=\"green\">".htmlspecialchars($player->getName())."</font>" : "<font color=\"red\">".htmlspecialchars($player->getName())."</font>").'</A>';
  181.                     $guild_nick = $player->getGuildNick();
  182.                     if($logged)
  183.                         if(in_array($player->getId(), $players_from_account_ids))
  184.                             $main_content .= '(<input type="text" name="nick" value="'.htmlspecialchars($player->getGuildNick()).'"><input type="submit" value="Change">)';
  185.                         else
  186.                         if(!empty($guild_nick))
  187.                             $main_content .= ' ('.htmlspecialchars($player->getGuildNick()).')';
  188.                     else
  189.                         if(!empty($guild_nick))
  190.                             $main_content .= ' ('.htmlspecialchars($player->getGuildNick()).')';
  191.                     if($level_in_guild > $rank->getLevel() || $guild_leader)
  192.                         if($guild_leader_char->getName() != $player->getName())
  193.                             $main_content .= '&nbsp;<font size=1>{<a href="?subtopic=guilds&action=kickplayer&guild='.$guild->getId().'&name='.urlencode($player->getName()).'">KICK</a>}</font>';
  194.                     $main_content .= '</FORM></TD></TR>';
  195.                 }
  196.                 $main_content .= '</TABLE></TD></TR>';
  197.             }
  198.         }
  199.         $main_content .= '</TABLE>';
  200.         $invited_list = $guild->listInvites();
  201.         if(count($invited_list) == 0)
  202.             $main_content .= '<BR><BR><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD COLSPAN=2 CLASS=white><B>Invited Characters</B></TD></TR><TR BGCOLOR='.$config['site']['lightborder'].'><TD>No invited characters found.</TD></TR></TABLE>';
  203.         else
  204.         {
  205.             $main_content .= '<BR><BR><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD COLSPAN=2 CLASS=white><B>Invited Characters</B></TD></TR>';
  206.             $show_accept_invite = 0;
  207.             $showed_invited = 1;
  208.             foreach($invited_list as $invited_player)
  209.             {
  210.                 if(count($account_players) > 0)
  211.                     foreach($account_players as $player_from_acc)
  212.                         if($player_from_acc->getName() == $invited_player->getName())
  213.                             $show_accept_invite++;
  214.                 if(is_int($showed_invited / 2)) { $bgcolor = $config['site']['darkborder']; } else { $bgcolor = $config['site']['lightborder']; } $showed_invited++;
  215.                 $main_content .= '<TR bgcolor="'.$bgcolor.'"><TD><a href="?subtopic=characters&name='.urlencode($invited_player->getName()).'">'.htmlspecialchars($invited_player->getName()).'</a>';
  216.                 if($guild_vice)
  217.                     $main_content .= '  (<a href="?subtopic=guilds&action=deleteinvite&guild='.$guild_id.'&name='.urlencode($invited_player->getName()).'">Cancel Invitation</a>)';
  218.                 $main_content .= '</TD></TR>';
  219.             }
  220.             $main_content .= '</TABLE>';
  221.         }
  222.  
  223.         $main_content .= "<h3 align=\"center\">Guild Wars</h3>";
  224.         if($logged)
  225.         {
  226.             $main_content .= '<center><a href="?subtopic=guilds&action=guildwar_choose_enemy&guild=' . $guild_id . '"><b>START WAR</b></a></center><br /><br />';
  227.         }
  228.         $main_content .= "<script type=\"text/javascript\"><!--
  229.         function show_hide(flip)
  230.         {
  231.                 var tmp = document.getElementById(flip);
  232.                 if(tmp)
  233.                         tmp.style.display = tmp.style.display == 'none' ? '' : 'none';
  234.         }
  235.         --></script>
  236.         <table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"4\">
  237.         <tr>
  238.         <td style=\"background: " . $config['site']['vdarkborder'] . "\" class=\"white\" width=\"150\"><b>Aggressor</b></td>
  239.         <td style=\"background: " . $config['site']['vdarkborder'] . "\" class=\"white\"><b>Information</b></td>
  240.         <td style=\"background: " . $config['site']['vdarkborder'] . "\" class=\"white\" width=\"150\"><b>Enemy</b></td>
  241.         </tr>";
  242.          
  243.         $warFrags = array();
  244.         foreach($SQL->query('SELECT * FROM `guildwar_kills` WHERE `killerguild` = ' . $guild_id . ' OR `targetguild` = ' . $guild_id . ' ORDER BY `time` DESC')->fetchAll() as $frag)
  245.         {
  246.             $warFrags[$frag['warid']][] = $frag;
  247.         }
  248.  
  249.         $count = 0;
  250.         foreach($SQL->query('SELECT `guild_wars`.`id`, `guild_wars`.`guild1`, `guild_wars`.`guild2`, `guild_wars`.`name1`, `guild_wars`.`name2`, `guild_wars`.`status`, `guild_wars`.`started`, `guild_wars`.`ended`, (SELECT COUNT(1) FROM `guildwar_kills` WHERE `guildwar_kills`.`warid` = `guild_wars`.`id` AND `guildwar_kills`.`killerguild` = `guild_wars`.`guild1`) guild1_kills, (SELECT COUNT(1) FROM `guildwar_kills` WHERE `guildwar_kills`.`warid` = `guild_wars`.`id` AND `guildwar_kills`.`killerguild` = `guild_wars`.`guild2`) guild2_kills FROM `guild_wars` WHERE `guild1` = ' . $guild_id . ' OR `guild2` = ' . $guild_id . ' ORDER BY CASE `status` WHEN 0 THEN 2 WHEN 1 THEN 1 WHEN 4 THEN 3 WHEN 3 THEN 4 WHEN 2 THEN 5 END, `started` DESC') as $war)
  251.         {
  252.             $count++;
  253.             $main_content .= "<tr style=\"background: " . (is_int($count / 2) ? $config['site']['darkborder'] : $config['site']['lightborder']) . ";\">
  254.         <td align=\"center\"><a href=\"?subtopic=guilds&action=show&guild=".$war['guild1']."\"><img src=\"guild_image.php?id=" . $war['guild1'] . "\" width=\"64\" height=\"64\" border=\"0\"/><br />".htmlspecialchars($war['name1'])."</a></td>
  255.         <td class=\"white\" align=\"center\">";
  256.             switch($war['status'])
  257.             {
  258.                 case 0:
  259.                 {
  260.                     $main_content .= "<font color=black><b>Pending acceptation</b><br />Invited on " . date("M d Y, H:i:s", $war['started']) . " for 2 hours war.<br />";
  261.                     if($guild_leader && $war['guild2'] == $guild->getID())
  262.                     {
  263.                         $main_content .= '<br /><a href="?subtopic=guilds&action=guildwar_invitation_accept&guild=' . $guild_id . '&war=' . $war['id'] . '" onclick="return confirm(\'Are you sure that you want ACCEPT that invitation for 2 hours war?\');" style="cursor: pointer;">&raquo; Click here to <span style="color: lime;">accept</span> invitation to war &laquo;</a>';
  264.                         $main_content .= '<br /><br /><a href="?subtopic=guilds&action=guildwar_invitation_reject&guild=' . $guild_id . '&war=' . $war['id'] . '" onclick="return confirm(\'Are you sure that you want REJECT that invitation for 2 hours war?\');" style="cursor: pointer;">&raquo; Click here to <span style="color: darkred;">reject</span> invitation to war &laquo;</a>';
  265.                     }
  266.                     if($guild_leader && $war['guild1'] == $guild->getID())
  267.                     {
  268.                         $main_content .= '<br /><br /><a href="?subtopic=guilds&action=guildwar_invitation_cancel&guild=' . $guild_id . '&war=' . $war['id'] . '" onclick="return confirm(\'Are you sure that you want CANCEL that invitation for 2 hours war?\');" style="cursor: pointer;">&raquo; Click here to <span style="color: darkred;">cancel</span> invitation to war &laquo;</a>';
  269.                     }
  270.                     $main_content .= '</font>';
  271.                     break;
  272.                 }
  273.                 case 1:
  274.                 {
  275.                     $main_content .= "<font size=\"12\"><span style=\"color: red;\">" . $war['guild1_kills'] . "</span><font color=black> : </font><span style=\"color: lime;\">" . $war['guild2_kills'] . "</span></font><br /><br /><span style=\"color: darkred; font-weight: bold;\">On a brutal war</span><br /><font color=black>Began on " . date("M d Y, H:i:s", $war['started']) . ", will end up after server restart after " . date("M d Y, H:i:s", $war['started'] + (2*3600)) . ".<br /></font>";
  276.                     $main_content .= "<br /><br />";
  277.                     if(in_array($war['status'], array(1,4)))
  278.                     {
  279.                         $main_content .= "<a onclick=\"show_hide('war-details:" . $war['id'] . "'); return false;\" style=\"cursor: pointer;\">&raquo; Details &laquo;</a>";
  280.                     }
  281.                     break;
  282.                 }
  283.                 case 2:
  284.                 {
  285.                     $main_content .= "<font color=black><b>Rejected invitation</b><br />Invited on " . date("M d Y, H:i:s", $war['started']) . ", rejected on " . date("M d Y, H:i:s", $war['ended']) . ".</font>";
  286.                     break;
  287.                 }
  288.                 case 3:
  289.                 {
  290.                     $main_content .= "<font color=black><b>Canceled invitation</b><br />Sent invite on " . date("M d Y, H:i:s", $war['started']) . ", canceled on " . date("M d Y, H:i:s", $war['ended']) . ".</font>";
  291.                     break;
  292.                 }
  293.                 case 4:
  294.                 {
  295.                     $main_content .= "<font color=black><b><i>Ended</i></b><br />Began on " . date("M d Y, H:i:s", $war['started']) . ", ended on " . date("M d Y, H:i:s", $war['ended']) . ". Frag statistics: <span style=\"color: red;\">" . $war['guild1_kills'] . "</span> to <span style=\"color: lime;\">" . $war['guild2_kills'] . "</span>.";
  296.                     $main_content .= "<br /><br />";
  297.                     if(in_array($war['status'], array(1,4)))
  298.                     {
  299.                         $main_content .= "<a onclick=\"show_hide('war-details:" . $war['id'] . "'); return false;\" style=\"cursor: pointer;\">&raquo; Details &laquo;</a>";
  300.                     }
  301.                     $main_content .= "</font>";
  302.                     break;
  303.                 }
  304.                 default:
  305.                 {
  306.                     $main_content .= "Unknown, please contact with gamemaster.";
  307.                     break;
  308.                 }
  309.             }
  310.             $main_content .= "</td>
  311.         <td align=\"center\"><a href=\"?subtopic=guilds&action=show&guild=".$war['guild2']."\"><img src=\"guild_image.php?id=" . $war['guild2'] . "\" width=\"64\" height=\"64\" border=\"0\"/><br />".htmlspecialchars($war['name2'])."</a></td>
  312.         </tr>
  313.         <tr id=\"war-details:" . $war['id'] . "\" style=\"display: none; background: " . (is_int($count / 2) ? $config['site']['darkborder'] : $config['site']['lightborder']) . ";\">
  314.         <td colspan=\"3\">";
  315.             if(in_array($war['status'], array(1,4)))
  316.             {
  317.                 if(isset($warFrags[$war['id']]))
  318.                 {
  319.                     foreach($warFrags[$war['id']] as $frag)
  320.                     {
  321.                         $main_content .= date("j M Y, H:i", $frag['time']) . " <span style=\"font-weight: bold; color: " . ($frag['killerguild'] == $war['guild1'] ? "red" :"lime") . ";\">+</span><a href=\"?subtopic=characters&name=" . urlencode($frag['killer']) . "\"><b>".htmlspecialchars($frag['killer'])."</b></a> killed <a href=\"?subtopic=characters&name=".urlencode($frag['target'])."\"> " . htmlspecialchars($frag['target']) . "</a>";
  322.                     }
  323.                 }
  324.                 else
  325.                     $main_content .= "<center>There were no frags on this war so far.</center>";
  326.             }
  327.             else
  328.                 $main_content .= "</td></tr>";
  329.         }
  330.          
  331.         if($count == 0)
  332.             $main_content .= "<tr style=\"background:".$config['site']['darkborder'].";\">
  333.         <td colspan=\"3\">Currently there are no active wars.</td>
  334.         </tr>";
  335.          
  336.         $main_content .= "</table>";
  337.  
  338.         $main_content .= '<BR><BR>
  339.         <TABLE BORDER=0 WIDTH=100%><TR><TD ALIGN=center><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=80 HEIGHT=1 BORDER=0<BR></TD>';
  340.         if(!$logged)
  341.             $main_content .= '<TD ALIGN=center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds&action=login&guild='.$guild_id.'&redirect=guild" METHOD=post><TR><TD>
  342.             <INPUT TYPE=image NAME="Login" ALT="Login" SRC="'.$layout_name.'/images/buttons/sbutton_login.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  343.             </TD></TR></FORM></TABLE></TD>';
  344.         else
  345.         {
  346.             if($show_accept_invite > 0)
  347.                 $main_content .= '<TD ALIGN=center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds&action=acceptinvite&guild='.$guild_id.'" METHOD=post><TR><TD>
  348.                 <INPUT TYPE=image NAME="Accept Invite" ALT="Accept Invite" SRC="'.$layout_name.'/images/buttons/sbutton_acceptinvite.png" BORDER=0 WIDTH=120 HEIGHT=18>
  349.                 </TD></TR></FORM></TABLE></TD>';
  350.             if($guild_vice)
  351.             {
  352.                 $main_content .= '<TD ALIGN=center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds&action=invite&guild='.$guild_id.'" METHOD=post><TR><TD>
  353.                 <INPUT TYPE=image NAME="Invite Player" ALT="Invite Player" SRC="'.$layout_name.'/images/buttons/sbutton_inviteplayer.png" BORDER=0 WIDTH=120 HEIGHT=18>
  354.                 </TD></TR></FORM></TABLE></TD>';
  355.                 $main_content .= '<TD ALIGN=center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds&action=changerank&guild='.$guild_id.'" METHOD=post><TR><TD>
  356.                 <INPUT TYPE=image NAME="Change Rank" ALT="Change Rank" SRC="'.$layout_name.'/images/buttons/sbutton_changerank.png" BORDER=0 WIDTH=120 HEIGHT=18>
  357.                 </TD></TR></FORM></TABLE></TD>';
  358.                
  359.                 $main_content .= '<TD ALIGN=center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds&guild='.$guild_id.'&action=deleteguild" METHOD=post><TR><TD>
  360.                 <INPUT TYPE=image NAME="Delete Guild" ALT="Delete Guild" SRC="'.$layout_name.'/images/buttons/deletarguild.png" BORDER=0 WIDTH=120 HEIGHT=18>
  361.                 </TD></TR></FORM></TABLE></TD>';
  362.             }
  363.             if($players_from_account_in_guild > 0)
  364.                 $main_content .= '<TD ALIGN=center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds&action=leaveguild&guild='.$guild_id.'" METHOD=post><TR><TD>
  365.                 <INPUT TYPE=image NAME="Leave Guild" ALT="Leave Guild" SRC="'.$layout_name.'/images/buttons/sbutton_leaveguild.png" BORDER=0 WIDTH=120 HEIGHT=18>
  366.                 </TD></TR></FORM></TABLE></TD>';
  367.         }
  368.         $main_content .= '<TD ALIGN=center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds" METHOD=post><TR><TD>
  369.         <INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  370.         </TD></TR></FORM></TABLE>
  371.         </TD><TD ALIGN=center><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=80 HEIGHT=1 BORDER=0<BR></TD></TR></TABLE>
  372.         </TD><TD><IMG src="'.$layout_name.'/images/blank.gif" WIDTH=10 HEIGHT=1 BORDER=0></TD>
  373.         </TR></TABLE></TABLE>';
  374.     }
  375. }
  376.  
  377. //--------------------------------------------------------------------------------------------------------------------
  378. //--------------------------------------------------------------------------------------------------------------------
  379. //--------------------------------------------------------------------------------------------------------------------
  380. //--------------------------------------------------------------------------------------------------------------------
  381. //change rank of player in guild
  382. if($action == 'changerank')
  383. {
  384.     $guild_id = (int) $_REQUEST['guild'];
  385.     if(!$logged)
  386.         $guild_errors[] = 'You are not logged in. You can\'t change rank.';
  387.     if(empty($guild_errors))
  388.     {
  389.         $guild = new Guild();
  390.         $guild->load($guild_id);
  391.         if(!$guild->isLoaded())
  392.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  393.     }
  394.     if(!empty($guild_errors))
  395.     {
  396.         //show errors
  397.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  398.         foreach($guild_errors as $guild_error)
  399.             $main_content .= '<li>'.$guild_error;
  400.         //errors and back button
  401.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br/><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  402.     }
  403.     else
  404.     {
  405.     //check is it vice or/and leader account (leader has vice + leader rights)
  406.     $rank_list = $guild->getGuildRanksList();
  407.     $guild_leader = FALSE;
  408.     $guild_vice = FALSE;
  409.     $account_players = $account_logged->getPlayers();
  410.     foreach($account_players as $player)
  411.     {
  412.         $player_rank = $player->getRank();
  413.         if(!empty($player_rank))
  414.             foreach($rank_list as $rank_in_guild)
  415.                 if($rank_in_guild->getId() == $player_rank->getId())
  416.                 {
  417.                     $players_from_account_in_guild[] = $player->getName();
  418.                     if($player_rank->getLevel() > 1) {
  419.                         $guild_vice = TRUE;
  420.                         $level_in_guild = $player_rank->getLevel();
  421.                     }
  422.                     if($guild->getOwner()->getId() == $player->getId()) {
  423.                         $guild_vice = TRUE;
  424.                         $guild_leader = TRUE;
  425.                     }
  426.                 }
  427.     }
  428.     if($guild_vice)
  429.     {
  430.         foreach($rank_list as $rank)
  431.         {
  432.             if($guild_leader || $rank->getLevel() < $level_in_guild)
  433.             {
  434.                 $ranks[$rid]['0'] = $rank->getId();
  435.                 $ranks[$rid]['1'] = $rank->getName();
  436.                 $rid++;
  437.                 $players_with_rank = $rank->getPlayersList();
  438.                 if(count($players_with_rank) > 0)
  439.                 {
  440.                     foreach($players_with_rank as $player)
  441.                     {
  442.                         if($guild->getOwner()->getId() != $player->getId() || $guild_leader)
  443.                         {
  444.                             $players_with_lower_rank[$sid]['0'] = htmlspecialchars($player->getName());
  445.                             $players_with_lower_rank[$sid]['1'] = htmlspecialchars($player->getName()).' ('.htmlspecialchars($rank->getName()).')';
  446.                             $sid++;
  447.                         }
  448.                     }
  449.                 }
  450.             }
  451.         }
  452.         if($_REQUEST['todo'] == 'save')
  453.         {
  454.             $player_name = $_REQUEST['name'];
  455.             $new_rank = (int) $_REQUEST['rankid'];
  456.             if(!check_name($player_name))
  457.                 $change_errors[] = 'Invalid player name format.';
  458.             $rank = new GuildRank();
  459.             $rank->load($new_rank);
  460.             if(!$rank->isLoaded())
  461.                 $change_errors[] = 'Rank with this ID doesn\'t exist.';
  462.             if($level_in_guild <= $rank->getLevel() && !$guild_leader)
  463.                 $change_errors[] = 'You can\'t set ranks with equal or higher level than your.';
  464.             if(empty($change_errors))
  465.             {
  466.                 $player_to_change = new Player();
  467.                 $player_to_change->find($player_name);
  468.                 if(!$player_to_change->isLoaded())
  469.                     $change_errors[] = 'Player with name '.htmlspecialchars($player_name).'</b> doesn\'t exist.';
  470.                 else
  471.                 {
  472.                     $player_in_guild = FALSE;
  473.                     if($guild->getName() == $player_to_change->getRank()->getGuild()->getName() || $guild_leader)
  474.                     {
  475.                         $player_in_guild = TRUE;
  476.                         $player_has_lower_rank = FALSE;
  477.                         if($player_to_change->getRank()->getLevel() < $level_in_guild || $guild_leader)
  478.                             $player_has_lower_rank = TRUE;
  479.                     }
  480.                 }
  481.                 $rank_in_guild = FALSE;
  482.                 foreach($rank_list as $rank_from_guild)
  483.                     if($rank_from_guild->getId() == $rank->getId())
  484.                         $rank_in_guild = TRUE;
  485.                 if(!$player_in_guild)
  486.                 $change_errors[] = 'This player isn\'t in your guild.';
  487.                 if(!$rank_in_guild)
  488.                     $change_errors[] = 'This rank isn\'t in your guild.';
  489.                 if(!$player_has_lower_rank)
  490.                     $change_errors[] = 'This player has higher rank in guild than you. You can\'t change his/her rank.';
  491.             }
  492.             if(empty($change_errors))
  493.             {
  494.                 $player_to_change->setRank($rank);
  495.                 $player_to_change->save();
  496.                 $main_content .= '<div class="TableContainer" >  <table class="Table1" cellpadding="0" cellspacing="0" >    <div class="CaptionContainer" >      <div class="CaptionInnerContainer" >        <span class="CaptionEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionBorderTop" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <div class="Text" >Guild Deleted</div>        <span class="CaptionVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <span class="CaptionBorderBottom" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>      </div>    </div>    <tr>      <td>        <div class="InnerTableContainer" >          <table style="width:100%;" ><tr><td>Rank of player <b>'.htmlspecialchars($player_to_change->getName()).'</b> has been changed to <b>'.htmlspecialchars($rank->getName()).'</b>.</td></tr>          </table>        </div>  </table></div></td></tr><br>';
  497.                 unset($players_with_lower_rank);
  498.                 unset($ranks);
  499.                 $rid = 0;
  500.                 $sid= 0;
  501.                 foreach($rank_list as $rank)
  502.                 {
  503.                     if($guild_leader || $rank->getLevel() < $level_in_guild)
  504.                     {
  505.                         $ranks[$rid]['0'] = $rank->getId();
  506.                         $ranks[$rid]['1'] = $rank->getName();
  507.                         $rid++;
  508.                         $players_with_rank = $rank->getPlayersList();
  509.                         if(count($players_with_rank) > 0)
  510.                         {
  511.                             foreach($players_with_rank as $player)
  512.                             {
  513.                                 if($guild->getOwner()->getId() != $player->getId() || $guild_leader)
  514.                                 {
  515.                                     $players_with_lower_rank[$sid]['0'] = htmlspecialchars($player->getName());
  516.                                     $players_with_lower_rank[$sid]['1'] = htmlspecialchars($player->getName()).' ('.htmlspecialchars($rank->getName()).')';
  517.                                     $sid++;
  518.                                 }
  519.                             }
  520.                         }
  521.                     }
  522.                 }
  523.             }
  524.             else
  525.             {
  526.                 $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  527.                 foreach($change_errors as $change_error)
  528.                     $main_content .= '<li>'.$change_error;
  529.                 $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br/>';
  530.             }
  531.         }
  532.         $main_content .= '<FORM ACTION="?subtopic=guilds&action=changerank&guild='.$guild_id.'&todo=save" METHOD=post>
  533.         <TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>
  534.         <TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Change Rank</B></TD></TR>
  535.         <TR BGCOLOR='.$config['site']['darkborder'].'><TD>Name: <SELECT NAME="name">';
  536.         foreach($players_with_lower_rank as $player_to_list)
  537.             $main_content .= '<OPTION value="'.$player_to_list['0'].'">'.$player_to_list['1'];
  538.         $main_content .= '</SELECT>&nbsp;Rank:&nbsp;<SELECT NAME="rankid">';
  539.         foreach($ranks as $rank)
  540.             $main_content .= '<OPTION value="'.htmlspecialchars($rank['0']).'">'.htmlspecialchars($rank['1']);
  541.         $main_content .= '</SELECT>&nbsp;&nbsp;&nbsp;<INPUT TYPE=image NAME="Submit" ALT="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18></TD><TR>
  542.         </TABLE></FORM><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  543.     }
  544.     else
  545.         $main_content .= 'Error. You are not a leader or vice leader in guild '.htmlspecialchars($guild->getName()).'.<FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></FORM>';
  546.     }
  547. }
  548.  
  549. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  550. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  551. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  552. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  553. //show guild page
  554. if($action == 'deleteinvite')
  555. {
  556.     //set rights in guild
  557.     $guild_id = (int) $_REQUEST['guild'];
  558.     $name = $_REQUEST['name'];
  559.     if(!$logged)
  560.         $guild_errors[] = 'You are not logged in. You can\'t delete invitations.';
  561.     if(!check_name($name))
  562.         $guild_errors[] = 'Invalid name format.';
  563.     if(empty($guild_errors))
  564.     {
  565.         $guild = new Guild();
  566.         $guild->load($guild_id);
  567.         if(!$guild->isLoaded())
  568.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  569.     }
  570.     if(empty($guild_errors))
  571.     {
  572.         $rank_list = $guild->getGuildRanksList();
  573.         $guild_leader = FALSE;
  574.         $guild_vice = FALSE;
  575.         $account_players = $account_logged->getPlayers();
  576.         foreach($account_players as $player)
  577.         {
  578.             $player_rank = $player->getRank();
  579.             if(!empty($player_rank))
  580.             {
  581.                 foreach($rank_list as $rank_in_guild)
  582.                 {
  583.                     if($rank_in_guild->getId() == $player_rank->getId())
  584.                     {
  585.                         $players_from_account_in_guild[] = $player->getName();
  586.                         if($player_rank->getLevel() > 1)
  587.                         {
  588.                             $guild_vice = TRUE;
  589.                             $level_in_guild = $player_rank->getLevel();
  590.                         }
  591.                         if($guild->getOwner()->getId() == $player->getId())
  592.                         {
  593.                             $guild_vice = TRUE;
  594.                             $guild_leader = TRUE;
  595.                         }
  596.                     }
  597.                 }
  598.             }
  599.         }
  600.     }
  601.     if(empty($guild_errors))
  602.     {
  603.         $player = new Player();
  604.         $player->find($name);
  605.         if(!$player->isLoaded())
  606.             $guild_errors[] = 'Player with name <b>'.htmlspecialchars($name).'</b> doesn\'t exist.';
  607.     }
  608.     if(!$guild_vice)
  609.         $guild_errors[] = 'You are not a leader or vice leader of guild <b>'.htmlspecialchars($guild->getName()).'</b>.';
  610.     if(empty($guild_errors))
  611.     {
  612.         $invited_list = $guild->listInvites();
  613.         if(count($invited_list) > 0)
  614.         {
  615.             $is_invited = FALSE;
  616.             foreach($invited_list as $invited)
  617.                 if($invited->getName() == $player->getName())
  618.                     $is_invited = TRUE;
  619.             if(!$is_invited)
  620.                 $guild_errors[] = '<b>'.htmlspecialchars($player->getName()).'</b> isn\'t invited to your guild.';
  621.         }
  622.         else
  623.             $guild_errors[] = 'No one is invited to your guild.';
  624.     }
  625.     if(!empty($guild_errors))
  626.     {
  627.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  628.         foreach($guild_errors as $guild_error)
  629.             $main_content .= '<li>'.$guild_error;
  630.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br/><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  631.     }
  632.     else
  633.     {
  634.         if($_REQUEST['todo'] == 'save')
  635.         {
  636.             $guild->deleteInvite($player);
  637.             $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Delete player invitation</B></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD WIDTH=100%>Player with name <b>'.htmlspecialchars($player->getName()).'</b> has been deleted from "invites list".</TD></TR></TABLE><br/><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  638.         }
  639.         else
  640.             $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Delete player invitation</B></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD WIDTH=100%>Are you sure you want to delete player with name <b>'.htmlspecialchars($player->getName()).'</b> from "invites list"?</TD></TR></TABLE><br/><center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><TR><FORM ACTION="?subtopic=guilds&action=deleteinvite&guild='.$guild_id.'&name='.urlencode($player->getName()).'&todo=save" METHOD=post><TD align="right" width="50%"><INPUT TYPE=image NAME="Submit" ALT="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18>&nbsp;&nbsp;</TD></FORM><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TD>&nbsp;&nbsp;<INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></TD></TR></FORM></TABLE></center>';
  641.     }
  642. }
  643.  
  644. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  645. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  646. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  647. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  648. //show guild page
  649. if($action == 'invite')
  650. {
  651.     //set rights in guild
  652.     $guild_id = (int) $_REQUEST['guild'];
  653.     $name = $_REQUEST['name'];
  654.     if(!$logged)
  655.         $guild_errors[] = 'You are not logged in. You can\'t invite players.';
  656.     if(empty($guild_errors))
  657.     {
  658.         $guild = new Guild();
  659.         $guild->load($guild_id);
  660.         if(!$guild->isLoaded())
  661.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  662.     }
  663.     if(empty($guild_errors))
  664.     {
  665.         $rank_list = $guild->getGuildRanksList();
  666.         $guild_leader = FALSE;
  667.         $guild_vice = FALSE;
  668.         $account_players = $account_logged->getPlayers();
  669.         foreach($account_players as $player)
  670.         {
  671.             $player_rank = $player->getRank();
  672.             if(!empty($player_rank))
  673.                 foreach($rank_list as $rank_in_guild)
  674.                     if($rank_in_guild->getId() == $player_rank->getId())
  675.                     {
  676.                         $players_from_account_in_guild[] = $player->getName();
  677.                         if($player_rank->getLevel() > 1)
  678.                         {
  679.                             $guild_vice = TRUE;
  680.                             $level_in_guild = $player_rank->getLevel();
  681.                         }
  682.                         if($guild->getOwner()->getId() == $player->getId())
  683.                         {
  684.                             $guild_vice = TRUE;
  685.                             $guild_leader = TRUE;
  686.                         }
  687.                     }
  688.         }
  689.     }
  690.     if(!$guild_vice)
  691.         $guild_errors[] = 'You are not a leader or vice leader of guild ID <b>'.$guild_id.'</b>.';
  692.     if($_REQUEST['todo'] == 'save')
  693.     {
  694.         if(!check_name($name))
  695.             $guild_errors[] = 'Invalid name format.';
  696.         if(empty($guild_errors))
  697.         {
  698.             $player = new Player();
  699.             $player->find($name);
  700.             if(!$player->isLoaded())
  701.                 $guild_errors[] = 'Player with name <b>'.htmlspecialchars($name).'</b> doesn\'t exist.';
  702.             else
  703.             {
  704.                 $rank_of_player = $player->getRank();
  705.                 if(!empty($rank_of_player))
  706.                     $guild_errors[] = 'Player with name <b>'.htmlspecialchars($name).'</b> is already in guild. He must leave guild before you can invite him.';
  707.             }
  708.         }
  709.         if(empty($guild_errors))
  710.         {
  711.             $invited_list = $guild->listInvites();
  712.             if(count($invited_list) > 0)
  713.                 foreach($invited_list as $invited)
  714.                     if($invited->getName() == $player->getName())
  715.                         $guild_errors[] = '<b>'.htmlspecialchars($player->getName()).'</b> is already invited to your guild.';
  716.         }
  717.     }
  718.     if(!empty($guild_errors))
  719.     {
  720.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  721.         foreach($guild_errors as $guild_error)
  722.             $main_content .= '<li>'.$guild_error;
  723.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br/><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  724.     }
  725.     else
  726.         if($_REQUEST['todo'] == 'save')
  727.         {
  728.             $guild->invite($player);
  729.             $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Invite player</B></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD WIDTH=100%>Player with name <b>'.htmlspecialchars($player->getName()).'</b> has been invited to your guild.</TD></TR></TABLE><br/><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  730.         }
  731.         else
  732.             $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Invite player</B></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD WIDTH=100%><FORM ACTION="?subtopic=guilds&action=invite&guild='.$guild_id.'&todo=save" METHOD=post>Invite player with name:&nbsp;&nbsp;<INPUT TYPE="text" NAME="name">&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE=image NAME="Submit" ALT="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18></FORM></TD></TD></TR></TR></TABLE><br/><center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><TR><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TD><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></TD></TR></FORM></TABLE></center>';
  733. }
  734.  
  735.  
  736. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  737. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  738. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  739. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  740. //show guild page
  741. if($action == 'acceptinvite')
  742. {
  743.     //set rights in guild
  744.     $guild_id = (int) $_REQUEST['guild'];
  745.     $name = $_REQUEST['name'];
  746.     if(!$logged)
  747.         $guild_errors[] = 'You are not logged in. You can\'t accept invitations.';
  748.     if(empty($guild_errors))
  749.     {
  750.         $guild = new Guild();
  751.         $guild->load($guild_id);
  752.         if(!$guild->isLoaded())
  753.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  754.     }
  755.  
  756.     if($_REQUEST['todo'] == 'save')
  757.     {
  758.         if(!check_name($name))
  759.             $guild_errors[] = 'Invalid name format.';
  760.         if(empty($guild_errors))
  761.         {
  762.             $player = new Player();
  763.             $player->find($name);
  764.             if(!$player->isLoaded())
  765.             {
  766.                 $guild_errors[] = 'Player with name <b>'.htmlspecialchars($name).'</b> doesn\'t exist.';
  767.             }
  768.             else
  769.             {
  770.                 $rank_of_player = $player->getRank();
  771.                 if(!empty($rank_of_player))
  772.                 {
  773.                     $guild_errors[] = 'Character with name <b>'.htmlspecialchars($name).'</b> is already in guild. You must leave guild before you join other guild.';
  774.                 }
  775.             }
  776.         }
  777.     }
  778.     if($_REQUEST['todo'] == 'save')
  779.     {
  780.         if(empty($guild_errors))
  781.         {
  782.             $is_invited = FALSE;
  783.             $invited_list = $guild->listInvites();
  784.             if(count($invited_list) > 0)
  785.             {
  786.                 foreach($invited_list as $invited)
  787.                 {
  788.                     if($invited->getName() == $player->getName())
  789.                     {
  790.                         $is_invited = TRUE;
  791.                     }
  792.                 }
  793.             }
  794.             if(!$is_invited)
  795.             {
  796.                 $guild_errors[] = 'Character '.htmlspecialchars($player->getName()).' isn\'t invited to guild <b>'.htmlspecialchars($guild->getName()).'</b>.';
  797.             }
  798.         }
  799.     }
  800.     else
  801.     {
  802.         if(empty($guild_errors))
  803.         {
  804.             $acc_invited = FALSE;
  805.             $account_players = $account_logged->getPlayers();
  806.             $invited_list = $guild->listInvites();
  807.             if(count($invited_list) > 0)
  808.             {
  809.                 foreach($invited_list as $invited)
  810.                 {
  811.                     foreach($account_players as $player_from_acc)
  812.                     {
  813.                         if($invited->getName() == $player_from_acc->getName())
  814.                         {
  815.                             $acc_invited = TRUE;
  816.                             $list_of_invited_players[] = $player_from_acc->getName();
  817.                         }
  818.                     }
  819.                 }
  820.             }
  821.         }
  822.         if(!$acc_invited)
  823.         {
  824.             $guild_errors[] = 'Any character from your account isn\'t invited to <b>'.htmlspecialchars($guild->getName()).'</b>.';
  825.         }
  826.     }
  827.     if(!empty($guild_errors))
  828.     {
  829.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  830.         foreach($guild_errors as $guild_error)
  831.         {
  832.             $main_content .= '<li>'.$guild_error;
  833.         }
  834.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br/><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  835.     }
  836.     else
  837.     {
  838.         if($_REQUEST['todo'] == 'save')
  839.         {
  840.             $guild->acceptInvite($player);
  841.             $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Accept invitation</B></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD WIDTH=100%>Player with name <b>'.htmlspecialchars($player->getName()).'</b> has been added to guild <b>'.htmlspecialchars($guild->getName()).'</b>.</TD></TR></TABLE><br/><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  842.         }
  843.         else
  844.         {
  845.             $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Accept invitation</B></TD></TR>';
  846.             $main_content .= '<TR BGCOLOR='.$config['site']['lightborder'].'><TD WIDTH=100%>Select character to join guild:</TD></TR>';
  847.             $main_content .= '<TR BGCOLOR='.$config['site']['darkborder'].'><TD>
  848.             <form action="?subtopic=guilds&action=acceptinvite&guild='.$guild_id.'&todo=save" METHOD="post">';
  849.             sort($list_of_invited_players);
  850.             foreach($list_of_invited_players as $invited_player_from_list)
  851.             {
  852.                 $main_content .= '<input type="radio" name="name" value="'.htmlspecialchars($invited_player_from_list).'" />'.htmlspecialchars($invited_player_from_list).'<br>';
  853.             }
  854.             $main_content .= '<br><INPUT TYPE=image NAME="Submit" ALT="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18></form></TD></TR></TABLE><br/><center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><TR><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TD><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></TD></TR></FORM></TABLE></center>';
  855.         }
  856.     }
  857. }
  858.  
  859.  
  860. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  861. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  862. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  863. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  864. //show guild page
  865. if($action == 'kickplayer')
  866. {
  867.     //set rights in guild
  868.     $guild_id = (int) $_REQUEST['guild'];
  869.     $name = $_REQUEST['name'];
  870.     if(!$logged)
  871.         $guild_errors[] = 'You are not logged in. You can\'t kick characters.';
  872.     if(!check_name($name))
  873.         $guild_errors[] = 'Invalid name format.';
  874.     if(empty($guild_errors))
  875.     {
  876.         $guild = new Guild();
  877.         $guild->load($guild_id);
  878.         if(!$guild->isLoaded())
  879.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  880.     }
  881.     if(empty($guild_errors))
  882.     {
  883.         $rank_list = $guild->getGuildRanksList();
  884.         $guild_leader = FALSE;
  885.         $guild_vice = FALSE;
  886.         $account_players = $account_logged->getPlayers();
  887.         foreach($account_players as $player)
  888.         {
  889.             $player_rank = $player->getRank();
  890.             if(!empty($player_rank))
  891.             {
  892.                 foreach($rank_list as $rank_in_guild)
  893.                 {
  894.                     if($rank_in_guild->getId() == $player_rank->getId())
  895.                     {
  896.                         $players_from_account_in_guild[] = $player->getName();
  897.                         if($player_rank->getLevel() > 1)
  898.                         {
  899.                             $guild_vice = TRUE;
  900.                             $level_in_guild = $player_rank->getLevel();
  901.                         }
  902.                         if($guild->getOwner()->getId() == $player->getId())
  903.                         {
  904.                             $guild_vice = TRUE;
  905.                             $guild_leader = TRUE;
  906.                         }
  907.                     }
  908.                 }
  909.             }
  910.         }
  911.     }
  912.     if(empty($guild_errors))
  913.     {
  914.         if(!$guild_leader && $level_in_guild < 3)
  915.         {
  916.             $guild_errors[] = 'You are not a leader of guild <b>'.htmlspecialchars($guild->getName()).'</b>. You can\'t kick players.';
  917.         }
  918.     }
  919.     if(empty($guild_errors))
  920.     {
  921.         $player = new Player();
  922.         $player->find($name);
  923.         if(!$player->isLoaded())
  924.         {
  925.             $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> doesn\'t exist.';
  926.         }
  927.         else
  928.         {
  929.             if($player->getRank()->getGuild()->getName() != $guild->getName())
  930.             {
  931.                 $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> isn\'t from your guild.';
  932.             }
  933.         }
  934.     }
  935.     if(empty($guild_errors))
  936.     {
  937.         if($player->getRank()->getLevel() >= $level_in_guild && !$guild_leader)
  938.         {
  939.             $guild_errors[] = 'You can\'t kick character <b>'.htmlspecialchars($name).'</b>. Too high access level.';
  940.         }
  941.     }
  942.     if(empty($guild_errors))
  943.     {
  944.         if($guild->getOwner()->getName() == $player->getName())
  945.         {
  946.             $guild_errors[] = 'It\'s not possible to kick guild owner!';
  947.         }
  948.     }
  949.     if(!empty($guild_errors))
  950.     {
  951.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  952.         foreach($guild_errors as $guild_error)
  953.         {
  954.             $main_content .= '<li>'.$guild_error;
  955.         }
  956.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br/><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  957.     }
  958.     else
  959.         if($_REQUEST['todo'] == 'save')
  960.         {
  961.             $player->setRank();
  962.             $player->save();
  963.             $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Kick player</B></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD WIDTH=100%>Player with name <b>'.htmlspecialchars($player->getName()).'</b> has been kicked from your guild.</TD></TR></TABLE><br/><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  964.         }
  965.         else
  966.             $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Kick player</B></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD WIDTH=100%>Are you sure you want to kick player with name <b>'.htmlspecialchars($player->getName()).'</b> from your guild?</TD></TR></TABLE><br/><center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><TR><FORM ACTION="?subtopic=guilds&action=kickplayer&guild='.$guild_id.'&name='.urlencode($player->getName()).'&todo=save" METHOD=post><TD align="right" width="50%"><INPUT TYPE=image NAME="Submit" ALT="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18>&nbsp;&nbsp;</TD></FORM><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TD>&nbsp;&nbsp;<INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></TD></TR></FORM></TABLE></center>';
  967. }
  968.  
  969. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  970. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  971. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  972. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  973. //show guild page
  974. if($action == 'leaveguild')
  975. {
  976.     //set rights in guild
  977.     $guild_id = (int) $_REQUEST['guild'];
  978.     $name = $_REQUEST['name'];
  979.     if(!$logged)
  980.         $guild_errors[] = 'You are not logged in. You can\'t leave guild.';
  981.     if(empty($guild_errors))
  982.     {
  983.         $guild = new Guild();
  984.         $guild->load($guild_id);
  985.         if(!$guild->isLoaded())
  986.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  987.     }
  988.  
  989.     if(empty($guild_errors))
  990.     {
  991.         $guild_owner_id = $guild->getOwner()->getId();
  992.         if($_REQUEST['todo'] == 'save')
  993.         {
  994.             if(!check_name($name))
  995.                 $guild_errors[] = 'Invalid name format.';
  996.             if(empty($guild_errors))
  997.             {
  998.                 $player = new Player();
  999.                 $player->find($name);
  1000.                 if(!$player->isLoaded())
  1001.                     $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> doesn\'t exist.';
  1002.                 else
  1003.                     if($player->getAccount()->getId() != $account_logged->getId())
  1004.                         $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> isn\'t from your account!';
  1005.             }
  1006.             if(empty($guild_errors))
  1007.             {
  1008.                 $player_loaded_rank = $player->getRank();
  1009.                 if(!empty($player_loaded_rank) && $player_loaded_rank->isLoaded())
  1010.                 {
  1011.                     if($player_loaded_rank->getGuild()->getId() != $guild->getId())
  1012.                         $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> isn\'t from guild <b>'.htmlspecialchars($guild->getName()).'</b>.';
  1013.                 }
  1014.                 else
  1015.                     $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> isn\'t in any guild.';
  1016.             }
  1017.             if(empty($guild_errors))
  1018.                 if($guild_owner_id == $player->getId())
  1019.                     $guild_errors[] = 'You can\'t leave guild. You are an owner of guild.';
  1020.         }
  1021.         else
  1022.         {
  1023.             $account_players = $account_logged->getPlayers();
  1024.             foreach($account_players as $player_fac)
  1025.             {
  1026.                 $player_rank = $player_fac->getRank();
  1027.                 if(!empty($player_rank))
  1028.                     if($player_rank->getGuild()->getId() == $guild->getId())
  1029.                         if($guild_owner_id != $player_fac->getId())
  1030.                             $array_of_player_ig[] = $player_fac->getName();
  1031.             }
  1032.         }
  1033.     }
  1034.     if(!empty($guild_errors))
  1035.     {
  1036.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1037.         foreach($guild_errors as $guild_error)
  1038.             $main_content .= '<li>'.$guild_error.'</li>';
  1039.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br/><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  1040.     }
  1041.     else
  1042.     {
  1043.         if($_REQUEST['todo'] == 'save')
  1044.         {
  1045.             $player->setRank();
  1046.             $player->save();
  1047.             $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Leave guild</B></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD WIDTH=100%>Player with name <b>'.htmlspecialchars($player->getName()).'</b> leaved guild <b>'.htmlspecialchars($guild->getName()).'</b>.</TD></TR></TABLE><br/><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  1048.         }
  1049.         else
  1050.         {
  1051.             $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Leave guild</B></TD></TR>';
  1052.             if(count($array_of_player_ig) > 0)
  1053.             {
  1054.                 $main_content .= '<TR BGCOLOR='.$config['site']['lightborder'].'><TD WIDTH=100%>Select character to leave guild:</TD></TR>';
  1055.                 $main_content .= '<TR BGCOLOR='.$config['site']['darkborder'].'><TD>
  1056.                 <form action="?subtopic=guilds&action=leaveguild&guild='.$guild_id.'&todo=save" METHOD="post">';
  1057.                 sort($array_of_player_ig);
  1058.                 foreach($array_of_player_ig as $player_to_leave)
  1059.                     $main_content .= '<input type="radio" name="name" value="'.htmlspecialchars($player_to_leave).'" />'.htmlspecialchars($player_to_leave).'<br>';
  1060.                 $main_content .= '</TD></TR><br></TABLE>';
  1061.             }
  1062.             else
  1063.                 $main_content .= '<TR BGCOLOR='.$config['site']['lightborder'].'><TD WIDTH=100%>Any of your characters can\'t leave guild.</TD></TR>';
  1064.             $main_content .= '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><tr>';
  1065.             if(count($array_of_player_ig) > 0)
  1066.                 $main_content .= '<td width="130" valign="top"><INPUT TYPE=image NAME="Submit" ALT="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18></form></td>';
  1067.             $main_content .= '<td><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18></FORM></td></tr></table>';
  1068.         }
  1069.     }
  1070. }
  1071.  
  1072. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1073. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1074. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1075. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1076. //create guild
  1077. if($action == 'createguild')
  1078. {
  1079.     $new_guild_name = trim($_REQUEST['guild']);
  1080.     $name = $_REQUEST['name'];
  1081.     $todo = $_REQUEST['todo'];
  1082.     if(!$logged)
  1083.         $guild_errors[] = 'You are not logged in. You can\'t create guild.';
  1084.     if(empty($guild_errors))
  1085.     {
  1086.         $account_players = $account_logged->getPlayers();
  1087.         foreach($account_players as $player)
  1088.         {
  1089.             $player_rank = $player->getRank();
  1090.             if(empty($player_rank))
  1091.                 if($player->getLevel() >= $config['site']['guild_need_level'])
  1092.                     if(!$config['site']['guild_need_pacc'] || $account_logged->isPremium())
  1093.                         $array_of_player_nig[] = $player->getName();
  1094.         }
  1095.     }
  1096.  
  1097.     if(count($array_of_player_nig) == 0)
  1098.         $guild_errors[] = 'On your account all characters are in guilds or have too low level to create new guild.';
  1099.     if($todo == 'save')
  1100.     {
  1101.         if(!check_guild_name($new_guild_name))
  1102.         {
  1103.             $guild_errors[] = 'Invalid guild name format.';
  1104.         }
  1105.         if(!check_name($name))
  1106.         {
  1107.             $guild_errors[] = 'Invalid character name format.';
  1108.         }
  1109.         if(empty($guild_errors))
  1110.         {
  1111.             $player = new Player();
  1112.             $player->find($name);
  1113.             if(!$player->isLoaded())
  1114.                 $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> doesn\'t exist.';
  1115.         }
  1116.         if(empty($guild_errors))
  1117.         {
  1118.             $guild = new Guild();
  1119.             $guild->find($new_guild_name);
  1120.             if($guild->isLoaded())
  1121.                 $guild_errors[] = 'Guild <b>'.htmlspecialchars($new_guild_name).'</b> already exist. Select other name.';
  1122.         }
  1123.         if(empty($guild_errors))
  1124.         {
  1125.             $bad_char = TRUE;
  1126.             foreach($array_of_player_nig as $nick_from_list)
  1127.                 if($nick_from_list == $player->getName())
  1128.                     $bad_char = FALSE;
  1129.             if($bad_char)
  1130.                 $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> isn\'t on your account or is already in guild.';
  1131.         }
  1132.         if(empty($guild_errors))
  1133.         {
  1134.             if($player->getLevel() < $config['site']['guild_need_level'])
  1135.                 $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> has too low level. To create guild you need character with level <b>'.$config['site']['guild_need_level'].'</b>.';
  1136.             if($config['site']['guild_need_pacc'] && !$account_logged->isPremium())
  1137.                 $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> is on FREE account. To create guild you need PREMIUM account.';
  1138.         }
  1139.     }
  1140.     if(!empty($guild_errors))
  1141.     {
  1142.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1143.         foreach($guild_errors as $guild_error)
  1144.             $main_content .= '<li>'.$guild_error.'</li>';
  1145.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1146.         unset($todo);
  1147.     }
  1148.  
  1149.     if($todo == 'save')
  1150.     {
  1151.         $new_guild = new Guild();
  1152.         $new_guild->setCreationData(time());
  1153.         $new_guild->setName($new_guild_name);
  1154.         $new_guild->setOwner($player);
  1155.         $new_guild->setDescription('New guild. Leader must edit this text :)');
  1156.         $new_guild->setGuildLogo('image/gif', Website::getFileContents('./images/default_guild_logo.gif'));
  1157.        
  1158.         $new_guild->save();
  1159.         $ranks = $new_guild->getGuildRanksList(true);
  1160.         foreach($ranks as $rank)
  1161.             if($rank->getLevel() == 3)
  1162.             {
  1163.                 $player->setRank($rank);
  1164.                 $player->save();
  1165.             }
  1166.         $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Create guild</B></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD WIDTH=100%><b>Congratulations!</b><br/>You have created guild <b>'.htmlspecialchars($new_guild_name).'</b>. <b>'.htmlspecialchars($player->getName()).'</b> is leader of this guild. Now you can invite players, change picture, description and motd of guild. Press submit to open guild manager.</TD></TR></TABLE><br/><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><FORM ACTION="?subtopic=guilds&action=show&guild='.$new_guild->getId().'" METHOD=post><TR><TD><center><INPUT TYPE=image NAME="Submit" ALT="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18></center></TD></TR></FORM></TABLE>';
  1167.     }
  1168.     else
  1169.     {
  1170.         $main_content .= 'To play on '.$config['server']['serverName'].' you need an account.
  1171.         All you have to do to create your new account is to enter your email address, password to new account, verification code from picture and to agree to the terms presented below.
  1172.         If you have done so, your account number, password and e-mail address will be shown on the following page and your account and password will be sent
  1173.         to your email address along with further instructions.<BR><BR>
  1174.         <FORM ACTION="?subtopic=guilds&action=createguild&todo=save" METHOD=post>
  1175.         <TABLE WIDTH=100% BORDER=0 CELLSPACING=1 CELLPADDING=4>
  1176.         <TR><TD BGCOLOR="'.$config['site']['vdarkborder'].'" CLASS=white><B>Create an '.htmlspecialchars($config['server']['serverName']).' Account</B></TD></TR>
  1177.         <TR><TD BGCOLOR="'.$config['site']['darkborder'].'"><TABLE BORDER=0 CELLSPACING=8 CELLPADDING=0>
  1178.           <TR><TD>
  1179.             <TABLE BORDER=0 CELLSPACING=5 CELLPADDING=0>';
  1180.         $main_content .= '<TR><TD width="150" valign="top"><B>Leader: </B></TD><TD><SELECT name="name">';
  1181.         if(count($array_of_player_nig) > 0)
  1182.         {
  1183.             sort($array_of_player_nig);
  1184.             foreach($array_of_player_nig as $nick)
  1185.                 $main_content .= '<OPTION>'.htmlspecialchars($nick).'</OPTION>';
  1186.         }
  1187.         $main_content .= '</SELECT><BR><font size="1" face="verdana,arial,helvetica">(Name of leader of new guild.)</font></TD></TR>
  1188.             <TR><TD width="150" valign="top"><B>Guild name: </B></TD><TD><INPUT NAME="guild" VALUE="" SIZE=30 MAXLENGTH=50><BR><font size="1" face="verdana,arial,helvetica">(Here write name of your new guild.)</font></TD></TR>
  1189.             </TABLE>
  1190.           </TD></TR>
  1191.         </TABLE></TD></TR>
  1192.         </TABLE>
  1193.         <BR>
  1194.         <TABLE BORDER=0 WIDTH=100%>
  1195.           <TR><TD ALIGN=center>
  1196.             <IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=120 HEIGHT=1 BORDER=0><BR>
  1197.           </TD><TD ALIGN=center VALIGN=top>
  1198.             <INPUT TYPE=image NAME="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  1199.             </FORM>
  1200.           </TD><TD ALIGN=center>
  1201.             <FORM  ACTION="?subtopic=guilds" METHOD=post>
  1202.             <INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  1203.             </FORM>
  1204.           </TD><TD ALIGN=center>
  1205.             <IMG SRC="/images/blank.gif" WIDTH=120 HEIGHT=1 BORDER=0><BR>
  1206.           </TD></TR>
  1207.         </TABLE>
  1208.         </TD>
  1209.         <TD><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=10 HEIGHT=1 BORDER=0></TD>
  1210.         </TR>
  1211.         </TABLE>';
  1212.     }
  1213. }
  1214. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1215. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1216. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1217. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1218. if($action == 'manager')
  1219. {
  1220.     $guild_id = (int) $_REQUEST['guild'];
  1221.     if(empty($guild_errors))
  1222.     {
  1223.         $guild = new Guild();
  1224.         $guild->load($guild_id);
  1225.         if(!$guild->isLoaded())
  1226.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1227.     }
  1228.     if(empty($guild_errors))
  1229.     {
  1230.         if($logged)
  1231.         {
  1232.             $guild_leader_char = $guild->getOwner();
  1233.             $rank_list = $guild->getGuildRanksList();
  1234.             $guild_leader = FALSE;
  1235.             $account_players = $account_logged->getPlayers();
  1236.             foreach($account_players as $player)
  1237.                 if($guild_leader_char->getId() == $player->getId())
  1238.                 {
  1239.                     $guild_vice = TRUE;
  1240.                     $guild_leader = TRUE;
  1241.                     $level_in_guild = 3;
  1242.                 }
  1243.             if($guild_leader)
  1244.             {
  1245.                 $main_content .= '<center><h2>Welcome to guild manager!</h2></center>Here you can change names of ranks, delete and add ranks, pass leadership to other guild member and delete guild.';
  1246.                 $main_content .= '<br/><br/><table style="clear:both" border=0 cellpadding=0 cellspacing=0 width="100%">
  1247.                 <tr bgcolor='.$config['site']['darkborder'].'><td width="170"><font color="red"><b>Option</b></font></td><td><font color="red"><b>Description</b></font></td></tr>
  1248.                 <tr bgcolor='.$config['site']['lightborder'].'><td width="170"><b><a href="?subtopic=guilds&guild='.$guild_id.'&action=passleadership">Pass Leadership</a></b></td><td><b>Pass leadership of guild to other guild member.</b></td></tr>
  1249.                 <tr bgcolor='.$config['site']['darkborder'].'><td width="170"><b><a href="?subtopic=guilds&guild='.$guild_id.'&action=deleteguild">Delete Guild</a></b></td><td><b>Delete guild, kick all members.</b></td></tr>
  1250.                 <tr bgcolor='.$config['site']['lightborder'].'><td width="170"><b><a href="?subtopic=guilds&guild='.$guild_id.'&action=changedescription">Change Description</a></b></td><td><b>Change description of guild.</b></td></tr>
  1251.                 <tr bgcolor='.$config['site']['darkborder'].'><td width="170"><b><a href="?subtopic=guilds&guild='.$guild_id.'&action=changemotd">Change MOTD</a></b></td><td><b>Change MOTD of guild.</b></td></tr>
  1252.                 <tr bgcolor='.$config['site']['lightborder'].'><td width="170"><b><a href="?subtopic=guilds&guild='.$guild_id.'&action=changelogo">Change guild logo</a></b></td><td><b>You cant upload a new logo, sorry.</b></td></tr>
  1253.                 </table>';
  1254.                 $main_content .= '<br><div class="TableContainer" >  <table class="Table1" cellpadding="0" cellspacing="0" >    <div class="CaptionContainer" >      <div class="CaptionInnerContainer" >        <span class="CaptionEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionBorderTop" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <div class="Text" >Add new rank</div>        <span class="CaptionVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <span class="CaptionBorderBottom" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>      </div>    </div>    <tr>      <td>        <div class="InnerTableContainer" >          <table style="width:100%;" ><tr><td width="120" valign="top">New rank name:</td><td> <form action="?subtopic=guilds&guild='.$guild_id.'&action=addrank" method="POST"><input type="text" name="rank_name" size="20"><input type="submit" value="Add"></form></td></tr>          </table>        </div>  </table></div></td></tr>';
  1255.                 $main_content .= '<center><h3>Change rank names and levels</h3></center><form action="?subtopic=guilds&action=saveranks&guild='.$guild_id.'" method=POST><table style="clear:both" border=0 cellpadding=0 cellspacing=0 width="100%"><tr bgcolor='.$config['site']['vdarkborder'].'><td rowspan="2" width="120" align="center"><font color="white"><b>Delete Rank</b></font></td><td rowspan="2" width="300"><font color="white"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name</b></font></td><td colspan="3" align="center"><font color="white"><b>Level of RANK in guild</b></font></td></tr><tr bgcolor='.$config['site']['vdarkborder'].'><td align="center" bgcolor="red"><font color="white"><b>Leader (3)</b></font></td><td align="center" bgcolor="yellow"><font color="black"><b>Vice (2)</b></font></td><td align="center" bgcolor="green"><font color="white"><b>Member (1)</b></font></td></tr>';
  1256.                 foreach($rank_list as $rank)
  1257.                 {
  1258.                     if(is_int($number_of_rows / 2)) { $bgcolor = $config['site']['darkborder']; } else { $bgcolor = $config['site']['lightborder']; } $number_of_rows++;
  1259.                     $main_content .= '<tr bgcolor="'.$bgcolor.'"><td align="center"><a href="?subtopic=guilds&guild='.$guild_id.'&action=deleterank&rankid='.urlencode($rank->getId()).'" border="0"><img src="'.$layout_name.'/images/news/delete.png" border="0" alt="Delete Rank"></a></td><td><input type="text" name="'.htmlspecialchars($rank->getId()).'_name" value="'.htmlspecialchars($rank->getName()).'" size="35"></td><td align="center"><input type="radio" name="'.$rank->getId().'_level" value="3"';
  1260.                     if($rank->getLevel() == 3)
  1261.                         $main_content .= ' checked="checked"';
  1262.                     $main_content .= ' /></td><td align="center"><input type="radio" name="'.$rank->getId().'_level" value="2"';
  1263.                     if($rank->getLevel() == 2)
  1264.                         $main_content .= ' checked="checked"';
  1265.                     $main_content .= ' /></td><td align="center"><input type="radio" name="'.$rank->getId().'_level" value="1"';
  1266.                     if($rank->getLevel() == 1)
  1267.                         $main_content .= ' checked="checked"';
  1268.                     $main_content .= ' /></td></tr>';
  1269.                 }
  1270.                 $main_content .= '<tr bgcolor='.$config['site']['vdarkborder'].'><td>&nbsp;</td><td>&nbsp;</td><td colspan="3" align="center"><input type="submit" value="Save All"></td></tr></table></form>';
  1271.                 $main_content .= '<h3>Ranks info:</h3><b>0. Owner of guild</b> - it\'s highest rank, only one player in guild may has this rank. Player with this rank can:
  1272.                 <li>Invite/Cancel Invitation/Kick Player from guild
  1273.                 <li>Change ranks of all players in guild
  1274.                 <li>Delete guild or pass leadership to other guild member
  1275.                 <li>Change names, levels(leader,vice,member), add and delete ranks
  1276.                 <li>Change MOTD, logo and description of guild<hr>
  1277.                 <b>3. Leader</b> - it\'s second rank in guild. Player with this rank can:
  1278.                 <li>Invite/Cancel Invitation/Kick Player from guild (only with lower rank than his)
  1279.                 <li>Change ranks of players with lower rank level ("vice leader", "member") in guild<hr>
  1280.                 <b>2. Vice Leader</b> - it\'s third rank in guild. Player with this rank can:
  1281.                 <li>Invite/Cancel Invitation
  1282.                 <li>Change ranks of players with lower rank level ("member") in guild<hr>
  1283.                 <b>1. Member</b> - it\'s lowest rank in guild. Player with this rank can:
  1284.                 <li>Be a member of guild';
  1285.                 $main_content .= '<br/><center><form action="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1286.             }
  1287.             else
  1288.                 $guild_errors[] = 'You are not a leader of guild!';
  1289.         }
  1290.         else
  1291.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1292.     }
  1293.     if(!empty($guild_errors))
  1294.     {
  1295.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1296.         foreach($guild_errors as $guild_error)
  1297.             $main_content .= '<li>'.$guild_error.'</li>';
  1298.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1299.     }
  1300. }
  1301. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1302. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1303. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1304. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1305. if($action == 'changelogo')
  1306. {
  1307.     $guild_id = (int) $_REQUEST['guild'];
  1308.  
  1309.     $guild = new Guild();
  1310.     $guild->load($guild_id);
  1311.     if(!$guild->isLoaded())
  1312.         $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1313.     if(empty($guild_errors))
  1314.     {
  1315.         if($logged)
  1316.         {
  1317.             $guild_leader_char = $guild->getOwner();
  1318.             $guild_leader = FALSE;
  1319.             $account_players = $account_logged->getPlayers();
  1320.             foreach($account_players as $player)
  1321.                 if($guild_leader_char->getId() == $player->getId())
  1322.                 {
  1323.                     $guild_vice = TRUE;
  1324.                     $guild_leader = TRUE;
  1325.                     $level_in_guild = 3;
  1326.                 }
  1327.             if($guild_leader)
  1328.             {
  1329.                 $max_image_size_b = $config['site']['guild_image_size_kb'] * 1024;
  1330.                 if($_REQUEST['todo'] == 'save')
  1331.                 {
  1332.                     $file = $_FILES['newlogo'];
  1333.                     switch($file['error'])
  1334.                     {
  1335.                         case UPLOAD_ERR_OK:
  1336.                             break; // all ok
  1337.                         case UPLOAD_ERR_INI_SIZE:
  1338.                         case UPLOAD_ERR_FORM_SIZE:
  1339.                             $upload_errors[] = 'Image is too large';
  1340.                             break;
  1341.                         case UPLOAD_ERR_PARTIAL:
  1342.                             $upload_errors[] = 'Image was only partially uploaded';
  1343.                             break;
  1344.                         case UPLOAD_ERR_NO_FILE:
  1345.                             $upload_errors[] = 'No image was uploaded';
  1346.                             break;
  1347.                         case UPLOAD_ERR_NO_TMP_DIR:
  1348.                             $upload_errors[] = 'Upload folder not found';
  1349.                             break;
  1350.                         case UPLOAD_ERR_CANT_WRITE:
  1351.                             $upload_errors[] = 'Unable to write uploaded file';
  1352.                             break;
  1353.                         case UPLOAD_ERR_EXTENSION:
  1354.                             $upload_errors[] =  'Upload failed due to extension';
  1355.                             break;
  1356.                         default:
  1357.                             $upload_errors[] =  'Unknown error';
  1358.                     }
  1359.                     if(is_uploaded_file($file['tmp_name']))
  1360.                     {
  1361.                         if($file['size'] > $max_image_size_b)
  1362.                             $upload_errors[] = 'Uploaded image is too big. Size: <b>'.$file['size'].' bytes</b>, Max. size: <b>'.$max_image_size_b.' bytes</b>.';
  1363.                         $info = getimagesize($file['tmp_name']);
  1364.                         if(!$info)
  1365.                             $upload_errors[] = 'Uploaded file is not an image!';
  1366.                     }
  1367.                     else
  1368.                         $upload_errors[] = 'You didn\'t send file or file is too big. Limit: <b>'.$config['site']['guild_image_size_kb'].' KB</b>.';
  1369.                     //show errors or save file
  1370.                     if(!empty($upload_errors))
  1371.                     {
  1372.                         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1373.                         foreach($upload_errors as $guild_error)
  1374.                             $main_content .= '<li>'.$guild_error;
  1375.                         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1376.                     }
  1377.                     else
  1378.                     {
  1379.                         $guild->setGuildLogo($info['mime'], file_get_contents($file['tmp_name']));
  1380.                         $guild->save();
  1381.                     }
  1382.                 }
  1383.                 $main_content .= '<center><h2>Change guild logo</h2></center>Here you can change logo of your guild.<BR>Current logo: <img src="' . $guild->getGuildLogoLink() . '" HEIGHT="64" WIDTH="64"><BR><BR>';
  1384.                 $main_content .= '<form enctype="multipart/form-data" action="?subtopic=guilds&guild='.$guild_id.'&action=changelogo" method="POST">
  1385.                 <input type="hidden" name="todo" value="save" />
  1386.                 <input type="hidden" name="MAX_FILE_SIZE" value="'.$max_image_size_b.'" />
  1387.                     Select new logo: <input name="newlogo" type="file" />
  1388.                     <input type="submit" value="Send new logo" /></form>Only <b>jpg, gif, png, bmp</b> pictures. Max. size: <b>'.$config['site']['guild_image_size_kb'].' KB</b><br>';
  1389.                 $main_content .= '<br/><center><form action="?subtopic=guilds&guild='.$guild_id.'&action=manager" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1390.             }
  1391.             else
  1392.                 $guild_errors[] = 'You are not a leader of guild!';
  1393.         }
  1394.         else
  1395.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1396.     }
  1397.     if(!empty($guild_errors))
  1398.     {
  1399.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1400.         foreach($guild_errors as $guild_error)
  1401.             $main_content .= '<li>'.$guild_error.'</li>';
  1402.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1403.         $main_content .= '<br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1404.     }
  1405. }
  1406.  
  1407.  
  1408. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1409. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1410. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1411. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1412. if($action == 'deleterank')
  1413. {
  1414.     $guild_id = (int) $_REQUEST['guild'];
  1415.     $rank_to_delete = (int) $_REQUEST['rankid'];
  1416.     if(empty($guild_errors))
  1417.     {
  1418.         $guild = new Guild();
  1419.         $guild->load($guild_id);
  1420.         if(!$guild->isLoaded())
  1421.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1422.     }
  1423.     if(empty($guild_errors))
  1424.     {
  1425.         if($logged)
  1426.         {
  1427.             $guild_leader_char = $guild->getOwner();
  1428.             $rank_list = $guild->getGuildRanksList();
  1429.             $guild_leader = FALSE;
  1430.             $account_players = $account_logged->getPlayers();
  1431.             foreach($account_players as $player)
  1432.                 if($guild->getOwner()->getId() == $player->getId())
  1433.                 {
  1434.                     $guild_leader = TRUE;
  1435.                     $level_in_guild = 3;
  1436.                 }
  1437.             if($guild_leader)
  1438.             {
  1439.                 $rank = new GuildRank();
  1440.                 $rank->load($rank_to_delete);
  1441.                 if(!$rank->isLoaded())
  1442.                     $guild_errors2[] = 'Rank with ID '.$rank_to_delete.' doesn\'t exist.';
  1443.                 else
  1444.                 {
  1445.                     if($rank->getGuild()->getId() != $guild->getId())
  1446.                         $guild_errors2[] = 'Rank with ID '.$rank_to_delete.' isn\'t from your guild.';
  1447.                     else
  1448.                     {
  1449.                         if(count($rank_list) < 2)
  1450.                             $guild_errors2[] = 'You have only 1 rank in your guild. You can\'t delete this rank.';
  1451.                         else
  1452.                         {
  1453.                             $players_with_rank = $rank->getPlayersList();
  1454.                             $players_with_rank_number = count($players_with_rank);
  1455.                             if($players_with_rank_number > 0)
  1456.                             {
  1457.                                 foreach($rank_list as $checkrank)
  1458.                                     if($checkrank->getId() != $rank->getId())
  1459.                                         if($checkrank->getLevel() <= $rank->getLevel())
  1460.                                             $new_rank = $checkrank;
  1461.                                 if(empty($new_rank))
  1462.                                 {
  1463.                                     $new_rank = new GuildRank();
  1464.                                     $new_rank->setGuild($guild);
  1465.                                     $new_rank->setLevel($rank->getLevel());
  1466.                                     $new_rank->setName('New Rank level '.$rank->getLevel());
  1467.                                     $new_rank->save();
  1468.                                 }
  1469.                                 foreach($players_with_rank as $player_in_guild)
  1470.                                 {
  1471.                                     $player_in_guild->setRank($new_rank);
  1472.                                     $player_in_guild->save();
  1473.                                 }
  1474.                             }
  1475.                             $rank->delete();
  1476.                             $saved = TRUE;
  1477.                         }
  1478.                     }
  1479.                 }
  1480.                 if($saved)
  1481.                     $main_content .= '<div class="TableContainer" >  <table class="Table1" cellpadding="0" cellspacing="0" >    <div class="CaptionContainer" >      <div class="CaptionInnerContainer" >        <span class="CaptionEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionBorderTop" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <div class="Text" >Rank Deleted</div>        <span class="CaptionVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <span class="CaptionBorderBottom" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>      </div>    </div>    <tr>      <td>        <div class="InnerTableContainer" >          <table style="width:100%;" ><tr><td>Rank <b>'.htmlspecialchars($rank->getName()).'</b> has been deleted. Players with this rank has now other rank.</td></tr>          </table>        </div>  </table></div></td></tr>';
  1482.                 else
  1483.                 {
  1484.                     $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1485.                     foreach($guild_errors2 as $guild_error)
  1486.                         $main_content .= '<li>'.$guild_error.'</li>';
  1487.                     $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1488.                 }
  1489.                 //back button
  1490.                 $main_content .= '<br/><center><form action="?subtopic=guilds&guild='.$guild_id.'&action=manager" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1491.             }
  1492.             else
  1493.                 $guild_errors[] = 'You are not a leader of guild!';
  1494.         }
  1495.         else
  1496.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1497.     }
  1498.     if(!empty($guild_errors))
  1499.     {
  1500.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1501.         foreach($guild_errors as $guild_error)
  1502.             $main_content .= '<li>'.$guild_error.'</li>';
  1503.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1504.         $main_content .= '<br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1505.     }
  1506. }
  1507. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1508. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1509. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1510. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1511. if($action == 'addrank')
  1512. {
  1513.     $guild_id = (int) $_REQUEST['guild'];
  1514.     $ranknew = $_REQUEST['rank_name'];
  1515.     if(empty($guild_errors))
  1516.     {
  1517.         if(!check_rank_name($ranknew))
  1518.             $guild_errors[] = 'Invalid rank name format.';
  1519.         if(!$logged)
  1520.             $guild_errors[] = 'You are not logged.';
  1521.         $guild = new Guild();
  1522.         $guild->load($guild_id);
  1523.         if(!$guild->isLoaded())
  1524.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1525.         if(empty($guild_errors))
  1526.         {
  1527.             $guild_leader_char = $guild->getOwner();
  1528.             $rank_list = $guild->getGuildRanksList();
  1529.             $guild_leader = FALSE;
  1530.             $account_players = $account_logged->getPlayers();
  1531.             foreach($account_players as $player)
  1532.                 if($guild_leader_char->getId() == $player->getId())
  1533.                 {
  1534.                     $guild_vice = TRUE;
  1535.                     $guild_leader = TRUE;
  1536.                     $level_in_guild = 3;
  1537.                 }
  1538.             if($guild_leader)
  1539.             {
  1540.                 $new_rank = new GuildRank();
  1541.                 $new_rank->setGuild($guild);
  1542.                 $new_rank->setLevel(1);
  1543.                 $new_rank->setName($ranknew);
  1544.                 $new_rank->save();
  1545.                 header("Location: ?subtopic=guilds&guild=".$guild_id."&action=manager");
  1546.                 $main_content .= 'New rank added. Redirecting...';
  1547.             }
  1548.             else
  1549.                 $guild_errors[] = 'You are not a leader of guild!';
  1550.         }
  1551.         if(!empty($guild_errors))
  1552.         {
  1553.             $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1554.             foreach($guild_errors as $guild_error)
  1555.                 $main_content .= '<li>'.$guild_error;
  1556.             $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1557.             $main_content .= '<br/><center><form action="?subtopic=guilds&guild='.$guild_id.'&action=show" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1558.         }
  1559.     }
  1560.     else
  1561.         if(!empty($guild_errors))
  1562.         {
  1563.             $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1564.             foreach($guild_errors as $guild_error)
  1565.                 $main_content .= '<li>'.$guild_error;
  1566.             $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1567.             $main_content .= '<br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1568.         }
  1569. }
  1570.  
  1571. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1572. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1573. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1574. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1575. if($action == 'changedescription')
  1576. {
  1577.     $guild_id = (int) $_REQUEST['guild'];
  1578.     if(empty($guild_errors))
  1579.     {
  1580.         $guild = new Guild();
  1581.         $guild->load($guild_id);
  1582.         if(!$guild->isLoaded())
  1583.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1584.     }
  1585.     if(empty($guild_errors))
  1586.     {
  1587.         if($logged)
  1588.         {
  1589.             $guild_leader_char = $guild->getOwner();
  1590.             $rank_list = $guild->getGuildRanksList();
  1591.             $guild_leader = FALSE;
  1592.             $account_players = $account_logged->getPlayers();
  1593.             foreach($account_players as $player)
  1594.                 if($guild->getOwner()->getId() == $player->getId())
  1595.                 {
  1596.                     $guild_vice = TRUE;
  1597.                     $guild_leader = TRUE;
  1598.                     $level_in_guild = 3;
  1599.                 }
  1600.             if($guild_leader)
  1601.             {
  1602.                 if($_REQUEST['todo'] == 'save')
  1603.                 {
  1604.                     $description = htmlspecialchars(substr(trim($_REQUEST['description']),0,$config['site']['guild_description_chars_limit']));
  1605.                     $guild->set('description', $description);
  1606.                     $guild->save();
  1607.                     $saved = TRUE;
  1608.                 }
  1609.                 $main_content .= '<center><h2>Change guild description</h2></center>';
  1610.                 if($saved)
  1611.                     $main_content .= '<center><font color="red" size="3"><b>CHANGES HAS BEEN SAVED!</b></font></center><br>';
  1612.                 $main_content .= 'Here you can change description of your guild.<BR>';
  1613.                 $main_content .= '<form enctype="multipart/form-data" action="?subtopic=guilds&guild='.$guild_id.'&action=changedescription" method="POST">
  1614.                 <input type="hidden" name="todo" value="save" />
  1615.                     <textarea name="description" cols="60" rows="'.($config['site']['guild_description_lines_limit'] - 1).'">'.$guild->getDescription().'</textarea><br>
  1616.                     (max. '.$config['site']['guild_description_lines_limit'].' lines, max. '.$config['site']['guild_description_chars_limit'].' chars) <input type="submit" value="Save description" /></form><br>';
  1617.                 $main_content .= '<br/><center><form action="?subtopic=guilds&guild='.$guild_id.'&action=manager" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1618.             }
  1619.             else
  1620.                 $guild_errors[] = 'You are not a leader of guild!';
  1621.         }
  1622.         else
  1623.         $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1624.     }
  1625.     if(!empty($guild_errors))
  1626.     {
  1627.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1628.         foreach($guild_errors as $guild_error)
  1629.             $main_content .= '<li>'.$guild_error.'</li>';
  1630.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1631.         $main_content .= '<br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1632.     }
  1633. }
  1634.  
  1635. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1636. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1637. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1638. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1639. if($action == 'passleadership')
  1640. {
  1641.     $guild_id = (int) $_REQUEST['guild'];
  1642.     $pass_to = trim($_REQUEST['player']);
  1643.     if(empty($guild_errors))
  1644.     {
  1645.         $guild = new Guild();
  1646.         $guild->load($guild_id);
  1647.         if(!$guild->isLoaded())
  1648.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1649.     }
  1650.     if(empty($guild_errors))
  1651.     {
  1652.         if($_POST['todo'] == 'save')
  1653.         {
  1654.             if(!check_name($pass_to))
  1655.                 $guild_errors2[] = 'Invalid player name format.';
  1656.             if(empty($guild_errors2))
  1657.             {
  1658.                 $to_player = new Player();
  1659.                 $to_player->find($pass_to);
  1660.                 if(!$to_player->isLoaded())
  1661.                     $guild_errors2[] = 'Player with name <b>'.htmlspecialchars($pass_to).'</b> doesn\'t exist.';
  1662.                 if(empty($guild_errors2))
  1663.                 {
  1664.                     $to_player_rank = $to_player->getRank();
  1665.                     if(!empty($to_player_rank))
  1666.                     {
  1667.                         $to_player_guild = $to_player_rank->getGuild();
  1668.                         if($to_player_guild->getId() != $guild->getId())
  1669.                             $guild_errors2[] = 'Player with name <b>'.htmlspecialchars($to_player->getName()).'</b> isn\'t from your guild.';
  1670.                     }
  1671.                     else
  1672.                         $guild_errors2[] = 'Player with name <b>'.htmlspecialchars($to_player->getName()).'</b> isn\'t from your guild.';
  1673.                 }
  1674.             }
  1675.         }
  1676.     }
  1677.     if(empty($guild_errors) && empty($guild_errors2))
  1678.     {
  1679.         if($logged)
  1680.         {
  1681.             $guild_leader_char = $guild->getOwner();
  1682.             $guild_leader = FALSE;
  1683.             $account_players = $account_logged->getPlayers();
  1684.             foreach($account_players as $player)
  1685.                 if($guild_leader_char->getId() == $player->getId())
  1686.                 {
  1687.                     $guild_vice = TRUE;
  1688.                     $guild_leader = TRUE;
  1689.                     $level_in_guild = 3;
  1690.                 }
  1691.             if($guild_leader)
  1692.             {
  1693.                 if($_POST['todo'] == 'save')
  1694.                 {
  1695.                     $guild->setOwner($to_player);
  1696.                     $guild->save();
  1697.                     $saved = TRUE;
  1698.                     $main_content .= '<div class="TableContainer" >  <table class="Table1" cellpadding="0" cellspacing="0" >    <div class="CaptionContainer" >      <div class="CaptionInnerContainer" >        <span class="CaptionEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionBorderTop" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <div class="Text" >Guild Deleted</div>        <span class="CaptionVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <span class="CaptionBorderBottom" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>      </div>    </div>    <tr>      <td>        <div class="InnerTableContainer" >          <table style="width:100%;" ><tr><td><b>'.htmlspecialchars($to_player->getName()).'</b> is now a Leader of <b>'.htmlspecialchars($guild->getName()).'</b>.</td></tr>          </table>        </div>  </table></div></td></tr><br/><center><form action="?subtopic=guilds&guild='.$guild_id.'&action=show" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1699.                 }
  1700.                 else
  1701.                     $main_content .= '<div class="TableContainer" >  <table class="Table1" cellpadding="0" cellspacing="0" >    <div class="CaptionContainer" >      <div class="CaptionInnerContainer" >        <span class="CaptionEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionBorderTop" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <div class="Text" >Guild Deleted</div>        <span class="CaptionVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <span class="CaptionBorderBottom" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>      </div>    </div>    <tr>      <td>        <div class="InnerTableContainer" >          <table style="width:100%;" ><tr><td>Pass leadership to: </b><br>
  1702.                     <form action="?subtopic=guilds&guild='.$guild_id.'&action=passleadership" METHOD=post><input type="hidden" name="todo" value="save"><input type="text" size="40" name="player"><input type="submit" value="Save"></form>
  1703.                     </td></tr>          </table>        </div>  </table></div></td></tr><br/><center><form action="?subtopic=guilds&guild='.$guild_id.'&action=manager" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1704.             }
  1705.             else
  1706.                 $guild_errors[] = 'You are not a leader of guild!';
  1707.         }
  1708.         else
  1709.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1710.     }
  1711.     if(empty($guild_errors) && !empty($guild_errors2))
  1712.     {
  1713.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1714.         foreach($guild_errors2 as $guild_error2)
  1715.             $main_content .= '<li>'.$guild_error2;
  1716.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1717.         $main_content .= '<br/><center><form action="?subtopic=guilds&guild='.$guild_id.'&action=passleadership" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1718.     }
  1719.     if(!empty($guild_errors))
  1720.     {
  1721.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1722.         foreach($guild_errors as $guild_error)
  1723.             $main_content .= '<li>'.$guild_error;
  1724.         if(!empty($guild_errors2))
  1725.             foreach($guild_errors2 as $guild_error2)
  1726.                 $main_content .= '<li>'.$guild_error2;
  1727.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br><br/><center><form action="?subtopic=guilds&action=show&guild='.$guild_id.'" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1728.     }
  1729. }
  1730. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1731. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1732. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1733. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1734. if($action == 'deleteguild')
  1735. {
  1736.     $guild_id = (int) $_REQUEST['guild'];
  1737.     if(empty($guild_errors))
  1738.     {
  1739.         $guild = new Guild();
  1740.         $guild->load($guild_id);
  1741.         if(!$guild->isLoaded())
  1742.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1743.     }
  1744.     if(empty($guild_errors))
  1745.     {
  1746.         if($logged)
  1747.         {
  1748.             $guild_leader_char = $guild->getOwner();
  1749.             $rank_list = $guild->getGuildRanksList();
  1750.             $guild_leader = FALSE;
  1751.             $account_players = $account_logged->getPlayers();
  1752.             foreach($account_players as $player)
  1753.                 if($guild->getOwner()->getId() == $player->getId())
  1754.                 {
  1755.                     $guild_vice = TRUE;
  1756.                     $guild_leader = TRUE;
  1757.                     $level_in_guild = 3;
  1758.                 }
  1759.             if($guild_leader)
  1760.             {
  1761.                 if($_POST['todo'] == 'save')
  1762.                 {
  1763.                     $guild->delete();
  1764.                     $saved = TRUE;
  1765.                 }
  1766.                 if($saved)
  1767.                 {
  1768.                     $main_content .= '<div class="TableContainer" >  <table class="Table1" cellpadding="0" cellspacing="0" >    <div class="CaptionContainer" >      <div class="CaptionInnerContainer" >        <span class="CaptionEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionBorderTop" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <div class="Text" >Guild Deleted</div>        <span class="CaptionVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <span class="CaptionBorderBottom" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>      </div>    </div>    <tr>      <td>        <div class="InnerTableContainer" >          <table style="width:100%;" ><tr><td>Guild with ID <b>'.$guild_id.'</b> has been deleted.</td></tr>          </table>        </div>  </table></div></td></tr>';
  1769.                     $main_content .= '<br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1770.                 }
  1771.                 else
  1772.                 {
  1773.                     $main_content .= '<div class="TableContainer" >  <table class="Table1" cellpadding="0" cellspacing="0" >    <div class="CaptionContainer" >      <div class="CaptionInnerContainer" >        <span class="CaptionEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionBorderTop" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <div class="Text" >Guild Deleted</div>        <span class="CaptionVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <span class="CaptionBorderBottom" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>      </div>    </div>    <tr>      <td>        <div class="InnerTableContainer" >          <table style="width:100%;" ><tr><td>Are you sure you want delete guild with ID <b>'.$guild_id.'</b>?<br>
  1774.                     <form action="?subtopic=guilds&guild='.$guild_id.'&action=deleteguild" METHOD=post><input type="hidden" name="todo" value="save"><input type="submit" value="Yes, delete"></form>
  1775.                     </td></tr>          </table>        </div>  </table></div></td></tr>';
  1776.                     $main_content .= '<br/><center><form action="?subtopic=guilds&guild='.$guild_id.'&action=manager" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1777.                 }
  1778.             }
  1779.             else
  1780.                 $guild_errors[] = 'You are not a leader of guild!';
  1781.         }
  1782.         else
  1783.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1784.     }
  1785.     if(!empty($guild_errors))
  1786.     {
  1787.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1788.         foreach($guild_errors as $guild_error)
  1789.             $main_content .= '<li>'.$guild_error.'</li>';
  1790.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1791.         $main_content .= '<br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1792.     }
  1793. }
  1794.  
  1795.  
  1796. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1797. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1798. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1799. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1800. if($action == 'deletebyadmin')
  1801. {
  1802.     $guild_id = (int) $_REQUEST['guild'];
  1803.     if(empty($guild_errors))
  1804.     {
  1805.         $guild = new Guild();
  1806.         $guild->load($guild_id);
  1807.         if(!$guild->isLoaded())
  1808.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1809.     }
  1810.     if(empty($guild_errors))
  1811.     {
  1812.         if($logged)
  1813.         {
  1814.             if($group_id_of_acc_logged >= $config['site']['access_admin_panel'])
  1815.             {
  1816.                 if($_POST['todo'] == 'save')
  1817.                 {
  1818.                     $guild->delete();
  1819.                     $main_content .= '<div class="TableContainer" >  <table class="Table1" cellpadding="0" cellspacing="0" >    <div class="CaptionContainer" >      <div class="CaptionInnerContainer" >        <span class="CaptionEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionBorderTop" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <div class="Text" >Guild Deleted</div>        <span class="CaptionVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <span class="CaptionBorderBottom" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>      </div>    </div>    <tr>      <td>        <div class="InnerTableContainer" >          <table style="width:100%;" ><tr><td>Guild with ID <b>'.$guild_id.'</b> has been deleted.</td></tr>          </table>        </div>  </table></div></td></tr><br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1820.                 }
  1821.                 else
  1822.                     $main_content .= '<div class="TableContainer" >  <table class="Table1" cellpadding="0" cellspacing="0" >    <div class="CaptionContainer" >      <div class="CaptionInnerContainer" >        <span class="CaptionEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionBorderTop" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <div class="Text" >Guild Deleted</div>        <span class="CaptionVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span>        <span class="CaptionBorderBottom" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span>        <span class="CaptionEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>        <span class="CaptionEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span>      </div>    </div>    <tr>      <td>        <div class="InnerTableContainer" >          <table style="width:100%;" ><tr><td>Are you sure you want delete guild <b>'.htmlspecialchars($guild->getName()).'</b>?<br>
  1823.                     <form action="?subtopic=guilds&guild='.$guild_id.'&action=deletebyadmin" METHOD=post><input type="hidden" name="todo" value="save"><input type="submit" value="Yes, delete"></form>
  1824.                     </td></tr>          </table>        </div>  </table></div></td></tr><br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1825.             }
  1826.             else
  1827.                 $guild_errors[] = 'You are not an admin!';
  1828.         }
  1829.         else
  1830.             $guild_errors[] = 'You are not logged. You can\'t delete guild.';
  1831.     }
  1832.     if(!empty($guild_errors))
  1833.     {
  1834.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1835.         foreach($guild_errors as $guild_error)
  1836.             $main_content .= '<li>'.$guild_error.'</li>';
  1837.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1838.         $main_content .= '<br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1839.     }
  1840. }
  1841.  
  1842. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1843. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1844. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1845. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1846. if($action == 'changemotd')
  1847. {
  1848.     $guild_id = (int) $_REQUEST['guild'];
  1849.     if(empty($guild_errors))
  1850.     {
  1851.         $guild = new Guild();
  1852.         $guild->load($guild_id);
  1853.         if(!$guild->isLoaded())
  1854.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1855.     }
  1856.     if(empty($guild_errors))
  1857.     {
  1858.         if($logged)
  1859.         {
  1860.             $guild_leader_char = $guild->getOwner();
  1861.             $rank_list = $guild->getGuildRanksList();
  1862.             $guild_leader = FALSE;
  1863.             $account_players = $account_logged->getPlayers();
  1864.             foreach($account_players as $player)
  1865.                 if($guild->getOwner()->getId() == $player->getId())
  1866.                 {
  1867.                     $guild_vice = TRUE;
  1868.                     $guild_leader = TRUE;
  1869.                     $level_in_guild = 3;
  1870.                 }
  1871.             if($guild_leader)
  1872.             {
  1873.                 if($_REQUEST['todo'] == 'save')
  1874.                 {
  1875.                     $motd = htmlspecialchars(substr(trim($_REQUEST['motd']),0,$config['site']['guild_motd_chars_limit']));
  1876.                     $guild->set('motd', $motd);
  1877.                     $guild->save();
  1878.                     $saved = TRUE;
  1879.                 }
  1880.                 $main_content .= '<center><h2>Change guild MOTD</h2></center>';
  1881.                 if($saved)
  1882.                     $main_content .= '<center><font color="red" size="3"><b>CHANGES HAS BEEN SAVED!</b></font></center><br>';
  1883.                 $main_content .= 'Here you can change MOTD (Message of the Day, showed in game!) of your guild.<BR>';
  1884.                 $main_content .= '<form enctype="multipart/form-data" action="?subtopic=guilds&guild='.$guild_id.'&action=changemotd" method="POST">
  1885.                 <input type="hidden" name="todo" value="save" />
  1886.                     <textarea name="motd" cols="60" rows="3">'.$guild->get('motd').'</textarea><br>
  1887.                     (max. '.$config['site']['guild_motd_chars_limit'].' chars) <input type="submit" value="Save MOTD" /></form><br>';
  1888.                 $main_content .= '<br/><center><form action="?subtopic=guilds&guild='.$guild_id.'&action=manager" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1889.             }
  1890.             else
  1891.                 $guild_errors[] = 'You are not a leader of guild!';
  1892.         }
  1893.         else
  1894.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1895.     }
  1896.     if(!empty($guild_errors))
  1897.     {
  1898.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1899.         foreach($guild_errors as $guild_error)
  1900.             $main_content .= '<li>'.$guild_error;
  1901.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1902.         $main_content .= '<br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  1903.     }
  1904. }
  1905.  
  1906. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1907. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1908. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1909. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1910. if($action == 'saveranks')
  1911. {
  1912.     $guild_id = (int) $_REQUEST['guild'];
  1913.     if(empty($guild_errors))
  1914.     {
  1915.         $guild = new Guild();
  1916.         $guild->load($guild_id);
  1917.         if(!$guild->isLoaded())
  1918.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1919.     }
  1920.     if(empty($guild_errors))
  1921.     {
  1922.         if($logged)
  1923.         {
  1924.             $guild_leader_char = $guild->getOwner();
  1925.             $rank_list = $guild->getGuildRanksList();
  1926.             $guild_leader = FALSE;
  1927.             $account_players = $account_logged->getPlayers();
  1928.             foreach($account_players as $player)
  1929.                 if($guild_leader_char->getId() == $player->getId())
  1930.                 {
  1931.                     $guild_vice = TRUE;
  1932.                     $guild_leader = TRUE;
  1933.                     $level_in_guild = 3;
  1934.                 }
  1935.             if($guild_leader)
  1936.             {
  1937.                 foreach($rank_list as $rank)
  1938.                 {
  1939.                     $rank_id = $rank->getId();
  1940.                     $name = $_REQUEST[$rank_id.'_name'];
  1941.                     $level = (int) $_REQUEST[$rank_id.'_level'];
  1942.                     if(check_rank_name($name))
  1943.                         $rank->setName($name);
  1944.                     else
  1945.                         $ranks_errors[] = 'Invalid rank name. Please use only a-Z, 0-9 and spaces. Rank ID <b>'.$rank_id.'</b>.';
  1946.                     if($level > 0 && $level < 4)
  1947.                         $rank->setLevel($level);
  1948.                     else
  1949.                         $ranks_errors[] = 'Invalid rank level. Contact with admin. Rank ID <b>'.$rank_id.'</b>.';
  1950.                     $rank->save();
  1951.                 }
  1952.                 if(!empty($ranks_errors))
  1953.                 {
  1954.                     $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1955.                     foreach($ranks_errors as $guild_error)
  1956.                         $main_content .= '<li>'.$guild_error.'</li>';
  1957.                     $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1958.                 }
  1959.                 else
  1960.                     header("Location: ?subtopic=guilds&action=manager&guild=".$guild_id);
  1961.             }
  1962.             else
  1963.                 $guild_errors[] = 'You are not a leader of guild!';
  1964.         }
  1965.         else
  1966.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1967.     }
  1968.     if(!empty($guild_errors)) {
  1969.     $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  1970.     foreach($guild_errors as $guild_error) {
  1971.         $main_content .= '<li>'.$guild_error.'</li>';
  1972.     }
  1973.     $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  1974.     }
  1975. }
  1976. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1977. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1978. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1979. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1980. if($action == 'cleanup_players')
  1981. {
  1982.     if($logged)
  1983.     {
  1984.         if($group_id_of_acc_logged >= $config['site']['access_admin_panel'])
  1985.         {
  1986.             $players_list = new DatabaseList('Player');
  1987.         }
  1988.         else
  1989.             $players_list = $account_logged->getPlayersList();
  1990.         if(count($players_list) > 0)
  1991.         {
  1992.             foreach($players_list as $player)
  1993.             {
  1994.                 $player_rank = $player->getRank();
  1995.                 if(!empty($player_rank))
  1996.                 {
  1997.                     if($player_rank->isLoaded())
  1998.                     {
  1999.                         $rank_guild = $player_rank->getGuild();
  2000.                         if(!$rank_guild->isLoaded())
  2001.                         {
  2002.                             $player->setRank();
  2003.                             $player->setGuildNick();
  2004.                             $player->save();
  2005.                             $changed_ranks_of[] = $player->getName();
  2006.                             $deleted_ranks[] = 'ID: '.$player_rank->getId().' - '.$player_rank->getName();
  2007.                             $player_rank->delete();
  2008.                         }
  2009.                     }
  2010.                     else
  2011.                     {
  2012.                         $player->setRank();
  2013.                         $player->setGuildNick('');
  2014.                         $player->save();
  2015.                         $changed_ranks_of[] = $player->getName();
  2016.                     }
  2017.                    
  2018.                 }
  2019.             }
  2020.             $main_content .= "<b>Deleted ranks (this ranks guilds doesn't exist [bug fix]):</b>";
  2021.             if(!empty($deleted_ranks))
  2022.                 foreach($deleted_ranks as $rank)
  2023.                     $main_content .= "<li>".htmlspecialchars($rank);
  2024.             $main_content .= "<BR /><BR /><b>Changed ranks of players (rank or guild of rank doesn't exist [bug fix]):</b>";
  2025.             if(!empty($changed_ranks_of))
  2026.                 foreach($changed_ranks_of as $name)
  2027.                     $main_content .= "<li>".htmlspecialchars($name);
  2028.         }
  2029.         else
  2030.             $main_content .= "0 players found.";
  2031.     }
  2032.     else
  2033.         $main_content .= "You are not logged in.";
  2034.     $main_content .= "<center><h3><a href=\"?subtopic=guilds\">BACK</a></h3></center>";
  2035. }
  2036. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2037. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2038. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2039. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2040.     if($action == 'change_nick')
  2041.     {
  2042.         if($logged)
  2043.         {
  2044.             $player_n = $_REQUEST['name'];
  2045.             $new_nick = $_REQUEST['nick'];
  2046.             $player = new Player();
  2047.             $player->find($player_n);
  2048.             $player_from_account = FALSE;
  2049.             if(strlen($new_nick) <= 30)
  2050.             {
  2051.                 if($player->isLoaded())
  2052.                 {
  2053.                     $account_players = $account_logged->getPlayersList();
  2054.                     if(count($account_players))
  2055.                     {
  2056.                         foreach($account_players as $acc_player)
  2057.                         {
  2058.                             if($acc_player->getId() == $player->getId())
  2059.                                 $player_from_account = TRUE;
  2060.                         }
  2061.                         if($player_from_account)
  2062.                         {
  2063.                             $player->setGuildNick($new_nick);
  2064.                             $player->save();
  2065.                             $main_content .= 'Guild nick of player <b>'.htmlspecialchars($player->getName()).'</b> changed to <b>'.htmlspecialchars($new_nick).'</b>.';
  2066.                             $addtolink = '&action=show&guild='.$player->getRank()->getGuildId();
  2067.                         }
  2068.                         else
  2069.                             $main_content .= 'This player is not from your account.';
  2070.                     }
  2071.                     else
  2072.                         $main_content .= 'This player is not from your account.';
  2073.                 }
  2074.                 else
  2075.                     $main_content .= 'Unknow error occured.';
  2076.             }
  2077.             else
  2078.                 $main_content .= 'Too long guild nick. Max. 30 chars, your: '.strlen($new_nick);
  2079.         }
  2080.         else
  2081.             $main_content .= 'You are not logged.';
  2082.         $main_content .= '<center><h3><a href="?subtopic=guilds'.$addtolink.'">BACK</a></h3></center>';
  2083.     }
  2084. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2085. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2086. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2087. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2088. if($action == 'guildwar_invitation_accept')
  2089. {
  2090.     $guild_id = (int) $_REQUEST['guild'];
  2091.     $war_id = (int) $_REQUEST['war'];
  2092.     if(!$logged)
  2093.         $guild_errors[] = 'You are not logged.';
  2094.     if(empty($guild_errors))
  2095.     {
  2096.         $guild = new Guild($guild_id);
  2097.         if(!$guild->isLoaded())
  2098.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  2099.         if(empty($guild_errors))
  2100.         {
  2101.             $guild_leader_char = $guild->getOwner();
  2102.             $guild_leader = FALSE;
  2103.             $account_players = $account_logged->getPlayers();
  2104.             foreach($account_players as $player)
  2105.             {
  2106.                 if($guild_leader_char->getId() == $player->getId())
  2107.                 {
  2108.                     $guild_leader = TRUE;
  2109.                 }
  2110.             }
  2111.             if($guild_leader)
  2112.             {
  2113.                 $war = new GuildWar($war_id);
  2114.                 if(!$war->isLoaded())
  2115.                     $guild_errors[] = 'War with ID <b>'.$war_id.'</b> doesn\'t exist.';
  2116.  
  2117.                 if(empty($guild_errors))
  2118.                 {
  2119.                     if($war->getGuild2ID() != $guild->getID() || $war->getStatus() != GuildWar::STATE_INVITED)
  2120.                     {
  2121.                         $guild_errors[] = 'Your guild is not invited to that war.';
  2122.                     }
  2123.  
  2124.                     if(empty($guild_errors))
  2125.                     {
  2126.                         $war->setStatus(GuildWar::STATE_ON_WAR);
  2127.                         $war->setStarted(time());
  2128.                         $war->setEnded(0);
  2129.                         $war->save();
  2130.                         header("Location: ?subtopic=guilds&action=show&guild=".$guild_id."");
  2131.                         $main_content .= 'War invitation accepted. Redirecting...';
  2132.                     }
  2133.                 }
  2134.             }
  2135.             else
  2136.                 $guild_errors[] = 'You are not a leader of guild!';
  2137.         }
  2138.     }
  2139.     if(!empty($guild_errors))
  2140.     {
  2141.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  2142.         foreach($guild_errors as $guild_error)
  2143.             $main_content .= '<li>'.$guild_error.'</li>';
  2144.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  2145.         $main_content .= '<br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  2146.     }
  2147. }
  2148. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2149. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2150. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2151. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2152. if($action == 'guildwar_invitation_reject')
  2153. {
  2154.     $guild_id = (int) $_REQUEST['guild'];
  2155.     $war_id = (int) $_REQUEST['war'];
  2156.     if(!$logged)
  2157.         $guild_errors[] = 'You are not logged.';
  2158.     if(empty($guild_errors))
  2159.     {
  2160.         $guild = new Guild($guild_id);
  2161.         if(!$guild->isLoaded())
  2162.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  2163.         if(empty($guild_errors))
  2164.         {
  2165.             $guild_leader_char = $guild->getOwner();
  2166.             $guild_leader = FALSE;
  2167.             $account_players = $account_logged->getPlayers();
  2168.             foreach($account_players as $player)
  2169.             {
  2170.                 if($guild_leader_char->getId() == $player->getId())
  2171.                 {
  2172.                     $guild_leader = TRUE;
  2173.                 }
  2174.             }
  2175.             if($guild_leader)
  2176.             {
  2177.                 $war = new GuildWar($war_id);
  2178.                 if(!$war->isLoaded())
  2179.                     $guild_errors[] = 'War with ID <b>'.$war_id.'</b> doesn\'t exist.';
  2180.  
  2181.                 if(empty($guild_errors))
  2182.                 {
  2183.                     if($war->getGuild2ID() != $guild->getID() || $war->getStatus() != GuildWar::STATE_INVITED)
  2184.                     {
  2185.                         $guild_errors[] = 'Your guild is not invited to that war.';
  2186.                     }
  2187.  
  2188.                     if(empty($guild_errors))
  2189.                     {
  2190.                         $war->setStatus(GuildWar::STATE_REJECTED);
  2191.                         $war->setEnded(time());
  2192.                         $war->save();
  2193.                         header("Location: ?subtopic=guilds&action=show&guild=".$guild_id."");
  2194.                         $main_content .= 'War invitation rejected. Redirecting...';
  2195.                     }
  2196.                 }
  2197.             }
  2198.             else
  2199.                 $guild_errors[] = 'You are not a leader of guild!';
  2200.         }
  2201.     }
  2202.     if(!empty($guild_errors))
  2203.     {
  2204.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  2205.         foreach($guild_errors as $guild_error)
  2206.             $main_content .= '<li>'.$guild_error.'</li>';
  2207.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  2208.         $main_content .= '<br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  2209.     }
  2210. }
  2211. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2212. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2213. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2214. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2215. if($action == 'guildwar_invitation_cancel')
  2216. {
  2217.     $guild_id = (int) $_REQUEST['guild'];
  2218.     $war_id = (int) $_REQUEST['war'];
  2219.     if(!$logged)
  2220.         $guild_errors[] = 'You are not logged.';
  2221.     if(empty($guild_errors))
  2222.     {
  2223.         $guild = new Guild($guild_id);
  2224.         if(!$guild->isLoaded())
  2225.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  2226.         if(empty($guild_errors))
  2227.         {
  2228.             $guild_leader_char = $guild->getOwner();
  2229.             $guild_leader = FALSE;
  2230.             $account_players = $account_logged->getPlayers();
  2231.             foreach($account_players as $player)
  2232.             {
  2233.                 if($guild_leader_char->getId() == $player->getId())
  2234.                 {
  2235.                     $guild_leader = TRUE;
  2236.                 }
  2237.             }
  2238.             if($guild_leader)
  2239.             {
  2240.                 $war = new GuildWar($war_id);
  2241.                 if(!$war->isLoaded())
  2242.                     $guild_errors[] = 'War with ID <b>'.$war_id.'</b> doesn\'t exist.';
  2243.  
  2244.                 if(empty($guild_errors))
  2245.                 {
  2246.                     if($war->getGuild1ID() != $guild->getID() || $war->getStatus() != GuildWar::STATE_INVITED)
  2247.                     {
  2248.                         $guild_errors[] = 'Your guild did not invite to that war.';
  2249.                     }
  2250.  
  2251.                     if(empty($guild_errors))
  2252.                     {
  2253.                         $war->setStatus(GuildWar::STATE_CANCELED);
  2254.                         $war->setEnded(time());
  2255.                         $war->save();
  2256.                         header("Location: ?subtopic=guilds&action=show&guild=".$guild_id."");
  2257.                         $main_content .= 'War invitation rejected. Redirecting...';
  2258.                     }
  2259.                 }
  2260.             }
  2261.             else
  2262.                 $guild_errors[] = 'You are not a leader of guild!';
  2263.         }
  2264.     }
  2265.     if(!empty($guild_errors))
  2266.     {
  2267.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  2268.         foreach($guild_errors as $guild_error)
  2269.             $main_content .= '<li>'.$guild_error.'</li>';
  2270.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  2271.         $main_content .= '<br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  2272.     }
  2273. }
  2274.  
  2275. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2276. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2277. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2278. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2279. if($action == 'guildwar_choose_enemy')
  2280. {
  2281.     $guild_id = (int) $_REQUEST['guild'];
  2282.     if(!$logged)
  2283.         $guild_errors[] = 'You are not logged.';
  2284.     if(empty($guild_errors))
  2285.     {
  2286.         $guild = new Guild($guild_id);
  2287.         if(!$guild->isLoaded())
  2288.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  2289.         if(empty($guild_errors))
  2290.         {
  2291.             $guild_leader_char = $guild->getOwner();
  2292.             $guild_leader = FALSE;
  2293.             $account_players = $account_logged->getPlayers();
  2294.             foreach($account_players as $player)
  2295.             {
  2296.                 if($guild_leader_char->getId() == $player->getId())
  2297.                 {
  2298.                     $guild_leader = TRUE;
  2299.                 }
  2300.             }
  2301.             if($guild_leader)
  2302.             {
  2303.                 $currentWars = array();
  2304.                 $wars = new DatabaseList('GuildWar');
  2305.                 foreach($wars as $war)
  2306.                 {
  2307.                     if($war->getStatus() == GuildWar::STATE_INVITED || $war->getStatus() == GuildWar::STATE_ON_WAR)
  2308.                     {
  2309.                         if($war->getGuild1ID() == $guild->getID())
  2310.                             $currentWars[$war->getGuild2ID()] = $war->getStatus();
  2311.                         elseif($war->getGuild2ID() == $guild->getID())
  2312.                             $currentWars[$war->getGuild1ID()] = $war->getStatus();
  2313.                     }
  2314.                 }
  2315.  
  2316.                 $main_content .= '<center><h1>' . htmlspecialchars($guild->getName()) . ' vs. ???</h2></center><br /><h3>Choose your enemy!</h3><br /><table width="100%" border="0" cellspacing="1" cellpadding="4">';
  2317.  
  2318.                 $guildsList = new DatabaseList('Guild');
  2319.                 $guildsList->addOrder(new SQL_Order(new SQL_Field('name'), SQL_Order::ASC));
  2320.                 $shown_guilds = 0;
  2321.                 foreach($guildsList as $enemyGuild)
  2322.                 {
  2323.                     if(is_int($shown_guilds / 2)) { $bgcolor = $config['site']['darkborder']; } else { $bgcolor = $config['site']['lightborder']; } $shown_guilds++;
  2324.                     $main_content .= '<tr BGCOLOR="'.$bgcolor.'"><td width="70px"><IMG SRC="guild_image.php?id='. $enemyGuild->getID() .'" WIDTH="64" HEIGHT="64"></td><td valign="top"><B>'.htmlspecialchars($enemyGuild->getName()).'</B></td><td>';
  2325.                     if($enemyGuild->getID() != $guild->getID())
  2326.                     {
  2327.                         if(isset($currentWars[$enemyGuild->getID()]))
  2328.                         {
  2329.                             // in war or invited
  2330.                             if($currentWars[$enemyGuild->getID()] == GuildWar::STATE_INVITED)
  2331.                             {
  2332.                                 // guild already invited you or you invited that guild
  2333.                                 $main_content .= 'There is already invitation between your and this guild.';
  2334.                             }
  2335.                             else
  2336.                             {
  2337.                                 // you are on war with this guild
  2338.                                 $main_content .= 'There is already war between your and this guild.';
  2339.                             }
  2340.                         }
  2341.                         else
  2342.                         {
  2343.                             // can invite
  2344.                             $main_content .= '<a href="?subtopic=guilds&action=guildwar_invite_guild&guild=' . $guild->getID() . '&enemy=' . $enemyGuild->getID() . '" onclick="return confirm(\'Are you sure that you want invite that guild?\')">INVITE FOR WAR</a>';
  2345.                         }
  2346.                     }
  2347.                     else
  2348.                     {
  2349.                         // your own guild
  2350.                         $main_content .= 'YOUR GUILD';
  2351.                     }
  2352.                     $main_content .= '</td></tr>';
  2353.                 }
  2354.                 $main_content .= '</table>';
  2355.             }
  2356.             else
  2357.                 $guild_errors[] = 'You are not a leader of guild!';
  2358.         }
  2359.     }
  2360.     if(!empty($guild_errors))
  2361.     {
  2362.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  2363.         foreach($guild_errors as $guild_error)
  2364.             $main_content .= '<li>'.$guild_error.'</li>';
  2365.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  2366.         $main_content .= '<br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  2367.     }
  2368. }
  2369.  
  2370.  
  2371. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2372. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2373. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2374. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  2375. if($action == 'guildwar_invite_guild')
  2376. {
  2377.     $guild_id = (int) $_REQUEST['guild'];
  2378.     $enemy_id = (int) $_REQUEST['enemy'];
  2379.     if(!$logged)
  2380.         $guild_errors[] = 'You are not logged.';
  2381.     if(empty($guild_errors))
  2382.     {
  2383.         $guild = new Guild($guild_id);
  2384.         $enemyGuild = new Guild($enemy_id);
  2385.         if(!$guild->isLoaded() || !$enemyGuild->isLoaded())
  2386.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> or ID<b>'.$enemy_id.'</b> doesn\'t exist.';
  2387.         if(empty($guild_errors))
  2388.         {
  2389.             $guild_leader_char = $guild->getOwner();
  2390.             $guild_leader = FALSE;
  2391.             $account_players = $account_logged->getPlayers();
  2392.             foreach($account_players as $player)
  2393.             {
  2394.                 if($guild_leader_char->getId() == $player->getId())
  2395.                 {
  2396.                     $guild_leader = TRUE;
  2397.                 }
  2398.             }
  2399.             if($guild_leader)
  2400.             {
  2401.                 if($enemyGuild->getID() != $guild->getID())
  2402.                 {
  2403.                     $currentWars = array();
  2404.                     $wars = new DatabaseList('GuildWar');
  2405.                     foreach($wars as $war)
  2406.                     {
  2407.                         if($war->getStatus() == GuildWar::STATE_INVITED || $war->getStatus() == GuildWar::STATE_ON_WAR)
  2408.                         {
  2409.                             if($war->getGuild1ID() == $guild->getID())
  2410.                                 $currentWars[$war->getGuild2ID()] = $war->getStatus();
  2411.                             elseif($war->getGuild2ID() == $guild->getID())
  2412.                                 $currentWars[$war->getGuild1ID()] = $war->getStatus();
  2413.                         }
  2414.                     }
  2415.                     if(isset($currentWars[$enemyGuild->getID()]))
  2416.                     {
  2417.                         // in war or invited
  2418.                         if($currentWars[$enemyGuild->getID()] == GuildWar::STATE_INVITED)
  2419.                         {
  2420.                             // guild already invited you or you invited that guild
  2421.                             $guild_errors[] = 'There is already invitation between your and this guild.';
  2422.                         }
  2423.                         else
  2424.                         {
  2425.                             // you are on war with this guild
  2426.                             $guild_errors[] = 'There is already war between your and this guild.';
  2427.                         }
  2428.                     }
  2429.                     else
  2430.                     {
  2431.                         // can invite
  2432.                         $war = new GuildWar();
  2433.                         $war->setGuild1ID($guild->getID());
  2434.                         $war->setGuild2ID($enemyGuild->getID());
  2435.                         $war->setGuild1Name($guild->getName());
  2436.                         $war->setGuild2Name($enemyGuild->getName());
  2437.                         $war->setStatus(GuildWar::STATE_INVITED);
  2438.                         $war->setStarted(time());
  2439.                         $war->setEnded(0);
  2440.                         $war->save();
  2441.                         header("Location: ?subtopic=guilds&action=show&guild=".$guild_id."");
  2442.                         $main_content .= 'War invitation sent. Redirecting...';
  2443.                     }
  2444.                 }
  2445.                 else
  2446.                 {
  2447.                     $guild_errors[] = 'You cannot invite same guild!';
  2448.                 }
  2449.             }
  2450.             else
  2451.                 $guild_errors[] = 'You are not a leader of guild!';
  2452.         }
  2453.     }
  2454.     if(!empty($guild_errors))
  2455.     {
  2456.         $main_content .= '<div class="SmallBox" >  <div class="MessageContainer" >    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="ErrorMessage" >      <div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div>      <div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>';
  2457.         foreach($guild_errors as $guild_error)
  2458.             $main_content .= '<li>'.$guild_error.'</li>';
  2459.         $main_content .= '</div>    <div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>    <div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div>  </div></div><br>';
  2460.         $main_content .= '<br/><center><form action="?subtopic=guilds" METHOD=post><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Back" alt="Back" src="'.$layout_name.'/images/buttons/_sbutton_back.gif" ></div></div></form></center>';
  2461.     }
  2462. }
Add Comment
Please, Sign In to add comment