def create_edit_script(unhashed_objs,fieldID):
    #unhashed_objs = py_db.unhash_decode_ord_conv_to_arr(unhashed_objs)
    
    #print HV
    #print unhashed_objs
    gtkkk = get_table_and_keyfield_from_obj_id(unhashed_objs)

    items = get_items_value_from_tbl(fieldID,gtkkk[0],gtkkk[1],unhashed_objs)
    #print items
    i=""
    fff =  ord_validation_mapping(py_db.encode(fieldID))
    #[u'\u0645\u062d\u0645\u062f \u0631\u0636\u0627', u'soccc_name', 'obj_1', 1]
    for it in items:
       i=i+create_value_by_element_type(it)
    i="<script type='text/javascript'>var fff_key='{1}';{0}</script>".format(i,fff)
    return i
def read_form_from_database_and_generate_html_with_objects_map(form_id):
# in this line i get form name for making form tag
    f_english_form_name = py_db.executeAndReturnRows("select f_english_form_name from tbl_forms where f_id={0}".format(form_id))[0][0].__str__()
# we get form items right now
    sql = """
    select
    fi_id,
    fi_name,
    fi_object_type,
    fi_if_radio_group_name,
    fi_if_mask_maskstring,
    fi_if_3_4_5_link_value,
    fi_not_null,
    fi_check_value_between,
    fi_check_value_from_to,
    fi_if_4_link_tbl_name,
    fi_link_to_form_name,
    fi_order,
    fi_default_value,
    fi_length,
    fi_exp
    from tbl_form_items where fi_link_to_form_name = (select f_id from tbl_forms where f_id={0}) order by fi_order
    """.format(form_id)
    rows = py_db.executeAndReturnRows(sql)
#this is link for sending data to server
# i set function name for js post then i will write other nec code
    formhtml=''
# generating vars
    script=""
    index=0
    objs_mapping=[]
# here we go making form items
#==============================================================
#==============================================================
#==============================================================
    for row in rows:
        if row[2] <> 7 and row[2] <> 8 :
            index=index+1
#__________________________________________________________________________________

        obj_map=[]
        obj_map.append(row[0])
        obj_map.append("obj_"+index.__str__())
        objs_mapping.append(obj_map)       
# Generating Simple Tags ---------------------------------------------------------------------------------------
        formhtml=formhtml+"<tr>"
        exp = ""
# getting if default value has or not
        def_val = " "
        if row[12]!="-1":
            def_val = " value='{0}'".format(row[12])
#________________________________
        if row[14] !=None:exp=row[14] 
# handling if simple textbox 
        if row[2] == 1:
            if row[4]!=None:
                script+='$("#obj_{0}").mask("{1}");'.format(index,row[4])
            formhtml += """<td class='td_lbls'>{1}</td><td><input type="text" name="obj_{0}" id="obj_{0}"  {3}/></td><td>{2}</td>""".format(index,row[1],exp,def_val)
# handling if simple textbox 
        if row[2] == 6:
            script += '$("#obj_{0}").mask("{1}");'.format(index,"1399/99/99")
            formhtml += """<td class='td_lbls'>{1}</td><td><input type="text" name="obj_{0}" id="obj_{0}"   {3}/> </td><td>{2}</td>""".format(index,row[1],exp,def_val)
    
 # handling if simple textbox 
        if row[2] == 2:
            formhtml += """<td class='td_lbls'>{1}</td><td><input type="text" name="obj_{0}" id="obj_{0}"   {3}/> </td><td>{2}</td>""".format(index,row[1],exp,def_val)
            
#______________________________
        if row[2]==3:
            def_val = ""
            if row[12]=="checked":
                def_val = ' checked="checked"'
            formhtml += """<td class='td_lbls'>{2}</td><td><input id="obj_{0}" name="obj_{0}"  type="checkbox" {1}  /> </td><td>{3}</td>""".format(index,def_val,row[1],exp)   

