-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
219 lines (209 loc) · 8.39 KB
/
Copy pathindex.php
File metadata and controls
219 lines (209 loc) · 8.39 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<style>
.year, .month {
padding: 1px 2px;
cursor: pointer;
margin-right: 5px;
}
p {
margin: 4px 0;
}
.selected { background: orange; }
.wrapper{
width: 100%;
margin: 0 auto;
}
.side-left{
width: 49%;
float: left;
margin-right: 1%;
background: skyblue;
}
.side-right{
width: 50%;
float: left;
background: palegreen;
}
.button {
color: #fff;
background-color: #6496c8;
text-shadow: -1px 1px #417cb8;
border: none;
cursor: pointer;
}
.bottom_pad {
margin-bottom: 2px;
}
@media (max-width: 600px) {
body {
font-size: 1.5em;
}
.side-left{
width: 100%;
clear: both;
}
.side-right{
border-top: solid 2px red;
margin-top: 10px;
width: 100%;
clear: both;
}
}
</style>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.year').click(function () {
var me = $(this), year = me.html();
$('.year.selected').removeClass('selected');
me.addClass('selected');
$('.month.selected').removeClass('selected');
$('.month[data=1]').addClass('selected');
$.get('get_data.php?func=year&year='+year, function(data) {
$('#getdata').html(data);
});
});
$('.month').click(function () {
var me = $(this)
, month = me.attr('data')
, year = $('.year.selected').html();
$('.month.selected').removeClass('selected');
me.addClass('selected');
$.get('get_data.php?func=month&year='+year+'&month='+month, function(data) {
$('#getdata').html(data);
});
});
$('#balance_change').click(function () {
var me=$('#balance');
$.get('get_data.php?func=balance_change&balance='+me.val(), function(data) {
$('#getdata').html(data);
me.val('');
});
});
$('.month.selected').click();
$('body').on('click', '.button.add', function() {
var button = $(this)
, date = button.attr('date')
, wrapper = button.parent()
, actiontype = button.attr('actiontype')
, text = "<input placeholder='Название' type='text' class='bottom_pad add_title'/><br/>" +
"<input placeholder='Сумма' type='text' class='bottom_pad add_value'/><br/>" +
"<input class='button add_go' actiontype='"+actiontype+"' date='"+date+"' type='button' value='Добавить'/>";
wrapper.html(text);
});
$('body').on('click', '.button.add_go', function() {
var button = $(this)
, date = button.attr('date')
, wrapper = button.parent()
, actiontype = button.attr('actiontype')
, text = wrapper.find('.add_title').val()
, summa = wrapper.find('.add_value').val();
$.get('get_data.php?func=add_go&date='+date+'&text='+text+'&summa='+summa+'&actiontype='+actiontype, function(data) {
$('#getdata').html(data);
});
});
$('body').on('click', '.button.remove', function() {
var button = $(this)
, id = button.attr('rid')
, actiontype = button.attr('actiontype')
, date = button.attr('date');
$.get('get_data.php?func=remove&id='+id+'&date='+date+'&actiontype='+actiontype, function(data) {
$('#getdata').html(data);
});
});
$('body').on('click', '.button.edit', function() {
var button = $(this)
, id = button.attr('rid')
, date = button.attr('date')
, actiontype = button.attr('actiontype')
, title = button.attr('rtitle')
, summa = button.attr('rsumma')
, wrapper = button.parent()
, text = "<input placeholder='Название' type='text' value='"+title+"' class='bottom_pad edit_title'/><br/>" +
"<input placeholder='Сумма' type='text' value='"+summa+"' class='bottom_pad edit_value'/><br/>" +
"<input class='button edit_go' date='"+date+"' actiontype='"+actiontype+"' rid='"+id+"' type='button' value='Изменить'/>";;
wrapper.html(text);
});
$('body').on('click', '.button.edit_go', function() {
var button = $(this)
, date = button.attr('date')
, id = button.attr('rid')
, wrapper = button.parent()
, actiontype = button.attr('actiontype')
, text = wrapper.find('.edit_title').val()
, summa = wrapper.find('.edit_value').val();
$.get('get_data.php?func=edit_go&id='+id+'&date='+date+'&text='+text+'&summa='+summa+'&actiontype='+actiontype, function(data) {
$('#getdata').html(data);
});
});
$('body').on('click', '.button.fact', function() {
var button = $(this)
, id = button.attr('rid')
, actiontype = button.attr('actiontype')
, date = button.attr('date');
$.get('get_data.php?func=fact&id='+id+'&date='+date+'&actiontype='+actiontype, function(data) {
$('#getdata').html(data);
});
});
});
</script>
</head>
<body>
<?php
function showReg(){
echo "<form action='' method='post'>\n";
echo "<input type='text' name='login' placeholder='login' />\n";
echo "<input type='password' placeholder='pass' name='pass' />\n";
echo "<input type='submit' value='Ok' />\n";
echo "</form></p>\n";
exit;
}
include 'base.php'; # подключим базу
# Проверка регистрации по сессиям
session_start();
if (!isset($_SESSION['login'])) {
if (!isset($_POST['login']) or !isset($_POST['pass'])) showReg();
# Проверяем логин-пароль
$user = htmlspecialchars($_POST['login']);
$pass = md5($_POST['pass']);
$res = mysql_query("SELECT pass,lastseen FROM user WHERE user='".mysql_real_escape_string ($user,$db)."'", $db);
$data = mysql_fetch_array($res);
if (strcmp($data['pass'],$pass) != 0 ) showReg();
mysql_query("UPDATE user SET lastseen=now() WHERE user='".mysql_real_escape_string ($user,$db)."'");
$_SESSION['login'] = $user;
$lastseen = $data['lastseen'];
$_SESSION['lastseen'] = $lastseen;
setcookie(session_name(),session_id(),time()+600);
} else {
$user = $_SESSION['login'];
$lastseen = $_SESSION['lastseen'];
}
?>
<b>Бюджет</b><br/>
<?php
print "Hello $user. Last seen you at: $lastseen <input id='balance' type='text'/> <input id='balance_change' value='Обновить баланс' class='button' type='button'/><br/>";
$date = getdate();
print "<p>";
for ($i=2017; $i<=2025; $i++) {
$selected = '';
if ($i == $date['year']) $selected = 'selected';
print "<span class='year $selected'>$i</span>";
}
print "</p><p>";
$i = ['Янв','Фев','Мар','Апр','Май','Июнь','Июль','Авг','Сен','Окт','Ноя','Дек'];
$j = 0;
foreach($i as $mon) {
$j++;
$selected = '';
if ($j == $date['mon']) $selected = 'selected';
print "<span data='$j' class='month $selected'>$mon</span>";
}
?>
</p>
<div id="getdata">
</div>
</body>
</html>