Blame view

php/classes/AmdaAction.php 37.9 KB
16035364   Benjamin Renard   First commit
1
2
3
<?php
/**
 * @class AmdaAction
aa94fd24   elena   Merge with last svn
4
 * @version $Id: AmdaAction.php 2976 2015-07-01 15:05:40Z benjamin $
16035364   Benjamin Renard   First commit
5
6
7
8
 *
 */


10200969   Roipoussiere   Remove whitespace...
9
class AmdaAction
735c653b   Elena.Budnik   rank at observato...
10
{
10200969   Roipoussiere   Remove whitespace...
11
	private $xmlFiles  = array('localParam' => 'LocalParams.xml', 'remoteParam' => 'RemoteParams.xml',
735c653b   Elena.Budnik   rank at observato...
12
										'remoteSimuParam' => 'RemoteParams.xml', 'derivedParam' => 'WsParams.xml', 'myDataParam' => 'WsParams.xml',
10200969   Roipoussiere   Remove whitespace...
13
14
										'timeTable' => 'Tt.xml', 'catalog' => 'Tt.xml', 'alias' => 'Alias.xml',
										'myData' => 'Files.xml',
735c653b   Elena.Budnik   rank at observato...
15
16
17
18
19
										'request' => 'Request.xml', 'condition' => 'Request.xml',
										'bkgWorks' => 'jobs.xml');

	private $user, $amdaStat;

10200969   Roipoussiere   Remove whitespace...
20
21
	public function __construct()
	{
735c653b   Elena.Budnik   rank at observato...
22
23
24
25
26
		$dd = new UserMgr();
		$this->user = $dd->user;
		if (!defined('NEWKERNEL_DEBUG') || !NEWKERNEL_DEBUG)
					$this->amdaStat = new AmdaStats($dd->user);
	}
16035364   Benjamin Renard   First commit
27

10200969   Roipoussiere   Remove whitespace...
28
	private function getUrlDirs($url)
735c653b   Elena.Budnik   rank at observato...
29
30
31
	{
		//TODO replace by ftp php class methods: ftp_nlist() etc
		require_once "simple_html_dom.php";
10200969   Roipoussiere   Remove whitespace...
32
33

		$url = html_entity_decode($url);
735c653b   Elena.Budnik   rank at observato...
34
		$trimmed_url = trim($url);
10200969   Roipoussiere   Remove whitespace...
35
		if (strrpos($trimmed_url, "/") == strlen($trimmed_url) - 1)
735c653b   Elena.Budnik   rank at observato...
36
		{
10200969   Roipoussiere   Remove whitespace...
37
			if (file_exists("temp.html")) unlink("temp.html");
735c653b   Elena.Budnik   rank at observato...
38
			exec("wget -O temp.html ".$url);
10200969   Roipoussiere   Remove whitespace...
39

735c653b   Elena.Budnik   rank at observato...
40
41
			$html = file_get_html('temp.html');
			$dirs = $html->find('a[href]');
10200969   Roipoussiere   Remove whitespace...
42
			foreach ($dirs as $dir)
735c653b   Elena.Budnik   rank at observato...
43
			{
6acb8d2a   Elena.Budnik   checkRequest in R...
44
45
				$name =  $dir->innertext; //$dir->href;
				$isLeaf = strrpos($name, "/") !== strlen($name) - 1;
10200969   Roipoussiere   Remove whitespace...
46
				$childrenToReturn[] = array('text' => $name, 'id' => $trimmed_url.$name, 'nodeType' => 'url', 'leaf' => $isLeaf);
735c653b   Elena.Budnik   rank at observato...
47
			}
10200969   Roipoussiere   Remove whitespace...
48

735c653b   Elena.Budnik   rank at observato...
49
		}
10200969   Roipoussiere   Remove whitespace...
50
51
52

		return $childrenToReturn;

735c653b   Elena.Budnik   rank at observato...
53
	}
10200969   Roipoussiere   Remove whitespace...
54

16035364   Benjamin Renard   First commit
55
56
/*****************************************************************
*                           PUBLIC FUNCTIONS
10200969   Roipoussiere   Remove whitespace...
57
58
*****************************************************************/

735c653b   Elena.Budnik   rank at observato...
59
60
61
62
	/*
	*   $obj = { id: node.id,  nodeType: node.nodeType }
	*/
	public function getTree($obj) {
16035364   Benjamin Renard   First commit
63

735c653b   Elena.Budnik   rank at observato...
64
		$node = $obj->node;
10200969   Roipoussiere   Remove whitespace...
65

735c653b   Elena.Budnik   rank at observato...
66
		$nodeType = $obj->nodeType;
a0f13ed1   Elena.Budnik   small format + ti...
67
		
735c653b   Elena.Budnik   rank at observato...
68
69
		$remoteBase = false;
		$isRemoteDataSet = false;
16035364   Benjamin Renard   First commit
70

10200969   Roipoussiere   Remove whitespace...
71
		if ($nodeType == 'url')
735c653b   Elena.Budnik   rank at observato...
72
		{
10200969   Roipoussiere   Remove whitespace...
73
			$url = $node == 'root' ? $obj->baseId : $node;
735c653b   Elena.Budnik   rank at observato...
74
75
			return  $this->getUrlDirs($url);
		}
16035364   Benjamin Renard   First commit
76

e57cb025   Benjamin Renard   Fix most of error...
77
		if (isset($obj->baseId)) $remoteBase = true;
16035364   Benjamin Renard   First commit
78

735c653b   Elena.Budnik   rank at observato...
79
		if ($node == 'root' && $remoteBase)  $node = $obj->baseId;
16035364   Benjamin Renard   First commit
80

10200969   Roipoussiere   Remove whitespace...
81
82
		if ($node == 'root' && !$remoteBase)
		{
e57cb025   Benjamin Renard   Fix most of error...
83
84
85
86
87
88
89
90
91
92
93
94
			if (file_exists(DATAPATH.$nodeType.'.json')) {
				$json_o = json_decode(file_get_contents(DATAPATH.$nodeType.'.json'));
				if (empty($json_o)) {
					$childrenToReturn = array();
				}
				else {
					$childrenToReturn = $json_o->nodes;
				}
			}
			else {
				$childrenToReturn = array();
			}
10200969   Roipoussiere   Remove whitespace...
95
96
		}
		else
735c653b   Elena.Budnik   rank at observato...
97
98
99
		{
			$Dom = new DomDocument("1.0");

10200969   Roipoussiere   Remove whitespace...
100
			switch ($nodeType)
735c653b   Elena.Budnik   rank at observato...
101
102
103
104
105
			{
				case 'sharedtimeTable':
				case 'sharedcatalog':
					$xmlName = SHAREDPATH.'/SharedObjectTree.xml';
					break;
10200969   Roipoussiere   Remove whitespace...
106
				case 'bkgWorks':
735c653b   Elena.Budnik   rank at observato...
107
108
109
					$xmlName = USERJOBDIR.$this->xmlFiles[$nodeType];
					break;
				case 'source':
10200969   Roipoussiere   Remove whitespace...
110
111
112
113
					$xmlName = DATAPATH.'RemoteData/'.$obj->baseId.'/base.xml';
					break;
				case 'destination':
					$xmlName = USERWSDIR.'RemoteParams.xml';
735c653b   Elena.Budnik   rank at observato...
114
					break;
735c653b   Elena.Budnik   rank at observato...
115
116
117
				default:
					$xmlName = USERWSDIR.$this->xmlFiles[$nodeType];
			}
16035364   Benjamin Renard   First commit
118

a0f13ed1   Elena.Budnik   small format + ti...
119
			if ($remoteBase){
735c653b   Elena.Budnik   rank at observato...
120
				$nodeType = 'remoteParam';
10200969   Roipoussiere   Remove whitespace...
121
122
			}

e57cb025   Benjamin Renard   Fix most of error...
123
			@$Dom->load($xmlName);
10200969   Roipoussiere   Remove whitespace...
124

a0f13ed1   Elena.Budnik   small format + ti...
125
			if ($node == "myRemoteSimuData-treeRootNode") $node = "myRemoteData-treeRootNode";
10200969   Roipoussiere   Remove whitespace...
126

735c653b   Elena.Budnik   rank at observato...
127
			$nodeToOpen = $Dom->getElementById($node);
e57cb025   Benjamin Renard   Fix most of error...
128
			$children = empty($nodeToOpen->childNodes) ? array() : $nodeToOpen->childNodes;
16035364   Benjamin Renard   First commit
129

10200969   Roipoussiere   Remove whitespace...
130
131
			foreach ($children as $child)
				if ($child->nodeType == XML_ELEMENT_NODE)
735c653b   Elena.Budnik   rank at observato...
132
133
				{
					$isLeaf = true;
10200969   Roipoussiere   Remove whitespace...
134

735c653b   Elena.Budnik   rank at observato...
135
					if ($child->hasChildNodes())
10200969   Roipoussiere   Remove whitespace...
136
137
						foreach ($child->childNodes as $grandChild)
							if ($grandChild -> nodeType == XML_ELEMENT_NODE)
735c653b   Elena.Budnik   rank at observato...
138
139
140
141
142
143
							{
									$isLeaf = false;
									break;
							}
					if ($child->tagName == 'folder')  $isLeaf = false;

10200969   Roipoussiere   Remove whitespace...
144
145
					//TODO MAKE PROPERLY  as function of nodetype !!!!
					$info = '';
735c653b   Elena.Budnik   rank at observato...
146
					$id =  $child->getAttribute('xml:id');
10200969   Roipoussiere   Remove whitespace...
147
					$name = $child->getAttribute('name');
735c653b   Elena.Budnik   rank at observato...
148
149
150
151
152
153
154
155
156
					$help = $child->getAttribute('att');
					if ($child->hasAttribute('dataStart')) $dataStart = $child->getAttribute('dataStart');
					if ($child->hasAttribute('dataStop')) $dataStop = $child->getAttribute('dataStop');

					$specialNode = false;
					$isParameter = false;
					$isAddable =  false;
					$isSimulation = false;
					$rank = null;
e57cb025   Benjamin Renard   Fix most of error...
157
					$skip = FALSE;
735c653b   Elena.Budnik   rank at observato...
158

10200969   Roipoussiere   Remove whitespace...
159
					switch ($nodeType)
735c653b   Elena.Budnik   rank at observato...
160
					{
10200969   Roipoussiere   Remove whitespace...
161
						case 'bkgWorks':
735c653b   Elena.Budnik   rank at observato...
162
163
							$specialNode = true;
							$status = $child->getAttribute('status');
10200969   Roipoussiere   Remove whitespace...
164
							//     if ($status == 'done') continue;
735c653b   Elena.Budnik   rank at observato...
165
							$childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType, 'leaf' => $isLeaf,
10200969   Roipoussiere   Remove whitespace...
166
									'pid' => $child->getAttribute('pid'), 'status' => $status,
735c653b   Elena.Budnik   rank at observato...
167
168
169
170
171
									'jobType' => $child->getAttribute('jobType'), 'info' => $child->getAttribute('info'));
						break;

						case 'condition':
							$objectMgr = new RequestMgr();
10200969   Roipoussiere   Remove whitespace...
172
173
							$info = $objectMgr->getObject($id)->expression;
						break;
735c653b   Elena.Budnik   rank at observato...
174

10200969   Roipoussiere   Remove whitespace...
175
						case 'request':
735c653b   Elena.Budnik   rank at observato...
176
						$objectMgr = new RequestMgr();
10200969   Roipoussiere   Remove whitespace...
177
178
179
180
						$objplot = $objectMgr->getObject($id);
						for ($i=0; $i < count($objplot->children); $i++)
						{
							for ($j=0; $j < count($objplot->children[$i]->children); $j++)
735c653b   Elena.Budnik   rank at observato...
181
182
183
184
							{
								$info = $info.' '.$objplot->children[$i]->children[$j]->name;
							}
						}
10200969   Roipoussiere   Remove whitespace...
185
						break;
735c653b   Elena.Budnik   rank at observato...
186

10200969   Roipoussiere   Remove whitespace...
187
						case 'alias':
735c653b   Elena.Budnik   rank at observato...
188
189
							$info = $id;
							$id = 'alias_'.$id;
10200969   Roipoussiere   Remove whitespace...
190
							if ($isLeaf) $isParameter = true;
735c653b   Elena.Budnik   rank at observato...
191
192
193
						break;

						case 'timeTable':
10200969   Roipoussiere   Remove whitespace...
194
						case 'catalog':
735c653b   Elena.Budnik   rank at observato...
195
196
							if ($isLeaf) $info = $child->getAttribute('intervals').' intervals';
						break;
10200969   Roipoussiere   Remove whitespace...
197

735c653b   Elena.Budnik   rank at observato...
198
199
						case 'sharedtimeTable':
						case 'sharedcatalog':
10200969   Roipoussiere   Remove whitespace...
200
							if ($isLeaf)
735c653b   Elena.Budnik   rank at observato...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
							{
								$info = '<b>Nb intervals:</b> '.$child->getAttribute('nbIntervals').'<br/>';
								$info .= '<b>Shared by:</b> '.$child->getAttribute('sharedBy').' ('.$child->getAttribute('sharedDate').')<br/>';
								$info .= '<b>Description:</b> '.$child->getAttribute('description');
							}
						break;
						case 'derivedParam':
							$info = $child->getAttribute('buildchain');
							if ($isLeaf) $isParameter = true;
						break;

						case 'localParam':

							$globalStart = null;
							$globalStop = null;
							$timeRestriction = false;
							$specialNode = true;
							$isParameter = false;
							$needsArgs = false;
10200969   Roipoussiere   Remove whitespace...
220
							$isSpectra = false;
735c653b   Elena.Budnik   rank at observato...
221
							$isStack = false;
e57cb025   Benjamin Renard   Fix most of error...
222
							$not_yet = false;
735c653b   Elena.Budnik   rank at observato...
223

10200969   Roipoussiere   Remove whitespace...
224
225
							if ($child->hasAttribute('desc'))
							{
735c653b   Elena.Budnik   rank at observato...
226
								$info = $child->getAttribute('desc');
10200969   Roipoussiere   Remove whitespace...
227
228
229
230

								if ($child->hasAttribute('dataStart') && $child->hasAttribute('dataStop'))
								{
									$info .= "<br/>Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop');
735c653b   Elena.Budnik   rank at observato...
231
								}
10200969   Roipoussiere   Remove whitespace...
232

735c653b   Elena.Budnik   rank at observato...
233
234
235
								if ($child->getAttribute('dataStart') == 'depending on mission')
								{
									$info .= "<br/>Time Range: ".$child->getAttribute('dataStart');
10200969   Roipoussiere   Remove whitespace...
236
237
238
								}

								if ($child->getAttribute('restriction') > 1)
735c653b   Elena.Budnik   rank at observato...
239
240
241
242
243
								{
									$restricted  = $child->getAttribute('restriction');
									$info .= "<br/><b>Time Restriction</b>: -$restricted days";
								}
							}
10200969   Roipoussiere   Remove whitespace...
244

735c653b   Elena.Budnik   rank at observato...
245
246
							if ($child->hasAttribute('units')) $info = $child->getAttribute('units');

10200969   Roipoussiere   Remove whitespace...
247
							if ($child->tagName == 'parameter')
735c653b   Elena.Budnik   rank at observato...
248
249
250
251
252
253
254
							{
								$isParameter = true;
								$isScatter = true;

								if ($child->parentNode->hasAttribute('dataStart'))
								{
									$globalStart = $child->parentNode->getAttribute('dataStart');
10200969   Roipoussiere   Remove whitespace...
255
									$globalStop = $child->parentNode->getAttribute('dataStop');
735c653b   Elena.Budnik   rank at observato...
256
257
258
259
260
								}

								if ($child->parentNode->getAttribute('restriction') > 1 )
								{
									$timeRestriction = true;
10200969   Roipoussiere   Remove whitespace...
261
262
263

								}
								/*------------------- to show not tested parameters ------*/
735c653b   Elena.Budnik   rank at observato...
264
								if ($child->getAttribute('tbd'))
10200969   Roipoussiere   Remove whitespace...
265
266
									$info .= "<br/><b>Not tested yet</b>";
								/*------------------- --------------------------------------*/
735c653b   Elena.Budnik   rank at observato...
267
							}
10200969   Roipoussiere   Remove whitespace...
268

735c653b   Elena.Budnik   rank at observato...
269
270
271
272
273
274
275
276
277
							$component_info = array();
							if ($child->tagName == 'component')
							{
								$isParameter = true;
								$isScatter = true;

								if ($child->parentNode->parentNode->hasAttribute('dataStart'))
								{
									$globalStart = $child->parentNode->parentNode->getAttribute('dataStart');
10200969   Roipoussiere   Remove whitespace...
278
279
									$globalStop = $child->parentNode->parentNode->getAttribute('dataStop');
								}
735c653b   Elena.Budnik   rank at observato...
280
281
282

								if ($child->parentNode->parentNode->getAttribute('restriction') > 1)
								{
10200969   Roipoussiere   Remove whitespace...
283
284
									$timeRestriction = true;
								}
735c653b   Elena.Budnik   rank at observato...
285
286
287
288
289

								if ($child->hasAttribute("index1"))
									$component_info["index1"] = $child->getAttribute('index1');
								if ($child->hasAttribute("index2"))
									$component_info["index2"] = $child->getAttribute('index2');
10200969   Roipoussiere   Remove whitespace...
290

735c653b   Elena.Budnik   rank at observato...
291
292
								$component_info["parentId"] = $child->parentNode->getAttribute('xml:id');
							}
10200969   Roipoussiere   Remove whitespace...
293

735c653b   Elena.Budnik   rank at observato...
294
							if ($child->tagName == 'parameter' && $child->hasChildNodes()) $isScatter = false;
10200969   Roipoussiere   Remove whitespace...
295
296

							if ($child->tagName == 'parameter' && $child->hasAttribute('display_type'))
735c653b   Elena.Budnik   rank at observato...
297
							{
10200969   Roipoussiere   Remove whitespace...
298
								if ($child->getAttribute('display_type') == 'spectrogram')
735c653b   Elena.Budnik   rank at observato...
299
								{
10200969   Roipoussiere   Remove whitespace...
300
301
										$needsArgs = true;
										$isSpectra = true;
735c653b   Elena.Budnik   rank at observato...
302
303
										$isScatter = false;
								}
10200969   Roipoussiere   Remove whitespace...
304
305
								elseif ($child->getAttribute('display_type') == 'stackplot')
								{
735c653b   Elena.Budnik   rank at observato...
306
307
308
										$isStack = true;
										$isScatter = false;
								}
10200969   Roipoussiere   Remove whitespace...
309
310
311
							}

							if ($isParameter)
735c653b   Elena.Budnik   rank at observato...
312
							{
735c653b   Elena.Budnik   rank at observato...
313
314
								$objectMgr = new AliasMgr();
								$alias = $objectMgr->getAlias($id);
10200969   Roipoussiere   Remove whitespace...
315
316

								$childrenToReturn[] = array('text' => $name,'alias' => $alias,
735c653b   Elena.Budnik   rank at observato...
317
318
319
320
321
									'id' => $id,'nodeType' => $nodeType, 'info' => $info, "component_info" => $component_info,
									'globalStart' => $globalStart, 'globalStop' => $globalStop, 'timeRestriction' => $timeRestriction,
									'leaf' => $isLeaf, 'isParameter' => $isParameter, 'isScatter' => $isScatter,
									'isSpectra' => $isSpectra,'isStack' => $isStack, 'needsArgs' => $needsArgs, 'help' => $help, 'notyet' => $not_yet);
							}
10200969   Roipoussiere   Remove whitespace...
322
							else
735c653b   Elena.Budnik   rank at observato...
323
							{
10200969   Roipoussiere   Remove whitespace...
324
								if ($child->tagName == 'mission' || $child->tagName == 'observatory')
735c653b   Elena.Budnik   rank at observato...
325
326
327
328
329
330
331
332
								{
									$disable = $child->hasAttribute('restriction');
									$rank = $child->getAttribute('rank');
								}
								else
								{
									$disable = $child->hasAttribute('restriction');
								}
10200969   Roipoussiere   Remove whitespace...
333

735c653b   Elena.Budnik   rank at observato...
334
335
336
								if ($disable)
								{
									if ($disable == 1) {
abda054b   Elena.Budnik   correct message
337
										$info .=  "<br/><b>Sorry ! Not finished yet...</b>";
735c653b   Elena.Budnik   rank at observato...
338
									}
10200969   Roipoussiere   Remove whitespace...
339
340
									else {
										$disable = false;
735c653b   Elena.Budnik   rank at observato...
341
342
343
									}
								}

10200969   Roipoussiere   Remove whitespace...
344
345
								$childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType,  'info' => $info,
									'leaf' => false, 'help' => $help, 'disable' => $disable, 'rank' => $rank);
735c653b   Elena.Budnik   rank at observato...
346
347
348
349
							}
						break;

						case 'remoteSimuParam' :
10200969   Roipoussiere   Remove whitespace...
350

bf74fc2d   Elena.Budnik   IMPEX
351
							$globalStart = null;
6657f68b   Elena.Budnik   monitor impex ser...
352
							$service_down = false;
735c653b   Elena.Budnik   rank at observato...
353
							$isSimulation = true;
10200969   Roipoussiere   Remove whitespace...
354
355

			            if ($child->getAttribute('isAddable')) // 'spase://IMPEX/SimulationModel/FMI/GUMICS'
735c653b   Elena.Budnik   rank at observato...
356
357
358
359
							{
								$isLeaf = false;
								$isAddable = true;
							}
10200969   Roipoussiere   Remove whitespace...
360
361

							if ($child->tagName == 'dataCenter')
735c653b   Elena.Budnik   rank at observato...
362
							{
10200969   Roipoussiere   Remove whitespace...
363
								if ($child->getAttribute('isSimulation'))
6657f68b   Elena.Budnik   monitor impex ser...
364
								{
10200969   Roipoussiere   Remove whitespace...
365
366
									$service_down = !($child->getAttribute('available'));
									break;
6657f68b   Elena.Budnik   monitor impex ser...
367
								}
10200969   Roipoussiere   Remove whitespace...
368
								else
735c653b   Elena.Budnik   rank at observato...
369
370
371
372
373
								{
									$skip = true;
									break;
								}
							}
10200969   Roipoussiere   Remove whitespace...
374
375

							if ($child->hasAttribute('rank'))
735c653b   Elena.Budnik   rank at observato...
376
377
378
							{
								$rank = $child->getAttribute('rank');
							}
10200969   Roipoussiere   Remove whitespace...
379

bf74fc2d   Elena.Budnik   IMPEX
380
381
							if ( $child->tagName == 'parameter')
							{
a0f13ed1   Elena.Budnik   small format + ti...
382
								if ($child->parentNode->hasAttribute('dataStart'))
bf74fc2d   Elena.Budnik   IMPEX
383
									{
a0f13ed1   Elena.Budnik   small format + ti...
384
385
										$globalStart = $child->parentNode->getAttribute('dataStart');
										$globalStop = $child->parentNode->getAttribute('dataStop');
bf74fc2d   Elena.Budnik   IMPEX
386
387
									}
							}
10200969   Roipoussiere   Remove whitespace...
388

bf74fc2d   Elena.Budnik   IMPEX
389
390
391
392
393
							if ( $child->tagName == 'component')
							{
								if ($child->parentNode->parentNode->hasAttribute('dataStart'))
									{
										$globalStart = $child->parentNode->parentNode->getAttribute('dataStart');
10200969   Roipoussiere   Remove whitespace...
394
										$globalStop = $child->parentNode->parentNode->getAttribute('dataStop');
bf74fc2d   Elena.Budnik   IMPEX
395
396
									}
							}
10200969   Roipoussiere   Remove whitespace...
397

735c653b   Elena.Budnik   rank at observato...
398
						case 'remoteParam' :
10200969   Roipoussiere   Remove whitespace...
399
400

							if ($child->getAttribute('isSimulation') && $child->tagName == 'dataCenter')
735c653b   Elena.Budnik   rank at observato...
401
402
403
404
405
406
407
							{
								$skip = true;
								break;
							}

							$isDeletable = $child->hasAttribute('isDeletable');
							$specialNode = true;
10200969   Roipoussiere   Remove whitespace...
408
409
410
411
412
							$isParameter = false;

							$isSpectra = false;

							switch ($id)
735c653b   Elena.Budnik   rank at observato...
413
							{
10200969   Roipoussiere   Remove whitespace...
414
								case 'CDAWEB'  :
735c653b   Elena.Budnik   rank at observato...
415
416
417
418
419
								case 'THEMIS' :
									$rank = 5;
									break;
								case 'MAPSKP' :
									$rank = 9;
10200969   Roipoussiere   Remove whitespace...
420
									break;
735c653b   Elena.Budnik   rank at observato...
421
422
								default:
							}
10200969   Roipoussiere   Remove whitespace...
423

735c653b   Elena.Budnik   rank at observato...
424
425
							$info = $child->getAttribute('desc');

10200969   Roipoussiere   Remove whitespace...
426
427
							if ($info && !$isSimulation)
							{
735c653b   Elena.Budnik   rank at observato...
428
								$info = str_replace(';', "<br/>Time Range: ", $info);
10200969   Roipoussiere   Remove whitespace...
429
430
431
							}

							if (($child->tagName == 'parameter') || ($child->tagName == 'component'))
735c653b   Elena.Budnik   rank at observato...
432
433
							{
								$isParameter = true;
10200969   Roipoussiere   Remove whitespace...
434
								$isScatter = true;
735c653b   Elena.Budnik   rank at observato...
435
							}
10200969   Roipoussiere   Remove whitespace...
436

9a63b7f6   Elena.Budnik   needsArgs to Simu...
437
							$needsArgs =  $child->getAttribute('needsArgs');
735c653b   Elena.Budnik   rank at observato...
438
439

							if (($child->tagName == 'parameter' && $child->hasChildNodes()) || $needsArgs) $isScatter = false;
10200969   Roipoussiere   Remove whitespace...
440
441

							if ($remoteBase)
735c653b   Elena.Budnik   rank at observato...
442
							{
10200969   Roipoussiere   Remove whitespace...
443
								if ($child->tagName == 'dataset') $isRemoteDataSet = true;
735c653b   Elena.Budnik   rank at observato...
444
							}
a0f13ed1   Elena.Budnik   small format + ti...
445
446
447
448
449
450
451
							
							if ($child->tagName == 'parameter'){
								if ($child->parentNode->hasAttribute('dataStart')){
									$globalStart = date('Y-m-d\TH:i:s\Z', strtotime($child->parentNode->getAttribute('dataStart')));
									$globalStop = date('Y-m-d\TH:i:s\Z',  strtotime($child->parentNode->getAttribute('dataStop')));
								}
							}
735c653b   Elena.Budnik   rank at observato...
452

a0f13ed1   Elena.Budnik   small format + ti...
453
454
455
456
457
458
459
							if ( $child->tagName == 'component'){
								if ($child->parentNode->parentNode->hasAttribute('dataStart')){
									$globalStart = date('Y-m-d\TH:i:s\Z', strtotime($child->parentNode->getAttribute('dataStart')));
									$globalStop = date('Y-m-d\TH:i:s\Z',  strtotime($child->parentNode->getAttribute('dataStop')));
								}
							}
							
10200969   Roipoussiere   Remove whitespace...
460
							if ($isParameter)
735c653b   Elena.Budnik   rank at observato...
461
							{
10200969   Roipoussiere   Remove whitespace...
462
								$disable = $child->parentNode->getAttribute('disabled');
735c653b   Elena.Budnik   rank at observato...
463
464
465
466
467
								$objectMgr = new AliasMgr();
								$alias = $objectMgr->getAlias($id);

								if ($child->hasAttribute('display_type') && $child->getAttribute('display_type') == 'spectrogram')
								{
10200969   Roipoussiere   Remove whitespace...
468
									$needsArgs = true;
735c653b   Elena.Budnik   rank at observato...
469
470
									$isScatter = false;
									$isSpectra = true;
10200969   Roipoussiere   Remove whitespace...
471
								}
bf74fc2d   Elena.Budnik   IMPEX
472
								if ($globalStart)
10200969   Roipoussiere   Remove whitespace...
473
								 $childrenToReturn[] = array('text' => $name,'alias' => $alias,
bf74fc2d   Elena.Budnik   IMPEX
474
										'id' => $id,'nodeType' => $nodeType,  'info' => $info, 'help' => $help,  'globalStart' => $globalStart,
10200969   Roipoussiere   Remove whitespace...
475
										'globalStop' => $globalStop, 'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter,
bf74fc2d   Elena.Budnik   IMPEX
476
477
										'isScatter' => $isScatter, 'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => $component_info);
								else
10200969   Roipoussiere   Remove whitespace...
478
									$childrenToReturn[] = array('text' => $name,'alias' => $alias,
bf74fc2d   Elena.Budnik   IMPEX
479
										'id' => $id,'nodeType' => $nodeType,  'info' => $info, 'help' => $help,
10200969   Roipoussiere   Remove whitespace...
480
										'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter,
bf74fc2d   Elena.Budnik   IMPEX
481
										'isScatter' => $isScatter, 'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => $component_info);
735c653b   Elena.Budnik   rank at observato...
482
							}
10200969   Roipoussiere   Remove whitespace...
483
484
							else
							{
e57cb025   Benjamin Renard   Fix most of error...
485
								$restricted = FALSE;
10200969   Roipoussiere   Remove whitespace...
486
// 								if ($child->tagName == 'dataCenter')
6657f68b   Elena.Budnik   monitor impex ser...
487
// 								{
10200969   Roipoussiere   Remove whitespace...
488
// 									$restricted = ($child->getAttribute('available') != "1");
6657f68b   Elena.Budnik   monitor impex ser...
489
// 								}
10200969   Roipoussiere   Remove whitespace...
490
491
492
493
//
								if ($id == 'CDAWEB' || $id == 'THEMIS'|| $id == 'MAPSKP')
									$restricted = FALSE;

735c653b   Elena.Budnik   rank at observato...
494
								if ($child->tagName == 'dataset')
6657f68b   Elena.Budnik   monitor impex ser...
495
								{
735c653b   Elena.Budnik   rank at observato...
496
									$nonavailable = ($child->getAttribute('disabled'));
6657f68b   Elena.Budnik   monitor impex ser...
497
								}
735c653b   Elena.Budnik   rank at observato...
498
								else
6657f68b   Elena.Budnik   monitor impex ser...
499
								{
735c653b   Elena.Budnik   rank at observato...
500
									$nonavailable = false;
6657f68b   Elena.Budnik   monitor impex ser...
501
								}
10200969   Roipoussiere   Remove whitespace...
502

735c653b   Elena.Budnik   rank at observato...
503
504
505
506
507
508
								if ($nonavailable)
									$info .= "<br/><b>Not available yet</b>";

								if ($child->getAttribute('url'))
									$info .= "<br/>".$child->getAttribute('url');

10200969   Roipoussiere   Remove whitespace...
509
								if ($child->hasAttribute('obsolete'))
735c653b   Elena.Budnik   rank at observato...
510
511
512
513
514
515
516
517
								{
									$info = $child->getAttribute('desc');
									$obsolete = true;
								}
								else
									$obsolete = false;

								$disable = $restricted || $nonavailable || $obsolete;
10200969   Roipoussiere   Remove whitespace...
518

735c653b   Elena.Budnik   rank at observato...
519
								$childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType,  'isAddable' => $isAddable,
10200969   Roipoussiere   Remove whitespace...
520
521
522
								'info' => $info, 'leaf' => false, 'isRemoteDataSet' => $isRemoteDataSet, 'disable' => $disable,
								'isSimulation' => $isSimulation, 'rank' => $rank, 'isDeletable' => $isDeletable, 'help' => $help);
							}
735c653b   Elena.Budnik   rank at observato...
523
						break;
10200969   Roipoussiere   Remove whitespace...
524
525
526

						case 'myData' :
							$info = $child->hasAttribute('info') ? $child->getAttribute('info') : $child->nodeValue;
735c653b   Elena.Budnik   rank at observato...
527
528
529
530
531
532
533
534
535
536
537
						break;

						case 'myDataParam' :

							$globalStart = null;
							$globalStop = null;
							$specialNode = true;
							$size = $child->getAttribute('size');
							$isScatter = $size == 1;
							$mask = $child->getAttribute('mask');
							$isSpectra = false;
10200969   Roipoussiere   Remove whitespace...
538
539

							if ($isLeaf)
735c653b   Elena.Budnik   rank at observato...
540
541
542
543
544
545
							{
									$isParameter = true;
									$info = "Size: ".$size."<br/>".$child->getAttribute('desc')."<br/> Mask: ".$mask;
									$isSpectra = $child->getAttribute('plottype') === 'Spectra';
							}

10200969   Roipoussiere   Remove whitespace...
546
							if ($child->hasAttribute('desc'))
735c653b   Elena.Budnik   rank at observato...
547
548
549
550
551
							{
									$globalStart = substr($child->getAttribute('desc'), 0, 19);
									$globalStop =  substr($child->getAttribute('desc'), 20);
							}

10200969   Roipoussiere   Remove whitespace...
552
							$childrenToReturn[] = array('text' => $name, 'size' =>  $size, 'id' => $id,
735c653b   Elena.Budnik   rank at observato...
553
								'globalStart' => $globalStart, 'globalStop' => $globalStop,
10200969   Roipoussiere   Remove whitespace...
554
								'nodeType' => $nodeType, 'info' => $info, 'isScatter' => $isScatter, 'leaf' => $isLeaf,
735c653b   Elena.Budnik   rank at observato...
555
556
557
								'isParameter' => $isParameter, 'linkedMask' => $mask, 'isSpectra' => $isSpectra);

						break;
10200969   Roipoussiere   Remove whitespace...
558
						default:
735c653b   Elena.Budnik   rank at observato...
559
					}
10200969   Roipoussiere   Remove whitespace...
560
561

					if (!$specialNode && !$skip)
735c653b   Elena.Budnik   rank at observato...
562
					{
10200969   Roipoussiere   Remove whitespace...
563
						if ($child->hasAttribute('desc'))
735c653b   Elena.Budnik   rank at observato...
564
							$info = $child->getAttribute('desc');
10200969   Roipoussiere   Remove whitespace...
565
566

						if ($isSimulation && $service_down)
6657f68b   Elena.Budnik   monitor impex ser...
567
568
569
						{
							$info = "<b>Service is currently down</b>";
						}
10200969   Roipoussiere   Remove whitespace...
570
571

						$childrenToReturn[] = array('text' => $name, 'id' => $id, 'nodeType' => $nodeType, 'info' => $info,
6657f68b   Elena.Budnik   monitor impex ser...
572
													'help' => $help, 'leaf' => $isLeaf, 'isParameter' => $isParameter);
735c653b   Elena.Budnik   rank at observato...
573
574
575
					}
				}
				// if $childrenToReturn we have to return []
e57cb025   Benjamin Renard   Fix most of error...
576
				if (empty($childrenToReturn))
10200969   Roipoussiere   Remove whitespace...
577
				{
735c653b   Elena.Budnik   rank at observato...
578
579
580
					$childrenToReturn = array('nodeType' => $nodeType, 'text' => null);
				}
			}
16035364   Benjamin Renard   First commit
581
      return  $childrenToReturn;
735c653b   Elena.Budnik   rank at observato...
582
	}