#______________________________
        if row[2]==4:
            def_val = ""
            if row[12]=="checked":
                def_val = ' checked="checked"'
                
            if row[3]!=None:
                def_val += ' group="'+row[3]+'"'

            formhtml += """<td class='td_lbls'>{2}</td><td><input name="obj_{0}"  id="obj_{0}" type="radio"  {1}   /> </td><td>{3}</td>""".format(index,def_val,row[1],exp)   
 #______________________________       
        if row[2]==5:
            ssql = "select {0},{1} from {2} {3}".format(
                row[9].split(":::")[1],
                row[9].split(":::")[2],
                row[9].split(":::")[0],
                row[9].split(":::")[3])
            ssql = ssql.replace("//1//",py_login.get_user_id())
            ssql = ssql.replace("//2//",py_login.get_socc_id())
            
            rowss = py_db.executeAndReturnRows(ssql)
            dd=""
            for r in rowss:
                dd+=' <option value="{0}">{1}</option>'.format(r[1],r[0])
                formhtml +="""  <td>{2}</td><td>  <select name="obj_{0}"  id="obj_{0}"> {1}  </select></td><td>{3}</td>  """.format(index,dd,row[1],exp)   
        
        formhtml=formhtml+"</tr>"
    
#--------------------Scripts ---------------------
        if row[2]==2:
            #// checking if text is integer
            script+= ' $("#obj_{0}").ForceNumericOnly();'.format(index)
        if row[6]==1:
            #checking if it is empty or not
            pass
#==============================================================
#==============================================================
#==============================================================
#here i make form
# i put hv as validation for hacking purposes
    formhtml = ' <a href="#" onclick="submit_frm_'+f_english_form_name+'()">Post</a>  '+formhtml

    HV = ord_validation_mapping( py_db.encode(conv_array_to_str(objs_mapping)))
    #print HV
    script = '   <script type="text/javascript">  {0}  </script>'.format(script)
    formhtml= create_form_html( HV,f_english_form_name,formhtml+script)
    htm = []
    htm.append(formhtml)

    htm.append(objs_mapping)
    return htm
def create_grid(form_id,view_type):
    f_table_name = py_db.executeAndReturnRows("select f_table_name from tbl_forms where f_id={0}".format(form_id))[0][0].__str__()
    sqls = "select f_key_field from tbl_forms where f_id={0}".format(form_id)
    #print sqls
    f_key_field =  py_db.executeAndReturnRows(sqls)[0][0].__str__()
    rows = py_db.executeAndReturnRows("select `fgd_link_to_form`,`fgd_field_name`,`fgd_title` from  tbl_form_grid_dictionary where fgd_link_to_form={0} order by fgd_id ".format(form_id))
    if len(rows)==0: return ""
    th = ""
    field_names = ""
    field_title = ""
    i=0
    for row in rows:
        i=i+1
        th = th+"<th>{0}</th>".format(row[2])
        if i==1: field_names = row[1].__str__()
        else : field_names = field_names+","+row[1].__str__()
       # if i==1: field_title = row[2].__str__()
       # else : field_title = field_title+","+row[2].__str__()
    sqls = "select {2} as key_fieeld,{0} from {1} limit 20".format(field_names,f_table_name,f_key_field)
   
    rows = py_db.executeAndReturnRows(sqls)
    tr = ""
    _tr=""
    __tr=""

    for row in rows:
        __tr=""
        i=0
        for ro in row:
            if i!=0:   #this line is for making delete and update button becuase it need primary fields
                __tr = __tr+"<td>{0}</td>".format(ro)
            i=i+1 
        hashid = form_id.__str__()+"?(xs)@"+row[0].__str__()+"?(xs)@"+ck[2].__str__()
        hashid = ord_validation_mapping(py_db.encode(hashid))
        __tr=__tr+"""<td>
        <a href="#" onclick="showModal('py_page_loader.py?idsf={0}')">Edit</a>
        </td><td><a href="#" onclick="__del('{0}')">Delete</a></td>
        
        """.format(hashid)
        _tr = "<tr>"+__tr+"</tr>"
        tr = tr+_tr
        # del and edit encode link is   table_id + key_field + user_id

    
    
    tbl = """
    <table class="bordered">
    <thead><tr>{0}</tr><thead>
    <tbody>{1}</tbody>
    </table>
    
    
    <script type="text/javascript">
 
 
    
    </script>
    
    
    
    """.format(th,tr)
    
    return tbl