Do not let any software impress you!

Only let it convince your intellect.
Slider img 1
Do not look for a business paradise!

It is a waste of time.
Slider img 2
Only yourself can push you uphill.

There is no easy road to prizes.
Slider img 3
Productivity is the name of the game.

And you have to conquer it.
Slider img 4
As long as you understand it,

you will start to build your know-how.
Slider img 5
We can help with that.

We have the tools and the method.
Slider img 6

Keep Proto
Document
Description
Characterization

Title : Document

Toolbars

call CloseForm(True)
call CloseForm(False)

Buttons

Fields


Keep Proto (AU_DOC.KEEPPROTO)
Document (AU_DOC.FILE_NAME)
Description (AU_DOC.DESCR)
Characterization (AU_DOC_RELTYPE2.AU_DOC_RELTYPE2_D)


AutoScript

lib

{===================================== Panels_Start ===================================}

proc Panels_Start()
return
     start_sql "HIST" "KOSMOS"
         SELECT AU_DOC_EVENT.*, AU_USER.UNAME FROM AU_DOC_EVENT, AU_USER
         WHERE (AU_DOC_EVENT.AU_USER = AU_USER.AU_USER)
         AND (AU_DOC_EVENT.AU_DOC = :DOC)
         ORDER BY AU_DOC_EVENT.EDATE
     end_sql
     q0 = QueryByName("HIST")
     call TSetParam(q0,"DOC",0)
     call TPrepare(q0)
end

{==================================== Form_Start ==================================}

