Jump to content
MakeWebGames

Script error please help


crimec

Recommended Posts

im having errors whit my companies script it wont credit the users with there wages and also it wont give them there working stats

 


<?php  
  /*------------includes--------------*/
  include ('./includes/connections.php');
  include ('./includes/brain_file.php');
  include ('./includes/style_top.php');
  /*------------includes--------------*/
  echo "<center><main>Company</main><hr width='750px'>";
  if($pl['my_jail'] > gmtime() || $pl['my_hosp'] > gmtime())
  {
     echo "<center><hr width='750px'/>Sorry this page is not viewable while in jail or hospital!<hr width='750px'/></center>";
     include ('./includes/style_bottom.php');
     exit();
  }
  if($_GET['action']) {
  if(!in_array($_GET['action'],array('pricing','storage','capacity','staffroom','advertising','shipping','manage','applications','train','fire','newsletter','funds','director','changename','banner','erase','quit','view'))) 
  {
     echo "Invalid action!
           <hr width='750px'/>
           ><a href='javascript:history.back()'>Okay</a>
           <hr width='750px'/>";
     include ('./includes/style_bottom.php');
     exit();
  }
  }

  $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? trim($_GET['action']) : 'index';

  switch($_GET['action'])
  {

     case 'view';
     comp_view();
     break;

     case 'quit';
     comp_leave();
     break;

     case 'erase';
     comp_erase();
     break;

     case 'banner';
     comp_img();
     break;

     case 'changename';
     comp_name();
     break;

     case 'director';
     comp_leader();
     break;

     case 'funds';
     comp_fund();
     break;

     case 'newsletter';
     comp_news();
     break;

     case 'fire';
     comp_fire();
     break;

     case 'train';
     comp_train();
     break;

     case 'applications';
     comp_apps();
     break;

     case 'manage';
     comp_manage();
     break;

     case 'shipping';
     ships();
     break;

     case 'advertising';
     ad_camp();
     break;

     case 'staffroom';
     comp_sroom();
     break;

     case 'capacity';
     comp_capacity();
     break;

     case 'storage';
     comp_store();
     break;

     case 'pricing';
     pricing();
     break;

     default:
     comp_index();
     break;
  }
  function comp_index()
  {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points`,`my_drugadd`
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $is = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
   {
      echo "You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
   }
   else
      {
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = array();
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = array();
        $type = mysql_query($q_ry);
        $t = array();
        $t = mysql_fetch_array($type);
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `comp_members` cm
                 LEFT JOIN `system_c_ranks` sr 
                 ON cm.m_rank = sr.cr_ID
                 WHERE cm.m_playerid = '".mysql_real_escape_string($_SESSION['playerid'])."'";
        $my_rank = array();
        $my_rank = mysql_query($q_ry);
        $mr = array();
        $mr = mysql_fetch_array($my_rank);

        echo "<table width = '780px' border = '0'>
                 <tr>
                   <td align='center' valign='top'>

              ".round_table('750')."<table width = '100%'>
                                       <tr>
                                          <td align = 'center'>";


   if($_SESSION['playerid'] == $ds['c_owner'])
   {
      echo "You currently own ",htmlentities($ds['c_name']),".<br>
            You do not have a daily pay, but you do have access to the profit made from the company.<br>
            You receive ".(5*$ds['c_star'])." Manual,
                        ".(5*$ds['c_star'])." Endurance 
                    and ".(5*$ds['c_star'])." Intelligence every day.";
   }
   else
   {
   if(!$mr['m_rank'])
   {
      echo "You currently work in ",htmlentities($ds['c_name']),".<br>
           You have not yet been assigned to a possition in this company,<br/>
           When your boss decides to assign you to a rank he will also decide on your wages,<br/>
           Each rank gives different stat gains.";
    }
    else
    {
       echo "You currently work in ",htmlentities($ds['c_name']),".<br>
             You work as a ",htmlentities($mr['cr_NAME']),",<br/>
             You receive "; if($mr['cr_MANUALGAIN'] != '0.0') echo "".($mr['cr_MANUALGAIN'])." Manual";
                            if($mr['cr_MANUALGAIN'] != '0.0') echo " and ";
                            if($mr['cr_ENDURGAIN'] != '0.0') echo "".($mr['cr_ENDURGAIN'])." Endurance";
                            if($mr['cr_ENDURGAIN'] != '0.0' && $mr['cr_INTELGAIN'] != '0.0') echo " and ";
                            if($mr['cr_INTELGAIN'] != '0.0') echo "".($mr['cr_INTELGAIN'])." Intelligence";
                            echo " every day.";
     }
     }
              echo "</td>
                       </tr>
                          </table>".end_round()."
                                <hr width = '750px'>
                                   ".round_table('750')."<table width = '100%'>
                                      <tr>
                                         <td align = 'center'>
                                            <b><font size=3>",htmlentities($ds['c_name']),"</font></b><br>",htmlentities($t['c_DESC']),"   
                                         </td>
                                      </tr>
                                   </table>".end_round()."
                                <hr width = '750px'>
                                   ".round_table('750')."<table width = '100%'>
                                                            <tr>
                                                               <td width = '50%' align = 'center'>
                                                                  <table width = '100%'>
                                                                     <tr>
                                                                        <td valign = 'top' align = 'left'>
                                                                           <b>Company details</b>
                                                                           <br>
                                                                           Name: <font color=#006600>",htmlentities($ds['c_name']),"</font>
                                                                           <br>
                                                                           Type: <font color=#006600>",htmlentities($t['c_NAME']),"</font>
                                                                           <br>
                                                                           Director: <a href='profile.php?XID=".$ds['playerid']."'><font color=#006600>".$ds['playername']."</font></a>
                                                                           <br>
                                                                           Company bank: <font color=#006600>",money_alter($ds['c_wallet']),"</font>
                                                                           <br>";

  $my_members = array();
  $mm = array();
  $q_ry = array();
  $q_ry = "SELECT * 
           FROM `comp_members`
           WHERE `m_comp` = '".mysql_real_escape_string($ds['c_id'])."'";
  $my_members = mysql_query($q_ry);
  $mm = mysql_fetch_array($my_members);

echo "Employees: <font color=#006600>".(mysql_num_rows($my_members)+1)."/".id_capacity($ds['c_capacity'])."</font><br>
Storage size: <font color=#006600>";

  if($t['c_STORAGE'] == 'yes')
 {
   echo id_storage($ds['c_storage']);
   }
    else
   {
  echo "0";
 }
  echo "</font><br>
 Todays customers: <font color=#006600>".number_format($ds['c_tcust'])."</font><br>
 Todays income: <font color=#006600>".money_alter($ds['c_tprofit'])."</font><br>
 Yesterdays customers: <font color=#006600>".number_format($ds['c_ycust'])."</font><br>
 Yesterdays income: <font color=#006600>".money_alter($ds['c_yprofit'])."</font><br>
 Days old: <font color=#006600>{$ds['c_days']}</font><br>
 Trains: <font color=#006600>{$ds['c_trains']}/5</font><br>
 <img src=images/{$ds['c_star']}_star.png>
 <br>
 </td></tr></table>
 </td><td width=50% valign=top align=left>
 <table width = '100%'><tr><td valign=top align=left>
 <b>Your details</b><br>
 Rank: <font color=#006600>";


   if($_SESSION['playerid'] == $ds['c_owner'])
   {
      echo "Director</font><br>
            Income: <font color=#006600> + $0</font><br>";
   }
   else
   {
   if(!$mr['m_rank'])
   {
      echo "None</font><br>
            Income: <font color=#006600> + $0</font><br>";
   }
   else
      {
         echo htmlentities($mr['cr_NAME']),"</font><br>
              Income: <font color=#006600> + ".money_alter($mr['m_gains'])."</font><br>";
      }
   }
        $stats = array();
        $st = array();
        $q_ry = array();
        $q_ry = "SELECT `my_labor`,`my_intelligence`,`my_endurance`
                 FROM `memberstats`
                 WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
        $stats = mysql_query($q_ry);
        $st = mysql_fetch_array($stats);

        echo"Manual labour: <font color=#006600>".number_format($st['my_labor'] ,4)."</font><br>
             Intelligence: <font color=#006600>".number_format($st['my_intelligence'] ,4)."</font><br>
             Endurance: <font color=#006600>".number_format($st['my_endurance'] ,4)."</font><br>
             Job points: <font color=#006600>".number_format($ic['my_comp_points'])."</font><br>

   </td></tr></table>

   </td></tr></table>".end_round()."<hr width = '750px'><table width = '750px'><tr>

   <td width=25% valign=top><center>Popularity: {$ds['c_pop']}%<br>

   </td>
   <td width=25% valign=top><center>Efficiency: {$ds['c_effic']}%<br></td>
   <td width=25% valign=top><center>Environment: {$ds['c_envi']}%<br></td>
   <td width=25% valign=top><center>Cleanliness: {$ds['c_clean']}%<br></td>
 </tr>
 <tr>";
               $cp = array();
               $cp = (int)($ds['c_pop']/100*100);
               $cnp = array();
               $cnp = 100-$cp;

               $ce = array();
               $ce = (int)($ds['c_effic']/100*100);
               $ecy = array();
               $ecy = 100-$ce;

               $en = array();
               $en = (int)($ds['c_envi']/100*100);
               $env = array();
               $env = 100-$en;

               $cl = array();
               $cl = (int)($ds['c_clean']/100*100);
               $cln = array();
               $cln = 100-$cl;

   echo "<td><center><img src='bar_green.png' width='$cp' height='5' border='0'><img src='bar_red.png' width='$cnp'  height='5' border='0'></td>

   <td><center><img src='bar_green.png' width='$ce' height='5' border='0'><img src='bar_red.png' width='$ecy'  height='5' border='0'></td>

   <td><center><img src='bar_green.png' width='$en' height='5' border='0'><img src='bar_red.png' width='$env'  height='5' border='0'></td>

   <td><center><img src='bar_green.png' width='$cl' height='5' border='0'><img src='bar_red.png' width='$cln'  height='5' border='0'></td>

  </tr>
  </table><hr width = '750px'>
  ".round_table('750')."<table width = '100%'>
                        <tr><td align = 'center'>
  <table width=75%><tr><td align='left' valign='top'>

> <a href=companies.php?action=pricing>Pricing</a><br>
> <a href=companies.php?action=shipping>Shipments</a><br>
> <a href=companies.php?action=advertising>Advertising</a><br>

> <a href=companies.php?action=storage>Storage size</a><br>
> <a href=companies.php?action=staffroom>Staff room size</a><br>
> <a href=companies.php?action=capacity>Company size</a><br>
> <a href=companyspecials.php>Company specials</a><br>



</td><td width=50% align=right>

<a href=companies.php?action=manage>Manage employees</a> <<br>
<a href=companies.php?action=applications>Applications</a> <<br>
<a href=companies.php?action=newsletter>Newsletter</a> <<br>
<a href=companies.php?action=funds>Company funds</a> <<br>
<a href=companies.php?action=director>Change director</a> <<br>
<a href=companies.php?action=changename>Change name</a> <<br>
<a href=companies.php?action=banner>Change image</a> <<br>
<a href=companies.php?action=erase>Erase company</a> <<br>";

$q_ry = array();
$q_ry = "SELECT * FROM `comp_events`
        WHERE `ce_comp` = '".mysql_real_escape_string($ds['c_id'])."'
        ORDER BY `ce_id` DESC";
$cev = array();
$cev = mysql_query($q_ry);

  $_GET['p']=abs(intval($_GET['p']*10));
  $pnoq=($_GET['p']) ? $_GET['p'] : 0;
  $pageno=mysql_num_rows($cev);
  $pages=(int) ($pageno/10)+1;
  if($pageno % 10 == 0)
  {
  $pages--;
  }

echo "</td></tr></table></td></tr></table>".end_round()."<hr width = '750px'>";


echo round_table('750')."<table width=100%><tr align=center bgcolor=#999999><td align=center width=20%><b>Time</b></td><td align=center><b>Main News (".(mysql_num_rows($cev)).")</b></td></tr><tr bgcolor=#DFDFDF><td colspan=2 align='center'><b>Page: </b>";
  for($i=1;$i <= $pages;$i++)
  {
  $pno=$i-1;
  echo "<a href='companies.php?p=$pno'>$i</a> ";
  }
echo "</td></tr>";
$q_ry = array();
$q_ry = "SELECT * FROM `comp_events`
        WHERE `ce_comp` = '".mysql_real_escape_string($ds['c_id'])."'
        ORDER BY `ce_id` DESC LIMIT $pnoq,10";
$cev = array();
$cev = mysql_query($q_ry);
$ce = array();
if(!mysql_num_rows($cev))
{
echo "<tr bgcolor=#e3e3e3><td align=center colspan='2'>None</td></tr>";
}
else
    {
while($ce = mysql_fetch_array($cev))
    {                                               $num++;
                                              $odd="#cccccc";
                                              $even="#e3e3e3";
                                         if ($num % 2) {
                                         $color="$even";
                                         } else {
                                         $color="$odd"; 
                                                      }
echo "<tr bgcolor=$color>
<td align=center>".date('F j Y',$ce['ce_time'])."<br/>".date('g:i:s a',$ce['ce_time'])."</td>
<td align=center>".($ce['ce_text'])."</td>
</tr>";
 }
 }
echo "</table>".end_round()."<hr width=750px>";




echo "<table width = '750px'><tr>
<td width=50% align=center><a href=newspaper.php?page=jobs>> Job listings</a></td>
<td width=50% align=center><A href=companies.php?action=quit>> Quit job</a></td>
</tr></table><hr width = '750px'>";
      }

  }



   function pricing()
   {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points` 
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $is = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
  {
      echo "You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = array();
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = array();
        $type = mysql_query($q_ry);
        $t = array();
        $t = mysql_fetch_array($type);

        if($_SESSION['playerid'] != $ds['playerid'])
        {
           echo "Sorry but only ",htmlentities($ds['playername'])," may change the companies pricing!
                 <hr width='750px'/>
                 ><a href='javascript:history.back()'>Okay</a>
                 <hr width='750px'/>";
           include ('./includes/style_bottom.php');
           exit();
        }
        if($t['c_PRODUCTS']!="yes")
        {
           echo "This company does not require any pricing!
                 <hr width='750px'/>
                 ><a href='javascript:history.back()'>Okay</a>
                 <hr width='750px'/>";
           include ('./includes/style_bottom.php');
           exit();
        }
        else
           {
           if(!$_POST['continue'])
           {
              echo round_table('750')."<table width = '100%'>
                                          <tr>
                                             <td align = 'center'>
                             <form method='post' action='companies.php?action=pricing'>
                             <b>Pricing</b><br>

                             <table width=100%><tr><td align = 'center'>
                             Here you can select how much you want to sell your products for. 
                             If you put your prices low, this will result in more customers and a higher popularity.
                             High prices may get you more money if your company has good stats,
                             however you may also get fewer customers.</td></tr></table><br>

                             <br><table width=100%><tr bgcolor=#999999><td width=35%><b>Name</b></td>
                                 <td width=20%><b>Sold yesterday</b></td><td width=20%><b>In stock</b></td>
                                 <td width=1%><b>Price each</b></td>

                             </tr><tr bgcolor=#DFDFDF>

                             <td>",htmlentities($t['c_PROD1']),"</td><td>".number_format($ds['c_SOLD1'])."</td><td>".number_format($ds['c_STOCK1'])."</td><td><input type=text value='{$ds['c_PROD1']}' name='item1' maxlength=8></td>

                             </tr><tr bgcolor=#CCCCCC>

                             <td>",htmlentities($t['c_PROD2']),"</td><td>".number_format($ds['c_SOLD2'])."</td><td>".number_format($ds['c_STOCK2'])."</td><td><input type=text value='{$ds['c_PROD2']}' name='item2' maxlength=8></td>

                             </tr><tr bgcolor=#DFDFDF>

                             <td>",htmlentities($t['c_PROD3']),"</td><td>".number_format($ds['c_SOLD3'])."</td><td>".number_format($ds['c_STOCK3'])."</td><td><input type=text value='{$ds['c_PROD3']}' name='item3' maxlength=8></td>

                             </tr><tr bgcolor=#CCCCCC>

                             <td>",htmlentities($t['c_PROD4']),"</td><td>".number_format($ds['c_SOLD4'])."</td><td>".number_format($ds['c_STOCK4'])."</td><td><input type=text value='{$ds['c_PROD4']}' name='item4' maxlength=8></td>

                             </tr><tr bgcolor=#999999>

                             <td colspan = '4' align = 'center'><input type = 'submit' name = 'continue' value = 'Update'></td>

                             </tr></table></td></tr></table>".end_round()."
                             </form>";
                             } 
                             else
                             {
                             $_POST['item1'] = abs(intval($_POST['item1']));
                             $_POST['item2'] = abs(intval($_POST['item2']));
                             $_POST['item3'] = abs(intval($_POST['item3']));
                             $_POST['item4'] = abs(intval($_POST['item4']));
                             if($_POST['item1'] == '' ||
                                $_POST['item2'] == '' || 
                                $_POST['item3'] == '' || 
                                $_POST['item4'] == '')
                             {
                                echo "Invalid, no prices may be blank!
                                      <hr width='750px'/>
                                      ><a href='javascript:history.back()'>Okay</a>
                                      <hr width='750px'/>";
                                include ('./includes/style_bottom.php');
                                exit();
                             }
                             else
                                {
                                   $q_ry = array();
                                   $q_ry = "UPDATE `members_companies`
                                            SET `c_PROD1` = '".mysql_real_escape_string($_POST['item1'])."',
                                                `c_PROD2` = '".mysql_real_escape_string($_POST['item2'])."',
                                                `c_PROD3` = '".mysql_real_escape_string($_POST['item3'])."',
                                                `c_PROD4` = '".mysql_real_escape_string($_POST['item4'])."'
                                            WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
                                   mysql_query($q_ry);
                                   echo "Prices updated successfully!
                                         <hr width='750px'/>
                                         ><a href='javascript:history.back()'>Okay</a>
                                         <hr width='750px'/>";
                                   include ('./includes/style_bottom.php');
                                   exit();
                                } 
                              }
                            }
                            echo "<hr width='750px'>><a href='companies.php'>Back</a><hr width='750px'></center>";
                           }
                          }


   function comp_store()
   {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points` 
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $is = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
  {
      echo "You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = array();
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = array();
        $type = mysql_query($q_ry);
        $t = array();
        $t = mysql_fetch_array($type);

        if($_SESSION['playerid'] != $ds['c_owner'])
        {
           echo "Sorry but only ",htmlentities($ds['playername'])," may change the companies store room!
                 <hr width='750px'/>
                 ><a href='javascript:history.back()'>Okay</a>
                 <hr width='750px'/>";
           include ('./includes/style_bottom.php');
           exit();
        }
        if($t['c_PRODUCTS']!="yes")
        {
           echo "This company does not require any pricing!
                 <hr width='750px'/>
                 ><a href='javascript:history.back()'>Okay</a>
                 <hr width='750px'/>";
           include ('./includes/style_bottom.php');
           exit();
        }


           if(!$_POST['next'] AND !$_GET['buy'])
           {
              echo "<b>Upgrade Storage Room</b><br>".round_table('750')."<table width=100%><tr><td align = 'center'>Here you can upgrade your storage room. Increasing the size will result in a more stable business, <br/>The more stock you have available the less you will have to dissapoint customers with the message \"Sorry were out of stock\".</td></tr></table><br><br><table width=100%>";

echo "<tr bgcolor=#999999><td><b>Sizes</b></td><td><b>Cost</b></td><td width=1%></td></tr>";

           if($ds['c_storage'] == '6')
           {
              echo "<tr bgcolor=#DFDFDF><td colspan='3' align='center'>No further upgrades are available.</td></tr>";
           }
           else
              {
               if(!$ds['c_storage']) { $gothrough = 1; } else { $gothrough = $ds['c_storage']+1; }
               $storage = array(1=>'1:Standard room:25000:10000',2=>'2:Large room:150000:20000',3=>'3:Huge room:1000000:40000',
                                4=>'4:Warehouse:10000000:80000',5=>'5:Large warehouse:100000000:250000',6=>'6:Huge warehouse:500000000:1000000');
               for($i = $gothrough; $i<=6; $i++)
               {
                  if ($i % 2) { $color="#e3e3e3"; } else { $color="#cccccc"; }
                  $data_store = explode(":", $storage[$i]);
                  $id = $data_store[0];
                  $name = $data_store[1];
                  $cost = $data_store[2];
                  $gain = $data_store[3];
                  echo "<form method='post' action='companies.php?action=storage&buy=".$id."'><tr bgcolor=$color><td>",$name,"</td><td>".money_alter($cost)."</td><td width=1%><input type=radio value='".$id."' name='size' onClick = 'submit()'></td></tr></form>";
               }
           }
           echo "<tr bgcolor = #999999><td align = center colspan = '3'> </td></tr></table>".end_round()."<hr width = '750px'>><a href='javascript:history.back()'>Back</a><hr width='750px'/>";
           }
           else if(in_array($_GET['buy'], array(1,2,3,4,5,6)))
           {
               $storage = array(1=>'1:Standard room:25000:10000',2=>'2:Large room:150000:20000',3=>'3:Huge room:1000000:40000',
                                4=>'4:Warehouse:10000000:80000',5=>'5:Large warehouse:100000000:250000',6=>'6:Huge warehouse:500000000:1000000');
                  $data_store = explode(":", $storage[$_GET['buy']]);
                  $id = $data_store[0];
                  $name = $data_store[1];
                  $cost = $data_store[2];
                  $gain = $data_store[3];
                        if($cost > $ds['c_wallet'])
                        {
                           echo "Sorry, You dont have enough money in your company bank for this upgrade!
                                 <hr width='750px'/>
                                 ><a href='javascript:history.back()'>Okay</a>
                                 <hr width='750px'/>";
                                 include ('./includes/style_bottom.php');
                                 exit();
                        }
                        else if($id <= $ds['c_storage'])
                        {
                           echo "Error, You cannot downgrade your company!
                                 <hr width='750px'/>
                                 ><a href='javascript:history.back()'>Okay</a>
                                 <hr width='750px'/>";
                                 include ('./includes/style_bottom.php');
                                 exit();
                        }
                        else
                           {
                              if(!$_GET['next'])
                              {
                              echo "Are you sure you want to buy the 
                                    <b>",htmlentities($name),"</b>
                                    for ".money_alter($cost)."?
                                    <hr width='750px'>
                                    <table width='750px'><tr>
                                    <td align='center' width='50%'>>
                                    <a href='companies.php?action=storage'>No</a></td>
                                    <td align='center' width='50%'>>
                                    <a href='companies.php?action=storage&buy={$_GET['buy']}&next=1'>Yes</a></td>
                                    </tr></table>
                                    <hr width='750px'></center>";

                              }
                              else
                              {
                                    $q_ry = array();
                                    $q_ry = "UPDATE `members_companies`
                                             SET `c_storage` = '".mysql_real_escape_string($id)."',
                                                 `c_wallet` = `c_wallet` - '".mysql_real_escape_string($cost)."'
                                             WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
                                    mysql_query($q_ry);
                                    echo "<center>Success, You now own a ",htmlentities($name),"!
                                    <hr width='750px'/>
                                    ><a href='javascript:history.back(2)'>Okay</a>
                                    <hr width='750px'/>";
                              }
                           }
             }
}
}


   function comp_capacity()
   {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points` 
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $is = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
  {
      echo "You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = array();
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = array();
        $type = mysql_query($q_ry);
        $t = array();
        $t = mysql_fetch_array($type);

        if($_SESSION['playerid'] != $ds['c_owner'])
        {
           echo "Sorry but only ",htmlentities($ds['playername'])," may change the companies capacity!
                 <hr width='750px'/>
                 ><a href='javascript:history.back()'>Okay</a>
                 <hr width='750px'/>";
           include ('./includes/style_bottom.php');
           exit();
        }


           if(!$_POST['next'] AND !$_GET['buy'])
           {
              echo "<b>Upgrade company capacity</b><br>".round_table('750')."<table width=100%><tr><td align = 'center'>Here you can upgrade your company capacity. Increasing the capacity will enable you to employ more people.</td></tr></table><br><br><table width=100%>";

echo "<tr bgcolor=#999999><td><b>Capacity</b></td><td><b>Cost</b></td><td width=1%></td></tr>";

           if($ds['c_capacity'] == '14')
           {
              echo "<tr bgcolor=#DFDFDF><td colspan='3' align='center'>No further upgrades are available.</td></tr>";
           }
           else
              {
               if(!$ds['c_capacity']) { $gothrough = 1; } else { $gothrough = $ds['c_capacity']+1; }
               $storage = array(1=>'1:25000:6',2=>'2:500000:8',3=>'3:1000000:10',4=>'4:1500000:12',5=>'5:2000000:14',6=>'6:2500000:16',7=>'7:3000000:18',8=>'8:3500000:20',9=>'9:4000000:22',
                                10=>'10:4500000:24',11=>'11:5000000:26',12=>'12:5500000:28',13=>'13:6000000:30');
               for($i = $gothrough; $i<=13; $i++)
               {
                  if ($i % 2) { $color="#e3e3e3"; } else { $color="#cccccc"; }
                  $data_store = explode(":", $storage[$i]);
                  $id = $data_store[0];
                  $cost = $data_store[1];
                  $gain = $data_store[2];
                  echo "<form method='post' action='companies.php?action=capacity&buy=".$id."'><tr bgcolor=$color><td>",$gain," Employees</td><td>".money_alter($cost)."</td><td width=1%><input type=radio value='".$id."' name='size' onClick = 'submit()'></td></tr></form>";
               }
           }
           echo "<tr bgcolor = #999999><td align = center colspan = '3'> </td></tr></table>".end_round()."<hr width = '750px'>><a href='javascript:history.back()'>Back</a><hr width='750px'/>";
           }
           else if(in_array($_GET['buy'], array(1,2,3,4,5,6,7,8,9,10,11,12,13)))
           {
               $storage = array(1=>'1:25000:6',2=>'2:500000:8',3=>'3:1000000:10',4=>'4:1500000:12',5=>'5:2000000:14',6=>'6:2500000:16',7=>'7:3000000:18',8=>'8:3500000:20',9=>'9:4000000:22',
                                10=>'10:4500000:24',11=>'11:5000000:26',12=>'12:5500000:28',13=>'13:6000000:30');
                  $data_store = explode(":", $storage[$_GET['buy']]);
                  $id = $data_store[0];
                  $cost = $data_store[1];
                  $gain = $data_store[2];
                        if($cost > $ds['c_wallet'])
                        {
                           echo "Sorry, You dont have enough money in your company bank for this upgrade!
                                 <hr width='750px'/>
                                 ><a href='javascript:history.back()'>Okay</a>
                                 <hr width='750px'/>";
                                 include ('./includes/style_bottom.php');
                                 exit();
                        }
                        else if($id <= $ds['c_capacity'])
                        {
                           echo "Error, You cannot downgrade your company!
                                 <hr width='750px'/>
                                 ><a href='javascript:history.back()'>Okay</a>
                                 <hr width='750px'/>";
                                 include ('./includes/style_bottom.php');
                                 exit();
                        }
                        else
                           {
                              if(!$_GET['next'])
                              {
                              echo "Are you sure you want to buy the 
                                    <b>".$gain." Employees</b>
                                    for ".money_alter($cost)."?
                                    <hr width='750px'>
                                    <table width='750px'><tr>
                                    <td align='center' width='50%'>>
                                    <a href='companies.php?action=capacity'>No</a></td>
                                    <td align='center' width='50%'>>
                                    <a href='companies.php?action=capacity&buy={$_GET['buy']}&next=1'>Yes</a></td>
                                    </tr></table>
                                    <hr width='750px'></center>";

                              }
                              else
                              {
                                    $q_ry = array();
                                    $q_ry = "UPDATE `members_companies`
                                             SET `c_capacity` = '".mysql_real_escape_string($id)."',
                                                 `c_wallet` = `c_wallet` - '".mysql_real_escape_string($cost)."'
                                             WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
                                    mysql_query($q_ry);
                                    echo "<center>Success, You now have a max of <b>".$gain." Employees</b>!
                                    <hr width='750px'/>
                                    ><a href='javascript:history.back(2)'>Okay</a>
                                    <hr width='750px'/>";
                              }
                           }
             }
}
}



   function comp_sroom()
   {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points` 
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $is = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
  {
      echo "You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = array();
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = array();
        $type = mysql_query($q_ry);
        $t = array();
        $t = mysql_fetch_array($type);

        if($_SESSION['playerid'] != $ds['c_owner'])
        {
           echo "Sorry but only ",htmlentities($ds['playername'])," may change the staff room!
                 <hr width='750px'/>
                 ><a href='javascript:history.back()'>Okay</a>
                 <hr width='750px'/>";
           include ('./includes/style_bottom.php');
           exit();
        }


           if(!$_POST['next'] AND !$_GET['buy'])
           {
              echo "<b>Upgrade staff room</b><br>".round_table('750')."<table width=100%><tr><td align = 'center'>Here you can upgrade your company staff room. Increasing the staff room will make staff work harder, It will also give your company more efficiency.</td></tr></table><br><br><table width=100%>";

echo "<tr bgcolor=#999999><td><b>Sizes</b></td><td><b>Cost</b></td><td width=1%></td></tr>";

           if($ds['c_sroom'] == '4')
           {
              echo "<tr bgcolor=#DFDFDF><td colspan='3' align='center'>No further upgrades are available.</td></tr>";
           }
           else
              {
               if(!$ds['c_sroom']) { $gothrough = 1; } else { $gothrough = $ds['c_sroom']+1; }
               $storage = array(1=>'1:Small staff room:50000:4',2=>'2:Standard staff room:250000:8',3=>'3:Large staff room:1000000:18',4=>'4:Huge staff room:25000000:30');
               for($i = $gothrough; $i<=4; $i++)
               {
                  if ($i % 2) { $color="#e3e3e3"; } else { $color="#cccccc"; }
                  $data_store = explode(":", $storage[$i]);
                  $id = $data_store[0];
                  $name = $data_store[1];
                  $cost = $data_store[2];
                  $gain = $data_store[3];
                  echo "<form method='post' action='companies.php?action=staffroom&buy=".$id."'><tr bgcolor=$color><td>",$name,"</td><td>".money_alter($cost)."</td><td width=1%><input type=radio value='".$id."' name='size' onClick = 'submit()'></td></tr></form>";
               }
           }
           echo "<tr bgcolor = #999999><td align = center colspan = '3'> </td></tr></table>".end_round()."<hr width = '750px'>><a href='javascript:history.back()'>Back</a><hr width='750px'/>";
           }
           else if(in_array($_GET['buy'], array(1,2,3,4)))
           {
               $storage = array(1=>'1:Small staff room:50000:4',2=>'2:Standard staff room:250000:8',3=>'3:Large staff room:1000000:18',4=>'4:Huge staff room:25000000:30');
                  $data_store = explode(":", $storage[$_GET['buy']]);
                  $id = $data_store[0];
                  $name = $data_store[1];
                  $cost = $data_store[2];
                  $gain = $data_store[3];
                        if($cost > $ds['c_wallet'])
                        {
                           echo "Sorry, You dont have enough money in your company bank for this upgrade!
                                 <hr width='750px'/>
                                 ><a href='javascript:history.back()'>Okay</a>
                                 <hr width='750px'/>";
                                 include ('./includes/style_bottom.php');
                                 exit();
                        }
                        else if($id <= $ds['c_sroom'])
                        {
                           echo "Error, You cannot downgrade your company!
                                 <hr width='750px'/>
                                 ><a href='javascript:history.back()'>Okay</a>
                                 <hr width='750px'/>";
                                 include ('./includes/style_bottom.php');
                                 exit();
                        }
                        else
                           {
                              if(!$_GET['next'])
                              {
                              echo "Are you sure you want to buy the 
                                    <b>".$name."</b>
                                    for ".money_alter($cost)."?
                                    <hr width='750px'>
                                    <table width='750px'><tr>
                                    <td align='center' width='50%'>>
                                    <a href='companies.php?action=staffroom'>No</a></td>
                                    <td align='center' width='50%'>>
                                    <a href='companies.php?action=staffroom&buy={$_GET['buy']}&next=1'>Yes</a></td>
                                    </tr></table>
                                    <hr width='750px'></center>";

                              }
                              else
                              {
                                    $q_ry = array();
                                    $q_ry = "UPDATE `members_companies`
                                             SET `c_sroom` = '".mysql_real_escape_string($id)."',
                                                 `c_wallet` = `c_wallet` - '".mysql_real_escape_string($cost)."'
                                             WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
                                    mysql_query($q_ry);
                                    echo "<center>Success, You now a <b>".$name."</b>!
                                    <hr width='750px'/>
                                    ><a href='javascript:history.back(2)'>Okay</a>
                                    <hr width='750px'/>";
                              }
                           }
             }
}
}


    function ad_camp()
    {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points` 
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $is = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
  {
      echo "You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = array();
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = array();
        $type = mysql_query($q_ry);
        $t = array();
        $t = mysql_fetch_array($type);

     $my_rank = array();
     $mr = array();
     $q_ry = array();
     $q_ry = "SELECT *
              FROM `comp_members` cm
              LEFT JOIN `system_c_ranks` sr 
              ON cm.m_rank = sr.cr_ID
              WHERE cm.m_playerid = '".mysql_real_escape_string($_SESSION['playerid'])."'";
     $my_rank = mysql_query($q_ry);
     $mr = mysql_fetch_array($my_rank);
     if($_SESSION['playerid'] != $ds['c_owner'])
    {
     echo "<center>Sorry, Only the company director can add advertising!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
    }

            if($ds['c_campaign'] != 'none')
           {
                    echo "<center>You are already running a ",htmlentities($ds['c_campaign'])," advertising campaign for ".number_format($ds['c_campdays'])." more days!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
           }
           if(!$_POST['next'] AND !$_GET['buy'])
           {
            echo round_table('750')."<b>Advertising</b><br><br><table width=100%><tr><td><center>
                  Advertising your company will increase the popularity of your company while lowering your competitors  
                  (Companies with the same type as you). Each campaign will last 7 days, the more you spend on one, 
                  the more popularity your company will get out of it.</td></tr></table><br>
                  <form method='post' action='companies.php?action=advertising'>
                  <table width=90%>
                  <tr bgcolor=#999999><td colspan=2><center><b>Advertising Campaigns</b></td></tr>
                  <tr bgcolor=#DFDFDF><td>Cheap Advertising Campaign</td><td width=1%>
                  <input type=radio value='1' name='advert'></td></tr>
                  <tr bgcolor=#CCCCCC><td>Standard Advertising Campaign</td><td width=1%>
                  <input type=radio value='2' name='advert'></td></tr>
                  <tr bgcolor=#DFDFDF><td>Expensive Advertising Campaign</td><td width=1%>
                  <input type=radio value='3' name='advert'></td></tr>
                  <tr bgcolor=#999999><td colspan=2><center><input type=submit name=next value=Next></td></tr>
             </table>".end_round()."
          </form>
          <hr width=750px>> <a href='companies.php'>Back</a>
          <hr width=750px>";
                         } 
                            else
                           {

                            if(!$_GET['buy'])
                            {
                              if($_POST['advert'] == '1')
                             {
                                echo "<center>Are you sure you wish to buy the <b>Cheap Advertising Campaign</b> for 
                                     ".money_alter($t['c_COST']/10)."?<br/>
                                     <hr width='750px'>
                                     <table width='750px'><tr>
                                     <td align='center' width='50%'>>
                                     <a href='companies.php?action=advertising'>No</a></td>
                                     <td align='center' width='50%'>>
                                     <a href='companies.php?action=advertising&buy=1'>Yes</a></td>
                                     </tr></table>
                                     <hr width='750px'>
                                     </center>";
                             }
                              else if($_POST['advert'] == '2')
                             {
                                echo "<center>Are you sure you wish to buy the <b>Standard Advertising Campaign</b> for 
                                     ".money_alter($t['c_COST']/5)."?<br/>
                                     <hr width='750px'>
                                     <table width='750px'><tr>
                                     <td align='center' width='50%'>>
                                     <a href='companies.php?action=advertising'>No</a></td>
                                     <td align='center' width='50%'>>
                                     <a href='companies.php?action=advertising&buy=2'>Yes</a></td>
                                     </tr></table>
                                     <hr width='750px'>
                                     </center>";
                             }
                              else if($_POST['advert'] == '3')
                             {
                                echo "<center>Are you sure you wish to buy the <b>Expensive Advertising Campaign</b> for 
                                     ".money_alter($t['c_COST']/2)."?<br/>
                                     <hr width='750px'>
                                     <table width='750px'><tr>
                                     <td align='center' width='50%'>>
                                     <a href='companies.php?action=advertising'>No</a></td>
                                     <td align='center' width='50%'>>
                                     <a href='companies.php?action=advertising&buy=3'>Yes</a></td>
                                     </tr></table>
                                     <hr width='750px'>";
                             } 
                              else
                                  {
                                    echo "<center>Error, You did not select a valid advertising campaign to run!<br/>
                                          ><a href='companies.php'>Okay</a></center>"; 
                                   }
                            }
                             else
                                 {
                                    if(!in_array($_GET['buy'], array('1' , '2', '3'))) {
                                    echo "Invalid Advertising campaign!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                    }
                                     else
                                         {


                              if($_GET['buy'] == '1')
                             {
                                $total = array();
                                $total = ($t['c_COST']/10);
                                if($total > $ds['c_wallet'])
                               {
                                echo "<center>
                                      Sorry, You dont have enough in your company bank for this advertising compaign.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                    }
                                     else
                                         {
                                            $q_ry = array();
                                            $q_ry = "UPDATE `members_companies`
                                                     SET `c_wallet` = `c_wallet` - '".mysql_real_escape_string($total)."',
                                                         `c_campaign` = 'cheap',
                                                         `c_campdays` = '7'
                                                     WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
                                            mysql_query($q_ry);
                                            echo "<center>You have started a Cheap Advertising Campaign!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                    }
                             }
                              else if($_GET['buy'] == '2')
                             {
                                $total = array();
                                $total = ($t['c_COST']/5);
                                if($total > $ds['c_wallet'])
                               {
                                echo "<center>
                                      Sorry, You dont have enough in your company bank for this advertising compaign.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                    }
                                     else
                                         {
                                            $q_ry = array();
                                            $q_ry = "UPDATE `members_companies`
                                                     SET `c_wallet` = `c_wallet` - '".mysql_real_escape_string($total)."',
                                                         `c_campaign` = 'standard',
                                                         `c_campdays` = '7'
                                                     WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
                                            mysql_query($q_ry);
                                            echo "<center>You have started a Standard Advertising Campaign!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                             }
                             }
                             else if($_GET['buy'] == '3')
                             {
                                $total = array();
                                $total = ($t['c_COST']/2);
                                if($total > $ds['c_wallet'])
                               {
                                echo "<center>
                                      Sorry, You dont have enough in your company bank for this advertising compaign.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                    }
                                     else
                                         {
                                            $q_ry = array();
                                            $q_ry = "UPDATE `members_companies`
                                                     SET `c_wallet` = `c_wallet` - '".mysql_real_escape_string($total)."',
                                                         `c_campaign` = 'expensive',
                                                         `c_campdays` = '7'
                                                     WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
                                            mysql_query($q_ry);
                                            echo "<center>You have started a Expensive Advertising Campaign!
            <hr width='750px'/>
            ><a href='javascript:history.back(3)'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                    }
                             }
                              else
                                  {
                                    echo "<center>Error, You did not select a valid advertising campaign to run!<br/>
                                          ><a href='companies.php'>Okay</a></center>"; 
                                   }
                                  }
                            }
                           }
                     }
                    }








   function ships()
   {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points` 
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $ic = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
   {
      echo "You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = array();
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = array();
        $type = mysql_query($q_ry);
        $t = array();
        $t = mysql_fetch_array($type);



   if($_SESSION['playerid'] != $ds['playerid'])
   {
      echo "Sorry but only ",htmlentities($ds['playername'])," may purchase shipments!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
   }
   if($t['c_PRODUCTS']!="yes")
   {
      echo "This company does not require any shipments!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
   }
                 else
                      {

                        if(!$_POST['continue'])
                       {
                        echo "<center><form method='post' action='companies.php?action=shipping'>
                             ".round_table('750')."<table width=100%><tr><td align = 'center'>
                             <b>Shipping</b><br>
                             Here you can select shippments to your company. 
                             The more you have the less customers you might dissapoint.
                             You have a max capacity of " . number_format(id_storage($ds['c_storage'])) . " products.<br>

                             <br><table width=100%><tr bgcolor=#999999><td width=35%><b>Name</b></td>
                                 <td width=20%><b>Price</b></td><td width=20%><b>Shipping time</b></td>
                                 <td width=1%><b>Qty to order</b></td>

                             </tr><tr bgcolor=#DFDFDF>

                             <td>",htmlentities($t['c_PROD1']),"</td><td>".money_alter($t['c_SHIP1'])."</td><td>".number_format($t['c_STIME'])."</td><td><input type=text value='0' name='ship1' maxlength=8></td>

                             </tr><tr bgcolor=#CCCCCC>

                             <td>",htmlentities($t['c_PROD2']),"</td><td>".money_alter($t['c_SHIP2'])."</td><td>".number_format($t['c_STIME'])."</td><td><input type=text value='0' name='ship2' maxlength=8></td>

                             </tr><tr bgcolor=#DFDFDF>

                             <td>",htmlentities($t['c_PROD3']),"</td><td>".money_alter($t['c_SHIP3'])."</td><td>".number_format($t['c_STIME'])."</td><td><input type=text value='0' name='ship3' maxlength=8></td>

                             </tr><tr bgcolor=#CCCCCC>

                             <td>",htmlentities($t['c_PROD4']),"</td><td>".money_alter($t['c_SHIP4'])."</td><td>".number_format($t['c_STIME'])."</td><td><input type=text value='0' name='ship4' maxlength=8></td>

                             </tr><tr bgcolor=#999999>

                             <td colspan = '4' align = 'center'><input type = 'submit' name = 'continue' value = 'Order'></td>

                             </tr></table></td></tr></table>".end_round()."

</form>";   


$shipments = array();
$q_ry = array();
$sh = array();
$num = array();
$num = 0;
$q_ry = "SELECT * FROM `company_shippments`
        WHERE `s_COMP` = '".mysql_real_escape_string($ds['c_id'])."'";
$shipments = mysql_query($q_ry);


if(!mysql_num_rows($shipments))
{
echo "";
}
else
    {
     echo round_table('750')."<b>Your current shipments.</b><table width = '100%'>";
     while($sh = mysql_fetch_array($shipments))
    {                                               $num++;
                                              $odd="#cccccc";
                                              $even="#e3e3e3";
                                         if ($num % 2) {
                                         $color="$even";
                                         } else {
                                         $color="$odd"; 
                                                      }
       echo "<tr bgcolor = '$color'><td align = 'center'><br/>";
       if($sh['s_ITEM1']) { echo "".number_format($sh['s_ITEM1'])." x <b>",htmlentities($t['c_PROD1']),"</b>,"; }
       if($sh['s_ITEM2']) { echo "".number_format($sh['s_ITEM2'])." x <b>",htmlentities($t['c_PROD2']),"</b>,"; }
       if($sh['s_ITEM3']) { echo "".number_format($sh['s_ITEM3'])." x <b>",htmlentities($t['c_PROD3']),"</b>,"; }
       if($sh['s_ITEM4']) { echo "".number_format($sh['s_ITEM4'])." x <b>",htmlentities($t['c_PROD4']),"</b>"; }
       echo "<br/>These items will arrive in ".number_format($sh['s_TIME'])." hours.<br/></td></tr>";
    }
     echo "</table>".end_round();
    }
                      }
                           else
                                   {
                        if($_POST['ship1'] == '' ||
                           $_POST['ship2'] == '' || 
                           $_POST['ship3'] == '' || 
                           $_POST['ship4'] == '')
                      {
                echo "Invalid, One or more of your shipments was marked as blank!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
               }
                else
                    {

                        $_POST['ship1'] = abs(intval($_POST['ship1']));
                        $_POST['ship2'] = abs(intval($_POST['ship2']));
                        $_POST['ship3'] = abs(intval($_POST['ship3']));
                        $_POST['ship4'] = abs(intval($_POST['ship4']));

                        if($_POST['ship1'] == '0' &&
                           $_POST['ship2'] == '0' &&
                           $_POST['ship3'] == '0' &&
                           $_POST['ship4'] == '0')
                      {
                echo "Invalid, You selected 0 on all shippments, please go back and try again.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
               }


                $storagegone = array(); 
                $storagegone = ($_POST['ship1']+$_POST['ship2']+$_POST['ship3']+$_POST['ship4']);

$shipments = array();
$q_ry = array();
$sh = array();
$num = array();
$num = 0;
$q_ry = "SELECT * FROM `company_shippments`
        WHERE `s_COMP` = '".mysql_real_escape_string($ds['c_id'])."'";
$shipments = mysql_query($q_ry);


if(!mysql_num_rows($shipments))
{
      $storagegone = $storagegone;
}
else
    {
     while($sh = mysql_fetch_array($shipments))
    {                             
          $storagegone = $storagegone + ($sh['s_ITEM1']+$sh['s_ITEM2']+$sh['s_ITEM3']+$sh['s_ITEM4']);
    }
    }
          $storagegone = $storagegone + ($ds['c_STOCK1']+$ds['c_STOCK2']+$ds['c_STOCK3']+$ds['c_STOCK4']);
               $storagefree = id_storage($ds['c_storage']);
                if($storagefree < $storagegone)
               {
                echo "Sorry, you dont have enough storage room for this many shipments!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
               }


                  $cost = array();
                  $cost = (($t['c_SHIP1']*$_POST['ship1'])+($t['c_SHIP2']*$_POST['ship2'])
                                                          +($t['c_SHIP3']*$_POST['ship3']) 
                                                          +($t['c_SHIP4']*$_POST['ship4']));
                      if($cost > $ds['c_wallet'])
                     {
                echo "Sorry, you dont have enough funds in your company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
               }
                 else {
               $q_ry = array();
               $q_ry = "INSERT INTO `company_shippments` 
                        VALUES ('NULL', '".mysql_real_escape_string($ds['c_id'])."',
                                    '".mysql_real_escape_string($_POST['ship1'])."',
                                    '".mysql_real_escape_string($_POST['ship2'])."',
                                    '".mysql_real_escape_string($_POST['ship3'])."',
                                    '".mysql_real_escape_string($_POST['ship4'])."',
                                    '".mysql_real_escape_string($t['c_STIME'])."')";
               mysql_query($q_ry);
               $q_ry = array();
               $q_ry = "UPDATE `members_companies`
                        SET `c_wallet` = `c_wallet` - '".mysql_real_escape_string($cost)."' 
                        WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
               mysql_query($q_ry);

               echo "Thank you for your order, it will now be processed, 
                    ".money_alter($cost)." has been payed to us.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                }   
              }
            }
      }
    }
   echo "<hr width='750px'>><a href='companies.php'>Back</a><hr width='750px'></center>";

}


    function comp_manage()
   {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points` 
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $ic = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
   {
      echo "You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = array();
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = array();
        $type = mysql_query($q_ry);
        $t = array();
        $t = mysql_fetch_array($type);



   if($_SESSION['playerid'] != $ds['playerid'])
   {
      echo "Sorry but only ",htmlentities($ds['playername'])," may manage employees!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
   }
     else
         {
          $q_ry = array();
          $q_ry = "SELECT *
                   FROM `comp_members` cm
                   LEFT JOIN `members` m 
                   ON cm.m_playerid = m.playerid
                   LEFT JOIN `memberstats` ms 
                   ON cm.m_playerid = ms.playerid
                   LEFT JOIN `members_extra` me 
                   ON cm.m_playerid = me.playerid
                   WHERE cm.m_comp = '".mysql_real_escape_string($ds['c_id'])."'";
          $employe = array();
          $employe = mysql_query($q_ry);
          echo "<center>".round_table('750')."<b>Company Employees</b><br><br>";
          if(!$_POST['change'])
          {
          echo "<table width=100%><tr><td align = 'center'>Here you can 
          view the employees details and change their rank and pay.<br>The company currently has 
          ".(mysql_num_rows($employe)+1)." employees (including the director).
          <br><br>
          > <a href=companies.php?action=applications>View applications to this company</a><br>
          </td></tr></table><br>";
       if($_GET['u'])
       {
          if($_GET['u'] == 1)
         {
           echo "<font color=#006600><b>UPDATED</b></font><br><br>";
         }
        else
            {
             echo "<font color=red><b>Abuse detected</b></font><br><br>";
             include('./includes/style_bottom.php');
             exit();
            }
       }
          echo "<table width=100% border=0><tr bgcolor=#999999><td colspan=9>
          <b><center>",htmlentities($ds['c_name'])," employees</b>
</td></tr>
<tr bgcolor=#999999>
<td width=1% align=center></td>
<td width=10%><div align=left><b><center>Name</b></div></td>
<td width=5%><div align=left><b><center>Effectiveness</b></div></td>
<td width=20%><div align=left><b><center>Stats</b></div></td>
<td width=5%><div align=left><b><center>Days</b></div></td>
<td width=1%><div align=left><b><center>Rank</b></div></td>
<td width=1%><div align=left><b><center>Pay</b></div></td>
<td width=1%><div align=left><b><center>Train</b></div></td>
<td width=1%><div align=left><b><center>Fire</b></div></td>
</tr>
<form action='companies.php?action=manage' method='post'>";

      $emp = array();
      while($emp = mysql_fetch_array($employe))
     {
      echo "

<tr bgcolor=#DFDFDF><td>";

         if($emp['laston'] >= time()-15*60) 
        { 
         echo "<img src='images/online.png' title='Online'/> "; 
        } 
         else 
             { 
              echo "<img src='images/offline.png' title='Offline'/> "; 
        } 



echo "</td></td>
<td align='left' width='50%'><a href=profile.php?XID={$emp['playerid']}>",htmlentities($emp['playername'])," [{$emp['playerid']}]</a></td>
<td align='center'>";

                    /*long ass effect formula start*/
                    $la=time()-$emp['laston'];
                    $unit="noeffect";
                    if($la >= 60)
                   {
                    $la=(int) ($la/60);
                    $unit="noeffect";
                   }
                    if($la >= 60)
                   {
                    $la=(int) ($la/60);
                    $unit="noeffect";
                   }
                    if($la >= 24)
                   {
                    $la=(int) ($la/24);
                    $unit="Days";
                   }
                    $myeffect = array();
                    $myeffect = 1;
                   if($unit == "Days" AND $la > 3)
                   {
                    $myeffect = $myeffect - 1;
                   }
                   else
                   {
                    $myeffect = $myeffect + 1;
                   }
                   if($emp['my_drugadd'] > 50)
                  {
                    $myeffect = $myeffect - 1;
                  }
                   else
                       {
                        $myeffect = $myeffect + 2;
                       }
                    if($emp['m_rank'])
                   {
                    $rank = array();
                    $q_ry = array();
                    $q_ry = "SELECT *
                             FROM `system_c_ranks`
                             WHERE `cr_ID` = '".mysql_real_escape_string($emp['m_rank'])."'";
                    $rank = mysql_query($q_ry);
                    $rk = array();
                    $rk = mysql_fetch_array($rank);

                    if(($emp[$rk['cr_PRIMSTAT']]+$emp[$rk['cr_SECSTAT']]) > $rk['cr_CAP'])
                   {
                    $myeffect = $myeffect - 1;
                   }
                    if(($emp[$rk['cr_PRIMSTAT']]+$emp[$rk['cr_SECSTAT']]) < $rk['cr_CAP']/10)
                   {
                    $myeffect = $myeffect - 1;
                   }
                    else
                        {
                    $myeffect = $myeffect + 1;
                   }
                   }
                    else
                   {
                    $myeffect = 1;
                   }
                    if($myeffect < 1)
                   {
                    $myeffect = 1;
                   }
                  if($emp['my_drugadd'] >= 80)
                  {
                    $myeffect = 1;
                  }
                   /*effect formula end lol*/


                    echo "<img src=images/{$myeffect}_star.png>
                    </center></div></td>
                    <td width='5%' align=left><b>M:</b>".number_format($emp['my_labor'])."<br/>
                         <b>E:</b>".number_format($emp['my_endurance'])."<br/>
                         <b>I:</b>".number_format($emp['my_intelligence'])."</td>
<td width='5%' align=left>{$emp['m_days']}</td>

<td><div align=left>";
                    $ranks = array();
                    $q_ry = array();
                    $q_ry = "SELECT *
                             FROM `system_c_ranks`
                             WHERE `cr_COMP` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
                    $ranks = mysql_query($q_ry);
                    $rks = array();
echo "<select name='{$emp['m_playerid']}rank'>";
while($rks = mysql_fetch_array($ranks))
{
     if($rks['cr_ID'] == $emp['m_rank'])
    {
     echo "<option value='{$rks['cr_ID']}' selected>",htmlentities($rks['cr_NAME']),"</option>";
    }
     else
          {
       echo "<option value='{$rks['cr_ID']}'>",htmlentities($rks['cr_NAME']),"</option>";
    } 
  }
  if(!$emp['m_rank'])
  {
   echo "<option value='0' selected>Unassigned</option>";
  }
   else
       {
   echo "<option value='0'>Unassigned</option>";
       }
       echo "</select></div></td>
       <td><input type=text size=7 name='{$emp['m_playerid']}wages' value='{$emp['m_gains']}'></td>
       <td>[<a href=companies.php?action=train&XID={$emp['m_playerid']}>Train</a>]</td>
       <td>[<a href=companies.php?action=fire&XID={$emp['m_playerid']}>Fire</a>]</td>
       </tr>";
     }
      echo "<tr bgcolor=#999999><td colspan='9' align='center'><input type=submit name=change value='Submit Changes'>    
      </td></tr></table></form>".end_round()."<br>
      <hr width='750px'>><a href=companies.php>Back</a>
      <hr width='750px'>";
                     }
                     else if($_POST['change'])
                        {
          $q_ry = array();
          $q_ry = "SELECT *
                   FROM `comp_members` 
                   WHERE `m_comp` = '".mysql_real_escape_string($ds['c_id'])."'";
          $employe = array();
          $employe = mysql_query($q_ry);
          $emp = array();
          $totalwages = array();
          $totalwages = 0;
          while($emp = mysql_fetch_array($employe))
          {
            $post_wages = array();
            $post_wages = $emp['m_playerid'].wages;
            $post_wages = abs(intval($_POST[$post_wages]));
            $totalwages = $totalwages + $post_wages;
          }
            if($totalwages > $ds['c_wallet'] AND $ds['c_wallet'] > 0)
            {
              echo "<center>Sorry, You have selected above your company funds for someone wages,
                    All wages must be lower than the company funds!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
           } 
            if($totalwages > 0 AND $ds['c_wallet'] < 0)
            {
              echo "<center>Sorry, You have selected above your company funds for someone wages,
                    All wages must be lower than the company funds!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
           } 
          $q_ry = array();
          $q_ry = "SELECT *
                   FROM `comp_members` 
                   WHERE `m_comp` = '".mysql_real_escape_string($ds['c_id'])."'";
          $employe = array();
          $employe = mysql_query($q_ry);
          $emp = array();
          while($emp = mysql_fetch_array($employe))
          {
            $post_rank = array();
            $post_rank = $emp['m_playerid'].rank;
            $post_wages = array();
            $post_wages = $emp['m_playerid'].wages;
            $post_wages = abs(intval($_POST[$post_wages]));
            if($_POST[$post_rank] > 0)
           {
            $rank = array();
            $q_ry = array();
            $q_ry = "SELECT *
                     FROM `system_c_ranks`
                     WHERE `cr_ID` = '".mysql_real_escape_string($_POST[$post_rank])."'
                     AND `cr_COMP` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
            $rank = mysql_query($q_ry);
            $rk = array();
            $rnk = array();
            $rnk = mysql_fetch_array($rank);
            if(!mysql_num_rows($rank))
           {
              echo "<center>Invalid rank detected!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
           } 
           else
              {
                    $rk = $_POST[$post_rank];
               }
            }
             else
                  {
                    $rk = 0;
                    $rnk['cr_NAME']="Unassigned";
                  }     

                if($rk != $emp['m_rank'])
                {
                $mess = array();
                $mess = "".htmlentities($pl['playername'])." has changed your rank to ".htmlentities($rnk['cr_NAME'])."";
                            in_event($emp['m_playerid'], $mess);
                                                               }
                if($post_wages != $emp['m_gains'])
                {
                $mess = array();
                $mess = "".htmlentities($pl['playername'])." has changed your daily pay to ".money_alter($post_wages)."";
                            in_event($emp['m_playerid'], $mess);
                                                               }
                           $q_ry = array();
                           $q_ry ="UPDATE `comp_members`
                                   SET `m_rank` = '".mysql_real_escape_string($rk)."',
                                       `m_gains` = '".mysql_real_escape_string($post_wages)."'
                                   WHERE `m_playerid` = '".mysql_real_escape_string($emp['m_playerid'])."'";
                           mysql_query($q_ry);     
                        }
                           header('location:companies.php?action=manage&u=1');
                        }
                         else
                             {
                              echo "<center>Error, Abuse detected!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                             }
              }
    }

   }

  function comp_apps()
 {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points` 
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $ic = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
   {
      echo "You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = array();
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = array();
        $type = mysql_query($q_ry);
        $t = array();
        $t = mysql_fetch_array($type);

     $my_rank = array();
     $mr = array();
     $q_ry = array();
     $q_ry = "SELECT *
              FROM `comp_members` cm
              LEFT JOIN `system_c_ranks` sr 
              ON cm.m_rank = sr.cr_ID
              WHERE cm.m_playerid = '".mysql_real_escape_string($_SESSION['playerid'])."'";
     $my_rank = mysql_query($q_ry);
     $mr = mysql_fetch_array($my_rank);
   if($_SESSION['playerid'] != $ds['playerid'])
   {
      echo "Sorry but only ",htmlentities($ds['playername'])," may manage applications!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
   }
           if(!$_POST['view'] AND !$_POST['accept'] AND !$_POST['decline'])
          {
           echo "<form action='companies.php?action=applications' method='post'>
                 ".round_table('750')."<table width='100%' border='0'>";

           $apps = array();
           $q_ry = array();
           $q_ry = "SELECT * 
                    FROM `applications` app
                    LEFT JOIN `members` m 
                    ON app.app_PLAYER = m.playerid
                    WHERE app.app_TYPE = 'company'
                    AND app.app_XID = '".mysql_real_escape_string($ds['c_id'])."'";
           $apps = mysql_query($q_ry);
           if(!mysql_num_rows($apps))
          {
           echo "<tr><td align='center'>There are no applications to view at this time.</td></tr>";
          }
           else
                {
                 $cap = array();
                 $num = array();
                 $num = 0;
                 while($cap = mysql_fetch_array($apps))
                {
                                              $num++;
                                              $odd="#cccccc";
                                              $even="#e3e3e3";
                                         if ($num % 2) {
                                         $color="$even";
                                         } else {
                                         $color="$odd"; 
                                                      }
                 echo "<tr bgcolor='$color'><td align='left' width='5px'>#{$num}</td>
                       <td align='left'>
                       <a href='profile.php?XID={$cap['app_PLAYER']}'><b>",htmlentities($cap['playername']),"
                       [{$cap['app_PLAYER']}]</b></a>
                       </td>
                       <td align='right' width='10px'>
                       <input type=hidden name=ID value={$cap['app_ID']}>
                       <input type=submit name=view value=View>
                       </td></tr>";
                }
                }
           echo "</td>
           </table>".end_round()."</center>";
          }
            else if($_POST['view'])
                 {
                  $_POST['ID'] = abs(intval($_POST['ID']));
                  if(!$_POST['ID'])
                 {
                  echo "<center>Error, Invalid ID!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                 }
           $apps = array();
           $q_ry = array();
           $q_ry = "SELECT * 
                    FROM `applications` app
                    LEFT JOIN `members` m 
                    ON app.app_PLAYER = m.playerid
                    WHERE app.app_TYPE = 'company'
                    AND app.app_ID = '".mysql_real_escape_string($_POST['ID'])."'";
           $apps = mysql_query($q_ry);
                  if(!mysql_num_rows($apps))
                 {
                  echo "<center>Error, Invalid ID!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                 } 
                  else
                       {
                        $cap = array();
                        $cap = mysql_fetch_array($apps);
                        echo "",htmlentities($cap['playername']),"'s application<hr width='750px'/>
                              <form action='companies.php?action=applications' method='post'>
                              ".round_table('750')."<table width = '100%' bgcolor=#FFFFFF><tr><td align='left' colspan='2'>
                              <b><u>",htmlentities($cap['playername']),"'s description:</u></b><br/><br/>
                              ",htmlentities($cap['app_DESC']),"<hr/>
                              <b><u>why ",htmlentities($cap['playername'])," wants to join:</u></b><br/><br/>
                              ",htmlentities($cap['app_WHY']),"<hr/>  
                              <b><u>Does ",htmlentities($cap['playername'])," consume drugs:</u></b><br/><br/>";
                              if($cap['app_DRUGS'] == 'yes')
                              {
                               echo "<font color='red'><b>Yes</b></font>";
                              }
                              else if($cap['app_DRUGS'] == 'no')
                              {
                               echo "<font color='green'><b>No</b></font>";
                              }
                              else if($cap['app_DRUGS'] == 'rare')
                              {
                               echo "<font color=#AA0000><b>Rarely</b></font>";
                              }
                              else
                              {
                               echo "<b>Prefer not to say</b>";
                              }
                              echo "<hr/>
                              <b><u>Prefered rank:</u></b><br/><br/>";
                              if($cap['app_RANK'])
                              {
                               $rank = array();
                               $q_ry = array();
                               $q_ry = "SELECT `cr_NAME`
                                        FROM `system_c_ranks`
                                        WHERE `cr_ID` = '".mysql_real_escape_string($cap['app_RANK'])."'";
                               $rank = mysql_query($q_ry);
                               $pr = array();
                               $pr = mysql_fetch_array($rank);
                               echo "",htmlentities($pr['cr_NAME']),"";
                              }
                              else
                              {
                               echo "Any";
                              }
                              echo "<hr/>
                              <b><u>How much ",htmlentities($cap['playername'])," would like to be payed:</u></b>
                              <br/><br/>";
                              if($cap['app_INCOME'])
                              {
                               echo "".money_alter($cap['app_INCOME'])."";
                              }
                              else
                              {
                               echo "N/A";
                              }
                              echo "<hr/>
                              <b><u>",htmlentities($cap['playername']),"'s stats:</u></b><br/><br/>";
                       $appst = array();
                       $q_ry = array();
                       $q_ry = "SELECT `my_labor`,`my_intelligence`,`my_endurance`
                                FROM `memberstats` WHERE `playerid` = '".mysql_real_escape_string($cap['app_PLAYER'])."'";
                       $appst = mysql_query($q_ry);
                       $mys = array();
                       $mys = mysql_fetch_array($appst);
                              echo "Manual labour: ".number_format($mys['my_labor'],4)."<br/>
                                    Intelligence: ".number_format($mys['my_intelligence'],4)."<br/>
                                    Endurance: ".number_format($mys['my_endurance'],4)."<br/>
                              </td></tr>
                                        <input type=hidden name=ID value={$_POST['ID']}>
                              <tr><td align=right width='50%'><input type=submit name=decline value=Decline></td>
                                  <td align=left width='50%'><input type=submit name=accept value=Accept></td></tr>
                              </table>".end_round()."</form>";
                      }
          }
                       else if($_POST['accept'])
                      {
                       $_POST['ID'] = abs(intval($_POST['ID']));
                       if(!$_POST['ID'])
                       {
   echo "<centerError, Invalid ID!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
 }
           $apps = array();
           $q_ry = array();
           $q_ry = "SELECT * 
                    FROM `applications` app
                    LEFT JOIN `members` m 
                    ON app.app_PLAYER = m.playerid
                    WHERE app.app_TYPE = 'company'
                    AND app.app_ID = '".mysql_real_escape_string($_POST['ID'])."'";
           $apps = mysql_query($q_ry);
                  if(!mysql_num_rows($apps))
                 {
                  echo "<center>Error, Invalid ID!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                 } 

  $my_members = array();
  $mm = array();
  $q_ry = array();
  $q_ry = "SELECT * 
           FROM `comp_members`
           WHERE `m_comp` = '".mysql_real_escape_string($ds['c_id'])."'";
  $my_members = mysql_query($q_ry);
  $mm = mysql_fetch_array($my_members);
    if((mysql_num_rows($my_members)+2) > id_capacity($ds['c_capacity']))
   {
   echo "<center>Sorry, you already have ".(mysql_num_rows($my_members)+1)."/".id_capacity($ds['c_capacity'])." members!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
   }




           $cap = array();
           $cap = mysql_fetch_array($apps);                  
   $my_job = array();
   $q_ry = array();
   $q_ry = "SELECT `playerid`
            FROM `members_extra` 
            WHERE `playerid` = '".mysql_real_escape_string($cap['playerid'])."'
            AND `my_job` > '0' ||
                  `playerid` = '".mysql_real_escape_string($cap['playerid'])."'
            AND `my_comp` > '0'";
   $my_job = mysql_query($q_ry);
   if(mysql_num_rows($my_job))
 {
   $q_ry = array();
   $q_ry = "DELETE FROM `applications` 
            WHERE `app_ID` = '".mysql_real_escape_string($_POST['ID'])."'";
   mysql_query($q_ry);
   echo "<center>Sorry, It seems this person has found another job!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
 }
  else
       {
   $q_ry = array();
   $q_ry = "INSERT INTO `comp_members` 
            VALUES ('NULL',
                    '".mysql_real_escape_string($cap['app_XID'])."',
                    '".mysql_real_escape_string($cap['app_PLAYER'])."',
                    '0','0','0')";
   mysql_query($q_ry);
   $q_ry = array();
   $q_ry = "UPDATE `members_extra` 
            SET `my_job` = '0',
                `my_comp` = '".mysql_real_escape_string($cap['app_XID'])."'
            WHERE `playerid` = '".mysql_real_escape_string($cap['app_PLAYER'])."'";
   mysql_query($q_ry);
   $mess = array();
   $mess = "".htmlentities($pl['playername'])." has accepted you into ".htmlentities($ds['c_name']).".";
   in_event($cap['app_PLAYER'], $mess);
   $q_ry = array();
   $q_ry = "DELETE FROM `applications` 
            WHERE `app_ID` = '".mysql_real_escape_string($_POST['ID'])."'";
   mysql_query($q_ry);
   echo "<center>Success, This person is now part of your company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
 }

                      }


                       else if($_POST['decline'])
                      {
                       $_POST['ID'] = abs(intval($_POST['ID']));
                       if(!$_POST['ID'])
                       {
   echo "<centerError, Invalid ID!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
 }
           $apps = array();
           $q_ry = array();
           $q_ry = "SELECT * 
                    FROM `applications` app
                    LEFT JOIN `members` m 
                    ON app.app_PLAYER = m.playerid
                    WHERE app.app_TYPE = 'company'
                    AND app.app_ID = '".mysql_real_escape_string($_POST['ID'])."'";
           $apps = mysql_query($q_ry);
           $cap = array();
           $cap = mysql_fetch_array($apps);  
                  if(!mysql_num_rows($apps))
                 {
                  echo "<center>Error, Invalid ID!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                 }                 
   $messg = array();
   $messg = "".htmlentities($pl['playername'])." has declined you from their company.";
   in_event($cap['app_PLAYER'], $messg);
   $q_ry = array();
   $q_ry = "DELETE FROM `applications` 
            WHERE `app_ID` = '".mysql_real_escape_string($_POST['ID'])."'";
   mysql_query($q_ry);
   echo "<center>Success, This person has been declined from your company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
     }
     else
        {
   echo "<center>Error, Invalid action!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
     }
} 
      $app = array();
      if($ds['c_APPS'] == 'off')
     {
               $app = "on";
             }
           else
             {
               $app = "off";
     }
     if($_GET['t'])
    {
       if($_GET['t'] == "off")
      {
   $q_ry = array();
   $q_ry = "UPDATE `members_companies` 
            SET `c_APPS` = 'off'
            WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
   mysql_query($q_ry);
        echo "<center><br/>Applications are now turned off.</center>";
        $app = "on";
      }
       else if($_GET['t'] == "on")
       {
   $q_ry = array();
   $q_ry = "UPDATE `members_companies` 
            SET `c_APPS` = 'on'
            WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
   mysql_query($q_ry);
        echo "<center><br/>Applications are now turned on.</center>";
        $app = "off";
       }
         else
              {
        echo "<center><br/>Error, invalid action for turning apps on/off.</center>";
              }
    }
      echo "<center><hr width='750px'/>
            ><a href='companies.php?action=applications&t={$app}'><b>Toggle application status to {$app}.</b></a>
            <hr width='750px'/></center>";
      echo "<center><hr width='750px'/>><a href='companies.php'>Back</a><hr width='750px'/></center>";

   }

    function comp_train()
   {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points` 
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $ic = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
   {
      echo "You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = array();
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = array();
        $type = mysql_query($q_ry);
        $t = array();
        $t = mysql_fetch_array($type);
   if($_SESSION['playerid'] != $ds['playerid'])
   {
      echo "Sorry but only ",htmlentities($ds['playername'])," can train people!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
   }
         $_GET['XID'] = abs(intval($_GET['XID']));
         if(!$_GET['XID'])
       {
         echo "<center>Error, Invalid ID!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
       }
         $thisemp = array();
         $q_ry = array();
         $q_ry = "SELECT *
                  FROM `comp_members`
                  WHERE `m_playerid` = '".mysql_real_escape_string($_GET['XID'])."'";
         $thisemp = mysql_query($q_ry);
         if(!mysql_num_rows($thisemp))
       {
         echo "<center>Error, Invalid ID!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
       }
         else
             {

             $q_ry = array();
             $q_ry = "SELECT `my_labor`,`my_intelligence`,`my_endurance`,`playername`
                      FROM `memberstats` ms 
                      LEFT JOIN `members`  m
                      ON ms.playerid = m.playerid
                      WHERE ms.playerid = '".mysql_real_escape_string($_GET['XID'])."'";
             $tats = array();
             $tats = mysql_query($q_ry);
             $s = array();
             $s = mysql_fetch_array($tats);

                  if($s['my_labor'] < $s['my_intelligence'] AND $s['my_labor'] < $s['my_endurance'])
                 {
                  $stat = array();
                  $stat = "my_labor";
                  $display = "Labour";
                 }
                  else if($s['my_intelligence'] < $s['my_labor'] AND $s['my_intelligence'] < $s['my_endurance'])
                 {
                  $stat = array();
                  $stat = "my_intelligence";
                  $display = "Intelligence";
                 }
                  else if($s['my_endurance'] < $s['my_labor'] AND $s['my_endurance'] < $s['my_intelligence'])
                 {
                  $stat = array();
                  $stat = "my_endurance";
                  $display = "Endurance";
                 }
                  else
                 {
                  $stat = array();
                  $stat = "my_labor";
                  $display = "Labour";
                 }


              $te = array();
              $te = mysql_fetch_array($thisemp);
             if(!$_POST['train'])
             {
              echo round_table('750')."You have chosen to train ",htmlentities($s['playername']),"
                        <br/>They will gain 25 $display per train,
                        You have <b>".number_format($ds['c_trains'])."</b> trains left to use.<br/>
                        You have <b>".money_alter($ds['c_wallet'])."</b> in your funds, 
                        It costs <b>\$10,000</b> each train you use.<br/>
                        <form action='companies.php?action=train&XID={$_GET['XID']}' method='post'>
                        <input type='submit' name='train' value='Train'></form>".end_round();
             }
             else
            {
             if($ds['c_wallet'] < 10000)
            {
         echo "<center>Error, it costs \$10,000 per train, you only have ".money_alter($ds['c_wallet'])."!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
            }
             else if($ds['c_trains'] < 1)
            {
         echo "<center>Error, You dont have enough trains left at this moment, Sorry.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
            }
             else if($te['m_days'] < 3)
            {
         echo "<center>Error, This person has not been in your company for 3 days or more, Please try someone that has.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
            }
            else 
                {
                $q_ry = array();
                $q_ry = "UPDATE `members_companies` 
                         SET `c_trains` = `c_trains` - '1',
                             `c_wallet` = `c_wallet` - '10000'
                         WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
                mysql_query($q_ry);
                $q_ry = array();
                $q_ry = "UPDATE `memberstats` 
                         SET {$stat} = {$stat} + '25'
                         WHERE `playerid` = '".mysql_real_escape_string($_GET['XID'])."'";
                mysql_query($q_ry);
                p_stats_add('trained', 1, $_GET['XID']);
                $mess = array();
                $mess = "".htmlentities($pl['playername'])." has trained you,
                         You gained <b>25</b> $display, You now have ".number_format(25+$s[$stat])." $display";
                in_event($_GET['XID'], $mess);
                echo "Train successfull, ",htmlentities($s['playername'])," now has ".number_format(25+$s[$stat])." 
                $display 
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
            }
            }
        }
        echo "<center><hr width='750px'/>><a href='companies.php'>Back</a><hr width='750px'/></center>";
    }
}


    function comp_fire()
   {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points` 
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $ic = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
   {
      echo "You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = array();
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = array();
        $type = mysql_query($q_ry);
        $t = array();
        $t = mysql_fetch_array($type);
   if($_SESSION['playerid'] != $ds['playerid'])
   {
      echo "Sorry but only ",htmlentities($ds['playername'])," can train people!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
   }
        $_GET['XID'] = abs(intval($_GET['XID']));
        if(!$_GET['XID'])
       {
         echo "<center>Error, Invalid ID!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
       } 
        else
            {
              $q_ry = array();
              $q_ry = "SELECT *
                       FROM `comp_members`
                       WHERE `m_playerid` = '".mysql_real_escape_string($_GET['XID'])."'";
              $chkm = array();
              $chkm = mysql_query($q_ry);
              if(!mysql_num_rows($chkm))
       {
         echo "<center>Error, Invalid ID!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
       } 
              else
                  {
                   $me = array();
                   $me = mysql_fetch_array($chkm);
                   $q_ry = array();
                   $q_ry = "SELECT `playername` 
                            FROM `members` 
                            WHERE `playerid` = '".mysql_real_escape_string($_GET['XID'])."'";
                   $name = array();
                   $name = mysql_query($q_ry);
                   $n = array();
                   $n = mysql_fetch_array($name);
                   if(!$_POST['submit'])
                  {
                   echo "<center>Are you sure you want to fire <b>",htmlentities($n['playername'])."</b>?<br/><br/>
                         <form action='companies.php?action=fire&XID={$_GET['XID']}' method='post'>
                         <input type='submit' name=submit value='Fire'>
                         </form></center>";
                  }
                   else
                        {
                   $q_ry = array();
                   $q_ry = "UPDATE `members_extra`
                            SET `my_comp` = '0',`my_comp_points` = '0',`my_job` = '0',`my_job_rank` = '0'
                            WHERE `playerid` = '".mysql_real_escape_string($_GET['XID'])."'";
                   mysql_query($q_ry);
                   $q_ry = array();
                   $q_ry = "DELETE FROM `comp_members`
                            WHERE `m_playerid` = '".mysql_real_escape_string($_GET['XID'])."'
                            AND `m_comp` = '".mysql_real_escape_string($ds['c_id'])."'";
                   mysql_query($q_ry);

                   $mess = array();
                   $mess = "".htmlentities($pl['playername'])." has fired you from the ".htmlentities($ds['c_name'])." company.";
                   in_event($_GET['XID'], $mess);
                   echo "<center>You fired ",htmlentities($n['playername']),"!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
       } 
                  }      
            }

           echo "<center><hr width='750px'>><a href='companies.php?action=manage'>Back</a><hr width='750px'></center>";
       }
     }

   function comp_news()
   {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points`,`my_drugadd`
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $ic = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
  {
   echo "<center>You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $details = array();
        $t = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $type = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = mysql_query($q_ry);
        $t = mysql_fetch_array($type);
        if($_SESSION['playerid'] != $ds['c_owner'])
        {
         echo "<center>Sorry, Only the director can send a newsletter.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
        }
       else
           {
           $q_ry = array();
           $q_ry = "SELECT *
                    FROM `comp_members`
                    WHERE `m_comp` = '".mysql_real_escape_string($ds['c_id'])."'";
           $membs = array();
           $membs = mysql_query($q_ry);
           if(!mysql_num_rows($membs))
                 {
         echo "<center>You have no employees to send a newsletter to.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
         }
         else
            {
            if(!$_POST['submit'])
            {
                 echo "<center>Here you can send a message to all your employees.<br/>
                       <form action='companies.php?action=newsletter' method='post'>
                       <textarea name='message' rows='10' cols='75'></textarea><br/>
                       <input type ='submit' name='submit' value='Send'>
                       <hr width='750px'/>><a href='companies.php'>Back</a><hr width='750px'/></center>";
                                 }
                                 else
                                    {
                           $_POST['message'] = htmlentities(stripslashes($_POST['message']));                             
                    if(!$_POST['message'])
                     {
                      echo "<center>Error, You must compose a message to send, It cannot be blank.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                      }
                      else
                          {
  $codes = array(':)',':P',':(',':o',':@','o_O',':s',';)',':*',':|o',':|',':D','xD',':L','xP');
  $images  = array(
  ' [img=images/smilies/smile.gif] ',
  ' [img=images/smilies/tounge.gif] ',
  ' [img=images/smilies/sad.gif] ',
  ' [img=images/smilies/shocked.gif] ',
  ' [img=images/smilies/angry.gif] ',
  ' [img=images/smilies/sarcy.gif] ',
  ' [img=images/smilies/confused.gif] ',
  ' [img=images/smilies/wink.gif] ',
  ' [img=images/smilies/cool.gif] ',
  ' [img=images/smilies/psyc.gif] ',
  ' [img=images/smilies/dissapointed.gif] ',
  ' [img=images/smilies/grin.gif] ',
  ' [img=images/smilies/histericle.gif] ',
  ' [img=images/smilies/laughing.gif] ',
  ' [img=images/smilies/histericletounge.gif] ');
  $_POST['message'] = str_replace($codes, $images, $_POST['message']);

           $q_ry = array();
           $q_ry = "SELECT *
                    FROM `comp_members`
                    WHERE `m_comp` = '".mysql_real_escape_string($ds['c_id'])."'";
           $membs = array();
           $membs = mysql_query($q_ry);
           $am = array();
           while($am = mysql_fetch_array($membs))
                         {
                           $q_ry = array();
                           $q_ry = "INSERT INTO `member_mail`
                                    VALUES ('NULL',
                                            '".mysql_real_escape_string($am['m_playerid'])."',
                                            '".mysql_real_escape_string($_SESSION['playerid'])."',
                                            'Company newsletter',
                                            '".mysql_real_escape_string($_POST['message'])."',
                                            unix_timestamp(),
                                            '0')";
                           mysql_query($q_ry);
                         }
                      p_stats_add('mail', 1, $_SESSION['playerid']);
                      p_stats_add('mail_comp', 1, $_SESSION['playerid']);
                      echo "<center>Success, Message sent to all employees.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                     }
                     }      
                     }
                     }
                     }
                     }


  function comp_fund()
 {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points`,`my_drugadd`
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $is = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
  {
   echo "<center>You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $details = array();
        $t = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $type = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = mysql_query($q_ry);
        $t = mysql_fetch_array($type);

     $my_rank = array();
     $mr = array();
     $q_ry = array();
     $q_ry = "SELECT *
              FROM `comp_members` cm
              LEFT JOIN `system_c_ranks` sr 
              ON cm.m_rank = sr.cr_ID
              WHERE cm.m_playerid = '".mysql_real_escape_string($_SESSION['playerid'])."'";
     $my_rank = mysql_query($q_ry);
     $mr = mysql_fetch_array($my_rank);
     if($_SESSION['playerid'] != $ds['c_owner'])
    {
     echo "<center>Sorry, Only the company director can change the company funds!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
    }
           if(!$_POST['add'] AND !$_POST['take'])
          {
           echo "<form action='companies.php?action=funds' method='post'>
                 ".round_table('750')."<table width='100%'><tr><td align='center' width='50%'>
                 You currently have <b>".money_alter($pl['wallet'])."</b> available to add.<br/>

           <input type = 'text' name = 'add' value = '{$pl['wallet']}'><br/>
           <input type = 'submit' name='deposite' value = 'Add money'>

           </td>


           <td align='center' width='50%'>
           You currently have <b>".money_alter($ds['c_wallet'])."</b> in the company funds<br/>

           <input type = 'text' name = 'take' value = '{$ds['c_wallet']}'><br/>
           <input type = 'submit' name='remove' value = 'Remove money'>

           </td>


           </tr></table>".end_round()."</center>";
          }
            else
                 {


                  if($_POST['deposite'] AND $_POST['remove'])
                                    {
                                        echo "<center>Error, You can only do one thing at a time!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                      }
                  else if($_POST['deposite'])
                                    {
                                      $_POST['add'] = abs(intval($_POST['add']));
                                      if($pl['wallet'] < $_POST['add'])
                                      {
                                        echo "<center>Error, You dont have that much money!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                      }
                                      else if(!$_POST['add'])
                                      {
                                        echo "<center>Error, You did not select an ammount!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                      }
                                       else
                                      {
                                       $q_ry = array();
                                       $q_ry = "UPDATE `members` 
                                                SET `wallet`=`wallet`-'".mysql_real_escape_string($_POST['add'])."'
                                                WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
                                       mysql_query($q_ry);
                                       $q_ry = array();
                                       $q_ry = "UPDATE `members_companies` 
                                                SET `c_wallet`=`c_wallet`+'".mysql_real_escape_string($_POST['add'])."'
                                                WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
                                       mysql_query($q_ry);
                               echo "<center>You have added <b>".money_alter($_POST['add'])."</b> to your company funds!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                      }
                                    }
                  else if($_POST['remove'])
                                           {
                                      $_POST['take'] = abs(intval($_POST['take']));
                                      if($ds['c_wallet'] < $_POST['take'])
                                      {
                                        echo "<center>Error, You dont have that much money in your funds!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                      }
                                      else if(!$_POST['take'])
                                      {
                                        echo "<center>Error, You did not select an ammount!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                      }
                                       else
                                      {
                                       $q_ry = array();
                                       $q_ry = "UPDATE `members` 
                                                SET `wallet`=`wallet`+'".mysql_real_escape_string($_POST['take'])."'
                                                WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
                                       mysql_query($q_ry);
                                       $q_ry = array();
                                       $q_ry = "UPDATE `members_companies` 
                                                SET `c_wallet`=`c_wallet`-'".mysql_real_escape_string($_POST['take'])."'
                                                WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
                                       mysql_query($q_ry);
                              echo "<center>You have taken <b>".money_alter($_POST['take'])."</b> from your company funds!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                      }
                                           }
                                                                          else
                                  {
                                    echo "<center>Error, You did not select a valid action!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                                      }
          }
     }
      echo "<center><hr width='750px'/>><a href='companies.php'>Back</a><hr width='750px'/></center>";
   }


  function comp_leader()
 {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points`,`my_drugadd`
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $is = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
  {
   echo "<center>You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $details = array();
        $t = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $type = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = mysql_query($q_ry);
        $t = mysql_fetch_array($type);

     $my_rank = array();
     $mr = array();
     $q_ry = array();
     $q_ry = "SELECT *
              FROM `comp_members` cm
              LEFT JOIN `system_c_ranks` sr 
              ON cm.m_rank = sr.cr_ID
              WHERE cm.m_playerid = '".mysql_real_escape_string($_SESSION['playerid'])."'";
     $my_rank = mysql_query($q_ry);
     $mr = mysql_fetch_array($my_rank);

     if($_SESSION['playerid'] != $ds['c_owner'])
    {
     echo "<center>Sorry, Only the company director can change the director!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
    }

       if(!$_POST['sure'] AND !$_POST['submit'])
      {
          echo"<b>Please enter the userid of the player you wish to transfer leadership of your company to.</b><br/>
               <form action='companies.php?action=director' method='post'>
               <input type='text' name='user' value='0'><br/>
               <input type='submit' name='submit' value='Change director'>
               </form>";
      }
        else if($_POST['submit'] AND !$_POST['sure'])
             {
               $_POST['user'] = abs(intval($_POST['user']));
               if(!$_POST['user'])
               {
                echo "<center>Error, Invalid user!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
               }
               $q_ry = array();
               $q_ry = "SELECT *
                        FROM `members` m
                        LEFT JOIN `comp_members` cm
                        ON m.playerid = cm.m_playerid
                        WHERE m.playerid = '".mysql_real_escape_string($_POST['user'])."'
                        AND cm.m_comp = '".mysql_real_escape_string($ds['c_id'])."'
                        AND m.my_level >= '10'";
               $us = mysql_query($q_ry);
               $u = array();
               $u = mysql_fetch_array($us);
               if(!mysql_num_rows($us))
              {
                echo "<center>Error, Either this user does not exist,
                They are not part of your company or they are not level 10 or above yet!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
               }
               echo"<b><font color=red>Are you sure you wish to transfer leadership to ",htmlentities($u['playername']),"?<br/>
                  Once you have done this there is NO going back.</font></b><br/>
               <form action='companies.php?action=director' method='post'>
               <input type='hidden' name='user' value='{$_POST['user']}'>
               <input type='submit' name='sure' value='Change director'>
               </form>";
             } 
              else if($_POST['sure'])
                  {
               $q_ry = array();
               $q_ry = "SELECT *
                        FROM `members` m
                        LEFT JOIN `comp_members` cm
                        ON m.playerid = cm.m_playerid
                        WHERE m.playerid = '".mysql_real_escape_string($_POST['user'])."'
                        AND cm.m_comp = '".mysql_real_escape_string($ds['c_id'])."'
                        AND m.my_level >= '10'";
               $us = mysql_query($q_ry);
               $u = array();
               $u = mysql_fetch_array($us);
               if(!mysql_num_rows($us))
              {
                echo "<center>Error, Either this user does not exist,
                They are not part of your company or they are not level 10 or above yet!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
               }
                else
                    {
                        $q_ry = array();
                        $q_ry = "DELETE FROM `comp_members`
                                 WHERE `m_playerid` = '".mysql_real_escape_string($_POST['user'])."'";
                        mysql_query($q_ry);
                        $q_ry = array();
                        $q_ry = "INSERT INTO `comp_members` 
                                 VALUES ('NULL',
                                         '".mysql_real_escape_string($ds['c_id'])."',
                                         '".mysql_real_escape_string($ds['c_owner'])."',
                                         '0','0','0')";
                        mysql_query($q_ry);
                        $q_ry = array();
                        $q_ry = "UPDATE `members_companies`
                                 SET `c_owner` = '".mysql_real_escape_string($_POST['user'])."'
                                 WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'"; 
                        mysql_query($q_ry);
                        $mess = array();
                        $mess = "".htmlentities($pl['playername'])." has 
                                 transfered the ownership of the <b>".htmlentities($ds['c_name'])."</b> company to you.";
                        in_event($_POST['user'], $mess);
                        echo "<center>Ownership has been transfered successfully.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
               }
                  } 
                   else
                  {
                        echo "<center>Error, please try again.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
               } 
             echo "<hr width='750px'/>><a href='companies.php'>Back</a><hr width='750px'/></center>";
     }
   }

  function comp_name()
 {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points`,`my_drugadd`
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $is = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
  {
   echo "<center>You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $details = array();
        $t = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $type = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = mysql_query($q_ry);
        $t = mysql_fetch_array($type);

     $my_rank = array();
     $mr = array();
     $q_ry = array();
     $q_ry = "SELECT *
              FROM `comp_members` cm
              LEFT JOIN `system_c_ranks` sr 
              ON cm.m_rank = sr.cr_ID
              WHERE cm.m_playerid = '".mysql_real_escape_string($_SESSION['playerid'])."'";
     $my_rank = mysql_query($q_ry);
     $mr = mysql_fetch_array($my_rank);
     if($_SESSION['playerid'] != $ds['c_owner'])
    {
     echo "<center>Sorry, Only the company director can change the company name!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
    }
           if(!$_POST['new'])
          {
           echo "Your current name is <b>",htmlentities($ds['c_name']),"</b><br/>
           <form action='companies.php?action=changename' method='post'>
           <input type = 'text' length = '50' maxlength = '50' name = 'new'><br/>
           <input type = 'submit' name='submit' value = 'Change name'></center>";
          }
            else
                 {
              $_POST['new'] = trim($_POST['new']);

              if(strlen($_POST['new']) < 3)
             {
               echo "<center>Error, ".strlen($_POST['new'])." characters is not enough,
                     minimum is 3 characters!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
             }      
              else if(strlen($_POST['new']) > 50)
             {
               echo "<center>Error, ".strlen($_POST['new'])." characters exeeds the max of 50 characters!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
             }      
              else if(!preg_match('/[a-z A-Z 0-9]+$/', $_POST['new']))
             {
              echo "<center>Sorry, invalid characters detected!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
             }   
              else 
                   {
                      $_POST['new'] = preg_replace('/[^a-zA-Z0-9_-\s ]/', '', $_POST['new']);


                     $q_ry = array();
                     $alred = array();
                     $q_ry = "SELECT `c_id`
                              FROM `members_companies`
                              WHERE `c_name` = '".mysql_real_escape_string($_POST['new'])."'";
                     $alred = mysql_query($q_ry);

                     if(mysql_num_rows($alred))
                    {
                      echo "<center>Name could not be changed to <b>",htmlentities($_POST['new']),"</b>!<br/>
                            A company already has this name.<br/>
                            ><a href='companies.php'>Okay</a></center>";
                      include('./includes/style_bottom.php');
                      exit();
                }
                     else
                         {

                      $q_ry = array();
                      $q_ry = "UPDATE `members_companies`
                               SET `c_name` = '".mysql_real_escape_string($_POST['new'])."'
                               WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
                      mysql_query($q_ry);
                      echo "<center>Name changed to <b>",htmlentities($_POST['new']),"</b>!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
                }
             }   
          }
     }
      echo "<center><hr width='750px'/>><a href='companies.php'>Back</a><hr width='750px'/></center>";
   }



  function comp_img()
 {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points`,`my_drugadd`
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $is = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
  {
   echo "<center>You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $details = array();
        $t = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $type = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = mysql_query($q_ry);
        $t = mysql_fetch_array($type);

     $my_rank = array();
     $mr = array();
     $q_ry = array();
     $q_ry = "SELECT *
              FROM `comp_members` cm
              LEFT JOIN `system_c_ranks` sr 
              ON cm.m_rank = sr.cr_ID
              WHERE cm.m_playerid = '".mysql_real_escape_string($_SESSION['playerid'])."'";
     $my_rank = mysql_query($q_ry);
     $mr = mysql_fetch_array($my_rank);
     if($_SESSION['playerid'] != $ds['c_owner'])
    {
     echo "<center>Sorry, Only the company director can change the company image!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
    }
           if(!$_POST['new'])
          {
           echo "<form action='companies.php?action=banner' method='post'>
                 Your current banner.<br/>";

                 if($ds['c_banner']!='')
                {
                   if(!@getimagesize($ds['c_banner']))
                  {
                   echo "<center>Image loading error!</center>";
                  }
                   else if(getimagesize($ds['c_banner']))
                  {
                   echo "<center><img src='{$ds['c_banner']}' border='1' width='400px' height='100px'></center>";
                  }
                  } else
                         {
                            echo "<center><img src='images/default.jpg' border='1'></center>";
                  }
           echo "<br/>Due to a small server, 
           We can only allow people to add images that are externally hosted at this time,
           <br/> We hope to have this changed in the very near future.<br/><br/>
           To add an image please enter the image location in the box below.
           <br/><input type = 'text' name = 'new' value = ''><br/>
           <input type = 'submit' name='submit' value = 'Change banner'>
           </center>";
          }
            else
                 {
                    $_POST['new'] = trim($_POST['new']);
                    if($_POST['new'] == '')
                   {
                    echo "<center>Error, banner has to contain a url!</center>";
                   }
                    else
                   {
                   if(!@getimagesize($_POST['new']))
                  {
                   echo "<center>Image loading error!</center>";
                  }
                   else if(getimagesize($_POST['new']))
                  {
                         $q_ry = array();
                         $q_ry = "UPDATE `members_companies`
                                  SET `c_banner` = '".mysql_real_escape_string($_POST['new'])."'
                                  WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."'";
                         mysql_query($q_ry);
                   echo "<center>Image changed to:<br/>
                         <img src='{$_POST['new']}' border='1' width='400px' height='100px'></center>";
                  }
                   else
                       {
                           echo "Sorry, there was a internal request failure, Please try again.";
                  }
                 }
      }
     }
      echo "<center><hr width='750px'/>><a href='companies.php'>Back</a><hr width='750px'/></center>";
   }


function comp_erase()
   {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points`,`my_drugadd`
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $is = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
  {
   echo "<center>You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $details = array();
        $t = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $type = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = mysql_query($q_ry);
        $t = mysql_fetch_array($type);
        if($_SESSION['playerid'] != $ds['c_owner'])
        {
         echo "<center>Sorry, Only the director can erase the company.
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
        }
       else
           {
             if(!$_GET['step'])
             {
              echo "<center><font color='red'><b>Warning: If you delete this company there will be no going back!<br/>
                    If there is any money in the funds you will lose it unless you withdraw it before hand.<br/>
                    Any members will be made Uneployed.<br/>
                    You will also lose all your job points.<br/></b>
                    </font><br/>Are you sure you want to erase this company?<br/><br/>
                    ><a href='companies.php?action=erase&step=erase'>Yes i read the warning im sure</a></center>";
             }
              else
                  {
                   $q_ry = array();
                   $q_ry = "SELECT `m_playerid`
                            FROM `comp_members`
		     WHERE `m_comp` = '".mysql_real_escape_string($ds['c_id'])."'";
                   $mymems = array();
                   $mymems = mysql_query($q_ry);
                   $mess = array();
                   $mess = "Your company director decided to erase the company you where in, You are now Uneployed.";
                   while($mm = mysql_fetch_array($mymems))
                  {
                    in_event($mm['m_playerid'], $mess);
                  }
                   $q_ry = array();
                   $q_ry = "UPDATE `members_extra`
                            SET `my_job` = '0',`my_job_rank` = '0',`my_comp` = '0',`my_comp_points` = '0'
                            WHERE `my_comp` = '".mysql_real_escape_string($ds['c_id'])."' ";
                   mysql_query($q_ry);
                   $q_ry = array();
                   $q_ry = "DELETE FROM `comp_members`
                            WHERE `m_comp` = '".mysql_real_escape_string($ds['c_id'])."' ";
                   mysql_query($q_ry);
                   $q_ry = array();
                   $q_ry = "DELETE FROM `company_shippments`
                            WHERE `s_COMP` = '".mysql_real_escape_string($ds['c_id'])."' ";
                   mysql_query($q_ry);
                   $q_ry = array();
                   $q_ry = "DELETE FROM `members_companies`
                            WHERE `c_id` = '".mysql_real_escape_string($ds['c_id'])."' ";
                   mysql_query($q_ry);
                   echo "<center>You erased the company!<br/>
                   ><a href='job.php'>Back</a></center>";
                   include('./includes/style_bottom.php');
                   exit();
                } 
             echo "<center><hr width='750px'/>><a href='companies.php'>Back</a><hr width='750px'/></center>";
           }
       }
   }

    function comp_leave()
   {
   global $pl;
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points`,`my_drugadd`
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $is = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
  {
   echo "<center>You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $details = array();
        $t = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $type = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = mysql_query($q_ry);
        $t = mysql_fetch_array($type);
        if($_SESSION['playerid'] == $ds['c_owner'])
       {
        header('location:companies.php?action=erase');
       }
       else
           {
             if(!$_GET['step'])
             {
              echo "<center><font color='red'><b>Warning: If you leave this company there will be no going back!<br/>
                    You will also lose all your job points.<br/></b>
                    </font><br/>Are you sure you want to leave this company?<br/><br/>
                    ><a href='companies.php?action=quit&step=leave'>Yes</a></center>";
             }
              else
                  {
                   $q_ry = array();
                   $q_ry = "UPDATE `members_extra`
                            SET `my_comp` = '0',`my_comp_points` = '0',`my_job` = '0',`my_job_rank` = '0'
                            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
                   mysql_query($q_ry);
                   $q_ry = array();
                   $q_ry = "DELETE FROM `comp_members`
                            WHERE `m_playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'
                            AND `m_comp` = '".mysql_real_escape_string($ds['c_id'])."'";
                   mysql_query($q_ry);
                   $mess = array();
                   $mess = "".htmlentities($pl['playername'])." has decided to quit the company.";
                   in_event($ds['c_owner'], $mess);
                   echo "<center>You left the company!<br/>
                   ><a href='job.php'>Back</a></center>";
                   include('./includes/style_bottom.php');
                   exit();
                } 
             echo "<center><hr width='750px'/>><a href='companies.php'>Back</a><hr width='750px'/></center>";
             }
         }
     }


  function comp_view()
 {
   global $pl;
            $_GET['XID'] = abs(intval($_GET['XID']));
        if(!$_GET['XID'])
       {
        echo "<center>Error, Invalid ID!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
       }
        else
            {
        $details = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($_GET['XID'])."'";
        $details = mysql_query($q_ry);
        if(!mysql_num_rows($details))
       {
        echo "<center>Error, Invalid ID!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
       }
       else
          {
        $ds = array();
        $ds = mysql_fetch_array($details);
        $type = array();
        $t = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = mysql_query($q_ry);
        $t = mysql_fetch_array($type);
        echo "".round_table('430')."<table width=100% border=0><tr valign=top bgcolor=#999999><td colspan=3>
<center>

<b><center>Details of ",htmlentities($ds['c_name'])," - ",htmlentities($t['c_NAME']),"</b><br></td></tr><tr><td colspan=3>";

                   if(!@getimagesize($ds['c_banner']))
                  {
                   echo "<center><img src='images/default.jpg' border='1' width='400px' height='100px'></center>";
                  }
                   else if(getimagesize($ds['c_banner']))
                  {
                   echo "<center><img src='{$ds['c_banner']}' border='1' width='400px' height='100px'></center>";
                  }


echo "</td></tr><tr><td bgcolor=#999999 colspan=3 align=center><img src=images/{$ds['c_star']}_star.png></td></tr>


<tr bgcolor=#DFDFDF><td width=100% colspan=3>

<center><table><tr><td><br>
<b>Type:</b> ",htmlentities($t['c_NAME']),"<br>
<b>Director:</b> <a href='profile.php?XID={$ds['playerid']}'>{$ds['playername']}</a><br>
<b>Days old:</b> {$ds['c_days']}<br><br>
<b>Daily profit:</b> ".money_alter($ds['c_tprofit'])."<br>
<b>Yesterdays profit:</b> ".money_alter($ds['c_yprofit'])."<br>
<b>Todays customers:</b> ".number_format($ds['c_tcust'])."<br>
<b>Yesterdays customers:</b> ".number_format($ds['c_ycust'])."<br><br>
</td></tr>
</table>


</td></tr>

<tr bgcolor=#999999><td colspan=3>

<b><center>",htmlentities($ds['c_name'])," employees</b>
</td></tr>

<tr bgcolor=#CCCCCC><td width=1%>";
         if($ds['laston'] >= time()-15*60) 
        { 
         echo "<img src='images/online.png' title='Online'/> "; 
        } 
         else 
             { 
              echo "<img src='images/offline.png' title='Offline'/> "; 
        } 
echo "</td>
<td width=49% align=left><a href='profile.php?XID={$ds['playerid']}'>",htmlentities($ds['playername']),"</a></td>
<td width=50% align=left><b>Rank:</b> Director ($0)</td>
</tr>";
                             $num = array();
                             $num = 0;
                             $emps = array();
                             $q_ry = array();
                             $q_ry = "SELECT `playername`,`laston`,`m_playerid`,`m_rank`,`m_gains`,`cr_NAME`
                                      FROM `members` m
                                      LEFT JOIN `comp_members` cm ON
                                      m.playerid = cm.m_playerid
                                      LEFT JOIN `system_c_ranks` scr ON
                                      cm.m_rank = scr.cr_ID
                                      WHERE cm.m_comp = '".mysql_real_escape_string($ds['c_id'])."'";
                             $emps = mysql_query($q_ry);
                             $emp = array();
                             while($emp = mysql_fetch_array($emps))
                            {
                                              $num++;
                                              $odd="#cccccc";
                                              $even="#e3e3e3";
                                         if ($num % 2) {
                                         $color="$even";
                                         } else {
                                         $color="$odd"; 
                                                      }
echo "<tr bgcolor=$color><td width=1%>";

         if($emp['laston'] >= time()-15*60) 
        { 
         echo "<img src='images/online.png' title='Online'/> "; 
        } 
         else 
             { 
              echo "<img src='images/offline.png' title='Offline'/> "; 
        } 
         echo "</td>
               <td width=49% align=left>
               <a href='profile.php?XID={$emp['m_playerid']}'>",htmlentities($emp['playername']),"</a></td>
               <td width=50% align=left><b>Rank:</b>";
               if(!$emp['m_rank'])
              {
                     echo " Unassigned";
              }
               else
                   {
               echo " ",htmlentities($emp['cr_NAME']),"";
                   }
                     echo "(".money_alter($emp['m_gains']).")</td></tr>";
        }
        echo "<tr bgcolor=#999999><td colspan=3> </td></tr></table>".end_round()."
              <br><hr width=750px>
        ><a href=appform.php?action=company&XID={$_GET['XID']}>Apply to this company</a>
        <br><hr width=750px>><a href='startcomp.php?XID={$t['c_ID']}'>Back</a><br><hr width=750px>";
                    }
            }
   }




function id_storage($id)
{
  $storage = array(0=>10000,1=>20000,2=>50000,3=>200000,4=>500000,5=>2000000,6=>10000000);
  return $storage[$id];
}
function id_capacity($id)
{
  $storage = array(0=>4,1=>6,2=>8,3=>10,4=>12,5=>14,6=>16,7=>18,8=>20,9=>22,10=>24,11=>26,12=>28,13=>30);
  return $storage[$id];
}
include ('./includes/style_bottom.php');
?>

Link to comment
Share on other sites

also here is my company specials script i keep getting a t else error could anyone help me here the scripti checked it but i couldnt find error if you can help me please mail me as i will let you check my script only people i can trust

 


<?php  
  /*------------includes--------------*/
  include ('./includes/connections.php');
  include ('./includes/brain_file.php');
  include ('./includes/style_top.php');
  /*------------includes--------------*/
   echo "<center><main>Company specials</main><hr width = '750px'>";
   $q_ry = array();
   $q_ry = "SELECT `my_comp`,`my_comp_points`
            FROM `members_extra`
            WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
   $incomp = array();
   $incomp = mysql_query($q_ry);
   $ic = array();
   $ic = mysql_fetch_array($incomp);
   if(!$ic['my_comp'])
  {
   echo "<center>You are not part of a company!
            <hr width='750px'/>
            ><a href='javascript:history.back()'>Okay</a>
            <hr width='750px'/>";
      include ('./includes/style_bottom.php');
      exit();
  }
   else
       {
        $details = array();
        $t = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `members_companies` mc
                 LEFT JOIN `members` m ON
                 mc.c_owner = m.playerid
                 WHERE mc.c_id = '".mysql_real_escape_string($ic['my_comp'])."'";
        $details = mysql_query($q_ry);
        $ds = array();
        $ds = mysql_fetch_array($details);
        $type = array();
        $q_ry = array();
        $q_ry = "SELECT *
                 FROM `system_companies`
                 WHERE `c_ID` = '".mysql_real_escape_string($ds['c_TYPE'])."'";
        $type = mysql_query($q_ry);
        $t = mysql_fetch_array($type);

     $my_rank = array();
     $mr = array();
     $q_ry = array();
     $q_ry = "SELECT *
              FROM `comp_members` cm
              LEFT JOIN `system_c_ranks` sr 
              ON cm.m_rank = sr.cr_ID
              WHERE cm.m_playerid = '".mysql_real_escape_string($_SESSION['playerid'])."'";
     $my_rank = mysql_query($q_ry);
     $mr = mysql_fetch_array($my_rank);

           if(!$_GET['step'])
          {
     echo "<table width=750px border=0><tr>
           <td align = 'left'><br>
           You have <b>".number_format($ic['my_comp_points'])."</b> company points.<br>
           You gain (1 x company rating) company points every day.<br>
           These points will be lost if you leave the company or you are kicked.<br><br>";
           if($t['c_ID'] == '1')
          {
            if($ds['c_star'] >= '1')
           {
           echo "•<a href=companyspecials.php?step=specialuse&XID=1>Protein boost</a> (10 Strength per 10 job points)<br/>";
           }
           if($ds['c_star'] >= '3')
           {
           echo "•<a href=companyspecials.php?step=specialuse&XID=2>Meat cleaver</a> (Meat cleaver item per 25 job points)<br/>";
           }
           if($ds['c_star'] >= '5')
           {
           echo "•<a href=companyspecials.php?step=specialuse&XID=3>Dual machete</a> (Dual machete item per 1000 job points)<br/>";
           }
           echo "<br></td>
           </tr></table><hr width='750px'>><a href='javascript:history.back()'>Back</a><hr width='750px'></center>";
          }
           if($t['c_ID'] == '2')
          {
            if($ds['c_star'] >= '1')
           {
           echo "•<a href=companyspecials.php?step=specialuse&XID=1>Can of energie</a> (Can of energie per 10 job points)<br/>";
           }
           if($ds['c_star'] >= '3')
           {
           echo "•<a href=companyspecials.php?step=specialuse&XID=2>Meat cleaver</a> (Meat cleaver item per 25 job points)<br/>";
           }
           if($ds['c_star'] >= '5')
           {
           echo "•<a href=companyspecials.php?step=specialuse&XID=3>Dual machete</a> (Dual machete item per 1000 job points)<br/>";
           }
           echo "<br></td>
           </tr></table><hr width='750px'>><a href='javascript:history.back()'>Back</a><hr width='750px'></center>";
          }
        }
           if($t['c_ID'] == '3')
          {
            if($ds['c_star'] >= '1')
           {
           echo "•<a href=companyspecials.php?step=specialuse&XID=1>Pyromaniac</a> (5 Happy per 2 job points)<br/>";
           }
           if($ds['c_star'] >= '3')
           {
           echo "•<a href=companyspecials.php?step=specialuse&XID=2>Illumination</a> (Increases Awareness per 25 job points)<br/>";
           }
           if($ds['c_star'] >= '5')
           {
           echo "•<a href=companyspecials.php?step=specialuse&XID=3>Gas Guzzler</a> (Trade 500 job points for a gas can)<br/>";
           }
           echo "<br></td>
           </tr></table><hr width='750px'>><a href='javascript:history.back()'>Back</a><hr width='750px'></center>";
          }
      }
                 else
                    {
           if(in_array($_GET['XID'], array(1)) && $t['c_ID'] == '1')
           {
              if($_GET['XID'] == '1' && $ds['c_star'] >= '1')
              {
                 if(!$_GET['next'])
                 {
                    echo "Are you sure you wish to swap 10 points for 10 strength?
                          <hr width='750px'>
                          <table width = '750px'>
                          <tr>
                          <td align = 'center' width = '50%'>
                          ><a href='companyspecials.php?step=specialuse&XID=".$_GET['XID']."&next=1'>Yes</a>
                          </td>
                          <td align = 'center' width = '50%'>
                          ><a href='companyspecials.php'>No</a>
                          </td>
                          </tr>
                          </table>
                          <hr width='750px'>";
                 }
                 else
                    {
                          if($ic['my_comp_points'] < '10')
                          {
                              echo "<center>You dont have enough points for this special!
                                    <hr width='750px'/>
                                    ><a href='javascript:history.back(2)'>Okay</a>
                                    <hr width='750px'/>";
                                    include ('./includes/style_bottom.php');
                                    exit();
                          }
                          else
                             {
                                    $q_ry = array();
                                    $q_ry = "UPDATE `memberstats`
                                             SET `my_strength` = `my_strength` + '10'
                                             WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
                                    mysql_query($q_ry);
                                    $q_ry = array();
                                    $q_ry = "UPDATE `members_extra`
                                             SET `my_comp_points` = `my_comp_points` - '10'
                                             WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
                                    mysql_query($q_ry);
                              echo "<center>You swapped 10 points for 10 strength!
                                    <hr width='750px'/>
                                    ><a href='javascript:history.back(2)'>Okay</a>
                                    <hr width='750px'/>";
                                    include ('./includes/style_bottom.php');
                                    exit();
                             }
                    }
              }
           }
           else if(in_array($_GET['XID'], array(1)) && $t['c_ID'] == '2')
           {
              if($_GET['XID'] == '1' && $ds['c_star'] >= '1')
              {
                 if(!$_GET['next'])
                 {
                    echo "Are you sure you wish to swap 10 points for a can of energie?
                          <hr width='750px'>
                          <table width = '750px'>
                          <tr>
                          <td align = 'center' width = '50%'>
                          ><a href='companyspecials.php?step=specialuse&XID=".$_GET['XID']."&next=1'>Yes</a>
                          </td>
                          <td align = 'center' width = '50%'>
                          ><a href='companyspecials.php'>No</a>
                          </td>
                          </tr>
                          </table>
                          <hr width='750px'>";
                 }
                 else
                    {
                          if($ic['my_comp_points'] < '10')
                          {
                              echo "<center>You dont have enough points for this special!
                                    <hr width='750px'/>
                                    ><a href='javascript:history.back(2)'>Okay</a>
                                    <hr width='750px'/>";
                                    include ('./includes/style_bottom.php');
                                    exit();
                          }
                          else
                             {
                              i_credit($_SESSION['playerid'], 112, 1);
                                    $q_ry = "UPDATE `members_extra`
                                             SET `my_comp_points` = `my_comp_points` - '10'
                                             WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
                                    mysql_query($q_ry);
                              echo "<center>You swapped 10 points for a can of energie!
                                    <hr width='750px'/>
                                    ><a href='javascript:history.back(2)'>Okay</a>
                                    <hr width='750px'/>";
                                    include ('./includes/style_bottom.php');
                                    exit();
                             }
                    }
              }
           }
           else if(in_array($_GET['XID'], array(1)) && $t['c_ID'] == '3')
           {
              if($_GET['XID'] == '1' && $ds['c_star'] >= '1')
              {
                 if(!$_GET['next'])
                 {
                    echo "Are you sure you wish to swap 2 points for 5 happy?
                          <hr width='750px'>
                          <table width = '750px'>
                          <tr>
                          <td align = 'center' width = '50%'>
                          ><a href='companyspecials.php?step=specialuse&XID=".$_GET['XID']."&next=1'>Yes</a>
                          </td>
                          <td align = 'center' width = '50%'>
                          ><a href='companyspecials.php'>No</a>
                          </td>
                          </tr>
                          </table>
                          <hr width='750px'>";
                 }
                 else
                    {
                          if($ic['my_comp_points'] < '2')
                          {
                              echo "<center>You dont have enough points for this special!
                                    <hr width='750px'/>
                                    ><a href='javascript:history.back(2)'>Okay</a>
                                    <hr width='750px'/>";
                                    include ('./includes/style_bottom.php');
                                    exit();
                          }
                          else
                             {
                                    $q_ry = "UPDATE `members_extra`
                                             SET `my_comp_points` = `my_comp_points` - '2'
                                             WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
                                    mysql_query($q_ry);
                                    $q_ry = "UPDATE `members`
                                             SET `my_happy` = `my_happy` + '5'
                                             WHERE `playerid` = '".mysql_real_escape_string($_SESSION['playerid'])."'";
                                    mysql_query($q_ry);
                              echo "<center>You swapped 2 points for 2 happy!
                                    <hr width='750px'/>
                                    ><a href='javascript:history.back(2)'>Okay</a>
                                    <hr width='750px'/>";
                                    include ('./includes/style_bottom.php');
                                    exit();
                             }
                    }
              }
           }
           else
              {
                              echo "<center>Error, Invalid special!
                                    <hr width='750px'/>
                                    ><a href='javascript:history.back()'>Okay</a>
                                    <hr width='750px'/>";
                                    include ('./includes/style_bottom.php');
                                    exit();
              }
           }
     }
   include ('./includes/style_bottom.php');
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...