-
Notifications
You must be signed in to change notification settings - Fork 0
/
adder2.php
executable file
·211 lines (142 loc) · 5.27 KB
/
adder2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
require_once 'globalVariables.php';
require_once 'HTTP/Request2.php'; //uses PEAR
$pmui = unserialize($_POST['pmui']);
$id = $_POST['id'];
//var_dump($pmui);
//print "<br /><br />";
$atname = "tool-id";
$tname = "translation";
$atorder = "order";
$torder = "1";
$placeInArr = "1";
//PREPARATION STAGE, check client, if client Symantec, use DDC, otherwise move on. If use
// DDC call LKR and then WRF again.
// Do we include the DDC task?
// IF client is not symantec, do nothing, else add DDC to the array.
if (strtolower($pmui['p_client']) != "symantec"){
unset($pmui['p_client']);
//print "Deleted CATEGORY for {$id} </br>"; // This removes the element from the array PROBLEM
} else {
$pmui['p_client'] = "DDC";
$pmui[$placeInArr] = $pmui['p_client'];
$placeInArr++;
unset($pmui['p_client']);
}
//END OF Do we include the DDC task?
// We always include the LKR
$pmui[$placeInArr] = "LKR";
$placeInArr++;
// END We always include the LKR
// We always include the WFR for TRANSFORMATION
$pmui[$placeInArr] = "WFR";
$placeInArr++;
// END We always include the WFR for TRANSFORMATION
ksort($pmui);
//GET THE DOCUMENT LOAD IT PREPARE TO WRITE ON IT
$doc = new DOMDocument();
$doc->load( $localFolder .$id .'.xlf' );
$xpath = new DOMXPath($doc);
$form = "form";
$type = "text";
$tasklistf = "";
$headers = $doc->getElementsByTagName( 'header' );
$text= "/n";
foreach( $headers as $header )
{
$reference = $doc->createElement("reference");
$header->appendChild($reference);
$ifile = $doc->createElement("internal-file");
$reference->appendChild($ifile);
$ifile->setAttribute($form, $type);
$wf = $doc->createElement("workflow");
$ifile->appendChild($wf);
foreach ($pmui as $value) {
$ltask = $doc->createElement("task");
$wf->appendChild($ltask);
$ifile->setAttribute($form, $type);
$ltask->setAttribute($atname, $value);
$ltask->setAttribute($atorder, $torder);
//Create check to see if a comma or a full stop is needed. Coom
// becomes . if the order number is equal to the lengh of the
//array pmui (count($pmui)) otherwise, it is comma
$comm = ($torder == (count($pmui))) ? '.' : ', ';
$torder++;
$tasklist = $value;
$tasklistf = $tasklistf . $tasklist . $comm;
}
}
// CHECK if there is a phase-group if not, add it
$xmlDoc = new DOMDocument();
$xmlDoc->load( $localFolder . $id . '.xlf' );
$countNodes = $xmlDoc->getElementsByTagName("phase-group");
if ($countNodes->length==0) {
// add a phase group inside the header
print "No phase group";
$heads = $doc->getElementsByTagName('header');
foreach($heads as $head)
{
$root_child=$doc->createElement('phase-group');
$head ->appendChild($root_child);
print "PHASE group added";
}
} Else {
//There is a phase-group and nothing hapens
print "YAY phase group";
}
//PHASE STUFF FROM NAOTO
$phasegroups = $doc->getElementsByTagName('phase-group');
$toolid='WFR';
$phasename='WF-Recommendation-Preparation';
foreach($phasegroups as $phasegroup)
{
$root_child=$doc->createElement('phase');
$phasegroup ->appendChild($root_child);
$root_attr1 = $doc->createAttribute('phase-name');
$root_child->appendChild($root_attr1);
$root_text = $doc->createTextNode($phasename);
$root_attr1 ->appendChild($root_text);
$root_attr2 = $doc->createAttribute('company-name');
$root_child->appendChild($root_attr2);
$root_text = $doc->createTextNode('SomeCompany');
$root_attr2 ->appendChild($root_text);
$root_attr3 = $doc->createAttribute('process-name');
$root_child->appendChild($root_attr3);
$root_text = $doc->createTextNode('WF-Recommender');
$root_attr3 ->appendChild($root_text);
$root_attr4 = $doc->createAttribute('contact-name');
$root_child->appendChild($root_attr4);
$root_text = $doc->createTextNode('Aram');
$root_attr4 ->appendChild($root_text);
$root_attr5 = $doc->createAttribute('contact-email');
$root_child->appendChild($root_attr5);
$root_text = $doc->createTextNode('[email protected]');
$root_attr5 ->appendChild($root_text);
$root_attr6 = $doc->createAttribute('tool-id');
$root_child->appendChild($root_attr6);
$root_text = $doc->createTextNode($toolid);
$root_attr6 ->appendChild($root_text);
$date=date("r", time());
$root_attr7 = $doc->createAttribute('date');
$root_child->appendChild($root_attr7);
$root_text = $doc->createTextNode($date);
$root_attr7 ->appendChild($root_text);
}
// END OF PHASE STUFF FROM NAOTO
//var_dump($pmui);
$doc->save($localFolder . $id .'.xlf');
//}
//print "yo ";
$msg = "The workflow recommender has added ". ($torder - 1) . " task(s): " . $tasklistf ;
$request = new HTTP_Request2($this_url.'/feedbacker.php', HTTP_Request2::METHOD_GET);
$url = $request->getUrl();
$url->setQueryVariable('id', $id); // set job id here
$url->setQueryVariable('msg', $msg); // set status id here
$request->send();
$request = new HTTP_Request2($this_url.'/outputer.php', HTTP_Request2::METHOD_GET);
$url = $request->getUrl();
$url->setQueryVariable('id', $id); // set job id here
$melons=$request->send()->getBody();
//print "<br /><br /> parser done <br /><br /> ";
print $melons;
?>