proc Form_Start()

     f = TopForm()
     fprev = PreviousForm(f)
     flib = FByResName("AU_ALLFILES.FM")
     fdoc = FByResName("AU_FILES.FM")

     task = FormTaskStr(f)

     {.................................run the HIST query}

     r = AU_DOC!AU_DOC
     call TSetParam(q0,"DOC",r)
     call TExecute(q0)
     call Refresh(f)                {...................top position for the list also achieved!!!!}

     modify_flag     = 0
     newversion_flag = 0

     if (task = "ptAppend") then

        call SetCaption("Insert New Document")

        if (_PARAM[10] <> "") then {...................entry form the fm form}

         p = PByName(f,"AU_DOC")
         t = TByName(p,"AU_DOC")
         call TEdit(t)
         call TSetFld(t,"FILE_NAME","
")
         call TSetFld(t,"OPENCOMMAND",_PARAM[10])
         call TPost(t)
         call ReLoadEditFields(f)

        else

         p = PByName(f,"AU_DOC")
         t = TByName(p,"AU_DOC")
         call TEdit(t)
         call TSetFld(t,"KEEPPROTO","1")
         call TPost(t)
         call ReLoadEditFields(f)

        endif

        call OnOpenForm_HideControl("ASKTOEDIT")
        call OnOpenForm_HideControl("MODIFY")
        call OnOpenForm_HideControl("NEWVERSION")

     elseif (task = "ptEdit") then

        call SetCaption("View Document")

        if (__params[6] = "ALL_MODE") then
         return
        endif

        username = GetUserName()
        doc_id = getfprevfield("AU_DOC")

        {...........................................check if the user is a librarian}
        if (fprev = flib) then
         editor_flag = 1
         owner_flag = 1
         viewer_flag = 1
         call OnOpenForm_HideControl("MODIFY")
         call OnOpenForm_HideControl("NEWVERSION")
         return
        else
         call OnOpenForm_HideControl("ASKTOEDIT")
         call OnOpenForm_HideControl("MODIFY")
         call OnOpenForm_HideControl("NEWVERSION")
         call OnOpenForm_DisableField("ISEDITING")
         call OnOpenForm_DisableField("F_EDITING_USER_UNAME")
         call OnOpenForm_HideControl("OK")
        endif

        {...........................................check the satus of the user against the document}
        start_sql "*" "KOSMOS"
         SELECT AU_USER.UNAME, AU_USER_1.UNAME, AU_DOC_PERM.ISEDITOR, AU_DOC_PERM.ISOWNER,
                 AU_DOC_PERM.ISOWNER, AU_DOC.AU_DOC, AU_DOC.EDITING_USER, AU_DOC.ISEDITED
         FROM ((((AU_DOC LEFT JOIN AU_DOC_PERM ON AU_DOC.AU_DOC = AU_DOC_PERM.AU_DOC)
                LEFT JOIN AU_USER ON AU_DOC_PERM.AU_USER = AU_USER.AU_USER)
                LEFT JOIN AU_POS ON AU_DOC_PERM.AU_POS = AU_POS.AU_POS)
                LEFT JOIN AU_ORGAN ON AU_POS.AU_POS = AU_ORGAN.AU_POS)
                LEFT JOIN AU_USER AS AU_USER_1 ON AU_ORGAN.KUSER = AU_USER_1.AU_USER
         WHERE ((AU_USER.UNAME=:U) OR (AU_USER_1.UNAME=:U)) AND (AU_DOC.AU_DOC = :D)
        end_sql
        q = QueryByName()
        call TSetParam(q,"U",username)
        call TSetParam(q,"D",doc_id)
        call TExecute(q)

        editor_flag = TGetFld(q,"ISEDITOR")
        owner_flag = TGetFld(q,"ISOWNER")
        viewer_flag = TGetFld(q,"ISVIEWER")
        is_editing = TGetFld(q,"ISEDITED")
        edit_user_id = TGetFld(q,"EDITING_USER")
        edit_user = LookUp("AU_USER","AU_USER",edit_user_id,"UNAME","")
        call FreeEmbSQL(q)

        if (is_editing = 1) then
         if (edit_user = username) then

         is_editing = 1

         else

         is_editing = 0 {.....edited by another user}

         endif
        endif

        if (is_editing = 1) then
         call SetCaption(" ")
         call OnOpenForm_HideControl("ASKTOEDIT")
         call OnOpenForm_ShowControl("MODIFY")
         call OnOpenForm_ShowControl("NEWVERSION")
        endif

        call OnOpenForm_DisableAllFields()        {.................initialy disable all}

        if (editor_flag = 1) then

         call OnOpenForm_ShowControl("ASKTOEDIT")

        endif
        if (owner_flag = 1) then
         call OnOpenForm_ShowControl("ASKTOEDIT")
         call OnOpenForm_EnableField("UNAME")
         call OnOpenForm_EnableField("POS_D")
         call OnOpenForm_EnableField("ISEDITOR")
         call OnOpenForm_EnableField("ISOWNER")
         call OnOpenForm_EnableField("ISVIEWER")
        endif

     endif

     {..............................use "smaller" version of DM!!}
     {........every editing permits the modification of the document}

     if (_app.DocumentManagerType = "0") then
        call OnOpenForm_HideControl("AU_DOC_VFIELD")
        call OnOpenForm_HideField("F_AU_DOC_TYPE_TDESCR")
        if (task = "ptEdit") then
         is_editing = 1
         modify_flag = 1
         call OnOpenForm_ShowControl("MODIFY")
        endif
     endif

end

{====================== Form_BeforeClose ================================}

fun Form_BeforeClose()

    is_link     = AU_DOC!ISLINK
    is_catalog = AU_DOC!ISCATALOG
    open_command = AU_DOC!OPENCOMMAND

    result = 1
end

{=================================== Form_End ===============================}

proc Form_End ( uvalue )

     if (__params[6] = "ALL_MODE") then
        return
     endif

     if (task = "ptAppend") or (task = "ptEdit") then
        {..............................................process the document entry}
        if (is_link <> 1) then
         tname = _PARAM[6]         {.....related table}
         recid = _PARAM[7]         {.....related record id}
         rtype = _PARAM[8]         {.....the type of relation}

         if (task = "ptAppend") then

         if (open_command = "") then
                 call DocumentEntry ( uvalue, tname, recid, rtype, modify_flag, newversion_flag )
                 if (recid = "") and (tname = "") then {............in append form}
                 uname = GetUserName()
                 fval = strcat("__ONAPPEND",uname)
                 call UpdateField("AU_DOC",uvalue,"FIELDS",fval)
                 endif
         elseif (open_command <> "") and (tname <> "") then
                 call DocRelate ( uvalue, tname, recid, rtype )
         endif

         elseif (task = "ptEdit") then

         if (is_catalog = 1) then

                 call CatalogPermissions ( uvalue )

         else

                 if (modify_flag = 1) then
                 call DocumentEntry ( uvalue, tname, recid, rtype, modify_flag, newversion_flag )
                 endif
                 if (newversion_flag = 1) then
                 call DocumentEntry ( uvalue, tname, recid, rtype, modify_flag, newversion_flag )
                 endif

         endif
         endif
        endif
     endif

     call CheckForAttachments(fprev) {............set the underlying form for attachments!!!}
return
     rel_id = SelectFrom("SELECT AU_DOC_REL FROM AU_DOC_REL WHERE (AU_DOC=",uvalue,")")
     str = strcat(rel_id,"=AU_DOC_REL")
     call OpenFormTop("ptEdit","AU_DOC_REL_E.FM","WORK.AU_DOC_REL",1,str)

end

{=============================== select_file ============================}

proc select_file()

     if (task = "ptAppend") then

        file = SelectFile("")
        file = ExpandUNCFileName(file)

        if (file <> "") then

         len1 = Length(file)
         if (len1 < 200) then

         p = PByName(f,"AU_DOC")
         t = TByName(p,"AU_DOC")
         call TEdit(t)
         call TSetFld(t,"FILE_NAME",file)
         call TPost(t)
         call ReLoadEditFields(f)
         else
         call message("Too Long File Path!")
         endif

        endif
     else
        call message(" ")
     endif
end