16035364   Benjamin Renard   First commit
583

0dc31ba8   Elena.Budnik   remoteParamManage...
584
585
586
587
588
	/*
	*  add Remote Parameter to user RemoteParams.xml
	*  send request to DDServer to AddVi if Vi doesn't exist
	*  create Remote Parameter Description	
	*/
10200969   Roipoussiere   Remove whitespace...
589
	public  function saveTree($obj)
735c653b   Elena.Budnik   rank at observato...
590
	{
0dc31ba8   Elena.Budnik   remoteParamManage...
591
		$paramMgr = new RemoteParamManager();
10200969   Roipoussiere   Remove whitespace...
592
		return $paramMgr->saveTree($obj);
735c653b   Elena.Budnik   rank at observato...
593
	}
0dc31ba8   Elena.Budnik   remoteParamManage...
594
595
596
597
	
	/*
	*  delete Remote Parameter from user RemoteParams.xml
	*/
10200969   Roipoussiere   Remove whitespace...
598
599
	public  function deleteFromTree($obj)
	{
0dc31ba8   Elena.Budnik   remoteParamManage...
600
		$paramMgr = new RemoteParamManager();
10200969   Roipoussiere   Remove whitespace...
601
		return $paramMgr->deleteFromTree($obj);
9a63b7f6   Elena.Budnik   needsArgs to Simu...
602
	}
