-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclock.php
130 lines (113 loc) · 3.6 KB
/
clock.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
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
<?
require(__DIR__.'/lib/utilities.php');
check_auth();
$rs = db()->query('SELECT `time_start`, `time_end` FROM `clock` WHERE `uid`=:uid AND `date_work`=:date_work', $_SESSION['uid'], date('Y-m-d'));
$time_clock_in = $rs->time_start;
$time_clock_out = $rs->time_end;
?>
<!DOCTYPE html>
<html>
<head>
<title>打卡</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="css/main.css">
<style>
.btn-xl {
display: none;
margin-top: 1.5rem;
padding: 0.5rem 0.5rem;
font-size: 4vw;
border-radius: 10px;
width: 20%;
}
.clock_time {
font-size: 2.5vw;
}
#clock_out_btn {
margin-top: 1rem;
}
@media screen and (max-width: 600px) {
.btn-xl {
margin-top: 1rem;
width: 90%;
padding: 1rem 1rem;
font-size: 10vw;
}
.clock_time {
font-size: 5vw;
}
#nav_mobile {
margin-top: 4rem;
}
}
</style>
</head>
<body>
<?php include 'nav.php'; ?>
<h1>打卡</h1>
<button id="clock_in_btn" class="btn btn-info btn-xl">上班</button>
<br>
<button id="clock_out_btn" class="btn btn-success btn-xl">下班</button>
<?php include 'nav_mobile.php'; ?>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="js/bootbox.min.js"></script>
<script src="js/utilities.js"></script>
<script>
var timeClockIn = '<?=$time_clock_in?>';
var timeClockOut = '<?=$time_clock_out?>';
//------------------------------------------------------------------------------
if (timeClockIn!='') {
disableButton($('#clock_in_btn'), timeClockIn, '上班');
}
if (timeClockOut!='') {
disableButton($('#clock_out_btn'), timeClockOut, '下班');
}
$('#clock_in_btn').fadeIn();
$('#clock_out_btn').fadeIn();
checkIfHoliday();
//------------------------------------------------------------------------------
$('#clock_in_btn').on('click', function(){
ajax('action/action_clock.php', {
action: 'clock_in',
}, function(timeClockIn){
bootbox.alert('完成打卡: '+timeClockIn);
disableButton($('#clock_in_btn'), timeClockIn, '上班');
});
});
$('#clock_out_btn').on('click', function(){
ajax('action/action_clock.php', {
action: 'clock_out',
}, function(timeClockOut){
bootbox.alert('完成打卡: '+timeClockOut);
disableButton($('#clock_out_btn'), timeClockOut, '下班');
});
});
function checkIfHoliday(){
ajax('action/action_holiday.php', {
action: 'check_if_holiday',
}, function(holidayName){
if (holidayName!='') {
bootbox.alert('恭喜! 今天放假: '+holidayName);
disableButton($('#clock_in_btn'));
disableButton($('#clock_out_btn'));
}
});
return;
}
function disableButton(button, clockTime=null, complete='上班'){
button.attr('disabled', '');
if (clockTime) {
button.html(complete+'<label class="clock_time"> '+timeSlice(clockTime)+'</label>');
}
return;
}
function timeSlice(time){
return time.toString().slice(11, 16);
}
</script>
</body>
</html>