/
edit_earning.php
66 lines (65 loc) · 2.45 KB
/
edit_earning.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
session_start();
if (!isset($_SESSION['isLogged'])) {
header("Location: login.php");
exit();
}
$errors=array();
$success = false;
require 'earningsDB.php';
?>
<html>
<head>
<meta charset="UTF-8">
<link type="text/css" rel="stylesheet" href="css/style.css">
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="js/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="js/javascript.js"></script>
<title></title>
</head>
<body>
<div class="mymenu">
</div>
<?php if (is_numeric($_GET['earning']) && (new EarningsDB())->isEarningToUser($_SESSION['id'], $_GET['earning'])) : ?>
<?php $earning_data = (new EarningsDB())->getData($_GET['earning']); ?>
<div class="add-container">
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') : ?>
<?php
$earning = new EarningsDB();
$errors = $earning->update($_GET['earning'], $_POST);
?>
<?php if (count($errors) == 0) : ?>
<?php
$success=true;
$earning_data = (new EarningsDB())->getData($_GET['earning']);
?>
<?php endif; ?>
<?php endif; ?>
<form method="post" action="">
<div class="add-item">
<label for="type_earning"> Изберете тип разход</label><br>
<select class="info" name="type_earning">
<option value="salary" <?= $earning_data->type == 'salary' ? 'selected' : '';?>> Заплата </option>
<option value="scholarship" <?= $earning_data->type == 'scholarship' ? 'selected' : '';?>> Стипендия </option>
<option value="inheritance" <?= $earning_data->type == 'inheritance' ? 'selected' : '';?>> Наследство </option>
<option value="other" <?= $earning_data->type == 'other' ? 'selected' : '';?>> Други </option>
</select></br>
<label for="value"> Променете приход </label><br>
<input class="info" type="text" name="value" value="<?= $earning_data->value; ?>"><br>
<?php if (isset($errors['value'])) : ?>
<p>
<?= $errors['value']; ?>
</p>
<?php endif; ?>
<input class="form-submit" type="submit" value="Промени">
<?php if($success): ?>
<p> Успешно променен </p>
<?php endif; ?>
</div>
</form>
</div>
<?php else : ?>
<p>Избрали сте грешен линк!</p>
<?php endif; ?>
</body>
</html>