/
py_user_manager.py
343 lines (270 loc) · 8.7 KB
/
py_user_manager.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!d:/Python27/python.exe -u
# -*- coding: UTF-8 -*-
import MySQLdb
import cgi
import sys
import cgitb
import py_convert_cgi_form_to_array_with_mapping
import py_db
import Cookie
import os
from pyDes import *
#import py_main
cgitb.enable()
def do_insert(param):
#name:user:comname:possst:false:true:possst
param = param.replace('false','0')
param = param.replace('true','1')
param = param.replace('false','0')
param = param.replace('true','1')
user_assistant_u_id=-1
if param.split(":")[5]=="1":
sqlstr='''
select u_id from tbl_users where u_complete_name = '{0}' limit 1
'''.format(param.split(":")[6]);
db=py_db.GetDB()
cur=db.cursor();
cur.execute(sqlstr)
rows = cur.fetchall()
for row in rows:
user_assistant_u_id = row[0]
sqlstr = '''
INSERT INTO `tbl_users`
(`u_name`,`u_pass`,
`u_secretariat_group_link`,`u_complete_name`,
`u_org_post`,`u_active`,
`u_has_assist`,`u_link_to_user_assistant`,
u_direct
)
VALUES
('{0}','{1}',{2},'{3}','{4}',{5},{6},{7},{8}
)
'''.format(
param.split(":")[0],
param.split(":")[1],
param.split(":")[8],
param.split(":")[2],
param.split(":")[3],
param.split(":")[4],
param.split(":")[5],
user_assistant_u_id.__str__(),
param.split(":")[7]
)
print 'Content-Type: text/html; charset=utf-8'
print ''
# print sqlstr
py_db.executesql(sqlstr)
print "1"
def send_tbl_array():
sqlstr="""
SELECT
t1.u_name,
t1.u_complete_name,
t1.u_org_post,
t1.u_active,
(SELECT t2.u_complete_name FROM tbl_users AS t2 WHERE t2.u_id=t1.`u_link_to_user_assistant`),
t1.u_direct
FROM tbl_users AS t1 ORDER BY t1.u_name ASC
"""
db=py_db.GetDB()
cur=db.cursor()
cur.execute(sqlstr)
rows = cur.fetchall()
arr_str=""
for row in rows:
arr_str=arr_str+"||"
for r in row:
arr_str=arr_str+":::"+r.__str__()
print 'Content-Type: text/html; charset=utf-8'
print ''
print arr_str
def sendonedate(uname):
sqlstring='''
select
`u_name`,
`u_pass`,
`u_complete_name`,
`u_org_post`,
`u_active`,
`u_has_assist`,
(select t2.u_complete_name from tbl_users t2 where t2.u_id=t1.u_link_to_user_assistant) as cmname ,
`u_direct`,
u_secretariat_group_link
from tbl_users t1 where u_name = '{0}' limit 1
'''.format(uname)
rows = py_db.executeAndReturnRows(sqlstring)
str=""
for row in rows:
for r in row:
str=str+"::"+r.__str__()
str=str.replace("::None","::")
print 'Content-Type: text/html; charset=utf-8'
print ''
print str
def convert_array_to_string(arr,breaker):
s=""
for r in arr:
s=sr+breaker+r
return s
def checkdupusername(param4):
rows = py_db.executeAndReturnRows('''
select count(*) from tbl_users where u_name='{0}' '''.format(param4))
print 'Content-Type: text/html; charset=utf-8'
print ''
print rows[0][0]
def checkifu_comp_name_is(param5):
rows = py_db.executeAndReturnRows('''
select count(*) from tbl_users where u_complete_name='{0}' '''.format(param5))
print 'Content-Type: text/html; charset=utf-8'
print ''
if rows[0][0]==1:print "0"
if rows[0][0]==0:print "1"
def do_update(param):
param = param.replace('false','0')
param = param.replace('true','1')
param = param.replace('false','0')
param = param.replace('true','1')
user_assistant_u_id=-1
drf=py_db.ifIntNullThen(param.split(":")[6].__str__()).__str__()
d=py_db.do_edit("update","tbl_users",
[["u_name","u_pass","u_secretariat_group_link","u_complete_name",
"u_org_post","u_active","u_has_assist","u_link_to_user_assistant","u_direct"],
[
param.split(":")[0],
param.split(":")[1],
param.split(":")[8],
param.split(":")[2],
param.split(":")[3],
param.split(":")[4],
param.split(":")[5],
drf,
param.split(":")[7]
],
[0,0,0,0,0,0,0,1,0]],
"yes",[
["tbl_users ,u_id,u_complete_name,u_id,{0},u_link_to_user_assistant".format(drf)]]
,"u_name",param.split(":")[0])
i=py_db.executesql(d)
print 'Content-Type: text/html; charset=utf-8'
print ''
print i
#print d
def get_sec_list():
rows = py_db.executeAndReturnRows("""
SELECT DISTINCT(s_group),`s_group_title`
FROM `tbl_secretariat`
"""
);
stt = ""
for row in rows:
stt = stt+":::"+row[0].__str__()+"ppp"+row[1].__str__()
print 'Content-Type: text/html; charset=utf-8'
print ''
print stt
def send_usr_premission_lst(param):
py_db.checkAccessCookie()
py_db.checkuser(5,py_db.username)
sqlstr = """
SELECT
t1.m_id,
t1.m_page_title ,
CASE
(SELECT t2.m_type_of_view
FROM tbl_module_premission t2
WHERE t2.m_user_link = {0} AND t2.m_module_link= t1.`m_id`)
WHEN 1 THEN "true"
ELSE "false"
END AS sss
FROM tbl_modules t1
""".format( py_db.get_userID_from_uname(param) )
rows = py_db.executeAndReturnRows(sqlstr)
str = ""
for row in rows:
str = str+"::"+row[0].__str__()+"pp"+row[1].__str__()+"pp"+row[2].__str__()
print 'Content-Type: text/html; charset=utf-8'
print ''
print str
def updateusrprm(param,uid):
py_db.checkAccessCookie()
py_db.checkuser(5,py_db.username)
__form = cgi.FieldStorage()
sel_uid = py_db.get_userID_from_uname(uid)
sd=param.split("bbb")
py_db.executesql("delete from tbl_module_premission where m_user_link = "+sel_uid)
for row in sd:
s="3"
if (row.split("=~")[1].__str__())== "true":s="1"
py_db.executesql("""
insert into tbl_module_premission
(`m_module_link`,`m_user_link`,`m_type_of_view`)
values
({0},{1},{2})
""".format(row.split("=~")[0].__str__(),
sel_uid,s))
print 'Content-Type: text/html; charset=utf-8'
print ''
print "1"
def sendusersum():
py_db.checkAccessCookie()
sqlstr = """
SELECT COUNT(*) FROM tbl_inbox WHERE `i_position`=1 AND `i_active_user_link`={0}
""".format(py_db.user_id)
row = py_db.executeAndReturnRows(sqlstr)
print 'Content-Type: text/html; charset=utf-8'
print ''
print row[0][0]
def checkif_doc_scanned(_param14):
row = py_db.executeAndReturnRows("select lp_address from tbl_letters_papers where lp_type=2 and lp_link_to_letters="+_param14)
str="0"
if len(row) <> 0: str=row[0][0]
print 'Content-Type: text/html; charset=utf-8'
print ''
print str
def get_negahban_list():
rows = py_db.executeAndReturnRows("SELECT * FROM `tbl_users` WHERE `u_org_post` LIKE '%نگهبان%'")
s=""
i=0
for row in rows:
if i==0:
s=row[0].__str__()+"="+row[4].__str__()
else:
s=s+"vfdd"+row[0].__str__()+"="+row[4].__str__()
i+=1
print 'Content-Type: text/html; charset=utf-8'
print ''
print s
#try:
form = cgi.FieldStorage()
param =form.getvalue("hstr","-1")
param2=form.getvalue("pssws","-1")
param3=form.getvalue("cllon","-1")
param4=form.getvalue("chkdup","-1")
param5=form.getvalue("chkexis","-1")
param6=form.getvalue("edithstr","-1")
param7=form.getvalue("unamsse","-1")
param8=form.getvalue("out","-1")
param9=form.getvalue("seclst","-1")
param10=form.getvalue("usprm","-1")
param11=form.getvalue("urpd","-1")
param12=form.getvalue("uid","-1")
param13=form.getvalue("i","-1")
param14=form.getvalue("checkscanned","-1")
param15=form.getvalue("negahban","-1")
if param !="-1":do_insert(param)
if param2 !="-1":send_tbl_array()
if param3 !="-1":sendonedate(param3)
if param4 !="-1":checkdupusername(param4)
if param5 !="-1":checkifu_comp_name_is(param5)
if param6 !="-1":do_update(param6)
if param7 !="-1":getFullName(param7)
if param8 !="-1":logout()
if param9 !="-1":get_sec_list()
if param10 != "-1":send_usr_premission_lst(param10)
if param11 != "-1" and param12 != "-1" :updateusrprm(param11,param12)
if param13 !="-1":sendusersum();
if param14!="-1":checkif_doc_scanned(param14)
if param15!="-1":get_negahban_list()
#except Exception:
# print 'Content-Type: text/html; charset=utf-8'
# print ''
# print Exception.__str__