Guest User

Gesior 2012 - guilds.php

a guest
Feb 14th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 150.29 KB | None | 0 0
  1. <?php
  2. if(!defined('INITIALIZED'))
  3.     exit;
  4.  
  5. if($action == 'login')
  6. {
  7.     if(check_guild_name($_REQUEST['guild']))
  8.         $guild = $_REQUEST['guild'];
  9.     if($_REQUEST['redirect'] == 'guild' || $_REQUEST['redirect'] == 'guilds')
  10.         $redirect = $_REQUEST['redirect'];
  11.     if(!$logged)
  12.     {
  13.         $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>';
  14.     }
  15.     else
  16.     {
  17.         $main_content .= '<center><h3>Now you are logged. Redirecting...</h3></center>';
  18.         if($redirect == 'guilds')
  19.             header("Location: ?subtopic=guilds");
  20.         elseif($redirect == 'guild')
  21.             header("Location: ?subtopic=guilds&action=show&guild=".urlencode($guild));
  22.         else
  23.             $main_content .= 'Wrong address to redirect!';
  24.     }
  25. }
  26. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  27. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  28. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  29. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  30. //show list of guilds
  31. if($action == '')
  32. {
  33.     if(count($config['site']['worlds']) > 1)
  34.     {
  35.         foreach($config['site']['worlds'] as $idd => $world_n)
  36.         {
  37.             if($idd == (int) $_REQUEST['world'])
  38.             {
  39.                 $world_id = $idd;
  40.                 $world_name = $world_n;
  41.             }
  42.         }
  43.     }
  44.     if(!isset($world_id))
  45.     {
  46.         $world_id = 0;
  47.         $world_name = $config['server']['serverName'];
  48.     }
  49.     if(count($config['site']['worlds']) > 1)
  50.     {
  51.         $main_content .= '<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR><TD></TD><TD>
  52.         <FORM ACTION="" METHOD=get><INPUT TYPE="hidden" NAME="subtopic" VALUE="guilds"><TABLE WIDTH=100% BORDER=0 CELLSPACING=1 CELLPADDING=4><TR><TD BGCOLOR="'.$config['site']['vdarkborder'].'" CLASS=white><B>World Selection</B></TD></TR><TR><TD BGCOLOR="'.$config['site']['darkborder'].'">
  53.         <TABLE BORDER=0 CELLPADDING=1><TR><TD>Guilds on world:</TD><TD><SELECT SIZE="1" NAME="world">';
  54.         foreach($config['site']['worlds'] as $id => $world_n)
  55.         {
  56.             if($id == $world_id)
  57.                 $main_content .= '<OPTION VALUE="'.$id.'" selected="selected">'.htmlspecialchars($world_n).'</OPTION>';
  58.             else
  59.                 $main_content .= '<OPTION VALUE="'.$id.'">'.htmlspecialchars($world_n).'</OPTION>';
  60.         }
  61.         $main_content .= '</SELECT> </TD><TD><INPUT TYPE="image" NAME="Submit" ALT="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif">
  62.             </TD></TR></TABLE></TABLE></FORM></TABLE>';
  63.     }
  64.    
  65.     $guilds_list = new DatabaseList('Guild');
  66.     $filterWorld = new SQL_Filter(new SQL_Field('world_id', 'guilds'), SQL_Filter::EQUAL, $world_id);
  67.     $guilds_list->setFilter($filterWorld);
  68.     $guilds_list->addOrder(new SQL_Order(new SQL_Field('name'), SQL_Order::ASC));
  69.    
  70.     $main_content .= '<h2><center>Guilds on '.htmlspecialchars($world_name).'</center></h2><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>
  71.     <TR BGCOLOR='.$config['site']['vdarkborder'].'><TD COLSPAN=3 CLASS=white><B>Guilds on '.htmlspecialchars($world_name).'</B></TD></TR>
  72.     <TR BGCOLOR='.$config['site']['darkborder'].'><TD WIDTH=64><B>Logo</B></TD>
  73.     <TD WIDTH=100%><B>Description</B></TD>
  74.     <TD WIDTH=56><B>&#160;</B></TD></TR>';
  75.     $showed_guilds = 1;
  76.     if(count($guilds_list) > 0)
  77.     {
  78.         foreach($guilds_list as $guild)
  79.         {
  80.             if(is_int($showed_guilds / 2)) { $bgcolor = $config['site']['darkborder']; } else { $bgcolor = $config['site']['lightborder']; } $showed_guilds++;
  81.             $description = $guild->getDescription();
  82.             $newlines   = array("\r\n", "\n", "\r");
  83.             $description_with_lines = str_replace($newlines, '<br />', $description, $count);
  84.             if($count < $config['site']['guild_description_lines_limit'])
  85.                 $description = $description_with_lines;
  86.             $main_content .= '<TR BGCOLOR="'.$bgcolor.'"><TD><IMG SRC="'. $guild->getGuildLogoLink() .'" WIDTH=64 HEIGHT=64></TD>
  87.             <TD valign="top"><B>'.htmlspecialchars($guild->getName()).'</B><BR/>'.$description.'';
  88.             if($group_id_of_acc_logged >= $config['site']['access_admin_panel'])
  89.                 $main_content .= '<br /><a href="?subtopic=guilds&action=deletebyadmin&guild='.$guild->getId().'">Delete this guild (for ADMIN only!)</a>';
  90.             $main_content .= '</TD><TD><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds&action=show&guild='.$guild->getId().'" METHOD=post><TR><TD>
  91.             <INPUT TYPE=image NAME="View" ALT="View" SRC="'.$layout_name.'/images/buttons/sbutton_view.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  92.             </TD></TR></FORM></TABLE>
  93.             </TD></TR>';
  94.         }
  95.     }
  96.     else
  97.         $main_content .= '<TR BGCOLOR='.$config['site']['lightborder'].'><TD><IMG SRC="images/default_guild_logo.gif" WIDTH=64 HEIGHT=64></TD>
  98.         <TD valign="top"><B>Create guild</B><BR/>Currently there is no guild on server. Create first! Press button "Create Guild".</TD>
  99.         <TD><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds&action=createguild" METHOD=post><TR><TD>
  100.         <INPUT TYPE=image NAME="Create Guild" ALT="Create Guild" SRC="'.$layout_name.'/images/buttons/sbutton_createguild.png" BORDER=0 WIDTH=120 HEIGHT=18>
  101.         </TD></TR></FORM></TABLE></TD></TR>';
  102.     $main_content .= '</TABLE><br><br>';
  103.     if($logged)
  104.         $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>
  105.         <INPUT TYPE=image NAME="Create Guild" ALT="Create Guild" SRC="'.$layout_name.'/images/buttons/sbutton_createguild.png" BORDER=0 WIDTH=120 HEIGHT=18>
  106.         </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>
  107.         <BR />If you have any problem with guilds try:
  108.         <BR /><a href="?subtopic=guilds&action=cleanup_players">Cleanup players</a> - can\'t join guild/be invited? Can\'t create guild? Try cleanup players.';
  109.     else
  110.         $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>
  111.         <INPUT TYPE=image NAME="Login" ALT="Login" SRC="'.$layout_name.'/images/buttons/sbutton_login.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  112.         </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>';
  113. }
  114. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  115. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  116. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  117. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  118. //show guild page
  119. if($action == 'show')
  120. {
  121.     $guild_id = (int) $_REQUEST['guild'];
  122.     $guild = new Guild();
  123.     $guild->load($guild_id);
  124.     if(!$guild->isLoaded())
  125.         $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  126.     if(!empty($guild_errors))
  127.     {
  128.         //show errors
  129.         $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/>';
  130.         foreach($guild_errors as $guild_error)
  131.             $main_content .= '<li>'.$guild_error;
  132.         //errors and back button
  133.         $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>';
  134.     }
  135.     else
  136.     {
  137.         //check is it vice or/and leader account (leader has vice + leader rights)
  138.         $guild_leader_char = $guild->getOwner();
  139.         $rank_list = $guild->getGuildRanksList();
  140.         $guild_leader = FALSE;
  141.         $guild_vice = FALSE;
  142.         if($logged)
  143.         {
  144.             $account_players = $account_logged->getPlayers();
  145.             foreach($account_players as $player)
  146.             {
  147.                 $players_from_account_ids[] = $player->getId();
  148.                 $player_rank = $player->getRank();
  149.                 if(!empty($player_rank))
  150.                     foreach($rank_list as $rank_in_guild)
  151.                         if($rank_in_guild->getId() == $player_rank->getId())
  152.                         {
  153.                             $players_from_account_in_guild[] = $player->getName();
  154.                             if($player_rank->getLevel() > 1)
  155.                             {
  156.                                 $guild_vice = TRUE;
  157.                                 $level_in_guild = $player_rank->getLevel();
  158.                             }
  159.                             if($guild->getOwner()->getId() == $player->getId())
  160.                             {
  161.                                 $guild_vice = TRUE;
  162.                                 $guild_leader = TRUE;
  163.                             }
  164.                         }
  165.             }
  166.         }
  167.         //show guild page
  168.         $description = $guild->getDescription();
  169.         $newlines   = array("\r\n", "\n", "\r");
  170.         $description_with_lines = str_replace($newlines, '<br />', $description, $count);
  171.         if($count < $config['site']['guild_description_lines_limit'])
  172.             $description = $description_with_lines;
  173.         $guild_owner = $guild->getOwner();
  174.         if($guild_owner->isLoaded())
  175.             $guild_owner = $guild_owner->getName();
  176.         $main_content .= '<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR>
  177.         <TD><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=10 HEIGHT=1 BORDER=0></TD><TD>
  178.         <TABLE BORDER=0 WIDTH=100%>
  179.         <TR><TD WIDTH=64><IMG SRC="' . $guild->getGuildLogoLink() . '" WIDTH=64 HEIGHT=64></TD>
  180.         <TD ALIGN=center WIDTH=100%><H1>'.htmlspecialchars($guild->getName()).'</H1></TD>
  181.         <TD WIDTH=64><IMG SRC="' . $guild->getGuildLogoLink() . '" WIDTH=64 HEIGHT=64></TD></TR>
  182.         </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()).'.';
  183.         if($guild_leader)
  184.             $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>';
  185.         $main_content .= '<BR><BR>
  186.         <TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>
  187.         <TR BGCOLOR='.$config['site']['vdarkborder'].'><TD COLSPAN=3 CLASS=white><B>Guild Members</B></TD></TR>
  188.         <TR BGCOLOR='.$config['site']['darkborder'].'><TD WIDTH=30%><B>Rank</B></TD>
  189.         <TD WIDTH=70%><B>Name and Title</B></TD></TR>';
  190.         $showed_players = 1;
  191.         foreach($rank_list as $rank)
  192.         {
  193.             $players_with_rank = $rank->getPlayersList();
  194.             $players_with_rank_number = count($players_with_rank);
  195.             if($players_with_rank_number > 0)
  196.             {
  197.                 if(is_int($showed_players / 2)) { $bgcolor = $config['site']['darkborder']; } else { $bgcolor = $config['site']['lightborder']; } $showed_players++;
  198.                 $main_content .= '<TR BGCOLOR="'.$bgcolor.'"><TD valign="top">'.htmlspecialchars($rank->getName()).'</TD>
  199.                 <TD><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>';
  200.                 foreach($players_with_rank as $player)
  201.                 {
  202.                     $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>';
  203.                     $guild_nick = $player->getGuildNick();
  204.                     if($logged)
  205.                         if(in_array($player->getId(), $players_from_account_ids))
  206.                             $main_content .= '(<input type="text" name="nick" value="'.htmlspecialchars($player->getGuildNick()).'"><input type="submit" value="Change">)';
  207.                         else
  208.                         if(!empty($guild_nick))
  209.                             $main_content .= ' ('.htmlspecialchars($player->getGuildNick()).')';
  210.                     else
  211.                         if(!empty($guild_nick))
  212.                             $main_content .= ' ('.htmlspecialchars($player->getGuildNick()).')';
  213.                     if($level_in_guild > $rank->getLevel() || $guild_leader)
  214.                         if($guild_leader_char->getName() != $player->getName())
  215.                             $main_content .= '&nbsp;<font size=1>{<a href="?subtopic=guilds&action=kickplayer&guild='.$guild->getId().'&name='.urlencode($player->getName()).'">KICK</a>}</font>';
  216.                     $main_content .= '</FORM></TD></TR>';
  217.                 }
  218.                 $main_content .= '</TABLE></TD></TR>';
  219.             }
  220.         }
  221.         $main_content .= '</TABLE>';
  222.         $invited_list = $guild->listInvites();
  223.         if(count($invited_list) == 0)
  224.             $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>';
  225.         else
  226.         {
  227.             $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>';
  228.             $show_accept_invite = 0;
  229.             $showed_invited = 1;
  230.             foreach($invited_list as $invited_player)
  231.             {
  232.                 if(count($account_players) > 0)
  233.                     foreach($account_players as $player_from_acc)
  234.                         if($player_from_acc->getName() == $invited_player->getName())
  235.                             $show_accept_invite++;
  236.                 if(is_int($showed_invited / 2)) { $bgcolor = $config['site']['darkborder']; } else { $bgcolor = $config['site']['lightborder']; } $showed_invited++;
  237.                 $main_content .= '<TR bgcolor="'.$bgcolor.'"><TD><a href="?subtopic=characters&name='.urlencode($invited_player->getName()).'">'.htmlspecialchars($invited_player->getName()).'</a>';
  238.                 if($guild_vice)
  239.                     $main_content .= '  (<a href="?subtopic=guilds&action=deleteinvite&guild='.$guild_id.'&name='.urlencode($invited_player->getName()).'">Cancel Invitation</a>)';
  240.                 $main_content .= '</TD></TR>';
  241.             }
  242.             $main_content .= '</TABLE>';
  243.         }
  244.         $main_content .= '<BR><BR>
  245.         <TABLE BORDER=0 WIDTH=100%><TR><TD ALIGN=center><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=80 HEIGHT=1 BORDER=0<BR></TD>';
  246.         if(!$logged)
  247.             $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>
  248.             <INPUT TYPE=image NAME="Login" ALT="Login" SRC="'.$layout_name.'/images/buttons/sbutton_login.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  249.             </TD></TR></FORM></TABLE></TD>';
  250.         else
  251.         {
  252.             if($show_accept_invite > 0)
  253.                 $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>
  254.                 <INPUT TYPE=image NAME="Accept Invite" ALT="Accept Invite" SRC="'.$layout_name.'/images/buttons/sbutton_acceptinvite.png" BORDER=0 WIDTH=120 HEIGHT=18>
  255.                 </TD></TR></FORM></TABLE></TD>';
  256.             if($guild_vice)
  257.             {
  258.                 $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>
  259.                 <INPUT TYPE=image NAME="Invite Player" ALT="Invite Player" SRC="'.$layout_name.'/images/buttons/sbutton_inviteplayer.png" BORDER=0 WIDTH=120 HEIGHT=18>
  260.                 </TD></TR></FORM></TABLE></TD>';
  261.                 $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>
  262.                 <INPUT TYPE=image NAME="Change Rank" ALT="Change Rank" SRC="'.$layout_name.'/images/buttons/sbutton_changerank.png" BORDER=0 WIDTH=120 HEIGHT=18>
  263.                 </TD></TR></FORM></TABLE></TD>';
  264.             }
  265.             if($players_from_account_in_guild > 0)
  266.                 $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>
  267.                 <INPUT TYPE=image NAME="Leave Guild" ALT="Leave Guild" SRC="'.$layout_name.'/images/buttons/sbutton_leaveguild.png" BORDER=0 WIDTH=120 HEIGHT=18>
  268.                 </TD></TR></FORM></TABLE></TD>';
  269.         }
  270.         $main_content .= '<TD ALIGN=center><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM ACTION="?subtopic=guilds&world='.$guild->getWorld().'" METHOD=post><TR><TD>
  271.         <INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  272.         </TD></TR></FORM></TABLE>
  273.         </TD><TD ALIGN=center><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=80 HEIGHT=1 BORDER=0<BR></TD></TR></TABLE>
  274.         </TD><TD><IMG src="'.$layout_name.'/images/blank.gif" WIDTH=10 HEIGHT=1 BORDER=0></TD>
  275.         </TR></TABLE></TABLE>';
  276.     }
  277. }
  278.  
  279. //--------------------------------------------------------------------------------------------------------------------
  280. //--------------------------------------------------------------------------------------------------------------------
  281. //--------------------------------------------------------------------------------------------------------------------
  282. //--------------------------------------------------------------------------------------------------------------------
  283. //change rank of player in guild
  284. if($action == 'changerank')
  285. {
  286.     $guild_id = (int) $_REQUEST['guild'];
  287.     if(!$logged)
  288.         $guild_errors[] = 'You are not logged in. You can\'t change rank.';
  289.     if(empty($guild_errors))
  290.     {
  291.         $guild = new Guild();
  292.         $guild->load($guild_id);
  293.         if(!$guild->isLoaded())
  294.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  295.     }
  296.     if(!empty($guild_errors))
  297.     {
  298.         //show errors
  299.         $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/>';
  300.         foreach($guild_errors as $guild_error)
  301.             $main_content .= '<li>'.$guild_error;
  302.         //errors and back button
  303.         $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>';
  304.     }
  305.     else
  306.     {
  307.     //check is it vice or/and leader account (leader has vice + leader rights)
  308.     $rank_list = $guild->getGuildRanksList();
  309.     $guild_leader = FALSE;
  310.     $guild_vice = FALSE;
  311.     $account_players = $account_logged->getPlayers();
  312.     foreach($account_players as $player)
  313.     {
  314.         $player_rank = $player->getRank();
  315.         if(!empty($player_rank))
  316.             foreach($rank_list as $rank_in_guild)
  317.                 if($rank_in_guild->getId() == $player_rank->getId())
  318.                 {
  319.                     $players_from_account_in_guild[] = $player->getName();
  320.                     if($player_rank->getLevel() > 1) {
  321.                         $guild_vice = TRUE;
  322.                         $level_in_guild = $player_rank->getLevel();
  323.                     }
  324.                     if($guild->getOwner()->getId() == $player->getId()) {
  325.                         $guild_vice = TRUE;
  326.                         $guild_leader = TRUE;
  327.                     }
  328.                 }
  329.     }
  330.     if($guild_vice)
  331.     {
  332.         foreach($rank_list as $rank)
  333.         {
  334.             if($guild_leader || $rank->getLevel() < $level_in_guild)
  335.             {
  336.                 $ranks[$rid]['0'] = $rank->getId();
  337.                 $ranks[$rid]['1'] = $rank->getName();
  338.                 $rid++;
  339.                 $players_with_rank = $rank->getPlayersList();
  340.                 if(count($players_with_rank) > 0)
  341.                 {
  342.                     foreach($players_with_rank as $player)
  343.                     {
  344.                         if($guild->getOwner()->getId() != $player->getId() || $guild_leader)
  345.                         {
  346.                             $players_with_lower_rank[$sid]['0'] = htmlspecialchars($player->getName());
  347.                             $players_with_lower_rank[$sid]['1'] = htmlspecialchars($player->getName()).' ('.htmlspecialchars($rank->getName()).')';
  348.                             $sid++;
  349.                         }
  350.                     }
  351.                 }
  352.             }
  353.         }
  354.         if($_REQUEST['todo'] == 'save')
  355.         {
  356.             $player_name = $_REQUEST['name'];
  357.             $new_rank = (int) $_REQUEST['rankid'];
  358.             if(!check_name($player_name))
  359.                 $change_errors[] = 'Invalid player name format.';
  360.             $rank = new GuildRank();
  361.             $rank->load($new_rank);
  362.             if(!$rank->isLoaded())
  363.                 $change_errors[] = 'Rank with this ID doesn\'t exist.';
  364.             if($level_in_guild <= $rank->getLevel() && !$guild_leader)
  365.                 $change_errors[] = 'You can\'t set ranks with equal or higher level than your.';
  366.             if(empty($change_errors))
  367.             {
  368.                 $player_to_change = new Player();
  369.                 $player_to_change->find($player_name);
  370.                 if(!$player_to_change->isLoaded())
  371.                     $change_errors[] = 'Player with name '.htmlspecialchars($player_name).'</b> doesn\'t exist.';
  372.                 else
  373.                 {
  374.                     $player_in_guild = FALSE;
  375.                     if($guild->getName() == $player_to_change->getRank()->getGuild()->getName() || $guild_leader)
  376.                     {
  377.                         $player_in_guild = TRUE;
  378.                         $player_has_lower_rank = FALSE;
  379.                         if($player_to_change->getRank()->getLevel() < $level_in_guild || $guild_leader)
  380.                             $player_has_lower_rank = TRUE;
  381.                     }
  382.                 }
  383.                 $rank_in_guild = FALSE;
  384.                 foreach($rank_list as $rank_from_guild)
  385.                     if($rank_from_guild->getId() == $rank->getId())
  386.                         $rank_in_guild = TRUE;
  387.                 if(!$player_in_guild)
  388.                 $change_errors[] = 'This player isn\'t in your guild.';
  389.                 if(!$rank_in_guild)
  390.                     $change_errors[] = 'This rank isn\'t in your guild.';
  391.                 if(!$player_has_lower_rank)
  392.                     $change_errors[] = 'This player has higher rank in guild than you. You can\'t change his/her rank.';
  393.             }
  394.             if(empty($change_errors))
  395.             {
  396.                 $player_to_change->setRank($rank);
  397.                 $player_to_change->save();
  398.                 $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>';
  399.                 unset($players_with_lower_rank);
  400.                 unset($ranks);
  401.                 $rid = 0;
  402.                 $sid= 0;
  403.                 foreach($rank_list as $rank)
  404.                 {
  405.                     if($guild_leader || $rank->getLevel() < $level_in_guild)
  406.                     {
  407.                         $ranks[$rid]['0'] = $rank->getId();
  408.                         $ranks[$rid]['1'] = $rank->getName();
  409.                         $rid++;
  410.                         $players_with_rank = $rank->getPlayersList();
  411.                         if(count($players_with_rank) > 0)
  412.                         {
  413.                             foreach($players_with_rank as $player)
  414.                             {
  415.                                 if($guild->getOwner()->getId() != $player->getId() || $guild_leader)
  416.                                 {
  417.                                     $players_with_lower_rank[$sid]['0'] = htmlspecialchars($player->getName());
  418.                                     $players_with_lower_rank[$sid]['1'] = htmlspecialchars($player->getName()).' ('.htmlspecialchars($rank->getName()).')';
  419.                                     $sid++;
  420.                                 }
  421.                             }
  422.                         }
  423.                     }
  424.                 }
  425.             }
  426.             else
  427.             {
  428.                 $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/>';
  429.                 foreach($change_errors as $change_error)
  430.                     $main_content .= '<li>'.$change_error;
  431.                 $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/>';
  432.             }
  433.         }
  434.         $main_content .= '<FORM ACTION="?subtopic=guilds&action=changerank&guild='.$guild_id.'&todo=save" METHOD=post>
  435.         <TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>
  436.         <TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Change Rank</B></TD></TR>
  437.         <TR BGCOLOR='.$config['site']['darkborder'].'><TD>Name: <SELECT NAME="name">';
  438.         foreach($players_with_lower_rank as $player_to_list)
  439.             $main_content .= '<OPTION value="'.$player_to_list['0'].'">'.$player_to_list['1'];
  440.         $main_content .= '</SELECT>&nbsp;Rank:&nbsp;<SELECT NAME="rankid">';
  441.         foreach($ranks as $rank)
  442.             $main_content .= '<OPTION value="'.htmlspecialchars($rank['0']).'">'.htmlspecialchars($rank['1']);
  443.         $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>
  444.         </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>';
  445.     }
  446.     else
  447.         $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>';
  448.     }
  449. }
  450.  
  451. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  452. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  453. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  454. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  455. //show guild page
  456. if($action == 'deleteinvite')
  457. {
  458.     //set rights in guild
  459.     $guild_id = (int) $_REQUEST['guild'];
  460.     $name = $_REQUEST['name'];
  461.     if(!$logged)
  462.         $guild_errors[] = 'You are not logged in. You can\'t delete invitations.';
  463.     if(!check_name($name))
  464.         $guild_errors[] = 'Invalid name format.';
  465.     if(empty($guild_errors))
  466.     {
  467.         $guild = new Guild();
  468.         $guild->load($guild_id);
  469.         if(!$guild->isLoaded())
  470.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  471.     }
  472.     if(empty($guild_errors))
  473.     {
  474.         $rank_list = $guild->getGuildRanksList();
  475.         $guild_leader = FALSE;
  476.         $guild_vice = FALSE;
  477.         $account_players = $account_logged->getPlayers();
  478.         foreach($account_players as $player)
  479.         {
  480.             $player_rank = $player->getRank();
  481.             if(!empty($player_rank))
  482.             {
  483.                 foreach($rank_list as $rank_in_guild)
  484.                 {
  485.                     if($rank_in_guild->getId() == $player_rank->getId())
  486.                     {
  487.                         $players_from_account_in_guild[] = $player->getName();
  488.                         if($player_rank->getLevel() > 1)
  489.                         {
  490.                             $guild_vice = TRUE;
  491.                             $level_in_guild = $player_rank->getLevel();
  492.                         }
  493.                         if($guild->getOwner()->getId() == $player->getId())
  494.                         {
  495.                             $guild_vice = TRUE;
  496.                             $guild_leader = TRUE;
  497.                         }
  498.                     }
  499.                 }
  500.             }
  501.         }
  502.     }
  503.     if(empty($guild_errors))
  504.     {
  505.         $player = new Player();
  506.         $player->find($name);
  507.         if(!$player->isLoaded())
  508.             $guild_errors[] = 'Player with name <b>'.htmlspecialchars($name).'</b> doesn\'t exist.';
  509.     }
  510.     if(!$guild_vice)
  511.         $guild_errors[] = 'You are not a leader or vice leader of guild <b>'.htmlspecialchars($guild->getName()).'</b>.';
  512.     if(empty($guild_errors))
  513.     {
  514.         $invited_list = $guild->listInvites();
  515.         if(count($invited_list) > 0)
  516.         {
  517.             $is_invited = FALSE;
  518.             foreach($invited_list as $invited)
  519.                 if($invited->getName() == $player->getName())
  520.                     $is_invited = TRUE;
  521.             if(!$is_invited)
  522.                 $guild_errors[] = '<b>'.htmlspecialchars($player->getName()).'</b> isn\'t invited to your guild.';
  523.         }
  524.         else
  525.             $guild_errors[] = 'No one is invited to your guild.';
  526.     }
  527.     if(!empty($guild_errors))
  528.     {
  529.         $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/>';
  530.         foreach($guild_errors as $guild_error)
  531.             $main_content .= '<li>'.$guild_error;
  532.         $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>';
  533.     }
  534.     else
  535.     {
  536.         if($_REQUEST['todo'] == 'save')
  537.         {
  538.             $guild->deleteInvite($player);
  539.             $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>';
  540.         }
  541.         else
  542.             $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>';
  543.     }
  544. }
  545.  
  546. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  547. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  548. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  549. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  550. //show guild page
  551. if($action == 'invite')
  552. {
  553.     //set rights in guild
  554.     $guild_id = (int) $_REQUEST['guild'];
  555.     $name = $_REQUEST['name'];
  556.     if(!$logged)
  557.         $guild_errors[] = 'You are not logged in. You can\'t invite players.';
  558.     if(empty($guild_errors))
  559.     {
  560.         $guild = new Guild();
  561.         $guild->load($guild_id);
  562.         if(!$guild->isLoaded())
  563.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  564.     }
  565.     if(empty($guild_errors))
  566.     {
  567.         $rank_list = $guild->getGuildRanksList();
  568.         $guild_leader = FALSE;
  569.         $guild_vice = FALSE;
  570.         $account_players = $account_logged->getPlayers();
  571.         foreach($account_players as $player)
  572.         {
  573.             $player_rank = $player->getRank();
  574.             if(!empty($player_rank))
  575.                 foreach($rank_list as $rank_in_guild)
  576.                     if($rank_in_guild->getId() == $player_rank->getId())
  577.                     {
  578.                         $players_from_account_in_guild[] = $player->getName();
  579.                         if($player_rank->getLevel() > 1)
  580.                         {
  581.                             $guild_vice = TRUE;
  582.                             $level_in_guild = $player_rank->getLevel();
  583.                         }
  584.                         if($guild->getOwner()->getId() == $player->getId())
  585.                         {
  586.                             $guild_vice = TRUE;
  587.                             $guild_leader = TRUE;
  588.                         }
  589.                     }
  590.         }
  591.     }
  592.     if(!$guild_vice)
  593.         $guild_errors[] = 'You are not a leader or vice leader of guild ID <b>'.$guild_id.'</b>.';
  594.     if($_REQUEST['todo'] == 'save')
  595.     {
  596.         if(!check_name($name))
  597.             $guild_errors[] = 'Invalid name format.';
  598.         if(empty($guild_errors))
  599.         {
  600.             $player = new Player();
  601.             $player->find($name);
  602.             if(!$player->isLoaded())
  603.                 $guild_errors[] = 'Player with name <b>'.htmlspecialchars($name).'</b> doesn\'t exist.';
  604.             else
  605.             {
  606.                 $rank_of_player = $player->getRank();
  607.                 if(!empty($rank_of_player))
  608.                     $guild_errors[] = 'Player with name <b>'.htmlspecialchars($name).'</b> is already in guild. He must leave guild before you can invite him.';
  609.             }
  610.         }
  611.         if(empty($guild_errors) && $guild->getWorld() != $player->getWorld())
  612.             $guild_errors[] = '<b>'.htmlspecialchars($player->getName()).'</b> is from other world then your guild.';
  613.         if(empty($guild_errors))
  614.         {
  615.             $invited_list = $guild->listInvites();
  616.             if(count($invited_list) > 0)
  617.                 foreach($invited_list as $invited)
  618.                     if($invited->getName() == $player->getName())
  619.                         $guild_errors[] = '<b>'.htmlspecialchars($player->getName()).'</b> is already invited to your guild.';
  620.         }
  621.     }
  622.     if(!empty($guild_errors))
  623.     {
  624.         $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/>';
  625.         foreach($guild_errors as $guild_error)
  626.             $main_content .= '<li>'.$guild_error;
  627.         $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>';
  628.     }
  629.     else
  630.         if($_REQUEST['todo'] == 'save')
  631.         {
  632.             $guild->invite($player);
  633.             $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>';
  634.         }
  635.         else
  636.             $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>';
  637. }
  638.  
  639.  
  640. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  641. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  642. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  643. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  644. //show guild page
  645. if($action == 'acceptinvite')
  646. {
  647.     //set rights in guild
  648.     $guild_id = (int) $_REQUEST['guild'];
  649.     $name = $_REQUEST['name'];
  650.     if(!$logged)
  651.         $guild_errors[] = 'You are not logged in. You can\'t accept invitations.';
  652.     if(empty($guild_errors))
  653.     {
  654.         $guild = new Guild();
  655.         $guild->load($guild_id);
  656.         if(!$guild->isLoaded())
  657.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  658.     }
  659.  
  660.     if($_REQUEST['todo'] == 'save')
  661.     {
  662.         if(!check_name($name))
  663.             $guild_errors[] = 'Invalid name format.';
  664.         if(empty($guild_errors))
  665.         {
  666.             $player = new Player();
  667.             $player->find($name);
  668.             if(!$player->isLoaded())
  669.             {
  670.                 $guild_errors[] = 'Player with name <b>'.htmlspecialchars($name).'</b> doesn\'t exist.';
  671.             }
  672.             else
  673.             {
  674.                 $rank_of_player = $player->getRank();
  675.                 if(!empty($rank_of_player))
  676.                 {
  677.                     $guild_errors[] = 'Character with name <b>'.htmlspecialchars($name).'</b> is already in guild. You must leave guild before you join other guild.';
  678.                 }
  679.             }
  680.         }
  681.     }
  682.     if($_REQUEST['todo'] == 'save')
  683.     {
  684.         if(empty($guild_errors))
  685.         {
  686.             $is_invited = FALSE;
  687.             $invited_list = $guild->listInvites();
  688.             if(count($invited_list) > 0)
  689.             {
  690.                 foreach($invited_list as $invited)
  691.                 {
  692.                     if($invited->getName() == $player->getName())
  693.                     {
  694.                         $is_invited = TRUE;
  695.                     }
  696.                 }
  697.             }
  698.             if(!$is_invited)
  699.             {
  700.                 $guild_errors[] = 'Character '.htmlspecialchars($player->getName()).' isn\'t invited to guild <b>'.htmlspecialchars($guild->getName()).'</b>.';
  701.             }
  702.         }
  703.     }
  704.     else
  705.     {
  706.         if(empty($guild_errors))
  707.         {
  708.             $acc_invited = FALSE;
  709.             $account_players = $account_logged->getPlayers();
  710.             $invited_list = $guild->listInvites();
  711.             if(count($invited_list) > 0)
  712.             {
  713.                 foreach($invited_list as $invited)
  714.                 {
  715.                     foreach($account_players as $player_from_acc)
  716.                     {
  717.                         if($invited->getName() == $player_from_acc->getName())
  718.                         {
  719.                             $acc_invited = TRUE;
  720.                             $list_of_invited_players[] = $player_from_acc->getName();
  721.                         }
  722.                     }
  723.                 }
  724.             }
  725.         }
  726.         if(!$acc_invited)
  727.         {
  728.             $guild_errors[] = 'Any character from your account isn\'t invited to <b>'.htmlspecialchars($guild->getName()).'</b>.';
  729.         }
  730.     }
  731.     if(!empty($guild_errors))
  732.     {
  733.         $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/>';
  734.         foreach($guild_errors as $guild_error)
  735.         {
  736.             $main_content .= '<li>'.$guild_error;
  737.         }
  738.         $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>';
  739.     }
  740.     else
  741.     {
  742.         if($_REQUEST['todo'] == 'save')
  743.         {
  744.             $guild->acceptInvite($player);
  745.             $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>';
  746.         }
  747.         else
  748.         {
  749.             $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>';
  750.             $main_content .= '<TR BGCOLOR='.$config['site']['lightborder'].'><TD WIDTH=100%>Select character to join guild:</TD></TR>';
  751.             $main_content .= '<TR BGCOLOR='.$config['site']['darkborder'].'><TD>
  752.             <form action="?subtopic=guilds&action=acceptinvite&guild='.$guild_id.'&todo=save" METHOD="post">';
  753.             sort($list_of_invited_players);
  754.             foreach($list_of_invited_players as $invited_player_from_list)
  755.             {
  756.                 $main_content .= '<input type="radio" name="name" value="'.htmlspecialchars($invited_player_from_list).'" />'.htmlspecialchars($invited_player_from_list).'<br>';
  757.             }
  758.             $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>';
  759.         }
  760.     }
  761. }
  762.  
  763.  
  764. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  765. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  766. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  767. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  768. //show guild page
  769. if($action == 'kickplayer')
  770. {
  771.     //set rights in guild
  772.     $guild_id = (int) $_REQUEST['guild'];
  773.     $name = $_REQUEST['name'];
  774.     if(!$logged)
  775.         $guild_errors[] = 'You are not logged in. You can\'t kick characters.';
  776.     if(!check_name($name))
  777.         $guild_errors[] = 'Invalid name format.';
  778.     if(empty($guild_errors))
  779.     {
  780.         $guild = new Guild();
  781.         $guild->load($guild_id);
  782.         if(!$guild->isLoaded())
  783.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  784.     }
  785.     if(empty($guild_errors))
  786.     {
  787.         $rank_list = $guild->getGuildRanksList();
  788.         $guild_leader = FALSE;
  789.         $guild_vice = FALSE;
  790.         $account_players = $account_logged->getPlayers();
  791.         foreach($account_players as $player)
  792.         {
  793.             $player_rank = $player->getRank();
  794.             if(!empty($player_rank))
  795.             {
  796.                 foreach($rank_list as $rank_in_guild)
  797.                 {
  798.                     if($rank_in_guild->getId() == $player_rank->getId())
  799.                     {
  800.                         $players_from_account_in_guild[] = $player->getName();
  801.                         if($player_rank->getLevel() > 1)
  802.                         {
  803.                             $guild_vice = TRUE;
  804.                             $level_in_guild = $player_rank->getLevel();
  805.                         }
  806.                         if($guild->getOwner()->getId() == $player->getId())
  807.                         {
  808.                             $guild_vice = TRUE;
  809.                             $guild_leader = TRUE;
  810.                         }
  811.                     }
  812.                 }
  813.             }
  814.         }
  815.     }
  816.     if(empty($guild_errors))
  817.     {
  818.         if(!$guild_leader && $level_in_guild < 3)
  819.         {
  820.             $guild_errors[] = 'You are not a leader of guild <b>'.htmlspecialchars($guild->getName()).'</b>. You can\'t kick players.';
  821.         }
  822.     }
  823.     if(empty($guild_errors))
  824.     {
  825.         $player = new Player();
  826.         $player->find($name);
  827.         if(!$player->isLoaded())
  828.         {
  829.             $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> doesn\'t exist.';
  830.         }
  831.         else
  832.         {
  833.             if($player->getRank()->getGuild()->getName() != $guild->getName())
  834.             {
  835.                 $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> isn\'t from your guild.';
  836.             }
  837.         }
  838.     }
  839.     if(empty($guild_errors))
  840.     {
  841.         if($player->getRank()->getLevel() >= $level_in_guild && !$guild_leader)
  842.         {
  843.             $guild_errors[] = 'You can\'t kick character <b>'.htmlspecialchars($name).'</b>. Too high access level.';
  844.         }
  845.     }
  846.     if(empty($guild_errors))
  847.     {
  848.         if($guild->getOwner()->getName() == $player->getName())
  849.         {
  850.             $guild_errors[] = 'It\'s not possible to kick guild owner!';
  851.         }
  852.     }
  853.     if(!empty($guild_errors))
  854.     {
  855.         $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/>';
  856.         foreach($guild_errors as $guild_error)
  857.         {
  858.             $main_content .= '<li>'.$guild_error;
  859.         }
  860.         $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>';
  861.     }
  862.     else
  863.         if($_REQUEST['todo'] == 'save')
  864.         {
  865.             $player->setRank();
  866.             $player->save();
  867.             $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>';
  868.         }
  869.         else
  870.             $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>';
  871. }
  872.  
  873. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  874. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  875. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  876. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  877. //show guild page
  878. if($action == 'leaveguild')
  879. {
  880.     //set rights in guild
  881.     $guild_id = (int) $_REQUEST['guild'];
  882.     $name = $_REQUEST['name'];
  883.     if(!$logged)
  884.         $guild_errors[] = 'You are not logged in. You can\'t leave guild.';
  885.     if(empty($guild_errors))
  886.     {
  887.         $guild = new Guild();
  888.         $guild->load($guild_id);
  889.         if(!$guild->isLoaded())
  890.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  891.     }
  892.  
  893.     if(empty($guild_errors))
  894.     {
  895.         $guild_owner_id = $guild->getOwner()->getId();
  896.         if($_REQUEST['todo'] == 'save')
  897.         {
  898.             if(!check_name($name))
  899.                 $guild_errors[] = 'Invalid name format.';
  900.             if(empty($guild_errors))
  901.             {
  902.                 $player = new Player();
  903.                 $player->find($name);
  904.                 if(!$player->isLoaded())
  905.                     $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> doesn\'t exist.';
  906.                 else
  907.                     if($player->getAccount()->getId() != $account_logged->getId())
  908.                         $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> isn\'t from your account!';
  909.             }
  910.             if(empty($guild_errors))
  911.             {
  912.                 $player_loaded_rank = $player->getRank();
  913.                 if(!empty($player_loaded_rank) && $player_loaded_rank->isLoaded())
  914.                 {
  915.                     if($player_loaded_rank->getGuild()->getId() != $guild->getId())
  916.                         $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> isn\'t from guild <b>'.htmlspecialchars($guild->getName()).'</b>.';
  917.                 }
  918.                 else
  919.                     $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> isn\'t in any guild.';
  920.             }
  921.             if(empty($guild_errors))
  922.                 if($guild_owner_id == $player->getId())
  923.                     $guild_errors[] = 'You can\'t leave guild. You are an owner of guild.';
  924.         }
  925.         else
  926.         {
  927.             $account_players = $account_logged->getPlayers();
  928.             foreach($account_players as $player_fac)
  929.             {
  930.                 $player_rank = $player_fac->getRank();
  931.                 if(!empty($player_rank))
  932.                     if($player_rank->getGuild()->getId() == $guild->getId())
  933.                         if($guild_owner_id != $player_fac->getId())
  934.                             $array_of_player_ig[] = $player_fac->getName();
  935.             }
  936.         }
  937.     }
  938.     if(!empty($guild_errors))
  939.     {
  940.         $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/>';
  941.         foreach($guild_errors as $guild_error)
  942.             $main_content .= '<li>'.$guild_error.'</li>';
  943.         $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>';
  944.     }
  945.     else
  946.     {
  947.         if($_REQUEST['todo'] == 'save')
  948.         {
  949.             $player->setRank();
  950.             $player->save();
  951.             $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>';
  952.         }
  953.         else
  954.         {
  955.             $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>';
  956.             if(count($array_of_player_ig) > 0)
  957.             {
  958.                 $main_content .= '<TR BGCOLOR='.$config['site']['lightborder'].'><TD WIDTH=100%>Select character to leave guild:</TD></TR>';
  959.                 $main_content .= '<TR BGCOLOR='.$config['site']['darkborder'].'><TD>
  960.                 <form action="?subtopic=guilds&action=leaveguild&guild='.$guild_id.'&todo=save" METHOD="post">';
  961.                 sort($array_of_player_ig);
  962.                 foreach($array_of_player_ig as $player_to_leave)
  963.                     $main_content .= '<input type="radio" name="name" value="'.htmlspecialchars($player_to_leave).'" />'.htmlspecialchars($player_to_leave).'<br>';
  964.                 $main_content .= '</TD></TR><br></TABLE>';
  965.             }
  966.             else
  967.                 $main_content .= '<TR BGCOLOR='.$config['site']['lightborder'].'><TD WIDTH=100%>Any of your characters can\'t leave guild.</TD></TR>';
  968.             $main_content .= '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%><tr>';
  969.             if(count($array_of_player_ig) > 0)
  970.                 $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>';
  971.             $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>';
  972.         }
  973.     }
  974. }
  975.  
  976. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  977. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  978. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  979. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  980. //create guild
  981. if($action == 'createguild')
  982. {
  983.     $new_guild_name = trim($_REQUEST['guild']);
  984.     $name = $_REQUEST['name'];
  985.     $todo = $_REQUEST['todo'];
  986.     if(!$logged)
  987.         $guild_errors[] = 'You are not logged in. You can\'t create guild.';
  988.     if(empty($guild_errors))
  989.     {
  990.         $account_players = $account_logged->getPlayers();
  991.         foreach($account_players as $player)
  992.         {
  993.             $player_rank = $player->getRank();
  994.             if(empty($player_rank))
  995.                 if($player->getLevel() >= $config['site']['guild_need_level'])
  996.                     if(!$config['site']['guild_need_pacc'] || $account_logged->isPremium())
  997.                         $array_of_player_nig[] = $player->getName();
  998.         }
  999.     }
  1000.  
  1001.     if(count($array_of_player_nig) == 0)
  1002.         $guild_errors[] = 'On your account all characters are in guilds or have too low level to create new guild.';
  1003.     if($todo == 'save')
  1004.     {
  1005.         if(!check_guild_name($new_guild_name))
  1006.         {
  1007.             $guild_errors[] = 'Invalid guild name format.';
  1008.         }
  1009.         if(!check_name($name))
  1010.         {
  1011.             $guild_errors[] = 'Invalid character name format.';
  1012.         }
  1013.         if(empty($guild_errors))
  1014.         {
  1015.             $player = new Player();
  1016.             $player->find($name);
  1017.             if(!$player->isLoaded())
  1018.                 $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> doesn\'t exist.';
  1019.         }
  1020.         if(empty($guild_errors))
  1021.         {
  1022.             $guild = new Guild();
  1023.             $guild->find($new_guild_name);
  1024.             if($guild->isLoaded())
  1025.                 $guild_errors[] = 'Guild <b>'.htmlspecialchars($new_guild_name).'</b> already exist. Select other name.';
  1026.         }
  1027.         if(empty($guild_errors))
  1028.         {
  1029.             $bad_char = TRUE;
  1030.             foreach($array_of_player_nig as $nick_from_list)
  1031.                 if($nick_from_list == $player->getName())
  1032.                     $bad_char = FALSE;
  1033.             if($bad_char)
  1034.                 $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> isn\'t on your account or is already in guild.';
  1035.         }
  1036.         if(empty($guild_errors))
  1037.         {
  1038.             if($player->getLevel() < $config['site']['guild_need_level'])
  1039.                 $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>.';
  1040.             if($config['site']['guild_need_pacc'] && !$account_logged->isPremium())
  1041.                 $guild_errors[] = 'Character <b>'.htmlspecialchars($name).'</b> is on FREE account. To create guild you need PREMIUM account.';
  1042.         }
  1043.     }
  1044.     if(!empty($guild_errors))
  1045.     {
  1046.         $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/>';
  1047.         foreach($guild_errors as $guild_error)
  1048.             $main_content .= '<li>'.$guild_error.'</li>';
  1049.         $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>';
  1050.         unset($todo);
  1051.     }
  1052.  
  1053.     if($todo == 'save')
  1054.     {
  1055.         $new_guild = new Guild();
  1056.         $new_guild->setCreationData(time());
  1057.         $new_guild->setName($new_guild_name);
  1058.         $new_guild->setOwner($player);
  1059.         $new_guild->setDescription('New guild. Leader must edit this text :)');
  1060.         $new_guild->setWorldID($player->getWorld());
  1061.         $new_guild->setGuildLogo('image/gif', Website::getFileContents('./images/default_guild_logo.gif'));
  1062.        
  1063.         $new_guild->save();
  1064.         $ranks = $new_guild->getGuildRanksList(true);
  1065.         foreach($ranks as $rank)
  1066.             if($rank->getLevel() == 3)
  1067.             {
  1068.                 $player->setRank($rank);
  1069.                 $player->save();
  1070.             }
  1071.         $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>';
  1072.     }
  1073.     else
  1074.     {
  1075.         $main_content .= 'To play on '.$config['server']['serverName'].' you need an account.
  1076.         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.
  1077.         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
  1078.         to your email address along with further instructions.<BR><BR>
  1079.         <FORM ACTION="?subtopic=guilds&action=createguild&todo=save" METHOD=post>
  1080.         <TABLE WIDTH=100% BORDER=0 CELLSPACING=1 CELLPADDING=4>
  1081.         <TR><TD BGCOLOR="'.$config['site']['vdarkborder'].'" CLASS=white><B>Create an '.htmlspecialchars($config['server']['serverName']).' Account</B></TD></TR>
  1082.         <TR><TD BGCOLOR="'.$config['site']['darkborder'].'"><TABLE BORDER=0 CELLSPACING=8 CELLPADDING=0>
  1083.           <TR><TD>
  1084.             <TABLE BORDER=0 CELLSPACING=5 CELLPADDING=0>';
  1085.         $main_content .= '<TR><TD width="150" valign="top"><B>Leader: </B></TD><TD><SELECT name="name">';
  1086.         if(count($array_of_player_nig) > 0)
  1087.         {
  1088.             sort($array_of_player_nig);
  1089.             foreach($array_of_player_nig as $nick)
  1090.                 $main_content .= '<OPTION>'.htmlspecialchars($nick).'</OPTION>';
  1091.         }
  1092.         $main_content .= '</SELECT><BR><font size="1" face="verdana,arial,helvetica">(Name of leader of new guild.)</font></TD></TR>
  1093.             <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>
  1094.             </TABLE>
  1095.           </TD></TR>
  1096.         </TABLE></TD></TR>
  1097.         </TABLE>
  1098.         <BR>
  1099.         <TABLE BORDER=0 WIDTH=100%>
  1100.           <TR><TD ALIGN=center>
  1101.             <IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=120 HEIGHT=1 BORDER=0><BR>
  1102.           </TD><TD ALIGN=center VALIGN=top>
  1103.             <INPUT TYPE=image NAME="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  1104.             </FORM>
  1105.           </TD><TD ALIGN=center>
  1106.             <FORM  ACTION="?subtopic=guilds" METHOD=post>
  1107.             <INPUT TYPE=image NAME="Back" ALT="Back" SRC="'.$layout_name.'/images/buttons/sbutton_back.gif" BORDER=0 WIDTH=120 HEIGHT=18>
  1108.             </FORM>
  1109.           </TD><TD ALIGN=center>
  1110.             <IMG SRC="/images/blank.gif" WIDTH=120 HEIGHT=1 BORDER=0><BR>
  1111.           </TD></TR>
  1112.         </TABLE>
  1113.         </TD>
  1114.         <TD><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=10 HEIGHT=1 BORDER=0></TD>
  1115.         </TR>
  1116.         </TABLE>';
  1117.     }
  1118. }
  1119. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1120. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1121. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1122. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1123. if($action == 'manager')
  1124. {
  1125.     $guild_id = (int) $_REQUEST['guild'];
  1126.     if(empty($guild_errors))
  1127.     {
  1128.         $guild = new Guild();
  1129.         $guild->load($guild_id);
  1130.         if(!$guild->isLoaded())
  1131.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1132.     }
  1133.     if(empty($guild_errors))
  1134.     {
  1135.         if($logged)
  1136.         {
  1137.             $guild_leader_char = $guild->getOwner();
  1138.             $rank_list = $guild->getGuildRanksList();
  1139.             $guild_leader = FALSE;
  1140.             $account_players = $account_logged->getPlayers();
  1141.             foreach($account_players as $player)
  1142.                 if($guild_leader_char->getId() == $player->getId())
  1143.                 {
  1144.                     $guild_vice = TRUE;
  1145.                     $guild_leader = TRUE;
  1146.                     $level_in_guild = 3;
  1147.                 }
  1148.             if($guild_leader)
  1149.             {
  1150.                 $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.';
  1151.                 $main_content .= '<br/><br/><table style="clear:both" border=0 cellpadding=0 cellspacing=0 width="100%">
  1152.                 <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>
  1153.                 <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>
  1154.                 <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>
  1155.                 <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>
  1156.                 <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>
  1157.                 <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>Upload new guild logo.</b></td></tr>
  1158.                 </table>';
  1159.                 $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>';
  1160.                 $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>';
  1161.                 foreach($rank_list as $rank)
  1162.                 {
  1163.                     if(is_int($number_of_rows / 2)) { $bgcolor = $config['site']['darkborder']; } else { $bgcolor = $config['site']['lightborder']; } $number_of_rows++;
  1164.                     $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"';
  1165.                     if($rank->getLevel() == 3)
  1166.                         $main_content .= ' checked="checked"';
  1167.                     $main_content .= ' /></td><td align="center"><input type="radio" name="'.$rank->getId().'_level" value="2"';
  1168.                     if($rank->getLevel() == 2)
  1169.                         $main_content .= ' checked="checked"';
  1170.                     $main_content .= ' /></td><td align="center"><input type="radio" name="'.$rank->getId().'_level" value="1"';
  1171.                     if($rank->getLevel() == 1)
  1172.                         $main_content .= ' checked="checked"';
  1173.                     $main_content .= ' /></td></tr>';
  1174.                 }
  1175.                 $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>';
  1176.                 $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:
  1177.                 <li>Invite/Cancel Invitation/Kick Player from guild
  1178.                 <li>Change ranks of all players in guild
  1179.                 <li>Delete guild or pass leadership to other guild member
  1180.                 <li>Change names, levels(leader,vice,member), add and delete ranks
  1181.                 <li>Change MOTD, logo and description of guild<hr>
  1182.                 <b>3. Leader</b> - it\'s second rank in guild. Player with this rank can:
  1183.                 <li>Invite/Cancel Invitation/Kick Player from guild (only with lower rank than his)
  1184.                 <li>Change ranks of players with lower rank level ("vice leader", "member") in guild<hr>
  1185.                 <b>2. Vice Leader</b> - it\'s third rank in guild. Player with this rank can:
  1186.                 <li>Invite/Cancel Invitation
  1187.                 <li>Change ranks of players with lower rank level ("member") in guild<hr>
  1188.                 <b>1. Member</b> - it\'s lowest rank in guild. Player with this rank can:
  1189.                 <li>Be a member of guild';
  1190.                 $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>';
  1191.             }
  1192.             else
  1193.                 $guild_errors[] = 'You are not a leader of guild!';
  1194.         }
  1195.         else
  1196.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1197.     }
  1198.     if(!empty($guild_errors))
  1199.     {
  1200.         $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/>';
  1201.         foreach($guild_errors as $guild_error)
  1202.             $main_content .= '<li>'.$guild_error.'</li>';
  1203.         $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>';
  1204.     }
  1205. }
  1206. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1207. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1208. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1209. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1210. if($action == 'changelogo')
  1211. {
  1212.     $guild_id = (int) $_REQUEST['guild'];
  1213.  
  1214.     $guild = new Guild();
  1215.     $guild->load($guild_id);
  1216.     if(!$guild->isLoaded())
  1217.         $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1218.     if(empty($guild_errors))
  1219.     {
  1220.         if($logged)
  1221.         {
  1222.             $guild_leader_char = $guild->getOwner();
  1223.             $guild_leader = FALSE;
  1224.             $account_players = $account_logged->getPlayers();
  1225.             foreach($account_players as $player)
  1226.                 if($guild_leader_char->getId() == $player->getId())
  1227.                 {
  1228.                     $guild_vice = TRUE;
  1229.                     $guild_leader = TRUE;
  1230.                     $level_in_guild = 3;
  1231.                 }
  1232.             if($guild_leader)
  1233.             {
  1234.                 $max_image_size_b = $config['site']['guild_image_size_kb'] * 1024;
  1235.                 if($_REQUEST['todo'] == 'save')
  1236.                 {
  1237.                     $file = $_FILES['newlogo'];
  1238.                     switch($file['error'])
  1239.                     {
  1240.                         case UPLOAD_ERR_OK:
  1241.                             break; // all ok
  1242.                         case UPLOAD_ERR_INI_SIZE:
  1243.                         case UPLOAD_ERR_FORM_SIZE:
  1244.                             $upload_errors[] = 'Image is too large';
  1245.                             break;
  1246.                         case UPLOAD_ERR_PARTIAL:
  1247.                             $upload_errors[] = 'Image was only partially uploaded';
  1248.                             break;
  1249.                         case UPLOAD_ERR_NO_FILE:
  1250.                             $upload_errors[] = 'No image was uploaded';
  1251.                             break;
  1252.                         case UPLOAD_ERR_NO_TMP_DIR:
  1253.                             $upload_errors[] = 'Upload folder not found';
  1254.                             break;
  1255.                         case UPLOAD_ERR_CANT_WRITE:
  1256.                             $upload_errors[] = 'Unable to write uploaded file';
  1257.                             break;
  1258.                         case UPLOAD_ERR_EXTENSION:
  1259.                             $upload_errors[] =  'Upload failed due to extension';
  1260.                             break;
  1261.                         default:
  1262.                             $upload_errors[] =  'Unknown error';
  1263.                     }
  1264.                     if(is_uploaded_file($file['tmp_name']))
  1265.                     {
  1266.                         if($file['size'] > $max_image_size_b)
  1267.                             $upload_errors[] = 'Uploaded image is too big. Size: <b>'.$file['size'].' bytes</b>, Max. size: <b>'.$max_image_size_b.' bytes</b>.';
  1268.                         $info = getimagesize($file['tmp_name']);
  1269.                         if(!$info)
  1270.                             $upload_errors[] = 'Uploaded file is not an image!';
  1271.                     }
  1272.                     else
  1273.                         $upload_errors[] = 'You didn\'t send file or file is too big. Limit: <b>'.$config['site']['guild_image_size_kb'].' KB</b>.';
  1274.                     //show errors or save file
  1275.                     if(!empty($upload_errors))
  1276.                     {
  1277.                         $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/>';
  1278.                         foreach($upload_errors as $guild_error)
  1279.                             $main_content .= '<li>'.$guild_error;
  1280.                         $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>';
  1281.                     }
  1282.                     else
  1283.                     {
  1284.                         $guild->setGuildLogo($info['mime'], file_get_contents($file['tmp_name']));
  1285.                         $guild->save();
  1286.                     }
  1287.                 }
  1288.                 $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>';
  1289.                 $main_content .= '<form enctype="multipart/form-data" action="?subtopic=guilds&guild='.$guild_id.'&action=changelogo" method="POST">
  1290.                 <input type="hidden" name="todo" value="save" />
  1291.                 <input type="hidden" name="MAX_FILE_SIZE" value="'.$max_image_size_b.'" />
  1292.                     Select new logo: <input name="newlogo" type="file" />
  1293.                     <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>';
  1294.                 $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>';
  1295.             }
  1296.             else
  1297.                 $guild_errors[] = 'You are not a leader of guild!';
  1298.         }
  1299.         else
  1300.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1301.     }
  1302.     if(!empty($guild_errors))
  1303.     {
  1304.         $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/>';
  1305.         foreach($guild_errors as $guild_error)
  1306.             $main_content .= '<li>'.$guild_error.'</li>';
  1307.         $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>';
  1308.         $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>';
  1309.     }
  1310. }
  1311.  
  1312.  
  1313. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1314. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1315. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1316. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1317. if($action == 'deleterank')
  1318. {
  1319.     $guild_id = (int) $_REQUEST['guild'];
  1320.     $rank_to_delete = (int) $_REQUEST['rankid'];
  1321.     if(empty($guild_errors))
  1322.     {
  1323.         $guild = new Guild();
  1324.         $guild->load($guild_id);
  1325.         if(!$guild->isLoaded())
  1326.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1327.     }
  1328.     if(empty($guild_errors))
  1329.     {
  1330.         if($logged)
  1331.         {
  1332.             $guild_leader_char = $guild->getOwner();
  1333.             $rank_list = $guild->getGuildRanksList();
  1334.             $guild_leader = FALSE;
  1335.             $account_players = $account_logged->getPlayers();
  1336.             foreach($account_players as $player)
  1337.                 if($guild->getOwner()->getId() == $player->getId())
  1338.                 {
  1339.                     $guild_leader = TRUE;
  1340.                     $level_in_guild = 3;
  1341.                 }
  1342.             if($guild_leader)
  1343.             {
  1344.                 $rank = new GuildRank();
  1345.                 $rank->load($rank_to_delete);
  1346.                 if(!$rank->isLoaded())
  1347.                     $guild_errors2[] = 'Rank with ID '.$rank_to_delete.' doesn\'t exist.';
  1348.                 else
  1349.                 {
  1350.                     if($rank->getGuild()->getId() != $guild->getId())
  1351.                         $guild_errors2[] = 'Rank with ID '.$rank_to_delete.' isn\'t from your guild.';
  1352.                     else
  1353.                     {
  1354.                         if(count($rank_list) < 2)
  1355.                             $guild_errors2[] = 'You have only 1 rank in your guild. You can\'t delete this rank.';
  1356.                         else
  1357.                         {
  1358.                             $players_with_rank = $rank->getPlayersList();
  1359.                             $players_with_rank_number = count($players_with_rank);
  1360.                             if($players_with_rank_number > 0)
  1361.                             {
  1362.                                 foreach($rank_list as $checkrank)
  1363.                                     if($checkrank->getId() != $rank->getId())
  1364.                                         if($checkrank->getLevel() <= $rank->getLevel())
  1365.                                             $new_rank = $checkrank;
  1366.                                 if(empty($new_rank))
  1367.                                 {
  1368.                                     $new_rank = new GuildRank();
  1369.                                     $new_rank->setGuild($guild);
  1370.                                     $new_rank->setLevel($rank->getLevel());
  1371.                                     $new_rank->setName('New Rank level '.$rank->getLevel());
  1372.                                     $new_rank->save();
  1373.                                 }
  1374.                                 foreach($players_with_rank as $player_in_guild)
  1375.                                 {
  1376.                                     $player_in_guild->setRank($new_rank);
  1377.                                     $player_in_guild->save();
  1378.                                 }
  1379.                             }
  1380.                             $rank->delete();
  1381.                             $saved = TRUE;
  1382.                         }
  1383.                     }
  1384.                 }
  1385.                 if($saved)
  1386.                     $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>';
  1387.                 else
  1388.                 {
  1389.                     $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/>';
  1390.                     foreach($guild_errors2 as $guild_error)
  1391.                         $main_content .= '<li>'.$guild_error.'</li>';
  1392.                     $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>';
  1393.                 }
  1394.                 //back button
  1395.                 $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>';
  1396.             }
  1397.             else
  1398.                 $guild_errors[] = 'You are not a leader of guild!';
  1399.         }
  1400.         else
  1401.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1402.     }
  1403.     if(!empty($guild_errors))
  1404.     {
  1405.         $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/>';
  1406.         foreach($guild_errors as $guild_error)
  1407.             $main_content .= '<li>'.$guild_error.'</li>';
  1408.         $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>';
  1409.         $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>';
  1410.     }
  1411. }
  1412. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1413. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1414. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1415. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1416. if($action == 'addrank')
  1417. {
  1418.     $guild_id = (int) $_REQUEST['guild'];
  1419.     $ranknew = $_REQUEST['rank_name'];
  1420.     if(empty($guild_errors))
  1421.     {
  1422.         if(!check_rank_name($ranknew))
  1423.             $guild_errors[] = 'Invalid rank name format.';
  1424.         if(!$logged)
  1425.             $guild_errors[] = 'You are not logged.';
  1426.         $guild = new Guild();
  1427.         $guild->load($guild_id);
  1428.         if(!$guild->isLoaded())
  1429.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1430.         if(empty($guild_errors))
  1431.         {
  1432.             $guild_leader_char = $guild->getOwner();
  1433.             $rank_list = $guild->getGuildRanksList();
  1434.             $guild_leader = FALSE;
  1435.             $account_players = $account_logged->getPlayers();
  1436.             foreach($account_players as $player)
  1437.                 if($guild_leader_char->getId() == $player->getId())
  1438.                 {
  1439.                     $guild_vice = TRUE;
  1440.                     $guild_leader = TRUE;
  1441.                     $level_in_guild = 3;
  1442.                 }
  1443.             if($guild_leader)
  1444.             {
  1445.                 $new_rank = new GuildRank();
  1446.                 $new_rank->setGuild($guild);
  1447.                 $new_rank->setLevel(1);
  1448.                 $new_rank->setName($ranknew);
  1449.                 $new_rank->save();
  1450.                 header("Location: ?subtopic=guilds&guild=".$guild_id."&action=manager");
  1451.                 $main_content .= 'New rank added. Redirecting...';
  1452.             }
  1453.             else
  1454.                 $guild_errors[] = 'You are not a leader of guild!';
  1455.         }
  1456.         if(!empty($guild_errors))
  1457.         {
  1458.             $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/>';
  1459.             foreach($guild_errors as $guild_error)
  1460.                 $main_content .= '<li>'.$guild_error;
  1461.             $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>';
  1462.             $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>';
  1463.         }
  1464.     }
  1465.     else
  1466.         if(!empty($guild_errors))
  1467.         {
  1468.             $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/>';
  1469.             foreach($guild_errors as $guild_error)
  1470.                 $main_content .= '<li>'.$guild_error;
  1471.             $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>';
  1472.             $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>';
  1473.         }
  1474. }
  1475.  
  1476. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1477. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1478. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1479. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1480. if($action == 'changedescription')
  1481. {
  1482.     $guild_id = (int) $_REQUEST['guild'];
  1483.     if(empty($guild_errors))
  1484.     {
  1485.         $guild = new Guild();
  1486.         $guild->load($guild_id);
  1487.         if(!$guild->isLoaded())
  1488.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1489.     }
  1490.     if(empty($guild_errors))
  1491.     {
  1492.         if($logged)
  1493.         {
  1494.             $guild_leader_char = $guild->getOwner();
  1495.             $rank_list = $guild->getGuildRanksList();
  1496.             $guild_leader = FALSE;
  1497.             $account_players = $account_logged->getPlayers();
  1498.             foreach($account_players as $player)
  1499.                 if($guild->getOwner()->getId() == $player->getId())
  1500.                 {
  1501.                     $guild_vice = TRUE;
  1502.                     $guild_leader = TRUE;
  1503.                     $level_in_guild = 3;
  1504.                 }
  1505.             if($guild_leader)
  1506.             {
  1507.                 if($_REQUEST['todo'] == 'save')
  1508.                 {
  1509.                     $description = htmlspecialchars(substr(trim($_REQUEST['description']),0,$config['site']['guild_description_chars_limit']));
  1510.                     $guild->set('description', $description);
  1511.                     $guild->save();
  1512.                     $saved = TRUE;
  1513.                 }
  1514.                 $main_content .= '<center><h2>Change guild description</h2></center>';
  1515.                 if($saved)
  1516.                     $main_content .= '<center><font color="red" size="3"><b>CHANGES HAS BEEN SAVED!</b></font></center><br>';
  1517.                 $main_content .= 'Here you can change description of your guild.<BR>';
  1518.                 $main_content .= '<form enctype="multipart/form-data" action="?subtopic=guilds&guild='.$guild_id.'&action=changedescription" method="POST">
  1519.                 <input type="hidden" name="todo" value="save" />
  1520.                     <textarea name="description" cols="60" rows="'.($config['site']['guild_description_lines_limit'] - 1).'">'.$guild->getDescription().'</textarea><br>
  1521.                     (max. '.$config['site']['guild_description_lines_limit'].' lines, max. '.$config['site']['guild_description_chars_limit'].' chars) <input type="submit" value="Save description" /></form><br>';
  1522.                 $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>';
  1523.             }
  1524.             else
  1525.                 $guild_errors[] = 'You are not a leader of guild!';
  1526.         }
  1527.         else
  1528.         $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1529.     }
  1530.     if(!empty($guild_errors))
  1531.     {
  1532.         $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/>';
  1533.         foreach($guild_errors as $guild_error)
  1534.             $main_content .= '<li>'.$guild_error.'</li>';
  1535.         $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>';
  1536.         $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>';
  1537.     }
  1538. }
  1539.  
  1540. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1541. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1542. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1543. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1544. if($action == 'passleadership')
  1545. {
  1546.     $guild_id = (int) $_REQUEST['guild'];
  1547.     $pass_to = trim($_REQUEST['player']);
  1548.     if(empty($guild_errors))
  1549.     {
  1550.         $guild = new Guild();
  1551.         $guild->load($guild_id);
  1552.         if(!$guild->isLoaded())
  1553.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1554.     }
  1555.     if(empty($guild_errors))
  1556.     {
  1557.         if($_POST['todo'] == 'save')
  1558.         {
  1559.             if(!check_name($pass_to))
  1560.                 $guild_errors2[] = 'Invalid player name format.';
  1561.             if(empty($guild_errors2))
  1562.             {
  1563.                 $to_player = new Player();
  1564.                 $to_player->find($pass_to);
  1565.                 if(!$to_player->isLoaded())
  1566.                     $guild_errors2[] = 'Player with name <b>'.htmlspecialchars($pass_to).'</b> doesn\'t exist.';
  1567.                 if(empty($guild_errors2))
  1568.                 {
  1569.                     $to_player_rank = $to_player->getRank();
  1570.                     if(!empty($to_player_rank))
  1571.                     {
  1572.                         $to_player_guild = $to_player_rank->getGuild();
  1573.                         if($to_player_guild->getId() != $guild->getId())
  1574.                             $guild_errors2[] = 'Player with name <b>'.htmlspecialchars($to_player->getName()).'</b> isn\'t from your guild.';
  1575.                     }
  1576.                     else
  1577.                         $guild_errors2[] = 'Player with name <b>'.htmlspecialchars($to_player->getName()).'</b> isn\'t from your guild.';
  1578.                 }
  1579.             }
  1580.         }
  1581.     }
  1582.     if(empty($guild_errors) && empty($guild_errors2))
  1583.     {
  1584.         if($logged)
  1585.         {
  1586.             $guild_leader_char = $guild->getOwner();
  1587.             $guild_leader = FALSE;
  1588.             $account_players = $account_logged->getPlayers();
  1589.             foreach($account_players as $player)
  1590.                 if($guild_leader_char->getId() == $player->getId())
  1591.                 {
  1592.                     $guild_vice = TRUE;
  1593.                     $guild_leader = TRUE;
  1594.                     $level_in_guild = 3;
  1595.                 }
  1596.             if($guild_leader)
  1597.             {
  1598.                 if($_POST['todo'] == 'save')
  1599.                 {
  1600.                     $guild->setOwner($to_player);
  1601.                     $guild->save();
  1602.                     $saved = TRUE;
  1603.                     $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>';
  1604.                 }
  1605.                 else
  1606.                     $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>
  1607.                     <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>
  1608.                     </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>';
  1609.             }
  1610.             else
  1611.                 $guild_errors[] = 'You are not a leader of guild!';
  1612.         }
  1613.         else
  1614.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1615.     }
  1616.     if(empty($guild_errors) && !empty($guild_errors2))
  1617.     {
  1618.         $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/>';
  1619.         foreach($guild_errors2 as $guild_error2)
  1620.             $main_content .= '<li>'.$guild_error2;
  1621.         $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>';
  1622.         $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>';
  1623.     }
  1624.     if(!empty($guild_errors))
  1625.     {
  1626.         $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/>';
  1627.         foreach($guild_errors as $guild_error)
  1628.             $main_content .= '<li>'.$guild_error;
  1629.         if(!empty($guild_errors2))
  1630.             foreach($guild_errors2 as $guild_error2)
  1631.                 $main_content .= '<li>'.$guild_error2;
  1632.         $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>';
  1633.     }
  1634. }
  1635. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1636. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1637. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1638. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1639. if($action == 'deleteguild')
  1640. {
  1641.     $guild_id = (int) $_REQUEST['guild'];
  1642.     if(empty($guild_errors))
  1643.     {
  1644.         $guild = new Guild();
  1645.         $guild->load($guild_id);
  1646.         if(!$guild->isLoaded())
  1647.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1648.     }
  1649.     if(empty($guild_errors))
  1650.     {
  1651.         if($logged)
  1652.         {
  1653.             $guild_leader_char = $guild->getOwner();
  1654.             $rank_list = $guild->getGuildRanksList();
  1655.             $guild_leader = FALSE;
  1656.             $account_players = $account_logged->getPlayers();
  1657.             foreach($account_players as $player)
  1658.                 if($guild->getOwner()->getId() == $player->getId())
  1659.                 {
  1660.                     $guild_vice = TRUE;
  1661.                     $guild_leader = TRUE;
  1662.                     $level_in_guild = 3;
  1663.                 }
  1664.             if($guild_leader)
  1665.             {
  1666.                 if($_POST['todo'] == 'save')
  1667.                 {
  1668.                     $guild->delete();
  1669.                     $saved = TRUE;
  1670.                 }
  1671.                 if($saved)
  1672.                 {
  1673.                     $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>';
  1674.                     $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>';
  1675.                 }
  1676.                 else
  1677.                 {
  1678.                     $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>
  1679.                     <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>
  1680.                     </td></tr>          </table>        </div>  </table></div></td></tr>';
  1681.                     $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>';
  1682.                 }
  1683.             }
  1684.             else
  1685.                 $guild_errors[] = 'You are not a leader of guild!';
  1686.         }
  1687.         else
  1688.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1689.     }
  1690.     if(!empty($guild_errors))
  1691.     {
  1692.         $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/>';
  1693.         foreach($guild_errors as $guild_error)
  1694.             $main_content .= '<li>'.$guild_error.'</li>';
  1695.         $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>';
  1696.         $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>';
  1697.     }
  1698. }
  1699.  
  1700.  
  1701. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1702. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1703. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1704. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1705. if($action == 'deletebyadmin')
  1706. {
  1707.     $guild_id = (int) $_REQUEST['guild'];
  1708.     if(empty($guild_errors))
  1709.     {
  1710.         $guild = new Guild();
  1711.         $guild->load($guild_id);
  1712.         if(!$guild->isLoaded())
  1713.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1714.     }
  1715.     if(empty($guild_errors))
  1716.     {
  1717.         if($logged)
  1718.         {
  1719.             if($group_id_of_acc_logged >= $config['site']['access_admin_panel'])
  1720.             {
  1721.                 if($_POST['todo'] == 'save')
  1722.                 {
  1723.                     $guild->delete();
  1724.                     $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>';
  1725.                 }
  1726.                 else
  1727.                     $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>
  1728.                     <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>
  1729.                     </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>';
  1730.             }
  1731.             else
  1732.                 $guild_errors[] = 'You are not an admin!';
  1733.         }
  1734.         else
  1735.             $guild_errors[] = 'You are not logged. You can\'t delete guild.';
  1736.     }
  1737.     if(!empty($guild_errors))
  1738.     {
  1739.         $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/>';
  1740.         foreach($guild_errors as $guild_error)
  1741.             $main_content .= '<li>'.$guild_error.'</li>';
  1742.         $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>';
  1743.         $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>';
  1744.     }
  1745. }
  1746.  
  1747. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1748. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1749. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1750. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1751. if($action == 'changemotd')
  1752. {
  1753.     $guild_id = (int) $_REQUEST['guild'];
  1754.     if(empty($guild_errors))
  1755.     {
  1756.         $guild = new Guild();
  1757.         $guild->load($guild_id);
  1758.         if(!$guild->isLoaded())
  1759.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1760.     }
  1761.     if(empty($guild_errors))
  1762.     {
  1763.         if($logged)
  1764.         {
  1765.             $guild_leader_char = $guild->getOwner();
  1766.             $rank_list = $guild->getGuildRanksList();
  1767.             $guild_leader = FALSE;
  1768.             $account_players = $account_logged->getPlayers();
  1769.             foreach($account_players as $player)
  1770.                 if($guild->getOwner()->getId() == $player->getId())
  1771.                 {
  1772.                     $guild_vice = TRUE;
  1773.                     $guild_leader = TRUE;
  1774.                     $level_in_guild = 3;
  1775.                 }
  1776.             if($guild_leader)
  1777.             {
  1778.                 if($_REQUEST['todo'] == 'save')
  1779.                 {
  1780.                     $motd = htmlspecialchars(substr(trim($_REQUEST['motd']),0,$config['site']['guild_motd_chars_limit']));
  1781.                     $guild->set('motd', $motd);
  1782.                     $guild->save();
  1783.                     $saved = TRUE;
  1784.                 }
  1785.                 $main_content .= '<center><h2>Change guild MOTD</h2></center>';
  1786.                 if($saved)
  1787.                     $main_content .= '<center><font color="red" size="3"><b>CHANGES HAS BEEN SAVED!</b></font></center><br>';
  1788.                 $main_content .= 'Here you can change MOTD (Message of the Day, showed in game!) of your guild.<BR>';
  1789.                 $main_content .= '<form enctype="multipart/form-data" action="?subtopic=guilds&guild='.$guild_id.'&action=changemotd" method="POST">
  1790.                 <input type="hidden" name="todo" value="save" />
  1791.                     <textarea name="motd" cols="60" rows="3">'.$guild->get('motd').'</textarea><br>
  1792.                     (max. '.$config['site']['guild_motd_chars_limit'].' chars) <input type="submit" value="Save MOTD" /></form><br>';
  1793.                 $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>';
  1794.             }
  1795.             else
  1796.                 $guild_errors[] = 'You are not a leader of guild!';
  1797.         }
  1798.         else
  1799.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1800.     }
  1801.     if(!empty($guild_errors))
  1802.     {
  1803.         $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/>';
  1804.         foreach($guild_errors as $guild_error)
  1805.             $main_content .= '<li>'.$guild_error;
  1806.         $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>';
  1807.         $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>';
  1808.     }
  1809. }
  1810.  
  1811. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1812. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1813. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1814. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1815. if($action == 'saveranks')
  1816. {
  1817.     $guild_id = (int) $_REQUEST['guild'];
  1818.     if(empty($guild_errors))
  1819.     {
  1820.         $guild = new Guild();
  1821.         $guild->load($guild_id);
  1822.         if(!$guild->isLoaded())
  1823.             $guild_errors[] = 'Guild with ID <b>'.$guild_id.'</b> doesn\'t exist.';
  1824.     }
  1825.     if(empty($guild_errors))
  1826.     {
  1827.         if($logged)
  1828.         {
  1829.             $guild_leader_char = $guild->getOwner();
  1830.             $rank_list = $guild->getGuildRanksList();
  1831.             $guild_leader = FALSE;
  1832.             $account_players = $account_logged->getPlayers();
  1833.             foreach($account_players as $player)
  1834.                 if($guild_leader_char->getId() == $player->getId())
  1835.                 {
  1836.                     $guild_vice = TRUE;
  1837.                     $guild_leader = TRUE;
  1838.                     $level_in_guild = 3;
  1839.                 }
  1840.             if($guild_leader)
  1841.             {
  1842.                 foreach($rank_list as $rank)
  1843.                 {
  1844.                     $rank_id = $rank->getId();
  1845.                     $name = $_REQUEST[$rank_id.'_name'];
  1846.                     $level = (int) $_REQUEST[$rank_id.'_level'];
  1847.                     if(check_rank_name($name))
  1848.                         $rank->setName($name);
  1849.                     else
  1850.                         $ranks_errors[] = 'Invalid rank name. Please use only a-Z, 0-9 and spaces. Rank ID <b>'.$rank_id.'</b>.';
  1851.                     if($level > 0 && $level < 4)
  1852.                         $rank->setLevel($level);
  1853.                     else
  1854.                         $ranks_errors[] = 'Invalid rank level. Contact with admin. Rank ID <b>'.$rank_id.'</b>.';
  1855.                     $rank->save();
  1856.                 }
  1857.                 if(!empty($ranks_errors))
  1858.                 {
  1859.                     $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/>';
  1860.                     foreach($ranks_errors as $guild_error)
  1861.                         $main_content .= '<li>'.$guild_error.'</li>';
  1862.                     $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>';
  1863.                 }
  1864.                 else
  1865.                     header("Location: ?subtopic=guilds&action=manager&guild=".$guild_id);
  1866.             }
  1867.             else
  1868.                 $guild_errors[] = 'You are not a leader of guild!';
  1869.         }
  1870.         else
  1871.             $guild_errors[] = 'You are not logged. You can\'t manage guild.';
  1872.     }
  1873.     if(!empty($guild_errors)) {
  1874.     $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/>';
  1875.     foreach($guild_errors as $guild_error) {
  1876.         $main_content .= '<li>'.$guild_error.'</li>';
  1877.     }
  1878.     $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>';
  1879.     }
  1880. }
  1881. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1882. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1883. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1884. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1885. if($action == 'cleanup_players')
  1886. {
  1887.     if($logged)
  1888.     {
  1889.         if($group_id_of_acc_logged >= $config['site']['access_admin_panel'])
  1890.         {
  1891.             $players_list = new DatabaseList('Player');
  1892.         }
  1893.         else
  1894.             $players_list = $account_logged->getPlayersList();
  1895.         if(count($players_list) > 0)
  1896.         {
  1897.             foreach($players_list as $player)
  1898.             {
  1899.                 $player_rank = $player->getRank();
  1900.                 if(!empty($player_rank))
  1901.                 {
  1902.                     if($player_rank->isLoaded())
  1903.                     {
  1904.                         $rank_guild = $player_rank->getGuild();
  1905.                         if(!$rank_guild->isLoaded())
  1906.                         {
  1907.                             $player->setRank();
  1908.                             $player->setGuildNick();
  1909.                             $player->save();
  1910.                             $changed_ranks_of[] = $player->getName();
  1911.                             $deleted_ranks[] = 'ID: '.$player_rank->getId().' - '.$player_rank->getName();
  1912.                             $player_rank->delete();
  1913.                         }
  1914.                     }
  1915.                     else
  1916.                     {
  1917.                         $player->setRank();
  1918.                         $player->setGuildNick('');
  1919.                         $player->save();
  1920.                         $changed_ranks_of[] = $player->getName();
  1921.                     }
  1922.                    
  1923.                 }
  1924.             }
  1925.             $main_content .= "<b>Deleted ranks (this ranks guilds doesn't exist [bug fix]):</b>";
  1926.             if(!empty($deleted_ranks))
  1927.                 foreach($deleted_ranks as $rank)
  1928.                     $main_content .= "<li>".htmlspecialchars($rank);
  1929.             $main_content .= "<BR /><BR /><b>Changed ranks of players (rank or guild of rank doesn't exist [bug fix]):</b>";
  1930.             if(!empty($changed_ranks_of))
  1931.                 foreach($changed_ranks_of as $name)
  1932.                     $main_content .= "<li>".htmlspecialchars($name);
  1933.         }
  1934.         else
  1935.             $main_content .= "0 players found.";
  1936.     }
  1937.     else
  1938.         $main_content .= "You are not logged in.";
  1939.     $main_content .= "<center><h3><a href=\"?subtopic=guilds\">BACK</a></h3></center>";
  1940. }
  1941. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1942. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1943. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1944. //-----------------------------------------------------------------------------//-----------------------------------------------------------------------------
  1945.     if($action == 'change_nick')
  1946.     {
  1947.         if($logged)
  1948.         {
  1949.             $player_n = $_REQUEST['name'];
  1950.             $new_nick = $_REQUEST['nick'];
  1951.             $player = new Player();
  1952.             $player->find($player_n);
  1953.             $player_from_account = FALSE;
  1954.             if(strlen($new_nick) <= 30)
  1955.             {
  1956.                 if($player->isLoaded())
  1957.                 {
  1958.                     $account_players = $account_logged->getPlayersList();
  1959.                     if(count($account_players))
  1960.                     {
  1961.                         foreach($account_players as $acc_player)
  1962.                         {
  1963.                             if($acc_player->getId() == $player->getId())
  1964.                                 $player_from_account = TRUE;
  1965.                         }
  1966.                         if($player_from_account)
  1967.                         {
  1968.                             $player->setGuildNick($new_nick);
  1969.                             $player->save();
  1970.                             $main_content .= 'Guild nick of player <b>'.htmlspecialchars($player->getName()).'</b> changed to <b>'.htmlspecialchars($new_nick).'</b>.';
  1971.                             $addtolink = '&action=show&guild='.$player->getRank()->getGuild()->getId();
  1972.                         }
  1973.                         else
  1974.                             $main_content .= 'This player is not from your account.';
  1975.                     }
  1976.                     else
  1977.                         $main_content .= 'This player is not from your account.';
  1978.                 }
  1979.                 else
  1980.                     $main_content .= 'Unknow error occured.';
  1981.             }
  1982.             else
  1983.                 $main_content .= 'Too long guild nick. Max. 30 chars, your: '.strlen($new_nick);
  1984.         }
  1985.         else
  1986.             $main_content .= 'You are not logged.';
  1987.         $main_content .= '<center><h3><a href="?subtopic=guilds'.$addtolink.'">BACK</a></h3></center>';
  1988.     }
Add Comment
Please, Sign In to add comment