Example #1
0
function IGB_consolidate3()
{
  global $playerinfo;
  global $db, $dbtables;
  global $dplanet_id, $minimum, $maximum, $IGB_tconsolidate, $ibank_paymentfee;
  global $l_igb_notenturns, $l_igb_back, $l_igb_logout, $l_igb_transfersuccessful;
  global $l_igb_currentpl, $l_igb_in, $l_igb_turncost, $l_igb_unnamed;

  $res = $db->Execute("SELECT name, credits, owner, sector_id FROM $dbtables[planets] WHERE planet_id=$dplanet_id");
  if(!$res || $res->EOF)
      IGB_error($l_igb_errunknownplanet, "IGB.php?kk=".date("U")."&command=transfer");
  $dest = $res->fields;

  if(empty($dest[name]))
    $dest[name]=$l_igb_unnamed;

  if($dest[owner] != $playerinfo[player_id])
    IGB_error($l_igb_errnotyourplanet, "IGB.php?kk=".date("U")."&command=transfer");

  $minimum = StripNonNum($minimum);
  $maximum = StripNonNum($maximum);

  $query = "SELECT SUM(credits) as total, COUNT(*) as count from $dbtables[planets] WHERE owner=$playerinfo[player_id] AND credits != 0";

  if($minimum != 0)
    $query .= " AND credits >= $minimum";

  if($maximum != 0)
    $query .= " AND credits <= $maximum";

  $query .= " AND planet_id != $dplanet_id";

  $res = $db->Execute($query);
  $amount = $res->fields;

  $fee = $ibank_paymentfee * $amount[total];

  $tcost = ceil($amount[count] / $IGB_tconsolidate);
  $transfer = $amount[total] - $fee;

  $cplanet = $transfer + $dest[credits];

  if($tcost > $playerinfo[turns])
    IGB_error($l_igb_notenturns, "IGB.php?kk=".date("U")."&command=transfer");

  echo "<tr><td colspan=2 align=center valign=top><font size=2 face=\"courier new\" color=#00FF00>$l_igb_transfersuccessful<br>---------------------------------</td></tr>" .
       "<tr valign=top>" .
       "<td><font size=2 face=\"courier new\" color=#00FF00>$l_igb_currentpl $dest[name] $l_igb_in $dest[sector_id] :<br><br>" .
       "$l_igb_turncost :</td>" .
       "<td align=right><font size=2 face=\"courier new\" color=#00FF00>" . NUMBER($cplanet) . " C<br><br>" .
       NUMBER($tcost) . "</td>" .
       "<tr valign=bottom>" .
       "<td><font size=2 face=\"courier new\" color=#00FF00><a href=IGB.php?kk=".date("U")."&command=login>$l_igb_back</a></td><td align=right><font size=2 face=\"courier new\" color=#00FF00>&nbsp;<br><a href=\"main.php?kk=".date("U")."\">$l_igb_logout</a></td>" .
       "</tr>";

  $query = "UPDATE $dbtables[planets] SET credits=0 WHERE owner=$playerinfo[player_id] AND credits != 0";

  if($minimum != 0)
    $query .= " AND credits >= $minimum";

  if($maximum != 0)
    $query .= " AND credits <= $maximum";

  $query .= " AND planet_id != $dplanet_id";

  $res = $db->Execute($query);
  $res = $db->Execute("UPDATE $dbtables[planets] SET credits=credits + $transfer WHERE planet_id=$dplanet_id");
  $res = $db->Execute("UPDATE $dbtables[players] SET turns=turns - $tcost WHERE player_id = $playerinfo[player_id]");
  $res = $db->Execute("INSERT INTO $dbtables[ibank_statement] SET player_id=$playerinfo[player_id], amount=$transfer, trans_type=5"); // Type 5 = consolidate

}
Example #2
0
function IGB_consolidate3()
{
    global $playerinfo;
    global $db, $db_logging;
    global $dplanet_id, $minimum, $maximum, $IGB_tconsolidate, $ibank_paymentfee;
    global $l_igb_notenturns, $l_igb_back, $l_igb_logout, $l_igb_transfersuccessful;
    global $l_igb_currentpl, $l_igb_in, $l_igb_turncost, $l_igb_unnamed;
    $res = $db->Execute("SELECT name, credits, owner, sector_id FROM {$db->prefix}planets WHERE planet_id={$dplanet_id}");
    db_op_result($db, $res, __LINE__, __FILE__, $db_logging);
    if (!$res || $res->EOF) {
        IGB_error($l_igb_errunknownplanet, "igb.php?command=transfer");
    }
    $dest = $res->fields;
    if (empty($dest['name'])) {
        $dest['name'] = $l_igb_unnamed;
    }
    if ($dest['owner'] != $playerinfo['ship_id']) {
        IGB_error($l_igb_errnotyourplanet, "igb.php?command=transfer");
    }
    $minimum = StripNonNum($minimum);
    $maximum = StripNonNum($maximum);
    $query = "SELECT SUM(credits) as total, COUNT(*) AS count FROM {$db->prefix}planets WHERE owner={$playerinfo['ship_id']} AND credits != 0";
    if ($minimum != 0) {
        $query .= " AND credits >= {$minimum}";
    }
    if ($maximum != 0) {
        $query .= " AND credits <= {$maximum}";
    }
    $query .= " AND planet_id != {$dplanet_id}";
    $res = $db->Execute($query);
    db_op_result($db, $res, __LINE__, __FILE__, $db_logging);
    $amount = $res->fields;
    $fee = $ibank_paymentfee * $amount['total'];
    $tcost = ceil($amount['count'] / $IGB_tconsolidate);
    $transfer = $amount['total'] - $fee;
    $cplanet = $transfer + $dest['credits'];
    if ($tcost > $playerinfo['turns']) {
        IGB_error($l_igb_notenturns, "igb.php?command=transfer");
    }
    echo "<tr><td colspan=2 align=center valign=top>{$l_igb_transfersuccessful}<br>---------------------------------</td></tr>" . "<tr valign=top>" . "<td>{$l_igb_currentpl} {$dest['name']} {$l_igb_in} {$dest['sector_id']} :<br><br>" . "{$l_igb_turncost} :</td>" . "<td align=right>" . NUMBER($cplanet) . " C<br><br>" . NUMBER($tcost) . "</td>" . "<tr valign=bottom>" . "<td><a href='igb.php?command=login'>{$l_igb_back}</a></td><td align=right>&nbsp;<br><a href=\"main.php\">{$l_igb_logout}</a></td>" . "</tr>";
    $query = "UPDATE {$db->prefix}planets SET credits=0 WHERE owner={$playerinfo['ship_id']} AND credits != 0";
    if ($minimum != 0) {
        $query .= " AND credits >= {$minimum}";
    }
    if ($maximum != 0) {
        $query .= " AND credits <= {$maximum}";
    }
    $query .= " AND planet_id != {$dplanet_id}";
    $res = $db->Execute($query);
    db_op_result($db, $res, __LINE__, __FILE__, $db_logging);
    $res = $db->Execute("UPDATE {$db->prefix}planets SET credits=credits + {$transfer} WHERE planet_id={$dplanet_id}");
    db_op_result($db, $res, __LINE__, __FILE__, $db_logging);
    $res = $db->Execute("UPDATE {$db->prefix}ships SET turns=turns - {$tcost} WHERE ship_id = {$playerinfo['ship_id']}");
    db_op_result($db, $res, __LINE__, __FILE__, $db_logging);
}