/
staff_al.py
205 lines (193 loc) · 7.72 KB
/
staff_al.py
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
import cgi
import sqlite3
import datetime
import os
from http.cookies import *
from datetime import timedelta, date
#http://localhost:8080/test/cgi-bin/form.py
try:
global con
global cur
con=sqlite3.connect("F:\Tom\staffapp.db")
cur=con.cursor()
global ht1
global ht3
global id
global id1
global type
global dt
global fd
global td
global approv
global reason
fd=''
td=''
if 'HTTP_COOKIE' in os.environ:
cookie_string=os.environ.get('HTTP_COOKIE')
ck=SimpleCookie()
ck.load(cookie_string)
if 'username' in cookie_string:
id=ck['username'].value
else:
id="Nil"
else:
id="None"
form=cgi.FieldStorage()
print("Content-Type:text/html\n\n")
def daterange(start_date, end_date):
for n in range(int ((end_date - start_date).days)):
yield start_date + timedelta(n)
cur.execute('select name from staff_det where id='+str(id))
nm=cur.fetchall()[0][0]
#print(nm)
cur.execute('select ldays from staff_det where id='+str(id))
lrem=cur.fetchall()[0][0]
cur.execute('select ccl from staff_det where id='+str(id))
ccl=cur.fetchall()[0][0]
#print(lrem)
leave=15+int(ccl)-int(lrem)
if leave<0:
leave='NA'
ht1='''
<html>
<head>
<link rel="icon" href="../favicon.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="../style.css" />
<title>Leave Form</title>
<table width="100%" bgcolor="black">
<tr>
<td width="10%"><img src="../logo.jpg" alt="img" height="130" width="148" ></td>
<td width="90%"><img src="../clg4.jpg" alt="img" height="130" width="1170" ></td>
</tr>
</table>
</head>
<body>
<table width="100%" class="top">
<tr>
<td>
<td align="center">
<object data="../'''+str(id)+'''.JPG" class="profile">
<img src="../100.JPG" alt="No image" class="profile"></object>
</td>
<td>'''+str(nm)+''' | 
Leave(s) remaining - '''+str(leave)+'''</td>
<td align="right"> 
<a href="notify2.py">Leave History </a>| 
<a href="pwd_ch.py">Change Password </a>| 
<a href="stafflogin.py">Logout</a> </td>
</tr>
</table>
<div class="tpmenu">
<ul>
<li>
<a href="staff_al.py">AL</a> 
<a href="staff_ccl.py">CCL</a> 
<a href="form.py">CL</a> 
<a href="staff_half.py">HDL</a> 
<a href="staff_mat.py">ML</a> 
<a href="staff_od.py">OD</a> 
</li>
</ul>
<div>
<table align="center" height=55>
<tr>
<td style="font-family:Tahoma;font-size:24px;">Academic Leave</td>
</tr>
</table>
<form method="POST">
<table align="Center" class="lf1">
<tr>
<td><b> Id</b></td>
<td>{id}</td>
</tr>
<tr>
<td><b> Date</b></td>
<td>From <input type="date" name="fromdt" name="fromdt"
required name="fromdt" placeholder="From date" min="'''+str(datetime.date.today())+'''"/></td>
</tr>
<td></td>
<td>To <input type="date" name="todt"
required name="todt" name="todt" placeholder="To date" min="'''+str(datetime.date.today())+'''"/></td>
<tr>
<td><b> Reason</b></td>
<td><pre><textarea maxlength="100" name="r" required rows="3" cols="35" placeholder="Enter reason (max. characters = 100)"></textarea> </pre></td>
</tr>
<tr><td>
I confirm the details </td><td><input type="checkbox" name="agree" required name="agree">Yes
</td></tr>
<tr><td></td><td> <input style="font-size:15px;" type="submit" name="submit" value="Get Substitution Form" /></td></tr>
</table>
</form>
</body><br><br><br>
<footer>
<table style="width:100%;" align="center">
<tr>
<td style="width:33%;text-align:center;font-size:18px;">3-5-1026, Narayanguda, Hyderabad, Telangana -500029</td>
<td style="width:33%;text-align:center;font-size:18px;">   Copyright © KMIT</td>
<td style="width:33%;text-align:center;font-size:18px;">   Website: <a href="http://www.kmit.in/" style="text-decoration:none"/>kmit.in</td>
</tr>
</table>
</footer>
</html>
'''
print(ht1.format(**locals()))
if "submit" in form:
cur.execute('select role from staff_det where id='+str(id))
role=cur.fetchone()[0]
approv=0
if role=="co-ord":
approv=1
f=form.getvalue('fromdt').split('-')
t=form.getvalue('todt').split('-')
fd=datetime.date(int(f[0]),int(f[1]),int(f[2]))
td=datetime.date(int(t[0]),int(t[1]),int(t[2]))
cur.execute('select fdt,tdt from leave_tab where id='+str(id)+' and type="academic" and approv>2 order by fdt')
data=cur.fetchall()
day1=0
if len(data)!=0:
f1=data[-1][0].split('-')
t1=data[-1][1].split('-')
fd1=datetime.date(int(f1[0]),int(f1[1]),int(f1[2]))
td1=datetime.date(int(t1[0]),int(t1[1]),int(t1[2]))
#print(data)
q1=fd1
while(q1<=td1): #made changes regarding sunday
if(q1.isoweekday()==7):
day1=day1+1
q1=q1+datetime.timedelta(1)
if fd.month==td.month:
if (fd.month!=fd1.month and fd.month!=td1.month):
ndays=(td-fd).days-day1
else:
ndays=(td-fd).days+1-day1
else:
if fd.month!=fd1.month and fd.month!=td1.month:
ndays=(td-fd).days-1-day1
else:
ndays=(td-fd).days-day1
else:
q1=fd
while(q1<=td): #made changes regarding sunday
if(q1.isoweekday()==7):
day1=day1+1
q1=q1+datetime.timedelta(1)
if td.month==fd.month:
ndays=(td-fd).days-day1
else:
ndays=(td-fd).days-1-day1
cur.execute('insert into leave_tab values(?,?,?,?,?,?,?,?,?,?)',(str(id),str(datetime.date.today()),'academic',str(form.getvalue('fromdt')),str(form.getvalue('todt')),approv,str(form.getvalue('r')),0,0,ndays))
con.commit()
ht='''
<html>
<body onload="window.location='http://localhost:8080/test/cgi-bin/form2.py'"></body>
</html>
'''
print(ht)
except Exception as e:
html='''
<html>
<body onload="window.location='http://localhost:8080/test/cgi-bin/staff_err.py'"></body>
</html>
'''
#print(html.format(**locals()))
print(e)