Blame view

php/classes/AmdaAction.php 40.8 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 $
9e3cbd95   Elena.Budnik   merge AMDA_IHM AM...
5
 * @brief
16035364   Benjamin Renard   First commit
6
 */
10200969   Roipoussiere   Remove whitespace...
7
class AmdaAction
735c653b   Elena.Budnik   rank at observato...
8
{
10200969   Roipoussiere   Remove whitespace...
9
	private $xmlFiles  = array('localParam' => 'LocalParams.xml', 'remoteParam' => 'RemoteParams.xml',
735c653b   Elena.Budnik   rank at observato...
10
										'remoteSimuParam' => 'RemoteParams.xml', 'derivedParam' => 'WsParams.xml', 'myDataParam' => 'WsParams.xml',
10200969   Roipoussiere   Remove whitespace...
11
12
										'timeTable' => 'Tt.xml', 'catalog' => 'Tt.xml', 'alias' => 'Alias.xml',
										'myData' => 'Files.xml',
735c653b   Elena.Budnik   rank at observato...
13
14
15
16
17
										'request' => 'Request.xml', 'condition' => 'Request.xml',
										'bkgWorks' => 'jobs.xml');

	private $user, $amdaStat;

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

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

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

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

735c653b   Elena.Budnik   rank at observato...
47
		}
10200969   Roipoussiere   Remove whitespace...
48
49
50

		return $childrenToReturn;

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

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

