1<?php
2
3/*EDI configuration variables definition */
4
5/*EDI Draft version 01B - Controlling agency is the UN - EAN version control number (EAN Code)
6this info is required in the header record of every message sent - prepended with the message type*/
7
8$EDIHeaderMsgId = 'D:01B:UN:EAN010';
9
10/*EDI Reference of the company */
11
12$EDIReference = 'WEBERP';
13
14/* EDI Messages for sending directory */
15
16$EDI_MsgPending = 'EDI_Pending';
17
18/* EDI Messages sent directory */
19
20$EDI_MsgSent = 'EDI_Sent';
21
22
23
24//Testing variables
25include ('includes/session.php');
26include ('includes/header.php');
27$PartnerCode='WALMON';
28$MessageType ='INVOIC';
29
30
31
32/*end of testing variables / code */
33
34include('includes/SQL_CommonFunctions.inc');
35
36$EDITrans = GetNextTransNo(99);
37
38/* Get the message lines for the heading
39replace variable names with data
40write the output to a file one line at a time
41
42Need code of supplier or customer and the type of message INVOIC or ORDERS*/
43
44$sql = "SELECT section,
45		linetext
46	FROM edimessageformat
47	WHERE partnercode='" . $PartnerCode . "'
48	AND messagetype='" . $MessageType . "'
49	ORDER BY sequenceno";
50
51$MessageLinesResult = DB_query($sql);
52
53$fp = fopen( $EDI_Pending . '/EDI_' . $MessageType . '_' . $EDITrans , 'w');
54
55while ($LineDetails = DB_fetch_array($MessageLinesResult)){
56
57	$PoistionPointer = 0;
58	$NewLineText ='';
59	/* now get each occurence of [ in the line */
60	while (mb_strpos ($LineDetails['linetext'],'[',$PoistionPointer)!=False){
61		$LastPositionPointer = $PoistionPointer;
62		$PositionPointer = mb_strpos ($LineDetails['linetext'],'[',$PoistionPointer);
63
64		$NewLineText = $NewLineText .  mb_substr($LineDetails['linetext'],$LastPositionPointer,$PoistionPointer-$LastPositionPointer);
65
66		$LastPositionPointer = $PoistionPointer;
67		$PositionPointer = mb_strpos ($LineDetails['linetext'],']',$PoistionPointer);
68
69		$VariableName = mb_substr($LineDetails['linetext'],$LastPositionPointer,$PoistionPointer-$LastPositionPointer);
70
71		$NewLineText = $NewLineText . $$VariableName;
72
73	}
74	/* now add the text from the last ] to the end of the line */
75	$LastPositionPointer = $PoistionPointer;
76	$NewLineText = $NewLineText .  mb_substr($LineDetails['linetext'],$LastPositionPointer);
77
78	echo "<BR>$NewLineText";
79
80	fputs($fp, $NewLineText ."\n");
81}
82
83fclose($fp);
84
85include ('includes/footer.php');
86
87?>
88