0dc31ba8   Elena.Budnik   remoteParamManage...
603
604
605
606
607
		
	public  function doNothing($obj)
	{
		return array("res" => 'ok');
	}
16035364   Benjamin Renard   First commit
608

0dc31ba8   Elena.Budnik   remoteParamManage...
609
610
611
	/*
	*  get temporary object from Upload
	*/
9a63b7f6   Elena.Budnik   needsArgs to Simu...
612
	public  function getUploadedObject($name, $format, $nodeType)
10200969   Roipoussiere   Remove whitespace...
613
614
	{
		switch ($nodeType)
9a63b7f6   Elena.Budnik   needsArgs to Simu...
615
		{
10200969   Roipoussiere   Remove whitespace...
616
617
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
9a63b7f6   Elena.Budnik   needsArgs to Simu...
618
				break;
10200969   Roipoussiere   Remove whitespace...
619
620
621
622
623
			case 'myDataParam' :
				$objectMgr = new FilesMgr();
				break;
			case 'catalog' :
				$objectMgr = new CatalogMgr();
9a63b7f6   Elena.Budnik   needsArgs to Simu...
624
				break;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
625
626
627
			default:
				return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
		}
bf74fc2d   Elena.Budnik   IMPEX
628
		return  $objectMgr->getUploadedObject($name, $format, true);
10200969   Roipoussiere   Remove whitespace...
629
	}
