DIEFW ;SFISC/DPC-FILER WP ;22MAR2006
 ;;22.0;VA FileMan;**1,8,1009,147**;Mar 30, 1999
WP(DIEFF,DIEFIEN,DIEFFLD,DIEFWPFL,DIEFTSRC,DIEFOUT) ;(FILE,IENS,FIELD,FLAGS,wp_root,msg_root)
WPX ;
 S DIEFWPFL=$G(DIEFWPFL)
 I '$D(DIQUIET) N DIQUIET S DIQUIET=1
 I '$D(DIFM) N DIFM S DIFM=1 D INIZE^DIEFU
 I DIEFIEN']"" D BLD^DIALOG(202,"IENS","IENS") G OUT
 I '$$VERFLG^DIEFU(DIEFWPFL,"AZK") G OUT
 I "@"'[DIEFTSRC I '$$VROOT^DIEFU(DIEFTSRC) G OUT
 I '$$VFILE^DIEFU(DIEFF,"D") G OUT
 I '$$VFIELD^DIEFU(DIEFF,DIEFFLD,"D") G OUT
 I $P($G(^DD(+$P(^DD(DIEFF,DIEFFLD,0),U,2),.01,0)),U,2)'["W" N EI S EI("FILE")=DIEFF,EI("FIELD")=DIEFFLD D BLD^DIALOG(726,.EI,.EI) G OUT
 I '$$VENTRY^DIEFU(DIEFF,DIEFIEN,"D") G OUT
 N DIEFNODE,DIEFSPOT S DIEFSPOT=" " D GLRF^DIOU(DIEFF,DIEFFLD,.DIEFNODE,.DIEFSPOT)
 N DEPTH,I,D
 S DEPTH=$L(DIEFIEN,",")-1
 F I=DEPTH:-1:1 S D="D"_(DEPTH-I) N @D S @D=$P(DIEFIEN,",",I)
 K DEPTH,D,I
 N DIEFLOCK I DIEFWPFL["K" D  G:'$D(DIEFLOCK) OUT
 . S DIEFLOCK=DIEFNODE
 . D LOCK^DILF(DIEFLOCK) E  D  ;**147
 . . K DIEFLOCK
 . . N EXT S EXT("FILE")=DIEFF,EXT("IENS")=DIEFIEN D BLD^DIALOG(110,"",.EXT)
 D PUTWP(DIEFWPFL,DIEFTSRC,DIEFNODE)
 I $D(DIEFLOCK) L -@DIEFLOCK
OUT I $G(DIEFOUT)]"" D CALLOUT^DIEFU(DIEFOUT)
 Q
 ;
PUTWP(DIEFWPFL,DIEFTSRC,DIEFNODE) ;
 N BEGIN D WP^DIET(DIEFF,DIEFFLD,DIEFIEN,DIEFNODE)
 I "@"[DIEFTSRC K @DIEFNODE Q
 I '($D(@DIEFTSRC)\10) D BLD^DIALOG(305,DIEFTSRC,DIEFTSRC) Q
 I $G(DIEFWPFL)'["A" S BEGIN=1 K @DIEFNODE
 E  S BEGIN=$$NUMLNS(DIEFNODE)+1 K:BEGIN=1 @DIEFNODE
 I $D(@DIEFTSRC@($O(@DIEFTSRC@(0)),0))#2 S DIEFWPFL=$G(DIEFWPFL)_"Z"
 N LINECNT,INLINE S INLINE=0
 F LINECNT=BEGIN:1 S INLINE=$O(@DIEFTSRC@(INLINE)) Q:INLINE'=+$P(INLINE,"E")  D
 . I $G(DIEFWPFL)'["Z" S @DIEFNODE@(LINECNT,0)=$G(@DIEFTSRC@(INLINE))
 . E  S @DIEFNODE@(LINECNT,0)=$G(@DIEFTSRC@(INLINE,0))
 S LINECNT=LINECNT-1
 S @DIEFNODE@(0)=U_U_LINECNT_U_LINECNT_U_DT
 Q
 ;
NUMLNS(DIWPROOT) ;
 N DIWPLN
 S DIWPLN=$P($G(@DIWPROOT@(0)),U,3)
 Q:DIWPLN DIWPLN
 S DIWPLN=$O(@DIWPROOT@(""),-1)
 Q +DIWPLN
