<%
function DocInfo_QryStr
  'strqry="SELECT  UNIQUE_ID, DOCUMENT_TYPE AS [Document Type],  PROPERTY_ADDRESS AS [Property Address], " & _
   '              " POSTAL_CODE AS [Postal Code], LAST_NAME AS [Last Name], " & _
    '             " FIRST_NAME AS [First Name], Left([Document_description],50) AS Description,  DOCUMENT_LOCATION AS " & _
     '            " [Document Location],  REGISTRATION_NUMBER AS [Registration Number],  DOCUMENT_DATE AS [Document Date], " & _
      '           " COUNCIL_APPROVAL AS [Council Approval] " & _
       '          " FROM DLTS_DOCUMENT_DETAIL "
         strqry="SELECT Unique_Id, DOCUMENT_TYPE, PROPERTY_ADDRESS, " & _
                 " POSTAL_CODE, LAST_NAME," & _
                 " FIRST_NAME, Document_description As Description, DOCUMENT_LOCATION," & _
                 " REGISTRATION_NUMBER, DOCUMENT_DATE, " & _
                 " COUNCIL_APPROVAL" & _
                 " FROM DLTS_DOCUMENT_DETAIL "
  docinfo_qrystr=strqry
end function
sub MainMenu
%>
<center>
<table border="0" cellpadding="0" cellspacing="0" width="500">
    <tr>
        <td align="center" bgcolor="#ffffff"><font color="#000000" size="5" face="arial, sans-serif">
        <b><u>Document Management System</u></b></td>
    </tr>
</table>
<br>
<% if session("admin") then
      tbsz=300
   else
      tbsz=200
   end if 
%>
<table border="0" cellpadding="0" cellspacing="0" width="<% =tbsz %>">
    <tr>
        <td align="center" width="100" bgcolor="#000000"
        height="20" onmouseover="this.bgColor='#772299';" onmouseout="this.bgColor='#000000';"><a href="docinfo_search.asp"><font
        color="#FFFFFF" size="1" face="arial"><b>Find Document</b></font></a></td>
    <% if session("admin")=0 then %>
    <td align="center" width="100" bgcolor="#000000"
        height="10" onmouseover="this.bgColor='#772299';" onmouseout="this.bgColor='#000000';"><a href="docinfo_login.asp"><font color="#FFFFFF"
        size="1" face="arial"><b>Login Admin </b></font></a></td>
    <% end if %>
       <% if session("admin")=1 then %>
            <td align="center" width="100" bgcolor="#000000"
             height="10" onmouseover="this.bgColor='#772299';" onmouseout="this.bgColor='#000000';"><a href="docinfo_edit.asp"><font color="#FFFFFF"
             size="1" face="arial"><b>Add New </b></font></a></td>
       <% end if %>
    </tr>
</table>
</center>
<%
end sub
function RecExist(strqry)
      set rs=server.createobject("adodb.recordset") 
      rs.open strqry, strconnection
      if rs.eof then
         RecExist=0
      else
         RecExist=1
      end if
      rs.close
      set rs=nothing
end function 
function RunQry(strqry)
      recAff=0
      set cnn=server.createobject("adodb.connection") 
      cnn.open strconnection
      cnn.execute strqry, recAff
      if recaff<>0 then
         runqry=1
      else
         runqry=0
      end if
      cnn.close
      set cnn=nothing
end function 
Function Addnew_Street (dt)
    dim rs 
    dt=ucase(trim(dt))
    strqry="Select * from DLTS_LKP_STREET WHERE street='" & dt & "'"
   
    set rs=server.createobject("adodb.recordset")
    rs.open strqry, strconnection, 2, 3
    if rs.eof then
       rs.addnew
       rs("Street")=dt
       rs("Municipality")="MARKHAM"
       rs.update
    end if
    rs.close         
    set rs=nothing
End function 
Function Addnew_DocType_Data (dt)
    dim rs 
    dt=ucase(trim(dt))
    strqry="Select * From DLTS_LKP_DOCUMENT_TYPE " & _
           " Where Document_Type_Description='" & ucase(dt) & "'"
    set rs=server.createobject("adodb.recordset")
    rs.open strqry, strconnection, 2, 3
    if rs.eof then
       set rs_dtid=server.createobject("adodb.recordset")
  
       strqry="Select (Max(document_type_id)+1) as new_dtid From DLTS_LKP_DOCUMENT_TYPE "
       rs_dtid.open  strqry, strconnection, 2, 3
       new_dtid=1 
       if isnumeric(rs_dtid(0)) then
          new_dtid=rs_dtid(0).value
       end if
       set rs_dtid=nothing       
       rs.addnew
       rs("document_type_id")=new_dtid
       rs("dococument_type_description")=ucase(dt)
       rs.update
       rs.close         
       set rs=nothing
    end if
End function 
function Update_DocInfo_Data(strqry, data, noFld, updtAs)
    dim rs 
    dim rs_uid
    set rs=server.createobject("adodb.recordset")
    rs.open strqry, strconnection, 2, 3
    if lcase(updtAs)="edit" then
       if not rs.eof then
          for i=0 to nofld
              if isdate(data(i)) then
                 rs(i)=datevalue(data(i))
              else
                 rs(i)=data(i)
              end if
          next
          rs.update
          updatedata="Data has been updated successfully"
       else
         updateData="Due to some error data could not be updated."
       end if
    end if
    if lcase(updtAs)="new" then
       set rs_uid=server.createobject("adodb.recordset")
  
       strqry="Select (Max(unique_id)+1) as new_unqid From DLTS_DOCUMENT_DETAIL "
       rs_uid.open strqry, strconnection, 2, 3
       newuid=rs_uid(0).value
       if not isnumeric(newuid) then
          data(10)=1
       else        
          data(10)=newuid
       end if
       rs_uid.close
       set rs_uid=nothing
       rs.addnew
       for i=0 to nofld
           if isdate(data(i)) then
              rs(i)=datevalue(data(i))
           else
              rs(i)=data(i)
           end if
       next
       rs.update
       updatedata="New data has been added successfully"
    end if
    rs.close
    set rs=nothing
end function 
%>