-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadmin_show_customers.py
executable file
·70 lines (70 loc) · 2.42 KB
/
admin_show_customers.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
#!/usr/bin/python
import config
import customer_details
import no_found
def show_customers(bit):
conn,cursor=config.connect_to_database()
sql="select * from customers where hasAcc='%s'"%bit
try:
cursor.execute(sql)
results=cursor.fetchall()
row_num=cursor.rowcount
bit=int(bit)
if bit==0:
flag="New customers"
cust_id="new_customers"
refresh_btn="new_customers_refresh"
elif bit==1:
flag="Approved customers"
cust_id="approved_customers"
refresh_btn="approved_customers_refresh"
elif bit==-1:
flag="Rejected customers"
cust_id="rejected_customers"
refresh_btn="rejected_customers_refresh"
else:
flag="New customers"
cust_id="new_customers"
refresh_btn="new_customers_refresh"
if int(row_num)==0:
cust=no_found.no_found("No "+flag)
else:
cust="""<div class="row" style="margin:20px;"><caption><h3>%s <button class="btn btn-primary" id="%s"><span class="glyphicon glyphicon-refresh"></span></button></h3></caption><table class="customerTable table-striped"><tr><td align="left">Index no.</td><td align="left">Username</td><td align="left">Full Name</td><td align="left">Email</td><td align="left">Contact no.</td></tr>"""%(flag,refresh_btn)
i=1
for row in results:
cid=str(row[0])
username=row[1]
fname=row[2].capitalize()
lname=row[3].capitalize()
middle_name=row[12].capitalize()
email=row[4]
contact=row[6]
full_name="%s %s %s"%(fname,middle_name,lname)
cust+="""<div><tr class='clickable-row' id='%s' style="cursor:pointer;"><td align="left">%s</td><td align="left">%s</td><td align="left">%s</td><td align="left">%s</td><td align="left">%s</td></tr></div>"""%(cid,i,username,full_name,email,contact)
i+=1
cust+="</table></div>"
cust+="""<script>
var get_table_of_details=function(flag)
{
$.ajax({
type: 'POST',
url: 'admin_interface.py',
data: 'flag='+flag,
success : function (data)
{
$("#show_here").empty();
$("#show_here").html(data);
}
});
};
$("#%s").click(function(){
get_table_of_details("%s");
});
$(".clickable-row").click(function() {
var c_id=$(this).attr("id");
$(this).append("<form action='customer_profile.php' id='show_customer' method='post'><input type='text' name='customer_id' value='"+c_id+"' /></form>");$("#show_customer").submit();
});
</script>"""%(refresh_btn,cust_id)
return cust
except:
return "-1"