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"      
import cgitb
import py_db
import py_convert_cgi_form_to_array_with_mapping
cgitb.enable()




py_db.checkAccessCookie()



print 'Content-Type: text/html; charset=utf-8'
print ''


db = py_db.GetDB()


form = cgi.FieldStorage()

dt=form.getvalue("id")
dm=form.getvalue("name")

if py_db.checkuser("10",py_db.username)[3]<>3:
    cur = db.cursor()
    cur.execute("insert into tbl_variables (dsc_name,dsc_type) values ('"+dm+"','"+dt+"')")
    db.commit()
    db.close()
print "1"
import cgi
import sys
import cgitb
import py_convert_cgi_form_to_array_with_mapping
import py_db
import Cookie
from datetime import *
import os
from pyDes import *



cgitb.enable()

py_db.checkAccessCookie()
py_db.checkuser(6,py_db.username)


def send_users_list():
    sql='''
      SELECT
      u_id,
u_complete_name,
u_org_post,
u_has_assist,
(SELECT `u_complete_name` FROM `tbl_users` t2 WHERE t2.u_id= t1.u_link_to_user_assistant) AS sssdsd

 FROM tbl_users t1
 
 where u_id not in ( select uh_user_id from tbl_users_hidden )
 and u_id in (SELECT DISTINCT t1.`urgm_link_to_users` FROM tbl_users_related_groups_member t1 WHERE t1.urgm_link_to_groups IN (SELECT DISTINCT t2.urgm_link_to_groups FROM tbl_users_related_groups_member t2 WHERE t2.`urgm_link_to_users`={0}))
# -*- coding: UTF-8 -*-
import MySQLdb
import cgi
import sys
import cgitb
import py_convert_cgi_form_to_array_with_mapping
import py_db
cgitb.enable()


print 'Content-Type: text/html; charset=utf-8'
print ''


py_db.checkAccessCookie()
py_db.checkuser("2",py_db.username)


db = py_db.GetDB()
form = cgi.FieldStorage()
dt=form.getvalue("id")
dta=form.getvalue("tpy","xcc")
cur = db.cursor()
sqlstr = """
SELECT l_id,
(SELECT dsc_name FROM tbl_variables WHERE dsc_id = l_creator_company_link),
(SELECT dsc_name FROM tbl_variables WHERE dsc_id = l_creator_person_link),
l_type_link,
l_letter_to_link,
(SELECT dsc_name FROM tbl_variables WHERE dsc_id = l_type_of_recieve_link),
l_date_of_create,
    htmlstr=""
    for line in f:
        htmlstr=htmlstr+line
### redirecting to LOGin PaGE  .    
    print 'Content-Type: text/html; charset=utf-8'
    print ''    
    print htmlstr
    exit()
###########################################################
# after true login it is to check module premission
#_________________________________________________________
form = cgi.FieldStorage()
moduleID=form.getvalue("mid","-1")
if moduleID=="--1":logout();
if moduleID=="-1":exit
page=py_db.checkuser(moduleID, py_db.username)
#insert_to_log()
print 'Content-Type: text/html; charset=utf-8'
print ''
#print page
if page[3]==3:
    htmlstr=render_page("frm_block.html","عدم دسترسی")
    htmlstrtemp="";
    f=open("frm_template_page.html",'r')
    for line in f:
        htmlstrtemp=htmlstrtemp+line
    htmlstrtemp=htmlstrtemp.replace("##content",htmlstr)
    htmlstrtemp=htmlstrtemp.replace("##menu","sssssss")
    fullname=py_db.getFullName(py_db.username);
    htmlstrtemp=htmlstrtemp.replace("#user name",fullname )