16035364   Benjamin Renard   First commit
630

0dc31ba8   Elena.Budnik   remoteParamManage...
631
632
633
	/*
	*  fill ascii file into grid
	*/
10200969   Roipoussiere   Remove whitespace...
634
635
636
	public  function getAsciiFile($obj)
	{
		$objectMgr = new FilesMgr();
bf74fc2d   Elena.Budnik   IMPEX
637
		return  $objectMgr->getAsciiFile($obj->fileName);
735c653b   Elena.Budnik   rank at observato...
638
	}
10200969   Roipoussiere   Remove whitespace...
639
640
641
642

	public function getMyParamInfo($object)
	{
		$objectMgr = new FilesMgr();
bf74fc2d   Elena.Budnik   IMPEX
643
		return  $objectMgr->getParamInfo($object);
10200969   Roipoussiere   Remove whitespace...
644
	}
16035364   Benjamin Renard   First commit
645

0dc31ba8   Elena.Budnik   remoteParamManage...
646
647
648
	/*
	*  get temporary object from Search
	*/
10200969   Roipoussiere   Remove whitespace...
649
650
651
	public  function getTmpObject($folderId, $name, $nodeType)
	{
		switch ($nodeType)
735c653b   Elena.Budnik   rank at observato...
652
		{
10200969   Roipoussiere   Remove whitespace...
653
654
655
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
			break;
735c653b   Elena.Budnik   rank at observato...
656
			case 'catalog' :
10200969   Roipoussiere   Remove whitespace...
657
658
				$objectMgr = new CatalogMgr();
			break;
735c653b   Elena.Budnik   rank at observato...
659
660
661
			default:
				return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
		}
bf74fc2d   Elena.Budnik   IMPEX
662
		return  $objectMgr->getTmpObject($folderId, $name, true);
fdf1413b   Elena.Budnik   TT download
663
	}
735c653b   Elena.Budnik   rank at observato...
664

10200969   Roipoussiere   Remove whitespace...
665
666
667
668

	public  function getObject($id, $nodeType)
	{
		switch ($nodeType)
735c653b   Elena.Budnik   rank at observato...
669
670
		{
			case 'myDataParam':
10200969   Roipoussiere   Remove whitespace...
671
672
			case 'derivedParam' :
				$objectMgr = new DerivedParamMgr($nodeType);
735c653b   Elena.Budnik   rank at observato...
673
				break;
10200969   Roipoussiere   Remove whitespace...
674
			case 'timeTable' :
735c653b   Elena.Budnik   rank at observato...
675
			case 'sharedtimeTable' :
10200969   Roipoussiere   Remove whitespace...
676
677
				$objectMgr = new TimeTableMgr();
				break;
735c653b   Elena.Budnik   rank at observato...
678
679
			case 'catalog' :
			case 'sharedcatalog' :
10200969   Roipoussiere   Remove whitespace...
680
681
682
				$objectMgr = new CatalogMgr();
				break;
			case 'condition' :
735c653b   Elena.Budnik   rank at observato...
683
			case 'request' :
10200969   Roipoussiere   Remove whitespace...
684
685
				$objectMgr = new RequestMgr($nodeType);
				break;
735c653b   Elena.Budnik   rank at observato...
686
			case 'bkgWorks' :
bf74fc2d   Elena.Budnik   IMPEX
687
 				require_once(INTEGRATION_SRC_DIR."RequestManager.php");
735c653b   Elena.Budnik   rank at observato...
688
689
690
				return $this->executeRequest($id, FunctionTypeEnumClass::PROCESSGETINFO);
				break;
			case 'myData' :
10200969   Roipoussiere   Remove whitespace...
691
				$objectMgr = new FilesMgr();
735c653b   Elena.Budnik   rank at observato...
692
				break;
10200969   Roipoussiere   Remove whitespace...
693
			default:
735c653b   Elena.Budnik   rank at observato...
694
695
				return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
		}
bf74fc2d   Elena.Budnik   IMPEX
696
		return  $objectMgr->getObject($id, $nodeType);
fdf1413b   Elena.Budnik   TT download
697
	}
10200969   Roipoussiere   Remove whitespace...
698

