| 1 |
<?php |
| 2 |
/** |
| 3 |
* File functions: |
| 4 |
* Astral market - add, buy astral components from other players |
| 5 |
* |
| 6 |
* @name : amarket.php |
| 7 |
* @copyright : (C) 2006 Vallheru Team based on Gamers-Fusion ver 2.5 |
| 8 |
* @author : thindil <thindil@users.sourceforge.net> |
| 9 |
* @author : eyescream <tduda@users.sourceforge.net> |
| 10 |
* @version : 1.3 |
| 11 |
* @since : 27.11.2006 |
| 12 |
* |
| 13 |
*/ |
| 14 |
|
| 15 |
// |
| 16 |
// |
| 17 |
// This program is free software; you can redistribute it and/or modify |
| 18 |
// it under the terms of the GNU General Public License as published by |
| 19 |
// the Free Software Foundation; either version 2 of the License, or |
| 20 |
// (at your option) any later version. |
| 21 |
// |
| 22 |
// This program is distributed in the hope that it will be useful, |
| 23 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 |
// GNU General Public License for more details. |
| 26 |
// |
| 27 |
// You should have received a copy of the GNU General Public License |
| 28 |
// along with this program; if not, write to the Free Software |
| 29 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 30 |
// |
| 31 |
// $Id$ |
| 32 |
|
| 33 |
$title = "Astralny rynek"; |
| 34 |
require_once("includes/head.php"); |
| 35 |
|
| 36 |
/** |
| 37 |
* Get the localization for game |
| 38 |
*/ |
| 39 |
require_once("languages/".$player -> lang."/amarket.php"); |
| 40 |
|
| 41 |
if ($player -> location != 'Altara' && $player -> location != 'Ardulith') |
| 42 |
{ |
| 43 |
error (ERROR); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Assign variables to template |
| 48 |
*/ |
| 49 |
$smarty -> assign(array("Message" => '', |
| 50 |
"Previous" => '', |
| 51 |
"Next" => '')); |
| 52 |
|
| 53 |
/** |
| 54 |
* Main menu |
| 55 |
*/ |
| 56 |
if (!isset($_GET['view']) && !isset($_GET['buy']) && !isset($_GET['wyc'])) |
| 57 |
{ |
| 58 |
$smarty -> assign(array("Minfo" => M_INFO, |
| 59 |
"Aview" => A_VIEW, |
| 60 |
"Asearch" => A_SEARCH, |
| 61 |
"Aadd" => A_ADD, |
| 62 |
"Adelete" => A_DELETE, |
| 63 |
"Alist" => A_LIST, |
| 64 |
"Aback2" => A_BACK2)); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Search astral components on market |
| 69 |
*/ |
| 70 |
if (isset ($_GET['view']) && $_GET['view'] == 'szukaj') |
| 71 |
{ |
| 72 |
$smarty -> assign(array("Sinfo" => S_INFO, |
| 73 |
"Sinfo2" => S_INFO2, |
| 74 |
"Astral" => ASTRAL, |
| 75 |
"Asearch" => A_SEARCH)); |
| 76 |
} |
| 77 |
|
| 78 |
$arrNames = array(MAP1, MAP2, MAP3, MAP4, MAP5, MAP6, MAP7, PLAN1, PLAN2, PLAN3, PLAN4, PLAN5, RECIPE1, RECIPE2, RECIPE3, RECIPE4, RECIPE5, FORMULA1, FORMULA2, FORMULA3, FORMULA4, FORMULA5); |
| 79 |
$arrNames2 = array(COMP1, COMP2, COMP3, COMP4, COMP5, COMP6, COMP7, CONST1, CONST2, CONST3, CONST4, CONST5, POTION1, POTION2, POTION3, POTION4, POTION5, JEWELLERY1, JEWELLERY2, JEWELLERY3, JEWELLERY4, JEWELLERY5); |
| 80 |
|
| 81 |
/** |
| 82 |
* View oferts on market |
| 83 |
*/ |
| 84 |
if (isset ($_GET['view']) && $_GET['view'] == 'market') |
| 85 |
{ |
| 86 |
$arrNames = array_merge($arrNames, $arrNames2); |
| 87 |
if (empty($_POST['szukany'])) |
| 88 |
{ |
| 89 |
$msel = $db -> Execute("SELECT count(*) FROM `amarket`"); |
| 90 |
$strSearch = ''; |
| 91 |
} |
| 92 |
else |
| 93 |
{ |
| 94 |
$_POST['szukany'] = strip_tags($_POST['szukany']); |
| 95 |
$intKey = array_search($_POST['szukany'], $arrNames); |
| 96 |
if ($intKey == NULL) |
| 97 |
{ |
| 98 |
$strSearch = 'A'; |
| 99 |
} |
| 100 |
if ($intKey < 7) |
| 101 |
{ |
| 102 |
$strSearch = "M".$intKey; |
| 103 |
} |
| 104 |
if ($intKey > 6 && $intKey < 12) |
| 105 |
{ |
| 106 |
$intNumber = $intKey - 7; |
| 107 |
$strSearch = "P".$intNumber; |
| 108 |
} |
| 109 |
if ($intKey > 11 && $intKey < 17) |
| 110 |
{ |
| 111 |
$intNumber = $intKey - 12; |
| 112 |
$strSearch = "R".$intNumber; |
| 113 |
} |
| 114 |
if ($intKey > 16 && $intKey < 24) |
| 115 |
{ |
| 116 |
$intNumber = $intKey - 17; |
| 117 |
$strSearch = "Y".$intNumber; |
| 118 |
} |
| 119 |
if ($intKey > 23 && $intKey < 29) |
| 120 |
{ |
| 121 |
$intNumber = $intKey - 24; |
| 122 |
$strSearch = "C".$intNumber; |
| 123 |
} |
| 124 |
if ($intKey > 28 && $intKey < 34) |
| 125 |
{ |
| 126 |
$intNumber = $intKey - 29; |
| 127 |
$strSearch = "O".$intNumber; |
| 128 |
} |
| 129 |
if ($intKey > 33 && $intKey < 39) |
| 130 |
{ |
| 131 |
$intNumber = $intKey - 34; |
| 132 |
$strSearch = "T".$intNumber; |
| 133 |
} |
| 134 |
if ($intKey > 38 && $intKey < 44) |
| 135 |
{ |
| 136 |
$intNumber = $intKey - 39; |
| 137 |
$strSearch = "J".$intNumber; |
| 138 |
} |
| 139 |
$msel = $db -> Execute("SELECT count(*) FROM `amarket` WHERE `type`='".$strSearch."'"); |
| 140 |
} |
| 141 |
$oferty = $msel -> fields['count(*)']; |
| 142 |
$msel -> Close(); |
| 143 |
if (!isset($_GET['limit'])) |
| 144 |
{ |
| 145 |
$_GET['limit'] = 0; |
| 146 |
} |
| 147 |
if (!isset($_GET['lista'])) |
| 148 |
{ |
| 149 |
$_GET['lista'] = 0; |
| 150 |
} |
| 151 |
if ($oferty == 0) |
| 152 |
{ |
| 153 |
error(NO_OFERTS); |
| 154 |
} |
| 155 |
if ($_GET['limit'] < $oferty) |
| 156 |
{ |
| 157 |
if (empty($_POST['szukany'])) |
| 158 |
{ |
| 159 |
$pm = $db -> SelectLimit("SELECT * FROM `amarket` ORDER BY ".$_GET['lista']." DESC", 30, $_GET['limit']); |
| 160 |
} |
| 161 |
else |
| 162 |
{ |
| 163 |
$pm = $db -> SelectLimit("SELECT * FROM `amarket` WHERE `type`='".$strSearch."' ORDER BY ".$_GET['lista']." DESC", 30, $_GET['limit']); |
| 164 |
} |
| 165 |
$arrname = array(); |
| 166 |
$arramount = array(); |
| 167 |
$arrcost = array(); |
| 168 |
$arrseller = array(); |
| 169 |
$arraction = array(); |
| 170 |
$arruser = array(); |
| 171 |
$arrNumber = array(); |
| 172 |
$i = 0; |
| 173 |
while (!$pm -> EOF) |
| 174 |
{ |
| 175 |
if (ereg("^M[0-9]", $pm -> fields['type'])) |
| 176 |
{ |
| 177 |
$intKey = str_replace("M", "", $pm -> fields['type']); |
| 178 |
$intNumber = $intKey; |
| 179 |
$arrNumber[$i] = $pm -> fields['number'] + 1; |
| 180 |
} |
| 181 |
if (ereg("^P[0-9]", $pm -> fields['type'])) |
| 182 |
{ |
| 183 |
$intKey = str_replace("P", "", $pm -> fields['type']); |
| 184 |
$intNumber = $intKey + 7; |
| 185 |
$arrNumber[$i] = $pm -> fields['number'] + 1; |
| 186 |
} |
| 187 |
if (ereg("^R[0-9]", $pm -> fields['type'])) |
| 188 |
{ |
| 189 |
$intKey = str_replace("R", "", $pm -> fields['type']); |
| 190 |
$intNumber = $intKey + 12; |
| 191 |
$arrNumber[$i] = $pm -> fields['number'] + 1; |
| 192 |
} |
| 193 |
if (ereg("^Y[0-9]", $pm -> fields['type'])) |
| 194 |
{ |
| 195 |
$intKey = str_replace("Y", "", $pm -> fields['type']); |
| 196 |
$intNumber = $intKey + 17; |
| 197 |
$arrNumber[$i] = '-'; |
| 198 |
} |
| 199 |
if (ereg("^C[0-9]", $pm -> fields['type'])) |
| 200 |
{ |
| 201 |
$intKey = str_replace("C", "", $pm -> fields['type']); |
| 202 |
$intNumber = $intKey + 24; |
| 203 |
$arrNumber[$i] = '-'; |
| 204 |
} |
| 205 |
if (ereg("^O[0-9]", $pm -> fields['type'])) |
| 206 |
{ |
| 207 |
$intKey = str_replace("O", "", $pm -> fields['type']); |
| 208 |
$intNumber = $intKey + 29; |
| 209 |
$arrNumber[$i] = '-'; |
| 210 |
} |
| 211 |
if (ereg("^T[0-9]", $pm -> fields['type'])) |
| 212 |
{ |
| 213 |
$intKey = str_replace("T", "", $pm -> fields['type']); |
| 214 |
$intNumber = $intKey + 34; |
| 215 |
$arrNumber[$i] = '-'; |
| 216 |
} |
| 217 |
if (ereg("^J[0-9]", $pm -> fields['type'])) |
| 218 |
{ |
| 219 |
$intKey = str_replace("J", "", $pm -> fields['type']); |
| 220 |
$intNumber = $intKey + 39; |
| 221 |
$arrNumber[$i] = '-'; |
| 222 |
} |
| 223 |
$arrname[$i] = $arrNames[$intNumber]; |
| 224 |
$arramount[$i] = $pm -> fields['amount']; |
| 225 |
$arrcost[$i] = $pm -> fields['cost']; |
| 226 |
$arrseller[$i] = $pm -> fields['seller']; |
| 227 |
$seller = $db -> Execute("SELECT `user` FROM `players` WHERE `id`=".$pm -> fields['seller']); |
| 228 |
$arruser[$i] = $seller -> fields['user']; |
| 229 |
$seller -> Close(); |
| 230 |
if ($player -> id == $pm -> fields['seller']) |
| 231 |
{ |
| 232 |
$arraction[$i] = "<td>- <a href=\"amarket.php?wyc=".$pm -> fields['id']."\">".A_DELETE."</a>"; |
| 233 |
} |
| 234 |
else |
| 235 |
{ |
| 236 |
$arraction[$i] = "<td>- <a href=\"amarket.php?buy=".$pm -> fields['id']."\">".A_BUY."</a>"; |
| 237 |
if ($player -> clas == 'Złodziej') |
| 238 |
{ |
| 239 |
$arraction[$i] = $arraction[$i]."<br />- <a href=\"amarket.php?steal=".$pm -> fields['id']."\">".A_STEAL."</a>"; |
| 240 |
} |
| 241 |
} |
| 242 |
$arraction[$i] = $arraction[$i]."</td></tr>"; |
| 243 |
$pm -> MoveNext(); |
| 244 |
$i = $i + 1; |
| 245 |
} |
| 246 |
$pm -> Close(); |
| 247 |
$smarty -> assign(array("Name" => $arrname, |
| 248 |
"Amount" => $arramount, |
| 249 |
"Cost" => $arrcost, |
| 250 |
"Seller" => $arrseller, |
| 251 |
"Action" => $arraction, |
| 252 |
"User" => $arruser, |
| 253 |
"Number" => $arrNumber, |
| 254 |
"Tastral" => ASTRAL, |
| 255 |
"Tamount" => T_AMOUNT, |
| 256 |
"Tcost" => T_COST, |
| 257 |
"Tseller" => T_SELLER, |
| 258 |
"Tnumber" => T_NUMBER, |
| 259 |
"Toptions" => T_OPTIONS, |
| 260 |
"Viewinfo" => VIEW_INFO)); |
| 261 |
if (!isset($_POST['szukany'])) |
| 262 |
{ |
| 263 |
$_POST['szukany'] = ''; |
| 264 |
} |
| 265 |
if ($_GET['limit'] >= 30) |
| 266 |
{ |
| 267 |
$lim = $_GET['limit'] - 30; |
| 268 |
$smarty -> assign ("Previous", "<form method=\"post\" action=\"amarket.php?view=market&limit=".$lim."&lista=".$_GET['lista']."\"><input type=\"hidden\" name=\"szukany\" value=\"".$_POST['szukany']."\"><input type=\"submit\" value=\"".A_PREVIOUS."\"></form> "); |
| 269 |
} |
| 270 |
$_GET['limit'] = $_GET['limit'] + 30; |
| 271 |
if ($oferty > 30 && $_GET['limit'] < $oferty) |
| 272 |
{ |
| 273 |
$smarty -> assign ("Next", " <form method=\"post\" action=\"amarket.php?view=market&limit=".$_GET['limit']."&lista=".$_GET['lista']."\"><input type=\"hidden\" name=\"szukany\" value=\"".$_POST['szukany']."\"><input type=\"submit\" value=\"".A_NEXT."\"></form>"); |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
|
| 278 |
/** |
| 279 |
* Add ofert on market |
| 280 |
*/ |
| 281 |
if (isset ($_GET['view']) && $_GET['view'] == 'add') |
| 282 |
{ |
| 283 |
$smarty -> assign(array("Addinfo" => ADD_INFO, |
| 284 |
"Astral" => ASTRAL, |
| 285 |
"Herbname" => $arrNames, |
| 286 |
"Aname" => $arrNames2, |
| 287 |
"Hamount" => H_AMOUNT, |
| 288 |
"Hcost" => H_COST, |
| 289 |
"Aadd" => A_ADD, |
| 290 |
"Tadd" => T_ADD, |
| 291 |
"Tadd2" => T_ADD2, |
| 292 |
"Anumber" => A_NUMBER, |
| 293 |
"Addofert" => 0)); |
| 294 |
if (isset ($_GET['step']) && ($_GET['step'] == 'piece' || $_GET['step'] == 'component')) |
| 295 |
{ |
| 296 |
if (!ereg("^[1-9][0-9]*$", $_POST['amount']) || !ereg("^[0-9]*$", $_POST['name']) || !ereg("^[1-9][0-9]*$", $_POST['number']) || !ereg("^[1-9][0-9]*$", $_POST['cost'])) |
| 297 |
{ |
| 298 |
error(ERROR); |
| 299 |
} |
| 300 |
if ($_GET['step'] == 'piece') |
| 301 |
{ |
| 302 |
if ($_POST['name'] < 7) |
| 303 |
{ |
| 304 |
$strName = 'M'; |
| 305 |
} |
| 306 |
if ($_POST['name'] > 6 && $_POST['name'] < 12) |
| 307 |
{ |
| 308 |
$strName = 'P'; |
| 309 |
} |
| 310 |
if ($_POST['name'] > 11 && $_POST['name'] < 17) |
| 311 |
{ |
| 312 |
$strName = 'R'; |
| 313 |
} |
| 314 |
if ($_POST['name'] > 16) |
| 315 |
{ |
| 316 |
$strName = 'Y'; |
| 317 |
} |
| 318 |
$strName2 = $arrNames[$_POST['name']]; |
| 319 |
} |
| 320 |
else |
| 321 |
{ |
| 322 |
if ($_POST['name'] < 7) |
| 323 |
{ |
| 324 |
$strName = 'C'; |
| 325 |
} |
| 326 |
if ($_POST['name'] > 6 && $_POST['name'] < 12) |
| 327 |
{ |
| 328 |
$strName = 'O'; |
| 329 |
} |
| 330 |
if ($_POST['name'] > 11 && $_POST['name'] < 17) |
| 331 |
{ |
| 332 |
$strName = 'T'; |
| 333 |
} |
| 334 |
if ($_POST['name'] > 16) |
| 335 |
{ |
| 336 |
$strName = 'J'; |
| 337 |
} |
| 338 |
$strName2 = $arrNames2[$_POST['name']]; |
| 339 |
} |
| 340 |
$arrNumber = array(0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4); |
| 341 |
$strPiecename = $strName.$arrNumber[$_POST['name']]; |
| 342 |
$intNumber = $_POST['number'] - 1; |
| 343 |
$objAmount = $db -> Execute("SELECT `amount` FROM `astral` WHERE `owner`=".$player -> id." AND `type`='".$strPiecename."' AND `number`=".$intNumber." AND `location`='V'") or die($db -> ErrorMsg()); |
| 344 |
if (!$objAmount -> fields['amount']) |
| 345 |
{ |
| 346 |
error(NO_AMOUNT.$strName2); |
| 347 |
} |
| 348 |
if ($objAmount -> fields['amount'] < $_POST['amount']) |
| 349 |
{ |
| 350 |
error(NO_AMOUNT.$strName2); |
| 351 |
} |
| 352 |
$objTest = $db -> Execute("SELECT `id` FROM `amarket` WHERE `seller`=".$player -> id." AND `type`='".$strPiecename."' AND `number`=".$intNumber); |
| 353 |
if (!$objTest -> fields['id']) |
| 354 |
{ |
| 355 |
$db -> Execute("INSERT INTO `amarket` (`seller`, `type`, `number`, `amount`, `cost`) VALUES(".$player -> id.", '".$strPiecename."', ".$intNumber.", ".$_POST['amount'].", ".$_POST['cost'].")") or die($db -> ErrorMsg()); |
| 356 |
if ($objAmount -> fields['amount'] == $_POST['amount']) |
| 357 |
{ |
| 358 |
$db -> Execute("DELETE FROM `astral` WHERE `owner`=".$player -> id." AND `type`='".$strPiecename."' AND `number`=".$intNumber." AND `location`='V'"); |
| 359 |
} |
| 360 |
else |
| 361 |
{ |
| 362 |
$db -> Execute("UPDATE `astral` SET `amount`=`amount`-".$_POST['amount']." WHERE `owner`=".$player -> id." AND `type`='".$strPiecename."' AND `number`=".$intNumber." AND `location`='V'"); |
| 363 |
} |
| 364 |
$smarty -> assign("Message", YOU_ADD." <a href=\"amarket.php?view=add\">".A_REFRESH."</a>"); |
| 365 |
} |
| 366 |
else |
| 367 |
{ |
| 368 |
$smarty -> assign(array("Addofert" => $objTest -> fields['id'], |
| 369 |
"Youwant" => YOU_WANT, |
| 370 |
"Ayes" => YES, |
| 371 |
"Herbname" => $_POST['name'], |
| 372 |
"Herbamount" => $_POST['amount'], |
| 373 |
"Astralnumber" => $_POST['number'], |
| 374 |
"Herbcost" => $_POST['cost'], |
| 375 |
"Step" => $_GET['step'])); |
| 376 |
if (isset($_POST['ofert'])) |
| 377 |
{ |
| 378 |
if (!ereg("^[1-9][0-9]*$", $_POST['ofert'])) |
| 379 |
{ |
| 380 |
error(ERROR); |
| 381 |
} |
| 382 |
require_once('includes/marketaddto.php'); |
| 383 |
addtoastral($objTest -> fields['id'], $objAmount -> fields['amount'], $player -> id, $strPiecename, $intNumber); |
| 384 |
$smarty -> assign("Message", YOU_ADD." <a href=\"amarket.php?view=add\">".A_REFRESH."</a>"); |
| 385 |
} |
| 386 |
} |
| 387 |
$objTest -> Close(); |
| 388 |
$objAmount -> Close(); |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
/** |
| 393 |
* Delete all oferts one player from market |
| 394 |
*/ |
| 395 |
if (isset ($_GET['view']) && $_GET['view'] == 'del') |
| 396 |
{ |
| 397 |
require_once('includes/marketdelall.php'); |
| 398 |
deleteallastral($player -> id); |
| 399 |
$smarty -> assign("Message", YOU_DELETE." (<a href=\"amarket.php\">".A_BACK."</a>)"); |
| 400 |
} |
| 401 |
|
| 402 |
/** |
| 403 |
* Buy components from market |
| 404 |
*/ |
| 405 |
if (isset($_GET['buy'])) |
| 406 |
{ |
| 407 |
if (!ereg("^[1-9][0-9]*$", $_GET['buy'])) |
| 408 |
{ |
| 409 |
error (ERROR); |
| 410 |
} |
| 411 |
$buy = $db -> Execute("SELECT * FROM `amarket` WHERE `id`=".$_GET['buy']) ; |
| 412 |
if (!$buy -> fields['id']) |
| 413 |
{ |
| 414 |
error (NO_OFERTS); |
| 415 |
} |
| 416 |
if ($buy -> fields['seller'] == $player -> id) |
| 417 |
{ |
| 418 |
error (IS_YOUR); |
| 419 |
} |
| 420 |
$seller = $db -> Execute("SELECT `user` FROM `players` WHERE `id`=".$buy -> fields['seller']); |
| 421 |
if (ereg("^M[0-9]", $buy -> fields['type'])) |
| 422 |
{ |
| 423 |
$intKey = str_replace("M", "", $buy -> fields['type']); |
| 424 |
$intNumber = $intKey; |
| 425 |
} |
| 426 |
if (ereg("^P[0-9]", $buy -> fields['type'])) |
| 427 |
{ |
| 428 |
$intKey = str_replace("P", "", $buy -> fields['type']); |
| 429 |
$intNumber = $intKey + 7; |
| 430 |
} |
| 431 |
if (ereg("^R[0-9]", $buy -> fields['type'])) |
| 432 |
{ |
| 433 |
$intKey = str_replace("R", "", $buy -> fields['type']); |
| 434 |
$intNumber = $intKey + 12; |
| 435 |
} |
| 436 |
if (ereg("^Y[0-9]", $buy -> fields['type'])) |
| 437 |
{ |
| 438 |
$intKey = str_replace("Y", "", $buy -> fields['type']); |
| 439 |
$intNumber = $intKey + 17; |
| 440 |
$buy -> fields['number'] = '-'; |
| 441 |
} |
| 442 |
if (ereg("^C[0-9]", $buy -> fields['type'])) |
| 443 |
{ |
| 444 |
$intKey = str_replace("C", "", $buy -> fields['type']); |
| 445 |
$intNumber = $intKey + 24; |
| 446 |
$buy -> fields['number'] = '-'; |
| 447 |
} |
| 448 |
if (ereg("^O[0-9]", $buy -> fields['type'])) |
| 449 |
{ |
| 450 |
$intKey = str_replace("O", "", $buy -> fields['type']); |
| 451 |
$intNumber = $intKey + 29; |
| 452 |
$buy -> fields['number'] = '-'; |
| 453 |
} |
| 454 |
if (ereg("^T[0-9]", $buy -> fields['type'])) |
| 455 |
{ |
| 456 |
$intKey = str_replace("T", "", $buy -> fields['type']); |
| 457 |
$intNumber = $intKey + 34; |
| 458 |
$buy -> fields['number'] = '-'; |
| 459 |
} |
| 460 |
if (ereg("^J[0-9]", $buy -> fields['type'])) |
| 461 |
{ |
| 462 |
$intKey = str_replace("J", "", $buy -> fields['type']); |
| 463 |
$intNumber = $intKey + 39; |
| 464 |
$buy -> fields['number'] = '-'; |
| 465 |
} |
| 466 |
$arrNames = array_merge($arrNames, $arrNames2); |
| 467 |
$strName = $arrNames[$intNumber]; |
| 468 |
$intAstralnumber = $buy -> fields['number'] + 1; |
| 469 |
$smarty -> assign(array("Name" => $strName, |
| 470 |
"Amount1" => $buy -> fields['amount'], |
| 471 |
"Itemid" => $buy -> fields['id'], |
| 472 |
"Cost" => $buy -> fields['cost'], |
| 473 |
"Seller" => $seller -> fields['user'], |
| 474 |
"Sid" => $buy -> fields['seller'], |
| 475 |
"Anumber" => $intAstralnumber, |
| 476 |
"Buyinfo" => BUY_INFO, |
| 477 |
"Bherb" => ASTRAL, |
| 478 |
"Oamount" => O_AMOUNT, |
| 479 |
"Hcost" => H_COST, |
| 480 |
"Hseller" => SELLER, |
| 481 |
"Bamount" => B_AMOUNT, |
| 482 |
"Tnumber" => T_NUMBER, |
| 483 |
"Abuy" => A_BUY)); |
| 484 |
$buy -> Close(); |
| 485 |
if (isset($_GET['step']) && $_GET['step'] == 'buy') |
| 486 |
{ |
| 487 |
if (!ereg("^[1-9][0-9]*$", $_POST['amount'])) |
| 488 |
{ |
| 489 |
error (ERROR); |
| 490 |
} |
| 491 |
$buy = $db -> Execute("SELECT * FROM `amarket` WHERE `id`=".$_GET['buy']); |
| 492 |
$price = $_POST['amount'] * $buy -> fields['cost']; |
| 493 |
if ($price > $player -> credits) |
| 494 |
{ |
| 495 |
error (NO_MONEY); |
| 496 |
} |
| 497 |
if ($_POST['amount'] > $buy -> fields['amount']) |
| 498 |
{ |
| 499 |
error(NO_AMOUNT.$strName.ON_MARKET); |
| 500 |
} |
| 501 |
$db -> Execute("UPDATE `players` SET `bank`=`bank`+".$price." WHERE `id`=".$buy -> fields['seller']); |
| 502 |
$db -> Execute("UPDATE `players` SET `credits`=`credits`-".$price." WHERE `id`=".$player -> id); |
| 503 |
$objTest = $db -> Execute("SELECT `amount` FROM `astral` WHERE `owner`=".$player -> id." AND `type`='".$buy -> fields['type']."' AND `number`=".$buy -> fields['number']." AND `location`='V'"); |
| 504 |
if (!$objTest -> fields['amount']) |
| 505 |
{ |
| 506 |
$db -> Execute("INSERT INTO `astral` (`owner`, `type`, `number`, `amount`, `location`) VALUES(".$player -> id.", '".$buy -> fields['type']."', ".$buy -> fields['number'].", ".$_POST['amount'].", 'V')"); |
| 507 |
} |
| 508 |
else |
| 509 |
{ |
| 510 |
$db -> Execute("UPDATE `astral` SET `amount`=`amount`+".$_POST['amount']." WHERE `owner`=".$player -> id." AND `type`='".$buy -> fields['type']."' AND `number`=".$buy -> fields['number']." AND `location`='V'"); |
| 511 |
} |
| 512 |
$objTest -> Close(); |
| 513 |
if ($_POST['amount'] == $buy -> fields['amount']) |
| 514 |
{ |
| 515 |
$db -> Execute("DELETE FROM `amarket` WHERE `id`=".$buy -> fields['id']); |
| 516 |
} |
| 517 |
else |
| 518 |
{ |
| 519 |
$db -> Execute("UPDATE `amarket` SET `amount`=`amount`-".$_POST['amount']." WHERE `id`=".$buy -> fields['id']); |
| 520 |
} |
| 521 |
$strDate = $db -> DBDate($newdate); |
| 522 |
$db -> Execute("INSERT INTO `log` (`owner`, `log`, `czas`) VALUES(".$buy -> fields['seller'].",'<b><a href=view.php?view=".$player -> id.">".$player -> user.L_ACCEPT.$player -> id.L_ACCEPT2.$_POST['amount'].L_AMOUNT.$strName.YOU_GET.$price.TO_BANK."', ".$strDate.")"); |
| 523 |
$smarty -> assign("Message", YOU_BUY.$_POST['amount'].I_AMOUNT.$strName.FOR_A.$price.GOLD_COINS); |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
/** |
| 528 |
* Delete one ofert from market |
| 529 |
*/ |
| 530 |
if (isset($_GET['wyc'])) |
| 531 |
{ |
| 532 |
if (!ereg("^[1-9][0-9]*$", $_GET['wyc'])) |
| 533 |
{ |
| 534 |
error (ERROR); |
| 535 |
} |
| 536 |
$dwyc = $db -> Execute("SELECT * FROM `amarket` WHERE `id`=".$_GET['wyc']); |
| 537 |
if ($dwyc -> fields['seller'] != $player -> id) |
| 538 |
{ |
| 539 |
error (NOT_YOUR); |
| 540 |
} |
| 541 |
require_once('includes/marketdel.php'); |
| 542 |
deleteastral($dwyc, $player -> id); |
| 543 |
$smarty -> assign("Message", YOU_DELETE." (<a href=\"amarket.php\">".A_BACK."</a>)"); |
| 544 |
} |
| 545 |
|
| 546 |
/** |
| 547 |
* List of all ofers on market |
| 548 |
*/ |
| 549 |
if (isset($_GET['view']) && $_GET['view'] == 'all') |
| 550 |
{ |
| 551 |
$oferts = $db -> Execute("SELECT `type` FROM `amarket` GROUP BY `type`"); |
| 552 |
$arrname = array(); |
| 553 |
$arramount = array(); |
| 554 |
$i = 0; |
| 555 |
$arrNames = array_merge($arrNames, $arrNames2); |
| 556 |
while (!$oferts -> EOF) |
| 557 |
{ |
| 558 |
if (ereg("^M[0-9]", $oferts -> fields['type'])) |
| 559 |
{ |
| 560 |
$intKey = str_replace("M", "", $oferts -> fields['type']); |
| 561 |
$intNumber = $intKey; |
| 562 |
} |
| 563 |
if (ereg("^P[0-9]", $oferts -> fields['type'])) |
| 564 |
{ |
| 565 |
$intKey = str_replace("P", "", $oferts -> fields['type']); |
| 566 |
$intNumber = $intKey + 7; |
| 567 |
} |
| 568 |
if (ereg("^R[0-9]", $oferts -> fields['type'])) |
| 569 |
{ |
| 570 |
$intKey = str_replace("R", "", $oferts -> fields['type']); |
| 571 |
$intNumber = $intKey + 12; |
| 572 |
} |
| 573 |
if (ereg("^Y[0-9]", $oferts -> fields['type'])) |
| 574 |
{ |
| 575 |
$intKey = str_replace("Y", "", $oferts -> fields['type']); |
| 576 |
$intNumber = $intKey + 17; |
| 577 |
} |
| 578 |
if (ereg("^C[0-9]", $oferts -> fields['type'])) |
| 579 |
{ |
| 580 |
$intKey = str_replace("C", "", $oferts -> fields['type']); |
| 581 |
$intNumber = $intKey + 24; |
| 582 |
} |
| 583 |
if (ereg("^O[0-9]", $oferts -> fields['type'])) |
| 584 |
{ |
| 585 |
$intKey = str_replace("O", "", $oferts -> fields['type']); |
| 586 |
$intNumber = $intKey + 29; |
| 587 |
} |
| 588 |
if (ereg("^T[0-9]", $oferts -> fields['type'])) |
| 589 |
{ |
| 590 |
$intKey = str_replace("T", "", $oferts -> fields['type']); |
| 591 |
$intNumber = $intKey + 34; |
| 592 |
} |
| 593 |
if (ereg("^J[0-9]", $oferts -> fields['type'])) |
| 594 |
{ |
| 595 |
$intKey = str_replace("J", "", $oferts -> fields['type']); |
| 596 |
$intNumber = $intKey + 39; |
| 597 |
} |
| 598 |
$arrname[$i] = $arrNames[$intNumber]; |
| 599 |
$arramount[$i] = 0; |
| 600 |
$query = $db -> Execute("SELECT `id` FROM `amarket` WHERE `type`='".$oferts -> fields['type']."'"); |
| 601 |
while (!$query -> EOF) |
| 602 |
{ |
| 603 |
$arramount[$i] = $arramount[$i] + 1; |
| 604 |
$query -> MoveNext(); |
| 605 |
} |
| 606 |
$query -> Close(); |
| 607 |
$oferts -> MoveNext(); |
| 608 |
$i = $i + 1; |
| 609 |
} |
| 610 |
$oferts -> Close(); |
| 611 |
$smarty -> assign(array("Name" => $arrname, |
| 612 |
"Amount" => $arramount, |
| 613 |
"Message" => "<br />(<a href=\"amarket.php\">".A_BACK."</a>)", |
| 614 |
"Listinfo" => LIST_INFO, |
| 615 |
"Hname" => H_NAME, |
| 616 |
"Hamount" => H_AMOUNT, |
| 617 |
"Haction" => H_ACTION, |
| 618 |
"Ashow" => A_SHOW)); |
| 619 |
} |
| 620 |
|
| 621 |
/** |
| 622 |
* Steal components from market |
| 623 |
*/ |
| 624 |
if (isset($_GET['steal'])) |
| 625 |
{ |
| 626 |
if (!ereg("^[1-9][0-9]*$", $_GET['steal'])) |
| 627 |
{ |
| 628 |
error(ERROR); |
| 629 |
} |
| 630 |
$objOwner = $db -> Execute("SELECT `seller` FROM `amarket` WHERE `id`=".$_GET['steal']); |
| 631 |
if ($objOwner -> fields['seller'] == $player -> id || $player -> clas != 'Złodziej' || $player -> location == 'Lochy') |
| 632 |
{ |
| 633 |
error(ERROR); |
| 634 |
} |
| 635 |
$objCrime = $db -> Execute("SELECT `astralcrime` FROM `players` WHERE `id`=".$player -> id); |
| 636 |
if ($objCrime -> fields['astralcrime'] == 'N') |
| 637 |
{ |
| 638 |
error (NO_CRIME); |
| 639 |
} |
| 640 |
if ($player -> hp <= 0) |
| 641 |
{ |
| 642 |
error (YOU_DEAD); |
| 643 |
} |
| 644 |
require_once('includes/astralsteal.php'); |
| 645 |
astralsteal($objOwner -> fields['seller'], 'R', 0, $_GET['steal']); |
| 646 |
$objOwner -> Close(); |
| 647 |
} |
| 648 |
|
| 649 |
/** |
| 650 |
* Initialization of variables |
| 651 |
*/ |
| 652 |
if (!isset($_GET['view'])) |
| 653 |
{ |
| 654 |
$_GET['view'] = ''; |
| 655 |
} |
| 656 |
if (!isset($_GET['wyc'])) |
| 657 |
{ |
| 658 |
$_GET['wyc'] = ''; |
| 659 |
} |
| 660 |
if (!isset($_GET['buy'])) |
| 661 |
{ |
| 662 |
$_GET['buy'] = ''; |
| 663 |
} |
| 664 |
|
| 665 |
/** |
| 666 |
* Assign variables to template and display page |
| 667 |
*/ |
| 668 |
$smarty -> assign(array("View" => $_GET['view'], |
| 669 |
"Remowe" => $_GET['wyc'], |
| 670 |
"Buy" => $_GET['buy'], |
| 671 |
"Aback" => A_BACK)); |
| 672 |
$smarty -> display ('amarket.tpl'); |
| 673 |
|
| 674 |
require_once("includes/foot.php"); |
| 675 |
?> |