735c653b   Elena.Budnik   rank at observato...
57
58
59
60
	/*
	*   $obj = { id: node.id,  nodeType: node.nodeType }
	*/
	public function getTree($obj) {
735c653b   Elena.Budnik   rank at observato...
61
		$node = $obj->node;
10200969   Roipoussiere   Remove whitespace...
62

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

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

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

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

10200969   Roipoussiere   Remove whitespace...
78
79
		if ($node == 'root' && !$remoteBase)
		{
e57cb025   Benjamin Renard   Fix most of error...
80
81
82
83
84
85
86
87
88
89
90
91
			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...
92
93
		}
		else
735c653b   Elena.Budnik   rank at observato...
94
95
96
		{
			$Dom = new DomDocument("1.0");

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

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

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

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

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

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

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

10200969   Roipoussiere   Remove whitespace...
142
143
					//TODO MAKE PROPERLY  as function of nodetype !!!!
					$info = '';
8ba47f72   Benjamin Renard   rest actualisatio...
144
145
					$dim_1 = 1;
					$dim_2 = 1;
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
					$help = $child->getAttribute('att');
735c653b   Elena.Budnik   rank at observato...
149
150
151
152
153
154

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

10200969   Roipoussiere   Remove whitespace...
157
					switch ($nodeType)
735c653b   Elena.Budnik   rank at observato...
158
					{
10200969   Roipoussiere   Remove whitespace...
159
						case 'bkgWorks':
735c653b   Elena.Budnik   rank at observato...
160
							$specialNode = true;
84db3b67   Nathanael Jourdane   Improve job toolt...
161
162
163
164
165
166
							$childrenToReturn[] = [
								'text'     => $name,
								'id'       => $id,
								'nodeType' => $nodeType,
								'leaf'     => $isLeaf,
								'pid'      => $child->getAttribute('pid'),
b4bca467   Nathanael Jourdane   job tooltip: use ...
167
								'status'   => $child->getAttribute('status'),
84db3b67   Nathanael Jourdane   Improve job toolt...
168
								'jobType'  => $child->getAttribute('jobType'),
812bc03d   Nathanael Jourdane   update job info o...
169
								'info'     => $child->getAttribute('info')
84db3b67   Nathanael Jourdane   Improve job toolt...
170
							];
b4bca467   Nathanael Jourdane   job tooltip: use ...
171
							break;
735c653b   Elena.Budnik   rank at observato...
172
173
174

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

10200969   Roipoussiere   Remove whitespace...
178
						case 'request':
735c653b   Elena.Budnik   rank at observato...
179
						$objectMgr = new RequestMgr();
10200969   Roipoussiere   Remove whitespace...
180
181
182
						$objplot = $objectMgr->getObject($id);
						for ($i=0; $i < count($objplot->children); $i++)
						{
812bc03d   Nathanael Jourdane   update job info o...
183
							for ($j=0; $j < count($objplot->children[$i]->children); $j++) {
367f7ed0   Nathanael Jourdane   jobs tooltip: dis...
184
								$info = $info.' . '.$objplot->children[$i]->children[$j]->name;
735c653b   Elena.Budnik   rank at observato...
185
186
							}
						}
10200969   Roipoussiere   Remove whitespace...
187
						break;
735c653b   Elena.Budnik   rank at observato...
188

10200969   Roipoussiere   Remove whitespace...
189
						case 'alias':
735c653b   Elena.Budnik   rank at observato...
190
191
							$info = $id;
							$id = 'alias_'.$id;
05ebfb1e   Elena.Budnik   alias, first commit
192
193
194
195
196
197
198
199
200
							$component_info = array();
							if ($child->hasAttribute("index1"))
								$component_info["index1"] = $child->getAttribute('index1');
							if ($child->hasAttribute("index2"))
								$component_info["index2"] = $child->getAttribute('index2');

							if ($child->hasAttribute("parentId"))
								$component_info["parentId"] = $child->getAttribute("parentId");
								
10200969   Roipoussiere   Remove whitespace...
201
							if ($isLeaf) $isParameter = true;
05ebfb1e   Elena.Budnik   alias, first commit
202
							
735c653b   Elena.Budnik   rank at observato...
203
204
205
						break;

						case 'timeTable':
10200969   Roipoussiere   Remove whitespace...
206
						case 'catalog':
735c653b   Elena.Budnik   rank at observato...
207
208
							if ($isLeaf) $info = $child->getAttribute('intervals').' intervals';
						break;
10200969   Roipoussiere   Remove whitespace...
209

735c653b   Elena.Budnik   rank at observato...
210
211
						case 'sharedtimeTable':
						case 'sharedcatalog':
10200969   Roipoussiere   Remove whitespace...
212
							if ($isLeaf)
735c653b   Elena.Budnik   rank at observato...
213
214
215
216
217
218
219
220
							{
								$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');
8ba47f72   Benjamin Renard   rest actualisatio...
221
222
223
224
225
226
227
228
							
							if ($child->hasAttribute('dim_1')) {
								$dim_1 = $child->getAttribute('dim_1');
							}
					                if ($child->hasAttribute('dim_2')) {
                                                                $dim_2 = $child->getAttribute('dim_2');
                                                        }

735c653b   Elena.Budnik   rank at observato...
229
230
231
232
233
234
235
236
237
238
239
							if ($isLeaf) $isParameter = true;
						break;

						case 'localParam':

							$globalStart = null;
							$globalStop = null;
							$timeRestriction = false;
							$specialNode = true;
							$isParameter = false;
							$needsArgs = false;
10200969   Roipoussiere   Remove whitespace...
240
							$isSpectra = false;
dc9e2c14   Elena.Budnik   init + message + ...
241
							$is2dSpectra = false;
735c653b   Elena.Budnik   rank at observato...
242
							$isStack = false;
e57cb025   Benjamin Renard   Fix most of error...
243
							$not_yet = false;
735c653b   Elena.Budnik   rank at observato...
244

10200969   Roipoussiere   Remove whitespace...
245
246
							if ($child->hasAttribute('desc'))
							{
735c653b   Elena.Budnik   rank at observato...
247
								$info = $child->getAttribute('desc');
10200969   Roipoussiere   Remove whitespace...
248

c57c57c9   Elena.Budnik   info message depe...
249
								if ($child->hasAttribute('dataStart') && $child->hasAttribute('dataStop')) {
10200969   Roipoussiere   Remove whitespace...
250
									$info .= "<br/>Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop');
a7316784   Elena.Budnik   add LastUpdate to...
251
252
253
254
									
									if ($child->hasAttribute('lastUpdate')) {
										$info .= "<br/>Last Updated: : ".$child->getAttribute('lastUpdate');
									}
735c653b   Elena.Budnik   rank at observato...
255
								}
10200969   Roipoussiere   Remove whitespace...
256

c57c57c9   Elena.Budnik   info message depe...
257
								if ($child->getAttribute('dataStart') == 'depending on mission') {
735c653b   Elena.Budnik   rank at observato...
258
									$info .= "<br/>Time Range: ".$child->getAttribute('dataStart');
10200969   Roipoussiere   Remove whitespace...
259
								}
a7316784   Elena.Budnik   add LastUpdate to...
260
	
f29c5e66   Elena.Budnik   plot only option
261
262
263
264
// 								if ($child->getAttribute('restriction') > 1) {
// 									$restricted  = $child->getAttribute('restriction');
// 									$info .= "<br/><b>Time Restriction</b>: -$restricted days";
// 								}
735c653b   Elena.Budnik   rank at observato...
265
							}
10200969   Roipoussiere   Remove whitespace...
266

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

f29c5e66   Elena.Budnik   plot only option
269
							if ($child->tagName == 'parameter') {
735c653b   Elena.Budnik   rank at observato...
270
								$isParameter = true;
735c653b   Elena.Budnik   rank at observato...
271

c57c57c9   Elena.Budnik   info message depe...
272
								if ($child->parentNode->hasAttribute('dataStart')) {
735c653b   Elena.Budnik   rank at observato...
273
									$globalStart = $child->parentNode->getAttribute('dataStart');
10200969   Roipoussiere   Remove whitespace...
274
									$globalStop = $child->parentNode->getAttribute('dataStop');
735c653b   Elena.Budnik   rank at observato...
275
								}
f29c5e66   Elena.Budnik   plot only option
276
277
278
279
280
									
								if ($child->parentNode->hasAttribute('restriction')) {
									if ($child->parentNode->getAttribute('restriction') == "plotOnly") {
										$not_yet = true;
									}
10200969   Roipoussiere   Remove whitespace...
281
								}
f29c5e66   Elena.Budnik   plot only option
282
283
284
// 								if ($child->parentNode->getAttribute('restriction') > 1 ) {
// 									$timeRestriction = true;
// 								}
735c653b   Elena.Budnik   rank at observato...
285
							}
10200969   Roipoussiere   Remove whitespace...
286

735c653b   Elena.Budnik   rank at observato...
287
288
289
290
							$component_info = array();
							if ($child->tagName == 'component')
							{
								$isParameter = true;
735c653b   Elena.Budnik   rank at observato...
291

c57c57c9   Elena.Budnik   info message depe...
292
								if ($child->parentNode->parentNode->hasAttribute('dataStart')) {
735c653b   Elena.Budnik   rank at observato...
293
									$globalStart = $child->parentNode->parentNode->getAttribute('dataStart');
10200969   Roipoussiere   Remove whitespace...
294
295
									$globalStop = $child->parentNode->parentNode->getAttribute('dataStop');
								}
f29c5e66   Elena.Budnik   plot only option
296
297
298
299
300
								
								if ($child->parentNode->parentNode->hasAttribute('restriction')) {
									if ($child->parentNode->parentNode->getAttribute('restriction') == "plotOnly") {
										$not_yet = true;
									}
10200969   Roipoussiere   Remove whitespace...
301
								}
f29c5e66   Elena.Budnik   plot only option
302
303
304
// 								if ($child->parentNode->parentNode->getAttribute('restriction') > 1) {
// 									$timeRestriction = true;
// 								}
735c653b   Elena.Budnik   rank at observato...
305
306
307
308
309

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

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

f29c5e66   Elena.Budnik   plot only option
314
							if ($child->tagName == 'parameter' && $child->hasAttribute('display_type')){
c57c57c9   Elena.Budnik   info message depe...
315
								if ($child->getAttribute('display_type') == 'spectrogram') {
10200969   Roipoussiere   Remove whitespace...
316
317
										$needsArgs = true;
										$isSpectra = true;
dc9e2c14   Elena.Budnik   init + message + ...
318
319
										if (strpos($child->getAttribute('name'),'2D') !== false)
											$is2dSpectra = true;
735c653b   Elena.Budnik   rank at observato...
320
								}
c57c57c9   Elena.Budnik   info message depe...
321
								elseif ($child->getAttribute('display_type') == 'stackplot') {
735c653b   Elena.Budnik   rank at observato...
322
										$isStack = true;
735c653b   Elena.Budnik   rank at observato...
323
								}
10200969   Roipoussiere   Remove whitespace...
324
325
							}

c57c57c9   Elena.Budnik   info message depe...
326
							if ($isParameter) {
735c653b   Elena.Budnik   rank at observato...
327
328
								$objectMgr = new AliasMgr();
								$alias = $objectMgr->getAlias($id);
10200969   Roipoussiere   Remove whitespace...
329

661293d7   Elena.Budnik   parse ## and @@ i...
330
								$childrenToReturn[] = array('text' => $name,'alias' => $alias,
735c653b   Elena.Budnik   rank at observato...
331
332
									'id' => $id,'nodeType' => $nodeType, 'info' => $info, "component_info" => $component_info,
									'globalStart' => $globalStart, 'globalStop' => $globalStop, 'timeRestriction' => $timeRestriction,
dc9e2c14   Elena.Budnik   init + message + ...
333
334
									'leaf' => $isLeaf, 'isParameter' => $isParameter,'isSpectra' => $isSpectra,
									'is2dSpectra' => $is2dSpectra,'isStack' => $isStack, 'needsArgs' => $needsArgs, 'help' => $help, 'notyet' => $not_yet);
735c653b   Elena.Budnik   rank at observato...
335
							}
c57c57c9   Elena.Budnik   info message depe...
336
							else {
c57c57c9   Elena.Budnik   info message depe...
337
								if ($child->tagName == 'mission' || $child->tagName == 'observatory') {
735c653b   Elena.Budnik   rank at observato...
338
339
									$rank = $child->getAttribute('rank');
								}
c57c57c9   Elena.Budnik   info message depe...
340
								
acf87705   Elena.Budnik   bug in disable param
341
342
								$disable = $child->hasAttribute('group');

c57c57c9   Elena.Budnik   info message depe...
343
								if ($disable) {
acf87705   Elena.Budnik   bug in disable param
344
									if ($child->getAttribute("group") !== "TBD") {
c57c57c9   Elena.Budnik   info message depe...
345
346
											$info .=  "<br/><b>Restricted Access</b>";
										}
10200969   Roipoussiere   Remove whitespace...
347
									else {
c57c57c9   Elena.Budnik   info message depe...
348
										$info .=  "<br/><b>Sorry! Not finished yet...</b>";
735c653b   Elena.Budnik   rank at observato...
349
									}
acf87705   Elena.Budnik   bug in disable param
350
351
352
353
								} 
								else {
									if ($child->hasAttribute('restriction') && $child->getAttribute('restriction') == 'plotOnly')
										$info .=  "<br/><b>Plot Only!!!</b>";
735c653b   Elena.Budnik   rank at observato...
354
355
								}

10200969   Roipoussiere   Remove whitespace...
356
357
								$childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType,  'info' => $info,
									'leaf' => false, 'help' => $help, 'disable' => $disable, 'rank' => $rank);
735c653b   Elena.Budnik   rank at observato...
358
359
360
361
							}
						break;

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

bf74fc2d   Elena.Budnik   IMPEX
363
							$globalStart = null;
6657f68b   Elena.Budnik   monitor impex ser...
364
							$service_down = false;
735c653b   Elena.Budnik   rank at observato...
365
							$isSimulation = true;
10200969   Roipoussiere   Remove whitespace...
366
367

			            if ($child->getAttribute('isAddable')) // 'spase://IMPEX/SimulationModel/FMI/GUMICS'
735c653b   Elena.Budnik   rank at observato...
368
369
370
371
							{
								$isLeaf = false;
								$isAddable = true;
							}
10200969   Roipoussiere   Remove whitespace...
372
373

							if ($child->tagName == 'dataCenter')
735c653b   Elena.Budnik   rank at observato...
374
							{
10200969   Roipoussiere   Remove whitespace...
375
								if ($child->getAttribute('isSimulation'))
6657f68b   Elena.Budnik   monitor impex ser...
376
								{
10200969   Roipoussiere   Remove whitespace...
377
378
									$service_down = !($child->getAttribute('available'));
									break;
6657f68b   Elena.Budnik   monitor impex ser...
379
								}
10200969   Roipoussiere   Remove whitespace...
380
								else
735c653b   Elena.Budnik   rank at observato...
381
382
383
384
385
								{
									$skip = true;
									break;
								}
							}
10200969   Roipoussiere   Remove whitespace...
386
387

							if ($child->hasAttribute('rank'))
735c653b   Elena.Budnik   rank at observato...
388
389
390
							{
								$rank = $child->getAttribute('rank');
							}
10200969   Roipoussiere   Remove whitespace...
391

bf74fc2d   Elena.Budnik   IMPEX
392
393
							if ( $child->tagName == 'parameter')
							{
abb54096   Elena.Budnik   time interval by ...
394
								if ($child->parentNode->hasAttribute('globalStart'))
bf74fc2d   Elena.Budnik   IMPEX
395
									{
abb54096   Elena.Budnik   time interval by ...
396
397
										$globalStart = $child->parentNode->getAttribute('globalStart');
										$globalStop = $child->parentNode->getAttribute('globalStop');
bf74fc2d   Elena.Budnik   IMPEX
398
399
									}
							}
10200969   Roipoussiere   Remove whitespace...
400

bf74fc2d   Elena.Budnik   IMPEX
401
402
							if ( $child->tagName == 'component')
							{
abb54096   Elena.Budnik   time interval by ...
403
								if ($child->parentNode->parentNode->hasAttribute('globalStart'))
bf74fc2d   Elena.Budnik   IMPEX
404
									{
abb54096   Elena.Budnik   time interval by ...
405
406
										$globalStart = $child->parentNode->parentNode->getAttribute('globalStart');
										$globalStop = $child->parentNode->parentNode->getAttribute('globalStop');
bf74fc2d   Elena.Budnik   IMPEX
407
408
									}
							}
10200969   Roipoussiere   Remove whitespace...
409

735c653b   Elena.Budnik   rank at observato...
410
						case 'remoteParam' :
10200969   Roipoussiere   Remove whitespace...
411
412

							if ($child->getAttribute('isSimulation') && $child->tagName == 'dataCenter')
735c653b   Elena.Budnik   rank at observato...
413
414
415
416
417
418
419
							{
								$skip = true;
								break;
							}

							$isDeletable = $child->hasAttribute('isDeletable');
							$specialNode = true;
10200969   Roipoussiere   Remove whitespace...
420
421
422
423
424
							$isParameter = false;

							$isSpectra = false;

							switch ($id)
735c653b   Elena.Budnik   rank at observato...
425
							{
10200969   Roipoussiere   Remove whitespace...
426
								case 'CDAWEB'  :
735c653b   Elena.Budnik   rank at observato...
427
428
429
								case 'THEMIS' :
									$rank = 5;
									break;
735c653b   Elena.Budnik   rank at observato...
430
431
								default:
							}
10200969   Roipoussiere   Remove whitespace...
432

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

10200969   Roipoussiere   Remove whitespace...
435
436
							if ($info && !$isSimulation)
							{
735c653b   Elena.Budnik   rank at observato...
437
								$info = str_replace(';', "<br/>Time Range: ", $info);
10200969   Roipoussiere   Remove whitespace...
438
439
440
							}

							if (($child->tagName == 'parameter') || ($child->tagName == 'component'))
735c653b   Elena.Budnik   rank at observato...
441
442
							{
								$isParameter = true;
735c653b   Elena.Budnik   rank at observato...
443
							}
10200969   Roipoussiere   Remove whitespace...
444

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

10200969   Roipoussiere   Remove whitespace...
447
							if ($remoteBase)
735c653b   Elena.Budnik   rank at observato...
448
							{
10200969   Roipoussiere   Remove whitespace...
449
								if ($child->tagName == 'dataset') $isRemoteDataSet = true;
735c653b   Elena.Budnik   rank at observato...
450
							}
a0f13ed1   Elena.Budnik   small format + ti...
451
452
453
454
455
456
457
							
							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...
458

a0f13ed1   Elena.Budnik   small format + ti...
459
460
461
462
463
464
465
							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...
466
							if ($isParameter)
735c653b   Elena.Budnik   rank at observato...
467
							{
10200969   Roipoussiere   Remove whitespace...
468
								$disable = $child->parentNode->getAttribute('disabled');
735c653b   Elena.Budnik   rank at observato...
469
470
471
472
473
								$objectMgr = new AliasMgr();
								$alias = $objectMgr->getAlias($id);

								if ($child->hasAttribute('display_type') && $child->getAttribute('display_type') == 'spectrogram')
								{
10200969   Roipoussiere   Remove whitespace...
474
									$needsArgs = true;
735c653b   Elena.Budnik   rank at observato...
475
									$isSpectra = true;
10200969   Roipoussiere   Remove whitespace...
476
								}
bf74fc2d   Elena.Budnik   IMPEX
477
								if ($globalStart)
10200969   Roipoussiere   Remove whitespace...
478
								 $childrenToReturn[] = array('text' => $name,'alias' => $alias,
bf74fc2d   Elena.Budnik   IMPEX
479
										'id' => $id,'nodeType' => $nodeType,  'info' => $info, 'help' => $help,  'globalStart' => $globalStart,
10200969   Roipoussiere   Remove whitespace...
480
										'globalStop' => $globalStop, 'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter,
1c007ca2   Elena.Budnik   vector icon for M...
481
										'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => isset($component_info) ? $component_info : NULL);
bf74fc2d   Elena.Budnik   IMPEX
482
								else
10200969   Roipoussiere   Remove whitespace...
483
									$childrenToReturn[] = array('text' => $name,'alias' => $alias,
bf74fc2d   Elena.Budnik   IMPEX
484
										'id' => $id,'nodeType' => $nodeType,  'info' => $info, 'help' => $help,
10200969   Roipoussiere   Remove whitespace...
485
										'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter,
1c007ca2   Elena.Budnik   vector icon for M...
486
										'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => $component_info);
735c653b   Elena.Budnik   rank at observato...
487
							}
10200969   Roipoussiere   Remove whitespace...
488
489
							else
							{
e57cb025   Benjamin Renard   Fix most of error...
490
								$restricted = FALSE;
9e3cbd95   Elena.Budnik   merge AMDA_IHM AM...
491
								
735c653b   Elena.Budnik   rank at observato...
492
								if ($child->tagName == 'dataset')
6657f68b   Elena.Budnik   monitor impex ser...
493
								{
735c653b   Elena.Budnik   rank at observato...
494
									$nonavailable = ($child->getAttribute('disabled'));
6657f68b   Elena.Budnik   monitor impex ser...
495
								}
735c653b   Elena.Budnik   rank at observato...
496
								else
6657f68b   Elena.Budnik   monitor impex ser...
497
								{
735c653b   Elena.Budnik   rank at observato...
498
									$nonavailable = false;
6657f68b   Elena.Budnik   monitor impex ser...
499
								}
10200969   Roipoussiere   Remove whitespace...
500

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

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

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

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

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

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

						case 'myDataParam' :

							$globalStart = null;
							$globalStop = null;
							$specialNode = true;
							$size = $child->getAttribute('size');
735c653b   Elena.Budnik   rank at observato...
533
							$mask = $child->getAttribute('mask');
19dcd963   Elena.Budnik   redmine #4903 : s...
534
535
536
							$sampling = null;
							if ($child->hasAttribute('minsampling')) 
								$sampling = $child->getAttribute('minsampling');
735c653b   Elena.Budnik   rank at observato...
537
							$isSpectra = false;
10200969   Roipoussiere   Remove whitespace...
538
539

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

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

10200969   Roipoussiere   Remove whitespace...
554
							$childrenToReturn[] = array('text' => $name, 'size' =>  $size, 'id' => $id,
735c653b   Elena.Budnik   rank at observato...
555
								'globalStart' => $globalStart, 'globalStop' => $globalStop,
1c007ca2   Elena.Budnik   vector icon for M...
556
								'nodeType' => $nodeType, 'info' => $info,  'leaf' => $isLeaf,
735c653b   Elena.Budnik   rank at observato...
557
558
559
								'isParameter' => $isParameter, 'linkedMask' => $mask, 'isSpectra' => $isSpectra);

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

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

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

						$childrenToReturn[] = array('text' => $name, 'id' => $id, 'nodeType' => $nodeType, 'info' => $info,
05ebfb1e   Elena.Budnik   alias, first commit
574
575
													'help' => $help, 'leaf' => $isLeaf, 'isParameter' => $isParameter, 'dim_1' => $dim_1, 'dim_2' => $dim_2,
													"component_info" => isset($component_info) ? $component_info : NULL);
735c653b   Elena.Budnik   rank at observato...
576
577
578
					}
				}
				// if $childrenToReturn we have to return []
e57cb025   Benjamin Renard   Fix most of error...
579
				if (empty($childrenToReturn))
10200969   Roipoussiere   Remove whitespace...
580
				{
735c653b   Elena.Budnik   rank at observato...
581
582
583
					$childrenToReturn = array('nodeType' => $nodeType, 'text' => null);
				}
			}
16035364   Benjamin Renard   First commit
584
      return  $childrenToReturn;
735c653b   Elena.Budnik   rank at observato...
585
	}
16035364   Benjamin Renard   First commit
586

0dc31ba8   Elena.Budnik   remoteParamManage...
587
588
589
590
591
	/*
	*  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...
592
	public  function saveTree($obj)
735c653b   Elena.Budnik   rank at observato...
593
	{
0dc31ba8   Elena.Budnik   remoteParamManage...
594
		$paramMgr = new RemoteParamManager();
2b8ea2a7   Elena.Budnik   RemoteParamManage...
595
596
597
598
599
600
		$res = $paramMgr->init();
		
		if ($res['success'])
			return $paramMgr->saveTree($obj);
		else 
			return $res;
735c653b   Elena.Budnik   rank at observato...
601
	}
0dc31ba8   Elena.Budnik   remoteParamManage...
602
603
604
605
	
	/*
	*  delete Remote Parameter from user RemoteParams.xml
	*/
10200969   Roipoussiere   Remove whitespace...
606
607
	public  function deleteFromTree($obj)
	{
0dc31ba8   Elena.Budnik   remoteParamManage...
608
		$paramMgr = new RemoteParamManager();
2b8ea2a7   Elena.Budnik   RemoteParamManage...
609
610
611
612
613
614
		$res = $paramMgr->init();
		
		if ($res['success'])
			return $paramMgr->deleteFromTree($obj);
		else 
			return $res;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
615
	}
0dc31ba8   Elena.Budnik   remoteParamManage...
616
617
618
619
620
		
	public  function doNothing($obj)
	{
		return array("res" => 'ok');
	}
16035364   Benjamin Renard   First commit
621

0dc31ba8   Elena.Budnik   remoteParamManage...
622
623
624
	/*
	*  get temporary object from Upload
	*/
9a63b7f6   Elena.Budnik   needsArgs to Simu...
625
	public  function getUploadedObject($name, $format, $nodeType)
10200969   Roipoussiere   Remove whitespace...
626
	{
5f8bd1f5   Nathanaël Jourdane   Fix Windows-files...
627
628
629
		$fileContent = preg_replace(['~\R~u', "/\t/"], ["\n", ' '], trim(file_get_contents(USERTEMPDIR . $name)));
		file_put_contents(USERTEMPDIR . $name, $fileContent);

10200969   Roipoussiere   Remove whitespace...
630
		switch ($nodeType)
9a63b7f6   Elena.Budnik   needsArgs to Simu...
631
		{
10200969   Roipoussiere   Remove whitespace...
632
633
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
9a63b7f6   Elena.Budnik   needsArgs to Simu...
634
				break;
10200969   Roipoussiere   Remove whitespace...
635
636
637
638
639
			case 'myDataParam' :
				$objectMgr = new FilesMgr();
				break;
			case 'catalog' :
				$objectMgr = new CatalogMgr();
9a63b7f6   Elena.Budnik   needsArgs to Simu...
640
				break;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
641
642
643
			default:
				return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
		}
bf74fc2d   Elena.Budnik   IMPEX
644
		return  $objectMgr->getUploadedObject($name, $format, true);
10200969   Roipoussiere   Remove whitespace...
645
	}
16035364   Benjamin Renard   First commit
646

0dc31ba8   Elena.Budnik   remoteParamManage...
647
648
649
	/*
	*  fill ascii file into grid
	*/
10200969   Roipoussiere   Remove whitespace...
650
651
652
	public  function getAsciiFile($obj)
	{
		$objectMgr = new FilesMgr();
bf74fc2d   Elena.Budnik   IMPEX
653
		return  $objectMgr->getAsciiFile($obj->fileName);
735c653b   Elena.Budnik   rank at observato...
654
	}
10200969   Roipoussiere   Remove whitespace...
655
656
657
658

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

0dc31ba8   Elena.Budnik   remoteParamManage...
662
663
664
	/*
	*  get temporary object from Search
	*/
10200969   Roipoussiere   Remove whitespace...
665
666
667
	public  function getTmpObject($folderId, $name, $nodeType)
	{
		switch ($nodeType)
735c653b   Elena.Budnik   rank at observato...
668
		{
10200969   Roipoussiere   Remove whitespace...
669
670
671
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
			break;
735c653b   Elena.Budnik   rank at observato...
672
			case 'catalog' :
10200969   Roipoussiere   Remove whitespace...
673
674
				$objectMgr = new CatalogMgr();
			break;
735c653b   Elena.Budnik   rank at observato...
675
676
677
			default:
				return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
		}
bf74fc2d   Elena.Budnik   IMPEX
678
		return  $objectMgr->getTmpObject($folderId, $name, true);
fdf1413b   Elena.Budnik   TT download
679
	}
735c653b   Elena.Budnik   rank at observato...
680

10200969   Roipoussiere   Remove whitespace...
681
682
683
684

	public  function getObject($id, $nodeType)
	{
		switch ($nodeType)
735c653b   Elena.Budnik   rank at observato...
685
686
		{
			case 'myDataParam':
10200969   Roipoussiere   Remove whitespace...
687
688
			case 'derivedParam' :
				$objectMgr = new DerivedParamMgr($nodeType);
735c653b   Elena.Budnik   rank at observato...
689
				break;
10200969   Roipoussiere   Remove whitespace...
690
			case 'timeTable' :
735c653b   Elena.Budnik   rank at observato...
691
			case 'sharedtimeTable' :
10200969   Roipoussiere   Remove whitespace...
692
693
				$objectMgr = new TimeTableMgr();
				break;
735c653b   Elena.Budnik   rank at observato...
694
695
			case 'catalog' :
			case 'sharedcatalog' :
10200969   Roipoussiere   Remove whitespace...
696
697
698
				$objectMgr = new CatalogMgr();
				break;
			case 'condition' :
735c653b   Elena.Budnik   rank at observato...
699
			case 'request' :
10200969   Roipoussiere   Remove whitespace...
700
701
				$objectMgr = new RequestMgr($nodeType);
				break;
9e3cbd95   Elena.Budnik   merge AMDA_IHM AM...
702
			case 'bkgWorks' :	
735c653b   Elena.Budnik   rank at observato...
703
704
705
				return $this->executeRequest($id, FunctionTypeEnumClass::PROCESSGETINFO);
				break;
			case 'myData' :
10200969   Roipoussiere   Remove whitespace...
706
				$objectMgr = new FilesMgr();
735c653b   Elena.Budnik   rank at observato...
707
				break;
10200969   Roipoussiere   Remove whitespace...
708
			default:
735c653b   Elena.Budnik   rank at observato...
709
710
				return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
		}
bf74fc2d   Elena.Budnik   IMPEX
711
		return  $objectMgr->getObject($id, $nodeType);
fdf1413b   Elena.Budnik   TT download
712
	}
10200969   Roipoussiere   Remove whitespace...
713

16035364   Benjamin Renard   First commit
714
715
716
/*
*   $obj = { id: node.id, leaf: node.leaf, nodeType: node.nodeType }
*/
10200969   Roipoussiere   Remove whitespace...
717
718
719
720
721
722
723
	public  function deleteObject($obj)
	{
		switch ($obj->nodeType)
		{
			case 'myDataParam' :
			case 'derivedParam' :
				$objectMgr = new DerivedParamMgr($obj->nodeType);
735c653b   Elena.Budnik   rank at observato...
724
				break;
10200969   Roipoussiere   Remove whitespace...
725
726
727
728
729
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
				break;
			case 'catalog' :
				$objectMgr = new CatalogMgr();
735c653b   Elena.Budnik   rank at observato...
730
				break;
10200969   Roipoussiere   Remove whitespace...
731
			case 'condition' :
735c653b   Elena.Budnik   rank at observato...
732
			case 'request' :
10200969   Roipoussiere   Remove whitespace...
733
				$objectMgr = new RequestMgr($obj->nodeType);
735c653b   Elena.Budnik   rank at observato...
734
735
736
737
				break;
			case 'alias' :
				$objectMgr = new AliasMgr();
				$obj->id = substr($obj->id,strlen('alias_'));
10200969   Roipoussiere   Remove whitespace...
738
				break;
735c653b   Elena.Budnik   rank at observato...
739
			case 'bkgWorks' :
735c653b   Elena.Budnik   rank at observato...
740
741
742
				return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSDELETE);

			case 'myData' :
16035364   Benjamin Renard   First commit
743
				$objectMgr = new FilesMgr();
735c653b   Elena.Budnik   rank at observato...
744
745
746
747
748
749
				break;
			default:
					return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}
		return  $objectMgr -> deleteObject($obj);
	}
16035364   Benjamin Renard   First commit
750
751
752
753

/*
*   $obj = { id: node.id, old_name: node.text, name: value,  parent : node.parentNode.id, leaf: node.leaf, nodeType: node.nodeType }
*/
10200969   Roipoussiere   Remove whitespace...
754
755
756
	public  function renameObject($obj)
	{
		switch ($obj->nodeType)
735c653b   Elena.Budnik   rank at observato...
757
		{
10200969   Roipoussiere   Remove whitespace...
758

16035364   Benjamin Renard   First commit
759
		  case 'myDataParam' :
10200969   Roipoussiere   Remove whitespace...
760
761
762
763
764
		  case 'derivedParam' :
			   $objectMgr = new DerivedParamMgr($obj->nodeType);
			   break;
		  case 'timeTable' :
			   $objectMgr = new TimeTableMgr();
16035364   Benjamin Renard   First commit
765
			   break;
10200969   Roipoussiere   Remove whitespace...
766
767
		  case 'catalog' :
			   $objectMgr = new CatalogMgr();
d18b535d   elena   catalog draft + c...
768
			   break;
10200969   Roipoussiere   Remove whitespace...
769
770
771
		  case 'condition' :
		  case 'request' :
			   $objectMgr = new RequestMgr($obj->nodeType);
16035364   Benjamin Renard   First commit
772
773
			   break;
		  case 'alias' :
10200969   Roipoussiere   Remove whitespace...
774
775
		  	   $objectMgr = new AliasMgr();
		  	   break;
16035364   Benjamin Renard   First commit
776
777
		  default:
			    return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
735c653b   Elena.Budnik   rank at observato...
778
		}
16035364   Benjamin Renard   First commit
779

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

10200969   Roipoussiere   Remove whitespace...
783
/*
16035364   Benjamin Renard   First commit
784
785
*   $obj = { name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES }
*/
10200969   Roipoussiere   Remove whitespace...
786
787
788
	public  function createObject($obj, $folder)
	{
		switch ($obj->nodeType)
9a63b7f6   Elena.Budnik   needsArgs to Simu...
789
		{
10200969   Roipoussiere   Remove whitespace...
790
			case 'myDataParam' :
9a63b7f6   Elena.Budnik   needsArgs to Simu...
791
			case 'derivedParam' :
10200969   Roipoussiere   Remove whitespace...
792
				if ($obj->nodeType == 'derivedParam' &&  $this->amdaStat->success)
2dab1b1b   Elena.Budnik   change input args...
793
						$this->amdaStat->addTask($this->user, 'create', null);
10200969   Roipoussiere   Remove whitespace...
794
				$objectMgr = new DerivedParamMgr($obj->nodeType);
8ba47f72   Benjamin Renard   rest actualisatio...
795
                 	break;
10200969   Roipoussiere   Remove whitespace...
796
797
798
799
800
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
				break;
			case 'catalog' :
				$objectMgr = new CatalogMgr();
16035364   Benjamin Renard   First commit
801
			   break;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
802
			case 'condition' :
10200969   Roipoussiere   Remove whitespace...
803
804
805
			case 'request' :
				$objectMgr = new RequestMgr($obj->nodeType);
				break;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
806
			case 'alias' :
10200969   Roipoussiere   Remove whitespace...
807
808
				$objectMgr = new AliasMgr();
				break;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
809
810
811
812
813
			default:
				return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}
		return  $objectMgr -> createObject($obj, $folder);
	}
16035364   Benjamin Renard   First commit
814

10200969   Roipoussiere   Remove whitespace...
815
/*
16035364   Benjamin Renard   First commit
816
817
*   $obj = { id:obj.id, name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES }
*/
10200969   Roipoussiere   Remove whitespace...
818
	public  function modifyObject($obj)
9a63b7f6   Elena.Budnik   needsArgs to Simu...
819
	{
10200969   Roipoussiere   Remove whitespace...
820
821
822
823
824
		switch ($obj->nodeType)
		{
			case 'myDataParam' :
			case 'derivedParam' :
				$objectMgr = new DerivedParamMgr($obj->nodeType);
9a63b7f6   Elena.Budnik   needsArgs to Simu...
825
				break;
10200969   Roipoussiere   Remove whitespace...
826
827
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
9a63b7f6   Elena.Budnik   needsArgs to Simu...
828
				break;
10200969   Roipoussiere   Remove whitespace...
829
830
831
832
			case 'catalog' :
				$objectMgr = new CatalogMgr();
				break;
			case 'condition' :
9a63b7f6   Elena.Budnik   needsArgs to Simu...
833
			case 'request' :
10200969   Roipoussiere   Remove whitespace...
834
				$objectMgr = new RequestMgr($obj->nodeType);
9a63b7f6   Elena.Budnik   needsArgs to Simu...
835
836
837
838
839
				break;
			default:
				return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}
		return  $objectMgr -> modifyObject($obj);
10200969   Roipoussiere   Remove whitespace...
840
	}
16035364   Benjamin Renard   First commit
841
842
843
844
845
846
847
848
849
850
/*
 * {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...
851
			case 'sharedtimeTable' :
16035364   Benjamin Renard   First commit
852
853
				$objectMgr = new TimeTableMgr();
				break;
d18b535d   elena   catalog draft + c...
854
			case 'catalog' :
169f14d2   Benjamin Renard   Add shared object...
855
			case 'sharedcatalog' :
d18b535d   elena   catalog draft + c...
856
857
				$objectMgr = new CatalogMgr();
				break;
16035364   Benjamin Renard   First commit
858
859
860
861
862
863
864
865
866
867
868
869
			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...
870
*   Get running jobs
16035364   Benjamin Renard   First commit
871
*/
bae6f5da   Nathanael Jourdane   bugFix fileName f...
872
	public function getJobs($obj = null)
6acb8d2a   Elena.Budnik   checkRequest in R...
873
	{
812bc03d   Nathanael Jourdane   update job info o...
874
		$obj = (object) array();
10200969   Roipoussiere   Remove whitespace...
875
		return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSRUNNINGINFO);
6acb8d2a   Elena.Budnik   checkRequest in R...
876
	}
16035364   Benjamin Renard   First commit
877
878
879
880
881
882
883


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

16035364   Benjamin Renard   First commit
889
		if (isset($obj->username) && isset($obj->password) && isset($obj->sessionID))
735c653b   Elena.Budnik   rank at observato...
890
		{
e5ab198f   Nathanael Jourdane   simple getStatus
891
			$dd = new WSUserMgr();
fcdd1349   Elena.Budnik   merge with master
892
			$dd->init($obj->username,$obj->password,$obj->sessionID, false);
735c653b   Elena.Budnik   rank at observato...
893
		}
a21497cc   Elena.Budnik   redmine #5645
894
		else {
16035364   Benjamin Renard   First commit
895
			$dd = new UserMgr();
a21497cc   Elena.Budnik   redmine #5645
896
897
			$dd->setSpecialSettings();
		}
10200969   Roipoussiere   Remove whitespace...
898
899

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

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

6acb8d2a   Elena.Budnik   checkRequest in R...
907
		if ($dd->user == 'impex')
16035364   Benjamin Renard   First commit
908
909
910
		{
			//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
911
//			return array('success' => false, "message" => "AKKA-KERNEL-INT - WS support for IMPEx not implemented");
6acb8d2a   Elena.Budnik   checkRequest in R...
912
		}
32bb889b   Elena.Budnik   #5532 to process ...
913
		else {
a21497cc   Elena.Budnik   redmine #5645
914
			// check disk space 
2c7f2cb6   Benjamin Renard   Remove old log fi...
915
916
917
918
919
920
			if ($dd->getWsSize() > DISK_QUOTA) {
				//Try to delete log files - cf. #6245
				if ($dd->getWsSize(TRUE) > DISK_QUOTA) {
					return array('success' => false, 'message' => 'Please clean up your workspace.<br/>No more space is available');
				}
			}
735c653b   Elena.Budnik   rank at observato...
921
		}
10200969   Roipoussiere   Remove whitespace...
922

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

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

6acb8d2a   Elena.Budnik   checkRequest in R...
928
	private function executeRequest($obj, $function)
05ebfb1e   Elena.Budnik   alias, first commit
929
930
	{ 				
	
32bb889b   Elena.Budnik   #5532 to process ...
931
932
933
		// Check user if access to DD Server and / or possible 'space consuming' action
		if (  $function == FunctionTypeEnumClass::PARAMS ||
				$function == FunctionTypeEnumClass::ACTION ||
8ba47f72   Benjamin Renard   rest actualisatio...
934
935
				$function == FunctionTypeEnumClass::PARAMSGEN ||
				$function == FunctionTypeEnumClass::PARAMSINFOGEN )
32bb889b   Elena.Budnik   #5532 to process ...
936
		{
7ac3e07e   Elena.Budnik   do not check user...
937
938
939
			$res = $this->checkUser($obj);
			if (!$res['success']) return $res;
		}
8ba47f72   Benjamin Renard   rest actualisatio...
940

16035364   Benjamin Renard   First commit
941
		$requestManager = new RequestManagerClass();
32bb889b   Elena.Budnik   #5532 to process ...
942
		try {
e57cb025   Benjamin Renard   Fix most of error...
943
			$res = $requestManager->runIHMRequest($this->user, !empty($res['userHost']) ? $res['userHost'] : NULL, $function, $obj);
32bb889b   Elena.Budnik   #5532 to process ...
944
		} catch (Exception $e) {
16035364   Benjamin Renard   First commit
945
			return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage());
10200969   Roipoussiere   Remove whitespace...
946
		}
16035364   Benjamin Renard   First commit
947
948
		return $res;
	}
10200969   Roipoussiere   Remove whitespace...
949
950
951

/*
*    Main EXECUTE PROCEDURE
16035364   Benjamin Renard   First commit
952
*/
735c653b   Elena.Budnik   rank at observato...
953
954
	public  function execute($node, $obj)
	{
fdf1413b   Elena.Budnik   TT download
955
956
957
958
		// 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
959
			return $this->executeRequest($obj, FunctionTypeEnumClass::ACTION);
10200969   Roipoussiere   Remove whitespace...
960
961
		else
		{
6acb8d2a   Elena.Budnik   checkRequest in R...
962
963
			$res = RequestMgr::checkRequest($obj);
			if (!$res['success']) return $res;
10200969   Roipoussiere   Remove whitespace...
964

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

16035364   Benjamin Renard   First commit
969
/*
a0b3d64e   Benjamin Renard   Derived parameter...
970
971
 * Generate derived parameter compilation
 */
735c653b   Elena.Budnik   rank at observato...
972
973
	public function compilParam($obj)
	{
bf776dc8   Benjamin Renard   working
974
//error_log(print_r($obj,TRUE));
735c653b   Elena.Budnik   rank at observato...
975
976
		return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMSGEN);
	}
a0b3d64e   Benjamin Renard   Derived parameter...
977

8ba47f72   Benjamin Renard   rest actualisatio...
978
979
980
981
982
983
984
985
986
987
988
989

/*
 * Generate parameter info for display (e.g size)
 */
        public function generateParamInfo($obj)
        {
                return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMSINFOGEN);
        }




a0b3d64e   Benjamin Renard   Derived parameter...
990
991
992
/*
 * Delete derived parameter compilation
 */
735c653b   Elena.Budnik   rank at observato...
993
994
	public function compilParamDelete($obj)
	{
a0b3d64e   Benjamin Renard   Derived parameter...
995
		$res = $this->checkUser($obj);
10200969   Roipoussiere   Remove whitespace...
996

a0b3d64e   Benjamin Renard   Derived parameter...
997
998
		if (!$res['success'])
			return $res;
10200969   Roipoussiere   Remove whitespace...
999

a0b3d64e   Benjamin Renard   Derived parameter...
1000
1001
1002
1003
		IHMConfigClass::setUserName($this->user);
		$libParamPath = IHMConfigClass::getCompilationPath()."lib/".$obj->paramId.".so";
		if (file_exists($libParamPath))
			unlink($libParamPath);
735c653b   Elena.Budnik   rank at observato...
1004
1005
		return array("success" => true);
	}
10200969   Roipoussiere   Remove whitespace...
1006

a0b3d64e   Benjamin Renard   Derived parameter...
1007
/*
e6e5b259   Benjamin Renard   Add kill plot req...
1008
 * kill plot process
16035364   Benjamin Renard   First commit
1009
 */
10200969   Roipoussiere   Remove whitespace...
1010

735c653b   Elena.Budnik   rank at observato...
1011
	public function killPlotRequest()
10200969   Roipoussiere   Remove whitespace...
1012
	{
735c653b   Elena.Budnik   rank at observato...
1013
1014
		return $this->executeRequest((object) array('nodeType' => 'killplot'), FunctionTypeEnumClass::PARAMS);
	}
16035364   Benjamin Renard   First commit
1015
1016
1017
1018

/*
 * merge time tables
 */
10200969   Roipoussiere   Remove whitespace...
1019
	public  function merge($obj)
735c653b   Elena.Budnik   rank at observato...
1020
1021
	{
		if ($this->amdaStat->success)
2dab1b1b   Elena.Budnik   change input args...
1022
			$this->amdaStat->addTask( $this->user, 'ttoper', null);
10200969   Roipoussiere   Remove whitespace...
1023

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

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

10200969   Roipoussiere   Remove whitespace...
1029

16035364   Benjamin Renard   First commit
1030
1031
1032
/*
 * intersect time tables
 */
10200969   Roipoussiere   Remove whitespace...
1033
	public  function intersect($obj)
735c653b   Elena.Budnik   rank at observato...
1034
1035
	{
		if ($this->amdaStat->success)
2dab1b1b   Elena.Budnik   change input args...
1036
				$this->amdaStat->addTask($this->user, 'ttoper', null);
16035364   Benjamin Renard   First commit
1037

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

735c653b   Elena.Budnik   rank at observato...
1041
1042
		return  $result;
	}
10200969   Roipoussiere   Remove whitespace...
1043

735c653b   Elena.Budnik   rank at observato...
1044
1045
1046
1047
	public function initTTCache($isCatalog = false, $nparams)
	{
		if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
		else              $cacheMgr = new CatalogCacheMgr();
10200969   Roipoussiere   Remove whitespace...
1048

735c653b   Elena.Budnik   rank at observato...
1049
1050
		return $cacheMgr->initTTCache($nparams);
	}
10200969   Roipoussiere   Remove whitespace...
1051
1052


735c653b   Elena.Budnik   rank at observato...
1053
1054
1055
1056
	public function initTTCacheFromTT($id, $type)
	{
		if ($type == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr();
		else $cacheMgr = new TimeTableCacheMgr();
10200969   Roipoussiere   Remove whitespace...
1057

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

735c653b   Elena.Budnik   rank at observato...
1061
1062
	public function initForChart($id, $name, $isTmpObject, $type)
	{
e1fd05b4   Elena.Budnik   visu from cacheCat
1063
1064
1065
		if ($isTmpObject && $type == 'catalog' && $id == 'cacheCat')
			return array('success' => true, 'cache' => $id);
			
735c653b   Elena.Budnik   rank at observato...
1066
		if ($type == 'catalog' || $type == 'sharedcatalog') $objMgr = new CatalogMgr();
10200969   Roipoussiere   Remove whitespace...
1067

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

735c653b   Elena.Budnik   rank at observato...
1071
1072
	public function initTTCacheFromTmpObject($folderId, $name, $isCatalog = false)
	{
10200969   Roipoussiere   Remove whitespace...
1073
		if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
735c653b   Elena.Budnik   rank at observato...
1074
1075
1076
1077
		else  $cacheMgr = new CatalogCacheMgr();

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

901ba3f3   Elena.Budnik   upload catalog
1079
	public function initTTCacheFromUploadedFile($name, $format, $isCatalog = false)
735c653b   Elena.Budnik   rank at observato...
1080
	{
901ba3f3   Elena.Budnik   upload catalog
1081
1082
		if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
		else  $cacheMgr = new CatalogCacheMgr();
10200969   Roipoussiere   Remove whitespace...
1083

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

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

e57cb025   Benjamin Renard   Fix most of error...
1092
		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...
1093
	}
10200969   Roipoussiere   Remove whitespace...
1094

735c653b   Elena.Budnik   rank at observato...
1095
1096
	public function readIntervalsForChart($o)
	{
e57cb025   Benjamin Renard   Fix most of error...
1097
		if (isset($o->typeTT) && ($o->typeTT == 'catalog' || $o->typeTT == 'sharedcatalog')) {
e1fd05b4   Elena.Budnik   visu from cacheCat
1098
1099
1100
1101
1102
1103
1104
1105
1106
				
				if ($o->fromPlugin && $o->id == 'cacheCat') {
					$objMgr = new CatalogCacheMgr();
					
					return $objMgr->getIntervals();
				}
				
				$objMgr = new CatalogMgr();
		}
10200969   Roipoussiere   Remove whitespace...
1107

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

735c653b   Elena.Budnik   rank at observato...
1111
1112
1113
1114
1115
	public function saveTTCacheIntervalsInTT($o)
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->saveInTT($o->ttId,$o->action,$o->cacheToken);
	}
10200969   Roipoussiere   Remove whitespace...
1116

735c653b   Elena.Budnik   rank at observato...
1117
1118
1119
1120
1121
1122
1123
	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...
1124

735c653b   Elena.Budnik   rank at observato...
1125
1126
1127
1128
1129
1130
1131
	public function removeTTCacheIntervalFromId($id, $isCatalog = false)
	{
		if ($isCatalog) $cacheMgr = new CatalogCacheMgr();
		else $cacheMgr = new TimeTableCacheMgr();

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

735c653b   Elena.Budnik   rank at observato...
1133
1134
	public function modifyTTCacheInterval($o)
	{
10200969   Roipoussiere   Remove whitespace...
1135
		if ($o->isCatalog)
735c653b   Elena.Budnik   rank at observato...
1136
		{
f9c8b272   elena   edit catalog
1137
			$cacheMgr = new CatalogCacheMgr();
735c653b   Elena.Budnik   rank at observato...
1138
			return $cacheMgr->modifyIntervalFromId($o);
f9c8b272   elena   edit catalog
1139
		}
735c653b   Elena.Budnik   rank at observato...
1140
		else $cacheMgr = new TimeTableCacheMgr();
10200969   Roipoussiere   Remove whitespace...
1141

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

735c653b   Elena.Budnik   rank at observato...
1145
1146
1147
1148
1149
	public function operationTTCacheIntervals($extendTime, $shiftTime)
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->operationIntervals($extendTime, $shiftTime);
	}
10200969   Roipoussiere   Remove whitespace...
1150

735c653b   Elena.Budnik   rank at observato...
1151
1152
1153
1154
1155
	public function mergeTTCacheIntervals()
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->mergeIntervals();
	}
10200969   Roipoussiere   Remove whitespace...
1156

735c653b   Elena.Budnik   rank at observato...
1157
1158
1159
1160
1161
	public function getTTCacheStatistics()
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->getStatistics();
	}
10200969   Roipoussiere   Remove whitespace...
1162

735c653b   Elena.Budnik   rank at observato...
1163
1164
1165
1166
1167
	public function getTTCacheStatus()
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->getStatus();
	}
aa94fd24   elena   Merge with last svn
1168

16035364   Benjamin Renard   First commit
1169
1170
/*
 * Send a feedback
10200969   Roipoussiere   Remove whitespace...
1171
 *
16035364   Benjamin Renard   First commit
1172
 */
735c653b   Elena.Budnik   rank at observato...
1173
1174
1175
1176
1177
	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...
1178

16035364   Benjamin Renard   First commit
1179
1180
/*
 * Save state
10200969   Roipoussiere   Remove whitespace...
1181
 *
16035364   Benjamin Renard   First commit
1182
 */
735c653b   Elena.Budnik   rank at observato...
1183
1184
1185
1186
1187
	public function saveState($datas)
	{
		$myStateMgr = new StateMgr();
		return $myStateMgr->saveState($datas);
	}
10200969   Roipoussiere   Remove whitespace...
1188

16035364   Benjamin Renard   First commit
1189
1190
/*
 * Load state
10200969   Roipoussiere   Remove whitespace...
1191
1192
 *
 */
735c653b   Elena.Budnik   rank at observato...
1193
	public function loadState($o)
10200969   Roipoussiere   Remove whitespace...
1194
	{
735c653b   Elena.Budnik   rank at observato...
1195
1196
1197
		$myStateMgr = new StateMgr();
		return $myStateMgr->loadState();
	}
10200969   Roipoussiere   Remove whitespace...
1198
1199

/*
16035364   Benjamin Renard   First commit
1200
1201
 * HST Images
 */
735c653b   Elena.Budnik   rank at observato...
1202
1203
1204
	public function getHstImagesUrl($o)
	{
		if ($this->amdaStat->success)
2dab1b1b   Elena.Budnik   change input args...
1205
			$this->amdaStat->addTask($this->user, 'images', null);
10200969   Roipoussiere   Remove whitespace...
1206

735c653b   Elena.Budnik   rank at observato...
1207
1208
1209
1210
1211
1212
		$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...
1213

735c653b   Elena.Budnik   rank at observato...
1214
1215
	public function getAPISImagesUrl($o)
	{
10200969   Roipoussiere   Remove whitespace...
1216
		if ($this->amdaStat->success)
2dab1b1b   Elena.Budnik   change input args...
1217
			$this->amdaStat->addTask($this->user, 'images', null);
10200969   Roipoussiere   Remove whitespace...
1218

735c653b   Elena.Budnik   rank at observato...
1219
1220
1221
1222
		$apisMgr = new APISMgr();
		$res = $apisMgr->get($o->target, $o->startTime, $o->stopTime, $o->datasets);

		return $res;
10200969   Roipoussiere   Remove whitespace...
1223
	}
16035364   Benjamin Renard   First commit
1224
1225
1226
/*
 * Filters
 */
e57cb025   Benjamin Renard   Fix most of error...
1227
	public function loadFilterList()
735c653b   Elena.Budnik   rank at observato...
1228
	{
10200969   Roipoussiere   Remove whitespace...
1229
		$filtersMgr = new FiltersMgr();
735c653b   Elena.Budnik   rank at observato...
1230
1231
1232
		$res = $filtersMgr->loadList();
		return $res;
	}
16035364   Benjamin Renard   First commit
1233

735c653b   Elena.Budnik   rank at observato...
1234
1235
1236
1237
1238
1239
1240
1241
1242
	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...
1243

735c653b   Elena.Budnik   rank at observato...
1244
1245
	public function saveFilter($o)
	{
10200969   Roipoussiere   Remove whitespace...
1246
		$filtersMgr = new FiltersMgr();
735c653b   Elena.Budnik   rank at observato...
1247
1248
		return $filtersMgr->save($o);
	}
10200969   Roipoussiere   Remove whitespace...
1249

735c653b   Elena.Budnik   rank at observato...
1250
1251
	public function createFilter($o)
	{
10200969   Roipoussiere   Remove whitespace...
1252
		$filtersMgr = new FiltersMgr();
735c653b   Elena.Budnik   rank at observato...
1253
1254
		return $filtersMgr->create($o);
	}
10200969   Roipoussiere   Remove whitespace...
1255

735c653b   Elena.Budnik   rank at observato...
1256
1257
1258
1259
1260
1261
	public function destroyFilter($o)
	{
		$filtersMgr = new FiltersMgr();
		$res = $filtersMgr->delete($o);
		return;
	}
10200969   Roipoussiere   Remove whitespace...
1262

735c653b   Elena.Budnik   rank at observato...
1263
1264
1265
1266
1267
1268
1269
	public function getCrtFilterId()
	{
		$filtersMgr = new FiltersMgr();
		$res = $filtersMgr->getCrtId();
		return $res;
	}

fdf1413b   Elena.Budnik   TT download
1270
1271
	public function getCrtFilterResult()
	{
10200969   Roipoussiere   Remove whitespace...
1272
		$filtersMgr = new FiltersMgr();
fdf1413b   Elena.Budnik   TT download
1273
1274
		return $filtersMgr->getCrtResult();
	}
10200969   Roipoussiere   Remove whitespace...
1275

fdf1413b   Elena.Budnik   TT download
1276
1277
	public function setCrtFilterId($o)
	{
10200969   Roipoussiere   Remove whitespace...
1278
		$filtersMgr = new FiltersMgr();
fdf1413b   Elena.Budnik   TT download
1279
1280
		return $filtersMgr->setCrtId($o->id);
	}
10200969   Roipoussiere   Remove whitespace...
1281

fdf1413b   Elena.Budnik   TT download
1282
1283
1284
1285
1286
1287
	public function resetFilter()
	{
		$filtersMgr = new FiltersMgr();
		$res = $filtersMgr->reset();
		return $res;
	}
10200969   Roipoussiere   Remove whitespace...
1288

16035364   Benjamin Renard   First commit
1289
1290
	public function logout($isGuest)
	{
10200969   Roipoussiere   Remove whitespace...
1291
		if ($isGuest)
735c653b   Elena.Budnik   rank at observato...
1292
		{
fdf1413b   Elena.Budnik   TT download
1293
1294
1295
			$guestMgr = new Guest($this->user);
			$guestMgr->deleteGuest();
		}
10200969   Roipoussiere   Remove whitespace...
1296
		else
735c653b   Elena.Budnik   rank at observato...
1297
		{
fdf1413b   Elena.Budnik   TT download
1298
			$this->cleanUserWS();
10200969   Roipoussiere   Remove whitespace...
1299
		}
16035364   Benjamin Renard   First commit
1300
		return;
10200969   Roipoussiere   Remove whitespace...
1301
	}
16035364   Benjamin Renard   First commit
1302

fdf1413b   Elena.Budnik   TT download
1303
1304
	public function getInfo($obj)
	{
10200969   Roipoussiere   Remove whitespace...
1305
		if (file_exists(HELPPATH.$obj->name))
fdf1413b   Elena.Budnik   TT download
1306
		{
10200969   Roipoussiere   Remove whitespace...
1307
			$content = file_get_contents(HELPPATH.$obj->name);
fdf1413b   Elena.Budnik   TT download
1308
1309
			return  array('success' => true, 'result' => $content);
		}
10200969   Roipoussiere   Remove whitespace...
1310
1311
1312
		return array('success' => false);
	}

fdf1413b   Elena.Budnik   TT download
1313
1314
1315
1316
1317
	public function getUserInfo()
	{
		$dd = new UserMgr();
		return $dd->getUserInfo();
	}
16035364   Benjamin Renard   First commit
1318

fdf1413b   Elena.Budnik   TT download
1319
1320
1321
1322
1323
	public function convertWS()
	{
		$dd = new UserMgr();
		return $dd->convertWS();
	}
16035364   Benjamin Renard   First commit
1324

fdf1413b   Elena.Budnik   TT download
1325
1326
1327
1328
1329
1330
	// $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...
1331
1332

		return  $res;
fdf1413b   Elena.Budnik   TT download
1333
	}
10200969   Roipoussiere   Remove whitespace...
1334
1335

	//$obj = array of IDs
fdf1413b   Elena.Budnik   TT download
1336
1337
1338
	public function addRun($obj)
	{
		$myBestRunsMgr = new BestRunsMgr();
10200969   Roipoussiere   Remove whitespace...
1339

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

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

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

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

fdf1413b   Elena.Budnik   TT download
1350
1351
1352
1353
	//AKKA - New action to clean user WS
	public function cleanUserWS()
	{
		$this->rrmdir(USERDIR.'DOWNLOAD.TEMP');
bf74fc2d   Elena.Budnik   IMPEX
1354
		IHMConfigClass::setUserName($this->user);
10200969   Roipoussiere   Remove whitespace...
1355
1356

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

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

fdf1413b   Elena.Budnik   TT download
1364
1365
1366
	public function rrmdir($dir){
		if (is_dir($dir)) {
			$objects = scandir($dir);
10200969   Roipoussiere   Remove whitespace...
1367
1368
			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
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
					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...
1382
		if (file_exists(USERDIR.$name))
fdf1413b   Elena.Budnik   TT download
1383
1384
1385
					unlink(USERDIR.$name);
		return array('success' => true);
	}
10200969   Roipoussiere   Remove whitespace...
1386

fdf1413b   Elena.Budnik   TT download
1387
1388
	public function interactivePlot($obj, $multiPlotState)
	{
fdf1413b   Elena.Budnik   TT download
1389
1390
1391
1392
1393
1394
		$inputobj = (Object)array(
			'action' => $obj,
			'multiPlotState' => $multiPlotState
		);
		return $this->executeRequest($inputobj, FunctionTypeEnumClass::ACTION);
	}
10200969   Roipoussiere   Remove whitespace...
1395

735c653b   Elena.Budnik   rank at observato...
1396
1397
	public function getParamPlotInit($obj)
	{
bf74fc2d   Elena.Budnik   IMPEX
1398
1399
1400
1401
1402
		// IMPEX param
		if (preg_match("#^spase___IMPEX_#",$obj->paramId))
			$type = 'impex_plot_init';
		else
		   $type = 'plot_init';
10200969   Roipoussiere   Remove whitespace...
1403

735c653b   Elena.Budnik   rank at observato...
1404
1405
		$inputobj = (Object)array(
				'paramId' => $obj->paramId,
bf74fc2d   Elena.Budnik   IMPEX
1406
				'type' => $type
735c653b   Elena.Budnik   rank at observato...
1407
1408
1409
		);
		return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
	}
10200969   Roipoussiere   Remove whitespace...
1410

735c653b   Elena.Budnik   rank at observato...
1411
1412
	public function getParamInfo($obj)
	{
bf74fc2d   Elena.Budnik   IMPEX
1413
1414
1415
1416
1417
		// IMPEX param
		if (preg_match("#^spase___IMPEX_#",$obj->paramId))
			$type = 'impex_param_info';
		else
		   $type = 'param_info';
10200969   Roipoussiere   Remove whitespace...
1418

735c653b   Elena.Budnik   rank at observato...
1419
1420
		$inputobj = (Object)array(
				'paramId' => $obj->paramId,
bf74fc2d   Elena.Budnik   IMPEX
1421
				'type' => $type
735c653b   Elena.Budnik   rank at observato...
1422
1423
1424
		);
		return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
	}
bf776dc8   Benjamin Renard   working
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
	public function getDerivedParamInfo($obj)
	{  
                 $dom = new DomDocument("1.0");
                 $xmlName=USERWSDIR.$this->xmlFiles['derivedParam'];
		 @$dom->load($xmlName);
		 $params=$dom->getElementsByTagName("param");
		 foreach($params as $param)
		 {
                        if($param->hasAttribute("name") && ("ws_" . ($param->getAttribute("name")))==$obj->paramId)
		        {
                         $dim_1=$param->getAttribute("dim_1");
			 $dim_2=$param->getAttribute("dim_2");
		   	 return $this->createDerivedParamInfo($dim_1,$dim_2,$obj->paramId);
		  	}
		
		}
		return array('success'=>false, 'message'=>'unkown parameter (derived parameter arguments are not handled)');	
	}
	
	public function createDerivedParamInfo($dim_1,$dim_2,$paramId)
	{
		/* case of constant */
		if($dim_1*$dim_2==1)
		{
		return array('success'=>false,'msg'=>"dim1=1 dim2=1 no arguments for this parameter");
		}elseif(($dim_1==1 && $dim_2>1 && $dim_2<=3)||($dim_2==1 && $dim_1>1 && $dim_1<=3) )  
		/* case of vector */
                {

	        $dims=array(
				'dim1'=>$dim_1,
				'dim2'=>$dim_2
			      );

		$compts=array();

		for($i=0;$i<($dim_1*$dim_2);++$i)
			{

			$c=array(

				'index_1'=>($dim_1>$dim_2)?(string)$i:"",
				'index_2'=>($dim_1<$dim_2)?$i:"",
				'name'=>$paramId.'('.$i.')'
				);
			array_push($compts,$c);

			}

		$data=array(
				'dimensions'=>$dims,
				'components'=>$compts
			    );
		
10200969   Roipoussiere   Remove whitespace...
1479

bf776dc8   Benjamin Renard   working
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
			return array('success'=>true,'data'=>$data);
		}else
		/* case of spectro*/
		{
		  $sizes=array($dim_1,$dim_2);
		  $dims=array(
				'dim1'=>$dim_1,
				'dim2'=>$dim_2
			      );
		$channels=array();
 		$tables=array();
		for($j=0;$j<count($sizes);$j++)
			{
		       $compts=array();
			
			for($i=0;$i<$sizes[$j];$i++)
				{
				$c=array('min'=>'L' . $i,'max'=>'L' . ($i+1));
				array_push($compts,$c);
				}

			$tab=array(
				'relatedDim'=>'dim' . ($j+1), 
				'name'=>'component' . ($j+1),
				'units'=>"",
				'variable'=>"",
				'channels'=>$compts,
				'minmax'=>""
				);

			array_push($tables,$tab);
			}
		 
                  $data=array(
				'dimensions'=>$dims,
				'tables'=>$tables
			     );
		return array('success'=>true,'data'=>$data);
                }
		
	}
735c653b   Elena.Budnik   rank at observato...
1521
1522
1523
1524
1525
1526
	public function getSharedObjectFolders($obj)
	{
		$mgr = new SharedObjectsMgr();
		$folders = $mgr->getFolders($obj->type);
		return array('success' => true, 'folders' => $folders);
	}
10200969   Roipoussiere   Remove whitespace...
1527

735c653b   Elena.Budnik   rank at observato...
1528
1529
1530
	public function shareObjects($obj)
	{
		$mgr = new SharedObjectsMgr();
10200969   Roipoussiere   Remove whitespace...
1531
		switch ($obj->type)
735c653b   Elena.Budnik   rank at observato...
1532
1533
1534
1535
1536
		{
			case 'timeTable' :
			case 'catalog' :
				$src_object_path = USERTTDIR.$obj->object->id.".xml";
				break;
10200969   Roipoussiere   Remove whitespace...
1537

735c653b   Elena.Budnik   rank at observato...
1538
1539
1540
			default:
				return array('success' => false, 'message' => 'Unknown object type');
		}
10200969   Roipoussiere   Remove whitespace...
1541

735c653b   Elena.Budnik   rank at observato...
1542
1543
1544
		$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...
1545

735c653b   Elena.Budnik   rank at observato...
1546
1547
1548
		$mgr->updateTree();
		return $result;
	}
10200969   Roipoussiere   Remove whitespace...
1549

735c653b   Elena.Budnik   rank at observato...
1550
1551
1552
1553
1554
1555
	public function isSharedObjectNameAlreadyUsed($obj)
	{
		$mgr = new SharedObjectsMgr();
		$alreadyUsed = $mgr->isNameAlreadyUsed($obj->type, $obj->name);
		return array('success' => true, 'alreadyUsed' => $alreadyUsed);
	}
10200969   Roipoussiere   Remove whitespace...
1556

0bda97f3   Benjamin Renard   Fix SAMP export f...
1557
1558
	public function getRequestByProcessId($obj)
	{
0bda97f3   Benjamin Renard   Fix SAMP export f...
1559
1560
		return $this->executeRequest($obj->processId, FunctionTypeEnumClass::PROCESSGETREQUEST);
	}
16035364   Benjamin Renard   First commit
1561
1562
}
?>