16035364   Benjamin Renard   First commit
699
700
701
/*
*   $obj = { id: node.id, leaf: node.leaf, nodeType: node.nodeType }
*/
10200969   Roipoussiere   Remove whitespace...
702
703
704
705
706
707
708
	public  function deleteObject($obj)
	{
		switch ($obj->nodeType)
		{
			case 'myDataParam' :
			case 'derivedParam' :
				$objectMgr = new DerivedParamMgr($obj->nodeType);
735c653b   Elena.Budnik   rank at observato...
709
				break;
10200969   Roipoussiere   Remove whitespace...
710
711
712
713
714
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
				break;
			case 'catalog' :
				$objectMgr = new CatalogMgr();
735c653b   Elena.Budnik   rank at observato...
715
				break;
10200969   Roipoussiere   Remove whitespace...
716
			case 'condition' :
735c653b   Elena.Budnik   rank at observato...
717
			case 'request' :
10200969   Roipoussiere   Remove whitespace...
718
				$objectMgr = new RequestMgr($obj->nodeType);
735c653b   Elena.Budnik   rank at observato...
719
720
721
722
				break;
			case 'alias' :
				$objectMgr = new AliasMgr();
				$obj->id = substr($obj->id,strlen('alias_'));
10200969   Roipoussiere   Remove whitespace...
723
				break;
735c653b   Elena.Budnik   rank at observato...
724
			case 'bkgWorks' :
bf74fc2d   Elena.Budnik   IMPEX
725
 				require_once(INTEGRATION_SRC_DIR."RequestManager.php");
735c653b   Elena.Budnik   rank at observato...
726
727
728
				return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSDELETE);

			case 'myData' :
16035364   Benjamin Renard   First commit
729
				$objectMgr = new FilesMgr();
735c653b   Elena.Budnik   rank at observato...
730
731
732
733
734
735
				break;
			default:
					return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}
		return  $objectMgr -> deleteObject($obj);
	}
16035364   Benjamin Renard   First commit
736
737
738
739

/*
*   $obj = { id: node.id, old_name: node.text, name: value,  parent : node.parentNode.id, leaf: node.leaf, nodeType: node.nodeType }
*/
10200969   Roipoussiere   Remove whitespace...
740
741
742
	public  function renameObject($obj)
	{
		switch ($obj->nodeType)
735c653b   Elena.Budnik   rank at observato...
743
		{
10200969   Roipoussiere   Remove whitespace...
744

16035364   Benjamin Renard   First commit
745
		  case 'myDataParam' :
10200969   Roipoussiere   Remove whitespace...
746
747
748
749
750
		  case 'derivedParam' :
			   $objectMgr = new DerivedParamMgr($obj->nodeType);
			   break;
		  case 'timeTable' :
			   $objectMgr = new TimeTableMgr();
16035364   Benjamin Renard   First commit
751
			   break;
10200969   Roipoussiere   Remove whitespace...
752
753
		  case 'catalog' :
			   $objectMgr = new CatalogMgr();
d18b535d   elena   catalog draft + c...
754
			   break;
10200969   Roipoussiere   Remove whitespace...
755
756
757
		  case 'condition' :
		  case 'request' :
			   $objectMgr = new RequestMgr($obj->nodeType);
16035364   Benjamin Renard   First commit
758
759
			   break;
		  case 'alias' :
10200969   Roipoussiere   Remove whitespace...
760
761
		  	   $objectMgr = new AliasMgr();
		  	   break;
16035364   Benjamin Renard   First commit
762
763
		  default:
			    return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
735c653b   Elena.Budnik   rank at observato...
764
		}
16035364   Benjamin Renard   First commit
765

735c653b   Elena.Budnik   rank at observato...
766
767
		return  $objectMgr -> renameObject($obj);
	}
16035364   Benjamin Renard   First commit
768

10200969   Roipoussiere   Remove whitespace...
769
/*
16035364   Benjamin Renard   First commit
770
771
*   $obj = { name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES }
*/
10200969   Roipoussiere   Remove whitespace...
772
773
774
	public  function createObject($obj, $folder)
	{
		switch ($obj->nodeType)
9a63b7f6   Elena.Budnik   needsArgs to Simu...
775
		{
10200969   Roipoussiere   Remove whitespace...
776
			case 'myDataParam' :
9a63b7f6   Elena.Budnik   needsArgs to Simu...
777
			case 'derivedParam' :
10200969   Roipoussiere   Remove whitespace...
778
				if ($obj->nodeType == 'derivedParam' &&  $this->amdaStat->success)
9a63b7f6   Elena.Budnik   needsArgs to Simu...
779
						$this->amdaStat->addTask('create', $this->user, null);
10200969   Roipoussiere   Remove whitespace...
780
781
782
783
784
785
786
				$objectMgr = new DerivedParamMgr($obj->nodeType);
				break;
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
				break;
			case 'catalog' :
				$objectMgr = new CatalogMgr();
16035364   Benjamin Renard   First commit
787
			   break;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
788
			case 'condition' :
10200969   Roipoussiere   Remove whitespace...
789
790
791
			case 'request' :
				$objectMgr = new RequestMgr($obj->nodeType);
				break;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
792
			case 'alias' :
10200969   Roipoussiere   Remove whitespace...
793
794
				$objectMgr = new AliasMgr();
				break;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
795
796
797
798
799
			default:
				return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}
		return  $objectMgr -> createObject($obj, $folder);
	}
16035364   Benjamin Renard   First commit
800

10200969   Roipoussiere   Remove whitespace...
801
/*
16035364   Benjamin Renard   First commit
802
803
*   $obj = { id:obj.id, name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES }
*/
10200969   Roipoussiere   Remove whitespace...
804
	public  function modifyObject($obj)
9a63b7f6   Elena.Budnik   needsArgs to Simu...
805
	{
10200969   Roipoussiere   Remove whitespace...
806
807
808
809
810
		switch ($obj->nodeType)
		{
			case 'myDataParam' :
			case 'derivedParam' :
				$objectMgr = new DerivedParamMgr($obj->nodeType);
9a63b7f6   Elena.Budnik   needsArgs to Simu...
811
				break;
10200969   Roipoussiere   Remove whitespace...
812
813
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
9a63b7f6   Elena.Budnik   needsArgs to Simu...
814
				break;
10200969   Roipoussiere   Remove whitespace...
815
816
817
818
			case 'catalog' :
				$objectMgr = new CatalogMgr();
				break;
			case 'condition' :
9a63b7f6   Elena.Budnik   needsArgs to Simu...
819
			case 'request' :
10200969   Roipoussiere   Remove whitespace...
820
				$objectMgr = new RequestMgr($obj->nodeType);
9a63b7f6   Elena.Budnik   needsArgs to Simu...
821
822
823
824
825
				break;
			default:
				return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}
		return  $objectMgr -> modifyObject($obj);
10200969   Roipoussiere   Remove whitespace...
826
	}
16035364   Benjamin Renard   First commit
827
828
829
830
831
832
833
834
835
836
/*
 * {obj.name, obj.nodeType, obj.leaf}
 */
    public function validNameObject($obj) {
		switch ($obj->nodeType) {
			case 'myDataParam' :
			case 'derivedParam' :
				$objectMgr = new DerivedParamMgr($obj->nodeType);
				break;
			case 'timeTable' :
d18b535d   elena   catalog draft + c...
837
			case 'sharedtimeTable' :
16035364   Benjamin Renard   First commit
838
839
				$objectMgr = new TimeTableMgr();
				break;
d18b535d   elena   catalog draft + c...
840
			case 'catalog' :
169f14d2   Benjamin Renard   Add shared object...
841
			case 'sharedcatalog' :
d18b535d   elena   catalog draft + c...
842
843
				$objectMgr = new CatalogMgr();
				break;
16035364   Benjamin Renard   First commit
844
845
846
847
848
849
850
851
852
853
854
855
			case 'condition' :
			case 'request' :
				$objectMgr = new RequestMgr($obj->nodeType);
				break;
			default:
				return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}

		return  $objectMgr -> validNameObject($obj);
    }

/*
bae6f5da   Nathanael Jourdane   bugFix fileName f...
856
*   Get running jobs
16035364   Benjamin Renard   First commit
857
*/
bae6f5da   Nathanael Jourdane   bugFix fileName f...
858
	public function getJobs($obj = null)
6acb8d2a   Elena.Budnik   checkRequest in R...
859
	{
6acb8d2a   Elena.Budnik   checkRequest in R...
860
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
e57cb025   Benjamin Renard   Fix most of error...
861
		$obj = (object) array();
10200969   Roipoussiere   Remove whitespace...
862
		return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSRUNNINGINFO);
6acb8d2a   Elena.Budnik   checkRequest in R...
863
	}
16035364   Benjamin Renard   First commit
864
865
866
867
868
869
870


	/* AKKA-KERNEL-INT
	Move user check from RequestMgr.php to AmdaAction.php
	*/
	private function checkUser($obj)
	{
32bb889b   Elena.Budnik   #5532 to process ...
871
		if (defined('NEWKERNEL_DEBUG') && NEWKERNEL_DEBUG){
16035364   Benjamin Renard   First commit
872
873
874
			$this->user = NEWKERNEL_DEBUG_USER;
			return array('success' => true);
		}
10200969   Roipoussiere   Remove whitespace...
875

16035364   Benjamin Renard   First commit
876
		if (isset($obj->username) && isset($obj->password) && isset($obj->sessionID))
735c653b   Elena.Budnik   rank at observato...
877
		{
e5ab198f   Nathanael Jourdane   simple getStatus
878
			$dd = new WSUserMgr();
fcdd1349   Elena.Budnik   merge with master
879
			$dd->init($obj->username,$obj->password,$obj->sessionID, false);
735c653b   Elena.Budnik   rank at observato...
880
		}
a21497cc   Elena.Budnik   redmine #5645
881
		else {
16035364   Benjamin Renard   First commit
882
			$dd = new UserMgr();
a21497cc   Elena.Budnik   redmine #5645
883
884
			$dd->setSpecialSettings();
		}
10200969   Roipoussiere   Remove whitespace...
885
886

		//TODO error handling
32bb889b   Elena.Budnik   #5532 to process ...
887
		if (($res = $dd->ddCheckUser()) != 0) {
10200969   Roipoussiere   Remove whitespace...
888
			if ($res == 156)
6acb8d2a   Elena.Budnik   checkRequest in R...
889
				return array('success' => false, 'message' => 'Your AMDA session is expired.<br/> Login please!');
16035364   Benjamin Renard   First commit
890

735c653b   Elena.Budnik   rank at observato...
891
892
			return array('success' => false, 'message' => 'ddLogin error: '.$res);
		}
16035364   Benjamin Renard   First commit
893

6acb8d2a   Elena.Budnik   checkRequest in R...
894
		if ($dd->user == 'impex')
16035364   Benjamin Renard   First commit
895
896
897
		{
			//if ($dd->getWsSize() > DISK_QUOTA * 100)
			//	error_log('Natacha! It is time to CLEAN UP IMPEX WS!',1,'nbourrel@irap.omp.eu');
e5ab198f   Nathanael Jourdane   simple getStatus
898
//			return array('success' => false, "message" => "AKKA-KERNEL-INT - WS support for IMPEx not implemented");
6acb8d2a   Elena.Budnik   checkRequest in R...
899
		}
32bb889b   Elena.Budnik   #5532 to process ...
900
		else {
a21497cc   Elena.Budnik   redmine #5645
901
			// check disk space 
6acb8d2a   Elena.Budnik   checkRequest in R...
902
			if ($dd->getWsSize() > DISK_QUOTA)
16035364   Benjamin Renard   First commit
903
				return array('success' => false, 'message' => 'Please clean up your workspace.<br/>No more space is available');
735c653b   Elena.Budnik   rank at observato...
904
		}
10200969   Roipoussiere   Remove whitespace...
905

735c653b   Elena.Budnik   rank at observato...
906
		$this->user = $dd->user;
10200969   Roipoussiere   Remove whitespace...
907

32bb889b   Elena.Budnik   #5532 to process ...
908
		return array('success' => true, 'userHost' => $dd->getIPclient());
16035364   Benjamin Renard   First commit
909
	}
