-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgebaeude.php
52 lines (45 loc) · 1.87 KB
/
gebaeude.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
* MIT Licence
* Copyright (c) 2023 Simon Frankenberger
*
* Please see LICENCE.md for complete licence text.
*/
require_once __DIR__ . '/../include/functions.inc.php';
require_once __DIR__ . '/../include/database.class.php';
ob_start();
requireLogin();
restrictSitter('Gebaeude');
$was = getOrDefault($_POST, 'was', 0);
$data = Database::getInstance()->getPlayerMoneyAndBuildingLevelsAndPointsAndEinnahmenZinsen($_SESSION['blm_user']);
requireEntryFound($data, '/?p=gebaeude', 112, __LINE__);
$buildingData = calculateBuildingDataForPlayer($was, $data);
if ($data['Geld'] < $buildingData['Kosten'] || !buildingRequirementsMet($was, $data)) {
redirectTo('/?p=gebaeude', 112, __LINE__);
}
Database::getInstance()->begin();
if (Database::getInstance()->createTableEntry(Database::TABLE_JOBS, array(
'finished' => date('Y-m-d H:i:s', time() + $buildingData['Dauer']),
'user_id' => $_SESSION['blm_user'],
'item' => (job_type_factor * job_type_building) + $was,
'cost' => $buildingData['Kosten']
)) == 0) {
Database::getInstance()->rollBack();
redirectTo(sprintf('/?p=gebaeude&was=%d', $was), 141, __LINE__);
}
if (Database::getInstance()->updateTableEntryCalculate(Database::TABLE_USERS, $_SESSION['blm_user'], array(
'Geld' => -$buildingData['Kosten']
), array(
'Geld >= :whr0' => $buildingData['Kosten']
)) == 0) {
Database::getInstance()->rollBack();
redirectTo(sprintf('/?p=gebaeude&was=%d', $was), 142, __LINE__);
}
if (Database::getInstance()->updateTableEntryCalculate(Database::TABLE_STATISTICS, null,
array('AusgabenGebaeude' => $buildingData['Kosten']),
array('user_id = :whr0' => $_SESSION['blm_user'])) == 0) {
Database::getInstance()->rollBack();
redirectTo('/?p=gebaeude', 142, __LINE__);
}
Database::getInstance()->commit();
redirectTo('/?p=gebaeude', 207, sprintf('g%s', $was));