PageRenderTime 62ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/demolish.php

https://bitbucket.org/jugoslin/phpdevana
PHP | 42 lines | 41 code | 1 blank | 0 comment | 33 complexity | a45703d0ab783d298db6693cc418b17c MD5 | raw file
  1. <?php include "antet.php"; include "func.php";
  2. if (isset($_SESSION["user"][0], $_GET["town"], $_POST["a"], $_POST["b"]))
  3. {
  4. $_GET["town"]=clean($_GET["town"]); $_POST["a"]=clean($_POST["a"]); $_POST["b"]=clean($_POST["b"]);
  5. $town=town($_GET["town"]); if ($town[1]!=$_SESSION["user"][0]) {header('Location: login.php'); die();}
  6. $buildings=buildings($_SESSION["user"][10]); $lim=explode("-", $town[11]);
  7. $land=explode("/", $town[13]); $land[0]=explode("-", $land[0]); $land[1]=explode("-", $land[1]); $land[2]=explode("-", $land[2]); $land[3]=explode("-", $land[3]); $land[4]=explode("-", $town[8]);
  8. $upk=explode("-", $buildings[$_POST["b"]][7]);
  9. if ($land[$_POST["a"]][$_POST["b"]]) $land[$_POST["a"]][$_POST["b"]]--; $town[3]-=$upk[$land[$_POST["a"]][$_POST["b"]]];
  10. if ($_POST["a"]<4)
  11. {
  12. $col="land"; $data=array(); $data[0]=implode("-", $land[0]); $data[1]=implode("-", $land[1]); $data[2]=implode("-", $land[2]); $data[3]=implode("-", $land[3]); $data=implode("/", $data);
  13. }
  14. else
  15. {
  16. $col="buildings"; $data=implode("-", $land[4]);
  17. }
  18. if ($_POST["a"]==4) switch ($_POST["b"])
  19. {//default limits values for a new town: 600-400-200-20-100-0-0-0-0-0-0-0-0
  20. case 4: $lim[0]=explode("-", $buildings[4][5]); if ($land[4][4]>0) $lim[0]=$lim[0][$land[4][4]-1]; else $lim[0]=600; break;
  21. case 5: $lim[1]=explode("-", $buildings[5][5]); if ($land[4][5]>0) $lim[1]=$lim[1][$land[4][5]-1]; else $lim[1]=400; break;
  22. case 6: $lim[5]=explode("-", $buildings[6][5]); if ($land[4][6]>0) $lim[5]=$lim[5][$land[4][6]-1]; else $lim[5]=0; break;
  23. case 7: $lim[2]-=800; $lim[4]=explode("-", $buildings[7][5]); if ($land[4][7]>0) $lim[4]=$lim[4][$land[4][7]-1]; else $lim[4]=100; break;
  24. case 8: $lim[3]=explode("-", $buildings[8][5]); if ($land[4][8]>0) $lim[3]=$lim[3][$land[4][8]-1]; else $lim[3]=20; break;
  25. case 13: $lim[6]=explode("-", $buildings[13][5]); if ($land[4][13]>0) $lim[6]=$lim[6][$land[4][13]-1]; else $lim[6]=0; break;
  26. case 14: $lim[7]=explode("-", $buildings[14][5]); if ($land[4][14]>0) $lim[7]=$lim[7][$land[4][14]-1]; else $lim[7]=0; break;
  27. case 15: $lim[8]=explode("-", $buildings[15][5]); if ($land[4][15]>0) $lim[8]=$lim[8][$land[4][15]-1]; else $lim[8]=0; break;
  28. case 18: $lim[9]=explode("-", $buildings[18][5]); if ($land[4][18]>0) $lim[9]=$lim[9][$land[4][18]-1]; else $lim[9]=0; break;
  29. case 19: $lim[10]=explode("-", $buildings[19][5]); if ($land[4][19]>0) $lim[10]=$lim[10][$land[4][19]-1]; else $lim[10]=0; break;
  30. case 20: $lim[11]=explode("-", $buildings[20][5]); if ($land[4][20]>0) $lim[11]=$lim[11][$land[4][20]-1]; else $lim[11]=0; break;
  31. case 21: $lim[12]=explode("-", $buildings[21][5]); if ($land[4][21]>0) $lim[12]=$lim[12][$land[4][21]-1]; else $lim[12]=0; break;
  32. }
  33. if ((($_POST["a"]==4)&&($_POST["b"]!=7))||($_POST["a"]<4))
  34. {
  35. $query="update towns set population=".$town[3].", ".$col."='".$data."', limits='".implode("-", $lim)."' where id=".$town[0];
  36. mysql_query($query, $db_id); header("Location: hall.php?town=".$town[0]);
  37. }
  38. else msg($lang['accessDenied']);
  39. }
  40. else {header('Location: login.php'); die();}
  41. ?>