10200969   Roipoussiere   Remove whitespace...
910

6acb8d2a   Elena.Budnik   checkRequest in R...
911
	private function executeRequest($obj, $function)
10200969   Roipoussiere   Remove whitespace...
912
	{
32bb889b   Elena.Budnik   #5532 to process ...
913
914
915
916
917
		// Check user if access to DD Server and / or possible 'space consuming' action
		if (  $function == FunctionTypeEnumClass::PARAMS ||
				$function == FunctionTypeEnumClass::ACTION ||
				$function == FunctionTypeEnumClass::PARAMSGEN )
		{
7ac3e07e   Elena.Budnik   do not check user...
918
919
920
921
			$res = $this->checkUser($obj);
			if (!$res['success']) return $res;
		}
		
16035364   Benjamin Renard   First commit
922
		$requestManager = new RequestManagerClass();
10200969   Roipoussiere   Remove whitespace...
923

32bb889b   Elena.Budnik   #5532 to process ...
924
		try {
e57cb025   Benjamin Renard   Fix most of error...
925
			$res = $requestManager->runIHMRequest($this->user, !empty($res['userHost']) ? $res['userHost'] : NULL, $function, $obj);
9b69cb35   Nathanael Jourdane   Implement batch m...
926
		} catch (Exception $e) {
16035364   Benjamin Renard   First commit
927
			return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage());
10200969   Roipoussiere   Remove whitespace...
928
		}
32bb889b   Elena.Budnik   #5532 to process ...
929
		
16035364   Benjamin Renard   First commit
930
931
		return $res;
	}
10200969   Roipoussiere   Remove whitespace...
932
933
934

/*
*    Main EXECUTE PROCEDURE
16035364   Benjamin Renard   First commit
935
*/
735c653b   Elena.Budnik   rank at observato...
936
937
	public  function execute($node, $obj)
	{
16035364   Benjamin Renard   First commit
938
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
10200969   Roipoussiere   Remove whitespace...
939

fdf1413b   Elena.Budnik   TT download
940
941
942
943
		// just convert TT / Catalog
		if ($obj->nodeType == "download" &&  $obj->downloadSrc == "1")
			return $this->executeRequest($obj, FunctionTypeEnumClass::TTCONVERT);
		else if (isset($obj->action))
16035364   Benjamin Renard   First commit
944
			return $this->executeRequest($obj, FunctionTypeEnumClass::ACTION);
10200969   Roipoussiere   Remove whitespace...
945
946
		else
		{
6acb8d2a   Elena.Budnik   checkRequest in R...
947
948
			$res = RequestMgr::checkRequest($obj);
			if (!$res['success']) return $res;
10200969   Roipoussiere   Remove whitespace...
949

16035364   Benjamin Renard   First commit
950
			return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMS);
6acb8d2a   Elena.Budnik   checkRequest in R...
951
		}
fdf1413b   Elena.Budnik   TT download
952
	}
10200969   Roipoussiere   Remove whitespace...
953

16035364   Benjamin Renard   First commit
954
/*
a0b3d64e   Benjamin Renard   Derived parameter...
955
956
 * Generate derived parameter compilation
 */
735c653b   Elena.Budnik   rank at observato...
957
958
959
960
961
	public function compilParam($obj)
	{
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMSGEN);
	}
a0b3d64e   Benjamin Renard   Derived parameter...
962
963
964
965

/*
 * Delete derived parameter compilation
 */
735c653b   Elena.Budnik   rank at observato...
966
967
	public function compilParamDelete($obj)
	{
a0b3d64e   Benjamin Renard   Derived parameter...
968
969
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		$res = $this->checkUser($obj);
10200969   Roipoussiere   Remove whitespace...
970

a0b3d64e   Benjamin Renard   Derived parameter...
971
972
		if (!$res['success'])
			return $res;
10200969   Roipoussiere   Remove whitespace...
973

a0b3d64e   Benjamin Renard   Derived parameter...
974
975
976
977
		IHMConfigClass::setUserName($this->user);
		$libParamPath = IHMConfigClass::getCompilationPath()."lib/".$obj->paramId.".so";
		if (file_exists($libParamPath))
			unlink($libParamPath);
735c653b   Elena.Budnik   rank at observato...
978
979
		return array("success" => true);
	}
10200969   Roipoussiere   Remove whitespace...
980

a0b3d64e   Benjamin Renard   Derived parameter...
981
/*
e6e5b259   Benjamin Renard   Add kill plot req...
982
 * kill plot process
16035364   Benjamin Renard   First commit
983
 */
10200969   Roipoussiere   Remove whitespace...
984

735c653b   Elena.Budnik   rank at observato...
985
	public function killPlotRequest()
10200969   Roipoussiere   Remove whitespace...
986
	{
735c653b   Elena.Budnik   rank at observato...
987
988
989
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		return $this->executeRequest((object) array('nodeType' => 'killplot'), FunctionTypeEnumClass::PARAMS);
	}
16035364   Benjamin Renard   First commit
990
991
992
993

/*
 * merge time tables
 */
10200969   Roipoussiere   Remove whitespace...
994
	public  function merge($obj)
735c653b   Elena.Budnik   rank at observato...
995
996
997
	{
		if ($this->amdaStat->success)
			$this->amdaStat->addTask('ttoper', $this->user, null);
10200969   Roipoussiere   Remove whitespace...
998

735c653b   Elena.Budnik   rank at observato...
999
		$objectMgr = new TimeTableMgr();
16035364   Benjamin Renard   First commit
1000

735c653b   Elena.Budnik   rank at observato...
1001
1002
		return  $objectMgr -> merge($obj);
	}
16035364   Benjamin Renard   First commit
1003

10200969   Roipoussiere   Remove whitespace...
1004

16035364   Benjamin Renard   First commit
1005
1006
1007
/*
 * intersect time tables
 */
10200969   Roipoussiere   Remove whitespace...
1008
	public  function intersect($obj)
735c653b   Elena.Budnik   rank at observato...
1009
1010
1011
	{
		if ($this->amdaStat->success)
				$this->amdaStat->addTask('ttoper', $this->user, null);
16035364   Benjamin Renard   First commit
1012

735c653b   Elena.Budnik   rank at observato...
1013
1014
		$objectMgr = new TimeTableMgr();
		$result = $objectMgr -> intersect($obj);
16035364   Benjamin Renard   First commit
1015

735c653b   Elena.Budnik   rank at observato...
1016
1017
		return  $result;
	}
10200969   Roipoussiere   Remove whitespace...
1018

735c653b   Elena.Budnik   rank at observato...
1019
1020
1021
1022
	public function initTTCache($isCatalog = false, $nparams)
	{
		if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
		else              $cacheMgr = new CatalogCacheMgr();
10200969   Roipoussiere   Remove whitespace...
1023

735c653b   Elena.Budnik   rank at observato...
1024
1025
		return $cacheMgr->initTTCache($nparams);
	}
10200969   Roipoussiere   Remove whitespace...
1026
1027


735c653b   Elena.Budnik   rank at observato...
1028
1029
1030
1031
	public function initTTCacheFromTT($id, $type)
	{
		if ($type == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr();
		else $cacheMgr = new TimeTableCacheMgr();
10200969   Roipoussiere   Remove whitespace...
1032

735c653b   Elena.Budnik   rank at observato...
1033
1034
		return $cacheMgr->initFromTT($id, $type);
	}
10200969   Roipoussiere   Remove whitespace...
1035

735c653b   Elena.Budnik   rank at observato...
1036
1037
	public function initForChart($id, $name, $isTmpObject, $type)
	{
e1fd05b4   Elena.Budnik   visu from cacheCat
1038
1039
1040
		if ($isTmpObject && $type == 'catalog' && $id == 'cacheCat')
			return array('success' => true, 'cache' => $id);
			
735c653b   Elena.Budnik   rank at observato...
1041
		if ($type == 'catalog' || $type == 'sharedcatalog') $objMgr = new CatalogMgr();
10200969   Roipoussiere   Remove whitespace...
1042

735c653b   Elena.Budnik   rank at observato...
1043
1044
		return $objMgr->initForChart($id, $name, $isTmpObject, $type);
	}
10200969   Roipoussiere   Remove whitespace...
1045

735c653b   Elena.Budnik   rank at observato...
1046
1047
	public function initTTCacheFromTmpObject($folderId, $name, $isCatalog = false)
	{
10200969   Roipoussiere   Remove whitespace...
1048
		if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
735c653b   Elena.Budnik   rank at observato...
1049
1050
1051
1052
		else  $cacheMgr = new CatalogCacheMgr();

		return $cacheMgr->initFromTmpObject($folderId, $name);
	}
10200969   Roipoussiere   Remove whitespace...
1053

901ba3f3   Elena.Budnik   upload catalog
1054
	public function initTTCacheFromUploadedFile($name, $format, $isCatalog = false)
735c653b   Elena.Budnik   rank at observato...
1055
	{
901ba3f3   Elena.Budnik   upload catalog
1056
1057
		if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
		else  $cacheMgr = new CatalogCacheMgr();
10200969   Roipoussiere   Remove whitespace...
1058

735c653b   Elena.Budnik   rank at observato...
1059
1060
		return $cacheMgr->initFromUploadedFile($name, $format);
	}
10200969   Roipoussiere   Remove whitespace...
1061

735c653b   Elena.Budnik   rank at observato...
1062
1063
	public function readTTCacheIntervals($o)
	{
e57cb025   Benjamin Renard   Fix most of error...
1064
		if (isset($o->typeTT) && ($o->typeTT == 'catalog' || $o->typeTT == 'sharedcatalog')) $cacheMgr = new CatalogCacheMgr();
735c653b   Elena.Budnik   rank at observato...
1065
		else $cacheMgr = new TimeTableCacheMgr();
10200969   Roipoussiere   Remove whitespace...
1066

e57cb025   Benjamin Renard   Fix most of error...
1067
		return $cacheMgr->getIntervals($o->start,$o->limit,isset($o->sort) ? $o->sort : NULL, isset($o->filter) ? $o->filter : NULL);
735c653b   Elena.Budnik   rank at observato...
1068
	}
10200969   Roipoussiere   Remove whitespace...
1069

735c653b   Elena.Budnik   rank at observato...
1070
1071
	public function readIntervalsForChart($o)
	{
e57cb025   Benjamin Renard   Fix most of error...
1072
		if (isset($o->typeTT) && ($o->typeTT == 'catalog' || $o->typeTT == 'sharedcatalog')) {
e1fd05b4   Elena.Budnik   visu from cacheCat
1073
1074
1075
1076
1077
1078
1079
1080
1081
				
				if ($o->fromPlugin && $o->id == 'cacheCat') {
					$objMgr = new CatalogCacheMgr();
					
					return $objMgr->getIntervals();
				}
				
				$objMgr = new CatalogMgr();
		}
10200969   Roipoussiere   Remove whitespace...
1082

735c653b   Elena.Budnik   rank at observato...
1083
1084
		return $objMgr->getIntervalsForChart($o->id, $o->name, $o->fromPlugin, $o->typeTT);
	}
10200969   Roipoussiere   Remove whitespace...
1085

735c653b   Elena.Budnik   rank at observato...
1086
1087
1088
1089
1090
	public function saveTTCacheIntervalsInTT($o)
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->saveInTT($o->ttId,$o->action,$o->cacheToken);
	}
10200969   Roipoussiere   Remove whitespace...
1091

735c653b   Elena.Budnik   rank at observato...
1092
1093
1094
1095
1096
1097
1098
	public function addTTCacheInterval($o)
	{
		if ($o->isCatalog) $cacheMgr = new CatalogCacheMgr();
		else $cacheMgr = new TimeTableCacheMgr();

		return $cacheMgr->addInterval($o->index, $o->start, $o->stop);
	}
10200969   Roipoussiere   Remove whitespace...
1099

735c653b   Elena.Budnik   rank at observato...
1100
1101
1102
1103
1104
1105
1106
	public function removeTTCacheIntervalFromId($id, $isCatalog = false)
	{
		if ($isCatalog) $cacheMgr = new CatalogCacheMgr();
		else $cacheMgr = new TimeTableCacheMgr();

		return $cacheMgr->removeIntervalFromId($id);
	}
10200969   Roipoussiere   Remove whitespace...
1107

735c653b   Elena.Budnik   rank at observato...
1108
1109
	public function modifyTTCacheInterval($o)
	{
10200969   Roipoussiere   Remove whitespace...
1110
		if ($o->isCatalog)
735c653b   Elena.Budnik   rank at observato...
1111
		{
f9c8b272   elena   edit catalog
1112
			$cacheMgr = new CatalogCacheMgr();
735c653b   Elena.Budnik   rank at observato...
1113
			return $cacheMgr->modifyIntervalFromId($o);
f9c8b272   elena   edit catalog
1114
		}
735c653b   Elena.Budnik   rank at observato...
1115
		else $cacheMgr = new TimeTableCacheMgr();
10200969   Roipoussiere   Remove whitespace...
1116

735c653b   Elena.Budnik   rank at observato...
1117
1118
		return $cacheMgr->modifyIntervalFromId($o->cacheId, $o->start, $o->stop);
	}
10200969   Roipoussiere   Remove whitespace...
1119

735c653b   Elena.Budnik   rank at observato...
1120
1121
1122
1123
1124
	public function operationTTCacheIntervals($extendTime, $shiftTime)
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->operationIntervals($extendTime, $shiftTime);
	}
10200969   Roipoussiere   Remove whitespace...
1125

735c653b   Elena.Budnik   rank at observato...
1126
1127
1128
1129
1130
	public function mergeTTCacheIntervals()
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->mergeIntervals();
	}
10200969   Roipoussiere   Remove whitespace...
1131

735c653b   Elena.Budnik   rank at observato...
1132
1133
1134
1135
1136
	public function getTTCacheStatistics()
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->getStatistics();
	}
10200969   Roipoussiere   Remove whitespace...
1137

735c653b   Elena.Budnik   rank at observato...
1138
1139
1140
1141
1142
	public function getTTCacheStatus()
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->getStatus();
	}
aa94fd24   elena   Merge with last svn
1143

16035364   Benjamin Renard   First commit
1144
1145
/*
 * Send a feedback
10200969   Roipoussiere   Remove whitespace...
1146
 *
16035364   Benjamin Renard   First commit
1147
 */
735c653b   Elena.Budnik   rank at observato...
1148
1149
1150
1151
1152
	public function sendFeedback($feed)
	{
		$feedMgr = new FeedbackMgr();
		return $feedMgr->addFeedback($feed->user, $feed->interface, $feed->subject, $feed->userText, $feed->userAgent, $feed->attach);
	}
10200969   Roipoussiere   Remove whitespace...
1153

16035364   Benjamin Renard   First commit
1154
1155
/*
 * Save state
10200969   Roipoussiere   Remove whitespace...
1156
 *
16035364   Benjamin Renard   First commit
1157
 */
735c653b   Elena.Budnik   rank at observato...
1158
1159
1160
1161
1162
	public function saveState($datas)
	{
		$myStateMgr = new StateMgr();
		return $myStateMgr->saveState($datas);
	}
10200969   Roipoussiere   Remove whitespace...
1163

16035364   Benjamin Renard   First commit
1164
1165
/*
 * Load state
10200969   Roipoussiere   Remove whitespace...
1166
1167
 *
 */
735c653b   Elena.Budnik   rank at observato...
1168
	public function loadState($o)
10200969   Roipoussiere   Remove whitespace...
1169
	{
735c653b   Elena.Budnik   rank at observato...
1170
1171
1172
		$myStateMgr = new StateMgr();
		return $myStateMgr->loadState();
	}
10200969   Roipoussiere   Remove whitespace...
1173
1174

/*
16035364   Benjamin Renard   First commit
1175
1176
 * HST Images
 */
735c653b   Elena.Budnik   rank at observato...
1177
1178
1179
1180
	public function getHstImagesUrl($o)
	{
		if ($this->amdaStat->success)
			$this->amdaStat->addTask('images', $this->user, null);
10200969   Roipoussiere   Remove whitespace...
1181

735c653b   Elena.Budnik   rank at observato...
1182
1183
1184
1185
1186
1187
		$myHstMgr = new HstMgr();
		$res = $myHstMgr->getImagesUrl($o->startTime, $o->stopTime, $o->planet);
		//if ($domRes->length <= 0)
		//	return array('success' => false, 'message' => 'Cannot find HST Images for this request.');
		return array('success' => true, 'result' => $res);
	}
10200969   Roipoussiere   Remove whitespace...
1188

735c653b   Elena.Budnik   rank at observato...
1189
1190
	public function getAPISImagesUrl($o)
	{
10200969   Roipoussiere   Remove whitespace...
1191
		if ($this->amdaStat->success)
735c653b   Elena.Budnik   rank at observato...
1192
			$this->amdaStat->addTask('images', $this->user, null);
10200969   Roipoussiere   Remove whitespace...
1193

735c653b   Elena.Budnik   rank at observato...
1194
1195
1196
1197
		$apisMgr = new APISMgr();
		$res = $apisMgr->get($o->target, $o->startTime, $o->stopTime, $o->datasets);

		return $res;
10200969   Roipoussiere   Remove whitespace...
1198
	}
16035364   Benjamin Renard   First commit
1199
1200
1201
/*
 * Filters
 */
e57cb025   Benjamin Renard   Fix most of error...
1202
	public function loadFilterList()
735c653b   Elena.Budnik   rank at observato...
1203
	{
10200969   Roipoussiere   Remove whitespace...
1204
		$filtersMgr = new FiltersMgr();
735c653b   Elena.Budnik   rank at observato...
1205
1206
1207
		$res = $filtersMgr->loadList();
		return $res;
	}
16035364   Benjamin Renard   First commit
1208

735c653b   Elena.Budnik   rank at observato...
1209
1210
1211
1212
1213
1214
1215
1216
1217
	public function loadFilters($o)
	{
		$filtersMgr = new FiltersMgr();
		if (isset($o->id))
			$res = $filtersMgr->loadFilter($o->id);
		else
			$res = $filtersMgr->loadAll();
		return $res;
	}
10200969   Roipoussiere   Remove whitespace...
1218

735c653b   Elena.Budnik   rank at observato...
1219
1220
	public function saveFilter($o)
	{
10200969   Roipoussiere   Remove whitespace...
1221
		$filtersMgr = new FiltersMgr();
735c653b   Elena.Budnik   rank at observato...
1222
1223
		return $filtersMgr->save($o);
	}
10200969   Roipoussiere   Remove whitespace...
1224

735c653b   Elena.Budnik   rank at observato...
1225
1226
	public function createFilter($o)
	{
10200969   Roipoussiere   Remove whitespace...
1227
		$filtersMgr = new FiltersMgr();
735c653b   Elena.Budnik   rank at observato...
1228
1229
		return $filtersMgr->create($o);
	}
10200969   Roipoussiere   Remove whitespace...
1230

735c653b   Elena.Budnik   rank at observato...
1231
1232
1233
1234
1235
1236
	public function destroyFilter($o)
	{
		$filtersMgr = new FiltersMgr();
		$res = $filtersMgr->delete($o);
		return;
	}
10200969   Roipoussiere   Remove whitespace...
1237

735c653b   Elena.Budnik   rank at observato...
1238
1239
1240
1241
1242
1243
1244
	public function getCrtFilterId()
	{
		$filtersMgr = new FiltersMgr();
		$res = $filtersMgr->getCrtId();
		return $res;
	}

fdf1413b   Elena.Budnik   TT download
1245
1246
	public function getCrtFilterResult()
	{
10200969   Roipoussiere   Remove whitespace...
1247
		$filtersMgr = new FiltersMgr();
fdf1413b   Elena.Budnik   TT download
1248
1249
		return $filtersMgr->getCrtResult();
	}
10200969   Roipoussiere   Remove whitespace...
1250

fdf1413b   Elena.Budnik   TT download
1251
1252
	public function setCrtFilterId($o)
	{
10200969   Roipoussiere   Remove whitespace...
1253
		$filtersMgr = new FiltersMgr();
fdf1413b   Elena.Budnik   TT download
1254
1255
		return $filtersMgr->setCrtId($o->id);
	}
10200969   Roipoussiere   Remove whitespace...
1256

fdf1413b   Elena.Budnik   TT download
1257
1258
1259
1260
1261
1262
	public function resetFilter()
	{
		$filtersMgr = new FiltersMgr();
		$res = $filtersMgr->reset();
		return $res;
	}
10200969   Roipoussiere   Remove whitespace...
1263

16035364   Benjamin Renard   First commit
1264
1265
	public function logout($isGuest)
	{
10200969   Roipoussiere   Remove whitespace...
1266
		if ($isGuest)
735c653b   Elena.Budnik   rank at observato...
1267
		{
fdf1413b   Elena.Budnik   TT download
1268
1269
1270
			$guestMgr = new Guest($this->user);
			$guestMgr->deleteGuest();
		}
10200969   Roipoussiere   Remove whitespace...
1271
		else
735c653b   Elena.Budnik   rank at observato...
1272
		{
fdf1413b   Elena.Budnik   TT download
1273
			$this->cleanUserWS();
10200969   Roipoussiere   Remove whitespace...
1274
		}
16035364   Benjamin Renard   First commit
1275
		return;
10200969   Roipoussiere   Remove whitespace...
1276
	}
16035364   Benjamin Renard   First commit
1277

fdf1413b   Elena.Budnik   TT download
1278
1279
	public function getInfo($obj)
	{
10200969   Roipoussiere   Remove whitespace...
1280
		if (file_exists(HELPPATH.$obj->name))
fdf1413b   Elena.Budnik   TT download
1281
		{
10200969   Roipoussiere   Remove whitespace...
1282
			$content = file_get_contents(HELPPATH.$obj->name);
fdf1413b   Elena.Budnik   TT download
1283
1284
			return  array('success' => true, 'result' => $content);
		}
10200969   Roipoussiere   Remove whitespace...
1285
1286
1287
		return array('success' => false);
	}

fdf1413b   Elena.Budnik   TT download
1288
1289
1290
1291
1292
	public function getUserInfo()
	{
		$dd = new UserMgr();
		return $dd->getUserInfo();
	}
16035364   Benjamin Renard   First commit
1293

fdf1413b   Elena.Budnik   TT download
1294
1295
1296
1297
1298
	public function convertWS()
	{
		$dd = new UserMgr();
		return $dd->convertWS();
	}
16035364   Benjamin Renard   First commit
1299

fdf1413b   Elena.Budnik   TT download
1300
1301
1302
1303
1304
1305
	// $obj ={"Object":"Earth","RunCount":"2",
	// "SW_Density_value":"10","SW_Density_weight":"1","SW_Density_scale":"7","SW_Temperature_value":"100", ....}
	public function getRun($obj)
	{
		$myBestRunsMgr = new BestRunsMgr();
		$res = $myBestRunsMgr->getRun($obj);
10200969   Roipoussiere   Remove whitespace...
1306
1307

		return  $res;
fdf1413b   Elena.Budnik   TT download
1308
	}
10200969   Roipoussiere   Remove whitespace...
1309
1310

	//$obj = array of IDs
fdf1413b   Elena.Budnik   TT download
1311
1312
1313
	public function addRun($obj)
	{
		$myBestRunsMgr = new BestRunsMgr();
10200969   Roipoussiere   Remove whitespace...
1314

bf74fc2d   Elena.Budnik   IMPEX
1315
		$ok = $myBestRunsMgr->init();
10200969   Roipoussiere   Remove whitespace...
1316

bf74fc2d   Elena.Budnik   IMPEX
1317
1318
		if (!$ok)
			return array('success'=>false,'message'=>'cannot init addRun');
10200969   Roipoussiere   Remove whitespace...
1319

fdf1413b   Elena.Budnik   TT download
1320
		$myBestRunsMgr->addRuns($obj);
10200969   Roipoussiere   Remove whitespace...
1321

bf74fc2d   Elena.Budnik   IMPEX
1322
		return array('success'=>true,'addedRuns'=>$obj);
10200969   Roipoussiere   Remove whitespace...
1323
1324
	}

fdf1413b   Elena.Budnik   TT download
1325
1326
1327
1328
	//AKKA - New action to clean user WS
	public function cleanUserWS()
	{
		$this->rrmdir(USERDIR.'DOWNLOAD.TEMP');
fdf1413b   Elena.Budnik   TT download
1329
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
bf74fc2d   Elena.Budnik   IMPEX
1330
		IHMConfigClass::setUserName($this->user);
10200969   Roipoussiere   Remove whitespace...
1331
1332

		// delete impex params and data
bf74fc2d   Elena.Budnik   IMPEX
1333
1334
		$impexParamMgr = new ImpexParamManager();
		$impexParamMgr->deleteImpexStaff();
10200969   Roipoussiere   Remove whitespace...
1335

e57cb025   Benjamin Renard   Fix most of error...
1336
		$obj = (object) array();
fdf1413b   Elena.Budnik   TT download
1337
1338
		return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSCLEAN);
	}
10200969   Roipoussiere   Remove whitespace...
1339

fdf1413b   Elena.Budnik   TT download
1340
1341
1342
	public function rrmdir($dir){
		if (is_dir($dir)) {
			$objects = scandir($dir);
10200969   Roipoussiere   Remove whitespace...
1343
1344
			foreach ($objects as $object) { // Recursively delete a directory that is not empty and directorys in directory
				if ($object != "." && $object != "..") {  // If object isn't a directory recall recursively this function
fdf1413b   Elena.Budnik   TT download
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
					if (filetype($dir."/".$object) == "dir")
						$this->rrmdir($dir."/".$object);
					else
						unlink($dir."/".$object);
				}
			}
			reset($objects);
			rmdir($dir);
		}
	}

	public function deleteSpecialInfo($name)
	{
10200969   Roipoussiere   Remove whitespace...
1358
		if (file_exists(USERDIR.$name))
fdf1413b   Elena.Budnik   TT download
1359
1360
1361
					unlink(USERDIR.$name);
		return array('success' => true);
	}
10200969   Roipoussiere   Remove whitespace...
1362

fdf1413b   Elena.Budnik   TT download
1363
1364
1365
1366
1367
1368
1369
1370
1371
	public function interactivePlot($obj, $multiPlotState)
	{
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		$inputobj = (Object)array(
			'action' => $obj,
			'multiPlotState' => $multiPlotState
		);
		return $this->executeRequest($inputobj, FunctionTypeEnumClass::ACTION);
	}
10200969   Roipoussiere   Remove whitespace...
1372

735c653b   Elena.Budnik   rank at observato...
1373
1374
1375
	public function getParamPlotInit($obj)
	{
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
bf74fc2d   Elena.Budnik   IMPEX
1376
1377
1378
1379
1380
		// IMPEX param
		if (preg_match("#^spase___IMPEX_#",$obj->paramId))
			$type = 'impex_plot_init';
		else
		   $type = 'plot_init';
10200969   Roipoussiere   Remove whitespace...
1381

735c653b   Elena.Budnik   rank at observato...
1382
1383
		$inputobj = (Object)array(
				'paramId' => $obj->paramId,
bf74fc2d   Elena.Budnik   IMPEX
1384
				'type' => $type
735c653b   Elena.Budnik   rank at observato...
1385
1386
1387
		);
		return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
	}
10200969   Roipoussiere   Remove whitespace...
1388

735c653b   Elena.Budnik   rank at observato...
1389
1390
	public function getParamInfo($obj)
	{
bf74fc2d   Elena.Budnik   IMPEX
1391
1392
1393
1394
1395
1396
 		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		// IMPEX param
		if (preg_match("#^spase___IMPEX_#",$obj->paramId))
			$type = 'impex_param_info';
		else
		   $type = 'param_info';
10200969   Roipoussiere   Remove whitespace...
1397

735c653b   Elena.Budnik   rank at observato...
1398
1399
		$inputobj = (Object)array(
				'paramId' => $obj->paramId,
bf74fc2d   Elena.Budnik   IMPEX
1400
				'type' => $type
735c653b   Elena.Budnik   rank at observato...
1401
1402
1403
		);
		return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
	}
10200969   Roipoussiere   Remove whitespace...
1404

735c653b   Elena.Budnik   rank at observato...
1405
1406
1407
1408
1409
1410
	public function getSharedObjectFolders($obj)
	{
		$mgr = new SharedObjectsMgr();
		$folders = $mgr->getFolders($obj->type);
		return array('success' => true, 'folders' => $folders);
	}
10200969   Roipoussiere   Remove whitespace...
1411

735c653b   Elena.Budnik   rank at observato...
1412
1413
1414
	public function shareObjects($obj)
	{
		$mgr = new SharedObjectsMgr();
10200969   Roipoussiere   Remove whitespace...
1415
		switch ($obj->type)
735c653b   Elena.Budnik   rank at observato...
1416
1417
1418
1419
1420
		{
			case 'timeTable' :
			case 'catalog' :
				$src_object_path = USERTTDIR.$obj->object->id.".xml";
				break;
10200969   Roipoussiere   Remove whitespace...
1421

735c653b   Elena.Budnik   rank at observato...
1422
1423
1424
			default:
				return array('success' => false, 'message' => 'Unknown object type');
		}
10200969   Roipoussiere   Remove whitespace...
1425

735c653b   Elena.Budnik   rank at observato...
1426
1427
1428
		$result = $mgr->add($obj->type, $obj->name, $obj->folder, $src_object_path, $obj->description, $this->user);
		if (!$result['success'])
			return $result;
10200969   Roipoussiere   Remove whitespace...
1429

735c653b   Elena.Budnik   rank at observato...
1430
1431
1432
		$mgr->updateTree();
		return $result;
	}
10200969   Roipoussiere   Remove whitespace...
1433

735c653b   Elena.Budnik   rank at observato...
1434
1435
1436
1437
1438
1439
	public function isSharedObjectNameAlreadyUsed($obj)
	{
		$mgr = new SharedObjectsMgr();
		$alreadyUsed = $mgr->isNameAlreadyUsed($obj->type, $obj->name);
		return array('success' => true, 'alreadyUsed' => $alreadyUsed);
	}
10200969   Roipoussiere   Remove whitespace...
1440

0bda97f3   Benjamin Renard   Fix SAMP export f...
1441
1442
1443
1444
1445
1446
	public function getRequestByProcessId($obj)
	{
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");

		return $this->executeRequest($obj->processId, FunctionTypeEnumClass::PROCESSGETREQUEST);
	}
16035364   Benjamin Renard   First commit
1447
1448
}
?>